diff options
author | Reid Kleckner <rnk@google.com> | 2017-04-13 00:58:09 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-04-13 00:58:09 +0000 |
commit | 7f72033e1cde7a3a76da8c79634dfb7bf4919b54 (patch) | |
tree | 91cd8b6c041464464cf122c8b204588149e44536 /llvm/lib/Transforms/Utils/CloneFunction.cpp | |
parent | 4104cf8257717c068622383441ee37bacaa1b74a (diff) | |
download | llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.zip llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.tar.gz llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.tar.bz2 |
[IR] Take func, ret, and arg attrs separately in AttributeList::get
This seems like a much more natural API, based on Derek Schuff's
comments on r300015. It further hides the implementation detail of
AttributeList that function attributes come last and appear at index
~0U, which is easy for the user to screw up. git diff says it saves code
as well: 97 insertions(+), 137 deletions(-)
This also makes it easier to change the implementation, which I want to
do next.
llvm-svn: 300153
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneFunction.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index ae58d61..0577026 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -103,23 +103,20 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges, TypeMapper, Materializer)); - SmallVector<AttributeSet, 4> AttrVec(NewFunc->arg_size() + 2); + SmallVector<AttributeSet, 4> NewArgAttrs(NewFunc->arg_size()); AttributeList OldAttrs = OldFunc->getAttributes(); - // Copy the return attributes. - AttrVec[0] = OldAttrs.getRetAttributes(); - // Clone any argument attributes that are present in the VMap. - for (const Argument &OldArg : OldFunc->args()) + for (const Argument &OldArg : OldFunc->args()) { if (Argument *NewArg = dyn_cast<Argument>(VMap[&OldArg])) { - AttrVec[NewArg->getArgNo() + 1] = + NewArgAttrs[NewArg->getArgNo()] = OldAttrs.getParamAttributes(OldArg.getArgNo() + 1); } + } - // Copy any function attributes. - AttrVec.back() = OldAttrs.getFnAttributes(); - - NewFunc->setAttributes(AttributeList::get(NewFunc->getContext(), AttrVec)); + NewFunc->setAttributes( + AttributeList::get(NewFunc->getContext(), OldAttrs.getFnAttributes(), + OldAttrs.getRetAttributes(), NewArgAttrs)); SmallVector<std::pair<unsigned, MDNode *>, 1> MDs; OldFunc->getAllMetadata(MDs); |