LLVM  10.0.0
Record.cpp
Go to the documentation of this file.
1 //===- Record.cpp - Record implementation ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implement the tablegen record classes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/FoldingSet.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/Statistic.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/StringSet.h"
23 #include "llvm/Config/llvm-config.h"
24 #include "llvm/Support/Allocator.h"
25 #include "llvm/Support/Casting.h"
26 #include "llvm/Support/Compiler.h"
28 #include "llvm/Support/SMLoc.h"
30 #include "llvm/TableGen/Error.h"
31 #include "llvm/TableGen/Record.h"
32 #include <cassert>
33 #include <cstdint>
34 #include <memory>
35 #include <map>
36 #include <string>
37 #include <utility>
38 #include <vector>
39 
40 using namespace llvm;
41 
42 #define DEBUG_TYPE "tblgen-records"
43 
45 
46 STATISTIC(CodeInitsConstructed,
47  "The total number of unique CodeInits constructed");
48 
49 //===----------------------------------------------------------------------===//
50 // Type implementations
51 //===----------------------------------------------------------------------===//
52 
53 BitRecTy BitRecTy::Shared;
54 CodeRecTy CodeRecTy::Shared;
55 IntRecTy IntRecTy::Shared;
56 StringRecTy StringRecTy::Shared;
57 DagRecTy DagRecTy::Shared;
58 
59 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
60 LLVM_DUMP_METHOD void RecTy::dump() const { print(errs()); }
61 #endif
62 
64  if (!ListTy)
65  ListTy = new(Allocator) ListRecTy(this);
66  return ListTy;
67 }
68 
69 bool RecTy::typeIsConvertibleTo(const RecTy *RHS) const {
70  assert(RHS && "NULL pointer");
71  return Kind == RHS->getRecTyKind();
72 }
73 
74 bool RecTy::typeIsA(const RecTy *RHS) const { return this == RHS; }
75 
76 bool BitRecTy::typeIsConvertibleTo(const RecTy *RHS) const{
78  return true;
79  if (const BitsRecTy *BitsTy = dyn_cast<BitsRecTy>(RHS))
80  return BitsTy->getNumBits() == 1;
81  return false;
82 }
83 
84 BitsRecTy *BitsRecTy::get(unsigned Sz) {
85  static std::vector<BitsRecTy*> Shared;
86  if (Sz >= Shared.size())
87  Shared.resize(Sz + 1);
88  BitsRecTy *&Ty = Shared[Sz];
89  if (!Ty)
90  Ty = new(Allocator) BitsRecTy(Sz);
91  return Ty;
92 }
93 
94 std::string BitsRecTy::getAsString() const {
95  return "bits<" + utostr(Size) + ">";
96 }
97 
98 bool BitsRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
99  if (RecTy::typeIsConvertibleTo(RHS)) //argument and the sender are same type
100  return cast<BitsRecTy>(RHS)->Size == Size;
101  RecTyKind kind = RHS->getRecTyKind();
102  return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
103 }
104 
105 bool BitsRecTy::typeIsA(const RecTy *RHS) const {
106  if (const BitsRecTy *RHSb = dyn_cast<BitsRecTy>(RHS))
107  return RHSb->Size == Size;
108  return false;
109 }
110 
111 bool IntRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
112  RecTyKind kind = RHS->getRecTyKind();
113  return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
114 }
115 
116 bool CodeRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
117  RecTyKind Kind = RHS->getRecTyKind();
118  return Kind == CodeRecTyKind || Kind == StringRecTyKind;
119 }
120 
121 std::string StringRecTy::getAsString() const {
122  return "string";
123 }
124 
125 bool StringRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
126  RecTyKind Kind = RHS->getRecTyKind();
127  return Kind == StringRecTyKind || Kind == CodeRecTyKind;
128 }
129 
130 std::string ListRecTy::getAsString() const {
131  return "list<" + Ty->getAsString() + ">";
132 }
133 
134 bool ListRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
135  if (const auto *ListTy = dyn_cast<ListRecTy>(RHS))
136  return Ty->typeIsConvertibleTo(ListTy->getElementType());
137  return false;
138 }
139 
140 bool ListRecTy::typeIsA(const RecTy *RHS) const {
141  if (const ListRecTy *RHSl = dyn_cast<ListRecTy>(RHS))
142  return getElementType()->typeIsA(RHSl->getElementType());
143  return false;
144 }
145 
146 std::string DagRecTy::getAsString() const {
147  return "dag";
148 }
149 
151  ArrayRef<Record *> Classes) {
152  ID.AddInteger(Classes.size());
153  for (Record *R : Classes)
154  ID.AddPointer(R);
155 }
156 
158  if (UnsortedClasses.empty()) {
159  static RecordRecTy AnyRecord(0);
160  return &AnyRecord;
161  }
162 
163  FoldingSet<RecordRecTy> &ThePool =
164  UnsortedClasses[0]->getRecords().RecordTypePool;
165 
166  SmallVector<Record *, 4> Classes(UnsortedClasses.begin(),
167  UnsortedClasses.end());
168  llvm::sort(Classes, [](Record *LHS, Record *RHS) {
169  return LHS->getNameInitAsString() < RHS->getNameInitAsString();
170  });
171 
173  ProfileRecordRecTy(ID, Classes);
174 
175  void *IP = nullptr;
176  if (RecordRecTy *Ty = ThePool.FindNodeOrInsertPos(ID, IP))
177  return Ty;
178 
179 #ifndef NDEBUG
180  // Check for redundancy.
181  for (unsigned i = 0; i < Classes.size(); ++i) {
182  for (unsigned j = 0; j < Classes.size(); ++j) {
183  assert(i == j || !Classes[i]->isSubClassOf(Classes[j]));
184  }
185  assert(&Classes[0]->getRecords() == &Classes[i]->getRecords());
186  }
187 #endif
188 
189  void *Mem = Allocator.Allocate(totalSizeToAlloc<Record *>(Classes.size()),
190  alignof(RecordRecTy));
191  RecordRecTy *Ty = new(Mem) RecordRecTy(Classes.size());
192  std::uninitialized_copy(Classes.begin(), Classes.end(),
193  Ty->getTrailingObjects<Record *>());
194  ThePool.InsertNode(Ty, IP);
195  return Ty;
196 }
197 
199  ProfileRecordRecTy(ID, getClasses());
200 }
201 
202 std::string RecordRecTy::getAsString() const {
203  if (NumClasses == 1)
204  return getClasses()[0]->getNameInitAsString();
205 
206  std::string Str = "{";
207  bool First = true;
208  for (Record *R : getClasses()) {
209  if (!First)
210  Str += ", ";
211  First = false;
212  Str += R->getNameInitAsString();
213  }
214  Str += "}";
215  return Str;
216 }
217 
218 bool RecordRecTy::isSubClassOf(Record *Class) const {
219  return llvm::any_of(getClasses(), [Class](Record *MySuperClass) {
220  return MySuperClass == Class ||
221  MySuperClass->isSubClassOf(Class);
222  });
223 }
224 
225 bool RecordRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
226  if (this == RHS)
227  return true;
228 
229  const RecordRecTy *RTy = dyn_cast<RecordRecTy>(RHS);
230  if (!RTy)
231  return false;
232 
233  return llvm::all_of(RTy->getClasses(), [this](Record *TargetClass) {
234  return isSubClassOf(TargetClass);
235  });
236 }
237 
238 bool RecordRecTy::typeIsA(const RecTy *RHS) const {
239  return typeIsConvertibleTo(RHS);
240 }
241 
243  SmallVector<Record *, 4> CommonSuperClasses;
245 
246  Stack.insert(Stack.end(), T1->classes_begin(), T1->classes_end());
247 
248  while (!Stack.empty()) {
249  Record *R = Stack.back();
250  Stack.pop_back();
251 
252  if (T2->isSubClassOf(R)) {
253  CommonSuperClasses.push_back(R);
254  } else {
255  R->getDirectSuperClasses(Stack);
256  }
257  }
258 
259  return RecordRecTy::get(CommonSuperClasses);
260 }
261 
263  if (T1 == T2)
264  return T1;
265 
266  if (RecordRecTy *RecTy1 = dyn_cast<RecordRecTy>(T1)) {
267  if (RecordRecTy *RecTy2 = dyn_cast<RecordRecTy>(T2))
268  return resolveRecordTypes(RecTy1, RecTy2);
269  }
270 
271  if (T1->typeIsConvertibleTo(T2))
272  return T2;
273  if (T2->typeIsConvertibleTo(T1))
274  return T1;
275 
276  if (ListRecTy *ListTy1 = dyn_cast<ListRecTy>(T1)) {
277  if (ListRecTy *ListTy2 = dyn_cast<ListRecTy>(T2)) {
278  RecTy* NewType = resolveTypes(ListTy1->getElementType(),
279  ListTy2->getElementType());
280  if (NewType)
281  return NewType->getListTy();
282  }
283  }
284 
285  return nullptr;
286 }
287 
288 //===----------------------------------------------------------------------===//
289 // Initializer implementations
290 //===----------------------------------------------------------------------===//
291 
292 void Init::anchor() {}
293 
294 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
295 LLVM_DUMP_METHOD void Init::dump() const { return print(errs()); }
296 #endif
297 
299  static UnsetInit TheInit;
300  return &TheInit;
301 }
302 
304  return const_cast<UnsetInit *>(this);
305 }
306 
308  return const_cast<UnsetInit *>(this);
309 }
310 
312  static BitInit True(true);
313  static BitInit False(false);
314 
315  return V ? &True : &False;
316 }
317 
319  if (isa<BitRecTy>(Ty))
320  return const_cast<BitInit *>(this);
321 
322  if (isa<IntRecTy>(Ty))
323  return IntInit::get(getValue());
324 
325  if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
326  // Can only convert single bit.
327  if (BRT->getNumBits() == 1)
328  return BitsInit::get(const_cast<BitInit *>(this));
329  }
330 
331  return nullptr;
332 }
333 
334 static void
336  ID.AddInteger(Range.size());
337 
338  for (Init *I : Range)
339  ID.AddPointer(I);
340 }
341 
343  static FoldingSet<BitsInit> ThePool;
344 
346  ProfileBitsInit(ID, Range);
347 
348  void *IP = nullptr;
349  if (BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
350  return I;
351 
352  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
353  alignof(BitsInit));
354  BitsInit *I = new(Mem) BitsInit(Range.size());
355  std::uninitialized_copy(Range.begin(), Range.end(),
356  I->getTrailingObjects<Init *>());
357  ThePool.InsertNode(I, IP);
358  return I;
359 }
360 
362  ProfileBitsInit(ID, makeArrayRef(getTrailingObjects<Init *>(), NumBits));
363 }
364 
366  if (isa<BitRecTy>(Ty)) {
367  if (getNumBits() != 1) return nullptr; // Only accept if just one bit!
368  return getBit(0);
369  }
370 
371  if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
372  // If the number of bits is right, return it. Otherwise we need to expand
373  // or truncate.
374  if (getNumBits() != BRT->getNumBits()) return nullptr;
375  return const_cast<BitsInit *>(this);
376  }
377 
378  if (isa<IntRecTy>(Ty)) {
379  int64_t Result = 0;
380  for (unsigned i = 0, e = getNumBits(); i != e; ++i)
381  if (auto *Bit = dyn_cast<BitInit>(getBit(i)))
382  Result |= static_cast<int64_t>(Bit->getValue()) << i;
383  else
384  return nullptr;
385  return IntInit::get(Result);
386  }
387 
388  return nullptr;
389 }
390 
391 Init *
393  SmallVector<Init *, 16> NewBits(Bits.size());
394 
395  for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
396  if (Bits[i] >= getNumBits())
397  return nullptr;
398  NewBits[i] = getBit(Bits[i]);
399  }
400  return BitsInit::get(NewBits);
401 }
402 
403 bool BitsInit::isConcrete() const {
404  for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
405  if (!getBit(i)->isConcrete())
406  return false;
407  }
408  return true;
409 }
410 
411 std::string BitsInit::getAsString() const {
412  std::string Result = "{ ";
413  for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
414  if (i) Result += ", ";
415  if (Init *Bit = getBit(e-i-1))
416  Result += Bit->getAsString();
417  else
418  Result += "*";
419  }
420  return Result + " }";
421 }
422 
423 // resolveReferences - If there are any field references that refer to fields
424 // that have been filled in, we can propagate the values now.
426  bool Changed = false;
427  SmallVector<Init *, 16> NewBits(getNumBits());
428 
429  Init *CachedBitVarRef = nullptr;
430  Init *CachedBitVarResolved = nullptr;
431 
432  for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
433  Init *CurBit = getBit(i);
434  Init *NewBit = CurBit;
435 
436  if (VarBitInit *CurBitVar = dyn_cast<VarBitInit>(CurBit)) {
437  if (CurBitVar->getBitVar() != CachedBitVarRef) {
438  CachedBitVarRef = CurBitVar->getBitVar();
439  CachedBitVarResolved = CachedBitVarRef->resolveReferences(R);
440  }
441  assert(CachedBitVarResolved && "Unresolved bitvar reference");
442  NewBit = CachedBitVarResolved->getBit(CurBitVar->getBitNum());
443  } else {
444  // getBit(0) implicitly converts int and bits<1> values to bit.
445  NewBit = CurBit->resolveReferences(R)->getBit(0);
446  }
447 
448  if (isa<UnsetInit>(NewBit) && R.keepUnsetBits())
449  NewBit = CurBit;
450  NewBits[i] = NewBit;
451  Changed |= CurBit != NewBit;
452  }
453 
454  if (Changed)
455  return BitsInit::get(NewBits);
456 
457  return const_cast<BitsInit *>(this);
458 }
459 
460 IntInit *IntInit::get(int64_t V) {
461  static std::map<int64_t, IntInit*> ThePool;
462 
463  IntInit *&I = ThePool[V];
464  if (!I) I = new(Allocator) IntInit(V);
465  return I;
466 }
467 
468 std::string IntInit::getAsString() const {
469  return itostr(Value);
470 }
471 
472 static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
473  // For example, with NumBits == 4, we permit Values from [-7 .. 15].
474  return (NumBits >= sizeof(Value) * 8) ||
475  (Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
476 }
477 
479  if (isa<IntRecTy>(Ty))
480  return const_cast<IntInit *>(this);
481 
482  if (isa<BitRecTy>(Ty)) {
483  int64_t Val = getValue();
484  if (Val != 0 && Val != 1) return nullptr; // Only accept 0 or 1 for a bit!
485  return BitInit::get(Val != 0);
486  }
487 
488  if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
489  int64_t Value = getValue();
490  // Make sure this bitfield is large enough to hold the integer value.
491  if (!canFitInBitfield(Value, BRT->getNumBits()))
492  return nullptr;
493 
494  SmallVector<Init *, 16> NewBits(BRT->getNumBits());
495  for (unsigned i = 0; i != BRT->getNumBits(); ++i)
496  NewBits[i] = BitInit::get(Value & ((i < 64) ? (1LL << i) : 0));
497 
498  return BitsInit::get(NewBits);
499  }
500 
501  return nullptr;
502 }
503 
504 Init *
506  SmallVector<Init *, 16> NewBits(Bits.size());
507 
508  for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
509  if (Bits[i] >= 64)
510  return nullptr;
511 
512  NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i]));
513  }
514  return BitsInit::get(NewBits);
515 }
516 
518  static StringSet<BumpPtrAllocator &> ThePool(Allocator);
519 
520  CodeInitsConstructed++;
521 
522  // Unlike StringMap, StringSet doesn't accept empty keys.
523  if (V.empty())
524  return new (Allocator) CodeInit("", Loc);
525 
526  // Location tracking prevents us from de-duping CodeInits as we're never
527  // called with the same string and same location twice. However, we can at
528  // least de-dupe the strings for a modest saving.
529  auto &Entry = *ThePool.insert(V).first;
530  return new(Allocator) CodeInit(Entry.getKey(), Loc);
531 }
532 
534  static StringMap<StringInit*, BumpPtrAllocator &> ThePool(Allocator);
535 
536  auto &Entry = *ThePool.insert(std::make_pair(V, nullptr)).first;
537  if (!Entry.second)
538  Entry.second = new(Allocator) StringInit(Entry.getKey());
539  return Entry.second;
540 }
541 
543  if (isa<StringRecTy>(Ty))
544  return const_cast<StringInit *>(this);
545  if (isa<CodeRecTy>(Ty))
546  return CodeInit::get(getValue(), SMLoc());
547 
548  return nullptr;
549 }
550 
552  if (isa<CodeRecTy>(Ty))
553  return const_cast<CodeInit *>(this);
554  if (isa<StringRecTy>(Ty))
555  return StringInit::get(getValue());
556 
557  return nullptr;
558 }
559 
561  ArrayRef<Init *> Range,
562  RecTy *EltTy) {
563  ID.AddInteger(Range.size());
564  ID.AddPointer(EltTy);
565 
566  for (Init *I : Range)
567  ID.AddPointer(I);
568 }
569 
571  static FoldingSet<ListInit> ThePool;
572 
574  ProfileListInit(ID, Range, EltTy);
575 
576  void *IP = nullptr;
577  if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
578  return I;
579 
580  assert(Range.empty() || !isa<TypedInit>(Range[0]) ||
581  cast<TypedInit>(Range[0])->getType()->typeIsConvertibleTo(EltTy));
582 
583  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
584  alignof(ListInit));
585  ListInit *I = new(Mem) ListInit(Range.size(), EltTy);
586  std::uninitialized_copy(Range.begin(), Range.end(),
587  I->getTrailingObjects<Init *>());
588  ThePool.InsertNode(I, IP);
589  return I;
590 }
591 
593  RecTy *EltTy = cast<ListRecTy>(getType())->getElementType();
594 
595  ProfileListInit(ID, getValues(), EltTy);
596 }
597 
599  if (getType() == Ty)
600  return const_cast<ListInit*>(this);
601 
602  if (auto *LRT = dyn_cast<ListRecTy>(Ty)) {
603  SmallVector<Init*, 8> Elements;
604  Elements.reserve(getValues().size());
605 
606  // Verify that all of the elements of the list are subclasses of the
607  // appropriate class!
608  bool Changed = false;
609  RecTy *ElementType = LRT->getElementType();
610  for (Init *I : getValues())
611  if (Init *CI = I->convertInitializerTo(ElementType)) {
612  Elements.push_back(CI);
613  if (CI != I)
614  Changed = true;
615  } else
616  return nullptr;
617 
618  if (!Changed)
619  return const_cast<ListInit*>(this);
620  return ListInit::get(Elements, ElementType);
621  }
622 
623  return nullptr;
624 }
625 
628  Vals.reserve(Elements.size());
629  for (unsigned Element : Elements) {
630  if (Element >= size())
631  return nullptr;
632  Vals.push_back(getElement(Element));
633  }
634  return ListInit::get(Vals, getElementType());
635 }
636 
638  assert(i < NumValues && "List element index out of range!");
639  DefInit *DI = dyn_cast<DefInit>(getElement(i));
640  if (!DI)
641  PrintFatalError("Expected record in list!");
642  return DI->getDef();
643 }
644 
646  SmallVector<Init*, 8> Resolved;
647  Resolved.reserve(size());
648  bool Changed = false;
649 
650  for (Init *CurElt : getValues()) {
651  Init *E = CurElt->resolveReferences(R);
652  Changed |= E != CurElt;
653  Resolved.push_back(E);
654  }
655 
656  if (Changed)
657  return ListInit::get(Resolved, getElementType());
658  return const_cast<ListInit *>(this);
659 }
660 
661 bool ListInit::isConcrete() const {
662  for (Init *Element : *this) {
663  if (!Element->isConcrete())
664  return false;
665  }
666  return true;
667 }
668 
669 std::string ListInit::getAsString() const {
670  std::string Result = "[";
671  const char *sep = "";
672  for (Init *Element : *this) {
673  Result += sep;
674  sep = ", ";
675  Result += Element->getAsString();
676  }
677  return Result + "]";
678 }
679 
680 Init *OpInit::getBit(unsigned Bit) const {
681  if (getType() == BitRecTy::get())
682  return const_cast<OpInit*>(this);
683  return VarBitInit::get(const_cast<OpInit*>(this), Bit);
684 }
685 
686 static void
688  ID.AddInteger(Opcode);
689  ID.AddPointer(Op);
690  ID.AddPointer(Type);
691 }
692 
694  static FoldingSet<UnOpInit> ThePool;
695 
697  ProfileUnOpInit(ID, Opc, LHS, Type);
698 
699  void *IP = nullptr;
700  if (UnOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
701  return I;
702 
703  UnOpInit *I = new(Allocator) UnOpInit(Opc, LHS, Type);
704  ThePool.InsertNode(I, IP);
705  return I;
706 }
707 
709  ProfileUnOpInit(ID, getOpcode(), getOperand(), getType());
710 }
711 
712 Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
713  switch (getOpcode()) {
714  case CAST:
715  if (isa<StringRecTy>(getType())) {
716  if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
717  return LHSs;
718 
719  if (DefInit *LHSd = dyn_cast<DefInit>(LHS))
720  return StringInit::get(LHSd->getAsString());
721 
722  if (IntInit *LHSi = dyn_cast<IntInit>(LHS))
723  return StringInit::get(LHSi->getAsString());
724  } else if (isa<RecordRecTy>(getType())) {
725  if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
726  if (!CurRec && !IsFinal)
727  break;
728  assert(CurRec && "NULL pointer");
729  Record *D;
730 
731  // Self-references are allowed, but their resolution is delayed until
732  // the final resolve to ensure that we get the correct type for them.
733  if (Name == CurRec->getNameInit()) {
734  if (!IsFinal)
735  break;
736  D = CurRec;
737  } else {
738  D = CurRec->getRecords().getDef(Name->getValue());
739  if (!D) {
740  if (IsFinal)
741  PrintFatalError(CurRec->getLoc(),
742  Twine("Undefined reference to record: '") +
743  Name->getValue() + "'\n");
744  break;
745  }
746  }
747 
748  DefInit *DI = DefInit::get(D);
749  if (!DI->getType()->typeIsA(getType())) {
750  PrintFatalError(CurRec->getLoc(),
751  Twine("Expected type '") +
752  getType()->getAsString() + "', got '" +
753  DI->getType()->getAsString() + "' in: " +
754  getAsString() + "\n");
755  }
756  return DI;
757  }
758  }
759 
760  if (Init *NewInit = LHS->convertInitializerTo(getType()))
761  return NewInit;
762  break;
763 
764  case HEAD:
765  if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
766  assert(!LHSl->empty() && "Empty list in head");
767  return LHSl->getElement(0);
768  }
769  break;
770 
771  case TAIL:
772  if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
773  assert(!LHSl->empty() && "Empty list in tail");
774  // Note the +1. We can't just pass the result of getValues()
775  // directly.
776  return ListInit::get(LHSl->getValues().slice(1), LHSl->getElementType());
777  }
778  break;
779 
780  case SIZE:
781  if (ListInit *LHSl = dyn_cast<ListInit>(LHS))
782  return IntInit::get(LHSl->size());
783  break;
784 
785  case EMPTY:
786  if (ListInit *LHSl = dyn_cast<ListInit>(LHS))
787  return IntInit::get(LHSl->empty());
788  if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
789  return IntInit::get(LHSs->getValue().empty());
790  break;
791 
792  case GETOP:
793  if (DagInit *Dag = dyn_cast<DagInit>(LHS)) {
794  DefInit *DI = DefInit::get(Dag->getOperatorAsDef({}));
795  if (!DI->getType()->typeIsA(getType())) {
796  PrintFatalError(CurRec->getLoc(),
797  Twine("Expected type '") +
798  getType()->getAsString() + "', got '" +
799  DI->getType()->getAsString() + "' in: " +
800  getAsString() + "\n");
801  } else {
802  return DI;
803  }
804  }
805  break;
806  }
807  return const_cast<UnOpInit *>(this);
808 }
809 
811  Init *lhs = LHS->resolveReferences(R);
812 
813  if (LHS != lhs || (R.isFinal() && getOpcode() == CAST))
814  return (UnOpInit::get(getOpcode(), lhs, getType()))
815  ->Fold(R.getCurrentRecord(), R.isFinal());
816  return const_cast<UnOpInit *>(this);
817 }
818 
819 std::string UnOpInit::getAsString() const {
820  std::string Result;
821  switch (getOpcode()) {
822  case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
823  case HEAD: Result = "!head"; break;
824  case TAIL: Result = "!tail"; break;
825  case SIZE: Result = "!size"; break;
826  case EMPTY: Result = "!empty"; break;
827  case GETOP: Result = "!getop"; break;
828  }
829  return Result + "(" + LHS->getAsString() + ")";
830 }
831 
832 static void
833 ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS,
834  RecTy *Type) {
835  ID.AddInteger(Opcode);
836  ID.AddPointer(LHS);
837  ID.AddPointer(RHS);
838  ID.AddPointer(Type);
839 }
840 
842  Init *RHS, RecTy *Type) {
843  static FoldingSet<BinOpInit> ThePool;
844 
846  ProfileBinOpInit(ID, Opc, LHS, RHS, Type);
847 
848  void *IP = nullptr;
849  if (BinOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
850  return I;
851 
852  BinOpInit *I = new(Allocator) BinOpInit(Opc, LHS, RHS, Type);
853  ThePool.InsertNode(I, IP);
854  return I;
855 }
856 
858  ProfileBinOpInit(ID, getOpcode(), getLHS(), getRHS(), getType());
859 }
860 
862  const StringInit *I1) {
864  Concat.append(I1->getValue());
865  return StringInit::get(Concat);
866 }
867 
869  // Shortcut for the common case of concatenating two strings.
870  if (const StringInit *I0s = dyn_cast<StringInit>(I0))
871  if (const StringInit *I1s = dyn_cast<StringInit>(I1))
872  return ConcatStringInits(I0s, I1s);
874 }
875 
876 static ListInit *ConcatListInits(const ListInit *LHS,
877  const ListInit *RHS) {
879  Args.insert(Args.end(), LHS->begin(), LHS->end());
880  Args.insert(Args.end(), RHS->begin(), RHS->end());
881  return ListInit::get(Args, LHS->getElementType());
882 }
883 
885  assert(isa<ListRecTy>(LHS->getType()) && "First arg must be a list");
886 
887  // Shortcut for the common case of concatenating two lists.
888  if (const ListInit *LHSList = dyn_cast<ListInit>(LHS))
889  if (const ListInit *RHSList = dyn_cast<ListInit>(RHS))
890  return ConcatListInits(LHSList, RHSList);
891  return BinOpInit::get(BinOpInit::LISTCONCAT, LHS, RHS, LHS->getType());
892 }
893 
895  return BinOpInit::get(BinOpInit::LISTSPLAT, LHS, RHS, LHS->getType());
896 }
897 
898 Init *BinOpInit::Fold(Record *CurRec) const {
899  switch (getOpcode()) {
900  case CONCAT: {
901  DagInit *LHSs = dyn_cast<DagInit>(LHS);
902  DagInit *RHSs = dyn_cast<DagInit>(RHS);
903  if (LHSs && RHSs) {
904  DefInit *LOp = dyn_cast<DefInit>(LHSs->getOperator());
905  DefInit *ROp = dyn_cast<DefInit>(RHSs->getOperator());
906  if ((!LOp && !isa<UnsetInit>(LHSs->getOperator())) ||
907  (!ROp && !isa<UnsetInit>(RHSs->getOperator())))
908  break;
909  if (LOp && ROp && LOp->getDef() != ROp->getDef()) {
910  PrintFatalError(Twine("Concatenated Dag operators do not match: '") +
911  LHSs->getAsString() + "' vs. '" + RHSs->getAsString() +
912  "'");
913  }
914  Init *Op = LOp ? LOp : ROp;
915  if (!Op)
916  Op = UnsetInit::get();
917 
920  for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
921  Args.push_back(LHSs->getArg(i));
922  ArgNames.push_back(LHSs->getArgName(i));
923  }
924  for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
925  Args.push_back(RHSs->getArg(i));
926  ArgNames.push_back(RHSs->getArgName(i));
927  }
928  return DagInit::get(Op, nullptr, Args, ArgNames);
929  }
930  break;
931  }
932  case LISTCONCAT: {
933  ListInit *LHSs = dyn_cast<ListInit>(LHS);
934  ListInit *RHSs = dyn_cast<ListInit>(RHS);
935  if (LHSs && RHSs) {
937  Args.insert(Args.end(), LHSs->begin(), LHSs->end());
938  Args.insert(Args.end(), RHSs->begin(), RHSs->end());
939  return ListInit::get(Args, LHSs->getElementType());
940  }
941  break;
942  }
943  case LISTSPLAT: {
945  IntInit *Size = dyn_cast<IntInit>(RHS);
946  if (Value && Size) {
947  SmallVector<Init *, 8> Args(Size->getValue(), Value);
948  return ListInit::get(Args, Value->getType());
949  }
950  break;
951  }
952  case STRCONCAT: {
953  StringInit *LHSs = dyn_cast<StringInit>(LHS);
954  StringInit *RHSs = dyn_cast<StringInit>(RHS);
955  if (LHSs && RHSs)
956  return ConcatStringInits(LHSs, RHSs);
957  break;
958  }
959  case EQ:
960  case NE:
961  case LE:
962  case LT:
963  case GE:
964  case GT: {
965  // try to fold eq comparison for 'bit' and 'int', otherwise fallback
966  // to string objects.
967  IntInit *L =
968  dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
969  IntInit *R =
970  dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
971 
972  if (L && R) {
973  bool Result;
974  switch (getOpcode()) {
975  case EQ: Result = L->getValue() == R->getValue(); break;
976  case NE: Result = L->getValue() != R->getValue(); break;
977  case LE: Result = L->getValue() <= R->getValue(); break;
978  case LT: Result = L->getValue() < R->getValue(); break;
979  case GE: Result = L->getValue() >= R->getValue(); break;
980  case GT: Result = L->getValue() > R->getValue(); break;
981  default: llvm_unreachable("unhandled comparison");
982  }
983  return BitInit::get(Result);
984  }
985 
986  if (getOpcode() == EQ || getOpcode() == NE) {
987  StringInit *LHSs = dyn_cast<StringInit>(LHS);
988  StringInit *RHSs = dyn_cast<StringInit>(RHS);
989 
990  // Make sure we've resolved
991  if (LHSs && RHSs) {
992  bool Equal = LHSs->getValue() == RHSs->getValue();
993  return BitInit::get(getOpcode() == EQ ? Equal : !Equal);
994  }
995  }
996 
997  break;
998  }
999  case SETOP: {
1000  DagInit *Dag = dyn_cast<DagInit>(LHS);
1001  DefInit *Op = dyn_cast<DefInit>(RHS);
1002  if (Dag && Op) {
1004  SmallVector<StringInit*, 8> ArgNames;
1005  for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) {
1006  Args.push_back(Dag->getArg(i));
1007  ArgNames.push_back(Dag->getArgName(i));
1008  }
1009  return DagInit::get(Op, nullptr, Args, ArgNames);
1010  }
1011  break;
1012  }
1013  case ADD:
1014  case MUL:
1015  case AND:
1016  case OR:
1017  case SHL:
1018  case SRA:
1019  case SRL: {
1020  IntInit *LHSi =
1021  dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
1022  IntInit *RHSi =
1023  dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
1024  if (LHSi && RHSi) {
1025  int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
1026  int64_t Result;
1027  switch (getOpcode()) {
1028  default: llvm_unreachable("Bad opcode!");
1029  case ADD: Result = LHSv + RHSv; break;
1030  case MUL: Result = LHSv * RHSv; break;
1031  case AND: Result = LHSv & RHSv; break;
1032  case OR: Result = LHSv | RHSv; break;
1033  case SHL: Result = LHSv << RHSv; break;
1034  case SRA: Result = LHSv >> RHSv; break;
1035  case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
1036  }
1037  return IntInit::get(Result);
1038  }
1039  break;
1040  }
1041  }
1042  return const_cast<BinOpInit *>(this);
1043 }
1044 
1046  Init *lhs = LHS->resolveReferences(R);
1047  Init *rhs = RHS->resolveReferences(R);
1048 
1049  if (LHS != lhs || RHS != rhs)
1050  return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))
1051  ->Fold(R.getCurrentRecord());
1052  return const_cast<BinOpInit *>(this);
1053 }
1054 
1055 std::string BinOpInit::getAsString() const {
1056  std::string Result;
1057  switch (getOpcode()) {
1058  case CONCAT: Result = "!con"; break;
1059  case ADD: Result = "!add"; break;
1060  case MUL: Result = "!mul"; break;
1061  case AND: Result = "!and"; break;
1062  case OR: Result = "!or"; break;
1063  case SHL: Result = "!shl"; break;
1064  case SRA: Result = "!sra"; break;
1065  case SRL: Result = "!srl"; break;
1066  case EQ: Result = "!eq"; break;
1067  case NE: Result = "!ne"; break;
1068  case LE: Result = "!le"; break;
1069  case LT: Result = "!lt"; break;
1070  case GE: Result = "!ge"; break;
1071  case GT: Result = "!gt"; break;
1072  case LISTCONCAT: Result = "!listconcat"; break;
1073  case LISTSPLAT: Result = "!listsplat"; break;
1074  case STRCONCAT: Result = "!strconcat"; break;
1075  case SETOP: Result = "!setop"; break;
1076  }
1077  return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
1078 }
1079 
1080 static void
1081 ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
1082  Init *RHS, RecTy *Type) {
1083  ID.AddInteger(Opcode);
1084  ID.AddPointer(LHS);
1085  ID.AddPointer(MHS);
1086  ID.AddPointer(RHS);
1087  ID.AddPointer(Type);
1088 }
1089 
1091  RecTy *Type) {
1092  static FoldingSet<TernOpInit> ThePool;
1093 
1095  ProfileTernOpInit(ID, Opc, LHS, MHS, RHS, Type);
1096 
1097  void *IP = nullptr;
1098  if (TernOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1099  return I;
1100 
1101  TernOpInit *I = new(Allocator) TernOpInit(Opc, LHS, MHS, RHS, Type);
1102  ThePool.InsertNode(I, IP);
1103  return I;
1104 }
1105 
1107  ProfileTernOpInit(ID, getOpcode(), getLHS(), getMHS(), getRHS(), getType());
1108 }
1109 
1110 static Init *ForeachApply(Init *LHS, Init *MHSe, Init *RHS, Record *CurRec) {
1111  MapResolver R(CurRec);
1112  R.set(LHS, MHSe);
1113  return RHS->resolveReferences(R);
1114 }
1115 
1116 static Init *ForeachDagApply(Init *LHS, DagInit *MHSd, Init *RHS,
1117  Record *CurRec) {
1118  bool Change = false;
1119  Init *Val = ForeachApply(LHS, MHSd->getOperator(), RHS, CurRec);
1120  if (Val != MHSd->getOperator())
1121  Change = true;
1122 
1124  for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
1125  Init *Arg = MHSd->getArg(i);
1126  Init *NewArg;
1127  StringInit *ArgName = MHSd->getArgName(i);
1128 
1129  if (DagInit *Argd = dyn_cast<DagInit>(Arg))
1130  NewArg = ForeachDagApply(LHS, Argd, RHS, CurRec);
1131  else
1132  NewArg = ForeachApply(LHS, Arg, RHS, CurRec);
1133 
1134  NewArgs.push_back(std::make_pair(NewArg, ArgName));
1135  if (Arg != NewArg)
1136  Change = true;
1137  }
1138 
1139  if (Change)
1140  return DagInit::get(Val, nullptr, NewArgs);
1141  return MHSd;
1142 }
1143 
1144 // Applies RHS to all elements of MHS, using LHS as a temp variable.
1145 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
1146  Record *CurRec) {
1147  if (DagInit *MHSd = dyn_cast<DagInit>(MHS))
1148  return ForeachDagApply(LHS, MHSd, RHS, CurRec);
1149 
1150  if (ListInit *MHSl = dyn_cast<ListInit>(MHS)) {
1151  SmallVector<Init *, 8> NewList(MHSl->begin(), MHSl->end());
1152 
1153  for (Init *&Item : NewList) {
1154  Init *NewItem = ForeachApply(LHS, Item, RHS, CurRec);
1155  if (NewItem != Item)
1156  Item = NewItem;
1157  }
1158  return ListInit::get(NewList, cast<ListRecTy>(Type)->getElementType());
1159  }
1160 
1161  return nullptr;
1162 }
1163 
1164 Init *TernOpInit::Fold(Record *CurRec) const {
1165  switch (getOpcode()) {
1166  case SUBST: {
1167  DefInit *LHSd = dyn_cast<DefInit>(LHS);
1168  VarInit *LHSv = dyn_cast<VarInit>(LHS);
1169  StringInit *LHSs = dyn_cast<StringInit>(LHS);
1170 
1171  DefInit *MHSd = dyn_cast<DefInit>(MHS);
1172  VarInit *MHSv = dyn_cast<VarInit>(MHS);
1173  StringInit *MHSs = dyn_cast<StringInit>(MHS);
1174 
1175  DefInit *RHSd = dyn_cast<DefInit>(RHS);
1176  VarInit *RHSv = dyn_cast<VarInit>(RHS);
1177  StringInit *RHSs = dyn_cast<StringInit>(RHS);
1178 
1179  if (LHSd && MHSd && RHSd) {
1180  Record *Val = RHSd->getDef();
1181  if (LHSd->getAsString() == RHSd->getAsString())
1182  Val = MHSd->getDef();
1183  return DefInit::get(Val);
1184  }
1185  if (LHSv && MHSv && RHSv) {
1186  std::string Val = RHSv->getName();
1187  if (LHSv->getAsString() == RHSv->getAsString())
1188  Val = MHSv->getName();
1189  return VarInit::get(Val, getType());
1190  }
1191  if (LHSs && MHSs && RHSs) {
1192  std::string Val = RHSs->getValue();
1193 
1194  std::string::size_type found;
1195  std::string::size_type idx = 0;
1196  while (true) {
1197  found = Val.find(LHSs->getValue(), idx);
1198  if (found == std::string::npos)
1199  break;
1200  Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
1201  idx = found + MHSs->getValue().size();
1202  }
1203 
1204  return StringInit::get(Val);
1205  }
1206  break;
1207  }
1208 
1209  case FOREACH: {
1210  if (Init *Result = ForeachHelper(LHS, MHS, RHS, getType(), CurRec))
1211  return Result;
1212  break;
1213  }
1214 
1215  case IF: {
1216  if (IntInit *LHSi = dyn_cast_or_null<IntInit>(
1217  LHS->convertInitializerTo(IntRecTy::get()))) {
1218  if (LHSi->getValue())
1219  return MHS;
1220  return RHS;
1221  }
1222  break;
1223  }
1224 
1225  case DAG: {
1226  ListInit *MHSl = dyn_cast<ListInit>(MHS);
1227  ListInit *RHSl = dyn_cast<ListInit>(RHS);
1228  bool MHSok = MHSl || isa<UnsetInit>(MHS);
1229  bool RHSok = RHSl || isa<UnsetInit>(RHS);
1230 
1231  if (isa<UnsetInit>(MHS) && isa<UnsetInit>(RHS))
1232  break; // Typically prevented by the parser, but might happen with template args
1233 
1234  if (MHSok && RHSok && (!MHSl || !RHSl || MHSl->size() == RHSl->size())) {
1236  unsigned Size = MHSl ? MHSl->size() : RHSl->size();
1237  for (unsigned i = 0; i != Size; ++i) {
1238  Init *Node = MHSl ? MHSl->getElement(i) : UnsetInit::get();
1239  Init *Name = RHSl ? RHSl->getElement(i) : UnsetInit::get();
1240  if (!isa<StringInit>(Name) && !isa<UnsetInit>(Name))
1241  return const_cast<TernOpInit *>(this);
1242  Children.emplace_back(Node, dyn_cast<StringInit>(Name));
1243  }
1244  return DagInit::get(LHS, nullptr, Children);
1245  }
1246  break;
1247  }
1248  }
1249 
1250  return const_cast<TernOpInit *>(this);
1251 }
1252 
1254  Init *lhs = LHS->resolveReferences(R);
1255 
1256  if (getOpcode() == IF && lhs != LHS) {
1257  if (IntInit *Value = dyn_cast_or_null<IntInit>(
1259  // Short-circuit
1260  if (Value->getValue())
1261  return MHS->resolveReferences(R);
1262  return RHS->resolveReferences(R);
1263  }
1264  }
1265 
1266  Init *mhs = MHS->resolveReferences(R);
1267  Init *rhs;
1268 
1269  if (getOpcode() == FOREACH) {
1270  ShadowResolver SR(R);
1271  SR.addShadow(lhs);
1272  rhs = RHS->resolveReferences(SR);
1273  } else {
1274  rhs = RHS->resolveReferences(R);
1275  }
1276 
1277  if (LHS != lhs || MHS != mhs || RHS != rhs)
1278  return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))
1279  ->Fold(R.getCurrentRecord());
1280  return const_cast<TernOpInit *>(this);
1281 }
1282 
1283 std::string TernOpInit::getAsString() const {
1284  std::string Result;
1285  bool UnquotedLHS = false;
1286  switch (getOpcode()) {
1287  case SUBST: Result = "!subst"; break;
1288  case FOREACH: Result = "!foreach"; UnquotedLHS = true; break;
1289  case IF: Result = "!if"; break;
1290  case DAG: Result = "!dag"; break;
1291  }
1292  return (Result + "(" +
1293  (UnquotedLHS ? LHS->getAsUnquotedString() : LHS->getAsString()) +
1294  ", " + MHS->getAsString() + ", " + RHS->getAsString() + ")");
1295 }
1296 
1298  Init *Start, Init *List, Init *Expr,
1299  RecTy *Type) {
1300  ID.AddPointer(Start);
1301  ID.AddPointer(List);
1302  ID.AddPointer(A);
1303  ID.AddPointer(B);
1304  ID.AddPointer(Expr);
1305  ID.AddPointer(Type);
1306 }
1307 
1309  Init *Expr, RecTy *Type) {
1310  static FoldingSet<FoldOpInit> ThePool;
1311 
1313  ProfileFoldOpInit(ID, Start, List, A, B, Expr, Type);
1314 
1315  void *IP = nullptr;
1316  if (FoldOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1317  return I;
1318 
1319  FoldOpInit *I = new (Allocator) FoldOpInit(Start, List, A, B, Expr, Type);
1320  ThePool.InsertNode(I, IP);
1321  return I;
1322 }
1323 
1325  ProfileFoldOpInit(ID, Start, List, A, B, Expr, getType());
1326 }
1327 
1328 Init *FoldOpInit::Fold(Record *CurRec) const {
1329  if (ListInit *LI = dyn_cast<ListInit>(List)) {
1330  Init *Accum = Start;
1331  for (Init *Elt : *LI) {
1332  MapResolver R(CurRec);
1333  R.set(A, Accum);
1334  R.set(B, Elt);
1335  Accum = Expr->resolveReferences(R);
1336  }
1337  return Accum;
1338  }
1339  return const_cast<FoldOpInit *>(this);
1340 }
1341 
1343  Init *NewStart = Start->resolveReferences(R);
1344  Init *NewList = List->resolveReferences(R);
1345  ShadowResolver SR(R);
1346  SR.addShadow(A);
1347  SR.addShadow(B);
1348  Init *NewExpr = Expr->resolveReferences(SR);
1349 
1350  if (Start == NewStart && List == NewList && Expr == NewExpr)
1351  return const_cast<FoldOpInit *>(this);
1352 
1353  return get(NewStart, NewList, A, B, NewExpr, getType())
1354  ->Fold(R.getCurrentRecord());
1355 }
1356 
1357 Init *FoldOpInit::getBit(unsigned Bit) const {
1358  return VarBitInit::get(const_cast<FoldOpInit *>(this), Bit);
1359 }
1360 
1361 std::string FoldOpInit::getAsString() const {
1362  return (Twine("!foldl(") + Start->getAsString() + ", " + List->getAsString() +
1363  ", " + A->getAsUnquotedString() + ", " + B->getAsUnquotedString() +
1364  ", " + Expr->getAsString() + ")")
1365  .str();
1366 }
1367 
1369  Init *Expr) {
1370  ID.AddPointer(CheckType);
1371  ID.AddPointer(Expr);
1372 }
1373 
1375  static FoldingSet<IsAOpInit> ThePool;
1376 
1378  ProfileIsAOpInit(ID, CheckType, Expr);
1379 
1380  void *IP = nullptr;
1381  if (IsAOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1382  return I;
1383 
1384  IsAOpInit *I = new (Allocator) IsAOpInit(CheckType, Expr);
1385  ThePool.InsertNode(I, IP);
1386  return I;
1387 }
1388 
1390  ProfileIsAOpInit(ID, CheckType, Expr);
1391 }
1392 
1394  if (TypedInit *TI = dyn_cast<TypedInit>(Expr)) {
1395  // Is the expression type known to be (a subclass of) the desired type?
1396  if (TI->getType()->typeIsConvertibleTo(CheckType))
1397  return IntInit::get(1);
1398 
1399  if (isa<RecordRecTy>(CheckType)) {
1400  // If the target type is not a subclass of the expression type, or if
1401  // the expression has fully resolved to a record, we know that it can't
1402  // be of the required type.
1403  if (!CheckType->typeIsConvertibleTo(TI->getType()) || isa<DefInit>(Expr))
1404  return IntInit::get(0);
1405  } else {
1406  // We treat non-record types as not castable.
1407  return IntInit::get(0);
1408  }
1409  }
1410  return const_cast<IsAOpInit *>(this);
1411 }
1412 
1414  Init *NewExpr = Expr->resolveReferences(R);
1415  if (Expr != NewExpr)
1416  return get(CheckType, NewExpr)->Fold();
1417  return const_cast<IsAOpInit *>(this);
1418 }
1419 
1420 Init *IsAOpInit::getBit(unsigned Bit) const {
1421  return VarBitInit::get(const_cast<IsAOpInit *>(this), Bit);
1422 }
1423 
1424 std::string IsAOpInit::getAsString() const {
1425  return (Twine("!isa<") + CheckType->getAsString() + ">(" +
1426  Expr->getAsString() + ")")
1427  .str();
1428 }
1429 
1431  if (RecordRecTy *RecordType = dyn_cast<RecordRecTy>(getType())) {
1432  for (Record *Rec : RecordType->getClasses()) {
1433  if (RecordVal *Field = Rec->getValue(FieldName))
1434  return Field->getType();
1435  }
1436  }
1437  return nullptr;
1438 }
1439 
1440 Init *
1442  if (getType() == Ty || getType()->typeIsA(Ty))
1443  return const_cast<TypedInit *>(this);
1444 
1445  if (isa<BitRecTy>(getType()) && isa<BitsRecTy>(Ty) &&
1446  cast<BitsRecTy>(Ty)->getNumBits() == 1)
1447  return BitsInit::get({const_cast<TypedInit *>(this)});
1448 
1449  return nullptr;
1450 }
1451 
1454  if (!T) return nullptr; // Cannot subscript a non-bits variable.
1455  unsigned NumBits = T->getNumBits();
1456 
1457  SmallVector<Init *, 16> NewBits;
1458  NewBits.reserve(Bits.size());
1459  for (unsigned Bit : Bits) {
1460  if (Bit >= NumBits)
1461  return nullptr;
1462 
1463  NewBits.push_back(VarBitInit::get(const_cast<TypedInit *>(this), Bit));
1464  }
1465  return BitsInit::get(NewBits);
1466 }
1467 
1469  // Handle the common case quickly
1470  if (getType() == Ty || getType()->typeIsA(Ty))
1471  return const_cast<TypedInit *>(this);
1472 
1473  if (Init *Converted = convertInitializerTo(Ty)) {
1474  assert(!isa<TypedInit>(Converted) ||
1475  cast<TypedInit>(Converted)->getType()->typeIsA(Ty));
1476  return Converted;
1477  }
1478 
1479  if (!getType()->typeIsConvertibleTo(Ty))
1480  return nullptr;
1481 
1482  return UnOpInit::get(UnOpInit::CAST, const_cast<TypedInit *>(this), Ty)
1483  ->Fold(nullptr);
1484 }
1485 
1488  if (!T) return nullptr; // Cannot subscript a non-list variable.
1489 
1490  if (Elements.size() == 1)
1491  return VarListElementInit::get(const_cast<TypedInit *>(this), Elements[0]);
1492 
1493  SmallVector<Init*, 8> ListInits;
1494  ListInits.reserve(Elements.size());
1495  for (unsigned Element : Elements)
1496  ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
1497  Element));
1498  return ListInit::get(ListInits, T->getElementType());
1499 }
1500 
1501 
1503  Init *Value = StringInit::get(VN);
1504  return VarInit::get(Value, T);
1505 }
1506 
1508  using Key = std::pair<RecTy *, Init *>;
1509  static DenseMap<Key, VarInit*> ThePool;
1510 
1511  Key TheKey(std::make_pair(T, VN));
1512 
1513  VarInit *&I = ThePool[TheKey];
1514  if (!I)
1515  I = new(Allocator) VarInit(VN, T);
1516  return I;
1517 }
1518 
1520  StringInit *NameString = cast<StringInit>(getNameInit());
1521  return NameString->getValue();
1522 }
1523 
1524 Init *VarInit::getBit(unsigned Bit) const {
1525  if (getType() == BitRecTy::get())
1526  return const_cast<VarInit*>(this);
1527  return VarBitInit::get(const_cast<VarInit*>(this), Bit);
1528 }
1529 
1531  if (Init *Val = R.resolve(VarName))
1532  return Val;
1533  return const_cast<VarInit *>(this);
1534 }
1535 
1537  using Key = std::pair<TypedInit *, unsigned>;
1538  static DenseMap<Key, VarBitInit*> ThePool;
1539 
1540  Key TheKey(std::make_pair(T, B));
1541 
1542  VarBitInit *&I = ThePool[TheKey];
1543  if (!I)
1544  I = new(Allocator) VarBitInit(T, B);
1545  return I;
1546 }
1547 
1548 std::string VarBitInit::getAsString() const {
1549  return TI->getAsString() + "{" + utostr(Bit) + "}";
1550 }
1551 
1553  Init *I = TI->resolveReferences(R);
1554  if (TI != I)
1555  return I->getBit(getBitNum());
1556 
1557  return const_cast<VarBitInit*>(this);
1558 }
1559 
1561  unsigned E) {
1562  using Key = std::pair<TypedInit *, unsigned>;
1563  static DenseMap<Key, VarListElementInit*> ThePool;
1564 
1565  Key TheKey(std::make_pair(T, E));
1566 
1567  VarListElementInit *&I = ThePool[TheKey];
1568  if (!I) I = new(Allocator) VarListElementInit(T, E);
1569  return I;
1570 }
1571 
1572 std::string VarListElementInit::getAsString() const {
1573  return TI->getAsString() + "[" + utostr(Element) + "]";
1574 }
1575 
1577  Init *NewTI = TI->resolveReferences(R);
1578  if (ListInit *List = dyn_cast<ListInit>(NewTI)) {
1579  // Leave out-of-bounds array references as-is. This can happen without
1580  // being an error, e.g. in the untaken "branch" of an !if expression.
1581  if (getElementNum() < List->size())
1582  return List->getElement(getElementNum());
1583  }
1584  if (NewTI != TI && isa<TypedInit>(NewTI))
1585  return VarListElementInit::get(cast<TypedInit>(NewTI), getElementNum());
1586  return const_cast<VarListElementInit *>(this);
1587 }
1588 
1590  if (getType() == BitRecTy::get())
1591  return const_cast<VarListElementInit*>(this);
1592  return VarBitInit::get(const_cast<VarListElementInit*>(this), Bit);
1593 }
1594 
1595 DefInit::DefInit(Record *D)
1596  : TypedInit(IK_DefInit, D->getType()), Def(D) {}
1597 
1599  return R->getDefInit();
1600 }
1601 
1603  if (auto *RRT = dyn_cast<RecordRecTy>(Ty))
1604  if (getType()->typeIsConvertibleTo(RRT))
1605  return const_cast<DefInit *>(this);
1606  return nullptr;
1607 }
1608 
1610  if (const RecordVal *RV = Def->getValue(FieldName))
1611  return RV->getType();
1612  return nullptr;
1613 }
1614 
1615 std::string DefInit::getAsString() const {
1616  return Def->getName();
1617 }
1618 
1620  Record *Class,
1622  ID.AddInteger(Args.size());
1623  ID.AddPointer(Class);
1624 
1625  for (Init *I : Args)
1626  ID.AddPointer(I);
1627 }
1628 
1630  static FoldingSet<VarDefInit> ThePool;
1631 
1633  ProfileVarDefInit(ID, Class, Args);
1634 
1635  void *IP = nullptr;
1636  if (VarDefInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1637  return I;
1638 
1639  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Args.size()),
1640  alignof(VarDefInit));
1641  VarDefInit *I = new(Mem) VarDefInit(Class, Args.size());
1642  std::uninitialized_copy(Args.begin(), Args.end(),
1643  I->getTrailingObjects<Init *>());
1644  ThePool.InsertNode(I, IP);
1645  return I;
1646 }
1647 
1649  ProfileVarDefInit(ID, Class, args());
1650 }
1651 
1652 DefInit *VarDefInit::instantiate() {
1653  if (!Def) {
1654  RecordKeeper &Records = Class->getRecords();
1655  auto NewRecOwner = std::make_unique<Record>(Records.getNewAnonymousName(),
1656  Class->getLoc(), Records,
1657  /*IsAnonymous=*/true);
1658  Record *NewRec = NewRecOwner.get();
1659 
1660  // Copy values from class to instance
1661  for (const RecordVal &Val : Class->getValues())
1662  NewRec->addValue(Val);
1663 
1664  // Substitute and resolve template arguments
1665  ArrayRef<Init *> TArgs = Class->getTemplateArgs();
1666  MapResolver R(NewRec);
1667 
1668  for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1669  if (i < args_size())
1670  R.set(TArgs[i], getArg(i));
1671  else
1672  R.set(TArgs[i], NewRec->getValue(TArgs[i])->getValue());
1673 
1674  NewRec->removeValue(TArgs[i]);
1675  }
1676 
1677  NewRec->resolveReferences(R);
1678 
1679  // Add superclasses.
1680  ArrayRef<std::pair<Record *, SMRange>> SCs = Class->getSuperClasses();
1681  for (const auto &SCPair : SCs)
1682  NewRec->addSuperClass(SCPair.first, SCPair.second);
1683 
1684  NewRec->addSuperClass(Class,
1685  SMRange(Class->getLoc().back(),
1686  Class->getLoc().back()));
1687 
1688  // Resolve internal references and store in record keeper
1689  NewRec->resolveReferences();
1690  Records.addDef(std::move(NewRecOwner));
1691 
1692  Def = DefInit::get(NewRec);
1693  }
1694 
1695  return Def;
1696 }
1697 
1699  TrackUnresolvedResolver UR(&R);
1700  bool Changed = false;
1701  SmallVector<Init *, 8> NewArgs;
1702  NewArgs.reserve(args_size());
1703 
1704  for (Init *Arg : args()) {
1705  Init *NewArg = Arg->resolveReferences(UR);
1706  NewArgs.push_back(NewArg);
1707  Changed |= NewArg != Arg;
1708  }
1709 
1710  if (Changed) {
1711  auto New = VarDefInit::get(Class, NewArgs);
1712  if (!UR.foundUnresolved())
1713  return New->instantiate();
1714  return New;
1715  }
1716  return const_cast<VarDefInit *>(this);
1717 }
1718 
1720  if (Def)
1721  return Def;
1722 
1724  for (Init *Arg : args())
1725  Arg->resolveReferences(R);
1726 
1727  if (!R.foundUnresolved())
1728  return const_cast<VarDefInit *>(this)->instantiate();
1729  return const_cast<VarDefInit *>(this);
1730 }
1731 
1732 std::string VarDefInit::getAsString() const {
1733  std::string Result = Class->getNameInitAsString() + "<";
1734  const char *sep = "";
1735  for (Init *Arg : args()) {
1736  Result += sep;
1737  sep = ", ";
1738  Result += Arg->getAsString();
1739  }
1740  return Result + ">";
1741 }
1742 
1744  using Key = std::pair<Init *, StringInit *>;
1745  static DenseMap<Key, FieldInit*> ThePool;
1746 
1747  Key TheKey(std::make_pair(R, FN));
1748 
1749  FieldInit *&I = ThePool[TheKey];
1750  if (!I) I = new(Allocator) FieldInit(R, FN);
1751  return I;
1752 }
1753 
1754 Init *FieldInit::getBit(unsigned Bit) const {
1755  if (getType() == BitRecTy::get())
1756  return const_cast<FieldInit*>(this);
1757  return VarBitInit::get(const_cast<FieldInit*>(this), Bit);
1758 }
1759 
1761  Init *NewRec = Rec->resolveReferences(R);
1762  if (NewRec != Rec)
1763  return FieldInit::get(NewRec, FieldName)->Fold(R.getCurrentRecord());
1764  return const_cast<FieldInit *>(this);
1765 }
1766 
1767 Init *FieldInit::Fold(Record *CurRec) const {
1768  if (DefInit *DI = dyn_cast<DefInit>(Rec)) {
1769  Record *Def = DI->getDef();
1770  if (Def == CurRec)
1771  PrintFatalError(CurRec->getLoc(),
1772  Twine("Attempting to access field '") +
1773  FieldName->getAsUnquotedString() + "' of '" +
1774  Rec->getAsString() + "' is a forbidden self-reference");
1775  Init *FieldVal = Def->getValue(FieldName)->getValue();
1776  if (FieldVal->isComplete())
1777  return FieldVal;
1778  }
1779  return const_cast<FieldInit *>(this);
1780 }
1781 
1783  ArrayRef<Init *> CondRange,
1784  ArrayRef<Init *> ValRange,
1785  const RecTy *ValType) {
1786  assert(CondRange.size() == ValRange.size() &&
1787  "Number of conditions and values must match!");
1788  ID.AddPointer(ValType);
1789  ArrayRef<Init *>::iterator Case = CondRange.begin();
1790  ArrayRef<Init *>::iterator Val = ValRange.begin();
1791 
1792  while (Case != CondRange.end()) {
1793  ID.AddPointer(*Case++);
1794  ID.AddPointer(*Val++);
1795  }
1796 }
1797 
1799  ProfileCondOpInit(ID,
1800  makeArrayRef(getTrailingObjects<Init *>(), NumConds),
1801  makeArrayRef(getTrailingObjects<Init *>() + NumConds, NumConds),
1802  ValType);
1803 }
1804 
1805 CondOpInit *
1807  ArrayRef<Init *> ValRange, RecTy *Ty) {
1808  assert(CondRange.size() == ValRange.size() &&
1809  "Number of conditions and values must match!");
1810 
1811  static FoldingSet<CondOpInit> ThePool;
1813  ProfileCondOpInit(ID, CondRange, ValRange, Ty);
1814 
1815  void *IP = nullptr;
1816  if (CondOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1817  return I;
1818 
1819  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(2*CondRange.size()),
1820  alignof(BitsInit));
1821  CondOpInit *I = new(Mem) CondOpInit(CondRange.size(), Ty);
1822 
1823  std::uninitialized_copy(CondRange.begin(), CondRange.end(),
1824  I->getTrailingObjects<Init *>());
1825  std::uninitialized_copy(ValRange.begin(), ValRange.end(),
1826  I->getTrailingObjects<Init *>()+CondRange.size());
1827  ThePool.InsertNode(I, IP);
1828  return I;
1829 }
1830 
1832  SmallVector<Init*, 4> NewConds;
1833  bool Changed = false;
1834  for (const Init *Case : getConds()) {
1835  Init *NewCase = Case->resolveReferences(R);
1836  NewConds.push_back(NewCase);
1837  Changed |= NewCase != Case;
1838  }
1839 
1840  SmallVector<Init*, 4> NewVals;
1841  for (const Init *Val : getVals()) {
1842  Init *NewVal = Val->resolveReferences(R);
1843  NewVals.push_back(NewVal);
1844  Changed |= NewVal != Val;
1845  }
1846 
1847  if (Changed)
1848  return (CondOpInit::get(NewConds, NewVals,
1849  getValType()))->Fold(R.getCurrentRecord());
1850 
1851  return const_cast<CondOpInit *>(this);
1852 }
1853 
1854 Init *CondOpInit::Fold(Record *CurRec) const {
1855  for ( unsigned i = 0; i < NumConds; ++i) {
1856  Init *Cond = getCond(i);
1857  Init *Val = getVal(i);
1858 
1859  if (IntInit *CondI = dyn_cast_or_null<IntInit>(
1860  Cond->convertInitializerTo(IntRecTy::get()))) {
1861  if (CondI->getValue())
1862  return Val->convertInitializerTo(getValType());
1863  } else
1864  return const_cast<CondOpInit *>(this);
1865  }
1866 
1867  PrintFatalError(CurRec->getLoc(),
1868  CurRec->getName() +
1869  " does not have any true condition in:" +
1870  this->getAsString());
1871  return nullptr;
1872 }
1873 
1875  for (const Init *Case : getConds())
1876  if (!Case->isConcrete())
1877  return false;
1878 
1879  for (const Init *Val : getVals())
1880  if (!Val->isConcrete())
1881  return false;
1882 
1883  return true;
1884 }
1885 
1887  for (const Init *Case : getConds())
1888  if (!Case->isComplete())
1889  return false;
1890 
1891  for (const Init *Val : getVals())
1892  if (!Val->isConcrete())
1893  return false;
1894 
1895  return true;
1896 }
1897 
1898 std::string CondOpInit::getAsString() const {
1899  std::string Result = "!cond(";
1900  for (unsigned i = 0; i < getNumConds(); i++) {
1901  Result += getCond(i)->getAsString() + ": ";
1902  Result += getVal(i)->getAsString();
1903  if (i != getNumConds()-1)
1904  Result += ", ";
1905  }
1906  return Result + ")";
1907 }
1908 
1909 Init *CondOpInit::getBit(unsigned Bit) const {
1910  return VarBitInit::get(const_cast<CondOpInit *>(this), Bit);
1911 }
1912 
1914  ArrayRef<Init *> ArgRange,
1915  ArrayRef<StringInit *> NameRange) {
1916  ID.AddPointer(V);
1917  ID.AddPointer(VN);
1918 
1919  ArrayRef<Init *>::iterator Arg = ArgRange.begin();
1921  while (Arg != ArgRange.end()) {
1922  assert(Name != NameRange.end() && "Arg name underflow!");
1923  ID.AddPointer(*Arg++);
1924  ID.AddPointer(*Name++);
1925  }
1926  assert(Name == NameRange.end() && "Arg name overflow!");
1927 }
1928 
1929 DagInit *
1931  ArrayRef<StringInit *> NameRange) {
1932  static FoldingSet<DagInit> ThePool;
1933 
1935  ProfileDagInit(ID, V, VN, ArgRange, NameRange);
1936 
1937  void *IP = nullptr;
1938  if (DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1939  return I;
1940 
1941  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *, StringInit *>(ArgRange.size(), NameRange.size()), alignof(BitsInit));
1942  DagInit *I = new(Mem) DagInit(V, VN, ArgRange.size(), NameRange.size());
1943  std::uninitialized_copy(ArgRange.begin(), ArgRange.end(),
1944  I->getTrailingObjects<Init *>());
1945  std::uninitialized_copy(NameRange.begin(), NameRange.end(),
1946  I->getTrailingObjects<StringInit *>());
1947  ThePool.InsertNode(I, IP);
1948  return I;
1949 }
1950 
1951 DagInit *
1953  ArrayRef<std::pair<Init*, StringInit*>> args) {
1956 
1957  for (const auto &Arg : args) {
1958  Args.push_back(Arg.first);
1959  Names.push_back(Arg.second);
1960  }
1961 
1962  return DagInit::get(V, VN, Args, Names);
1963 }
1964 
1966  ProfileDagInit(ID, Val, ValName, makeArrayRef(getTrailingObjects<Init *>(), NumArgs), makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames));
1967 }
1968 
1970  if (DefInit *DefI = dyn_cast<DefInit>(Val))
1971  return DefI->getDef();
1972  PrintFatalError(Loc, "Expected record as operator");
1973  return nullptr;
1974 }
1975 
1977  SmallVector<Init*, 8> NewArgs;
1978  NewArgs.reserve(arg_size());
1979  bool ArgsChanged = false;
1980  for (const Init *Arg : getArgs()) {
1981  Init *NewArg = Arg->resolveReferences(R);
1982  NewArgs.push_back(NewArg);
1983  ArgsChanged |= NewArg != Arg;
1984  }
1985 
1986  Init *Op = Val->resolveReferences(R);
1987  if (Op != Val || ArgsChanged)
1988  return DagInit::get(Op, ValName, NewArgs, getArgNames());
1989 
1990  return const_cast<DagInit *>(this);
1991 }
1992 
1993 bool DagInit::isConcrete() const {
1994  if (!Val->isConcrete())
1995  return false;
1996  for (const Init *Elt : getArgs()) {
1997  if (!Elt->isConcrete())
1998  return false;
1999  }
2000  return true;
2001 }
2002 
2003 std::string DagInit::getAsString() const {
2004  std::string Result = "(" + Val->getAsString();
2005  if (ValName)
2006  Result += ":" + ValName->getAsUnquotedString();
2007  if (!arg_empty()) {
2008  Result += " " + getArg(0)->getAsString();
2009  if (getArgName(0)) Result += ":$" + getArgName(0)->getAsUnquotedString();
2010  for (unsigned i = 1, e = getNumArgs(); i != e; ++i) {
2011  Result += ", " + getArg(i)->getAsString();
2012  if (getArgName(i)) Result += ":$" + getArgName(i)->getAsUnquotedString();
2013  }
2014  }
2015  return Result + ")";
2016 }
2017 
2018 //===----------------------------------------------------------------------===//
2019 // Other implementations
2020 //===----------------------------------------------------------------------===//
2021 
2023  : Name(N), TyAndPrefix(T, P) {
2025  assert(Value && "Cannot create unset value for current type!");
2026 }
2027 
2029  return cast<StringInit>(getNameInit())->getValue();
2030 }
2031 
2033  if (V) {
2034  Value = V->getCastTo(getType());
2035  if (Value) {
2036  assert(!isa<TypedInit>(Value) ||
2037  cast<TypedInit>(Value)->getType()->typeIsA(getType()));
2038  if (BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
2039  if (!isa<BitsInit>(Value)) {
2041  Bits.reserve(BTy->getNumBits());
2042  for (unsigned i = 0, e = BTy->getNumBits(); i < e; ++i)
2043  Bits.push_back(Value->getBit(i));
2044  Value = BitsInit::get(Bits);
2045  }
2046  }
2047  }
2048  return Value == nullptr;
2049  }
2050  Value = nullptr;
2051  return false;
2052 }
2053 
2054 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2055 LLVM_DUMP_METHOD void RecordVal::dump() const { errs() << *this; }
2056 #endif
2057 
2058 void RecordVal::print(raw_ostream &OS, bool PrintSem) const {
2059  if (getPrefix()) OS << "field ";
2060  OS << *getType() << " " << getNameInitAsString();
2061 
2062  if (getValue())
2063  OS << " = " << *getValue();
2064 
2065  if (PrintSem) OS << ";\n";
2066 }
2067 
2068 unsigned Record::LastID = 0;
2069 
2070 void Record::checkName() {
2071  // Ensure the record name has string type.
2072  const TypedInit *TypedName = cast<const TypedInit>(Name);
2073  if (!isa<StringRecTy>(TypedName->getType()))
2074  PrintFatalError(getLoc(), Twine("Record name '") + Name->getAsString() +
2075  "' is not a string!");
2076 }
2077 
2079  SmallVector<Record *, 4> DirectSCs;
2080  getDirectSuperClasses(DirectSCs);
2081  return RecordRecTy::get(DirectSCs);
2082 }
2083 
2085  if (!TheInit)
2086  TheInit = new(Allocator) DefInit(this);
2087  return TheInit;
2088 }
2089 
2090 void Record::setName(Init *NewName) {
2091  Name = NewName;
2092  checkName();
2093  // DO NOT resolve record values to the name at this point because
2094  // there might be default values for arguments of this def. Those
2095  // arguments might not have been resolved yet so we don't want to
2096  // prematurely assume values for those arguments were not passed to
2097  // this def.
2098  //
2099  // Nonetheless, it may be that some of this Record's values
2100  // reference the record name. Indeed, the reason for having the
2101  // record name be an Init is to provide this flexibility. The extra
2102  // resolve steps after completely instantiating defs takes care of
2103  // this. See TGParser::ParseDef and TGParser::ParseDefm.
2104 }
2105 
2107  ArrayRef<std::pair<Record *, SMRange>> SCs = getSuperClasses();
2108  while (!SCs.empty()) {
2109  // Superclasses are in reverse preorder, so 'back' is a direct superclass,
2110  // and its transitive superclasses are directly preceding it.
2111  Record *SC = SCs.back().first;
2112  SCs = SCs.drop_back(1 + SC->getSuperClasses().size());
2113  Classes.push_back(SC);
2114  }
2115 }
2116 
2118  for (RecordVal &Value : Values) {
2119  if (SkipVal == &Value) // Skip resolve the same field as the given one
2120  continue;
2121  if (Init *V = Value.getValue()) {
2122  Init *VR = V->resolveReferences(R);
2123  if (Value.setValue(VR)) {
2124  std::string Type;
2125  if (TypedInit *VRT = dyn_cast<TypedInit>(VR))
2126  Type =
2127  (Twine("of type '") + VRT->getType()->getAsString() + "' ").str();
2128  PrintFatalError(getLoc(), Twine("Invalid value ") + Type +
2129  "is found when setting '" +
2130  Value.getNameInitAsString() +
2131  "' of type '" +
2132  Value.getType()->getAsString() +
2133  "' after resolving references: " +
2134  VR->getAsUnquotedString() + "\n");
2135  }
2136  }
2137  }
2138  Init *OldName = getNameInit();
2139  Init *NewName = Name->resolveReferences(R);
2140  if (NewName != OldName) {
2141  // Re-register with RecordKeeper.
2142  setName(NewName);
2143  }
2144 }
2145 
2147  RecordResolver R(*this);
2148  R.setFinal(true);
2149  resolveReferences(R);
2150 }
2151 
2153  RecordValResolver R(*this, RV);
2154  resolveReferences(R, RV);
2155 }
2156 
2157 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2158 LLVM_DUMP_METHOD void Record::dump() const { errs() << *this; }
2159 #endif
2160 
2162  OS << R.getNameInitAsString();
2163 
2164  ArrayRef<Init *> TArgs = R.getTemplateArgs();
2165  if (!TArgs.empty()) {
2166  OS << "<";
2167  bool NeedComma = false;
2168  for (const Init *TA : TArgs) {
2169  if (NeedComma) OS << ", ";
2170  NeedComma = true;
2171  const RecordVal *RV = R.getValue(TA);
2172  assert(RV && "Template argument record not found??");
2173  RV->print(OS, false);
2174  }
2175  OS << ">";
2176  }
2177 
2178  OS << " {";
2180  if (!SC.empty()) {
2181  OS << "\t//";
2182  for (const auto &SuperPair : SC)
2183  OS << " " << SuperPair.first->getNameInitAsString();
2184  }
2185  OS << "\n";
2186 
2187  for (const RecordVal &Val : R.getValues())
2188  if (Val.getPrefix() && !R.isTemplateArg(Val.getNameInit()))
2189  OS << Val;
2190  for (const RecordVal &Val : R.getValues())
2191  if (!Val.getPrefix() && !R.isTemplateArg(Val.getNameInit()))
2192  OS << Val;
2193 
2194  return OS << "}\n";
2195 }
2196 
2198  const RecordVal *R = getValue(FieldName);
2199  if (!R || !R->getValue())
2200  PrintFatalError(getLoc(), "Record `" + getName() +
2201  "' does not have a field named `" + FieldName + "'!\n");
2202  return R->getValue();
2203 }
2204 
2206  const RecordVal *R = getValue(FieldName);
2207  if (!R || !R->getValue())
2208  PrintFatalError(getLoc(), "Record `" + getName() +
2209  "' does not have a field named `" + FieldName + "'!\n");
2210 
2211  if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
2212  return SI->getValue();
2213  if (CodeInit *CI = dyn_cast<CodeInit>(R->getValue()))
2214  return CI->getValue();
2215 
2216  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2217  FieldName + "' does not have a string initializer!");
2218 }
2219 
2221  const RecordVal *R = getValue(FieldName);
2222  if (!R || !R->getValue())
2223  PrintFatalError(getLoc(), "Record `" + getName() +
2224  "' does not have a field named `" + FieldName + "'!\n");
2225 
2226  if (BitsInit *BI = dyn_cast<BitsInit>(R->getValue()))
2227  return BI;
2228  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2229  FieldName + "' does not have a BitsInit initializer!");
2230 }
2231 
2233  const RecordVal *R = getValue(FieldName);
2234  if (!R || !R->getValue())
2235  PrintFatalError(getLoc(), "Record `" + getName() +
2236  "' does not have a field named `" + FieldName + "'!\n");
2237 
2238  if (ListInit *LI = dyn_cast<ListInit>(R->getValue()))
2239  return LI;
2240  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2241  FieldName + "' does not have a list initializer!");
2242 }
2243 
2244 std::vector<Record*>
2246  ListInit *List = getValueAsListInit(FieldName);
2247  std::vector<Record*> Defs;
2248  for (Init *I : List->getValues()) {
2249  if (DefInit *DI = dyn_cast<DefInit>(I))
2250  Defs.push_back(DI->getDef());
2251  else
2252  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2253  FieldName + "' list is not entirely DefInit!");
2254  }
2255  return Defs;
2256 }
2257 
2258 int64_t Record::getValueAsInt(StringRef FieldName) const {
2259  const RecordVal *R = getValue(FieldName);
2260  if (!R || !R->getValue())
2261  PrintFatalError(getLoc(), "Record `" + getName() +
2262  "' does not have a field named `" + FieldName + "'!\n");
2263 
2264  if (IntInit *II = dyn_cast<IntInit>(R->getValue()))
2265  return II->getValue();
2266  PrintFatalError(getLoc(), Twine("Record `") + getName() + "', field `" +
2267  FieldName +
2268  "' does not have an int initializer: " +
2269  R->getValue()->getAsString());
2270 }
2271 
2272 std::vector<int64_t>
2274  ListInit *List = getValueAsListInit(FieldName);
2275  std::vector<int64_t> Ints;
2276  for (Init *I : List->getValues()) {
2277  if (IntInit *II = dyn_cast<IntInit>(I))
2278  Ints.push_back(II->getValue());
2279  else
2280  PrintFatalError(getLoc(),
2281  Twine("Record `") + getName() + "', field `" + FieldName +
2282  "' does not have a list of ints initializer: " +
2283  I->getAsString());
2284  }
2285  return Ints;
2286 }
2287 
2288 std::vector<StringRef>
2290  ListInit *List = getValueAsListInit(FieldName);
2291  std::vector<StringRef> Strings;
2292  for (Init *I : List->getValues()) {
2293  if (StringInit *SI = dyn_cast<StringInit>(I))
2294  Strings.push_back(SI->getValue());
2295  else
2296  PrintFatalError(getLoc(),
2297  Twine("Record `") + getName() + "', field `" + FieldName +
2298  "' does not have a list of strings initializer: " +
2299  I->getAsString());
2300  }
2301  return Strings;
2302 }
2303 
2305  const RecordVal *R = getValue(FieldName);
2306  if (!R || !R->getValue())
2307  PrintFatalError(getLoc(), "Record `" + getName() +
2308  "' does not have a field named `" + FieldName + "'!\n");
2309 
2310  if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
2311  return DI->getDef();
2312  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2313  FieldName + "' does not have a def initializer!");
2314 }
2315 
2317  const RecordVal *R = getValue(FieldName);
2318  if (!R || !R->getValue())
2319  PrintFatalError(getLoc(), "Record `" + getName() +
2320  "' does not have a field named `" + FieldName + "'!\n");
2321 
2322  if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
2323  return DI->getDef();
2324  if (isa<UnsetInit>(R->getValue()))
2325  return nullptr;
2326  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2327  FieldName + "' does not have either a def initializer or '?'!");
2328 }
2329 
2330 
2331 bool Record::getValueAsBit(StringRef FieldName) const {
2332  const RecordVal *R = getValue(FieldName);
2333  if (!R || !R->getValue())
2334  PrintFatalError(getLoc(), "Record `" + getName() +
2335  "' does not have a field named `" + FieldName + "'!\n");
2336 
2337  if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
2338  return BI->getValue();
2339  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2340  FieldName + "' does not have a bit initializer!");
2341 }
2342 
2343 bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
2344  const RecordVal *R = getValue(FieldName);
2345  if (!R || !R->getValue())
2346  PrintFatalError(getLoc(), "Record `" + getName() +
2347  "' does not have a field named `" + FieldName.str() + "'!\n");
2348 
2349  if (isa<UnsetInit>(R->getValue())) {
2350  Unset = true;
2351  return false;
2352  }
2353  Unset = false;
2354  if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
2355  return BI->getValue();
2356  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2357  FieldName + "' does not have a bit initializer!");
2358 }
2359 
2361  const RecordVal *R = getValue(FieldName);
2362  if (!R || !R->getValue())
2363  PrintFatalError(getLoc(), "Record `" + getName() +
2364  "' does not have a field named `" + FieldName + "'!\n");
2365 
2366  if (DagInit *DI = dyn_cast<DagInit>(R->getValue()))
2367  return DI;
2368  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2369  FieldName + "' does not have a dag initializer!");
2370 }
2371 
2372 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2373 LLVM_DUMP_METHOD void RecordKeeper::dump() const { errs() << *this; }
2374 #endif
2375 
2377  OS << "------------- Classes -----------------\n";
2378  for (const auto &C : RK.getClasses())
2379  OS << "class " << *C.second;
2380 
2381  OS << "------------- Defs -----------------\n";
2382  for (const auto &D : RK.getDefs())
2383  OS << "def " << *D.second;
2384  return OS;
2385 }
2386 
2387 /// GetNewAnonymousName - Generate a unique anonymous name that can be used as
2388 /// an identifier.
2390  return StringInit::get("anonymous_" + utostr(AnonCounter++));
2391 }
2392 
2393 std::vector<Record *>
2395  Record *Class = getClass(ClassName);
2396  if (!Class)
2397  PrintFatalError("ERROR: Couldn't find the `" + ClassName + "' class!\n");
2398 
2399  std::vector<Record*> Defs;
2400  for (const auto &D : getDefs())
2401  if (D.second->isSubClassOf(Class))
2402  Defs.push_back(D.second.get());
2403 
2404  return Defs;
2405 }
2406 
2408  auto It = Map.find(VarName);
2409  if (It == Map.end())
2410  return nullptr;
2411 
2412  Init *I = It->second.V;
2413 
2414  if (!It->second.Resolved && Map.size() > 1) {
2415  // Resolve mutual references among the mapped variables, but prevent
2416  // infinite recursion.
2417  Map.erase(It);
2418  I = I->resolveReferences(*this);
2419  Map[VarName] = {I, true};
2420  }
2421 
2422  return I;
2423 }
2424 
2426  Init *Val = Cache.lookup(VarName);
2427  if (Val)
2428  return Val;
2429 
2430  for (Init *S : Stack) {
2431  if (S == VarName)
2432  return nullptr; // prevent infinite recursion
2433  }
2434 
2435  if (RecordVal *RV = getCurrentRecord()->getValue(VarName)) {
2436  if (!isa<UnsetInit>(RV->getValue())) {
2437  Val = RV->getValue();
2438  Stack.push_back(VarName);
2439  Val = Val->resolveReferences(*this);
2440  Stack.pop_back();
2441  }
2442  }
2443 
2444  Cache[VarName] = Val;
2445  return Val;
2446 }
2447 
2449  Init *I = nullptr;
2450 
2451  if (R) {
2452  I = R->resolve(VarName);
2453  if (I && !FoundUnresolved) {
2454  // Do not recurse into the resolved initializer, as that would change
2455  // the behavior of the resolver we're delegating, but do check to see
2456  // if there are unresolved variables remaining.
2458  I->resolveReferences(Sub);
2459  FoundUnresolved |= Sub.FoundUnresolved;
2460  }
2461  }
2462 
2463  if (!I)
2464  FoundUnresolved = true;
2465  return I;
2466 }
2467 
2469 {
2470  if (VarName == VarNameToTrack)
2471  Found = true;
2472  return nullptr;
2473 }
Init * Fold() const
Definition: Record.cpp:1393
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:841
uint64_t CallInst * C
Represents a range in source code.
Definition: SMLoc.h:48
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
Definition: FoldingSet.cpp:51
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:365
StringRef getName() const
Definition: Record.cpp:2028
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:641
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:810
RecTyKind
Subclass discriminator (for dyn_cast<> et al.)
Definition: Record.h:57
void print(raw_ostream &OS) const
Definition: Record.h:79
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:1420
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StringRef getName() const
Definition: Record.cpp:1519
Record * getValueAsOptionalDef(StringRef FieldName) const
This method looks up the specified field and returns its value as a Record, returning null if the fie...
Definition: Record.cpp:2316
Record * getValueAsDef(StringRef FieldName) const
This method looks up the specified field and returns its value as a Record, throwing an exception if ...
Definition: Record.cpp:2304
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:239
BitsInit * getValueAsBitsInit(StringRef FieldName) const
This method looks up the specified field and returns its value as a BitsInit, throwing an exception i...
Definition: Record.cpp:2220
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:167
Init * getValue() const
Definition: Record.h:1414
This class represents lattice values for constants.
Definition: AllocatorList.h:23
X.Y - Represent a reference to a subfield of a variable.
Definition: Record.h:1260
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:492
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This method is used to implement the bitrange selection operator.
Definition: Record.cpp:505
virtual std::string getAsUnquotedString() const
Convert this value to a string form, without adding quote markers.
Definition: Record.h:367
Record * getCurrentRecord() const
Definition: Record.h:1878
bool foundUnresolved() const
Definition: Record.h:1979
[AL, AH, CL] - Represent a list of defs
Definition: Record.h:661
iterator begin() const
Definition: ArrayRef.h:146
&#39;7&#39; - Represent an initialization by a literal integer value.
Definition: Record.h:564
static void ProfileFoldOpInit(FoldingSetNodeID &ID, Init *A, Init *B, Init *Start, Init *List, Init *Expr, RecTy *Type)
Definition: Record.cpp:1297
&#39;list<Ty>&#39; - Represent a list of values, all of which must be of the specified type.
Definition: Record.h:195
void getDirectSuperClasses(SmallVectorImpl< Record *> &Classes) const
Append the direct super classes of this record to Classes.
Definition: Record.cpp:2106
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
!op (X, Y) - Combine two inits.
Definition: Record.h:801
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:1589
bool typeIsA(const RecTy *RHS) const override
Return true if &#39;this&#39; type is equal to or a subtype of RHS.
Definition: Record.cpp:105
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:592
DagInit * getValueAsDag(StringRef FieldName) const
This method looks up the specified field and returns its value as an Dag, throwing an exception if th...
Definition: Record.cpp:2360
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1732
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:318
AL - Represent a reference to a &#39;def&#39; in the description.
Definition: Record.h:1174
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1530
static Init * getListConcat(TypedInit *lhs, Init *rhs)
Definition: Record.cpp:884
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
Definition: Record.cpp:2425
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:1357
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
Definition: FoldingSet.h:444
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
Definition: Record.cpp:693
void addDef(std::unique_ptr< Record > R)
Definition: Record.h:1731
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This method is used to implement the bitrange selection operator.
Definition: Record.cpp:1452
RecTy * getFieldType(StringInit *FieldName) const override
This method is used to implement the FieldInit class.
Definition: Record.cpp:1609
Init * getCastTo(RecTy *Ty) const override
If this initializer is convertible to Ty, return an initializer whose type is-a Ty, generating a !cast operation if required.
Definition: Record.cpp:1468
Init * Fold(Record *CurRec, bool IsFinal=false) const
Definition: Record.cpp:712
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1548
static Init * getStrConcat(Init *lhs, Init *rhs)
Definition: Record.cpp:868
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1182
static VarInit * get(StringRef VN, RecTy *T)
Definition: Record.cpp:1502
static uint32_t Concat[]
STATISTIC(NumFunctions, "Total number of functions")
ListInit * getValueAsListInit(StringRef FieldName) const
This method looks up the specified field and returns its value as a ListInit, throwing an exception i...
Definition: Record.cpp:2232
int64_t getValueAsInt(StringRef FieldName) const
This method looks up the specified field and returns its value as an int64_t, throwing an exception i...
Definition: Record.cpp:2258
Resolve all references to a specific RecordVal.
Definition: Record.h:1935
const_record_iterator classes_begin() const
Definition: Record.h:268
static ListInit * ConcatListInits(const ListInit *LHS, const ListInit *RHS)
Definition: Record.cpp:876
static BumpPtrAllocator Allocator
Definition: Record.cpp:44
void reserve(size_type N)
Definition: SmallVector.h:369
virtual Init * getCastTo(RecTy *Ty) const =0
If this initializer is convertible to Ty, return an initializer whose type is-a Ty, generating a !cast operation if required.
Resolve all variables from a record except for unset variables.
Definition: Record.h:1918
bool typeIsA(const RecTy *RHS) const override
Return true if &#39;this&#39; type is equal to or a subtype of RHS.
Definition: Record.cpp:238
&#39;{ a, b, c }&#39; - Represents an initializer for a BitsRecTy value.
Definition: Record.h:513
Record * getElementAsRecord(unsigned i) const
Definition: Record.cpp:637
std::string getAsString() const override
Definition: Record.cpp:130
std::string getNameInitAsString() const
Definition: Record.h:1408
Init * Fold() const
Definition: Record.cpp:1719
void dump() const
Debugging method that may be called through a debugger, just invokes print on stderr.
Definition: Record.cpp:295
static BitRecTy * get()
Definition: Record.h:110
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)
static IntInit * get(int64_t V)
Definition: Record.cpp:460
static BitsInit * get(ArrayRef< Init *> Range)
Definition: Record.cpp:342
(Optionally) delegate resolving to a sub-resolver, and keep track whether there were unresolved refer...
Definition: Record.h:1971
bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const
This method looks up the specified field and returns its value as a bit.
Definition: Record.cpp:2343
Init * getArg(unsigned Num) const
Definition: Record.h:1343
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const
Definition: Record.h:1509
&#39;?&#39; - Represents an uninitialized value
Definition: Record.h:457
&#39;true&#39;/&#39;false&#39; - Represent a concrete initializer for a bit.
Definition: Record.h:483
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This method is used to implement the bitrange selection operator.
Definition: Record.cpp:392
void dump() const
Definition: Record.cpp:2055
static Init * ForeachApply(Init *LHS, Init *MHSe, Init *RHS, Record *CurRec)
Definition: Record.cpp:1110
static BitsRecTy * get(unsigned Sz)
Definition: Record.cpp:84
Record * getDef() const
Definition: Record.h:1193
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
This is the common super-class of types that have a specific, explicit, type.
Definition: Record.h:425
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:460
static RecordRecTy * resolveRecordTypes(RecordRecTy *T1, RecordRecTy *T2)
Definition: Record.cpp:242
Shift and rotation operations.
Definition: ISDOpcodes.h:471
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:98
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:361
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:680
RecTy * getElementType() const
Definition: Record.h:208
static StringRecTy * get()
Definition: Record.h:186
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:857
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:196
ArrayRef< Init * > getTemplateArgs() const
Definition: Record.h:1503
std::string getAsString() const override
Definition: Record.cpp:202
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
std::string getAsString() const override
Definition: Record.cpp:121
List[4] - Represent access to one element of a var or field.
Definition: Record.h:1142
&#39;[classname]&#39; - Type of record values that have zero or more superclasses.
Definition: Record.h:237
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:542
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:468
std::vector< Record * > getValueAsListOfDefs(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of records, throwing an exception if the field does not exist or if the value is not the right type.
Definition: Record.cpp:2245
void AddInteger(signed I)
Definition: FoldingSet.cpp:60
!foldl (a, b, expr, start, lst) - Fold over a list.
Definition: Record.h:998
Init * getValueInit(StringRef FieldName) const
Return the initializer for a value with the specified name, or throw an exception if the field does n...
Definition: Record.cpp:2197
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
!cond(condition_1: value1, ...
Definition: Record.h:923
void print(raw_ostream &OS, bool PrintSem=true) const
Definition: Record.cpp:2058
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:819
const_iterator end() const
Definition: Record.h:715
virtual Init * resolve(Init *VarName)=0
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
StringInit * getArgName(unsigned Num) const
Definition: Record.h:1348
void InsertNode(T *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
Definition: FoldingSet.h:451
Key
PAL metadata keys.
ArrayRef< SMLoc > getLoc() const
Definition: Record.h:1492
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
&#39;bits<n>&#39; - Represent a fixed number of bits
Definition: Record.h:118
ArrayRef< Record * > getClasses() const
Definition: Record.h:262
std::string itostr(int64_t X)
Definition: StringExtras.h:238
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:198
bool isTemplateArg(Init *Name) const
Definition: Record.h:1516
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1253
RecTy * getType() const
Definition: Record.h:1413
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:202
bool isSubClassOf(const Record *R) const
Definition: Record.h:1563
ArrayRef< Init * > getValues() const
Definition: Record.h:710
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:669
bool isFinal() const
Definition: Record.h:1892
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
Record * getOperatorAsDef(ArrayRef< SMLoc > Loc) const
Definition: Record.cpp:1969
unsigned getNumBits() const
Definition: Record.h:130
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1576
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:125
#define EQ(a, b)
Definition: regexec.c:112
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
Definition: Record.cpp:2407
virtual Init * getBit(unsigned Bit) const =0
This method is used to return the initializer for the specified bit.
static CodeInit * get(StringRef, const SMLoc &Loc)
Definition: Record.cpp:517
ArrayRef< RecordVal > getValues() const
Definition: Record.h:1507
const_record_iterator classes_end() const
Definition: Record.h:269
Init * convertInitListSlice(ArrayRef< unsigned > Elements) const override
This method is used to implement the list slice selection operator.
Definition: Record.cpp:626
&#39;code&#39; - Represent a code fragment
Definition: Record.h:140
void resolveReferencesTo(const RecordVal *RV)
If anything in this record refers to RV, replace the reference to RV with the RHS of RV...
Definition: Record.cpp:2152
bool isSubClassOf(Record *Class) const
Definition: Record.cpp:218
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:551
virtual Init * convertInitializerTo(RecTy *Ty) const =0
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
void addShadow(Init *Key)
Definition: Record.h:1960
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:598
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:111
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:305
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1798
Base class for operators.
Definition: Record.h:727
#define P(N)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1552
RecTy * getType() const
Definition: Record.h:441
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:225
Init * getElement(unsigned i) const
Definition: Record.h:686
Resolve arbitrary mappings.
Definition: Record.h:1898
void dump() const
Definition: Record.cpp:2158
Init * getNameInit() const
Definition: Record.h:1406
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
virtual bool isConcrete() const
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:356
void resolveReferences()
If there are any field references that refer to fields that have been filled in, we can propagate the...
Definition: Record.cpp:2146
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:158
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void set(Init *Key, Init *Value)
Definition: Record.h:1912
"foo" - Represent an initialization by a string value.
Definition: Record.h:594
RecTy * getFieldType(StringInit *FieldName) const override
This method is used to implement the FieldInit class.
Definition: Record.cpp:1430
static void ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS, Init *RHS, RecTy *Type)
Definition: Record.cpp:1081
void dump() const
Definition: Record.cpp:2373
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:1870
static void ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op, RecTy *Type)
Definition: Record.cpp:687
const T * getTrailingObjects() const
Returns a pointer to the trailing object array of the given type (which must be one of those specifie...
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:116
!op (X) - Transform an init.
Definition: Record.h:752
Init * getCastTo(RecTy *Ty) const override
If this initializer is convertible to Ty, return an initializer whose type is-a Ty, generating a !cast operation if required.
Definition: Record.cpp:303
const std::string getNameInitAsString() const
Definition: Record.h:1486
static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringInit *VN, ArrayRef< Init *> ArgRange, ArrayRef< StringInit *> NameRange)
Definition: Record.cpp:1913
bool getPrefix() const
Definition: Record.h:1412
static DagInit * get(Init *V, StringInit *VN, ArrayRef< Init *> ArgRange, ArrayRef< StringInit *> NameRange)
Definition: Record.cpp:1930
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1760
void dump() const
Definition: Record.cpp:60
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1189
constexpr double e
Definition: MathExtras.h:57
StringRef getValueAsString(StringRef FieldName) const
This method looks up the specified field and returns its value as a string, throwing an exception if ...
Definition: Record.cpp:2205
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
int64_t getValue() const
Definition: Record.h:580
&#39;string&#39; - Represent an string value
Definition: Record.h:176
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.cpp:1874
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1698
static BitInit * get(bool V)
Definition: Record.cpp:311
static bool canFitInBitfield(int64_t Value, unsigned NumBits)
Definition: Record.cpp:472
bool setValue(Init *V)
Definition: Record.cpp:2032
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1615
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:425
static void ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS, RecTy *Type)
Definition: Record.cpp:833
DefInit * getDefInit()
get the corresponding DefInit.
Definition: Record.cpp:2084
static wasm::ValType getType(const TargetRegisterClass *RC)
static Init * ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, Record *CurRec)
Definition: Record.cpp:1145
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:473
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:2003
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
std::vector< int64_t > getValueAsListOfInts(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of integers, throwing an exception if the field does not exist or if the value is not the right type.
Definition: Record.cpp:2273
static RecordRecTy * get(ArrayRef< Record *> Classes)
Get the record type with the given non-redundant list of superclasses.
Definition: Record.cpp:157
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1114
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:1441
std::vector< Record * > getAllDerivedDefinitions(StringRef ClassName) const
This method returns all concrete definitions that derive from the specified class name...
Definition: Record.cpp:2394
Delegate resolving to a sub-resolver, but shadow some variable names.
Definition: Record.h:1950
void setFinal(bool Final)
Definition: Record.h:1894
std::vector< StringRef > getValueAsListOfStrings(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of strings, throwing an exception if the field does not exist or if the value is not the right type.
Definition: Record.cpp:2289
static FieldInit * get(Init *R, StringInit *FN)
Definition: Record.cpp:1743
virtual Init * resolveReferences(Resolver &R) const
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.h:410
Init * Fold(Record *CurRec) const
Definition: Record.cpp:898
std::string getAsString() const override
Definition: Record.cpp:94
Init * convertInitListSlice(ArrayRef< unsigned > Elements) const override
This method is used to implement the list slice selection operator.
Definition: Record.cpp:1486
static StringInit * ConcatStringInits(const StringInit *I0, const StringInit *I1)
Definition: Record.cpp:861
bool typeIsA(const RecTy *RHS) const override
Return true if &#39;this&#39; type is equal to or a subtype of RHS.
Definition: Record.cpp:140
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1163
virtual bool typeIsA(const RecTy *RHS) const
Return true if &#39;this&#39; type is equal to or a subtype of RHS.
Definition: Record.cpp:74
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
Definition: Record.cpp:2448
const RecordVal * getValue(const Init *Name) const
Definition: Record.h:1522
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1831
const RecordMap & getClasses() const
Definition: Record.h:1704
Init * getOperator() const
Definition: Record.h:1332
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
static VarBitInit * get(TypedInit *T, unsigned B)
Definition: Record.cpp:1536
static StringInit * get(StringRef)
Definition: Record.cpp:533
RecordKeeper & getRecords() const
Definition: Record.h:1607
iterator end() const
Definition: ArrayRef.h:147
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:411
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1342
CHAIN = SC CHAIN, Imm128 - System call.
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1328
unsigned getNumArgs() const
Definition: Record.h:1341
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:1602
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1898
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
RecTy * getElementType() const
Definition: Record.h:690
static DefInit * get(Record *)
Definition: Record.cpp:1598
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:203
classname<targs...> - Represent an uninstantiated anonymous class instantiation.
Definition: Record.h:1209
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:478
static VarDefInit * get(Record *Class, ArrayRef< Init *> Args)
Definition: Record.cpp:1629
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:1909
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:393
static IsAOpInit * get(RecTy *CheckType, Init *Expr)
Definition: Record.cpp:1374
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:242
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1045
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
Definition: Record.cpp:2468
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:645
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg)
Definition: Error.cpp:68
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1648
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:708
!isa<type>(expr) - Dynamically determine the type of an expression.
Definition: Record.h:1035
RecordRecTy * getType()
Definition: Record.cpp:2078
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:467
static FoldOpInit * get(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
Definition: Record.cpp:1308
static void ProfileIsAOpInit(FoldingSetNodeID &ID, RecTy *CheckType, Init *Expr)
Definition: Record.cpp:1368
&#39;int&#39; - Represent an integer value of no particular size
Definition: Record.h:158
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:1524
bool getValueAsBit(StringRef FieldName) const
This method looks up the specified field and returns its value as a bit, throwing an exception if the...
Definition: Record.cpp:2331
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1055
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1965
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:134
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:448
Init * getNameInit() const
Definition: Record.h:1482
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.cpp:403
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.cpp:661
static Init * ForeachDagApply(Init *LHS, DagInit *MHSd, Init *RHS, Record *CurRec)
Definition: Record.cpp:1116
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
static UnsetInit * get()
Definition: Record.cpp:298
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1164
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:76
void addValue(const RecordVal &RV)
Definition: Record.h:1545
const NodeList & List
Definition: RDFGraph.cpp:201
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:1090
const_iterator begin() const
Definition: Record.h:714
static VarListElementInit * get(TypedInit *T, unsigned E)
Definition: Record.cpp:1560
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
RecTy * resolveTypes(RecTy *T1, RecTy *T2)
Find a common type that T1 and T2 convert to.
Definition: Record.cpp:262
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1413
static void ProfileVarDefInit(FoldingSetNodeID &ID, Record *Class, ArrayRef< Init *> Args)
Definition: Record.cpp:1619
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1324
Opcode{0} - Represent access to one bit of a variable or field.
Definition: Record.h:1105
&#39;Opcode&#39; - Represent a reference to an entire variable object.
Definition: Record.h:1068
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1389
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1283
static void ProfileCondOpInit(FoldingSetNodeID &ID, ArrayRef< Init *> CondRange, ArrayRef< Init *> ValRange, const RecTy *ValType)
Definition: Record.cpp:1782
Init * resolveReferences(Resolver &R) const override
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.cpp:1976
std::string getAsString() const override
Definition: Record.cpp:146
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
uint32_t Size
Definition: Profile.cpp:46
&#39;bit&#39; - Represent a single bit
Definition: Record.h:100
!op (X, Y, Z) - Combine two inits.
Definition: Record.h:859
static void ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef< Init *> Range)
Definition: Record.cpp:335
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2096
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1854
static ListInit * get(ArrayRef< Init *> Range, RecTy *EltTy)
Definition: Record.cpp:570
virtual bool keepUnsetBits() const
Definition: Record.h:1887
RecTyKind getRecTyKind() const
Definition: Record.h:76
virtual bool typeIsConvertibleTo(const RecTy *RHS) const
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:69
StringRef getValue() const
Definition: Record.h:610
&#39;dag&#39; - Represent a dag fragment
Definition: Record.h:218
Record * getDef(StringRef Name) const
Definition: Record.h:1712
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
StringRef getName() const
Definition: Record.h:1480
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.cpp:1754
LLVM Value Representation.
Definition: Value.h:74
(v a, b) - Represent a DAG tree value.
Definition: Record.h:1302
virtual std::string getAsString() const =0
Convert this value to a string form.
size_t size() const
Definition: Record.h:717
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.cpp:1993
static void ProfileListInit(FoldingSetNodeID &ID, ArrayRef< Init *> Range, RecTy *EltTy)
Definition: Record.cpp:560
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:27
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
static CondOpInit * get(ArrayRef< Init *> C, ArrayRef< Init *> V, RecTy *Type)
Definition: Record.cpp:1806
void setName(Init *Name)
Definition: Record.cpp:2090
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1106
static void ProfileRecordRecTy(FoldingSetNodeID &ID, ArrayRef< Record *> Classes)
Definition: Record.cpp:150
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1424
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.cpp:1886
virtual std::string getAsString() const =0
Init * convertInitializerTo(RecTy *Ty) const override
Convert to an initializer whose type is-a Ty, or return nullptr if this is not possible (this can hap...
Definition: Record.cpp:307
Represents a location in source code.
Definition: SMLoc.h:23
ListRecTy * getListTy()
Returns the type representing list<this>.
Definition: Record.cpp:63
Init * getNewAnonymousName()
GetNewAnonymousName - Generate a unique anonymous name that can be used as an identifier.
Definition: Record.cpp:2389
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
const RecordMap & getDefs() const
Definition: Record.h:1705
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1361
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1767
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
#define T1
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.cpp:1572
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:153
static IntRecTy * get()
Definition: Record.h:168
RecordVal(Init *N, RecTy *T, bool P)
Definition: Record.cpp:2022
static Init * getListSplat(TypedInit *lhs, Init *rhs)
Definition: Record.cpp:894