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