Skip to content

Commit 9ba91fe

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 e3a67f6 commit 9ba91fe

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

2927+
/// Create a runtime call for kmpc_alloc_shared.
2928+
///
2929+
/// \param Loc The insert and source location description.
2930+
/// \param VarType Type of variable to be allocated.
2931+
/// \param Name Name of call Instruction.
2932+
///
2933+
/// \returns CallInst to the kmpc_alloc_shared call.
2934+
LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
2935+
Type *VarType,
2936+
const Twine &Name = Twine(""));
2937+
2938+
/// Create a runtime call for kmpc_free_shared.
2939+
///
2940+
/// \param Loc The insert and source location description.
2941+
/// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
2942+
/// \param VarType Type of variable to be freed.
2943+
/// \param Name Name of call Instruction.
2944+
///
2945+
/// \returns CallInst to the kmpc_free_shared call.
2946+
LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
2947+
Value *Addr, Type *VarType,
2948+
const Twine &Name = Twine(""));
2949+
29272950
/// Create a runtime call for kmpc_threadprivate_cached
29282951
///
29292952
/// \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
@@ -6657,6 +6657,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc,
66576657
return Builder.CreateCall(Fn, Args, Name);
66586658
}
66596659

6660+
CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
6661+
Type *VarType,
6662+
const Twine &Name) {
6663+
IRBuilder<>::InsertPointGuard IPG(Builder);
6664+
updateToLocation(Loc);
6665+
6666+
const DataLayout &DL = M.getDataLayout();
6667+
Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
6668+
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
6669+
CallInst *Call = Builder.CreateCall(Fn, Args, Name);
6670+
Call->addRetAttr(
6671+
Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
6672+
return Call;
6673+
}
6674+
6675+
CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
6676+
Value *Addr, Type *VarType,
6677+
const Twine &Name) {
6678+
IRBuilder<>::InsertPointGuard IPG(Builder);
6679+
updateToLocation(Loc);
6680+
6681+
Value *Args[] = {
6682+
Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
6683+
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
6684+
return Builder.CreateCall(Fn, Args, Name);
6685+
}
6686+
66606687
CallInst *OpenMPIRBuilder::createOMPInteropInit(
66616688
const LocationDescription &Loc, Value *InteropVar,
66626689
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,

0 commit comments

Comments
 (0)