Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2924,6 +2924,29 @@ class OpenMPIRBuilder {
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.
Expand Down
27 changes: 27 additions & 0 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DL.getTypeAllocSize() would give the size with alignment and to be used here for correct size of allocation.

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,
Expand Down