summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Afonso <safonsof@amd.com>2025-07-08 12:27:08 +0100
committerSergio Afonso <safonsof@amd.com>2025-10-03 11:33:55 +0100
commit9ba91fe91269b5771dfa94114e2606b29d79e2f1 (patch)
treeb913cf27d0628d19baf9002ad69f66481105234d
parente3a67f629ee53dcb0ab5dbbe60dc480474c05670 (diff)
[OpenMP][OMPIRBuilder] Add device shared memory allocation supportusers/skatrak/flang-generic-02-ompirbuilder-shared-mem
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL functions to the list of those the OMPIRBuilder is able to create.
-rw-r--r--llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h23
-rw-r--r--llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp27
2 files changed, 50 insertions, 0 deletions
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 0a11617ea971..6a657724dc61 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2924,6 +2924,29 @@ public:
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index fb501983ca93..ab2a059e423c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6657,6 +6657,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc,
return Builder.CreateCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,