Skip to content

Commit 1fcfe48

Browse files
committed
[OMPIRBuilder] Introduce struct to hold default kernel teams/threads
This patch introduces the `OpenMPIRBuilder::TargetKernelDefaultAttrs` structure used to simplify passing default and constant values for number of teams and threads, and possibly other target kernel-related information in the future. This is used to forward values passed to `createTarget` to `createTargetInit`, which previously used a default unrelated set of values.
1 parent 26fbb25 commit 1fcfe48

File tree

8 files changed

+102
-81
lines changed

8 files changed

+102
-81
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5880,10 +5880,13 @@ void CGOpenMPRuntime::emitUsesAllocatorsFini(CodeGenFunction &CGF,
58805880

58815881
void CGOpenMPRuntime::computeMinAndMaxThreadsAndTeams(
58825882
const OMPExecutableDirective &D, CodeGenFunction &CGF,
5883-
int32_t &MinThreadsVal, int32_t &MaxThreadsVal, int32_t &MinTeamsVal,
5884-
int32_t &MaxTeamsVal) {
5883+
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs) {
5884+
assert(Attrs.MaxTeams.size() == 1 && Attrs.MaxThreads.size() == 1 &&
5885+
"invalid default attrs structure");
5886+
int32_t &MaxTeamsVal = Attrs.MaxTeams.front();
5887+
int32_t &MaxThreadsVal = Attrs.MaxThreads.front();
58855888

5886-
getNumTeamsExprForTargetDirective(CGF, D, MinTeamsVal, MaxTeamsVal);
5889+
getNumTeamsExprForTargetDirective(CGF, D, Attrs.MinTeams, MaxTeamsVal);
58875890
getNumThreadsExprForTargetDirective(CGF, D, MaxThreadsVal,
58885891
/*UpperBoundOnly=*/true);
58895892

@@ -5901,12 +5904,12 @@ void CGOpenMPRuntime::computeMinAndMaxThreadsAndTeams(
59015904
else
59025905
continue;
59035906

5904-
MinThreadsVal = std::max(MinThreadsVal, AttrMinThreadsVal);
5907+
Attrs.MinThreads = std::max(Attrs.MinThreads, AttrMinThreadsVal);
59055908
if (AttrMaxThreadsVal > 0)
59065909
MaxThreadsVal = MaxThreadsVal > 0
59075910
? std::min(MaxThreadsVal, AttrMaxThreadsVal)
59085911
: AttrMaxThreadsVal;
5909-
MinTeamsVal = std::max(MinTeamsVal, AttrMinBlocksVal);
5912+
Attrs.MinTeams = std::max(Attrs.MinTeams, AttrMinBlocksVal);
59105913
if (AttrMaxBlocksVal > 0)
59115914
MaxTeamsVal = MaxTeamsVal > 0 ? std::min(MaxTeamsVal, AttrMaxBlocksVal)
59125915
: AttrMaxBlocksVal;

clang/lib/CodeGen/CGOpenMPRuntime.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,9 @@ class CGOpenMPRuntime {
312312
llvm::OpenMPIRBuilder OMPBuilder;
313313

314314
/// Helper to determine the min/max number of threads/teams for \p D.
315-
void computeMinAndMaxThreadsAndTeams(const OMPExecutableDirective &D,
316-
CodeGenFunction &CGF,
317-
int32_t &MinThreadsVal,
318-
int32_t &MaxThreadsVal,
319-
int32_t &MinTeamsVal,
320-
int32_t &MaxTeamsVal);
315+
void computeMinAndMaxThreadsAndTeams(
316+
const OMPExecutableDirective &D, CodeGenFunction &CGF,
317+
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
321318

322319
/// Helper to emit outlined function for 'target' directive.
323320
/// \param D Directive to emit.

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,11 @@ void CGOpenMPRuntimeGPU::emitNonSPMDKernel(const OMPExecutableDirective &D,
745745
void CGOpenMPRuntimeGPU::emitKernelInit(const OMPExecutableDirective &D,
746746
CodeGenFunction &CGF,
747747
EntryFunctionState &EST, bool IsSPMD) {
748-
int32_t MinThreadsVal = 1, MaxThreadsVal = -1, MinTeamsVal = 1,
749-
MaxTeamsVal = -1;
750-
computeMinAndMaxThreadsAndTeams(D, CGF, MinThreadsVal, MaxThreadsVal,
751-
MinTeamsVal, MaxTeamsVal);
748+
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs Attrs;
749+
computeMinAndMaxThreadsAndTeams(D, CGF, Attrs);
752750

753751
CGBuilderTy &Bld = CGF.Builder;
754-
Bld.restoreIP(OMPBuilder.createTargetInit(
755-
Bld, IsSPMD, MinThreadsVal, MaxThreadsVal, MinTeamsVal, MaxTeamsVal));
752+
Bld.restoreIP(OMPBuilder.createTargetInit(Bld, IsSPMD, Attrs));
756753
if (!IsSPMD)
757754
emitGenericVarsProlog(CGF, EST.Loc);
758755
}

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,20 @@ class OpenMPIRBuilder {
22232223
MapNamesArray(MapNamesArray) {}
22242224
};
22252225

2226+
/// Container to pass the default attributes with which a kernel must be
2227+
/// launched, used to set kernel attributes and populate associated static
2228+
/// structures.
2229+
///
2230+
/// For max values, < 0 means unset, == 0 means set but unknown at compile
2231+
/// time. The number of max values will be 1 except for the case where
2232+
/// ompx_bare is set.
2233+
struct TargetKernelDefaultAttrs {
2234+
SmallVector<int32_t, 3> MaxTeams = {-1};
2235+
int32_t MinTeams = 1;
2236+
SmallVector<int32_t, 3> MaxThreads = {-1};
2237+
int32_t MinThreads = 1;
2238+
};
2239+
22262240
/// Data structure that contains the needed information to construct the
22272241
/// kernel args vector.
22282242
struct TargetKernelArgs {
@@ -2726,15 +2740,11 @@ class OpenMPIRBuilder {
27262740
///
27272741
/// \param Loc The insert and source location description.
27282742
/// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
2729-
/// \param MinThreads Minimal number of threads, or 0.
2730-
/// \param MaxThreads Maximal number of threads, or 0.
2731-
/// \param MinTeams Minimal number of teams, or 0.
2732-
/// \param MaxTeams Maximal number of teams, or 0.
2733-
InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD,
2734-
int32_t MinThreadsVal = 0,
2735-
int32_t MaxThreadsVal = 0,
2736-
int32_t MinTeamsVal = 0,
2737-
int32_t MaxTeamsVal = 0);
2743+
/// \param Attrs Structure containing the default numbers of threads and teams
2744+
/// to launch the kernel with.
2745+
InsertPointTy createTargetInit(
2746+
const LocationDescription &Loc, bool IsSPMD,
2747+
const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
27382748

27392749
/// Create a runtime call for kmpc_target_deinit
27402750
///
@@ -2898,8 +2908,8 @@ class OpenMPIRBuilder {
28982908
/// \param CodeGenIP The insertion point where the call to the outlined
28992909
/// function should be emitted.
29002910
/// \param EntryInfo The entry information about the function.
2901-
/// \param NumTeams Number of teams specified in the num_teams clause.
2902-
/// \param NumThreads Number of teams specified in the thread_limit clause.
2911+
/// \param DefaultAttrs Structure containing the default numbers of threads
2912+
/// and teams to launch the kernel with.
29032913
/// \param Inputs The input values to the region that will be passed.
29042914
/// as arguments to the outlined function.
29052915
/// \param BodyGenCB Callback that will generate the region code.
@@ -2912,9 +2922,10 @@ class OpenMPIRBuilder {
29122922
const LocationDescription &Loc, bool IsOffloadEntry,
29132923
OpenMPIRBuilder::InsertPointTy AllocaIP,
29142924
OpenMPIRBuilder::InsertPointTy CodeGenIP,
2915-
TargetRegionEntryInfo &EntryInfo, ArrayRef<int32_t> NumTeams,
2916-
ArrayRef<int32_t> NumThreads, SmallVectorImpl<Value *> &Inputs,
2917-
GenMapInfoCallbackTy GenMapInfoCB, TargetBodyGenCallbackTy BodyGenCB,
2925+
TargetRegionEntryInfo &EntryInfo,
2926+
const TargetKernelDefaultAttrs &DefaultAttrs,
2927+
SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
2928+
TargetBodyGenCallbackTy BodyGenCB,
29182929
TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
29192930
SmallVector<DependData> Dependencies = {}, bool HasNowait = false);
29202931

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6109,10 +6109,12 @@ CallInst *OpenMPIRBuilder::createCachedThreadPrivate(
61096109
return Builder.CreateCall(Fn, Args);
61106110
}
61116111

6112-
OpenMPIRBuilder::InsertPointTy
6113-
OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD,
6114-
int32_t MinThreadsVal, int32_t MaxThreadsVal,
6115-
int32_t MinTeamsVal, int32_t MaxTeamsVal) {
6112+
OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
6113+
const LocationDescription &Loc, bool IsSPMD,
6114+
const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs) {
6115+
assert(!Attrs.MaxThreads.empty() && !Attrs.MaxTeams.empty() &&
6116+
"expected num_threads and num_teams to be specified");
6117+
61166118
if (!updateToLocation(Loc))
61176119
return Loc.IP;
61186120

@@ -6139,21 +6141,23 @@ OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD,
61396141

61406142
// Manifest the launch configuration in the metadata matching the kernel
61416143
// environment.
6142-
if (MinTeamsVal > 1 || MaxTeamsVal > 0)
6143-
writeTeamsForKernel(T, *Kernel, MinTeamsVal, MaxTeamsVal);
6144+
if (Attrs.MinTeams > 1 || Attrs.MaxTeams.front() > 0)
6145+
writeTeamsForKernel(T, *Kernel, Attrs.MinTeams, Attrs.MaxTeams.front());
61446146

6145-
// For max values, < 0 means unset, == 0 means set but unknown.
6147+
// If MaxThreads not set, select the maximum between the default workgroup
6148+
// size and the MinThreads value.
6149+
int32_t MaxThreadsVal = Attrs.MaxThreads.front();
61466150
if (MaxThreadsVal < 0)
61476151
MaxThreadsVal = std::max(
6148-
int32_t(getGridValue(T, Kernel).GV_Default_WG_Size), MinThreadsVal);
6152+
int32_t(getGridValue(T, Kernel).GV_Default_WG_Size), Attrs.MinThreads);
61496153

61506154
if (MaxThreadsVal > 0)
6151-
writeThreadBoundsForKernel(T, *Kernel, MinThreadsVal, MaxThreadsVal);
6155+
writeThreadBoundsForKernel(T, *Kernel, Attrs.MinThreads, MaxThreadsVal);
61526156

6153-
Constant *MinThreads = ConstantInt::getSigned(Int32, MinThreadsVal);
6157+
Constant *MinThreads = ConstantInt::getSigned(Int32, Attrs.MinThreads);
61546158
Constant *MaxThreads = ConstantInt::getSigned(Int32, MaxThreadsVal);
6155-
Constant *MinTeams = ConstantInt::getSigned(Int32, MinTeamsVal);
6156-
Constant *MaxTeams = ConstantInt::getSigned(Int32, MaxTeamsVal);
6159+
Constant *MinTeams = ConstantInt::getSigned(Int32, Attrs.MinTeams);
6160+
Constant *MaxTeams = ConstantInt::getSigned(Int32, Attrs.MaxTeams.front());
61576161
Constant *ReductionDataSize = ConstantInt::getSigned(Int32, 0);
61586162
Constant *ReductionBufferLength = ConstantInt::getSigned(Int32, 0);
61596163

@@ -6724,8 +6728,9 @@ FunctionCallee OpenMPIRBuilder::createDispatchDeinitFunction() {
67246728
}
67256729

67266730
static Expected<Function *> createOutlinedFunction(
6727-
OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, StringRef FuncName,
6728-
SmallVectorImpl<Value *> &Inputs,
6731+
OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
6732+
const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs,
6733+
StringRef FuncName, SmallVectorImpl<Value *> &Inputs,
67296734
OpenMPIRBuilder::TargetBodyGenCallbackTy &CBFunc,
67306735
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy &ArgAccessorFuncCB) {
67316736
SmallVector<Type *> ParameterTypes;
@@ -6792,7 +6797,8 @@ static Expected<Function *> createOutlinedFunction(
67926797

67936798
// Insert target init call in the device compilation pass.
67946799
if (OMPBuilder.Config.isTargetDevice())
6795-
Builder.restoreIP(OMPBuilder.createTargetInit(Builder, /*IsSPMD*/ false));
6800+
Builder.restoreIP(
6801+
OMPBuilder.createTargetInit(Builder, /*IsSPMD=*/false, DefaultAttrs));
67966802

67976803
BasicBlock *UserCodeEntryBB = Builder.GetInsertBlock();
67986804

@@ -6989,16 +6995,18 @@ static Function *emitTargetTaskProxyFunction(OpenMPIRBuilder &OMPBuilder,
69896995

69906996
static Error emitTargetOutlinedFunction(
69916997
OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, bool IsOffloadEntry,
6992-
TargetRegionEntryInfo &EntryInfo, Function *&OutlinedFn,
6993-
Constant *&OutlinedFnID, SmallVectorImpl<Value *> &Inputs,
6998+
TargetRegionEntryInfo &EntryInfo,
6999+
const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs,
7000+
Function *&OutlinedFn, Constant *&OutlinedFnID,
7001+
SmallVectorImpl<Value *> &Inputs,
69947002
OpenMPIRBuilder::TargetBodyGenCallbackTy &CBFunc,
69957003
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy &ArgAccessorFuncCB) {
69967004

69977005
OpenMPIRBuilder::FunctionGenCallback &&GenerateOutlinedFunction =
6998-
[&OMPBuilder, &Builder, &Inputs, &CBFunc,
6999-
&ArgAccessorFuncCB](StringRef EntryFnName) {
7000-
return createOutlinedFunction(OMPBuilder, Builder, EntryFnName, Inputs,
7001-
CBFunc, ArgAccessorFuncCB);
7006+
[&](StringRef EntryFnName) {
7007+
return createOutlinedFunction(OMPBuilder, Builder, DefaultAttrs,
7008+
EntryFnName, Inputs, CBFunc,
7009+
ArgAccessorFuncCB);
70027010
};
70037011

70047012
return OMPBuilder.emitTargetRegionFunction(
@@ -7294,9 +7302,10 @@ void OpenMPIRBuilder::emitOffloadingArraysAndArgs(
72947302

72957303
static void
72967304
emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7297-
OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn,
7298-
Constant *OutlinedFnID, ArrayRef<int32_t> NumTeams,
7299-
ArrayRef<int32_t> NumThreads, SmallVectorImpl<Value *> &Args,
7305+
OpenMPIRBuilder::InsertPointTy AllocaIP,
7306+
const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs,
7307+
Function *OutlinedFn, Constant *OutlinedFnID,
7308+
SmallVectorImpl<Value *> &Args,
73007309
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
73017310
SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies = {},
73027311
bool HasNoWait = false) {
@@ -7377,9 +7386,9 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
73777386

73787387
SmallVector<Value *, 3> NumTeamsC;
73797388
SmallVector<Value *, 3> NumThreadsC;
7380-
for (auto V : NumTeams)
7389+
for (auto V : DefaultAttrs.MaxTeams)
73817390
NumTeamsC.push_back(llvm::ConstantInt::get(Builder.getInt32Ty(), V));
7382-
for (auto V : NumThreads)
7391+
for (auto V : DefaultAttrs.MaxThreads)
73837392
NumThreadsC.push_back(llvm::ConstantInt::get(Builder.getInt32Ty(), V));
73847393

73857394
unsigned NumTargetItems = Info.NumberOfPtrs;
@@ -7420,7 +7429,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
74207429
OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
74217430
const LocationDescription &Loc, bool IsOffloadEntry, InsertPointTy AllocaIP,
74227431
InsertPointTy CodeGenIP, TargetRegionEntryInfo &EntryInfo,
7423-
ArrayRef<int32_t> NumTeams, ArrayRef<int32_t> NumThreads,
7432+
const TargetKernelDefaultAttrs &DefaultAttrs,
74247433
SmallVectorImpl<Value *> &Args, GenMapInfoCallbackTy GenMapInfoCB,
74257434
OpenMPIRBuilder::TargetBodyGenCallbackTy CBFunc,
74267435
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
@@ -7437,16 +7446,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
74377446
// the target region itself is generated using the callbacks CBFunc
74387447
// and ArgAccessorFuncCB
74397448
if (Error Err = emitTargetOutlinedFunction(
7440-
*this, Builder, IsOffloadEntry, EntryInfo, OutlinedFn, OutlinedFnID,
7441-
Args, CBFunc, ArgAccessorFuncCB))
7449+
*this, Builder, IsOffloadEntry, EntryInfo, DefaultAttrs, OutlinedFn,
7450+
OutlinedFnID, Args, CBFunc, ArgAccessorFuncCB))
74427451
return Err;
74437452

74447453
// If we are not on the target device, then we need to generate code
74457454
// to make a remote call (offload) to the previously outlined function
74467455
// that represents the target region. Do that now.
74477456
if (!Config.isTargetDevice())
7448-
emitTargetCall(*this, Builder, AllocaIP, OutlinedFn, OutlinedFnID, NumTeams,
7449-
NumThreads, Args, GenMapInfoCB, Dependencies, HasNowait);
7457+
emitTargetCall(*this, Builder, AllocaIP, DefaultAttrs, OutlinedFn,
7458+
OutlinedFnID, Args, GenMapInfoCB, Dependencies, HasNowait);
74507459
return Builder.saveIP();
74517460
}
74527461

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6182,9 +6182,12 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
61826182

61836183
TargetRegionEntryInfo EntryInfo("func", 42, 4711, 17);
61846184
OpenMPIRBuilder::LocationDescription OmpLoc({Builder.saveIP(), DL});
6185-
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget(
6186-
OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(), Builder.saveIP(),
6187-
EntryInfo, -1, 0, Inputs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);
6185+
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
6186+
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
6187+
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
6188+
OMPBuilder.createTarget(OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(),
6189+
Builder.saveIP(), EntryInfo, DefaultAttrs, Inputs,
6190+
GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);
61886191
assert(AfterIP && "unexpected error");
61896192
Builder.restoreIP(*AfterIP);
61906193
OMPBuilder.finalize();
@@ -6292,11 +6295,11 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
62926295
TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
62936296
/*Line=*/3, /*Count=*/0);
62946297

6295-
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
6296-
OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
6297-
EntryInfo, /*NumTeams=*/-1,
6298-
/*NumThreads=*/0, CapturedArgs, GenMapInfoCB,
6299-
BodyGenCB, SimpleArgAccessorCB);
6298+
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
6299+
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
6300+
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget(
6301+
Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP, EntryInfo, DefaultAttrs,
6302+
CapturedArgs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);
63006303
assert(AfterIP && "unexpected error");
63016304
Builder.restoreIP(*AfterIP);
63026305

@@ -6443,11 +6446,11 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
64436446
TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
64446447
/*Line=*/3, /*Count=*/0);
64456448

6446-
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
6447-
OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
6448-
EntryInfo, /*NumTeams=*/-1,
6449-
/*NumThreads=*/0, CapturedArgs, GenMapInfoCB,
6450-
BodyGenCB, SimpleArgAccessorCB);
6449+
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
6450+
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
6451+
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget(
6452+
Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP, EntryInfo, DefaultAttrs,
6453+
CapturedArgs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);
64516454
assert(AfterIP && "unexpected error");
64526455
Builder.restoreIP(*AfterIP);
64536456

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,9 +3902,6 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
39023902
if (!getTargetEntryUniqueInfo(entryInfo, targetOp, parentName))
39033903
return failure();
39043904

3905-
int32_t defaultValTeams = -1;
3906-
int32_t defaultValThreads = 0;
3907-
39083905
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
39093906
findAllocaInsertPoint(builder, moduleTranslation);
39103907

@@ -3939,6 +3936,10 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
39393936
allocaIP, codeGenIP);
39403937
};
39413938

3939+
// TODO: Populate default attributes based on the construct and clauses.
3940+
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs defaultAttrs = {
3941+
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
3942+
39423943
llvm::SmallVector<llvm::Value *, 4> kernelInput;
39433944
for (size_t i = 0; i < mapVars.size(); ++i) {
39443945
// declare target arguments are not passed to kernels as arguments
@@ -3957,8 +3958,8 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
39573958
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
39583959
moduleTranslation.getOpenMPBuilder()->createTarget(
39593960
ompLoc, isOffloadEntry, allocaIP, builder.saveIP(), entryInfo,
3960-
defaultValTeams, defaultValThreads, kernelInput, genMapInfoCB, bodyCB,
3961-
argAccessorCB, dds, targetOp.getNowait());
3961+
defaultAttrs, kernelInput, genMapInfoCB, bodyCB, argAccessorCB, dds,
3962+
targetOp.getNowait());
39623963

39633964
if (failed(handleError(afterIP, opInst)))
39643965
return failure();

mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module attributes {omp.is_target_device = true} {
2929
// CHECK: @[[SRC_LOC:.*]] = private unnamed_addr constant [23 x i8] c"{{[^"]*}}", align 1
3030
// CHECK: @[[IDENT:.*]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[SRC_LOC]] }, align 8
3131
// CHECK: @[[DYNA_ENV:.*]] = weak_odr protected global %struct.DynamicEnvironmentTy zeroinitializer
32-
// CHECK: @[[KERNEL_ENV:.*]] = weak_odr protected constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 1, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[IDENT]], ptr @[[DYNA_ENV]] }
32+
// CHECK: @[[KERNEL_ENV:.*]] = weak_odr protected constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 1, i8 1, i32 0, i32 0, i32 0, i32 -1, i32 0, i32 0 }, ptr @[[IDENT]], ptr @[[DYNA_ENV]] }
3333
// CHECK: define weak_odr protected void @__omp_offloading_{{[^_]+}}_{{[^_]+}}_omp_target_region__l{{[0-9]+}}(ptr %[[DYN_PTR:.*]], ptr %[[ADDR_A:.*]], ptr %[[ADDR_B:.*]], ptr %[[ADDR_C:.*]])
3434
// CHECK: %[[TMP_A:.*]] = alloca ptr, align 8
3535
// CHECK: store ptr %[[ADDR_A]], ptr %[[TMP_A]], align 8

0 commit comments

Comments
 (0)