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