summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/CloneFunction.cpp22
-rw-r--r--llvm/lib/Transforms/Utils/CodeExtractor.cpp3
2 files changed, 14 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 60b988e880b..f4803028f3c 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -103,21 +103,25 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
TypeMapper, Materializer));
+ SmallVector<std::pair<unsigned, AttributeSetNode*>, 4> AttrVec;
AttributeList OldAttrs = OldFunc->getAttributes();
+
+ // Copy the return attributes.
+ if (auto *RetAttrs = OldAttrs.getRetAttributes())
+ AttrVec.emplace_back(AttributeList::ReturnIndex, RetAttrs);
+
// Clone any argument attributes that are present in the VMap.
for (const Argument &OldArg : OldFunc->args())
if (Argument *NewArg = dyn_cast<Argument>(VMap[&OldArg])) {
- AttributeList attrs = OldAttrs.getParamAttributes(OldArg.getArgNo() + 1);
- if (attrs.getNumSlots() > 0)
- NewArg->addAttr(attrs);
+ if (auto *ParmAttrs = OldAttrs.getParamAttributes(OldArg.getArgNo() + 1))
+ AttrVec.emplace_back(NewArg->getArgNo() + 1, ParmAttrs);
}
- NewFunc->setAttributes(
- NewFunc->getAttributes()
- .addAttributes(NewFunc->getContext(), AttributeList::ReturnIndex,
- OldAttrs.getRetAttributes())
- .addAttributes(NewFunc->getContext(), AttributeList::FunctionIndex,
- OldAttrs.getFnAttributes()));
+ // Copy any function attributes.
+ if (auto *FnAttrs = OldAttrs.getFnAttributes())
+ AttrVec.emplace_back(AttributeList::FunctionIndex, FnAttrs);
+
+ NewFunc->setAttributes(AttributeList::get(NewFunc->getContext(), AttrVec));
SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
OldFunc->getAllMetadata(MDs);
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 755427cace2..3bc33d0c666 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -362,8 +362,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
// "target-features" attribute allowing it to be lowered.
// FIXME: This should be changed to check to see if a specific
// attribute can not be inherited.
- AttributeList OldFnAttrs = oldFunction->getAttributes().getFnAttributes();
- AttrBuilder AB(OldFnAttrs, AttributeList::FunctionIndex);
+ AttrBuilder AB(oldFunction->getAttributes().getFnAttributes());
for (const auto &Attr : AB.td_attrs())
newFunction->addFnAttr(Attr.first, Attr.second);
OpenPOWER on IntegriCloud