LCOV - code coverage report
Current view: top level - lib/TableGen - Record.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 949 1064 89.2 %
Date: 2017-09-14 15:23:50 Functions: 128 132 97.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Record.cpp - Record implementation ---------------------------------===//
       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             : // Implement the tablegen record classes.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/ADT/ArrayRef.h"
      15             : #include "llvm/ADT/DenseMap.h"
      16             : #include "llvm/ADT/FoldingSet.h"
      17             : #include "llvm/ADT/SmallString.h"
      18             : #include "llvm/ADT/SmallVector.h"
      19             : #include "llvm/ADT/StringExtras.h"
      20             : #include "llvm/ADT/StringMap.h"
      21             : #include "llvm/ADT/StringRef.h"
      22             : #include "llvm/Support/Allocator.h"
      23             : #include "llvm/Support/Casting.h"
      24             : #include "llvm/Support/Compiler.h"
      25             : #include "llvm/Support/ErrorHandling.h"
      26             : #include "llvm/Support/SMLoc.h"
      27             : #include "llvm/Support/raw_ostream.h"
      28             : #include "llvm/TableGen/Error.h"
      29             : #include "llvm/TableGen/Record.h"
      30             : #include <cassert>
      31             : #include <cstdint>
      32             : #include <memory>
      33             : #include <string>
      34             : #include <utility>
      35             : #include <vector>
      36             : 
      37             : using namespace llvm;
      38             : 
      39         275 : static BumpPtrAllocator Allocator;
      40             : 
      41             : //===----------------------------------------------------------------------===//
      42             : //    Type implementations
      43             : //===----------------------------------------------------------------------===//
      44             : 
      45         275 : BitRecTy BitRecTy::Shared;
      46         275 : CodeRecTy CodeRecTy::Shared;
      47         275 : IntRecTy IntRecTy::Shared;
      48         275 : StringRecTy StringRecTy::Shared;
      49         275 : DagRecTy DagRecTy::Shared;
      50             : 
      51             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
      52             : LLVM_DUMP_METHOD void RecTy::dump() const { print(errs()); }
      53             : #endif
      54             : 
      55     1129625 : ListRecTy *RecTy::getListTy() {
      56     1129625 :   if (!ListTy)
      57      324432 :     ListTy = new(Allocator) ListRecTy(this);
      58     1129625 :   return ListTy;
      59             : }
      60             : 
      61    16315423 : bool RecTy::typeIsConvertibleTo(const RecTy *RHS) const {
      62             :   assert(RHS && "NULL pointer");
      63    16315423 :   return Kind == RHS->getRecTyKind();
      64             : }
      65             : 
      66     7256629 : bool BitRecTy::typeIsConvertibleTo(const RecTy *RHS) const{
      67     7256629 :   if (RecTy::typeIsConvertibleTo(RHS) || RHS->getRecTyKind() == IntRecTyKind)
      68             :     return true;
      69           0 :   if (const BitsRecTy *BitsTy = dyn_cast<BitsRecTy>(RHS))
      70           0 :     return BitsTy->getNumBits() == 1;
      71             :   return false;
      72             : }
      73             : 
      74     1127522 : BitsRecTy *BitsRecTy::get(unsigned Sz) {
      75     1127690 :   static std::vector<BitsRecTy*> Shared;
      76     2255044 :   if (Sz >= Shared.size())
      77         325 :     Shared.resize(Sz + 1);
      78     2255044 :   BitsRecTy *&Ty = Shared[Sz];
      79     1127522 :   if (!Ty)
      80        4912 :     Ty = new(Allocator) BitsRecTy(Sz);
      81     1127522 :   return Ty;
      82             : }
      83             : 
      84         184 : std::string BitsRecTy::getAsString() const {
      85         552 :   return "bits<" + utostr(Size) + ">";
      86             : }
      87             : 
      88     6854380 : bool BitsRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
      89     6854380 :   if (RecTy::typeIsConvertibleTo(RHS)) //argument and the sender are same type
      90      156115 :     return cast<BitsRecTy>(RHS)->Size == Size;
      91     6698265 :   RecTyKind kind = RHS->getRecTyKind();
      92     6698265 :   return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
      93             : }
      94             : 
      95     4832651 : bool IntRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
      96     4832651 :   RecTyKind kind = RHS->getRecTyKind();
      97     4832651 :   return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
      98             : }
      99             : 
     100      118672 : std::string StringRecTy::getAsString() const {
     101      356016 :   return "string";
     102             : }
     103             : 
     104         162 : std::string ListRecTy::getAsString() const {
     105         486 :   return "list<" + Ty->getAsString() + ">";
     106             : }
     107             : 
     108        1348 : bool ListRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
     109        1348 :   if (const auto *ListTy = dyn_cast<ListRecTy>(RHS))
     110        1348 :     return Ty->typeIsConvertibleTo(ListTy->getElementType());
     111             :   return false;
     112             : }
     113             : 
     114         142 : std::string DagRecTy::getAsString() const {
     115         426 :   return "dag";
     116             : }
     117             : 
     118      147951 : RecordRecTy *RecordRecTy::get(Record *R) {
     119      295902 :   return dyn_cast<RecordRecTy>(R->getDefInit()->getType());
     120             : }
     121             : 
     122          81 : std::string RecordRecTy::getAsString() const {
     123         162 :   return Rec->getName();
     124             : }
     125             : 
     126     6663058 : bool RecordRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
     127     6663058 :   const RecordRecTy *RTy = dyn_cast<RecordRecTy>(RHS);
     128             :   if (!RTy)
     129             :     return false;
     130             : 
     131     9714459 :   if (RTy->getRecord() == Rec || Rec->isSubClassOf(RTy->getRecord()))
     132             :     return true;
     133             : 
     134     2846894 :   for (const auto &SCPair : RTy->getRecord()->getSuperClasses())
     135     1897004 :     if (Rec->isSubClassOf(SCPair.first))
     136             :       return true;
     137             : 
     138             :   return false;
     139             : }
     140             : 
     141     1689554 : RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
     142     1689554 :   if (T1->typeIsConvertibleTo(T2))
     143             :     return T2;
     144        2116 :   if (T2->typeIsConvertibleTo(T1))
     145             :     return T1;
     146             : 
     147             :   // If one is a Record type, check superclasses
     148           0 :   if (RecordRecTy *RecTy1 = dyn_cast<RecordRecTy>(T1)) {
     149             :     // See if T2 inherits from a type T1 also inherits from
     150           0 :     for (const auto &SuperPair1 : RecTy1->getRecord()->getSuperClasses()) {
     151           0 :       RecordRecTy *SuperRecTy1 = RecordRecTy::get(SuperPair1.first);
     152           0 :       RecTy *NewType1 = resolveTypes(SuperRecTy1, T2);
     153           0 :       if (NewType1)
     154             :         return NewType1;
     155             :     }
     156             :   }
     157           0 :   if (RecordRecTy *RecTy2 = dyn_cast<RecordRecTy>(T2)) {
     158             :     // See if T1 inherits from a type T2 also inherits from
     159           0 :     for (const auto &SuperPair2 : RecTy2->getRecord()->getSuperClasses()) {
     160           0 :       RecordRecTy *SuperRecTy2 = RecordRecTy::get(SuperPair2.first);
     161           0 :       RecTy *NewType2 = resolveTypes(T1, SuperRecTy2);
     162           0 :       if (NewType2)
     163             :         return NewType2;
     164             :     }
     165             :   }
     166             :   return nullptr;
     167             : }
     168             : 
     169             : //===----------------------------------------------------------------------===//
     170             : //    Initializer implementations
     171             : //===----------------------------------------------------------------------===//
     172             : 
     173           0 : void Init::anchor() {}
     174             : 
     175             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     176             : LLVM_DUMP_METHOD void Init::dump() const { return print(errs()); }
     177             : #endif
     178             : 
     179     4149733 : UnsetInit *UnsetInit::get() {
     180     4150008 :   static UnsetInit TheInit;
     181     4149733 :   return &TheInit;
     182             : }
     183             : 
     184    42033356 : Init *UnsetInit::convertInitializerTo(RecTy *Ty) const {
     185      100662 :   if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
     186      301986 :     SmallVector<Init *, 16> NewBits(BRT->getNumBits());
     187             : 
     188      859152 :     for (unsigned i = 0; i != BRT->getNumBits(); ++i)
     189     1516980 :       NewBits[i] = UnsetInit::get();
     190             : 
     191      100662 :     return BitsInit::get(NewBits);
     192             :   }
     193             : 
     194             :   // All other types can just be returned.
     195    41932694 :   return const_cast<UnsetInit *>(this);
     196             : }
     197             : 
     198    11607947 : BitInit *BitInit::get(bool V) {
     199    11608169 :   static BitInit True(true);
     200    11608169 :   static BitInit False(false);
     201             : 
     202    11607947 :   return V ? &True : &False;
     203             : }
     204             : 
     205   195923836 : Init *BitInit::convertInitializerTo(RecTy *Ty) const {
     206   391847672 :   if (isa<BitRecTy>(Ty))
     207   194501239 :     return const_cast<BitInit *>(this);
     208             : 
     209     2845194 :   if (isa<IntRecTy>(Ty))
     210     1422597 :     return IntInit::get(getValue());
     211             : 
     212           0 :   if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
     213             :     // Can only convert single bit.
     214           0 :     if (BRT->getNumBits() == 1)
     215           0 :       return BitsInit::get(const_cast<BitInit *>(this));
     216             :   }
     217             : 
     218             :   return nullptr;
     219             : }
     220             : 
     221             : static void
     222    20223756 : ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef<Init *> Range) {
     223    20223756 :   ID.AddInteger(Range.size());
     224             : 
     225   474334937 :   for (Init *I : Range)
     226   433887425 :     ID.AddPointer(I);
     227    20223756 : }
     228             : 
     229     7206604 : BitsInit *BitsInit::get(ArrayRef<Init *> Range) {
     230     7206772 :   static FoldingSet<BitsInit> ThePool;
     231             : 
     232    14413208 :   FoldingSetNodeID ID;
     233     7206604 :   ProfileBitsInit(ID, Range);
     234             : 
     235     7206604 :   void *IP = nullptr;
     236     6365473 :   if (BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
     237             :     return I;
     238             : 
     239     1682262 :   void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
     240      841131 :                                  alignof(BitsInit));
     241     1682262 :   BitsInit *I = new(Mem) BitsInit(Range.size());
     242     2523393 :   std::uninitialized_copy(Range.begin(), Range.end(),
     243             :                           I->getTrailingObjects<Init *>());
     244     1682262 :   ThePool.InsertNode(I, IP);
     245      841131 :   return I;
     246             : }
     247             : 
     248    13017152 : void BitsInit::Profile(FoldingSetNodeID &ID) const {
     249    39051456 :   ProfileBitsInit(ID, makeArrayRef(getTrailingObjects<Init *>(), NumBits));
     250    13017152 : }
     251             : 
     252    61779802 : Init *BitsInit::convertInitializerTo(RecTy *Ty) const {
     253   123559604 :   if (isa<BitRecTy>(Ty)) {
     254        5512 :     if (getNumBits() != 1) return nullptr; // Only accept if just one bit!
     255        5512 :     return getBit(0);
     256             :   }
     257             : 
     258   112551314 :   if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
     259             :     // If the number of bits is right, return it.  Otherwise we need to expand
     260             :     // or truncate.
     261    50777024 :     if (getNumBits() != BRT->getNumBits()) return nullptr;
     262    50777016 :     return const_cast<BitsInit *>(this);
     263             :   }
     264             : 
     265    21994532 :   if (isa<IntRecTy>(Ty)) {
     266    10997266 :     int64_t Result = 0;
     267    21205913 :     for (unsigned i = 0, e = getNumBits(); i != e; ++i)
     268    26182568 :       if (auto *Bit = dyn_cast<BitInit>(getBit(i)))
     269    10208647 :         Result |= static_cast<int64_t>(Bit->getValue()) << i;
     270             :       else
     271             :         return nullptr;
     272     5231992 :     return IntInit::get(Result);
     273             :   }
     274             : 
     275             :   return nullptr;
     276             : }
     277             : 
     278             : Init *
     279           0 : BitsInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
     280           0 :   SmallVector<Init *, 16> NewBits(Bits.size());
     281             : 
     282           0 :   for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
     283           0 :     if (Bits[i] >= getNumBits())
     284             :       return nullptr;
     285           0 :     NewBits[i] = getBit(Bits[i]);
     286             :   }
     287           0 :   return BitsInit::get(NewBits);
     288             : }
     289             : 
     290         240 : std::string BitsInit::getAsString() const {
     291         720 :   std::string Result = "{ ";
     292        1389 :   for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
     293        1149 :     if (i) Result += ", ";
     294        2298 :     if (Init *Bit = getBit(e-i-1))
     295        3447 :       Result += Bit->getAsString();
     296             :     else
     297             :       Result += "*";
     298             :   }
     299         480 :   return Result + " }";
     300             : }
     301             : 
     302             : // Fix bit initializer to preserve the behavior that bit reference from a unset
     303             : // bits initializer will resolve into VarBitInit to keep the field name and bit
     304             : // number used in targets with fixed insn length.
     305             : static Init *fixBitInit(const RecordVal *RV, Init *Before, Init *After) {
     306    88873779 :   if (RV || !isa<UnsetInit>(After))
     307             :     return After;
     308             :   return Before;
     309             : }
     310             : 
     311             : // resolveReferences - If there are any field references that refer to fields
     312             : // that have been filled in, we can propagate the values now.
     313    74272102 : Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const {
     314    74272102 :   bool Changed = false;
     315   222816306 :   SmallVector<Init *, 16> NewBits(getNumBits());
     316             : 
     317    74272102 :   Init *CachedInit = nullptr;
     318    74272102 :   Init *CachedBitVar = nullptr;
     319    74272102 :   bool CachedBitVarChanged = false;
     320             : 
     321   729494749 :   for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
     322   655222647 :     Init *CurBit = getBit(i);
     323   655222647 :     Init *CurBitVar = CurBit->getBitVar();
     324             : 
     325  1310445294 :     NewBits[i] = CurBit;
     326             : 
     327   655222647 :     if (CurBitVar == CachedBitVar) {
     328   473646841 :       if (CachedBitVarChanged) {
     329    33047470 :         Init *Bit = CachedInit->getBit(CurBit->getBitNum());
     330    99142410 :         NewBits[i] = fixBitInit(RV, CurBit, Bit);
     331             :       }
     332   473646841 :       continue;
     333             :     }
     334             :     CachedBitVar = CurBitVar;
     335             :     CachedBitVarChanged = false;
     336             : 
     337             :     Init *B;
     338             :     do {
     339   199435988 :       B = CurBitVar;
     340   199435988 :       CurBitVar = CurBitVar->resolveReferences(R, RV);
     341   199435988 :       CachedBitVarChanged |= B != CurBitVar;
     342   199435988 :       Changed |= B != CurBitVar;
     343   199435988 :     } while (B != CurBitVar);
     344   181575806 :     CachedInit = CurBitVar;
     345             : 
     346   181575806 :     if (CachedBitVarChanged) {
     347    16214866 :       Init *Bit = CurBitVar->getBit(CurBit->getBitNum());
     348    48644598 :       NewBits[i] = fixBitInit(RV, CurBit, Bit);
     349             :     }
     350             :   }
     351             : 
     352    74272102 :   if (Changed)
     353     5923560 :     return BitsInit::get(NewBits);
     354             : 
     355    68348542 :   return const_cast<BitsInit *>(this);
     356             : }
     357             : 
     358     9530019 : IntInit *IntInit::get(int64_t V) {
     359     9530269 :   static DenseMap<int64_t, IntInit*> ThePool;
     360             : 
     361     9530019 :   IntInit *&I = ThePool[V];
     362     9642367 :   if (!I) I = new(Allocator) IntInit(V);
     363     9530019 :   return I;
     364             : }
     365             : 
     366      587422 : std::string IntInit::getAsString() const {
     367      587422 :   return itostr(Value);
     368             : }
     369             : 
     370             : static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
     371             :   // For example, with NumBits == 4, we permit Values from [-7 .. 15].
     372      560408 :   return (NumBits >= sizeof(Value) * 8) ||
     373      560672 :          (Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
     374             : }
     375             : 
     376    27909197 : Init *IntInit::convertInitializerTo(RecTy *Ty) const {
     377    55818394 :   if (isa<IntRecTy>(Ty))
     378    26036266 :     return const_cast<IntInit *>(this);
     379             : 
     380     3745862 :   if (isa<BitRecTy>(Ty)) {
     381     1312299 :     int64_t Val = getValue();
     382     1312299 :     if (Val != 0 && Val != 1) return nullptr;  // Only accept 0 or 1 for a bit!
     383     1312298 :     return BitInit::get(Val != 0);
     384             :   }
     385             : 
     386     1121264 :   if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
     387      560632 :     int64_t Value = getValue();
     388             :     // Make sure this bitfield is large enough to hold the integer value.
     389      560632 :     if (!canFitInBitfield(Value, BRT->getNumBits()))
     390             :       return nullptr;
     391             : 
     392     1121262 :     SmallVector<Init *, 16> NewBits(BRT->getNumBits());
     393     4428207 :     for (unsigned i = 0; i != BRT->getNumBits(); ++i)
     394     7735152 :       NewBits[i] = BitInit::get(Value & (1LL << i));
     395             : 
     396      560631 :     return BitsInit::get(NewBits);
     397             :   }
     398             : 
     399             :   return nullptr;
     400             : }
     401             : 
     402             : Init *
     403           0 : IntInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
     404           0 :   SmallVector<Init *, 16> NewBits(Bits.size());
     405             : 
     406           0 :   for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
     407           0 :     if (Bits[i] >= 64)
     408             :       return nullptr;
     409             : 
     410           0 :     NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i]));
     411             :   }
     412           0 :   return BitsInit::get(NewBits);
     413             : }
     414             : 
     415       27917 : CodeInit *CodeInit::get(StringRef V) {
     416       28099 :   static StringMap<CodeInit*, BumpPtrAllocator &> ThePool(Allocator);
     417             : 
     418      139585 :   auto &Entry = *ThePool.insert(std::make_pair(V, nullptr)).first;
     419       27917 :   if (!Entry.second)
     420       58722 :     Entry.second = new(Allocator) CodeInit(Entry.getKey());
     421       27917 :   return Entry.second;
     422             : }
     423             : 
     424    92304529 : StringInit *StringInit::get(StringRef V) {
     425    92304804 :   static StringMap<StringInit*, BumpPtrAllocator &> ThePool(Allocator);
     426             : 
     427   461522645 :   auto &Entry = *ThePool.insert(std::make_pair(V, nullptr)).first;
     428    92304529 :   if (!Entry.second)
     429    35263629 :     Entry.second = new(Allocator) StringInit(Entry.getKey());
     430    92304529 :   return Entry.second;
     431             : }
     432             : 
     433    60967545 : Init *StringInit::convertInitializerTo(RecTy *Ty) const {
     434    60967545 :   if (isa<StringRecTy>(Ty))
     435    60229315 :     return const_cast<StringInit *>(this);
     436             : 
     437             :   return nullptr;
     438             : }
     439             : 
     440      771801 : Init *CodeInit::convertInitializerTo(RecTy *Ty) const {
     441     1543602 :   if (isa<CodeRecTy>(Ty))
     442      771801 :     return const_cast<CodeInit *>(this);
     443             : 
     444             :   return nullptr;
     445             : }
     446             : 
     447    11470643 : static void ProfileListInit(FoldingSetNodeID &ID,
     448             :                             ArrayRef<Init *> Range,
     449             :                             RecTy *EltTy) {
     450    11470643 :   ID.AddInteger(Range.size());
     451    11470643 :   ID.AddPointer(EltTy);
     452             : 
     453    43465563 :   for (Init *I : Range)
     454    20524277 :     ID.AddPointer(I);
     455    11470643 : }
     456             : 
     457     3927433 : ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
     458     3927653 :   static FoldingSet<ListInit> ThePool;
     459             : 
     460     7854866 :   FoldingSetNodeID ID;
     461     3927433 :   ProfileListInit(ID, Range, EltTy);
     462             : 
     463     3927433 :   void *IP = nullptr;
     464     2835337 :   if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
     465             :     return I;
     466             : 
     467     2184192 :   void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
     468     1092096 :                                  alignof(ListInit));
     469     2184192 :   ListInit *I = new(Mem) ListInit(Range.size(), EltTy);
     470     3276288 :   std::uninitialized_copy(Range.begin(), Range.end(),
     471             :                           I->getTrailingObjects<Init *>());
     472     2184192 :   ThePool.InsertNode(I, IP);
     473     1092096 :   return I;
     474             : }
     475             : 
     476     7543210 : void ListInit::Profile(FoldingSetNodeID &ID) const {
     477    15086420 :   RecTy *EltTy = cast<ListRecTy>(getType())->getElementType();
     478             : 
     479     7543210 :   ProfileListInit(ID, getValues(), EltTy);
     480     7543210 : }
     481             : 
     482    36042355 : Init *ListInit::convertInitializerTo(RecTy *Ty) const {
     483    36042355 :   if (getType() == Ty)
     484    17791251 :     return const_cast<ListInit*>(this);
     485             : 
     486    18251104 :   if (auto *LRT = dyn_cast<ListRecTy>(Ty)) {
     487    36502208 :     SmallVector<Init*, 8> Elements;
     488    18251104 :     Elements.reserve(getValues().size());
     489             : 
     490             :     // Verify that all of the elements of the list are subclasses of the
     491             :     // appropriate class!
     492    18251104 :     bool Changed = false;
     493    18251104 :     RecTy *ElementType = LRT->getElementType();
     494    63832155 :     for (Init *I : getValues())
     495    27329947 :       if (Init *CI = I->convertInitializerTo(ElementType)) {
     496    27329947 :         Elements.push_back(CI);
     497    27329947 :         if (CI != I)
     498           0 :           Changed = true;
     499             :       } else
     500           0 :         return nullptr;
     501             : 
     502    18251104 :     if (!Changed)
     503    18251104 :       return const_cast<ListInit*>(this);
     504           0 :     return ListInit::get(Elements, Ty);
     505             :   }
     506             : 
     507             :   return nullptr;
     508             : }
     509             : 
     510          11 : Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
     511          22 :   SmallVector<Init*, 8> Vals;
     512          11 :   Vals.reserve(Elements.size());
     513          64 :   for (unsigned Element : Elements) {
     514          42 :     if (Element >= size())
     515             :       return nullptr;
     516          42 :     Vals.push_back(getElement(Element));
     517             :   }
     518          22 :   return ListInit::get(Vals, getType());
     519             : }
     520             : 
     521     1132176 : Record *ListInit::getElementAsRecord(unsigned i) const {
     522             :   assert(i < NumValues && "List element index out of range!");
     523     2264352 :   DefInit *DI = dyn_cast<DefInit>(getElement(i));
     524             :   if (!DI)
     525           0 :     PrintFatalError("Expected record in list!");
     526     1132176 :   return DI->getDef();
     527             : }
     528             : 
     529    31348862 : Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) const {
     530    62697724 :   SmallVector<Init*, 8> Resolved;
     531    62697724 :   Resolved.reserve(size());
     532    31348862 :   bool Changed = false;
     533             : 
     534    84360249 :   for (Init *CurElt : getValues()) {
     535             :     Init *E;
     536             : 
     537             :     do {
     538    22898516 :       E = CurElt;
     539    22898516 :       CurElt = CurElt->resolveReferences(R, RV);
     540    22898516 :       Changed |= E != CurElt;
     541    22898516 :     } while (E != CurElt);
     542    21662525 :     Resolved.push_back(E);
     543             :   }
     544             : 
     545    31348862 :   if (Changed)
     546     2186434 :     return ListInit::get(Resolved, getType());
     547    30255645 :   return const_cast<ListInit *>(this);
     548             : }
     549             : 
     550       55343 : Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV,
     551             :                                             unsigned Elt) const {
     552       55343 :   if (Elt >= size())
     553             :     return nullptr;  // Out of range reference.
     554       55343 :   Init *E = getElement(Elt);
     555             :   // If the element is set to some value, or if we are resolving a reference
     556             :   // to a specific variable and that variable is explicitly unset, then
     557             :   // replace the VarListElementInit with it.
     558      110678 :   if (IRV || !isa<UnsetInit>(E))
     559             :     return E;
     560             :   return nullptr;
     561             : }
     562             : 
     563          85 : std::string ListInit::getAsString() const {
     564         255 :   std::string Result = "[";
     565          85 :   const char *sep = "";
     566         472 :   for (Init *Element : *this) {
     567         217 :     Result += sep;
     568         217 :     sep = ", ";
     569         651 :     Result += Element->getAsString();
     570             :   }
     571         170 :   return Result + "]";
     572             : }
     573             : 
     574          63 : Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
     575             :                                           unsigned Elt) const {
     576          63 :   Init *Resolved = resolveReferences(R, IRV);
     577          59 :   OpInit *OResolved = dyn_cast<OpInit>(Resolved);
     578             :   if (OResolved) {
     579          59 :     Resolved = OResolved->Fold(&R, nullptr);
     580             :   }
     581             : 
     582          63 :   if (Resolved != this) {
     583          16 :     TypedInit *Typed = cast<TypedInit>(Resolved);
     584          16 :     if (Init *New = Typed->resolveListElementReference(R, IRV, Elt))
     585             :       return New;
     586          12 :     return VarListElementInit::get(Typed, Elt);
     587             :   }
     588             : 
     589             :   return nullptr;
     590             : }
     591             : 
     592       51978 : Init *OpInit::getBit(unsigned Bit) const {
     593       51978 :   if (getType() == BitRecTy::get())
     594          65 :     return const_cast<OpInit*>(this);
     595       51913 :   return VarBitInit::get(const_cast<OpInit*>(this), Bit);
     596             : }
     597             : 
     598             : static void
     599     4978643 : ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op, RecTy *Type) {
     600     4978643 :   ID.AddInteger(Opcode);
     601     4978643 :   ID.AddPointer(Op);
     602     4978643 :   ID.AddPointer(Type);
     603     4978643 : }
     604             : 
     605     2130576 : UnOpInit *UnOpInit::get(UnaryOp Opc, Init *LHS, RecTy *Type) {
     606     2130758 :   static FoldingSet<UnOpInit> ThePool;
     607             : 
     608     4261152 :   FoldingSetNodeID ID;
     609     2130576 :   ProfileUnOpInit(ID, Opc, LHS, Type);
     610             : 
     611     2130576 :   void *IP = nullptr;
     612     1853632 :   if (UnOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
     613             :     return I;
     614             : 
     615      553888 :   UnOpInit *I = new(Allocator) UnOpInit(Opc, LHS, Type);
     616      553888 :   ThePool.InsertNode(I, IP);
     617      276944 :   return I;
     618             : }
     619             : 
     620     2848067 : void UnOpInit::Profile(FoldingSetNodeID &ID) const {
     621     2848067 :   ProfileUnOpInit(ID, getOpcode(), getOperand(), getType());
     622     2848067 : }
     623             : 
     624     3238136 : Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
     625     3238136 :   switch (getOpcode()) {
     626     3233591 :   case CAST:
     627     3233591 :     if (isa<StringRecTy>(getType())) {
     628     1356382 :       if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
     629             :         return LHSs;
     630             : 
     631      814857 :       if (DefInit *LHSd = dyn_cast<DefInit>(LHS))
     632      188523 :         return StringInit::get(LHSd->getAsString());
     633             : 
     634      833013 :       if (IntInit *LHSi = dyn_cast<IntInit>(LHS))
     635      431514 :         return StringInit::get(LHSi->getAsString());
     636             :     } else {
     637     3092394 :       if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
     638             :         // From TGParser::ParseIDValue
     639     1215185 :         if (CurRec) {
     640     1215185 :           if (const RecordVal *RV = CurRec->getValue(Name)) {
     641           0 :             if (RV->getType() != getType())
     642           0 :               PrintFatalError("type mismatch in cast");
     643           0 :             return VarInit::get(Name, RV->getType());
     644             :           }
     645             : 
     646     2430370 :           Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name,
     647     1215185 :                                               ":");
     648             : 
     649     1215185 :           if (CurRec->isTemplateArg(TemplateArgName)) {
     650           0 :             const RecordVal *RV = CurRec->getValue(TemplateArgName);
     651             :             assert(RV && "Template arg doesn't exist??");
     652             : 
     653           0 :             if (RV->getType() != getType())
     654           0 :               PrintFatalError("type mismatch in cast");
     655             : 
     656           0 :             return VarInit::get(TemplateArgName, RV->getType());
     657             :           }
     658             :         }
     659             : 
     660     1215185 :         if (CurMultiClass) {
     661          84 :           Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name,
     662          42 :                                      "::");
     663             : 
     664          84 :           if (CurMultiClass->Rec.isTemplateArg(MCName)) {
     665           0 :             const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
     666             :             assert(RV && "Template arg doesn't exist??");
     667             : 
     668           0 :             if (RV->getType() != getType())
     669           0 :               PrintFatalError("type mismatch in cast");
     670             : 
     671           0 :             return VarInit::get(MCName, RV->getType());
     672             :           }
     673             :         }
     674             :         assert(CurRec && "NULL pointer");
     675     1215185 :         if (Record *D = (CurRec->getRecords()).getDef(Name->getValue()))
     676     1215185 :           return DefInit::get(D);
     677             : 
     678           0 :         PrintFatalError(CurRec->getLoc(),
     679           0 :                         "Undefined reference:'" + Name->getValue() + "'\n");
     680             :       }
     681             : 
     682     1324048 :       if (isa<IntRecTy>(getType())) {
     683       11643 :         if (BitsInit *BI = dyn_cast<BitsInit>(LHS)) {
     684        5203 :           if (Init *NewInit = BI->convertInitializerTo(IntRecTy::get()))
     685             :             return NewInit;
     686             :           break;
     687             :         }
     688             :       }
     689             :     }
     690             :     break;
     691             : 
     692        1248 :   case HEAD:
     693        1537 :     if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
     694             :       assert(!LHSl->empty() && "Empty list in head");
     695         289 :       return LHSl->getElement(0);
     696             :     }
     697             :     break;
     698             : 
     699          36 :   case TAIL:
     700          48 :     if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
     701             :       assert(!LHSl->empty() && "Empty list in tail");
     702             :       // Note the +1.  We can't just pass the result of getValues()
     703             :       // directly.
     704          36 :       return ListInit::get(LHSl->getValues().slice(1), LHSl->getType());
     705             :     }
     706             :     break;
     707             : 
     708        3261 :   case EMPTY:
     709        4256 :     if (ListInit *LHSl = dyn_cast<ListInit>(LHS))
     710         995 :       return IntInit::get(LHSl->empty());
     711        2266 :     if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
     712           0 :       return IntInit::get(LHSs->getValue().empty());
     713             :     break;
     714             :   }
     715     1205459 :   return const_cast<UnOpInit *>(this);
     716             : }
     717             : 
     718     2659366 : Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) const {
     719     2659366 :   Init *lhs = LHS->resolveReferences(R, RV);
     720             : 
     721     2659366 :   if (LHS != lhs)
     722     1542545 :     return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, nullptr);
     723     1116821 :   return Fold(&R, nullptr);
     724             : }
     725             : 
     726      117535 : std::string UnOpInit::getAsString() const {
     727      235070 :   std::string Result;
     728      117535 :   switch (getOpcode()) {
     729      470092 :   case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
     730           2 :   case HEAD: Result = "!head"; break;
     731           5 :   case TAIL: Result = "!tail"; break;
     732           5 :   case EMPTY: Result = "!empty"; break;
     733             :   }
     734      587675 :   return Result + "(" + LHS->getAsString() + ")";
     735             : }
     736             : 
     737             : static void
     738    20591770 : ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS,
     739             :                  RecTy *Type) {
     740    20591770 :   ID.AddInteger(Opcode);
     741    20591770 :   ID.AddPointer(LHS);
     742    20591770 :   ID.AddPointer(RHS);
     743    20591770 :   ID.AddPointer(Type);
     744    20591770 : }
     745             : 
     746     7117966 : BinOpInit *BinOpInit::get(BinaryOp Opc, Init *LHS,
     747             :                           Init *RHS, RecTy *Type) {
     748     7118153 :   static FoldingSet<BinOpInit> ThePool;
     749             : 
     750    14235932 :   FoldingSetNodeID ID;
     751     7117966 :   ProfileBinOpInit(ID, Opc, LHS, RHS, Type);
     752             : 
     753     7117966 :   void *IP = nullptr;
     754     5055154 :   if (BinOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
     755             :     return I;
     756             : 
     757     4125624 :   BinOpInit *I = new(Allocator) BinOpInit(Opc, LHS, RHS, Type);
     758     4125624 :   ThePool.InsertNode(I, IP);
     759     2062812 :   return I;
     760             : }
     761             : 
     762    13473804 : void BinOpInit::Profile(FoldingSetNodeID &ID) const {
     763    13473804 :   ProfileBinOpInit(ID, getOpcode(), getLHS(), getRHS(), getType());
     764    13473804 : }
     765             : 
     766    22643139 : static StringInit *ConcatStringInits(const StringInit *I0,
     767             :                                      const StringInit *I1) {
     768    67929417 :   SmallString<80> Concat(I0->getValue());
     769    45286278 :   Concat.append(I1->getValue());
     770    45286278 :   return StringInit::get(Concat);
     771             : }
     772             : 
     773    24770203 : Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
     774    24770203 :   switch (getOpcode()) {
     775      113296 :   case CONCAT: {
     776      226592 :     DagInit *LHSs = dyn_cast<DagInit>(LHS);
     777      226592 :     DagInit *RHSs = dyn_cast<DagInit>(RHS);
     778      113296 :     if (LHSs && RHSs) {
     779       37002 :       DefInit *LOp = dyn_cast<DefInit>(LHSs->getOperator());
     780       37002 :       DefInit *ROp = dyn_cast<DefInit>(RHSs->getOperator());
     781       18501 :       if (!LOp || !ROp || LOp->getDef() != ROp->getDef())
     782           0 :         PrintFatalError("Concated Dag operators do not match!");
     783       37002 :       SmallVector<Init*, 8> Args;
     784       37002 :       SmallVector<StringInit*, 8> ArgNames;
     785       52448 :       for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
     786       33947 :         Args.push_back(LHSs->getArg(i));
     787       33947 :         ArgNames.push_back(LHSs->getArgName(i));
     788             :       }
     789       42446 :       for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
     790       23945 :         Args.push_back(RHSs->getArg(i));
     791       23945 :         ArgNames.push_back(RHSs->getArgName(i));
     792             :       }
     793       37002 :       return DagInit::get(LHSs->getOperator(), nullptr, Args, ArgNames);
     794             :     }
     795             :     break;
     796             :   }
     797     1766535 :   case LISTCONCAT: {
     798     3533070 :     ListInit *LHSs = dyn_cast<ListInit>(LHS);
     799     3533070 :     ListInit *RHSs = dyn_cast<ListInit>(RHS);
     800     1766535 :     if (LHSs && RHSs) {
     801      767842 :       SmallVector<Init *, 8> Args;
     802      767842 :       Args.insert(Args.end(), LHSs->begin(), LHSs->end());
     803     1151763 :       Args.insert(Args.end(), RHSs->begin(), RHSs->end());
     804     1535684 :       return ListInit::get(
     805      383921 :           Args, cast<ListRecTy>(LHSs->getType())->getElementType());
     806             :     }
     807             :     break;
     808             :   }
     809    10599989 :   case STRCONCAT: {
     810    21199978 :     StringInit *LHSs = dyn_cast<StringInit>(LHS);
     811    21199978 :     StringInit *RHSs = dyn_cast<StringInit>(RHS);
     812    10599989 :     if (LHSs && RHSs)
     813     3561681 :       return ConcatStringInits(LHSs, RHSs);
     814             :     break;
     815             :   }
     816     6002510 :   case EQ: {
     817             :     // try to fold eq comparison for 'bit' and 'int', otherwise fallback
     818             :     // to string objects.
     819             :     IntInit *L =
     820    12005020 :       dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
     821             :     IntInit *R =
     822    12005020 :       dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
     823             : 
     824     6002510 :     if (L && R)
     825     1076954 :       return IntInit::get(L->getValue() == R->getValue());
     826             : 
     827     9851112 :     StringInit *LHSs = dyn_cast<StringInit>(LHS);
     828     9851112 :     StringInit *RHSs = dyn_cast<StringInit>(RHS);
     829             : 
     830             :     // Make sure we've resolved
     831     4925556 :     if (LHSs && RHSs)
     832      161564 :       return IntInit::get(LHSs->getValue() == RHSs->getValue());
     833             : 
     834             :     break;
     835             :   }
     836     6287873 :   case ADD:
     837             :   case AND:
     838             :   case OR:
     839             :   case SHL:
     840             :   case SRA:
     841             :   case SRL: {
     842             :     IntInit *LHSi =
     843    12575746 :       dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
     844             :     IntInit *RHSi =
     845    12575746 :       dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
     846     6287873 :     if (LHSi && RHSi) {
     847      599692 :       int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
     848             :       int64_t Result;
     849      599692 :       switch (getOpcode()) {
     850           0 :       default: llvm_unreachable("Bad opcode!");
     851       19343 :       case ADD: Result = LHSv +  RHSv; break;
     852       24929 :       case AND: Result = LHSv &  RHSv; break;
     853       13496 :       case OR: Result = LHSv | RHSv; break;
     854      304700 :       case SHL: Result = LHSv << RHSv; break;
     855           0 :       case SRA: Result = LHSv >> RHSv; break;
     856      237224 :       case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
     857             :       }
     858      599692 :       return IntInit::get(Result);
     859             :     }
     860             :     break;
     861             :   }
     862             :   }
     863    18967890 :   return const_cast<BinOpInit *>(this);
     864             : }
     865             : 
     866    23961232 : Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) const {
     867    23961232 :   Init *lhs = LHS->resolveReferences(R, RV);
     868    23961232 :   Init *rhs = RHS->resolveReferences(R, RV);
     869             : 
     870    23961232 :   if (LHS != lhs || RHS != rhs)
     871     6119197 :     return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R,nullptr);
     872    17842035 :   return Fold(&R, nullptr);
     873             : }
     874             : 
     875      533807 : std::string BinOpInit::getAsString() const {
     876     1067614 :   std::string Result;
     877      533807 :   switch (getOpcode()) {
     878           0 :   case CONCAT: Result = "!con"; break;
     879           0 :   case ADD: Result = "!add"; break;
     880           0 :   case AND: Result = "!and"; break;
     881           0 :   case OR: Result = "!or"; break;
     882           2 :   case SHL: Result = "!shl"; break;
     883           0 :   case SRA: Result = "!sra"; break;
     884           0 :   case SRL: Result = "!srl"; break;
     885          11 :   case EQ: Result = "!eq"; break;
     886           4 :   case LISTCONCAT: Result = "!listconcat"; break;
     887      533790 :   case STRCONCAT: Result = "!strconcat"; break;
     888             :   }
     889     4270456 :   return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
     890             : }
     891             : 
     892             : static void
     893     6833614 : ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
     894             :                   Init *RHS, RecTy *Type) {
     895     6833614 :   ID.AddInteger(Opcode);
     896     6833614 :   ID.AddPointer(LHS);
     897     6833614 :   ID.AddPointer(MHS);
     898     6833614 :   ID.AddPointer(RHS);
     899     6833614 :   ID.AddPointer(Type);
     900     6833614 : }
     901             : 
     902     2607863 : TernOpInit *TernOpInit::get(TernaryOp Opc, Init *LHS, Init *MHS, Init *RHS,
     903             :                             RecTy *Type) {
     904     2608027 :   static FoldingSet<TernOpInit> ThePool;
     905             : 
     906     5215726 :   FoldingSetNodeID ID;
     907     2607863 :   ProfileTernOpInit(ID, Opc, LHS, MHS, RHS, Type);
     908             : 
     909     2607863 :   void *IP = nullptr;
     910     2467116 :   if (TernOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
     911             :     return I;
     912             : 
     913      281494 :   TernOpInit *I = new(Allocator) TernOpInit(Opc, LHS, MHS, RHS, Type);
     914      281494 :   ThePool.InsertNode(I, IP);
     915      140747 :   return I;
     916             : }
     917             : 
     918     4225751 : void TernOpInit::Profile(FoldingSetNodeID &ID) const {
     919     4225751 :   ProfileTernOpInit(ID, getOpcode(), getLHS(), getMHS(), getRHS(), getType());
     920     4225751 : }
     921             : 
     922             : static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
     923             :                            Record *CurRec, MultiClass *CurMultiClass);
     924             : 
     925         170 : static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
     926             :                                RecTy *Type, Record *CurRec,
     927             :                                MultiClass *CurMultiClass) {
     928             :   // If this is a dag, recurse
     929         340 :   if (auto *TArg = dyn_cast<TypedInit>(Arg))
     930         340 :     if (isa<DagRecTy>(TArg->getType()))
     931          12 :       return ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass);
     932             : 
     933         158 :   SmallVector<Init *, 8> NewOperands;
     934         158 :   NewOperands.reserve(RHSo->getNumOperands());
     935         632 :   for (unsigned i = 0, e = RHSo->getNumOperands(); i < e; ++i) {
     936         576 :     if (auto *RHSoo = dyn_cast<OpInit>(RHSo->getOperand(i))) {
     937         204 :       if (Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
     938         102 :                                            Type, CurRec, CurMultiClass))
     939         102 :         NewOperands.push_back(Result);
     940             :       else
     941           0 :         NewOperands.push_back(Arg);
     942        1116 :     } else if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
     943          56 :       NewOperands.push_back(Arg);
     944             :     } else {
     945         316 :       NewOperands.push_back(RHSo->getOperand(i));
     946             :     }
     947             :   }
     948             : 
     949             :   // Now run the operator and use its result as the new leaf
     950         316 :   const OpInit *NewOp = RHSo->clone(NewOperands);
     951         158 :   Init *NewVal = NewOp->Fold(CurRec, CurMultiClass);
     952         158 :   return (NewVal != NewOp) ? NewVal : nullptr;
     953             : }
     954             : 
     955         293 : static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
     956             :                            Record *CurRec, MultiClass *CurMultiClass) {
     957         293 :   OpInit *RHSo = dyn_cast<OpInit>(RHS);
     958             : 
     959             :   if (!RHSo)
     960           0 :     PrintFatalError(CurRec->getLoc(), "!foreach requires an operator\n");
     961             : 
     962         293 :   TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
     963             : 
     964             :   if (!LHSt)
     965           0 :     PrintFatalError(CurRec->getLoc(), "!foreach requires typed variable\n");
     966             : 
     967          24 :   DagInit *MHSd = dyn_cast<DagInit>(MHS);
     968          48 :   if (MHSd && isa<DagRecTy>(Type)) {
     969          24 :     Init *Val = MHSd->getOperator();
     970          24 :     if (Init *Result = EvaluateOperation(RHSo, LHS, Val,
     971          24 :                                          Type, CurRec, CurMultiClass))
     972          24 :       Val = Result;
     973             : 
     974          48 :     SmallVector<std::pair<Init *, StringInit*>, 8> args;
     975          68 :     for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
     976          44 :       Init *Arg = MHSd->getArg(i);
     977          44 :       StringInit *ArgName = MHSd->getArgName(i);
     978             : 
     979             :       // Process args
     980          44 :       if (Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
     981          44 :                                            CurRec, CurMultiClass))
     982          44 :         Arg = Result;
     983             : 
     984             :       // TODO: Process arg names
     985          88 :       args.push_back(std::make_pair(Arg, ArgName));
     986             :     }
     987             : 
     988          24 :     return DagInit::get(Val, nullptr, args);
     989             :   }
     990             : 
     991          12 :   ListInit *MHSl = dyn_cast<ListInit>(MHS);
     992          24 :   if (MHSl && isa<ListRecTy>(Type)) {
     993          24 :     SmallVector<Init *, 8> NewOperands;
     994          48 :     SmallVector<Init *, 8> NewList(MHSl->begin(), MHSl->end());
     995             : 
     996          56 :     for (Init *&Item : NewList) {
     997          20 :       NewOperands.clear();
     998          76 :       for(unsigned i = 0; i < RHSo->getNumOperands(); ++i) {
     999             :         // First, replace the foreach variable with the list item
    1000         168 :         if (LHS->getAsString() == RHSo->getOperand(i)->getAsString())
    1001          20 :           NewOperands.push_back(Item);
    1002             :         else
    1003          36 :           NewOperands.push_back(RHSo->getOperand(i));
    1004             :       }
    1005             : 
    1006             :       // Now run the operator and use its result as the new list item
    1007          40 :       const OpInit *NewOp = RHSo->clone(NewOperands);
    1008          20 :       Init *NewItem = NewOp->Fold(CurRec, CurMultiClass);
    1009          20 :       if (NewItem != NewOp)
    1010          20 :         Item = NewItem;
    1011             :     }
    1012          24 :     return ListInit::get(NewList, MHSl->getType());
    1013             :   }
    1014             :   return nullptr;
    1015             : }
    1016             : 
    1017    12410039 : Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
    1018    12410039 :   switch (getOpcode()) {
    1019       20310 :   case SUBST: {
    1020       40620 :     DefInit *LHSd = dyn_cast<DefInit>(LHS);
    1021       40620 :     VarInit *LHSv = dyn_cast<VarInit>(LHS);
    1022       40620 :     StringInit *LHSs = dyn_cast<StringInit>(LHS);
    1023             : 
    1024       40620 :     DefInit *MHSd = dyn_cast<DefInit>(MHS);
    1025       40620 :     VarInit *MHSv = dyn_cast<VarInit>(MHS);
    1026       40620 :     StringInit *MHSs = dyn_cast<StringInit>(MHS);
    1027             : 
    1028       40620 :     DefInit *RHSd = dyn_cast<DefInit>(RHS);
    1029       40620 :     VarInit *RHSv = dyn_cast<VarInit>(RHS);
    1030       40620 :     StringInit *RHSs = dyn_cast<StringInit>(RHS);
    1031             : 
    1032       20310 :     if (LHSd && MHSd && RHSd) {
    1033         162 :       Record *Val = RHSd->getDef();
    1034         486 :       if (LHSd->getAsString() == RHSd->getAsString())
    1035          45 :         Val = MHSd->getDef();
    1036         162 :       return DefInit::get(Val);
    1037             :     }
    1038       20148 :     if (LHSv && MHSv && RHSv) {
    1039           0 :       std::string Val = RHSv->getName();
    1040           0 :       if (LHSv->getAsString() == RHSv->getAsString())
    1041           0 :         Val = MHSv->getName();
    1042           0 :       return VarInit::get(Val, getType());
    1043             :     }
    1044       20148 :     if (LHSs && MHSs && RHSs) {
    1045        7492 :       std::string Val = RHSs->getValue();
    1046             : 
    1047             :       std::string::size_type found;
    1048             :       std::string::size_type idx = 0;
    1049             :       while (true) {
    1050       28894 :         found = Val.find(LHSs->getValue(), idx);
    1051        6528 :         if (found == std::string::npos)
    1052             :           break;
    1053       11128 :         Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
    1054        2782 :         idx = found + MHSs->getValue().size();
    1055             :       }
    1056             : 
    1057        3746 :       return StringInit::get(Val);
    1058             :     }
    1059             :     break;
    1060             :   }
    1061             : 
    1062         281 :   case FOREACH: {
    1063         562 :     if (Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
    1064         281 :                                      CurRec, CurMultiClass))
    1065             :       return Result;
    1066             :     break;
    1067             :   }
    1068             : 
    1069    12389448 :   case IF: {
    1070    24778896 :     IntInit *LHSi = dyn_cast<IntInit>(LHS);
    1071    12389448 :     if (Init *I = LHS->convertInitializerTo(IntRecTy::get()))
    1072             :       LHSi = dyn_cast<IntInit>(I);
    1073     4214022 :     if (LHSi) {
    1074     2449879 :       if (LHSi->getValue())
    1075      977469 :         return MHS;
    1076     1472410 :       return RHS;
    1077             :     }
    1078             :     break;
    1079             :   }
    1080             :   }
    1081             : 
    1082     9956228 :   return const_cast<TernOpInit *>(this);
    1083             : }
    1084             : 
    1085    12400339 : Init *TernOpInit::resolveReferences(Record &R,
    1086             :                                     const RecordVal *RV) const {
    1087    12400339 :   Init *lhs = LHS->resolveReferences(R, RV);
    1088             : 
    1089    12400339 :   if (getOpcode() == IF && lhs != LHS) {
    1090     2486286 :     IntInit *Value = dyn_cast<IntInit>(lhs);
    1091     2486286 :     if (Init *I = lhs->convertInitializerTo(IntRecTy::get()))
    1092             :       Value = dyn_cast<IntInit>(I);
    1093     2449879 :     if (Value) {
    1094             :       // Short-circuit
    1095     2449879 :       if (Value->getValue()) {
    1096      977469 :         Init *mhs = MHS->resolveReferences(R, RV);
    1097     1954938 :         return (TernOpInit::get(getOpcode(), lhs, mhs,
    1098     1954938 :                                 RHS, getType()))->Fold(&R, nullptr);
    1099             :       }
    1100     1472410 :       Init *rhs = RHS->resolveReferences(R, RV);
    1101     1472410 :       return (TernOpInit::get(getOpcode(), lhs, MHS,
    1102     1472410 :                               rhs, getType()))->Fold(&R, nullptr);
    1103             :     }
    1104             :   }
    1105             : 
    1106     9950460 :   Init *mhs = MHS->resolveReferences(R, RV);
    1107     9950460 :   Init *rhs = RHS->resolveReferences(R, RV);
    1108             : 
    1109     9950460 :   if (LHS != lhs || MHS != mhs || RHS != rhs)
    1110      148343 :     return (TernOpInit::get(getOpcode(), lhs, mhs, rhs,
    1111      148343 :                             getType()))->Fold(&R, nullptr);
    1112     9802117 :   return Fold(&R, nullptr);
    1113             : }
    1114             : 
    1115          99 : std::string TernOpInit::getAsString() const {
    1116         198 :   std::string Result;
    1117          99 :   switch (getOpcode()) {
    1118          49 :   case SUBST: Result = "!subst"; break;
    1119           9 :   case FOREACH: Result = "!foreach"; break;
    1120          41 :   case IF: Result = "!if"; break;
    1121             :   }
    1122         891 :   return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", " +
    1123         396 :          RHS->getAsString() + ")";
    1124             : }
    1125             : 
    1126       36561 : RecTy *TypedInit::getFieldType(StringInit *FieldName) const {
    1127       73122 :   if (RecordRecTy *RecordType = dyn_cast<RecordRecTy>(getType()))
    1128       73122 :     if (RecordVal *Field = RecordType->getRecord()->getValue(FieldName))
    1129       36561 :       return Field->getType();
    1130             :   return nullptr;
    1131             : }
    1132             : 
    1133             : Init *
    1134    36555428 : TypedInit::convertInitializerTo(RecTy *Ty) const {
    1135    73110856 :   if (isa<IntRecTy>(Ty)) {
    1136    19058070 :     if (getType()->typeIsConvertibleTo(Ty))
    1137    18622324 :       return const_cast<TypedInit *>(this);
    1138             :     return nullptr;
    1139             :   }
    1140             : 
    1141    17497358 :   if (isa<StringRecTy>(Ty)) {
    1142     6901553 :     if (isa<StringRecTy>(getType()))
    1143     6901553 :       return const_cast<TypedInit *>(this);
    1144             :     return nullptr;
    1145             :   }
    1146             : 
    1147    10595805 :   if (isa<CodeRecTy>(Ty)) {
    1148             :     if (isa<CodeRecTy>(getType()))
    1149             :       return const_cast<TypedInit *>(this);
    1150             :     return nullptr;
    1151             :   }
    1152             : 
    1153    21191610 :   if (isa<BitRecTy>(Ty)) {
    1154             :     // Accept variable if it is already of bit type!
    1155     3383882 :     if (isa<BitRecTy>(getType()))
    1156     1359071 :       return const_cast<TypedInit *>(this);
    1157      348530 :     if (auto *BitsTy = dyn_cast<BitsRecTy>(getType())) {
    1158             :       // Accept only bits<1> expression.
    1159       15660 :       if (BitsTy->getNumBits() == 1)
    1160       15660 :         return const_cast<TypedInit *>(this);
    1161             :       return nullptr;
    1162             :     }
    1163             :     // Ternary !if can be converted to bit, but only if both sides are
    1164             :     // convertible to a bit.
    1165      317210 :     if (const auto *TOI = dyn_cast<TernOpInit>(this)) {
    1166      317210 :       if (TOI->getOpcode() == TernOpInit::TernaryOp::IF &&
    1167      634420 :           TOI->getMHS()->convertInitializerTo(BitRecTy::get()) &&
    1168      317210 :           TOI->getRHS()->convertInitializerTo(BitRecTy::get()))
    1169      317210 :         return const_cast<TypedInit *>(this);
    1170             :       return nullptr;
    1171             :     }
    1172             :     return nullptr;
    1173             :   }
    1174             : 
    1175     9068219 :   if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
    1176      174630 :     if (BRT->getNumBits() == 1 && isa<BitRecTy>(getType()))
    1177       13158 :       return BitsInit::get(const_cast<TypedInit *>(this));
    1178             : 
    1179      157776 :     if (getType()->typeIsConvertibleTo(BRT)) {
    1180      473328 :       SmallVector<Init *, 16> NewBits(BRT->getNumBits());
    1181             : 
    1182     1208429 :       for (unsigned i = 0; i != BRT->getNumBits(); ++i)
    1183     2101306 :         NewBits[i] = VarBitInit::get(const_cast<TypedInit *>(this), i);
    1184      157776 :       return BitsInit::get(NewBits);
    1185             :     }
    1186             : 
    1187             :     return nullptr;
    1188             :   }
    1189             : 
    1190    12494272 :   if (auto *DLRT = dyn_cast<ListRecTy>(Ty)) {
    1191     7509526 :     if (auto *SLRT = dyn_cast<ListRecTy>(getType()))
    1192     3754763 :       if (SLRT->getElementType()->typeIsConvertibleTo(DLRT->getElementType()))
    1193     3754763 :         return const_cast<TypedInit *>(this);
    1194             :     return nullptr;
    1195             :   }
    1196             : 
    1197     6006767 :   if (auto *DRT = dyn_cast<DagRecTy>(Ty)) {
    1198     1022021 :     if (getType()->typeIsConvertibleTo(DRT))
    1199     1022021 :       return const_cast<TypedInit *>(this);
    1200             :     return nullptr;
    1201             :   }
    1202             : 
    1203     7925450 :   if (auto *SRRT = dyn_cast<RecordRecTy>(Ty)) {
    1204             :     // Ensure that this is compatible with Rec.
    1205     7925450 :     if (RecordRecTy *DRRT = dyn_cast<RecordRecTy>(getType()))
    1206     7925450 :       if (DRRT->getRecord()->isSubClassOf(SRRT->getRecord()) ||
    1207             :           DRRT->getRecord() == SRRT->getRecord())
    1208     3962725 :         return const_cast<TypedInit *>(this);
    1209             :     return nullptr;
    1210             :   }
    1211             : 
    1212             :   return nullptr;
    1213             : }
    1214             : 
    1215       37865 : Init *TypedInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
    1216       75730 :   BitsRecTy *T = dyn_cast<BitsRecTy>(getType());
    1217             :   if (!T) return nullptr;  // Cannot subscript a non-bits variable.
    1218       37865 :   unsigned NumBits = T->getNumBits();
    1219             : 
    1220       37865 :   SmallVector<Init *, 16> NewBits;
    1221       37865 :   NewBits.reserve(Bits.size());
    1222      212067 :   for (unsigned Bit : Bits) {
    1223      136337 :     if (Bit >= NumBits)
    1224             :       return nullptr;
    1225             : 
    1226      136337 :     NewBits.push_back(VarBitInit::get(const_cast<TypedInit *>(this), Bit));
    1227             :   }
    1228       37865 :   return BitsInit::get(NewBits);
    1229             : }
    1230             : 
    1231        1191 : Init *TypedInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
    1232        2382 :   ListRecTy *T = dyn_cast<ListRecTy>(getType());
    1233             :   if (!T) return nullptr;  // Cannot subscript a non-list variable.
    1234             : 
    1235        1191 :   if (Elements.size() == 1)
    1236          83 :     return VarListElementInit::get(const_cast<TypedInit *>(this), Elements[0]);
    1237             : 
    1238        1108 :   SmallVector<Init*, 8> ListInits;
    1239        1108 :   ListInits.reserve(Elements.size());
    1240       12988 :   for (unsigned Element : Elements)
    1241       10772 :     ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
    1242             :                                                 Element));
    1243        1108 :   return ListInit::get(ListInits, T);
    1244             : }
    1245             : 
    1246             : 
    1247        1741 : VarInit *VarInit::get(StringRef VN, RecTy *T) {
    1248        1741 :   Init *Value = StringInit::get(VN);
    1249        1741 :   return VarInit::get(Value, T);
    1250             : }
    1251             : 
    1252      636326 : VarInit *VarInit::get(Init *VN, RecTy *T) {
    1253             :   using Key = std::pair<RecTy *, Init *>;
    1254      636591 :   static DenseMap<Key, VarInit*> ThePool;
    1255             : 
    1256     1272652 :   Key TheKey(std::make_pair(T, VN));
    1257             : 
    1258      636326 :   VarInit *&I = ThePool[TheKey];
    1259      636326 :   if (!I)
    1260      637882 :     I = new(Allocator) VarInit(VN, T);
    1261      636326 :   return I;
    1262             : }
    1263             : 
    1264     6476166 : StringRef VarInit::getName() const {
    1265    12952332 :   StringInit *NameString = cast<StringInit>(getNameInit());
    1266     6476166 :   return NameString->getValue();
    1267             : }
    1268             : 
    1269      870973 : Init *VarInit::getBit(unsigned Bit) const {
    1270      870973 :   if (getType() == BitRecTy::get())
    1271       20883 :     return const_cast<VarInit*>(this);
    1272      850090 :   return VarBitInit::get(const_cast<VarInit*>(this), Bit);
    1273             : }
    1274             : 
    1275       24758 : Init *VarInit::resolveListElementReference(Record &R,
    1276             :                                            const RecordVal *IRV,
    1277             :                                            unsigned Elt) const {
    1278       49516 :   if (R.isTemplateArg(getNameInit())) return nullptr;
    1279       24754 :   if (IRV && IRV->getNameInit() != getNameInit()) return nullptr;
    1280             : 
    1281       21726 :   RecordVal *RV = R.getValue(getNameInit());
    1282             :   assert(RV && "Reference to a non-existent variable?");
    1283       21708 :   ListInit *LI = dyn_cast<ListInit>(RV->getValue());
    1284             :   if (!LI)
    1285          36 :     return VarListElementInit::get(cast<TypedInit>(RV->getValue()), Elt);
    1286             : 
    1287       10845 :   if (Elt >= LI->size())
    1288             :     return nullptr;  // Out of range reference.
    1289       10819 :   Init *E = LI->getElement(Elt);
    1290             :   // If the element is set to some value, or if we are resolving a reference
    1291             :   // to a specific variable and that variable is explicitly unset, then
    1292             :   // replace the VarListElementInit with it.
    1293       21613 :   if (IRV || !isa<UnsetInit>(E))
    1294             :     return E;
    1295             :   return nullptr;
    1296             : }
    1297             : 
    1298      102307 : RecTy *VarInit::getFieldType(StringInit *FieldName) const {
    1299      204614 :   if (RecordRecTy *RTy = dyn_cast<RecordRecTy>(getType()))
    1300      204614 :     if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
    1301      102307 :       return RV->getType();
    1302             :   return nullptr;
    1303             : }
    1304             : 
    1305    31230248 : Init *VarInit::getFieldInit(Record &R, const RecordVal *RV,
    1306             :                             StringInit *FieldName) const {
    1307    62460496 :   if (isa<RecordRecTy>(getType()))
    1308    62460496 :     if (const RecordVal *Val = R.getValue(VarName)) {
    1309    34726569 :       if (RV != Val && (RV || isa<UnsetInit>(Val->getValue())))
    1310             :         return nullptr;
    1311     4195726 :       Init *TheInit = Val->getValue();
    1312             :       assert(TheInit != this && "Infinite loop detected!");
    1313     4195726 :       if (Init *I = TheInit->getFieldInit(R, RV, FieldName))
    1314             :         return I;
    1315         858 :       return nullptr;
    1316             :     }
    1317             :   return nullptr;
    1318             : }
    1319             : 
    1320   159608903 : Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const {
    1321   319217806 :   if (RecordVal *Val = R.getValue(VarName))
    1322   171894942 :     if (RV == Val || (!RV && !isa<UnsetInit>(Val->getValue())))
    1323    25426051 :       return Val->getValue();
    1324   134182852 :   return const_cast<VarInit *>(this);
    1325             : }
    1326             : 
    1327     2163607 : VarBitInit *VarBitInit::get(TypedInit *T, unsigned B) {
    1328             :   using Key = std::pair<TypedInit *, unsigned>;
    1329     2163764 :   static DenseMap<Key, VarBitInit*> ThePool;
    1330             : 
    1331     4327214 :   Key TheKey(std::make_pair(T, B));
    1332             : 
    1333     2163607 :   VarBitInit *&I = ThePool[TheKey];
    1334     2163607 :   if (!I)
    1335      843296 :     I = new(Allocator) VarBitInit(T, B);
    1336     2163607 :   return I;
    1337             : }
    1338             : 
    1339         810 : Init *VarBitInit::convertInitializerTo(RecTy *Ty) const {
    1340        1620 :   if (isa<BitRecTy>(Ty))
    1341         810 :     return const_cast<VarBitInit *>(this);
    1342             : 
    1343             :   return nullptr;
    1344             : }
    1345             : 
    1346         186 : std::string VarBitInit::getAsString() const {
    1347         930 :   return TI->getAsString() + "{" + utostr(Bit) + "}";
    1348             : }
    1349             : 
    1350        1422 : Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) const {
    1351        1422 :   Init *I = TI->resolveReferences(R, RV);
    1352        1422 :   if (TI != I)
    1353         612 :     return I->getBit(getBitNum());
    1354             : 
    1355         810 :   return const_cast<VarBitInit*>(this);
    1356             : }
    1357             : 
    1358       10885 : VarListElementInit *VarListElementInit::get(TypedInit *T,
    1359             :                                             unsigned E) {
    1360             :   using Key = std::pair<TypedInit *, unsigned>;
    1361       10921 :   static DenseMap<Key, VarListElementInit*> ThePool;
    1362             : 
    1363       21770 :   Key TheKey(std::make_pair(T, E));
    1364             : 
    1365       10885 :   VarListElementInit *&I = ThePool[TheKey];
    1366       15349 :   if (!I) I = new(Allocator) VarListElementInit(T, E);
    1367       10885 :   return I;
    1368             : }
    1369             : 
    1370          25 : std::string VarListElementInit::getAsString() const {
    1371         125 :   return TI->getAsString() + "[" + utostr(Element) + "]";
    1372             : }
    1373             : 
    1374             : Init *
    1375       35579 : VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) const {
    1376      106737 :   if (Init *I = getVariable()->resolveListElementReference(R, RV,
    1377       71158 :                                                            getElementNum()))
    1378             :     return I;
    1379       13956 :   return const_cast<VarListElementInit *>(this);
    1380             : }
    1381             : 
    1382           0 : Init *VarListElementInit::getBit(unsigned Bit) const {
    1383           0 :   if (getType() == BitRecTy::get())
    1384           0 :     return const_cast<VarListElementInit*>(this);
    1385           0 :   return VarBitInit::get(const_cast<VarListElementInit*>(this), Bit);
    1386             : }
    1387             : 
    1388          11 : Init *VarListElementInit:: resolveListElementReference(Record &R,
    1389             :                                                        const RecordVal *RV,
    1390             :                                                        unsigned Elt) const {
    1391          11 :   if (Init *Result = TI->resolveListElementReference(R, RV, Element)) {
    1392           5 :     if (TypedInit *TInit = dyn_cast<TypedInit>(Result)) {
    1393           5 :       if (Init *Result2 = TInit->resolveListElementReference(R, RV, Elt))
    1394             :         return Result2;
    1395           0 :       return VarListElementInit::get(TInit, Elt);
    1396             :     }
    1397             :     return Result;
    1398             :   }
    1399             : 
    1400             :   return nullptr;
    1401             : }
    1402             : 
    1403     7665258 : DefInit *DefInit::get(Record *R) {
    1404     7665258 :   return R->getDefInit();
    1405             : }
    1406             : 
    1407    56209246 : Init *DefInit::convertInitializerTo(RecTy *Ty) const {
    1408    56209246 :   if (auto *RRT = dyn_cast<RecordRecTy>(Ty))
    1409   112418492 :     if (getDef()->isSubClassOf(RRT->getRecord()))
    1410    56209246 :       return const_cast<DefInit *>(this);
    1411             :   return nullptr;
    1412             : }
    1413             : 
    1414       17320 : RecTy *DefInit::getFieldType(StringInit *FieldName) const {
    1415       34640 :   if (const RecordVal *RV = Def->getValue(FieldName))
    1416       17320 :     return RV->getType();
    1417             :   return nullptr;
    1418             : }
    1419             : 
    1420     7554740 : Init *DefInit::getFieldInit(Record &R, const RecordVal *RV,
    1421             :                             StringInit *FieldName) const {
    1422    15109480 :   return Def->getValue(FieldName)->getValue();
    1423             : }
    1424             : 
    1425     3462666 : std::string DefInit::getAsString() const {
    1426     6925332 :   return Def->getName();
    1427             : }
    1428             : 
    1429      380616 : FieldInit *FieldInit::get(Init *R, StringInit *FN) {
    1430             :   using Key = std::pair<Init *, StringInit *>;
    1431      380793 :   static DenseMap<Key, FieldInit*> ThePool;
    1432             : 
    1433      761232 :   Key TheKey(std::make_pair(R, FN));
    1434             : 
    1435      380616 :   FieldInit *&I = ThePool[TheKey];
    1436      543778 :   if (!I) I = new(Allocator) FieldInit(R, FN);
    1437      380616 :   return I;
    1438             : }
    1439             : 
    1440       75069 : Init *FieldInit::getBit(unsigned Bit) const {
    1441       75069 :   if (getType() == BitRecTy::get())
    1442         455 :     return const_cast<FieldInit*>(this);
    1443       74614 :   return VarBitInit::get(const_cast<FieldInit*>(this), Bit);
    1444             : }
    1445             : 
    1446       10770 : Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
    1447             :                                              unsigned Elt) const {
    1448       10770 :   if (Init *ListVal = Rec->getFieldInit(R, RV, FieldName))
    1449       10770 :     if (ListInit *LI = dyn_cast<ListInit>(ListVal)) {
    1450       10770 :       if (Elt >= LI->size()) return nullptr;
    1451       10770 :       Init *E = LI->getElement(Elt);
    1452             : 
    1453             :       // If the element is set to some value, or if we are resolving a
    1454             :       // reference to a specific variable and that variable is explicitly
    1455             :       // unset, then replace the VarListElementInit with it.
    1456       21540 :       if (RV || !isa<UnsetInit>(E))
    1457             :         return E;
    1458             :     }
    1459             :   return nullptr;
    1460             : }
    1461             : 
    1462    37126392 : Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const {
    1463    37126392 :   Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
    1464             : 
    1465    37126392 :   if (Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName)) {
    1466     7543970 :     Init *BVR = BitsVal->resolveReferences(R, RV);
    1467     7543970 :     return BVR->isComplete() ? BVR : const_cast<FieldInit *>(this);
    1468             :   }
    1469             : 
    1470    29582422 :   if (NewRec != Rec)
    1471      306009 :     return FieldInit::get(NewRec, FieldName);
    1472    29276413 :   return const_cast<FieldInit *>(this);
    1473             : }
    1474             : 
    1475    13193087 : static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringInit *VN,
    1476             :                            ArrayRef<Init *> ArgRange,
    1477             :                            ArrayRef<StringInit *> NameRange) {
    1478    13193087 :   ID.AddPointer(V);
    1479    13193087 :   ID.AddPointer(VN);
    1480             : 
    1481    13193087 :   ArrayRef<Init *>::iterator Arg = ArgRange.begin();
    1482    13193087 :   ArrayRef<StringInit *>::iterator Name = NameRange.begin();
    1483    38362858 :   while (Arg != ArgRange.end()) {
    1484             :     assert(Name != NameRange.end() && "Arg name underflow!");
    1485    25169771 :     ID.AddPointer(*Arg++);
    1486    25169771 :     ID.AddPointer(*Name++);
    1487             :   }
    1488             :   assert(Name == NameRange.end() && "Arg name overflow!");
    1489    13193087 : }
    1490             : 
    1491             : DagInit *
    1492     4213775 : DagInit::get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
    1493             :              ArrayRef<StringInit *> NameRange) {
    1494     4213938 :   static FoldingSet<DagInit> ThePool;
    1495             : 
    1496     8427550 :   FoldingSetNodeID ID;
    1497     4213775 :   ProfileDagInit(ID, V, VN, ArgRange, NameRange);
    1498             : 
    1499     4213775 :   void *IP = nullptr;
    1500     2034427 :   if (DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
    1501             :     return I;
    1502             : 
    1503     4358696 :   void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *, StringInit *>(ArgRange.size(), NameRange.size()), alignof(BitsInit));
    1504     4358696 :   DagInit *I = new(Mem) DagInit(V, VN, ArgRange.size(), NameRange.size());
    1505     6538044 :   std::uninitialized_copy(ArgRange.begin(), ArgRange.end(),
    1506             :                           I->getTrailingObjects<Init *>());
    1507     6538044 :   std::uninitialized_copy(NameRange.begin(), NameRange.end(),
    1508             :                           I->getTrailingObjects<StringInit *>());
    1509     4358696 :   ThePool.InsertNode(I, IP);
    1510     2179348 :   return I;
    1511             : }
    1512             : 
    1513             : DagInit *
    1514     1105489 : DagInit::get(Init *V, StringInit *VN,
    1515             :              ArrayRef<std::pair<Init*, StringInit*>> args) {
    1516     2210978 :   SmallVector<Init *, 8> Args;
    1517     2210978 :   SmallVector<StringInit *, 8> Names;
    1518             : 
    1519     3800535 :   for (const auto &Arg : args) {
    1520     1589557 :     Args.push_back(Arg.first);
    1521     1589557 :     Names.push_back(Arg.second);
    1522             :   }
    1523             : 
    1524     3316467 :   return DagInit::get(V, VN, Args, Names);
    1525             : }
    1526             : 
    1527     8979312 : void DagInit::Profile(FoldingSetNodeID &ID) const {
    1528    44896560 :   ProfileDagInit(ID, Val, ValName, makeArrayRef(getTrailingObjects<Init *>(), NumArgs), makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames));
    1529     8979312 : }
    1530             : 
    1531    13154322 : Init *DagInit::convertInitializerTo(RecTy *Ty) const {
    1532    26308644 :   if (isa<DagRecTy>(Ty))
    1533    13154322 :     return const_cast<DagInit *>(this);
    1534             : 
    1535             :   return nullptr;
    1536             : }
    1537             : 
    1538    28642494 : Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) const {
    1539    57284988 :   SmallVector<Init*, 8> NewArgs;
    1540    57284988 :   NewArgs.reserve(arg_size());
    1541    28642494 :   bool ArgsChanged = false;
    1542   107811610 :   for (const Init *Arg : getArgs()) {
    1543    50526622 :     Init *NewArg = Arg->resolveReferences(R, RV);
    1544    50526622 :     NewArgs.push_back(NewArg);
    1545    50526622 :     ArgsChanged |= NewArg != Arg;
    1546             :   }
    1547             : 
    1548    28642494 :   Init *Op = Val->resolveReferences(R, RV);
    1549    28642494 :   if (Op != Val || ArgsChanged)
    1550     6179570 :     return DagInit::get(Op, ValName, NewArgs, getArgNames());
    1551             : 
    1552    25552709 :   return const_cast<DagInit *>(this);
    1553             : }
    1554             : 
    1555        4256 : std::string DagInit::getAsString() const {
    1556       12768 :   std::string Result = "(" + Val->getAsString();
    1557        4256 :   if (ValName)
    1558           4 :     Result += ":" + ValName->getAsUnquotedString();
    1559        4256 :   if (!arg_empty()) {
    1560       16976 :     Result += " " + getArg(0)->getAsString();
    1561       16036 :     if (getArgName(0)) Result += ":$" + getArgName(0)->getAsUnquotedString();
    1562       12023 :     for (unsigned i = 1, e = getNumArgs(); i != e; ++i) {
    1563       31116 :       Result += ", " + getArg(i)->getAsString();
    1564       28871 :       if (getArgName(i)) Result += ":$" + getArgName(i)->getAsUnquotedString();
    1565             :     }
    1566             :   }
    1567        8512 :   return Result + ")";
    1568             : }
    1569             : 
    1570             : //===----------------------------------------------------------------------===//
    1571             : //    Other implementations
    1572             : //===----------------------------------------------------------------------===//
    1573             : 
    1574     3343041 : RecordVal::RecordVal(Init *N, RecTy *T, bool P)
    1575     6686082 :   : Name(N), TyAndPrefix(T, P) {
    1576     3343041 :   Value = UnsetInit::get()->convertInitializerTo(T);
    1577             :   assert(Value && "Cannot create unset value for current type!");
    1578     3343041 : }
    1579             : 
    1580     1342838 : StringRef RecordVal::getName() const {
    1581     2685676 :   return cast<StringInit>(getNameInit())->getValue();
    1582             : }
    1583             : 
    1584             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
    1585             : LLVM_DUMP_METHOD void RecordVal::dump() const { errs() << *this; }
    1586             : #endif
    1587             : 
    1588        2250 : void RecordVal::print(raw_ostream &OS, bool PrintSem) const {
    1589        2250 :   if (getPrefix()) OS << "field ";
    1590       11250 :   OS << *getType() << " " << getNameInitAsString();
    1591             : 
    1592        2250 :   if (getValue())
    1593        2241 :     OS << " = " << *getValue();
    1594             : 
    1595        2250 :   if (PrintSem) OS << ";\n";
    1596        2250 : }
    1597             : 
    1598             : unsigned Record::LastID = 0;
    1599             : 
    1600     2828488 : void Record::init() {
    1601     2828488 :   checkName();
    1602             : 
    1603             :   // Every record potentially has a def at the top.  This value is
    1604             :   // replaced with the top-level def name at instantiation time.
    1605     5656976 :   addValue(RecordVal(StringInit::get("NAME"), StringRecTy::get(), false));
    1606     2828488 : }
    1607             : 
    1608     3012270 : void Record::checkName() {
    1609             :   // Ensure the record name has string type.
    1610     6024540 :   const TypedInit *TypedName = cast<const TypedInit>(Name);
    1611     3012270 :   if (!isa<StringRecTy>(TypedName->getType()))
    1612           0 :     PrintFatalError(getLoc(), "Record name is not a string!");
    1613     3012270 : }
    1614             : 
    1615     7816040 : DefInit *Record::getDefInit() {
    1616     7816040 :   if (!TheInit)
    1617     2814120 :     TheInit = new(Allocator) DefInit(this, new(Allocator) RecordRecTy(this));
    1618     7816040 :   return TheInit;
    1619             : }
    1620             : 
    1621   221794834 : StringRef Record::getName() const {
    1622   443589668 :   return cast<StringInit>(Name)->getValue();
    1623             : }
    1624             : 
    1625      183782 : void Record::setName(Init *NewName) {
    1626      183782 :   Name = NewName;
    1627      183782 :   checkName();
    1628             :   // DO NOT resolve record values to the name at this point because
    1629             :   // there might be default values for arguments of this def.  Those
    1630             :   // arguments might not have been resolved yet so we don't want to
    1631             :   // prematurely assume values for those arguments were not passed to
    1632             :   // this def.
    1633             :   //
    1634             :   // Nonetheless, it may be that some of this Record's values
    1635             :   // reference the record name.  Indeed, the reason for having the
    1636             :   // record name be an Init is to provide this flexibility.  The extra
    1637             :   // resolve steps after completely instantiating defs takes care of
    1638             :   // this.  See TGParser::ParseDef and TGParser::ParseDefm.
    1639      183782 : }
    1640             : 
    1641    11595945 : void Record::resolveReferencesTo(const RecordVal *RV) {
    1642   488361690 :   for (RecordVal &Value : Values) {
    1643   453573855 :     if (RV == &Value) // Skip resolve the same field as the given one
    1644     9033204 :       continue;
    1645   444540651 :     if (Init *V = Value.getValue())
    1646   889081284 :       if (Value.setValue(V->resolveReferences(*this, RV)))
    1647           0 :         PrintFatalError(getLoc(), "Invalid value is found when setting '" +
    1648           0 :                         Value.getNameInitAsString() +
    1649           0 :                         "' after resolving references" +
    1650           0 :                         (RV ? " against '" + RV->getNameInitAsString() +
    1651           0 :                               "' of (" + RV->getValue()->getAsUnquotedString() +
    1652             :                               ")"
    1653           0 :                             : "") + "\n");
    1654             :   }
    1655    11595945 :   Init *OldName = getNameInit();
    1656    11595945 :   Init *NewName = Name->resolveReferences(*this, RV);
    1657    11595945 :   if (NewName != OldName) {
    1658             :     // Re-register with RecordKeeper.
    1659      180656 :     setName(NewName);
    1660             :   }
    1661    11595945 : }
    1662             : 
    1663             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
    1664             : LLVM_DUMP_METHOD void Record::dump() const { errs() << *this; }
    1665             : #endif
    1666             : 
    1667         687 : raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) {
    1668        2061 :   OS << R.getNameInitAsString();
    1669             : 
    1670         687 :   ArrayRef<Init *> TArgs = R.getTemplateArgs();
    1671         687 :   if (!TArgs.empty()) {
    1672         109 :     OS << "<";
    1673         109 :     bool NeedComma = false;
    1674         387 :     for (const Init *TA : TArgs) {
    1675         169 :       if (NeedComma) OS << ", ";
    1676         169 :       NeedComma = true;
    1677         169 :       const RecordVal *RV = R.getValue(TA);
    1678             :       assert(RV && "Template argument record not found??");
    1679         169 :       RV->print(OS, false);
    1680             :     }
    1681         109 :     OS << ">";
    1682             :   }
    1683             : 
    1684         687 :   OS << " {";
    1685         687 :   ArrayRef<std::pair<Record *, SMRange>> SC = R.getSuperClasses();
    1686         687 :   if (!SC.empty()) {
    1687         531 :     OS << "\t//";
    1688        1815 :     for (const auto &SuperPair : SC)
    1689        3012 :       OS << " " << SuperPair.first->getNameInitAsString();
    1690             :   }
    1691         687 :   OS << "\n";
    1692             : 
    1693        3624 :   for (const RecordVal &Val : R.getValues())
    1694        2253 :     if (Val.getPrefix() && !R.isTemplateArg(Val.getNameInit()))
    1695           3 :       OS << Val;
    1696        3624 :   for (const RecordVal &Val : R.getValues())
    1697        4497 :     if (!Val.getPrefix() && !R.isTemplateArg(Val.getNameInit()))
    1698        2078 :       OS << Val;
    1699             : 
    1700         687 :   return OS << "}\n";
    1701             : }
    1702             : 
    1703      571148 : Init *Record::getValueInit(StringRef FieldName) const {
    1704      571148 :   const RecordVal *R = getValue(FieldName);
    1705      571148 :   if (!R || !R->getValue())
    1706           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1707           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1708      571148 :   return R->getValue();
    1709             : }
    1710             : 
    1711     7403102 : StringRef Record::getValueAsString(StringRef FieldName) const {
    1712     7403102 :   const RecordVal *R = getValue(FieldName);
    1713     7403102 :   if (!R || !R->getValue())
    1714           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1715           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1716             : 
    1717    14560751 :   if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
    1718             :     return SI->getValue();
    1719      490906 :   if (CodeInit *CI = dyn_cast<CodeInit>(R->getValue()))
    1720             :     return CI->getValue();
    1721             : 
    1722           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1723           0 :     FieldName + "' does not have a string initializer!");
    1724             : }
    1725             : 
    1726      707395 : BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const {
    1727      707395 :   const RecordVal *R = getValue(FieldName);
    1728      707395 :   if (!R || !R->getValue())
    1729           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1730           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1731             : 
    1732     1414790 :   if (BitsInit *BI = dyn_cast<BitsInit>(R->getValue()))
    1733      707395 :     return BI;
    1734           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1735           0 :     FieldName + "' does not have a BitsInit initializer!");
    1736             : }
    1737             : 
    1738     4374104 : ListInit *Record::getValueAsListInit(StringRef FieldName) const {
    1739     4374104 :   const RecordVal *R = getValue(FieldName);
    1740     4374104 :   if (!R || !R->getValue())
    1741           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1742           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1743             : 
    1744     8748208 :   if (ListInit *LI = dyn_cast<ListInit>(R->getValue()))
    1745     4374104 :     return LI;
    1746           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1747           0 :     FieldName + "' does not have a list initializer!");
    1748             : }
    1749             : 
    1750             : std::vector<Record*>
    1751     3227552 : Record::getValueAsListOfDefs(StringRef FieldName) const {
    1752     3227552 :   ListInit *List = getValueAsListInit(FieldName);
    1753     3227552 :   std::vector<Record*> Defs;
    1754    11692270 :   for (Init *I : List->getValues()) {
    1755     5237166 :     if (DefInit *DI = dyn_cast<DefInit>(I))
    1756    10474332 :       Defs.push_back(DI->getDef());
    1757             :     else
    1758           0 :       PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1759           0 :         FieldName + "' list is not entirely DefInit!");
    1760             :   }
    1761     3227552 :   return Defs;
    1762             : }
    1763             : 
    1764     3004309 : int64_t Record::getValueAsInt(StringRef FieldName) const {
    1765     3004309 :   const RecordVal *R = getValue(FieldName);
    1766     3004309 :   if (!R || !R->getValue())
    1767           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1768           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1769             : 
    1770     6008618 :   if (IntInit *II = dyn_cast<IntInit>(R->getValue()))
    1771     3004309 :     return II->getValue();
    1772           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1773           0 :     FieldName + "' does not have an int initializer!");
    1774             : }
    1775             : 
    1776             : std::vector<int64_t>
    1777       73298 : Record::getValueAsListOfInts(StringRef FieldName) const {
    1778       73298 :   ListInit *List = getValueAsListInit(FieldName);
    1779       73298 :   std::vector<int64_t> Ints;
    1780      174919 :   for (Init *I : List->getValues()) {
    1781       28323 :     if (IntInit *II = dyn_cast<IntInit>(I))
    1782       56646 :       Ints.push_back(II->getValue());
    1783             :     else
    1784           0 :       PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1785           0 :         FieldName + "' does not have a list of ints initializer!");
    1786             :   }
    1787       73298 :   return Ints;
    1788             : }
    1789             : 
    1790             : std::vector<StringRef>
    1791        9584 : Record::getValueAsListOfStrings(StringRef FieldName) const {
    1792        9584 :   ListInit *List = getValueAsListInit(FieldName);
    1793        9584 :   std::vector<StringRef> Strings;
    1794       29417 :   for (Init *I : List->getValues()) {
    1795       10249 :     if (StringInit *SI = dyn_cast<StringInit>(I))
    1796       20498 :       Strings.push_back(SI->getValue());
    1797             :     else
    1798           0 :       PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1799           0 :         FieldName + "' does not have a list of strings initializer!");
    1800             :   }
    1801        9584 :   return Strings;
    1802             : }
    1803             : 
    1804     5439225 : Record *Record::getValueAsDef(StringRef FieldName) const {
    1805     5439225 :   const RecordVal *R = getValue(FieldName);
    1806     5439225 :   if (!R || !R->getValue())
    1807           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1808           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1809             : 
    1810    10878450 :   if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
    1811     5439225 :     return DI->getDef();
    1812           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1813           0 :     FieldName + "' does not have a def initializer!");
    1814             : }
    1815             : 
    1816    15441827 : bool Record::getValueAsBit(StringRef FieldName) const {
    1817    15441827 :   const RecordVal *R = getValue(FieldName);
    1818    15441827 :   if (!R || !R->getValue())
    1819           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1820           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1821             : 
    1822    30883654 :   if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
    1823    15441827 :     return BI->getValue();
    1824           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1825           0 :     FieldName + "' does not have a bit initializer!");
    1826             : }
    1827             : 
    1828     1375192 : bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
    1829     1375192 :   const RecordVal *R = getValue(FieldName);
    1830     1375192 :   if (!R || !R->getValue())
    1831           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1832           0 :       "' does not have a field named `" + FieldName.str() + "'!\n");
    1833             : 
    1834     2750384 :   if (isa<UnsetInit>(R->getValue())) {
    1835      989591 :     Unset = true;
    1836      989591 :     return false;
    1837             :   }
    1838      385601 :   Unset = false;
    1839      771202 :   if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
    1840      385601 :     return BI->getValue();
    1841           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1842           0 :     FieldName + "' does not have a bit initializer!");
    1843             : }
    1844             : 
    1845     2042852 : DagInit *Record::getValueAsDag(StringRef FieldName) const {
    1846     2042852 :   const RecordVal *R = getValue(FieldName);
    1847     2042852 :   if (!R || !R->getValue())
    1848           0 :     PrintFatalError(getLoc(), "Record `" + getName() +
    1849           0 :       "' does not have a field named `" + FieldName + "'!\n");
    1850             : 
    1851     4085704 :   if (DagInit *DI = dyn_cast<DagInit>(R->getValue()))
    1852     2042852 :     return DI;
    1853           0 :   PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
    1854           0 :     FieldName + "' does not have a dag initializer!");
    1855             : }
    1856             : 
    1857             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
    1858             : LLVM_DUMP_METHOD void MultiClass::dump() const {
    1859             :   errs() << "Record:\n";
    1860             :   Rec.dump();
    1861             : 
    1862             :   errs() << "Defs:\n";
    1863             :   for (const auto &Proto : DefPrototypes)
    1864             :     Proto->dump();
    1865             : }
    1866             : 
    1867             : LLVM_DUMP_METHOD void RecordKeeper::dump() const { errs() << *this; }
    1868             : #endif
    1869             : 
    1870          63 : raw_ostream &llvm::operator<<(raw_ostream &OS, const RecordKeeper &RK) {
    1871          63 :   OS << "------------- Classes -----------------\n";
    1872         328 :   for (const auto &C : RK.getClasses())
    1873         278 :     OS << "class " << *C.second;
    1874             : 
    1875          63 :   OS << "------------- Defs -----------------\n";
    1876         737 :   for (const auto &D : RK.getDefs())
    1877        1096 :     OS << "def " << *D.second;
    1878          63 :   return OS;
    1879             : }
    1880             : 
    1881             : std::vector<Record *>
    1882        1970 : RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const {
    1883        1970 :   Record *Class = getClass(ClassName);
    1884        1970 :   if (!Class)
    1885           0 :     PrintFatalError("ERROR: Couldn't find the `" + ClassName + "' class!\n");
    1886             : 
    1887        1970 :   std::vector<Record*> Defs;
    1888    29977815 :   for (const auto &D : getDefs())
    1889    89915715 :     if (D.second->isSubClassOf(Class))
    1890     4463619 :       Defs.push_back(D.second.get());
    1891             : 
    1892        1970 :   return Defs;
    1893             : }
    1894             : 
    1895    19422572 : static Init *GetStrConcat(Init *I0, Init *I1) {
    1896             :   // Shortcut for the common case of concatenating two strings.
    1897    19116458 :   if (const StringInit *I0s = dyn_cast<StringInit>(I0))
    1898    19081458 :     if (const StringInit *I1s = dyn_cast<StringInit>(I1))
    1899    19081458 :       return ConcatStringInits(I0s, I1s);
    1900      341114 :   return BinOpInit::get(BinOpInit::STRCONCAT, I0, I1, StringRecTy::get());
    1901             : }
    1902             : 
    1903     9146632 : Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass,
    1904             :                         Init *Name, StringRef Scoper) {
    1905     9146632 :   Init *NewName = GetStrConcat(CurRec.getNameInit(), StringInit::get(Scoper));
    1906     9146632 :   NewName = GetStrConcat(NewName, Name);
    1907     9146632 :   if (CurMultiClass && Scoper != "::") {
    1908      564654 :     Init *Prefix = GetStrConcat(CurMultiClass->Rec.getNameInit(),
    1909     1129308 :                                 StringInit::get("::"));
    1910      564654 :     NewName = GetStrConcat(Prefix, NewName);
    1911             :   }
    1912             : 
    1913      153057 :   if (BinOpInit *BinOp = dyn_cast<BinOpInit>(NewName))
    1914      153057 :     NewName = BinOp->Fold(&CurRec, CurMultiClass);
    1915     9146632 :   return NewName;
    1916         825 : }

Generated by: LCOV version 1.13