diff options
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r-- | lib/Transforms/IPO/ArgumentPromotion.cpp | 35 | ||||
-rw-r--r-- | lib/Transforms/IPO/DeadArgumentElimination.cpp | 38 | ||||
-rw-r--r-- | lib/Transforms/IPO/ExtractFunction.cpp | 1 | ||||
-rw-r--r-- | lib/Transforms/IPO/LowerSetJmp.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/IPO/PruneEH.cpp | 1 |
5 files changed, 69 insertions, 8 deletions
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 7479c8ee67..26d8853891 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -35,6 +35,7 @@ #include "llvm/Module.h" #include "llvm/CallGraphSCCPass.h" #include "llvm/Instructions.h" +#include "llvm/ParameterAttributes.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CallGraph.h" #include "llvm/Target/TargetData.h" @@ -139,10 +140,10 @@ bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) { // No promotable pointer arguments. if (PointerArgs.empty()) return false; - // Okay, promote all of the arguments are rewrite the callees! + // Okay, promote all of the arguments and rewrite the callees! Function *NewF = DoPromotion(F, PointerArgs); - // Update the call graph to know that the old function is gone. + // Update the call graph to know that the function has been transformed. getAnalysis<CallGraph>().changeFunction(F, NewF); return true; } @@ -349,9 +350,23 @@ Function *ArgPromotion::DoPromotion(Function *F, // what the new GEP/Load instructions we are inserting look like. std::map<std::vector<Value*>, LoadInst*> OriginalLoads; - for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) + // ParamAttrs - Keep track of the parameter attributes for the arguments + // that we are *not* promoting. For the ones that we do promote, the parameter + // attributes are lost + ParamAttrsVector ParamAttrsVec; + const ParamAttrsList *PAL = F->getParamAttrs(); + + unsigned index = 1; + for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; + ++I, ++index) if (!ArgsToPromote.count(I)) { Params.push_back(I->getType()); + if (PAL) { + unsigned attrs = PAL->getParamAttrs(index); + if (attrs) + ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), + attrs)); + } } else if (I->use_empty()) { ++NumArgumentsDead; } else { @@ -387,6 +402,13 @@ Function *ArgPromotion::DoPromotion(Function *F, const Type *RetTy = FTy->getReturnType(); + // Recompute the parameter attributes list based on the new arguments for + // the function. + if (ParamAttrsVec.empty()) + PAL = 0; + else + PAL = ParamAttrsList::get(ParamAttrsVec); + // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which // have zero fixed arguments. bool ExtraArgHack = false; @@ -394,11 +416,14 @@ Function *ArgPromotion::DoPromotion(Function *F, ExtraArgHack = true; Params.push_back(Type::Int32Ty); } + + // Construct the new function type using the new arguments. FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); - // 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()); NF->setCallingConv(F->getCallingConv()); + NF->setParamAttrs(PAL); F->getParent()->getFunctionList().insert(F, NF); // Get the alias analysis information that we need to update to reflect our @@ -449,9 +474,11 @@ Function *ArgPromotion::DoPromotion(Function *F, New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); + cast<InvokeInst>(New)->setParamAttrs(PAL); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); + cast<CallInst>(New)->setParamAttrs(PAL); if (cast<CallInst>(Call)->isTailCall()) cast<CallInst>(New)->setTailCall(); } diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 3d345eefaa..a76a43a20b 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -26,6 +26,7 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" #include "llvm/Pass.h" +#include "llvm/ParameterAttributes.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/Debug.h" #include "llvm/ADT/Statistic.h" @@ -157,6 +158,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { // Create the new function body and insert it into the module... Function *NF = new Function(NFTy, Fn.getLinkage()); NF->setCallingConv(Fn.getCallingConv()); + NF->setParamAttrs(Fn.getParamAttrs()); Fn.getParent()->getFunctionList().insert(&Fn, NF); NF->takeName(&Fn); @@ -176,9 +178,11 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); + cast<InvokeInst>(New)->setParamAttrs(NF->getParamAttrs()); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); + cast<CallInst>(New)->setParamAttrs(NF->getParamAttrs()); if (cast<CallInst>(Call)->isTailCall()) cast<CallInst>(New)->setTailCall(); } @@ -233,10 +237,10 @@ static inline bool CallPassesValueThoughVararg(Instruction *Call, // (used in a computation), MaybeLive (only passed as an argument to a call), or // Dead (not used). DAE::Liveness DAE::getArgumentLiveness(const Argument &A) { - const FunctionType *FTy = A.getParent()->getFunctionType(); + const Function *F = A.getParent(); // If this is the return value of a struct function, it's not really dead. - if (FTy->isStructReturn() && &*A.getParent()->arg_begin() == &A) + if (F->isStructReturn() && &*(F->arg_begin()) == &A) return Live; if (A.use_empty()) // First check, directly dead? @@ -488,10 +492,32 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { const FunctionType *FTy = F->getFunctionType(); std::vector<const Type*> Params; - for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) - if (!DeadArguments.count(I)) + // Set up to build a new list of parameter attributes + ParamAttrsVector ParamAttrsVec; + const ParamAttrsList *PAL = F->getParamAttrs(); + + // Construct the new parameter list from non-dead arguments. Also construct + // a new set of parameter attributes to correspond. + unsigned index = 1; + for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; + ++I, ++index) + if (!DeadArguments.count(I)) { Params.push_back(I->getType()); + if (PAL) { + uint16_t Attrs = PAL->getParamAttrs(index); + if (Attrs != ParamAttr::None) + ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), + Attrs)); + } + } + + // Reconstruct the ParamAttrsList based on the vector we constructed. + if (ParamAttrsVec.empty()) + PAL = 0; + else + PAL = ParamAttrsList::get(ParamAttrsVec); + // Make the function return void if the return value is dead. const Type *RetTy = FTy->getReturnType(); if (DeadRetVal.count(F)) { RetTy = Type::VoidTy; @@ -507,11 +533,13 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { Params.push_back(Type::Int32Ty); } + // Create the new function type based on the recomputed parameters. FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); // Create the new function body and insert it into the module... Function *NF = new Function(NFTy, F->getLinkage()); NF->setCallingConv(F->getCallingConv()); + NF->setParamAttrs(PAL); F->getParent()->getFunctionList().insert(F, NF); NF->takeName(F); @@ -542,9 +570,11 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); + cast<InvokeInst>(New)->setParamAttrs(PAL); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); + cast<CallInst>(New)->setParamAttrs(PAL); if (cast<CallInst>(Call)->isTailCall()) cast<CallInst>(New)->setTailCall(); } diff --git a/lib/Transforms/IPO/ExtractFunction.cpp b/lib/Transforms/IPO/ExtractFunction.cpp index ed22465f89..e5b2d41d52 100644 --- a/lib/Transforms/IPO/ExtractFunction.cpp +++ b/lib/Transforms/IPO/ExtractFunction.cpp @@ -95,6 +95,7 @@ namespace { Function *New = new Function(I->getFunctionType(), GlobalValue::ExternalLinkage); New->setCallingConv(I->getCallingConv()); + New->setParamAttrs(I->getParamAttrs()); // If it's not the named function, delete the body of the function I->dropAllReferences(); diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp index dbc3199162..90ece1799d 100644 --- a/lib/Transforms/IPO/LowerSetJmp.cpp +++ b/lib/Transforms/IPO/LowerSetJmp.cpp @@ -476,6 +476,8 @@ void LowerSetJmp::visitCallInst(CallInst& CI) InvokeInst* II = new InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func], Params.begin(), Params.end(), CI.getName(), Term); + II->setCallingConv(CI.getCallingConv()); + II->setParamAttrs(CI.getParamAttrs()); // Replace the old call inst with the invoke inst and remove the call. CI.replaceAllUsesWith(II); diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 52f8d5efbf..631b5f797a 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -156,6 +156,7 @@ bool PruneEH::SimplifyFunction(Function *F) { Args.begin(), Args.end(), "", II); Call->takeName(II); Call->setCallingConv(II->getCallingConv()); + Call->setParamAttrs(II->getParamAttrs()); // Anything that used the value produced by the invoke instruction // now uses the value produced by the call instruction. |