LLVM  6.0.0svn
Macros | Functions | Variables
LowerExpectIntrinsic.cpp File Reference
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Scalar.h"
Include dependency graph for LowerExpectIntrinsic.cpp:

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 bool handleSwitchExpect (SwitchInst &SI)
 
static void handlePhiDef (CallInst *Expect)
 Handler for PHINodes that define the value argument to an .expect call. More...
 
template<class BrSelInst >
static bool handleBrSelExpect (BrSelInst &BSI)
 
static bool handleBranchExpect (BranchInst &BI)
 
static bool lowerExpectIntrinsic (Function &F)
 
 INITIALIZE_PASS (LowerExpectIntrinsic, "lower-expect", "Lower 'expect' Intrinsics", false, false) FunctionPass *llvm
 

Variables

static cl::opt< uint32_tLikelyBranchWeight ("likely-branch-weight", cl::Hidden, cl::init(2000), cl::desc("Weight of the branch likely to be taken (default = 2000)"))
 
static cl::opt< uint32_tUnlikelyBranchWeight ("unlikely-branch-weight", cl::Hidden, cl::init(1), cl::desc("Weight of the branch unlikely to be taken (default = 1)"))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "lower-expect-intrinsic"

Definition at line 33 of file LowerExpectIntrinsic.cpp.

Function Documentation

◆ handleBranchExpect()

static bool handleBranchExpect ( BranchInst BI)
static

Definition at line 300 of file LowerExpectIntrinsic.cpp.

References llvm::BranchInst::isUnconditional().

Referenced by lowerExpectIntrinsic().

◆ handleBrSelExpect()

template<class BrSelInst >
static bool handleBrSelExpect ( BrSelInst &  BSI)
static

◆ handlePhiDef()

static void handlePhiDef ( CallInst Expect)
static

Handler for PHINodes that define the value argument to an .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 94 of file LowerExpectIntrinsic.cpp.

References Arg, llvm::dyn_cast(), llvm::CallInst::getArgOperand(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getValue(), llvm::BranchInst::isConditional(), llvm::BranchInst::isUnconditional(), LikelyBranchWeight, llvm_unreachable, llvm::LLVMContext::MD_prof, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::reverse(), llvm::Instruction::setMetadata(), llvm::APInt::sext(), UnlikelyBranchWeight, and llvm::APInt::zext().

Referenced by lowerExpectIntrinsic().

◆ handleSwitchExpect()

static bool handleSwitchExpect ( SwitchInst SI)
static

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( LowerExpectIntrinsic  ,
"lower-expect"  ,
"Lower 'expect' Intrinsics"  ,
false  ,
false   
)

Definition at line 378 of file LowerExpectIntrinsic.cpp.

◆ lowerExpectIntrinsic()

static bool lowerExpectIntrinsic ( Function F)
static

◆ STATISTIC()

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

Variable Documentation

◆ 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)"))
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)"))
static