LLVM API Documentation

Record.h
Go to the documentation of this file.
00001 //===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the main TableGen data structures, including the TableGen
00011 // types, values, and high-level data structures.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_TABLEGEN_RECORD_H
00016 #define LLVM_TABLEGEN_RECORD_H
00017 
00018 #include "llvm/ADT/ArrayRef.h"
00019 #include "llvm/ADT/FoldingSet.h"
00020 #include "llvm/Support/Allocator.h"
00021 #include "llvm/Support/Casting.h"
00022 #include "llvm/Support/DataTypes.h"
00023 #include "llvm/Support/ErrorHandling.h"
00024 #include "llvm/Support/SourceMgr.h"
00025 #include "llvm/Support/raw_ostream.h"
00026 #include <map>
00027 
00028 namespace llvm {
00029 class raw_ostream;
00030 
00031 // RecTy subclasses.
00032 class BitRecTy;
00033 class BitsRecTy;
00034 class IntRecTy;
00035 class StringRecTy;
00036 class ListRecTy;
00037 class DagRecTy;
00038 class RecordRecTy;
00039 
00040 // Init subclasses.
00041 class Init;
00042 class UnsetInit;
00043 class BitInit;
00044 class BitsInit;
00045 class IntInit;
00046 class StringInit;
00047 class ListInit;
00048 class UnOpInit;
00049 class BinOpInit;
00050 class TernOpInit;
00051 class DefInit;
00052 class DagInit;
00053 class TypedInit;
00054 class VarInit;
00055 class FieldInit;
00056 class VarBitInit;
00057 class VarListElementInit;
00058 
00059 // Other classes.
00060 class Record;
00061 class RecordVal;
00062 struct MultiClass;
00063 class RecordKeeper;
00064 
00065 //===----------------------------------------------------------------------===//
00066 //  Type Classes
00067 //===----------------------------------------------------------------------===//
00068 
00069 class RecTy {
00070 public:
00071   /// \brief Subclass discriminator (for dyn_cast<> et al.)
00072   enum RecTyKind {
00073     BitRecTyKind,
00074     BitsRecTyKind,
00075     IntRecTyKind,
00076     StringRecTyKind,
00077     ListRecTyKind,
00078     DagRecTyKind,
00079     RecordRecTyKind
00080   };
00081 
00082 private:
00083   RecTyKind Kind;
00084   ListRecTy *ListTy;
00085   virtual void anchor();
00086 
00087 public:
00088   RecTyKind getRecTyKind() const { return Kind; }
00089 
00090   RecTy(RecTyKind K) : Kind(K), ListTy(nullptr) {}
00091   virtual ~RecTy() {}
00092 
00093   virtual std::string getAsString() const = 0;
00094   void print(raw_ostream &OS) const { OS << getAsString(); }
00095   void dump() const;
00096 
00097   /// typeIsConvertibleTo - Return true if all values of 'this' type can be
00098   /// converted to the specified type.
00099   virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
00100 
00101   /// getListTy - Returns the type representing list<this>.
00102   ListRecTy *getListTy();
00103 
00104 public:   // These methods should only be called from subclasses of Init
00105   virtual Init *convertValue( UnsetInit *UI) { return nullptr; }
00106   virtual Init *convertValue(   BitInit *BI) { return nullptr; }
00107   virtual Init *convertValue(  BitsInit *BI) { return nullptr; }
00108   virtual Init *convertValue(   IntInit *II) { return nullptr; }
00109   virtual Init *convertValue(StringInit *SI) { return nullptr; }
00110   virtual Init *convertValue(  ListInit *LI) { return nullptr; }
00111   virtual Init *convertValue( UnOpInit *UI) {
00112     return convertValue((TypedInit*)UI);
00113   }
00114   virtual Init *convertValue( BinOpInit *UI) {
00115     return convertValue((TypedInit*)UI);
00116   }
00117   virtual Init *convertValue( TernOpInit *UI) {
00118     return convertValue((TypedInit*)UI);
00119   }
00120   virtual Init *convertValue(VarBitInit *VB) { return nullptr; }
00121   virtual Init *convertValue(   DefInit *DI) { return nullptr; }
00122   virtual Init *convertValue(   DagInit *DI) { return nullptr; }
00123   virtual Init *convertValue( TypedInit *TI) { return nullptr; }
00124   virtual Init *convertValue(   VarInit *VI) {
00125     return convertValue((TypedInit*)VI);
00126   }
00127   virtual Init *convertValue( FieldInit *FI) {
00128     return convertValue((TypedInit*)FI);
00129   }
00130 
00131 public:
00132   virtual bool baseClassOf(const RecTy*) const;
00133 };
00134 
00135 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
00136   Ty.print(OS);
00137   return OS;
00138 }
00139 
00140 /// BitRecTy - 'bit' - Represent a single bit
00141 ///
00142 class BitRecTy : public RecTy {
00143   static BitRecTy Shared;
00144   BitRecTy() : RecTy(BitRecTyKind) {}
00145 
00146 public:
00147   static bool classof(const RecTy *RT) {
00148     return RT->getRecTyKind() == BitRecTyKind;
00149   }
00150 
00151   static BitRecTy *get() { return &Shared; }
00152 
00153   Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
00154   Init *convertValue(   BitInit *BI) override { return (Init*)BI; }
00155   Init *convertValue(  BitsInit *BI) override;
00156   Init *convertValue(   IntInit *II) override;
00157   Init *convertValue(StringInit *SI) override { return nullptr; }
00158   Init *convertValue(  ListInit *LI) override { return nullptr; }
00159   Init *convertValue(VarBitInit *VB) override { return (Init*)VB; }
00160   Init *convertValue(   DefInit *DI) override { return nullptr; }
00161   Init *convertValue(   DagInit *DI) override { return nullptr; }
00162   Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
00163   Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
00164   Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
00165   Init *convertValue( TypedInit *TI) override;
00166   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00167   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00168 
00169   std::string getAsString() const override { return "bit"; }
00170 
00171   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00172     return RHS->baseClassOf(this);
00173   }
00174   bool baseClassOf(const RecTy*) const override;
00175 };
00176 
00177 /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
00178 ///
00179 class BitsRecTy : public RecTy {
00180   unsigned Size;
00181   explicit BitsRecTy(unsigned Sz) : RecTy(BitsRecTyKind), Size(Sz) {}
00182 
00183 public:
00184   static bool classof(const RecTy *RT) {
00185     return RT->getRecTyKind() == BitsRecTyKind;
00186   }
00187 
00188   static BitsRecTy *get(unsigned Sz);
00189 
00190   unsigned getNumBits() const { return Size; }
00191 
00192   Init *convertValue( UnsetInit *UI) override;
00193   Init *convertValue(   BitInit *UI) override;
00194   Init *convertValue(  BitsInit *BI) override;
00195   Init *convertValue(   IntInit *II) override;
00196   Init *convertValue(StringInit *SI) override { return nullptr; }
00197   Init *convertValue(  ListInit *LI) override { return nullptr; }
00198   Init *convertValue(VarBitInit *VB) override { return nullptr; }
00199   Init *convertValue(   DefInit *DI) override { return nullptr; }
00200   Init *convertValue(   DagInit *DI) override { return nullptr; }
00201   Init *convertValue(  UnOpInit *UI) override { return RecTy::convertValue(UI);}
00202   Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
00203   Init *convertValue(TernOpInit *UI) override { return RecTy::convertValue(UI);}
00204   Init *convertValue( TypedInit *TI) override;
00205   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00206   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00207 
00208   std::string getAsString() const override;
00209 
00210   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00211     return RHS->baseClassOf(this);
00212   }
00213   bool baseClassOf(const RecTy*) const override;
00214 };
00215 
00216 /// IntRecTy - 'int' - Represent an integer value of no particular size
00217 ///
00218 class IntRecTy : public RecTy {
00219   static IntRecTy Shared;
00220   IntRecTy() : RecTy(IntRecTyKind) {}
00221 
00222 public:
00223   static bool classof(const RecTy *RT) {
00224     return RT->getRecTyKind() == IntRecTyKind;
00225   }
00226 
00227   static IntRecTy *get() { return &Shared; }
00228 
00229   Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
00230   Init *convertValue(   BitInit *BI) override;
00231   Init *convertValue(  BitsInit *BI) override;
00232   Init *convertValue(   IntInit *II) override { return (Init*)II; }
00233   Init *convertValue(StringInit *SI) override { return nullptr; }
00234   Init *convertValue(  ListInit *LI) override { return nullptr; }
00235   Init *convertValue(VarBitInit *VB) override { return nullptr; }
00236   Init *convertValue(   DefInit *DI) override { return nullptr; }
00237   Init *convertValue(   DagInit *DI) override { return nullptr; }
00238   Init *convertValue( UnOpInit *UI)  override { return RecTy::convertValue(UI);}
00239   Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
00240   Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
00241   Init *convertValue( TypedInit *TI) override;
00242   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00243   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00244 
00245   std::string getAsString() const override { return "int"; }
00246 
00247   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00248     return RHS->baseClassOf(this);
00249   }
00250 
00251   bool baseClassOf(const RecTy*) const override;
00252 };
00253 
00254 /// StringRecTy - 'string' - Represent an string value
00255 ///
00256 class StringRecTy : public RecTy {
00257   static StringRecTy Shared;
00258   StringRecTy() : RecTy(StringRecTyKind) {}
00259 
00260 public:
00261   static bool classof(const RecTy *RT) {
00262     return RT->getRecTyKind() == StringRecTyKind;
00263   }
00264 
00265   static StringRecTy *get() { return &Shared; }
00266 
00267   Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
00268   Init *convertValue(   BitInit *BI) override { return nullptr; }
00269   Init *convertValue(  BitsInit *BI) override { return nullptr; }
00270   Init *convertValue(   IntInit *II) override { return nullptr; }
00271   Init *convertValue(StringInit *SI) override { return (Init*)SI; }
00272   Init *convertValue(  ListInit *LI) override { return nullptr; }
00273   Init *convertValue( UnOpInit *BO) override;
00274   Init *convertValue( BinOpInit *BO) override;
00275   Init *convertValue( TernOpInit *BO) override {return RecTy::convertValue(BO);}
00276 
00277   Init *convertValue(VarBitInit *VB) override { return nullptr; }
00278   Init *convertValue(   DefInit *DI) override { return nullptr; }
00279   Init *convertValue(   DagInit *DI) override { return nullptr; }
00280   Init *convertValue( TypedInit *TI) override;
00281   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00282   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00283 
00284   std::string getAsString() const override { return "string"; }
00285 
00286   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00287     return RHS->baseClassOf(this);
00288   }
00289 };
00290 
00291 /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
00292 /// the specified type.
00293 ///
00294 class ListRecTy : public RecTy {
00295   RecTy *Ty;
00296   explicit ListRecTy(RecTy *T) : RecTy(ListRecTyKind), Ty(T) {}
00297   friend ListRecTy *RecTy::getListTy();
00298 
00299 public:
00300   static bool classof(const RecTy *RT) {
00301     return RT->getRecTyKind() == ListRecTyKind;
00302   }
00303 
00304   static ListRecTy *get(RecTy *T) { return T->getListTy(); }
00305   RecTy *getElementType() const { return Ty; }
00306 
00307   Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
00308   Init *convertValue(   BitInit *BI) override { return nullptr; }
00309   Init *convertValue(  BitsInit *BI) override { return nullptr; }
00310   Init *convertValue(   IntInit *II) override { return nullptr; }
00311   Init *convertValue(StringInit *SI) override { return nullptr; }
00312   Init *convertValue(  ListInit *LI) override;
00313   Init *convertValue(VarBitInit *VB) override { return nullptr; }
00314   Init *convertValue(   DefInit *DI) override { return nullptr; }
00315   Init *convertValue(   DagInit *DI) override { return nullptr; }
00316   Init *convertValue(  UnOpInit *UI) override { return RecTy::convertValue(UI);}
00317   Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
00318   Init *convertValue(TernOpInit *UI) override { return RecTy::convertValue(UI);}
00319   Init *convertValue( TypedInit *TI) override;
00320   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00321   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00322 
00323   std::string getAsString() const override;
00324 
00325   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00326     return RHS->baseClassOf(this);
00327   }
00328 
00329   bool baseClassOf(const RecTy*) const override;
00330 };
00331 
00332 /// DagRecTy - 'dag' - Represent a dag fragment
00333 ///
00334 class DagRecTy : public RecTy {
00335   static DagRecTy Shared;
00336   DagRecTy() : RecTy(DagRecTyKind) {}
00337 
00338 public:
00339   static bool classof(const RecTy *RT) {
00340     return RT->getRecTyKind() == DagRecTyKind;
00341   }
00342 
00343   static DagRecTy *get() { return &Shared; }
00344 
00345   Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
00346   Init *convertValue(   BitInit *BI) override { return nullptr; }
00347   Init *convertValue(  BitsInit *BI) override { return nullptr; }
00348   Init *convertValue(   IntInit *II) override { return nullptr; }
00349   Init *convertValue(StringInit *SI) override { return nullptr; }
00350   Init *convertValue(  ListInit *LI) override { return nullptr; }
00351   Init *convertValue(VarBitInit *VB) override { return nullptr; }
00352   Init *convertValue(   DefInit *DI) override { return nullptr; }
00353   Init *convertValue( UnOpInit *BO) override;
00354   Init *convertValue( BinOpInit *BO) override;
00355   Init *convertValue( TernOpInit *BO) override {return RecTy::convertValue(BO);}
00356   Init *convertValue(   DagInit *CI) override { return (Init*)CI; }
00357   Init *convertValue( TypedInit *TI) override;
00358   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00359   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00360 
00361   std::string getAsString() const override { return "dag"; }
00362 
00363   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00364     return RHS->baseClassOf(this);
00365   }
00366 };
00367 
00368 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
00369 /// (R32 X = EAX).
00370 ///
00371 class RecordRecTy : public RecTy {
00372   Record *Rec;
00373   explicit RecordRecTy(Record *R) : RecTy(RecordRecTyKind), Rec(R) {}
00374   friend class Record;
00375 
00376 public:
00377   static bool classof(const RecTy *RT) {
00378     return RT->getRecTyKind() == RecordRecTyKind;
00379   }
00380 
00381   static RecordRecTy *get(Record *R);
00382 
00383   Record *getRecord() const { return Rec; }
00384 
00385   Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
00386   Init *convertValue(   BitInit *BI) override { return nullptr; }
00387   Init *convertValue(  BitsInit *BI) override { return nullptr; }
00388   Init *convertValue(   IntInit *II) override { return nullptr; }
00389   Init *convertValue(StringInit *SI) override { return nullptr; }
00390   Init *convertValue(  ListInit *LI) override { return nullptr; }
00391   Init *convertValue(VarBitInit *VB) override { return nullptr; }
00392   Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
00393   Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
00394   Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
00395   Init *convertValue(   DefInit *DI) override;
00396   Init *convertValue(   DagInit *DI) override { return nullptr; }
00397   Init *convertValue( TypedInit *VI) override;
00398   Init *convertValue(   VarInit *VI) override { return RecTy::convertValue(VI);}
00399   Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
00400 
00401   std::string getAsString() const override;
00402 
00403   bool typeIsConvertibleTo(const RecTy *RHS) const override {
00404     return RHS->baseClassOf(this);
00405   }
00406   bool baseClassOf(const RecTy*) const override;
00407 };
00408 
00409 /// resolveTypes - Find a common type that T1 and T2 convert to.
00410 /// Return 0 if no such type exists.
00411 ///
00412 RecTy *resolveTypes(RecTy *T1, RecTy *T2);
00413 
00414 //===----------------------------------------------------------------------===//
00415 //  Initializer Classes
00416 //===----------------------------------------------------------------------===//
00417 
00418 class Init {
00419 protected:
00420   /// \brief Discriminator enum (for isa<>, dyn_cast<>, et al.)
00421   ///
00422   /// This enum is laid out by a preorder traversal of the inheritance
00423   /// hierarchy, and does not contain an entry for abstract classes, as per
00424   /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
00425   ///
00426   /// We also explicitly include "first" and "last" values for each
00427   /// interior node of the inheritance tree, to make it easier to read the
00428   /// corresponding classof().
00429   ///
00430   /// We could pack these a bit tighter by not having the IK_FirstXXXInit
00431   /// and IK_LastXXXInit be their own values, but that would degrade
00432   /// readability for really no benefit.
00433   enum InitKind {
00434     IK_BitInit,
00435     IK_FirstTypedInit,
00436     IK_BitsInit,
00437     IK_DagInit,
00438     IK_DefInit,
00439     IK_FieldInit,
00440     IK_IntInit,
00441     IK_ListInit,
00442     IK_FirstOpInit,
00443     IK_BinOpInit,
00444     IK_TernOpInit,
00445     IK_UnOpInit,
00446     IK_LastOpInit,
00447     IK_StringInit,
00448     IK_VarInit,
00449     IK_VarListElementInit,
00450     IK_LastTypedInit,
00451     IK_UnsetInit,
00452     IK_VarBitInit
00453   };
00454 
00455 private:
00456   const InitKind Kind;
00457   Init(const Init &) LLVM_DELETED_FUNCTION;
00458   Init &operator=(const Init &) LLVM_DELETED_FUNCTION;
00459   virtual void anchor();
00460 
00461 public:
00462   InitKind getKind() const { return Kind; }
00463 
00464 protected:
00465   explicit Init(InitKind K) : Kind(K) {}
00466 
00467 public:
00468   virtual ~Init() {}
00469 
00470   /// isComplete - This virtual method should be overridden by values that may
00471   /// not be completely specified yet.
00472   virtual bool isComplete() const { return true; }
00473 
00474   /// print - Print out this value.
00475   void print(raw_ostream &OS) const { OS << getAsString(); }
00476 
00477   /// getAsString - Convert this value to a string form.
00478   virtual std::string getAsString() const = 0;
00479   /// getAsUnquotedString - Convert this value to a string form,
00480   /// without adding quote markers.  This primaruly affects
00481   /// StringInits where we will not surround the string value with
00482   /// quotes.
00483   virtual std::string getAsUnquotedString() const { return getAsString(); }
00484 
00485   /// dump - Debugging method that may be called through a debugger, just
00486   /// invokes print on stderr.
00487   void dump() const;
00488 
00489   /// convertInitializerTo - This virtual function is a simple call-back
00490   /// function that should be overridden to call the appropriate
00491   /// RecTy::convertValue method.
00492   ///
00493   virtual Init *convertInitializerTo(RecTy *Ty) const = 0;
00494 
00495   /// convertInitializerBitRange - This method is used to implement the bitrange
00496   /// selection operator.  Given an initializer, it selects the specified bits
00497   /// out, returning them as a new init of bits type.  If it is not legal to use
00498   /// the bit subscript operator on this initializer, return null.
00499   ///
00500   virtual Init *
00501   convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
00502     return nullptr;
00503   }
00504 
00505   /// convertInitListSlice - This method is used to implement the list slice
00506   /// selection operator.  Given an initializer, it selects the specified list
00507   /// elements, returning them as a new init of list type.  If it is not legal
00508   /// to take a slice of this, return null.
00509   ///
00510   virtual Init *
00511   convertInitListSlice(const std::vector<unsigned> &Elements) const {
00512     return nullptr;
00513   }
00514 
00515   /// getFieldType - This method is used to implement the FieldInit class.
00516   /// Implementors of this method should return the type of the named field if
00517   /// they are of record type.
00518   ///
00519   virtual RecTy *getFieldType(const std::string &FieldName) const {
00520     return nullptr;
00521   }
00522 
00523   /// getFieldInit - This method complements getFieldType to return the
00524   /// initializer for the specified field.  If getFieldType returns non-null
00525   /// this method should return non-null, otherwise it returns null.
00526   ///
00527   virtual Init *getFieldInit(Record &R, const RecordVal *RV,
00528                              const std::string &FieldName) const {
00529     return nullptr;
00530   }
00531 
00532   /// resolveReferences - This method is used by classes that refer to other
00533   /// variables which may not be defined at the time the expression is formed.
00534   /// If a value is set for the variable later, this method will be called on
00535   /// users of the value to allow the value to propagate out.
00536   ///
00537   virtual Init *resolveReferences(Record &R, const RecordVal *RV) const {
00538     return const_cast<Init *>(this);
00539   }
00540 
00541   /// getBit - This method is used to return the initializer for the specified
00542   /// bit.
00543   virtual Init *getBit(unsigned Bit) const = 0;
00544 
00545   /// getBitVar - This method is used to retrieve the initializer for bit
00546   /// reference. For non-VarBitInit, it simply returns itself.
00547   virtual Init *getBitVar() const { return const_cast<Init*>(this); }
00548 
00549   /// getBitNum - This method is used to retrieve the bit number of a bit
00550   /// reference. For non-VarBitInit, it simply returns 0.
00551   virtual unsigned getBitNum() const { return 0; }
00552 };
00553 
00554 inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
00555   I.print(OS); return OS;
00556 }
00557 
00558 /// TypedInit - This is the common super-class of types that have a specific,
00559 /// explicit, type.
00560 ///
00561 class TypedInit : public Init {
00562   RecTy *Ty;
00563 
00564   TypedInit(const TypedInit &Other) LLVM_DELETED_FUNCTION;
00565   TypedInit &operator=(const TypedInit &Other) LLVM_DELETED_FUNCTION;
00566 
00567 protected:
00568   explicit TypedInit(InitKind K, RecTy *T) : Init(K), Ty(T) {}
00569 
00570 public:
00571   static bool classof(const Init *I) {
00572     return I->getKind() >= IK_FirstTypedInit &&
00573            I->getKind() <= IK_LastTypedInit;
00574   }
00575   RecTy *getType() const { return Ty; }
00576 
00577   Init *
00578   convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
00579   Init *
00580   convertInitListSlice(const std::vector<unsigned> &Elements) const override;
00581 
00582   /// getFieldType - This method is used to implement the FieldInit class.
00583   /// Implementors of this method should return the type of the named field if
00584   /// they are of record type.
00585   ///
00586   RecTy *getFieldType(const std::string &FieldName) const override;
00587 
00588   /// resolveListElementReference - This method is used to implement
00589   /// VarListElementInit::resolveReferences.  If the list element is resolvable
00590   /// now, we return the resolved value, otherwise we return null.
00591   virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
00592                                             unsigned Elt) const = 0;
00593 };
00594 
00595 /// UnsetInit - ? - Represents an uninitialized value
00596 ///
00597 class UnsetInit : public Init {
00598   UnsetInit() : Init(IK_UnsetInit) {}
00599   UnsetInit(const UnsetInit &) LLVM_DELETED_FUNCTION;
00600   UnsetInit &operator=(const UnsetInit &Other) LLVM_DELETED_FUNCTION;
00601   void anchor() override;
00602 
00603 public:
00604   static bool classof(const Init *I) {
00605     return I->getKind() == IK_UnsetInit;
00606   }
00607   static UnsetInit *get();
00608 
00609   Init *convertInitializerTo(RecTy *Ty) const override {
00610     return Ty->convertValue(const_cast<UnsetInit *>(this));
00611   }
00612 
00613   Init *getBit(unsigned Bit) const override {
00614     return const_cast<UnsetInit*>(this);
00615   }
00616 
00617   bool isComplete() const override { return false; }
00618   std::string getAsString() const override { return "?"; }
00619 };
00620 
00621 /// BitInit - true/false - Represent a concrete initializer for a bit.
00622 ///
00623 class BitInit : public Init {
00624   bool Value;
00625 
00626   explicit BitInit(bool V) : Init(IK_BitInit), Value(V) {}
00627   BitInit(const BitInit &Other) LLVM_DELETED_FUNCTION;
00628   BitInit &operator=(BitInit &Other) LLVM_DELETED_FUNCTION;
00629   void anchor() override;
00630 
00631 public:
00632   static bool classof(const Init *I) {
00633     return I->getKind() == IK_BitInit;
00634   }
00635   static BitInit *get(bool V);
00636 
00637   bool getValue() const { return Value; }
00638 
00639   Init *convertInitializerTo(RecTy *Ty) const override {
00640     return Ty->convertValue(const_cast<BitInit *>(this));
00641   }
00642 
00643   Init *getBit(unsigned Bit) const override {
00644     assert(Bit < 1 && "Bit index out of range!");
00645     return const_cast<BitInit*>(this);
00646   }
00647 
00648   std::string getAsString() const override { return Value ? "1" : "0"; }
00649 };
00650 
00651 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
00652 /// It contains a vector of bits, whose size is determined by the type.
00653 ///
00654 class BitsInit : public TypedInit, public FoldingSetNode {
00655   std::vector<Init*> Bits;
00656 
00657   BitsInit(ArrayRef<Init *> Range)
00658     : TypedInit(IK_BitsInit, BitsRecTy::get(Range.size())),
00659       Bits(Range.begin(), Range.end()) {}
00660 
00661   BitsInit(const BitsInit &Other) LLVM_DELETED_FUNCTION;
00662   BitsInit &operator=(const BitsInit &Other) LLVM_DELETED_FUNCTION;
00663 
00664 public:
00665   static bool classof(const Init *I) {
00666     return I->getKind() == IK_BitsInit;
00667   }
00668   static BitsInit *get(ArrayRef<Init *> Range);
00669 
00670   void Profile(FoldingSetNodeID &ID) const;
00671 
00672   unsigned getNumBits() const { return Bits.size(); }
00673 
00674   Init *convertInitializerTo(RecTy *Ty) const override {
00675     return Ty->convertValue(const_cast<BitsInit *>(this));
00676   }
00677   Init *
00678   convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
00679 
00680   bool isComplete() const override {
00681     for (unsigned i = 0; i != getNumBits(); ++i)
00682       if (!getBit(i)->isComplete()) return false;
00683     return true;
00684   }
00685   bool allInComplete() const {
00686     for (unsigned i = 0; i != getNumBits(); ++i)
00687       if (getBit(i)->isComplete()) return false;
00688     return true;
00689   }
00690   std::string getAsString() const override;
00691 
00692   /// resolveListElementReference - This method is used to implement
00693   /// VarListElementInit::resolveReferences.  If the list element is resolvable
00694   /// now, we return the resolved value, otherwise we return null.
00695   Init *resolveListElementReference(Record &R, const RecordVal *RV,
00696                                     unsigned Elt) const override {
00697     llvm_unreachable("Illegal element reference off bits<n>");
00698   }
00699 
00700   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
00701 
00702   Init *getBit(unsigned Bit) const override {
00703     assert(Bit < Bits.size() && "Bit index out of range!");
00704     return Bits[Bit];
00705   }
00706 };
00707 
00708 /// IntInit - 7 - Represent an initialization by a literal integer value.
00709 ///
00710 class IntInit : public TypedInit {
00711   int64_t Value;
00712 
00713   explicit IntInit(int64_t V)
00714     : TypedInit(IK_IntInit, IntRecTy::get()), Value(V) {}
00715 
00716   IntInit(const IntInit &Other) LLVM_DELETED_FUNCTION;
00717   IntInit &operator=(const IntInit &Other) LLVM_DELETED_FUNCTION;
00718 
00719 public:
00720   static bool classof(const Init *I) {
00721     return I->getKind() == IK_IntInit;
00722   }
00723   static IntInit *get(int64_t V);
00724 
00725   int64_t getValue() const { return Value; }
00726 
00727   Init *convertInitializerTo(RecTy *Ty) const override {
00728     return Ty->convertValue(const_cast<IntInit *>(this));
00729   }
00730   Init *
00731   convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
00732 
00733   std::string getAsString() const override;
00734 
00735   /// resolveListElementReference - This method is used to implement
00736   /// VarListElementInit::resolveReferences.  If the list element is resolvable
00737   /// now, we return the resolved value, otherwise we return null.
00738   Init *resolveListElementReference(Record &R, const RecordVal *RV,
00739                                     unsigned Elt) const override {
00740     llvm_unreachable("Illegal element reference off int");
00741   }
00742 
00743   Init *getBit(unsigned Bit) const override {
00744     return BitInit::get((Value & (1ULL << Bit)) != 0);
00745   }
00746 };
00747 
00748 /// StringInit - "foo" - Represent an initialization by a string value.
00749 ///
00750 class StringInit : public TypedInit {
00751   std::string Value;
00752 
00753   explicit StringInit(const std::string &V)
00754     : TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
00755 
00756   StringInit(const StringInit &Other) LLVM_DELETED_FUNCTION;
00757   StringInit &operator=(const StringInit &Other) LLVM_DELETED_FUNCTION;
00758   void anchor() override;
00759 
00760 public:
00761   static bool classof(const Init *I) {
00762     return I->getKind() == IK_StringInit;
00763   }
00764   static StringInit *get(StringRef);
00765 
00766   const std::string &getValue() const { return Value; }
00767 
00768   Init *convertInitializerTo(RecTy *Ty) const override {
00769     return Ty->convertValue(const_cast<StringInit *>(this));
00770   }
00771 
00772   std::string getAsString() const override { return "\"" + Value + "\""; }
00773   std::string getAsUnquotedString() const override { return Value; }
00774 
00775   /// resolveListElementReference - This method is used to implement
00776   /// VarListElementInit::resolveReferences.  If the list element is resolvable
00777   /// now, we return the resolved value, otherwise we return null.
00778   Init *resolveListElementReference(Record &R, const RecordVal *RV,
00779                                     unsigned Elt) const override {
00780     llvm_unreachable("Illegal element reference off string");
00781   }
00782 
00783   Init *getBit(unsigned Bit) const override {
00784     llvm_unreachable("Illegal bit reference off string");
00785   }
00786 };
00787 
00788 /// ListInit - [AL, AH, CL] - Represent a list of defs
00789 ///
00790 class ListInit : public TypedInit, public FoldingSetNode {
00791   std::vector<Init*> Values;
00792 
00793 public:
00794   typedef std::vector<Init*>::const_iterator const_iterator;
00795 
00796 private:
00797   explicit ListInit(ArrayRef<Init *> Range, RecTy *EltTy)
00798     : TypedInit(IK_ListInit, ListRecTy::get(EltTy)),
00799       Values(Range.begin(), Range.end()) {}
00800 
00801   ListInit(const ListInit &Other) LLVM_DELETED_FUNCTION;
00802   ListInit &operator=(const ListInit &Other) LLVM_DELETED_FUNCTION;
00803 
00804 public:
00805   static bool classof(const Init *I) {
00806     return I->getKind() == IK_ListInit;
00807   }
00808   static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
00809 
00810   void Profile(FoldingSetNodeID &ID) const;
00811 
00812   unsigned getSize() const { return Values.size(); }
00813   Init *getElement(unsigned i) const {
00814     assert(i < Values.size() && "List element index out of range!");
00815     return Values[i];
00816   }
00817 
00818   Record *getElementAsRecord(unsigned i) const;
00819 
00820   Init *
00821     convertInitListSlice(const std::vector<unsigned> &Elements) const override;
00822 
00823   Init *convertInitializerTo(RecTy *Ty) const override {
00824     return Ty->convertValue(const_cast<ListInit *>(this));
00825   }
00826 
00827   /// resolveReferences - This method is used by classes that refer to other
00828   /// variables which may not be defined at the time they expression is formed.
00829   /// If a value is set for the variable later, this method will be called on
00830   /// users of the value to allow the value to propagate out.
00831   ///
00832   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
00833 
00834   std::string getAsString() const override;
00835 
00836   ArrayRef<Init*> getValues() const { return Values; }
00837 
00838   inline const_iterator begin() const { return Values.begin(); }
00839   inline const_iterator end  () const { return Values.end();   }
00840 
00841   inline size_t         size () const { return Values.size();  }
00842   inline bool           empty() const { return Values.empty(); }
00843 
00844   /// resolveListElementReference - This method is used to implement
00845   /// VarListElementInit::resolveReferences.  If the list element is resolvable
00846   /// now, we return the resolved value, otherwise we return null.
00847   Init *resolveListElementReference(Record &R, const RecordVal *RV,
00848                                     unsigned Elt) const override;
00849 
00850   Init *getBit(unsigned Bit) const override {
00851     llvm_unreachable("Illegal bit reference off list");
00852   }
00853 };
00854 
00855 /// OpInit - Base class for operators
00856 ///
00857 class OpInit : public TypedInit {
00858   OpInit(const OpInit &Other) LLVM_DELETED_FUNCTION;
00859   OpInit &operator=(OpInit &Other) LLVM_DELETED_FUNCTION;
00860 
00861 protected:
00862   explicit OpInit(InitKind K, RecTy *Type) : TypedInit(K, Type) {}
00863 
00864 public:
00865   static bool classof(const Init *I) {
00866     return I->getKind() >= IK_FirstOpInit &&
00867            I->getKind() <= IK_LastOpInit;
00868   }
00869   // Clone - Clone this operator, replacing arguments with the new list
00870   virtual OpInit *clone(std::vector<Init *> &Operands) const = 0;
00871 
00872   virtual int getNumOperands() const = 0;
00873   virtual Init *getOperand(int i) const = 0;
00874 
00875   // Fold - If possible, fold this to a simpler init.  Return this if not
00876   // possible to fold.
00877   virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
00878 
00879   Init *convertInitializerTo(RecTy *Ty) const override {
00880     return Ty->convertValue(const_cast<OpInit *>(this));
00881   }
00882 
00883   Init *resolveListElementReference(Record &R, const RecordVal *RV,
00884                                     unsigned Elt) const override;
00885 
00886   Init *getBit(unsigned Bit) const override;
00887 };
00888 
00889 /// UnOpInit - !op (X) - Transform an init.
00890 ///
00891 class UnOpInit : public OpInit {
00892 public:
00893   enum UnaryOp { CAST, HEAD, TAIL, EMPTY };
00894 
00895 private:
00896   UnaryOp Opc;
00897   Init *LHS;
00898 
00899   UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
00900     : OpInit(IK_UnOpInit, Type), Opc(opc), LHS(lhs) {}
00901 
00902   UnOpInit(const UnOpInit &Other) LLVM_DELETED_FUNCTION;
00903   UnOpInit &operator=(const UnOpInit &Other) LLVM_DELETED_FUNCTION;
00904 
00905 public:
00906   static bool classof(const Init *I) {
00907     return I->getKind() == IK_UnOpInit;
00908   }
00909   static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
00910 
00911   // Clone - Clone this operator, replacing arguments with the new list
00912   OpInit *clone(std::vector<Init *> &Operands) const override {
00913     assert(Operands.size() == 1 &&
00914            "Wrong number of operands for unary operation");
00915     return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
00916   }
00917 
00918   int getNumOperands() const override { return 1; }
00919   Init *getOperand(int i) const override {
00920     assert(i == 0 && "Invalid operand id for unary operator");
00921     return getOperand();
00922   }
00923 
00924   UnaryOp getOpcode() const { return Opc; }
00925   Init *getOperand() const { return LHS; }
00926 
00927   // Fold - If possible, fold this to a simpler init.  Return this if not
00928   // possible to fold.
00929   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
00930 
00931   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
00932 
00933   std::string getAsString() const override;
00934 };
00935 
00936 /// BinOpInit - !op (X, Y) - Combine two inits.
00937 ///
00938 class BinOpInit : public OpInit {
00939 public:
00940   enum BinaryOp { ADD, AND, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ };
00941 
00942 private:
00943   BinaryOp Opc;
00944   Init *LHS, *RHS;
00945 
00946   BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
00947       OpInit(IK_BinOpInit, Type), Opc(opc), LHS(lhs), RHS(rhs) {}
00948 
00949   BinOpInit(const BinOpInit &Other) LLVM_DELETED_FUNCTION;
00950   BinOpInit &operator=(const BinOpInit &Other) LLVM_DELETED_FUNCTION;
00951 
00952 public:
00953   static bool classof(const Init *I) {
00954     return I->getKind() == IK_BinOpInit;
00955   }
00956   static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
00957                         RecTy *Type);
00958 
00959   // Clone - Clone this operator, replacing arguments with the new list
00960   OpInit *clone(std::vector<Init *> &Operands) const override {
00961     assert(Operands.size() == 2 &&
00962            "Wrong number of operands for binary operation");
00963     return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
00964   }
00965 
00966   int getNumOperands() const override { return 2; }
00967   Init *getOperand(int i) const override {
00968     assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
00969     if (i == 0) {
00970       return getLHS();
00971     } else {
00972       return getRHS();
00973     }
00974   }
00975 
00976   BinaryOp getOpcode() const { return Opc; }
00977   Init *getLHS() const { return LHS; }
00978   Init *getRHS() const { return RHS; }
00979 
00980   // Fold - If possible, fold this to a simpler init.  Return this if not
00981   // possible to fold.
00982   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
00983 
00984   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
00985 
00986   std::string getAsString() const override;
00987 };
00988 
00989 /// TernOpInit - !op (X, Y, Z) - Combine two inits.
00990 ///
00991 class TernOpInit : public OpInit {
00992 public:
00993   enum TernaryOp { SUBST, FOREACH, IF };
00994 
00995 private:
00996   TernaryOp Opc;
00997   Init *LHS, *MHS, *RHS;
00998 
00999   TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
01000              RecTy *Type) :
01001       OpInit(IK_TernOpInit, Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
01002 
01003   TernOpInit(const TernOpInit &Other) LLVM_DELETED_FUNCTION;
01004   TernOpInit &operator=(const TernOpInit &Other) LLVM_DELETED_FUNCTION;
01005 
01006 public:
01007   static bool classof(const Init *I) {
01008     return I->getKind() == IK_TernOpInit;
01009   }
01010   static TernOpInit *get(TernaryOp opc, Init *lhs,
01011                          Init *mhs, Init *rhs,
01012                          RecTy *Type);
01013 
01014   // Clone - Clone this operator, replacing arguments with the new list
01015   OpInit *clone(std::vector<Init *> &Operands) const override {
01016     assert(Operands.size() == 3 &&
01017            "Wrong number of operands for ternary operation");
01018     return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
01019                            getType());
01020   }
01021 
01022   int getNumOperands() const override { return 3; }
01023   Init *getOperand(int i) const override {
01024     assert((i == 0 || i == 1 || i == 2) &&
01025            "Invalid operand id for ternary operator");
01026     if (i == 0) {
01027       return getLHS();
01028     } else if (i == 1) {
01029       return getMHS();
01030     } else {
01031       return getRHS();
01032     }
01033   }
01034 
01035   TernaryOp getOpcode() const { return Opc; }
01036   Init *getLHS() const { return LHS; }
01037   Init *getMHS() const { return MHS; }
01038   Init *getRHS() const { return RHS; }
01039 
01040   // Fold - If possible, fold this to a simpler init.  Return this if not
01041   // possible to fold.
01042   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
01043 
01044   bool isComplete() const override { return false; }
01045 
01046   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
01047 
01048   std::string getAsString() const override;
01049 };
01050 
01051 /// VarInit - 'Opcode' - Represent a reference to an entire variable object.
01052 ///
01053 class VarInit : public TypedInit {
01054   Init *VarName;
01055 
01056   explicit VarInit(const std::string &VN, RecTy *T)
01057       : TypedInit(IK_VarInit, T), VarName(StringInit::get(VN)) {}
01058   explicit VarInit(Init *VN, RecTy *T)
01059       : TypedInit(IK_VarInit, T), VarName(VN) {}
01060 
01061   VarInit(const VarInit &Other) LLVM_DELETED_FUNCTION;
01062   VarInit &operator=(const VarInit &Other) LLVM_DELETED_FUNCTION;
01063 
01064 public:
01065   static bool classof(const Init *I) {
01066     return I->getKind() == IK_VarInit;
01067   }
01068   static VarInit *get(const std::string &VN, RecTy *T);
01069   static VarInit *get(Init *VN, RecTy *T);
01070 
01071   Init *convertInitializerTo(RecTy *Ty) const override {
01072     return Ty->convertValue(const_cast<VarInit *>(this));
01073   }
01074 
01075   const std::string &getName() const;
01076   Init *getNameInit() const { return VarName; }
01077   std::string getNameInitAsString() const {
01078     return getNameInit()->getAsUnquotedString();
01079   }
01080 
01081   Init *resolveListElementReference(Record &R, const RecordVal *RV,
01082                                     unsigned Elt) const override;
01083 
01084   RecTy *getFieldType(const std::string &FieldName) const override;
01085   Init *getFieldInit(Record &R, const RecordVal *RV,
01086                      const std::string &FieldName) const override;
01087 
01088   /// resolveReferences - This method is used by classes that refer to other
01089   /// variables which may not be defined at the time they expression is formed.
01090   /// If a value is set for the variable later, this method will be called on
01091   /// users of the value to allow the value to propagate out.
01092   ///
01093   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
01094 
01095   Init *getBit(unsigned Bit) const override;
01096 
01097   std::string getAsString() const override { return getName(); }
01098 };
01099 
01100 /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
01101 ///
01102 class VarBitInit : public Init {
01103   TypedInit *TI;
01104   unsigned Bit;
01105 
01106   VarBitInit(TypedInit *T, unsigned B) : Init(IK_VarBitInit), TI(T), Bit(B) {
01107     assert(T->getType() &&
01108            (isa<IntRecTy>(T->getType()) ||
01109             (isa<BitsRecTy>(T->getType()) &&
01110              cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
01111            "Illegal VarBitInit expression!");
01112   }
01113 
01114   VarBitInit(const VarBitInit &Other) LLVM_DELETED_FUNCTION;
01115   VarBitInit &operator=(const VarBitInit &Other) LLVM_DELETED_FUNCTION;
01116 
01117 public:
01118   static bool classof(const Init *I) {
01119     return I->getKind() == IK_VarBitInit;
01120   }
01121   static VarBitInit *get(TypedInit *T, unsigned B);
01122 
01123   Init *convertInitializerTo(RecTy *Ty) const override {
01124     return Ty->convertValue(const_cast<VarBitInit *>(this));
01125   }
01126 
01127   Init *getBitVar() const override { return TI; }
01128   unsigned getBitNum() const override { return Bit; }
01129 
01130   std::string getAsString() const override;
01131   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
01132 
01133   Init *getBit(unsigned B) const override {
01134     assert(B < 1 && "Bit index out of range!");
01135     return const_cast<VarBitInit*>(this);
01136   }
01137 };
01138 
01139 /// VarListElementInit - List[4] - Represent access to one element of a var or
01140 /// field.
01141 class VarListElementInit : public TypedInit {
01142   TypedInit *TI;
01143   unsigned Element;
01144 
01145   VarListElementInit(TypedInit *T, unsigned E)
01146       : TypedInit(IK_VarListElementInit,
01147                   cast<ListRecTy>(T->getType())->getElementType()),
01148         TI(T), Element(E) {
01149     assert(T->getType() && isa<ListRecTy>(T->getType()) &&
01150            "Illegal VarBitInit expression!");
01151   }
01152 
01153   VarListElementInit(const VarListElementInit &Other) LLVM_DELETED_FUNCTION;
01154   void operator=(const VarListElementInit &Other) LLVM_DELETED_FUNCTION;
01155 
01156 public:
01157   static bool classof(const Init *I) {
01158     return I->getKind() == IK_VarListElementInit;
01159   }
01160   static VarListElementInit *get(TypedInit *T, unsigned E);
01161 
01162   Init *convertInitializerTo(RecTy *Ty) const override {
01163     return Ty->convertValue(const_cast<VarListElementInit *>(this));
01164   }
01165 
01166   TypedInit *getVariable() const { return TI; }
01167   unsigned getElementNum() const { return Element; }
01168 
01169   /// resolveListElementReference - This method is used to implement
01170   /// VarListElementInit::resolveReferences.  If the list element is resolvable
01171   /// now, we return the resolved value, otherwise we return null.
01172   Init *resolveListElementReference(Record &R, const RecordVal *RV,
01173                                     unsigned Elt) const override;
01174 
01175   std::string getAsString() const override;
01176   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
01177 
01178   Init *getBit(unsigned Bit) const override;
01179 };
01180 
01181 /// DefInit - AL - Represent a reference to a 'def' in the description
01182 ///
01183 class DefInit : public TypedInit {
01184   Record *Def;
01185 
01186   DefInit(Record *D, RecordRecTy *T) : TypedInit(IK_DefInit, T), Def(D) {}
01187   friend class Record;
01188 
01189   DefInit(const DefInit &Other) LLVM_DELETED_FUNCTION;
01190   DefInit &operator=(const DefInit &Other) LLVM_DELETED_FUNCTION;
01191 
01192 public:
01193   static bool classof(const Init *I) {
01194     return I->getKind() == IK_DefInit;
01195   }
01196   static DefInit *get(Record*);
01197 
01198   Init *convertInitializerTo(RecTy *Ty) const override {
01199     return Ty->convertValue(const_cast<DefInit *>(this));
01200   }
01201 
01202   Record *getDef() const { return Def; }
01203 
01204   //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
01205 
01206   RecTy *getFieldType(const std::string &FieldName) const override;
01207   Init *getFieldInit(Record &R, const RecordVal *RV,
01208                      const std::string &FieldName) const override;
01209 
01210   std::string getAsString() const override;
01211 
01212   Init *getBit(unsigned Bit) const override {
01213     llvm_unreachable("Illegal bit reference off def");
01214   }
01215 
01216   /// resolveListElementReference - This method is used to implement
01217   /// VarListElementInit::resolveReferences.  If the list element is resolvable
01218   /// now, we return the resolved value, otherwise we return null.
01219   Init *resolveListElementReference(Record &R, const RecordVal *RV,
01220                                     unsigned Elt) const override {
01221     llvm_unreachable("Illegal element reference off def");
01222   }
01223 };
01224 
01225 /// FieldInit - X.Y - Represent a reference to a subfield of a variable
01226 ///
01227 class FieldInit : public TypedInit {
01228   Init *Rec;                // Record we are referring to
01229   std::string FieldName;    // Field we are accessing
01230 
01231   FieldInit(Init *R, const std::string &FN)
01232       : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
01233     assert(getType() && "FieldInit with non-record type!");
01234   }
01235 
01236   FieldInit(const FieldInit &Other) LLVM_DELETED_FUNCTION;
01237   FieldInit &operator=(const FieldInit &Other) LLVM_DELETED_FUNCTION;
01238 
01239 public:
01240   static bool classof(const Init *I) {
01241     return I->getKind() == IK_FieldInit;
01242   }
01243   static FieldInit *get(Init *R, const std::string &FN);
01244   static FieldInit *get(Init *R, const Init *FN);
01245 
01246   Init *convertInitializerTo(RecTy *Ty) const override {
01247     return Ty->convertValue(const_cast<FieldInit *>(this));
01248   }
01249 
01250   Init *getBit(unsigned Bit) const override;
01251 
01252   Init *resolveListElementReference(Record &R, const RecordVal *RV,
01253                                     unsigned Elt) const override;
01254 
01255   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
01256 
01257   std::string getAsString() const override {
01258     return Rec->getAsString() + "." + FieldName;
01259   }
01260 };
01261 
01262 /// DagInit - (v a, b) - Represent a DAG tree value.  DAG inits are required
01263 /// to have at least one value then a (possibly empty) list of arguments.  Each
01264 /// argument can have a name associated with it.
01265 ///
01266 class DagInit : public TypedInit, public FoldingSetNode {
01267   Init *Val;
01268   std::string ValName;
01269   std::vector<Init*> Args;
01270   std::vector<std::string> ArgNames;
01271 
01272   DagInit(Init *V, const std::string &VN,
01273           ArrayRef<Init *> ArgRange,
01274           ArrayRef<std::string> NameRange)
01275       : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
01276           Args(ArgRange.begin(), ArgRange.end()),
01277           ArgNames(NameRange.begin(), NameRange.end()) {}
01278 
01279   DagInit(const DagInit &Other) LLVM_DELETED_FUNCTION;
01280   DagInit &operator=(const DagInit &Other) LLVM_DELETED_FUNCTION;
01281 
01282 public:
01283   static bool classof(const Init *I) {
01284     return I->getKind() == IK_DagInit;
01285   }
01286   static DagInit *get(Init *V, const std::string &VN,
01287                       ArrayRef<Init *> ArgRange,
01288                       ArrayRef<std::string> NameRange);
01289   static DagInit *get(Init *V, const std::string &VN,
01290                       const std::vector<
01291                         std::pair<Init*, std::string> > &args);
01292 
01293   void Profile(FoldingSetNodeID &ID) const;
01294 
01295   Init *convertInitializerTo(RecTy *Ty) const override {
01296     return Ty->convertValue(const_cast<DagInit *>(this));
01297   }
01298 
01299   Init *getOperator() const { return Val; }
01300 
01301   const std::string &getName() const { return ValName; }
01302 
01303   unsigned getNumArgs() const { return Args.size(); }
01304   Init *getArg(unsigned Num) const {
01305     assert(Num < Args.size() && "Arg number out of range!");
01306     return Args[Num];
01307   }
01308   const std::string &getArgName(unsigned Num) const {
01309     assert(Num < ArgNames.size() && "Arg number out of range!");
01310     return ArgNames[Num];
01311   }
01312 
01313   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
01314 
01315   std::string getAsString() const override;
01316 
01317   typedef std::vector<Init*>::const_iterator       const_arg_iterator;
01318   typedef std::vector<std::string>::const_iterator const_name_iterator;
01319 
01320   inline const_arg_iterator  arg_begin() const { return Args.begin(); }
01321   inline const_arg_iterator  arg_end  () const { return Args.end();   }
01322 
01323   inline size_t              arg_size () const { return Args.size();  }
01324   inline bool                arg_empty() const { return Args.empty(); }
01325 
01326   inline const_name_iterator name_begin() const { return ArgNames.begin(); }
01327   inline const_name_iterator name_end  () const { return ArgNames.end();   }
01328 
01329   inline size_t              name_size () const { return ArgNames.size();  }
01330   inline bool                name_empty() const { return ArgNames.empty(); }
01331 
01332   Init *getBit(unsigned Bit) const override {
01333     llvm_unreachable("Illegal bit reference off dag");
01334   }
01335 
01336   Init *resolveListElementReference(Record &R, const RecordVal *RV,
01337                                     unsigned Elt) const override {
01338     llvm_unreachable("Illegal element reference off dag");
01339   }
01340 };
01341 
01342 //===----------------------------------------------------------------------===//
01343 //  High-Level Classes
01344 //===----------------------------------------------------------------------===//
01345 
01346 class RecordVal {
01347   Init *Name;
01348   RecTy *Ty;
01349   unsigned Prefix;
01350   Init *Value;
01351 
01352 public:
01353   RecordVal(Init *N, RecTy *T, unsigned P);
01354   RecordVal(const std::string &N, RecTy *T, unsigned P);
01355 
01356   const std::string &getName() const;
01357   const Init *getNameInit() const { return Name; }
01358   std::string getNameInitAsString() const {
01359     return getNameInit()->getAsUnquotedString();
01360   }
01361 
01362   unsigned getPrefix() const { return Prefix; }
01363   RecTy *getType() const { return Ty; }
01364   Init *getValue() const { return Value; }
01365 
01366   bool setValue(Init *V) {
01367     if (V) {
01368       Value = V->convertInitializerTo(Ty);
01369       return Value == nullptr;
01370     }
01371     Value = nullptr;
01372     return false;
01373   }
01374 
01375   void dump() const;
01376   void print(raw_ostream &OS, bool PrintSem = true) const;
01377 };
01378 
01379 inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
01380   RV.print(OS << "  ");
01381   return OS;
01382 }
01383 
01384 class Record {
01385   static unsigned LastID;
01386 
01387   // Unique record ID.
01388   unsigned ID;
01389   Init *Name;
01390   // Location where record was instantiated, followed by the location of
01391   // multiclass prototypes used.
01392   SmallVector<SMLoc, 4> Locs;
01393   std::vector<Init *> TemplateArgs;
01394   std::vector<RecordVal> Values;
01395   std::vector<Record *> SuperClasses;
01396   std::vector<SMRange> SuperClassRanges;
01397 
01398   // Tracks Record instances. Not owned by Record.
01399   RecordKeeper &TrackedRecords;
01400 
01401   DefInit *TheInit;
01402   bool IsAnonymous;
01403 
01404   // Class-instance values can be used by other defs.  For example, Struct<i>
01405   // is used here as a template argument to another class:
01406   //
01407   //   multiclass MultiClass<int i> {
01408   //     def Def : Class<Struct<i>>;
01409   //
01410   // These need to get fully resolved before instantiating any other
01411   // definitions that usie them (e.g. Def).  However, inside a multiclass they
01412   // can't be immediately resolved so we mark them ResolveFirst to fully
01413   // resolve them later as soon as the multiclass is instantiated.
01414   bool ResolveFirst;
01415 
01416   void init();
01417   void checkName();
01418 
01419 public:
01420   // Constructs a record.
01421   explicit Record(const std::string &N, ArrayRef<SMLoc> locs,
01422                   RecordKeeper &records, bool Anonymous = false) :
01423     ID(LastID++), Name(StringInit::get(N)), Locs(locs.begin(), locs.end()),
01424     TrackedRecords(records), TheInit(nullptr), IsAnonymous(Anonymous),
01425     ResolveFirst(false) {
01426     init();
01427   }
01428   explicit Record(Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
01429                   bool Anonymous = false) :
01430     ID(LastID++), Name(N), Locs(locs.begin(), locs.end()),
01431     TrackedRecords(records), TheInit(nullptr), IsAnonymous(Anonymous),
01432     ResolveFirst(false) {
01433     init();
01434   }
01435 
01436   // When copy-constructing a Record, we must still guarantee a globally unique
01437   // ID number.  All other fields can be copied normally.
01438   Record(const Record &O) :
01439     ID(LastID++), Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
01440     Values(O.Values), SuperClasses(O.SuperClasses),
01441     SuperClassRanges(O.SuperClassRanges), TrackedRecords(O.TrackedRecords),
01442     TheInit(O.TheInit), IsAnonymous(O.IsAnonymous),
01443     ResolveFirst(O.ResolveFirst) { }
01444 
01445   ~Record() {}
01446 
01447   static unsigned getNewUID() { return LastID++; }
01448 
01449   unsigned getID() const { return ID; }
01450 
01451   const std::string &getName() const;
01452   Init *getNameInit() const {
01453     return Name;
01454   }
01455   const std::string getNameInitAsString() const {
01456     return getNameInit()->getAsUnquotedString();
01457   }
01458 
01459   void setName(Init *Name);               // Also updates RecordKeeper.
01460   void setName(const std::string &Name);  // Also updates RecordKeeper.
01461 
01462   ArrayRef<SMLoc> getLoc() const { return Locs; }
01463 
01464   /// get the corresponding DefInit.
01465   DefInit *getDefInit();
01466 
01467   const std::vector<Init *> &getTemplateArgs() const {
01468     return TemplateArgs;
01469   }
01470   const std::vector<RecordVal> &getValues() const { return Values; }
01471   const std::vector<Record*>   &getSuperClasses() const { return SuperClasses; }
01472   ArrayRef<SMRange> getSuperClassRanges() const { return SuperClassRanges; }
01473 
01474   bool isTemplateArg(Init *Name) const {
01475     for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
01476       if (TemplateArgs[i] == Name) return true;
01477     return false;
01478   }
01479   bool isTemplateArg(StringRef Name) const {
01480     return isTemplateArg(StringInit::get(Name.str()));
01481   }
01482 
01483   const RecordVal *getValue(const Init *Name) const {
01484     for (unsigned i = 0, e = Values.size(); i != e; ++i)
01485       if (Values[i].getNameInit() == Name) return &Values[i];
01486     return nullptr;
01487   }
01488   const RecordVal *getValue(StringRef Name) const {
01489     return getValue(StringInit::get(Name));
01490   }
01491   RecordVal *getValue(const Init *Name) {
01492     for (unsigned i = 0, e = Values.size(); i != e; ++i)
01493       if (Values[i].getNameInit() == Name) return &Values[i];
01494     return nullptr;
01495   }
01496   RecordVal *getValue(StringRef Name) {
01497     return getValue(StringInit::get(Name));
01498   }
01499 
01500   void addTemplateArg(Init *Name) {
01501     assert(!isTemplateArg(Name) && "Template arg already defined!");
01502     TemplateArgs.push_back(Name);
01503   }
01504   void addTemplateArg(StringRef Name) {
01505     addTemplateArg(StringInit::get(Name.str()));
01506   }
01507 
01508   void addValue(const RecordVal &RV) {
01509     assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
01510     Values.push_back(RV);
01511     if (Values.size() > 1)
01512       // Keep NAME at the end of the list.  It makes record dumps a
01513       // bit prettier and allows TableGen tests to be written more
01514       // naturally.  Tests can use CHECK-NEXT to look for Record
01515       // fields they expect to see after a def.  They can't do that if
01516       // NAME is the first Record field.
01517       std::swap(Values[Values.size() - 2], Values[Values.size() - 1]);
01518   }
01519 
01520   void removeValue(Init *Name) {
01521     for (unsigned i = 0, e = Values.size(); i != e; ++i)
01522       if (Values[i].getNameInit() == Name) {
01523         Values.erase(Values.begin()+i);
01524         return;
01525       }
01526     llvm_unreachable("Cannot remove an entry that does not exist!");
01527   }
01528 
01529   void removeValue(StringRef Name) {
01530     removeValue(StringInit::get(Name.str()));
01531   }
01532 
01533   bool isSubClassOf(const Record *R) const {
01534     for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
01535       if (SuperClasses[i] == R)
01536         return true;
01537     return false;
01538   }
01539 
01540   bool isSubClassOf(StringRef Name) const {
01541     for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
01542       if (SuperClasses[i]->getNameInitAsString() == Name)
01543         return true;
01544     return false;
01545   }
01546 
01547   void addSuperClass(Record *R, SMRange Range) {
01548     assert(!isSubClassOf(R) && "Already subclassing record!");
01549     SuperClasses.push_back(R);
01550     SuperClassRanges.push_back(Range);
01551   }
01552 
01553   /// resolveReferences - If there are any field references that refer to fields
01554   /// that have been filled in, we can propagate the values now.
01555   ///
01556   void resolveReferences() { resolveReferencesTo(nullptr); }
01557 
01558   /// resolveReferencesTo - If anything in this record refers to RV, replace the
01559   /// reference to RV with the RHS of RV.  If RV is null, we resolve all
01560   /// possible references.
01561   void resolveReferencesTo(const RecordVal *RV);
01562 
01563   RecordKeeper &getRecords() const {
01564     return TrackedRecords;
01565   }
01566 
01567   bool isAnonymous() const {
01568     return IsAnonymous;
01569   }
01570 
01571   bool isResolveFirst() const {
01572     return ResolveFirst;
01573   }
01574 
01575   void setResolveFirst(bool b) {
01576     ResolveFirst = b;
01577   }
01578 
01579   void dump() const;
01580 
01581   //===--------------------------------------------------------------------===//
01582   // High-level methods useful to tablegen back-ends
01583   //
01584 
01585   /// getValueInit - Return the initializer for a value with the specified name,
01586   /// or throw an exception if the field does not exist.
01587   ///
01588   Init *getValueInit(StringRef FieldName) const;
01589 
01590   /// Return true if the named field is unset.
01591   bool isValueUnset(StringRef FieldName) const {
01592     return getValueInit(FieldName) == UnsetInit::get();
01593   }
01594 
01595   /// getValueAsString - This method looks up the specified field and returns
01596   /// its value as a string, throwing an exception if the field does not exist
01597   /// or if the value is not a string.
01598   ///
01599   std::string getValueAsString(StringRef FieldName) const;
01600 
01601   /// getValueAsBitsInit - This method looks up the specified field and returns
01602   /// its value as a BitsInit, throwing an exception if the field does not exist
01603   /// or if the value is not the right type.
01604   ///
01605   BitsInit *getValueAsBitsInit(StringRef FieldName) const;
01606 
01607   /// getValueAsListInit - This method looks up the specified field and returns
01608   /// its value as a ListInit, throwing an exception if the field does not exist
01609   /// or if the value is not the right type.
01610   ///
01611   ListInit *getValueAsListInit(StringRef FieldName) const;
01612 
01613   /// getValueAsListOfDefs - This method looks up the specified field and
01614   /// returns its value as a vector of records, throwing an exception if the
01615   /// field does not exist or if the value is not the right type.
01616   ///
01617   std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
01618 
01619   /// getValueAsListOfInts - This method looks up the specified field and
01620   /// returns its value as a vector of integers, throwing an exception if the
01621   /// field does not exist or if the value is not the right type.
01622   ///
01623   std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
01624 
01625   /// getValueAsListOfStrings - This method looks up the specified field and
01626   /// returns its value as a vector of strings, throwing an exception if the
01627   /// field does not exist or if the value is not the right type.
01628   ///
01629   std::vector<std::string> getValueAsListOfStrings(StringRef FieldName) const;
01630 
01631   /// getValueAsDef - This method looks up the specified field and returns its
01632   /// value as a Record, throwing an exception if the field does not exist or if
01633   /// the value is not the right type.
01634   ///
01635   Record *getValueAsDef(StringRef FieldName) const;
01636 
01637   /// getValueAsBit - This method looks up the specified field and returns its
01638   /// value as a bit, throwing an exception if the field does not exist or if
01639   /// the value is not the right type.
01640   ///
01641   bool getValueAsBit(StringRef FieldName) const;
01642 
01643   /// getValueAsBitOrUnset - This method looks up the specified field and
01644   /// returns its value as a bit. If the field is unset, sets Unset to true and
01645   /// returns false.
01646   ///
01647   bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
01648 
01649   /// getValueAsInt - This method looks up the specified field and returns its
01650   /// value as an int64_t, throwing an exception if the field does not exist or
01651   /// if the value is not the right type.
01652   ///
01653   int64_t getValueAsInt(StringRef FieldName) const;
01654 
01655   /// getValueAsDag - This method looks up the specified field and returns its
01656   /// value as an Dag, throwing an exception if the field does not exist or if
01657   /// the value is not the right type.
01658   ///
01659   DagInit *getValueAsDag(StringRef FieldName) const;
01660 };
01661 
01662 raw_ostream &operator<<(raw_ostream &OS, const Record &R);
01663 
01664 struct MultiClass {
01665   Record Rec;  // Placeholder for template args and Name.
01666   typedef std::vector<Record*> RecordVector;
01667   RecordVector DefPrototypes;
01668 
01669   void dump() const;
01670 
01671   MultiClass(const std::string &Name, SMLoc Loc, RecordKeeper &Records) :
01672     Rec(Name, Loc, Records) {}
01673 };
01674 
01675 class RecordKeeper {
01676   typedef std::map<std::string, std::unique_ptr<Record>> RecordMap;
01677   RecordMap Classes, Defs;
01678 
01679 public:
01680   const RecordMap &getClasses() const { return Classes; }
01681   const RecordMap &getDefs() const { return Defs; }
01682 
01683   Record *getClass(const std::string &Name) const {
01684     auto I = Classes.find(Name);
01685     return I == Classes.end() ? nullptr : I->second.get();
01686   }
01687   Record *getDef(const std::string &Name) const {
01688     auto I = Defs.find(Name);
01689     return I == Defs.end() ? nullptr : I->second.get();
01690   }
01691   void addClass(Record *_R) {
01692     std::unique_ptr<Record> R(_R);
01693     bool Ins = Classes.insert(std::make_pair(R->getName(),
01694                                              std::move(R))).second;
01695     (void)Ins;
01696     assert(Ins && "Class already exists");
01697   }
01698   void addDef(Record *_R) {
01699     std::unique_ptr<Record> R(_R);
01700     bool Ins = Defs.insert(std::make_pair(R->getName(),
01701                                           std::move(R))).second;
01702     (void)Ins;
01703     assert(Ins && "Record already exists");
01704   }
01705 
01706   //===--------------------------------------------------------------------===//
01707   // High-level helper methods, useful for tablegen backends...
01708 
01709   /// getAllDerivedDefinitions - This method returns all concrete definitions
01710   /// that derive from the specified class name.  If a class with the specified
01711   /// name does not exist, an exception is thrown.
01712   std::vector<Record*>
01713   getAllDerivedDefinitions(const std::string &ClassName) const;
01714 
01715   void dump() const;
01716 };
01717 
01718 /// LessRecord - Sorting predicate to sort record pointers by name.
01719 ///
01720 struct LessRecord {
01721   bool operator()(const Record *Rec1, const Record *Rec2) const {
01722     return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
01723   }
01724 };
01725 
01726 /// LessRecordByID - Sorting predicate to sort record pointers by their
01727 /// unique ID. If you just need a deterministic order, use this, since it
01728 /// just compares two `unsigned`; the other sorting predicates require
01729 /// string manipulation.
01730 struct LessRecordByID {
01731   bool operator()(const Record *LHS, const Record *RHS) const {
01732     return LHS->getID() < RHS->getID();
01733   }
01734 };
01735 
01736 /// LessRecordFieldName - Sorting predicate to sort record pointers by their
01737 /// name field.
01738 ///
01739 struct LessRecordFieldName {
01740   bool operator()(const Record *Rec1, const Record *Rec2) const {
01741     return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
01742   }
01743 };
01744 
01745 struct LessRecordRegister {
01746   static size_t min(size_t a, size_t b) { return a < b ? a : b; }
01747   static bool ascii_isdigit(char x) { return x >= '0' && x <= '9'; }
01748 
01749   struct RecordParts {
01750     SmallVector<std::pair< bool, StringRef>, 4> Parts;
01751 
01752     RecordParts(StringRef Rec) {
01753       if (Rec.empty())
01754         return;
01755 
01756       size_t Len = 0;
01757       const char *Start = Rec.data();
01758       const char *Curr = Start;
01759       bool isDigitPart = ascii_isdigit(Curr[0]);
01760       for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
01761         bool isDigit = ascii_isdigit(Curr[I]);
01762         if (isDigit != isDigitPart) {
01763           Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
01764           Len = 0;
01765           Start = &Curr[I];
01766           isDigitPart = ascii_isdigit(Curr[I]);
01767         }
01768       }
01769       // Push the last part.
01770       Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
01771     }
01772 
01773     size_t size() { return Parts.size(); }
01774 
01775     std::pair<bool, StringRef> getPart(size_t i) {
01776       assert (i < Parts.size() && "Invalid idx!");
01777       return Parts[i];
01778     }
01779   };
01780 
01781   bool operator()(const Record *Rec1, const Record *Rec2) const {
01782     RecordParts LHSParts(StringRef(Rec1->getName()));
01783     RecordParts RHSParts(StringRef(Rec2->getName()));
01784 
01785     size_t LHSNumParts = LHSParts.size();
01786     size_t RHSNumParts = RHSParts.size();
01787     assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
01788 
01789     if (LHSNumParts != RHSNumParts)
01790       return LHSNumParts < RHSNumParts;
01791 
01792     // We expect the registers to be of the form [_a-zA-z]+([0-9]*[_a-zA-Z]*)*.
01793     for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
01794       std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
01795       std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
01796       // Expect even part to always be alpha.
01797       assert (LHSPart.first == false && RHSPart.first == false &&
01798               "Expected both parts to be alpha.");
01799       if (int Res = LHSPart.second.compare(RHSPart.second))
01800         return Res < 0;
01801     }
01802     for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
01803       std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
01804       std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
01805       // Expect odd part to always be numeric.
01806       assert (LHSPart.first == true && RHSPart.first == true &&
01807               "Expected both parts to be numeric.");
01808       if (LHSPart.second.size() != RHSPart.second.size())
01809         return LHSPart.second.size() < RHSPart.second.size();
01810 
01811       unsigned LHSVal, RHSVal;
01812 
01813       bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
01814       assert(!LHSFailed && "Unable to convert LHS to integer.");
01815       bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
01816       assert(!RHSFailed && "Unable to convert RHS to integer.");
01817 
01818       if (LHSVal != RHSVal)
01819         return LHSVal < RHSVal;
01820     }
01821     return LHSNumParts < RHSNumParts;
01822   }
01823 };
01824 
01825 raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
01826 
01827 /// QualifyName - Return an Init with a qualifier prefix referring
01828 /// to CurRec's name.
01829 Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass,
01830                   Init *Name, const std::string &Scoper);
01831 
01832 /// QualifyName - Return an Init with a qualifier prefix referring
01833 /// to CurRec's name.
01834 Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass,
01835                   const std::string &Name, const std::string &Scoper);
01836 
01837 } // End llvm namespace
01838 
01839 #endif