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