Skip to content

Commit 9493624

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 9e948a5 commit 9493624

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
@@ -2907,6 +2907,29 @@ class OpenMPIRBuilder {
29072907
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
29082908
Value *Allocator, std::string Name = "");
29092909

2910+
/// Create a runtime call for kmpc_alloc_shared.
2911+
///
2912+
/// \param Loc The insert and source location description.
2913+
/// \param VarType Type of variable to be allocated.
2914+
/// \param Name Name of call Instruction.
2915+
///
2916+
/// \returns CallInst to the kmpc_alloc_shared call.
2917+
LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
2918+
Type *VarType,
2919+
const Twine &Name = Twine(""));
2920+
2921+
/// Create a runtime call for kmpc_free_shared.
2922+
///
2923+
/// \param Loc The insert and source location description.
2924+
/// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
2925+
/// \param VarType Type of variable to be freed.
2926+
/// \param Name Name of call Instruction.
2927+
///
2928+
/// \returns CallInst to the kmpc_free_shared call.
2929+
LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
2930+
Value *Addr, Type *VarType,
2931+
const Twine &Name = Twine(""));
2932+
29102933
/// Create a runtime call for kmpc_threadprivate_cached
29112934
///
29122935
/// \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
@@ -6631,6 +6631,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc,
66316631
return Builder.CreateCall(Fn, Args, Name);
66326632
}
66336633

6634+
CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
6635+
Type *VarType,
6636+
const Twine &Name) {
6637+
IRBuilder<>::InsertPointGuard IPG(Builder);
6638+
updateToLocation(Loc);
6639+
6640+
const DataLayout &DL = M.getDataLayout();
6641+
Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
6642+
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
6643+
CallInst *Call = Builder.CreateCall(Fn, Args, Name);
6644+
Call->addRetAttr(
6645+
Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
6646+
return Call;
6647+
}
6648+
6649+
CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
6650+
Value *Addr, Type *VarType,
6651+
const Twine &Name) {
6652+
IRBuilder<>::InsertPointGuard IPG(Builder);
6653+
updateToLocation(Loc);
6654+
6655+
Value *Args[] = {
6656+
Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
6657+
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
6658+
return Builder.CreateCall(Fn, Args, Name);
6659+
}
6660+
66346661
CallInst *OpenMPIRBuilder::createOMPInteropInit(
66356662
const LocationDescription &Loc, Value *InteropVar,
66366663
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,

0 commit comments

Comments
 (0)