LLVM 20.0.0git
Record.h
Go to the documentation of this file.
1//===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
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// This file defines the main TableGen data structures, including the TableGen
10// types, values, and high-level data structures.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TABLEGEN_RECORD_H
15#define LLVM_TABLEGEN_RECORD_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/DenseSet.h"
20#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/StringRef.h"
27#include "llvm/Support/SMLoc.h"
28#include "llvm/Support/Timer.h"
31#include <cassert>
32#include <cstddef>
33#include <cstdint>
34#include <map>
35#include <memory>
36#include <optional>
37#include <string>
38#include <utility>
39#include <variant>
40#include <vector>
41
42namespace llvm {
43namespace detail {
44struct RecordKeeperImpl;
45} // namespace detail
46
47class ListRecTy;
48class Record;
49class RecordKeeper;
50class RecordVal;
51class Resolver;
52class StringInit;
53class TypedInit;
54
55//===----------------------------------------------------------------------===//
56// Type Classes
57//===----------------------------------------------------------------------===//
58
59class RecTy {
60public:
61 /// Subclass discriminator (for dyn_cast<> et al.)
62 enum RecTyKind {
70 };
71
72private:
73 RecTyKind Kind;
74 /// The RecordKeeper that uniqued this Type.
75 RecordKeeper &RK;
76 /// ListRecTy of the list that has elements of this type.
77 ListRecTy *ListTy = nullptr;
78
79public:
80 RecTy(RecTyKind K, RecordKeeper &RK) : Kind(K), RK(RK) {}
81 virtual ~RecTy() = default;
82
83 RecTyKind getRecTyKind() const { return Kind; }
84
85 /// Return the RecordKeeper that uniqued this Type.
86 RecordKeeper &getRecordKeeper() const { return RK; }
87
88 virtual std::string getAsString() const = 0;
89 void print(raw_ostream &OS) const { OS << getAsString(); }
90 void dump() const;
91
92 /// Return true if all values of 'this' type can be converted to the specified
93 /// type.
94 virtual bool typeIsConvertibleTo(const RecTy *RHS) const;
95
96 /// Return true if 'this' type is equal to or a subtype of RHS. For example,
97 /// a bit set is not an int, but they are convertible.
98 virtual bool typeIsA(const RecTy *RHS) const;
99
100 /// Returns the type representing list<thistype>.
102};
103
105 Ty.print(OS);
106 return OS;
107}
108
109/// 'bit' - Represent a single bit
110class BitRecTy : public RecTy {
112
114
115public:
116 static bool classof(const RecTy *RT) {
117 return RT->getRecTyKind() == BitRecTyKind;
118 }
119
120 static BitRecTy *get(RecordKeeper &RK);
121
122 std::string getAsString() const override { return "bit"; }
123
124 bool typeIsConvertibleTo(const RecTy *RHS) const override;
125};
126
127/// 'bits<n>' - Represent a fixed number of bits
128class BitsRecTy : public RecTy {
129 unsigned Size;
130
131 explicit BitsRecTy(RecordKeeper &RK, unsigned Sz)
132 : RecTy(BitsRecTyKind, RK), Size(Sz) {}
133
134public:
135 static bool classof(const RecTy *RT) {
136 return RT->getRecTyKind() == BitsRecTyKind;
137 }
138
139 static BitsRecTy *get(RecordKeeper &RK, unsigned Sz);
140
141 unsigned getNumBits() const { return Size; }
142
143 std::string getAsString() const override;
144
145 bool typeIsConvertibleTo(const RecTy *RHS) const override;
146};
147
148/// 'int' - Represent an integer value of no particular size
149class IntRecTy : public RecTy {
151
153
154public:
155 static bool classof(const RecTy *RT) {
156 return RT->getRecTyKind() == IntRecTyKind;
157 }
158
159 static IntRecTy *get(RecordKeeper &RK);
160
161 std::string getAsString() const override { return "int"; }
162
163 bool typeIsConvertibleTo(const RecTy *RHS) const override;
164};
165
166/// 'string' - Represent an string value
167class StringRecTy : public RecTy {
169
171
172public:
173 static bool classof(const RecTy *RT) {
174 return RT->getRecTyKind() == StringRecTyKind;
175 }
176
177 static StringRecTy *get(RecordKeeper &RK);
178
179 std::string getAsString() const override;
180
181 bool typeIsConvertibleTo(const RecTy *RHS) const override;
182};
183
184/// 'list<Ty>' - Represent a list of element values, all of which must be of
185/// the specified type. The type is stored in ElementTy.
186class ListRecTy : public RecTy {
188
189 RecTy *ElementTy;
190
191 explicit ListRecTy(RecTy *T)
192 : RecTy(ListRecTyKind, T->getRecordKeeper()), ElementTy(T) {}
193
194public:
195 static bool classof(const RecTy *RT) {
196 return RT->getRecTyKind() == ListRecTyKind;
197 }
198
199 static ListRecTy *get(RecTy *T) { return T->getListTy(); }
200 RecTy *getElementType() const { return ElementTy; }
201
202 std::string getAsString() const override;
203
204 bool typeIsConvertibleTo(const RecTy *RHS) const override;
205
206 bool typeIsA(const RecTy *RHS) const override;
207};
208
209/// 'dag' - Represent a dag fragment
210class DagRecTy : public RecTy {
212
214
215public:
216 static bool classof(const RecTy *RT) {
217 return RT->getRecTyKind() == DagRecTyKind;
218 }
219
220 static DagRecTy *get(RecordKeeper &RK);
221
222 std::string getAsString() const override;
223};
224
225/// '[classname]' - Type of record values that have zero or more superclasses.
226///
227/// The list of superclasses is non-redundant, i.e. only contains classes that
228/// are not the superclass of some other listed class.
229class RecordRecTy final : public RecTy, public FoldingSetNode,
230 public TrailingObjects<RecordRecTy, Record *> {
231 friend class Record;
233
234 unsigned NumClasses;
235
236 explicit RecordRecTy(RecordKeeper &RK, unsigned Num)
237 : RecTy(RecordRecTyKind, RK), NumClasses(Num) {}
238
239public:
240 RecordRecTy(const RecordRecTy &) = delete;
242
243 // Do not use sized deallocation due to trailing objects.
244 void operator delete(void *p) { ::operator delete(p); }
245
246 static bool classof(const RecTy *RT) {
247 return RT->getRecTyKind() == RecordRecTyKind;
248 }
249
250 /// Get the record type with the given non-redundant list of superclasses.
251 static RecordRecTy *get(RecordKeeper &RK, ArrayRef<Record *> Classes);
252 static RecordRecTy *get(Record *Class);
253
254 void Profile(FoldingSetNodeID &ID) const;
255
257 return ArrayRef(getTrailingObjects<Record *>(), NumClasses);
258 }
259
260 using const_record_iterator = Record * const *;
261
262 const_record_iterator classes_begin() const { return getClasses().begin(); }
263 const_record_iterator classes_end() const { return getClasses().end(); }
264
265 std::string getAsString() const override;
266
267 bool isSubClassOf(Record *Class) const;
268 bool typeIsConvertibleTo(const RecTy *RHS) const override;
269
270 bool typeIsA(const RecTy *RHS) const override;
271};
272
273/// Find a common type that T1 and T2 convert to.
274/// Return 0 if no such type exists.
275RecTy *resolveTypes(RecTy *T1, RecTy *T2);
276
277//===----------------------------------------------------------------------===//
278// Initializer Classes
279//===----------------------------------------------------------------------===//
280
281class Init {
282protected:
283 /// Discriminator enum (for isa<>, dyn_cast<>, et al.)
284 ///
285 /// This enum is laid out by a preorder traversal of the inheritance
286 /// hierarchy, and does not contain an entry for abstract classes, as per
287 /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
288 ///
289 /// We also explicitly include "first" and "last" values for each
290 /// interior node of the inheritance tree, to make it easier to read the
291 /// corresponding classof().
292 ///
293 /// We could pack these a bit tighter by not having the IK_FirstXXXInit
294 /// and IK_LastXXXInit be their own values, but that would degrade
295 /// readability for really no benefit.
296 enum InitKind : uint8_t {
297 IK_First, // unused; silence a spurious warning
323 };
324
325private:
326 const InitKind Kind;
327
328protected:
329 uint8_t Opc; // Used by UnOpInit, BinOpInit, and TernOpInit
330
331private:
332 virtual void anchor();
333
334public:
335 /// Get the kind (type) of the value.
336 InitKind getKind() const { return Kind; }
337
338 /// Get the record keeper that initialized this Init.
340
341protected:
342 explicit Init(InitKind K, uint8_t Opc = 0) : Kind(K), Opc(Opc) {}
343
344public:
345 Init(const Init &) = delete;
346 Init &operator=(const Init &) = delete;
347 virtual ~Init() = default;
348
349 /// Is this a complete value with no unset (uninitialized) subvalues?
350 virtual bool isComplete() const { return true; }
351
352 /// Is this a concrete and fully resolved value without any references or
353 /// stuck operations? Unset values are concrete.
354 virtual bool isConcrete() const { return false; }
355
356 /// Print this value.
357 void print(raw_ostream &OS) const { OS << getAsString(); }
358
359 /// Convert this value to a literal form.
360 virtual std::string getAsString() const = 0;
361
362 /// Convert this value to a literal form,
363 /// without adding quotes around a string.
364 virtual std::string getAsUnquotedString() const { return getAsString(); }
365
366 /// Debugging method that may be called through a debugger; just
367 /// invokes print on stderr.
368 void dump() const;
369
370 /// If this value is convertible to type \p Ty, return a value whose
371 /// type is \p Ty, generating a !cast operation if required.
372 /// Otherwise, return null.
373 virtual Init *getCastTo(RecTy *Ty) const = 0;
374
375 /// Convert to a value whose type is \p Ty, or return null if this
376 /// is not possible. This can happen if the value's type is convertible
377 /// to \p Ty, but there are unresolved references.
378 virtual Init *convertInitializerTo(RecTy *Ty) const = 0;
379
380 /// This function is used to implement the bit range
381 /// selection operator. Given a value, it selects the specified bits,
382 /// returning them as a new \p Init of type \p bits. If it is not legal
383 /// to use the bit selection operator on this value, null is returned.
385 return nullptr;
386 }
387
388 /// This function is used to implement the FieldInit class.
389 /// Implementors of this method should return the type of the named
390 /// field if they are of type record.
391 virtual RecTy *getFieldType(StringInit *FieldName) const {
392 return nullptr;
393 }
394
395 /// This function is used by classes that refer to other
396 /// variables which may not be defined at the time the expression is formed.
397 /// If a value is set for the variable later, this method will be called on
398 /// users of the value to allow the value to propagate out.
399 virtual Init *resolveReferences(Resolver &R) const {
400 return const_cast<Init *>(this);
401 }
402
403 /// Get the \p Init value of the specified bit.
404 virtual Init *getBit(unsigned Bit) const = 0;
405};
406
408 I.print(OS); return OS;
409}
410
411/// This is the common superclass of types that have a specific,
412/// explicit type, stored in ValueTy.
413class TypedInit : public Init {
414 RecTy *ValueTy;
415
416protected:
417 explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
418 : Init(K, Opc), ValueTy(T) {}
419
420public:
421 TypedInit(const TypedInit &) = delete;
422 TypedInit &operator=(const TypedInit &) = delete;
423
424 static bool classof(const Init *I) {
425 return I->getKind() >= IK_FirstTypedInit &&
426 I->getKind() <= IK_LastTypedInit;
427 }
428
429 /// Get the type of the Init as a RecTy.
430 RecTy *getType() const { return ValueTy; }
431
432 /// Get the record keeper that initialized this Init.
433 RecordKeeper &getRecordKeeper() const { return ValueTy->getRecordKeeper(); }
434
435 Init *getCastTo(RecTy *Ty) const override;
436 Init *convertInitializerTo(RecTy *Ty) const override;
437
439
440 /// This method is used to implement the FieldInit class.
441 /// Implementors of this method should return the type of the named field if
442 /// they are of type record.
443 RecTy *getFieldType(StringInit *FieldName) const override;
444};
445
446/// '?' - Represents an uninitialized value.
447class UnsetInit : public Init {
449
450 /// The record keeper that initialized this Init.
451 RecordKeeper &RK;
452
453 UnsetInit(RecordKeeper &RK) : Init(IK_UnsetInit), RK(RK) {}
454
455public:
456 UnsetInit(const UnsetInit &) = delete;
457 UnsetInit &operator=(const UnsetInit &) = delete;
458
459 static bool classof(const Init *I) {
460 return I->getKind() == IK_UnsetInit;
461 }
462
463 /// Get the singleton unset Init.
464 static UnsetInit *get(RecordKeeper &RK);
465
466 /// Get the record keeper that initialized this Init.
467 RecordKeeper &getRecordKeeper() const { return RK; }
468
469 Init *getCastTo(RecTy *Ty) const override;
470 Init *convertInitializerTo(RecTy *Ty) const override;
471
472 Init *getBit(unsigned Bit) const override {
473 return const_cast<UnsetInit*>(this);
474 }
475
476 /// Is this a complete value with no unset (uninitialized) subvalues?
477 bool isComplete() const override { return false; }
478
479 bool isConcrete() const override { return true; }
480
481 /// Get the string representation of the Init.
482 std::string getAsString() const override { return "?"; }
483};
484
485// Represent an argument.
486using ArgAuxType = std::variant<unsigned, Init *>;
487class ArgumentInit : public Init, public FoldingSetNode {
488public:
489 enum Kind {
492 };
493
494private:
495 Init *Value;
496 ArgAuxType Aux;
497
498protected:
500 : Init(IK_ArgumentInit), Value(Value), Aux(Aux) {}
501
502public:
503 ArgumentInit(const ArgumentInit &) = delete;
505
506 static bool classof(const Init *I) { return I->getKind() == IK_ArgumentInit; }
507
508 RecordKeeper &getRecordKeeper() const { return Value->getRecordKeeper(); }
509
510 static ArgumentInit *get(Init *Value, ArgAuxType Aux);
511
512 bool isPositional() const { return Aux.index() == Positional; }
513 bool isNamed() const { return Aux.index() == Named; }
514
515 Init *getValue() const { return Value; }
516 unsigned getIndex() const {
517 assert(isPositional() && "Should be positional!");
518 return std::get<Positional>(Aux);
519 }
520 Init *getName() const {
521 assert(isNamed() && "Should be named!");
522 return std::get<Named>(Aux);
523 }
524 ArgumentInit *cloneWithValue(Init *Value) const { return get(Value, Aux); }
525
526 void Profile(FoldingSetNodeID &ID) const;
527
528 Init *resolveReferences(Resolver &R) const override;
529 std::string getAsString() const override {
530 if (isPositional())
531 return utostr(getIndex()) + ": " + Value->getAsString();
532 if (isNamed())
533 return getName()->getAsString() + ": " + Value->getAsString();
534 llvm_unreachable("Unsupported argument type!");
535 return "";
536 }
537
538 bool isComplete() const override { return false; }
539 bool isConcrete() const override { return false; }
540 Init *getBit(unsigned Bit) const override { return Value->getBit(Bit); }
541 Init *getCastTo(RecTy *Ty) const override { return Value->getCastTo(Ty); }
542 Init *convertInitializerTo(RecTy *Ty) const override {
543 return Value->convertInitializerTo(Ty);
544 }
545};
546
547/// 'true'/'false' - Represent a concrete initializer for a bit.
548class BitInit final : public TypedInit {
550
551 bool Value;
552
553 explicit BitInit(bool V, RecTy *T) : TypedInit(IK_BitInit, T), Value(V) {}
554
555public:
556 BitInit(const BitInit &) = delete;
558
559 static bool classof(const Init *I) {
560 return I->getKind() == IK_BitInit;
561 }
562
563 static BitInit *get(RecordKeeper &RK, bool V);
564
565 bool getValue() const { return Value; }
566
567 Init *convertInitializerTo(RecTy *Ty) const override;
568
569 Init *getBit(unsigned Bit) const override {
570 assert(Bit < 1 && "Bit index out of range!");
571 return const_cast<BitInit*>(this);
572 }
573
574 bool isConcrete() const override { return true; }
575 std::string getAsString() const override { return Value ? "1" : "0"; }
576};
577
578/// '{ a, b, c }' - Represents an initializer for a BitsRecTy value.
579/// It contains a vector of bits, whose size is determined by the type.
580class BitsInit final : public TypedInit, public FoldingSetNode,
581 public TrailingObjects<BitsInit, Init *> {
582 unsigned NumBits;
583
584 BitsInit(RecordKeeper &RK, unsigned N)
585 : TypedInit(IK_BitsInit, BitsRecTy::get(RK, N)), NumBits(N) {}
586
587public:
588 BitsInit(const BitsInit &) = delete;
589 BitsInit &operator=(const BitsInit &) = delete;
590
591 // Do not use sized deallocation due to trailing objects.
592 void operator delete(void *p) { ::operator delete(p); }
593
594 static bool classof(const Init *I) {
595 return I->getKind() == IK_BitsInit;
596 }
597
599
600 void Profile(FoldingSetNodeID &ID) const;
601
602 unsigned getNumBits() const { return NumBits; }
603
604 Init *convertInitializerTo(RecTy *Ty) const override;
606
607 bool isComplete() const override {
608 for (unsigned i = 0; i != getNumBits(); ++i)
609 if (!getBit(i)->isComplete()) return false;
610 return true;
611 }
612
613 bool allInComplete() const {
614 for (unsigned i = 0; i != getNumBits(); ++i)
615 if (getBit(i)->isComplete()) return false;
616 return true;
617 }
618
619 bool isConcrete() const override;
620 std::string getAsString() const override;
621
622 Init *resolveReferences(Resolver &R) const override;
623
624 Init *getBit(unsigned Bit) const override {
625 assert(Bit < NumBits && "Bit index out of range!");
626 return getTrailingObjects<Init *>()[Bit];
627 }
628};
629
630/// '7' - Represent an initialization by a literal integer value.
631class IntInit : public TypedInit {
632 int64_t Value;
633
634 explicit IntInit(RecordKeeper &RK, int64_t V)
636
637public:
638 IntInit(const IntInit &) = delete;
639 IntInit &operator=(const IntInit &) = delete;
640
641 static bool classof(const Init *I) {
642 return I->getKind() == IK_IntInit;
643 }
644
645 static IntInit *get(RecordKeeper &RK, int64_t V);
646
647 int64_t getValue() const { return Value; }
648
649 Init *convertInitializerTo(RecTy *Ty) const override;
651
652 bool isConcrete() const override { return true; }
653 std::string getAsString() const override;
654
655 Init *getBit(unsigned Bit) const override {
656 return BitInit::get(getRecordKeeper(), (Value & (1ULL << Bit)) != 0);
657 }
658};
659
660/// "anonymous_n" - Represent an anonymous record name
662 unsigned Value;
663
664 explicit AnonymousNameInit(RecordKeeper &RK, unsigned V)
666
667public:
670
671 static bool classof(const Init *I) {
672 return I->getKind() == IK_AnonymousNameInit;
673 }
674
675 static AnonymousNameInit *get(RecordKeeper &RK, unsigned);
676
677 unsigned getValue() const { return Value; }
678
679 StringInit *getNameInit() const;
680
681 std::string getAsString() const override;
682
683 Init *resolveReferences(Resolver &R) const override;
684
685 Init *getBit(unsigned Bit) const override {
686 llvm_unreachable("Illegal bit reference off string");
687 }
688};
689
690/// "foo" - Represent an initialization by a string value.
691class StringInit : public TypedInit {
692public:
694 SF_String, // Format as "text"
695 SF_Code, // Format as [{text}]
696 };
697
698private:
700 StringFormat Format;
701
702 explicit StringInit(RecordKeeper &RK, StringRef V, StringFormat Fmt)
703 : TypedInit(IK_StringInit, StringRecTy::get(RK)), Value(V), Format(Fmt) {}
704
705public:
706 StringInit(const StringInit &) = delete;
707 StringInit &operator=(const StringInit &) = delete;
708
709 static bool classof(const Init *I) {
710 return I->getKind() == IK_StringInit;
711 }
712
714 StringFormat Fmt = SF_String);
715
717 return (Fmt1 == SF_Code || Fmt2 == SF_Code) ? SF_Code : SF_String;
718 }
719
720 StringRef getValue() const { return Value; }
721 StringFormat getFormat() const { return Format; }
722 bool hasCodeFormat() const { return Format == SF_Code; }
723
724 Init *convertInitializerTo(RecTy *Ty) const override;
725
726 bool isConcrete() const override { return true; }
727
728 std::string getAsString() const override {
729 if (Format == SF_String)
730 return "\"" + Value.str() + "\"";
731 else
732 return "[{" + Value.str() + "}]";
733 }
734
735 std::string getAsUnquotedString() const override {
736 return std::string(Value);
737 }
738
739 Init *getBit(unsigned Bit) const override {
740 llvm_unreachable("Illegal bit reference off string");
741 }
742};
743
744/// [AL, AH, CL] - Represent a list of defs
745///
746class ListInit final : public TypedInit, public FoldingSetNode,
747 public TrailingObjects<ListInit, Init *> {
748 unsigned NumValues;
749
750public:
751 using const_iterator = Init *const *;
752
753private:
754 explicit ListInit(unsigned N, RecTy *EltTy)
755 : TypedInit(IK_ListInit, ListRecTy::get(EltTy)), NumValues(N) {}
756
757public:
758 ListInit(const ListInit &) = delete;
759 ListInit &operator=(const ListInit &) = delete;
760
761 // Do not use sized deallocation due to trailing objects.
762 void operator delete(void *p) { ::operator delete(p); }
763
764 static bool classof(const Init *I) {
765 return I->getKind() == IK_ListInit;
766 }
767 static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
768
769 void Profile(FoldingSetNodeID &ID) const;
770
771 Init *getElement(unsigned i) const {
772 assert(i < NumValues && "List element index out of range!");
773 return getTrailingObjects<Init *>()[i];
774 }
776 return cast<ListRecTy>(getType())->getElementType();
777 }
778
779 Record *getElementAsRecord(unsigned i) const;
780
781 Init *convertInitializerTo(RecTy *Ty) const override;
782
783 /// This method is used by classes that refer to other
784 /// variables which may not be defined at the time they expression is formed.
785 /// If a value is set for the variable later, this method will be called on
786 /// users of the value to allow the value to propagate out.
787 ///
788 Init *resolveReferences(Resolver &R) const override;
789
790 bool isComplete() const override;
791 bool isConcrete() const override;
792 std::string getAsString() const override;
793
795 return ArrayRef(getTrailingObjects<Init *>(), NumValues);
796 }
797
798 const_iterator begin() const { return getTrailingObjects<Init *>(); }
799 const_iterator end () const { return begin() + NumValues; }
800
801 size_t size () const { return NumValues; }
802 bool empty() const { return NumValues == 0; }
803
804 Init *getBit(unsigned Bit) const override {
805 llvm_unreachable("Illegal bit reference off list");
806 }
807};
808
809/// Base class for operators
810///
811class OpInit : public TypedInit {
812protected:
813 explicit OpInit(InitKind K, RecTy *Type, uint8_t Opc)
814 : TypedInit(K, Type, Opc) {}
815
816public:
817 OpInit(const OpInit &) = delete;
818 OpInit &operator=(OpInit &) = delete;
819
820 static bool classof(const Init *I) {
821 return I->getKind() >= IK_FirstOpInit &&
822 I->getKind() <= IK_LastOpInit;
823 }
824
825 // Clone - Clone this operator, replacing arguments with the new list
827
828 virtual unsigned getNumOperands() const = 0;
829 virtual Init *getOperand(unsigned i) const = 0;
830
831 Init *getBit(unsigned Bit) const override;
832};
833
834/// !op (X) - Transform an init.
835///
836class UnOpInit : public OpInit, public FoldingSetNode {
837public:
838 enum UnaryOp : uint8_t {
849 REPR
850 };
851
852private:
853 Init *LHS;
854
855 UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
856 : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
857
858public:
859 UnOpInit(const UnOpInit &) = delete;
860 UnOpInit &operator=(const UnOpInit &) = delete;
861
862 static bool classof(const Init *I) {
863 return I->getKind() == IK_UnOpInit;
864 }
865
866 static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
867
868 void Profile(FoldingSetNodeID &ID) const;
869
870 // Clone - Clone this operator, replacing arguments with the new list
872 assert(Operands.size() == 1 &&
873 "Wrong number of operands for unary operation");
874 return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
875 }
876
877 unsigned getNumOperands() const override { return 1; }
878
879 Init *getOperand(unsigned i) const override {
880 assert(i == 0 && "Invalid operand id for unary operator");
881 return getOperand();
882 }
883
884 UnaryOp getOpcode() const { return (UnaryOp)Opc; }
885 Init *getOperand() const { return LHS; }
886
887 // Fold - If possible, fold this to a simpler init. Return this if not
888 // possible to fold.
889 Init *Fold(Record *CurRec, bool IsFinal = false) const;
890
891 Init *resolveReferences(Resolver &R) const override;
892
893 std::string getAsString() const override;
894};
895
896/// !op (X, Y) - Combine two inits.
897class BinOpInit : public OpInit, public FoldingSetNode {
898public:
899 enum BinaryOp : uint8_t {
928 };
929
930private:
931 Init *LHS, *RHS;
932
933 BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
934 OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
935
936public:
937 BinOpInit(const BinOpInit &) = delete;
938 BinOpInit &operator=(const BinOpInit &) = delete;
939
940 static bool classof(const Init *I) {
941 return I->getKind() == IK_BinOpInit;
942 }
943
944 static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
945 RecTy *Type);
946 static Init *getStrConcat(Init *lhs, Init *rhs);
947 static Init *getListConcat(TypedInit *lhs, Init *rhs);
948
949 void Profile(FoldingSetNodeID &ID) const;
950
951 // Clone - Clone this operator, replacing arguments with the new list
953 assert(Operands.size() == 2 &&
954 "Wrong number of operands for binary operation");
955 return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
956 }
957
958 unsigned getNumOperands() const override { return 2; }
959 Init *getOperand(unsigned i) const override {
960 switch (i) {
961 default: llvm_unreachable("Invalid operand id for binary operator");
962 case 0: return getLHS();
963 case 1: return getRHS();
964 }
965 }
966
967 BinaryOp getOpcode() const { return (BinaryOp)Opc; }
968 Init *getLHS() const { return LHS; }
969 Init *getRHS() const { return RHS; }
970
971 std::optional<bool> CompareInit(unsigned Opc, Init *LHS, Init *RHS) const;
972
973 // Fold - If possible, fold this to a simpler init. Return this if not
974 // possible to fold.
975 Init *Fold(Record *CurRec) const;
976
977 Init *resolveReferences(Resolver &R) const override;
978
979 std::string getAsString() const override;
980};
981
982/// !op (X, Y, Z) - Combine two inits.
983class TernOpInit : public OpInit, public FoldingSetNode {
984public:
985 enum TernaryOp : uint8_t {
996 };
997
998private:
999 Init *LHS, *MHS, *RHS;
1000
1001 TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
1002 RecTy *Type) :
1003 OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
1004
1005public:
1006 TernOpInit(const TernOpInit &) = delete;
1007 TernOpInit &operator=(const TernOpInit &) = delete;
1008
1009 static bool classof(const Init *I) {
1010 return I->getKind() == IK_TernOpInit;
1011 }
1012
1013 static TernOpInit *get(TernaryOp opc, Init *lhs,
1014 Init *mhs, Init *rhs,
1015 RecTy *Type);
1016
1017 void Profile(FoldingSetNodeID &ID) const;
1018
1019 // Clone - Clone this operator, replacing arguments with the new list
1021 assert(Operands.size() == 3 &&
1022 "Wrong number of operands for ternary operation");
1023 return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
1024 getType());
1025 }
1026
1027 unsigned getNumOperands() const override { return 3; }
1028 Init *getOperand(unsigned i) const override {
1029 switch (i) {
1030 default: llvm_unreachable("Invalid operand id for ternary operator");
1031 case 0: return getLHS();
1032 case 1: return getMHS();
1033 case 2: return getRHS();
1034 }
1035 }
1036
1037 TernaryOp getOpcode() const { return (TernaryOp)Opc; }
1038 Init *getLHS() const { return LHS; }
1039 Init *getMHS() const { return MHS; }
1040 Init *getRHS() const { return RHS; }
1041
1042 // Fold - If possible, fold this to a simpler init. Return this if not
1043 // possible to fold.
1044 Init *Fold(Record *CurRec) const;
1045
1046 bool isComplete() const override {
1047 return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
1048 }
1049
1050 Init *resolveReferences(Resolver &R) const override;
1051
1052 std::string getAsString() const override;
1053};
1054
1055/// !cond(condition_1: value1, ... , condition_n: value)
1056/// Selects the first value for which condition is true.
1057/// Otherwise reports an error.
1058class CondOpInit final : public TypedInit, public FoldingSetNode,
1059 public TrailingObjects<CondOpInit, Init *> {
1060 unsigned NumConds;
1061 RecTy *ValType;
1062
1063 CondOpInit(unsigned NC, RecTy *Type)
1065 NumConds(NC), ValType(Type) {}
1066
1067 size_t numTrailingObjects(OverloadToken<Init *>) const {
1068 return 2*NumConds;
1069 }
1070
1071public:
1072 CondOpInit(const CondOpInit &) = delete;
1073 CondOpInit &operator=(const CondOpInit &) = delete;
1074
1075 static bool classof(const Init *I) {
1076 return I->getKind() == IK_CondOpInit;
1077 }
1078
1080 RecTy *Type);
1081
1082 void Profile(FoldingSetNodeID &ID) const;
1083
1084 RecTy *getValType() const { return ValType; }
1085
1086 unsigned getNumConds() const { return NumConds; }
1087
1088 Init *getCond(unsigned Num) const {
1089 assert(Num < NumConds && "Condition number out of range!");
1090 return getTrailingObjects<Init *>()[Num];
1091 }
1092
1093 Init *getVal(unsigned Num) const {
1094 assert(Num < NumConds && "Val number out of range!");
1095 return getTrailingObjects<Init *>()[Num+NumConds];
1096 }
1097
1099 return ArrayRef(getTrailingObjects<Init *>(), NumConds);
1100 }
1101
1103 return ArrayRef(getTrailingObjects<Init *>() + NumConds, NumConds);
1104 }
1105
1106 Init *Fold(Record *CurRec) const;
1107
1108 Init *resolveReferences(Resolver &R) const override;
1109
1110 bool isConcrete() const override;
1111 bool isComplete() const override;
1112 std::string getAsString() const override;
1113
1116
1117 inline const_case_iterator arg_begin() const { return getConds().begin(); }
1118 inline const_case_iterator arg_end () const { return getConds().end(); }
1119
1120 inline size_t case_size () const { return NumConds; }
1121 inline bool case_empty() const { return NumConds == 0; }
1122
1123 inline const_val_iterator name_begin() const { return getVals().begin();}
1124 inline const_val_iterator name_end () const { return getVals().end(); }
1125
1126 inline size_t val_size () const { return NumConds; }
1127 inline bool val_empty() const { return NumConds == 0; }
1128
1129 Init *getBit(unsigned Bit) const override;
1130};
1131
1132/// !foldl (a, b, expr, start, lst) - Fold over a list.
1133class FoldOpInit : public TypedInit, public FoldingSetNode {
1134private:
1135 Init *Start;
1136 Init *List;
1137 Init *A;
1138 Init *B;
1139 Init *Expr;
1140
1141 FoldOpInit(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
1142 : TypedInit(IK_FoldOpInit, Type), Start(Start), List(List), A(A), B(B),
1143 Expr(Expr) {}
1144
1145public:
1146 FoldOpInit(const FoldOpInit &) = delete;
1147 FoldOpInit &operator=(const FoldOpInit &) = delete;
1148
1149 static bool classof(const Init *I) { return I->getKind() == IK_FoldOpInit; }
1150
1151 static FoldOpInit *get(Init *Start, Init *List, Init *A, Init *B, Init *Expr,
1152 RecTy *Type);
1153
1154 void Profile(FoldingSetNodeID &ID) const;
1155
1156 // Fold - If possible, fold this to a simpler init. Return this if not
1157 // possible to fold.
1158 Init *Fold(Record *CurRec) const;
1159
1160 bool isComplete() const override { return false; }
1161
1162 Init *resolveReferences(Resolver &R) const override;
1163
1164 Init *getBit(unsigned Bit) const override;
1165
1166 std::string getAsString() const override;
1167};
1168
1169/// !isa<type>(expr) - Dynamically determine the type of an expression.
1170class IsAOpInit : public TypedInit, public FoldingSetNode {
1171private:
1172 RecTy *CheckType;
1173 Init *Expr;
1174
1175 IsAOpInit(RecTy *CheckType, Init *Expr)
1177 CheckType(CheckType), Expr(Expr) {}
1178
1179public:
1180 IsAOpInit(const IsAOpInit &) = delete;
1181 IsAOpInit &operator=(const IsAOpInit &) = delete;
1182
1183 static bool classof(const Init *I) { return I->getKind() == IK_IsAOpInit; }
1184
1185 static IsAOpInit *get(RecTy *CheckType, Init *Expr);
1186
1187 void Profile(FoldingSetNodeID &ID) const;
1188
1189 // Fold - If possible, fold this to a simpler init. Return this if not
1190 // possible to fold.
1191 Init *Fold() const;
1192
1193 bool isComplete() const override { return false; }
1194
1195 Init *resolveReferences(Resolver &R) const override;
1196
1197 Init *getBit(unsigned Bit) const override;
1198
1199 std::string getAsString() const override;
1200};
1201
1202/// !exists<type>(expr) - Dynamically determine if a record of `type` named
1203/// `expr` exists.
1204class ExistsOpInit : public TypedInit, public FoldingSetNode {
1205private:
1206 RecTy *CheckType;
1207 Init *Expr;
1208
1209 ExistsOpInit(RecTy *CheckType, Init *Expr)
1211 CheckType(CheckType), Expr(Expr) {}
1212
1213public:
1214 ExistsOpInit(const ExistsOpInit &) = delete;
1216
1217 static bool classof(const Init *I) { return I->getKind() == IK_ExistsOpInit; }
1218
1219 static ExistsOpInit *get(RecTy *CheckType, Init *Expr);
1220
1221 void Profile(FoldingSetNodeID &ID) const;
1222
1223 // Fold - If possible, fold this to a simpler init. Return this if not
1224 // possible to fold.
1225 Init *Fold(Record *CurRec, bool IsFinal = false) const;
1226
1227 bool isComplete() const override { return false; }
1228
1229 Init *resolveReferences(Resolver &R) const override;
1230
1231 Init *getBit(unsigned Bit) const override;
1232
1233 std::string getAsString() const override;
1234};
1235
1236/// 'Opcode' - Represent a reference to an entire variable object.
1237class VarInit : public TypedInit {
1238 Init *VarName;
1239
1240 explicit VarInit(Init *VN, RecTy *T)
1241 : TypedInit(IK_VarInit, T), VarName(VN) {}
1242
1243public:
1244 VarInit(const VarInit &) = delete;
1245 VarInit &operator=(const VarInit &) = delete;
1246
1247 static bool classof(const Init *I) {
1248 return I->getKind() == IK_VarInit;
1249 }
1250
1251 static VarInit *get(StringRef VN, RecTy *T);
1252 static VarInit *get(Init *VN, RecTy *T);
1253
1254 StringRef getName() const;
1255 Init *getNameInit() const { return VarName; }
1256
1257 std::string getNameInitAsString() const {
1258 return getNameInit()->getAsUnquotedString();
1259 }
1260
1261 /// This method is used by classes that refer to other
1262 /// variables which may not be defined at the time they expression is formed.
1263 /// If a value is set for the variable later, this method will be called on
1264 /// users of the value to allow the value to propagate out.
1265 ///
1266 Init *resolveReferences(Resolver &R) const override;
1267
1268 Init *getBit(unsigned Bit) const override;
1269
1270 std::string getAsString() const override { return std::string(getName()); }
1271};
1272
1273/// Opcode{0} - Represent access to one bit of a variable or field.
1274class VarBitInit final : public TypedInit {
1275 TypedInit *TI;
1276 unsigned Bit;
1277
1278 VarBitInit(TypedInit *T, unsigned B)
1279 : TypedInit(IK_VarBitInit, BitRecTy::get(T->getRecordKeeper())), TI(T),
1280 Bit(B) {
1281 assert(T->getType() &&
1282 (isa<IntRecTy>(T->getType()) ||
1283 (isa<BitsRecTy>(T->getType()) &&
1284 cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
1285 "Illegal VarBitInit expression!");
1286 }
1287
1288public:
1289 VarBitInit(const VarBitInit &) = delete;
1290 VarBitInit &operator=(const VarBitInit &) = delete;
1291
1292 static bool classof(const Init *I) {
1293 return I->getKind() == IK_VarBitInit;
1294 }
1295
1296 static VarBitInit *get(TypedInit *T, unsigned B);
1297
1298 Init *getBitVar() const { return TI; }
1299 unsigned getBitNum() const { return Bit; }
1300
1301 std::string getAsString() const override;
1302 Init *resolveReferences(Resolver &R) const override;
1303
1304 Init *getBit(unsigned B) const override {
1305 assert(B < 1 && "Bit index out of range!");
1306 return const_cast<VarBitInit*>(this);
1307 }
1308};
1309
1310/// AL - Represent a reference to a 'def' in the description
1311class DefInit : public TypedInit {
1312 friend class Record;
1313
1314 Record *Def;
1315
1316 explicit DefInit(Record *D);
1317
1318public:
1319 DefInit(const DefInit &) = delete;
1320 DefInit &operator=(const DefInit &) = delete;
1321
1322 static bool classof(const Init *I) {
1323 return I->getKind() == IK_DefInit;
1324 }
1325
1326 static DefInit *get(Record*);
1327
1328 Init *convertInitializerTo(RecTy *Ty) const override;
1329
1330 Record *getDef() const { return Def; }
1331
1332 //virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);
1333
1334 RecTy *getFieldType(StringInit *FieldName) const override;
1335
1336 bool isConcrete() const override { return true; }
1337 std::string getAsString() const override;
1338
1339 Init *getBit(unsigned Bit) const override {
1340 llvm_unreachable("Illegal bit reference off def");
1341 }
1342};
1343
1344/// classname<targs...> - Represent an uninstantiated anonymous class
1345/// instantiation.
1346class VarDefInit final : public TypedInit,
1347 public FoldingSetNode,
1348 public TrailingObjects<VarDefInit, ArgumentInit *> {
1349 Record *Class;
1350 DefInit *Def = nullptr; // after instantiation
1351 unsigned NumArgs;
1352
1353 explicit VarDefInit(Record *Class, unsigned N);
1354
1355 DefInit *instantiate();
1356
1357public:
1358 VarDefInit(const VarDefInit &) = delete;
1359 VarDefInit &operator=(const VarDefInit &) = delete;
1360
1361 // Do not use sized deallocation due to trailing objects.
1362 void operator delete(void *p) { ::operator delete(p); }
1363
1364 static bool classof(const Init *I) {
1365 return I->getKind() == IK_VarDefInit;
1366 }
1367 static VarDefInit *get(Record *Class, ArrayRef<ArgumentInit *> Args);
1368
1369 void Profile(FoldingSetNodeID &ID) const;
1370
1371 Init *resolveReferences(Resolver &R) const override;
1372 Init *Fold() const;
1373
1374 std::string getAsString() const override;
1375
1376 ArgumentInit *getArg(unsigned i) const {
1377 assert(i < NumArgs && "Argument index out of range!");
1378 return getTrailingObjects<ArgumentInit *>()[i];
1379 }
1380
1382
1384 return getTrailingObjects<ArgumentInit *>();
1385 }
1386 const_iterator args_end () const { return args_begin() + NumArgs; }
1387
1388 size_t args_size () const { return NumArgs; }
1389 bool args_empty() const { return NumArgs == 0; }
1390
1392 return ArrayRef(args_begin(), NumArgs);
1393 }
1394
1395 Init *getBit(unsigned Bit) const override {
1396 llvm_unreachable("Illegal bit reference off anonymous def");
1397 }
1398};
1399
1400/// X.Y - Represent a reference to a subfield of a variable
1401class FieldInit : public TypedInit {
1402 Init *Rec; // Record we are referring to
1403 StringInit *FieldName; // Field we are accessing
1404
1405 FieldInit(Init *R, StringInit *FN)
1406 : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
1407#ifndef NDEBUG
1408 if (!getType()) {
1409 llvm::errs() << "In Record = " << Rec->getAsString()
1410 << ", got FieldName = " << *FieldName
1411 << " with non-record type!\n";
1412 llvm_unreachable("FieldInit with non-record type!");
1413 }
1414#endif
1415 }
1416
1417public:
1418 FieldInit(const FieldInit &) = delete;
1419 FieldInit &operator=(const FieldInit &) = delete;
1420
1421 static bool classof(const Init *I) {
1422 return I->getKind() == IK_FieldInit;
1423 }
1424
1425 static FieldInit *get(Init *R, StringInit *FN);
1426
1427 Init *getRecord() const { return Rec; }
1428 StringInit *getFieldName() const { return FieldName; }
1429
1430 Init *getBit(unsigned Bit) const override;
1431
1432 Init *resolveReferences(Resolver &R) const override;
1433 Init *Fold(Record *CurRec) const;
1434
1435 bool isConcrete() const override;
1436 std::string getAsString() const override {
1437 return Rec->getAsString() + "." + FieldName->getValue().str();
1438 }
1439};
1440
1441/// (v a, b) - Represent a DAG tree value. DAG inits are required
1442/// to have at least one value then a (possibly empty) list of arguments. Each
1443/// argument can have a name associated with it.
1444class DagInit final : public TypedInit, public FoldingSetNode,
1445 public TrailingObjects<DagInit, Init *, StringInit *> {
1446 friend TrailingObjects;
1447
1448 Init *Val;
1449 StringInit *ValName;
1450 unsigned NumArgs;
1451 unsigned NumArgNames;
1452
1453 DagInit(Init *V, StringInit *VN, unsigned NumArgs, unsigned NumArgNames)
1454 : TypedInit(IK_DagInit, DagRecTy::get(V->getRecordKeeper())), Val(V),
1455 ValName(VN), NumArgs(NumArgs), NumArgNames(NumArgNames) {}
1456
1457 size_t numTrailingObjects(OverloadToken<Init *>) const { return NumArgs; }
1458
1459public:
1460 DagInit(const DagInit &) = delete;
1461 DagInit &operator=(const DagInit &) = delete;
1462
1463 static bool classof(const Init *I) {
1464 return I->getKind() == IK_DagInit;
1465 }
1466
1467 static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
1468 ArrayRef<StringInit*> NameRange);
1469 static DagInit *get(Init *V, StringInit *VN,
1470 ArrayRef<std::pair<Init*, StringInit*>> Args);
1471
1472 void Profile(FoldingSetNodeID &ID) const;
1473
1474 Init *getOperator() const { return Val; }
1476
1477 StringInit *getName() const { return ValName; }
1478
1480 return ValName ? ValName->getValue() : StringRef();
1481 }
1482
1483 unsigned getNumArgs() const { return NumArgs; }
1484
1485 Init *getArg(unsigned Num) const {
1486 assert(Num < NumArgs && "Arg number out of range!");
1487 return getTrailingObjects<Init *>()[Num];
1488 }
1489
1490 /// This method looks up the specified argument name and returns its argument
1491 /// number or std::nullopt if that argument name does not exist.
1492 std::optional<unsigned> getArgNo(StringRef Name) const;
1493
1494 StringInit *getArgName(unsigned Num) const {
1495 assert(Num < NumArgNames && "Arg number out of range!");
1496 return getTrailingObjects<StringInit *>()[Num];
1497 }
1498
1499 StringRef getArgNameStr(unsigned Num) const {
1500 StringInit *Init = getArgName(Num);
1501 return Init ? Init->getValue() : StringRef();
1502 }
1503
1505 return ArrayRef(getTrailingObjects<Init *>(), NumArgs);
1506 }
1507
1509 return ArrayRef(getTrailingObjects<StringInit *>(), NumArgNames);
1510 }
1511
1512 Init *resolveReferences(Resolver &R) const override;
1513
1514 bool isConcrete() const override;
1515 std::string getAsString() const override;
1516
1519
1520 inline const_arg_iterator arg_begin() const { return getArgs().begin(); }
1521 inline const_arg_iterator arg_end () const { return getArgs().end(); }
1522
1523 inline size_t arg_size () const { return NumArgs; }
1524 inline bool arg_empty() const { return NumArgs == 0; }
1525
1526 inline const_name_iterator name_begin() const { return getArgNames().begin();}
1527 inline const_name_iterator name_end () const { return getArgNames().end(); }
1528
1529 inline size_t name_size () const { return NumArgNames; }
1530 inline bool name_empty() const { return NumArgNames == 0; }
1531
1532 Init *getBit(unsigned Bit) const override {
1533 llvm_unreachable("Illegal bit reference off dag");
1534 }
1535};
1536
1537//===----------------------------------------------------------------------===//
1538// High-Level Classes
1539//===----------------------------------------------------------------------===//
1540
1541/// This class represents a field in a record, including its name, type,
1542/// value, and source location.
1544 friend class Record;
1545
1546public:
1548 FK_Normal, // A normal record field.
1549 FK_NonconcreteOK, // A field that can be nonconcrete ('field' keyword).
1550 FK_TemplateArg, // A template argument.
1551 };
1552
1553private:
1554 Init *Name;
1555 SMLoc Loc; // Source location of definition of name.
1557 Init *Value;
1558 bool IsUsed = false;
1559
1560 /// Reference locations to this record value.
1561 SmallVector<SMRange> ReferenceLocs;
1562
1563public:
1565 RecordVal(Init *N, SMLoc Loc, RecTy *T, FieldKind K);
1566
1567 /// Get the record keeper used to unique this value.
1568 RecordKeeper &getRecordKeeper() const { return Name->getRecordKeeper(); }
1569
1570 /// Get the name of the field as a StringRef.
1571 StringRef getName() const;
1572
1573 /// Get the name of the field as an Init.
1574 Init *getNameInit() const { return Name; }
1575
1576 /// Get the name of the field as a std::string.
1577 std::string getNameInitAsString() const {
1578 return getNameInit()->getAsUnquotedString();
1579 }
1580
1581 /// Get the source location of the point where the field was defined.
1582 const SMLoc &getLoc() const { return Loc; }
1583
1584 /// Is this a field where nonconcrete values are okay?
1585 bool isNonconcreteOK() const {
1586 return TyAndKind.getInt() == FK_NonconcreteOK;
1587 }
1588
1589 /// Is this a template argument?
1590 bool isTemplateArg() const {
1591 return TyAndKind.getInt() == FK_TemplateArg;
1592 }
1593
1594 /// Get the type of the field value as a RecTy.
1595 RecTy *getType() const { return TyAndKind.getPointer(); }
1596
1597 /// Get the type of the field for printing purposes.
1598 std::string getPrintType() const;
1599
1600 /// Get the value of the field as an Init.
1601 Init *getValue() const { return Value; }
1602
1603 /// Set the value of the field from an Init.
1604 bool setValue(Init *V);
1605
1606 /// Set the value and source location of the field.
1607 bool setValue(Init *V, SMLoc NewLoc);
1608
1609 /// Add a reference to this record value.
1610 void addReferenceLoc(SMRange Loc) { ReferenceLocs.push_back(Loc); }
1611
1612 /// Return the references of this record value.
1613 ArrayRef<SMRange> getReferenceLocs() const { return ReferenceLocs; }
1614
1615 /// Whether this value is used. Useful for reporting warnings, for example
1616 /// when a template argument is unused.
1617 void setUsed(bool Used) { IsUsed = Used; }
1618 bool isUsed() const { return IsUsed; }
1619
1620 void dump() const;
1621
1622 /// Print the value to an output stream, possibly with a semicolon.
1623 void print(raw_ostream &OS, bool PrintSem = true) const;
1624};
1625
1627 RV.print(OS << " ");
1628 return OS;
1629}
1630
1631class Record {
1632public:
1637
1638 // User-defined constructor to support std::make_unique(). It can be
1639 // removed in C++20 when braced initialization is supported.
1642 };
1643
1644 struct DumpInfo {
1647
1648 // User-defined constructor to support std::make_unique(). It can be
1649 // removed in C++20 when braced initialization is supported.
1651 };
1652
1654
1655private:
1656 Init *Name;
1657 // Location where record was instantiated, followed by the location of
1658 // multiclass prototypes used, and finally by the locations of references to
1659 // this record.
1661 SmallVector<SMLoc, 0> ForwardDeclarationLocs;
1662 SmallVector<SMRange, 0> ReferenceLocs;
1667
1668 // All superclasses in the inheritance forest in post-order (yes, it
1669 // must be a forest; diamond-shaped inheritance is not allowed).
1671
1672 // Tracks Record instances. Not owned by Record.
1673 RecordKeeper &TrackedRecords;
1674
1675 // The DefInit corresponding to this record.
1676 DefInit *CorrespondingDefInit = nullptr;
1677
1678 // Unique record ID.
1679 unsigned ID;
1680
1681 RecordKind Kind;
1682
1683 void checkName();
1684
1685public:
1686 // Constructs a record.
1687 explicit Record(Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1688 RecordKind Kind = RK_Def)
1689 : Name(N), Locs(locs), TrackedRecords(records),
1690 ID(getNewUID(N->getRecordKeeper())), Kind(Kind) {
1691 checkName();
1692 }
1693
1695 RecordKind Kind = RK_Def)
1696 : Record(StringInit::get(records, N), locs, records, Kind) {}
1697
1698 // When copy-constructing a Record, we must still guarantee a globally unique
1699 // ID number. Don't copy CorrespondingDefInit either, since it's owned by the
1700 // original record. All other fields can be copied normally.
1701 Record(const Record &O)
1702 : Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
1703 Values(O.Values), Assertions(O.Assertions),
1704 SuperClasses(O.SuperClasses), TrackedRecords(O.TrackedRecords),
1705 ID(getNewUID(O.getRecords())), Kind(O.Kind) {}
1706
1707 static unsigned getNewUID(RecordKeeper &RK);
1708
1709 unsigned getID() const { return ID; }
1710
1711 StringRef getName() const { return cast<StringInit>(Name)->getValue(); }
1712
1714 return Name;
1715 }
1716
1717 std::string getNameInitAsString() const {
1718 return getNameInit()->getAsUnquotedString();
1719 }
1720
1721 void setName(Init *Name); // Also updates RecordKeeper.
1722
1723 ArrayRef<SMLoc> getLoc() const { return Locs; }
1724 void appendLoc(SMLoc Loc) { Locs.push_back(Loc); }
1725
1727 return ForwardDeclarationLocs;
1728 }
1729
1730 /// Add a reference to this record value.
1731 void appendReferenceLoc(SMRange Loc) { ReferenceLocs.push_back(Loc); }
1732
1733 /// Return the references of this record value.
1734 ArrayRef<SMRange> getReferenceLocs() const { return ReferenceLocs; }
1735
1736 // Update a class location when encountering a (re-)definition.
1737 void updateClassLoc(SMLoc Loc);
1738
1739 // Make the type that this record should have based on its superclasses.
1741
1742 /// get the corresponding DefInit.
1744
1745 bool isClass() const { return Kind == RK_Class; }
1746
1747 bool isMultiClass() const { return Kind == RK_MultiClass; }
1748
1749 bool isAnonymous() const { return Kind == RK_AnonymousDef; }
1750
1752 return TemplateArgs;
1753 }
1754
1755 ArrayRef<RecordVal> getValues() const { return Values; }
1756
1757 ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
1758 ArrayRef<DumpInfo> getDumps() const { return Dumps; }
1759
1761 return SuperClasses;
1762 }
1763
1764 /// Determine whether this record has the specified direct superclass.
1765 bool hasDirectSuperClass(const Record *SuperClass) const;
1766
1767 /// Append the direct superclasses of this record to Classes.
1769
1770 bool isTemplateArg(Init *Name) const {
1771 return llvm::is_contained(TemplateArgs, Name);
1772 }
1773
1774 const RecordVal *getValue(const Init *Name) const {
1775 for (const RecordVal &Val : Values)
1776 if (Val.Name == Name) return &Val;
1777 return nullptr;
1778 }
1779
1780 const RecordVal *getValue(StringRef Name) const {
1781 return getValue(StringInit::get(getRecords(), Name));
1782 }
1783
1784 RecordVal *getValue(const Init *Name) {
1785 return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
1786 }
1787
1789 return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
1790 }
1791
1792 void addTemplateArg(Init *Name) {
1793 assert(!isTemplateArg(Name) && "Template arg already defined!");
1794 TemplateArgs.push_back(Name);
1795 }
1796
1797 void addValue(const RecordVal &RV) {
1798 assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
1799 Values.push_back(RV);
1800 }
1801
1802 void removeValue(Init *Name) {
1803 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1804 if (Values[i].getNameInit() == Name) {
1805 Values.erase(Values.begin()+i);
1806 return;
1807 }
1808 llvm_unreachable("Cannot remove an entry that does not exist!");
1809 }
1810
1813 }
1814
1815 void addAssertion(SMLoc Loc, Init *Condition, Init *Message) {
1816 Assertions.push_back(AssertionInfo(Loc, Condition, Message));
1817 }
1818
1819 void addDump(SMLoc Loc, Init *Message) {
1820 Dumps.push_back(DumpInfo(Loc, Message));
1821 }
1822
1823 void appendAssertions(const Record *Rec) {
1824 Assertions.append(Rec->Assertions);
1825 }
1826
1827 void appendDumps(const Record *Rec) { Dumps.append(Rec->Dumps); }
1828
1829 void checkRecordAssertions();
1830 void emitRecordDumps();
1832
1833 bool isSubClassOf(const Record *R) const {
1834 for (const auto &SCPair : SuperClasses)
1835 if (SCPair.first == R)
1836 return true;
1837 return false;
1838 }
1839
1840 bool isSubClassOf(StringRef Name) const {
1841 for (const auto &SCPair : SuperClasses) {
1842 if (const auto *SI = dyn_cast<StringInit>(SCPair.first->getNameInit())) {
1843 if (SI->getValue() == Name)
1844 return true;
1845 } else if (SCPair.first->getNameInitAsString() == Name) {
1846 return true;
1847 }
1848 }
1849 return false;
1850 }
1851
1853 assert(!CorrespondingDefInit &&
1854 "changing type of record after it has been referenced");
1855 assert(!isSubClassOf(R) && "Already subclassing record!");
1856 SuperClasses.push_back(std::make_pair(R, Range));
1857 }
1858
1859 /// If there are any field references that refer to fields that have been
1860 /// filled in, we can propagate the values now.
1861 ///
1862 /// This is a final resolve: any error messages, e.g. due to undefined !cast
1863 /// references, are generated now.
1864 void resolveReferences(Init *NewName = nullptr);
1865
1866 /// Apply the resolver to the name of the record as well as to the
1867 /// initializers of all fields of the record except SkipVal.
1868 ///
1869 /// The resolver should not resolve any of the fields itself, to avoid
1870 /// recursion / infinite loops.
1871 void resolveReferences(Resolver &R, const RecordVal *SkipVal = nullptr);
1872
1874 return TrackedRecords;
1875 }
1876
1877 void dump() const;
1878
1879 //===--------------------------------------------------------------------===//
1880 // High-level methods useful to tablegen back-ends
1881 //
1882
1883 /// Return the source location for the named field.
1884 SMLoc getFieldLoc(StringRef FieldName) const;
1885
1886 /// Return the initializer for a value with the specified name, or throw an
1887 /// exception if the field does not exist.
1888 Init *getValueInit(StringRef FieldName) const;
1889
1890 /// Return true if the named field is unset.
1891 bool isValueUnset(StringRef FieldName) const {
1892 return isa<UnsetInit>(getValueInit(FieldName));
1893 }
1894
1895 /// This method looks up the specified field and returns its value as a
1896 /// string, throwing an exception if the field does not exist or if the value
1897 /// is not a string.
1898 StringRef getValueAsString(StringRef FieldName) const;
1899
1900 /// This method looks up the specified field and returns its value as a
1901 /// string, throwing an exception if the value is not a string and
1902 /// std::nullopt if the field does not exist.
1903 std::optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
1904
1905 /// This method looks up the specified field and returns its value as a
1906 /// BitsInit, throwing an exception if the field does not exist or if the
1907 /// value is not the right type.
1908 BitsInit *getValueAsBitsInit(StringRef FieldName) const;
1909
1910 /// This method looks up the specified field and returns its value as a
1911 /// ListInit, throwing an exception if the field does not exist or if the
1912 /// value is not the right type.
1913 ListInit *getValueAsListInit(StringRef FieldName) const;
1914
1915 /// This method looks up the specified field and returns its value as a
1916 /// vector of records, throwing an exception if the field does not exist or
1917 /// if the value is not the right type.
1918 std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
1919
1920 /// This method looks up the specified field and returns its value as a
1921 /// vector of integers, throwing an exception if the field does not exist or
1922 /// if the value is not the right type.
1923 std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
1924
1925 /// This method looks up the specified field and returns its value as a
1926 /// vector of strings, throwing an exception if the field does not exist or
1927 /// if the value is not the right type.
1928 std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
1929
1930 /// This method looks up the specified field and returns its value as a
1931 /// Record, throwing an exception if the field does not exist or if the value
1932 /// is not the right type.
1933 Record *getValueAsDef(StringRef FieldName) const;
1934
1935 /// This method looks up the specified field and returns its value as a
1936 /// Record, returning null if the field exists but is "uninitialized" (i.e.
1937 /// set to `?`), and throwing an exception if the field does not exist or if
1938 /// its value is not the right type.
1939 Record *getValueAsOptionalDef(StringRef FieldName) const;
1940
1941 /// This method looks up the specified field and returns its value as a bit,
1942 /// throwing an exception if the field does not exist or if the value is not
1943 /// the right type.
1944 bool getValueAsBit(StringRef FieldName) const;
1945
1946 /// This method looks up the specified field and returns its value as a bit.
1947 /// If the field is unset, sets Unset to true and returns false.
1948 bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
1949
1950 /// This method looks up the specified field and returns its value as an
1951 /// int64_t, throwing an exception if the field does not exist or if the
1952 /// value is not the right type.
1953 int64_t getValueAsInt(StringRef FieldName) const;
1954
1955 /// This method looks up the specified field and returns its value as an Dag,
1956 /// throwing an exception if the field does not exist or if the value is not
1957 /// the right type.
1958 DagInit *getValueAsDag(StringRef FieldName) const;
1959};
1960
1961raw_ostream &operator<<(raw_ostream &OS, const Record &R);
1962
1964 using RecordMap = std::map<std::string, std::unique_ptr<Record>, std::less<>>;
1965 using GlobalMap = std::map<std::string, Init *, std::less<>>;
1966
1967public:
1968 RecordKeeper();
1970
1971 /// Return the internal implementation of the RecordKeeper.
1973
1974 /// Get the main TableGen input file's name.
1975 const std::string getInputFilename() const { return InputFilename; }
1976
1977 /// Get the map of classes.
1978 const RecordMap &getClasses() const { return Classes; }
1979
1980 /// Get the map of records (defs).
1981 const RecordMap &getDefs() const { return Defs; }
1982
1983 /// Get the map of global variables.
1984 const GlobalMap &getGlobals() const { return ExtraGlobals; }
1985
1986 /// Get the class with the specified name.
1988 auto I = Classes.find(Name);
1989 return I == Classes.end() ? nullptr : I->second.get();
1990 }
1991
1992 /// Get the concrete record with the specified name.
1994 auto I = Defs.find(Name);
1995 return I == Defs.end() ? nullptr : I->second.get();
1996 }
1997
1998 /// Get the \p Init value of the specified global variable.
2000 if (Record *R = getDef(Name))
2001 return R->getDefInit();
2002 auto It = ExtraGlobals.find(Name);
2003 return It == ExtraGlobals.end() ? nullptr : It->second;
2004 }
2005
2006 void saveInputFilename(std::string Filename) {
2007 InputFilename = Filename;
2008 }
2009
2010 void addClass(std::unique_ptr<Record> R) {
2011 bool Ins = Classes.insert(std::make_pair(std::string(R->getName()),
2012 std::move(R))).second;
2013 (void)Ins;
2014 assert(Ins && "Class already exists");
2015 }
2016
2017 void addDef(std::unique_ptr<Record> R) {
2018 bool Ins = Defs.insert(std::make_pair(std::string(R->getName()),
2019 std::move(R))).second;
2020 (void)Ins;
2021 assert(Ins && "Record already exists");
2022 }
2023
2025 bool Ins = ExtraGlobals.insert(std::make_pair(std::string(Name), I)).second;
2026 (void)Ins;
2027 assert(!getDef(Name));
2028 assert(Ins && "Global already exists");
2029 }
2030
2032
2033 /// Start phase timing; called if the --time-phases option is specified.
2035 TimingGroup = new TimerGroup("TableGen", "TableGen Phase Timing");
2036 }
2037
2038 /// Start timing a phase. Automatically stops any previous phase timer.
2040
2041 /// Stop timing a phase.
2042 void stopTimer();
2043
2044 /// Start timing the overall backend. If the backend itself starts a timer,
2045 /// then this timer is cleared.
2047
2048 /// Stop timing the overall backend.
2049 void stopBackendTimer();
2050
2051 /// Stop phase timing and print the report.
2053 if (TimingGroup)
2054 delete TimingGroup;
2055 }
2056
2057 //===--------------------------------------------------------------------===//
2058 // High-level helper methods, useful for tablegen backends.
2059
2060 /// Get all the concrete records that inherit from the one specified
2061 /// class. The class must be defined.
2062 std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
2063
2064 /// Get all the concrete records that inherit from all the specified
2065 /// classes. The classes must be defined.
2066 std::vector<Record *> getAllDerivedDefinitions(
2067 ArrayRef<StringRef> ClassNames) const;
2068
2069 /// Get all the concrete records that inherit from specified class, if the
2070 /// class is defined. Returns an empty vector if the class is not defined.
2071 std::vector<Record *>
2073
2074 void dump() const;
2075
2076private:
2077 RecordKeeper(RecordKeeper &&) = delete;
2078 RecordKeeper(const RecordKeeper &) = delete;
2079 RecordKeeper &operator=(RecordKeeper &&) = delete;
2080 RecordKeeper &operator=(const RecordKeeper &) = delete;
2081
2082 std::string InputFilename;
2083 RecordMap Classes, Defs;
2084 mutable StringMap<std::vector<Record *>> ClassRecordsMap;
2085 GlobalMap ExtraGlobals;
2086
2087 // These members are for the phase timing feature. We need a timer group,
2088 // the last timer started, and a flag to say whether the last timer
2089 // is the special "backend overall timer."
2090 TimerGroup *TimingGroup = nullptr;
2091 Timer *LastTimer = nullptr;
2092 bool BackendTimer = false;
2093
2094 /// The internal uniquer implementation of the RecordKeeper.
2095 std::unique_ptr<detail::RecordKeeperImpl> Impl;
2096};
2097
2098/// Sorting predicate to sort record pointers by name.
2100 bool operator()(const Record *Rec1, const Record *Rec2) const {
2101 return Rec1->getName().compare_numeric(Rec2->getName()) < 0;
2102 }
2103};
2104
2105/// Sorting predicate to sort record pointers by their
2106/// unique ID. If you just need a deterministic order, use this, since it
2107/// just compares two `unsigned`; the other sorting predicates require
2108/// string manipulation.
2110 bool operator()(const Record *LHS, const Record *RHS) const {
2111 return LHS->getID() < RHS->getID();
2112 }
2113};
2114
2115/// Sorting predicate to sort record pointers by their Name field.
2117 bool operator()(const Record *Rec1, const Record *Rec2) const {
2118 return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
2119 }
2120};
2121
2125
2127 if (Rec.empty())
2128 return;
2129
2130 size_t Len = 0;
2131 const char *Start = Rec.data();
2132 const char *Curr = Start;
2133 bool IsDigitPart = isDigit(Curr[0]);
2134 for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
2135 bool IsDigit = isDigit(Curr[I]);
2136 if (IsDigit != IsDigitPart) {
2137 Parts.push_back(std::make_pair(IsDigitPart, StringRef(Start, Len)));
2138 Len = 0;
2139 Start = &Curr[I];
2140 IsDigitPart = isDigit(Curr[I]);
2141 }
2142 }
2143 // Push the last part.
2144 Parts.push_back(std::make_pair(IsDigitPart, StringRef(Start, Len)));
2145 }
2146
2147 size_t size() { return Parts.size(); }
2148
2149 std::pair<bool, StringRef> getPart(size_t i) {
2150 assert (i < Parts.size() && "Invalid idx!");
2151 return Parts[i];
2152 }
2153 };
2154
2155 bool operator()(const Record *Rec1, const Record *Rec2) const {
2156 int64_t LHSPositionOrder = Rec1->getValueAsInt("PositionOrder");
2157 int64_t RHSPositionOrder = Rec2->getValueAsInt("PositionOrder");
2158 if (LHSPositionOrder != RHSPositionOrder)
2159 return LHSPositionOrder < RHSPositionOrder;
2160
2161 RecordParts LHSParts(StringRef(Rec1->getName()));
2162 RecordParts RHSParts(StringRef(Rec2->getName()));
2163
2164 size_t LHSNumParts = LHSParts.size();
2165 size_t RHSNumParts = RHSParts.size();
2166 assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
2167
2168 if (LHSNumParts != RHSNumParts)
2169 return LHSNumParts < RHSNumParts;
2170
2171 // We expect the registers to be of the form [_a-zA-Z]+([0-9]*[_a-zA-Z]*)*.
2172 for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
2173 std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
2174 std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
2175 // Expect even part to always be alpha.
2176 assert (LHSPart.first == false && RHSPart.first == false &&
2177 "Expected both parts to be alpha.");
2178 if (int Res = LHSPart.second.compare(RHSPart.second))
2179 return Res < 0;
2180 }
2181 for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
2182 std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
2183 std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
2184 // Expect odd part to always be numeric.
2185 assert (LHSPart.first == true && RHSPart.first == true &&
2186 "Expected both parts to be numeric.");
2187 if (LHSPart.second.size() != RHSPart.second.size())
2188 return LHSPart.second.size() < RHSPart.second.size();
2189
2190 unsigned LHSVal, RHSVal;
2191
2192 bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
2193 assert(!LHSFailed && "Unable to convert LHS to integer.");
2194 bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
2195 assert(!RHSFailed && "Unable to convert RHS to integer.");
2196
2197 if (LHSVal != RHSVal)
2198 return LHSVal < RHSVal;
2199 }
2200 return LHSNumParts < RHSNumParts;
2201 }
2202};
2203
2204raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
2205
2206//===----------------------------------------------------------------------===//
2207// Resolvers
2208//===----------------------------------------------------------------------===//
2209
2210/// Interface for looking up the initializer for a variable name, used by
2211/// Init::resolveReferences.
2213 Record *CurRec;
2214 bool IsFinal = false;
2215
2216public:
2217 explicit Resolver(Record *CurRec) : CurRec(CurRec) {}
2218 virtual ~Resolver() = default;
2219
2220 Record *getCurrentRecord() const { return CurRec; }
2221
2222 /// Return the initializer for the given variable name (should normally be a
2223 /// StringInit), or nullptr if the name could not be resolved.
2224 virtual Init *resolve(Init *VarName) = 0;
2225
2226 // Whether bits in a BitsInit should stay unresolved if resolving them would
2227 // result in a ? (UnsetInit). This behavior is used to represent instruction
2228 // encodings by keeping references to unset variables within a record.
2229 virtual bool keepUnsetBits() const { return false; }
2230
2231 // Whether this is the final resolve step before adding a record to the
2232 // RecordKeeper. Error reporting during resolve and related constant folding
2233 // should only happen when this is true.
2234 bool isFinal() const { return IsFinal; }
2235
2236 void setFinal(bool Final) { IsFinal = Final; }
2237};
2238
2239/// Resolve arbitrary mappings.
2240class MapResolver final : public Resolver {
2241 struct MappedValue {
2242 Init *V;
2243 bool Resolved;
2244
2245 MappedValue() : V(nullptr), Resolved(false) {}
2246 MappedValue(Init *V, bool Resolved) : V(V), Resolved(Resolved) {}
2247 };
2248
2250
2251public:
2252 explicit MapResolver(Record *CurRec = nullptr) : Resolver(CurRec) {}
2253
2254 void set(Init *Key, Init *Value) { Map[Key] = {Value, false}; }
2255
2256 bool isComplete(Init *VarName) const {
2257 auto It = Map.find(VarName);
2258 assert(It != Map.end() && "key must be present in map");
2259 return It->second.V->isComplete();
2260 }
2261
2262 Init *resolve(Init *VarName) override;
2263};
2264
2265/// Resolve all variables from a record except for unset variables.
2266class RecordResolver final : public Resolver {
2269 Init *Name = nullptr;
2270
2271public:
2272 explicit RecordResolver(Record &R) : Resolver(&R) {}
2273
2274 void setName(Init *NewName) { Name = NewName; }
2275
2276 Init *resolve(Init *VarName) override;
2277
2278 bool keepUnsetBits() const override { return true; }
2279};
2280
2281/// Delegate resolving to a sub-resolver, but shadow some variable names.
2282class ShadowResolver final : public Resolver {
2283 Resolver &R;
2284 DenseSet<Init *> Shadowed;
2285
2286public:
2288 : Resolver(R.getCurrentRecord()), R(R) {
2289 setFinal(R.isFinal());
2290 }
2291
2292 void addShadow(Init *Key) { Shadowed.insert(Key); }
2293
2294 Init *resolve(Init *VarName) override {
2295 if (Shadowed.count(VarName))
2296 return nullptr;
2297 return R.resolve(VarName);
2298 }
2299};
2300
2301/// (Optionally) delegate resolving to a sub-resolver, and keep track whether
2302/// there were unresolved references.
2303class TrackUnresolvedResolver final : public Resolver {
2304 Resolver *R;
2305 bool FoundUnresolved = false;
2306
2307public:
2308 explicit TrackUnresolvedResolver(Resolver *R = nullptr)
2309 : Resolver(R ? R->getCurrentRecord() : nullptr), R(R) {}
2310
2311 bool foundUnresolved() const { return FoundUnresolved; }
2312
2313 Init *resolve(Init *VarName) override;
2314};
2315
2316/// Do not resolve anything, but keep track of whether a given variable was
2317/// referenced.
2318class HasReferenceResolver final : public Resolver {
2319 Init *VarNameToTrack;
2320 bool Found = false;
2321
2322public:
2323 explicit HasReferenceResolver(Init *VarNameToTrack)
2324 : Resolver(nullptr), VarNameToTrack(VarNameToTrack) {}
2325
2326 bool found() const { return Found; }
2327
2328 Init *resolve(Init *VarName) override;
2329};
2330
2331void EmitDetailedRecords(RecordKeeper &RK, raw_ostream &OS);
2332void EmitJSON(RecordKeeper &RK, raw_ostream &OS);
2333
2334} // end namespace llvm
2335
2336#endif // LLVM_TABLEGEN_RECORD_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
std::string Name
This file defines a hash set that can be used to remove duplication of nodes in a graph.
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
Load MIR Sample Profile
#define T1
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the PointerIntPair class.
const NodeList & List
Definition: RDFGraph.cpp:201
static bool isDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
This header defines support for implementing classes that have some trailing object (or arrays of obj...
Value * RHS
Value * LHS
"anonymous_n" - Represent an anonymous record name
Definition: Record.h:661
unsigned getValue() const
Definition: Record.h:677
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:622
StringInit * getNameInit() const
Definition: Record.cpp:614
static AnonymousNameInit * get(RecordKeeper &RK, unsigned)
Definition: Record.cpp:610
AnonymousNameInit(const AnonymousNameInit &)=delete
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:685
static bool classof(const Init *I)
Definition: Record.h:671
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:618
AnonymousNameInit & operator=(const AnonymousNameInit &)=delete
Init * getName() const
Definition: Record.h:520
static bool classof(const Init *I)
Definition: Record.h:506
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:539
ArgumentInit * cloneWithValue(Init *Value) const
Definition: Record.h:524
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:540
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.h:541
bool isNamed() const
Definition: Record.h:513
ArgumentInit(Init *Value, ArgAuxType Aux)
Definition: Record.h:499
Init * convertInitializerTo(RecTy *Ty) const override
Convert to a value whose type is Ty, or return null if this is not possible.
Definition: Record.h:542
bool isPositional() const
Definition: Record.h:512
static ArgumentInit * get(Init *Value, ArgAuxType Aux)
Definition: Record.cpp:384
ArgumentInit(const ArgumentInit &)=delete
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:399
ArgumentInit & operator=(const ArgumentInit &)=delete
Init * getValue() const
Definition: Record.h:515
RecordKeeper & getRecordKeeper() const
Definition: Record.h:508
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:538
unsigned getIndex() const
Definition: Record.h:516
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.h:529
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
!op (X, Y) - Combine two inits.
Definition: Record.h:897
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:1474
Init * getLHS() const
Definition: Record.h:968
Init * getRHS() const
Definition: Record.h:969
OpInit * clone(ArrayRef< Init * > Operands) const override
Definition: Record.h:952
std::optional< bool > CompareInit(unsigned Opc, Init *LHS, Init *RHS) const
Definition: Record.cpp:1098
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1484
unsigned getNumOperands() const override
Definition: Record.h:958
BinaryOp getOpcode() const
Definition: Record.h:967
BinOpInit & operator=(const BinOpInit &)=delete
Init * getOperand(unsigned i) const override
Definition: Record.h:959
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1208
static Init * getStrConcat(Init *lhs, Init *rhs)
Definition: Record.cpp:1071
static bool classof(const Init *I)
Definition: Record.h:940
static Init * getListConcat(TypedInit *lhs, Init *rhs)
Definition: Record.cpp:1088
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:1001
BinOpInit(const BinOpInit &)=delete
'true'/'false' - Represent a concrete initializer for a bit.
Definition: Record.h:548
BitInit(const BitInit &)=delete
static BitInit * get(RecordKeeper &RK, bool V)
Definition: Record.cpp:407
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.h:575
BitInit & operator=(BitInit &)=delete
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:411
bool getValue() const
Definition: Record.h:565
static bool classof(const Init *I)
Definition: Record.h:559
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:569
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:574
'bit' - Represent a single bit
Definition: Record.h:110
static BitRecTy * get(RecordKeeper &RK)
Definition: Record.cpp:120
static bool classof(const RecTy *RT)
Definition: Record.h:116
std::string getAsString() const override
Definition: Record.h:122
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:124
'{ a, b, c }' - Represents an initializer for a BitsRecTy value.
Definition: Record.h:581
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:607
bool allInComplete() const
Definition: Record.h:613
Init * resolveReferences(Resolver &R) const override
This function is used by classes that refer to other variables which may not be defined at the time t...
Definition: Record.cpp:517
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:503
static bool classof(const Init *I)
Definition: Record.h:594
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:624
unsigned getNumBits() const
Definition: Record.h:602
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This function is used to implement the bit range selection operator.
Definition: Record.cpp:484
BitsInit & operator=(const BitsInit &)=delete
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:457
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:495
BitsInit(const BitsInit &)=delete
static BitsInit * get(RecordKeeper &RK, ArrayRef< Init * > Range)
Definition: Record.cpp:435
'bits<n>' - Represent a fixed number of bits
Definition: Record.h:128
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:146
unsigned getNumBits() const
Definition: Record.h:141
static bool classof(const RecTy *RT)
Definition: Record.h:135
std::string getAsString() const override
Definition: Record.cpp:142
static BitsRecTy * get(RecordKeeper &RK, unsigned Sz)
Definition: Record.cpp:132
!cond(condition_1: value1, ... , condition_n: value) Selects the first value for which condition is t...
Definition: Record.h:1059
CondOpInit & operator=(const CondOpInit &)=delete
Init * getCond(unsigned Num) const
Definition: Record.h:1088
const_val_iterator name_end() const
Definition: Record.h:1124
bool case_empty() const
Definition: Record.h:1121
const_case_iterator arg_end() const
Definition: Record.h:1118
ArrayRef< Init * > getVals() const
Definition: Record.h:1102
static CondOpInit * get(ArrayRef< Init * > C, ArrayRef< Init * > V, RecTy *Type)
Definition: Record.cpp:2435
size_t case_size() const
Definition: Record.h:1120
CondOpInit(const CondOpInit &)=delete
ArrayRef< Init * > getConds() const
Definition: Record.h:1098
size_t val_size() const
Definition: Record.h:1126
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:2505
SmallVectorImpl< Init * >::const_iterator const_case_iterator
Definition: Record.h:1114
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:2540
const_val_iterator name_begin() const
Definition: Record.h:1123
SmallVectorImpl< Init * >::const_iterator const_val_iterator
Definition: Record.h:1115
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2529
Init * Fold(Record *CurRec) const
Definition: Record.cpp:2483
unsigned getNumConds() const
Definition: Record.h:1086
RecTy * getValType() const
Definition: Record.h:1084
Init * getVal(unsigned Num) const
Definition: Record.h:1093
bool val_empty() const
Definition: Record.h:1127
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:2460
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.cpp:2517
static bool classof(const Init *I)
Definition: Record.h:1075
const_case_iterator arg_begin() const
Definition: Record.h:1117
(v a, b) - Represent a DAG tree value.
Definition: Record.h:1445
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:2636
unsigned getNumArgs() const
Definition: Record.h:1483
std::optional< unsigned > getArgNo(StringRef Name) const
This method looks up the specified argument name and returns its argument number or std::nullopt if t...
Definition: Record.cpp:2610
StringInit * getName() const
Definition: Record.h:1477
Init * getOperator() const
Definition: Record.h:1474
size_t name_size() const
Definition: Record.h:1529
DagInit(const DagInit &)=delete
StringInit * getArgName(unsigned Num) const
Definition: Record.h:1494
StringRef getArgNameStr(unsigned Num) const
Definition: Record.h:1499
Record * getOperatorAsDef(ArrayRef< SMLoc > Loc) const
Definition: Record.cpp:2603
const_arg_iterator arg_begin() const
Definition: Record.h:1520
const_arg_iterator arg_end() const
Definition: Record.h:1521
ArrayRef< StringInit * > getArgNames() const
Definition: Record.h:1508
static DagInit * get(Init *V, StringInit *VN, ArrayRef< Init * > ArgRange, ArrayRef< StringInit * > NameRange)
Definition: Record.cpp:2560
Init * getArg(unsigned Num) const
Definition: Record.h:1485
static bool classof(const Init *I)
Definition: Record.h:1463
bool name_empty() const
Definition: Record.h:1530
SmallVectorImpl< StringInit * >::const_iterator const_name_iterator
Definition: Record.h:1518
const_name_iterator name_end() const
Definition: Record.h:1527
ArrayRef< Init * > getArgs() const
Definition: Record.h:1504
const_name_iterator name_begin() const
Definition: Record.h:1526
size_t arg_size() const
Definition: Record.h:1523
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:1532
bool arg_empty() const
Definition: Record.h:1524
StringRef getNameStr() const
Definition: Record.h:1479
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:2619
DagInit & operator=(const DagInit &)=delete
SmallVectorImpl< Init * >::const_iterator const_arg_iterator
Definition: Record.h:1517
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2646
'dag' - Represent a dag fragment
Definition: Record.h:210
std::string getAsString() const override
Definition: Record.cpp:195
static DagRecTy * get(RecordKeeper &RK)
Definition: Record.cpp:191
static bool classof(const RecTy *RT)
Definition: Record.h:216
AL - Represent a reference to a 'def' in the description.
Definition: Record.h:1311
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:2213
DefInit & operator=(const DefInit &)=delete
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2226
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:1339
RecTy * getFieldType(StringInit *FieldName) const override
This method is used to implement the FieldInit class.
Definition: Record.cpp:2220
DefInit(const DefInit &)=delete
static bool classof(const Init *I)
Definition: Record.h:1322
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:1336
static DefInit * get(Record *)
Definition: Record.cpp:2209
Record * getDef() const
Definition: Record.h:1330
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
!exists<type>(expr) - Dynamically determine if a record of type named expr exists.
Definition: Record.h:1204
static bool classof(const Init *I)
Definition: Record.h:1217
Init * Fold(Record *CurRec, bool IsFinal=false) const
Definition: Record.cpp:2049
ExistsOpInit(const ExistsOpInit &)=delete
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:1227
static ExistsOpInit * get(RecTy *CheckType, Init *Expr)
Definition: Record.cpp:2031
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2094
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:2083
ExistsOpInit & operator=(const ExistsOpInit &)=delete
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:2090
X.Y - Represent a reference to a subfield of a variable.
Definition: Record.h:1401
static bool classof(const Init *I)
Definition: Record.h:1421
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.h:1436
Init * getRecord() const
Definition: Record.h:1427
StringInit * getFieldName() const
Definition: Record.h:1428
Init * Fold(Record *CurRec) const
Definition: Record.cpp:2390
static FieldInit * get(Init *R, StringInit *FN)
Definition: Record.cpp:2369
FieldInit & operator=(const FieldInit &)=delete
FieldInit(const FieldInit &)=delete
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:2377
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:2383
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:2405
!foldl (a, b, expr, start, lst) - Fold over a list.
Definition: Record.h:1133
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:1937
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:1952
static bool classof(const Init *I)
Definition: Record.h:1149
FoldOpInit & operator=(const FoldOpInit &)=delete
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1956
FoldOpInit(const FoldOpInit &)=delete
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1923
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:1160
static FoldOpInit * get(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
Definition: Record.cpp:1904
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:138
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:327
Do not resolve anything, but keep track of whether a given variable was referenced.
Definition: Record.h:2318
HasReferenceResolver(Init *VarNameToTrack)
Definition: Record.h:2323
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:3327
uint8_t Opc
Definition: Record.h:329
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:399
virtual std::string getAsUnquotedString() const
Convert this value to a literal form, without adding quotes around a string.
Definition: Record.h:364
void dump() const
Debugging method that may be called through a debugger; just invokes print on stderr.
Definition: Record.cpp:346
void print(raw_ostream &OS) const
Print this value.
Definition: Record.h:357
virtual std::string getAsString() const =0
Convert this value to a literal form.
InitKind
Discriminator enum (for isa<>, dyn_cast<>, et al.)
Definition: Record.h:296
@ IK_FoldOpInit
Definition: Record.h:312
@ IK_IntInit
Definition: Record.h:304
@ IK_LastTypedInit
Definition: Record.h:320
@ IK_UnsetInit
Definition: Record.h:321
@ IK_DagInit
Definition: Record.h:301
@ IK_VarBitInit
Definition: Record.h:318
@ IK_ListInit
Definition: Record.h:305
@ IK_FirstOpInit
Definition: Record.h:306
@ IK_VarDefInit
Definition: Record.h:319
@ IK_ArgumentInit
Definition: Record.h:322
@ IK_ExistsOpInit
Definition: Record.h:314
@ IK_DefInit
Definition: Record.h:302
@ IK_BinOpInit
Definition: Record.h:307
@ IK_FirstTypedInit
Definition: Record.h:298
@ IK_BitInit
Definition: Record.h:299
@ IK_BitsInit
Definition: Record.h:300
@ IK_UnOpInit
Definition: Record.h:309
@ IK_StringInit
Definition: Record.h:316
@ IK_IsAOpInit
Definition: Record.h:313
@ IK_First
Definition: Record.h:297
@ IK_VarInit
Definition: Record.h:317
@ IK_LastOpInit
Definition: Record.h:310
@ IK_AnonymousNameInit
Definition: Record.h:315
@ IK_CondOpInit
Definition: Record.h:311
@ IK_FieldInit
Definition: Record.h:303
@ IK_TernOpInit
Definition: Record.h:308
InitKind getKind() const
Get the kind (type) of the value.
Definition: Record.h:336
virtual Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const
This function is used to implement the bit range selection operator.
Definition: Record.h:384
virtual bool isConcrete() const
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:354
virtual bool isComplete() const
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:350
virtual ~Init()=default
Init(const Init &)=delete
virtual Init * getCastTo(RecTy *Ty) const =0
If this value is convertible to type Ty, return a value whose type is Ty, generating a !...
Init & operator=(const Init &)=delete
RecordKeeper & getRecordKeeper() const
Get the record keeper that initialized this Init.
Definition: Record.cpp:349
virtual RecTy * getFieldType(StringInit *FieldName) const
This function is used to implement the FieldInit class.
Definition: Record.h:391
virtual Init * convertInitializerTo(RecTy *Ty) const =0
Convert to a value whose type is Ty, or return null if this is not possible.
Init(InitKind K, uint8_t Opc=0)
Definition: Record.h:342
'7' - Represent an initialization by a literal integer value.
Definition: Record.h:631
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This function is used to implement the bit range selection operator.
Definition: Record.cpp:597
IntInit(const IntInit &)=delete
static IntInit * get(RecordKeeper &RK, int64_t V)
Definition: Record.cpp:552
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:655
static bool classof(const Init *I)
Definition: Record.h:641
IntInit & operator=(const IntInit &)=delete
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:569
int64_t getValue() const
Definition: Record.h:647
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:652
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:559
'int' - Represent an integer value of no particular size
Definition: Record.h:149
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:157
static IntRecTy * get(RecordKeeper &RK)
Definition: Record.cpp:153
std::string getAsString() const override
Definition: Record.h:161
static bool classof(const RecTy *RT)
Definition: Record.h:155
!isa<type>(expr) - Dynamically determine the type of an expression.
Definition: Record.h:1170
IsAOpInit(const IsAOpInit &)=delete
IsAOpInit & operator=(const IsAOpInit &)=delete
static bool classof(const Init *I)
Definition: Record.h:1183
static IsAOpInit * get(RecTy *CheckType, Init *Expr)
Definition: Record.cpp:1969
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:1193
Init * Fold() const
Definition: Record.cpp:1988
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2019
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:2008
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:2015
[AL, AH, CL] - Represent a list of defs
Definition: Record.h:747
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:754
ListInit & operator=(const ListInit &)=delete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.cpp:746
static ListInit * get(ArrayRef< Init * > Range, RecTy *EltTy)
Definition: Record.cpp:659
RecTy * getElementType() const
Definition: Record.h:775
ListInit(const ListInit &)=delete
Init * getElement(unsigned i) const
Definition: Record.h:771
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.cpp:738
size_t size() const
Definition: Record.h:801
Init *const * const_iterator
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:686
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:804
ArrayRef< Init * > getValues() const
Definition: Record.h:794
Record * getElementAsRecord(unsigned i) const
Definition: Record.cpp:714
const_iterator begin() const
Definition: Record.h:798
const_iterator end() const
Definition: Record.h:799
bool empty() const
Definition: Record.h:802
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:722
static bool classof(const Init *I)
Definition: Record.h:764
'list<Ty>' - Represent a list of element values, all of which must be of the specified type.
Definition: Record.h:186
static bool classof(const RecTy *RT)
Definition: Record.h:195
bool typeIsA(const RecTy *RHS) const override
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:185
std::string getAsString() const override
Definition: Record.cpp:175
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:179
RecTy * getElementType() const
Definition: Record.h:200
static ListRecTy * get(RecTy *T)
Definition: Record.h:199
Resolve arbitrary mappings.
Definition: Record.h:2240
void set(Init *Key, Init *Value)
Definition: Record.h:2254
MapResolver(Record *CurRec=nullptr)
Definition: Record.h:2252
bool isComplete(Init *VarName) const
Definition: Record.h:2256
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:3264
Base class for operators.
Definition: Record.h:811
virtual Init * getOperand(unsigned i) const =0
virtual unsigned getNumOperands() const =0
OpInit & operator=(OpInit &)=delete
static bool classof(const Init *I)
Definition: Record.h:820
OpInit(const OpInit &)=delete
virtual OpInit * clone(ArrayRef< Init * > Operands) const =0
OpInit(InitKind K, RecTy *Type, uint8_t Opc)
Definition: Record.h:813
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:765
PointerIntPair - This class implements a pair of a pointer and small integer.
IntType getInt() const
PointerTy getPointer() const
RecordKeeper & getRecordKeeper() const
Return the RecordKeeper that uniqued this Type.
Definition: Record.h:86
ListRecTy * getListTy()
Returns the type representing list<thistype>.
Definition: Record.cpp:107
virtual bool typeIsA(const RecTy *RHS) const
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:118
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:113
RecTyKind
Subclass discriminator (for dyn_cast<> et al.)
Definition: Record.h:62
@ RecordRecTyKind
Definition: Record.h:69
@ ListRecTyKind
Definition: Record.h:67
@ BitsRecTyKind
Definition: Record.h:64
@ DagRecTyKind
Definition: Record.h:68
@ IntRecTyKind
Definition: Record.h:65
@ StringRecTyKind
Definition: Record.h:66
@ BitRecTyKind
Definition: Record.h:63
RecTy(RecTyKind K, RecordKeeper &RK)
Definition: Record.h:80
virtual std::string getAsString() const =0
RecTyKind getRecTyKind() const
Definition: Record.h:83
void dump() const
Definition: Record.cpp:104
virtual ~RecTy()=default
void print(raw_ostream &OS) const
Definition: Record.h:89
void addDef(std::unique_ptr< Record > R)
Definition: Record.h:2017
void addClass(std::unique_ptr< Record > R)
Definition: Record.h:2010
std::vector< Record * > getAllDerivedDefinitions(StringRef ClassName) const
Get all the concrete records that inherit from the one specified class.
Definition: Record.cpp:3223
Record * getDef(StringRef Name) const
Get the concrete record with the specified name.
Definition: Record.h:1993
const RecordMap & getClasses() const
Get the map of classes.
Definition: Record.h:1978
Record * getClass(StringRef Name) const
Get the class with the specified name.
Definition: Record.h:1987
void stopPhaseTiming()
Stop phase timing and print the report.
Definition: Record.h:2052
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:3259
const RecordMap & getDefs() const
Get the map of records (defs).
Definition: Record.h:1981
void dump() const
Definition: Record.cpp:3161
detail::RecordKeeperImpl & getImpl()
Return the internal implementation of the RecordKeeper.
Definition: Record.h:1972
void stopBackendTimer()
Stop timing the overall backend.
Definition: Record.cpp:3213
void saveInputFilename(std::string Filename)
Definition: Record.h:2006
void startPhaseTiming()
Start phase timing; called if the –time-phases option is specified.
Definition: Record.h:2034
const GlobalMap & getGlobals() const
Get the map of global variables.
Definition: Record.h:1984
void stopTimer()
Stop timing a phase.
Definition: Record.cpp:3199
void startTimer(StringRef Name)
Start timing a phase. Automatically stops any previous phase timer.
Definition: Record.cpp:3184
void addExtraGlobal(StringRef Name, Init *I)
Definition: Record.h:2024
Init * getNewAnonymousName()
GetNewAnonymousName - Generate a unique anonymous name that can be used as an identifier.
Definition: Record.cpp:3177
Init * getGlobal(StringRef Name) const
Get the Init value of the specified global variable.
Definition: Record.h:1999
const std::string getInputFilename() const
Get the main TableGen input file's name.
Definition: Record.h:1975
void startBackendTimer(StringRef Name)
Start timing the overall backend.
Definition: Record.cpp:3206
'[classname]' - Type of record values that have zero or more superclasses.
Definition: Record.h:230
Record *const * const_record_iterator
Definition: Record.h:260
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:276
RecordRecTy & operator=(const RecordRecTy &)=delete
static RecordRecTy * get(RecordKeeper &RK, ArrayRef< Record * > Classes)
Get the record type with the given non-redundant list of superclasses.
Definition: Record.cpp:206
const_record_iterator classes_begin() const
Definition: Record.h:262
const_record_iterator classes_end() const
Definition: Record.h:263
std::string getAsString() const override
Definition: Record.cpp:253
RecordRecTy(const RecordRecTy &)=delete
bool typeIsA(const RecTy *RHS) const override
Return true if 'this' type is equal to or a subtype of RHS.
Definition: Record.cpp:289
static bool classof(const RecTy *RT)
Definition: Record.h:246
bool isSubClassOf(Record *Class) const
Definition: Record.cpp:269
ArrayRef< Record * > getClasses() const
Definition: Record.h:256
Resolve all variables from a record except for unset variables.
Definition: Record.h:2266
void setName(Init *NewName)
Definition: Record.h:2274
bool keepUnsetBits() const override
Definition: Record.h:2278
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:3282
RecordResolver(Record &R)
Definition: Record.h:2272
This class represents a field in a record, including its name, type, value, and source location.
Definition: Record.h:1543
bool setValue(Init *V)
Set the value of the field from an Init.
Definition: Record.cpp:2698
bool isTemplateArg() const
Is this a template argument?
Definition: Record.h:1590
std::string getNameInitAsString() const
Get the name of the field as a std::string.
Definition: Record.h:1577
void setUsed(bool Used)
Whether this value is used.
Definition: Record.h:1617
bool isNonconcreteOK() const
Is this a field where nonconcrete values are okay?
Definition: Record.h:1585
RecordKeeper & getRecordKeeper() const
Get the record keeper used to unique this value.
Definition: Record.h:1568
const SMLoc & getLoc() const
Get the source location of the point where the field was defined.
Definition: Record.h:1582
bool isUsed() const
Definition: Record.h:1618
void dump() const
Definition: Record.cpp:2747
StringRef getName() const
Get the name of the field as a StringRef.
Definition: Record.cpp:2679
void addReferenceLoc(SMRange Loc)
Add a reference to this record value.
Definition: Record.h:1610
void print(raw_ostream &OS, bool PrintSem=true) const
Print the value to an output stream, possibly with a semicolon.
Definition: Record.cpp:2750
RecTy * getType() const
Get the type of the field value as a RecTy.
Definition: Record.h:1595
Init * getNameInit() const
Get the name of the field as an Init.
Definition: Record.h:1574
ArrayRef< SMRange > getReferenceLocs() const
Return the references of this record value.
Definition: Record.h:1613
std::string getPrintType() const
Get the type of the field for printing purposes.
Definition: Record.cpp:2683
Init * getValue() const
Get the value of the field as an Init.
Definition: Record.h:1601
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:3022
void addAssertion(SMLoc Loc, Init *Condition, Init *Message)
Definition: Record.h:1815
void addDump(SMLoc Loc, Init *Message)
Definition: Record.h:1819
bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const
This method looks up the specified field and returns its value as a bit.
Definition: Record.cpp:3092
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:3080
unsigned getID() const
Definition: Record.h:1709
@ RK_AnonymousDef
Definition: Record.h:1653
@ RK_MultiClass
Definition: Record.h:1653
static unsigned getNewUID(RecordKeeper &RK)
Definition: Record.cpp:2790
ArrayRef< SMLoc > getLoc() const
Definition: Record.h:1723
void appendReferenceLoc(SMRange Loc)
Add a reference to this record value.
Definition: Record.h:1731
void checkUnusedTemplateArgs()
Definition: Record.cpp:3147
void emitRecordDumps()
Definition: Record.cpp:3136
Record(Init *N, ArrayRef< SMLoc > locs, RecordKeeper &records, RecordKind Kind=RK_Def)
Definition: Record.h:1687
ArrayRef< DumpInfo > getDumps() const
Definition: Record.h:1758
bool isAnonymous() const
Definition: Record.h:1749
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:3065
ArrayRef< AssertionInfo > getAssertions() const
Definition: Record.h:1757
std::string getNameInitAsString() const
Definition: Record.h:1717
Init * getNameInit() const
Definition: Record.h:1713
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:2981
void removeValue(StringRef Name)
Definition: Record.h:1811
void dump() const
Definition: Record.cpp:2890
void getDirectSuperClasses(SmallVectorImpl< Record * > &Classes) const
Append the direct superclasses of this record to Classes.
Definition: Record.cpp:2828
RecordKeeper & getRecords() const
Definition: Record.h:1873
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:2969
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:3038
const RecordVal * getValue(const Init *Name) const
Definition: Record.h:1774
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:3053
void appendLoc(SMLoc Loc)
Definition: Record.h:1724
Record(const Record &O)
Definition: Record.h:1701
bool isValueUnset(StringRef FieldName) const
Return true if the named field is unset.
Definition: Record.h:1891
bool isMultiClass() const
Definition: Record.h:1747
void addValue(const RecordVal &RV)
Definition: Record.h:1797
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:3109
bool hasDirectSuperClass(const Record *SuperClass) const
Determine whether this record has the specified direct superclass.
Definition: Record.cpp:2815
Record(StringRef N, ArrayRef< SMLoc > locs, RecordKeeper &records, RecordKind Kind=RK_Def)
Definition: Record.h:1694
bool isClass() const
Definition: Record.h:1745
StringRef getName() const
Definition: Record.h:1711
bool isSubClassOf(StringRef Name) const
Definition: Record.h:1840
void appendDumps(const Record *Rec)
Definition: Record.h:1827
void addTemplateArg(Init *Name)
Definition: Record.h:1792
ArrayRef< Init * > getTemplateArgs() const
Definition: Record.h:1751
bool isSubClassOf(const Record *R) const
Definition: Record.h:1833
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:2937
ArrayRef< RecordVal > getValues() const
Definition: Record.h:1755
SMLoc getFieldLoc(StringRef FieldName) const
Return the source location for the named field.
Definition: Record.cpp:2929
ArrayRef< SMLoc > getForwardDeclarationLocs() const
Definition: Record.h:1726
const RecordVal * getValue(StringRef Name) const
Definition: Record.h:1780
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:2994
void addSuperClass(Record *R, SMRange Range)
Definition: Record.h:1852
bool isTemplateArg(Init *Name) const
Definition: Record.h:1770
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:2954
DefInit * getDefInit()
get the corresponding DefInit.
Definition: Record.cpp:2782
ArrayRef< SMRange > getReferenceLocs() const
Return the references of this record value.
Definition: Record.h:1734
void updateClassLoc(SMLoc Loc)
Definition: Record.cpp:2760
RecordVal * getValue(const Init *Name)
Definition: Record.h:1784
RecordRecTy * getType()
Definition: Record.cpp:2776
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:2882
void setName(Init *Name)
Definition: Record.cpp:2794
void appendAssertions(const Record *Rec)
Definition: Record.h:1823
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const
Definition: Record.h:1760
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:3007
void removeValue(Init *Name)
Definition: Record.h:1802
RecordVal * getValue(StringRef Name)
Definition: Record.h:1788
void checkRecordAssertions()
Definition: Record.cpp:3125
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:2945
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2212
virtual ~Resolver()=default
bool isFinal() const
Definition: Record.h:2234
Record * getCurrentRecord() const
Definition: Record.h:2220
void setFinal(bool Final)
Definition: Record.h:2236
virtual Init * resolve(Init *VarName)=0
Return the initializer for the given variable name (should normally be a StringInit),...
virtual bool keepUnsetBits() const
Definition: Record.h:2229
Resolver(Record *CurRec)
Definition: Record.h:2217
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:2282
ShadowResolver(Resolver &R)
Definition: Record.h:2287
void addShadow(Init *Key)
Definition: Record.h:2292
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.h:2294
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:586
iterator erase(const_iterator CI)
Definition: SmallVector.h:750
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:591
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:696
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
"foo" - Represent an initialization by a string value.
Definition: Record.h:691
StringInit(const StringInit &)=delete
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.h:728
StringInit & operator=(const StringInit &)=delete
StringFormat getFormat() const
Definition: Record.h:721
bool hasCodeFormat() const
Definition: Record.h:722
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:642
StringRef getValue() const
Definition: Record.h:720
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:726
static StringFormat determineFormat(StringFormat Fmt1, StringFormat Fmt2)
Definition: Record.h:716
static StringInit * get(RecordKeeper &RK, StringRef, StringFormat Fmt=SF_String)
Definition: Record.cpp:632
static bool classof(const Init *I)
Definition: Record.h:709
std::string getAsUnquotedString() const override
Convert this value to a literal form, without adding quotes around a string.
Definition: Record.h:735
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:739
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
'string' - Represent an string value
Definition: Record.h:167
static bool classof(const RecTy *RT)
Definition: Record.h:173
static StringRecTy * get(RecordKeeper &RK)
Definition: Record.cpp:162
std::string getAsString() const override
Definition: Record.cpp:166
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:170
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:215
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
int compare_numeric(StringRef RHS) const
compare_numeric - Compare two strings, treating sequences of digits as numbers.
Definition: StringRef.cpp:61
!op (X, Y, Z) - Combine two inits.
Definition: Record.h:983
OpInit * clone(ArrayRef< Init * > Operands) const override
Definition: Record.h:1020
TernOpInit(const TernOpInit &)=delete
Init * getRHS() const
Definition: Record.h:1040
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:1046
Init * Fold(Record *CurRec) const
Definition: Record.cpp:1636
unsigned getNumOperands() const override
Definition: Record.h:1027
static bool classof(const Init *I)
Definition: Record.h:1009
Init * getLHS() const
Definition: Record.h:1038
Init * getOperand(unsigned i) const override
Definition: Record.h:1028
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:1868
TernOpInit & operator=(const TernOpInit &)=delete
TernaryOp getOpcode() const
Definition: Record.h:1037
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:1838
Init * getMHS() const
Definition: Record.h:1039
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:1537
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition: Timer.h:173
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:79
(Optionally) delegate resolving to a sub-resolver, and keep track whether there were unresolved refer...
Definition: Record.h:2303
bool foundUnresolved() const
Definition: Record.h:2311
TrackUnresolvedResolver(Resolver *R=nullptr)
Definition: Record.h:2308
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition: Record.cpp:3307
See the file comment for details on the usage of the TrailingObjects type.
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:413
static bool classof(const Init *I)
Definition: Record.h:424
TypedInit(InitKind K, RecTy *T, uint8_t Opc=0)
Definition: Record.h:417
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:2138
RecTy * getFieldType(StringInit *FieldName) const override
This method is used to implement the FieldInit class.
Definition: Record.cpp:2100
RecordKeeper & getRecordKeeper() const
Get the record keeper that initialized this Init.
Definition: Record.h:433
TypedInit(const TypedInit &)=delete
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:2111
TypedInit & operator=(const TypedInit &)=delete
RecTy * getType() const
Get the type of the Init as a RecTy.
Definition: Record.h:430
Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const override
This function is used to implement the bit range selection operator.
Definition: Record.cpp:2122
!op (X) - Transform an init.
Definition: Record.h:836
Init * getOperand() const
Definition: Record.h:885
UnOpInit & operator=(const UnOpInit &)=delete
Init * Fold(Record *CurRec, bool IsFinal=false) const
Definition: Record.cpp:796
static bool classof(const Init *I)
Definition: Record.h:862
UnaryOp getOpcode() const
Definition: Record.h:884
OpInit * clone(ArrayRef< Init * > Operands) const override
Definition: Record.h:871
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:959
unsigned getNumOperands() const override
Definition: Record.h:877
UnOpInit(const UnOpInit &)=delete
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
Definition: Record.cpp:778
Init * getOperand(unsigned i) const override
Definition: Record.h:879
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:968
'?' - Represents an uninitialized value.
Definition: Record.h:447
UnsetInit & operator=(const UnsetInit &)=delete
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition: Record.h:477
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:361
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:472
UnsetInit(const UnsetInit &)=delete
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?...
Definition: Record.h:479
static UnsetInit * get(RecordKeeper &RK)
Get the singleton unset Init.
Definition: Record.cpp:357
static bool classof(const Init *I)
Definition: Record.h:459
std::string getAsString() const override
Get the string representation of the Init.
Definition: Record.h:482
RecordKeeper & getRecordKeeper() const
Get the record keeper that initialized this Init.
Definition: Record.h:467
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:365
LLVM Value Representation.
Definition: Value.h:74
Opcode{0} - Represent access to one bit of a variable or field.
Definition: Record.h:1274
unsigned getBitNum() const
Definition: Record.h:1299
VarBitInit(const VarBitInit &)=delete
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2194
Init * getBit(unsigned B) const override
Get the Init value of the specified bit.
Definition: Record.h:1304
Init * getBitVar() const
Definition: Record.h:1298
static bool classof(const Init *I)
Definition: Record.h:1292
static VarBitInit * get(TypedInit *T, unsigned B)
Definition: Record.cpp:2186
VarBitInit & operator=(const VarBitInit &)=delete
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:2198
classname<targs...> - Represent an uninstantiated anonymous class instantiation.
Definition: Record.h:1348
size_t args_size() const
Definition: Record.h:1388
static VarDefInit * get(Record *Class, ArrayRef< ArgumentInit * > Args)
Definition: Record.cpp:2241
ArgumentInit * getArg(unsigned i) const
Definition: Record.h:1376
ArrayRef< ArgumentInit * > args() const
Definition: Record.h:1391
ArgumentInit *const * const_iterator
Definition: Record.h:1381
Init * Fold() const
Definition: Record.cpp:2345
const_iterator args_end() const
Definition: Record.h:1386
const_iterator args_begin() const
Definition: Record.h:1383
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.h:1395
VarDefInit & operator=(const VarDefInit &)=delete
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:2324
static bool classof(const Init *I)
Definition: Record.h:1364
VarDefInit(const VarDefInit &)=delete
bool args_empty() const
Definition: Record.h:1389
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.cpp:2358
'Opcode' - Represent a reference to an entire variable object.
Definition: Record.h:1237
VarInit & operator=(const VarInit &)=delete
static bool classof(const Init *I)
Definition: Record.h:1247
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:2180
Init * getNameInit() const
Definition: Record.h:1255
StringRef getName() const
Definition: Record.cpp:2169
std::string getAsString() const override
Convert this value to a literal form.
Definition: Record.h:1270
VarInit(const VarInit &)=delete
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition: Record.cpp:2174
static VarInit * get(StringRef VN, RecTy *T)
Definition: Record.cpp:2156
std::string getNameInitAsString() const
Definition: Record.h:1257
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ 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
std::variant< unsigned, Init * > ArgAuxType
Definition: Record.h:486
RecTy * resolveTypes(RecTy *T1, RecTy *T2)
Find a common type that T1 and T2 convert to.
Definition: Record.cpp:310
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void EmitJSON(RecordKeeper &RK, raw_ostream &OS)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:292
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1886
void EmitDetailedRecords(RecordKeeper &RK, raw_ostream &OS)
#define N
#define NC
Definition: regutils.h:42
Sorting predicate to sort record pointers by their unique ID.
Definition: Record.h:2109
bool operator()(const Record *LHS, const Record *RHS) const
Definition: Record.h:2110
Sorting predicate to sort record pointers by their Name field.
Definition: Record.h:2116
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:2117
SmallVector< std::pair< bool, StringRef >, 4 > Parts
Definition: Record.h:2124
std::pair< bool, StringRef > getPart(size_t i)
Definition: Record.h:2149
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:2155
Sorting predicate to sort record pointers by name.
Definition: Record.h:2099
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:2100
AssertionInfo(SMLoc Loc, Init *Condition, Init *Message)
Definition: Record.h:1640
DumpInfo(SMLoc Loc, Init *Message)
Definition: Record.h:1650
This class represents the internal implementation of the RecordKeeper.
Definition: Record.cpp:53