[llvm-branch-commits] [flang] [flang] Lower loops whose branching is confined to their body structurally (PR #225758)

Tom Eccles via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Sep 24 03:18:25 PDT 2026


================
@@ -2642,6 +2647,97 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     return wrapOp;
   }
 
+  /// Wrap a loop's *body* -- not the construct, and not the loop control -- in
+  /// an scf.execute_region. A category (c) loop keeps its structured loop op
+  /// while its self-contained raw branching lives inside the region, which may
+  /// hold as many blocks as it needs.
+  ///
+  /// The builder must already be positioned inside the loop body. On return it
+  /// is inside the region. Returns null when the loop has no such internals.
+  mlir::scf::ExecuteRegionOp
+  wrapUnstructuredBody(Fortran::lower::pft::Evaluation &eval,
+                       mlir::Block *&yieldBlock,
+                       mlir::Block *&savedEndDoBlock) {
+    if (!eval.lowerBodyAsWrappedRegion())
----------------
tblah wrote:

nit: this should also check for `--wrap-unstructured-constructs-in-execute-region=false`

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


More information about the llvm-branch-commits mailing list