LLVM  3.7.0
Macros | Functions | Variables
PlaceSafepoints.cpp File Reference
#include "llvm/Pass.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/ADT/SetOperations.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Statepoint.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
Include dependency graph for PlaceSafepoints.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "safepoint-placement"
 

Functions

 STATISTIC (NumEntrySafepoints,"Number of entry safepoints inserted")
 
 STATISTIC (NumCallSafepoints,"Number of call safepoints inserted")
 
 STATISTIC (NumBackedgeSafepoints,"Number of backedge safepoints inserted")
 
 STATISTIC (CallInLoop,"Number of loops w/o safepoints due to calls in loop")
 
 STATISTIC (FiniteExecution,"Number of loops w/o safepoints finite execution")
 
static void InsertSafepointPoll (Instruction *InsertBefore, std::vector< CallSite > &ParsePointsNeeded)
 
static bool isGCLeafFunction (const CallSite &CS)
 
static bool needsStatepoint (const CallSite &CS)
 
static ValueReplaceWithStatepoint (const CallSite &CS,Pass *P)
 Replaces the given call site (Call or Invoke) with a gc.statepoint intrinsic with an empty deoptimization arguments list. More...
 
static bool containsUnconditionalCallSafepoint (Loop *L, BasicBlock *Header, BasicBlock *Pred, DominatorTree &DT)
 Returns true if this loop is known to contain a call safepoint which must unconditionally execute on any iteration of the loop which returns to the loop header via an edge from Pred. More...
 
static bool mustBeFiniteCountedLoop (Loop *L, ScalarEvolution *SE, BasicBlock *Pred)
 Returns true if this loop is known to terminate in a finite number of iterations. More...
 
static void scanOneBB (Instruction *start, Instruction *end, std::vector< CallInst * > &calls, std::set< BasicBlock * > &seen, std::vector< BasicBlock * > &worklist)
 
static void scanInlinedCode (Instruction *start, Instruction *end, std::vector< CallInst * > &calls, std::set< BasicBlock * > &seen)
 
static bool doesNotRequireEntrySafepointBefore (const CallSite &CS)
 Returns true if an entry safepoint is not required before this callsite in the caller function. More...
 
static InstructionfindLocationForEntrySafepoint (Function &F, DominatorTree &DT)
 
static void findCallSafepoints (Function &F, std::vector< CallSite > &Found)
 Identify the list of call sites which need to be have parseable state. More...
 
template<typename T >
static void unique_unsorted (std::vector< T > &vec)
 Implement a unique function which doesn't require we sort the input vector. More...
 
static bool isGCSafepointPoll (Function &F)
 
static bool shouldRewriteFunction (Function &F)
 Returns true if this function should be rewritten to include safepoint polls and parseable call sites. More...
 
static bool enableEntrySafepoints (Function &F)
 
static bool enableBackedgeSafepoints (Function &F)
 
static bool enableCallSafepoints (Function &F)
 
