[Mlir-commits] [mlir] 8a98c3e - [MLIR][Presburger] MaybeLocalRepr: add explicit bool() for convenience

Arjun P llvmlistbot at llvm.org
Sat Feb 5 06:03:07 PST 2022


Author: Arjun P
Date: 2022-02-05T19:33:01+05:30
New Revision: 8a98c3e07f63ac2e96ac9b46af603dca8be42e62

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

LOG: [MLIR][Presburger] MaybeLocalRepr: add explicit bool() for convenience

This also slightly simplifies some code.

Reviewed By: Groverkss

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

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/Utils.h
    mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h
index 8e57ac151d258..10a6fd771035a 100644
--- a/mlir/include/mlir/Analysis/Presburger/Utils.h
+++ b/mlir/include/mlir/Analysis/Presburger/Utils.h
@@ -31,6 +31,7 @@ enum class ReprKind { Inequality, Equality, None };
 /// and `upperBoundIdx` is set. By default the kind attribute is set to None.
 struct MaybeLocalRepr {
   ReprKind kind = ReprKind::None;
+  explicit operator bool() const { return kind != ReprKind::None; }
   union {
     unsigned equalityIdx;
     struct {

diff  --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
index c1c228b5c4992..2d65fd9d0fcd1 100644
--- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
@@ -872,9 +872,9 @@ void IntegerPolyhedron::getLocalReprs(
     changed = false;
     for (unsigned i = 0, e = getNumLocalIds(); i < e; ++i) {
       if (!foundRepr[i + divOffset]) {
-        auto res = computeSingleVarRepr(*this, foundRepr, divOffset + i,
-                                        dividends[i], denominators[i]);
-        if (res.kind == ReprKind::None)
+        MaybeLocalRepr res = computeSingleVarRepr(
+            *this, foundRepr, divOffset + i, dividends[i], denominators[i]);
+        if (!res)
           continue;
         foundRepr[i + divOffset] = true;
         repr[i] = res;
@@ -886,7 +886,7 @@ void IntegerPolyhedron::getLocalReprs(
   // Set 0 denominator for identifiers for which no division representation
   // could be found.
   for (unsigned i = 0, e = repr.size(); i < e; ++i)
-    if (repr[i].kind == ReprKind::None)
+    if (!repr[i])
       denominators[i] = 0;
 }
 


        


More information about the Mlir-commits mailing list