[Mlir-commits] [mlir] [MLIR] Support interrupting AffineExpr walks (PR #74792)

Uday Bondhugula llvmlistbot at llvm.org
Fri Dec 8 17:38:39 PST 2023


================
@@ -186,8 +215,19 @@ class AffineExprVisitor : public AffineExprVisitorBase<SubClass, RetTy> {
 private:
   // Walk the operands - each operand is itself walked in post order.
   RetTy walkOperandsPostOrder(AffineBinaryOpExpr expr) {
-    walkPostOrder(expr.getLHS());
-    walkPostOrder(expr.getRHS());
+    if constexpr (std::is_same<RetTy, WalkResult>::value) {
+      if (walkPostOrder(expr.getLHS()).wasInterrupted())
+        return WalkResult::interrupt();
+    } else {
+      walkPostOrder(expr.getLHS());
+    }
+    if constexpr (std::is_same<RetTy, WalkResult>::value) {
+      if (walkPostOrder(expr.getLHS()).wasInterrupted())
+        return WalkResult::interrupt();
+      return WalkResult::advance();
+    } else {
----------------
bondhugula wrote:

Nit: While the `else` can be removed, given the `constexpr` here, I felt it's better to keep it because you can't be having that `else` block (with or without a `return` for the `else` block statement) trailing for the case a WalkResult type is expected as the return type. So better to keep if/else with constexpr - otherwise you are getting something like this when `constexpr` is true:
```
....
if (...)
  ...
return WalkResult::advance();
walkPostOrder(...);
```

https://github.com/llvm/llvm-project/pull/74792


More information about the Mlir-commits mailing list