diff options
author | Devang Patel <dpatel@apple.com> | 2008-09-26 22:53:05 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2008-09-26 22:53:05 +0000 |
commit | 19c874638d9478a5d5028854817a5ee72293bb2b (patch) | |
tree | 748636424f3d1005b6c8713365639fb969466c37 /lib/Transforms/IPO | |
parent | d5d8191b202c0f96f33c826c93d9796451ff7fca (diff) |
Now Attributes are divided in three groups
- return attributes - inreg, zext and sext
- parameter attributes
- function attributes - nounwind, readonly, readnone, noreturn
Return attributes use 0 as the index.
Function attributes use ~0U as the index.
This patch requires corresponding changes in llvm-gcc and clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r-- | lib/Transforms/IPO/AddReadAttrs.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/IPO/ArgumentPromotion.cpp | 18 | ||||
-rw-r--r-- | lib/Transforms/IPO/DeadArgumentElimination.cpp | 23 | ||||
-rw-r--r-- | lib/Transforms/IPO/PruneEH.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/IPO/StructRetPromotion.cpp | 16 |
5 files changed, 44 insertions, 19 deletions
diff --git a/lib/Transforms/IPO/AddReadAttrs.cpp b/lib/Transforms/IPO/AddReadAttrs.cpp index 4e0677b0d8..897548bad5 100644 --- a/lib/Transforms/IPO/AddReadAttrs.cpp +++ b/lib/Transforms/IPO/AddReadAttrs.cpp @@ -105,10 +105,10 @@ bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) { MadeChange = true; // Clear out any existing attributes. - F->removeAttribute(0, Attribute::ReadOnly | Attribute::ReadNone); + F->removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); // Add in the new attribute. - F->addAttribute(0, ReadsMemory ? Attribute::ReadOnly : Attribute::ReadNone); + F->addAttribute(~0, ReadsMemory ? Attribute::ReadOnly : Attribute::ReadNone); if (ReadsMemory) NumReadOnly++; diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index fe6583e4da..d66e2c4620 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -508,7 +508,7 @@ Function *ArgPromotion::DoPromotion(Function *F, const AttrListPtr &PAL = F->getAttributes(); // Add any return attributes. - if (Attributes attrs = PAL.getAttributes(0)) + if (Attributes attrs = PAL.getRetAttributes()) AttributesVec.push_back(AttributeWithIndex::get(0, attrs)); // First, determine the new argument list @@ -525,7 +525,7 @@ Function *ArgPromotion::DoPromotion(Function *F, } else if (!ArgsToPromote.count(I)) { // Unchanged argument Params.push_back(I->getType()); - if (Attributes attrs = PAL.getAttributes(ArgIndex)) + if (Attributes attrs = PAL.getParamAttributes(ArgIndex)) AttributesVec.push_back(AttributeWithIndex::get(Params.size(), attrs)); } else if (I->use_empty()) { // Dead argument (which are always marked as promotable) @@ -578,6 +578,10 @@ Function *ArgPromotion::DoPromotion(Function *F, } } + // Add any function attributes. + if (Attributes attrs = PAL.getFnAttributes()) + AttributesVec.push_back(AttributeWithIndex::get(~0, attrs)); + const Type *RetTy = FTy->getReturnType(); // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which @@ -621,7 +625,7 @@ Function *ArgPromotion::DoPromotion(Function *F, const AttrListPtr &CallPAL = CS.getAttributes(); // Add any return attributes. - if (Attributes attrs = CallPAL.getAttributes(0)) + if (Attributes attrs = CallPAL.getRetAttributes()) AttributesVec.push_back(AttributeWithIndex::get(0, attrs)); // Loop over the operands, inserting GEP and loads in the caller as @@ -633,7 +637,7 @@ Function *ArgPromotion::DoPromotion(Function *F, if (!ArgsToPromote.count(I) && !ByValArgsToTransform.count(I)) { Args.push_back(*AI); // Unmodified argument - if (Attributes Attrs = CallPAL.getAttributes(ArgIndex)) + if (Attributes Attrs = CallPAL.getParamAttributes(ArgIndex)) AttributesVec.push_back(AttributeWithIndex::get(Args.size(), Attrs)); } else if (ByValArgsToTransform.count(I)) { @@ -688,10 +692,14 @@ Function *ArgPromotion::DoPromotion(Function *F, // Push any varargs arguments on the list for (; AI != CS.arg_end(); ++AI, ++ArgIndex) { Args.push_back(*AI); - if (Attributes Attrs = CallPAL.getAttributes(ArgIndex)) + if (Attributes Attrs = CallPAL.getParamAttributes(ArgIndex)) AttributesVec.push_back(AttributeWithIndex::get(Args.size(), Attrs)); } + // Add any function attributes. + if (Attributes attrs = CallPAL.getFnAttributes()) + AttributesVec.push_back(AttributeWithIndex::get(~0, attrs)); + Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index eef326b758..8f0c4c41fc 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -229,6 +229,8 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { SmallVector<AttributeWithIndex, 8> AttributesVec; for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i) AttributesVec.push_back(PAL.getSlot(i)); + if (Attributes FnAttrs = PAL.getFnAttributes()) + AttributesVec.push_back(AttributeWithIndex::get(~0, FnAttrs)); PAL = AttrListPtr::get(AttributesVec.begin(), AttributesVec.end()); } @@ -593,8 +595,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { const AttrListPtr &PAL = F->getAttributes(); // The existing function return attributes. - Attributes RAttrs = PAL.getAttributes(0); - + Attributes RAttrs = PAL.getRetAttributes(); + Attributes FnAttrs = PAL.getFnAttributes(); // Find out the new return value. @@ -678,7 +680,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // Get the original parameter attributes (skipping the first one, that is // for the return value. - if (Attributes Attrs = PAL.getAttributes(i + 1)) + if (Attributes Attrs = PAL.getParamAttributes(i + 1)) AttributesVec.push_back(AttributeWithIndex::get(Params.size(), Attrs)); } else { ++NumArgumentsEliminated; @@ -687,6 +689,9 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { } } + if (FnAttrs != Attribute::None) + AttributesVec.push_back(AttributeWithIndex::get(~0, FnAttrs)); + // Reconstruct the AttributesList based on the vector we constructed. AttrListPtr NewPAL = AttrListPtr::get(AttributesVec.begin(), AttributesVec.end()); @@ -730,7 +735,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { const AttrListPtr &CallPAL = CS.getAttributes(); // The call return attributes. - Attributes RAttrs = CallPAL.getAttributes(0); + Attributes RAttrs = CallPAL.getRetAttributes(); + Attributes FnAttrs = CallPAL.getFnAttributes(); // Adjust in case the function was changed to return void. RAttrs &= ~Attribute::typeIncompatible(NF->getReturnType()); if (RAttrs) @@ -746,7 +752,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { if (ArgAlive[i]) { Args.push_back(*I); // Get original parameter attributes, but skip return attributes. - if (Attributes Attrs = CallPAL.getAttributes(i + 1)) + if (Attributes Attrs = CallPAL.getParamAttributes(i + 1)) AttributesVec.push_back(AttributeWithIndex::get(Args.size(), Attrs)); } @@ -756,13 +762,16 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // Push any varargs arguments on the list. Don't forget their attributes. for (CallSite::arg_iterator E = CS.arg_end(); I != E; ++I, ++i) { Args.push_back(*I); - if (Attributes Attrs = CallPAL.getAttributes(i + 1)) + if (Attributes Attrs = CallPAL.getParamAttributes(i + 1)) AttributesVec.push_back(AttributeWithIndex::get(Args.size(), Attrs)); } + if (FnAttrs != Attribute::None) + AttributesVec.push_back(AttributeWithIndex::get(~0, FnAttrs)); + // Reconstruct the AttributesList based on the vector we constructed. AttrListPtr NewCallPAL = AttrListPtr::get(AttributesVec.begin(), - AttributesVec.end()); + AttributesVec.end()); Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 821e7d5da9..622184415c 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -133,7 +133,7 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) { NewAttributes |= Attribute::NoReturn; const AttrListPtr &PAL = SCC[i]->getFunction()->getAttributes(); - const AttrListPtr &NPAL = PAL.addAttr(0, NewAttributes); + const AttrListPtr &NPAL = PAL.addAttr(~0, NewAttributes); if (PAL != NPAL) { MadeChange = true; SCC[i]->getFunction()->setAttributes(NPAL); diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index 07b9e504c7..96ef66c127 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -210,7 +210,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, const AttrListPtr &PAL = F->getAttributes(); // Add any return attributes. - if (Attributes attrs = PAL.getAttributes(0)) + if (Attributes attrs = PAL.getRetAttributes()) AttributesVec.push_back(AttributeWithIndex::get(0, attrs)); // Skip first argument. @@ -221,12 +221,17 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, unsigned ParamIndex = 2; while (I != E) { Params.push_back(I->getType()); - if (Attributes Attrs = PAL.getAttributes(ParamIndex)) + if (Attributes Attrs = PAL.getParamAttributes(ParamIndex)) AttributesVec.push_back(AttributeWithIndex::get(ParamIndex - 1, Attrs)); ++I; ++ParamIndex; } + // Add any fn attributes. + if (Attributes attrs = PAL.getFnAttributes()) + AttributesVec.push_back(AttributeWithIndex::get(~0, attrs)); + + FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg()); Function *NF = Function::Create(NFTy, F->getLinkage()); NF->takeName(F); @@ -264,7 +269,7 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { const AttrListPtr &PAL = F->getAttributes(); // Add any return attributes. - if (Attributes attrs = PAL.getAttributes(0)) + if (Attributes attrs = PAL.getRetAttributes()) ArgAttrsVec.push_back(AttributeWithIndex::get(0, attrs)); // Copy arguments, however skip first one. @@ -276,12 +281,15 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { unsigned ParamIndex = 2; while (AI != AE) { Args.push_back(*AI); - if (Attributes Attrs = PAL.getAttributes(ParamIndex)) + if (Attributes Attrs = PAL.getParamAttributes(ParamIndex)) ArgAttrsVec.push_back(AttributeWithIndex::get(ParamIndex - 1, Attrs)); ++ParamIndex; ++AI; } + // Add any function attributes. + if (Attributes attrs = PAL.getFnAttributes()) + ArgAttrsVec.push_back(AttributeWithIndex::get(~0, attrs)); AttrListPtr NewPAL = AttrListPtr::get(ArgAttrsVec.begin(), ArgAttrsVec.end()); |