diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h b/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h @@ -117,10 +117,12 @@ 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) + ModifierMask = ModifierMonotonic | ModifierNonmonotonic, + LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask) }; } // end namespace omp diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -1431,8 +1431,16 @@ Value *ThreadNum = getOrCreateThreadID(SrcLoc); - OMPScheduleType DynamicSchedType = - SchedType | OMPScheduleType::ModifierNonmonotonic; + OMPScheduleType DynamicSchedType = SchedType; + if (!static_cast(SchedType & omp::OMPScheduleType::ModifierMask)) { + if (SchedType == omp::OMPScheduleType::DynamicChunked || + SchedType == omp::OMPScheduleType::GuidedChunked) { + DynamicSchedType |= omp::OMPScheduleType::ModifierNonmonotonic; + } else { + DynamicSchedType |= omp::OMPScheduleType::ModifierMonotonic; + } + } + Constant *SchedulingType = ConstantInt::get(I32Type, static_cast(DynamicSchedType)); diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -1721,7 +1721,7 @@ 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; @@ -1794,8 +1794,19 @@ 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(InitCall->getArgOperand(2)); + omp::OMPScheduleType ExpectedSchedType = SchedType; + if (!static_cast(SchedType & omp::OMPScheduleType::ModifierMask)) { + if (SchedType == omp::OMPScheduleType::DynamicChunked || + SchedType == omp::OMPScheduleType::GuidedChunked) { + ExpectedSchedType |= omp::OMPScheduleType::ModifierNonmonotonic; + } else { + ExpectedSchedType |= omp::OMPScheduleType::ModifierMonotonic; + } + } + + EXPECT_EQ(SchedVal->getValue(), static_cast(ExpectedSchedType)); ConstantInt *OrigLowerBound = dyn_cast(LowerBoundStore->getValueOperand()); @@ -1827,12 +1838,23 @@ EXPECT_FALSE(verifyModule(*M, &errs())); } -INSTANTIATE_TEST_CASE_P(OpenMPWSLoopSchedulingTypes, - OpenMPIRBuilderTestWithParams, - ::testing::Values(omp::OMPScheduleType::DynamicChunked, - omp::OMPScheduleType::GuidedChunked, - omp::OMPScheduleType::Auto, - omp::OMPScheduleType::Runtime)); +INSTANTIATE_TEST_CASE_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;