[llvm] aa5ebfd - [ValueLattice] Make mark* functions public, return if value changed.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 15 11:55:59 PST 2020


Author: Florian Hahn
Date: 2020-02-15T20:54:58+01:00
New Revision: aa5ebfdf205de6d599c1fed3161da3b63b6f0bef

URL: https://github.com/llvm/llvm-project/commit/aa5ebfdf205de6d599c1fed3161da3b63b6f0bef
DIFF: https://github.com/llvm/llvm-project/commit/aa5ebfdf205de6d599c1fed3161da3b63b6f0bef.diff

LOG: [ValueLattice] Make mark* functions public, return if value changed.

This patch prepares ValueLatticeElement to be used by SCCP, by:
* making the mark* functions public
* make the mark* functions return a bool indicating if the value has changed.

Reviewers: efriedma, davide, mssimpso, nikic

Reviewed By: nikic

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

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ValueLattice.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ValueLattice.h b/llvm/include/llvm/Analysis/ValueLattice.h
index ffe43adefba0..b3bf6b571aaa 100644
--- a/llvm/include/llvm/Analysis/ValueLattice.h
+++ b/llvm/include/llvm/Analysis/ValueLattice.h
@@ -140,6 +140,7 @@ class ValueLatticeElement {
   }
 
   bool isUndefined() const { return Tag == undefined; }
+  bool isUnknown() const { return Tag == undefined; }
   bool isConstant() const { return Tag == constant; }
   bool isNotConstant() const { return Tag == notconstant; }
   bool isConstantRange() const { return Tag == constantrange; }
@@ -170,71 +171,75 @@ class ValueLatticeElement {
     return None;
   }
 
-private:
-  void markOverdefined() {
+  bool markOverdefined() {
     if (isOverdefined())
-      return;
+      return false;
     if (isConstant() || isNotConstant())
       ConstVal = nullptr;
     if (isConstantRange())
       Range.~ConstantRange();
     Tag = overdefined;
+    return true;
   }
 
-  void markConstant(Constant *V) {
-    assert(V && "Marking constant with NULL");
-    if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
-      markConstantRange(ConstantRange(CI->getValue()));
-      return;
-    }
+  bool markConstant(Constant *V) {
     if (isa<UndefValue>(V))
-      return;
+      return false;
+
+    if (isConstant()) {
+      assert(getConstant() == V && "Marking constant with 
diff erent value");
+      return false;
+    }
+
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
+      return markConstantRange(ConstantRange(CI->getValue()));
 
-    assert((!isConstant() || getConstant() == V) &&
-           "Marking constant with 
diff erent value");
     assert(isUndefined());
     Tag = constant;
     ConstVal = V;
+    return true;
   }
 
-  void markNotConstant(Constant *V) {
+  bool markNotConstant(Constant *V) {
     assert(V && "Marking constant with NULL");
-    if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
-      markConstantRange(ConstantRange(CI->getValue() + 1, CI->getValue()));
-      return;
-    }
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
+      return markConstantRange(
+          ConstantRange(CI->getValue() + 1, CI->getValue()));
+
     if (isa<UndefValue>(V))
-      return;
+      return false;
 
-    assert((!isConstant() || getConstant() != V) &&
-           "Marking constant !constant with same value");
-    assert((!isNotConstant() || getNotConstant() == V) &&
-           "Marking !constant with 
diff erent value");
-    assert(isUndefined() || isConstant());
+    if (isNotConstant()) {
+      assert(getNotConstant() == V && "Marking !constant with 
diff erent value");
+      return false;
+    }
+
+    assert(isUndefined());
     Tag = notconstant;
     ConstVal = V;
+    return true;
   }
 
-  void markConstantRange(ConstantRange NewR) {
+  bool markConstantRange(ConstantRange NewR) {
     if (isConstantRange()) {
       if (NewR.isEmptySet())
         markOverdefined();
       else {
+        assert(NewR.contains(getConstantRange()) && "Existing range must be a subset of NewR");
         Range = std::move(NewR);
       }
-      return;
+      return true;
     }
 
     assert(isUndefined());
     if (NewR.isEmptySet())
-      markOverdefined();
-    else {
-      Tag = constantrange;
-      new (&Range) ConstantRange(std::move(NewR));
-    }
+      return markOverdefined();
+
+    Tag = constantrange;
+    new (&Range) ConstantRange(std::move(NewR));
+    return true;
   }
 
-public:
   /// Updates this object to approximate both this object and RHS. Returns
   /// true if this object has been changed.
   bool mergeIn(const ValueLatticeElement &RHS, const DataLayout &DL) {
@@ -273,12 +278,11 @@ class ValueLatticeElement {
     }
     ConstantRange NewR = getConstantRange().unionWith(RHS.getConstantRange());
     if (NewR.isFullSet())
-      markOverdefined();
+      return markOverdefined();
     else if (NewR == getConstantRange())
       return false;
     else
-      markConstantRange(std::move(NewR));
-    return true;
+      return markConstantRange(std::move(NewR));
   }
 
   /// Compares this symbolic value with Other using Pred and returns either


        


More information about the llvm-commits mailing list