Preserve calling conventions when doing IPO

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21798 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-05-09 01:05:50 +00:00
parent c154cef9a1
commit f201dbc1a4
3 changed files with 13 additions and 5 deletions

View File

@ -394,6 +394,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Create the new function body and insert it into the module... // Create the new function body and insert it into the module...
Function *NF = new Function(NFTy, F->getLinkage(), F->getName()); Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
NF->setCallingConv(F->getCallingConv());
F->getParent()->getFunctionList().insert(F, NF); F->getParent()->getFunctionList().insert(F, NF);
// Get the alias analysis information that we need to update to reflect our // Get the alias analysis information that we need to update to reflect our
@ -411,7 +412,8 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Loop over the operands, inserting GEP and loads in the caller as // Loop over the operands, inserting GEP and loads in the caller as
// appropriate. // appropriate.
CallSite::arg_iterator AI = CS.arg_begin(); CallSite::arg_iterator AI = CS.arg_begin();
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I, ++AI) for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
I != E; ++I, ++AI)
if (!ArgsToPromote.count(I)) if (!ArgsToPromote.count(I))
Args.push_back(*AI); // Unmodified argument Args.push_back(*AI); // Unmodified argument
else if (!I->use_empty()) { else if (!I->use_empty()) {
@ -441,8 +443,10 @@ Function *ArgPromotion::DoPromotion(Function *F,
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
Args, "", Call); Args, "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else { } else {
New = new CallInst(NF, Args, "", Call); New = new CallInst(NF, Args, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall()) if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall(); cast<CallInst>(New)->setTailCall();
} }

View File

@ -400,6 +400,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
// Create the new function body and insert it into the module... // Create the new function body and insert it into the module...
Function *NF = new Function(NFTy, F->getLinkage(), F->getName()); Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
NF->setCallingConv(F->getCallingConv());
F->getParent()->getFunctionList().insert(F, NF); F->getParent()->getFunctionList().insert(F, NF);
// Loop over all of the callers of the function, transforming the call sites // Loop over all of the callers of the function, transforming the call sites
@ -428,8 +429,10 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
Args, "", Call); Args, "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else { } else {
New = new CallInst(NF, Args, "", Call); New = new CallInst(NF, Args, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall()) if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall(); cast<CallInst>(New)->setTailCall();
} }

View File

@ -144,10 +144,11 @@ bool PruneEH::SimplifyFunction(Function *F) {
if (DoesNotUnwind.count(CG[F])) { if (DoesNotUnwind.count(CG[F])) {
// Insert a call instruction before the invoke... // Insert a call instruction before the invoke...
std::string Name = II->getName(); II->setName(""); std::string Name = II->getName(); II->setName("");
Value *Call = new CallInst(II->getCalledValue(), CallInst *Call = new CallInst(II->getCalledValue(),
std::vector<Value*>(II->op_begin()+3, std::vector<Value*>(II->op_begin()+3,
II->op_end()), II->op_end()),
Name, II); Name, II);
Call->setCallingConv(II->getCallingConv());
// Anything that used the value produced by the invoke instruction // Anything that used the value produced by the invoke instruction
// now uses the value produced by the call instruction. // now uses the value produced by the call instruction.