Change typeIncompatible to return an AttrBuilder instead of new-ing an AttributeSet.

This makes use of the new API which can remove attributes from a set given a builder.

This is much faster than creating a temporary set and reduces llc time by about 0.3% which was all spent creating temporary attributes sets on the context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236668 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper 2015-05-06 23:19:56 +00:00
parent 4716d634a2
commit a7574638e7
6 changed files with 23 additions and 39 deletions

View File

@ -565,7 +565,7 @@ public:
namespace AttributeFuncs { namespace AttributeFuncs {
/// \brief Which attributes cannot be applied to a type. /// \brief Which attributes cannot be applied to a type.
AttributeSet typeIncompatible(Type *Ty, uint64_t Index); AttrBuilder typeIncompatible(const Type *Ty);
} // end AttributeFuncs namespace } // end AttributeFuncs namespace

View File

@ -1370,7 +1370,7 @@ AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// \brief Which attributes cannot be applied to a type. /// \brief Which attributes cannot be applied to a type.
AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) { AttrBuilder AttributeFuncs::typeIncompatible(const Type *Ty) {
AttrBuilder Incompatible; AttrBuilder Incompatible;
if (!Ty->isIntegerTy()) if (!Ty->isIntegerTy())
@ -1392,5 +1392,5 @@ AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) {
.addAttribute(Attribute::StructRet) .addAttribute(Attribute::StructRet)
.addAttribute(Attribute::InAlloca); .addAttribute(Attribute::InAlloca);
return AttributeSet::get(Ty->getContext(), Index, Incompatible); return Incompatible;
} }

View File

