LLVM  13.0.0git
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 //===----------------------------------------------------------------------===//
47 // Type implementations
48 //===----------------------------------------------------------------------===//
49 
50 BitRecTy BitRecTy::Shared;
51 IntRecTy IntRecTy::Shared;
52 StringRecTy StringRecTy::Shared;
53 DagRecTy DagRecTy::Shared;
54 
55 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
56 LLVM_DUMP_METHOD void RecTy::dump() const { print(errs()); }
57 #endif
58 
60  if (!ListTy)
61  ListTy = new(Allocator) ListRecTy(this);
62  return ListTy;
63 }
64 
65 bool RecTy::typeIsConvertibleTo(const RecTy *RHS) const {
66  assert(RHS && "NULL pointer");
67  return Kind == RHS->getRecTyKind();
68 }
69 
70 bool RecTy::typeIsA(const RecTy *RHS) const { return this == RHS; }
71 
72 bool BitRecTy::typeIsConvertibleTo(const RecTy *RHS) const{
74  return true;
75  if (const BitsRecTy *BitsTy = dyn_cast<BitsRecTy>(RHS))
76  return BitsTy->getNumBits() == 1;
77  return false;
78 }
79 
80 BitsRecTy *BitsRecTy::get(unsigned Sz) {
81  static std::vector<BitsRecTy*> Shared;
82  if (Sz >= Shared.size())
83  Shared.resize(Sz + 1);
84  BitsRecTy *&Ty = Shared[Sz];
85  if (!Ty)
86  Ty = new(Allocator) BitsRecTy(Sz);
87  return Ty;
88 }
89 
90 std::string BitsRecTy::getAsString() const {
91  return "bits<" + utostr(Size) + ">";
92 }
93 
94 bool BitsRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
95  if (RecTy::typeIsConvertibleTo(RHS)) //argument and the sender are same type
96  return cast<BitsRecTy>(RHS)->Size == Size;
97  RecTyKind kind = RHS->getRecTyKind();
98  return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
99 }
100 
101 bool BitsRecTy::typeIsA(const RecTy *RHS) const {
102  if (const BitsRecTy *RHSb = dyn_cast<BitsRecTy>(RHS))
103  return RHSb->Size == Size;
104  return false;
105 }
106 
107 bool IntRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
108  RecTyKind kind = RHS->getRecTyKind();
109  return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
110 }
111 
112 std::string StringRecTy::getAsString() const {
113  return "string";
114 }
115 
116 bool StringRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
117  RecTyKind Kind = RHS->getRecTyKind();
118  return Kind == StringRecTyKind;
119 }
120 
121 std::string ListRecTy::getAsString() const {
122  return "list<" + ElementTy->getAsString() + ">";
123 }
124 
125 bool ListRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
126  if (const auto *ListTy = dyn_cast<ListRecTy>(RHS))
127  return ElementTy->typeIsConvertibleTo(ListTy->getElementType());
128  return false;
129 }
130 
131 bool ListRecTy::typeIsA(const RecTy *RHS) const {
132  if (const ListRecTy *RHSl = dyn_cast<ListRecTy>(RHS))
133  return getElementType()->typeIsA(RHSl->getElementType());
134  return false;
135 }
136 
137 std::string DagRecTy::getAsString() const {
138  return "dag";
139 }
140 
142  ArrayRef<Record *> Classes) {
143  ID.AddInteger(Classes.size());
144  for (Record *R : Classes)
145  ID.AddPointer(R);
146 }
147 
149  if (UnsortedClasses.empty()) {
150  static RecordRecTy AnyRecord(0);
151  return &AnyRecord;
152  }
153 
154  FoldingSet<RecordRecTy> &ThePool =
155  UnsortedClasses[0]->getRecords().RecordTypePool;
156 
157  SmallVector<Record *, 4> Classes(UnsortedClasses.begin(),
158  UnsortedClasses.end());
159  llvm::sort(Classes, [](Record *LHS, Record *RHS) {
160  return LHS->getNameInitAsString() < RHS->getNameInitAsString();
161  });
162 
164  ProfileRecordRecTy(ID, Classes);
165 
166  void *IP = nullptr;
167  if (RecordRecTy *Ty = ThePool.FindNodeOrInsertPos(ID, IP))
168  return Ty;
169 
170 #ifndef NDEBUG
171  // Check for redundancy.
172  for (unsigned i = 0; i < Classes.size(); ++i) {
173  for (unsigned j = 0; j < Classes.size(); ++j) {
174  assert(i == j || !Classes[i]->isSubClassOf(Classes[j]));
175  }
176  assert(&Classes[0]->getRecords() == &Classes[i]->getRecords());
177  }
178 #endif
179 
180  void *Mem = Allocator.Allocate(totalSizeToAlloc<Record *>(Classes.size()),
181  alignof(RecordRecTy));
182  RecordRecTy *Ty = new(Mem) RecordRecTy(Classes.size());
183  std::uninitialized_copy(Classes.begin(), Classes.end(),
184  Ty->getTrailingObjects<Record *>());
185  ThePool.InsertNode(Ty, IP);
186  return Ty;
187 }
188 
191 }
192 
193 std::string RecordRecTy::getAsString() const {
194  if (NumClasses == 1)
195  return getClasses()[0]->getNameInitAsString();
196 
197  std::string Str = "{";
198  bool First = true;
199  for (Record *R : getClasses()) {
200  if (!First)
201  Str += ", ";
202  First = false;
203  Str += R->getNameInitAsString();
204  }
205  Str += "}";
206  return Str;
207 }
208 
209 bool RecordRecTy::isSubClassOf(Record *Class) const {
210  return llvm::any_of(getClasses(), [Class](Record *MySuperClass) {
211  return MySuperClass == Class ||
212  MySuperClass->isSubClassOf(Class);
213  });
214 }
215 
216 bool RecordRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
217  if (this == RHS)
218  return true;
219 
220  const RecordRecTy *RTy = dyn_cast<RecordRecTy>(RHS);
221  if (!RTy)
222  return false;
223 
224  return llvm::all_of(RTy->getClasses(), [this](Record *TargetClass) {
225  return isSubClassOf(TargetClass);
226  });
227 }
228 
229 bool RecordRecTy::typeIsA(const RecTy *RHS) const {
230  return typeIsConvertibleTo(RHS);
231 }
232 
234  SmallVector<Record *, 4> CommonSuperClasses;
235  SmallVector<Record *, 4> Stack(T1->classes_begin(), T1->classes_end());
236 
237  while (!Stack.empty()) {
238  Record *R = Stack.pop_back_val();
239 
240  if (T2->isSubClassOf(R)) {
241  CommonSuperClasses.push_back(R);
242  } else {
243  R->getDirectSuperClasses(Stack);
244  }
245  }
246 
247  return RecordRecTy::get(CommonSuperClasses);
248 }
249 
251  if (T1 == T2)
252  return T1;
253 
254  if (RecordRecTy *RecTy1 = dyn_cast<RecordRecTy>(T1)) {
255  if (RecordRecTy *RecTy2 = dyn_cast<RecordRecTy>(T2))
256  return resolveRecordTypes(RecTy1, RecTy2);
257  }
258 
259  if (T1->typeIsConvertibleTo(T2))
260  return T2;
261  if (T2->typeIsConvertibleTo(T1))
262  return T1;
263 
264  if (ListRecTy *ListTy1 = dyn_cast<ListRecTy>(T1)) {
265  if (ListRecTy *ListTy2 = dyn_cast<ListRecTy>(T2)) {
266  RecTy* NewType = resolveTypes(ListTy1->getElementType(),
267  ListTy2->getElementType());
268  if (NewType)
269  return NewType->getListTy();
270  }
271  }
272 
273  return nullptr;
274 }
275 
276 //===----------------------------------------------------------------------===//
277 // Initializer implementations
278 //===----------------------------------------------------------------------===//
279 
280 void Init::anchor() {}
281 
282 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
283 LLVM_DUMP_METHOD void Init::dump() const { return print(errs()); }
284 #endif
285 
287  static UnsetInit TheInit;
288  return &TheInit;
289 }
290 
292  return const_cast<UnsetInit *>(this);
293 }
294 
296  return const_cast<UnsetInit *>(this);
297 }
298 
300  static BitInit True(true);
301  static BitInit False(false);
302 
303  return V ? &True : &False;
304 }
305 
307  if (isa<BitRecTy>(Ty))
308  return const_cast<BitInit *>(this);
309 
310  if (isa<IntRecTy>(Ty))
311  return IntInit::get(getValue());
312 
313  if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
314  // Can only convert single bit.
315  if (BRT->getNumBits() == 1)
316  return BitsInit::get(const_cast<BitInit *>(this));
317  }
318 
319  return nullptr;
320 }
321 
322 static void
324  ID.AddInteger(Range.size());
325 
326  for (Init *I : Range)
327  ID.AddPointer(I);
328 }
329 
331  static FoldingSet<BitsInit> ThePool;
332 
334  ProfileBitsInit(ID, Range);
335 
336  void *IP = nullptr;
337  if (BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
338  return I;
339 
340  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
341  alignof(BitsInit));
342  BitsInit *I = new(Mem) BitsInit(Range.size());
343  std::uninitialized_copy(Range.begin(), Range.end(),
344  I->getTrailingObjects<Init *>());
345  ThePool.InsertNode(I, IP);
346  return I;
347 }
348 
350  ProfileBitsInit(ID, makeArrayRef(getTrailingObjects<Init *>(), NumBits));
351 }
352 
354  if (isa<BitRecTy>(Ty)) {
355  if (getNumBits() != 1) return nullptr; // Only accept if just one bit!
356  return getBit(0);
357  }
358 
359  if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
360  // If the number of bits is right, return it. Otherwise we need to expand
361  // or truncate.
362  if (getNumBits() != BRT->getNumBits()) return nullptr;
363  return const_cast<BitsInit *>(this);
364  }
365 
366  if (isa<IntRecTy>(Ty)) {
367  int64_t Result = 0;
368  for (unsigned i = 0, e = getNumBits(); i != e; ++i)
369  if (auto *Bit = dyn_cast<BitInit>(getBit(i)))
370  Result |= static_cast<int64_t>(Bit->getValue()) << i;
371  else
372  return nullptr;
373  return IntInit::get(Result);
374  }
375 
376  return nullptr;
377 }
378 
379 Init *
381  SmallVector<Init *, 16> NewBits(Bits.size());
382 
383  for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
384  if (Bits[i] >= getNumBits())
385  return nullptr;
386  NewBits[i] = getBit(Bits[i]);
387  }
388  return BitsInit::get(NewBits);
389 }
390 
391 bool BitsInit::isConcrete() const {
392  for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
393  if (!getBit(i)->isConcrete())
394  return false;
395  }
396  return true;
397 }
398 
399 std::string BitsInit::getAsString() const {
400  std::string Result = "{ ";
401  for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
402  if (i) Result += ", ";
403  if (Init *Bit = getBit(e-i-1))
404  Result += Bit->getAsString();
405  else
406  Result += "*";
407  }
408  return Result + " }";
409 }
410 
411 // resolveReferences - If there are any field references that refer to fields
412 // that have been filled in, we can propagate the values now.
414  bool Changed = false;
416 
417  Init *CachedBitVarRef = nullptr;
418  Init *CachedBitVarResolved = nullptr;
419 
420  for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
421  Init *CurBit = getBit(i);
422  Init *NewBit = CurBit;
423 
424  if (VarBitInit *CurBitVar = dyn_cast<VarBitInit>(CurBit)) {
425  if (CurBitVar->getBitVar() != CachedBitVarRef) {
426  CachedBitVarRef = CurBitVar->getBitVar();
427  CachedBitVarResolved = CachedBitVarRef->resolveReferences(R);
428  }
429  assert(CachedBitVarResolved && "Unresolved bitvar reference");
430  NewBit = CachedBitVarResolved->getBit(CurBitVar->getBitNum());
431  } else {
432  // getBit(0) implicitly converts int and bits<1> values to bit.
433  NewBit = CurBit->resolveReferences(R)->getBit(0);
434  }
435 
436  if (isa<UnsetInit>(NewBit) && R.keepUnsetBits())
437  NewBit = CurBit;
438  NewBits[i] = NewBit;
439  Changed |= CurBit != NewBit;
440  }
441 
442  if (Changed)
443  return BitsInit::get(NewBits);
444 
445  return const_cast<BitsInit *>(this);
446 }
447 
448 IntInit *IntInit::get(int64_t V) {
449  static std::map<int64_t, IntInit*> ThePool;
450 
451  IntInit *&I = ThePool[V];
452  if (!I) I = new(Allocator) IntInit(V);
453  return I;
454 }
455 
456 std::string IntInit::getAsString() const {
457  return itostr(Value);
458 }
459 
460 static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
461  // For example, with NumBits == 4, we permit Values from [-7 .. 15].
462  return (NumBits >= sizeof(Value) * 8) ||
463  (Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
464 }
465 
467  if (isa<IntRecTy>(Ty))
468  return const_cast<IntInit *>(this);
469 
470  if (isa<BitRecTy>(Ty)) {
471  int64_t Val = getValue();
472  if (Val != 0 && Val != 1) return nullptr; // Only accept 0 or 1 for a bit!
473  return BitInit::get(Val != 0);
474  }
475 
476  if (auto *BRT = dyn_cast<BitsRecTy>(Ty)) {
477  int64_t Value = getValue();
478  // Make sure this bitfield is large enough to hold the integer value.
479  if (!canFitInBitfield(Value, BRT->getNumBits()))
480  return nullptr;
481 
482  SmallVector<Init *, 16> NewBits(BRT->getNumBits());
483  for (unsigned i = 0; i != BRT->getNumBits(); ++i)
484  NewBits[i] = BitInit::get(Value & ((i < 64) ? (1LL << i) : 0));
485 
486  return BitsInit::get(NewBits);
487  }
488 
489  return nullptr;
490 }
491 
492 Init *
494  SmallVector<Init *, 16> NewBits(Bits.size());
495 
496  for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
497  if (Bits[i] >= 64)
498  return nullptr;
499 
500  NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i]));
501  }
502  return BitsInit::get(NewBits);
503 }
504 
506  return new (Allocator) AnonymousNameInit(V);
507 }
508 
510  return StringInit::get(getAsString());
511 }
512 
513 std::string AnonymousNameInit::getAsString() const {
514  return "anonymous_" + utostr(Value);
515 }
516 
518  auto *Old = const_cast<Init *>(static_cast<const Init *>(this));
519  auto *New = R.resolve(Old);
520  New = New ? New : Old;
521  if (R.isFinal())
522  if (auto *Anonymous = dyn_cast<AnonymousNameInit>(New))
523  return Anonymous->getNameInit();
524  return New;
525 }
526 
530 
531  if (Fmt == SF_String) {
532  auto &Entry = *StringPool.insert(std::make_pair(V, nullptr)).first;
533  if (!Entry.second)
534  Entry.second = new (Allocator) StringInit(Entry.getKey(), Fmt);
535  return Entry.second;
536  } else {
537  auto &Entry = *CodePool.insert(std::make_pair(V, nullptr)).first;
538  if (!Entry.second)
539  Entry.second = new (Allocator) StringInit(Entry.getKey(), Fmt);
540  return Entry.second;
541  }
542 }
543 
545  if (isa<StringRecTy>(Ty))
546  return const_cast<StringInit *>(this);
547 
548  return nullptr;
549 }
550 
552  ArrayRef<Init *> Range,
553  RecTy *EltTy) {
554  ID.AddInteger(Range.size());
555  ID.AddPointer(EltTy);
556 
557  for (Init *I : Range)
558  ID.AddPointer(I);
559 }
560 
562  static FoldingSet<ListInit> ThePool;
563 
565  ProfileListInit(ID, Range, EltTy);
566 
567  void *IP = nullptr;
568  if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
569  return I;
570 
571  assert(Range.empty() || !isa<TypedInit>(Range[0]) ||
572  cast<TypedInit>(Range[0])->getType()->typeIsConvertibleTo(EltTy));
573 
574  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
575  alignof(ListInit));
576  ListInit *I = new(Mem) ListInit(Range.size(), EltTy);
577  std::uninitialized_copy(Range.begin(), Range.end(),
578  I->getTrailingObjects<Init *>());
579  ThePool.InsertNode(I, IP);
580  return I;
581 }
582 
584  RecTy *EltTy = cast<ListRecTy>(getType())->getElementType();
585 
586  ProfileListInit(ID, getValues(), EltTy);
587 }
588 
590  if (getType() == Ty)
591  return const_cast<ListInit*>(this);
592 
593  if (auto *LRT = dyn_cast<ListRecTy>(Ty)) {
594  SmallVector<Init*, 8> Elements;
595  Elements.reserve(getValues().size());
596 
597  // Verify that all of the elements of the list are subclasses of the
598  // appropriate class!
599  bool Changed = false;
600  RecTy *ElementType = LRT->getElementType();
601  for (Init *I : getValues())
602  if (Init *CI = I->convertInitializerTo(ElementType)) {
603  Elements.push_back(CI);
604  if (CI != I)
605  Changed = true;
606  } else
607  return nullptr;
608 
609  if (!Changed)
610  return const_cast<ListInit*>(this);
611  return ListInit::get(Elements, ElementType);
612  }
613 
614  return nullptr;
615 }
616 
618  if (Elements.size() == 1) {
619  if (Elements[0] >= size())
620  return nullptr;
621  return getElement(Elements[0]);
622  }
623 
625  Vals.reserve(Elements.size());
626  for (unsigned Element : Elements) {
627  if (Element >= size())
628  return nullptr;
629  Vals.push_back(getElement(Element));
630  }
631  return ListInit::get(Vals, getElementType());
632 }
633 
635  assert(i < NumValues && "List element index out of range!");
636  DefInit *DI = dyn_cast<DefInit>(getElement(i));
637  if (!DI)
638  PrintFatalError("Expected record in list!");
639  return DI->getDef();
640 }
641 
643  SmallVector<Init*, 8> Resolved;
644  Resolved.reserve(size());
645  bool Changed = false;
646 
647  for (Init *CurElt : getValues()) {
648  Init *E = CurElt->resolveReferences(R);
649  Changed |= E != CurElt;
650  Resolved.push_back(E);
651  }
652 
653  if (Changed)
654  return ListInit::get(Resolved, getElementType());
655  return const_cast<ListInit *>(this);
656 }
657 
658 bool ListInit::isComplete() const {
659  for (Init *Element : *this) {
660  if (!Element->isComplete())
661  return false;
662  }
663  return true;
664 }
665 
666 bool ListInit::isConcrete() const {
667  for (Init *Element : *this) {
668  if (!Element->isConcrete())
669  return false;
670  }
671  return true;
672 }
673 
674 std::string ListInit::getAsString() const {
675  std::string Result = "[";
676  const char *sep = "";
677  for (Init *Element : *this) {
678  Result += sep;
679  sep = ", ";
680  Result += Element->getAsString();
681  }
682  return Result + "]";
683 }
684 
685 Init *OpInit::getBit(unsigned Bit) const {
686  if (getType() == BitRecTy::get())
687  return const_cast<OpInit*>(this);
688  return VarBitInit::get(const_cast<OpInit*>(this), Bit);
689 }
690 
691 static void
693  ID.AddInteger(Opcode);
694  ID.AddPointer(Op);
695  ID.AddPointer(Type);
696 }
697 
699  static FoldingSet<UnOpInit> ThePool;
700 
702  ProfileUnOpInit(ID, Opc, LHS, Type);
703 
704  void *IP = nullptr;
705  if (UnOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
706  return I;
707 
708  UnOpInit *I = new(Allocator) UnOpInit(Opc, LHS, Type);
709  ThePool.InsertNode(I, IP);
710  return I;
711 }
712 
715 }
716 
717 Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
718  switch (getOpcode()) {
719  case CAST:
720  if (isa<StringRecTy>(getType())) {
721  if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
722  return LHSs;
723 
724  if (DefInit *LHSd = dyn_cast<DefInit>(LHS))
725  return StringInit::get(LHSd->getAsString());
726 
727  if (IntInit *LHSi =
728  dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get())))
729  return StringInit::get(LHSi->getAsString());
730 
731  } else if (isa<RecordRecTy>(getType())) {
732  if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
733  if (!CurRec && !IsFinal)
734  break;
735  assert(CurRec && "NULL pointer");
736  Record *D;
737 
738  // Self-references are allowed, but their resolution is delayed until
739  // the final resolve to ensure that we get the correct type for them.
740  auto *Anonymous = dyn_cast<AnonymousNameInit>(CurRec->getNameInit());
741  if (Name == CurRec->getNameInit() ||
742  (Anonymous && Name == Anonymous->getNameInit())) {
743  if (!IsFinal)
744  break;
745  D = CurRec;
746  } else {
747  D = CurRec->getRecords().getDef(Name->getValue());
748  if (!D) {
749  if (IsFinal)
750  PrintFatalError(CurRec->getLoc(),
751  Twine("Undefined reference to record: '") +
752  Name->getValue() + "'\n");
753  break;
754  }
755  }
756 
757  DefInit *DI = DefInit::get(D);
758  if (!DI->getType()->typeIsA(getType())) {
759  PrintFatalError(CurRec->getLoc(),
760  Twine("Expected type '") +
761  getType()->getAsString() + "', got '" +
762  DI->getType()->getAsString() + "' in: " +
763  getAsString() + "\n");
764  }
765  return DI;
766  }
767  }
768 
769  if (Init *NewInit = LHS->convertInitializerTo(getType()))
770  return NewInit;
771  break;
772 
773  case NOT:
774  if (IntInit *LHSi =
775  dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get())))
776  return IntInit::get(LHSi->getValue() ? 0 : 1);
777  break;
778 
779  case HEAD:
780  if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
781  assert(!LHSl->empty() && "Empty list in head");
782  return LHSl->getElement(0);
783  }
784  break;
785 
786  case TAIL:
787  if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
788  assert(!LHSl->empty() && "Empty list in tail");
789  // Note the +1. We can't just pass the result of getValues()
790  // directly.
791  return ListInit::get(LHSl->getValues().slice(1), LHSl->getElementType());
792  }
793  break;
794 
795  case SIZE:
796  if (ListInit *LHSl = dyn_cast<ListInit>(LHS))
797  return IntInit::get(LHSl->size());
798  if (DagInit *LHSd = dyn_cast<DagInit>(LHS))
799  return IntInit::get(LHSd->arg_size());
800  if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
801  return IntInit::get(LHSs->getValue().size());
802  break;
803 
804  case EMPTY:
805  if (ListInit *LHSl = dyn_cast<ListInit>(LHS))
806  return IntInit::get(LHSl->empty());
807  if (DagInit *LHSd = dyn_cast<DagInit>(LHS))
808  return IntInit::get(LHSd->arg_empty());
809  if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
810  return IntInit::get(LHSs->getValue().empty());
811  break;
812 
813  case GETDAGOP:
814  if (DagInit *Dag = dyn_cast<DagInit>(LHS)) {
815  DefInit *DI = DefInit::get(Dag->getOperatorAsDef({}));
816  if (!DI->getType()->typeIsA(getType())) {
817  PrintFatalError(CurRec->getLoc(),
818  Twine("Expected type '") +
819  getType()->getAsString() + "', got '" +
820  DI->getType()->getAsString() + "' in: " +
821  getAsString() + "\n");
822  } else {
823  return DI;
824  }
825  }
826  break;
827  }
828  return const_cast<UnOpInit *>(this);
829 }
830 
832  Init *lhs = LHS->resolveReferences(R);
833 
834  if (LHS != lhs || (R.isFinal() && getOpcode() == CAST))
835  return (UnOpInit::get(getOpcode(), lhs, getType()))
836  ->Fold(R.getCurrentRecord(), R.isFinal());
837  return const_cast<UnOpInit *>(this);
838 }
839 
840 std::string UnOpInit::getAsString() const {
841  std::string Result;
842  switch (getOpcode()) {
843  case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
844  case NOT: Result = "!not"; break;
845  case HEAD: Result = "!head"; break;
846  case TAIL: Result = "!tail"; break;
847  case SIZE: Result = "!size"; break;
848  case EMPTY: Result = "!empty"; break;
849  case GETDAGOP: Result = "!getdagop"; break;
850  }
851  return Result + "(" + LHS->getAsString() + ")";
852 }
853 
854 static void
855 ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS,
856  RecTy *Type) {
857  ID.AddInteger(Opcode);
858  ID.AddPointer(LHS);
859  ID.AddPointer(RHS);
860  ID.AddPointer(Type);
861 }
862 
864  Init *RHS, RecTy *Type) {
865  static FoldingSet<BinOpInit> ThePool;
866 
868  ProfileBinOpInit(ID, Opc, LHS, RHS, Type);
869 
870  void *IP = nullptr;
871  if (BinOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
872  return I;
873 
874  BinOpInit *I = new(Allocator) BinOpInit(Opc, LHS, RHS, Type);
875  ThePool.InsertNode(I, IP);
876  return I;
877 }
878 
881 }
882 
884  const StringInit *I1) {
886  Concat.append(I1->getValue());
887  return StringInit::get(Concat,
889  I1->getFormat()));
890 }
891 
893  const StringInit *Delim) {
894  if (List->size() == 0)
895  return StringInit::get("");
896  StringInit *Element = dyn_cast<StringInit>(List->getElement(0));
897  if (!Element)
898  return nullptr;
899  SmallString<80> Result(Element->getValue());
901 
902  for (unsigned I = 1, E = List->size(); I < E; ++I) {
903  Result.append(Delim->getValue());
904  StringInit *Element = dyn_cast<StringInit>(List->getElement(I));
905  if (!Element)
906  return nullptr;
907  Result.append(Element->getValue());
908  Fmt = StringInit::determineFormat(Fmt, Element->getFormat());
909  }
910  return StringInit::get(Result, Fmt);
911 }
912 
914  const StringInit *Delim) {
915  if (List->size() == 0)
916  return StringInit::get("");
917  IntInit *Element =
918  dyn_cast_or_null<IntInit>(List->getElement(0)
919  ->convertInitializerTo(IntRecTy::get()));
920  if (!Element)
921  return nullptr;
922  SmallString<80> Result(Element->getAsString());
923 
924  for (unsigned I = 1, E = List->size(); I < E; ++I) {
925  Result.append(Delim->getValue());
926  IntInit *Element =
927  dyn_cast_or_null<IntInit>(List->getElement(I)
928  ->convertInitializerTo(IntRecTy::get()));
929  if (!Element)
930  return nullptr;
931  Result.append(Element->getAsString());
932  }
933  return StringInit::get(Result);
934 }
935 
937  // Shortcut for the common case of concatenating two strings.
938  if (const StringInit *I0s = dyn_cast<StringInit>(I0))
939  if (const StringInit *I1s = dyn_cast<StringInit>(I1))
940  return ConcatStringInits(I0s, I1s);
942 }
943 
944 static ListInit *ConcatListInits(const ListInit *LHS,
945  const ListInit *RHS) {
947  llvm::append_range(Args, *LHS);
948  llvm::append_range(Args, *RHS);
949  return ListInit::get(Args, LHS->getElementType());
950 }
951 
953  assert(isa<ListRecTy>(LHS->getType()) && "First arg must be a list");
954 
955  // Shortcut for the common case of concatenating two lists.
956  if (const ListInit *LHSList = dyn_cast<ListInit>(LHS))
957  if (const ListInit *RHSList = dyn_cast<ListInit>(RHS))
958  return ConcatListInits(LHSList, RHSList);
959  return BinOpInit::get(BinOpInit::LISTCONCAT, LHS, RHS, LHS->getType());
960 }
961 
962 Init *BinOpInit::Fold(Record *CurRec) const {
963  switch (getOpcode()) {
964  case CONCAT: {
965  DagInit *LHSs = dyn_cast<DagInit>(LHS);
966  DagInit *RHSs = dyn_cast<DagInit>(RHS);
967  if (LHSs && RHSs) {
968  DefInit *LOp = dyn_cast<DefInit>(LHSs->getOperator());
969  DefInit *ROp = dyn_cast<DefInit>(RHSs->getOperator());
970  if ((!LOp && !isa<UnsetInit>(LHSs->getOperator())) ||
971  (!ROp && !isa<UnsetInit>(RHSs->getOperator())))
972  break;
973  if (LOp && ROp && LOp->getDef() != ROp->getDef()) {
974  PrintFatalError(Twine("Concatenated Dag operators do not match: '") +
975  LHSs->getAsString() + "' vs. '" + RHSs->getAsString() +
976  "'");
977  }
978  Init *Op = LOp ? LOp : ROp;
979  if (!Op)
980  Op = UnsetInit::get();
981 
984  for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
985  Args.push_back(LHSs->getArg(i));
986  ArgNames.push_back(LHSs->getArgName(i));
987  }
988  for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
989  Args.push_back(RHSs->getArg(i));
990  ArgNames.push_back(RHSs->getArgName(i));
991  }
992  return DagInit::get(Op, nullptr, Args, ArgNames);
993  }
994  break;
995  }
996  case LISTCONCAT: {
997  ListInit *LHSs = dyn_cast<ListInit>(LHS);
998  ListInit *RHSs = dyn_cast<ListInit>(RHS);
999  if (LHSs && RHSs) {
1001  llvm::append_range(Args, *LHSs);
1002  llvm::append_range(Args, *RHSs);
1003  return ListInit::get(Args, LHSs->getElementType());
1004  }
1005  break;
1006  }
1007  case LISTSPLAT: {
1008  TypedInit *Value = dyn_cast<TypedInit>(LHS);
1009  IntInit *Size = dyn_cast<IntInit>(RHS);
1010  if (Value && Size) {
1011  SmallVector<Init *, 8> Args(Size->getValue(), Value);
1012  return ListInit::get(Args, Value->getType());
1013  }
1014  break;
1015  }
1016  case STRCONCAT: {
1017  StringInit *LHSs = dyn_cast<StringInit>(LHS);
1018  StringInit *RHSs = dyn_cast<StringInit>(RHS);
1019  if (LHSs && RHSs)
1020  return ConcatStringInits(LHSs, RHSs);
1021  break;
1022  }
1023  case INTERLEAVE: {
1024  ListInit *List = dyn_cast<ListInit>(LHS);
1025  StringInit *Delim = dyn_cast<StringInit>(RHS);
1026  if (List && Delim) {
1027  StringInit *Result;
1028  if (isa<StringRecTy>(List->getElementType()))
1029  Result = interleaveStringList(List, Delim);
1030  else
1031  Result = interleaveIntList(List, Delim);
1032  if (Result)
1033  return Result;
1034  }
1035  break;
1036  }
1037  case EQ:
1038  case NE:
1039  case LE:
1040  case LT:
1041  case GE:
1042  case GT: {
1043  // First see if we have two bit, bits, or int.
1044  IntInit *LHSi =
1045  dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
1046  IntInit *RHSi =
1047  dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
1048 
1049  if (LHSi && RHSi) {
1050  bool Result;
1051  switch (getOpcode()) {
1052  case EQ: Result = LHSi->getValue() == RHSi->getValue(); break;
1053  case NE: Result = LHSi->getValue() != RHSi->getValue(); break;
1054  case LE: Result = LHSi->getValue() <= RHSi->getValue(); break;
1055  case LT: Result = LHSi->getValue() < RHSi->getValue(); break;
1056  case GE: Result = LHSi->getValue() >= RHSi->getValue(); break;
1057  case GT: Result = LHSi->getValue() > RHSi->getValue(); break;
1058  default: llvm_unreachable("unhandled comparison");
1059  }
1060  return BitInit::get(Result);
1061  }
1062 
1063  // Next try strings.
1064  StringInit *LHSs = dyn_cast<StringInit>(LHS);
1065  StringInit *RHSs = dyn_cast<StringInit>(RHS);
1066 
1067  if (LHSs && RHSs) {
1068  bool Result;
1069  switch (getOpcode()) {
1070  case EQ: Result = LHSs->getValue() == RHSs->getValue(); break;
1071  case NE: Result = LHSs->getValue() != RHSs->getValue(); break;
1072  case LE: Result = LHSs->getValue() <= RHSs->getValue(); break;
1073  case LT: Result = LHSs->getValue() < RHSs->getValue(); break;
1074  case GE: Result = LHSs->getValue() >= RHSs->getValue(); break;
1075  case GT: Result = LHSs->getValue() > RHSs->getValue(); break;
1076  default: llvm_unreachable("unhandled comparison");
1077  }
1078  return BitInit::get(Result);
1079  }
1080 
1081  // Finally, !eq and !ne can be used with records.
1082  if (getOpcode() == EQ || getOpcode() == NE) {
1083  DefInit *LHSd = dyn_cast<DefInit>(LHS);
1084  DefInit *RHSd = dyn_cast<DefInit>(RHS);
1085  if (LHSd && RHSd)
1086  return BitInit::get((getOpcode() == EQ) ? LHSd == RHSd
1087  : LHSd != RHSd);
1088  }
1089 
1090  break;
1091  }
1092  case SETDAGOP: {
1093  DagInit *Dag = dyn_cast<DagInit>(LHS);
1094  DefInit *Op = dyn_cast<DefInit>(RHS);
1095  if (Dag && Op) {
1097  SmallVector<StringInit*, 8> ArgNames;
1098  for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) {
1099  Args.push_back(Dag->getArg(i));
1100  ArgNames.push_back(Dag->getArgName(i));
1101  }
1102  return DagInit::get(Op, nullptr, Args, ArgNames);
1103  }
1104  break;
1105  }
1106  case ADD:
1107  case SUB:
1108  case MUL:
1109  case AND:
1110  case OR:
1111  case XOR:
1112  case SHL:
1113  case SRA:
1114  case SRL: {
1115  IntInit *LHSi =
1116  dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
1117  IntInit *RHSi =
1118  dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
1119  if (LHSi && RHSi) {
1120  int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
1121  int64_t Result;
1122  switch (getOpcode()) {
1123  default: llvm_unreachable("Bad opcode!");
1124  case ADD: Result = LHSv + RHSv; break;
1125  case SUB: Result = LHSv - RHSv; break;
1126  case MUL: Result = LHSv * RHSv; break;
1127  case AND: Result = LHSv & RHSv; break;
1128  case OR: Result = LHSv | RHSv; break;
1129  case XOR: Result = LHSv ^ RHSv; break;
1130  case SHL: Result = (uint64_t)LHSv << (uint64_t)RHSv; break;
1131  case SRA: Result = LHSv >> RHSv; break;
1132  case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
1133  }
1134  return IntInit::get(Result);
1135  }
1136  break;
1137  }
1138  }
1139  return const_cast<BinOpInit *>(this);
1140 }
1141 
1143  Init *lhs = LHS->resolveReferences(R);
1144  Init *rhs = RHS->resolveReferences(R);
1145 
1146  if (LHS != lhs || RHS != rhs)
1147  return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))
1148  ->Fold(R.getCurrentRecord());
1149  return const_cast<BinOpInit *>(this);
1150 }
1151 
1152 std::string BinOpInit::getAsString() const {
1153  std::string Result;
1154  switch (getOpcode()) {
1155  case CONCAT: Result = "!con"; break;
1156  case ADD: Result = "!add"; break;
1157  case SUB: Result = "!sub"; break;
1158  case MUL: Result = "!mul"; break;
1159  case AND: Result = "!and"; break;
1160  case OR: Result = "!or"; break;
1161  case XOR: Result = "!xor"; break;
1162  case SHL: Result = "!shl"; break;
1163  case SRA: Result = "!sra"; break;
1164  case SRL: Result = "!srl"; break;
1165  case EQ: Result = "!eq"; break;
1166  case NE: Result = "!ne"; break;
1167  case LE: Result = "!le"; break;
1168  case LT: Result = "!lt"; break;
1169  case GE: Result = "!ge"; break;
1170  case GT: Result = "!gt"; break;
1171  case LISTCONCAT: Result = "!listconcat"; break;
1172  case LISTSPLAT: Result = "!listsplat"; break;
1173  case STRCONCAT: Result = "!strconcat"; break;
1174  case INTERLEAVE: Result = "!interleave"; break;
1175  case SETDAGOP: Result = "!setdagop"; break;
1176  }
1177  return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
1178 }
1179 
1180 static void
1181 ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
1182  Init *RHS, RecTy *Type) {
1183  ID.AddInteger(Opcode);
1184  ID.AddPointer(LHS);
1185  ID.AddPointer(MHS);
1186  ID.AddPointer(RHS);
1187  ID.AddPointer(Type);
1188 }
1189 
1191  RecTy *Type) {
1192  static FoldingSet<TernOpInit> ThePool;
1193 
1195  ProfileTernOpInit(ID, Opc, LHS, MHS, RHS, Type);
1196 
1197  void *IP = nullptr;
1198  if (TernOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1199  return I;
1200 
1201  TernOpInit *I = new(Allocator) TernOpInit(Opc, LHS, MHS, RHS, Type);
1202  ThePool.InsertNode(I, IP);
1203  return I;
1204 }
1205 
1208 }
1209 
1210 static Init *ItemApply(Init *LHS, Init *MHSe, Init *RHS, Record *CurRec) {
1211  MapResolver R(CurRec);
1212  R.set(LHS, MHSe);
1213  return RHS->resolveReferences(R);
1214 }
1215 
1216 static Init *ForeachDagApply(Init *LHS, DagInit *MHSd, Init *RHS,
1217  Record *CurRec) {
1218  bool Change = false;
1219  Init *Val = ItemApply(LHS, MHSd->getOperator(), RHS, CurRec);
1220  if (Val != MHSd->getOperator())
1221  Change = true;
1222 
1224  for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
1225  Init *Arg = MHSd->getArg(i);
1226  Init *NewArg;
1227  StringInit *ArgName = MHSd->getArgName(i);
1228 
1229  if (DagInit *Argd = dyn_cast<DagInit>(Arg))
1230  NewArg = ForeachDagApply(LHS, Argd, RHS, CurRec);
1231  else
1232  NewArg = ItemApply(LHS, Arg, RHS, CurRec);
1233 
1234  NewArgs.push_back(std::make_pair(NewArg, ArgName));
1235  if (Arg != NewArg)
1236  Change = true;
1237  }
1238 
1239  if (Change)
1240  return DagInit::get(Val, nullptr, NewArgs);
1241  return MHSd;
1242 }
1243 
1244 // Applies RHS to all elements of MHS, using LHS as a temp variable.
1245 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
1246  Record *CurRec) {
1247  if (DagInit *MHSd = dyn_cast<DagInit>(MHS))
1248  return ForeachDagApply(LHS, MHSd, RHS, CurRec);
1249 
1250  if (ListInit *MHSl = dyn_cast<ListInit>(MHS)) {
1251  SmallVector<Init *, 8> NewList(MHSl->begin(), MHSl->end());
1252 
1253  for (Init *&Item : NewList) {
1254  Init *NewItem = ItemApply(LHS, Item, RHS, CurRec);
1255  if (NewItem != Item)
1256  Item = NewItem;
1257  }
1258  return ListInit::get(NewList, cast<ListRecTy>(Type)->getElementType());
1259  }
1260 
1261  return nullptr;
1262 }
1263 
1264 // Evaluates RHS for all elements of MHS, using LHS as a temp variable.
1265 // Creates a new list with the elements that evaluated to true.
1266 static Init *FilterHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
1267  Record *CurRec) {
1268  if (ListInit *MHSl = dyn_cast<ListInit>(MHS)) {
1269  SmallVector<Init *, 8> NewList;
1270 
1271  for (Init *Item : MHSl->getValues()) {
1272  Init *Include = ItemApply(LHS, Item, RHS, CurRec);
1273  if (!Include)
1274  return nullptr;
1275  if (IntInit *IncludeInt = dyn_cast_or_null<IntInit>(
1276  Include->convertInitializerTo(IntRecTy::get()))) {
1277  if (IncludeInt->getValue())
1278  NewList.push_back(Item);
1279  } else {
1280  return nullptr;
1281  }
1282  }
1283  return ListInit::get(NewList, cast<ListRecTy>(Type)->getElementType());
1284  }
1285 
1286  return nullptr;
1287 }
1288 
1289 Init *TernOpInit::Fold(Record *CurRec) const {
1290  switch (getOpcode()) {
1291  case SUBST: {
1292  DefInit *LHSd = dyn_cast<DefInit>(LHS);
1293  VarInit *LHSv = dyn_cast<VarInit>(LHS);
1294  StringInit *LHSs = dyn_cast<StringInit>(LHS);
1295 
1296  DefInit *MHSd = dyn_cast<DefInit>(MHS);
1297  VarInit *MHSv = dyn_cast<VarInit>(MHS);
1298  StringInit *MHSs = dyn_cast<StringInit>(MHS);
1299 
1300  DefInit *RHSd = dyn_cast<DefInit>(RHS);
1301  VarInit *RHSv = dyn_cast<VarInit>(RHS);
1302  StringInit *RHSs = dyn_cast<StringInit>(RHS);
1303 
1304  if (LHSd && MHSd && RHSd) {
1305  Record *Val = RHSd->getDef();
1306  if (LHSd->getAsString() == RHSd->getAsString())
1307  Val = MHSd->getDef();
1308  return DefInit::get(Val);
1309  }
1310  if (LHSv && MHSv && RHSv) {
1311  std::string Val = std::string(RHSv->getName());
1312  if (LHSv->getAsString() == RHSv->getAsString())
1313  Val = std::string(MHSv->getName());
1314  return VarInit::get(Val, getType());
1315  }
1316  if (LHSs && MHSs && RHSs) {
1317  std::string Val = std::string(RHSs->getValue());
1318 
1319  std::string::size_type found;
1320  std::string::size_type idx = 0;
1321  while (true) {
1322  found = Val.find(std::string(LHSs->getValue()), idx);
1323  if (found == std::string::npos)
1324  break;
1325  Val.replace(found, LHSs->getValue().size(),
1326  std::string(MHSs->getValue()));
1327  idx = found + MHSs->getValue().size();
1328  }
1329 
1330  return StringInit::get(Val);
1331  }
1332  break;
1333  }
1334 
1335  case FOREACH: {
1336  if (Init *Result = ForeachHelper(LHS, MHS, RHS, getType(), CurRec))
1337  return Result;
1338  break;
1339  }
1340 
1341  case FILTER: {
1342  if (Init *Result = FilterHelper(LHS, MHS, RHS, getType(), CurRec))
1343  return Result;
1344  break;
1345  }
1346 
1347  case IF: {
1348  if (IntInit *LHSi = dyn_cast_or_null<IntInit>(
1350  if (LHSi->getValue())
1351  return MHS;
1352  return RHS;
1353  }
1354  break;
1355  }
1356 
1357  case DAG: {
1358  ListInit *MHSl = dyn_cast<ListInit>(MHS);
1359  ListInit *RHSl = dyn_cast<ListInit>(RHS);
1360  bool MHSok = MHSl || isa<UnsetInit>(MHS);
1361  bool RHSok = RHSl || isa<UnsetInit>(RHS);
1362 
1363  if (isa<UnsetInit>(MHS) && isa<UnsetInit>(RHS))
1364  break; // Typically prevented by the parser, but might happen with template args
1365 
1366  if (MHSok && RHSok && (!MHSl || !RHSl || MHSl->size() == RHSl->size())) {
1368  unsigned Size = MHSl ? MHSl->size() : RHSl->size();
1369  for (unsigned i = 0; i != Size; ++i) {
1370  Init *Node = MHSl ? MHSl->getElement(i) : UnsetInit::get();
1371  Init *Name = RHSl ? RHSl->getElement(i) : UnsetInit::get();
1372  if (!isa<StringInit>(Name) && !isa<UnsetInit>(Name))
1373  return const_cast<TernOpInit *>(this);
1374  Children.emplace_back(Node, dyn_cast<StringInit>(Name));
1375  }
1376  return DagInit::get(LHS, nullptr, Children);
1377  }
1378  break;
1379  }
1380 
1381  case SUBSTR: {
1382  StringInit *LHSs = dyn_cast<StringInit>(LHS);
1383  IntInit *MHSi = dyn_cast<IntInit>(MHS);
1384  IntInit *RHSi = dyn_cast<IntInit>(RHS);
1385  if (LHSs && MHSi && RHSi) {
1386  int64_t StringSize = LHSs->getValue().size();
1387  int64_t Start = MHSi->getValue();
1388  int64_t Length = RHSi->getValue();
1389  if (Start < 0 || Start > StringSize)
1390  PrintError(CurRec->getLoc(),
1391  Twine("!substr start position is out of range 0...") +
1392  std::to_string(StringSize) + ": " +
1393  std::to_string(Start));
1394  if (Length < 0)
1395  PrintError(CurRec->getLoc(), "!substr length must be nonnegative");
1396  return StringInit::get(LHSs->getValue().substr(Start, Length),
1397  LHSs->getFormat());
1398  }
1399  break;
1400  }
1401 
1402  case FIND: {
1403  StringInit *LHSs = dyn_cast<StringInit>(LHS);
1404  StringInit *MHSs = dyn_cast<StringInit>(MHS);
1405  IntInit *RHSi = dyn_cast<IntInit>(RHS);
1406  if (LHSs && MHSs && RHSi) {
1407  int64_t SourceSize = LHSs->getValue().size();
1408  int64_t Start = RHSi->getValue();
1409  if (Start < 0 || Start > SourceSize)
1410  PrintError(CurRec->getLoc(),
1411  Twine("!find start position is out of range 0...") +
1412  std::to_string(SourceSize) + ": " +
1413  std::to_string(Start));
1414  auto I = LHSs->getValue().find(MHSs->getValue(), Start);
1415  if (I == std::string::npos)
1416  return IntInit::get(-1);
1417  return IntInit::get(I);
1418  }
1419  break;
1420  }
1421  }
1422 
1423  return const_cast<TernOpInit *>(this);
1424 }
1425 
1427  Init *lhs = LHS->resolveReferences(R);
1428 
1429  if (getOpcode() == IF && lhs != LHS) {
1430  if (IntInit *Value = dyn_cast_or_null<IntInit>(
1432  // Short-circuit
1433  if (Value->getValue())
1434  return MHS->resolveReferences(R);
1435  return RHS->resolveReferences(R);
1436  }
1437  }
1438 
1439  Init *mhs = MHS->resolveReferences(R);
1440  Init *rhs;
1441 
1442  if (getOpcode() == FOREACH || getOpcode() == FILTER) {
1443  ShadowResolver SR(R);
1444  SR.addShadow(lhs);
1445  rhs = RHS->resolveReferences(SR);
1446  } else {
1447  rhs = RHS->resolveReferences(R);
1448  }
1449 
1450  if (LHS != lhs || MHS != mhs || RHS != rhs)
1451  return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))
1452  ->Fold(R.getCurrentRecord());
1453  return const_cast<TernOpInit *>(this);
1454 }
1455 
1456 std::string TernOpInit::getAsString() const {
1457  std::string Result;
1458  bool UnquotedLHS = false;
1459  switch (getOpcode()) {
1460  case DAG: Result = "!dag"; break;
1461  case FILTER: Result = "!filter"; UnquotedLHS = true; break;
1462  case FOREACH: Result = "!foreach"; UnquotedLHS = true; break;
1463  case IF: Result = "!if"; break;
1464  case SUBST: Result = "!subst"; break;
1465  case SUBSTR: Result = "!substr"; break;
1466  case FIND: Result = "!find"; break;
1467  }
1468  return (Result + "(" +
1469  (UnquotedLHS ? LHS->getAsUnquotedString() : LHS->getAsString()) +
1470  ", " + MHS->getAsString() + ", " + RHS->getAsString() + ")");
1471 }
1472 
1474  Init *Start, Init *List, Init *Expr,
1475  RecTy *Type) {
1476  ID.AddPointer(Start);
1477  ID.AddPointer(List);
1478  ID.AddPointer(A);
1479  ID.AddPointer(B);
1480  ID.AddPointer(Expr);
1481  ID.AddPointer(Type);
1482 }
1483 
1485  Init *Expr, RecTy *Type) {
1486  static FoldingSet<FoldOpInit> ThePool;
1487 
1489  ProfileFoldOpInit(ID, Start, List, A, B, Expr, Type);
1490 
1491  void *IP = nullptr;
1492  if (FoldOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1493  return I;
1494 
1495  FoldOpInit *I = new (Allocator) FoldOpInit(Start, List, A, B, Expr, Type);
1496  ThePool.InsertNode(I, IP);
1497  return I;
1498 }
1499 
1501  ProfileFoldOpInit(ID, Start, List, A, B, Expr, getType());
1502 }
1503 
1504 Init *FoldOpInit::Fold(Record *CurRec) const {
1505  if (ListInit *LI = dyn_cast<ListInit>(List)) {
1506  Init *Accum = Start;
1507  for (Init *Elt : *LI) {
1508  MapResolver R(CurRec);
1509  R.set(A, Accum);
1510  R.set(B, Elt);
1511  Accum = Expr->resolveReferences(R);
1512  }
1513  return Accum;
1514  }
1515  return const_cast<FoldOpInit *>(this);
1516 }
1517 
1519  Init *NewStart = Start->resolveReferences(R);
1520  Init *NewList = List->resolveReferences(R);
1521  ShadowResolver SR(R);
1522  SR.addShadow(A);
1523  SR.addShadow(B);
1524  Init *NewExpr = Expr->resolveReferences(SR);
1525 
1526  if (Start == NewStart && List == NewList && Expr == NewExpr)
1527  return const_cast<FoldOpInit *>(this);
1528 
1529  return get(NewStart, NewList, A, B, NewExpr, getType())
1530  ->Fold(R.getCurrentRecord());
1531 }
1532 
1533 Init *FoldOpInit::getBit(unsigned Bit) const {
1534  return VarBitInit::get(const_cast<FoldOpInit *>(this), Bit);
1535 }
1536 
1537 std::string FoldOpInit::getAsString() const {
1538  return (Twine("!foldl(") + Start->getAsString() + ", " + List->getAsString() +
1539  ", " + A->getAsUnquotedString() + ", " + B->getAsUnquotedString() +
1540  ", " + Expr->getAsString() + ")")
1541  .str();
1542 }
1543 
1545  Init *Expr) {
1546  ID.AddPointer(CheckType);
1547  ID.AddPointer(Expr);
1548 }
1549 
1551  static FoldingSet<IsAOpInit> ThePool;
1552 
1554  ProfileIsAOpInit(ID, CheckType, Expr);
1555 
1556  void *IP = nullptr;
1557  if (IsAOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1558  return I;
1559 
1560  IsAOpInit *I = new (Allocator) IsAOpInit(CheckType, Expr);
1561  ThePool.InsertNode(I, IP);
1562  return I;
1563 }
1564 
1566  ProfileIsAOpInit(ID, CheckType, Expr);
1567 }
1568 
1570  if (TypedInit *TI = dyn_cast<TypedInit>(Expr)) {
1571  // Is the expression type known to be (a subclass of) the desired type?
1572  if (TI->getType()->typeIsConvertibleTo(CheckType))
1573  return IntInit::get(1);
1574 
1575  if (isa<RecordRecTy>(CheckType)) {
1576  // If the target type is not a subclass of the expression type, or if
1577  // the expression has fully resolved to a record, we know that it can't
1578  // be of the required type.
1579  if (!CheckType->typeIsConvertibleTo(TI->getType()) || isa<DefInit>(Expr))
1580  return IntInit::get(0);
1581  } else {
1582  // We treat non-record types as not castable.
1583  return IntInit::get(0);
1584  }
1585  }
1586  return const_cast<IsAOpInit *>(this);
1587 }
1588 
1590  Init *NewExpr = Expr->resolveReferences(R);
1591  if (Expr != NewExpr)
1592  return get(CheckType, NewExpr)->Fold();
1593  return const_cast<IsAOpInit *>(this);
1594 }
1595 
1596 Init *IsAOpInit::getBit(unsigned Bit) const {
1597  return VarBitInit::get(const_cast<IsAOpInit *>(this), Bit);
1598 }
1599 
1600 std::string IsAOpInit::getAsString() const {
1601  return (Twine("!isa<") + CheckType->getAsString() + ">(" +
1602  Expr->getAsString() + ")")
1603  .str();
1604 }
1605 
1607  if (RecordRecTy *RecordType = dyn_cast<RecordRecTy>(getType())) {
1608  for (Record *Rec : RecordType->getClasses()) {
1609  if (RecordVal *Field = Rec->getValue(FieldName))
1610  return Field->getType();
1611  }
1612  }
1613  return nullptr;
1614 }
1615 
1616 Init *
1618  if (getType() == Ty || getType()->typeIsA(Ty))
1619  return const_cast<TypedInit *>(this);
1620 
1621  if (isa<BitRecTy>(getType()) && isa<BitsRecTy>(Ty) &&
1622  cast<BitsRecTy>(Ty)->getNumBits() == 1)
1623  return BitsInit::get({const_cast<TypedInit *>(this)});
1624 
1625  return nullptr;
1626 }
1627 
1629  BitsRecTy *T = dyn_cast<BitsRecTy>(getType());
1630  if (!T) return nullptr; // Cannot subscript a non-bits variable.
1631  unsigned NumBits = T->getNumBits();
1632 
1633  SmallVector<Init *, 16> NewBits;
1634  NewBits.reserve(Bits.size());
1635  for (unsigned Bit : Bits) {
1636  if (Bit >= NumBits)
1637  return nullptr;
1638 
1639  NewBits.push_back(VarBitInit::get(const_cast<TypedInit *>(this), Bit));
1640  }
1641  return BitsInit::get(NewBits);
1642 }
1643 
1645  // Handle the common case quickly
1646  if (getType() == Ty || getType()->typeIsA(Ty))
1647  return const_cast<TypedInit *>(this);
1648 
1649  if (Init *Converted = convertInitializerTo(Ty)) {
1650  assert(!isa<TypedInit>(Converted) ||
1651  cast<TypedInit>(Converted)->getType()->typeIsA(Ty));
1652  return Converted;
1653  }
1654 
1655  if (!getType()->typeIsConvertibleTo(Ty))
1656  return nullptr;
1657 
1658  return UnOpInit::get(UnOpInit::CAST, const_cast<TypedInit *>(this), Ty)
1659  ->Fold(nullptr);
1660 }
1661 
1663  ListRecTy *T = dyn_cast<ListRecTy>(getType());
1664  if (!T) return nullptr; // Cannot subscript a non-list variable.
1665 
1666  if (Elements.size() == 1)
1667  return VarListElementInit::get(const_cast<TypedInit *>(this), Elements[0]);
1668 
1669  SmallVector<Init*, 8> ListInits;
1670  ListInits.reserve(Elements.size());
1671  for (unsigned Element : Elements)
1672  ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
1673  Element));
1674  return ListInit::get(ListInits, T->getElementType());
1675 }
1676 
1677 
1679  Init *Value = StringInit::get(VN);
1680  return VarInit::get(Value, T);
1681 }
1682 
1684  using Key = std::pair<RecTy *, Init *>;
1685  static DenseMap<Key, VarInit*> ThePool;
1686 
1687  Key TheKey(std::make_pair(T, VN));
1688 
1689  VarInit *&I = ThePool[TheKey];
1690  if (!I)
1691  I = new(Allocator) VarInit(VN, T);
1692  return I;
1693 }
1694 
1696  StringInit *NameString = cast<StringInit>(getNameInit());
1697  return NameString->getValue();
1698 }
1699 
1700 Init *VarInit::getBit(unsigned Bit) const {
1701  if (getType() == BitRecTy::get())
1702  return const_cast<VarInit*>(this);
1703  return VarBitInit::get(const_cast<VarInit*>(this), Bit);
1704 }
1705 
1707  if (Init *Val = R.resolve(VarName))
1708  return Val;
1709  return const_cast<VarInit *>(this);
1710 }
1711 
1713  using Key = std::pair<TypedInit *, unsigned>;
1714  static DenseMap<Key, VarBitInit*> ThePool;
1715 
1716  Key TheKey(std::make_pair(T, B));
1717 
1718  VarBitInit *&I = ThePool[TheKey];
1719  if (!I)
1720  I = new(Allocator) VarBitInit(T, B);
1721  return I;
1722 }
1723 
1724 std::string VarBitInit::getAsString() const {
1725  return TI->getAsString() + "{" + utostr(Bit) + "}";
1726 }
1727 
1729  Init *I = TI->resolveReferences(R);
1730  if (TI != I)
1731  return I->getBit(getBitNum());
1732 
1733  return const_cast<VarBitInit*>(this);
1734 }
1735 
1737  unsigned E) {
1738  using Key = std::pair<TypedInit *, unsigned>;
1739  static DenseMap<Key, VarListElementInit*> ThePool;
1740 
1741  Key TheKey(std::make_pair(T, E));
1742 
1743  VarListElementInit *&I = ThePool[TheKey];
1744  if (!I) I = new(Allocator) VarListElementInit(T, E);
1745  return I;
1746 }
1747 
1748 std::string VarListElementInit::getAsString() const {
1749  return TI->getAsString() + "[" + utostr(Element) + "]";
1750 }
1751 
1753  Init *NewTI = TI->resolveReferences(R);
1754  if (ListInit *List = dyn_cast<ListInit>(NewTI)) {
1755  // Leave out-of-bounds array references as-is. This can happen without
1756  // being an error, e.g. in the untaken "branch" of an !if expression.
1757  if (getElementNum() < List->size())
1758  return List->getElement(getElementNum());
1759  }
1760  if (NewTI != TI && isa<TypedInit>(NewTI))
1761  return VarListElementInit::get(cast<TypedInit>(NewTI), getElementNum());
1762  return const_cast<VarListElementInit *>(this);
1763 }
1764 
1766  if (getType() == BitRecTy::get())
1767  return const_cast<VarListElementInit*>(this);
1768  return VarBitInit::get(const_cast<VarListElementInit*>(this), Bit);
1769 }
1770 
1771 DefInit::DefInit(Record *D)
1772  : TypedInit(IK_DefInit, D->getType()), Def(D) {}
1773 
1775  return R->getDefInit();
1776 }
1777 
1779  if (auto *RRT = dyn_cast<RecordRecTy>(Ty))
1780  if (getType()->typeIsConvertibleTo(RRT))
1781  return const_cast<DefInit *>(this);
1782  return nullptr;
1783 }
1784 
1786  if (const RecordVal *RV = Def->getValue(FieldName))
1787  return RV->getType();
1788  return nullptr;
1789 }
1790 
1791 std::string DefInit::getAsString() const { return std::string(Def->getName()); }
1792 
1794  Record *Class,
1796  ID.AddInteger(Args.size());
1797  ID.AddPointer(Class);
1798 
1799  for (Init *I : Args)
1800  ID.AddPointer(I);
1801 }
1802 
1804  static FoldingSet<VarDefInit> ThePool;
1805 
1807  ProfileVarDefInit(ID, Class, Args);
1808 
1809  void *IP = nullptr;
1810  if (VarDefInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
1811  return I;
1812 
1813  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Args.size()),
1814  alignof(VarDefInit));
1815  VarDefInit *I = new(Mem) VarDefInit(Class, Args.size());
1816  std::uninitialized_copy(Args.begin(), Args.end(),
1817  I->getTrailingObjects<Init *>());
1818  ThePool.InsertNode(I, IP);
1819  return I;
1820 }
1821 
1823  ProfileVarDefInit(ID, Class, args());
1824 }
1825 
1826 DefInit *VarDefInit::instantiate() {
1827  if (!Def) {
1828  RecordKeeper &Records = Class->getRecords();
1829  auto NewRecOwner = std::make_unique<Record>(Records.getNewAnonymousName(),
1830  Class->getLoc(), Records,
1831  /*IsAnonymous=*/true);
1832  Record *NewRec = NewRecOwner.get();
1833 
1834  // Copy values from class to instance
1835  for (const RecordVal &Val : Class->getValues())
1836  NewRec->addValue(Val);
1837 
1838  // Copy assertions from class to instance.
1839  NewRec->appendAssertions(Class);
1840 
1841  // Substitute and resolve template arguments
1842  ArrayRef<Init *> TArgs = Class->getTemplateArgs();
1843  MapResolver R(NewRec);
1844 
1845  for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1846  if (i < args_size())
1847  R.set(TArgs[i], getArg(i));
1848  else
1849  R.set(TArgs[i], NewRec->getValue(TArgs[i])->getValue());
1850 
1851  NewRec->removeValue(TArgs[i]);
1852  }
1853 
1854  NewRec->resolveReferences(R);
1855 
1856  // Add superclasses.
1858  for (const auto &SCPair : SCs)
1859  NewRec->addSuperClass(SCPair.first, SCPair.second);
1860 
1861  NewRec->addSuperClass(Class,
1862  SMRange(Class->getLoc().back(),
1863  Class->getLoc().back()));
1864 
1865  // Resolve internal references and store in record keeper
1866  NewRec->resolveReferences();
1867  Records.addDef(std::move(NewRecOwner));
1868 
1869  // Check the assertions.
1870  NewRec->checkRecordAssertions();
1871 
1872  Def = DefInit::get(NewRec);
1873  }
1874 
1875  return Def;
1876 }
1877 
1879  TrackUnresolvedResolver UR(&R);
1880  bool Changed = false;
1881  SmallVector<Init *, 8> NewArgs;
1882  NewArgs.reserve(args_size());
1883 
1884  for (Init *Arg : args()) {
1885  Init *NewArg = Arg->resolveReferences(UR);
1886  NewArgs.push_back(NewArg);
1887  Changed |= NewArg != Arg;
1888  }
1889 
1890  if (Changed) {
1891  auto New = VarDefInit::get(Class, NewArgs);
1892  if (!UR.foundUnresolved())
1893  return New->instantiate();
1894  return New;
1895  }
1896  return const_cast<VarDefInit *>(this);
1897 }
1898 
1900  if (Def)
1901  return Def;
1902 
1904  for (Init *Arg : args())
1905  Arg->resolveReferences(R);
1906 
1907  if (!R.foundUnresolved())
1908  return const_cast<VarDefInit *>(this)->instantiate();
1909  return const_cast<VarDefInit *>(this);
1910 }
1911 
1912 std::string VarDefInit::getAsString() const {
1913  std::string Result = Class->getNameInitAsString() + "<";
1914  const char *sep = "";
1915  for (Init *Arg : args()) {
1916  Result += sep;
1917  sep = ", ";
1918  Result += Arg->getAsString();
1919  }
1920  return Result + ">";
1921 }
1922 
1924  using Key = std::pair<Init *, StringInit *>;
1925  static DenseMap<Key, FieldInit*> ThePool;
1926 
1927  Key TheKey(std::make_pair(R, FN));
1928 
1929  FieldInit *&I = ThePool[TheKey];
1930  if (!I) I = new(Allocator) FieldInit(R, FN);
1931  return I;
1932 }
1933 
1934 Init *FieldInit::getBit(unsigned Bit) const {
1935  if (getType() == BitRecTy::get())
1936  return const_cast<FieldInit*>(this);
1937  return VarBitInit::get(const_cast<FieldInit*>(this), Bit);
1938 }
1939 
1941  Init *NewRec = Rec->resolveReferences(R);
1942  if (NewRec != Rec)
1943  return FieldInit::get(NewRec, FieldName)->Fold(R.getCurrentRecord());
1944  return const_cast<FieldInit *>(this);
1945 }
1946 
1947 Init *FieldInit::Fold(Record *CurRec) const {
1948  if (DefInit *DI = dyn_cast<DefInit>(Rec)) {
1949  Record *Def = DI->getDef();
1950  if (Def == CurRec)
1951  PrintFatalError(CurRec->getLoc(),
1952  Twine("Attempting to access field '") +
1953  FieldName->getAsUnquotedString() + "' of '" +
1954  Rec->getAsString() + "' is a forbidden self-reference");
1955  Init *FieldVal = Def->getValue(FieldName)->getValue();
1956  if (FieldVal->isConcrete())
1957  return FieldVal;
1958  }
1959  return const_cast<FieldInit *>(this);
1960 }
1961 
1963  if (DefInit *DI = dyn_cast<DefInit>(Rec)) {
1964  Init *FieldVal = DI->getDef()->getValue(FieldName)->getValue();
1965  return FieldVal->isConcrete();
1966  }
1967  return false;
1968 }
1969 
1971  ArrayRef<Init *> CondRange,
1972  ArrayRef<Init *> ValRange,
1973  const RecTy *ValType) {
1974  assert(CondRange.size() == ValRange.size() &&
1975  "Number of conditions and values must match!");
1976  ID.AddPointer(ValType);
1977  ArrayRef<Init *>::iterator Case = CondRange.begin();
1978  ArrayRef<Init *>::iterator Val = ValRange.begin();
1979 
1980  while (Case != CondRange.end()) {
1981  ID.AddPointer(*Case++);
1982  ID.AddPointer(*Val++);
1983  }
1984 }
1985 
1988  makeArrayRef(getTrailingObjects<Init *>(), NumConds),
1989  makeArrayRef(getTrailingObjects<Init *>() + NumConds, NumConds),
1990  ValType);
1991 }
1992 
1993 CondOpInit *
1995  ArrayRef<Init *> ValRange, RecTy *Ty) {
1996  assert(CondRange.size() == ValRange.size() &&
1997  "Number of conditions and values must match!");
1998 
1999  static FoldingSet<CondOpInit> ThePool;
2001  ProfileCondOpInit(ID, CondRange, ValRange, Ty);
2002 
2003  void *IP = nullptr;
2004  if (CondOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
2005  return I;
2006 
2007  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(2*CondRange.size()),
2008  alignof(BitsInit));
2009  CondOpInit *I = new(Mem) CondOpInit(CondRange.size(), Ty);
2010 
2011  std::uninitialized_copy(CondRange.begin(), CondRange.end(),
2012  I->getTrailingObjects<Init *>());
2013  std::uninitialized_copy(ValRange.begin(), ValRange.end(),
2014  I->getTrailingObjects<Init *>()+CondRange.size());
2015  ThePool.InsertNode(I, IP);
2016  return I;
2017 }
2018 
2020  SmallVector<Init*, 4> NewConds;
2021  bool Changed = false;
2022  for (const Init *Case : getConds()) {
2023  Init *NewCase = Case->resolveReferences(R);
2024  NewConds.push_back(NewCase);
2025  Changed |= NewCase != Case;
2026  }
2027 
2028  SmallVector<Init*, 4> NewVals;
2029  for (const Init *Val : getVals()) {
2030  Init *NewVal = Val->resolveReferences(R);
2031  NewVals.push_back(NewVal);
2032  Changed |= NewVal != Val;
2033  }
2034 
2035  if (Changed)
2036  return (CondOpInit::get(NewConds, NewVals,
2037  getValType()))->Fold(R.getCurrentRecord());
2038 
2039  return const_cast<CondOpInit *>(this);
2040 }
2041 
2042 Init *CondOpInit::Fold(Record *CurRec) const {
2043  for ( unsigned i = 0; i < NumConds; ++i) {
2044  Init *Cond = getCond(i);
2045  Init *Val = getVal(i);
2046 
2047  if (IntInit *CondI = dyn_cast_or_null<IntInit>(
2048  Cond->convertInitializerTo(IntRecTy::get()))) {
2049  if (CondI->getValue())
2050  return Val->convertInitializerTo(getValType());
2051  } else
2052  return const_cast<CondOpInit *>(this);
2053  }
2054 
2055  PrintFatalError(CurRec->getLoc(),
2056  CurRec->getName() +
2057  " does not have any true condition in:" +
2058  this->getAsString());
2059  return nullptr;
2060 }
2061 
2063  for (const Init *Case : getConds())
2064  if (!Case->isConcrete())
2065  return false;
2066 
2067  for (const Init *Val : getVals())
2068  if (!Val->isConcrete())
2069  return false;
2070 
2071  return true;
2072 }
2073 
2075  for (const Init *Case : getConds())
2076  if (!Case->isComplete())
2077  return false;
2078 
2079  for (const Init *Val : getVals())
2080  if (!Val->isConcrete())
2081  return false;
2082 
2083  return true;
2084 }
2085 
2086 std::string CondOpInit::getAsString() const {
2087  std::string Result = "!cond(";
2088  for (unsigned i = 0; i < getNumConds(); i++) {
2089  Result += getCond(i)->getAsString() + ": ";
2090  Result += getVal(i)->getAsString();
2091  if (i != getNumConds()-1)
2092  Result += ", ";
2093  }
2094  return Result + ")";
2095 }
2096 
2097 Init *CondOpInit::getBit(unsigned Bit) const {
2098  return VarBitInit::get(const_cast<CondOpInit *>(this), Bit);
2099 }
2100 
2102  ArrayRef<Init *> ArgRange,
2103  ArrayRef<StringInit *> NameRange) {
2104  ID.AddPointer(V);
2105  ID.AddPointer(VN);
2106 
2107  ArrayRef<Init *>::iterator Arg = ArgRange.begin();
2109  while (Arg != ArgRange.end()) {
2110  assert(Name != NameRange.end() && "Arg name underflow!");
2111  ID.AddPointer(*Arg++);
2112  ID.AddPointer(*Name++);
2113  }
2114  assert(Name == NameRange.end() && "Arg name overflow!");
2115 }
2116 
2117 DagInit *
2119  ArrayRef<StringInit *> NameRange) {
2120  static FoldingSet<DagInit> ThePool;
2121 
2123  ProfileDagInit(ID, V, VN, ArgRange, NameRange);
2124 
2125  void *IP = nullptr;
2126  if (DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
2127  return I;
2128 
2129  void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *, StringInit *>(ArgRange.size(), NameRange.size()), alignof(BitsInit));
2130  DagInit *I = new(Mem) DagInit(V, VN, ArgRange.size(), NameRange.size());
2131  std::uninitialized_copy(ArgRange.begin(), ArgRange.end(),
2132  I->getTrailingObjects<Init *>());
2133  std::uninitialized_copy(NameRange.begin(), NameRange.end(),
2134  I->getTrailingObjects<StringInit *>());
2135  ThePool.InsertNode(I, IP);
2136  return I;
2137 }
2138 
2139 DagInit *
2141  ArrayRef<std::pair<Init*, StringInit*>> args) {
2144 
2145  for (const auto &Arg : args) {
2146  Args.push_back(Arg.first);
2147  Names.push_back(Arg.second);
2148  }
2149 
2150  return DagInit::get(V, VN, Args, Names);
2151 }
2152 
2154  ProfileDagInit(ID, Val, ValName, makeArrayRef(getTrailingObjects<Init *>(), NumArgs), makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames));
2155 }
2156 
2158  if (DefInit *DefI = dyn_cast<DefInit>(Val))
2159  return DefI->getDef();
2160  PrintFatalError(Loc, "Expected record as operator");
2161  return nullptr;
2162 }
2163 
2165  SmallVector<Init*, 8> NewArgs;
2166  NewArgs.reserve(arg_size());
2167  bool ArgsChanged = false;
2168  for (const Init *Arg : getArgs()) {
2169  Init *NewArg = Arg->resolveReferences(R);
2170  NewArgs.push_back(NewArg);
2171  ArgsChanged |= NewArg != Arg;
2172  }
2173 
2174  Init *Op = Val->resolveReferences(R);
2175  if (Op != Val || ArgsChanged)
2176  return DagInit::get(Op, ValName, NewArgs, getArgNames());
2177 
2178  return const_cast<DagInit *>(this);
2179 }
2180 
2181 bool DagInit::isConcrete() const {
2182  if (!Val->isConcrete())
2183  return false;
2184  for (const Init *Elt : getArgs()) {
2185  if (!Elt->isConcrete())
2186  return false;
2187  }
2188  return true;
2189 }
2190 
2191 std::string DagInit::getAsString() const {
2192  std::string Result = "(" + Val->getAsString();
2193  if (ValName)
2194  Result += ":" + ValName->getAsUnquotedString();
2195  if (!arg_empty()) {
2196  Result += " " + getArg(0)->getAsString();
2197  if (getArgName(0)) Result += ":$" + getArgName(0)->getAsUnquotedString();
2198  for (unsigned i = 1, e = getNumArgs(); i != e; ++i) {
2199  Result += ", " + getArg(i)->getAsString();
2200  if (getArgName(i)) Result += ":$" + getArgName(i)->getAsUnquotedString();
2201  }
2202  }
2203  return Result + ")";
2204 }
2205 
2206 //===----------------------------------------------------------------------===//
2207 // Other implementations
2208 //===----------------------------------------------------------------------===//
2209 
2211  : Name(N), TyAndKind(T, K) {
2213  assert(Value && "Cannot create unset value for current type!");
2214 }
2215 
2216 // This constructor accepts the same arguments as the above, but also
2217 // a source location.
2219  : Name(N), Loc(Loc), TyAndKind(T, K) {
2221  assert(Value && "Cannot create unset value for current type!");
2222 }
2223 
2225  return cast<StringInit>(getNameInit())->getValue();
2226 }
2227 
2228 std::string RecordVal::getPrintType() const {
2229  if (getType() == StringRecTy::get()) {
2230  if (auto *StrInit = dyn_cast<StringInit>(Value)) {
2231  if (StrInit->hasCodeFormat())
2232  return "code";
2233  else
2234  return "string";
2235  } else {
2236  return "string";
2237  }
2238  } else {
2239  return TyAndKind.getPointer()->getAsString();
2240  }
2241 }
2242 
2244  if (V) {
2245  Value = V->getCastTo(getType());
2246  if (Value) {
2247  assert(!isa<TypedInit>(Value) ||
2248  cast<TypedInit>(Value)->getType()->typeIsA(getType()));
2249  if (BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
2250  if (!isa<BitsInit>(Value)) {
2252  Bits.reserve(BTy->getNumBits());
2253  for (unsigned I = 0, E = BTy->getNumBits(); I < E; ++I)
2254  Bits.push_back(Value->getBit(I));
2256  }
2257  }
2258  }
2259  return Value == nullptr;
2260  }
2261  Value = nullptr;
2262  return false;
2263 }
2264 
2265 // This version of setValue takes a source location and resets the
2266 // location in the RecordVal.
2267 bool RecordVal::setValue(Init *V, SMLoc NewLoc) {
2268  Loc = NewLoc;
2269  if (V) {
2270  Value = V->getCastTo(getType());
2271  if (Value) {
2272  assert(!isa<TypedInit>(Value) ||
2273  cast<TypedInit>(Value)->getType()->typeIsA(getType()));
2274  if (BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
2275  if (!isa<BitsInit>(Value)) {
2277  Bits.reserve(BTy->getNumBits());
2278  for (unsigned I = 0, E = BTy->getNumBits(); I < E; ++I)
2279  Bits.push_back(Value->getBit(I));
2281  }
2282  }
2283  }
2284  return Value == nullptr;
2285  }
2286  Value = nullptr;
2287  return false;
2288 }
2289 
2290 #include "llvm/TableGen/Record.h"
2291 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2292 LLVM_DUMP_METHOD void RecordVal::dump() const { errs() << *this; }
2293 #endif
2294 
2295 void RecordVal::print(raw_ostream &OS, bool PrintSem) const {
2296  if (isNonconcreteOK()) OS << "field ";
2297  OS << getPrintType() << " " << getNameInitAsString();
2298 
2299  if (getValue())
2300  OS << " = " << *getValue();
2301 
2302  if (PrintSem) OS << ";\n";
2303 }
2304 
2305 unsigned Record::LastID = 0;
2306 
2307 void Record::checkName() {
2308  // Ensure the record name has string type.
2309  const TypedInit *TypedName = cast<const TypedInit>(Name);
2310  if (!isa<StringRecTy>(TypedName->getType()))
2311  PrintFatalError(getLoc(), Twine("Record name '") + Name->getAsString() +
2312  "' is not a string!");
2313 }
2314 
2316  SmallVector<Record *, 4> DirectSCs;
2317  getDirectSuperClasses(DirectSCs);
2318  return RecordRecTy::get(DirectSCs);
2319 }
2320 
2322  if (!CorrespondingDefInit)
2323  CorrespondingDefInit = new (Allocator) DefInit(this);
2324  return CorrespondingDefInit;
2325 }
2326 
2327 void Record::setName(Init *NewName) {
2328  Name = NewName;
2329  checkName();
2330  // DO NOT resolve record values to the name at this point because
2331  // there might be default values for arguments of this def. Those
2332  // arguments might not have been resolved yet so we don't want to
2333  // prematurely assume values for those arguments were not passed to
2334  // this def.
2335  //
2336  // Nonetheless, it may be that some of this Record's values
2337  // reference the record name. Indeed, the reason for having the
2338  // record name be an Init is to provide this flexibility. The extra
2339  // resolve steps after completely instantiating defs takes care of
2340  // this. See TGParser::ParseDef and TGParser::ParseDefm.
2341 }
2342 
2343 // NOTE for the next two functions:
2344 // Superclasses are in post-order, so the final one is a direct
2345 // superclass. All of its transitive superclases immediately precede it,
2346 // so we can step through the direct superclasses in reverse order.
2347 
2348 bool Record::hasDirectSuperClass(const Record *Superclass) const {
2350 
2351  for (int I = SCs.size() - 1; I >= 0; --I) {
2352  const Record *SC = SCs[I].first;
2353  if (SC == Superclass)
2354  return true;
2355  I -= SC->getSuperClasses().size();
2356  }
2357 
2358  return false;
2359 }
2360 
2363 
2364  while (!SCs.empty()) {
2365  Record *SC = SCs.back().first;
2366  SCs = SCs.drop_back(1 + SC->getSuperClasses().size());
2367  Classes.push_back(SC);
2368  }
2369 }
2370 
2372  Init *OldName = getNameInit();
2373  Init *NewName = Name->resolveReferences(R);
2374  if (NewName != OldName) {
2375  // Re-register with RecordKeeper.
2376  setName(NewName);
2377  }
2378 
2379  // Resolve the field values.
2380  for (RecordVal &Value : Values) {
2381  if (SkipVal == &Value) // Skip resolve the same field as the given one
2382  continue;
2383  if (Init *V = Value.getValue()) {
2384  Init *VR = V->resolveReferences(R);
2385  if (Value.setValue(VR)) {
2386  std::string Type;
2387  if (TypedInit *VRT = dyn_cast<TypedInit>(VR))
2388  Type =
2389  (Twine("of type '") + VRT->getType()->getAsString() + "' ").str();
2391  getLoc(),
2392  Twine("Invalid value ") + Type + "found when setting field '" +
2393  Value.getNameInitAsString() + "' of type '" +
2394  Value.getType()->getAsString() +
2395  "' after resolving references: " + VR->getAsUnquotedString() +
2396  "\n");
2397  }
2398  }
2399  }
2400 
2401  // Resolve the assertion expressions.
2402  for (auto &Assertion : Assertions) {
2403  Init *Value = Assertion.Condition->resolveReferences(R);
2404  Assertion.Condition = Value;
2405  Value = Assertion.Message->resolveReferences(R);
2406  Assertion.Message = Value;
2407  }
2408 }
2409 
2411  RecordResolver R(*this);
2412  R.setName(NewName);
2413  R.setFinal(true);
2414  resolveReferences(R);
2415 }
2416 
2417 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2418 LLVM_DUMP_METHOD void Record::dump() const { errs() << *this; }
2419 #endif
2420 
2422  OS << R.getNameInitAsString();
2423 
2424  ArrayRef<Init *> TArgs = R.getTemplateArgs();
2425  if (!TArgs.empty()) {
2426  OS << "<";
2427  bool NeedComma = false;
2428  for (const Init *TA : TArgs) {
2429  if (NeedComma) OS << ", ";
2430  NeedComma = true;
2431  const RecordVal *RV = R.getValue(TA);
2432  assert(RV && "Template argument record not found??");
2433  RV->print(OS, false);
2434  }
2435  OS << ">";
2436  }
2437 
2438  OS << " {";
2439  ArrayRef<std::pair<Record *, SMRange>> SC = R.getSuperClasses();
2440  if (!SC.empty()) {
2441  OS << "\t//";
2442  for (const auto &SuperPair : SC)
2443  OS << " " << SuperPair.first->getNameInitAsString();
2444  }
2445  OS << "\n";
2446 
2447  for (const RecordVal &Val : R.getValues())
2448  if (Val.isNonconcreteOK() && !R.isTemplateArg(Val.getNameInit()))
2449  OS << Val;
2450  for (const RecordVal &Val : R.getValues())
2451  if (!Val.isNonconcreteOK() && !R.isTemplateArg(Val.getNameInit()))
2452  OS << Val;
2453 
2454  return OS << "}\n";
2455 }
2456 
2458  const RecordVal *R = getValue(FieldName);
2459  if (!R)
2460  PrintFatalError(getLoc(), "Record `" + getName() +
2461  "' does not have a field named `" + FieldName + "'!\n");
2462  return R->getLoc();
2463 }
2464 
2466  const RecordVal *R = getValue(FieldName);
2467  if (!R || !R->getValue())
2468  PrintFatalError(getLoc(), "Record `" + getName() +
2469  "' does not have a field named `" + FieldName + "'!\n");
2470  return R->getValue();
2471 }
2472 
2475  if (!S.hasValue())
2476  PrintFatalError(getLoc(), "Record `" + getName() +
2477  "' does not have a field named `" + FieldName + "'!\n");
2478  return S.getValue();
2479 }
2480 
2483  const RecordVal *R = getValue(FieldName);
2484  if (!R || !R->getValue())
2485  return llvm::Optional<StringRef>();
2486  if (isa<UnsetInit>(R->getValue()))
2487  return llvm::Optional<StringRef>();
2488 
2489  if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
2490  return SI->getValue();
2491 
2493  "Record `" + getName() + "', ` field `" + FieldName +
2494  "' exists but does not have a string initializer!");
2495 }
2496 
2498  const RecordVal *R = getValue(FieldName);
2499  if (!R || !R->getValue())
2500  PrintFatalError(getLoc(), "Record `" + getName() +
2501  "' does not have a field named `" + FieldName + "'!\n");
2502 
2503  if (BitsInit *BI = dyn_cast<BitsInit>(R->getValue()))
2504  return BI;
2505  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName +
2506  "' exists but does not have a bits value");
2507 }
2508 
2510  const RecordVal *R = getValue(FieldName);
2511  if (!R || !R->getValue())
2512  PrintFatalError(getLoc(), "Record `" + getName() +
2513  "' does not have a field named `" + FieldName + "'!\n");
2514 
2515  if (ListInit *LI = dyn_cast<ListInit>(R->getValue()))
2516  return LI;
2517  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName +
2518  "' exists but does not have a list value");
2519 }
2520 
2521 std::vector<Record*>
2523  ListInit *List = getValueAsListInit(FieldName);
2524  std::vector<Record*> Defs;
2525  for (Init *I : List->getValues()) {
2526  if (DefInit *DI = dyn_cast<DefInit>(I))
2527  Defs.push_back(DI->getDef());
2528  else
2529  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2530  FieldName + "' list is not entirely DefInit!");
2531  }
2532  return Defs;
2533 }
2534 
2535 int64_t Record::getValueAsInt(StringRef FieldName) const {
2536  const RecordVal *R = getValue(FieldName);
2537  if (!R || !R->getValue())
2538  PrintFatalError(getLoc(), "Record `" + getName() +
2539  "' does not have a field named `" + FieldName + "'!\n");
2540 
2541  if (IntInit *II = dyn_cast<IntInit>(R->getValue()))
2542  return II->getValue();
2543  PrintFatalError(getLoc(), Twine("Record `") + getName() + "', field `" +
2544  FieldName +
2545  "' exists but does not have an int value: " +
2546  R->getValue()->getAsString());
2547 }
2548 
2549 std::vector<int64_t>
2551  ListInit *List = getValueAsListInit(FieldName);
2552  std::vector<int64_t> Ints;
2553  for (Init *I : List->getValues()) {
2554  if (IntInit *II = dyn_cast<IntInit>(I))
2555  Ints.push_back(II->getValue());
2556  else
2558  Twine("Record `") + getName() + "', field `" + FieldName +
2559  "' exists but does not have a list of ints value: " +
2560  I->getAsString());
2561  }
2562  return Ints;
2563 }
2564 
2565 std::vector<StringRef>
2567  ListInit *List = getValueAsListInit(FieldName);
2568  std::vector<StringRef> Strings;
2569  for (Init *I : List->getValues()) {
2570  if (StringInit *SI = dyn_cast<StringInit>(I))
2571  Strings.push_back(SI->getValue());
2572  else
2574  Twine("Record `") + getName() + "', field `" + FieldName +
2575  "' exists but does not have a list of strings value: " +
2576  I->getAsString());
2577  }
2578  return Strings;
2579 }
2580 
2582  const RecordVal *R = getValue(FieldName);
2583  if (!R || !R->getValue())
2584  PrintFatalError(getLoc(), "Record `" + getName() +
2585  "' does not have a field named `" + FieldName + "'!\n");
2586 
2587  if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
2588  return DI->getDef();
2589  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2590  FieldName + "' does not have a def initializer!");
2591 }
2592 
2594  const RecordVal *R = getValue(FieldName);
2595  if (!R || !R->getValue())
2596  PrintFatalError(getLoc(), "Record `" + getName() +
2597  "' does not have a field named `" + FieldName + "'!\n");
2598 
2599  if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
2600  return DI->getDef();
2601  if (isa<UnsetInit>(R->getValue()))
2602  return nullptr;
2603  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2604  FieldName + "' does not have either a def initializer or '?'!");
2605 }
2606 
2607 
2608 bool Record::getValueAsBit(StringRef FieldName) const {
2609  const RecordVal *R = getValue(FieldName);
2610  if (!R || !R->getValue())
2611  PrintFatalError(getLoc(), "Record `" + getName() +
2612  "' does not have a field named `" + FieldName + "'!\n");
2613 
2614  if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
2615  return BI->getValue();
2616  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2617  FieldName + "' does not have a bit initializer!");
2618 }
2619 
2620 bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
2621  const RecordVal *R = getValue(FieldName);
2622  if (!R || !R->getValue())
2623  PrintFatalError(getLoc(), "Record `" + getName() +
2624  "' does not have a field named `" + FieldName.str() + "'!\n");
2625 
2626  if (isa<UnsetInit>(R->getValue())) {
2627  Unset = true;
2628  return false;
2629  }
2630  Unset = false;
2631  if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
2632  return BI->getValue();
2633  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2634  FieldName + "' does not have a bit initializer!");
2635 }
2636 
2638  const RecordVal *R = getValue(FieldName);
2639  if (!R || !R->getValue())
2640  PrintFatalError(getLoc(), "Record `" + getName() +
2641  "' does not have a field named `" + FieldName + "'!\n");
2642 
2643  if (DagInit *DI = dyn_cast<DagInit>(R->getValue()))
2644  return DI;
2645  PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
2646  FieldName + "' does not have a dag initializer!");
2647 }
2648 
2649 // Check all record assertions: For each one, resolve the condition
2650 // and message, then call CheckAssert().
2651 // Note: The condition and message are probably already resolved,
2652 // but resolving again allows calls before records are resolved.
2654  RecordResolver R(*this);
2655  R.setFinal(true);
2656 
2657  for (auto Assertion : getAssertions()) {
2658  Init *Condition = Assertion.Condition->resolveReferences(R);
2659  Init *Message = Assertion.Message->resolveReferences(R);
2660  CheckAssert(Assertion.Loc, Condition, Message);
2661  }
2662 }
2663 
2664 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2665 LLVM_DUMP_METHOD void RecordKeeper::dump() const { errs() << *this; }
2666 #endif
2667 
2669  OS << "------------- Classes -----------------\n";
2670  for (const auto &C : RK.getClasses())
2671  OS << "class " << *C.second;
2672 
2673  OS << "------------- Defs -----------------\n";
2674  for (const auto &D : RK.getDefs())
2675  OS << "def " << *D.second;
2676  return OS;
2677 }
2678 
2679 /// GetNewAnonymousName - Generate a unique anonymous name that can be used as
2680 /// an identifier.
2682  return AnonymousNameInit::get(AnonCounter++);
2683 }
2684 
2685 // These functions implement the phase timing facility. Starting a timer
2686 // when one is already running stops the running one.
2687 
2689  if (TimingGroup) {
2690  if (LastTimer && LastTimer->isRunning()) {
2691  LastTimer->stopTimer();
2692  if (BackendTimer) {
2693  LastTimer->clear();
2694  BackendTimer = false;
2695  }
2696  }
2697 
2698  LastTimer = new Timer("", Name, *TimingGroup);
2699  LastTimer->startTimer();
2700  }
2701 }
2702 
2704  if (TimingGroup) {
2705  assert(LastTimer && "No phase timer was started");
2706  LastTimer->stopTimer();
2707  }
2708 }
2709 
2711  if (TimingGroup) {
2712  startTimer(Name);
2713  BackendTimer = true;
2714  }
2715 }
2716 
2718  if (TimingGroup) {
2719  if (BackendTimer) {
2720  stopTimer();
2721  BackendTimer = false;
2722  }
2723  }
2724 }
2725 
2726 // We cache the record vectors for single classes. Many backends request
2727 // the same vectors multiple times.
2729  StringRef ClassName) const {
2730 
2731  auto Pair = ClassRecordsMap.try_emplace(ClassName);
2732  if (Pair.second)
2733  Pair.first->second = getAllDerivedDefinitions(makeArrayRef(ClassName));
2734 
2735  return Pair.first->second;
2736 }
2737 
2739  ArrayRef<StringRef> ClassNames) const {
2740  SmallVector<Record *, 2> ClassRecs;
2741  std::vector<Record *> Defs;
2742 
2743  assert(ClassNames.size() > 0 && "At least one class must be passed.");
2744  for (const auto &ClassName : ClassNames) {
2745  Record *Class = getClass(ClassName);
2746  if (!Class)
2747  PrintFatalError("The class '" + ClassName + "' is not defined\n");
2748  ClassRecs.push_back(Class);
2749  }
2750 
2751  for (const auto &OneDef : getDefs()) {
2752  if (all_of(ClassRecs, [&OneDef](const Record *Class) {
2753  return OneDef.second->isSubClassOf(Class);
2754  }))
2755  Defs.push_back(OneDef.second.get());
2756  }
2757 
2758  return Defs;
2759 }
2760 
2762  auto It = Map.find(VarName);
2763  if (It == Map.end())
2764  return nullptr;
2765 
2766  Init *I = It->second.V;
2767 
2768  if (!It->second.Resolved && Map.size() > 1) {
2769  // Resolve mutual references among the mapped variables, but prevent
2770  // infinite recursion.
2771  Map.erase(It);
2772  I = I->resolveReferences(*this);
2773  Map[VarName] = {I, true};
2774  }
2775 
2776  return I;
2777 }
2778 
2780  Init *Val = Cache.lookup(VarName);
2781  if (Val)
2782  return Val;
2783 
2784  if (llvm::is_contained(Stack, VarName))
2785  return nullptr; // prevent infinite recursion
2786 
2787  if (RecordVal *RV = getCurrentRecord()->getValue(VarName)) {
2788  if (!isa<UnsetInit>(RV->getValue())) {
2789  Val = RV->getValue();
2790  Stack.push_back(VarName);
2791  Val = Val->resolveReferences(*this);
2792  Stack.pop_back();
2793  }
2794  } else if (Name && VarName == getCurrentRecord()->getNameInit()) {
2795  Stack.push_back(VarName);
2796  Val = Name->resolveReferences(*this);
2797  Stack.pop_back();
2798  }
2799 
2800  Cache[VarName] = Val;
2801  return Val;
2802 }
2803 
2805  Init *I = nullptr;
2806 
2807  if (R) {
2808  I = R->resolve(VarName);
2809  if (I && !FoundUnresolved) {
2810  // Do not recurse into the resolved initializer, as that would change
2811  // the behavior of the resolver we're delegating, but do check to see
2812  // if there are unresolved variables remaining.
2814  I->resolveReferences(Sub);
2815  FoundUnresolved |= Sub.FoundUnresolved;
2816  }
2817  }
2818 
2819  if (!I)
2820  FoundUnresolved = true;
2821  return I;
2822 }
2823 
2825 {
2826  if (VarName == VarNameToTrack)
2827  Found = true;
2828  return nullptr;
2829 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::Init::isComplete
virtual bool isComplete() const
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:336
llvm::CondOpInit::getConds
ArrayRef< Init * > getConds() const
Definition: Record.h:967
llvm::FieldInit::Fold
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1947
i
i
Definition: README.txt:29
llvm::TernOpInit::IF
@ IF
Definition: Record.h:865
llvm::Record::isSubClassOf
bool isSubClassOf(const Record *R) const
Definition: Record.h:1636
llvm::ListInit::isComplete
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.cpp:658
llvm::DefInit::getFieldType
RecTy * getFieldType(StringInit *FieldName) const override
This method is used to implement the FieldInit class.
Definition: Record.cpp:1785
llvm::BinOpInit::XOR
@ XOR
Definition: Record.h:808
llvm::TernOpInit::getOpcode
TernaryOp getOpcode() const
Definition: Record.h:906
llvm::ListInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:674
llvm::ListInit::convertInitListSlice
Init * convertInitListSlice(ArrayRef< unsigned > Elements) const override
This function is used to implement the list slice selection operator.
Definition: Record.cpp:617
llvm::ArrayRef::drop_back
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:210
llvm::RecordVal::getPrintType
std::string getPrintType() const
Get the type of the field for printing purposes.
Definition: Record.cpp:2228
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:499
llvm::Timer::clear
void clear()
Clear the timer state.
Definition: Timer.cpp:180
llvm::IsAOpInit::Fold
Init * Fold() const
Definition: Record.cpp:1569
llvm
Definition: AllocatorList.h:23
llvm::tgtok::Def
@ Def
Definition: TGLexer.h:50
llvm::StringRecTy
'string' - Represent an string value
Definition: Record.h:160
llvm::IntInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:466
llvm::VarDefInit::args
ArrayRef< Init * > args() const
Definition: Record.h:1256
llvm::RecordKeeper
Definition: Record.h:1771
llvm::Init::convertInitializerTo
virtual Init * convertInitializerTo(RecTy *Ty) const =0
Convert to a value whose type is Ty, or return null if this is not possible.
llvm::CondOpInit::getCond
Init * getCond(unsigned Num) const
Definition: Record.h:957
llvm::RecordRecTy::get
static RecordRecTy * get(ArrayRef< Record * > Classes)
Get the record type with the given non-redundant list of superclasses.
Definition: Record.cpp:148
llvm::Init::Opc
uint8_t Opc
Definition: Record.h:318
llvm::TypedInit::getCastTo
Init * getCastTo(RecTy *Ty) const override
If this value is convertible to type Ty, return a value whose type is Ty, generating a !...
Definition: Record.cpp:1644
llvm::AnonymousNameInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:513
llvm::Init::getCastTo
virtual Init * getCastTo(RecTy *Ty) const =0
If this value is convertible to type Ty, return a value whose type is Ty, generating a !...
llvm::Record::getDirectSuperClasses
void getDirectSuperClasses(SmallVectorImpl< Record * > &Classes) const
Append the direct superclasses of this record to Classes.
Definition: Record.cpp:2361
llvm::BitsInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:413
llvm::VarListElementInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:1765
llvm::UnOpInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:840
llvm::OpInit
Base class for operators.
Definition: Record.h:732
llvm::TernOpInit::FOREACH
@ FOREACH
Definition: Record.h:865
llvm::ListInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:589
llvm::BinOpInit::get
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:863
llvm::IntInit::convertInitializerBitRange
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This function is used to implement the bit range selection operator.
Definition: Record.cpp:493
llvm::StringInit::get
static StringInit * get(StringRef, StringFormat Fmt=SF_String)
Definition: Record.cpp:527
llvm::Record::getValueAsListOfDefs
std::vector< Record * > getValueAsListOfDefs(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of records,...
Definition: Record.cpp:2522
StringRef.h
llvm::BinOpInit::AND
@ AND
Definition: Record.h:808
llvm::TernOpInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1456
Allocator
static BumpPtrAllocator Allocator
Definition: Record.cpp:44
llvm::TypedInit::getFieldType
RecTy * getFieldType(StringInit *FieldName) const override
This method is used to implement the FieldInit class.
Definition: Record.cpp:1606
llvm::ArrayRef::iterator
const_pointer iterator
Definition: ArrayRef.h:50
llvm::FoldingSetImpl< FoldingSet< T >, T >::InsertNode
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:470
llvm::StringRef::find
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:315
llvm::IsAOpInit
!isa<type>(expr) - Dynamically determine the type of an expression.
Definition: Record.h:1039
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
Statistic.h
llvm::BitsRecTy::typeIsConvertibleTo
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:94
llvm::FunctionLoweringInfo::StatepointRelocationRecord
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
Definition: FunctionLoweringInfo.h:96
CheckType
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
Definition: SelectionDAGISel.cpp:2569
llvm::OpInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:685
ErrorHandling.h
llvm::FieldInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1940
llvm::Record::getSuperClasses
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const
Definition: Record.h:1571
ProfileCondOpInit
static void ProfileCondOpInit(FoldingSetNodeID &ID, ArrayRef< Init * > CondRange, ArrayRef< Init * > ValRange, const RecTy *ValType)
Definition: Record.cpp:1970
Allocator.h
llvm::DagInit
(v a, b) - Represent a DAG tree value.
Definition: Record.h:1307
llvm::X86II::TA
@ TA
Definition: X86BaseInfo.h:803
llvm::FieldInit::get
static FieldInit * get(Init *R, StringInit *FN)
Definition: Record.cpp:1923
llvm::tgtok::VarName
@ VarName
Definition: TGLexer.h:71
NewExpr
Definition: ItaniumDemangle.h:1773
llvm::FoldingSetImpl< FoldingSet< T >, T >::FindNodeOrInsertPos
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
Definition: FoldingSet.h:462
llvm::TrackUnresolvedResolver
(Optionally) delegate resolving to a sub-resolver, and keep track whether there were unresolved refer...
Definition: Record.h:2091
llvm::DagInit::arg_size
size_t arg_size() const
Definition: Record.h:1382
llvm::RecordVal::getNameInitAsString
std::string getNameInitAsString() const
Get the name of the field as a std::string.
Definition: Record.h:1429
llvm::RecTy::print
void print(raw_ostream &OS) const
Definition: Record.h:81
llvm::BinOpInit::OR
@ OR
Definition: Record.h:808
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
DenseMap.h
llvm::Timer
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:82
llvm::IntRecTy
'int' - Represent an integer value of no particular size
Definition: Record.h:142
llvm::BinOpInit
!op (X, Y) - Combine two inits.
Definition: Record.h:806
llvm::tgtok::Bits
@ Bits
Definition: TGLexer.h:50
llvm::BinOpInit::SRA
@ SRA
Definition: Record.h:808
llvm::AnonymousNameInit::getNameInit
StringInit * getNameInit() const
Definition: Record.cpp:509
T1
#define T1
Definition: Mips16ISelLowering.cpp:340
llvm::TernOpInit
!op (X, Y, Z) - Combine two inits.
Definition: Record.h:863
llvm::RecTy::dump
void dump() const
Definition: Record.cpp:56
llvm::DagRecTy
'dag' - Represent a dag fragment
Definition: Record.h:202
llvm::RecTy::BitsRecTyKind
@ BitsRecTyKind
Definition: Record.h:61
llvm::FoldOpInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1537
llvm::Optional
Definition: APInt.h:33
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::DagInit::getOperatorAsDef
Record * getOperatorAsDef(ArrayRef< SMLoc > Loc) const
Definition: Record.cpp:2157
llvm::BitRecTy::typeIsConvertibleTo
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:72
llvm::DagInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2191
llvm::Record::getLoc
ArrayRef< SMLoc > getLoc() const
Definition: Record.h:1552
llvm::BinOpInit::GT
@ GT
Definition: Record.h:810
llvm::TernOpInit::SUBST
@ SUBST
Definition: Record.h:865
llvm::VarBitInit::get
static VarBitInit * get(TypedInit *T, unsigned B)
Definition: Record.cpp:1712
llvm::ListInit::get
static ListInit * get(ArrayRef< Init * > Range, RecTy *EltTy)
Definition: Record.cpp:561
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::FoldOpInit::get
static FoldOpInit * get(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
Definition: Record.cpp:1484
ItemApply
static Init * ItemApply(Init *LHS, Init *MHSe, Init *RHS, Record *CurRec)
Definition: Record.cpp:1210
interleaveStringList
static StringInit * interleaveStringList(const ListInit *List, const StringInit *Delim)
Definition: Record.cpp:892
ProfileDagInit
static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringInit *VN, ArrayRef< Init * > ArgRange, ArrayRef< StringInit * > NameRange)
Definition: Record.cpp:2101
llvm::Init::getBit
virtual Init * getBit(unsigned Bit) const =0
Get the Init value of the specified bit.
llvm::BinOpInit::getStrConcat
static Init * getStrConcat(Init *lhs, Init *rhs)
Definition: Record.cpp:936
resolveRecordTypes
static RecordRecTy * resolveRecordTypes(RecordRecTy *T1, RecordRecTy *T2)
Definition: Record.cpp:233
llvm::TernOpInit::SUBSTR
@ SUBSTR
Definition: Record.h:865
llvm::Record::getValueAsOptionalDef
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:2593
llvm::RecordVal::FieldKind
FieldKind
Definition: Record.h:1406
llvm::Timer::startTimer
void startTimer()
Start the timer running.
Definition: Timer.cpp:165
llvm::DagInit::getArg
Init * getArg(unsigned Num) const
Definition: Record.h:1348
llvm::VarInit
'Opcode' - Represent a reference to an entire variable object.
Definition: Record.h:1072
llvm::Record::getFieldLoc
SMLoc getFieldLoc(StringRef FieldName) const
Return the source location for the named field.
Definition: Record.cpp:2457
llvm::AnonymousNameInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:517
llvm::DagInit::getOperator
Init * getOperator() const
Definition: Record.h:1337
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
llvm::RecTy
Definition: Record.h:56
llvm::ListRecTy::typeIsA
bool typeIsA(const RecTy *RHS) const override
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:131
ProfileFoldOpInit
static void ProfileFoldOpInit(FoldingSetNodeID &ID, Init *A, Init *B, Init *Start, Init *List, Init *Expr, RecTy *Type)
Definition: Record.cpp:1473
llvm::TernOpInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1206
llvm::BitRecTy
'bit' - Represent a single bit
Definition: Record.h:102
llvm::TernOpInit::Fold
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1289
llvm::Record::getValueAsListInit
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:2509
llvm::CondOpInit::Fold
Init * Fold(Record *CurRec) const
Definition: Record.cpp:2042
llvm::ListInit::getElementType
RecTy * getElementType() const
Definition: Record.h:694
llvm::BinOpInit::getLHS
Init * getLHS() const
Definition: Record.h:850
llvm::BitsRecTy
'bits<n>' - Represent a fixed number of bits
Definition: Record.h:120
llvm::RecordKeeper::startBackendTimer
void startBackendTimer(StringRef Name)
Start timing the overall backend.
Definition: Record.cpp:2710
llvm::Timer::isRunning
bool isRunning() const
Check if the timer is currently running.
Definition: Timer.h:119
llvm::Resolver
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2000
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:609
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::Record::getTemplateArgs
ArrayRef< Init * > getTemplateArgs() const
Definition: Record.h:1563
llvm::tgtok::Dag
@ Dag
Definition: TGLexer.h:50
llvm::StringInit::SF_String
@ SF_String
Definition: Record.h:614
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1285
llvm::BinOpInit::getRHS
Init * getRHS() const
Definition: Record.h:851
llvm::all_of
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:1482
llvm::Record::resolveReferences
void resolveReferences(Init *NewName=nullptr)
If there are any field references that refer to fields that have been filled in, we can propagate the...
Definition: Record.cpp:2410
llvm::RecordKeeper::startTimer
void startTimer(StringRef Name)
Start timing a phase. Automatically stops any previous phase timer.
Definition: Record.cpp:2688
llvm::ArrayRef::back
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:174
llvm::BitsInit::isConcrete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:391
llvm::CondOpInit::getVals
ArrayRef< Init * > getVals() const
Definition: Record.h:971
llvm::UnOpInit::GETDAGOP
@ GETDAGOP
Definition: Record.h:759
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:410
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:145
llvm::VarDefInit::getArg
Init * getArg(unsigned i) const
Definition: Record.h:1243
llvm::VarListElementInit::getElementNum
unsigned getElementNum() const
Definition: Record.h:1169
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::StringRecTy::typeIsConvertibleTo
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:116
llvm::FoldOpInit
!foldl (a, b, expr, start, lst) - Fold over a list.
Definition: Record.h:1002
llvm::BitsInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:399
llvm::CheckAssert
void CheckAssert(SMLoc Loc, Init *Condition, Init *Message)
Definition: Error.cpp:159
llvm::UnOpInit::UnaryOp
UnaryOp
Definition: Record.h:759
llvm::IsAOpInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1589
llvm::DagInit::arg_empty
bool arg_empty() const
Definition: Record.h:1383
llvm::BinOpInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1142
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::BinOpInit::BinaryOp
BinaryOp
Definition: Record.h:808
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:276
llvm::ListRecTy::getElementType
RecTy * getElementType() const
Definition: Record.h:192
llvm::TrackUnresolvedResolver::resolve
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:2804
llvm::RecordKeeper::addDef
void addDef(std::unique_ptr< Record > R)
Definition: Record.h:1835
llvm::CondOpInit
!cond(condition_1: value1, ...
Definition: Record.h:927
llvm::UnsetInit::get
static UnsetInit * get()
Get the singleton unset Init.
Definition: Record.cpp:286
llvm::DagInit::isConcrete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:2181
llvm::UnOpInit::CAST
@ CAST
Definition: Record.h:759
llvm::DagRecTy::getAsString
std::string getAsString() const override
Definition: Record.cpp:137
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::Init::dump
void dump() const
Debugging method that may be called through a debugger; just invokes print on stderr.
Definition: Record.cpp:283
llvm::RecordKeeper::stopBackendTimer
void stopBackendTimer()
Stop timing the overall backend.
Definition: Record.cpp:2717
llvm::BinOpInit::ADD
@ ADD
Definition: Record.h:808
llvm::TernOpInit::getRHS
Init * getRHS() const
Definition: Record.h:909
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
llvm::IntInit::get
static IntInit * get(int64_t V)
Definition: Record.cpp:448
llvm::ListInit::resolveReferences
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:642
Concat
static constexpr int Concat[]
Definition: X86InterleavedAccess.cpp:239
SMLoc.h
llvm::TypedInit::getType
RecTy * getType() const
Get the type of the Init as a RecTy.
Definition: Record.h:424
llvm::PrintFatalError
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg)
Definition: Error.cpp:125
ProfileListInit
static void ProfileListInit(FoldingSetNodeID &ID, ArrayRef< Init * > Range, RecTy *EltTy)
Definition: Record.cpp:551
llvm::IntRecTy::get
static IntRecTy * get()
Definition: Record.h:152
llvm::RecordRecTy::getAsString
std::string getAsString() const override
Definition: Record.cpp:193
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::BinOpInit::getListConcat
static Init * getListConcat(TypedInit *lhs, Init *rhs)
Definition: Record.cpp:952
llvm::DefInit::getDef
Record * getDef() const
Definition: Record.h:1197
llvm::wasm::ValType
ValType
Definition: Wasm.h:392
llvm::ListInit::isConcrete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:666
llvm::IsAOpInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:1596
StringMap.h
llvm::VarDefInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1822
llvm::BitsInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:544
llvm::TernOpInit::get
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:1190
llvm::RecordVal::getValue
Init * getValue() const
Get the value of the field as an Init.
Definition: Record.h:1453
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:245
llvm::CondOpInit::getNumConds
unsigned getNumConds() const
Definition: Record.h:955
llvm::IntInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:456
llvm::CondOpInit::get
static CondOpInit * get(ArrayRef< Init * > C, ArrayRef< Init * > V, RecTy *Type)
Definition: Record.cpp:1994
llvm::ShadowResolver::addShadow
void addShadow(Init *Key)
Definition: Record.h:2080
llvm::AnonymousNameInit
"anonymous_n" - Represent an anonymous record name
Definition: Record.h:581
llvm::FieldInit
X.Y - Represent a reference to a subfield of a variable.
Definition: Record.h:1264
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
llvm::TernOpInit::DAG
@ DAG
Definition: Record.h:865
llvm::RecordVal::dump
void dump() const
Definition: Record.cpp:2292
llvm::Record::dump
void dump() const
Definition: Record.cpp:2418
llvm::IsAOpInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1600
llvm::BinOpInit::LISTSPLAT
@ LISTSPLAT
Definition: Record.h:809
llvm::AnonymousNameInit::get
static AnonymousNameInit * get(unsigned)
Definition: Record.cpp:505
llvm::BitInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:306
llvm::TernOpInit::TernaryOp
TernaryOp
Definition: Record.h:865
llvm::RecordRecTy::typeIsA
bool typeIsA(const RecTy *RHS) const override
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:229
llvm::Record::getAssertions
ArrayRef< AssertionInfo > getAssertions() const
Definition: Record.h:1569
llvm::BinOpInit::NE
@ NE
Definition: Record.h:810
llvm::VarBitInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1724
llvm::CondOpInit::isConcrete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:2062
llvm::FieldInit::isConcrete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:1962
ProfileBinOpInit
static void ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS, RecTy *Type)
Definition: Record.cpp:855
llvm::UnOpInit
!op (X) - Transform an init.
Definition: Record.h:757
Error.h
FilterHelper
static Init * FilterHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, Record *CurRec)
Definition: Record.cpp:1266
llvm::RecordVal::setValue
bool setValue(Init *V)
Set the value of the field from an Init.
Definition: Record.cpp:2243
llvm::Resolver::getCurrentRecord
Record * getCurrentRecord() const
Definition: Record.h:2008
llvm::Init::isConcrete
virtual bool isConcrete() const
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:340
llvm::UnsetInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:295
llvm::VarListElementInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1752
llvm::BitInit::getValue
bool getValue() const
Definition: Record.h:485
llvm::IsAOpInit::get
static IsAOpInit * get(RecTy *CheckType, Init *Expr)
Definition: Record.cpp:1550
llvm::IntInit
'7' - Represent an initialization by a literal integer value.
Definition: Record.h:551
llvm::Record::getDefInit
DefInit * getDefInit()
get the corresponding DefInit.
Definition: Record.cpp:2321
llvm::DefInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1791
llvm::DefInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:1778
llvm::ListInit
[AL, AH, CL] - Represent a list of defs
Definition: Record.h:665
llvm::StringInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:544
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::MapResolver
Resolve arbitrary mappings.
Definition: Record.h:2028
llvm::RecordVal::print
void print(raw_ostream &OS, bool PrintSem=true) const
Print the value to an output stream, possibly with a semicolon.
Definition: Record.cpp:2295
llvm::Record::getValues
ArrayRef< RecordVal > getValues() const
Definition: Record.h:1567
llvm::DefInit
AL - Represent a reference to a 'def' in the description.
Definition: Record.h:1178
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::TernOpInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1426
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::DenseMap
Definition: DenseMap.h:714
llvm::VarInit::get
static VarInit * get(StringRef VN, RecTy *T)
Definition: Record.cpp:1678
llvm::RecordRecTy
'[classname]' - Type of record values that have zero or more superclasses.
Definition: Record.h:221
llvm::ShadowResolver
Delegate resolving to a sub-resolver, but shadow some variable names.
Definition: Record.h:2070
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::Record::addValue
void addValue(const RecordVal &RV)
Definition: Record.h:1608
llvm::ListInit::size
size_t size() const
Definition: Record.h:722
StringExtras.h
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1547
llvm::Record::getNameInitAsString
const std::string getNameInitAsString() const
Definition: Record.h:1546
ArrayRef.h
ProfileTernOpInit
static void ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS, Init *RHS, RecTy *Type)
Definition: Record.cpp:1181
llvm::IntInit::getValue
int64_t getValue() const
Definition: Record.h:567
llvm::Record::checkRecordAssertions
void checkRecordAssertions()
Definition: Record.cpp:2653
llvm::tgtok::Include
@ Include
Definition: TGLexer.h:51
llvm::BitsRecTy::typeIsA
bool typeIsA(const RecTy *RHS) const override
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:101
llvm::resolveTypes
RecTy * resolveTypes(RecTy *T1, RecTy *T2)
Find a common type that T1 and T2 convert to.
Definition: Record.cpp:250
llvm::BinOpInit::GE
@ GE
Definition: Record.h:810
llvm::BinOpInit::SHL
@ SHL
Definition: Record.h:808
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ListRecTy
'list<Ty>' - Represent a list of element values, all of which must be of the specified type.
Definition: Record.h:179
llvm::Record::getValueAsListOfStrings
std::vector< StringRef > getValueAsListOfStrings(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of strings,...
Definition: Record.cpp:2566
llvm::FoldOpInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1518
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::TypedInit::convertInitializerBitRange
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This function is used to implement the bit range selection operator.
Definition: Record.cpp:1628
llvm::BinOpInit::Fold
Init * Fold(Record *CurRec) const
Definition: Record.cpp:962
llvm::Init::resolveReferences
virtual Init * resolveReferences(Resolver &R) const
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.h:393
llvm::BinOpInit::LISTCONCAT
@ LISTCONCAT
Definition: Record.h:808
llvm::Init::getAsUnquotedString
virtual std::string getAsUnquotedString() const
Convert this value to a literal form, without adding quotes around a string.
Definition: Record.h:350
llvm::Record::removeValue
void removeValue(Init *Name)
Definition: Record.h:1613
llvm::Record::getValueAsListOfInts
std::vector< int64_t > getValueAsListOfInts(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of integers,...
Definition: Record.cpp:2550
llvm::BinOpInit::EQ
@ EQ
Definition: Record.h:809
llvm::Timer::stopTimer
void stopTimer()
Stop the timer.
Definition: Timer.cpp:172
llvm::VarBitInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1728
B
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional ldr LCPI1_0 ldr ldr tst movne lsr ldr LCPI1_1 and r0 bx lr it saves an instruction and a register It might be profitable to cse MOVi16 if there are lots of bit immediates with the same bottom half Robert Muth started working on an alternate jump table implementation that does not put the tables in line in the text This is more like the llvm default jump table implementation This might be useful sometime Several revisions of patches are on the mailing beginning while CMP sets them like a subtract Therefore to be able to use CMN for comparisons other than the Z we ll need additional logic to reverse the conditionals associated with the comparison Perhaps a pseudo instruction for the with a post codegen pass to clean up and handle the condition codes See PR5694 for testcase Given the following on int B
Definition: README.txt:592
ProfileRecordRecTy
static void ProfileRecordRecTy(FoldingSetNodeID &ID, ArrayRef< Record * > Classes)
Definition: Record.cpp:141
llvm::Record::getValueAsDag
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:2637
llvm::RecordKeeper::getDefs
const RecordMap & getDefs() const
Get the map of records (defs).
Definition: Record.h:1799
llvm::Record
Definition: Record.h:1472
ConcatListInits
static ListInit * ConcatListInits(const ListInit *LHS, const ListInit *RHS)
Definition: Record.cpp:944
llvm::VarInit::getName
StringRef getName() const
Definition: Record.cpp:1695
ProfileIsAOpInit
static void ProfileIsAOpInit(FoldingSetNodeID &ID, RecTy *CheckType, Init *Expr)
Definition: Record.cpp:1544
llvm::MapResolver::resolve
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:2761
llvm::RecordKeeper::getClass
Record * getClass(StringRef Name) const
Get the class with the specified name.
Definition: Record.h:1805
llvm::BinOpInit::SUB
@ SUB
Definition: Record.h:808
llvm::Init::getAsString
virtual std::string getAsString() const =0
Convert this value to a literal form.
llvm::StringRecTy::getAsString
std::string getAsString() const override
Definition: Record.cpp:112
llvm::UnOpInit::NOT
@ NOT
Definition: Record.h:759
llvm::Record::getValueAsBitsInit
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:2497
llvm::VarInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.h:1105
llvm::Record::getType
RecordRecTy * getType()
Definition: Record.cpp:2315
llvm::RecordKeeper::getClasses
const RecordMap & getClasses() const
Get the map of classes.
Definition: Record.h:1796
llvm::TypedInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:1617
llvm::VarInit::resolveReferences
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:1706
llvm::StringInit
"foo" - Represent an initialization by a string value.
Definition: Record.h:611
llvm::BitsInit::convertInitializerTo
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.cpp:353
llvm::BinOpInit::INTERLEAVE
@ INTERLEAVE
Definition: Record.h:809
llvm::FoldingSet
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:493
llvm::RecordKeeper::getAllDerivedDefinitions
std::vector< Record * > getAllDerivedDefinitions(StringRef ClassName) const
Get all the concrete records that inherit from the one specified class.
Definition: Record.cpp:2728
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::Record::addSuperClass
void addSuperClass(Record *R, SMRange Range)
Definition: Record.h:1655
llvm::CondOpInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2086
llvm::any_of
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:1489
llvm::UnOpInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:713
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:167
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm::BitsInit::getNumBits
unsigned getNumBits() const
Definition: Record.h:522
llvm::TernOpInit::getLHS
Init * getLHS() const
Definition: Record.h:907
llvm::BitInit
'true'/'false' - Represent a concrete initializer for a bit.
Definition: Record.h:470
llvm::TrailingObjects::getTrailingObjects
const T * getTrailingObjects() const
Returns a pointer to the trailing object array of the given type (which must be one of those specifie...
Definition: TrailingObjects.h:285
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::CondOpInit::getVal
Init * getVal(unsigned Num) const
Definition: Record.h:962
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::RecordVal::getNameInit
Init * getNameInit() const
Get the name of the field as an Init.
Definition: Record.h:1426
llvm::RecTy::typeIsA
virtual bool typeIsA(const RecTy *RHS) const
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:70
llvm::Record::getNameInit
Init * getNameInit() const
Definition: Record.h:1542
llvm::RecordRecTy::getClasses
ArrayRef< Record * > getClasses() const
Definition: Record.h:246
Compiler.h
llvm::CondOpInit::isComplete
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.cpp:2074
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1672
llvm::FoldOpInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1500
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:313
llvm::ListInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:583
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::VarDefInit::args_size
size_t args_size() const
Definition: Record.h:1253
llvm::DagInit::getArgNames
ArrayRef< StringInit * > getArgNames() const
Definition: Record.h:1367
ForeachHelper
static Init * ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, Record *CurRec)
Definition: Record.cpp:1245
llvm::BitRecTy::get
static BitRecTy * get()
Definition: Record.h:112
llvm::DagInit::getArgs
ArrayRef< Init * > getArgs() const
Definition: Record.h:1363
llvm::Init
Definition: Record.h:271
llvm::Record::getValueAsBitOrUnset
bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const
This method looks up the specified field and returns its value as a bit.
Definition: Record.cpp:2620
llvm::RecTy::getListTy
ListRecTy * getListTy()
Returns the type representing list<thistype>.
Definition: Record.cpp:59
llvm::IsAOpInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1565
llvm::RecordVal::getName
StringRef getName() const
Get the name of the field as a StringRef.
Definition: Record.cpp:2224
llvm::RecordKeeper::stopTimer
void stopTimer()
Stop timing a phase.
Definition: Record.cpp:2703
FoldingSet.h
llvm::Record::getValueAsInt
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:2535
llvm::BitsInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:349
llvm::DagInit::getNumArgs
unsigned getNumArgs() const
Definition: Record.h:1346
StringSet.h
llvm::CondOpInit::getValType
RecTy * getValType() const
Definition: Record.h:953
j
return j(j<< 16)
llvm::HasReferenceResolver::resolve
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:2824
llvm::BitsInit::convertInitializerBitRange
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This function is used to implement the bit range selection operator.
Definition: Record.cpp:380
llvm::ListInit::getValues
ArrayRef< Init * > getValues() const
Definition: Record.h:715
llvm::UnsetInit
'?' - Represents an uninitialized value.
Definition: Record.h:439
llvm::DagInit::get
static DagInit * get(Init *V, StringInit *VN, ArrayRef< Init * > ArgRange, ArrayRef< StringInit * > NameRange)
Definition: Record.cpp:2118
llvm::UnOpInit::SIZE
@ SIZE
Definition: Record.h:759
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::BinOpInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1152
llvm::TernOpInit::getMHS
Init * getMHS() const
Definition: Record.h:908
llvm::RecordVal::getType
RecTy * getType() const
Get the type of the field value as a RecTy.
Definition: Record.h:1447
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::UnOpInit::get
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
Definition: Record.cpp:698
llvm::BinOpInit::SRL
@ SRL
Definition: Record.h:808
llvm::TernOpInit::FILTER
@ FILTER
Definition: Record.h:865
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::Resolver::resolve
virtual Init * resolve(Init *VarName)=0
Return the initializer for the given variable name (should normally be a StringInit),...
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:153
llvm::BitsRecTy::get
static BitsRecTy * get(unsigned Sz)
Definition: Record.cpp:80
llvm::RecordVal::isNonconcreteOK
bool isNonconcreteOK() const
Is this a field where nonconcrete values are okay?
Definition: Record.h:1437
llvm::VarDefInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:1878
llvm::Record::getRecords
RecordKeeper & getRecords() const
Definition: Record.h:1676
llvm::BinOpInit::getOpcode
BinaryOp getOpcode() const
Definition: Record.h:849
llvm::Record::getValue
const RecordVal * getValue(const Init *Name) const
Definition: Record.h:1585
llvm::VarInit::getNameInit
Init * getNameInit() const
Definition: Record.h:1090
llvm::StringInit::getValue
StringRef getValue() const
Definition: Record.h:639
llvm::FieldInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:1934
llvm::RecordResolver::resolve
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:2779
Casting.h
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1423
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
interleaveIntList
static StringInit * interleaveIntList(const ListInit *List, const StringInit *Delim)
Definition: Record.cpp:913
llvm::VarBitInit::getBitNum
unsigned getBitNum() const
Definition: Record.h:1133
llvm::UnOpInit::TAIL
@ TAIL
Definition: Record.h:759
llvm::ListRecTy::typeIsConvertibleTo
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:125
llvm::BitsInit::get
static BitsInit * get(ArrayRef< Init * > Range)
Definition: Record.cpp:330
llvm::Record::getValueInit
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:2465
llvm::UnOpInit::HEAD
@ HEAD
Definition: Record.h:759
ProfileVarDefInit
static void ProfileVarDefInit(FoldingSetNodeID &ID, Record *Class, ArrayRef< Init * > Args)
Definition: Record.cpp:1793
llvm::RecTy::StringRecTyKind
@ StringRecTyKind
Definition: Record.h:63
llvm::ListRecTy::getAsString
std::string getAsString() const override
Definition: Record.cpp:121
ProfileBitsInit
static void ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef< Init * > Range)
Definition: Record.cpp:323
llvm::Init::print
void print(raw_ostream &OS) const
Print this value.
Definition: Record.h:343
llvm::RecordRecTy::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:189
llvm::CondOpInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:2097
llvm::VarListElementInit::get
static VarListElementInit * get(TypedInit *T, unsigned E)
Definition: Record.cpp:1736
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::UnsetInit::getCastTo
Init * getCastTo(RecTy *Ty) const override
If this value is convertible to type Ty, return a value whose type is Ty, generating a !...
Definition: Record.cpp:291
llvm::RecTy::typeIsConvertibleTo
virtual bool typeIsConvertibleTo(const RecTy *RHS) const
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:65
llvm::CondOpInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:2019
llvm::BinOpInit::LT
@ LT
Definition: Record.h:810
llvm::TernOpInit::FIND
@ FIND
Definition: Record.h:865
llvm::RecTy::getAsString
virtual std::string getAsString() const =0
llvm::BinOpInit::SETDAGOP
@ SETDAGOP
Definition: Record.h:810
llvm::RecordVal::RecordVal
RecordVal(Init *N, RecTy *T, FieldKind K)
Definition: Record.cpp:2210
ProfileUnOpInit
static void ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op, RecTy *Type)
Definition: Record.cpp:692
SmallVector.h
llvm::RecTy::getRecTyKind
RecTyKind getRecTyKind() const
Definition: Record.h:78
llvm::Record::getName
StringRef getName() const
Definition: Record.h:1540
llvm::RecTy::BitRecTyKind
@ BitRecTyKind
Definition: Record.h:60
llvm::ListInit::getElementAsRecord
Record * getElementAsRecord(unsigned i) const
Definition: Record.cpp:634
llvm::PrintError
void PrintError(const Twine &Msg)
Definition: Error.cpp:101
llvm::FoldOpInit::Fold
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1504
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
List
const NodeList & List
Definition: RDFGraph.cpp:201
llvm::UnOpInit::Fold
Init * Fold(Record *CurRec, bool IsFinal=false) const
Definition: Record.cpp:717
N
#define N
llvm::StringInit::determineFormat
static StringFormat determineFormat(StringFormat Fmt1, StringFormat Fmt2)
Definition: Record.h:635
llvm::Record::getValueAsBit
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:2608
llvm::Record::appendAssertions
void appendAssertions(const Record *Rec)
Definition: Record.h:1630
llvm::RecTy::RecTyKind
RecTyKind
Subclass discriminator (for dyn_cast<> et al.)
Definition: Record.h:59
llvm::VarBitInit
Opcode{0} - Represent access to one bit of a variable or field.
Definition: Record.h:1109
llvm::CondOpInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:1986
llvm::TrackUnresolvedResolver::foundUnresolved
bool foundUnresolved() const
Definition: Record.h:2099
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:62
llvm::BinOpInit::STRCONCAT
@ STRCONCAT
Definition: Record.h:809
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::Record::getValueAsString
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:2473
llvm::RecordKeeper::getNewAnonymousName
Init * getNewAnonymousName()
GetNewAnonymousName - Generate a unique anonymous name that can be used as an identifier.
Definition: Record.cpp:2681
llvm::DagInit::getArgName
StringInit * getArgName(unsigned Num) const
Definition: Record.h:1353
canFitInBitfield
static bool canFitInBitfield(int64_t Value, unsigned NumBits)
Definition: Record.cpp:460
llvm::tgtok::Bit
@ Bit
Definition: TGLexer.h:50
llvm::BitsRecTy::getAsString
std::string getAsString() const override
Definition: Record.cpp:90
llvm::UnOpInit::getOperand
Init * getOperand() const
Definition: Record.h:794
llvm::UnOpInit::EMPTY
@ EMPTY
Definition: Record.h:759
llvm::BinOpInit::MUL
@ MUL
Definition: Record.h:808
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::StringInit::getFormat
StringFormat getFormat() const
Definition: Record.h:640
llvm::BinOpInit::LE
@ LE
Definition: Record.h:810
llvm::StringInit::StringFormat
StringFormat
Definition: Record.h:613
llvm::RecordResolver
Resolve all variables from a record except for unset variables.
Definition: Record.h:2054
llvm::StringInit::getAsUnquotedString
std::string getAsUnquotedString() const override
Convert this value to a literal form, without adding quotes around a string.
Definition: Record.h:654
llvm::DagInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:2164
llvm::UnOpInit::resolveReferences
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:831
ForeachDagApply
static Init * ForeachDagApply(Init *LHS, DagInit *MHSd, Init *RHS, Record *CurRec)
Definition: Record.cpp:1216
llvm::BinOpInit::CONCAT
@ CONCAT
Definition: Record.h:809
llvm::VarDefInit::get
static VarDefInit * get(Record *Class, ArrayRef< Init * > Args)
Definition: Record.cpp:1803
llvm::BitsInit
'{ a, b, c }' - Represents an initializer for a BitsRecTy value.
Definition: Record.h:500
llvm::VarListElementInit
List[4] - Represent access to one element of a var or field.
Definition: Record.h:1146
llvm::VarInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:1700
llvm::OptimizedStructLayoutField
A field in a structure.
Definition: OptimizedStructLayout.h:45
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::VarDefInit::Fold
Init * Fold() const
Definition: Record.cpp:1899
llvm::RecTy::IntRecTyKind
@ IntRecTyKind
Definition: Record.h:62
llvm::RecordKeeper::getDef
Record * getDef(StringRef Name) const
Get the concrete record with the specified name.
Definition: Record.h:1811
llvm::UnOpInit::getOpcode
UnaryOp getOpcode() const
Definition: Record.h:793
raw_ostream.h
llvm::RecordVal
This class represents a field in a record, including its name, type, value, and source location.
Definition: Record.h:1402
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
llvm::IntRecTy::typeIsConvertibleTo
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:107
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:623
llvm::RecordRecTy::isSubClassOf
bool isSubClassOf(Record *Class) const
Definition: Record.cpp:209
llvm::VarDefInit
classname<targs...> - Represent an uninstantiated anonymous class instantiation.
Definition: Record.h:1213
llvm::RecordRecTy::typeIsConvertibleTo
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
Definition: Record.cpp:216
llvm::DagInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:2153
llvm::Record::getValueAsOptionalString
llvm::Optional< StringRef > getValueAsOptionalString(StringRef FieldName) const
This method looks up the specified field and returns its value as a string, throwing an exception if ...
Definition: Record.cpp:2482
llvm::RecordKeeper::dump
void dump() const
Definition: Record.cpp:2665
Record.h
llvm::Record::setName
void setName(Init *Name)
Definition: Record.cpp:2327
llvm::Record::hasDirectSuperClass
bool hasDirectSuperClass(const Record *SuperClass) const
Determine whether this record has the specified direct superclass.
Definition: Record.cpp:2348
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::TypedInit::convertInitListSlice
Init * convertInitListSlice(ArrayRef< unsigned > Elements) const override
This function is used to implement the list slice selection operator.
Definition: Record.cpp:1662
llvm::ListInit::getElement
Init * getElement(unsigned i) const
Definition: Record.h:690
llvm::DefInit::get
static DefInit * get(Record *)
Definition: Record.cpp:1774
llvm::BinOpInit::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Record.cpp:879
llvm::VarDefInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1912
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:154
llvm::FoldingSetBase::Node::Node
Node()=default
llvm::Record::getValueAsDef
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:2581
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:907
ConcatStringInits
static StringInit * ConcatStringInits(const StringInit *I0, const StringInit *I1)
Definition: Record.cpp:883
llvm::BitInit::get
static BitInit * get(bool V)
Definition: Record.cpp:299
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::StringRecTy::get
static StringRecTy * get()
Definition: Record.h:170
llvm::TypedInit
This is the common superclass of types that have a specific, explicit type, stored in ValueTy.
Definition: Record.h:407
llvm::FoldOpInit::getBit
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:1533
llvm::VarListElementInit::getAsString
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1748