[llvm] 6185fb1 - [Attributor][NFC] Refactor interface
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 20 00:52:55 PST 2020
Author: Johannes Doerfert
Date: 2020-02-20T02:46:40-06:00
New Revision: 6185fb13d6410ef64dd98d40d11d1edb8c712908
URL: https://github.com/llvm/llvm-project/commit/6185fb13d6410ef64dd98d40d11d1edb8c712908
DIFF: https://github.com/llvm/llvm-project/commit/6185fb13d6410ef64dd98d40d11d1edb8c712908.diff
LOG: [Attributor][NFC] Refactor interface
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 1cc29cdb6d31..5d6c231a27bb 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -411,22 +411,6 @@ struct IRPosition {
SmallVectorImpl<Attribute> &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<Attribute::AttrKind> AKs) const {
if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT)
@@ -481,6 +465,10 @@ struct IRPosition {
/// Verify internal invariants.
void verify();
+ /// Return the attributes of kind \p AK existing in the IR as attribute.
+ bool getAttrsFromIRAttr(Attribute::AttrKind AK,
+ SmallVectorImpl<Attribute> &Attrs) const;
+
protected:
/// The value this position is anchored at.
Value *AnchorVal;
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 2d82ba35b147..aeae4c08773f 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -678,9 +678,10 @@ SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) {
bool IRPosition::hasAttr(ArrayRef<Attribute::AttrKind> AKs,
bool IgnoreSubsumingPositions) const {
+ SmallVector<Attribute, 4> 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<Attribute::AttrKind> AKs,
SmallVectorImpl<Attribute> &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<Attribute::AttrKind> AKs,
}
}
+bool IRPosition::getAttrsFromIRAttr(Attribute::AttrKind AK,
+ SmallVectorImpl<Attribute> &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:
More information about the llvm-commits
mailing list