LLVM: lib/Transforms/Scalar/LowerExpectIntrinsic.cpp File Reference (original) (raw)

Go to the source code of this file.

Macros
#define DEBUG_TYPE "lower-expect-intrinsic"
Functions
STATISTIC (ExpectIntrinsicsHandled, "Number of 'expect' intrinsic instructions handled")
static std::tuple< uint32_t, uint32_t > getBranchWeight (Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount)
static bool handleSwitchExpect (SwitchInst &SI)
static void handlePhiDef (CallInst *Expect)
Handler for PHINodes that define the value argument to an @llvm.expect call.
template
static bool handleBrSelExpect (BrSelInst &BSI)
static bool handleBranchExpect (BranchInst &BI)
static bool lowerExpectIntrinsic (Function &F)
Variables
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 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)"))

DEBUG_TYPE

#define DEBUG_TYPE "lower-expect-intrinsic"

getBranchWeight()

handleBranchExpect()

handleBrSelExpect()

template

bool handleBrSelExpect ( BrSelInst & BSI) static

Definition at line 276 of file LowerExpectIntrinsic.cpp.

References llvm::misexpect::checkFrontendInstrumentation(), llvm::MDBuilder::createBranchWeights(), llvm::dyn_cast(), llvm::CallBase::getArgOperand(), llvm::ConstantInt::getBitWidth(), getBranchWeight(), llvm::CallBase::getCalledFunction(), llvm::Value::getContext(), llvm::Function::getIntrinsicID(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::ConstantInt::getZExtValue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, and llvm::User::setOperand().

Referenced by handleBranchExpect(), and lowerExpectIntrinsic().

handlePhiDef()

void handlePhiDef ( CallInst * Expect) static

Handler for PHINodes that define the value argument to an @llvm.expect call.

If the operand of the phi has a constant value and it 'contradicts' with the expected value of phi def, then the corresponding incoming edge of the phi is unlikely to be taken. Using that information, the branch probability info for the originating branch can be inferred.

Definition at line 116 of file LowerExpectIntrinsic.cpp.

References llvm::cast(), llvm::MDBuilder::createBranchWeights(), llvm::dyn_cast(), llvm::CallBase::getArgOperand(), getBranchWeight(), llvm::CallBase::getCalledFunction(), llvm::Function::getIntrinsicID(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getValue(), llvm::isa(), llvm::BranchInst::isConditional(), llvm::BranchInst::isUnconditional(), llvm_unreachable, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::reverse(), llvm::Instruction::setMetadata(), and std::swap().

Referenced by lowerExpectIntrinsic().

handleSwitchExpect()

Definition at line 364 of file LowerExpectIntrinsic.cpp.

References Changed, llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), F, llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledFunction(), llvm::Function::getIntrinsicID(), handleBranchExpect(), handleBrSelExpect(), handlePhiDef(), handleSwitchExpect(), llvm::make_early_inc_range(), llvm::Value::replaceAllUsesWith(), and llvm::reverse().

Referenced by llvm::LowerExpectIntrinsicPass::run().

STATISTIC()

STATISTIC ( ExpectIntrinsicsHandled ,
"Number of 'expect' intrinsic instructions handled" )

LikelyBranchWeight

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)")) ( "likely-branch-weight" , cl::Hidden , cl::init(2000) , cl::desc("Weight of the branch likely to be taken (default = 2000)") ) static

UnlikelyBranchWeight

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)")) ( "unlikely-branch-weight" , cl::Hidden , cl::init(1) , cl::desc("Weight of the branch unlikely to be taken (default = 1)") ) static