[Mlir-commits] [flang] [mlir] [flang] Introduce omp.target_allocmem and omp.target_freemem omp dialect ops. (PR #145464)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 16 09:25:34 PDT 2025
================
@@ -1887,4 +1887,68 @@ def MaskedOp : OpenMP_Op<"masked", clauses = [
];
}
+//===----------------------------------------------------------------------===//
+// TargetAllocMemOp
+//===----------------------------------------------------------------------===//
+
+def TargetAllocMemOp : OpenMP_Op<"target_allocmem",
+ [MemoryEffects<[MemAlloc<DefaultResource>]>, AttrSizedOperandSegments]> {
+ let summary = "allocate storage on an openmp device for an object of a given type";
+
+ let description = [{
+ Allocates memory on the specified OpenMP device for an object of the given type.
+ Returns an integer value representing the device pointer to the allocated memory.
+ The memory is uninitialized after allocation. Operations must be paired with
+ `omp.target_freemem` to avoid memory leaks.
+
+ ```mlir
+ %device = arith.constant 0 : i32
+ %ptr = omp.target_allocmem %device : i32, vector<3x3xi32>
+ ```
+ }];
+
+ let arguments = (ins
+ Arg<AnyInteger>:$device,
+ TypeAttr:$in_type,
+ OptionalAttr<StrAttr>:$uniq_name,
+ OptionalAttr<StrAttr>:$bindc_name,
+ Variadic<IntLikeType>:$typeparams,
+ Variadic<IntLikeType>:$shape
----------------
skc7 wrote:
Reference for this op is fir.allocmem and when fir.allocmem is hoisted out of omp.target region, it will be replaced by omp.target_allocmem in the workdistribute lowering pass in #140523
Have used the similar arguments for this op like in fir.allocmem.
$shape is required as it provide the runtime extents of dynamic dimensions when allocating Fortran arrays.
Updated the description in the latest patch.
https://github.com/llvm/llvm-project/pull/145464
More information about the Mlir-commits
mailing list