Skip to content

Commit ea4c5fb

Browse files
[OpenMP]Add support for workshare loop modifier in lowering
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
1 parent 1d5b976 commit ea4c5fb

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ enum class OMPScheduleType {
117117
Runtime = 37,
118118
Auto = 38, // auto
119119

120+
ModifierMonotonic =
121+
(1 << 29), // Set if the monotonic schedule modifier was present
120122
ModifierNonmonotonic =
121-
(1 << 30), /**< Set if the nonmonotonic schedule modifier was present */
122-
123-
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierNonmonotonic)
123+
(1 << 30), // Set if the nonmonotonic schedule modifier was present
124+
ModifierMask = ModifierMonotonic | ModifierNonmonotonic,
125+
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask)
124126
};
125127

126128
} // end namespace omp

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,10 +1431,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createDynamicWorkshareLoop(
14311431

14321432
Value *ThreadNum = getOrCreateThreadID(SrcLoc);
14331433

1434-
OMPScheduleType DynamicSchedType =
1435-
SchedType | OMPScheduleType::ModifierNonmonotonic;
14361434
Constant *SchedulingType =
1437-
ConstantInt::get(I32Type, static_cast<int>(DynamicSchedType));
1435+
ConstantInt::get(I32Type, static_cast<int>(SchedType));
14381436

14391437
// Call the "init" function.
14401438
Builder.CreateCall(DynamicInit,

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
17211721

17221722
omp::OMPScheduleType SchedType = GetParam();
17231723
uint32_t ChunkSize = 1;
1724-
switch (SchedType) {
1724+
switch (SchedType & ~omp::OMPScheduleType::ModifierMask) {
17251725
case omp::OMPScheduleType::DynamicChunked:
17261726
case omp::OMPScheduleType::GuidedChunked:
17271727
ChunkSize = 7;
@@ -1794,8 +1794,9 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
17941794
EXPECT_EQ(InitCall->getCalledFunction()->getName(),
17951795
"__kmpc_dispatch_init_4u");
17961796
EXPECT_EQ(InitCall->getNumArgOperands(), 7U);
1797-
EXPECT_EQ(InitCall->getArgOperand(6),
1798-
ConstantInt::get(Type::getInt32Ty(Ctx), ChunkSize));
1797+
EXPECT_EQ(InitCall->getArgOperand(6), ConstantInt::get(LCTy, ChunkSize));
1798+
ConstantInt *SchedVal = cast<ConstantInt>(InitCall->getArgOperand(2));
1799+
EXPECT_EQ(SchedVal->getValue(), static_cast<uint64_t>(SchedType));
17991800

18001801
ConstantInt *OrigLowerBound =
18011802
dyn_cast<ConstantInt>(LowerBoundStore->getValueOperand());
@@ -1827,12 +1828,23 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
18271828
EXPECT_FALSE(verifyModule(*M, &errs()));
18281829
}
18291830

1830-
INSTANTIATE_TEST_SUITE_P(OpenMPWSLoopSchedulingTypes,
1831-
OpenMPIRBuilderTestWithParams,
1832-
::testing::Values(omp::OMPScheduleType::DynamicChunked,
1833-
omp::OMPScheduleType::GuidedChunked,
1834-
omp::OMPScheduleType::Auto,
1835-
omp::OMPScheduleType::Runtime));
1831+
INSTANTIATE_TEST_CASE_P(
1832+
OpenMPWSLoopSchedulingTypes, OpenMPIRBuilderTestWithParams,
1833+
::testing::Values(omp::OMPScheduleType::DynamicChunked,
1834+
omp::OMPScheduleType::GuidedChunked,
1835+
omp::OMPScheduleType::Auto, omp::OMPScheduleType::Runtime,
1836+
omp::OMPScheduleType::DynamicChunked |
1837+
omp::OMPScheduleType::ModifierMonotonic,
1838+
omp::OMPScheduleType::DynamicChunked |
1839+
omp::OMPScheduleType::ModifierNonmonotonic,
1840+
omp::OMPScheduleType::GuidedChunked |
1841+
omp::OMPScheduleType::ModifierMonotonic,
1842+
omp::OMPScheduleType::GuidedChunked |
1843+
omp::OMPScheduleType::ModifierNonmonotonic,
1844+
omp::OMPScheduleType::Auto |
1845+
omp::OMPScheduleType::ModifierMonotonic,
1846+
omp::OMPScheduleType::Runtime |
1847+
omp::OMPScheduleType::ModifierMonotonic));
18361848

18371849
TEST_F(OpenMPIRBuilderTest, MasterDirective) {
18381850
using InsertPointTy = OpenMPIRBuilder::InsertPointTy;

0 commit comments

Comments
 (0)