Skip to content

Commit 464cd87

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 464cd87

File tree

9 files changed

+332
-93
lines changed

9 files changed

+332
-93
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: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,13 @@ 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 dist_schedule as this is handled slightly differently
1100+
/// \param DistScheduleSchedType Defines the Schedule Type for the Distribute loop. Defaults to None if no Distribute loop is present.
10991101
///
11001102
/// \returns Point where to insert code after the workshare construct.
11011103
InsertPointOrErrorTy applyStaticWorkshareLoop(
11021104
DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1103-
omp::WorksharingLoopType LoopType, bool NeedsBarrier);
1105+
omp::WorksharingLoopType LoopType, bool NeedsBarrier, bool HasDistSchedule = false, omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
11041106

11051107
/// Modifies the canonical loop a statically-scheduled workshare loop with a
11061108
/// user-specified chunk size.
@@ -1113,13 +1115,20 @@ class OpenMPIRBuilder {
11131115
/// \param NeedsBarrier Indicates whether a barrier must be inserted after the
11141116
/// loop.
11151117
/// \param ChunkSize The user-specified chunk size.
1118+
/// \param SchedType Optional type of scheduling to be passed to the init function.
1119+
/// \param DistScheduleChunkSize The size of dist_shcedule chunk considered as a unit when
1120+
/// scheduling. If \p nullptr, defaults to 1.
1121+
/// \param DistScheduleSchedType Defines the Schedule Type for the Distribute loop. Defaults to None if no Distribute loop is present.
11161122
///
11171123
/// \returns Point where to insert code after the workshare construct.
11181124
InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc DL,
11191125
CanonicalLoopInfo *CLI,
11201126
InsertPointTy AllocaIP,
11211127
bool NeedsBarrier,
1122-
Value *ChunkSize);
1128+
Value *ChunkSize,
1129+
omp::OMPScheduleType SchedType = omp::OMPScheduleType::UnorderedStaticChunked,
1130+
Value *DistScheduleChunkSize = nullptr,
1131+
omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
11231132

11241133
/// Modifies the canonical loop to be a dynamically-scheduled workshare loop.
11251134
///
@@ -1139,14 +1148,17 @@ class OpenMPIRBuilder {
11391148
/// the loop.
11401149
/// \param Chunk The size of loop chunk considered as a unit when
11411150
/// scheduling. If \p nullptr, defaults to 1.
1151+
/// \param DistScheduleChunk The size of dist_shcedule chunk considered as a unit when
1152+
/// scheduling. If \p nullptr, defaults to 1.
11421153
///
11431154
/// \returns Point where to insert code after the workshare construct.
11441155
InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc DL,
11451156
CanonicalLoopInfo *CLI,
11461157
InsertPointTy AllocaIP,
11471158
omp::OMPScheduleType SchedType,
11481159
bool NeedsBarrier,
1149-
Value *Chunk = nullptr);
1160+
Value *Chunk = nullptr,
1161+
Value *DistScheduleChunk = nullptr);
11501162

11511163
/// Create alternative version of the loop to support if clause
11521164
///
@@ -1197,6 +1209,9 @@ class OpenMPIRBuilder {
11971209
/// present.
11981210
/// \param LoopType Information about type of loop worksharing.
11991211
/// It corresponds to type of loop workshare OpenMP pragma.
1212+
/// \param HasDistSchedule Defines if the clause being lowered is dist_schedule as this is handled slightly differently
1213+
///
1214+
/// \param ChunkSize The chunk size for dist_schedule loop
12001215
///
12011216
/// \returns Point where to insert code after the workshare construct.
12021217
LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
@@ -1207,7 +1222,9 @@ class OpenMPIRBuilder {
12071222
bool HasMonotonicModifier = false, bool HasNonmonotonicModifier = false,
12081223
bool HasOrderedClause = false,
12091224
omp::WorksharingLoopType LoopType =
1210-
omp::WorksharingLoopType::ForStaticLoop);
1225+
omp::WorksharingLoopType::ForStaticLoop,
1226+
bool HasDistSchedule = false,
1227+
Value* DistScheduleChunkSize = nullptr);
12111228

12121229
/// Tile a loop nest.
12131230
///

0 commit comments

Comments
 (0)