[llvm] r302827 - De-virtualize TerminatorInst successor accessors
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu May 11 14:26:55 PDT 2017
Author: rnk
Date: Thu May 11 16:26:55 2017
New Revision: 302827
URL: http://llvm.org/viewvc/llvm-project?rev=302827&view=rev
Log:
De-virtualize TerminatorInst successor accessors
Use the same switch technique to eliminate virtual successor accessors
from TerminatorInst. Extracted from D31261.
NFC
Modified:
llvm/trunk/include/llvm/IR/InstrTypes.h
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/lib/IR/Instructions.cpp
Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=302827&r1=302826&r2=302827&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Thu May 11 16:26:55 2017
@@ -65,27 +65,15 @@ protected:
// Out of line virtual method, so the vtable, etc has a home.
~TerminatorInst() override;
- /// Virtual methods - Terminators should overload these and provide inline
- /// overrides of non-V methods.
- virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
- virtual unsigned getNumSuccessorsV() const = 0;
- virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
-
public:
/// Return the number of successors that this terminator has.
- unsigned getNumSuccessors() const {
- return getNumSuccessorsV();
- }
+ unsigned getNumSuccessors() const;
/// Return the specified successor.
- BasicBlock *getSuccessor(unsigned idx) const {
- return getSuccessorV(idx);
- }
+ BasicBlock *getSuccessor(unsigned idx) const;
/// Update the specified successor to point at the provided block.
- void setSuccessor(unsigned idx, BasicBlock *B) {
- setSuccessorV(idx, B);
- }
+ void setSuccessor(unsigned idx, BasicBlock *B);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
Modified: llvm/trunk/include/llvm/IR/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=302827&r1=302826&r2=302827&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h (original)
+++ llvm/trunk/include/llvm/IR/Instructions.h Thu May 11 16:26:55 2017
@@ -2950,9 +2950,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
@@ -3060,9 +3061,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
@@ -3424,9 +3426,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
@@ -3529,9 +3532,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
@@ -4009,9 +4013,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
@@ -4108,9 +4113,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
@@ -4291,9 +4297,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned Idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned Idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned Idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned Idx, BasicBlock *B);
};
template <>
@@ -4456,9 +4463,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned Idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned Idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned Idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned Idx, BasicBlock *B);
};
template <>
@@ -4544,9 +4552,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned Idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned Idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned Idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned Idx, BasicBlock *B);
// Shadow Instruction::setInstructionSubclassData with a private forwarding
// method so that subclasses cannot accidentally use it.
@@ -4599,9 +4608,10 @@ public:
}
private:
- BasicBlock *getSuccessorV(unsigned idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned idx, BasicBlock *B) override;
+ friend TerminatorInst;
+ BasicBlock *getSuccessorV(unsigned idx) const;
+ unsigned getNumSuccessorsV() const;
+ void setSuccessorV(unsigned idx, BasicBlock *B);
};
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=302827&r1=302826&r2=302827&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Thu May 11 16:26:55 2017
@@ -45,6 +45,42 @@ User::op_iterator CallSite::getCallee()
TerminatorInst::~TerminatorInst() {
}
+unsigned TerminatorInst::getNumSuccessors() const {
+ switch (getOpcode()) {
+#define HANDLE_TERM_INST(N, OPC, CLASS) \
+ case Instruction::OPC: \
+ return static_cast<const CLASS *>(this)->getNumSuccessorsV();
+#include "llvm/IR/Instruction.def"
+ default:
+ break;
+ }
+ llvm_unreachable("not a terminator");
+}
+
+BasicBlock *TerminatorInst::getSuccessor(unsigned idx) const {
+ switch (getOpcode()) {
+#define HANDLE_TERM_INST(N, OPC, CLASS) \
+ case Instruction::OPC: \
+ return static_cast<const CLASS *>(this)->getSuccessorV(idx);
+#include "llvm/IR/Instruction.def"
+ default:
+ break;
+ }
+ llvm_unreachable("not a terminator");
+}
+
+void TerminatorInst::setSuccessor(unsigned idx, BasicBlock *B) {
+ switch (getOpcode()) {
+#define HANDLE_TERM_INST(N, OPC, CLASS) \
+ case Instruction::OPC: \
+ return static_cast<CLASS *>(this)->setSuccessorV(idx, B);
+#include "llvm/IR/Instruction.def"
+ default:
+ break;
+ }
+ llvm_unreachable("not a terminator");
+}
+
//===----------------------------------------------------------------------===//
// UnaryInstruction Class
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list