Skip to content

Commit 45c6667

Browse files
committed
Move IsSPMD into the new structure
1 parent f73a439 commit 45c6667

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,11 @@ void CGOpenMPRuntimeGPU::emitKernelInit(const OMPExecutableDirective &D,
745745
CodeGenFunction &CGF,
746746
EntryFunctionState &EST, bool IsSPMD) {
747747
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs Attrs;
748+
Attrs.IsSPMD = IsSPMD;
748749
computeMinAndMaxThreadsAndTeams(D, CGF, Attrs);
749750

750751
CGBuilderTy &Bld = CGF.Builder;
751-
Bld.restoreIP(OMPBuilder.createTargetInit(Bld, IsSPMD, Attrs));
752+
Bld.restoreIP(OMPBuilder.createTargetInit(Bld, Attrs));
752753
if (!IsSPMD)
753754
emitGenericVarsProlog(CGF, EST.Loc);
754755
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,7 @@ class OpenMPIRBuilder {
22332233
/// time. The number of max values will be 1 except for the case where
22342234
/// ompx_bare is set.
22352235
struct TargetKernelDefaultAttrs {
2236+
bool IsSPMD = false;
22362237
SmallVector<int32_t, 3> MaxTeams = {-1};
22372238
int32_t MinTeams = 1;
22382239
SmallVector<int32_t, 3> MaxThreads = {-1};
@@ -2741,11 +2742,10 @@ class OpenMPIRBuilder {
27412742
/// Create a runtime call for kmpc_target_init
27422743
///
27432744
/// \param Loc The insert and source location description.
2744-
/// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
2745-
/// \param Attrs Structure containing the default numbers of threads and teams
2746-
/// to launch the kernel with.
2745+
/// \param Attrs Structure containing the default attributes, including
2746+
/// numbers of threads and teams to launch the kernel with.
27472747
InsertPointTy createTargetInit(
2748-
const LocationDescription &Loc, bool IsSPMD,
2748+
const LocationDescription &Loc,
27492749
const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
27502750

27512751
/// Create a runtime call for kmpc_target_deinit

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6129,7 +6129,7 @@ CallInst *OpenMPIRBuilder::createCachedThreadPrivate(
61296129
}
61306130

61316131
OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
6132-
const LocationDescription &Loc, bool IsSPMD,
6132+
const LocationDescription &Loc,
61336133
const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs) {
61346134
assert(!Attrs.MaxThreads.empty() && !Attrs.MaxTeams.empty() &&
61356135
"expected num_threads and num_teams to be specified");
@@ -6141,8 +6141,9 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
61416141
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
61426142
Constant *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
61436143
Constant *IsSPMDVal = ConstantInt::getSigned(
6144-
Int8, IsSPMD ? OMP_TGT_EXEC_MODE_SPMD : OMP_TGT_EXEC_MODE_GENERIC);
6145-
Constant *UseGenericStateMachineVal = ConstantInt::getSigned(Int8, !IsSPMD);
6144+
Int8, Attrs.IsSPMD ? OMP_TGT_EXEC_MODE_SPMD : OMP_TGT_EXEC_MODE_GENERIC);
6145+
Constant *UseGenericStateMachineVal =
6146+
ConstantInt::getSigned(Int8, !Attrs.IsSPMD);
61466147
Constant *MayUseNestedParallelismVal = ConstantInt::getSigned(Int8, true);
61476148
Constant *DebugIndentionLevelVal = ConstantInt::getSigned(Int16, 0);
61486149

@@ -6816,8 +6817,7 @@ static Expected<Function *> createOutlinedFunction(
68166817

68176818
// Insert target init call in the device compilation pass.
68186819
if (OMPBuilder.Config.isTargetDevice())
6819-
Builder.restoreIP(
6820-
OMPBuilder.createTargetInit(Builder, /*IsSPMD=*/false, DefaultAttrs));
6820+
Builder.restoreIP(OMPBuilder.createTargetInit(Builder, DefaultAttrs));
68216821

68226822
BasicBlock *UserCodeEntryBB = Builder.GetInsertBlock();
68236823

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6183,7 +6183,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
61836183
TargetRegionEntryInfo EntryInfo("func", 42, 4711, 17);
61846184
OpenMPIRBuilder::LocationDescription OmpLoc({Builder.saveIP(), DL});
61856185
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
6186-
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
6186+
/*IsSPMD=*/false, /*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0},
6187+
/*MinThreads=*/0};
61876188
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
61886189
OMPBuilder.createTarget(OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(),
61896190
Builder.saveIP(), EntryInfo, DefaultAttrs, Inputs,
@@ -6296,7 +6297,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
62966297
/*Line=*/3, /*Count=*/0);
62976298

62986299
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
6299-
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
6300+
/*IsSPMD=*/false, /*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0},
6301+
/*MinThreads=*/0};
63006302
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget(
63016303
Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP, EntryInfo, DefaultAttrs,
63026304
CapturedArgs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);
@@ -6453,7 +6455,8 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
64536455
/*Line=*/3, /*Count=*/0);
64546456

64556457
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
6456-
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
6458+
/*IsSPMD=*/false, /*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0},
6459+
/*MinThreads=*/0};
64576460
OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget(
64586461
Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP, EntryInfo, DefaultAttrs,
64596462
CapturedArgs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,8 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
40874087

40884088
// TODO: Populate default attributes based on the construct and clauses.
40894089
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs defaultAttrs = {
4090-
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
4090+
/*IsSPMD=*/false, /*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0},
4091+
/*MinThreads=*/0};
40914092

40924093
llvm::SmallVector<llvm::Value *, 4> kernelInput;
40934094
for (size_t i = 0; i < mapVars.size(); ++i) {

0 commit comments

Comments
 (0)