forked from OSchip/llvm-project
[InstCombine] Simplify attribute code with new AttributeList::get NFC
llvm-svn: 300230
This commit is contained in:
parent
3a1150352d
commit
c3fae796fd
|
@ -4054,10 +4054,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
||||||
|
|
||||||
// Okay, we decided that this is a safe thing to do: go ahead and start
|
// Okay, we decided that this is a safe thing to do: go ahead and start
|
||||||
// inserting cast instructions as necessary.
|
// inserting cast instructions as necessary.
|
||||||
std::vector<Value*> Args;
|
SmallVector<Value *, 8> Args;
|
||||||
|
SmallVector<AttributeSet, 8> ArgAttrs;
|
||||||
Args.reserve(NumActualArgs);
|
Args.reserve(NumActualArgs);
|
||||||
SmallVector<AttributeList, 8> attrVec;
|
ArgAttrs.reserve(NumActualArgs);
|
||||||
attrVec.reserve(NumCommonArgs);
|
|
||||||
|
|
||||||
// Get any return attributes.
|
// Get any return attributes.
|
||||||
AttrBuilder RAttrs(CallerPAL, AttributeList::ReturnIndex);
|
AttrBuilder RAttrs(CallerPAL, AttributeList::ReturnIndex);
|
||||||
|
@ -4066,32 +4066,25 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
||||||
// with the existing attributes. Wipe out any problematic attributes.
|
// with the existing attributes. Wipe out any problematic attributes.
|
||||||
RAttrs.remove(AttributeFuncs::typeIncompatible(NewRetTy));
|
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();
|
AI = CS.arg_begin();
|
||||||
for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
|
for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
|
||||||
Type *ParamTy = FT->getParamType(i);
|
Type *ParamTy = FT->getParamType(i);
|
||||||
|
|
||||||
if ((*AI)->getType() == ParamTy) {
|
Value *NewArg = *AI;
|
||||||
Args.push_back(*AI);
|
if ((*AI)->getType() != ParamTy)
|
||||||
} else {
|
NewArg = Builder->CreateBitOrPointerCast(*AI, ParamTy);
|
||||||
Args.push_back(Builder->CreateBitOrPointerCast(*AI, ParamTy));
|
Args.push_back(NewArg);
|
||||||
}
|
|
||||||
|
|
||||||
// Add any parameter attributes.
|
// Add any parameter attributes.
|
||||||
AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1));
|
ArgAttrs.push_back(CallerPAL.getParamAttributes(i + 1));
|
||||||
if (PAttrs.hasAttributes())
|
|
||||||
attrVec.push_back(
|
|
||||||
AttributeList::get(Caller->getContext(), i + 1, PAttrs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the function takes more arguments than the call was taking, add them
|
// If the function takes more arguments than the call was taking, add them
|
||||||
// now.
|
// 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)));
|
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 we are removing arguments to the function, emit an obnoxious warning.
|
||||||
if (FT->getNumParams() < NumActualArgs) {
|
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.
|
// Add all of the arguments in their promoted form to the arg list.
|
||||||
for (unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) {
|
for (unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) {
|
||||||
Type *PTy = getPromotedType((*AI)->getType());
|
Type *PTy = getPromotedType((*AI)->getType());
|
||||||
|
Value *NewArg = *AI;
|
||||||
if (PTy != (*AI)->getType()) {
|
if (PTy != (*AI)->getType()) {
|
||||||
// Must promote to pass through va_arg area!
|
// Must promote to pass through va_arg area!
|
||||||
Instruction::CastOps opcode =
|
Instruction::CastOps opcode =
|
||||||
CastInst::getCastOpcode(*AI, false, PTy, false);
|
CastInst::getCastOpcode(*AI, false, PTy, false);
|
||||||
Args.push_back(Builder->CreateCast(opcode, *AI, PTy));
|
NewArg = Builder->CreateCast(opcode, *AI, PTy);
|
||||||
} else {
|
|
||||||
Args.push_back(*AI);
|
|
||||||
}
|
}
|
||||||
|
Args.push_back(NewArg);
|
||||||
|
|
||||||
// Add any parameter attributes.
|
// Add any parameter attributes.
|
||||||
AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1));
|
ArgAttrs.push_back(CallerPAL.getParamAttributes(i + 1));
|
||||||
if (PAttrs.hasAttributes())
|
|
||||||
attrVec.push_back(
|
|
||||||
AttributeList::get(FT->getContext(), i + 1, PAttrs));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributeSet FnAttrs = CallerPAL.getFnAttributes();
|
AttributeSet FnAttrs = CallerPAL.getFnAttributes();
|
||||||
if (CallerPAL.hasAttributes(AttributeList::FunctionIndex))
|
|
||||||
attrVec.push_back(AttributeList::get(Callee->getContext(),
|
|
||||||
AttributeList::FunctionIndex,
|
|
||||||
AttrBuilder(FnAttrs)));
|
|
||||||
|
|
||||||
if (NewRetTy->isVoidTy())
|
if (NewRetTy->isVoidTy())
|
||||||
Caller->setName(""); // Void type should not have a name.
|
Caller->setName(""); // Void type should not have a name.
|
||||||
|
|
||||||
const AttributeList &NewCallerPAL =
|
assert((ArgAttrs.size() == FT->getNumParams() || FT->isVarArg()) &&
|
||||||
AttributeList::get(Callee->getContext(), attrVec);
|
"missing argument attributes");
|
||||||
|
LLVMContext &Ctx = Callee->getContext();
|
||||||
|
AttributeList NewCallerPAL = AttributeList::get(
|
||||||
|
Ctx, FnAttrs, AttributeSet::get(Ctx, RAttrs), ArgAttrs);
|
||||||
|
|
||||||
SmallVector<OperandBundleDef, 1> OpBundles;
|
SmallVector<OperandBundleDef, 1> OpBundles;
|
||||||
CS.getOperandBundlesAsDefs(OpBundles);
|
CS.getOperandBundlesAsDefs(OpBundles);
|
||||||
|
|
Loading…
Reference in New Issue