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. This is never null: a field that
1647 /// has not been given a value has an UnsetInit.
1648 const Init *getValue() const { return Value; }
1649
1650 /// Set the value of the field from an Init.
1651 bool setValue(const Init *V);
1652
1653 /// Set the value and source location of the field.
1654 bool setValue(const Init *V, SMLoc NewLoc);
1655
1656 /// Whether this value is used. Useful for reporting warnings, for example
1657 /// when a template argument is unused.
1658 void setUsed(bool Used) {
1659 unsigned Flags = TyAndFlags.getInt() & ~UsedBit;
1660 TyAndFlags.setInt(Used ? Flags | UsedBit : Flags);
1661 }
1662 bool isUsed() const { return TyAndFlags.getInt() & UsedBit; }
1663
1664 void dump() const;
1665
1666 /// Print the value to an output stream, possibly with a semicolon.
1667 void print(raw_ostream &OS, bool PrintSem = true) const;
1668};
1669
1671 RV.print(OS << " ");
1672 return OS;
1673}
1674
1675class Record {
1676public:
1681
1682 // User-defined constructor to support std::make_unique(). It can be
1683 // removed in C++20 when braced initialization is supported.
1686 };
1687
1688 struct DumpInfo {
1691
1692 // User-defined constructor to support std::make_unique(). It can be
1693 // removed in C++20 when braced initialization is supported.
1695 };
1696
1698
1699private:
1700 const Init *Name;
1701 // Location where record was instantiated, followed by the location of
1702 // multiclass prototypes used, and finally by the locations of references to
1703 // this record.
1705 SmallVector<SMLoc, 0> ForwardDeclarationLocs;
1706 mutable SmallVector<SMRange, 0> ReferenceLocs;
1707 mutable DenseMap<const Init *, SmallVector<SMRange, 0>> ValueReferenceLocs;
1708 // Template arguments, in order.
1710 // Fields, including the ones inherited from superclasses.
1714
1715 // Direct superclasses, which are roots of the inheritance forest (yes, it
1716 // must be a forest; diamond-shaped inheritance is not allowed).
1718
1719 // Tracks Record instances. Not owned by Record.
1720 RecordKeeper &TrackedRecords;
1721
1722 // The DefInit corresponding to this record.
1723 mutable DefInit *CorrespondingDefInit = nullptr;
1724
1725 // Unique record ID.
1726 unsigned ID;
1727
1728 RecordKind Kind;
1729
1730 void checkName();
1731
1732public:
1733 // Constructs a record.
1734 explicit Record(const Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1735 RecordKind Kind = RK_Def)
1736 : Name(N), Locs(locs), TrackedRecords(records),
1737 ID(getNewUID(N->getRecordKeeper())), Kind(Kind) {
1738 checkName();
1739 }
1740
1742 RecordKind Kind = RK_Def)
1743 : Record(StringInit::get(records, N), locs, records, Kind) {}
1744
1745 // When copy-constructing a Record, we must still guarantee a globally unique
1746 // ID number. Don't copy CorrespondingDefInit either, since it's owned by the
1747 // original record. All other fields can be copied normally.
1748 Record(const Record &O)
1749 : Name(O.Name), Locs(O.Locs), ValueReferenceLocs(O.ValueReferenceLocs),
1750 TemplateArgs(O.TemplateArgs), Values(O.Values),
1751 Assertions(O.Assertions), Dumps(O.Dumps),
1752 DirectSuperClasses(O.DirectSuperClasses),
1753 TrackedRecords(O.TrackedRecords), ID(getNewUID(O.getRecords())),
1754 Kind(O.Kind) {}
1755
1756 static unsigned getNewUID(RecordKeeper &RK);
1757
1758 unsigned getID() const { return ID; }
1759
1760 StringRef getName() const { return cast<StringInit>(Name)->getValue(); }
1761
1762 const Init *getNameInit() const { return Name; }
1763
1764 std::string getNameInitAsString() const {
1765 return getNameInit()->getAsUnquotedString();
1766 }
1767
1768 void setName(const Init *Name); // Also updates RecordKeeper.
1769
1770 ArrayRef<SMLoc> getLoc() const { return Locs; }
1771 void appendLoc(SMLoc Loc) { Locs.push_back(Loc); }
1772
1774 return ForwardDeclarationLocs;
1775 }
1776
1777 /// Add a reference to this record value.
1778 void appendReferenceLoc(SMRange Loc) const { ReferenceLocs.push_back(Loc); }
1779
1780 /// Return the references of this record value.
1781 ArrayRef<SMRange> getReferenceLocs() const { return ReferenceLocs; }
1782
1783 /// Add a reference to the value named \p Name.
1784 void appendValueReferenceLoc(const Init *Name, SMRange Loc) const {
1785 ValueReferenceLocs[Name].push_back(Loc);
1786 }
1787
1788 /// Add the references to the value named \p Name in \p From.
1789 void appendValueReferenceLocs(const Record &From, const Init *Name) const {
1790 auto It = From.ValueReferenceLocs.find(Name);
1791 if (It != From.ValueReferenceLocs.end())
1792 llvm::append_range(ValueReferenceLocs[Name], It->second);
1793 }
1794
1795 /// Return the references to the value named \p Name.
1797 auto It = ValueReferenceLocs.find(Name);
1798 if (It == ValueReferenceLocs.end())
1799 return {};
1800 return It->second;
1801 }
1802
1803 // Update a class location when encountering a (re-)definition.
1804 void updateClassLoc(SMLoc Loc);
1805
1806 // Make the type that this record should have based on its superclasses.
1807 const RecordRecTy *getType() const;
1808
1809 /// get the corresponding DefInit.
1810 DefInit *getDefInit() const;
1811
1812 bool isClass() const { return Kind == RK_Class; }
1813
1814 bool isMultiClass() const { return Kind == RK_MultiClass; }
1815
1816 bool isAnonymous() const { return Kind == RK_AnonymousDef; }
1817
1818 /// Return the template arguments of this class or multiclass.
1819 ArrayRef<RecordVal> getTemplateArgs() const { return TemplateArgs; }
1820
1821 /// Return the fields of this record.
1822 ArrayRef<RecordVal> getValues() const { return Values; }
1823
1824 ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
1825 ArrayRef<DumpInfo> getDumps() const { return Dumps; }
1826
1827 /// Append all superclasses in post-order to \p Classes.
1828 void getSuperClasses(std::vector<const Record *> &Classes) const {
1829 for (const Record *SC : make_first_range(DirectSuperClasses)) {
1830 SC->getSuperClasses(Classes);
1831 Classes.push_back(SC);
1832 }
1833 }
1834
1835 /// Return all superclasses in post-order.
1836 std::vector<const Record *> getSuperClasses() const {
1837 std::vector<const Record *> Classes;
1838 getSuperClasses(Classes);
1839 return Classes;
1840 }
1841
1842 /// Determine whether this record has the specified direct superclass.
1844 return is_contained(make_first_range(DirectSuperClasses), SuperClass);
1845 }
1846
1847 /// Return the direct superclasses of this record.
1849 return DirectSuperClasses;
1850 }
1851
1852 /// Return the template argument with the given name, or null if there is
1853 /// none.
1854 const RecordVal *getTemplateArg(const Init *Name) const {
1855 for (const RecordVal &Arg : TemplateArgs)
1856 if (Arg.Name == Name)
1857 return &Arg;
1858 return nullptr;
1859 }
1860
1862 return const_cast<RecordVal *>(
1863 static_cast<const Record *>(this)->getTemplateArg(Name));
1864 }
1865
1866 /// Return the field with the given name, or null if there is none. Use
1867 /// getTemplateArg() to look up template arguments.
1868 const RecordVal *getValue(const Init *Name) const {
1869 for (const RecordVal &Val : Values)
1870 if (Val.Name == Name) return &Val;
1871 return nullptr;
1872 }
1873
1874 const RecordVal *getValue(StringRef Name) const {
1875 return getValue(StringInit::get(getRecords(), Name));
1876 }
1877
1878 RecordVal *getValue(const Init *Name) {
1879 return const_cast<RecordVal *>(
1880 static_cast<const Record *>(this)->getValue(Name));
1881 }
1882
1884 return const_cast<RecordVal *>(
1885 static_cast<const Record *>(this)->getValue(Name));
1886 }
1887
1888 /// Add a template argument. Return false, without adding it, if there is
1889 /// already a template argument with the same name.
1890 bool addTemplateArg(const RecordVal &Arg) {
1891 assert(Arg.isTemplateArg() && "Not a template argument!");
1892 if (getTemplateArg(Arg.getNameInit()))
1893 return false;
1894 TemplateArgs.push_back(Arg);
1895 return true;
1896 }
1897
1898 void addValue(const RecordVal &RV) {
1899 assert(!RV.isTemplateArg() && "Use addTemplateArg for template arguments");
1900 assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
1901 Values.push_back(RV);
1902 }
1903
1904 void removeValue(const Init *Name) {
1905 auto It = llvm::find_if(
1906 Values, [Name](const RecordVal &V) { return V.getNameInit() == Name; });
1907 if (It == Values.end())
1908 llvm_unreachable("Cannot remove an entry that does not exist!");
1909 Values.erase(It);
1910 }
1911
1914 }
1915
1916 void addAssertion(SMLoc Loc, const Init *Condition, const Init *Message) {
1917 Assertions.push_back(AssertionInfo(Loc, Condition, Message));
1918 }
1919
1920 void addDump(SMLoc Loc, const Init *Message) {
1921 Dumps.push_back(DumpInfo(Loc, Message));
1922 }
1923
1924 void appendAssertions(const Record *Rec) {
1925 Assertions.append(Rec->Assertions);
1926 }
1927
1928 void appendDumps(const Record *Rec) { Dumps.append(Rec->Dumps); }
1929
1930 void checkRecordAssertions();
1931 void emitRecordDumps();
1933
1934 bool isSubClassOf(const Record *R) const {
1935 for (const Record *SC : make_first_range(DirectSuperClasses)) {
1936 if (SC == R || SC->isSubClassOf(R))
1937 return true;
1938 }
1939 return false;
1940 }
1941
1942 bool isSubClassOf(StringRef Name) const {
1943 for (const Record *SC : make_first_range(DirectSuperClasses)) {
1944 if (const auto *SI = dyn_cast<StringInit>(SC->getNameInit())) {
1945 if (SI->getValue() == Name)
1946 return true;
1947 } else if (SC->getNameInitAsString() == Name) {
1948 return true;
1949 }
1950 if (SC->isSubClassOf(Name))
1951 return true;
1952 }
1953 return false;
1954 }
1955
1957 assert(!CorrespondingDefInit &&
1958 "changing type of record after it has been referenced");
1959 assert(!isSubClassOf(R) && "Already subclassing record!");
1960 DirectSuperClasses.emplace_back(R, Range);
1961 }
1962
1963 /// If there are any field references that refer to fields that have been
1964 /// filled in, we can propagate the values now.
1965 ///
1966 /// This is a final resolve: any error messages, e.g. due to undefined !cast
1967 /// references, are generated now.
1968 void resolveReferences(const Init *NewName = nullptr);
1969
1970 /// Apply the resolver to the name of the record as well as to the
1971 /// initializers of all fields of the record except SkipVal.
1972 ///
1973 /// The resolver should not resolve any of the fields itself, to avoid
1974 /// recursion / infinite loops.
1975 void resolveReferences(Resolver &R, const RecordVal *SkipVal = nullptr);
1976
1978 return TrackedRecords;
1979 }
1980
1981 void dump() const;
1982
1983 //===--------------------------------------------------------------------===//
1984 // High-level methods useful to tablegen back-ends
1985 //
1986
1987 /// Return the source location for the named field.
1988 SMLoc getFieldLoc(StringRef FieldName) const;
1989
1990 /// Return the initializer for a value with the specified name, or throw an
1991 /// exception if the field does not exist.
1992 const Init *getValueInit(StringRef FieldName) const;
1993
1994 /// Return true if the named field is unset.
1995 bool isValueUnset(StringRef FieldName) const {
1996 return isa<UnsetInit>(getValueInit(FieldName));
1997 }
1998
1999 /// This method looks up the specified field and returns its value as a
2000 /// string, throwing an exception if the field does not exist or if the value
2001 /// is not a string.
2002 StringRef getValueAsString(StringRef FieldName) const;
2003
2004 /// This method looks up the specified field and returns its value as a
2005 /// string, throwing an exception if the value is not a string and
2006 /// std::nullopt if the field does not exist.
2007 std::optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
2008
2009 /// This method looks up the specified field and returns its value as a
2010 /// BitsInit, throwing an exception if the field does not exist or if the
2011 /// value is not the right type.
2012 const BitsInit *getValueAsBitsInit(StringRef FieldName) const;
2013
2014 /// This method looks up the specified field and returns its value as a
2015 /// ListInit, throwing an exception if the field does not exist or if the
2016 /// value is not the right type.
2017 const ListInit *getValueAsListInit(StringRef FieldName) const;
2018
2019 /// This method looks up the specified field and returns its value as a
2020 /// vector of records, throwing an exception if the field does not exist or
2021 /// if the value is not the right type.
2022 std::vector<const Record *> getValueAsListOfDefs(StringRef FieldName) const;
2023
2024 /// This method looks up the specified field and returns its value as a
2025 /// vector of integers, throwing an exception if the field does not exist or
2026 /// if the value is not the right type.
2027 std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
2028
2029 /// This method looks up the specified field and returns its value as a
2030 /// vector of strings, throwing an exception if the field does not exist or
2031 /// if the value is not the right type.
2032 std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
2033
2034 /// This method looks up the specified field and returns its value as a
2035 /// Record, throwing an exception if the field does not exist or if the value
2036 /// is not the right type.
2037 const Record *getValueAsDef(StringRef FieldName) const;
2038
2039 /// This method looks up the specified field and returns its value as a
2040 /// Record, returning null if the field exists but is "uninitialized" (i.e.
2041 /// set to `?`), and throwing an exception if the field does not exist or if
2042 /// its value is not the right type.
2043 const Record *getValueAsOptionalDef(StringRef FieldName) const;
2044
2045 /// This method looks up the specified field and returns its value as a bit,
2046 /// throwing an exception if the field does not exist or if the value is not
2047 /// the right type.
2048 bool getValueAsBit(StringRef FieldName) const;
2049
2050 /// This method looks up the specified field and returns its value as a bit.
2051 /// If the field is unset, sets Unset to true and returns false.
2052 bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
2053
2054 /// This method looks up the specified field and returns its value as an
2055 /// int64_t, throwing an exception if the field does not exist or if the
2056 /// value is not the right type.
2057 int64_t getValueAsInt(StringRef FieldName) const;
2058
2059 /// This method looks up the specified field and returns its value as an Dag,
2060 /// throwing an exception if the field does not exist or if the value is not
2061 /// the right type.
2062 const DagInit *getValueAsDag(StringRef FieldName) const;
2063};
2064
2065raw_ostream &operator<<(raw_ostream &OS, const Record &R);
2066
2068 using RecordMap = StringMap<std::unique_ptr<Record>>;
2069 using GlobalMap = std::map<std::string, const Init *, std::less<>>;
2070
2071public:
2072 RecordKeeper();
2074
2075 /// Return the internal implementation of the RecordKeeper.
2077
2078 /// Get the main TableGen input file's name.
2079 StringRef getInputFilename() const { return InputFilename; }
2080
2081 /// Get all classes, sorted by name.
2083
2084 /// Get all records (defs), sorted by name.
2086
2087 /// Get the map of global variables.
2088 const GlobalMap &getGlobals() const { return ExtraGlobals; }
2089
2090 /// Get the class with the specified name.
2091 const Record *getClass(StringRef Name) const {
2092 auto It = Classes.find(Name);
2093 return It == Classes.end() ? nullptr : It->second.get();
2094 }
2095
2096 /// Get the concrete record with the specified name.
2097 const Record *getDef(StringRef Name) const {
2098 auto It = Defs.find(Name);
2099 return It == Defs.end() ? nullptr : It->second.get();
2100 }
2101
2102 /// Get the \p Init value of the specified global variable.
2103 const Init *getGlobal(StringRef Name) const {
2104 if (const Record *R = getDef(Name))
2105 return R->getDefInit();
2106 auto It = ExtraGlobals.find(Name);
2107 return It == ExtraGlobals.end() ? nullptr : It->second;
2108 }
2109
2110 void saveInputFilename(std::string Filename) {
2111 InputFilename = std::move(Filename);
2112 }
2113
2114 void addClass(std::unique_ptr<Record> R) {
2115 bool Ins = Classes.try_emplace(R->getName(), std::move(R)).second;
2116 (void)Ins;
2117 assert(Ins && "Class already exists");
2118 }
2119
2120 void addDef(std::unique_ptr<Record> R) {
2121 for (const Record *SC : make_first_range(R->getDirectSuperClasses()))
2122 DefsByDirectSuperClass[SC].push_back(R.get());
2123 bool Ins = Defs.try_emplace(R->getName(), std::move(R)).second;
2124 (void)Ins;
2125 assert(Ins && "Record already exists");
2126 // Clear cache
2127 if (!Cache.empty())
2128 Cache.clear();
2129 }
2130
2131 void addExtraGlobal(StringRef Name, const Init *I) {
2132 bool Ins = ExtraGlobals.try_emplace(std::string(Name), I).second;
2133 (void)Ins;
2134 assert(!getDef(Name));
2135 assert(Ins && "Global already exists");
2136 }
2137
2138 const Init *getNewAnonymousName();
2139
2140 TGTimer &getTimer() const { return *Timer; }
2141
2142 //===--------------------------------------------------------------------===//
2143 // High-level helper methods, useful for tablegen backends.
2144
2145 /// Get all the concrete records that inherit from the one specified
2146 /// class. The class must be defined.
2148
2149 /// Get all the concrete records that inherit from all the specified
2150 /// classes. The classes must be defined.
2151 std::vector<const Record *>
2153
2154 /// Get all the concrete records that inherit from specified class, if the
2155 /// class is defined. Returns an empty vector if the class is not defined.
2158
2159 void dump() const;
2160
2161 void dumpAllocationStats(raw_ostream &OS) const;
2162
2163private:
2164 RecordKeeper(RecordKeeper &&) = delete;
2165 RecordKeeper(const RecordKeeper &) = delete;
2166 RecordKeeper &operator=(RecordKeeper &&) = delete;
2167 RecordKeeper &operator=(const RecordKeeper &) = delete;
2168
2169 std::string InputFilename;
2170 RecordMap Classes, Defs;
2171 // Classes and Defs sorted by name, built on demand.
2172 mutable std::vector<const Record *> SortedClasses, SortedDefs;
2173 mutable std::map<std::string, std::vector<const Record *>> Cache;
2174 // The defs that each class is a direct superclass of.
2176 DefsByDirectSuperClass;
2177 GlobalMap ExtraGlobals;
2178
2179 /// The internal uniquer implementation of the RecordKeeper.
2180 std::unique_ptr<detail::RecordKeeperImpl> Impl;
2181 std::unique_ptr<TGTimer> Timer;
2182};
2183
2184/// Sorting predicate to sort record pointers by name.
2186 bool operator()(const Record *Rec1, const Record *Rec2) const {
2187 return Rec1->getName().compare_numeric(Rec2->getName()) < 0;
2188 }
2189};
2190
2191/// Sorting predicate to sort record pointers by their
2192/// unique ID. If you just need a deterministic order, use this, since it
2193/// just compares two `unsigned`; the other sorting predicates require
2194/// string manipulation.
2196 bool operator()(const Record *LHS, const Record *RHS) const {
2197 return LHS->getID() < RHS->getID();
2198 }
2199};
2200
2201/// Sorting predicate to sort record pointers by their Name field.
2203 bool operator()(const Record *Rec1, const Record *Rec2) const {
2204 return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
2205 }
2206};
2207
2211
2213 if (Rec.empty())
2214 return;
2215
2216 size_t Len = 0;
2217 const char *Start = Rec.data();
2218 const char *Curr = Start;
2219 bool IsDigitPart = isDigit(Curr[0]);
2220 for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
2221 bool IsDigit = isDigit(Curr[I]);
2222 if (IsDigit != IsDigitPart) {
2223 Parts.emplace_back(IsDigitPart, StringRef(Start, Len));
2224 Len = 0;
2225 Start = &Curr[I];
2226 IsDigitPart = isDigit(Curr[I]);
2227 }
2228 }
2229 // Push the last part.
2230 Parts.emplace_back(IsDigitPart, StringRef(Start, Len));
2231 }
2232
2233 size_t size() { return Parts.size(); }
2234
2235 std::pair<bool, StringRef> getPart(size_t Idx) { return Parts[Idx]; }
2236 };
2237
2238 bool operator()(const Record *Rec1, const Record *Rec2) const {
2239 int64_t LHSPositionOrder = Rec1->getValueAsInt("PositionOrder");
2240 int64_t RHSPositionOrder = Rec2->getValueAsInt("PositionOrder");
2241 if (LHSPositionOrder != RHSPositionOrder)
2242 return LHSPositionOrder < RHSPositionOrder;
2243
2244 RecordParts LHSParts(StringRef(Rec1->getName()));
2245 RecordParts RHSParts(StringRef(Rec2->getName()));
2246
2247 size_t LHSNumParts = LHSParts.size();
2248 size_t RHSNumParts = RHSParts.size();
2249 assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
2250
2251 if (LHSNumParts != RHSNumParts)
2252 return LHSNumParts < RHSNumParts;
2253
2254 // We expect the registers to be of the form [_a-zA-Z]+([0-9]*[_a-zA-Z]*)*.
2255 for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
2256 std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
2257 std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
2258 // Expect even part to always be alpha.
2259 assert (LHSPart.first == false && RHSPart.first == false &&
2260 "Expected both parts to be alpha.");
2261 if (int Res = LHSPart.second.compare(RHSPart.second))
2262 return Res < 0;
2263 }
2264 for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
2265 std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
2266 std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
2267 // Expect odd part to always be numeric.
2268 assert (LHSPart.first == true && RHSPart.first == true &&
2269 "Expected both parts to be numeric.");
2270 if (LHSPart.second.size() != RHSPart.second.size())
2271 return LHSPart.second.size() < RHSPart.second.size();
2272
2273 unsigned LHSVal, RHSVal;
2274
2275 bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
2276 assert(!LHSFailed && "Unable to convert LHS to integer.");
2277 bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
2278 assert(!RHSFailed && "Unable to convert RHS to integer.");
2279
2280 if (LHSVal != RHSVal)
2281 return LHSVal < RHSVal;
2282 }
2283 return LHSNumParts < RHSNumParts;
2284 }
2285};
2286
2287raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
2288
2289//===----------------------------------------------------------------------===//
2290// Resolvers
2291//===----------------------------------------------------------------------===//
2292
2293/// Interface for looking up the initializer for a variable name, used by
2294/// Init::resolveReferences.
2296 const Record *CurRec;
2297 bool IsFinal = false;
2298
2299public:
2300 explicit Resolver(const Record *CurRec) : CurRec(CurRec) {}
2301 virtual ~Resolver() = default;
2302
2303 const Record *getCurrentRecord() const { return CurRec; }
2304
2305 /// Return the initializer for the given variable name (should normally be a
2306 /// StringInit), or nullptr if the name could not be resolved.
2307 virtual const Init *resolve(const Init *VarName) = 0;
2308
2309 // Whether bits in a BitsInit should stay unresolved if resolving them would
2310 // result in a ? (UnsetInit). This behavior is used to represent instruction
2311 // encodings by keeping references to unset variables within a record.
2312 virtual bool keepUnsetBits() const { return false; }
2313
2314 // Whether this is the final resolve step before adding a record to the
2315 // RecordKeeper. Error reporting during resolve and related constant folding
2316 // should only happen when this is true.
2317 bool isFinal() const { return IsFinal; }
2318
2319 void setFinal(bool Final) {
2320 IsFinal = Final;
2322 }
2323
2324 /// Return the cached result of resolving \p I, or nullptr. \p FoundUnresolved
2325 /// is set if the result has unresolved references.
2326 virtual const Init *getCachedResult(const Init *I,
2327 bool &FoundUnresolved) const {
2328 return nullptr;
2329 }
2330
2331 /// Cache the result of resolving \p I.
2332 virtual void cacheResult(const Init *I, const Init *Result,
2333 bool FoundUnresolved) {}
2334
2335 /// Called when a cached result has unresolved references.
2336 virtual void noteUnresolved() {}
2337
2338protected:
2339 virtual void clearCachedResults() {}
2340};
2341
2342/// Resolve arbitrary mappings.
2343class MapResolver final : public Resolver {
2344 struct MappedValue {
2345 const Init *V;
2346 bool Resolved;
2347
2348 MappedValue() : V(nullptr), Resolved(false) {}
2349 MappedValue(const Init *V, bool Resolved) : V(V), Resolved(Resolved) {}
2350 };
2351
2354 // Number of mapped values being resolved. Each is removed from Map while it
2355 // is resolved to prevent infinite recursion, so results computed meanwhile
2356 // may be incomplete and are not cached.
2357 unsigned NumInProgress = 0;
2358
2359public:
2360 explicit MapResolver(const Record *CurRec = nullptr) : Resolver(CurRec) {}
2361
2362 void set(const Init *Key, const Init *Value) {
2363 Map[Key] = {Value, false};
2365 }
2366
2367 bool isComplete(Init *VarName) const {
2368 auto It = Map.find(VarName);
2369 assert(It != Map.end() && "key must be present in map");
2370 return It->second.V->isComplete();
2371 }
2372
2373 const Init *resolve(const Init *VarName) override;
2374
2376 bool &FoundUnresolved) const override {
2377 if (NumInProgress)
2378 return nullptr;
2379 auto [Result, Unresolved] = ResultCache.lookup(I);
2380 FoundUnresolved = Unresolved;
2381 return Result;
2382 }
2383
2384 void cacheResult(const Init *I, const Init *Result,
2385 bool FoundUnresolved) override {
2386 if (!NumInProgress)
2387 ResultCache[I] = {Result, FoundUnresolved};
2388 }
2389
2390protected:
2391 void clearCachedResults() override { ResultCache.clear(); }
2392};
2393
2394/// Resolve all variables from a record except for unset variables.
2395class RecordResolver final : public Resolver {
2399 const Init *Name = nullptr;
2400
2401public:
2402 explicit RecordResolver(const Record &R) : Resolver(&R) {}
2403
2404 void setName(const Init *NewName) {
2405 Name = NewName;
2407 }
2408
2409 const Init *resolve(const Init *VarName) override;
2410
2411 bool keepUnsetBits() const override { return true; }
2412
2413 // Variables on the stack resolve to nullptr to prevent infinite recursion,
2414 // so results computed meanwhile may be incomplete and are not cached.
2416 bool &FoundUnresolved) const override {
2417 if (!Stack.empty())
2418 return nullptr;
2419 auto [Result, Unresolved] = ResultCache.lookup(I);
2420 FoundUnresolved = Unresolved;
2421 return Result;
2422 }
2423
2424 void cacheResult(const Init *I, const Init *Result,
2425 bool FoundUnresolved) override {
2426 if (Stack.empty())
2427 ResultCache[I] = {Result, FoundUnresolved};
2428 }
2429
2430protected:
2431 void clearCachedResults() override { ResultCache.clear(); }
2432};
2433
2434/// Delegate resolving to a sub-resolver, but shadow some variable names.
2435class ShadowResolver final : public Resolver {
2436 Resolver &R;
2437 DenseSet<const Init *> Shadowed;
2438
2439public:
2441 : Resolver(R.getCurrentRecord()), R(R) {
2442 setFinal(R.isFinal());
2443 }
2444
2445 void addShadow(const Init *Key) { Shadowed.insert(Key); }
2446
2447 const Init *resolve(const Init *VarName) override {
2448 if (Shadowed.count(VarName))
2449 return nullptr;
2450 return R.resolve(VarName);
2451 }
2452};
2453
2454/// (Optionally) delegate resolving to a sub-resolver, and keep track whether
2455/// there were unresolved references.
2456class TrackUnresolvedResolver final : public Resolver {
2457 Resolver *R;
2458 bool FoundUnresolved = false;
2459
2460public:
2461 explicit TrackUnresolvedResolver(Resolver *R = nullptr)
2462 : Resolver(R ? R->getCurrentRecord() : nullptr), R(R) {}
2463
2464 bool foundUnresolved() const { return FoundUnresolved; }
2465
2466 const Init *resolve(const Init *VarName) override;
2467
2468 // Tracking doesn't change results, so share the underlying resolver's cache.
2469 const Init *getCachedResult(const Init *I, bool &Unresolved) const override {
2470 return R ? R->getCachedResult(I, Unresolved) : nullptr;
2471 }
2472
2473 void cacheResult(const Init *I, const Init *Result,
2474 bool Unresolved) override {
2475 if (R)
2476 R->cacheResult(I, Result, Unresolved);
2477 }
2478
2479 void noteUnresolved() override {
2480 FoundUnresolved = true;
2481 if (R)
2482 R->noteUnresolved();
2483 }
2484};
2485
2486/// Do not resolve anything, but keep track of whether a given variable was
2487/// referenced.
2488class HasReferenceResolver final : public Resolver {
2489 const Init *VarNameToTrack;
2490 bool Found = false;
2491
2492public:
2493 explicit HasReferenceResolver(const Init *VarNameToTrack)
2494 : Resolver(nullptr), VarNameToTrack(VarNameToTrack) {}
2495
2496 bool found() const { return Found; }
2497
2498 const Init *resolve(const Init *VarName) override;
2499};
2500
2501void EmitDetailedRecords(const RecordKeeper &RK, raw_ostream &OS);
2502void EmitJSON(const RecordKeeper &RK, raw_ostream &OS);
2503
2504} // end namespace llvm
2505
2506#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:2580
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:2548
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:2622
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:2599
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:2611
static const CondOpInit * get(ArrayRef< const Init * > Conds, ArrayRef< const Init * > Values, const RecTy *Type)
Definition Record.cpp:2529
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:2605
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:2706
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:2676
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:2686
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:2640
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:2669
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:2712
'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:2498
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:2485
static const FieldInit * get(const Init *R, const StringInit *FN)
Definition Record.cpp:2477
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:2491
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:2513
!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:2493
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3353
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:2391
const Init * getCachedResult(const Init *I, bool &FoundUnresolved) const override
Return the cached result of resolving I, or nullptr.
Definition Record.h:2375
void cacheResult(const Init *I, const Init *Result, bool FoundUnresolved) override
Cache the result of resolving I.
Definition Record.h:2384
void set(const Init *Key, const Init *Value)
Definition Record.h:2362
bool isComplete(Init *VarName) const
Definition Record.h:2367
MapResolver(const Record *CurRec=nullptr)
Definition Record.h:2360
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3288
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:2120
void addClass(std::unique_ptr< Record > R)
Definition Record.h:2114
TGTimer & getTimer() const
Definition Record.h:2140
const Record * getClass(StringRef Name) const
Get the class with the specified name.
Definition Record.h:2091
ArrayRef< const Record * > getClasses() const
Get all classes, sorted by name.
Definition Record.cpp:3198
const Init * getNewAnonymousName()
GetNewAnonymousName - Generate a unique anonymous name that can be used as an identifier.
Definition Record.cpp:3167
void dump() const
Definition Record.cpp:3151
StringRef getInputFilename() const
Get the main TableGen input file's name.
Definition Record.h:2079
detail::RecordKeeperImpl & getImpl()
Return the internal implementation of the RecordKeeper.
Definition Record.h:2076
void saveInputFilename(std::string Filename)
Definition Record.h:2110
const GlobalMap & getGlobals() const
Get the map of global variables.
Definition Record.h:2088
const Init * getGlobal(StringRef Name) const
Get the Init value of the specified global variable.
Definition Record.h:2103
ArrayRef< const Record * > getDefs() const
Get all records (defs), sorted by name.
Definition Record.cpp:3202
void dumpAllocationStats(raw_ostream &OS) const
Definition Record.cpp:3284
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:3278
void addExtraGlobal(StringRef Name, const Init *I)
Definition Record.h:2131
const Record * getDef(StringRef Name) const
Get the concrete record with the specified name.
Definition Record.h:2097
ArrayRef< const Record * > getAllDerivedDefinitions(StringRef ClassName) const
Get all the concrete records that inherit from the one specified class.
Definition Record.cpp:3172
'[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:2431
bool keepUnsetBits() const override
Definition Record.h:2411
void cacheResult(const Init *I, const Init *Result, bool FoundUnresolved) override
Cache the result of resolving I.
Definition Record.h:2424
RecordResolver(const Record &R)
Definition Record.h:2402
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3308
void setName(const Init *NewName)
Definition Record.h:2404
const Init * getCachedResult(const Init *I, bool &FoundUnresolved) const override
Return the cached result of resolving I, or nullptr.
Definition Record.h:2415
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:1658
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:2766
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:1648
bool isUsed() const
Definition Record.h:1662
void dump() const
Definition Record.cpp:2795
StringRef getName() const
Get the name of the field as a StringRef.
Definition Record.cpp:2747
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:2798
RecordVal(const Init *N, const RecTy *T, FieldKind K)
Definition Record.cpp:2733
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:2751
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:3024
const RecordRecTy * getType() const
Definition Record.cpp:2821
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:2950
bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const
This method looks up the specified field and returns its value as a bit.
Definition Record.cpp:3081
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:3073
unsigned getID() const
Definition Record.h:1758
@ RK_AnonymousDef
Definition Record.h:1697
static unsigned getNewUID(RecordKeeper &RK)
Definition Record.cpp:2835
ArrayRef< SMLoc > getLoc() const
Definition Record.h:1770
void addDump(SMLoc Loc, const Init *Message)
Definition Record.h:1920
void checkUnusedTemplateArgs()
Definition Record.cpp:3136
void emitRecordDumps()
Definition Record.cpp:3125
ArrayRef< DumpInfo > getDumps() const
Definition Record.h:1825
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:2999
bool isAnonymous() const
Definition Record.h:1816
bool addTemplateArg(const RecordVal &Arg)
Add a template argument.
Definition Record.h:1890
ArrayRef< AssertionInfo > getAssertions() const
Definition Record.h:1824
void appendValueReferenceLoc(const Init *Name, SMRange Loc) const
Add a reference to the value named Name.
Definition Record.h:1784
std::string getNameInitAsString() const
Definition Record.h:1764
void removeValue(StringRef Name)
Definition Record.h:1912
void appendValueReferenceLocs(const Record &From, const Init *Name) const
Add the references to the value named Name in From.
Definition Record.h:1789
void dump() const
Definition Record.cpp:2906
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:3055
RecordKeeper & getRecords() const
Definition Record.h:1977
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:3094
RecordVal * getTemplateArg(const Init *Name)
Definition Record.h:1861
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:3040
const RecordVal * getValue(const Init *Name) const
Return the field with the given name, or null if there is none.
Definition Record.h:1868
void appendLoc(SMLoc Loc)
Definition Record.h:1771
Record(const Record &O)
Definition Record.h:1748
bool isValueUnset(StringRef FieldName) const
Return true if the named field is unset.
Definition Record.h:1995
std::vector< const Record * > getSuperClasses() const
Return all superclasses in post-order.
Definition Record.h:1836
const RecordVal * getTemplateArg(const Init *Name) const
Return the template argument with the given name, or null if there is none.
Definition Record.h:1854
bool isMultiClass() const
Definition Record.h:1814
bool hasDirectSuperClass(const Record *SuperClass) const
Determine whether this record has the specified direct superclass.
Definition Record.h:1843
void addValue(const RecordVal &RV)
Definition Record.h:1898
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:3063
void addAssertion(SMLoc Loc, const Init *Condition, const Init *Message)
Definition Record.h:1916
Record(StringRef N, ArrayRef< SMLoc > locs, RecordKeeper &records, RecordKind Kind=RK_Def)
Definition Record.h:1741
bool isClass() const
Definition Record.h:1812
ArrayRef< std::pair< const Record *, SMRange > > getDirectSuperClasses() const
Return the direct superclasses of this record.
Definition Record.h:1848
StringRef getName() const
Definition Record.h:1760
Record(const Init *N, ArrayRef< SMLoc > locs, RecordKeeper &records, RecordKind Kind=RK_Def)
Definition Record.h:1734
void setName(const Init *Name)
Definition Record.cpp:2839
bool isSubClassOf(StringRef Name) const
Definition Record.h:1942
ArrayRef< RecordVal > getTemplateArgs() const
Return the template arguments of this class or multiclass.
Definition Record.h:1819
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:2990
void appendDumps(const Record *Rec)
Definition Record.h:1928
bool isSubClassOf(const Record *R) const
Definition Record.h:1934
DefInit * getDefInit() const
get the corresponding DefInit.
Definition Record.cpp:2827
ArrayRef< RecordVal > getValues() const
Return the fields of this record.
Definition Record.h:1822
SMLoc getFieldLoc(StringRef FieldName) const
Return the source location for the named field.
Definition Record.cpp:2942
ArrayRef< SMLoc > getForwardDeclarationLocs() const
Definition Record.h:1773
const RecordVal * getValue(StringRef Name) const
Definition Record.h:1874
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:2898
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:2967
void removeValue(const Init *Name)
Definition Record.h:1904
ArrayRef< SMRange > getReferenceLocs() const
Return the references of this record value.
Definition Record.h:1781
void updateClassLoc(SMLoc Loc)
Definition Record.cpp:2805
RecordVal * getValue(const Init *Name)
Definition Record.h:1878
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:2982
void addDirectSuperClass(const Record *R, SMRange Range)
Definition Record.h:1956
ArrayRef< SMRange > getValueReferenceLocs(const Init *Name) const
Return the references to the value named Name.
Definition Record.h:1796
void appendAssertions(const Record *Rec)
Definition Record.h:1924
const Init * getNameInit() const
Definition Record.h:1762
void getSuperClasses(std::vector< const Record * > &Classes) const
Append all superclasses in post-order to Classes.
Definition Record.h:1828
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:3013
RecordVal * getValue(StringRef Name)
Definition Record.h:1883
void checkRecordAssertions()
Definition Record.cpp:3106
void appendReferenceLoc(SMRange Loc) const
Add a reference to this record value.
Definition Record.h:1778
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:2958
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition Record.h:2295
virtual ~Resolver()=default
virtual void noteUnresolved()
Called when a cached result has unresolved references.
Definition Record.h:2336
virtual const Init * getCachedResult(const Init *I, bool &FoundUnresolved) const
Return the cached result of resolving I, or nullptr.
Definition Record.h:2326
virtual void cacheResult(const Init *I, const Init *Result, bool FoundUnresolved)
Cache the result of resolving I.
Definition Record.h:2332
bool isFinal() const
Definition Record.h:2317
Resolver(const Record *CurRec)
Definition Record.h:2300
const Record * getCurrentRecord() const
Definition Record.h:2303
virtual void clearCachedResults()
Definition Record.h:2339
void setFinal(bool Final)
Definition Record.h:2319
virtual bool keepUnsetBits() const
Definition Record.h:2312
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:2440
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.h:2447
void addShadow(const Init *Key)
Definition Record.h:2445
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:2469
const Init * resolve(const Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit),...
Definition Record.cpp:3333
void noteUnresolved() override
Called when a cached result has unresolved references.
Definition Record.h:2479
TrackUnresolvedResolver(Resolver *R=nullptr)
Definition Record.h:2461
void cacheResult(const Init *I, const Init *Result, bool Unresolved) override
Cache the result of resolving I.
Definition Record.h:2473
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:2423
const Init * Fold() const
Definition Record.cpp:2454
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:2467
'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:2195
bool operator()(const Record *LHS, const Record *RHS) const
Definition Record.h:2196
Sorting predicate to sort record pointers by their Name field.
Definition Record.h:2202
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition Record.h:2203
std::pair< bool, StringRef > getPart(size_t Idx)
Definition Record.h:2235
SmallVector< std::pair< bool, StringRef >, 4 > Parts
Definition Record.h:2210
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition Record.h:2238
Sorting predicate to sort record pointers by name.
Definition Record.h:2185
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition Record.h:2186
AssertionInfo(SMLoc Loc, const Init *Condition, const Init *Message)
Definition Record.h:1684
DumpInfo(SMLoc Loc, const Init *Message)
Definition Record.h:1694
const Init * Message
Definition Record.h:1690