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