diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/ArgumentPromotion.cpp | 31 | ||||
-rw-r--r-- | lib/Transforms/IPO/DeadArgumentElimination.cpp | 52 | ||||
-rw-r--r-- | lib/Transforms/IPO/GlobalOpt.cpp | 17 | ||||
-rw-r--r-- | lib/Transforms/IPO/PruneEH.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/IPO/StructRetPromotion.cpp | 44 | ||||
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 67 |
6 files changed, 91 insertions, 126 deletions
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 25fa0a292b..d7f122b564 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -35,7 +35,6 @@ #include "llvm/Module.h" #include "llvm/CallGraphSCCPass.h" #include "llvm/Instructions.h" -#include "llvm/ParamAttrsList.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CallGraph.h" #include "llvm/Target/TargetData.h" @@ -401,11 +400,11 @@ Function *ArgPromotion::DoPromotion(Function *F, // 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(); + SmallVector<ParamAttrsWithIndex, 8> ParamAttrsVec; + const PAListPtr &PAL = F->getParamAttrs(); // Add any return attributes. - if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None) + if (ParameterAttributes attrs = PAL.getParamAttrs(0)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); unsigned ArgIndex = 1; @@ -420,8 +419,7 @@ Function *ArgPromotion::DoPromotion(Function *F, ++NumByValArgsPromoted; } else if (!ArgsToPromote.count(I)) { Params.push_back(I->getType()); - if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(ArgIndex) : - ParamAttr::None) + if (ParameterAttributes attrs = PAL.getParamAttrs(ArgIndex)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), attrs)); } else if (I->use_empty()) { ++NumArgumentsDead; @@ -476,8 +474,8 @@ Function *ArgPromotion::DoPromotion(Function *F, // Recompute the parameter attributes list based on the new arguments for // the function. - NF->setParamAttrs(ParamAttrsList::get(ParamAttrsVec)); - ParamAttrsVec.clear(); PAL = 0; + NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end())); + ParamAttrsVec.clear(); if (F->hasCollector()) NF->setCollector(F->getCollector()); @@ -494,11 +492,10 @@ Function *ArgPromotion::DoPromotion(Function *F, while (!F->use_empty()) { CallSite CS = CallSite::get(F->use_back()); Instruction *Call = CS.getInstruction(); - PAL = CS.getParamAttrs(); + const PAListPtr &CallPAL = CS.getParamAttrs(); // Add any return attributes. - if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : - ParamAttr::None) + if (ParameterAttributes attrs = CallPAL.getParamAttrs(0)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); // Loop over the operands, inserting GEP and loads in the caller as @@ -510,8 +507,7 @@ Function *ArgPromotion::DoPromotion(Function *F, if (!ArgsToPromote.count(I) && !ByValArgsToTransform.count(I)) { Args.push_back(*AI); // Unmodified argument - if (ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(ArgIndex) : - ParamAttr::None) + if (ParameterAttributes Attrs = CallPAL.getParamAttrs(ArgIndex)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs)); } else if (ByValArgsToTransform.count(I)) { @@ -550,8 +546,7 @@ Function *ArgPromotion::DoPromotion(Function *F, // Push any varargs arguments on the list for (; AI != CS.arg_end(); ++AI, ++ArgIndex) { Args.push_back(*AI); - if (ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(ArgIndex) : - ParamAttr::None) + if (ParameterAttributes Attrs = CallPAL.getParamAttrs(ArgIndex)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs)); } @@ -560,11 +555,13 @@ 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(ParamAttrsList::get(ParamAttrsVec)); + cast<InvokeInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), + ParamAttrsVec.end())); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); - cast<CallInst>(New)->setParamAttrs(ParamAttrsList::get(ParamAttrsVec)); + cast<CallInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), + ParamAttrsVec.end())); if (cast<CallInst>(Call)->isTailCall()) cast<CallInst>(New)->setTailCall(); } diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 088269d816..27501778da 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -26,9 +26,9 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" #include "llvm/Pass.h" -#include "llvm/ParamAttrsList.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/Debug.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/Compiler.h" #include <set> @@ -176,16 +176,12 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { Args.assign(CS.arg_begin(), CS.arg_begin()+NumArgs); // Drop any attributes that were on the vararg arguments. - const ParamAttrsList *PAL = CS.getParamAttrs(); - if (PAL && PAL->getParamIndex(PAL->size() - 1) > NumArgs) { - ParamAttrsVector ParamAttrsVec; - for (unsigned i = 0; PAL->getParamIndex(i) <= NumArgs; ++i) { - ParamAttrsWithIndex PAWI; - PAWI = ParamAttrsWithIndex::get(PAL->getParamIndex(i), - PAL->getParamAttrsAtIndex(i)); - ParamAttrsVec.push_back(PAWI); - } - PAL = ParamAttrsList::get(ParamAttrsVec); + PAListPtr PAL = CS.getParamAttrs(); + if (!PAL.isEmpty() && PAL.getSlot(PAL.getNumSlots() - 1).Index > NumArgs) { + SmallVector<ParamAttrsWithIndex, 8> ParamAttrsVec; + for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i) + ParamAttrsVec.push_back(PAL.getSlot(i)); + PAL = PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()); } Instruction *New; @@ -508,11 +504,11 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { std::vector<const Type*> Params; // Set up to build a new list of parameter attributes - ParamAttrsVector ParamAttrsVec; - const ParamAttrsList *PAL = F->getParamAttrs(); + SmallVector<ParamAttrsWithIndex, 8> ParamAttrsVec; + const PAListPtr &PAL = F->getParamAttrs(); // The existing function return attributes. - ParameterAttributes RAttrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None; + ParameterAttributes RAttrs = PAL.getParamAttrs(0); // Make the function return void if the return value is dead. const Type *RetTy = FTy->getReturnType(); @@ -532,14 +528,13 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { ++I, ++index) if (!DeadArguments.count(I)) { Params.push_back(I->getType()); - ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(index) : - ParamAttr::None; - if (Attrs) + + if (ParameterAttributes Attrs = PAL.getParamAttrs(index)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), Attrs)); } // Reconstruct the ParamAttrsList based on the vector we constructed. - PAL = ParamAttrsList::get(ParamAttrsVec); + PAListPtr NewPAL = PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()); // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which // have zero fixed arguments. @@ -556,7 +551,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { // 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); + NF->setParamAttrs(NewPAL); if (F->hasCollector()) NF->setCollector(F->getCollector()); F->getParent()->getFunctionList().insert(F, NF); @@ -570,10 +565,10 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { CallSite CS = CallSite::get(F->use_back()); Instruction *Call = CS.getInstruction(); ParamAttrsVec.clear(); - PAL = CS.getParamAttrs(); + const PAListPtr &CallPAL = CS.getParamAttrs(); // The call return attributes. - ParameterAttributes RAttrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None; + ParameterAttributes RAttrs = CallPAL.getParamAttrs(0); // Adjust in case the function was changed to return void. RAttrs &= ~ParamAttr::typeIncompatible(NF->getReturnType()); if (RAttrs) @@ -586,9 +581,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { I != E; ++I, ++AI, ++index) if (!DeadArguments.count(I)) { // Remove operands for dead arguments Args.push_back(*AI); - ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(index) : - ParamAttr::None; - if (Attrs) + if (ParameterAttributes Attrs = CallPAL.getParamAttrs(index)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs)); } @@ -598,25 +591,24 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { // Push any varargs arguments on the list. Don't forget their attributes. for (; AI != CS.arg_end(); ++AI) { Args.push_back(*AI); - ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(index++) : - ParamAttr::None; - if (Attrs) + if (ParameterAttributes Attrs = CallPAL.getParamAttrs(index++)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs)); } // Reconstruct the ParamAttrsList based on the vector we constructed. - PAL = ParamAttrsList::get(ParamAttrsVec); + PAListPtr NewCallPAL = PAListPtr::get(ParamAttrsVec.begin(), + ParamAttrsVec.end()); Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); - cast<InvokeInst>(New)->setParamAttrs(PAL); + cast<InvokeInst>(New)->setParamAttrs(NewCallPAL); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); - cast<CallInst>(New)->setParamAttrs(PAL); + cast<CallInst>(New)->setParamAttrs(NewCallPAL); if (cast<CallInst>(Call)->isTailCall()) cast<CallInst>(New)->setTailCall(); } diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 7bfed8afc6..5bb7494cd1 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -21,7 +21,6 @@ #include "llvm/Instructions.h" #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" -#include "llvm/ParamAttrsList.h" #include "llvm/Pass.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Target/TargetData.h" @@ -1592,18 +1591,13 @@ static void ChangeCalleesToFastCall(Function *F) { } } -static const ParamAttrsList *StripNest(const ParamAttrsList *Attrs) { - if (!Attrs) - return NULL; - - for (unsigned i = 0, e = Attrs->size(); i != e; ++i) { - if ((Attrs->getParamAttrsAtIndex(i) & ParamAttr::Nest) == 0) +static PAListPtr StripNest(const PAListPtr &Attrs) { + for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) { + if ((Attrs.getSlot(i).Attrs & ParamAttr::Nest) == 0) continue; - Attrs = ParamAttrsList::excludeAttrs(Attrs, Attrs->getParamIndex(i), - ParamAttr::Nest); // There can be only one. - break; + return Attrs.removeAttr(Attrs.getSlot(i).Index, ParamAttr::Nest); } return Attrs; @@ -1640,8 +1634,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) { Changed = true; } - if (F->getParamAttrs() && - F->getParamAttrs()->hasAttrSomewhere(ParamAttr::Nest) && + if (F->getParamAttrs().hasAttrSomewhere(ParamAttr::Nest) && OnlyCalledDirectly(F)) { // The function is not used by a trampoline intrinsic, so it is safe // to remove the 'nest' attribute. diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 147818a47e..46e11280b0 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -25,7 +25,6 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" -#include "llvm/ParamAttrsList.h" #include <set> #include <algorithm> using namespace llvm; @@ -131,9 +130,8 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) { if (!SCCMightReturn) NewAttributes |= ParamAttr::NoReturn; - const ParamAttrsList *PAL = SCC[i]->getFunction()->getParamAttrs(); - PAL = ParamAttrsList::includeAttrs(PAL, 0, NewAttributes); - SCC[i]->getFunction()->setParamAttrs(PAL); + const PAListPtr &PAL = SCC[i]->getFunction()->getParamAttrs(); + SCC[i]->getFunction()->setParamAttrs(PAL.addAttr(0, NewAttributes)); } for (unsigned i = 0, e = SCC.size(); i != e; ++i) { diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index c6b561dfd3..1e51cb96c9 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -17,7 +17,6 @@ #include "llvm/Module.h" #include "llvm/CallGraphSCCPass.h" #include "llvm/Instructions.h" -#include "llvm/ParamAttrsList.h" #include "llvm/Analysis/CallGraph.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/CFG.h" @@ -117,7 +116,8 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) { SmallVector<Value*, 2> GEPIdx; GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, 0)); GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, idx)); - Value *NGEPI = new GetElementPtrInst(TheAlloca, GEPIdx.begin(), GEPIdx.end(), + Value *NGEPI = new GetElementPtrInst(TheAlloca, GEPIdx.begin(), + GEPIdx.end(), "mrv.gep", I); Value *NV = new LoadInst(NGEPI, "mrv.ld", I); RetVals.push_back(NV); @@ -200,11 +200,11 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, std::vector<const Type*> Params; // ParamAttrs - Keep track of the parameter attributes for the arguments. - ParamAttrsVector ParamAttrsVec; - const ParamAttrsList *PAL = F->getParamAttrs(); + SmallVector<ParamAttrsWithIndex, 8> ParamAttrsVec; + const PAListPtr &PAL = F->getParamAttrs(); // Add any return attributes. - if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None) + if (ParameterAttributes attrs = PAL.getParamAttrs(0)) ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); // Skip first argument. @@ -215,12 +215,8 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, unsigned ParamIndex = 2; while (I != E) { Params.push_back(I->getType()); - if (PAL) { - ParameterAttributes Attrs = PAL->getParamAttrs(ParamIndex); - if (Attrs != ParamAttr::None) - ParamAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, - Attrs)); - } + if (ParameterAttributes Attrs = PAL.getParamAttrs(ParamIndex)) + ParamAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, Attrs)); ++I; ++ParamIndex; } @@ -228,7 +224,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg()); Function *NF = new Function(NFTy, F->getLinkage(), F->getName()); NF->setCallingConv(F->getCallingConv()); - NF->setParamAttrs(ParamAttrsList::get(ParamAttrsVec)); + NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end())); F->getParent()->getFunctionList().insert(F, NF); NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList()); @@ -253,16 +249,17 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { SmallVector<Value*, 16> Args; // ParamAttrs - Keep track of the parameter attributes for the arguments. - ParamAttrsVector ArgAttrsVec; + SmallVector<ParamAttrsWithIndex, 8> ArgAttrsVec; - for (Value::use_iterator FUI = F->use_begin(), FUE = F->use_end(); FUI != FUE;) { + for (Value::use_iterator FUI = F->use_begin(), FUE = F->use_end(); + FUI != FUE;) { CallSite CS = CallSite::get(*FUI); ++FUI; Instruction *Call = CS.getInstruction(); - const ParamAttrsList *PAL = F->getParamAttrs(); + const PAListPtr &PAL = F->getParamAttrs(); // Add any return attributes. - if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None) + if (ParameterAttributes attrs = PAL.getParamAttrs(0)) ArgAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); // Copy arguments, however skip first one. @@ -274,27 +271,26 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { unsigned ParamIndex = 2; while (AI != AE) { Args.push_back(*AI); - if (PAL) { - ParameterAttributes Attrs = PAL->getParamAttrs(ParamIndex); - if (Attrs != ParamAttr::None) - ArgAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, - Attrs)); - } + if (ParameterAttributes Attrs = PAL.getParamAttrs(ParamIndex)) + ArgAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, Attrs)); ++ParamIndex; ++AI; } + + PAListPtr NewPAL = PAListPtr::get(ArgAttrsVec.begin(), ArgAttrsVec.end()); + // Build new call instruction. Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); - cast<InvokeInst>(New)->setParamAttrs(ParamAttrsList::get(ArgAttrsVec)); + cast<InvokeInst>(New)->setParamAttrs(NewPAL); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); - cast<CallInst>(New)->setParamAttrs(ParamAttrsList::get(ArgAttrsVec)); + cast<CallInst>(New)->setParamAttrs(NewPAL); if (cast<CallInst>(Call)->isTailCall()) cast<CallInst>(New)->setTailCall(); } diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 4f517e6fbf..ec51508e65 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -39,7 +39,6 @@ #include "llvm/Pass.h" #include "llvm/DerivedTypes.h" #include "llvm/GlobalVariable.h" -#include "llvm/ParamAttrsList.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Target/TargetData.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -8419,7 +8418,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { return false; Function *Callee = cast<Function>(CE->getOperand(0)); Instruction *Caller = CS.getInstruction(); - const ParamAttrsList* CallerPAL = CS.getParamAttrs(); + const PAListPtr &CallerPAL = CS.getParamAttrs(); // Okay, this is a cast from a function to a different type. Unless doing so // would cause a type conversion of one of our arguments, change this call to @@ -8445,8 +8444,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { !CastInst::isCastable(FT->getReturnType(), OldRetTy)) return false; // Cannot transform this return value. - if (CallerPAL && !Caller->use_empty()) { - ParameterAttributes RAttrs = CallerPAL->getParamAttrs(0); + if (!CallerPAL.isEmpty() && !Caller->use_empty()) { + ParameterAttributes RAttrs = CallerPAL.getParamAttrs(0); if (RAttrs & ParamAttr::typeIncompatible(FT->getReturnType())) return false; // Attribute not compatible with transformed value. } @@ -8476,11 +8475,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { if (!CastInst::isCastable(ActTy, ParamTy)) return false; // Cannot transform this parameter value. - if (CallerPAL) { - ParameterAttributes PAttrs = CallerPAL->getParamAttrs(i + 1); - if (PAttrs & ParamAttr::typeIncompatible(ParamTy)) - return false; // Attribute not compatible with transformed value. - } + if (CallerPAL.getParamAttrs(i + 1) & ParamAttr::typeIncompatible(ParamTy)) + return false; // Attribute not compatible with transformed value. ConstantInt *c = dyn_cast<ConstantInt>(*AI); // Some conversions are safe even if we do not have a body. @@ -8496,16 +8492,17 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { if (FT->getNumParams() < NumActualArgs && !FT->isVarArg() && Callee->isDeclaration()) - return false; // Do not delete arguments unless we have a function body... + return false; // Do not delete arguments unless we have a function body. - if (FT->getNumParams() < NumActualArgs && FT->isVarArg() && CallerPAL) + if (FT->getNumParams() < NumActualArgs && FT->isVarArg() && + !CallerPAL.isEmpty()) // In this case we have more arguments than the new function type, but we // won't be dropping them. Check that these extra arguments have attributes // that are compatible with being a vararg call argument. - for (unsigned i = CallerPAL->size(); i; --i) { - if (CallerPAL->getParamIndex(i - 1) <= FT->getNumParams()) + for (unsigned i = CallerPAL.getNumSlots(); i; --i) { + if (CallerPAL.getSlot(i - 1).Index <= FT->getNumParams()) break; - ParameterAttributes PAttrs = CallerPAL->getParamAttrsAtIndex(i - 1); + ParameterAttributes PAttrs = CallerPAL.getSlot(i - 1).Attrs; if (PAttrs & ParamAttr::VarArgsIncompatible) return false; } @@ -8514,12 +8511,11 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // inserting cast instructions as necessary... std::vector<Value*> Args; Args.reserve(NumActualArgs); - ParamAttrsVector attrVec; + SmallVector<ParamAttrsWithIndex, 8> attrVec; attrVec.reserve(NumCommonArgs); // Get any return attributes. - ParameterAttributes RAttrs = CallerPAL ? CallerPAL->getParamAttrs(0) : - ParamAttr::None; + ParameterAttributes RAttrs = CallerPAL.getParamAttrs(0); // If the return value is not being used, the type may not be compatible // with the existing attributes. Wipe out any problematic attributes. @@ -8542,9 +8538,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { } // Add any parameter attributes. - ParameterAttributes PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) : - ParamAttr::None; - if (PAttrs) + if (ParameterAttributes PAttrs = CallerPAL.getParamAttrs(i + 1)) attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs)); } @@ -8574,10 +8568,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { } // Add any parameter attributes. - ParameterAttributes PAttrs = CallerPAL ? - CallerPAL->getParamAttrs(i + 1) : - ParamAttr::None; - if (PAttrs) + if (ParameterAttributes PAttrs = CallerPAL.getParamAttrs(i + 1)) attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs)); } } @@ -8586,7 +8577,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { if (FT->getReturnType() == Type::VoidTy) Caller->setName(""); // Void type should not have a name. - const ParamAttrsList* NewCallerPAL = ParamAttrsList::get(attrVec); + const PAListPtr &NewCallerPAL = PAListPtr::get(attrVec.begin(),attrVec.end()); Instruction *NC; if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { @@ -8642,11 +8633,11 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { Value *Callee = CS.getCalledValue(); const PointerType *PTy = cast<PointerType>(Callee->getType()); const FunctionType *FTy = cast<FunctionType>(PTy->getElementType()); - const ParamAttrsList *Attrs = CS.getParamAttrs(); + const PAListPtr &Attrs = CS.getParamAttrs(); // If the call already has the 'nest' attribute somewhere then give up - // otherwise 'nest' would occur twice after splicing in the chain. - if (Attrs && Attrs->hasAttrSomewhere(ParamAttr::Nest)) + if (Attrs.hasAttrSomewhere(ParamAttr::Nest)) return 0; IntrinsicInst *Tramp = @@ -8657,7 +8648,8 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { const PointerType *NestFPTy = cast<PointerType>(NestF->getType()); const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType()); - if (const ParamAttrsList *NestAttrs = NestF->getParamAttrs()) { + const PAListPtr &NestAttrs = NestF->getParamAttrs(); + if (!NestAttrs.isEmpty()) { unsigned NestIdx = 1; const Type *NestTy = 0; ParameterAttributes NestAttr = ParamAttr::None; @@ -8665,10 +8657,10 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { // Look for a parameter marked with the 'nest' attribute. for (FunctionType::param_iterator I = NestFTy->param_begin(), E = NestFTy->param_end(); I != E; ++NestIdx, ++I) - if (NestAttrs->paramHasAttr(NestIdx, ParamAttr::Nest)) { + if (NestAttrs.paramHasAttr(NestIdx, ParamAttr::Nest)) { // Record the parameter type and any other attributes. NestTy = *I; - NestAttr = NestAttrs->getParamAttrs(NestIdx); + NestAttr = NestAttrs.getParamAttrs(NestIdx); break; } @@ -8677,17 +8669,15 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { std::vector<Value*> NewArgs; NewArgs.reserve(unsigned(CS.arg_end()-CS.arg_begin())+1); - ParamAttrsVector NewAttrs; - NewAttrs.reserve(Attrs ? Attrs->size() + 1 : 1); + SmallVector<ParamAttrsWithIndex, 8> NewAttrs; + NewAttrs.reserve(Attrs.getNumSlots() + 1); // Insert the nest argument into the call argument list, which may // mean appending it. Likewise for attributes. // Add any function result attributes. - ParameterAttributes Attr = Attrs ? Attrs->getParamAttrs(0) : - ParamAttr::None; - if (Attr) - NewAttrs.push_back (ParamAttrsWithIndex::get(0, Attr)); + if (ParameterAttributes Attr = Attrs.getParamAttrs(0)) + NewAttrs.push_back(ParamAttrsWithIndex::get(0, Attr)); { unsigned Idx = 1; @@ -8707,8 +8697,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { // Add the original argument and attributes. NewArgs.push_back(*I); - Attr = Attrs ? Attrs->getParamAttrs(Idx) : 0; - if (Attr) + if (ParameterAttributes Attr = Attrs.getParamAttrs(Idx)) NewAttrs.push_back (ParamAttrsWithIndex::get(Idx + (Idx >= NestIdx), Attr)); @@ -8751,7 +8740,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { FunctionType::get(FTy->getReturnType(), NewTypes, FTy->isVarArg()); Constant *NewCallee = NestF->getType() == PointerType::getUnqual(NewFTy) ? NestF : ConstantExpr::getBitCast(NestF, PointerType::getUnqual(NewFTy)); - const ParamAttrsList *NewPAL = ParamAttrsList::get(NewAttrs); + const PAListPtr &NewPAL = PAListPtr::get(NewAttrs.begin(),NewAttrs.end()); Instruction *NewCaller; if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { |