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