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 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 4104cf8257717c068622383441ee37bacaa1b74a (diff) | |
download | bcm5719-llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.tar.gz bcm5719-llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.zip |
[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 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e0830663349..82630f5b012 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2935,12 +2935,9 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, continue; // Get the call site's attribute list. - SmallVector<llvm::AttributeSet, 8> newAttrs; + SmallVector<llvm::AttributeSet, 8> newArgAttrs; llvm::AttributeList oldAttrs = callSite.getAttributes(); - // Collect any return attributes from the call. - newAttrs.push_back(oldAttrs.getRetAttributes()); - // If the function was passed too few arguments, don't transform. unsigned newNumArgs = newFn->arg_size(); if (callSite.arg_size() < newNumArgs) continue; @@ -2949,21 +2946,19 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, // If any of the types mismatch, we don't transform. unsigned argNo = 0; bool dontTransform = false; - for (llvm::Function::arg_iterator ai = newFn->arg_begin(), - ae = newFn->arg_end(); ai != ae; ++ai, ++argNo) { - if (callSite.getArgument(argNo)->getType() != ai->getType()) { + for (llvm::Argument &A : newFn->args()) { + if (callSite.getArgument(argNo)->getType() != A.getType()) { dontTransform = true; break; } // Add any parameter attributes. - newAttrs.push_back(oldAttrs.getParamAttributes(argNo + 1)); + newArgAttrs.push_back(oldAttrs.getParamAttributes(argNo + 1)); + argNo++; } if (dontTransform) continue; - newAttrs.push_back(oldAttrs.getFnAttributes()); - // Okay, we can transform this. Create the new call instruction and copy // over the required information. newArgs.append(callSite.arg_begin(), callSite.arg_begin() + argNo); @@ -2987,8 +2982,9 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, if (!newCall->getType()->isVoidTy()) newCall->takeName(callSite.getInstruction()); - newCall.setAttributes( - llvm::AttributeList::get(newFn->getContext(), newAttrs)); + newCall.setAttributes(llvm::AttributeList::get( + newFn->getContext(), oldAttrs.getFnAttributes(), + oldAttrs.getRetAttributes(), newArgAttrs)); newCall.setCallingConv(callSite.getCallingConv()); // Finally, remove the old call, replacing any uses with the new one. |