[llvm] r368925 - [Attributor][NFC] Add merge/join/clamp operators to the IntegerState

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 14:35:21 PDT 2019


Author: jdoerfert
Date: Wed Aug 14 14:35:20 2019
New Revision: 368925

URL: http://llvm.org/viewvc/llvm-project?rev=368925&view=rev
Log:
[Attributor][NFC] Add merge/join/clamp operators to the IntegerState

Differential Revision: https://reviews.llvm.org/D66146

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=368925&r1=368924&r2=368925&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/Attributor.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/Attributor.h Wed Aug 14 14:35:20 2019
@@ -887,6 +887,31 @@ struct IntegerState : public AbstractSta
            this->getKnown() == R.getKnown();
   }
 
+  /// Inequality for IntegerState.
+  bool operator!=(const IntegerState &R) const { return !(*this == R); }
+
+  /// "Clamp" this state with \p R. The result is the maximum of the known
+  /// information but the minimum of the assumed.
+  IntegerState operator^=(const IntegerState &R) {
+    takeKnownMaximum(R.Known);
+    takeAssumedMinimum(R.Assumed);
+    return *this;
+  }
+
+  /// Make this the minimum, known and assumed, of this state and \p R.
+  IntegerState operator&=(const IntegerState &R) {
+    Known = std::min(Known, R.Known);
+    Assumed = std::min(Assumed, R.Assumed);
+    return *this;
+  }
+
+  /// Make this the maximum, known and assumed, of this state and \p R.
+  IntegerState operator|=(const IntegerState &R) {
+    Known = std::max(Known, R.Known);
+    Assumed = std::max(Assumed, R.Assumed);
+    return *this;
+  }
+
 private:
   /// The known state encoding in an integer of type base_t.
   base_t Known = getWorstState();

Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=368925&r1=368924&r2=368925&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Wed Aug 14 14:35:20 2019
@@ -1650,6 +1650,30 @@ struct DerefState : AbstractState {
     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;
+  }
 };
 
 struct AADereferenceableImpl : AADereferenceable, DerefState {




More information about the llvm-commits mailing list