[flang-commits] [flang] [flang][Multi-Image] Moving Mutli-image lowering to PRIF into the MIF dialect (PR #161179)

via flang-commits flang-commits at lists.llvm.org
Mon Sep 29 07:34:21 PDT 2025


================
@@ -0,0 +1,274 @@
+//===-- MIFOps.td - MIF operation definitions ------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of the MIF dialect operations
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef FORTRAN_DIALECT_MIF_MIF_OPS
+#define FORTRAN_DIALECT_MIF_MIF_OPS
+
+include "flang/Optimizer/Dialect/MIF/MIFDialect.td"
+include "flang/Optimizer/Dialect/FIRTypes.td"
+include "flang/Optimizer/Dialect/FIRAttr.td"
+include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td"
+include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
+include "mlir/Interfaces/LoopLikeInterface.td"
+include "mlir/IR/BuiltinAttributes.td"
+
+class mif_Op<string mnemonic, list<Trait> traits>
+    : Op<MIFDialect, mnemonic, traits>;
+
+//===----------------------------------------------------------------------===//
+// Initialization and Finalization
+//===----------------------------------------------------------------------===//
+
+def mif_InitOp : mif_Op<"init", []> {
+  let summary = "Initialize the parallel environment";
+  let description = [{This operation will initialize the parallel environment}];
+
+  let results = (outs I32:$stat);
+  let assemblyFormat = "`->` type($stat) attr-dict";
+}
+
+//===----------------------------------------------------------------------===//
+// Image Queries
+//===----------------------------------------------------------------------===//
+
+def mif_NumImagesOp
+    : mif_Op<"num_images", [NoMemoryEffect, AttrSizedOperandSegments]> {
----------------
jeanPerier wrote:

I do not think it is accurate/correct to use `NoMemoryEffect` on most of MIF operations:
- When they have memory arguments, they most likely have read or write effects (`mif.num_images` will read its team arguments).
- Outside of the arguments, they manipulate (read/write) some program state not visible in the IR (the PRIF runtime).


Given them `NoMemoryEffect` could lead to weird bug where MLIR CSE would merge two mif.num_image where the team address argument is the same while the this type(team) address may have been reassigned a different team identifier between the two calls, leading to invalid code.

To start with, I think it is better to have MIF operations not implementing the side effect interface. We can think how to accurately describe their side effects (adding some MIF memory resource to abstract the read/writes to PRIF runtime) afterwards when doing opimizations.

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


More information about the flang-commits mailing list