[llvm] r369653 - [Attributor][NFC] Move DerefState to header and use StateWrapper
Hideto Ueno via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 07:18:29 PDT 2019
Author: uenoku
Date: Thu Aug 22 07:18:29 2019
New Revision: 369653
URL: http://llvm.org/viewvc/llvm-project?rev=369653&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
llvm/trunk/lib/Transforms/IPO/Attributor.cpp
Modified: llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/Attributor.h?rev=369653&r1=369652&r2=369653&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/Attributor.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/Attributor.h Thu Aug 22 07:18:29 2019
@@ -1349,27 +1349,110 @@ struct AAIsDead : public StateWrapper<Bo
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,
Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=369653&r1=369652&r2=369653&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Thu Aug 22 07:18:29 2019
@@ -1890,78 +1890,6 @@ using AAIsDeadCallSite = AAIsDeadFunctio
/// -------------------- 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
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 : AADerefer
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 : AADerefer
std::to_string(getKnownDereferenceableBytes()) + "-" +
std::to_string(getAssumedDereferenceableBytes()) + ">";
}
-
-private:
- const AANonNull *NonNullAA = nullptr;
};
/// Dereferenceable attribute for a floating value.
More information about the llvm-commits
mailing list