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

Go to the source code of this file.

Macros
#define DEBUG_TYPE "callsite-splitting"
Functions
STATISTIC (NumCallSiteSplit, "Number of call-site split")
static void addNonNullAttribute (CallBase &CB, Value *Op)
static void setConstantInArgument (CallBase &CB, Value *Op, Constant *ConstValue)
static bool isCondRelevantToAnyCallArgument (ICmpInst *Cmp, CallBase &CB)
static void recordCondition (CallBase &CB, BasicBlock *From, BasicBlock *To, ConditionsTy &Conditions)
If From has a conditional jump to To, add the condition to Conditions, if it is relevant to any argument at CB.
static void recordConditions (CallBase &CB, BasicBlock *Pred, ConditionsTy &Conditions, BasicBlock *StopAt)
Record ICmp conditions relevant to any argument in CB following Pred's single predecessors.
static void addConditions (CallBase &CB, const ConditionsTy &Conditions)
static SmallVector< BasicBlock *, 2 > getTwoPredecessors (BasicBlock *BB)
static bool canSplitCallSite (CallBase &CB, TargetTransformInfo &TTI)
static Instruction * cloneInstForMustTail (Instruction *I, BasicBlock::iterator Before, Value *V)
static void copyMustTailReturn (BasicBlock *SplitBB, Instruction *CI, Instruction *NewCI)
Copy mandatory musttail return sequence that follows original CI, and link it up to NewCI value instead:
static void splitCallSite (CallBase &CB, ArrayRef< std::pair< BasicBlock *, ConditionsTy > > Preds, DomTreeUpdater &DTU)
For each (predecessor, conditions from predecessors) pair, it will split the basic block containing the call site, hook it up to the predecessor and replace the call instruction with new call instructions, which contain constraints based on the conditions from their predecessors.
static bool isPredicatedOnPHI (CallBase &CB)
static PredsWithCondsTy shouldSplitOnPHIPredicatedArgument (CallBase &CB)
static PredsWithCondsTy shouldSplitOnPredicatedArgument (CallBase &CB, DomTreeUpdater &DTU)
static bool tryToSplitCallSite (CallBase &CB, TargetTransformInfo &TTI, DomTreeUpdater &DTU)
static bool doCallSiteSplitting (Function &F, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT)
Variables
static cl::opt< unsigned > DuplicationThreshold ("callsite-splitting-duplication-threshold", cl::Hidden, cl::desc("Only allow instructions before a call, if " "their cost is below DuplicationThreshold"), cl::init(5))
Only allow instructions before a call, if their CodeSize cost is below DuplicationThreshold.

DEBUG_TYPE

#define DEBUG_TYPE "callsite-splitting"

ConditionsTy

ConditionTy

PredsWithCondsTy

addConditions()

addNonNullAttribute()

canSplitCallSite()

Definition at line 184 of file CallSiteSplitting.cpp.

References llvm::BasicBlock::begin(), llvm::CallBase::cannotDuplicate(), llvm::BasicBlock::canSplitPredecessors(), DuplicationThreshold, llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::isa(), llvm::CallBase::isConvergent(), llvm::BasicBlock::isEHPad(), llvm::make_range(), llvm::predecessors(), llvm::SmallVectorTemplateCommon< T, typename >::size(), and llvm::TargetTransformInfo::TCK_CodeSize.

Referenced by tryToSplitCallSite().

cloneInstForMustTail()

copyMustTailReturn()

Copy mandatory musttail return sequence that follows original CI, and link it up to NewCI value instead:

Insert this sequence right before SplitBB's terminator, which will be cleaned up later in splitCallSite below.

Definition at line 239 of file CallSiteSplitting.cpp.

