llvm.org GIT mirror llvm / d8f5923
[TableGen] Use some free space in Init to store the opcode for UnOpInit/BinOpInit/TernOpInit allowing those types to be a little smaller. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256733 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 4 years ago
2 changed file(s) with 23 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
231231 /// We could pack these a bit tighter by not having the IK_FirstXXXInit
232232 /// and IK_LastXXXInit be their own values, but that would degrade
233233 /// readability for really no benefit.
234 enum InitKind {
234 enum InitKind : uint8_t {
235235 IK_BitInit,
236236 IK_FirstTypedInit,
237237 IK_BitsInit,
255255
256256 private:
257257 const InitKind Kind;
258 protected:
259 uint8_t Opc; // Used by UnOpInit, BinOpInit, and TernOpInit
260 private:
258261 Init(const Init &) = delete;
259262 Init &operator=(const Init &) = delete;
260263 virtual void anchor();
263266 InitKind getKind() const { return Kind; }
264267
265268 protected:
266 explicit Init(InitKind K) : Kind(K) {}
269 explicit Init(InitKind K, uint8_t Opc = 0) : Kind(K), Opc(Opoc) {}
267270
268271 public:
269272 virtual ~Init() {}
364367 TypedInit &operator=(const TypedInit &Other) = delete;
365368
366369 protected:
367 explicit TypedInit(InitKind K, RecTy *T) : Init(K), Ty(T) {}
370 explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
371 : Init(K, Opc), Ty(T) {}
368372 ~TypedInit() override {
369373 // If this is a DefInit we need to delete the RecordRecTy.
370374 if (getKind() == IK_DefInit)
649653 OpInit &operator=(OpInit &Other) = delete;
650654
651655 protected:
652 explicit OpInit(InitKind K, RecTy *Type) : TypedInit(K, Type) {}
656 explicit OpInit(InitKind K, RecTy *Type, uint8_t Opc)
657 : TypedInit(K, Type, Opc) {}
653658
654659 public:
655660 static bool classof(const Init *I) {
676681 ///
677682 class UnOpInit : public OpInit {
678683 public:
679 enum UnaryOp { CAST, HEAD, TAIL, EMPTY };
684 enum UnaryOp : uint8_t { CAST, HEAD, TAIL, EMPTY };
680685
681686 private:
682 UnaryOp Opc;
683687 Init *LHS;
684688
685689 UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
686 : OpInit(IK_UnOpInit, Type), Opc(opc), LHS(lhs) {}
690 : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
687691
688692 UnOpInit(const UnOpInit &Other) = delete;
689693 UnOpInit &operator=(const UnOpInit &Other) = delete;
707711 return getOperand();
708712 }
709713
710 UnaryOp getOpcode() const { return Opc; }
714 UnaryOp getOpcode() const { return (UnaryOp)Opc; }
711715 Init *getOperand() const { return LHS; }
712716
713717 // Fold - If possible, fold this to a simpler init. Return this if not
723727 ///
724728 class BinOpInit : public OpInit {
725729 public:
726 enum BinaryOp { ADD, AND, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ };
730 enum BinaryOp : uint8_t { ADD, AND, SHL, SRA, SRL, LISTCONCAT,
731 STRCONCAT, CONCAT, EQ };
727732
728733 private:
729 BinaryOp Opc;
730734 Init *LHS, *RHS;
731735
732736 BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
733 OpInit(IK_BinOpInit, Type), Opc(opc), LHS(lhs), RHS(rhs) {}
737 OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
734738
735739 BinOpInit(const BinOpInit &Other) = delete;
736740 BinOpInit &operator=(const BinOpInit &Other) = delete;
758762 }
759763 }
760764
761 BinaryOp getOpcode() const { return Opc; }
765 BinaryOp getOpcode() const { return (BinaryOp)Opc; }
762766 Init *getLHS() const { return LHS; }
763767 Init *getRHS() const { return RHS; }
764768
775779 ///
776780 class TernOpInit : public OpInit {
777781 public:
778 enum TernaryOp { SUBST, FOREACH, IF };
782 enum TernaryOp : uint8_t { SUBST, FOREACH, IF };
779783
780784 private:
781 TernaryOp Opc;
782785 Init *LHS, *MHS, *RHS;
783786
784787 TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
785788 RecTy *Type) :
786 OpInit(IK_TernOpInit, Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
789 OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
787790
788791 TernOpInit(const TernOpInit &Other) = delete;
789792 TernOpInit &operator=(const TernOpInit &Other) = delete;
814817 }
815818 }
816819
817 TernaryOp getOpcode() const { return Opc; }
820 TernaryOp getOpcode() const { return (TernaryOp)Opc; }
818821 Init *getLHS() const { return LHS; }
819822 Init *getMHS() const { return MHS; }
820823 Init *getRHS() const { return RHS; }
721721
722722 std::string UnOpInit::getAsString() const {
723723 std::string Result;
724 switch (Opc) {
724 switch (getOpcode()) {
725725 case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
726726 case HEAD: Result = "!head"; break;
727727 case TAIL: Result = "!tail"; break;
849849
850850 std::string BinOpInit::getAsString() const {
851851 std::string Result;
852 switch (Opc) {
852 switch (getOpcode()) {
853853 case CONCAT: Result = "!con"; break;
854854 case ADD: Result = "!add"; break;
855855 case AND: Result = "!and"; break;
10531053 const RecordVal *RV) const {
10541054 Init *lhs = LHS->resolveReferences(R, RV);
10551055
1056 if (Opc == IF && lhs != LHS) {
1056 if (getOpcode() == IF && lhs != LHS) {
10571057 IntInit *Value = dyn_cast(lhs);
10581058 if (Init *I = lhs->convertInitializerTo(IntRecTy::get()))
10591059 Value = dyn_cast(I);
10811081
10821082 std::string TernOpInit::getAsString() const {
10831083 std::string Result;
1084 switch (Opc) {
1084 switch (getOpcode()) {
10851085 case SUBST: Result = "!subst"; break;
10861086 case FOREACH: Result = "!foreach"; break;
10871087 case IF: Result = "!if"; break;