[flang-commits] [flang] [flang][MIF] Adding common features related to coarray (PR #215576)

Jean-Didier PAILLEUX via flang-commits flang-commits at lists.llvm.org
Wed Aug 12 00:53:33 PDT 2026


================
@@ -346,6 +346,66 @@ mlir::Value genTerminationOperationWrapper(fir::FirOpBuilder &builder,
   return fir::AddrOfOp::create(builder, loc, funcType, symbolRef);
 }
 
+// Generates the image index relative to the initial team, regardless of which
+// team is selected. Generates a call to the `prif_initial_team_index` function
+// (analogous to `prif_image_index`) if `cosubcripts` contains at least one
+// value; otherwise, it generates a call to `prif_this_image_no_coarray` without
+// the `team` argument.
+[[maybe_unused]] static mlir::Value
+getInitialTeamIndex(fir::FirOpBuilder &builder, mlir::Location loc,
+                    mlir::Value coarrayHandle,
+                    llvm::SmallVector<mlir::Value> cosubscripts) {
+  mlir::Type boxTy = fir::BoxType::get(builder.getNoneType());
+  mlir::Type i32Ty = builder.getI32Type();
+  mlir::Type i64Ty = builder.getI64Type();
+  mlir::Type boxArrTy = genBoxedSequenceType(i64Ty);
+  mlir::Value index = builder.createTemporary(loc, i32Ty);
+
+  // If there are no subscripts, the current image index is used.
+  if (cosubscripts.size() == 0) {
+    mlir::FunctionType ftype = mlir::FunctionType::get(
+        builder.getContext(),
+        /*inputs*/ {boxTy, builder.getRefType(i32Ty)}, /*results*/ {});
+    mlir::Value teamArg = fir::AbsentOp::create(builder, loc, boxTy);
+    mlir::func::FuncOp funcOp = builder.createFunction(
+        loc, getPRIFProcName("this_image_no_coarray"), ftype);
+    llvm::SmallVector<mlir::Value> args =
+        fir::runtime::createArguments(builder, loc, ftype, teamArg, index);
+    fir::CallOp::create(builder, loc, funcOp, args);
+    return index;
+  }
----------------
JDPailleux wrote:

Thanks for clarifying that and I admit I wasn't sure about `prif_this_image`. I'll take your comments into account and will probably go with option 2.

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


More information about the flang-commits mailing list