[flang] [llvm] [Flang] Adding lowering for the allocation and deallocation of coarrays (PR #182110)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 06:41:58 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:
Finalization is quite tricky, a single callback to a final routine is not enough to deal with cases where for instance a coarray is of a derived type that itself does not have final routines but contains components that are themselves derived types with different final routine (potentially elemental, requiring looping over the component elements).
Right now the flang runtime is visiting the derived type components in search for final routines (using the runtime type info, and the search is speed up with flags that indicate if there is no components with final routines).
How do you envision to deal with these situations?
https://github.com/llvm/llvm-project/pull/182110
More information about the llvm-commits
mailing list