/// in the body of the inlined function into invokes and turn unwind
/// instructions into branches to the invoke unwind dest.
///
-/// II is the invoke instruction begin inlined. FirstNewBlock is the first
+/// II is the invoke instruction being inlined. FirstNewBlock is the first
/// block of the inlined code (the last block is the end of the function),
/// and InlineCodeInfo is information about the code that got inlined.
static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
InvokeArgs.begin(), InvokeArgs.end(),
CI->getName(), BB->getTerminator());
II->setCallingConv(CI->getCallingConv());
- II->setParamAttrs(CI->getParamAttrs());
+ II->setAttributes(CI->getAttributes());
// Make sure that anything using the call now uses the invoke!
CI->replaceAllUsesWith(II);
CallGraph &CG) {
const Function *Caller = CS.getInstruction()->getParent()->getParent();
const Function *Callee = CS.getCalledFunction();
-
- // Update the call graph by deleting the edge from Callee to Caller
CallGraphNode *CalleeNode = CG[Callee];
CallGraphNode *CallerNode = CG[Caller];
- CallerNode->removeCallEdgeFor(CS);
// Since we inlined some uninlined call sites in the callee into the caller,
// add edges from the caller to all of the callees of the callee.
- for (CallGraphNode::iterator I = CalleeNode->begin(),
- E = CalleeNode->end(); I != E; ++I) {
+ CallGraphNode::iterator I = CalleeNode->begin(), E = CalleeNode->end();
+
+ // Consider the case where CalleeNode == CallerNode.
+ CallGraphNode::CalledFunctionsVector CallCache;
+ if (CalleeNode == CallerNode) {
+ CallCache.assign(I, E);
+ I = CallCache.begin();
+ E = CallCache.end();
+ }
+
+ for (; I != E; ++I) {
const Instruction *OrigCall = I->first.getInstruction();
DenseMap<const Value*, Value*>::iterator VMI = ValueMap.find(OrigCall);
CallerNode->addCalledFunction(CallSite::get(NewCall), I->second);
}
}
+ // Update the call graph by deleting the edge from Callee to Caller. We must
+ // do this after the loop above in case Caller and Callee are the same.
+ CallerNode->removeCallEdgeFor(CS);
}
CalledFunc->getFunctionType()->isVarArg()) return false;
- // If the call to the callee is a non-tail call, we must clear the 'tail'
+ // If the call to the callee is not a tail call, we must clear the 'tail'
// flags on any calls that we inline.
bool MustClearTailCallFlags =
- isa<CallInst>(TheCall) && !cast<CallInst>(TheCall)->isTailCall();
+ !(isa<CallInst>(TheCall) && cast<CallInst>(TheCall)->isTailCall());
// If the call to the callee cannot throw, set the 'nounwind' flag on any
// calls that we inline.
// by them explicit. However, we don't do this if the callee is readonly
// or readnone, because the copy would be unneeded: the callee doesn't
// modify the struct.
- if (CalledFunc->paramHasAttr(ArgNo+1, ParamAttr::ByVal) &&
+ if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) &&
!CalledFunc->onlyReadsMemory()) {
const Type *AggTy = cast<PointerType>(I->getType())->getElementType();
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
Value *NewAlloca = new AllocaInst(AggTy, 0, Align, I->getName(),
Caller->begin()->begin());
// Emit a memcpy.
+ const Type *Tys[] = { Type::Int64Ty };
Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
- Intrinsic::memcpy_i64);
+ Intrinsic::memcpy,
+ Tys, 1);
Value *DestCast = new BitCastInst(NewAlloca, VoidPtrTy, "tmp", TheCall);
Value *SrcCast = new BitCastInst(*AI, VoidPtrTy, "tmp", TheCall);
TheCall->replaceAllUsesWith(PHI);
}
- // Loop over all of the return instructions adding entries to the PHI node as
- // appropriate.
+ // Loop over all of the return instructions adding entries to the PHI node
+ // as appropriate.
if (PHI) {
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i];
}
}
- // Add a branch to the merge points and remove retrun instructions.
+ // Add a branch to the merge points and remove return instructions.
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i];
BranchInst::Create(AfterCallBB, RI);