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