[flang] [llvm] [Flang] Adding lowering for the allocation and deallocation of coarrays (PR #182110)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 06:36:38 PST 2026


================
@@ -425,4 +426,59 @@ def mif_TeamNumberOp : mif_Op<"team_number", []> {
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// Allocation and Deallocation
+//===----------------------------------------------------------------------===//
+
+def mif_AllocCoarrayOp
+    : mif_Op<"alloc_coarray", [AttrSizedOperandSegments,
+                               MemoryEffects<[MemAlloc<DefaultResource>]>]> {
+  let summary = "Perform the allocation of a coarray and provide a "
+                "corresponding coarray descriptor";
+
+  let description = [{
+    This operation allocates a coarray and provides the corresponding 
+    coarray descriptor. This call is collective over the current team.
+  }];
+
+  let arguments = (ins StrAttr:$uniq_name,
+      Arg<fir_ReferenceType, "", [MemRead, MemWrite]>:$box,
+      DenseI64ArrayAttr:$lcobounds, DenseI64ArrayAttr:$ucobounds,
+      Arg<Optional<AnyReferenceLike>, "", [MemWrite]>:$stat,
+      Arg<Optional<AnyRefOrBoxType>, "", [MemWrite]>:$errmsg);
+
+  let builders = [OpBuilder<(ins "mlir::Value":$box, "llvm::StringRef":$symName,
+                      "mlir::DenseI64ArrayAttr":$lcobounds,
+                      "mlir::DenseI64ArrayAttr":$ucobounds, "mlir::Value":$stat,
+                      "mlir::Value":$errmsg)>,
+                  OpBuilder<(ins "mlir::Value":$box, "llvm::StringRef":$symName,
+                      "mlir::DenseI64ArrayAttr":$lcobounds,
+                      "mlir::DenseI64ArrayAttr":$ucobounds)>];
+
+  let hasVerifier = 1;
+  let assemblyFormat = [{
+    $box 
+    (`stat` $stat^ )?
+    (`errmsg` $errmsg^ )? 
+    attr-dict `:` functional-type(operands, results)
+  }];
+}
+
+def mif_DeallocCoarrayOp
+    : mif_Op<"dealloc_coarray", [AttrSizedOperandSegments,
+                                 MemoryEffects<[MemFree<DefaultResource>]>]> {
+  let summary = "Perform the deallocation of a coarray";
+  let description = [{
+    This call releases memory allocated by `mif_AllocCoarrayOp` for a coarray.
----------------
jeanPerier wrote:

Is it also in charge of finalization of derived type (and nested allocatable component deallocation) if needed?

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


More information about the llvm-commits mailing list