@ -1350,9 +1350,10 @@ void Verifier::VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
V); V);
Assert(!AttrBuilder(Attrs, Idx) Assert(!AttrBuilder(Attrs, Idx)
.hasAttributes(AttributeFuncs::typeIncompatible(Ty, Idx), Idx), .overlaps(AttributeFuncs::typeIncompatible(Ty)),
"Wrong types for attribute: " + "Wrong types for attribute: " +
AttributeFuncs::typeIncompatible(Ty, Idx).getAsString(Idx), AttributeSet::get(*Context, Idx,
AttributeFuncs::typeIncompatible(Ty)).getAsString(Idx),
V); V);
if (PointerType *PTy = dyn_cast<PointerType>(Ty)) { if (PointerType *PTy = dyn_cast<PointerType>(Ty)) {

View File

@ -849,17 +849,12 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// here. Currently, this should not be possible, but special handling might be // here. Currently, this should not be possible, but special handling might be
// required when new return value attributes are added. // required when new return value attributes are added.
if (NRetTy->isVoidTy()) if (NRetTy->isVoidTy())
RAttrs = RAttrs = RAttrs.removeAttributes(NRetTy->getContext(),
AttributeSet::get(NRetTy->getContext(), AttributeSet::ReturnIndex, AttributeSet::ReturnIndex,
AttrBuilder(RAttrs, AttributeSet::ReturnIndex). AttributeFuncs::typeIncompatible(NRetTy));
removeAttributes(AttributeFuncs::
typeIncompatible(NRetTy, AttributeSet::ReturnIndex),
AttributeSet::ReturnIndex));
else else
assert(!AttrBuilder(RAttrs, AttributeSet::ReturnIndex). assert(!AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
hasAttributes(AttributeFuncs:: overlaps(AttributeFuncs::typeIncompatible(NRetTy)) &&
typeIncompatible(NRetTy, AttributeSet::ReturnIndex),
AttributeSet::ReturnIndex) &&
"Return attributes no longer compatible?"); "Return attributes no longer compatible?");
if (RAttrs.hasAttributes(AttributeSet::ReturnIndex)) if (RAttrs.hasAttributes(AttributeSet::ReturnIndex))
@ -903,13 +898,9 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
AttributeSet RAttrs = CallPAL.getRetAttributes(); AttributeSet RAttrs = CallPAL.getRetAttributes();
// Adjust in case the function was changed to return void. // Adjust in case the function was changed to return void.
RAttrs = RAttrs = RAttrs.removeAttributes(NRetTy->getContext(),
AttributeSet::get(NF->getContext(), AttributeSet::ReturnIndex, AttributeSet::ReturnIndex,
AttrBuilder(RAttrs, AttributeSet::ReturnIndex). AttributeFuncs::typeIncompatible(NF->getReturnType()));
removeAttributes(AttributeFuncs::
typeIncompatible(NF->getReturnType(),
AttributeSet::ReturnIndex),
AttributeSet::ReturnIndex));
if (RAttrs.hasAttributes(AttributeSet::ReturnIndex)) if (RAttrs.hasAttributes(AttributeSet::ReturnIndex))
AttributesVec.push_back(AttributeSet::get(NF->getContext(), RAttrs)); AttributesVec.push_back(AttributeSet::get(NF->getContext(), RAttrs));

View File

@ -1513,10 +1513,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
if (!CallerPAL.isEmpty() && !Caller->use_empty()) { if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
AttrBuilder RAttrs(CallerPAL, AttributeSet::ReturnIndex); AttrBuilder RAttrs(CallerPAL, AttributeSet::ReturnIndex);
if (RAttrs. if (RAttrs.overlaps(AttributeFuncs::typeIncompatible(NewRetTy)))
hasAttributes(AttributeFuncs::
typeIncompatible(NewRetTy, AttributeSet::ReturnIndex),
AttributeSet::ReturnIndex))
return false; // Attribute not compatible with transformed value. return false; // Attribute not compatible with transformed value.
} }
@ -1557,8 +1554,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
return false; // Cannot transform this parameter value. return false; // Cannot transform this parameter value.
if (AttrBuilder(CallerPAL.getParamAttributes(i + 1), i + 1). if (AttrBuilder(CallerPAL.getParamAttributes(i + 1), i + 1).
hasAttributes(AttributeFuncs:: overlaps(AttributeFuncs::typeIncompatible(ParamTy)))
typeIncompatible(ParamTy, i + 1), i + 1))
return false; // Attribute not compatible with transformed value. return false; // Attribute not compatible with transformed value.
if (CS.isInAllocaArgument(i)) if (CS.isInAllocaArgument(i))
@ -1631,10 +1627,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
// If the return value is not being used, the type may not be compatible // If the return value is not being used, the type may not be compatible
// with the existing attributes. Wipe out any problematic attributes. // with the existing attributes. Wipe out any problematic attributes.
RAttrs. RAttrs.remove(AttributeFuncs::typeIncompatible(NewRetTy));
removeAttributes(AttributeFuncs::
typeIncompatible(NewRetTy, AttributeSet::ReturnIndex),
AttributeSet::ReturnIndex);
// Add the new return attributes. // Add the new return attributes.
if (RAttrs.hasAttributes()) if (RAttrs.hasAttributes())

View File

@ -526,9 +526,9 @@ DataFlowSanitizer::buildWrapperFunction(Function *F, StringRef NewFName,
F->getParent()); F->getParent());
NewF->copyAttributesFrom(F); NewF->copyAttributesFrom(F);
NewF->removeAttributes( NewF->removeAttributes(
AttributeSet::ReturnIndex, AttributeSet::ReturnIndex,
AttributeFuncs::typeIncompatible(NewFT->getReturnType(), AttributeSet::get(F->getContext(), AttributeSet::ReturnIndex,
AttributeSet::ReturnIndex)); AttributeFuncs::typeIncompatible(NewFT->getReturnType())));
BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF); BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF);
if (F->isVarArg()) { if (F->isVarArg()) {
@ -703,9 +703,9 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
Function *NewF = Function::Create(NewFT, F.getLinkage(), "", &M); Function *NewF = Function::Create(NewFT, F.getLinkage(), "", &M);
NewF->copyAttributesFrom(&F); NewF->copyAttributesFrom(&F);
NewF->removeAttributes( NewF->removeAttributes(
AttributeSet::ReturnIndex, AttributeSet::ReturnIndex,
AttributeFuncs::typeIncompatible(NewFT->getReturnType(), AttributeSet::get(NewF->getContext(), AttributeSet::ReturnIndex,
AttributeSet::ReturnIndex)); AttributeFuncs::typeIncompatible(NewFT->getReturnType())));
for (Function::arg_iterator FArg = F.arg_begin(), for (Function::arg_iterator FArg = F.arg_begin(),
NewFArg = NewF->arg_begin(), NewFArg = NewF->arg_begin(),
FArgEnd = F.arg_end(); FArgEnd = F.arg_end();
@ -1587,8 +1587,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
NewCS.setCallingConv(CS.getCallingConv()); NewCS.setCallingConv(CS.getCallingConv());
NewCS.setAttributes(CS.getAttributes().removeAttributes( NewCS.setAttributes(CS.getAttributes().removeAttributes(
*DFSF.DFS.Ctx, AttributeSet::ReturnIndex, *DFSF.DFS.Ctx, AttributeSet::ReturnIndex,
AttributeFuncs::typeIncompatible(NewCS.getInstruction()->getType(), AttributeFuncs::typeIncompatible(NewCS.getInstruction()->getType())));
AttributeSet::ReturnIndex)));
if (Next) { if (Next) {
ExtractValueInst *ExVal = ExtractValueInst *ExVal =