32 #define DEBUG_TYPE "lower-expect-intrinsic"
35 "Number of 'expect' intrinsic instructions handled");
51 cl::desc(
"Weight of the branch likely to be taken (default = 2000)"));
54 cl::desc(
"Weight of the branch unlikely to be taken (default = 1)"));
126 if (ExpectedValue->
isOne())
136 BSI.setCondition(ArgValue);
144 return handleBrSelExpect<BranchInst>(BI);
148 bool Changed =
false;
152 if (
BranchInst *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
154 ExpectIntrinsicsHandled++;
155 }
else if (
SwitchInst *
SI = dyn_cast<SwitchInst>(BB.getTerminator())) {
157 ExpectIntrinsicsHandled++;
163 for (
auto BI = BB.rbegin(), BE = BB.rend(); BI != BE;) {
169 ExpectIntrinsicsHandled++;
215 "Lower 'expect' Intrinsics",
false,
false)
218 return new LowerExpectIntrinsic();
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
INITIALIZE_PASS(LowerExpectIntrinsic,"lower-expect","Lower 'expect' Intrinsics", false, false) FunctionPass *llvm
This class represents a function call, abstracting a target machine's calling convention.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Run the pass over the function.
bool isUnconditional() const
This class represents the LLVM 'select' instruction.
static bool lowerExpectIntrinsic(Function &F)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static cl::opt< uint32_t > UnlikelyBranchWeight("unlikely-branch-weight", cl::Hidden, cl::init(1), cl::desc("Weight of the branch unlikely to be taken (default = 1)"))
initializer< Ty > init(const Ty &Val)
A set of analyses that are preserved following a run of a transformation pass.
unsigned getCaseIndex() const
Returns number of current case.
void initializeLowerExpectIntrinsicPass(PassRegistry &)
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This instruction compares its operands according to the predicate given to the constructor.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Predicate getPredicate() const
Return the predicate for this instruction.
static cl::opt< uint32_t > LikelyBranchWeight("likely-branch-weight", cl::Hidden, cl::init(2000), cl::desc("Weight of the branch likely to be taken (default = 2000)"))
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
static bool handleBrSelExpect(BrSelInst &BSI)
This is the shared class of boolean and integer constants.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
CaseIt findCaseValue(const ConstantInt *C)
Search all of the case values for the specified constant.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
void setOperand(unsigned i, Value *Val)
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
static bool handleBranchExpect(BranchInst &BI)
Value * getCondition() const
void setCondition(Value *V)
The header file for the LowerExpectIntrinsic pass as used by the new pass manager.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
CaseIt case_default()
Returns an iterator that points to the default case.
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
LLVM Value Representation.
A container for analyses that lazily runs them and caches their results.
static bool handleSwitchExpect(SwitchInst &SI)
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
FunctionPass * createLowerExpectIntrinsicPass()