From: Reid Kleckner Date: Thu, 13 Apr 2017 00:58:09 +0000 (+0000) Subject: [IR] Take func, ret, and arg attrs separately in AttributeList::get X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e65ba1f3740b2c95223526d7927bb6cc12a898db;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300153 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index e083066334..82630f5b01 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2935,12 +2935,9 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, continue; // Get the call site's attribute list. - SmallVector newAttrs; + SmallVector 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.