diff --git a/include/llvm/Transforms/IPO/Attributor.h b/include/llvm/Transforms/IPO/Attributor.h index 1cc29cdb6d3..5d6c231a27b 100644 --- a/include/llvm/Transforms/IPO/Attributor.h +++ b/include/llvm/Transforms/IPO/Attributor.h @@ -411,22 +411,6 @@ struct IRPosition { SmallVectorImpl &Attrs, bool IgnoreSubsumingPositions = false) const; - /// Return the attribute of kind \p AK existing in the IR at this position. - Attribute getAttr(Attribute::AttrKind AK) const { - if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT) - return Attribute(); - - AttributeList AttrList; - if (ImmutableCallSite ICS = ImmutableCallSite(&getAnchorValue())) - AttrList = ICS.getAttributes(); - else - AttrList = getAssociatedFunction()->getAttributes(); - - if (AttrList.hasAttribute(getAttrIdx(), AK)) - return AttrList.getAttribute(getAttrIdx(), AK); - return Attribute(); - } - /// Remove the attribute of kind \p AKs existing in the IR at this position. void removeAttrs(ArrayRef AKs) const { if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT) @@ -481,6 +465,10 @@ private: /// Verify internal invariants. void verify(); + /// Return the attributes of kind \p AK existing in the IR as attribute. + bool getAttrsFromIRAttr(Attribute::AttrKind AK, + SmallVectorImpl &Attrs) const; + protected: /// The value this position is anchored at. Value *AnchorVal; diff --git a/lib/Transforms/IPO/Attributor.cpp b/lib/Transforms/IPO/Attributor.cpp index 2d82ba35b14..aeae4c08773 100644 --- a/lib/Transforms/IPO/Attributor.cpp +++ b/lib/Transforms/IPO/Attributor.cpp @@ -678,9 +678,10 @@ SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) { bool IRPosition::hasAttr(ArrayRef AKs, bool IgnoreSubsumingPositions) const { + SmallVector Attrs; for (const IRPosition &EquivIRP : SubsumingPositionIterator(*this)) { for (Attribute::AttrKind AK : AKs) - if (EquivIRP.getAttr(AK).getKindAsEnum() == AK) + if (EquivIRP.getAttrsFromIRAttr(AK, Attrs)) return true; // The first position returned by the SubsumingPositionIterator is // always the position itself. If we ignore subsuming positions we @@ -695,11 +696,8 @@ void IRPosition::getAttrs(ArrayRef AKs, SmallVectorImpl &Attrs, bool IgnoreSubsumingPositions) const { for (const IRPosition &EquivIRP : SubsumingPositionIterator(*this)) { - for (Attribute::AttrKind AK : AKs) { - const Attribute &Attr = EquivIRP.getAttr(AK); - if (Attr.getKindAsEnum() == AK) - Attrs.push_back(Attr); - } + for (Attribute::AttrKind AK : AKs) + EquivIRP.getAttrsFromIRAttr(AK, Attrs); // The first position returned by the SubsumingPositionIterator is // always the position itself. If we ignore subsuming positions we // are done after the first iteration. @@ -708,6 +706,24 @@ void IRPosition::getAttrs(ArrayRef AKs, } } +bool IRPosition::getAttrsFromIRAttr(Attribute::AttrKind AK, + SmallVectorImpl &Attrs) const { + if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT) + return false; + + AttributeList AttrList; + if (ImmutableCallSite ICS = ImmutableCallSite(&getAnchorValue())) + AttrList = ICS.getAttributes(); + else + AttrList = getAssociatedFunction()->getAttributes(); + + bool HasAttr = AttrList.hasAttribute(getAttrIdx(), AK); + if (HasAttr) + Attrs.push_back(AttrList.getAttribute(getAttrIdx(), AK)); + return HasAttr; +} + + void IRPosition::verify() { switch (KindOrArgNo) { default: