Skip to content

Commit

Permalink
[OpenMP]Add support for workshare loop modifier in lowering
Browse files Browse the repository at this point in the history
When lowering the dynamic, guided, auto and runtime types of scheduling,
there is an optional monotonic or non-monotonic modifier. This patch
adds support in the OMP IR Builder to pass this down to the runtime
functions.

Also implements tests for the variants.

Differential Revision: https://reviews.llvm.org/D102008
  • Loading branch information
Leporacanthicus committed May 27, 2021
1 parent 96ef4f4 commit 9091ecd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
8 changes: 5 additions & 3 deletions llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ enum class OMPScheduleType {
Runtime = 37,
Auto = 38, // auto

ModifierMonotonic =
(1 << 29), // Set if the monotonic schedule modifier was present
ModifierNonmonotonic =
(1 << 30), /**< Set if the nonmonotonic schedule modifier was present */

LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierNonmonotonic)
(1 << 30), // Set if the nonmonotonic schedule modifier was present
ModifierMask = ModifierMonotonic | ModifierNonmonotonic,
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask)
};

} // end namespace omp
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,10 +1431,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createDynamicWorkshareLoop(

Value *ThreadNum = getOrCreateThreadID(SrcLoc);

OMPScheduleType DynamicSchedType =
SchedType | OMPScheduleType::ModifierNonmonotonic;
Constant *SchedulingType =
ConstantInt::get(I32Type, static_cast<int>(DynamicSchedType));
ConstantInt::get(I32Type, static_cast<int>(SchedType));

// Call the "init" function.
Builder.CreateCall(DynamicInit,
Expand Down
30 changes: 21 additions & 9 deletions llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {

omp::OMPScheduleType SchedType = GetParam();
uint32_t ChunkSize = 1;
switch (SchedType) {
switch (SchedType & ~omp::OMPScheduleType::ModifierMask) {
case omp::OMPScheduleType::DynamicChunked:
case omp::OMPScheduleType::GuidedChunked:
ChunkSize = 7;
Expand Down Expand Up @@ -1794,8 +1794,9 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
EXPECT_EQ(InitCall->getCalledFunction()->getName(),
"__kmpc_dispatch_init_4u");
EXPECT_EQ(InitCall->getNumArgOperands(), 7U);
EXPECT_EQ(InitCall->getArgOperand(6),
ConstantInt::get(Type::getInt32Ty(Ctx), ChunkSize));
EXPECT_EQ(InitCall->getArgOperand(6), ConstantInt::get(LCTy, ChunkSize));
ConstantInt *SchedVal = cast<ConstantInt>(InitCall->getArgOperand(2));
EXPECT_EQ(SchedVal->getValue(), static_cast<uint64_t>(SchedType));

ConstantInt *OrigLowerBound =
dyn_cast<ConstantInt>(LowerBoundStore->getValueOperand());
Expand Down Expand Up @@ -1827,12 +1828,23 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
EXPECT_FALSE(verifyModule(*M, &errs()));
}

INSTANTIATE_TEST_SUITE_P(OpenMPWSLoopSchedulingTypes,
OpenMPIRBuilderTestWithParams,
::testing::Values(omp::OMPScheduleType::DynamicChunked,
omp::OMPScheduleType::GuidedChunked,
omp::OMPScheduleType::Auto,
omp::OMPScheduleType::Runtime));
INSTANTIATE_TEST_SUITE_P(
OpenMPWSLoopSchedulingTypes, OpenMPIRBuilderTestWithParams,
::testing::Values(omp::OMPScheduleType::DynamicChunked,
omp::OMPScheduleType::GuidedChunked,
omp::OMPScheduleType::Auto, omp::OMPScheduleType::Runtime,
omp::OMPScheduleType::DynamicChunked |
omp::OMPScheduleType::ModifierMonotonic,
omp::OMPScheduleType::DynamicChunked |
omp::OMPScheduleType::ModifierNonmonotonic,
omp::OMPScheduleType::GuidedChunked |
omp::OMPScheduleType::ModifierMonotonic,
omp::OMPScheduleType::GuidedChunked |
omp::OMPScheduleType::ModifierNonmonotonic,
omp::OMPScheduleType::Auto |
omp::OMPScheduleType::ModifierMonotonic,
omp::OMPScheduleType::Runtime |
omp::OMPScheduleType::ModifierMonotonic));

TEST_F(OpenMPIRBuilderTest, MasterDirective) {
using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
Expand Down

0 comments on commit 9091ecd

Please sign in to comment.