static BasicBlocknormalizeForInvokeSafepoint (BasicBlock *BB, BasicBlock *InvokeParent)
 
 INITIALIZE_PASS_BEGIN (PlaceBackedgeSafepointsImpl,"place-backedge-safepoints-impl","Place Backedge Safepoints", false, false) INITIALIZE_PASS_END(PlaceBackedgeSafepointsImpl
 
place backedge safepoints
Place Backedge false 
INITIALIZE_PASS_BEGIN (PlaceSafepoints,"place-safepoints","Place Safepoints", false, false) INITIALIZE_PASS_END(PlaceSafepoints
 

Variables

static cl::opt< boolAllBackedges ("spp-all-backedges", cl::Hidden, cl::init(false))
 
static cl::opt< boolSkipCounted ("spp-counted", cl::Hidden, cl::init(true))
 If true, do not place backedge safepoints in counted loops. More...
 
static cl::opt< boolSplitBackedge ("spp-split-backedge", cl::Hidden, cl::init(false))
 
static cl::opt< boolTraceLSP ("spp-trace", cl::Hidden, cl::init(false))
 
static cl::opt< boolNoEntry ("spp-no-entry", cl::Hidden, cl::init(false))
 
static cl::opt< boolNoCall ("spp-no-call", cl::Hidden, cl::init(false))
 
static cl::opt< boolNoBackedge ("spp-no-backedge", cl::Hidden, cl::init(false))
 
static const char *const GCSafepointPollName = "gc.safepoint_poll"
 
place backedge safepoints impl
 
place backedge safepoints
Place Backedge 
Safepoints
 
place backedge safepoints
Place Backedge 
false
 
place backedge safepoints
Place Backedge false place 
safepoints
 

Macro Definition Documentation

#define DEBUG_TYPE   "safepoint-placement"

Definition at line 84 of file PlaceSafepoints.cpp.

Function Documentation

static bool containsUnconditionalCallSafepoint ( Loop L,
BasicBlock Header,
BasicBlock Pred,
DominatorTree DT 
)
static

Returns true if this loop is known to contain a call safepoint which must unconditionally execute on any iteration of the loop which returns to the loop header via an edge from Pred.

Returns a conservative correct answer; i.e. false is always valid.

Definition at line 215 of file PlaceSafepoints.cpp.

References llvm::CS, llvm::DominatorTree::dominates(), llvm::DomTreeNodeBase< T >::getBlock(), llvm::DomTreeNodeBase< T >::getIDom(), llvm::DominatorTreeBase< N >::getNode(), I, and needsStatepoint().

static bool doesNotRequireEntrySafepointBefore ( const CallSite CS)
static

Returns true if an entry safepoint is not required before this callsite in the caller function.

Definition at line 387 of file PlaceSafepoints.cpp.

References llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction().

Referenced by findLocationForEntrySafepoint().

static bool enableBackedgeSafepoints ( Function F)
static

Definition at line 523 of file PlaceSafepoints.cpp.

References NoBackedge.

static bool enableCallSafepoints ( Function F)
static

Definition at line 524 of file PlaceSafepoints.cpp.

References NoCall.

static bool enableEntrySafepoints ( Function F)
static

Definition at line 522 of file PlaceSafepoints.cpp.

References NoEntry.

static void findCallSafepoints ( Function F,
std::vector< CallSite > &  Found 
)
static

Identify the list of call sites which need to be have parseable state.

Definition at line 466 of file PlaceSafepoints.cpp.

References llvm::CS, I, llvm::inst_range(), and needsStatepoint().

static Instruction* findLocationForEntrySafepoint ( Function F,
DominatorTree DT 
)
static
INITIALIZE_PASS_BEGIN ( PlaceBackedgeSafepointsImpl  ,
"place-backedge-safepoints-impl ,
"Place Backedge Safepoints ,
false  ,
false   
)
place backedge safepoints Place Backedge false INITIALIZE_PASS_BEGIN ( PlaceSafepoints  ,
"place-safepoints ,
"Place Safepoints ,
false  ,
false   
)
static void InsertSafepointPoll ( Instruction InsertBefore,
std::vector< CallSite > &  ParsePointsNeeded 
)
static
place backedge safepoints Place Backedge false place Place static false bool isGCLeafFunction ( const CallSite CS)
static
static bool isGCSafepointPoll ( Function F)
static
static bool mustBeFiniteCountedLoop ( Loop L,
ScalarEvolution SE,
BasicBlock Pred 
)
static

Returns true if this loop is known to terminate in a finite number of iterations.

Note that this function may return false for a loop which does actual terminate in a finite constant number of iterations due to conservatism in the analysis.

Definition at line 256 of file PlaceSafepoints.cpp.

References llvm::ScalarEvolution::getCouldNotCompute(), llvm::ScalarEvolution::getExitCount(), llvm::ScalarEvolution::getMaxBackedgeTakenCount(), llvm::ConstantRange::getUnsignedMax(), llvm::ScalarEvolution::getUnsignedRange(), llvm::APInt::isIntN(), llvm::LoopBase< N, M >::isLoopExiting(), SkipCounted, and llvm::APInt::ult().

static bool needsStatepoint ( const CallSite CS)
static
static BasicBlock* normalizeForInvokeSafepoint ( BasicBlock BB,
BasicBlock InvokeParent 
)
static
static Value * ReplaceWithStatepoint ( const CallSite CS,
Pass P 
)
static

Replaces the given call site (Call or Invoke) with a gc.statepoint intrinsic with an empty deoptimization arguments list.

This does NOT do explicit relocation for GC support.

Definition at line 867 of file PlaceSafepoints.cpp.

References llvm::AttrBuilder::addAttribute(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_begin(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_end(), llvm::BasicBlock::begin(), llvm::Call, llvm::AttributeSet::FunctionIndex, llvm::ConstantPointerNull::get(), llvm::StringRef::getAsInteger(), llvm::AttributeSet::getAttribute(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::getAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledValue(), llvm::CallInst::getCallingConv(), llvm::InvokeInst::getCallingConv(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::BasicBlock::getFirstInsertionPt(), llvm::AttributeSet::getFnAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Value::getName(), llvm::ilist_node< NodeTy >::getNextNode(), llvm::InvokeInst::getNormalDest(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::AttributeSet::getRetAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::getType(), llvm::Value::getType(), llvm::InvokeInst::getUnwindDest(), llvm::Attribute::getValueAsString(), llvm::Value::hasName(), llvm::IP, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::isCall(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, InstrTy, CallTy, InvokeTy, IterTy >::isInvoke(), llvm::Attribute::isStringAttribute(), llvm::CallInst::isTailCall(), llvm::Type::isVoidTy(), llvm_unreachable, llvm::makeArrayRef(), llvm::None, llvm::AttributeSet::removeAttributes(), llvm::CallInst::setAttributes(), llvm::InvokeInst::setAttributes(), llvm::InvokeInst::setCallingConv(), and llvm::Value::use_empty().

static void scanInlinedCode ( Instruction start,
Instruction end,
std::vector< CallInst * > &  calls,
std::set< BasicBlock * > &  seen 
)
static
static void scanOneBB ( Instruction start,
Instruction end,
std::vector< CallInst * > &  calls,
std::set< BasicBlock * > &  seen,
std::vector< BasicBlock * > &  worklist 
)
static
static bool shouldRewriteFunction ( Function F)
static

Returns true if this function should be rewritten to include safepoint polls and parseable call sites.

The main point of this function is to be an extension point for custom logic.

Definition at line 508 of file PlaceSafepoints.cpp.

References llvm::Function::getGC(), and llvm::Function::hasGC().

STATISTIC ( NumEntrySafepoints  ,
"Number of entry safepoints inserted"   
)
STATISTIC ( NumCallSafepoints  ,
"Number of call safepoints inserted"   
)
STATISTIC ( NumBackedgeSafepoints  ,
"Number of backedge safepoints inserted"   
)
STATISTIC ( CallInLoop  ,
"Number of loops w/o safepoints due to calls in loop"   
)
STATISTIC ( FiniteExecution  ,
"Number of loops w/o safepoints finite execution  
)
template<typename T >
static void unique_unsorted ( std::vector< T > &  vec)
static

Implement a unique function which doesn't require we sort the input vector.

Doing so has the effect of changing the output of a couple of tests in ways which make them less useful in testing fused safepoints.

Definition at line 487 of file PlaceSafepoints.cpp.

References std::swap().

Variable Documentation

cl::opt<bool> AllBackedges("spp-all-backedges", cl::Hidden, cl::init(false))
static
place backedge safepoints Place Backedge false place Place false

Definition at line 754 of file PlaceSafepoints.cpp.

const char* const GCSafepointPollName = "gc.safepoint_poll"
static

Definition at line 499 of file PlaceSafepoints.cpp.

Referenced by InsertSafepointPoll(), and isGCSafepointPoll().

place backedge safepoints impl
cl::opt<bool> NoBackedge("spp-no-backedge", cl::Hidden, cl::init(false))
static
cl::opt<bool> NoCall("spp-no-call", cl::Hidden, cl::init(false))
static

Referenced by enableCallSafepoints().

cl::opt<bool> NoEntry("spp-no-entry", cl::Hidden, cl::init(false))
static

Referenced by enableEntrySafepoints().

place backedge safepoints Place Backedge false place Place Safepoints

Definition at line 754 of file PlaceSafepoints.cpp.

place backedge safepoints Place Backedge false place safepoints

Definition at line 759 of file PlaceSafepoints.cpp.

cl::opt<bool> SkipCounted("spp-counted", cl::Hidden, cl::init(true))
static

If true, do not place backedge safepoints in counted loops.

Referenced by mustBeFiniteCountedLoop().

cl::opt<bool> SplitBackedge("spp-split-backedge", cl::Hidden, cl::init(false))
static
cl::opt<bool> TraceLSP("spp-trace", cl::Hidden, cl::init(false))
static