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