Author: rnk Date: Wed Apr 12 19:58:09 2017 New Revision: 300153 URL: http://llvm.org/viewvc/llvm-project?rev=300153&view=rev Log: [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. Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=300153&r1=300152&r2=300153&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Apr 12 19:58:09 2017 @@ -2935,12 +2935,9 @@ static void replaceUsesOfNonProtoConstan 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 replaceUsesOfNonProtoConstan // 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 replaceUsesOfNonProtoConstan 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits