Skip to content

Commit f27aedb

Browse files
committed
[OpenMP][OMPIRBuilder] Add device shared memory allocation support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL functions to the list of those the OMPIRBuilder is able to create.
1 parent aa494bd commit f27aedb

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,29 @@ class OpenMPIRBuilder {
27772777
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
27782778
Value *Allocator, std::string Name = "");
27792779

2780+
/// Create a runtime call for kmpc_alloc_shared.
2781+
///
2782+
/// \param Loc The insert and source location description.
2783+
/// \param VarType Type of variable to be allocated.
2784+
/// \param Name Name of call Instruction.
2785+
///
2786+
/// \returns CallInst to the kmpc_alloc_shared call.
2787+
LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
2788+
Type *VarType,
2789+
const Twine &Name = Twine(""));
2790+
2791+
/// Create a runtime call for kmpc_free_shared.
2792+
///
2793+
/// \param Loc The insert and source location description.
2794+
/// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
2795+
/// \param VarType Type of variable to be freed.
2796+
/// \param Name Name of call Instruction.
2797+
///
2798+
/// \returns CallInst to the kmpc_free_shared call.
2799+
LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
2800+
Value *Addr, Type *VarType,
2801+
const Twine &Name = Twine(""));
2802+
27802803
/// Create a runtime call for kmpc_threadprivate_cached
27812804
///
27822805
/// \param Loc The insert and source location description.

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc,
62136213
return Builder.CreateCall(Fn, Args, Name);
62146214
}
62156215

6216+
CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
6217+
Type *VarType,
6218+
const Twine &Name) {
6219+
IRBuilder<>::InsertPointGuard IPG(Builder);
6220+
updateToLocation(Loc);
6221+
6222+
const DataLayout &DL = M.getDataLayout();
6223+
Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
6224+
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
6225+
CallInst *Call = Builder.CreateCall(Fn, Args, Name);
6226+
Call->addRetAttr(
6227+
Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
6228+
return Call;
6229+
}
6230+
6231+
CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
6232+
Value *Addr, Type *VarType,
6233+
const Twine &Name) {
6234+
IRBuilder<>::InsertPointGuard IPG(Builder);
6235+
updateToLocation(Loc);
6236+
6237+
Value *Args[] = {
6238+
Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
6239+
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
6240+
return Builder.CreateCall(Fn, Args, Name);
6241+
}
6242+
62166243
CallInst *OpenMPIRBuilder::createOMPInteropInit(
62176244
const LocationDescription &Loc, Value *InteropVar,
62186245
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,

0 commit comments

Comments
 (0)