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