summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/IPO/ArgumentPromotion.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/ArgumentPromotion.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index b8f92f26b33..cc525ce6e36 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -42,7 +42,6 @@
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
-#include "llvm/IR/AttributeSetNode.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
@@ -103,11 +102,13 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
// Attribute - 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
- SmallVector<AttributeSetNode *, 8> AttributesVec;
+ SmallVector<AttributeList, 8> AttributesVec;
const AttributeList &PAL = F->getAttributes();
// Add any return attributes.
- AttributesVec.push_back(PAL.getRetAttributes());
+ if (PAL.hasAttributes(AttributeList::ReturnIndex))
+ AttributesVec.push_back(
+ AttributeList::get(F->getContext(), PAL.getRetAttributes()));
// First, determine the new argument list
unsigned ArgIndex = 1;
@@ -118,12 +119,16 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
StructType *STy = cast<StructType>(AgTy);
Params.insert(Params.end(), STy->element_begin(), STy->element_end());
- AttributesVec.insert(AttributesVec.end(), STy->getNumElements(), nullptr);
++NumByValArgsPromoted;
} else if (!ArgsToPromote.count(&*I)) {
// Unchanged argument
Params.push_back(I->getType());
- AttributesVec.push_back(PAL.getParamAttributes(ArgIndex));
+ AttributeList attrs = PAL.getParamAttributes(ArgIndex);
+ if (attrs.hasAttributes(ArgIndex)) {
+ AttrBuilder B(attrs, ArgIndex);
+ AttributesVec.push_back(
+ AttributeList::get(F->getContext(), Params.size(), B));
+ }
} else if (I->use_empty()) {
// Dead argument (which are always marked as promotable)
++NumArgumentsDead;
@@ -168,7 +173,6 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
Params.push_back(GetElementPtrInst::getIndexedType(
cast<PointerType>(I->getType()->getScalarType())->getElementType(),
ArgIndex.second));
- AttributesVec.push_back(nullptr);
assert(Params.back());
}
@@ -180,7 +184,9 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
}
// Add any function attributes.
- AttributesVec.push_back(PAL.getFnAttributes());
+ if (PAL.hasAttributes(AttributeList::FunctionIndex))
+ AttributesVec.push_back(
+ AttributeList::get(FTy->getContext(), PAL.getFnAttributes()));
Type *RetTy = FTy->getReturnType();
@@ -217,7 +223,9 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
const AttributeList &CallPAL = CS.getAttributes();
// Add any return attributes.
- AttributesVec.push_back(CallPAL.getRetAttributes());
+ if (CallPAL.hasAttributes(AttributeList::ReturnIndex))
+ AttributesVec.push_back(
+ AttributeList::get(F->getContext(), CallPAL.getRetAttributes()));
// Loop over the operands, inserting GEP and loads in the caller as
// appropriate.
@@ -227,7 +235,12 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
++I, ++AI, ++ArgIndex)
if (!ArgsToPromote.count(&*I) && !ByValArgsToTransform.count(&*I)) {
Args.push_back(*AI); // Unmodified argument
- AttributesVec.push_back(CallPAL.getAttributes(ArgIndex));
+
+ if (CallPAL.hasAttributes(ArgIndex)) {
+ AttrBuilder B(CallPAL, ArgIndex);
+ AttributesVec.push_back(
+ AttributeList::get(F->getContext(), Args.size(), B));
+ }
} else if (ByValArgsToTransform.count(&*I)) {
// Emit a GEP and load for each element of the struct.
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
@@ -240,7 +253,6 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i), Call);
// TODO: Tell AA about the new values?
Args.push_back(new LoadInst(Idx, Idx->getName() + ".val", Call));
- AttributesVec.push_back(nullptr);
}
} else if (!I->use_empty()) {
// Non-dead argument: insert GEPs and loads as appropriate.
@@ -283,18 +295,23 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
newLoad->setAAMetadata(AAInfo);
Args.push_back(newLoad);
- AttributesVec.push_back(nullptr);
}
}
// Push any varargs arguments on the list.
for (; AI != CS.arg_end(); ++AI, ++ArgIndex) {
Args.push_back(*AI);
- AttributesVec.push_back(CallPAL.getAttributes(ArgIndex));
+ if (CallPAL.hasAttributes(ArgIndex)) {
+ AttrBuilder B(CallPAL, ArgIndex);
+ AttributesVec.push_back(
+ AttributeList::get(F->getContext(), Args.size(), B));
+ }
}
// Add any function attributes.
- AttributesVec.push_back(CallPAL.getFnAttributes());
+ if (CallPAL.hasAttributes(AttributeList::FunctionIndex))
+ AttributesVec.push_back(
+ AttributeList::get(Call->getContext(), CallPAL.getFnAttributes()));
SmallVector<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);
OpenPOWER on IntegriCloud