[Mlir-commits] [mlir] [MLIR] Introduce support for early exits (PR #166688)

Matthias Springer llvmlistbot at llvm.org
Fri Jun 12 03:18:11 PDT 2026


================
@@ -61,4 +61,88 @@ def GraphRegionNoTerminator : TraitList<[
     HasOnlyGraphRegion
   ]>;
 
+// Indicates that this op may propagate a breaking control-flow event from a
+// nested region upward to the addressed HasBreakingControlFlowOpInterface
+// operation. The op does NOT consume the break itself; it is merely transparent
+// to it. All ops that sit between a breaking terminator and the
+// HasBreakingControlFlowOpInterface ancestor that will ultimately receive the
+// break must carry this trait.
+def PropagateControlFlowBreak : NativeOpTrait<"PropagateControlFlowBreak">;
+
+def HasBreakingControlFlowOpInterface : OpInterface<"HasBreakingControlFlowOpInterface"> {
+  let description = [{
+    Interface for operations that act as the target of a breaking control-flow
+    event (e.g. `scf.break` or `scf.continue`). Every intermediate op must
+    carry the `PropagateControlFlowBreak` trait. The terminator may identify the
+    receiver with any dialect-defined mechanism, such as a builtin token value,
+    an attribute, or a symbolic relationship to an enclosing operation.
+  }];
+  let cppNamespace = "::mlir";
+
+  let methods = [
+    StaticInterfaceMethod<
+      /*desc=*/[{
+        Return true if this operation accepts the given terminator operation
+        as a breaking-control-flow predecessor. Ops that also use
+        `HasNestedTerminator<[...]>` should delegate to the terminator list
+        check from that trait. Ops without `HasNestedTerminator` must provide
+        an explicit implementation (e.g. `return true;` to accept all, or a
+        type check to restrict).
+      }],
+      /*retTy=*/"bool",
+      /*methodName=*/"acceptsTerminator",
+      /*args=*/(ins "Operation *":$op)
+    >,
+    InterfaceMethod<
+      /*desc=*/[{
+        Return true if this operation has at least one breaking terminator
+        nested inside it that targets this operation directly. Used to decide
+        whether post-dominance analysis must account for early-exit paths.
+      }],
+      /*retTy=*/"bool",
+      /*methodName=*/"hasNestedPredecessors",
+      /*args=*/(ins),
+      /*methodBody=*/[{}],
+      /*defaultImplementation=*/[{
+        return ::mlir::hasNestedPredecessors(this->getOperation());
----------------
matthias-springer wrote:

Can we add a more efficient implementation for `scf.loop` that directly checks the users of the token or are we then loosing test coverage?


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


More information about the Mlir-commits mailing list