[InstCombine] Simplify attribute code with new AttributeList::get NFC

llvm-svn: 300230
This commit is contained in:
Reid Kleckner 2017-04-13 18:11:03 +00:00
parent 3a1150352d
commit c3fae796fd
1 changed files with 20 additions and 31 deletions

View File

@ -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<Value*> Args;
SmallVector<Value *, 8> Args;
SmallVector<AttributeSet, 8> ArgAttrs;
Args.reserve(NumActualArgs);
SmallVector<AttributeList, 8> 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<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);