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 const Init *getElement(unsigned Idx) const { return getElements()[Idx]; }
797
798 std::pair<ArrayRef<const Init *>, const RecTy *> getKey() const {
799 return {getElements(), getElementType()};
800 }
801
802 const RecTy *getElementType() const {
803 return cast<ListRecTy>(getType())->getElementType();
804 }
805
806 const Record *getElementAsRecord(unsigned Idx) const;
807
808 const Init *convertInitializerTo(const RecTy *Ty) const override;
809
810 /// This method is used by classes that refer to other
811 /// variables which may not be defined at the time they expression is formed.
812 /// If a value is set for the variable later, this method will be called on
813 /// users of the value to allow the value to propagate out.
814 ///
815 const Init *resolveReferences(Resolver &R) const override;
816
817 bool isComplete() const override;
818 bool isConcrete() const override;
819 std::string getAsString() const override;
820
821 const_iterator begin() const { return getElements().begin(); }
822 const_iterator end() const { return getElements().end(); }
823
824 size_t size() const { return NumElements; }
825 bool empty() const { return NumElements == 0; }
826
827 const Init *getBit(unsigned Bit) const override {
828 llvm_unreachable("Illegal bit reference off list");
829 }
830};
831
832/// Base class for operators
833///
834class OpInit : public TypedInit {
835protected:
836 explicit OpInit(InitKind K, const RecTy *Type, uint8_t Opc)
837 : TypedInit(K, Type, Opc) {}
838
839public:
840 OpInit(const OpInit &) = delete;
841 OpInit &operator=(OpInit &) = delete;
842
843 static bool classof(const Init *I) {
844 return I->getKind() >= IK_FirstOpInit &&
845 I->getKind() <= IK_LastOpInit;
846 }
847
848 const Init *getBit(unsigned Bit) const final;
849};
850
851/// !op (X) - Transform an init.
852///
853class UnOpInit final : public OpInit, public FoldingSetNode {
854public:
871
872private:
873 const Init *LHS;
874
875 UnOpInit(UnaryOp opc, const Init *lhs, const RecTy *Type)
876 : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
877
878public:
879 UnOpInit(const UnOpInit &) = delete;
880 UnOpInit &operator=(const UnOpInit &) = delete;
881
882 static bool classof(const Init *I) {
883 return I->getKind() == IK_UnOpInit;
884 }
885
886 static const UnOpInit *get(UnaryOp opc, const Init *lhs, const RecTy *Type);
887
888 UnaryOp getOpcode() const { return (UnaryOp)Opc; }
889 const Init *getOperand() const { return LHS; }
890
891 std::tuple<UnaryOp, const Init *, const RecTy *> getKey() const {
892 return {getOpcode(), LHS, getType()};
893 }
894
895 // Fold - If possible, fold this to a simpler init. Return this if not
896 // possible to fold.
897 const Init *Fold(const Record *CurRec, bool IsFinal = false) const;
898
899 const Init *resolveReferences(Resolver &R) const override;
900
901 std::string getAsString() const override;
902};
903
904/// !op (X, Y) - Combine two inits.
905class BinOpInit final : public OpInit, public FoldingSetNode {
906public:
939
940private:
941 const Init *LHS, *RHS;
942
943 BinOpInit(BinaryOp opc, const Init *lhs, const Init *rhs, const RecTy *Type)
944 : OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
945
946public:
947 BinOpInit(const BinOpInit &) = delete;
948 BinOpInit &operator=(const BinOpInit &) = delete;
949
950 static bool classof(const Init *I) {
951 return I->getKind() == IK_BinOpInit;
952 }
953
954 static const BinOpInit *get(BinaryOp opc, const Init *lhs, const Init *rhs,
955 const RecTy *Type);
956 static const Init *getStrConcat(const Init *lhs, const Init *rhs);
957 static const Init *getListConcat(const TypedInit *lhs, const Init *rhs);
958
959 BinaryOp getOpcode() const { return (BinaryOp)Opc; }
960 const Init *getLHS() const { return LHS; }
961 const Init *getRHS() const { return RHS; }
962
963 std::tuple<BinaryOp, const Init *, const Init *, const RecTy *>
964 getKey() const {
965 return {getOpcode(), LHS, RHS, getType()};
966 }
967
968 std::optional<bool> CompareInit(unsigned Opc, const Init *LHS,
969 const Init *RHS) const;
970
971 // Fold - If possible, fold this to a simpler init. Return this if not
972 // possible to fold.
973 const Init *Fold(const Record *CurRec) const;
974
975 const Init *resolveReferences(Resolver &R) const override;
976
977 std::string getAsString() const override;
978};
979
980/// !op (X, Y, Z) - Combine two inits.
981class TernOpInit final : public OpInit, public FoldingSetNode {
982public:
996
997private:
998 const Init *LHS, *MHS, *RHS;
999
1000 TernOpInit(TernaryOp opc, const Init *lhs, const Init *mhs, const Init *rhs,
1001 const RecTy *Type)
1002 : OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
1003
1004public:
1005 TernOpInit(const TernOpInit &) = delete;
1006 TernOpInit &operator=(const TernOpInit &) = delete;
1007
1008 static bool classof(const Init *I) {
1009 return I->getKind() == IK_TernOpInit;
1010 }
1011
1012 static const TernOpInit *get(TernaryOp opc, const Init *lhs, const Init *mhs,
1013 const Init *rhs, const RecTy *Type);
1014
1015 TernaryOp getOpcode() const { return (TernaryOp)Opc; }
1016 const Init *getLHS() const { return LHS; }
1017 const Init *getMHS() const { return MHS; }
1018 const Init *getRHS() const { return RHS; }
1019
1020 std::tuple<TernaryOp, const Init *, const Init *, const Init *, const RecTy *>
1021 getKey() const {
1022 return {getOpcode(), LHS, MHS, RHS, getType()};
1023 }
1024
1025 // Fold - If possible, fold this to a simpler init. Return this if not
1026 // possible to fold.
1027 const Init *Fold(const Record *CurRec) const;
1028
1029 bool isComplete() const override {
1030 return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
1031 }
1032
1033 const Init *resolveReferences(Resolver &R) const override;
1034
1035 std::string getAsString() const override;
1036};
1037
1038/// !cond(condition_1: value1, ... , condition_n: value)
1039/// Selects the first value for which condition is true.
1040/// Otherwise reports an error.
1041class CondOpInit final : public TypedInit,
1042 public FoldingSetNode,
1043 private TrailingObjects<CondOpInit, const Init *> {
1044 friend TrailingObjects;
1045 unsigned NumConds;
1046 const RecTy *ValType;
1047
1049 const RecTy *Type);
1050
1051public:
1052 CondOpInit(const CondOpInit &) = delete;
1053 CondOpInit &operator=(const CondOpInit &) = delete;
1054
1055 static bool classof(const Init *I) {
1056 return I->getKind() == IK_CondOpInit;
1057 }
1058
1059 static const CondOpInit *get(ArrayRef<const Init *> Conds,
1061 const RecTy *Type);
1062
1063 std::tuple<const RecTy *, ArrayRef<const Init *>, ArrayRef<const Init *>>
1064 getKey() const {
1065 return {ValType, getConds(), getVals()};
1066 }
1067
1068 const RecTy *getValType() const { return ValType; }
1069
1070 unsigned getNumConds() const { return NumConds; }
1071
1072 const Init *getCond(unsigned Num) const { return getConds()[Num]; }
1073
1074 const Init *getVal(unsigned Num) const { return getVals()[Num]; }
1075
1077 return getTrailingObjects(NumConds);
1078 }
1079
1081 return ArrayRef(getTrailingObjects() + NumConds, NumConds);
1082 }
1083
1084 auto getCondAndVals() const { return zip_equal(getConds(), getVals()); }
1085
1086 const Init *Fold(const Record *CurRec) const;
1087
1088 const Init *resolveReferences(Resolver &R) const override;
1089
1090 bool isConcrete() const override;
1091 bool isComplete() const override;
1092 std::string getAsString() const override;
1093
1096
1097 inline const_case_iterator arg_begin() const { return getConds().begin(); }
1098 inline const_case_iterator arg_end () const { return getConds().end(); }
1099
1100 inline size_t case_size () const { return NumConds; }
1101 inline bool case_empty() const { return NumConds == 0; }
1102
1103 inline const_val_iterator name_begin() const { return getVals().begin();}
1104 inline const_val_iterator name_end () const { return getVals().end(); }
1105
1106 inline size_t val_size () const { return NumConds; }
1107 inline bool val_empty() const { return NumConds == 0; }
1108
1109 const Init *getBit(unsigned Bit) const override;
1110};
1111
1112/// !foldl (a, b, expr, start, lst) - Fold over a list.
1113class FoldOpInit final : public TypedInit, public FoldingSetNode {
1114private:
1115 const Init *Start, *List, *A, *B, *Expr;
1116
1117 FoldOpInit(const Init *Start, const Init *List, const Init *A, const Init *B,
1118 const Init *Expr, const RecTy *Type)
1119 : TypedInit(IK_FoldOpInit, Type), Start(Start), List(List), A(A), B(B),
1120 Expr(Expr) {}
1121
1122public:
1123 FoldOpInit(const FoldOpInit &) = delete;
1124 FoldOpInit &operator=(const FoldOpInit &) = delete;
1125
1126 static bool classof(const Init *I) { return I->getKind() == IK_FoldOpInit; }
1127
1128 static const FoldOpInit *get(const Init *Start, const Init *List,
1129 const Init *A, const Init *B, const Init *Expr,
1130 const RecTy *Type);
1131
1132 std::tuple<const Init *, const Init *, const Init *, const Init *,
1133 const Init *, const RecTy *>
1134 getKey() const {
1135 return {Start, List, A, B, Expr, getType()};
1136 }
1137
1138 // Fold - If possible, fold this to a simpler init. Return this if not
1139 // possible to fold.
1140 const Init *Fold(const Record *CurRec) const;
1141
1142 bool isComplete() const override { return false; }
1143
1144 const Init *resolveReferences(Resolver &R) const override;
1145
1146 const Init *getBit(unsigned Bit) const override;
1147
1148 std::string getAsString() const override;
1149};
1150
1151/// !isa<type>(expr) - Dynamically determine the type of an expression.
1152class IsAOpInit final : public TypedInit, public FoldingSetNode {
1153private:
1154 const RecTy *CheckType;
1155 const Init *Expr;
1156
1157 IsAOpInit(const RecTy *CheckType, const Init *Expr)
1158 : TypedInit(IK_IsAOpInit, IntRecTy::get(CheckType->getRecordKeeper())),
1159 CheckType(CheckType), Expr(Expr) {}
1160
1161public:
1162 IsAOpInit(const IsAOpInit &) = delete;
1163 IsAOpInit &operator=(const IsAOpInit &) = delete;
1164
1165 static bool classof(const Init *I) { return I->getKind() == IK_IsAOpInit; }
1166
1167 static const IsAOpInit *get(const RecTy *CheckType, const Init *Expr);
1168
1169 std::pair<const RecTy *, const Init *> getKey() const {
1170 return {CheckType, Expr};
1171 }
1172
1173 // Fold - If possible, fold this to a simpler init. Return this if not
1174 // possible to fold.
1175 const Init *Fold() const;
1176
1177 bool isComplete() const override { return false; }
1178
1179 const Init *resolveReferences(Resolver &R) const override;
1180
1181 const Init *getBit(unsigned Bit) const override;
1182
1183 std::string getAsString() const override;
1184};
1185
1186/// !exists<type>(expr) - Dynamically determine if a record of `type` named
1187/// `expr` exists.
1188class ExistsOpInit final : public TypedInit, public FoldingSetNode {
1189private:
1190 const RecTy *CheckType;
1191 const Init *Expr;
1192
1193 ExistsOpInit(const RecTy *CheckType, const Init *Expr)
1194 : TypedInit(IK_ExistsOpInit, IntRecTy::get(CheckType->getRecordKeeper())),
1195 CheckType(CheckType), Expr(Expr) {}
1196
1197public:
1198 ExistsOpInit(const ExistsOpInit &) = delete;
1199 ExistsOpInit &operator=(const ExistsOpInit &) = delete;
1200
1201 static bool classof(const Init *I) { return I->getKind() == IK_ExistsOpInit; }
1202
1203 static const ExistsOpInit *get(const RecTy *CheckType, const Init *Expr);
1204
1205 std::pair<const RecTy *, const Init *> getKey() const {
1206 return {CheckType, Expr};
1207 }
1208
1209 // Fold - If possible, fold this to a simpler init. Return this if not
1210 // possible to fold.
1211 const Init *Fold(const Record *CurRec, bool IsFinal = false) const;
1212
1213 bool isComplete() const override { return false; }
1214
1215 const Init *resolveReferences(Resolver &R) const override;
1216
1217 const Init *getBit(unsigned Bit) const override;
1218
1219 std::string getAsString() const override;
1220};
1221
1222/// !instances<type>([regex]) - Produces a list of records whose type is `type`.
1223/// If `regex` is provided, only records whose name matches the regular
1224/// expression `regex` will be included.
1225class InstancesOpInit final : public TypedInit, public FoldingSetNode {
1226private:
1227 const RecTy *Type;
1228 const Init *Regex;
1229
1230 InstancesOpInit(const RecTy *Type, const Init *Regex)
1232 Regex(Regex) {}
1233
1234public:
1235 InstancesOpInit(const InstancesOpInit &) = delete;
1236 InstancesOpInit &operator=(const InstancesOpInit &) = delete;
1237
1238 static bool classof(const Init *I) {
1239 return I->getKind() == IK_InstancesOpInit;
1240 }
1241
1242 static const InstancesOpInit *get(const RecTy *Type, const Init *Regex);
1243
1244 std::pair<const RecTy *, const Init *> getKey() const {
1245 return {Type, Regex};
1246 }
1247
1248 const Init *Fold(const Record *CurRec, bool IsFinal = false) const;
1249
1250 bool isComplete() const override { return false; }
1251
1252 const Init *resolveReferences(Resolver &R) const override;
1253
1254 const Init *getBit(unsigned Bit) const override {
1255 llvm_unreachable("Illegal bit reference off !instances");
1256 }
1257
1258 std::string getAsString() const override;
1259};
1260
1261/// 'Opcode' - Represent a reference to an entire variable object.
1262class VarInit final : public TypedInit {
1263 const Init *VarName;
1264
1265 explicit VarInit(const Init *VN, const RecTy *T)
1266 : TypedInit(IK_VarInit, T), VarName(VN) {}
1267
1268public:
1269 VarInit(const VarInit &) = delete;
1270 VarInit &operator=(const VarInit &) = delete;
1271
1272 static bool classof(const Init *I) {
1273 return I->getKind() == IK_VarInit;
1274 }
1275
1276 static const VarInit *get(StringRef VN, const RecTy *T);
1277 static const VarInit *get(const Init *VN, const RecTy *T);
1278
1279 StringRef getName() const;
1280 const Init *getNameInit() const { return VarName; }
1281
1282 std::string getNameInitAsString() const {
1283 return getNameInit()->getAsUnquotedString();
1284 }
1285
1286 /// This method is used by classes that refer to other
1287 /// variables which may not be defined at the time they expression is formed.
1288 /// If a value is set for the variable later, this method will be called on
1289 /// users of the value to allow the value to propagate out.
1290 ///
1291 const Init *resolveReferences(Resolver &R) const override;
1292
1293 const Init *getBit(unsigned Bit) const override;
1294
1295 std::string getAsString() const override { return std::string(getName()); }
1296};
1297
1298/// Opcode{0} - Represent access to one bit of a variable or field.
1299class VarBitInit final : public TypedInit {
1300 const TypedInit *TI;
1301 unsigned Bit;
1302
1303 VarBitInit(const TypedInit *T, unsigned B)
1304 : TypedInit(IK_VarBitInit, BitRecTy::get(T->getRecordKeeper())), TI(T),
1305 Bit(B) {
1306 assert(T->getType() &&
1307 (isa<IntRecTy>(T->getType()) ||
1308 (isa<BitsRecTy>(T->getType()) &&
1309 cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
1310 "Illegal VarBitInit expression!");
1311 }
1312
1313public:
1314 VarBitInit(const VarBitInit &) = delete;
1315 VarBitInit &operator=(const VarBitInit &) = delete;
1316
1317 static bool classof(const Init *I) {
1318 return I->getKind() == IK_VarBitInit;
1319 }
1320
1321 static const VarBitInit *get(const TypedInit *T, unsigned B);
1322
1323 const Init *getBitVar() const { return TI; }
1324 unsigned getBitNum() const { return Bit; }
1325
1326 std::string getAsString() const override;
1327 const Init *resolveReferences(Resolver &R) const override;
1328
1329 const Init *getBit(unsigned B) const override {
1330 assert(B < 1 && "Bit index out of range!");
1331 return this;
1332 }
1333};
1334
1335/// AL - Represent a reference to a 'def' in the description
1336class DefInit final : public TypedInit {
1337 friend class Record;
1338
1339 const Record *Def;
1340
1341 explicit DefInit(const Record *D);
1342
1343public:
1344 DefInit(const DefInit &) = delete;
1345 DefInit &operator=(const DefInit &) = delete;
1346
1347 static bool classof(const Init *I) {
1348 return I->getKind() == IK_DefInit;
1349 }
1350
1351 const Init *convertInitializerTo(const RecTy *Ty) const override;
1352
1353 const Record *getDef() const { return Def; }
1354
1355 const RecTy *getFieldType(const StringInit *FieldName) const override;
1356
1357 bool isConcrete() const override { return true; }
1358 std::string getAsString() const override;
1359
1360 const Init *getBit(unsigned Bit) const override {
1361 llvm_unreachable("Illegal bit reference off def");
1362 }
1363};
1364
1365/// classname<targs...> - Represent an uninstantiated anonymous class
1366/// instantiation.
1367class VarDefInit final
1368 : public TypedInit,
1369 public FoldingSetNode,
1370 private TrailingObjects<VarDefInit, const ArgumentInit *> {
1371 friend TrailingObjects;
1372 SMLoc Loc;
1373 const Record *Class;
1374 const DefInit *Def = nullptr; // after instantiation
1375 unsigned NumArgs;
1376
1377 explicit VarDefInit(SMLoc Loc, const Record *Class,
1379
1380 const DefInit *instantiate();
1381
1382public:
1383 VarDefInit(const VarDefInit &) = delete;
1384 VarDefInit &operator=(const VarDefInit &) = delete;
1385
1386 // Do not use sized deallocation due to trailing objects.
1387 void operator delete(void *Ptr) { ::operator delete(Ptr); }
1388
1389 static bool classof(const Init *I) {
1390 return I->getKind() == IK_VarDefInit;
1391 }
1392 static const VarDefInit *get(SMLoc Loc, const Record *Class,
1394
1395 std::pair<const Record *, ArrayRef<const ArgumentInit *>> getKey() const {
1396 return {Class, args()};
1397 }
1398
1399 const Init *resolveReferences(Resolver &R) const override;
1400 const Init *Fold() const;
1401
1402 std::string getAsString() const override;
1403
1404 const ArgumentInit *getArg(unsigned i) const { return args()[i]; }
1405
1406 using const_iterator = const ArgumentInit *const *;
1407
1408 const_iterator args_begin() const { return args().begin(); }
1409 const_iterator args_end() const { return args().end(); }
1410
1411 size_t args_size () const { return NumArgs; }
1412 bool args_empty() const { return NumArgs == 0; }
1413
1415 return getTrailingObjects(NumArgs);
1416 }
1417
1418 const Init *getBit(unsigned Bit) const override {
1419 llvm_unreachable("Illegal bit reference off anonymous def");
1420 }
1421};
1422
1423/// X.Y - Represent a reference to a subfield of a variable
1424class FieldInit final : public TypedInit {
1425 const Init *Rec; // Record we are referring to
1426 const StringInit *FieldName; // Field we are accessing
1427
1428 FieldInit(const Init *R, const StringInit *FN)
1429 : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
1430#ifndef NDEBUG
1431 if (!getType()) {
1432 llvm::errs() << "In Record = " << Rec->getAsString()
1433 << ", got FieldName = " << *FieldName
1434 << " with non-record type!\n";
1435 llvm_unreachable("FieldInit with non-record type!");
1436 }
1437#endif
1438 }
1439
1440public:
1441 FieldInit(const FieldInit &) = delete;
1442 FieldInit &operator=(const FieldInit &) = delete;
1443
1444 static bool classof(const Init *I) {
1445 return I->getKind() == IK_FieldInit;
1446 }
1447
1448 static const FieldInit *get(const Init *R, const StringInit *FN);
1449
1450 const Init *getRecord() const { return Rec; }
1451 const StringInit *getFieldName() const { return FieldName; }
1452
1453 const Init *getBit(unsigned Bit) const override;
1454
1455 const Init *resolveReferences(Resolver &R) const override;
1456 const Init *Fold(const Record *CurRec) const;
1457
1458 bool isConcrete() const override;
1459 std::string getAsString() const override {
1460 return Rec->getAsString() + "." + FieldName->getValue().str();
1461 }
1462};
1463
1464/// (v a, b) - Represent a DAG tree value. DAG inits are required
1465/// to have at least one value then a (possibly empty) list of arguments. Each
1466/// argument can have a name associated with it.
1467class DagInit final
1468 : public TypedInit,
1469 public FoldingSetNode,
1470 private TrailingObjects<DagInit, const Init *, const StringInit *> {
1471 friend TrailingObjects;
1472
1473 const Init *Val;
1474 const StringInit *ValName;
1475 unsigned NumArgs;
1476
1477 DagInit(const Init *V, const StringInit *VN, ArrayRef<const Init *> Args,
1479
1480 size_t numTrailingObjects(OverloadToken<const Init *>) const {
1481 return NumArgs;
1482 }
1483
1484public:
1485 DagInit(const DagInit &) = delete;
1486 DagInit &operator=(const DagInit &) = delete;
1487
1488 static bool classof(const Init *I) {
1489 return I->getKind() == IK_DagInit;
1490 }
1491
1492 static const DagInit *get(const Init *V, const StringInit *VN,
1495
1496 static const DagInit *get(const Init *V, ArrayRef<const Init *> Args,
1498 return DagInit::get(V, nullptr, Args, ArgNames);
1499 }
1500
1501 static const DagInit *
1502 get(const Init *V, const StringInit *VN,
1503 ArrayRef<std::pair<const Init *, const StringInit *>> ArgAndNames);
1504
1505 static const DagInit *
1506 get(const Init *V,
1507 ArrayRef<std::pair<const Init *, const StringInit *>> ArgAndNames) {
1508 return DagInit::get(V, nullptr, ArgAndNames);
1509 }
1510
1511 std::tuple<const Init *, const StringInit *, ArrayRef<const Init *>,
1513 getKey() const {
1514 return {Val, ValName, getArgs(), getArgNames()};
1515 }
1516
1517 const Init *getOperator() const { return Val; }
1519
1520 const StringInit *getName() const { return ValName; }
1521
1523 return ValName ? ValName->getValue() : StringRef();
1524 }
1525
1526 unsigned getNumArgs() const { return NumArgs; }
1527
1528 const Init *getArg(unsigned Num) const { return getArgs()[Num]; }
1529
1530 /// This method looks up the specified argument name and returns its argument
1531 /// number or std::nullopt if that argument name does not exist.
1532 std::optional<unsigned> getArgNo(StringRef Name) const;
1533
1534 const StringInit *getArgName(unsigned Num) const {
1535 return getArgNames()[Num];
1536 }
1537
1538 StringRef getArgNameStr(unsigned Num) const {
1539 const StringInit *Init = getArgName(Num);
1540 return Init ? Init->getValue() : StringRef();
1541 }
1542
1546
1550
1551 // Return a range of std::pair.
1552 auto getArgAndNames() const {
1553 auto Zip = llvm::zip_equal(getArgs(), getArgNames());
1554 using EltTy = decltype(*adl_begin(Zip));
1555 return llvm::map_range(Zip, [](const EltTy &E) {
1556 return std::make_pair(std::get<0>(E), std::get<1>(E));
1557 });
1558 }
1559
1560 const Init *resolveReferences(Resolver &R) const override;
1561
1562 bool isConcrete() const override;
1563 std::string getAsString() const override;
1564
1568
1569 inline const_arg_iterator arg_begin() const { return getArgs().begin(); }
1570 inline const_arg_iterator arg_end () const { return getArgs().end(); }
1571
1572 inline size_t arg_size () const { return NumArgs; }
1573 inline bool arg_empty() const { return NumArgs == 0; }
1574
1575 inline const_name_iterator name_begin() const { return getArgNames().begin();}
1576 inline const_name_iterator name_end () const { return getArgNames().end(); }
1577
1578 const Init *getBit(unsigned Bit) const override {
1579 llvm_unreachable("Illegal bit reference off dag");
1580 }
1581};
1582
1583//===----------------------------------------------------------------------===//
1584// High-Level Classes
1585//===----------------------------------------------------------------------===//
1586
1587/// This class represents a field in a record, including its name, type,
1588/// value, and source location.
1590 friend class Record;
1591
1592public:
1594 FK_Normal, // A normal record field.
1595 FK_NonconcreteOK, // A field that can be nonconcrete ('field' keyword).
1596 FK_TemplateArg, // A template argument.
1597 };
1598
1599private:
1600 const Init *Name;
1601 SMLoc Loc; // Source location of definition of name.
1602 // The low two bits of the flags are the FieldKind, and bit 2 is set if the
1603 // value is used.
1605 static constexpr unsigned KindMask = 3;
1606 static constexpr unsigned UsedBit = 4;
1607 const Init *Value;
1608
1609 FieldKind getKind() const {
1610 return FieldKind(TyAndFlags.getInt() & KindMask);
1611 }
1612
1613public:
1614 RecordVal(const Init *N, const RecTy *T, FieldKind K);
1615 RecordVal(const Init *N, SMLoc Loc, const RecTy *T, FieldKind K);
1616
1617 /// Get the record keeper used to unique this value.
1618 RecordKeeper &getRecordKeeper() const { return Name->getRecordKeeper(); }
1619
1620 /// Get the name of the field as a StringRef.
1621 StringRef getName() const;
1622
1623 /// Get the name of the field as an Init.
1624 const Init *getNameInit() const { return Name; }
1625
1626 /// Get the name of the field as a std::string.
1627 std::string getNameInitAsString() const {
1628 return getNameInit()->getAsUnquotedString();
1629 }
1630
1631 /// Get the source location of the point where the field was defined.
1632 SMLoc getLoc() const { return Loc; }
1633
1634 /// Is this a field where nonconcrete values are okay?
1635 bool isNonconcreteOK() const { return getKind() == FK_NonconcreteOK; }
1636
1637 /// Is this a template argument?
1638 bool isTemplateArg() const { return getKind() == FK_TemplateArg; }
1639
1640 /// Get the type of the field value as a RecTy.
1641 const RecTy *getType() const { return TyAndFlags.getPointer(); }
1642
1643 /// Get the type of the field for printing purposes.
1644 std::string getPrintType() const;
1645
1646 /// Get the value of the field as an Init.
1647 const Init *getValue() const { return Value; }
1648
1649 /// Set the value of the field from an Init.
1650 bool setValue(const Init *V);
1651
1652 /// Set the value and source location of the field.
1653 bool setValue(const Init *V, SMLoc NewLoc);
1654
1655 /// Whether this value is used. Useful for reporting warnings, for example
1656 /// when a template argument is unused.
1657 void setUsed(bool Used) {
1658 unsigned Flags = TyAndFlags.getInt() & ~UsedBit;
1659 TyAndFlags.setInt(Used ? Flags | UsedBit : Flags);
1660 }
1661 bool isUsed() const { return TyAndFlags.getInt() & UsedBit; }
1662
1663 void dump() const;
1664
1665 /// Print the value to an output stream, possibly with a semicolon.
1666 void print(raw_ostream &OS, bool PrintSem = true) const;
1667};
1668
1670 RV.print(OS << " ");
1671 return OS;
1672}
1673
1674class Record {
1675public:
1680
1681 // User-defined constructor to support std::make_unique(). It can be
1682 // removed in C++20 when braced initialization is supported.
1685 };
1686
1687 struct DumpInfo {
1690
1691 // User-defined constructor to support std::make_unique(). It can be
1692 // removed in C++20 when braced initialization is supported.
1694 };
1695
1697
1698private:
1699 const Init *Name;
1700 // Location where record was instantiated, followed by the location of
1701 // multiclass prototypes used, and finally by the locations of references to
1702 // this record.
1704 SmallVector<SMLoc, 0> ForwardDeclarationLocs;
1705 mutable SmallVector<SMRange, 0> ReferenceLocs;
1706 mutable DenseMap<const Init *, SmallVector<SMRange, 0>> ValueReferenceLocs;
1711
1712 // Direct superclasses, which are roots of the inheritance forest (yes, it
1713 // must be a forest; diamond-shaped inheritance is not allowed).
1715
1716 // Tracks Record instances. Not owned by Record.
1717 RecordKeeper &TrackedRecords;
1718
1719 // The DefInit corresponding to this record.
1720 mutable DefInit *CorrespondingDefInit = nullptr;
1721
1722 // Unique record ID.
1723 unsigned ID;
1724
1725 RecordKind Kind;
1726
1727 void checkName();
1728
1729public:
1730 // Constructs a record.
1731 explicit Record(const Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1732 RecordKind Kind = RK_Def)
1733 : Name(N), Locs(locs), TrackedRecords(records),
1734 ID(getNewUID(N->getRecordKeeper())), Kind(Kind) {
1735 checkName();
1736 }
1737
1739 RecordKind Kind = RK_Def)
1740 : Record(StringInit::get(records, N), locs, records, Kind) {}
1741
1742 // When copy-constructing a Record, we must still guarantee a globally unique
1743 // ID number. Don't copy CorrespondingDefInit either, since it's owned by the
1744 // original record. All other fields can be copied normally.
1745 Record(const Record &O)
1746 : Name(O.Name), Locs(O.Locs), ValueReferenceLocs(O.ValueReferenceLocs),
1747 TemplateArgs(O.TemplateArgs), Values(O.Values),
1748 Assertions(O.Assertions), DirectSuperClasses(O.DirectSuperClasses),
1749 TrackedRecords(O.TrackedRecords), ID(getNewUID(O.getRecords())),
1750 Kind(O.Kind) {}
1751
1752 static unsigned getNewUID(RecordKeeper &RK);
1753
1754 unsigned getID() const { return ID; }
1755
1756 StringRef getName() const { return cast<StringInit>(Name)->getValue(); }
1757
1758 const Init *getNameInit() const { return Name; }
1759
1760 std::string getNameInitAsString() const {
1761 return getNameInit()->getAsUnquotedString();
1762 }
1763
1764 void setName(const Init *Name); // Also updates RecordKeeper.
1765
1766 ArrayRef<SMLoc> getLoc() const { return Locs; }
1767 void appendLoc(SMLoc Loc) { Locs.push_back(Loc); }
1768
1770 return ForwardDeclarationLocs;
1771 }
1772
1773 /// Add a reference to this record value.
1774 void appendReferenceLoc(SMRange Loc) const { ReferenceLocs.push_back(Loc); }
1775
1776 /// Return the references of this record value.
1777 ArrayRef<SMRange> getReferenceLocs() const { return ReferenceLocs; }
1778
1779 /// Add a reference to the value named \p Name.
1780 void appendValueReferenceLoc(const Init *Name, SMRange Loc) const {
1781 ValueReferenceLocs[Name].push_back(Loc);
1782 }
1783
1784 /// Add the references to the value named \p Name in \p From.
1785 void appendValueReferenceLocs(const Record &From, const Init *Name) const {
1786 auto It = From.ValueReferenceLocs.find(Name);
1787 if (It != From.ValueReferenceLocs.end())
1788 llvm::append_range(ValueReferenceLocs[Name], It->second);
1789 }
1790
1791 /// Return the references to the value named \p Name.
1793 auto It = ValueReferenceLocs.find(Name);
1794 if (It == ValueReferenceLocs.end())
1795 return {};
1796 return It->second;
1797 }
1798
1799 // Update a class location when encountering a (re-)definition.
1800 void updateClassLoc(SMLoc Loc);
1801
1802 // Make the type that this record should have based on its superclasses.
1803 const RecordRecTy *getType() const;
1804
1805 /// get the corresponding DefInit.
1806 DefInit *getDefInit() const;
1807
1808 bool isClass() const { return Kind == RK_Class; }
1809
1810 bool isMultiClass() const { return Kind == RK_MultiClass; }
1811
1812 bool isAnonymous() const { return Kind == RK_AnonymousDef; }
1813
1814 ArrayRef<const Init *> getTemplateArgs() const { return TemplateArgs; }
1815
1816 ArrayRef<RecordVal> getValues() const { return Values; }
1817
1818 ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
1819 ArrayRef<DumpInfo> getDumps() const { return Dumps; }
1820
1821 /// Append all superclasses in post-order to \p Classes.
1822 void getSuperClasses(std::vector<const Record *> &Classes) const {
1823 for (const Record *SC : make_first_range(DirectSuperClasses)) {
1824 SC->getSuperClasses(Classes);
1825 Classes.push_back(SC);
1826 }
1827 }
1828
1829 /// Return all superclasses in post-order.
1830 std::vector<const Record *> getSuperClasses() const {
1831 std::vector<const Record *> Classes;
1832 getSuperClasses(Classes);
1833 return Classes;
1834 }
1835
1836 /// Determine whether this record has the specified direct superclass.
1838 return is_contained(make_first_range(DirectSuperClasses), SuperClass);
1839 }
1840
1841 /// Return the direct superclasses of this record.
1843 return DirectSuperClasses;
1844 }
1845
1846 bool isTemplateArg(const Init *Name) const {
1847 return llvm::is_contained(TemplateArgs, Name);
1848 }
1849
1850 const RecordVal *getValue(const Init *Name) const {
1851 for (const RecordVal &Val : Values)
1852 if (Val.Name == Name) return &Val;
1853 return nullptr;
1854 }
1855
1856 const RecordVal *getValue(StringRef Name) const {
1857 return getValue(StringInit::get(getRecords(), Name));
1858 }
1859
1860 RecordVal *getValue(const Init *Name) {
1861 return const_cast<RecordVal *>(
1862 static_cast<const Record *>(this)->getValue(Name));
1863 }
1864
1866 return const_cast<RecordVal *>(
1867 static_cast<const Record *>(this)->getValue(Name));
1868 }
1869
1870 void addTemplateArg(const Init *Name) {
1871 assert(!isTemplateArg(Name) && "Template arg already defined!");
1872 TemplateArgs.push_back(Name);
1873 }
1874
1875 void addValue(const RecordVal &RV) {
1876 assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
1877 Values.push_back(RV);
1878 }
1879
1880 void removeValue(const Init *Name) {
1881 auto It = llvm::find_if(
1882 Values, [Name](const RecordVal &V) { return V.getNameInit() == Name; });
1883 if (It == Values.end())
1884 llvm_unreachable("Cannot remove an entry that does not exist!");
1885 Values.erase(It);
1886 }
1887
1890 }
1891
1892 void addAssertion(SMLoc Loc, const Init *Condition, const Init *Message) {
1893 Assertions.push_back(AssertionInfo(Loc, Condition, Message));
1894 }
1895
1896 void addDump(SMLoc Loc, const Init *Message) {
1897 Dumps.push_back(DumpInfo(Loc, Message));
1898 }
1899
1900 void appendAssertions(const Record *Rec) {
1901 Assertions.append(Rec->Assertions);
1902 }
1903
1904 void appendDumps(const Record *Rec) { Dumps.append(Rec->Dumps); }
1905
1906 void checkRecordAssertions();
1907 void emitRecordDumps();
1909
1910 bool isSubClassOf(const Record *R) const {
1911 for (const Record *SC : make_first_range(DirectSuperClasses)) {
1912 if (SC == R || SC->isSubClassOf(R))
1913 return true;
1914 }
1915 return false;
1916 }
1917
1918 bool isSubClassOf(StringRef Name) const {
1919 for (const Record *SC : make_first_range(DirectSuperClasses)) {
1920 if (const auto *SI = dyn_cast<StringInit>(SC->getNameInit())) {
1921 if (SI->getValue() == Name)
1922 return true;
1923 } else if (SC->getNameInitAsString() == Name) {
1924 return true;
1925 }
1926 if (SC->isSubClassOf(Name))
1927 return true;
1928 }
1929 return false;
1930 }
1931
1933 assert(!CorrespondingDefInit &&
1934 "changing type of record after it has been referenced");
1935 assert(!isSubClassOf(R) && "Already subclassing record!");
1936 DirectSuperClasses.emplace_back(R, Range);
1937 }
1938
1939 /// If there are any field references that refer to fields that have been
1940 /// filled in, we can propagate the values now.
1941 ///
1942 /// This is a final resolve: any error messages, e.g. due to undefined !cast
1943 /// references, are generated now.
1944 void resolveReferences(const Init *NewName = nullptr);
1945
1946 /// Apply the resolver to the name of the record as well as to the
1947 /// initializers of all fields of the record except SkipVal.
1948 ///
1949 /// The resolver should not resolve any of the fields itself, to avoid
1950 /// recursion / infinite loops.
1951 void resolveReferences(Resolver &R, const RecordVal *SkipVal = nullptr);
1952
1954 return TrackedRecords;
1955 }
1956
1957 void dump() const;
1958
1959 //===--------------------------------------------------------------------===//
1960 // High-level methods useful to tablegen back-ends
1961 //
1962
1963 /// Return the source location for the named field.
1964 SMLoc getFieldLoc(StringRef FieldName) const;
1965
1966 /// Return the initializer for a value with the specified name, or throw an
1967 /// exception if the field does not exist.
1968 const Init *getValueInit(StringRef FieldName) const;
1969
1970 /// Return true if the named field is unset.
1971 bool isValueUnset(StringRef FieldName) const {
1972 return isa<UnsetInit>(getValueInit(FieldName));
1973 }
1974
1975 /// This method looks up the specified field and returns its value as a
1976 /// string, throwing an exception if the field does not exist or if the value
1977 /// is not a string.
1978 StringRef getValueAsString(StringRef FieldName) const;
1979
1980 /// This method looks up the specified field and returns its value as a
1981 /// string, throwing an exception if the value is not a string and
1982 /// std::nullopt if the field does not exist.
1983 std::optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
1984
1985 /// This method looks up the specified field and returns its value as a
1986 /// BitsInit, throwing an exception if the field does not exist or if the
1987 /// value is not the right type.
1988 const BitsInit *getValueAsBitsInit(StringRef FieldName) const;
1989
1990 /// This method looks up the specified field and returns its value as a
1991 /// ListInit, throwing an exception if the field does not exist or if the
1992 /// value is not the right type.
1993 const ListInit *getValueAsListInit(StringRef FieldName) const;
1994
1995 /// This method looks up the specified field and returns its value as a
1996 /// vector of records, throwing an exception if the field does not exist or
1997 /// if the value is not the right type.
1998 std::vector<const Record *> getValueAsListOfDefs(StringRef FieldName) const;
1999
2000 /// This method looks up the specified field and returns its value as a
2001 /// vector of integers, throwing an exception if the field does not exist or
2002 /// if the value is not the right type.
2003 std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
2004
2005 /// This method looks up the specified field and returns its value as a
2006 /// vector of strings, throwing an exception if the field does not exist or
2007 /// if the value is not the right type.
2008 std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
2009
2010 /// This method looks up the specified field and returns its value as a
2011 /// Record, throwing an exception if the field does not exist or if the value
2012 /// is not the right type.
2013 const Record *getValueAsDef(StringRef FieldName) const;
2014
2015 /// This method looks up the specified field and returns its value as a
2016 /// Record, returning null if the field exists but is "uninitialized" (i.e.
2017 /// set to `?`), and throwing an exception if the field does not exist or if
2018 /// its value is not the right type.
2019 const Record *getValueAsOptionalDef(StringRef FieldName) const;
2020
2021 /// This method looks up the specified field and returns its value as a bit,
2022 /// throwing an exception if the field does not exist or if the value is not
2023 /// the right type.
2024 bool getValueAsBit(StringRef FieldName) const;
2025
2026 /// This method looks up the specified field and returns its value as a bit.
2027 /// If the field is unset, sets Unset to true and returns false.
2028 bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
2029
2030 /// This method looks up the specified field and returns its value as an
2031 /// int64_t, throwing an exception if the field does not exist or if the
2032 /// value is not the right type.
2033 int64_t getValueAsInt(StringRef FieldName) const;
2034
2035 /// This method looks up the specified field and returns its value as an Dag,
2036 /// throwing an exception if the field does not exist or if the value is not
2037 /// the right type.
2038 const DagInit *getValueAsDag(StringRef FieldName) const;
2039};
2040
2041raw_ostream &operator<<(raw_ostream &OS, const Record &R);
2042
2044 using RecordMap = StringMap<std::unique_ptr<Record>>;
2045 using GlobalMap = std::map<std::string, const Init *, std::less<>>;
2046
2047public:
2048 RecordKeeper();
2050
2051 /// Return the internal implementation of the RecordKeeper.
2053
2054 /// Get the main TableGen input file's name.
2055 StringRef getInputFilename() const { return InputFilename; }
2056
2057 /// Get all classes, sorted by name.
2059
2060 /// Get all records (defs), sorted by name.
2062
2063 /// Get the map of global variables.
2064 const GlobalMap &getGlobals() const { return ExtraGlobals; }
2065
2066 /// Get the class with the specified name.
2067 const Record *getClass(StringRef Name) const {
2068 auto It = Classes.find(Name);
2069 return It == Classes.end() ? nullptr : It->second.get();
2070 }
2071
2072 /// Get the concrete record with the specified name.
2073 const Record *getDef(StringRef Name) const {
2074 auto It = Defs.find(Name);
2075 return It == Defs.end() ? nullptr : It->second.get();
2076 }
2077
2078 /// Get the \p Init value of the specified global variable.
2079 const Init *getGlobal(StringRef Name) const {
2080 if (const Record *R = getDef(Name))
2081 return R->getDefInit();
2082 auto It = ExtraGlobals.find(Name);
2083 return It == ExtraGlobals.end() ? nullptr : It->second;
2084 }
2085
2086 void saveInputFilename(std::string Filename) {
2087 InputFilename = std::move(Filename);
2088 }
2089
2090 void addClass(std::unique_ptr<Record> R) {
2091 bool Ins = Classes.try_emplace(R->getName(), std::move(R)).second;
2092 (void)Ins;
2093 assert(Ins && "Class already exists");
2094 }
2095
2096 void addDef(std::unique_ptr<Record> R) {
2097 for (const Record *SC : make_first_range(R->getDirectSuperClasses()))
2098 DefsByDirectSuperClass[SC].push_back(R.get());
2099 bool Ins = Defs.try_emplace(R->getName(), std::move(R)).second;
2100 (void)Ins;
2101 assert(Ins && "Record already exists");
2102 // Clear cache
2103 if (!Cache.empty())
2104 Cache.clear();
2105 }
2106
2107 void addExtraGlobal(StringRef Name, const Init *I) {
2108 bool Ins = ExtraGlobals.try_emplace(std::string(Name), I).second;
2109 (void)Ins;
2110 assert(!getDef(Name));
2111 assert(Ins && "Global already exists");
2112 }
2113
2114 const Init *getNewAnonymousName();
2115
2116 TGTimer &getTimer() const { return *Timer; }
2117
2118 //===--------------------------------------------------------------------===//
2119 // High-level helper methods, useful for tablegen backends.
2120
2121 /// Get all the concrete records that inherit from the one specified
2122 /// class. The class must be defined.
2124
2125 /// Get all the concrete records that inherit from all the specified
2126 /// classes. The classes must be defined.
2127 std::vector<const Record *>
2129
2130 /// Get all the concrete records that inherit from specified class, if the
2131 /// class is defined. Returns an empty vector if the class is not defined.
2134
2135 void dump() const;
2136
2137 void dumpAllocationStats(raw_ostream &OS) const;
2138
2139private:
2140 RecordKeeper(RecordKeeper &&) = delete;
2141 RecordKeeper(const RecordKeeper &) = delete;
2142 RecordKeeper &operator=(RecordKeeper &&) = delete;
2143 RecordKeeper &operator=(const RecordKeeper &) = delete;
2144
2145 std::string InputFilename;
2146 RecordMap Classes, Defs;
2147 // Classes and Defs sorted by name, built on demand.
2148 mutable std::vector<const Record *> SortedClasses, SortedDefs;
2149 mutable std::map<std::string, std::vector<const Record *>> Cache;
2150 // The defs that each class is a direct superclass of.
2152 DefsByDirectSuperClass;
2153 GlobalMap ExtraGlobals;
2154
2155 /// The internal uniquer implementation of the RecordKeeper.
2156 std::unique_ptr<detail::RecordKeeperImpl> Impl;
2157 std::unique_ptr<TGTimer> Timer;
2158};
2159
2160/// Sorting predicate to sort record pointers by name.
2162 bool operator()(const Record *Rec1, const Record *Rec2) const {
2163 return Rec1->getName().compare_numeric(Rec2->getName()) < 0;
2164 }
2165};
2166
2167/// Sorting predicate to sort record pointers by their
2168/// unique ID. If you just need a deterministic order, use this, since it
2169/// just compares two `unsigned`; the other sorting predicates require
2170/// string manipulation.
2172 bool operator()(const Record *LHS, const Record *RHS) const {
2173 return LHS->getID() < RHS->getID();
2174 }
2175};
2176
2177/// Sorting predicate to sort record pointers by their Name field.
2179 bool operator()(const Record *Rec1, const Record *Rec2) const {
2180 return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
2181 }
2182};
2183
2187
2189 if (Rec.empty())
2190 return;
2191
2192 size_t Len = 0;
2193 const char *Start = Rec.data();
2194 const char *Curr = Start;
2195 bool IsDigitPart = isDigit(Curr[0]);
2196 for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
2197 bool IsDigit = isDigit(Curr[I]);
2198 if (IsDigit != IsDigitPart) {
2199 Parts.emplace_back(IsDigitPart, StringRef(Start, Len));
2200 Len = 0;
2201 Start = &Curr[I];
2202 IsDigitPart = isDigit(Curr[I]);
2203 }
2204 }
2205 // Push the last part.
2206 Parts.emplace_back(IsDigitPart, StringRef(Start, Len));
2207 }
2208
2209 size_t size() { return Parts.size(); }
2210
2211 std::pair<bool, StringRef> getPart(size_t Idx) { return Parts[Idx]; }
2212 };
2213
2214 bool operator()(const Record *Rec1, const Record *Rec2) const {
2215 int64_t LHSPositionOrder = Rec1->getValueAsInt("PositionOrder");
2216 int64_t RHSPositionOrder = Rec2->getValueAsInt("PositionOrder");
2217 if (LHSPositionOrder != RHSPositionOrder)
2218 return LHSPositionOrder < RHSPositionOrder;
2219
2220 RecordParts LHSParts(StringRef(Rec1->getName()));
2221 RecordParts RHSParts(StringRef(Rec2->getName()));
2222
2223 size_t LHSNumParts = LHSParts.size();
2224 size_t RHSNumParts = RHSParts.size();
2225 assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
2226
2227 if (LHSNumParts != RHSNumParts)
2228 return LHSNumParts < RHSNumParts;
2229
2230 // We expect the registers to be of the form [_a-zA-Z]+([0-9]*[_a-zA-Z]*)*.
2231 for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
2232 std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
2233 std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
2234 // Expect even part to always be alpha.
2235 assert (LHSPart.first == false && RHSPart.first == false &&
2236 "Expected both parts to be alpha.");
2237 if (int Res = LHSPart.second.compare(RHSPart.second))
2238 return Res < 0;
2239 }
2240 for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
2241 std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
2242 std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
2243 // Expect odd part to always be numeric.
2244 assert (LHSPart.first == true && RHSPart.first == true &&
2245 "Expected both parts to be numeric.");
2246 if (LHSPart.second.size() != RHSPart.second.size())
2247 return LHSPart.second.size() < RHSPart.second.size();
2248
2249 unsigned LHSVal, RHSVal;
2250
2251 bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
2252 assert(!LHSFailed && "Unable to convert LHS to integer.");
2253 bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
2254 assert(!RHSFailed && "Unable to convert RHS to integer.");
2255
2256 if (LHSVal != RHSVal)
2257 return LHSVal < RHSVal;
2258 }
2259 return LHSNumParts < RHSNumParts;
2260 }
2261};
2262
2263raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
2264
2265//===----------------------------------------------------------------------===//
2266// Resolvers
2267//===----------------------------------------------------------------------===//
2268
2269/// Interface for looking up the initializer for a variable name, used by
2270/// Init::resolveReferences.
2272 const Record *CurRec;
2273 bool IsFinal = false;
2274
2275public:
2276 explicit Resolver(const Record *CurRec) : CurRec(CurRec) {}
2277 virtual ~Resolver() = default;
2278
2279 const Record *getCurrentRecord() const { return CurRec; }
2280
2281 /// Return the initializer for the given variable name (should normally be a
2282 /// StringInit), or nullptr if the name could not be resolved.
2283 virtual const Init *resolve(const Init *VarName) = 0;
2284
2285 // Whether bits in a BitsInit should stay unresolved if resolving them would
2286 // result in a ? (UnsetInit). This behavior is used to represent instruction
2287 // encodings by keeping references to unset variables within a record.
2288 virtual bool keepUnsetBits() const { return false; }
2289
2290 // Whether this is the final resolve step before adding a record to the
2291 // RecordKeeper. Error reporting during resolve and related constant folding
2292 // should only happen when this is true.
2293 bool isFinal() const { return IsFinal; }
2294
2295 void setFinal(bool Final) {
2296 IsFinal = Final;
2298 }
2299
2300 /// Return the cached result of resolving \p I, or nullptr. \p FoundUnresolved
2301 /// is set if the result has unresolved references.
2302 virtual const Init *getCachedResult(const Init *I,
2303 bool &FoundUnresolved) const {
2304 return nullptr;
2305 }
2306
2307 /// Cache the result of resolving \p I.
2308 virtual void cacheResult(const Init *I, const Init *Result,
2309 bool FoundUnresolved) {}
2310
2311 /// Called when a cached result has unresolved references.
2312 virtual void noteUnresolved() {}
2313
2314protected:
2315 virtual void clearCachedResults() {}
2316};
2317
2318/// Resolve arbitrary mappings.
2319class MapResolver final : public Resolver {
2320 struct MappedValue {
2321 const Init *V;
2322 bool Resolved;
2323
2324 MappedValue() : V(nullptr), Resolved(false) {}
2325 MappedValue(const Init *V, bool Resolved) : V(V), Resolved(Resolved) {}
2326 };
2327
2330 // Number of mapped values being resolved. Each is removed from Map while it
2331 // is resolved to prevent infinite recursion, so results computed meanwhile
2332 // may be incomplete and are not cached.
2333 unsigned NumInProgress = 0;
2334
2335public:
2336 explicit MapResolver(const Record *CurRec = nullptr) : Resolver(CurRec) {}
2337
2338 void set(const Init *Key, const Init *Value) {
2339 Map[Key] = {Value, false};
2341 }
2342
2343 bool isComplete(Init *VarName) const {
2344 auto It = Map.find(VarName);
2345 assert(It != Map.end() && "key must be present in map");
2346 return It->second.V->isComplete();
2347 }
2348
2349 const Init *resolve(const Init *VarName) override;
2350
2352 bool &FoundUnresolved) const override {
2353 if (NumInProgress)
2354 return nullptr;
2355 auto [Result, Unresolved] = ResultCache.lookup(I);
2356 FoundUnresolved = Unresolved;
2357 return Result;
2358 }
2359
2360 void cacheResult(const Init *I, const Init *Result,
2361 bool FoundUnresolved) override {
2362 if (!NumInProgress)
2363 ResultCache[I] = {Result, FoundUnresolved};
2364 }
2365
2366protected:
2367 void clearCachedResults() override { ResultCache.clear(); }
2368};
2369
2370/// Resolve all variables from a record except for unset variables.
2371class RecordResolver final : public Resolver {
2375 const Init *Name = nullptr;
2376
2377public:
2378 explicit RecordResolver(const Record &R) : Resolver(&R) {}
2379
2380 void setName(const Init *NewName) {
2381 Name = NewName;
2383 }
2384
2385 const Init *resolve(const Init *VarName) override;
2386
2387 bool keepUnsetBits() const override { return true; }
2388
2389 // Variables on the stack resolve to nullptr to prevent infinite recursion,
2390 // so results computed meanwhile may be incomplete and are not cached.
2392 bool &FoundUnresolved) const override {
2393 if (!Stack.empty())
2394 return nullptr;
2395 auto [Result, Unresolved] = ResultCache.lookup(I);
2396 FoundUnresolved = Unresolved;
2397 return Result;
2398 }
2399
2400 void cacheResult(const Init *I, const Init *Result,
2401 bool FoundUnresolved) override {
2402 if (Stack.empty())
2403 ResultCache[I] = {Result, FoundUnresolved};
2404 }
2405
2406protected:
2407 void clearCachedResults() override { ResultCache.clear(); }
2408};
2409
2410/// Delegate resolving to a sub-resolver, but shadow some variable names.
2411class ShadowResolver final : public Resolver {
2412 Resolver &R;
2413 DenseSet<const Init *> Shadowed;
2414
2415public:
2417 : Resolver(R.getCurrentRecord()), R(R) {
2418 setFinal(R.isFinal());
2419 }
2420
2421 void addShadow(const Init *Key) { Shadowed.insert(Key); }
2422
2423 const Init *resolve(const Init *VarName) override {
2424 if (Shadowed.count(VarName))
2425 return nullptr;
2426 return R.resolve(VarName);
2427 }
2428};
2429
2430/// (Optionally) delegate resolving to a sub-resolver, and keep track whether
2431/// there were unresolved references.
2432class TrackUnresolvedResolver final : public Resolver {
2433 Resolver *R;
2434 bool FoundUnresolved = false;
2435
2436public:
2437 explicit TrackUnresolvedResolver(Resolver *R = nullptr)
2438 : Resolver(R ? R->getCurrentRecord() : nullptr), R(R) {}
2439
2440 bool foundUnresolved() const { return FoundUnresolved; }
2441
2442 const Init *resolve(const Init *VarName) override;
2443
2444 // Tracking doesn't change results, so share the underlying resolver's cache.
2445 const Init *getCachedResult(const Init *I, bool &Unresolved) const override {
2446 return R ? R->getCachedResult(I, Unresolved) : nullptr;
2447 }
2448
2449 void cacheResult(const Init *I, const Init *Result,
2450 bool Unresolved) override {
2451 if (R)
2452 R->cacheResult(I, Result, Unresolved);
2453 }
2454
2455 void noteUnresolved() override {
2456 FoundUnresolved = true;
2457 if (R)
2458 R->noteUnresolved();
2459 }
2460};
2461
2462/// Do not resolve anything, but keep track of whether a given variable was
2463/// referenced.
2464class HasReferenceResolver final : public Resolver {
2465 const Init *VarNameToTrack;
2466 bool Found = false;
2467
2468public:
2469 explicit HasReferenceResolver(const Init *VarNameToTrack)
2470 : Resolver(nullptr), VarNameToTrack(VarNameToTrack) {}
2471
2472 bool found() const { return Found; }
2473
2474 const Init *resolve(const Init *VarName) override;
2475};
2476
2477void EmitDetailedRecords(const RecordKeeper &RK, raw_ostream &OS);
2478void EmitJSON(const RecordKeeper &RK, raw_ostream &OS);
2479
2480} // end namespace llvm
2481
2482#endif // LLVM_TABLEGEN_RECORD_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
uint64_t 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")
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:905
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:964
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:959
BinOpInit & operator=(const BinOpInit &)=delete
const Init * getRHS() const
Definition Record.h:961
std::optional< bool > CompareInit(unsigned Opc, const Init *LHS, const Init *RHS) const
Definition Record.cpp:1110
const Init * getLHS() const
Definition Record.h:960
static bool classof(const Init *I)
Definition Record.h:950
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:1043
CondOpInit & operator=(const CondOpInit &)=delete
SmallVectorImpl< const Init * >::const_iterator const_case_iterator
Definition Record.h:1094
const Init * Fold(const Record *CurRec) const
Definition Record.cpp:2581
SmallVectorImpl< const Init * >::const_iterator const_val_iterator
Definition Record.h:1095
auto getCondAndVals() const
Definition Record.h:1084
const_val_iterator name_end() const
Definition Record.h:1104
bool case_empty() const
Definition Record.h:1101
const_case_iterator arg_end() const
Definition Record.h:1098
size_t case_size() const
Definition Record.h:1100
ArrayRef< const Init * > getVals() const
Definition Record.h:1080
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:1106
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:1072
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:1103
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:1064
unsigned getNumConds() const
Definition Record.h:1070
bool val_empty() const
Definition Record.h:1107
const RecTy * getValType() const
Definition Record.h:1068
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:1055
const Init * getVal(unsigned Num) const
Definition Record.h:1074
const_case_iterator arg_begin() const
Definition Record.h:1097
ArrayRef< const Init * > getConds() const
Definition Record.h:1076
(v a, b) - Represent a DAG tree value.
Definition Record.h:1470
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:1506
unsigned getNumArgs() const
Definition Record.h:1526
const StringInit * getArgName(unsigned Num) const
Definition Record.h:1534
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:1513
DagInit(const DagInit &)=delete
StringRef getArgNameStr(unsigned Num) const
Definition Record.h:1538
const_arg_iterator arg_begin() const
Definition Record.h:1569
const_arg_iterator arg_end() const
Definition Record.h:1570
const StringInit * getName() const
Definition Record.h:1520
const Init * getOperator() const
Definition Record.h:1517
SmallVectorImpl< const StringInit * >::const_iterator const_name_iterator
Definition Record.h:1566
SmallVectorImpl< const Init * >::const_iterator const_arg_iterator
Definition Record.h:1565
static bool classof(const Init *I)
Definition Record.h:1488
const Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition Record.h:1578
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:1496
ArrayRef< const StringInit * > getArgNames() const
Definition Record.h:1547
const_name_iterator name_end() const
Definition Record.h:1576
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:1575
size_t arg_size() const
Definition Record.h:1572
bool arg_empty() const
Definition Record.h:1573
const Record * getOperatorAsDef(ArrayRef< SMLoc > Loc) const
Definition Record.cpp:2670
const Init * getArg(unsigned Num) const
Definition Record.h:1528
StringRef getNameStr() const
Definition Record.h:1522
DagInit & operator=(const DagInit &)=delete
auto getArgAndNames() const
Definition Record.h:1552
ArrayRef< const Init * > getArgs() const
Definition Record.h:1543
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:1336
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:1360
friend class Record
Definition Record.h:1337
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:1347
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations?
Definition Record.h:1357
const Record * getDef() const
Definition Record.h:1353
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:1188
std::pair< const RecTy *, const Init * > getKey() const
Definition Record.h:1205
static bool classof(const Init *I)
Definition Record.h:1201
ExistsOpInit(const ExistsOpInit &)=delete
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition Record.h:1213
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:1424
static bool classof(const Init *I)
Definition Record.h:1444
std::string getAsString() const override
Convert this value to a literal form.
Definition Record.h:1459
const Init * Fold(const Record *CurRec) const
Definition Record.cpp:2499
const StringInit * getFieldName() const
Definition Record.h:1451
const Init * getRecord() const
Definition Record.h:1450
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:1113
const Init * Fold(const Record *CurRec) const
Definition Record.cpp:2022
static bool classof(const Init *I)
Definition Record.h:1126
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:1134
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:1142
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:2469
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3365
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:1225
const Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition Record.h:1254
std::pair< const RecTy *, const Init * > getKey() const
Definition Record.h:1244
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:1238
InstancesOpInit(const InstancesOpInit &)=delete
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition Record.h:1250
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:1152
IsAOpInit(const IsAOpInit &)=delete
IsAOpInit & operator=(const IsAOpInit &)=delete
std::pair< const RecTy *, const Init * > getKey() const
Definition Record.h:1169
static bool classof(const Init *I)
Definition Record.h:1165
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:1177
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:802
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:824
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
const Record * getElementAsRecord(unsigned Idx) const
Definition Record.cpp:710
const_iterator begin() const
Definition Record.h:821
const_iterator end() const
Definition Record.h:822
ArrayRef< const Init * > getElements() const
Definition Record.h:792
std::pair< ArrayRef< const Init * >, const RecTy * > getKey() const
Definition Record.h:798
bool empty() const
Definition Record.h:825
const Init * getElement(unsigned Idx) const
Definition Record.h:796
const Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
Definition Record.h:827
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:2367
const Init * getCachedResult(const Init *I, bool &FoundUnresolved) const override
Return the cached result of resolving I, or nullptr.
Definition Record.h:2351
void cacheResult(const Init *I, const Init *Result, bool FoundUnresolved) override
Cache the result of resolving I.
Definition Record.h:2360
void set(const Init *Key, const Init *Value)
Definition Record.h:2338
bool isComplete(Init *VarName) const
Definition Record.h:2343
MapResolver(const Record *CurRec=nullptr)
Definition Record.h:2336
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3300
Base class for operators.
Definition Record.h:834
OpInit & operator=(OpInit &)=delete
static bool classof(const Init *I)
Definition Record.h:843
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:836
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:2096
void addClass(std::unique_ptr< Record > R)
Definition Record.h:2090
TGTimer & getTimer() const
Definition Record.h:2116
const Record * getClass(StringRef Name) const
Get the class with the specified name.
Definition Record.h:2067
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:2055
detail::RecordKeeperImpl & getImpl()
Return the internal implementation of the RecordKeeper.
Definition Record.h:2052
void saveInputFilename(std::string Filename)
Definition Record.h:2086
const GlobalMap & getGlobals() const
Get the map of global variables.
Definition Record.h:2064
const Init * getGlobal(StringRef Name) const
Get the Init value of the specified global variable.
Definition Record.h:2079
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:3296
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:3290
void addExtraGlobal(StringRef Name, const Init *I)
Definition Record.h:2107
const Record * getDef(StringRef Name) const
Get the concrete record with the specified name.
Definition Record.h:2073
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:2407
bool keepUnsetBits() const override
Definition Record.h:2387
void cacheResult(const Init *I, const Init *Result, bool FoundUnresolved) override
Cache the result of resolving I.
Definition Record.h:2400
RecordResolver(const Record &R)
Definition Record.h:2378
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3320
void setName(const Init *NewName)
Definition Record.h:2380
const Init * getCachedResult(const Init *I, bool &FoundUnresolved) const override
Return the cached result of resolving I, or nullptr.
Definition Record.h:2391
This class represents a field in a record, including its name, type, value, and source location.
Definition Record.h:1589
bool isTemplateArg() const
Is this a template argument?
Definition Record.h:1638
std::string getNameInitAsString() const
Get the name of the field as a std::string.
Definition Record.h:1627
void setUsed(bool Used)
Whether this value is used.
Definition Record.h:1657
bool isNonconcreteOK() const
Is this a field where nonconcrete values are okay?
Definition Record.h:1635
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:1618
SMLoc getLoc() const
Get the source location of the point where the field was defined.
Definition Record.h:1632
const Init * getValue() const
Get the value of the field as an Init.
Definition Record.h:1647
bool isUsed() const
Definition Record.h:1661
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:1590
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:1624
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:1641
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:1754
@ RK_AnonymousDef
Definition Record.h:1696
static unsigned getNewUID(RecordKeeper &RK)
Definition Record.cpp:2843
ArrayRef< SMLoc > getLoc() const
Definition Record.h:1766
void addDump(SMLoc Loc, const Init *Message)
Definition Record.h:1896
void checkUnusedTemplateArgs()
Definition Record.cpp:3147
void emitRecordDumps()
Definition Record.cpp:3136
ArrayRef< DumpInfo > getDumps() const
Definition Record.h:1819
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:1812
ArrayRef< AssertionInfo > getAssertions() const
Definition Record.h:1818
void appendValueReferenceLoc(const Init *Name, SMRange Loc) const
Add a reference to the value named Name.
Definition Record.h:1780
std::string getNameInitAsString() const
Definition Record.h:1760
void removeValue(StringRef Name)
Definition Record.h:1888
void appendValueReferenceLocs(const Record &From, const Init *Name) const
Add the references to the value named Name in From.
Definition Record.h:1785
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:1953
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:1850
void addTemplateArg(const Init *Name)
Definition Record.h:1870
void appendLoc(SMLoc Loc)
Definition Record.h:1767
Record(const Record &O)
Definition Record.h:1745
bool isValueUnset(StringRef FieldName) const
Return true if the named field is unset.
Definition Record.h:1971
std::vector< const Record * > getSuperClasses() const
Return all superclasses in post-order.
Definition Record.h:1830
bool isMultiClass() const
Definition Record.h:1810
bool hasDirectSuperClass(const Record *SuperClass) const
Determine whether this record has the specified direct superclass.
Definition Record.h:1837
void addValue(const RecordVal &RV)
Definition Record.h:1875
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:1892
Record(StringRef N, ArrayRef< SMLoc > locs, RecordKeeper &records, RecordKind Kind=RK_Def)
Definition Record.h:1738
bool isClass() const
Definition Record.h:1808
ArrayRef< std::pair< const Record *, SMRange > > getDirectSuperClasses() const
Return the direct superclasses of this record.
Definition Record.h:1842
StringRef getName() const
Definition Record.h:1756
Record(const Init *N, ArrayRef< SMLoc > locs, RecordKeeper &records, RecordKind Kind=RK_Def)
Definition Record.h:1731
bool isTemplateArg(const Init *Name) const
Definition Record.h:1846
void setName(const Init *Name)
Definition Record.cpp:2847
bool isSubClassOf(StringRef Name) const
Definition Record.h:1918
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:1904
bool isSubClassOf(const Record *R) const
Definition Record.h:1910
DefInit * getDefInit() const
get the corresponding DefInit.
Definition Record.cpp:2835
ArrayRef< RecordVal > getValues() const
Definition Record.h:1816
SMLoc getFieldLoc(StringRef FieldName) const
Return the source location for the named field.
Definition Record.cpp:2953
ArrayRef< SMLoc > getForwardDeclarationLocs() const
Definition Record.h:1769
const RecordVal * getValue(StringRef Name) const
Definition Record.h:1856
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:1880
ArrayRef< const Init * > getTemplateArgs() const
Definition Record.h:1814
ArrayRef< SMRange > getReferenceLocs() const
Return the references of this record value.
Definition Record.h:1777
void updateClassLoc(SMLoc Loc)
Definition Record.cpp:2813
RecordVal * getValue(const Init *Name)
Definition Record.h:1860
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:1932
ArrayRef< SMRange > getValueReferenceLocs(const Init *Name) const
Return the references to the value named Name.
Definition Record.h:1792
void appendAssertions(const Record *Rec)
Definition Record.h:1900
const Init * getNameInit() const
Definition Record.h:1758
void getSuperClasses(std::vector< const Record * > &Classes) const
Append all superclasses in post-order to Classes.
Definition Record.h:1822
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:1865
void checkRecordAssertions()
Definition Record.cpp:3117
void appendReferenceLoc(SMRange Loc) const
Add a reference to this record value.
Definition Record.h:1774
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:2271
virtual ~Resolver()=default
virtual void noteUnresolved()
Called when a cached result has unresolved references.
Definition Record.h:2312
virtual const Init * getCachedResult(const Init *I, bool &FoundUnresolved) const
Return the cached result of resolving I, or nullptr.
Definition Record.h:2302
virtual void cacheResult(const Init *I, const Init *Result, bool FoundUnresolved)
Cache the result of resolving I.
Definition Record.h:2308
bool isFinal() const
Definition Record.h:2293
Resolver(const Record *CurRec)
Definition Record.h:2276
const Record * getCurrentRecord() const
Definition Record.h:2279
virtual void clearCachedResults()
Definition Record.h:2315
void setFinal(bool Final)
Definition Record.h:2295
virtual bool keepUnsetBits() const
Definition Record.h:2288
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:2416
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.h:2423
void addShadow(const Init *Key)
Definition Record.h:2421
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:981
TernOpInit(const TernOpInit &)=delete
const Init * Fold(const Record *CurRec) const
Definition Record.cpp:1742
const Init * getLHS() const
Definition Record.h:1016
bool isComplete() const override
Is this a complete value with no unset (uninitialized) subvalues?
Definition Record.h:1029
static bool classof(const Init *I)
Definition Record.h:1008
std::tuple< TernaryOp, const Init *, const Init *, const Init *, const RecTy * > getKey() const
Definition Record.h:1021
const Init * getMHS() const
Definition Record.h:1017
const Init * getRHS() const
Definition Record.h:1018
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:1015
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:2445
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3345
void noteUnresolved() override
Called when a cached result has unresolved references.
Definition Record.h:2455
TrackUnresolvedResolver(Resolver *R=nullptr)
Definition Record.h:2437
void cacheResult(const Init *I, const Init *Result, bool Unresolved) override
Cache the result of resolving I.
Definition Record.h:2449
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:853
const Init * getOperand() const
Definition Record.h:889
UnOpInit & operator=(const UnOpInit &)=delete
static bool classof(const Init *I)
Definition Record.h:882
UnaryOp getOpcode() const
Definition Record.h:888
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:891
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:1299
static const VarBitInit * get(const TypedInit *T, unsigned B)
Definition Record.cpp:2309
unsigned getBitNum() const
Definition Record.h:1324
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:1323
static bool classof(const Init *I)
Definition Record.h:1317
const Init * getBit(unsigned B) const override
Get the Init value of the specified bit.
Definition Record.h:1329
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:1370
size_t args_size() const
Definition Record.h:1411
ArrayRef< const ArgumentInit * > args() const
Definition Record.h:1414
const ArgumentInit * getArg(unsigned i) const
Definition Record.h:1404
std::pair< const Record *, ArrayRef< const ArgumentInit * > > getKey() const
Definition Record.h:1395
const_iterator args_end() const
Definition Record.h:1409
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:1408
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:1418
const ArgumentInit *const * const_iterator
Definition Record.h:1406
static bool classof(const Init *I)
Definition Record.h:1389
VarDefInit(const VarDefInit &)=delete
bool args_empty() const
Definition Record.h:1412
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:1262
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:1272
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:1295
VarInit(const VarInit &)=delete
const Init * getNameInit() const
Definition Record.h:1280
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:1282
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:2171
bool operator()(const Record *LHS, const Record *RHS) const
Definition Record.h:2172
Sorting predicate to sort record pointers by their Name field.
Definition Record.h:2178
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition Record.h:2179
std::pair< bool, StringRef > getPart(size_t Idx)
Definition Record.h:2211
SmallVector< std::pair< bool, StringRef >, 4 > Parts
Definition Record.h:2186
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition Record.h:2214
Sorting predicate to sort record pointers by name.
Definition Record.h:2161
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition Record.h:2162
AssertionInfo(SMLoc Loc, const Init *Condition, const Init *Message)
Definition Record.h:1683
DumpInfo(SMLoc Loc, const Init *Message)
Definition Record.h:1693
const Init * Message
Definition Record.h:1689