summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp31
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp52
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp17
-rw-r--r--lib/Transforms/IPO/PruneEH.cpp6
-rw-r--r--lib/Transforms/IPO/StructRetPromotion.cpp44
5 files changed, 63 insertions, 87 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();
}