[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:22 PDT 2025


================
@@ -0,0 +1,133 @@
+//===- MIFOps.cpp - MIF dialect ops implementation ----------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Optimizer/Dialect/MIF/MIFOps.h"
+#include "flang/Optimizer/Dialect/FIRAttr.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/MIF/MIFDialect.h"
+#include "mlir/IR/Matchers.h"
+#include "mlir/IR/PatternMatch.h"
+#include "llvm/ADT/SmallVector.h"
+
+#define GET_OP_CLASSES
+#include "flang/Optimizer/Dialect/MIF/MIFOps.cpp.inc"
+
+//===----------------------------------------------------------------------===//
+// NumImagesOp
+//===----------------------------------------------------------------------===//
+
+void mif::NumImagesOp::build(mlir::OpBuilder &builder,
+                             mlir::OperationState &result,
+                             mlir::Value teamArg) {
+  bool isTeamNumber =
+      teamArg && fir::unwrapPassByRefType(teamArg.getType()).isInteger();
+  if (isTeamNumber)
+    build(builder, result, teamArg, /*team*/ mlir::Value{});
+  else
+    build(builder, result, /*team_number*/ mlir::Value{}, teamArg);
+}
+
+llvm::LogicalResult mif::NumImagesOp::verify() {
+  if (getTeam() && getTeamNumber())
+    return emitOpError(
+        "team and team_number must not be provided at the same time");
+  return mlir::success();
+}
+
+//===----------------------------------------------------------------------===//
+// ThisImageOp
+//===----------------------------------------------------------------------===//
+
+void mif::ThisImageOp::build(mlir::OpBuilder &builder,
+                             mlir::OperationState &result, mlir::Value coarray,
+                             mlir::Value team) {
+  build(builder, result, coarray, /*dim*/ mlir::Value{}, team);
+}
+
+void mif::ThisImageOp::build(mlir::OpBuilder &builder,
+                             mlir::OperationState &result, mlir::Value team) {
+  build(builder, result, /*coarray*/ mlir::Value{}, /*dim*/ mlir::Value{},
+        team);
+}
+
+llvm::LogicalResult mif::ThisImageOp::verify() {
+  if (getDim() && !getCoarray())
+    return emitOpError(
+        "`dim` must be provied at the same time as the `coarray` argument.");
+  return mlir::success();
+}
+
+//===----------------------------------------------------------------------===//
+// SyncImagesOp
+//===----------------------------------------------------------------------===//
+
+llvm::LogicalResult mif::SyncImagesOp::verify() {
+  if (getImageSet()) {
+    mlir::Type t = getImageSet().getType();
+    fir::BoxType boxTy = mlir::dyn_cast<fir::BoxType>(t);
+    if (auto seqTy =
+            mlir::dyn_cast<fir::SequenceType>(boxTy.getElementType())) {
----------------
jeanPerier wrote:

Use `fir::unwrapRefType(boxTy.getElementType())` here instead of `boxTy.getElementType()`.

fir.box element type may contain fir.ptr/heap indirection to indicate that the box is for the target of a POINTER/ALLOCATABLE.

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


More information about the flang-commits mailing list