================
@@ -2202,6 +2202,68 @@ def TargetFreeMemOp : OpenMP_Op<"target_freemem",
Arg<I64, "", [MemFree]>:$heapref
);
let assemblyFormat = "$device `,` $heapref attr-dict `:` type($device) `,`
qualified(type($heapref))";
+ let hasVerifier = 1;
+}
+
+//===----------------------------------------------------------------------===//
+// AllocSharedMemOp
+//===----------------------------------------------------------------------===//
+
+def AllocSharedMemOp : OpenMP_Op<"alloc_shared_mem", traits = [
+ AttrSizedOperandSegments
+ ], clauses = [
+ OpenMP_HeapAllocClause
+ ]> {
+ let summary = "allocate storage on shared memory for an object of a given
type";
+
+ let description = [{
+ Allocates memory shared across threads of a team for an object of the given
+ type. Returns a pointer representing the allocated memory. The memory is
+ uninitialized after allocation. Operations must be paired with
+ `omp.free_shared` to avoid memory leaks.
+
+ ```mlir
+ // Allocate a static 3x3 integer vector.
+ %ptr_shared = omp.alloc_shared_mem vector<3x3xi32> : !llvm.ptr
+ // ...
+ omp.free_shared_mem %ptr_shared : !llvm.ptr
+ ```
+ }] # clausesDescription;
+
+ let results = (outs OpenMP_PointerLikeType);
+ let assemblyFormat = clausesAssemblyFormat # " attr-dict `:` type(results)";
+}
+
+//===----------------------------------------------------------------------===//
+// FreeSharedMemOp
+//===----------------------------------------------------------------------===//
+
+def FreeSharedMemOp : OpenMP_Op<"free_shared_mem", [MemoryEffects<[MemFree]>]>
{
+ let summary = "free shared memory";
+
+ let description = [{
+ Deallocates shared memory that was previously allocated by an
+ `omp.alloc_shared_mem` operation. After this operation, the deallocated
+ memory is in an undefined state and should not be accessed.
+ It is crucial to ensure that all accesses to the memory region are
completed
+ before `omp.alloc_shared_mem` is called to avoid undefined behavior.
----------------
Meinersbur wrote:
```suggestion
before `omp.free_shared_mem` is called to avoid undefined behavior.
```
The concept of alloc/free might not need such detailed explanation
https://github.com/llvm/llvm-project/pull/161862
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits