17c788888872233748da10a8177a9a1eb176c1bc8Peter Collingbourne//===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
23da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman//
301d45827a1e512f3b19ba857772bf02baa3c0c4eJohn Criswell//                     The LLVM Compiler Infrastructure
401d45827a1e512f3b19ba857772bf02baa3c0c4eJohn Criswell//
53060910e290949a9ac5eda8726d030790c4d60ffChris Lattner// This file is distributed under the University of Illinois Open Source
63060910e290949a9ac5eda8726d030790c4d60ffChris Lattner// License. See LICENSE.TXT for details.
73da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman//
801d45827a1e512f3b19ba857772bf02baa3c0c4eJohn Criswell//===----------------------------------------------------------------------===//
9e62c1185bee05facc25d1d725434f517261d308bChris Lattner//
1014d7c59491347a2f8f29e120fd75a4cad42f68e7Chris Lattner// This file defines the main TableGen data structures, including the TableGen
1114d7c59491347a2f8f29e120fd75a4cad42f68e7Chris Lattner// types, values, and high-level data structures.
12e62c1185bee05facc25d1d725434f517261d308bChris Lattner//
13e62c1185bee05facc25d1d725434f517261d308bChris Lattner//===----------------------------------------------------------------------===//
14e62c1185bee05facc25d1d725434f517261d308bChris Lattner
157c788888872233748da10a8177a9a1eb176c1bc8Peter Collingbourne#ifndef LLVM_TABLEGEN_RECORD_H
167c788888872233748da10a8177a9a1eb176c1bc8Peter Collingbourne#define LLVM_TABLEGEN_RECORD_H
17e62c1185bee05facc25d1d725434f517261d308bChris Lattner
18c45a2cacd09f88b8b715fd89f5bf6c2347b2cce9David Greene#include "llvm/ADT/ArrayRef.h"
19726bbde3c4ac5a279c86d1632b7b94498b01854aDavid Greene#include "llvm/ADT/FoldingSet.h"
20dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene#include "llvm/Support/Allocator.h"
2189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva#include "llvm/Support/Casting.h"
223cc52ea33c0b96d1682f14fc45c45b57df0f39b6Michael J. Spencer#include "llvm/Support/DataTypes.h"
2350bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper#include "llvm/Support/ErrorHandling.h"
24255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/Support/SourceMgr.h"
251a55180238dbcf11113f610aea010447e51f595bDaniel Dunbar#include "llvm/Support/raw_ostream.h"
26e62c1185bee05facc25d1d725434f517261d308bChris Lattner#include <map>
27028936ada14335bb04f377d46a6261dc4c66dafdJohn Criswell
28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
291a55180238dbcf11113f610aea010447e51f595bDaniel Dunbarclass raw_ostream;
3021870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
317dda395004eb962cef1c1554b1e8b2ad069760e0Chris Lattner// RecTy subclasses.
327cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerclass BitRecTy;
337cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerclass BitsRecTy;
347cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerclass IntRecTy;
357cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerclass StringRecTy;
367cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerclass ListRecTy;
3740f71134b9fef0ca06c516f033cc9403394a913cChris Lattnerclass DagRecTy;
387cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerclass RecordRecTy;
397cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner
407dda395004eb962cef1c1554b1e8b2ad069760e0Chris Lattner// Init subclasses.
41afd54269ab9951c0dcdea076c4d6f48a345e9d27David Greeneclass Init;
42e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass UnsetInit;
43e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass BitInit;
44e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass BitsInit;
45e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass IntInit;
46e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass StringInit;
47e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass ListInit;
48e6c27de069225e1122c78385ad22a2ff656db8e6David Greeneclass UnOpInit;
49711e5d96aa648ebe96b09483d0775f3b16283e3dChris Lattnerclass BinOpInit;
504afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greeneclass TernOpInit;
51e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass DefInit;
528e9a9774eb12b5242f74b8ac5b20e0a938ec9c53Chris Lattnerclass DagInit;
53b45b3b3cd14faaf5a3ea5226af7e1e3cd653e6cbChris Lattnerclass TypedInit;
54b45b3b3cd14faaf5a3ea5226af7e1e3cd653e6cbChris Lattnerclass VarInit;
55a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattnerclass FieldInit;
56b45b3b3cd14faaf5a3ea5226af7e1e3cd653e6cbChris Lattnerclass VarBitInit;
571dba7abdd77e19c230f0426825a5ae4879471dccChris Lattnerclass VarListElementInit;
587cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner
597dda395004eb962cef1c1554b1e8b2ad069760e0Chris Lattner// Other classes.
60e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass Record;
617dda395004eb962cef1c1554b1e8b2ad069760e0Chris Lattnerclass RecordVal;
62293b13350c2fbae8a64b0b0beb440cb859968c8cBob Wilsonstruct MultiClass;
6367db883487fca3472fdde51e931657e22d4d0495Chris Lattnerclass RecordKeeper;
64e62c1185bee05facc25d1d725434f517261d308bChris Lattner
65e62c1185bee05facc25d1d725434f517261d308bChris Lattner//===----------------------------------------------------------------------===//
66e62c1185bee05facc25d1d725434f517261d308bChris Lattner//  Type Classes
67e62c1185bee05facc25d1d725434f517261d308bChris Lattner//===----------------------------------------------------------------------===//
68e62c1185bee05facc25d1d725434f517261d308bChris Lattner
6977f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesenclass RecTy {
7089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silvapublic:
7189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  /// \brief Subclass discriminator (for dyn_cast<> et al.)
7289adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  enum RecTyKind {
7389adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    BitRecTyKind,
7489adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    BitsRecTyKind,
7589adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    IntRecTyKind,
7689adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    StringRecTyKind,
7789adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    ListRecTyKind,
7889adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    DagRecTyKind,
7989adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    RecordRecTyKind
8089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  };
8189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
8289adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silvaprivate:
8389adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  RecTyKind Kind;
8477f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  ListRecTy *ListTy;
852d24e2a396a1d211baaeedf32148a3b657240170David Blaikie  virtual void anchor();
8689adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
8777f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesenpublic:
8889adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  RecTyKind getRecTyKind() const { return Kind; }
8989adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
90dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  RecTy(RecTyKind K) : Kind(K), ListTy(nullptr) {}
91e62c1185bee05facc25d1d725434f517261d308bChris Lattner  virtual ~RecTy() {}
92e62c1185bee05facc25d1d725434f517261d308bChris Lattner
9399ba1f7b8deaf2a296c98600dbf593754cbd43a2Chris Lattner  virtual std::string getAsString() const = 0;
941a55180238dbcf11113f610aea010447e51f595bDaniel Dunbar  void print(raw_ostream &OS) const { OS << getAsString(); }
957cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  void dump() const;
967cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner
977cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  /// typeIsConvertibleTo - Return true if all values of 'this' type can be
987cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  /// converted to the specified type.
997cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
1007cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner
10177f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  /// getListTy - Returns the type representing list<this>.
10277f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  ListRecTy *getListTy();
10377f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen
1047cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattnerpublic:   // These methods should only be called from subclasses of Init
105dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue( UnsetInit *UI) { return nullptr; }
106dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(   BitInit *BI) { return nullptr; }
107dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(  BitsInit *BI) { return nullptr; }
108dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(   IntInit *II) { return nullptr; }
109dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(StringInit *SI) { return nullptr; }
110dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(  ListInit *LI) { return nullptr; }
11105bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *convertValue( UnOpInit *UI) {
11205bce0beee87512e52428d4b80f5a8e79a949576David Greene    return convertValue((TypedInit*)UI);
113e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  }
11405bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *convertValue( BinOpInit *UI) {
11505bce0beee87512e52428d4b80f5a8e79a949576David Greene    return convertValue((TypedInit*)UI);
116e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene  }
11705bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *convertValue( TernOpInit *UI) {
11805bce0beee87512e52428d4b80f5a8e79a949576David Greene    return convertValue((TypedInit*)UI);
1194afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  }
120dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(VarBitInit *VB) { return nullptr; }
121dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(   DefInit *DI) { return nullptr; }
122dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue(   DagInit *DI) { return nullptr; }
123dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual Init *convertValue( TypedInit *TI) { return nullptr; }
12405bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *convertValue(   VarInit *VI) {
12505bce0beee87512e52428d4b80f5a8e79a949576David Greene    return convertValue((TypedInit*)VI);
126b45b3b3cd14faaf5a3ea5226af7e1e3cd653e6cbChris Lattner  }
12705bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *convertValue( FieldInit *FI) {
12805bce0beee87512e52428d4b80f5a8e79a949576David Greene    return convertValue((TypedInit*)FI);
129b45b3b3cd14faaf5a3ea5226af7e1e3cd653e6cbChris Lattner  }
130e62c1185bee05facc25d1d725434f517261d308bChris Lattner
13137fda193d292d78c672b8019723c7907af312c43Sean Silvapublic:
13237fda193d292d78c672b8019723c7907af312c43Sean Silva  virtual bool baseClassOf(const RecTy*) const;
133e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
134e62c1185bee05facc25d1d725434f517261d308bChris Lattner
1351a55180238dbcf11113f610aea010447e51f595bDaniel Dunbarinline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
136e62c1185bee05facc25d1d725434f517261d308bChris Lattner  Ty.print(OS);
137e62c1185bee05facc25d1d725434f517261d308bChris Lattner  return OS;
138e62c1185bee05facc25d1d725434f517261d308bChris Lattner}
139e62c1185bee05facc25d1d725434f517261d308bChris Lattner
14007278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// BitRecTy - 'bit' - Represent a single bit
14107278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
1421fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass BitRecTy : public RecTy {
14377f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static BitRecTy Shared;
14489adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  BitRecTy() : RecTy(BitRecTyKind) {}
145dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
1461fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
14789adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
14889adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == BitRecTyKind;
14989adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
15089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
15177f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static BitRecTy *get() { return &Shared; }
15277f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen
15336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
15436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   BitInit *BI) override { return (Init*)BI; }
15536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(  BitsInit *BI) override;
15636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   IntInit *II) override;
157dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(StringInit *SI) override { return nullptr; }
158dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  ListInit *LI) override { return nullptr; }
15936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(VarBitInit *VB) override { return (Init*)VB; }
160dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DefInit *DI) override { return nullptr; }
161dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DagInit *DI) override { return nullptr; }
16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
16336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
16436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
16536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *TI) override;
16636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
16736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
16936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return "bit"; }
17036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
17136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
1727cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return RHS->baseClassOf(this);
1737cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  }
17436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool baseClassOf(const RecTy*) const override;
175e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
176e62c1185bee05facc25d1d725434f517261d308bChris Lattner
1771b2c94713600531ddeefb23cd10c49cd533aa09bEli Bendersky/// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
17807278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
179e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass BitsRecTy : public RecTy {
180e62c1185bee05facc25d1d725434f517261d308bChris Lattner  unsigned Size;
18189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  explicit BitsRecTy(unsigned Sz) : RecTy(BitsRecTyKind), Size(Sz) {}
182dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
18377f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesenpublic:
18489adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
18589adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == BitsRecTyKind;
18689adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
18789adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
18877f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static BitsRecTy *get(unsigned Sz);
189e62c1185bee05facc25d1d725434f517261d308bChris Lattner
190e62c1185bee05facc25d1d725434f517261d308bChris Lattner  unsigned getNumBits() const { return Size; }
191e62c1185bee05facc25d1d725434f517261d308bChris Lattner
19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override;
19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   BitInit *UI) override;
19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(  BitsInit *BI) override;
19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   IntInit *II) override;
196dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(StringInit *SI) override { return nullptr; }
197dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  ListInit *LI) override { return nullptr; }
198dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(VarBitInit *VB) override { return nullptr; }
199dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DefInit *DI) override { return nullptr; }
200dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DagInit *DI) override { return nullptr; }
201dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  UnOpInit *UI) override { return RecTy::convertValue(UI);}
20236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
203dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(TernOpInit *UI) override { return RecTy::convertValue(UI);}
20436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *TI) override;
205dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
206dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
20736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
20836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
20936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
210dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
2117cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return RHS->baseClassOf(this);
2127cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  }
21336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool baseClassOf(const RecTy*) const override;
214e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
215e62c1185bee05facc25d1d725434f517261d308bChris Lattner
21607278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// IntRecTy - 'int' - Represent an integer value of no particular size
21707278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
2181fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass IntRecTy : public RecTy {
21977f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static IntRecTy Shared;
22089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  IntRecTy() : RecTy(IntRecTyKind) {}
221dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
2221fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
22389adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
22489adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == IntRecTyKind;
22589adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
22689adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
22777f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static IntRecTy *get() { return &Shared; }
22877f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen
22936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
23036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   BitInit *BI) override;
23136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(  BitsInit *BI) override;
23236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   IntInit *II) override { return (Init*)II; }
233dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(StringInit *SI) override { return nullptr; }
234dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  ListInit *LI) override { return nullptr; }
235dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(VarBitInit *VB) override { return nullptr; }
236dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DefInit *DI) override { return nullptr; }
237dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DagInit *DI) override { return nullptr; }
23836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnOpInit *UI)  override { return RecTy::convertValue(UI);}
23936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
24036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
24136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *TI) override;
24236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
24336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
24436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
24536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return "int"; }
24636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
24736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
2487cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return RHS->baseClassOf(this);
2497cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  }
2507cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner
25136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool baseClassOf(const RecTy*) const override;
252e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
253e62c1185bee05facc25d1d725434f517261d308bChris Lattner
25407278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// StringRecTy - 'string' - Represent an string value
25507278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
2561fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass StringRecTy : public RecTy {
25777f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static StringRecTy Shared;
25889adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  StringRecTy() : RecTy(StringRecTyKind) {}
259dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
2601fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
26189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
26289adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == StringRecTyKind;
26389adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
26489adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
26577f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static StringRecTy *get() { return &Shared; }
26677f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen
26736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
268dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   BitInit *BI) override { return nullptr; }
269dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  BitsInit *BI) override { return nullptr; }
270dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   IntInit *II) override { return nullptr; }
27136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(StringInit *SI) override { return (Init*)SI; }
272dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  ListInit *LI) override { return nullptr; }
27336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnOpInit *BO) override;
27436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *BO) override;
27536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TernOpInit *BO) override {return RecTy::convertValue(BO);}
27636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
277dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(VarBitInit *VB) override { return nullptr; }
278dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DefInit *DI) override { return nullptr; }
279dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DagInit *DI) override { return nullptr; }
28036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *TI) override;
28136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
28236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
28336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
28436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return "string"; }
28536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
28636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
2877cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return RHS->baseClassOf(this);
2887cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  }
289e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
290e62c1185bee05facc25d1d725434f517261d308bChris Lattner
2911b2c94713600531ddeefb23cd10c49cd533aa09bEli Bendersky/// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
2921b2c94713600531ddeefb23cd10c49cd533aa09bEli Bendersky/// the specified type.
29307278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
294e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass ListRecTy : public RecTy {
2957cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  RecTy *Ty;
29689adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  explicit ListRecTy(RecTy *T) : RecTy(ListRecTyKind), Ty(T) {}
29777f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  friend ListRecTy *RecTy::getListTy();
298dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
29977f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesenpublic:
30089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
30189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == ListRecTyKind;
30289adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
30389adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
30477f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static ListRecTy *get(RecTy *T) { return T->getListTy(); }
3057cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  RecTy *getElementType() const { return Ty; }
306f1b36f9a71eb267f04b7bd3a32aca9bc69f71e97Chris Lattner
30736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
308dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   BitInit *BI) override { return nullptr; }
309dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  BitsInit *BI) override { return nullptr; }
310dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   IntInit *II) override { return nullptr; }
311dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(StringInit *SI) override { return nullptr; }
31236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(  ListInit *LI) override;
313dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(VarBitInit *VB) override { return nullptr; }
314dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DefInit *DI) override { return nullptr; }
315dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DagInit *DI) override { return nullptr; }
316dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  UnOpInit *UI) override { return RecTy::convertValue(UI);}
31736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
318dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(TernOpInit *UI) override { return RecTy::convertValue(UI);}
31936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *TI) override;
32036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
32136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
32236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
32336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
32436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
325dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
3267cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return RHS->baseClassOf(this);
3277cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  }
3287cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner
32936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool baseClassOf(const RecTy*) const override;
330f05760de76b4ec26474da18c97770ca369972cfdChris Lattner};
331f05760de76b4ec26474da18c97770ca369972cfdChris Lattner
33240f71134b9fef0ca06c516f033cc9403394a913cChris Lattner/// DagRecTy - 'dag' - Represent a dag fragment
33340f71134b9fef0ca06c516f033cc9403394a913cChris Lattner///
3341fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass DagRecTy : public RecTy {
33577f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static DagRecTy Shared;
33689adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  DagRecTy() : RecTy(DagRecTyKind) {}
337dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
3381fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
33989adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
34089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == DagRecTyKind;
34189adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
34289adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
34377f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static DagRecTy *get() { return &Shared; }
34477f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen
34536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
346dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   BitInit *BI) override { return nullptr; }
347dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  BitsInit *BI) override { return nullptr; }
348dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   IntInit *II) override { return nullptr; }
349dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(StringInit *SI) override { return nullptr; }
350dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  ListInit *LI) override { return nullptr; }
351dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(VarBitInit *VB) override { return nullptr; }
352dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DefInit *DI) override { return nullptr; }
35336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnOpInit *BO) override;
35436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *BO) override;
35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TernOpInit *BO) override {return RecTy::convertValue(BO);}
35636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   DagInit *CI) override { return (Init*)CI; }
35736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *TI) override;
35836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
35936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
36036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
36136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return "dag"; }
36236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
363dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
36440f71134b9fef0ca06c516f033cc9403394a913cChris Lattner    return RHS->baseClassOf(this);
36540f71134b9fef0ca06c516f033cc9403394a913cChris Lattner  }
36640f71134b9fef0ca06c516f033cc9403394a913cChris Lattner};
36740f71134b9fef0ca06c516f033cc9403394a913cChris Lattner
368234b3ec8795e0661af56aa1d1a978a41d80686c5Misha Brukman/// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
36907278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// (R32 X = EAX).
37007278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
371e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass RecordRecTy : public RecTy {
372e62c1185bee05facc25d1d725434f517261d308bChris Lattner  Record *Rec;
37389adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  explicit RecordRecTy(Record *R) : RecTy(RecordRecTyKind), Rec(R) {}
37477f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  friend class Record;
375dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
37677f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesenpublic:
37789adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  static bool classof(const RecTy *RT) {
37889adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva    return RT->getRecTyKind() == RecordRecTyKind;
37989adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva  }
38089adeb225db4cd4d5c671d2ac5e2e6a6e755b5bcSean Silva
38177f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  static RecordRecTy *get(Record *R);
382e62c1185bee05facc25d1d725434f517261d308bChris Lattner
383a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  Record *getRecord() const { return Rec; }
384a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner
38536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
386dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   BitInit *BI) override { return nullptr; }
387dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  BitsInit *BI) override { return nullptr; }
388dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   IntInit *II) override { return nullptr; }
389dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(StringInit *SI) override { return nullptr; }
390dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(  ListInit *LI) override { return nullptr; }
391dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(VarBitInit *VB) override { return nullptr; }
39236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
39336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
39436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
39536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   DefInit *DI) override;
396dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Init *convertValue(   DagInit *DI) override { return nullptr; }
39736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( TypedInit *VI) override;
39836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
39936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
40036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
40136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
40236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
40336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool typeIsConvertibleTo(const RecTy *RHS) const override {
4047cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return RHS->baseClassOf(this);
4057cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  }
40636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool baseClassOf(const RecTy*) const override;
407e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
408e62c1185bee05facc25d1d725434f517261d308bChris Lattner
40921870411d9c1807526b613d04c2ebae5a43c263bBob Wilson/// resolveTypes - Find a common type that T1 and T2 convert to.
410e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene/// Return 0 if no such type exists.
411e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene///
412e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid GreeneRecTy *resolveTypes(RecTy *T1, RecTy *T2);
41307278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner
414e62c1185bee05facc25d1d725434f517261d308bChris Lattner//===----------------------------------------------------------------------===//
415e62c1185bee05facc25d1d725434f517261d308bChris Lattner//  Initializer Classes
416e62c1185bee05facc25d1d725434f517261d308bChris Lattner//===----------------------------------------------------------------------===//
417e62c1185bee05facc25d1d725434f517261d308bChris Lattner
418afd54269ab9951c0dcdea076c4d6f48a345e9d27David Greeneclass Init {
419b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silvaprotected:
420b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// \brief Discriminator enum (for isa<>, dyn_cast<>, et al.)
421b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  ///
422b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// This enum is laid out by a preorder traversal of the inheritance
423b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// hierarchy, and does not contain an entry for abstract classes, as per
424b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
425b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  ///
426b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// We also explicitly include "first" and "last" values for each
427b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// interior node of the inheritance tree, to make it easier to read the
428b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// corresponding classof().
429b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  ///
430b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// We could pack these a bit tighter by not having the IK_FirstXXXInit
431b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// and IK_LastXXXInit be their own values, but that would degrade
432b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  /// readability for really no benefit.
433b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  enum InitKind {
434b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_BitInit,
435b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_BitsInit,
436b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_FirstTypedInit,
437b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_DagInit,
438b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_DefInit,
439b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_FieldInit,
440b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_IntInit,
441b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_ListInit,
442b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_FirstOpInit,
443b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_BinOpInit,
444b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_TernOpInit,
445b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_UnOpInit,
446b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_LastOpInit,
447b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_StringInit,
448b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_VarInit,
449b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_VarListElementInit,
450b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_LastTypedInit,
451b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_UnsetInit,
452b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    IK_VarBitInit
453b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  };
454b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva
455b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silvaprivate:
456b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  const InitKind Kind;
457a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  Init(const Init &) LLVM_DELETED_FUNCTION;
458a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  Init &operator=(const Init &) LLVM_DELETED_FUNCTION;
4592d24e2a396a1d211baaeedf32148a3b657240170David Blaikie  virtual void anchor();
460dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
461b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silvapublic:
462b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  InitKind getKind() const { return Kind; }
463b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva
464dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greeneprotected:
465b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  explicit Init(InitKind K) : Kind(K) {}
466dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
467afd54269ab9951c0dcdea076c4d6f48a345e9d27David Greenepublic:
468e62c1185bee05facc25d1d725434f517261d308bChris Lattner  virtual ~Init() {}
469e62c1185bee05facc25d1d725434f517261d308bChris Lattner
470f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// isComplete - This virtual method should be overridden by values that may
471f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// not be completely specified yet.
472f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  virtual bool isComplete() const { return true; }
473f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner
474f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// print - Print out this value.
4751a55180238dbcf11113f610aea010447e51f595bDaniel Dunbar  void print(raw_ostream &OS) const { OS << getAsString(); }
4763aba4d39fd101238ac06871895c28f26736d80cbChris Lattner
4773aba4d39fd101238ac06871895c28f26736d80cbChris Lattner  /// getAsString - Convert this value to a string form.
4783aba4d39fd101238ac06871895c28f26736d80cbChris Lattner  virtual std::string getAsString() const = 0;
4790b18d59435a7c01a433ac69845e6d8e1ad66ce8bDavid Greene  /// getAsUnquotedString - Convert this value to a string form,
4800b18d59435a7c01a433ac69845e6d8e1ad66ce8bDavid Greene  /// without adding quote markers.  This primaruly affects
4810b18d59435a7c01a433ac69845e6d8e1ad66ce8bDavid Greene  /// StringInits where we will not surround the string value with
4820b18d59435a7c01a433ac69845e6d8e1ad66ce8bDavid Greene  /// quotes.
4834b18691c3580674691875ec37c84a1c4edf2d586Jim Grosbach  virtual std::string getAsUnquotedString() const { return getAsString(); }
484f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner
485f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// dump - Debugging method that may be called through a debugger, just
4861a55180238dbcf11113f610aea010447e51f595bDaniel Dunbar  /// invokes print on stderr.
487e62c1185bee05facc25d1d725434f517261d308bChris Lattner  void dump() const;
488e62c1185bee05facc25d1d725434f517261d308bChris Lattner
489f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// convertInitializerTo - This virtual function is a simple call-back
490f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// function that should be overridden to call the appropriate
491f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// RecTy::convertValue method.
492f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  ///
49305bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *convertInitializerTo(RecTy *Ty) const = 0;
494f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner
495f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// convertInitializerBitRange - This method is used to implement the bitrange
496f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// selection operator.  Given an initializer, it selects the specified bits
4977331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner  /// out, returning them as a new init of bits type.  If it is not legal to use
4987331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner  /// the bit subscript operator on this initializer, return null.
499f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  ///
50005bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *
501f37dd02f7743ebd2424480361f5a7db510495c4fDavid Greene  convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
502dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return nullptr;
503e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
504e62c1185bee05facc25d1d725434f517261d308bChris Lattner
505b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner  /// convertInitListSlice - This method is used to implement the list slice
506b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner  /// selection operator.  Given an initializer, it selects the specified list
507b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner  /// elements, returning them as a new init of list type.  If it is not legal
508b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner  /// to take a slice of this, return null.
509b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner  ///
51005bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *
511f37dd02f7743ebd2424480361f5a7db510495c4fDavid Greene  convertInitListSlice(const std::vector<unsigned> &Elements) const {
512dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return nullptr;
513b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner  }
514b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner
515a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  /// getFieldType - This method is used to implement the FieldInit class.
516a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  /// Implementors of this method should return the type of the named field if
517a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  /// they are of record type.
518a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  ///
519dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  virtual RecTy *getFieldType(const std::string &FieldName) const {
520dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return nullptr;
521dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  }
522a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner
523b1ed0fc6308885c5887ed0474e8a4fbf63a39b45Chris Lattner  /// getFieldInit - This method complements getFieldType to return the
524b1ed0fc6308885c5887ed0474e8a4fbf63a39b45Chris Lattner  /// initializer for the specified field.  If getFieldType returns non-null
525b1ed0fc6308885c5887ed0474e8a4fbf63a39b45Chris Lattner  /// this method should return non-null, otherwise it returns null.
526b1ed0fc6308885c5887ed0474e8a4fbf63a39b45Chris Lattner  ///
52705bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *getFieldInit(Record &R, const RecordVal *RV,
52805bce0beee87512e52428d4b80f5a8e79a949576David Greene                             const std::string &FieldName) const {
529dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return nullptr;
530b1ed0fc6308885c5887ed0474e8a4fbf63a39b45Chris Lattner  }
5313da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
532f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// resolveReferences - This method is used by classes that refer to other
533a8449e6aaa6f494d85e75d4755f9c47abf1e06ceBob Wilson  /// variables which may not be defined at the time the expression is formed.
534f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// If a value is set for the variable later, this method will be called on
535f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  /// users of the value to allow the value to propagate out.
536f1e37d9d037bb5f7beb688822beddd2340cd871eChris Lattner  ///
53705bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *resolveReferences(Record &R, const RecordVal *RV) const {
53805bce0beee87512e52428d4b80f5a8e79a949576David Greene    return const_cast<Init *>(this);
5397dda395004eb962cef1c1554b1e8b2ad069760e0Chris Lattner  }
540307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
541307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  /// getBit - This method is used to return the initializer for the specified
542307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  /// bit.
543307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  virtual Init *getBit(unsigned Bit) const = 0;
544307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
545307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  /// getBitVar - This method is used to retrieve the initializer for bit
546307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  /// reference. For non-VarBitInit, it simply returns itself.
547307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  virtual Init *getBitVar() const { return const_cast<Init*>(this); }
548307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
549307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  /// getBitNum - This method is used to retrieve the bit number of a bit
550307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  /// reference. For non-VarBitInit, it simply returns 0.
551307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  virtual unsigned getBitNum() const { return 0; }
552e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
553e62c1185bee05facc25d1d725434f517261d308bChris Lattner
5541a55180238dbcf11113f610aea010447e51f595bDaniel Dunbarinline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
555e62c1185bee05facc25d1d725434f517261d308bChris Lattner  I.print(OS); return OS;
556e62c1185bee05facc25d1d725434f517261d308bChris Lattner}
557e62c1185bee05facc25d1d725434f517261d308bChris Lattner
558beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene/// TypedInit - This is the common super-class of types that have a specific,
559beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene/// explicit, type.
560beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene///
561beb31a51f67f651c5fa3c5094a78266d04a697a5David Greeneclass TypedInit : public Init {
562beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  RecTy *Ty;
563dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
564a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  TypedInit(const TypedInit &Other) LLVM_DELETED_FUNCTION;
565a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  TypedInit &operator=(const TypedInit &Other) LLVM_DELETED_FUNCTION;
566dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
567dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greeneprotected:
568b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  explicit TypedInit(InitKind K, RecTy *T) : Init(K), Ty(T) {}
569d568b3f55294917d1cc701da14a8a7daeb6563e6Eric Christopher
570dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
571b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
572b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() >= IK_FirstTypedInit &&
573b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva           I->getKind() <= IK_LastTypedInit;
574b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
575beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  RecTy *getType() const { return Ty; }
576beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene
57736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *
57836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
57936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *
58036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  convertInitListSlice(const std::vector<unsigned> &Elements) const override;
581beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene
5829703843dfa5640ddfc4362d7aa20b03fba485eceDavid Greene  /// getFieldType - This method is used to implement the FieldInit class.
5839703843dfa5640ddfc4362d7aa20b03fba485eceDavid Greene  /// Implementors of this method should return the type of the named field if
5849703843dfa5640ddfc4362d7aa20b03fba485eceDavid Greene  /// they are of record type.
5859703843dfa5640ddfc4362d7aa20b03fba485eceDavid Greene  ///
58636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  RecTy *getFieldType(const std::string &FieldName) const override;
5879703843dfa5640ddfc4362d7aa20b03fba485eceDavid Greene
588beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// resolveListElementReference - This method is used to implement
589beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// VarListElementInit::resolveReferences.  If the list element is resolvable
590beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// now, we return the resolved value, otherwise we return null.
59105bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
59205bce0beee87512e52428d4b80f5a8e79a949576David Greene                                            unsigned Elt) const = 0;
593beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene};
594beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene
59507278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// UnsetInit - ? - Represents an uninitialized value
59607278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
5971fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass UnsetInit : public Init {
598b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  UnsetInit() : Init(IK_UnsetInit) {}
599a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  UnsetInit(const UnsetInit &) LLVM_DELETED_FUNCTION;
600a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  UnsetInit &operator=(const UnsetInit &Other) LLVM_DELETED_FUNCTION;
60136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void anchor() override;
602dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
6031fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
604b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
605b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_UnsetInit;
606b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
60705bce0beee87512e52428d4b80f5a8e79a949576David Greene  static UnsetInit *get();
608dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
60936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
61005bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<UnsetInit *>(this));
611e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
612e62c1185bee05facc25d1d725434f517261d308bChris Lattner
61336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
614307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    return const_cast<UnsetInit*>(this);
615307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
616307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
61736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isComplete() const override { return false; }
61836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return "?"; }
619e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
620e62c1185bee05facc25d1d725434f517261d308bChris Lattner
62107278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// BitInit - true/false - Represent a concrete initializer for a bit.
62207278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
623e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass BitInit : public Init {
624e62c1185bee05facc25d1d725434f517261d308bChris Lattner  bool Value;
625dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
626b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  explicit BitInit(bool V) : Init(IK_BitInit), Value(V) {}
627a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  BitInit(const BitInit &Other) LLVM_DELETED_FUNCTION;
628a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  BitInit &operator=(BitInit &Other) LLVM_DELETED_FUNCTION;
62936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void anchor() override;
630dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
631dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
632b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
633b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_BitInit;
634b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
63505bce0beee87512e52428d4b80f5a8e79a949576David Greene  static BitInit *get(bool V);
636e62c1185bee05facc25d1d725434f517261d308bChris Lattner
637e62c1185bee05facc25d1d725434f517261d308bChris Lattner  bool getValue() const { return Value; }
638e62c1185bee05facc25d1d725434f517261d308bChris Lattner
63936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
64005bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<BitInit *>(this));
641e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
642e62c1185bee05facc25d1d725434f517261d308bChris Lattner
64336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
644307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    assert(Bit < 1 && "Bit index out of range!");
645307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    return const_cast<BitInit*>(this);
646307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
647307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
64836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return Value ? "1" : "0"; }
649e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
650e62c1185bee05facc25d1d725434f517261d308bChris Lattner
65107278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
65207278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// It contains a vector of bits, whose size is determined by the type.
65307278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
654726bbde3c4ac5a279c86d1632b7b94498b01854aDavid Greeneclass BitsInit : public Init, public FoldingSetNode {
65505bce0beee87512e52428d4b80f5a8e79a949576David Greene  std::vector<Init*> Bits;
656dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
657b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  BitsInit(ArrayRef<Init *> Range)
658b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    : Init(IK_BitsInit), Bits(Range.begin(), Range.end()) {}
659e62c1185bee05facc25d1d725434f517261d308bChris Lattner
660a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  BitsInit(const BitsInit &Other) LLVM_DELETED_FUNCTION;
661a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  BitsInit &operator=(const BitsInit &Other) LLVM_DELETED_FUNCTION;
662dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
663dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
664b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
665b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_BitsInit;
666b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
66705bce0beee87512e52428d4b80f5a8e79a949576David Greene  static BitsInit *get(ArrayRef<Init *> Range);
668dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
669726bbde3c4ac5a279c86d1632b7b94498b01854aDavid Greene  void Profile(FoldingSetNodeID &ID) const;
670726bbde3c4ac5a279c86d1632b7b94498b01854aDavid Greene
671e62c1185bee05facc25d1d725434f517261d308bChris Lattner  unsigned getNumBits() const { return Bits.size(); }
672e62c1185bee05facc25d1d725434f517261d308bChris Lattner
67336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
67405bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<BitsInit *>(this));
675e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
67636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *
67736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
678e62c1185bee05facc25d1d725434f517261d308bChris Lattner
67936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isComplete() const override {
680e62c1185bee05facc25d1d725434f517261d308bChris Lattner    for (unsigned i = 0; i != getNumBits(); ++i)
681e62c1185bee05facc25d1d725434f517261d308bChris Lattner      if (!getBit(i)->isComplete()) return false;
682e62c1185bee05facc25d1d725434f517261d308bChris Lattner    return true;
683e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
6841808e4d251005b122b1d3f7a08a01a55c328da1cJohnny Chen  bool allInComplete() const {
6851808e4d251005b122b1d3f7a08a01a55c328da1cJohnny Chen    for (unsigned i = 0; i != getNumBits(); ++i)
6861808e4d251005b122b1d3f7a08a01a55c328da1cJohnny Chen      if (getBit(i)->isComplete()) return false;
6871808e4d251005b122b1d3f7a08a01a55c328da1cJohnny Chen    return true;
6881808e4d251005b122b1d3f7a08a01a55c328da1cJohnny Chen  }
68936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
690e62c1185bee05facc25d1d725434f517261d308bChris Lattner
69136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
692307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
69336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
694307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    assert(Bit < Bits.size() && "Bit index out of range!");
695307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    return Bits[Bit];
696307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
697e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
698e62c1185bee05facc25d1d725434f517261d308bChris Lattner
699135fe6ac5f5b80ef68c19b3ec7bb0063e28f2babBenjamin Kramer/// IntInit - 7 - Represent an initialization by a literal integer value.
70007278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
701e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greeneclass IntInit : public TypedInit {
70263f97201dc9dcebbe84d1b73113166c64212b4b8Dan Gohman  int64_t Value;
703dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
704b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  explicit IntInit(int64_t V)
705b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    : TypedInit(IK_IntInit, IntRecTy::get()), Value(V) {}
706e62c1185bee05facc25d1d725434f517261d308bChris Lattner
707a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  IntInit(const IntInit &Other) LLVM_DELETED_FUNCTION;
708a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  IntInit &operator=(const IntInit &Other) LLVM_DELETED_FUNCTION;
709dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
710dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
711b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
712b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_IntInit;
713b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
71405bce0beee87512e52428d4b80f5a8e79a949576David Greene  static IntInit *get(int64_t V);
715dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
71663f97201dc9dcebbe84d1b73113166c64212b4b8Dan Gohman  int64_t getValue() const { return Value; }
717e62c1185bee05facc25d1d725434f517261d308bChris Lattner
71836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
71905bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<IntInit *>(this));
720e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
72136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *
72236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
723e62c1185bee05facc25d1d725434f517261d308bChris Lattner
72436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
725e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene
726e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  /// resolveListElementReference - This method is used to implement
727e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  /// VarListElementInit::resolveReferences.  If the list element is resolvable
728e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  /// now, we return the resolved value, otherwise we return null.
72936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
73036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override {
73150bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper    llvm_unreachable("Illegal element reference off int");
732e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  }
733307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
73436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
735236bcf1fcd6164d624956c0858593c1a780b9a0bAaron Ballman    return BitInit::get((Value & (1ULL << Bit)) != 0);
736307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
737e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
738e62c1185bee05facc25d1d725434f517261d308bChris Lattner
73907278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// StringInit - "foo" - Represent an initialization by a string value.
74007278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
741beb31a51f67f651c5fa3c5094a78266d04a697a5David Greeneclass StringInit : public TypedInit {
742e62c1185bee05facc25d1d725434f517261d308bChris Lattner  std::string Value;
743dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
744d568b3f55294917d1cc701da14a8a7daeb6563e6Eric Christopher  explicit StringInit(const std::string &V)
745b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    : TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
746e62c1185bee05facc25d1d725434f517261d308bChris Lattner
747a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  StringInit(const StringInit &Other) LLVM_DELETED_FUNCTION;
748a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  StringInit &operator=(const StringInit &Other) LLVM_DELETED_FUNCTION;
74936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void anchor() override;
750dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
751dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
752b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
753b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_StringInit;
754b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
755ebaf92c67dac4974f98a08f8096d3eb2f4edd09dJakob Stoklund Olesen  static StringInit *get(StringRef);
756dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
7575c737ad4d669b835b8fb973a5c477a4dbb213830Chris Lattner  const std::string &getValue() const { return Value; }
7585c737ad4d669b835b8fb973a5c477a4dbb213830Chris Lattner
75936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
76005bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<StringInit *>(this));
761e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
762e62c1185bee05facc25d1d725434f517261d308bChris Lattner
76336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return "\"" + Value + "\""; }
76436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsUnquotedString() const override { return Value; }
765beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene
766beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// resolveListElementReference - This method is used to implement
767beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// VarListElementInit::resolveReferences.  If the list element is resolvable
768beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// now, we return the resolved value, otherwise we return null.
76936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
77036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override {
77150bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper    llvm_unreachable("Illegal element reference off string");
772beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  }
773307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
77436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
775307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    llvm_unreachable("Illegal bit reference off string");
776307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
777e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
778e62c1185bee05facc25d1d725434f517261d308bChris Lattner
77907278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// ListInit - [AL, AH, CL] - Represent a list of defs
78007278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
781aad4c9fc37b38cae21343173084c81d789535446David Greeneclass ListInit : public TypedInit, public FoldingSetNode {
78205bce0beee87512e52428d4b80f5a8e79a949576David Greene  std::vector<Init*> Values;
783dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
784e62c1185bee05facc25d1d725434f517261d308bChris Lattnerpublic:
78505bce0beee87512e52428d4b80f5a8e79a949576David Greene  typedef std::vector<Init*>::const_iterator const_iterator;
7865f9f9ba00b85eb19da2618f393e43a6a11b5d892David Greene
787aad4c9fc37b38cae21343173084c81d789535446David Greeneprivate:
78805bce0beee87512e52428d4b80f5a8e79a949576David Greene  explicit ListInit(ArrayRef<Init *> Range, RecTy *EltTy)
789b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    : TypedInit(IK_ListInit, ListRecTy::get(EltTy)),
790b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      Values(Range.begin(), Range.end()) {}
791e62c1185bee05facc25d1d725434f517261d308bChris Lattner
792a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  ListInit(const ListInit &Other) LLVM_DELETED_FUNCTION;
793a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  ListInit &operator=(const ListInit &Other) LLVM_DELETED_FUNCTION;
794dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
795dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
796b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
797b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_ListInit;
798b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
79905bce0beee87512e52428d4b80f5a8e79a949576David Greene  static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
800dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
801aad4c9fc37b38cae21343173084c81d789535446David Greene  void Profile(FoldingSetNodeID &ID) const;
802aad4c9fc37b38cae21343173084c81d789535446David Greene
8037cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner  unsigned getSize() const { return Values.size(); }
80405bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getElement(unsigned i) const {
8057cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    assert(i < Values.size() && "List element index out of range!");
8067cf0ce4b8d122575c3348b5fa4947014c3d8432dChris Lattner    return Values[i];
807e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
808e62c1185bee05facc25d1d725434f517261d308bChris Lattner
80950d456539dea5e61d7a1592a78f1861fb35b0063Chris Lattner  Record *getElementAsRecord(unsigned i) const;
81021870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
81136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *
81236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    convertInitListSlice(const std::vector<unsigned> &Elements) const override;
813b0fef64dc98d32b90782360aa9480417b7ca34fdChris Lattner
81436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
81505bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<ListInit *>(this));
816e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
817e62c1185bee05facc25d1d725434f517261d308bChris Lattner
8181dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// resolveReferences - This method is used by classes that refer to other
8191dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// variables which may not be defined at the time they expression is formed.
8201dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// If a value is set for the variable later, this method will be called on
8211dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// users of the value to allow the value to propagate out.
8221dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  ///
82336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
8241dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner
82536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
82682137bd061440070839f2b94c8b7c16da4f41a6dAnton Korobeynikov
82705bce0beee87512e52428d4b80f5a8e79a949576David Greene  ArrayRef<Init*> getValues() const { return Values; }
828c45a2cacd09f88b8b715fd89f5bf6c2347b2cce9David Greene
82982137bd061440070839f2b94c8b7c16da4f41a6dAnton Korobeynikov  inline const_iterator begin() const { return Values.begin(); }
83082137bd061440070839f2b94c8b7c16da4f41a6dAnton Korobeynikov  inline const_iterator end  () const { return Values.end();   }
83182137bd061440070839f2b94c8b7c16da4f41a6dAnton Korobeynikov
83282137bd061440070839f2b94c8b7c16da4f41a6dAnton Korobeynikov  inline size_t         size () const { return Values.size();  }
83382137bd061440070839f2b94c8b7c16da4f41a6dAnton Korobeynikov  inline bool           empty() const { return Values.empty(); }
834e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene
835e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  /// resolveListElementReference - This method is used to implement
836e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  /// VarListElementInit::resolveReferences.  If the list element is resolvable
837e1b469170bb3ab259fd488fb95c29efe802cdd6aDavid Greene  /// now, we return the resolved value, otherwise we return null.
83836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
83936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override;
840307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
84136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
842307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    llvm_unreachable("Illegal bit reference off list");
843307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
844e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
845e62c1185bee05facc25d1d725434f517261d308bChris Lattner
846d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene/// OpInit - Base class for operators
847d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene///
848d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greeneclass OpInit : public TypedInit {
849a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  OpInit(const OpInit &Other) LLVM_DELETED_FUNCTION;
850a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  OpInit &operator=(OpInit &Other) LLVM_DELETED_FUNCTION;
851d568b3f55294917d1cc701da14a8a7daeb6563e6Eric Christopher
852dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greeneprotected:
853b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  explicit OpInit(InitKind K, RecTy *Type) : TypedInit(K, Type) {}
854dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
855dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
856b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
857b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() >= IK_FirstOpInit &&
858b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva           I->getKind() <= IK_LastOpInit;
859b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
860d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  // Clone - Clone this operator, replacing arguments with the new list
86105bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual OpInit *clone(std::vector<Init *> &Operands) const = 0;
862d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
863a9ad04191cb56c42944b17980b8b2bb2afe11ab2Dan Gohman  virtual int getNumOperands() const = 0;
86405bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *getOperand(int i) const = 0;
865d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
866d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  // Fold - If possible, fold this to a simpler init.  Return this if not
867d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  // possible to fold.
86805bce0beee87512e52428d4b80f5a8e79a949576David Greene  virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
869d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
87036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
87105bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<OpInit *>(this));
872d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  }
87321870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
87436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
87536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override;
876307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
87736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override;
878d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene};
879d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
880d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene/// UnOpInit - !op (X) - Transform an init.
881d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene///
882e6c27de069225e1122c78385ad22a2ff656db8e6David Greeneclass UnOpInit : public OpInit {
883e6c27de069225e1122c78385ad22a2ff656db8e6David Greenepublic:
8841434f66b2e132a707e2c8ccb3350ea13fb5aa051David Greene  enum UnaryOp { CAST, HEAD, TAIL, EMPTY };
885dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
886e6c27de069225e1122c78385ad22a2ff656db8e6David Greeneprivate:
887e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  UnaryOp Opc;
88805bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *LHS;
889dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
89005bce0beee87512e52428d4b80f5a8e79a949576David Greene  UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
891b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    : OpInit(IK_UnOpInit, Type), Opc(opc), LHS(lhs) {}
892dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
893a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  UnOpInit(const UnOpInit &Other) LLVM_DELETED_FUNCTION;
894a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  UnOpInit &operator=(const UnOpInit &Other) LLVM_DELETED_FUNCTION;
895dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
896e6c27de069225e1122c78385ad22a2ff656db8e6David Greenepublic:
897b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
898b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_UnOpInit;
899b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
90005bce0beee87512e52428d4b80f5a8e79a949576David Greene  static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
901d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
902e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  // Clone - Clone this operator, replacing arguments with the new list
90336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  OpInit *clone(std::vector<Init *> &Operands) const override {
904aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky    assert(Operands.size() == 1 &&
905aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky           "Wrong number of operands for unary operation");
906dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene    return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
907e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  }
908d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
90936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  int getNumOperands() const override { return 1; }
91036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getOperand(int i) const override {
911e6c27de069225e1122c78385ad22a2ff656db8e6David Greene    assert(i == 0 && "Invalid operand id for unary operator");
912e6c27de069225e1122c78385ad22a2ff656db8e6David Greene    return getOperand();
913e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  }
91421870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
915e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  UnaryOp getOpcode() const { return Opc; }
91605bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getOperand() const { return LHS; }
917d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
918e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  // Fold - If possible, fold this to a simpler init.  Return this if not
919e6c27de069225e1122c78385ad22a2ff656db8e6David Greene  // possible to fold.
92036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
921d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
92236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
92321870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
92436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
925e6c27de069225e1122c78385ad22a2ff656db8e6David Greene};
926e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene
927e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene/// BinOpInit - !op (X, Y) - Combine two inits.
928e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene///
929d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greeneclass BinOpInit : public OpInit {
930e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greenepublic:
931dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  enum BinaryOp { ADD, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ };
932dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
933e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greeneprivate:
934e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene  BinaryOp Opc;
93505bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *LHS, *RHS;
936dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
93705bce0beee87512e52428d4b80f5a8e79a949576David Greene  BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
938b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      OpInit(IK_BinOpInit, Type), Opc(opc), LHS(lhs), RHS(rhs) {}
939dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
940a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  BinOpInit(const BinOpInit &Other) LLVM_DELETED_FUNCTION;
941a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  BinOpInit &operator=(const BinOpInit &Other) LLVM_DELETED_FUNCTION;
942dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
943dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
944b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
945b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_BinOpInit;
946b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
94705bce0beee87512e52428d4b80f5a8e79a949576David Greene  static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
94805bce0beee87512e52428d4b80f5a8e79a949576David Greene                        RecTy *Type);
94921870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
950d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  // Clone - Clone this operator, replacing arguments with the new list
95136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  OpInit *clone(std::vector<Init *> &Operands) const override {
952aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky    assert(Operands.size() == 2 &&
953aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky           "Wrong number of operands for binary operation");
954dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene    return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
955d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  }
956d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
95736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  int getNumOperands() const override { return 2; }
95836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getOperand(int i) const override {
959aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky    assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
960d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene    if (i == 0) {
961d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene      return getLHS();
96221870411d9c1807526b613d04c2ebae5a43c263bBob Wilson    } else {
963d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene      return getRHS();
964d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene    }
965d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene  }
966d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
967e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene  BinaryOp getOpcode() const { return Opc; }
96805bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getLHS() const { return LHS; }
96905bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getRHS() const { return RHS; }
970e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene
971e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene  // Fold - If possible, fold this to a simpler init.  Return this if not
972e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene  // possible to fold.
97336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
974e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene
97536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
97621870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
97736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
978e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene};
979e8cf21e8e3db64dd49777d6bf6c867d47e9f5407David Greene
980d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene/// TernOpInit - !op (X, Y, Z) - Combine two inits.
981d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene///
9824afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greeneclass TernOpInit : public OpInit {
9834afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greenepublic:
984ffc0ab6037aa45bc22f57433148e5f586843b3a7David Greene  enum TernaryOp { SUBST, FOREACH, IF };
985dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
9864afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greeneprivate:
9874afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  TernaryOp Opc;
98805bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *LHS, *MHS, *RHS;
989dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
99005bce0beee87512e52428d4b80f5a8e79a949576David Greene  TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
991f37dd02f7743ebd2424480361f5a7db510495c4fDavid Greene             RecTy *Type) :
992b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      OpInit(IK_TernOpInit, Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
993dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
994a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  TernOpInit(const TernOpInit &Other) LLVM_DELETED_FUNCTION;
995a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  TernOpInit &operator=(const TernOpInit &Other) LLVM_DELETED_FUNCTION;
996dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
997dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
998b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
999b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_TernOpInit;
1000b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
100105bce0beee87512e52428d4b80f5a8e79a949576David Greene  static TernOpInit *get(TernaryOp opc, Init *lhs,
100205bce0beee87512e52428d4b80f5a8e79a949576David Greene                         Init *mhs, Init *rhs,
100305bce0beee87512e52428d4b80f5a8e79a949576David Greene                         RecTy *Type);
100421870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
10054afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  // Clone - Clone this operator, replacing arguments with the new list
100636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  OpInit *clone(std::vector<Init *> &Operands) const override {
1007aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky    assert(Operands.size() == 3 &&
1008aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky           "Wrong number of operands for ternary operation");
1009dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene    return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
1010dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene                           getType());
10114afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  }
10124afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene
101336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  int getNumOperands() const override { return 3; }
101436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getOperand(int i) const override {
1015aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky    assert((i == 0 || i == 1 || i == 2) &&
1016aa0b3df5a03304cf6fbc27d95a0d95717a3a61d0Nick Lewycky           "Invalid operand id for ternary operator");
10174afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene    if (i == 0) {
10184afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene      return getLHS();
101921870411d9c1807526b613d04c2ebae5a43c263bBob Wilson    } else if (i == 1) {
10204afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene      return getMHS();
102121870411d9c1807526b613d04c2ebae5a43c263bBob Wilson    } else {
10224afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene      return getRHS();
10234afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene    }
10244afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  }
10254afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene
10264afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  TernaryOp getOpcode() const { return Opc; }
102705bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getLHS() const { return LHS; }
102805bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getMHS() const { return MHS; }
102905bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *getRHS() const { return RHS; }
10304afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene
10314afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  // Fold - If possible, fold this to a simpler init.  Return this if not
10324afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene  // possible to fold.
103336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
103421870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
103536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isComplete() const override { return false; }
1036548f5a0b751aafba88473e4863c2baf7741b56a5Bill Wendling
103736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
103821870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
103936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
10404afc509b7ffe2c4ea234dfd7af5105feb21685d9David Greene};
1041d418c1b768b5ff26afe05a5ce84d920bbbc99583David Greene
104207278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// VarInit - 'Opcode' - Represent a reference to an entire variable object.
104307278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
10447331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattnerclass VarInit : public TypedInit {
1045ee6dca17252de152720655282fb4b74b76fb2fe9David Greene  Init *VarName;
1046dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1047d568b3f55294917d1cc701da14a8a7daeb6563e6Eric Christopher  explicit VarInit(const std::string &VN, RecTy *T)
1048b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      : TypedInit(IK_VarInit, T), VarName(StringInit::get(VN)) {}
1049ee6dca17252de152720655282fb4b74b76fb2fe9David Greene  explicit VarInit(Init *VN, RecTy *T)
1050b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      : TypedInit(IK_VarInit, T), VarName(VN) {}
1051dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1052a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  VarInit(const VarInit &Other) LLVM_DELETED_FUNCTION;
1053a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  VarInit &operator=(const VarInit &Other) LLVM_DELETED_FUNCTION;
1054dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1055dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
1056b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
1057b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_VarInit;
1058b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
105905bce0beee87512e52428d4b80f5a8e79a949576David Greene  static VarInit *get(const std::string &VN, RecTy *T);
106005bce0beee87512e52428d4b80f5a8e79a949576David Greene  static VarInit *get(Init *VN, RecTy *T);
10613da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
106236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
106305bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<VarInit *>(this));
1064e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
1065e62c1185bee05facc25d1d725434f517261d308bChris Lattner
1066ee6dca17252de152720655282fb4b74b76fb2fe9David Greene  const std::string &getName() const;
1067ee6dca17252de152720655282fb4b74b76fb2fe9David Greene  Init *getNameInit() const { return VarName; }
1068ee6dca17252de152720655282fb4b74b76fb2fe9David Greene  std::string getNameInitAsString() const {
1069ee6dca17252de152720655282fb4b74b76fb2fe9David Greene    return getNameInit()->getAsUnquotedString();
1070ee6dca17252de152720655282fb4b74b76fb2fe9David Greene  }
1071e62c1185bee05facc25d1d725434f517261d308bChris Lattner
107236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
107336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override;
10747331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner
107536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  RecTy *getFieldType(const std::string &FieldName) const override;
107636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getFieldInit(Record &R, const RecordVal *RV,
107736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                     const std::string &FieldName) const override;
10789b929aa7495ee0b5d389370baeb332456632b2feChris Lattner
10799b929aa7495ee0b5d389370baeb332456632b2feChris Lattner  /// resolveReferences - This method is used by classes that refer to other
10809b929aa7495ee0b5d389370baeb332456632b2feChris Lattner  /// variables which may not be defined at the time they expression is formed.
10819b929aa7495ee0b5d389370baeb332456632b2feChris Lattner  /// If a value is set for the variable later, this method will be called on
10829b929aa7495ee0b5d389370baeb332456632b2feChris Lattner  /// users of the value to allow the value to propagate out.
10839b929aa7495ee0b5d389370baeb332456632b2feChris Lattner  ///
108436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
10853da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
108636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override;
1087307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
108836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override { return getName(); }
1089e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
1090e62c1185bee05facc25d1d725434f517261d308bChris Lattner
10917331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner/// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
109207278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
1093e62c1185bee05facc25d1d725434f517261d308bChris Lattnerclass VarBitInit : public Init {
109405bce0beee87512e52428d4b80f5a8e79a949576David Greene  TypedInit *TI;
1095e62c1185bee05facc25d1d725434f517261d308bChris Lattner  unsigned Bit;
1096dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1097b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  VarBitInit(TypedInit *T, unsigned B) : Init(IK_VarBitInit), TI(T), Bit(B) {
1098307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    assert(T->getType() &&
109963554988a94b8a4bcf3de77659a0b27c07a0975dSean Silva           (isa<IntRecTy>(T->getType()) ||
110063554988a94b8a4bcf3de77659a0b27c07a0975dSean Silva            (isa<BitsRecTy>(T->getType()) &&
110163554988a94b8a4bcf3de77659a0b27c07a0975dSean Silva             cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
11027331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner           "Illegal VarBitInit expression!");
11037331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner  }
1104e62c1185bee05facc25d1d725434f517261d308bChris Lattner
1105a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  VarBitInit(const VarBitInit &Other) LLVM_DELETED_FUNCTION;
1106a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  VarBitInit &operator=(const VarBitInit &Other) LLVM_DELETED_FUNCTION;
1107dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1108dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
1109b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
1110b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_VarBitInit;
1111b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
111205bce0beee87512e52428d4b80f5a8e79a949576David Greene  static VarBitInit *get(TypedInit *T, unsigned B);
1113dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
111436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
111505bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<VarBitInit *>(this));
1116e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
1117e62c1185bee05facc25d1d725434f517261d308bChris Lattner
111836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBitVar() const override { return TI; }
111936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned getBitNum() const override { return Bit; }
11203da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
112136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
112236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
1123307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
112436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned B) const override {
1125307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    assert(B < 1 && "Bit index out of range!");
1126307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao    return const_cast<VarBitInit*>(this);
1127307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao  }
1128e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
1129e62c1185bee05facc25d1d725434f517261d308bChris Lattner
11303da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman/// VarListElementInit - List[4] - Represent access to one element of a var or
11311dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner/// field.
11321dba7abdd77e19c230f0426825a5ae4879471dccChris Lattnerclass VarListElementInit : public TypedInit {
113305bce0beee87512e52428d4b80f5a8e79a949576David Greene  TypedInit *TI;
11341dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  unsigned Element;
1135dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
113605bce0beee87512e52428d4b80f5a8e79a949576David Greene  VarListElementInit(TypedInit *T, unsigned E)
1137b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      : TypedInit(IK_VarListElementInit,
1138b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva                  cast<ListRecTy>(T->getType())->getElementType()),
1139b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva        TI(T), Element(E) {
114063554988a94b8a4bcf3de77659a0b27c07a0975dSean Silva    assert(T->getType() && isa<ListRecTy>(T->getType()) &&
11411dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner           "Illegal VarBitInit expression!");
11421dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  }
11431dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner
1144a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  VarListElementInit(const VarListElementInit &Other) LLVM_DELETED_FUNCTION;
1145a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  void operator=(const VarListElementInit &Other) LLVM_DELETED_FUNCTION;
1146dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1147dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
1148b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
1149b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_VarListElementInit;
1150b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
115105bce0beee87512e52428d4b80f5a8e79a949576David Greene  static VarListElementInit *get(TypedInit *T, unsigned E);
1152dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
115336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
115405bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<VarListElementInit *>(this));
11551dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  }
11561dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner
115705bce0beee87512e52428d4b80f5a8e79a949576David Greene  TypedInit *getVariable() const { return TI; }
11581dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  unsigned getElementNum() const { return Element; }
11591dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner
11601dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// resolveListElementReference - This method is used to implement
11611dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// VarListElementInit::resolveReferences.  If the list element is resolvable
11621dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner  /// now, we return the resolved value, otherwise we return null.
116336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
116436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override;
11651dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner
116636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
116736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
1168307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
116936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override;
11701dba7abdd77e19c230f0426825a5ae4879471dccChris Lattner};
117107278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner
117207278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner/// DefInit - AL - Represent a reference to a 'def' in the description
117307278e48dc27d8ac64b5ff7ed6361536c2f38ea1Chris Lattner///
1174beb31a51f67f651c5fa3c5094a78266d04a697a5David Greeneclass DefInit : public TypedInit {
1175e62c1185bee05facc25d1d725434f517261d308bChris Lattner  Record *Def;
1176dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1177b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  DefInit(Record *D, RecordRecTy *T) : TypedInit(IK_DefInit, T), Def(D) {}
117877f8274c7d4bfb5e2a449eb49dc78dcae37e5457Jakob Stoklund Olesen  friend class Record;
1179dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1180a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  DefInit(const DefInit &Other) LLVM_DELETED_FUNCTION;
1181a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  DefInit &operator=(const DefInit &Other) LLVM_DELETED_FUNCTION;
1182dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1183e62c1185bee05facc25d1d725434f517261d308bChris Lattnerpublic:
1184b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
1185b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_DefInit;
1186b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
118705bce0beee87512e52428d4b80f5a8e79a949576David Greene  static DefInit *get(Record*);
11883da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
118936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
119005bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<DefInit *>(this));
1191e62c1185bee05facc25d1d725434f517261d308bChris Lattner  }
1192e62c1185bee05facc25d1d725434f517261d308bChris Lattner
1193e62c1185bee05facc25d1d725434f517261d308bChris Lattner  Record *getDef() const { return Def; }
1194e62c1185bee05facc25d1d725434f517261d308bChris Lattner
119505bce0beee87512e52428d4b80f5a8e79a949576David Greene  //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
1196b1ed0fc6308885c5887ed0474e8a4fbf63a39b45Chris Lattner
119736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  RecTy *getFieldType(const std::string &FieldName) const override;
119836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getFieldInit(Record &R, const RecordVal *RV,
119936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                     const std::string &FieldName) const override;
12003da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
120136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override;
1202beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene
120336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override {
120450bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper    llvm_unreachable("Illegal bit reference off def");
1205beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  }
1206beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene
1207beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// resolveListElementReference - This method is used to implement
1208beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// VarListElementInit::resolveReferences.  If the list element is resolvable
1209beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  /// now, we return the resolved value, otherwise we return null.
121036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
121136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override {
121250bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper    llvm_unreachable("Illegal element reference off def");
1213beb31a51f67f651c5fa3c5094a78266d04a697a5David Greene  }
1214e62c1185bee05facc25d1d725434f517261d308bChris Lattner};
1215e62c1185bee05facc25d1d725434f517261d308bChris Lattner
1216a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner/// FieldInit - X.Y - Represent a reference to a subfield of a variable
1217a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner///
12187331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattnerclass FieldInit : public TypedInit {
121905bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *Rec;                // Record we are referring to
1220a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  std::string FieldName;    // Field we are accessing
1221dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
122205bce0beee87512e52428d4b80f5a8e79a949576David Greene  FieldInit(Init *R, const std::string &FN)
1223b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
12247331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner    assert(getType() && "FieldInit with non-record type!");
1225a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  }
1226a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner
1227a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  FieldInit(const FieldInit &Other) LLVM_DELETED_FUNCTION;
1228a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  FieldInit &operator=(const FieldInit &Other) LLVM_DELETED_FUNCTION;
1229dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1230dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
1231b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
1232b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_FieldInit;
1233b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
123405bce0beee87512e52428d4b80f5a8e79a949576David Greene  static FieldInit *get(Init *R, const std::string &FN);
123505bce0beee87512e52428d4b80f5a8e79a949576David Greene  static FieldInit *get(Init *R, const Init *FN);
1236dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
123736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *convertInitializerTo(RecTy *Ty) const override {
123805bce0beee87512e52428d4b80f5a8e79a949576David Greene    return Ty->convertValue(const_cast<FieldInit *>(this));
1239a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  }
1240a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner
124136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *getBit(unsigned Bit) const override;
1242307525cd24c3b9c081ddb3c34a3418f2875cd556Michael Liao
124336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveListElementReference(Record &R, const RecordVal *RV,
124436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    unsigned Elt) const override;
12457331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3Chris Lattner
124636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
124724151a6888c752ff1d7fc80b500f5a836c9ac528Chris Lattner
124836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::string getAsString() const override {
12493aba4d39fd101238ac06871895c28f26736d80cbChris Lattner    return Rec->getAsString() + "." + FieldName;
1250a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner  }
1251a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner};
1252a1651900e1772b05afd2280308e9acc5a58cefb8Chris Lattner
12538c06318821e4febb3a7f1afbab72dae362f1bf5fChris Lattner/// DagInit - (v a, b) - Represent a DAG tree value.  DAG inits are required
12548c06318821e4febb3a7f1afbab72dae362f1bf5fChris Lattner/// to have at least one value then a (possibly empty) list of arguments.  Each
12558c06318821e4febb3a7f1afbab72dae362f1bf5fChris Lattner/// argument can have a name associated with it.
12568e9a9774eb12b5242f74b8ac5b20e0a938ec9c53Chris Lattner///
125778621a851ae84520de7d24a6d61e1dcf25749712David Greeneclass DagInit : public TypedInit, public FoldingSetNode {
125805bce0beee87512e52428d4b80f5a8e79a949576David Greene  Init *Val;
12597cee81703de8333d457ec9e560b0537b71df5a48Nate Begeman  std::string ValName;
126005bce0beee87512e52428d4b80f5a8e79a949576David Greene  std::vector<Init*> Args;
126191290d7e9a743de363049e705a8303ae1f3a6e68Chris Lattner  std::vector<std::string> ArgNames;
1262dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
126305bce0beee87512e52428d4b80f5a8e79a949576David Greene  DagInit(Init *V, const std::string &VN,
126405bce0beee87512e52428d4b80f5a8e79a949576David Greene          ArrayRef<Init *> ArgRange,
126578621a851ae84520de7d24a6d61e1dcf25749712David Greene          ArrayRef<std::string> NameRange)
1266b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva      : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
126778621a851ae84520de7d24a6d61e1dcf25749712David Greene          Args(ArgRange.begin(), ArgRange.end()),
126878621a851ae84520de7d24a6d61e1dcf25749712David Greene          ArgNames(NameRange.begin(), NameRange.end()) {}
126921870411d9c1807526b613d04c2ebae5a43c263bBob Wilson
1270a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  DagInit(const DagInit &Other) LLVM_DELETED_FUNCTION;
1271a558d91cedd4fd5c2d3327a8a18e12c35530efa8Craig Topper  DagInit &operator=(const DagInit &Other) LLVM_DELETED_FUNCTION;
1272dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greene
1273dcd35c797d458d8b1dbc36cf7f1504166d5b2f16David Greenepublic:
1274b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  static bool classof(const Init *I) {
1275b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva    return I->getKind() == IK_DagInit;
1276b0c6fa3b4b74d9cd03beb5a4cb9702abc85ac169Sean Silva  }
127705bce0beee87512e52428d4b80f5a8e79a949576David Greene  static DagInit *get(Init *V, const std::string &VN,
127805bce0beee87512e52428d4b80f5a8e79a949576David Greene                      ArrayRef<Init *> ArgRange,
127905bce0beee87512e52428d4b80f5a8e79a949576David Greene                      ArrayRef<std::string> NameRange);
128005bce0beee87512e52428d4b80f5a8e79a949576David Greene  static DagInit *get(Init *V, const std::string &VN,
128105bce0beee87512e52428d4b80f5a8e79a949576David Greene                      const std::vector<
1282