[flang-commits] [flang] [llvm] [flang][MIF] Adding lowering for EVENT POST/WAIT statements (PR #210283)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 16 15:58:11 PDT 2026


================
@@ -520,3 +520,99 @@ fir::ExtendedValue Fortran::lower::CoarrayExprHelper::genValue(
     const Fortran::evaluate::CoarrayRef &expr) {
   TODO(converter.getCurrentLocation(), "coarray: coarray value");
 }
+
+//===----------------------------------------------------------------------===//
+// EVENT and NOTIFY statements
+//===----------------------------------------------------------------------===//
+
+void Fortran::lower::genNotifyWaitStatement(
+    Fortran::lower::AbstractConverter &converter,
+    const Fortran::parser::NotifyWaitStmt &) {
+  TODO(converter.getCurrentLocation(), "coarray: NOTIFY WAIT runtime");
+}
+
+void Fortran::lower::genEventPostStatement(
+    Fortran::lower::AbstractConverter &converter,
+    const Fortran::parser::EventPostStmt &stmt) {
+  converter.checkCoarrayEnabled();
+  mlir::Location loc = converter.getCurrentLocation();
+  fir::FirOpBuilder &builder = converter.getFirOpBuilder();
+  Fortran::lower::StatementContext stmtCtx;
+
+  // Handle STAT and ERRMSG values
+  const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList =
+      std::get<std::list<Fortran::parser::StatOrErrmsg>>(stmt.t);
+  auto [statAddr, errMsgAddr] = converter.genStatAndErrmsg(loc, statOrErrList);
+
+  // Handle EVENT-VAR and IMAGE_NUMBER
+  auto eventExpr = Fortran::semantics::GetExpr(
+      std::get<Fortran::parser::EventVariable>(stmt.t));
+  mlir::Value event = fir::getBase(
+      converter.genExprBox(loc, *eventExpr, stmtCtx, /*allowCoarray=*/true));
----------------
MattPD wrote:

Thanks for the tests! `Lower/MIF/events2.f90` covers the EVENT POST lowering.

`Fir/MIF/events3.mlir` doesn't reach the new branch in `convertRefTypeToCPtrType`, though. Its input is already converted IR with no `mif` op, so `--mif-convert` leaves the function unchanged. The test passes on a build without the fix.

Could a test like this one replace `events3.mlir`? This one passes with this PR and fails on a build without the fix:

```mlir
// RUN: fir-opt --mif-convert %s | FileCheck %s

func.func @class_wait(%arg0: !fir.class<!fir.heap<!fir.type<event>>, corank:1>) {
  mif.event_wait %arg0 : (!fir.class<!fir.heap<!fir.type<event>>, corank:1>) -> ()
  return
}

// CHECK-LABEL: func.func @class_wait(
// CHECK-SAME:    %[[EVENT:.*]]: !fir.class<!fir.heap<!fir.type<event>>, corank:1>)
// CHECK:         %[[CPTR:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
// CHECK:         %[[ADDR:.*]] = fir.box_addr %[[EVENT]] : (!fir.class<!fir.heap<!fir.type<event>>, corank:1>) -> !fir.heap<!fir.type<event>>
// CHECK:         %[[INT:.*]] = fir.convert %[[ADDR]] : (!fir.heap<!fir.type<event>>) -> i64
// CHECK:         %[[FIELD:.*]] = fir.coordinate_of %[[CPTR]], __address
// CHECK:         fir.store %[[INT]] to %[[FIELD]] : !fir.ref<i64>
// CHECK:         fir.call @_QMprifPprif_event_wait(%[[CPTR]],
```

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


More information about the flang-commits mailing list