14 #define DEBUG_TYPE "lower-expect-intrinsic"
32 STATISTIC(IfHandled,
"Number of 'expect' intrinsic instructions handled");
36 cl::desc(
"Weight of the branch likely to be taken (default = 64)"));
39 cl::desc(
"Weight of the branch unlikely to be taken (default = 4)"));
60 bool LowerExpectIntrinsic::HandleSwitchExpect(
SwitchInst *SI) {
76 std::vector<uint32_t> Weights(n + 1);
80 for (
unsigned i = 0; i != n; ++i)
92 bool LowerExpectIntrinsic::HandleIfExpect(
BranchInst *BI) {
123 if (ExpectedValue->
isOne())
135 bool LowerExpectIntrinsic::runOnFunction(
Function &
F) {
141 if (HandleIfExpect(BI))
144 if (HandleSwitchExpect(SI))
170 "Intrinsics",
false,
false)
173 return new LowerExpectIntrinsic();
static PassRegistry * getPassRegistry()
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
MDNode - a tuple of other values.
bool isUnconditional() const
ID
LLVM Calling Convention Representation.
STATISTIC(IfHandled,"Number of 'expect' intrinsic instructions handled")
INITIALIZE_PASS(LowerExpectIntrinsic,"lower-expect","Lower 'expect' ""Intrinsics", false, false) FunctionPass *llvm
void replaceAllUsesWith(Value *V)
initializer< Ty > init(const Ty &Val)
static cl::opt< uint32_t > UnlikelyBranchWeight("unlikely-branch-weight", cl::Hidden, cl::init(4), cl::desc("Weight of the branch unlikely to be taken (default = 4)"))
unsigned getCaseIndex() const
Returns number of current case.
void initializeLowerExpectIntrinsicPass(PassRegistry &)
LLVM Basic Block Representation.
unsigned getIntrinsicID() const LLVM_READONLY
Represent an integer comparison operator.
Value * getOperand(unsigned i) const
Predicate getPredicate() const
Return the predicate for this instruction.
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
Class for constant integers.
Function * getCalledFunction() const
CaseIt findCaseValue(const ConstantInt *C)
void setOperand(unsigned i, Value *Val)
Value * getArgOperand(unsigned i) const
Value * getCondition() const
Value * getCondition() const
void setCondition(Value *V)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
unsigned getNumCases() const
static cl::opt< uint32_t > LikelyBranchWeight("likely-branch-weight", cl::Hidden, cl::init(64), cl::desc("Weight of the branch likely to be taken (default = 64)"))
LLVM Value Representation.
bool isOne() const
Determine if the value is one.
FunctionPass * createLowerExpectIntrinsicPass()