From c3fae796fd6999c96de6b532c68f79cc9bd25ac3 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 13 Apr 2017 18:11:03 +0000 Subject: [PATCH] [InstCombine] Simplify attribute code with new AttributeList::get NFC llvm-svn: 300230 --- .../Transforms/InstCombine/InstCombineCalls.cpp | 51 +++++++++------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 814f593..8f796ed 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -4054,10 +4054,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // Okay, we decided that this is a safe thing to do: go ahead and start // inserting cast instructions as necessary. - std::vector Args; + SmallVector Args; + SmallVector ArgAttrs; Args.reserve(NumActualArgs); - SmallVector attrVec; - attrVec.reserve(NumCommonArgs); + ArgAttrs.reserve(NumActualArgs); // Get any return attributes. AttrBuilder RAttrs(CallerPAL, AttributeList::ReturnIndex); @@ -4066,32 +4066,25 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // with the existing attributes. Wipe out any problematic attributes. RAttrs.remove(AttributeFuncs::typeIncompatible(NewRetTy)); - // Add the new return attributes. - if (RAttrs.hasAttributes()) - attrVec.push_back(AttributeList::get(Caller->getContext(), - AttributeList::ReturnIndex, RAttrs)); - AI = CS.arg_begin(); for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) { Type *ParamTy = FT->getParamType(i); - if ((*AI)->getType() == ParamTy) { - Args.push_back(*AI); - } else { - Args.push_back(Builder->CreateBitOrPointerCast(*AI, ParamTy)); - } + Value *NewArg = *AI; + if ((*AI)->getType() != ParamTy) + NewArg = Builder->CreateBitOrPointerCast(*AI, ParamTy); + Args.push_back(NewArg); // Add any parameter attributes. - AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1)); - if (PAttrs.hasAttributes()) - attrVec.push_back( - AttributeList::get(Caller->getContext(), i + 1, PAttrs)); + ArgAttrs.push_back(CallerPAL.getParamAttributes(i + 1)); } // If the function takes more arguments than the call was taking, add them // now. - for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i) + for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i) { Args.push_back(Constant::getNullValue(FT->getParamType(i))); + ArgAttrs.push_back(AttributeSet()); + } // If we are removing arguments to the function, emit an obnoxious warning. if (FT->getNumParams() < NumActualArgs) { @@ -4100,35 +4093,31 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // Add all of the arguments in their promoted form to the arg list. for (unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) { Type *PTy = getPromotedType((*AI)->getType()); + Value *NewArg = *AI; if (PTy != (*AI)->getType()) { // Must promote to pass through va_arg area! Instruction::CastOps opcode = CastInst::getCastOpcode(*AI, false, PTy, false); - Args.push_back(Builder->CreateCast(opcode, *AI, PTy)); - } else { - Args.push_back(*AI); + NewArg = Builder->CreateCast(opcode, *AI, PTy); } + Args.push_back(NewArg); // Add any parameter attributes. - AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1)); - if (PAttrs.hasAttributes()) - attrVec.push_back( - AttributeList::get(FT->getContext(), i + 1, PAttrs)); + ArgAttrs.push_back(CallerPAL.getParamAttributes(i + 1)); } } } AttributeSet FnAttrs = CallerPAL.getFnAttributes(); - if (CallerPAL.hasAttributes(AttributeList::FunctionIndex)) - attrVec.push_back(AttributeList::get(Callee->getContext(), - AttributeList::FunctionIndex, - AttrBuilder(FnAttrs))); if (NewRetTy->isVoidTy()) Caller->setName(""); // Void type should not have a name. - const AttributeList &NewCallerPAL = - AttributeList::get(Callee->getContext(), attrVec); + assert((ArgAttrs.size() == FT->getNumParams() || FT->isVarArg()) && + "missing argument attributes"); + LLVMContext &Ctx = Callee->getContext(); + AttributeList NewCallerPAL = AttributeList::get( + Ctx, FnAttrs, AttributeSet::get(Ctx, RAttrs), ArgAttrs); SmallVector OpBundles; CS.getOperandBundlesAsDefs(OpBundles); -- 2.7.4