summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHideto Ueno <uenoku.tokotoko@gmail.com>2019-08-22 14:18:29 +0000
committerHideto Ueno <uenoku.tokotoko@gmail.com>2019-08-22 14:18:29 +0000
commit70576cac521a3d6eb90db41fa2e60b4b55eec861 (patch)
treeb0b53cf60d88cf946c58e02723e514220f3987d4
parent00235e1b920e220d813db9b8037e88ed6d59d6f4 (diff)
downloadbcm5719-llvm-70576cac521a3d6eb90db41fa2e60b4b55eec861.tar.gz
bcm5719-llvm-70576cac521a3d6eb90db41fa2e60b4b55eec861.zip
[Attributor][NFC] Move DerefState to header and use StateWrapper
Summary: In D65402, I want to get DerefState from AADereferenceable but it was not allowed. This patch moves DerefState definition into Attributor.h and makes AADerefenceable inherit StateWrapper. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66585 llvm-svn: 369653
-rw-r--r--llvm/include/llvm/Transforms/IPO/Attributor.h95
-rw-r--r--llvm/lib/Transforms/IPO/Attributor.cpp97
2 files changed, 90 insertions, 102 deletions
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 4c95392c22a..5eba0372026 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1349,27 +1349,110 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute>,
static const char ID;
};
+/// State for dereferenceable attribute
+struct DerefState : AbstractState {
+
+ /// State representing for dereferenceable bytes.
+ IntegerState DerefBytesState;
+
+ /// State representing that whether the value is globaly dereferenceable.
+ BooleanState GlobalState;
+
+ /// See AbstractState::isValidState()
+ bool isValidState() const override { return DerefBytesState.isValidState(); }
+
+ /// See AbstractState::isAtFixpoint()
+ bool isAtFixpoint() const override {
+ return !isValidState() ||
+ (DerefBytesState.isAtFixpoint() && GlobalState.isAtFixpoint());
+ }
+
+ /// See AbstractState::indicateOptimisticFixpoint(...)
+ ChangeStatus indicateOptimisticFixpoint() override {
+ DerefBytesState.indicateOptimisticFixpoint();
+ GlobalState.indicateOptimisticFixpoint();
+ return ChangeStatus::UNCHANGED;
+ }
+
+ /// See AbstractState::indicatePessimisticFixpoint(...)
+ ChangeStatus indicatePessimisticFixpoint() override {
+ DerefBytesState.indicatePessimisticFixpoint();
+ GlobalState.indicatePessimisticFixpoint();
+ return ChangeStatus::CHANGED;
+ }
+
+ /// Update known dereferenceable bytes.
+ void takeKnownDerefBytesMaximum(uint64_t Bytes) {
+ DerefBytesState.takeKnownMaximum(Bytes);
+ }
+
+ /// Update assumed dereferenceable bytes.
+ void takeAssumedDerefBytesMinimum(uint64_t Bytes) {
+ DerefBytesState.takeAssumedMinimum(Bytes);
+ }
+
+ /// Equality for DerefState.
+ bool operator==(const DerefState &R) {
+ return this->DerefBytesState == R.DerefBytesState &&
+ this->GlobalState == R.GlobalState;
+ }
+
+ /// Inequality for IntegerState.
+ bool operator!=(const DerefState &R) { return !(*this == R); }
+
+ /// See IntegerState::operator^=
+ DerefState operator^=(const DerefState &R) {
+ DerefBytesState ^= R.DerefBytesState;
+ GlobalState ^= R.GlobalState;
+ return *this;
+ }
+
+ /// See IntegerState::operator&=
+ DerefState operator&=(const DerefState &R) {
+ DerefBytesState &= R.DerefBytesState;
+ GlobalState &= R.GlobalState;
+ return *this;
+ }
+
+ /// See IntegerState::operator|=
+ DerefState operator|=(const DerefState &R) {
+ DerefBytesState |= R.DerefBytesState;
+ GlobalState |= R.GlobalState;
+ return *this;
+ }
+
+protected:
+ const AANonNull *NonNullAA = nullptr;
+};
+
/// An abstract interface for all dereferenceable attribute.
struct AADereferenceable
- : public IRAttribute<Attribute::Dereferenceable, AbstractAttribute> {
+ : public IRAttribute<Attribute::Dereferenceable,
+ StateWrapper<DerefState, AbstractAttribute>> {
AADereferenceable(const IRPosition &IRP) : IRAttribute(IRP) {}
/// Return true if we assume that the underlying value is nonnull.
- virtual bool isAssumedNonNull() const = 0;
+ bool isAssumedNonNull() const {
+ return NonNullAA && NonNullAA->isAssumedNonNull();
+ }
/// Return true if we assume that underlying value is
/// dereferenceable(_or_null) globally.
- virtual bool isAssumedGlobal() const = 0;
+ bool isAssumedGlobal() const { return GlobalState.getAssumed(); }
/// Return true if we know that underlying value is
/// dereferenceable(_or_null) globally.
- virtual bool isKnownGlobal() const = 0;
+ bool isKnownGlobal() const { return GlobalState.getKnown(); }
/// Return assumed dereferenceable bytes.
- virtual uint32_t getAssumedDereferenceableBytes() const = 0;
+ uint32_t getAssumedDereferenceableBytes() const {
+ return DerefBytesState.getAssumed();
+ }
/// Return known dereferenceable bytes.
- virtual uint32_t getKnownDereferenceableBytes() const = 0;
+ uint32_t getKnownDereferenceableBytes() const {
+ return DerefBytesState.getKnown();
+ }
/// Create an abstract attribute view for the position \p IRP.
static AADereferenceable &createForPosition(const IRPosition &IRP,
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 6caa0275c7d..ede72d70185 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1890,78 +1890,6 @@ using AAIsDeadCallSite = AAIsDeadFunction;
/// -------------------- Dereferenceable Argument Attribute --------------------
-struct DerefState : AbstractState {
-
- /// State representing for dereferenceable bytes.
- IntegerState DerefBytesState;
-
- /// State representing that whether the value is globaly dereferenceable.
- BooleanState GlobalState;
-
- /// See AbstractState::isValidState()
- bool isValidState() const override { return DerefBytesState.isValidState(); }
-
- /// See AbstractState::isAtFixpoint()
- bool isAtFixpoint() const override {
- return !isValidState() ||
- (DerefBytesState.isAtFixpoint() && GlobalState.isAtFixpoint());
- }
-
- /// See AbstractState::indicateOptimisticFixpoint(...)
- ChangeStatus indicateOptimisticFixpoint() override {
- DerefBytesState.indicateOptimisticFixpoint();
- GlobalState.indicateOptimisticFixpoint();
- return ChangeStatus::UNCHANGED;
- }
-
- /// See AbstractState::indicatePessimisticFixpoint(...)
- ChangeStatus indicatePessimisticFixpoint() override {
- DerefBytesState.indicatePessimisticFixpoint();
- GlobalState.indicatePessimisticFixpoint();
- return ChangeStatus::CHANGED;
- }
-
- /// Update known dereferenceable bytes.
- void takeKnownDerefBytesMaximum(uint64_t Bytes) {
- DerefBytesState.takeKnownMaximum(Bytes);
- }
-
- /// Update assumed dereferenceable bytes.
- void takeAssumedDerefBytesMinimum(uint64_t Bytes) {
- DerefBytesState.takeAssumedMinimum(Bytes);
- }
-
- /// Equality for DerefState.
- bool operator==(const DerefState &R) {
- return this->DerefBytesState == R.DerefBytesState &&
- this->GlobalState == R.GlobalState;
- }
-
- /// Inequality for IntegerState.
- bool operator!=(const DerefState &R) { return !(*this == R); }
-
- /// See IntegerState::operator^=
- DerefState operator^=(const DerefState &R) {
- DerefBytesState ^= R.DerefBytesState;
- GlobalState ^= R.GlobalState;
- return *this;
- }
-
- /// See IntegerState::operator&=
- DerefState operator&=(const DerefState &R) {
- DerefBytesState &= R.DerefBytesState;
- GlobalState &= R.GlobalState;
- return *this;
- }
-
- /// See IntegerState::operator|=
- DerefState operator|=(const DerefState &R) {
- DerefBytesState |= R.DerefBytesState;
- GlobalState |= R.GlobalState;
- return *this;
- }
-};
-
template <>
ChangeStatus clampStateAndIndicateChange<DerefState>(DerefState &S,
const DerefState &R) {
@@ -1972,7 +1900,7 @@ ChangeStatus clampStateAndIndicateChange<DerefState>(DerefState &S,
return CS0 | CS1;
}
-struct AADereferenceableImpl : AADereferenceable, DerefState {
+struct AADereferenceableImpl : AADereferenceable {
AADereferenceableImpl(const IRPosition &IRP) : AADereferenceable(IRP) {}
using StateType = DerefState;
@@ -1992,26 +1920,6 @@ struct AADereferenceableImpl : AADereferenceable, DerefState {
const StateType &getState() const override { return *this; }
/// }
- /// See AADereferenceable::getAssumedDereferenceableBytes().
- uint32_t getAssumedDereferenceableBytes() const override {
- return DerefBytesState.getAssumed();
- }
-
- /// See AADereferenceable::getKnownDereferenceableBytes().
- uint32_t getKnownDereferenceableBytes() const override {
- return DerefBytesState.getKnown();
- }
-
- /// See AADereferenceable::isAssumedGlobal().
- bool isAssumedGlobal() const override { return GlobalState.getAssumed(); }
-
- /// See AADereferenceable::isKnownGlobal().
- bool isKnownGlobal() const override { return GlobalState.getKnown(); }
-
- bool isAssumedNonNull() const override {
- return NonNullAA && NonNullAA->isAssumedNonNull();
- }
-
void getDeducedAttributes(LLVMContext &Ctx,
SmallVectorImpl<Attribute> &Attrs) const override {
// TODO: Add *_globally support
@@ -2033,9 +1941,6 @@ struct AADereferenceableImpl : AADereferenceable, DerefState {
std::to_string(getKnownDereferenceableBytes()) + "-" +
std::to_string(getAssumedDereferenceableBytes()) + ">";
}
-
-private:
- const AANonNull *NonNullAA = nullptr;
};
/// Dereferenceable attribute for a floating value.
OpenPOWER on IntegriCloud