35 bool InsertLifetime) {
39 bool InsertLifetime) {
45 class InvokeInliningInfo {
54 : OuterResumeDest(II->getUnwindDest()), InnerResumeDest(0),
55 CallerLPad(0), InnerEHValuesPHI(0) {
61 for (; isa<PHINode>(
I); ++
I) {
67 CallerLPad = cast<LandingPadInst>(
I);
73 return OuterResumeDest;
91 void addIncomingPHIValuesFor(
BasicBlock *BB)
const {
92 addIncomingPHIValuesForInto(BB, OuterResumeDest);
97 for (
unsigned i = 0, e = UnwindDestPHIValues.size(); i != e; ++i, ++
I) {
106 BasicBlock *InvokeInliningInfo::getInnerResumeDest() {
107 if (InnerResumeDest)
return InnerResumeDest;
112 OuterResumeDest->splitBasicBlock(SplitPoint,
113 OuterResumeDest->getName() +
".body");
116 const unsigned PHICapacity = 2;
121 for (
unsigned i = 0, e = UnwindDestPHIValues.size(); i != e; ++i, ++
I) {
122 PHINode *OuterPHI = cast<PHINode>(
I);
124 OuterPHI->
getName() +
".lpad-body",
127 InnerPHI->addIncoming(OuterPHI, OuterResumeDest);
132 "eh.lpad-body", InsertPoint);
134 InnerEHValuesPHI->addIncoming(CallerLPad, OuterResumeDest);
137 return InnerResumeDest;
144 void InvokeInliningInfo::forwardResume(
ResumeInst *RI,
154 addIncomingPHIValuesForInto(Src, Dest);
156 InnerEHValuesPHI->addIncoming(RI->
getOperand(0), Src);
162 E = InlinedLPads.
end(); I != E; ++
I) {
164 for (
unsigned OuterIdx = 0, OuterNum = OuterLPad->
getNumClauses();
165 OuterIdx != OuterNum; ++OuterIdx)
178 InvokeInliningInfo &Invoke) {
186 L->reserveClauses(NumClauses);
187 for (
unsigned i = 0; i != NumClauses; ++i)
211 Invoke.getOuterResumeDest(),
212 InvokeArgs, CI->
getName(), BB);
225 Invoke.addIncomingPHIValuesFor(BB);
247 InvokeInliningInfo Invoke(II);
252 if (
InvokeInst *II = dyn_cast<InvokeInst>(I->getTerminator()))
264 if (
ResumeInst *RI = dyn_cast<ResumeInst>(BB->getTerminator()))
265 Invoke.forwardResume(RI, InlinedLPads);
295 if (CalleeNode == CallerNode) {
296 CallCache.assign(I, E);
297 I = CallCache.begin();
301 for (; I != E; ++
I) {
302 const Value *OrigCall = I->first;
306 if (VMI == VMap.
end() || VMI->
second == 0)
312 if (NewCall == 0)
continue;
323 if (I->second->getFunction() == 0)
344 unsigned ByValAlignment) {
345 Type *AggTy = cast<PointerType>(Arg->
getType())->getElementType();
354 if (ByValAlignment <= 1)
360 IFI.
TD) >= ByValAlignment)
379 Align = std::max(Align, ByValAlignment);
384 &*Caller->
begin()->begin());
403 Value *CallArgs[] = {
404 DestCast, SrcCast, Size,
408 IRBuilder<>(TheCall).CreateCall(MemCpyFn, CallArgs);
421 switch (II->getIntrinsicID()) {
436 if (AI->
getType() == Int8PtrTy)
442 if (I->getType() != Int8PtrTy)
continue;
443 if (I->stripPointerCasts() != AI)
continue;
474 for (; FI != Fn->
end(); ++FI) {
482 MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx);
501 bool InsertLifetime) {
504 "Instruction not in function!");
510 if (CalledFunc == 0 ||
516 bool MustClearTailCallFlags =
517 !(isa<CallInst>(TheCall) && cast<CallInst>(TheCall)->isTailCall());
530 if (CalledFunc->
hasGC()) {
531 if (!Caller->
hasGC())
533 else if (CalledFunc->
getGC() != Caller->
getGC())
538 Value *CalleePersonality = 0;
541 if (
const InvokeInst *II = dyn_cast<InvokeInst>(I->getTerminator())) {
551 if (CalleePersonality) {
554 if (
const InvokeInst *II = dyn_cast<InvokeInst>(I->getTerminator())) {
583 "No varargs calls can be inlined!");
590 E = CalledFunc->
arg_end(); I != E; ++
I, ++AI, ++ArgNo) {
591 Value *ActualArg = *AI;
604 MustClearTailCallFlags |= ActualArg != *AI;
615 false, Returns,
".i",
616 &InlinedFunctionInfo, IFI.
TD, TheCall);
619 FirstNewBlock = LastBlock; ++FirstNewBlock;
636 E = FirstNewBlock->end(); I != E; ) {
638 if (AI == 0)
continue;
655 while (isa<AllocaInst>(I) &&
656 isa<Constant>(cast<AllocaInst>(I)->getArraySize())) {
665 FirstNewBlock->getInstList(),
674 for (
unsigned ai = 0, ae = IFI.
StaticAllocas.size(); ai != ae; ++ai) {
689 uint64_t AllocaArraySize = AIArraySize->getLimitedValue();
690 assert(AllocaArraySize > 0 &&
"array size of AllocaInst is zero");
693 if (AllocaArraySize != ~0ULL &&
694 UINT64_MAX / AllocaArraySize >= AllocaTypeSize) {
696 AllocaArraySize * AllocaTypeSize);
701 builder.CreateLifetimeStart(AI, AllocaSize);
702 for (
unsigned ri = 0, re = Returns.
size(); ri != re; ++ri) {
719 .CreateCall(StackSave,
"savedstack");
723 for (
unsigned i = 0, e = Returns.
size(); i != e; ++i) {
724 IRBuilder<>(Returns[i]).CreateCall(StackRestore, SavedPtr);
733 (MustClearTailCallFlags || MarkNoUnwind)) {
737 if (
CallInst *CI = dyn_cast<CallInst>(I)) {
738 if (MustClearTailCallFlags)
739 CI->setTailCall(
false);
741 CI->setDoesNotThrow();
747 if (
InvokeInst *II = dyn_cast<InvokeInst>(TheCall))
753 if (Returns.
size() == 1 && std::distance(FirstNewBlock, Caller->
end()) == 1) {
756 FirstNewBlock->begin(), FirstNewBlock->end());
762 if (
InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
780 Returns[0]->eraseFromParent();
794 if (
InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
803 CalledFunc->
getName()+
".exit");
810 CalledFunc->
getName()+
".exit");
817 assert(Br && Br->
getOpcode() == Instruction::Br &&
818 "splitBasicBlock broken!");
826 FirstNewBlock, Caller->
end());
833 if (Returns.
size() > 1) {
838 AfterCallBB->
begin());
847 for (
unsigned i = 0, e = Returns.
size(); i != e; ++i) {
850 "Ret value not consistent in function!");
858 for (
unsigned i = 0, e = Returns.
size(); i != e; ++i) {
869 if (CreatedBranchToNormalDest)
871 }
else if (!Returns.
empty()) {
875 if (TheCall == Returns[0]->getReturnValue())
882 BasicBlock *ReturnBB = Returns[0]->getParent();
890 if (CreatedBranchToNormalDest)
891 CreatedBranchToNormalDest->
setDebugLoc(Returns[0]->getDebugLoc());
894 Returns[0]->eraseFromParent();
907 assert(cast<BranchInst>(Br)->isUnconditional() &&
"splitBasicBlock broken!");
908 BasicBlock *CalleeEntry = cast<BranchInst>(Br)->getSuccessor(0);
const Value * getCalledValue() const
static ConstantInt * getFalse(LLVMContext &Context)
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
void addIncoming(Value *V, BasicBlock *BB)
void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=0, const DataLayout *TD=0, Instruction *TheCall=0)
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
The main container class for the LLVM Intermediate Representation.
bool InlineFunction(CallInst *C, InlineFunctionInfo &IFI, bool InsertLifetime=true)
unsigned arg_size() const
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getPrefTypeAlignment(Type *Ty) const
const char * getGC() const
Type * getReturnType() const
const Function * getParent() const
Return the enclosing method, or null if none.
MDNode * getAsMDNode(const LLVMContext &Ctx) const
MDNode - a tuple of other values.
static IntegerType * getInt64Ty(LLVMContext &C)
Value * getPersonalityFn() const
static DebugLoc updateInlinedAtInfo(const DebugLoc &DL, const DebugLoc &InlinedAtDL, LLVMContext &Ctx)
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=0)
Create a lifetime.end intrinsic.
SmallVector< AllocaInst *, 4 > StaticAllocas
StringRef getName() const
void addCalledFunction(CallSite CS, CallGraphNode *M)
std::vector< CallRecord >::iterator iterator
bool isUnknown() const
isUnknown - Return true if this is an unknown location.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=0)
This file contains the simple types necessary to represent the attributes associated with functions a...
Type * getAllocatedType() const
LandingPadInst * getLandingPadInst() const
bool doesNotThrow() const
Determine if the call cannot unwind.
static Constant * getSizeOf(Type *Ty)
static void UpdateCallGraphAfterInlining(CallSite CS, Function::iterator FirstNewBlock, ValueToValueMapTy &VMap, InlineFunctionInfo &IFI)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
const BasicBlock & back() const
iterator find(const KeyT &Val)
This class represents a no-op cast from one type to another.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
unsigned getNumClauses() const
getNumClauses - Get the number of clauses for this landing pad.
void replaceAllUsesWith(Value *V)
void addClause(Value *ClauseVal)
addClause - Add a catch or filter clause to the landing pad.
BasicBlock * getNormalDest() const
static bool isUsedByLifetimeMarker(Value *V)
Value * getClause(unsigned Idx) const
LLVM Basic Block Representation.
InstrTy * getInstruction() const
PointerType * getType() const
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
LandingPadInst * getLandingPadInst()
Return the landingpad instruction associated with the landing pad.
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
SmallVector< WeakVH, 8 > InlinedCalls
const InstListType & getInstList() const
Return the underlying instruction list container.
static bool hasLifetimeMarkers(AllocaInst *AI)
Value * getOperand(unsigned i) const
MDNode * getInlinedAt(const LLVMContext &Ctx) const
static UndefValue * get(Type *T)
Value * SimplifyInstruction(Instruction *I, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
LLVMContext & getContext() const
All values hold a context through their type.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
iterator erase(iterator where)
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
MDNode * getScope(const LLVMContext &Ctx) const
static void Split(std::vector< std::string > &V, const StringRef S)
const BasicBlockListType & getBasicBlockList() const
BasicBlock * getUnwindDest() const
bool doesNotThrow() const
Determine if the call cannot unwind.
Class for constant integers.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
uint64_t getTypeAllocSize(Type *Ty) const
void eraseFromParent()
Unlink 'this' from the containing function and delete it.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
static void fixupLineNumbers(Function *Fn, Function::iterator FI, Instruction *TheCall)
const BasicBlock & getEntryBlock() const
void splice(iterator where, iplist &L2)
void setOperand(unsigned i, Value *Val)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
void setGC(const char *Str)
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
const AttributeSet & getAttributes() const
static bool HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB, InvokeInliningInfo &Invoke)
static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope, MDNode *InlinedAt=0)
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout *TD=0)
DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope, LLVMContext &VMContext)
static IntegerType * getInt32Ty(LLVMContext &C)
bool isDeclaration() const
ImmutableCallSite - establish a view to a call site for examination.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
FunctionType * getFunctionType() const
static Value * HandleByValArgument(Value *Arg, Instruction *TheCall, const Function *CalledFunc, InlineFunctionInfo &IFI, unsigned ByValAlignment)
static DebugLoc getFromDILocation(MDNode *N)
getFromDILocation - Translate the DILocation quad into a DebugLoc.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
uint64_t getTypeStoreSize(Type *Ty) const
bool ContainsDynamicAllocas
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
void removeCallEdgeFor(CallSite CS)
const Value * getArraySize() const
CallingConv::ID getCallingConv() const
std::vector< CallRecord > CalledFunctionsVector
const BasicBlock * getParent() const
FunTy * getCalledFunction() const
static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock, ClonedCodeInfo &InlinedCodeInfo)