LCOV - code coverage report
Current view: top level - include/llvm/TableGen - Record.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 260 320 81.2 %
Date: 2017-09-14 15:23:50 Functions: 62 123 50.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file defines the main TableGen data structures, including the TableGen
      11             : // types, values, and high-level data structures.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_TABLEGEN_RECORD_H
      16             : #define LLVM_TABLEGEN_RECORD_H
      17             : 
      18             : #include "llvm/ADT/ArrayRef.h"
      19             : #include "llvm/ADT/FoldingSet.h"
      20             : #include "llvm/ADT/PointerIntPair.h"
      21             : #include "llvm/ADT/SmallVector.h"
      22             : #include "llvm/ADT/StringRef.h"
      23             : #include "llvm/Support/Casting.h"
      24             : #include "llvm/Support/ErrorHandling.h"
      25             : #include "llvm/Support/SMLoc.h"
      26             : #include "llvm/Support/TrailingObjects.h"
      27             : #include "llvm/Support/raw_ostream.h"
      28             : #include <algorithm>
      29             : #include <cassert>
      30             : #include <cstddef>
      31             : #include <cstdint>
      32             : #include <map>
      33             : #include <memory>
      34             : #include <string>
      35             : #include <utility>
      36             : #include <vector>
      37             : 
      38             : namespace llvm {
      39             : 
      40             : class ListRecTy;
      41             : struct MultiClass;
      42             : class Record;
      43             : class RecordKeeper;
      44             : class RecordVal;
      45             : class StringInit;
      46             : 
      47             : //===----------------------------------------------------------------------===//
      48             : //  Type Classes
      49             : //===----------------------------------------------------------------------===//
      50             : 
      51             : class RecTy {
      52             : public:
      53             :   /// \brief Subclass discriminator (for dyn_cast<> et al.)
      54             :   enum RecTyKind {
      55             :     BitRecTyKind,
      56             :     BitsRecTyKind,
      57             :     CodeRecTyKind,
      58             :     IntRecTyKind,
      59             :     StringRecTyKind,
      60             :     ListRecTyKind,
      61             :     DagRecTyKind,
      62             :     RecordRecTyKind
      63             :   };
      64             : 
      65             : private:
      66             :   RecTyKind Kind;
      67             :   ListRecTy *ListTy = nullptr;
      68             : 
      69             : public:
      70      869577 :   RecTy(RecTyKind K) : Kind(K) {}
      71             :   virtual ~RecTy() = default;
      72             : 
      73             :   RecTyKind getRecTyKind() const { return Kind; }
      74             : 
      75             :   virtual std::string getAsString() const = 0;
      76        6750 :   void print(raw_ostream &OS) const { OS << getAsString(); }
      77             :   void dump() const;
      78             : 
      79             :   /// Return true if all values of 'this' type can be converted to the specified
      80             :   /// type.
      81             :   virtual bool typeIsConvertibleTo(const RecTy *RHS) const;
      82             : 
      83             :   /// Returns the type representing list<this>.
      84             :   ListRecTy *getListTy();
      85             : };
      86             : 
      87             : inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
      88        2250 :   Ty.print(OS);
      89             :   return OS;
      90             : }
      91             : 
      92             : /// 'bit' - Represent a single bit
      93         275 : class BitRecTy : public RecTy {
      94             :   static BitRecTy Shared;
      95             : 
      96         550 :   BitRecTy() : RecTy(BitRecTyKind) {}
      97             : 
      98             : public:
      99             :   static bool classof(const RecTy *RT) {
     100   271875400 :     return RT->getRecTyKind() == BitRecTyKind;
     101             :   }
     102             : 
     103             :   static BitRecTy *get() { return &Shared; }
     104             : 
     105         105 :   std::string getAsString() const override { return "bit"; }
     106             : 
     107             :   bool typeIsConvertibleTo(const RecTy *RHS) const override;
     108             : };
     109             : 
     110             : /// 'bits<n>' - Represent a fixed number of bits
     111           0 : class BitsRecTy : public RecTy {
     112             :   unsigned Size;
     113             : 
     114        4912 :   explicit BitsRecTy(unsigned Sz) : RecTy(BitsRecTyKind), Size(Sz) {}
     115             : 
     116             : public:
     117             :   static bool classof(const RecTy *RT) {
     118   113272142 :     return RT->getRecTyKind() == BitsRecTyKind;
     119             :   }
     120             : 
     121             :   static BitsRecTy *get(unsigned Sz);
     122             : 
     123             :   unsigned getNumBits() const { return Size; }
     124             : 
     125             :   std::string getAsString() const override;
     126             : 
     127             :   bool typeIsConvertibleTo(const RecTy *RHS) const override;
     128             : };
     129             : 
     130             : /// 'code' - Represent a code fragment
     131         275 : class CodeRecTy : public RecTy {
     132             :   static CodeRecTy Shared;
     133             : 
     134         550 :   CodeRecTy() : RecTy(CodeRecTyKind) {}
     135             : 
     136             : public:
     137             :   static bool classof(const RecTy *RT) {
     138    11367606 :     return RT->getRecTyKind() == CodeRecTyKind;
     139             :   }
     140             : 
     141             :   static CodeRecTy *get() { return &Shared; }
     142             : 
     143           9 :   std::string getAsString() const override { return "code"; }
     144             : };
     145             : 
     146             : /// 'int' - Represent an integer value of no particular size
     147         275 : class IntRecTy : public RecTy {
     148             :   static IntRecTy Shared;
     149             : 
     150         550 :   IntRecTy() : RecTy(IntRecTyKind) {}
     151             : 
     152             : public:
     153             :   static bool classof(const RecTy *RT) {
     154    77546512 :     return RT->getRecTyKind() == IntRecTyKind;
     155             :   }
     156             : 
     157             :   static IntRecTy *get() { return &Shared; }
     158             : 
     159        1995 :   std::string getAsString() const override { return "int"; }
     160             : 
     161             :   bool typeIsConvertibleTo(const RecTy *RHS) const override;
     162             : };
     163             : 
     164             : /// 'string' - Represent an string value
     165         275 : class StringRecTy : public RecTy {
     166             :   static StringRecTy Shared;
     167             : 
     168         550 :   StringRecTy() : RecTy(StringRecTyKind) {}
     169             : 
     170             : public:
     171             :   static bool classof(const RecTy *RT) {
     172   104942335 :     return RT->getRecTyKind() == StringRecTyKind ||
     173    13329758 :            RT->getRecTyKind() == CodeRecTyKind;
     174             :   }
     175             : 
     176             :   static StringRecTy *get() { return &Shared; }
     177             : 
     178             :   std::string getAsString() const override;
     179             : };
     180             : 
     181             : /// 'list<Ty>' - Represent a list of values, all of which must be of
     182             : /// the specified type.
     183           0 : class ListRecTy : public RecTy {
     184             :   friend ListRecTy *RecTy::getListTy();
     185             : 
     186             :   RecTy *Ty;
     187             : 
     188      324432 :   explicit ListRecTy(RecTy *T) : RecTy(ListRecTyKind), Ty(T) {}
     189             : 
     190             : public:
     191             :   static bool classof(const RecTy *RT) {
     192    29396106 :     return RT->getRecTyKind() == ListRecTyKind;
     193             :   }
     194             : 
     195     1129625 :   static ListRecTy *get(RecTy *T) { return T->getListTy(); }
     196             :   RecTy *getElementType() const { return Ty; }
     197             : 
     198             :   std::string getAsString() const override;
     199             : 
     200             :   bool typeIsConvertibleTo(const RecTy *RHS) const override;
     201             : };
     202             : 
     203             : /// 'dag' - Represent a dag fragment
     204         275 : class DagRecTy : public RecTy {
     205             :   static DagRecTy Shared;
     206             : 
     207         550 :   DagRecTy() : RecTy(DagRecTyKind) {}
     208             : 
     209             : public:
     210             :   static bool classof(const RecTy *RT) {
     211    18139262 :     return RT->getRecTyKind() == DagRecTyKind;
     212             :   }
     213             : 
     214             :   static DagRecTy *get() { return &Shared; }
     215             : 
     216             :   std::string getAsString() const override;
     217             : };
     218             : 
     219             : /// '[classname]' - Represent an instance of a class, such as:
     220             : /// (R32 X = EAX).
     221           0 : class RecordRecTy : public RecTy {
     222             :   friend class Record;
     223             : 
     224             :   Record *Rec;
     225             : 
     226     1407060 :   explicit RecordRecTy(Record *R) : RecTy(RecordRecTyKind), Rec(R) {}
     227             : 
     228             : public:
     229             :   static bool classof(const RecTy *RT) {
     230    98065277 :     return RT->getRecTyKind() == RecordRecTyKind;
     231             :   }
     232             : 
     233             :   static RecordRecTy *get(Record *R);
     234             : 
     235             :   Record *getRecord() const { return Rec; }
     236             : 
     237             :   std::string getAsString() const override;
     238             : 
     239             :   bool typeIsConvertibleTo(const RecTy *RHS) const override;
     240             : };
     241             : 
     242             : /// Find a common type that T1 and T2 convert to.
     243             : /// Return 0 if no such type exists.
     244             : RecTy *resolveTypes(RecTy *T1, RecTy *T2);
     245             : 
     246             : //===----------------------------------------------------------------------===//
     247             : //  Initializer Classes
     248             : //===----------------------------------------------------------------------===//
     249             : 
     250             : class Init {
     251             : protected:
     252             :   /// \brief Discriminator enum (for isa<>, dyn_cast<>, et al.)
     253             :   ///
     254             :   /// This enum is laid out by a preorder traversal of the inheritance
     255             :   /// hierarchy, and does not contain an entry for abstract classes, as per
     256             :   /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
     257             :   ///
     258             :   /// We also explicitly include "first" and "last" values for each
     259             :   /// interior node of the inheritance tree, to make it easier to read the
     260             :   /// corresponding classof().
     261             :   ///
     262             :   /// We could pack these a bit tighter by not having the IK_FirstXXXInit
     263             :   /// and IK_LastXXXInit be their own values, but that would degrade
     264             :   /// readability for really no benefit.
     265             :   enum InitKind : uint8_t {
     266             :     IK_BitInit,
     267             :     IK_FirstTypedInit,
     268             :     IK_BitsInit,
     269             :     IK_CodeInit,
     270             :     IK_DagInit,
     271             :     IK_DefInit,
     272             :     IK_FieldInit,
     273             :     IK_IntInit,
     274             :     IK_ListInit,
     275             :     IK_FirstOpInit,
     276             :     IK_BinOpInit,
     277             :     IK_TernOpInit,
     278             :     IK_UnOpInit,
     279             :     IK_LastOpInit,
     280             :     IK_StringInit,
     281             :     IK_VarInit,
     282             :     IK_VarListElementInit,
     283             :     IK_LastTypedInit,
     284             :     IK_UnsetInit,
     285             :     IK_VarBitInit
     286             :   };
     287             : 
     288             : private:
     289             :   const InitKind Kind;
     290             : 
     291             : protected:
     292             :   uint8_t Opc; // Used by UnOpInit, BinOpInit, and TernOpInit
     293             : 
     294             : private:
     295             :   virtual void anchor();
     296             : 
     297             : public:
     298             :   InitKind getKind() const { return Kind; }
     299             : 
     300             : protected:
     301    19952020 :   explicit Init(InitKind K, uint8_t Opc = 0) : Kind(K), Opc(Opc) {}
     302             : 
     303             : public:
     304             :   Init(const Init &) = delete;
     305             :   Init &operator=(const Init &) = delete;
     306             :   virtual ~Init() = default;
     307             : 
     308             :   /// This virtual method should be overridden by values that may
     309             :   /// not be completely specified yet.
     310    21974635 :   virtual bool isComplete() const { return true; }
     311             : 
     312             :   /// Print out this value.
     313    11724441 :   void print(raw_ostream &OS) const { OS << getAsString(); }
     314             : 
     315             :   /// Convert this value to a string form.
     316             :   virtual std::string getAsString() const = 0;
     317             :   /// Convert this value to a string form,
     318             :   /// without adding quote markers.  This primaruly affects
     319             :   /// StringInits where we will not surround the string value with
     320             :   /// quotes.
     321      549848 :   virtual std::string getAsUnquotedString() const { return getAsString(); }
     322             : 
     323             :   /// Debugging method that may be called through a debugger, just
     324             :   /// invokes print on stderr.
     325             :   void dump() const;
     326             : 
     327             :   /// This virtual function converts to the appropriate
     328             :   /// Init based on the passed in type.
     329             :   virtual Init *convertInitializerTo(RecTy *Ty) const = 0;
     330             : 
     331             :   /// This method is used to implement the bitrange
     332             :   /// selection operator.  Given an initializer, it selects the specified bits
     333             :   /// out, returning them as a new init of bits type.  If it is not legal to use
     334             :   /// the bit subscript operator on this initializer, return null.
     335           0 :   virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
     336           0 :     return nullptr;
     337             :   }
     338             : 
     339             :   /// This method is used to implement the list slice
     340             :   /// selection operator.  Given an initializer, it selects the specified list
     341             :   /// elements, returning them as a new init of list type.  If it is not legal
     342             :   /// to take a slice of this, return null.
     343           0 :   virtual Init *convertInitListSlice(ArrayRef<unsigned> Elements) const {
     344           0 :     return nullptr;
     345             :   }
     346             : 
     347             :   /// This method is used to implement the FieldInit class.
     348             :   /// Implementors of this method should return the type of the named field if
     349             :   /// they are of record type.
     350           0 :   virtual RecTy *getFieldType(StringInit *FieldName) const {
     351           0 :     return nullptr;
     352             :   }
     353             : 
     354             :   /// This method complements getFieldType to return the
     355             :   /// initializer for the specified field.  If getFieldType returns non-null
     356             :   /// this method should return non-null, otherwise it returns null.
     357     2547900 :   virtual Init *getFieldInit(Record &R, const RecordVal *RV,
     358             :                              StringInit *FieldName) const {
     359     2547900 :     return nullptr;
     360             :   }
     361             : 
     362             :   /// This method is used by classes that refer to other
     363             :   /// variables which may not be defined at the time the expression is formed.
     364             :   /// If a value is set for the variable later, this method will be called on
     365             :   /// users of the value to allow the value to propagate out.
     366   513284772 :   virtual Init *resolveReferences(Record &R, const RecordVal *RV) const {
     367   513284772 :     return const_cast<Init *>(this);
     368             :   }
     369             : 
     370             :   /// This method is used to return the initializer for the specified
     371             :   /// bit.
     372             :   virtual Init *getBit(unsigned Bit) const = 0;
     373             : 
     374             :   /// This method is used to retrieve the initializer for bit
     375             :   /// reference. For non-VarBitInit, it simply returns itself.
     376   386282546 :   virtual Init *getBitVar() const { return const_cast<Init*>(this); }
     377             : 
     378             :   /// This method is used to retrieve the bit number of a bit
     379             :   /// reference. For non-VarBitInit, it simply returns 0.
     380     6098369 :   virtual unsigned getBitNum() const { return 0; }
     381             : };
     382             : 
     383             : inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
     384     3908147 :   I.print(OS); return OS;
     385             : }
     386             : 
     387             : /// This is the common super-class of types that have a specific,
     388             : /// explicit, type.
     389           0 : class TypedInit : public Init {
     390             :   RecTy *Ty;
     391             : 
     392             : protected:
     393             :   explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
     394    39059306 :     : Init(K, Opc), Ty(T) {}
     395             : 
     396             : public:
     397             :   TypedInit(const TypedInit &) = delete;
     398             :   TypedInit &operator=(const TypedInit &) = delete;
     399             : 
     400             :   static bool classof(const Init *I) {
     401     8166429 :     return I->getKind() >= IK_FirstTypedInit &&
     402     4055398 :            I->getKind() <= IK_LastTypedInit;
     403             :   }
     404             : 
     405             :   RecTy *getType() const { return Ty; }
     406             : 
     407             :   Init *convertInitializerTo(RecTy *Ty) const override;
     408             : 
     409             :   Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
     410             :   Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
     411             : 
     412             :   /// This method is used to implement the FieldInit class.
     413             :   /// Implementors of this method should return the type of the named field if
     414             :   /// they are of record type.
     415             :   ///
     416             :   RecTy *getFieldType(StringInit *FieldName) const override;
     417             : 
     418             :   /// This method is used to implement
     419             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
     420             :   /// now, we return the resolved value, otherwise we return null.
     421             :   virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
     422             :                                             unsigned Elt) const = 0;
     423             : };
     424             : 
     425             : /// '?' - Represents an uninitialized value
     426         275 : class UnsetInit : public Init {
     427         550 :   UnsetInit() : Init(IK_UnsetInit) {}
     428             : 
     429             : public:
     430             :   UnsetInit(const UnsetInit &) = delete;
     431             :   UnsetInit &operator=(const UnsetInit &) = delete;
     432             : 
     433             :   static bool classof(const Init *I) {
     434    61024948 :     return I->getKind() == IK_UnsetInit;
     435             :   }
     436             : 
     437             :   static UnsetInit *get();
     438             : 
     439             :   Init *convertInitializerTo(RecTy *Ty) const override;
     440             : 
     441       63402 :   Init *getBit(unsigned Bit) const override {
     442       63402 :     return const_cast<UnsetInit*>(this);
     443             :   }
     444             : 
     445      211991 :   bool isComplete() const override { return false; }
     446      437316 :   std::string getAsString() const override { return "?"; }
     447             : };
     448             : 
     449             : /// 'true'/'false' - Represent a concrete initializer for a bit.
     450         444 : class BitInit : public Init {
     451             :   bool Value;
     452             : 
     453         888 :   explicit BitInit(bool V) : Init(IK_BitInit), Value(V) {}
     454             : 
     455             : public:
     456             :   BitInit(const BitInit &) = delete;
     457             :   BitInit &operator=(BitInit &) = delete;
     458             : 
     459             :   static bool classof(const Init *I) {
     460       21379 :     return I->getKind() == IK_BitInit;
     461             :   }
     462             : 
     463             :   static BitInit *get(bool V);
     464             : 
     465             :   bool getValue() const { return Value; }
     466             : 
     467             :   Init *convertInitializerTo(RecTy *Ty) const override;
     468             : 
     469     6072968 :   Init *getBit(unsigned Bit) const override {
     470             :     assert(Bit < 1 && "Bit index out of range!");
     471     6072968 :     return const_cast<BitInit*>(this);
     472             :   }
     473             : 
     474       27876 :   std::string getAsString() const override { return Value ? "1" : "0"; }
     475             : };
     476             : 
     477             : /// '{ a, b, c }' - Represents an initializer for a BitsRecTy value.
     478             : /// It contains a vector of bits, whose size is determined by the type.
     479           0 : class BitsInit final : public TypedInit, public FoldingSetNode,
     480             :                        public TrailingObjects<BitsInit, Init *> {
     481             :   unsigned NumBits;
     482             : 
     483             :   BitsInit(unsigned N)
     484     2523393 :     : TypedInit(IK_BitsInit, BitsRecTy::get(N)), NumBits(N) {}
     485             : 
     486             : public:
     487             :   BitsInit(const BitsInit &) = delete;
     488             :   BitsInit &operator=(const BitsInit &) = delete;
     489             : 
     490             :   // Do not use sized deallocation due to trailing objects.
     491           0 :   void operator delete(void *p) { ::operator delete(p); }
     492             : 
     493             :   static bool classof(const Init *I) {
     494      797744 :     return I->getKind() == IK_BitsInit;
     495             :   }
     496             : 
     497             :   static BitsInit *get(ArrayRef<Init *> Range);
     498             : 
     499             :   void Profile(FoldingSetNodeID &ID) const;
     500             : 
     501             :   unsigned getNumBits() const { return NumBits; }
     502             : 
     503             :   Init *convertInitializerTo(RecTy *Ty) const override;
     504             :   Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
     505             : 
     506     4251242 :   bool isComplete() const override {
     507    20566325 :     for (unsigned i = 0; i != getNumBits(); ++i)
     508    16406122 :       if (!getBit(i)->isComplete()) return false;
     509             :     return true;
     510             :   }
     511             : 
     512             :   bool allInComplete() const {
     513       22983 :     for (unsigned i = 0; i != getNumBits(); ++i)
     514       20271 :       if (getBit(i)->isComplete()) return false;
     515             :     return true;
     516             :   }
     517             : 
     518             :   std::string getAsString() const override;
     519             : 
     520             :   /// This method is used to implement
     521             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
     522             :   /// now, we return the resolved value, otherwise we return null.
     523           0 :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     524             :                                     unsigned Elt) const override {
     525           0 :     llvm_unreachable("Illegal element reference off bits<n>");
     526             :   }
     527             : 
     528             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     529             : 
     530    36670647 :   Init *getBit(unsigned Bit) const override {
     531             :     assert(Bit < NumBits && "Bit index out of range!");
     532   765065531 :     return getTrailingObjects<Init *>()[Bit];
     533             :   }
     534             : };
     535             : 
     536             : /// '7' - Represent an initialization by a literal integer value.
     537           0 : class IntInit : public TypedInit {
     538             :   int64_t Value;
     539             : 
     540             :   explicit IntInit(int64_t V)
     541      112348 :     : TypedInit(IK_IntInit, IntRecTy::get()), Value(V) {}
     542             : 
     543             : public:
     544             :   IntInit(const IntInit &) = delete;
     545             :   IntInit &operator=(const IntInit &) = delete;
     546             : 
     547             :   static bool classof(const Init *I) {
     548    54816474 :     return I->getKind() == IK_IntInit;
     549             :   }
     550             : 
     551             :   static IntInit *get(int64_t V);
     552             : 
     553             :   int64_t getValue() const { return Value; }
     554             : 
     555             :   Init *convertInitializerTo(RecTy *Ty) const override;
     556             :   Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
     557             : 
     558             :   std::string getAsString() const override;
     559             : 
     560             :   /// This method is used to implement
     561             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
     562             :   /// now, we return the resolved value, otherwise we return null.
     563           0 :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     564             :                                     unsigned Elt) const override {
     565           0 :     llvm_unreachable("Illegal element reference off int");
     566             :   }
     567             : 
     568     5459036 :   Init *getBit(unsigned Bit) const override {
     569     5459036 :     return BitInit::get((Value & (1ULL << Bit)) != 0);
     570             :   }
     571             : };
     572             : 
     573             : /// "foo" - Represent an initialization by a string value.
     574           0 : class StringInit : public TypedInit {
     575             :   StringRef Value;
     576             : 
     577             :   explicit StringInit(StringRef V)
     578    23509086 :       : TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
     579             : 
     580             : public:
     581             :   StringInit(const StringInit &) = delete;
     582             :   StringInit &operator=(const StringInit &) = delete;
     583             : 
     584             :   static bool classof(const Init *I) {
     585    74362354 :     return I->getKind() == IK_StringInit;
     586             :   }
     587             : 
     588             :   static StringInit *get(StringRef);
     589             : 
     590             :   StringRef getValue() const { return Value; }
     591             : 
     592             :   Init *convertInitializerTo(RecTy *Ty) const override;
     593             : 
     594     2160016 :   std::string getAsString() const override { return "\"" + Value.str() + "\""; }
     595             : 
     596     4897588 :   std::string getAsUnquotedString() const override { return Value; }
     597             : 
     598             :   /// resolveListElementReference - This method is used to implement
     599             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
     600             :   /// now, we return the resolved value, otherwise we return null.
     601           0 :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     602             :                                     unsigned Elt) const override {
     603           0 :     llvm_unreachable("Illegal element reference off string");
     604             :   }
     605             : 
     606           0 :   Init *getBit(unsigned Bit) const override {
     607           0 :     llvm_unreachable("Illegal bit reference off string");
     608             :   }
     609             : };
     610             : 
     611           0 : class CodeInit : public TypedInit {
     612             :   StringRef Value;
     613             : 
     614             :   explicit CodeInit(StringRef V)
     615       19574 :       : TypedInit(IK_CodeInit, static_cast<RecTy *>(CodeRecTy::get())),
     616       19574 :         Value(V) {}
     617             : 
     618             : public:
     619             :   CodeInit(const StringInit &) = delete;
     620             :   CodeInit &operator=(const StringInit &) = delete;
     621             : 
     622             :   static bool classof(const Init *I) {
     623         716 :     return I->getKind() == IK_CodeInit;
     624             :   }
     625             : 
     626             :   static CodeInit *get(StringRef);
     627             : 
     628             :   StringRef getValue() const { return Value; }
     629             : 
     630             :   Init *convertInitializerTo(RecTy *Ty) const override;
     631             : 
     632           1 :   std::string getAsString() const override {
     633           4 :     return "[{" + Value.str() + "}]";
     634             :   }
     635             : 
     636          66 :   std::string getAsUnquotedString() const override { return Value; }
     637             : 
     638             :   /// This method is used to implement
     639             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
     640             :   /// now, we return the resolved value, otherwise we return null.
     641           0 :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     642             :                                     unsigned Elt) const override {
     643           0 :     llvm_unreachable("Illegal element reference off string");
     644             :   }
     645             : 
     646           0 :   Init *getBit(unsigned Bit) const override {
     647           0 :     llvm_unreachable("Illegal bit reference off string");
     648             :   }
     649             : };
     650             : 
     651             : /// [AL, AH, CL] - Represent a list of defs
     652             : ///
     653           0 : class ListInit final : public TypedInit, public FoldingSetNode,
     654             :                        public TrailingObjects<ListInit, Init *> {
     655             :   unsigned NumValues;
     656             : 
     657             : public:
     658             :   using const_iterator = Init *const *;
     659             : 
     660             : private:
     661             :   explicit ListInit(unsigned N, RecTy *EltTy)
     662     4368384 :     : TypedInit(IK_ListInit, ListRecTy::get(EltTy)), NumValues(N) {}
     663             : 
     664             : public:
     665             :   ListInit(const ListInit &) = delete;
     666             :   ListInit &operator=(const ListInit &) = delete;
     667             : 
     668             :   // Do not use sized deallocation due to trailing objects.
     669           0 :   void operator delete(void *p) { ::operator delete(p); }
     670             : 
     671             :   static bool classof(const Init *I) {
     672     3712603 :     return I->getKind() == IK_ListInit;
     673             :   }
     674             :   static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
     675             : 
     676             :   void Profile(FoldingSetNodeID &ID) const;
     677             : 
     678             :   Init *getElement(unsigned i) const {
     679             :     assert(i < NumValues && "List element index out of range!");
     680     1398199 :     return getTrailingObjects<Init *>()[i];
     681             :   }
     682             : 
     683             :   Record *getElementAsRecord(unsigned i) const;
     684             : 
     685             :   Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
     686             : 
     687             :   Init *convertInitializerTo(RecTy *Ty) const override;
     688             : 
     689             :   /// This method is used by classes that refer to other
     690             :   /// variables which may not be defined at the time they expression is formed.
     691             :   /// If a value is set for the variable later, this method will be called on
     692             :   /// users of the value to allow the value to propagate out.
     693             :   ///
     694             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     695             : 
     696             :   std::string getAsString() const override;
     697             : 
     698             :   ArrayRef<Init*> getValues() const {
     699   237299349 :     return makeArrayRef(getTrailingObjects<Init *>(), NumValues);
     700             :   }
     701             : 
     702     1544234 :   const_iterator begin() const { return getTrailingObjects<Init *>(); }
     703      772117 :   const_iterator end  () const { return begin() + NumValues; }
     704             : 
     705    31351437 :   size_t         size () const { return NumValues;  }
     706         995 :   bool           empty() const { return NumValues == 0; }
     707             : 
     708             :   /// This method is used to implement
     709             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
     710             :   /// now, we return the resolved value, otherwise we return null.
     711             :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     712             :                                     unsigned Elt) const override;
     713             : 
     714           0 :   Init *getBit(unsigned Bit) const override {
     715           0 :     llvm_unreachable("Illegal bit reference off list");
     716             :   }
     717             : };
     718             : 
     719             : /// Base class for operators
     720             : ///
     721           0 : class OpInit : public TypedInit {
     722             : protected:
     723             :   explicit OpInit(InitKind K, RecTy *Type, uint8_t Opc)
     724     4961006 :     : TypedInit(K, Type, Opc) {}
     725             : 
     726             : public:
     727             :   OpInit(const OpInit &) = delete;
     728             :   OpInit &operator=(OpInit &) = delete;
     729             : 
     730             :   static bool classof(const Init *I) {
     731        1284 :     return I->getKind() >= IK_FirstOpInit &&
     732         454 :            I->getKind() <= IK_LastOpInit;
     733             :   }
     734             : 
     735             :   // Clone - Clone this operator, replacing arguments with the new list
     736             :   virtual OpInit *clone(ArrayRef<Init *> Operands) const = 0;
     737             : 
     738             :   virtual unsigned getNumOperands() const = 0;
     739             :   virtual Init *getOperand(unsigned i) const = 0;
     740             : 
     741             :   // Fold - If possible, fold this to a simpler init.  Return this if not
     742             :   // possible to fold.
     743             :   virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
     744             : 
     745             :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     746             :                                     unsigned Elt) const override;
     747             : 
     748             :   Init *getBit(unsigned Bit) const override;
     749             : };
     750             : 
     751             : /// !op (X) - Transform an init.
     752             : ///
     753           0 : class UnOpInit : public OpInit, public FoldingSetNode {
     754             : public:
     755             :   enum UnaryOp : uint8_t { CAST, HEAD, TAIL, EMPTY };
     756             : 
     757             : private:
     758             :   Init *LHS;
     759             : 
     760             :   UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
     761      830832 :     : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
     762             : 
     763             : public:
     764             :   UnOpInit(const UnOpInit &) = delete;
     765             :   UnOpInit &operator=(const UnOpInit &) = delete;
     766             : 
     767             :   static bool classof(const Init *I) {
     768             :     return I->getKind() == IK_UnOpInit;
     769             :   }
     770             : 
     771             :   static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
     772             : 
     773             :   void Profile(FoldingSetNodeID &ID) const;
     774             : 
     775             :   // Clone - Clone this operator, replacing arguments with the new list
     776           0 :   OpInit *clone(ArrayRef<Init *> Operands) const override {
     777             :     assert(Operands.size() == 1 &&
     778             :            "Wrong number of operands for unary operation");
     779           0 :     return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
     780             :   }
     781             : 
     782           0 :   unsigned getNumOperands() const override { return 1; }
     783             : 
     784           0 :   Init *getOperand(unsigned i) const override {
     785             :     assert(i == 0 && "Invalid operand id for unary operator");
     786           0 :     return getOperand();
     787             :   }
     788             : 
     789             :   UnaryOp getOpcode() const { return (UnaryOp)Opc; }
     790             :   Init *getOperand() const { return LHS; }
     791             : 
     792             :   // Fold - If possible, fold this to a simpler init.  Return this if not
     793             :   // possible to fold.
     794             :   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
     795             : 
     796             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     797             : 
     798             :   std::string getAsString() const override;
     799             : };
     800             : 
     801             : /// !op (X, Y) - Combine two inits.
     802           0 : class BinOpInit : public OpInit, public FoldingSetNode {
     803             : public:
     804             :   enum BinaryOp : uint8_t { ADD, AND, OR, SHL, SRA, SRL, LISTCONCAT,
     805             :                             STRCONCAT, CONCAT, EQ };
     806             : 
     807             : private:
     808             :   Init *LHS, *RHS;
     809             : 
     810     2062812 :   BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
     811     6188436 :       OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
     812             : 
     813             : public:
     814             :   BinOpInit(const BinOpInit &) = delete;
     815             :   BinOpInit &operator=(const BinOpInit &) = delete;
     816             : 
     817             :   static bool classof(const Init *I) {
     818     9146632 :     return I->getKind() == IK_BinOpInit;
     819             :   }
     820             : 
     821             :   static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
     822             :                         RecTy *Type);
     823             : 
     824             :   void Profile(FoldingSetNodeID &ID) const;
     825             : 
     826             :   // Clone - Clone this operator, replacing arguments with the new list
     827           4 :   OpInit *clone(ArrayRef<Init *> Operands) const override {
     828             :     assert(Operands.size() == 2 &&
     829             :            "Wrong number of operands for binary operation");
     830           4 :     return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
     831             :   }
     832             : 
     833          12 :   unsigned getNumOperands() const override { return 2; }
     834          12 :   Init *getOperand(unsigned i) const override {
     835          12 :     switch (i) {
     836           0 :     default: llvm_unreachable("Invalid operand id for binary operator");
     837           4 :     case 0: return getLHS();
     838           8 :     case 1: return getRHS();
     839             :     }
     840             :   }
     841             : 
     842             :   BinaryOp getOpcode() const { return (BinaryOp)Opc; }
     843             :   Init *getLHS() const { return LHS; }
     844             :   Init *getRHS() const { return RHS; }
     845             : 
     846             :   // Fold - If possible, fold this to a simpler init.  Return this if not
     847             :   // possible to fold.
     848             :   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
     849             : 
     850             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     851             : 
     852             :   std::string getAsString() const override;
     853             : };
     854             : 
     855             : /// !op (X, Y, Z) - Combine two inits.
     856           0 : class TernOpInit : public OpInit, public FoldingSetNode {
     857             : public:
     858             :   enum TernaryOp : uint8_t { SUBST, FOREACH, IF };
     859             : 
     860             : private:
     861             :   Init *LHS, *MHS, *RHS;
     862             : 
     863             :   TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
     864      140747 :              RecTy *Type) :
     865      422241 :       OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
     866             : 
     867             : public:
     868             :   TernOpInit(const TernOpInit &) = delete;
     869             :   TernOpInit &operator=(const TernOpInit &) = delete;
     870             : 
     871             :   static bool classof(const Init *I) {
     872      317210 :     return I->getKind() == IK_TernOpInit;
     873             :   }
     874             : 
     875             :   static TernOpInit *get(TernaryOp opc, Init *lhs,
     876             :                          Init *mhs, Init *rhs,
     877             :                          RecTy *Type);
     878             : 
     879             :   void Profile(FoldingSetNodeID &ID) const;
     880             : 
     881             :   // Clone - Clone this operator, replacing arguments with the new list
     882         174 :   OpInit *clone(ArrayRef<Init *> Operands) const override {
     883             :     assert(Operands.size() == 3 &&
     884             :            "Wrong number of operands for ternary operation");
     885         174 :     return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
     886         174 :                            getType());
     887             :   }
     888             : 
     889         380 :   unsigned getNumOperands() const override { return 3; }
     890        1242 :   Init *getOperand(unsigned i) const override {
     891        1242 :     switch (i) {
     892           0 :     default: llvm_unreachable("Invalid operand id for ternary operator");
     893         506 :     case 0: return getLHS();
     894         494 :     case 1: return getMHS();
     895         242 :     case 2: return getRHS();
     896             :     }
     897             :   }
     898             : 
     899             :   TernaryOp getOpcode() const { return (TernaryOp)Opc; }
     900             :   Init *getLHS() const { return LHS; }
     901             :   Init *getMHS() const { return MHS; }
     902             :   Init *getRHS() const { return RHS; }
     903             : 
     904             :   // Fold - If possible, fold this to a simpler init.  Return this if not
     905             :   // possible to fold.
     906             :   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
     907             : 
     908      293293 :   bool isComplete() const override { return false; }
     909             : 
     910             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     911             : 
     912             :   std::string getAsString() const override;
     913             : };
     914             : 
     915             : /// 'Opcode' - Represent a reference to an entire variable object.
     916           0 : class VarInit : public TypedInit {
     917             :   Init *VarName;
     918             : 
     919             :   explicit VarInit(Init *VN, RecTy *T)
     920      637882 :       : TypedInit(IK_VarInit, T), VarName(VN) {}
     921             : 
     922             : public:
     923             :   VarInit(const VarInit &) = delete;
     924             :   VarInit &operator=(const VarInit &) = delete;
     925             : 
     926             :   static bool classof(const Init *I) {
     927    16265842 :     return I->getKind() == IK_VarInit;
     928             :   }
     929             : 
     930             :   static VarInit *get(StringRef VN, RecTy *T);
     931             :   static VarInit *get(Init *VN, RecTy *T);
     932             : 
     933             :   StringRef getName() const;
     934             :   Init *getNameInit() const { return VarName; }
     935             : 
     936             :   std::string getNameInitAsString() const {
     937             :     return getNameInit()->getAsUnquotedString();
     938             :   }
     939             : 
     940             :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
     941             :                                     unsigned Elt) const override;
     942             : 
     943             :   RecTy *getFieldType(StringInit *FieldName) const override;
     944             :   Init *getFieldInit(Record &R, const RecordVal *RV,
     945             :                      StringInit *FieldName) const override;
     946             : 
     947             :   /// This method is used by classes that refer to other
     948             :   /// variables which may not be defined at the time they expression is formed.
     949             :   /// If a value is set for the variable later, this method will be called on
     950             :   /// users of the value to allow the value to propagate out.
     951             :   ///
     952             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     953             : 
     954             :   Init *getBit(unsigned Bit) const override;
     955             : 
     956      988614 :   std::string getAsString() const override { return getName(); }
     957             : };
     958             : 
     959             : /// Opcode{0} - Represent access to one bit of a variable or field.
     960           0 : class VarBitInit : public Init {
     961             :   TypedInit *TI;
     962             :   unsigned Bit;
     963             : 
     964      843296 :   VarBitInit(TypedInit *T, unsigned B) : Init(IK_VarBitInit), TI(T), Bit(B) {
     965             :     assert(T->getType() &&
     966             :            (isa<IntRecTy>(T->getType()) ||
     967             :             (isa<BitsRecTy>(T->getType()) &&
     968             :              cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
     969             :            "Illegal VarBitInit expression!");
     970             :   }
     971             : 
     972             : public:
     973             :   VarBitInit(const VarBitInit &) = delete;
     974             :   VarBitInit &operator=(const VarBitInit &) = delete;
     975             : 
     976             :   static bool classof(const Init *I) {
     977             :     return I->getKind() == IK_VarBitInit;
     978             :   }
     979             : 
     980             :   static VarBitInit *get(TypedInit *T, unsigned B);
     981             : 
     982             :   Init *convertInitializerTo(RecTy *Ty) const override;
     983             : 
     984   273934290 :   Init *getBitVar() const override { return TI; }
     985    43964481 :   unsigned getBitNum() const override { return Bit; }
     986             : 
     987             :   std::string getAsString() const override;
     988             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
     989             : 
     990           0 :   Init *getBit(unsigned B) const override {
     991             :     assert(B < 1 && "Bit index out of range!");
     992           0 :     return const_cast<VarBitInit*>(this);
     993             :   }
     994             : };
     995             : 
     996             : /// List[4] - Represent access to one element of a var or
     997             : /// field.
     998           0 : class VarListElementInit : public TypedInit {
     999             :   TypedInit *TI;
    1000             :   unsigned Element;
    1001             : 
    1002             :   VarListElementInit(TypedInit *T, unsigned E)
    1003        2232 :       : TypedInit(IK_VarListElementInit,
    1004             :                   cast<ListRecTy>(T->getType())->getElementType()),
    1005        6696 :         TI(T), Element(E) {
    1006             :     assert(T->getType() && isa<ListRecTy>(T->getType()) &&
    1007             :            "Illegal VarBitInit expression!");
    1008             :   }
    1009             : 
    1010             : public:
    1011             :   VarListElementInit(const VarListElementInit &) = delete;
    1012             :   VarListElementInit &operator=(const VarListElementInit &) = delete;
    1013             : 
    1014             :   static bool classof(const Init *I) {
    1015             :     return I->getKind() == IK_VarListElementInit;
    1016             :   }
    1017             : 
    1018             :   static VarListElementInit *get(TypedInit *T, unsigned E);
    1019             : 
    1020             :   TypedInit *getVariable() const { return TI; }
    1021             :   unsigned getElementNum() const { return Element; }
    1022             : 
    1023             :   /// This method is used to implement
    1024             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
    1025             :   /// now, we return the resolved value, otherwise we return null.
    1026             :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
    1027             :                                     unsigned Elt) const override;
    1028             : 
    1029             :   std::string getAsString() const override;
    1030             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
    1031             : 
    1032             :   Init *getBit(unsigned Bit) const override;
    1033             : };
    1034             : 
    1035             : /// AL - Represent a reference to a 'def' in the description
    1036           0 : class DefInit : public TypedInit {
    1037             :   friend class Record;
    1038             : 
    1039             :   Record *Def;
    1040             : 
    1041     1407060 :   DefInit(Record *D, RecordRecTy *T) : TypedInit(IK_DefInit, T), Def(D) {}
    1042             : 
    1043             : public:
    1044             :   DefInit(const DefInit &) = delete;
    1045             :   DefInit &operator=(const DefInit &) = delete;
    1046             : 
    1047             :   static bool classof(const Init *I) {
    1048    10703951 :     return I->getKind() == IK_DefInit;
    1049             :   }
    1050             : 
    1051             :   static DefInit *get(Record*);
    1052             : 
    1053             :   Init *convertInitializerTo(RecTy *Ty) const override;
    1054             : 
    1055             :   Record *getDef() const { return Def; }
    1056             : 
    1057             :   //virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);
    1058             : 
    1059             :   RecTy *getFieldType(StringInit *FieldName) const override;
    1060             :   Init *getFieldInit(Record &R, const RecordVal *RV,
    1061             :                      StringInit *FieldName) const override;
    1062             : 
    1063             :   std::string getAsString() const override;
    1064             : 
    1065           0 :   Init *getBit(unsigned Bit) const override {
    1066           0 :     llvm_unreachable("Illegal bit reference off def");
    1067             :   }
    1068             : 
    1069             :   /// This method is used to implement
    1070             :   /// VarListElementInit::resolveReferences.  If the list element is resolvable
    1071             :   /// now, we return the resolved value, otherwise we return null.
    1072           0 :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
    1073             :                                     unsigned Elt) const override {
    1074           0 :     llvm_unreachable("Illegal element reference off def");
    1075             :   }
    1076             : };
    1077             : 
    1078             : /// X.Y - Represent a reference to a subfield of a variable
    1079           0 : class FieldInit : public TypedInit {
    1080             :   Init *Rec;                // Record we are referring to
    1081             :   StringInit *FieldName;    // Field we are accessing
    1082             : 
    1083             :   FieldInit(Init *R, StringInit *FN)
    1084      163162 :       : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
    1085             :     assert(getType() && "FieldInit with non-record type!");
    1086             :   }
    1087             : 
    1088             : public:
    1089             :   FieldInit(const FieldInit &) = delete;
    1090             :   FieldInit &operator=(const FieldInit &) = delete;
    1091             : 
    1092             :   static bool classof(const Init *I) {
    1093             :     return I->getKind() == IK_FieldInit;
    1094             :   }
    1095             : 
    1096             :   static FieldInit *get(Init *R, StringInit *FN);
    1097             : 
    1098             :   Init *getBit(unsigned Bit) const override;
    1099             : 
    1100             :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
    1101             :                                     unsigned Elt) const override;
    1102             : 
    1103             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
    1104             : 
    1105         562 :   std::string getAsString() const override {
    1106        2810 :     return Rec->getAsString() + "." + FieldName->getValue().str();
    1107             :   }
    1108             : };
    1109             : 
    1110             : /// (v a, b) - Represent a DAG tree value.  DAG inits are required
    1111             : /// to have at least one value then a (possibly empty) list of arguments.  Each
    1112             : /// argument can have a name associated with it.
    1113           0 : class DagInit final : public TypedInit, public FoldingSetNode,
    1114             :                       public TrailingObjects<DagInit, Init *, StringInit *> {
    1115             :   friend TrailingObjects;
    1116             : 
    1117             :   Init *Val;
    1118             :   StringInit *ValName;
    1119             :   unsigned NumArgs;
    1120             :   unsigned NumArgNames;
    1121             : 
    1122             :   DagInit(Init *V, StringInit *VN, unsigned NumArgs, unsigned NumArgNames)
    1123     4358696 :       : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
    1124     6538044 :         NumArgs(NumArgs), NumArgNames(NumArgNames) {}
    1125             : 
    1126    17362671 :   size_t numTrailingObjects(OverloadToken<Init *>) const { return NumArgs; }
    1127             : 
    1128             : public:
    1129             :   DagInit(const DagInit &) = delete;
    1130             :   DagInit &operator=(const DagInit &) = delete;
    1131             : 
    1132             :   static bool classof(const Init *I) {
    1133     1079762 :     return I->getKind() == IK_DagInit;
    1134             :   }
    1135             : 
    1136             :   static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
    1137             :                       ArrayRef<StringInit*> NameRange);
    1138             :   static DagInit *get(Init *V, StringInit *VN,
    1139             :                       ArrayRef<std::pair<Init*, StringInit*>> Args);
    1140             : 
    1141             :   void Profile(FoldingSetNodeID &ID) const;
    1142             : 
    1143             :   Init *convertInitializerTo(RecTy *Ty) const override;
    1144             : 
    1145             :   Init *getOperator() const { return Val; }
    1146             : 
    1147             :   StringInit *getName() const { return ValName; }
    1148             : 
    1149             :   StringRef getNameStr() const {
    1150        1101 :     return ValName ? ValName->getValue() : StringRef();
    1151             :   }
    1152             : 
    1153             :   unsigned getNumArgs() const { return NumArgs; }
    1154             : 
    1155             :   Init *getArg(unsigned Num) const {
    1156             :     assert(Num < NumArgs && "Arg number out of range!");
    1157     4056029 :     return getTrailingObjects<Init *>()[Num];
    1158             :   }
    1159             : 
    1160             :   StringInit *getArgName(unsigned Num) const {
    1161             :     assert(Num < NumArgNames && "Arg number out of range!");
    1162     3175847 :     return getTrailingObjects<StringInit *>()[Num];
    1163             :   }
    1164             : 
    1165             :   StringRef getArgNameStr(unsigned Num) const {
    1166     2997278 :     StringInit *Init = getArgName(Num);
    1167     2944109 :     return Init ? Init->getValue() : StringRef();
    1168             :   }
    1169             : 
    1170             :   ArrayRef<Init *> getArgs() const {
    1171    86098455 :     return makeArrayRef(getTrailingObjects<Init *>(), NumArgs);
    1172             :   }
    1173             : 
    1174             :   ArrayRef<StringInit *> getArgNames() const {
    1175     9269355 :     return makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames);
    1176             :   }
    1177             : 
    1178             :   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
    1179             : 
    1180             :   std::string getAsString() const override;
    1181             : 
    1182             :   using const_arg_iterator = SmallVectorImpl<Init*>::const_iterator;
    1183             :   using const_name_iterator = SmallVectorImpl<StringInit*>::const_iterator;
    1184             : 
    1185       31897 :   inline const_arg_iterator  arg_begin() const { return getArgs().begin(); }
    1186       48444 :   inline const_arg_iterator  arg_end  () const { return getArgs().end(); }
    1187             : 
    1188    28643476 :   inline size_t              arg_size () const { return NumArgs; }
    1189             :   inline bool                arg_empty() const { return NumArgs == 0; }
    1190             : 
    1191             :   inline const_name_iterator name_begin() const { return getArgNames().begin();}
    1192             :   inline const_name_iterator name_end  () const { return getArgNames().end(); }
    1193             : 
    1194             :   inline size_t              name_size () const { return NumArgNames; }
    1195             :   inline bool                name_empty() const { return NumArgNames == 0; }
    1196             : 
    1197           0 :   Init *getBit(unsigned Bit) const override {
    1198           0 :     llvm_unreachable("Illegal bit reference off dag");
    1199             :   }
    1200             : 
    1201           0 :   Init *resolveListElementReference(Record &R, const RecordVal *RV,
    1202             :                                     unsigned Elt) const override {
    1203           0 :     llvm_unreachable("Illegal element reference off dag");
    1204             :   }
    1205             : };
    1206             : 
    1207             : //===----------------------------------------------------------------------===//
    1208             : //  High-Level Classes
    1209             : //===----------------------------------------------------------------------===//
    1210             : 
    1211             : class RecordVal {
    1212             :   friend class Record;
    1213             : 
    1214             :   Init *Name;
    1215             :   PointerIntPair<RecTy *, 1, bool> TyAndPrefix;
    1216             :   Init *Value;
    1217             : 
    1218             : public:
    1219             :   RecordVal(Init *N, RecTy *T, bool P);
    1220             : 
    1221             :   StringRef getName() const;
    1222             :   Init *getNameInit() const { return Name; }
    1223             : 
    1224             :   std::string getNameInitAsString() const {
    1225        2250 :     return getNameInit()->getAsUnquotedString();
    1226             :   }
    1227             : 
    1228     4064980 :   bool getPrefix() const { return TyAndPrefix.getInt(); }
    1229   935544964 :   RecTy *getType() const { return TyAndPrefix.getPointer(); }
    1230             :   Init *getValue() const { return Value; }
    1231             : 
    1232             :   bool setValue(Init *V) {
    1233   460348102 :     if (V) {
    1234   920696204 :       Value = V->convertInitializerTo(getType());
    1235   460294410 :       return Value == nullptr;
    1236             :     }
    1237           0 :     Value = nullptr;
    1238             :     return false;
    1239             :   }
    1240             : 
    1241             :   void dump() const;
    1242             :   void print(raw_ostream &OS, bool PrintSem = true) const;
    1243             : };
    1244             : 
    1245        2081 : inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
    1246        2081 :   RV.print(OS << "  ");
    1247        2081 :   return OS;
    1248             : }
    1249             : 
    1250    14382510 : class Record {
    1251             :   static unsigned LastID;
    1252             : 
    1253             :   Init *Name;
    1254             :   // Location where record was instantiated, followed by the location of
    1255             :   // multiclass prototypes used.
    1256             :   SmallVector<SMLoc, 4> Locs;
    1257             :   SmallVector<Init *, 0> TemplateArgs;
    1258             :   SmallVector<RecordVal, 0> Values;
    1259             :   SmallVector<std::pair<Record *, SMRange>, 0> SuperClasses;
    1260             : 
    1261             :   // Tracks Record instances. Not owned by Record.
    1262             :   RecordKeeper &TrackedRecords;
    1263             : 
    1264             :   DefInit *TheInit = nullptr;
    1265             : 
    1266             :   // Unique record ID.
    1267             :   unsigned ID;
    1268             : 
    1269             :   bool IsAnonymous;
    1270             : 
    1271             :   // Class-instance values can be used by other defs.  For example, Struct<i>
    1272             :   // is used here as a template argument to another class:
    1273             :   //
    1274             :   //   multiclass MultiClass<int i> {
    1275             :   //     def Def : Class<Struct<i>>;
    1276             :   //
    1277             :   // These need to get fully resolved before instantiating any other
    1278             :   // definitions that use them (e.g. Def).  However, inside a multiclass they
    1279             :   // can't be immediately resolved so we mark them ResolveFirst to fully
    1280             :   // resolve them later as soon as the multiclass is instantiated.
    1281             :   bool ResolveFirst = false;
    1282             : 
    1283             :   void init();
    1284             :   void checkName();
    1285             : 
    1286             : public:
    1287             :   // Constructs a record.
    1288     2828488 :   explicit Record(Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
    1289     2828488 :                   bool Anonymous = false) :
    1290             :     Name(N), Locs(locs.begin(), locs.end()), TrackedRecords(records),
    1291    16970928 :     ID(LastID++), IsAnonymous(Anonymous) {
    1292     2828488 :     init();
    1293     2828488 :   }
    1294             : 
    1295             :   explicit Record(StringRef N, ArrayRef<SMLoc> locs, RecordKeeper &records,
    1296             :                   bool Anonymous = false)
    1297      179761 :     : Record(StringInit::get(N), locs, records, Anonymous) {}
    1298             : 
    1299             :   // When copy-constructing a Record, we must still guarantee a globally unique
    1300             :   // ID number.  Don't copy TheInit either since it's owned by the original
    1301             :   // record. All other fields can be copied normally.
    1302       60524 :   Record(const Record &O) :
    1303       60524 :     Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
    1304             :     Values(O.Values), SuperClasses(O.SuperClasses),
    1305      121048 :     TrackedRecords(O.TrackedRecords), ID(LastID++),
    1306      423668 :     IsAnonymous(O.IsAnonymous), ResolveFirst(O.ResolveFirst) { }
    1307             : 
    1308       16277 :   static unsigned getNewUID() { return LastID++; }
    1309             : 
    1310             :   unsigned getID() const { return ID; }
    1311             : 
    1312             :   StringRef getName() const;
    1313             : 
    1314             :   Init *getNameInit() const {
    1315             :     return Name;
    1316             :   }
    1317             : 
    1318             :   const std::string getNameInitAsString() const {
    1319     2792054 :     return getNameInit()->getAsUnquotedString();
    1320             :   }
    1321             : 
    1322             :   void setName(Init *Name);      // Also updates RecordKeeper.
    1323             : 
    1324     2826882 :   ArrayRef<SMLoc> getLoc() const { return Locs; }
    1325             : 
    1326             :   /// get the corresponding DefInit.
    1327             :   DefInit *getDefInit();
    1328             : 
    1329             :   ArrayRef<Init *> getTemplateArgs() const {
    1330    19977872 :     return TemplateArgs;
    1331             :   }
    1332             : 
    1333     7791854 :   ArrayRef<RecordVal> getValues() const { return Values; }
    1334             : 
    1335             :   ArrayRef<std::pair<Record *, SMRange>>  getSuperClasses() const {
    1336     9408414 :     return SuperClasses;
    1337             :   }
    1338             : 
    1339             :   bool isTemplateArg(Init *Name) const {
    1340    28327956 :     for (Init *TA : TemplateArgs)
    1341     3960295 :       if (TA == Name) return true;
    1342             :     return false;
    1343             :   }
    1344             : 
    1345             :   const RecordVal *getValue(const Init *Name) const {
    1346 19417463075 :     for (const RecordVal &Val : Values)
    1347 18591414343 :       if (Val.Name == Name) return &Val;
    1348             :     return nullptr;
    1349             :   }
    1350             : 
    1351             :   const RecordVal *getValue(StringRef Name) const {
    1352    86211636 :     return getValue(StringInit::get(Name));
    1353             :   }
    1354             : 
    1355             :   RecordVal *getValue(const Init *Name) {
    1356   322383972 :     return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
    1357             :   }
    1358             : 
    1359     2443910 :   RecordVal *getValue(StringRef Name) {
    1360     2443910 :     return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
    1361             :   }
    1362             : 
    1363             :   void addTemplateArg(Init *Name) {
    1364             :     assert(!isTemplateArg(Name) && "Template arg already defined!");
    1365      306680 :     TemplateArgs.push_back(Name);
    1366             :   }
    1367             : 
    1368    86571711 :   void addValue(const RecordVal &RV) {
    1369             :     assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
    1370    86571711 :     Values.push_back(RV);
    1371   173143422 :     if (Values.size() > 1)
    1372             :       // Keep NAME at the end of the list.  It makes record dumps a
    1373             :       // bit prettier and allows TableGen tests to be written more
    1374             :       // naturally.  Tests can use CHECK-NEXT to look for Record
    1375             :       // fields they expect to see after a def.  They can't do that if
    1376             :       // NAME is the first Record field.
    1377   418716115 :       std::swap(Values[Values.size() - 2], Values[Values.size() - 1]);
    1378    86571711 :   }
    1379             : 
    1380     8315521 :   void removeValue(Init *Name) {
    1381   209841169 :     for (unsigned i = 0, e = Values.size(); i != e; ++i)
    1382   403051296 :       if (Values[i].getNameInit() == Name) {
    1383    16631042 :         Values.erase(Values.begin()+i);
    1384     8315521 :         return;
    1385             :       }
    1386           0 :     llvm_unreachable("Cannot remove an entry that does not exist!");
    1387             :   }
    1388             : 
    1389             :   void removeValue(StringRef Name) {
    1390             :     removeValue(StringInit::get(Name));
    1391             :   }
    1392             : 
    1393             :   bool isSubClassOf(const Record *R) const {
    1394   486200674 :     for (const auto &SCPair : SuperClasses)
    1395   229346288 :       if (SCPair.first == R)
    1396             :         return true;
    1397             :     return false;
    1398             :   }
    1399             : 
    1400    60833369 :   bool isSubClassOf(StringRef Name) const {
    1401   285221512 :     for (const auto &SCPair : SuperClasses) {
    1402   245724839 :       if (const auto *SI = dyn_cast<StringInit>(SCPair.first->getNameInit())) {
    1403             :         if (SI->getValue() == Name)
    1404             :           return true;
    1405     2432295 :       } else if (SCPair.first->getNameInitAsString() == Name) {
    1406             :         return true;
    1407             :       }
    1408             :     }
    1409             :     return false;
    1410             :   }
    1411             : 
    1412             :   void addSuperClass(Record *R, SMRange Range) {
    1413             :     assert(!isSubClassOf(R) && "Already subclassing record!");
    1414    24753538 :     SuperClasses.push_back(std::make_pair(R, Range));
    1415             :   }
    1416             : 
    1417             :   /// If there are any field references that refer to fields
    1418             :   /// that have been filled in, we can propagate the values now.
    1419     2562741 :   void resolveReferences() { resolveReferencesTo(nullptr); }
    1420             : 
    1421             :   /// If anything in this record refers to RV, replace the
    1422             :   /// reference to RV with the RHS of RV.  If RV is null, we resolve all
    1423             :   /// possible references.
    1424             :   void resolveReferencesTo(const RecordVal *RV);
    1425             : 
    1426             :   RecordKeeper &getRecords() const {
    1427             :     return TrackedRecords;
    1428             :   }
    1429             : 
    1430             :   bool isAnonymous() const {
    1431             :     return IsAnonymous;
    1432             :   }
    1433             : 
    1434             :   bool isResolveFirst() const {
    1435             :     return ResolveFirst;
    1436             :   }
    1437             : 
    1438             :   void setResolveFirst(bool b) {
    1439       11823 :     ResolveFirst = b;
    1440             :   }
    1441             : 
    1442             :   void print(raw_ostream &OS) const;
    1443             :   void dump() const;
    1444             : 
    1445             :   //===--------------------------------------------------------------------===//
    1446             :   // High-level methods useful to tablegen back-ends
    1447             :   //
    1448             : 
    1449             :   /// Return the initializer for a value with the specified name,
    1450             :   /// or throw an exception if the field does not exist.
    1451             :   Init *getValueInit(StringRef FieldName) const;
    1452             : 
    1453             :   /// Return true if the named field is unset.
    1454             :   bool isValueUnset(StringRef FieldName) const {
    1455      182762 :     return isa<UnsetInit>(getValueInit(FieldName));
    1456             :   }
    1457             : 
    1458             :   /// This method looks up the specified field and returns
    1459             :   /// its value as a string, throwing an exception if the field does not exist
    1460             :   /// or if the value is not a string.
    1461             :   StringRef getValueAsString(StringRef FieldName) const;
    1462             : 
    1463             :   /// This method looks up the specified field and returns
    1464             :   /// its value as a BitsInit, throwing an exception if the field does not exist
    1465             :   /// or if the value is not the right type.
    1466             :   BitsInit *getValueAsBitsInit(StringRef FieldName) const;
    1467             : 
    1468             :   /// This method looks up the specified field and returns
    1469             :   /// its value as a ListInit, throwing an exception if the field does not exist
    1470             :   /// or if the value is not the right type.
    1471             :   ListInit *getValueAsListInit(StringRef FieldName) const;
    1472             : 
    1473             :   /// This method looks up the specified field and
    1474             :   /// returns its value as a vector of records, throwing an exception if the
    1475             :   /// field does not exist or if the value is not the right type.
    1476             :   std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
    1477             : 
    1478             :   /// This method looks up the specified field and
    1479             :   /// returns its value as a vector of integers, throwing an exception if the
    1480             :   /// field does not exist or if the value is not the right type.
    1481             :   std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
    1482             : 
    1483             :   /// This method looks up the specified field and
    1484             :   /// returns its value as a vector of strings, throwing an exception if the
    1485             :   /// field does not exist or if the value is not the right type.
    1486             :   std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
    1487             : 
    1488             :   /// This method looks up the specified field and returns its
    1489             :   /// value as a Record, throwing an exception if the field does not exist or if
    1490             :   /// the value is not the right type.
    1491             :   Record *getValueAsDef(StringRef FieldName) const;
    1492             : 
    1493             :   /// This method looks up the specified field and returns its
    1494             :   /// value as a bit, throwing an exception if the field does not exist or if
    1495             :   /// the value is not the right type.
    1496             :   bool getValueAsBit(StringRef FieldName) const;
    1497             : 
    1498             :   /// This method looks up the specified field and
    1499             :   /// returns its value as a bit. If the field is unset, sets Unset to true and
    1500             :   /// returns false.
    1501             :   bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
    1502             : 
    1503             :   /// This method looks up the specified field and returns its
    1504             :   /// value as an int64_t, throwing an exception if the field does not exist or
    1505             :   /// if the value is not the right type.
    1506             :   int64_t getValueAsInt(StringRef FieldName) const;
    1507             : 
    1508             :   /// This method looks up the specified field and returns its
    1509             :   /// value as an Dag, throwing an exception if the field does not exist or if
    1510             :   /// the value is not the right type.
    1511             :   DagInit *getValueAsDag(StringRef FieldName) const;
    1512             : };
    1513             : 
    1514             : raw_ostream &operator<<(raw_ostream &OS, const Record &R);
    1515             : 
    1516       21304 : struct MultiClass {
    1517             :   Record Rec;  // Placeholder for template args and Name.
    1518             :   using RecordVector = std::vector<std::unique_ptr<Record>>;
    1519             :   RecordVector DefPrototypes;
    1520             : 
    1521             :   void dump() const;
    1522             : 
    1523       21304 :   MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records) :
    1524       63912 :     Rec(Name, Loc, Records) {}
    1525             : };
    1526             : 
    1527        1650 : class RecordKeeper {
    1528             :   using RecordMap = std::map<std::string, std::unique_ptr<Record>>;
    1529             :   RecordMap Classes, Defs;
    1530             : 
    1531             : public:
    1532           2 :   const RecordMap &getClasses() const { return Classes; }
    1533           1 :   const RecordMap &getDefs() const { return Defs; }
    1534             : 
    1535     3114067 :   Record *getClass(StringRef Name) const {
    1536    12456268 :     auto I = Classes.find(Name);
    1537    12160780 :     return I == Classes.end() ? nullptr : I->second.get();
    1538             :   }
    1539             : 
    1540     9703628 :   Record *getDef(StringRef Name) const {
    1541    38814512 :     auto I = Defs.find(Name);
    1542    34207454 :     return I == Defs.end() ? nullptr : I->second.get();
    1543             :   }
    1544             : 
    1545      145944 :   void addClass(std::unique_ptr<Record> R) {
    1546      583776 :     bool Ins = Classes.insert(std::make_pair(R->getName(),
    1547      291888 :                                              std::move(R))).second;
    1548             :     (void)Ins;
    1549             :     assert(Ins && "Class already exists");
    1550      145944 :   }
    1551             : 
    1552     2550665 :   void addDef(std::unique_ptr<Record> R) {
    1553    10202660 :     bool Ins = Defs.insert(std::make_pair(R->getName(),
    1554     5101330 :                                           std::move(R))).second;
    1555             :     (void)Ins;
    1556             :     assert(Ins && "Record already exists");
    1557     2550665 :   }
    1558             : 
    1559             :   //===--------------------------------------------------------------------===//
    1560             :   // High-level helper methods, useful for tablegen backends...
    1561             : 
    1562             :   /// This method returns all concrete definitions
    1563             :   /// that derive from the specified class name.  A class with the specified
    1564             :   /// name must exist.
    1565             :   std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
    1566             : 
    1567             :   void dump() const;
    1568             : };
    1569             : 
    1570             : /// Sorting predicate to sort record pointers by name.
    1571             : struct LessRecord {
    1572      493485 :   bool operator()(const Record *Rec1, const Record *Rec2) const {
    1573      493485 :     return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
    1574             :   }
    1575             : };
    1576             : 
    1577             : /// Sorting predicate to sort record pointers by their
    1578             : /// unique ID. If you just need a deterministic order, use this, since it
    1579             : /// just compares two `unsigned`; the other sorting predicates require
    1580             : /// string manipulation.
    1581             : struct LessRecordByID {
    1582             :   bool operator()(const Record *LHS, const Record *RHS) const {
    1583   105355757 :     return LHS->getID() < RHS->getID();
    1584             :   }
    1585             : };
    1586             : 
    1587             : /// Sorting predicate to sort record pointers by their
    1588             : /// name field.
    1589             : struct LessRecordFieldName {
    1590       11648 :   bool operator()(const Record *Rec1, const Record *Rec2) const {
    1591       23296 :     return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
    1592             :   }
    1593             : };
    1594             : 
    1595             : struct LessRecordRegister {
    1596    30698153 :   static bool ascii_isdigit(char x) { return x >= '0' && x <= '9'; }
    1597             : 
    1598     3166096 :   struct RecordParts {
    1599             :     SmallVector<std::pair< bool, StringRef>, 4> Parts;
    1600             : 
    1601     3166096 :     RecordParts(StringRef Rec) {
    1602     1583048 :       if (Rec.empty())
    1603             :         return;
    1604             : 
    1605     1583048 :       size_t Len = 0;
    1606     1583048 :       const char *Start = Rec.data();
    1607     1583048 :       const char *Curr = Start;
    1608     3166096 :       bool isDigitPart = ascii_isdigit(Curr[0]);
    1609    24449679 :       for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
    1610    45733262 :         bool isDigit = ascii_isdigit(Curr[I]);
    1611    22866631 :         if (isDigit != isDigitPart) {
    1612    12496948 :           Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
    1613     6248474 :           Len = 0;
    1614     6248474 :           Start = &Curr[I];
    1615    12496948 :           isDigitPart = ascii_isdigit(Curr[I]);
    1616             :         }
    1617             :       }
    1618             :       // Push the last part.
    1619     3166096 :       Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
    1620             :     }
    1621             : 
    1622     3166096 :     size_t size() { return Parts.size(); }
    1623             : 
    1624             :     std::pair<bool, StringRef> getPart(size_t i) {
    1625             :       assert (i < Parts.size() && "Invalid idx!");
    1626     8177448 :       return Parts[i];
    1627             :     }
    1628             :   };
    1629             : 
    1630      791524 :   bool operator()(const Record *Rec1, const Record *Rec2) const {
    1631     1583048 :     RecordParts LHSParts(StringRef(Rec1->getName()));
    1632     1583048 :     RecordParts RHSParts(StringRef(Rec2->getName()));
    1633             : 
    1634      791524 :     size_t LHSNumParts = LHSParts.size();
    1635      791524 :     size_t RHSNumParts = RHSParts.size();
    1636             :     assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
    1637             : 
    1638      791524 :     if (LHSNumParts != RHSNumParts)
    1639      141583 :       return LHSNumParts < RHSNumParts;
    1640             : 
    1641             :     // We expect the registers to be of the form [_a-zA-Z]+([0-9]*[_a-zA-Z]*)*.
    1642     3398307 :     for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
    1643     1585937 :       std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
    1644     1585937 :       std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
    1645             :       // Expect even part to always be alpha.
    1646             :       assert (LHSPart.first == false && RHSPart.first == false &&
    1647             :               "Expected both parts to be alpha.");
    1648       40667 :       if (int Res = LHSPart.second.compare(RHSPart.second))
    1649      211754 :         return Res < 0;
    1650             :     }
    1651      483047 :     for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
    1652      458425 :       std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
    1653      458425 :       std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
    1654             :       // Expect odd part to always be numeric.
    1655             :       assert (LHSPart.first == true && RHSPart.first == true &&
    1656             :               "Expected both parts to be numeric.");
    1657      458425 :       if (LHSPart.second.size() != RHSPart.second.size())
    1658      519685 :         return LHSPart.second.size() < RHSPart.second.size();
    1659             : 
    1660             :       unsigned LHSVal, RHSVal;
    1661             : 
    1662      374735 :       bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
    1663             :       assert(!LHSFailed && "Unable to convert LHS to integer.");
    1664      374735 :       bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
    1665             :       assert(!RHSFailed && "Unable to convert RHS to integer.");
    1666             : 
    1667      374735 :       if (LHSVal != RHSVal)
    1668      352305 :         return LHSVal < RHSVal;
    1669             :     }
    1670             :     return LHSNumParts < RHSNumParts;
    1671             :   }
    1672             : };
    1673             : 
    1674             : raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
    1675             : 
    1676             : /// Return an Init with a qualifier prefix referring
    1677             : /// to CurRec's name.
    1678             : Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass,
    1679             :                   Init *Name, StringRef Scoper);
    1680             : 
    1681             : } // end namespace llvm
    1682             : 
    1683             : #endif // LLVM_TABLEGEN_RECORD_H

Generated by: LCOV version 1.13