llvm.org GIT mirror llvm / b0c6fa3
tblgen: Put dyn_cast<> machinery in place for Init hierarchy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165645 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Silva 7 years ago
1 changed file(s) with 122 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
484484 //===----------------------------------------------------------------------===//
485485
486486 class Init {
487 protected:
488 /// \brief Discriminator enum (for isa<>, dyn_cast<>, et al.)
489 ///
490 /// This enum is laid out by a preorder traversal of the inheritance
491 /// hierarchy, and does not contain an entry for abstract classes, as per
492 /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
493 ///
494 /// We also explicitly include "first" and "last" values for each
495 /// interior node of the inheritance tree, to make it easier to read the
496 /// corresponding classof().
497 ///
498 /// We could pack these a bit tighter by not having the IK_FirstXXXInit
499 /// and IK_LastXXXInit be their own values, but that would degrade
500 /// readability for really no benefit.
501 enum InitKind {
502 IK_BitInit,
503 IK_BitsInit,
504 IK_FirstTypedInit,
505 IK_DagInit,
506 IK_DefInit,
507 IK_FieldInit,
508 IK_IntInit,
509 IK_ListInit,
510 IK_FirstOpInit,
511 IK_BinOpInit,
512 IK_TernOpInit,
513 IK_UnOpInit,
514 IK_LastOpInit,
515 IK_StringInit,
516 IK_VarInit,
517 IK_VarListElementInit,
518 IK_LastTypedInit,
519 IK_UnsetInit,
520 IK_VarBitInit
521 };
522
523 private:
524 const InitKind Kind;
487525 Init(const Init &) LLVM_DELETED_FUNCTION;
488526 Init &operator=(const Init &) LLVM_DELETED_FUNCTION;
489527 virtual void anchor();
490528
529 public:
530 InitKind getKind() const { return Kind; }
531
491532 protected:
492 Init(void) {}
533 explicit Init(InitKind K) : Kind(K) {}
493534
494535 public:
495536 virtual ~Init() {}
590631 TypedInit &operator=(const TypedInit &Other) LLVM_DELETED_FUNCTION;
591632
592633 protected:
593 explicit TypedInit(RecTy *T) : Ty(T) {}
594
595 public:
634 explicit TypedInit(InitKind K, RecTy *T) : Init(K), Ty(T) {}
635
636 public:
637 static bool classof(const Init *I) {
638 return I->getKind() >= IK_FirstTypedInit &&
639 I->getKind() <= IK_LastTypedInit;
640 }
596641 RecTy *getType() const { return Ty; }
597642
598643 virtual Init *
617662 /// UnsetInit - ? - Represents an uninitialized value
618663 ///
619664 class UnsetInit : public Init {
620 UnsetInit() : Init() {}
665 UnsetInit() : Init(IK_UnsetInit) {}
621666 UnsetInit(const UnsetInit &) LLVM_DELETED_FUNCTION;
622667 UnsetInit &operator=(const UnsetInit &Other) LLVM_DELETED_FUNCTION;
623668 virtual void anchor();
624669
625670 public:
671 static bool classof(const Init *I) {
672 return I->getKind() == IK_UnsetInit;
673 }
626674 static UnsetInit *get();
627675
628676 virtual Init *convertInitializerTo(RecTy *Ty) const {
643691 class BitInit : public Init {
644692 bool Value;
645693
646 explicit BitInit(bool V) : Value(V) {}
694 explicit BitInit(bool V) : Init(IK_BitInit), Value(V) {}
647695 BitInit(const BitInit &Other) LLVM_DELETED_FUNCTION;
648696 BitInit &operator=(BitInit &Other) LLVM_DELETED_FUNCTION;
649697 virtual void anchor();
650698
651699 public:
700 static bool classof(const Init *I) {
701 return I->getKind() == IK_BitInit;
702 }
652703 static BitInit *get(bool V);
653704
654705 bool getValue() const { return Value; }
671722 class BitsInit : public Init, public FoldingSetNode {
672723 std::vector Bits;
673724
674 BitsInit(ArrayRef Range) : Bits(Range.begin(), Range.end()) {}
725 BitsInit(ArrayRef Range)
726 : Init(IK_BitsInit), Bits(Range.begin(), Range.end()) {}
675727
676728 BitsInit(const BitsInit &Other) LLVM_DELETED_FUNCTION;
677729 BitsInit &operator=(const BitsInit &Other) LLVM_DELETED_FUNCTION;
678730
679731 public:
732 static bool classof(const Init *I) {
733 return I->getKind() == IK_BitsInit;
734 }
680735 static BitsInit *get(ArrayRef Range);
681736
682737 void Profile(FoldingSetNodeID &ID) const;
715770 class IntInit : public TypedInit {
716771 int64_t Value;
717772
718 explicit IntInit(int64_t V) : TypedInit(IntRecTy::get()), Value(V) {}
773 explicit IntInit(int64_t V)
774 : TypedInit(IK_IntInit, IntRecTy::get()), Value(V) {}
719775
720776 IntInit(const IntInit &Other) LLVM_DELETED_FUNCTION;
721777 IntInit &operator=(const IntInit &Other) LLVM_DELETED_FUNCTION;
722778
723779 public:
780 static bool classof(const Init *I) {
781 return I->getKind() == IK_IntInit;
782 }
724783 static IntInit *get(int64_t V);
725784
726785 int64_t getValue() const { return Value; }
753812 std::string Value;
754813
755814 explicit StringInit(const std::string &V)
756 : TypedInit(StringRecTy::get()), Value(V) {}
815 : TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
757816
758817 StringInit(const StringInit &Other) LLVM_DELETED_FUNCTION;
759818 StringInit &operator=(const StringInit &Other) LLVM_DELETED_FUNCTION;
760819 virtual void anchor();
761820
762821 public:
822 static bool classof(const Init *I) {
823 return I->getKind() == IK_StringInit;
824 }
763825 static StringInit *get(StringRef);
764826
765827 const std::string &getValue() const { return Value; }
793855
794856 private:
795857 explicit ListInit(ArrayRef Range, RecTy *EltTy)
796 : TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {}
858 : TypedInit(IK_ListInit, ListRecTy::get(EltTy)),
859 Values(Range.begin(), Range.end()) {}
797860
798861 ListInit(const ListInit &Other) LLVM_DELETED_FUNCTION;
799862 ListInit &operator=(const ListInit &Other) LLVM_DELETED_FUNCTION;
800863
801864 public:
865 static bool classof(const Init *I) {
866 return I->getKind() == IK_ListInit;
867 }
802868 static ListInit *get(ArrayRef Range, RecTy *EltTy);
803869
804870 void Profile(FoldingSetNodeID &ID) const;
854920 OpInit &operator=(OpInit &Other) LLVM_DELETED_FUNCTION;
855921
856922 protected:
857 explicit OpInit(RecTy *Type) : TypedInit(Type) {}
858
859 public:
923 explicit OpInit(InitKind K, RecTy *Type) : TypedInit(K, Type) {}
924
925 public:
926 static bool classof(const Init *I) {
927 return I->getKind() >= IK_FirstOpInit &&
928 I->getKind() <= IK_LastOpInit;
929 }
860930 // Clone - Clone this operator, replacing arguments with the new list
861931 virtual OpInit *clone(std::vector &Operands) const = 0;
862932
888958 Init *LHS;
889959
890960 UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
891 : OpInit(Type), Opc(opc), LHS(lhs) {}
961 : OpInit(IK_UnOpInit, Type), Opc(opc), LHS(lhs) {}
892962
893963 UnOpInit(const UnOpInit &Other) LLVM_DELETED_FUNCTION;
894964 UnOpInit &operator=(const UnOpInit &Other) LLVM_DELETED_FUNCTION;
895965
896966 public:
967 static bool classof(const Init *I) {
968 return I->getKind() == IK_UnOpInit;
969 }
897970 static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
898971
899972 // Clone - Clone this operator, replacing arguments with the new list
9311004 Init *LHS, *RHS;
9321005
9331006 BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
934 OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {}
1007 OpInit(IK_BinOpInit, Type), Opc(opc), LHS(lhs), RHS(rhs) {}
9351008
9361009 BinOpInit(const BinOpInit &Other) LLVM_DELETED_FUNCTION;
9371010 BinOpInit &operator=(const BinOpInit &Other) LLVM_DELETED_FUNCTION;
9381011
9391012 public:
1013 static bool classof(const Init *I) {
1014 return I->getKind() == IK_BinOpInit;
1015 }
9401016 static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
9411017 RecTy *Type);
9421018
9811057
9821058 TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
9831059 RecTy *Type) :
984 OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
1060 OpInit(IK_TernOpInit, Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
9851061
9861062 TernOpInit(const TernOpInit &Other) LLVM_DELETED_FUNCTION;
9871063 TernOpInit &operator=(const TernOpInit &Other) LLVM_DELETED_FUNCTION;
9881064
9891065 public:
1066 static bool classof(const Init *I) {
1067 return I->getKind() == IK_TernOpInit;
1068 }
9901069 static TernOpInit *get(TernaryOp opc, Init *lhs,
9911070 Init *mhs, Init *rhs,
9921071 RecTy *Type);
10351114 Init *VarName;
10361115
10371116 explicit VarInit(const std::string &VN, RecTy *T)
1038 : TypedInit(T), VarName(StringInit::get(VN)) {}
1117 : TypedInit(IK_VarInit, T), VarName(StringInit::get(VN)) {}
10391118 explicit VarInit(Init *VN, RecTy *T)
1040 : TypedInit(T), VarName(VN) {}
1119 : TypedInit(IK_VarInit, T), VarName(VN) {}
10411120
10421121 VarInit(const VarInit &Other) LLVM_DELETED_FUNCTION;
10431122 VarInit &operator=(const VarInit &Other) LLVM_DELETED_FUNCTION;
10441123
10451124 public:
1125 static bool classof(const Init *I) {
1126 return I->getKind() == IK_VarInit;
1127 }
10461128 static VarInit *get(const std::string &VN, RecTy *T);
10471129 static VarInit *get(Init *VN, RecTy *T);
10481130
10821164 TypedInit *TI;
10831165 unsigned Bit;
10841166
1085 VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) {
1167 VarBitInit(TypedInit *T, unsigned B) : Init(IK_VarBitInit), TI(T), Bit(B) {
10861168 assert(T->getType() &&
10871169 (isa(T->getType()) ||
10881170 (isa(T->getType()) &&
10941176 VarBitInit &operator=(const VarBitInit &Other) LLVM_DELETED_FUNCTION;
10951177
10961178 public:
1179 static bool classof(const Init *I) {
1180 return I->getKind() == IK_VarBitInit;
1181 }
10971182 static VarBitInit *get(TypedInit *T, unsigned B);
10981183
10991184 virtual Init *convertInitializerTo(RecTy *Ty) const {
11191204 unsigned Element;
11201205
11211206 VarListElementInit(TypedInit *T, unsigned E)
1122 : TypedInit(cast(T->getType())->getElementType()),
1123 TI(T), Element(E) {
1207 : TypedInit(IK_VarListElementInit,
1208 cast(T->getType())->getElementType()),
1209 TI(T), Element(E) {
11241210 assert(T->getType() && isa(T->getType()) &&
11251211 "Illegal VarBitInit expression!");
11261212 }
11291215 void operator=(const VarListElementInit &Other) LLVM_DELETED_FUNCTION;
11301216
11311217 public:
1218 static bool classof(const Init *I) {
1219 return I->getKind() == IK_VarListElementInit;
1220 }
11321221 static VarListElementInit *get(TypedInit *T, unsigned E);
11331222
11341223 virtual Init *convertInitializerTo(RecTy *Ty) const {
11561245 class DefInit : public TypedInit {
11571246 Record *Def;
11581247
1159 DefInit(Record *D, RecordRecTy *T) : TypedInit(T), Def(D) {}
1248 DefInit(Record *D, RecordRecTy *T) : TypedInit(IK_DefInit, T), Def(D) {}
11601249 friend class Record;
11611250
11621251 DefInit(const DefInit &Other) LLVM_DELETED_FUNCTION;
11631252 DefInit &operator=(const DefInit &Other) LLVM_DELETED_FUNCTION;
11641253
11651254 public:
1255 static bool classof(const Init *I) {
1256 return I->getKind() == IK_DefInit;
1257 }
11661258 static DefInit *get(Record*);
11671259
11681260 virtual Init *convertInitializerTo(RecTy *Ty) const {
12001292 std::string FieldName; // Field we are accessing
12011293
12021294 FieldInit(Init *R, const std::string &FN)
1203 : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
1295 : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
12041296 assert(getType() && "FieldInit with non-record type!");
12051297 }
12061298
12081300 FieldInit &operator=(const FieldInit &Other) LLVM_DELETED_FUNCTION;
12091301
12101302 public:
1303 static bool classof(const Init *I) {
1304 return I->getKind() == IK_FieldInit;
1305 }
12111306 static FieldInit *get(Init *R, const std::string &FN);
12121307 static FieldInit *get(Init *R, const Init *FN);
12131308
12411336 DagInit(Init *V, const std::string &VN,
12421337 ArrayRef ArgRange,
12431338 ArrayRef NameRange)
1244 : TypedInit(DagRecTy::get()), Val(V), ValName(VN),
1339 : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
12451340 Args(ArgRange.begin(), ArgRange.end()),
12461341 ArgNames(NameRange.begin(), NameRange.end()) {}
12471342
12491344 DagInit &operator=(const DagInit &Other) LLVM_DELETED_FUNCTION;
12501345
12511346 public:
1347 static bool classof(const Init *I) {
1348 return I->getKind() == IK_DagInit;
1349 }
12521350 static DagInit *get(Init *V, const std::string &VN,
12531351 ArrayRef ArgRange,
12541352 ArrayRef NameRange);