diff options
author | Chris Lattner <sabre@nondot.org> | 2008-03-12 17:45:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-03-12 17:45:29 +0000 |
commit | 58d74910c6b82e622ecbb57d6644d48fec5a5c0f (patch) | |
tree | f04d1ab294b3379bf97d9f727d4ade9e7079ca48 /lib/Transforms/IPO/StructRetPromotion.cpp | |
parent | 37f603f5d78f735e8de92113429b67c77aa58086 (diff) |
Reimplement the parameter attributes support, phase #1. hilights:
1. There is now a "PAListPtr" class, which is a smart pointer around
the underlying uniqued parameter attribute list object, and manages
its refcount. It is now impossible to mess up the refcount.
2. PAListPtr is now the main interface to the underlying object, and
the underlying object is now completely opaque.
3. Implementation details like SmallVector and FoldingSet are now no
longer part of the interface.
4. You can create a PAListPtr with an arbitrary sequence of
ParamAttrsWithIndex's, no need to make a SmallVector of a specific
size (you can just use an array or scalar or vector if you wish).
5. All the client code that had to check for a null pointer before
dereferencing the pointer is simplified to just access the
PAListPtr directly.
6. The interfaces for adding attrs to a list and removing them is a
bit simpler.
Phase #2 will rename some stuff (e.g. PAListPtr) and do other less
invasive changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/StructRetPromotion.cpp')
-rw-r--r-- | lib/Transforms/IPO/StructRetPromotion.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
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(); } |