llvm.org GIT mirror llvm / cbc4dcf
De-virtualize TerminatorInst successor accessors Use the same switch technique to eliminate virtual successor accessors from TerminatorInst. Extracted from D31261. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302827 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
3 changed file(s) with 79 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
6464 // Out of line virtual method, so the vtable, etc has a home.
6565 ~TerminatorInst() override;
6666
67 /// Virtual methods - Terminators should overload these and provide inline
68 /// overrides of non-V methods.
69 virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
70 virtual unsigned getNumSuccessorsV() const = 0;
71 virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
72
7367 public:
7468 /// Return the number of successors that this terminator has.
75 unsigned getNumSuccessors() const {
76 return getNumSuccessorsV();
77 }
69 unsigned getNumSuccessors() const;
7870
7971 /// Return the specified successor.
80 BasicBlock *getSuccessor(unsigned idx) const {
81 return getSuccessorV(idx);
82 }
72 BasicBlock *getSuccessor(unsigned idx) const;
8373
8474 /// Update the specified successor to point at the provided block.
85 void setSuccessor(unsigned idx, BasicBlock *B) {
86 setSuccessorV(idx, B);
87 }
75 void setSuccessor(unsigned idx, BasicBlock *B);
8876
8977 // Methods for support type inquiry through isa, cast, and dyn_cast:
9078 static inline bool classof(const Instruction *I) {
29492949 }
29502950
29512951 private:
2952 BasicBlock *getSuccessorV(unsigned idx) const override;
2953 unsigned getNumSuccessorsV() const override;
2954 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2952 friend TerminatorInst;
2953 BasicBlock *getSuccessorV(unsigned idx) const;
2954 unsigned getNumSuccessorsV() const;
2955 void setSuccessorV(unsigned idx, BasicBlock *B);
29552956 };
29562957
29572958 template <>
30593060 }
30603061
30613062 private:
3062 BasicBlock *getSuccessorV(unsigned idx) const override;
3063 unsigned getNumSuccessorsV() const override;
3064 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3063 friend TerminatorInst;
3064 BasicBlock *getSuccessorV(unsigned idx) const;
3065 unsigned getNumSuccessorsV() const;
3066 void setSuccessorV(unsigned idx, BasicBlock *B);
30653067 };
30663068
30673069 template <>
34233425 }
34243426
34253427 private:
3426 BasicBlock *getSuccessorV(unsigned idx) const override;
3427 unsigned getNumSuccessorsV() const override;
3428 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3428 friend TerminatorInst;
3429 BasicBlock *getSuccessorV(unsigned idx) const;
3430 unsigned getNumSuccessorsV() const;
3431 void setSuccessorV(unsigned idx, BasicBlock *B);
34293432 };
34303433
34313434 template <>
35283531 }
35293532
35303533 private:
3531 BasicBlock *getSuccessorV(unsigned idx) const override;
3532 unsigned getNumSuccessorsV() const override;
3533 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3534 friend TerminatorInst;
3535 BasicBlock *getSuccessorV(unsigned idx) const;
3536 unsigned getNumSuccessorsV() const;
3537 void setSuccessorV(unsigned idx, BasicBlock *B);
35343538 };
35353539
35363540 template <>
40084012 }
40094013
40104014 private:
4011 BasicBlock *getSuccessorV(unsigned idx) const override;
4012 unsigned getNumSuccessorsV() const override;
4013 void setSuccessorV(unsigned idx, BasicBlock *B) override;
4015 friend TerminatorInst;
4016 BasicBlock *getSuccessorV(unsigned idx) const;
4017 unsigned getNumSuccessorsV() const;
4018 void setSuccessorV(unsigned idx, BasicBlock *B);
40144019
40154020 template bool hasFnAttrImpl(AttrKind Kind) const {
40164021 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
41074112 }
41084113
41094114 private:
4110 BasicBlock *getSuccessorV(unsigned idx) const override;
4111 unsigned getNumSuccessorsV() const override;
4112 void setSuccessorV(unsigned idx, BasicBlock *B) override;
4115 friend TerminatorInst;
4116 BasicBlock *getSuccessorV(unsigned idx) const;
4117 unsigned getNumSuccessorsV() const;
4118 void setSuccessorV(unsigned idx, BasicBlock *B);
41134119 };
41144120
41154121 template <>
42904296 }
42914297
42924298 private:
4293 BasicBlock *getSuccessorV(unsigned Idx) const override;
4294 unsigned getNumSuccessorsV() const override;
4295 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4299 friend TerminatorInst;
4300 BasicBlock *getSuccessorV(unsigned Idx) const;
4301 unsigned getNumSuccessorsV() const;
4302 void setSuccessorV(unsigned Idx, BasicBlock *B);
42964303 };
42974304
42984305 template <>
44554462 }
44564463
44574464 private:
4458 BasicBlock *getSuccessorV(unsigned Idx) const override;
4459 unsigned getNumSuccessorsV() const override;
4460 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4465 friend TerminatorInst;
4466 BasicBlock *getSuccessorV(unsigned Idx) const;
4467 unsigned getNumSuccessorsV() const;
4468 void setSuccessorV(unsigned Idx, BasicBlock *B);
44614469 };
44624470
44634471 template <>
45434551 }
45444552
45454553 private:
4546 BasicBlock *getSuccessorV(unsigned Idx) const override;
4547 unsigned getNumSuccessorsV() const override;
4548 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4554 friend TerminatorInst;
4555 BasicBlock *getSuccessorV(unsigned Idx) const;
4556 unsigned getNumSuccessorsV() const;
4557 void setSuccessorV(unsigned Idx, BasicBlock *B);
45494558
45504559 // Shadow Instruction::setInstructionSubclassData with a private forwarding
45514560 // method so that subclasses cannot accidentally use it.
45984607 }
45994608
46004609 private:
4601 BasicBlock *getSuccessorV(unsigned idx) const override;
4602 unsigned getNumSuccessorsV() const override;
4603 void setSuccessorV(unsigned idx, BasicBlock *B) override;
4610 friend TerminatorInst;
4611 BasicBlock *getSuccessorV(unsigned idx) const;
4612 unsigned getNumSuccessorsV() const;
4613 void setSuccessorV(unsigned idx, BasicBlock *B);
46044614 };
46054615
46064616 //===----------------------------------------------------------------------===//
4242
4343 // Out of line virtual method, so the vtable, etc has a home.
4444 TerminatorInst::~TerminatorInst() {
45 }
46
47 unsigned TerminatorInst::getNumSuccessors() const {
48 switch (getOpcode()) {
49 #define HANDLE_TERM_INST(N, OPC, CLASS) \
50 case Instruction::OPC: \
51 return static_cast(this)->getNumSuccessorsV();
52 #include "llvm/IR/Instruction.def"
53 default:
54 break;
55 }
56 llvm_unreachable("not a terminator");
57 }
58
59 BasicBlock *TerminatorInst::getSuccessor(unsigned idx) const {
60 switch (getOpcode()) {
61 #define HANDLE_TERM_INST(N, OPC, CLASS) \
62 case Instruction::OPC: \
63 return static_cast(this)->getSuccessorV(idx);
64 #include "llvm/IR/Instruction.def"
65 default:
66 break;
67 }
68 llvm_unreachable("not a terminator");
69 }
70
71 void TerminatorInst::setSuccessor(unsigned idx, BasicBlock *B) {
72 switch (getOpcode()) {
73 #define HANDLE_TERM_INST(N, OPC, CLASS) \
74 case Instruction::OPC: \
75 return static_cast(this)->setSuccessorV(idx, B);
76 #include "llvm/IR/Instruction.def"
77 default:
78 break;
79 }
80 llvm_unreachable("not a terminator");
4581 }
4682
4783 //===----------------------------------------------------------------------===//