From 324c99dee5096be095adc3972c4a512ca0f74090 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 10 Apr 2017 20:18:10 +0000 Subject: [IR] Make AttributeSetNode public, avoid temporary AttributeList copies Summary: AttributeList::get(Fn|Ret|Param)Attributes no longer creates a temporary AttributeList just to hide the AttributeSetNode type. I've also added a factory method to create AttributeLists from a parallel array of AttributeSetNodes. I think this simplifies construction of AttributeLists when rewriting function prototypes. Previously we would test if a particular index had attributes, and conditionally add a temporary attribute list to a vector. Now the attribute set vector is parallel to the argument vector already that these passes already construct. My long term vision is to wrap AttributeSetNode* inside an AttributeSet type that holds the enum attributes, but that will come in a follow up change. I haven't done any performance measurements for this change because profiling hasn't shown that any of the affected code is hot. Reviewers: pete, chandlerc, sanjoy, hfinkel Reviewed By: pete Subscribers: jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D31198 llvm-svn: 299875 --- llvm/lib/Transforms/Utils/CloneFunction.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp') 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, 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(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, 1> MDs; OldFunc->getAllMetadata(MDs); -- cgit v1.2.3