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