Skip to content

Commit 08ed236

Browse files
committed
[MLIR][OpenMP] Add support for dist_schedule
`dist_schedule` was previously supported in Flang/Clang but was not implemented in MLIR, instead a user would get a "not yet implemented" error. This patch adds support for the `dist_schedule` clause to be lowered to LLVM IR when used in an `omp.distribute` section. Support is also added for `dist_schedule` to be used when the loop nest is embedded within a Workshare Loop. There has needed to be some rework required to ensure that MLIR/LLVM emits the correct Schedule Type for the clause, as it uses a different schedule type to other OpenMP directives/clauses in the runtime library. Add llvm loop metadata Update implementation to support processing in workshare loop.
1 parent 7f0e407 commit 08ed236

File tree

9 files changed

+347
-102
lines changed

9 files changed

+347
-102
lines changed

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ def OMP_SCHEDULE_Dynamic : EnumVal<"dynamic", 3, 1> {}
458458
def OMP_SCHEDULE_Guided : EnumVal<"guided", 4, 1> {}
459459
def OMP_SCHEDULE_Auto : EnumVal<"auto", 5, 1> {}
460460
def OMP_SCHEDULE_Runtime : EnumVal<"runtime", 6, 1> {}
461-
def OMP_SCHEDULE_Default : EnumVal<"default", 7, 0> { let isDefault = 1; }
461+
def OMP_SCHEDULE_Distribute : EnumVal<"distribute", 7, 1> {}
462+
def OMP_SCHEDULE_Default : EnumVal<"default", 8, 0> { let isDefault = 1; }
462463
def OMPC_Schedule : Clause<[Spelling<"schedule">]> {
463464
let clangClass = "OMPScheduleClause";
464465
let flangClass = "OmpScheduleClause";
@@ -469,6 +470,7 @@ def OMPC_Schedule : Clause<[Spelling<"schedule">]> {
469470
OMP_SCHEDULE_Guided,
470471
OMP_SCHEDULE_Auto,
471472
OMP_SCHEDULE_Runtime,
473+
OMP_SCHEDULE_Distribute,
472474
OMP_SCHEDULE_Default
473475
];
474476
}

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,17 @@ class OpenMPIRBuilder {
10961096
/// \param NeedsBarrier Indicates whether a barrier must be inserted after
10971097
/// the loop.
10981098
/// \param LoopType Type of workshare loop.
1099+
/// \param HasDistSchedule Defines if the clause being lowered is
1100+
/// dist_schedule as this is handled slightly differently
1101+
/// \param DistScheduleSchedType Defines the Schedule Type for the Distribute
1102+
/// loop. Defaults to None if no Distribute loop is present.
10991103
///
11001104
/// \returns Point where to insert code after the workshare construct.
11011105
InsertPointOrErrorTy applyStaticWorkshareLoop(
11021106
DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1103-
omp::WorksharingLoopType LoopType, bool NeedsBarrier);
1107+
omp::WorksharingLoopType LoopType, bool NeedsBarrier,
1108+
bool HasDistSchedule = false,
1109+
omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
11041110

11051111
/// Modifies the canonical loop a statically-scheduled workshare loop with a
11061112
/// user-specified chunk size.
@@ -1113,13 +1119,22 @@ class OpenMPIRBuilder {
11131119
/// \param NeedsBarrier Indicates whether a barrier must be inserted after the
11141120
/// loop.
11151121
/// \param ChunkSize The user-specified chunk size.
1122+
/// \param SchedType Optional type of scheduling to be passed to the init
1123+
/// function.
1124+
/// \param DistScheduleChunkSize The size of dist_shcedule chunk considered
1125+
/// as a unit when
1126+
/// scheduling. If \p nullptr, defaults to 1.
1127+
/// \param DistScheduleSchedType Defines the Schedule Type for the Distribute
1128+
/// loop. Defaults to None if no Distribute loop is present.
11161129
///
11171130
/// \returns Point where to insert code after the workshare construct.
1118-
InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc DL,
1119-
CanonicalLoopInfo *CLI,
1120-
InsertPointTy AllocaIP,
1121-
bool NeedsBarrier,
1122-
Value *ChunkSize);
1131+
InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(
1132+
DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1133+
bool NeedsBarrier, Value *ChunkSize,
1134+
omp::OMPScheduleType SchedType =
1135+
omp::OMPScheduleType::UnorderedStaticChunked,
1136+
Value *DistScheduleChunkSize = nullptr,
1137+
omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
11231138

11241139
/// Modifies the canonical loop to be a dynamically-scheduled workshare loop.
11251140
///
@@ -1139,14 +1154,15 @@ class OpenMPIRBuilder {
11391154
/// the loop.
11401155
/// \param Chunk The size of loop chunk considered as a unit when
11411156
/// scheduling. If \p nullptr, defaults to 1.
1157+
/// \param DistScheduleChunk The size of dist_shcedule chunk considered as
1158+
/// a unit when
1159+
/// scheduling. If \p nullptr, defaults to 1.
11421160
///
11431161
/// \returns Point where to insert code after the workshare construct.
1144-
InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc DL,
1145-
CanonicalLoopInfo *CLI,
1146-
InsertPointTy AllocaIP,
1147-
omp::OMPScheduleType SchedType,
1148-
bool NeedsBarrier,
1149-
Value *Chunk = nullptr);
1162+
InsertPointOrErrorTy applyDynamicWorkshareLoop(
1163+
DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1164+
omp::OMPScheduleType SchedType, bool NeedsBarrier, Value *Chunk = nullptr,
1165+
Value *DistScheduleChunk = nullptr);
11501166

11511167
/// Create alternative version of the loop to support if clause
11521168
///
@@ -1197,6 +1213,10 @@ class OpenMPIRBuilder {
11971213
/// present.
11981214
/// \param LoopType Information about type of loop worksharing.
11991215
/// It corresponds to type of loop workshare OpenMP pragma.
1216+
/// \param HasDistSchedule Defines if the clause being lowered is
1217+
/// dist_schedule as this is handled slightly differently
1218+
///
1219+
/// \param ChunkSize The chunk size for dist_schedule loop
12001220
///
12011221
/// \returns Point where to insert code after the workshare construct.
12021222
LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
@@ -1207,7 +1227,8 @@ class OpenMPIRBuilder {
12071227
bool HasMonotonicModifier = false, bool HasNonmonotonicModifier = false,
12081228
bool HasOrderedClause = false,
12091229
omp::WorksharingLoopType LoopType =
1210-
omp::WorksharingLoopType::ForStaticLoop);
1230+
omp::WorksharingLoopType::ForStaticLoop,
1231+
bool HasDistSchedule = false, Value *DistScheduleChunkSize = nullptr);
12111232

12121233
/// Tile a loop nest.
12131234
///

0 commit comments

Comments
 (0)