References assert(), cloneInstForMustTail(), llvm::dyn_cast(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getParent(), llvm::Function::getReturnType(), llvm::BasicBlock::getTerminator(), II, and llvm::Type::isVoidTy().

Referenced by splitCallSite().

doCallSiteSplitting()

getTwoPredecessors()

isCondRelevantToAnyCallArgument()

isPredicatedOnPHI()

recordCondition()

If From has a conditional jump to To, add the condition to Conditions, if it is relevant to any argument at CB.

Definition at line 129 of file CallSiteSplitting.cpp.

References llvm::cast(), Cond, llvm::dyn_cast(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, isCondRelevantToAnyCallArgument(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by recordConditions(), and shouldSplitOnPredicatedArgument().

recordConditions()

setConstantInArgument()

shouldSplitOnPHIPredicatedArgument()

PredsWithCondsTy shouldSplitOnPHIPredicatedArgument ( CallBase & CB) static

shouldSplitOnPredicatedArgument()

Definition at line 455 of file CallSiteSplitting.cpp.

References llvm::all_of(), assert(), llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::getDomTree(), llvm::DominatorTreeBase< NodeT, IsPostDom >::getNode(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), getTwoPredecessors(), llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::hasDomTree(), P, llvm::SmallVectorTemplateBase< T, bool >::push_back(), recordCondition(), recordConditions(), llvm::reverse(), and llvm::StopAt.

Referenced by tryToSplitCallSite().

splitCallSite()

For each (predecessor, conditions from predecessors) pair, it will split the basic block containing the call site, hook it up to the predecessor and replace the call instruction with new call instructions, which contain constraints based on the conditions from their predecessors.

For example, in the IR below with an OR condition, the call-site can be split. In this case, Preds for Tail is [(Header, a == null), (TBB, a != null, b == null)]. Tail is replaced by 2 split blocks, containing CallInst1, which has constraints based on the conditions from Head and CallInst2, which has constraints based on the conditions coming from TBB.

From :

Header: c = icmp eq i32* a, null br i1 c Tail, TBB TBB: c2 = icmp eq i32* b, null br i1 c Tail, End Tail: ca = call i1 @callee (i32* a, i32* b)

to :

Header: // PredBB1 is Header c = icmp eq i32* a, null br i1 c Tail-split1, TBB TBB: // PredBB2 is TBB c2 = icmp eq i32* b, null br i1 c Tail-split2, End Tail-split1: ca1 = call @callee (i32* null, i32* b) // CallInst1 br Tail Tail-split2: ca2 = call @callee (i32* nonnull a, i32* null) // CallInst2 br Tail Tail: p = phi i1 [ca1, Tail-split1],[ca2, Tail-split2]

Note that in case any arguments at the call-site are constrained by its predecessors, new call-sites with more constrained arguments will be created in createCallSitesOnPredicatedArgument().

Definition at line 302 of file CallSiteSplitting.cpp.

References addConditions(), llvm::PHINode::addIncoming(), llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdatesPermissive(), llvm::CallBase::args(), assert(), llvm::BasicBlock::begin(), llvm::cast(), copyMustTailReturn(), llvm::PHINode::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::DomTreeUpdater::deleteBB(), llvm::Instruction::dropDbgRecords(), llvm::DuplicateInstructionsInSplitBetween(), llvm::Instruction::eraseFromParent(), llvm::Instruction::getDebugLoc(), llvm::ilist_node_impl< OptionsT >::getIterator(), getParent(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::ilist_node_impl< OptionsT >::getReverseIterator(), llvm::Value::getType(), I, llvm::Instruction::insertBefore(), llvm::isa(), llvm::CallBase::isMustTailCall(), LLVM_DEBUG, llvm::BasicBlock::phis(), llvm::predecessors(), llvm::BasicBlock::rend(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setDebugLoc(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::SplitBlock(), and llvm::Value::use_empty().

Referenced by tryToSplitCallSite().

STATISTIC()

STATISTIC ( NumCallSiteSplit ,
"Number of call-site split" )

tryToSplitCallSite()

DuplicationThreshold

cl::opt< unsigned > DuplicationThreshold("callsite-splitting-duplication-threshold", cl::Hidden, cl::desc("Only allow instructions before a call, if " "their cost is below DuplicationThreshold"), cl::init(5)) ( "callsite-splitting-duplication-threshold" , cl::Hidden , cl::desc("Only allow instructions before a call, if " "their cost is below DuplicationThreshold") , cl::init(5) ) static

Only allow instructions before a call, if their CodeSize cost is below DuplicationThreshold.

Those instructions need to be duplicated in all split blocks.

Referenced by canSplitCallSite().