Skip to content

Commit b3b4696

Browse files
authored
[MLIR][OpenMP] NFC: Sort clauses alphabetically (1/2) (llvm#101193)
This patch sorts the clause lists for the following OpenMP operations: - omp.parallel - omp.teams - omp.sections - omp.wsloop - omp.distribute - omp.task This change results in the reordering of operation arguments, so impacted unit tests are updated accordingly.
1 parent 38e6453 commit b3b4696

File tree

6 files changed

+99
-105
lines changed

6 files changed

+99
-105
lines changed

flang/test/Lower/OpenMP/task.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ subroutine task_multiple_clauses()
227227
integer :: x, y, z
228228
logical :: buzz
229229

230-
!CHECK: omp.task if(%{{.+}}) final(%{{.+}}) priority(%{{.+}}) allocate(%{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>) {
230+
!CHECK: omp.task allocate(%{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>) final(%{{.+}}) if(%{{.+}}) priority(%{{.+}}) {
231231
!$omp task if(buzz) final(buzz) priority(z) allocate(omp_high_bw_mem_alloc: x) private(x) firstprivate(y)
232232

233233
!CHECK: %[[X_PRIV_ALLOCA:.+]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFtask_multiple_clausesEx"}

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ def ParallelOp : OpenMP_Op<"parallel", traits = [
132132
DeclareOpInterfaceMethods<OutlineableOpenMPOpInterface>,
133133
RecursiveMemoryEffects
134134
], clauses = [
135-
// TODO: Sort clauses alphabetically.
135+
OpenMP_AllocateClauseSkip<assemblyFormat = true>,
136136
OpenMP_IfClauseSkip<assemblyFormat = true>,
137137
OpenMP_NumThreadsClauseSkip<assemblyFormat = true>,
138-
OpenMP_AllocateClauseSkip<assemblyFormat = true>,
139-
OpenMP_ReductionClauseSkip<assemblyFormat = true>,
138+
OpenMP_PrivateClauseSkip<assemblyFormat = true>,
140139
OpenMP_ProcBindClauseSkip<assemblyFormat = true>,
141-
OpenMP_PrivateClauseSkip<assemblyFormat = true>
140+
OpenMP_ReductionClauseSkip<assemblyFormat = true>
142141
], singleRegion = true> {
143142
let summary = "parallel construct";
144143
let description = [{
@@ -195,9 +194,8 @@ def TerminatorOp : OpenMP_Op<"terminator", [Terminator, Pure]> {
195194
def TeamsOp : OpenMP_Op<"teams", traits = [
196195
AttrSizedOperandSegments, RecursiveMemoryEffects
197196
], clauses = [
198-
// TODO: Sort clauses alphabetically.
199-
OpenMP_NumTeamsClause, OpenMP_IfClause, OpenMP_ThreadLimitClause,
200-
OpenMP_AllocateClause, OpenMP_ReductionClause, OpenMP_PrivateClause
197+
OpenMP_AllocateClause, OpenMP_IfClause, OpenMP_NumTeamsClause,
198+
OpenMP_PrivateClause, OpenMP_ReductionClause, OpenMP_ThreadLimitClause
201199
], singleRegion = true> {
202200
let summary = "teams construct";
203201
let description = [{
@@ -237,9 +235,8 @@ def SectionOp : OpenMP_Op<"section", [HasParent<"SectionsOp">],
237235
def SectionsOp : OpenMP_Op<"sections", traits = [
238236
AttrSizedOperandSegments
239237
], clauses = [
240-
// TODO: Sort clauses alphabetically.
241-
OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause,
242-
OpenMP_PrivateClause
238+
OpenMP_AllocateClause, OpenMP_NowaitClause, OpenMP_PrivateClause,
239+
OpenMP_ReductionClause
243240
], singleRegion = true> {
244241
let summary = "sections construct";
245242
let description = [{
@@ -362,15 +359,14 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
362359
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
363360
RecursiveMemoryEffects, SingleBlock
364361
], clauses = [
365-
// TODO: Sort clauses alphabetically.
362+
OpenMP_AllocateClauseSkip<assemblyFormat = true>,
366363
OpenMP_LinearClauseSkip<assemblyFormat = true>,
367-
OpenMP_ReductionClauseSkip<assemblyFormat = true>,
368-
OpenMP_ScheduleClauseSkip<assemblyFormat = true>,
369364
OpenMP_NowaitClauseSkip<assemblyFormat = true>,
370-
OpenMP_OrderedClauseSkip<assemblyFormat = true>,
371365
OpenMP_OrderClauseSkip<assemblyFormat = true>,
372-
OpenMP_AllocateClauseSkip<assemblyFormat = true>,
373-
OpenMP_PrivateClauseSkip<assemblyFormat = true>
366+
OpenMP_OrderedClauseSkip<assemblyFormat = true>,
367+
OpenMP_PrivateClauseSkip<assemblyFormat = true>,
368+
OpenMP_ReductionClauseSkip<assemblyFormat = true>,
369+
OpenMP_ScheduleClauseSkip<assemblyFormat = true>
374370
], singleRegion = true> {
375371
let summary = "worksharing-loop construct";
376372
let description = [{
@@ -506,8 +502,7 @@ def DistributeOp : OpenMP_Op<"distribute", traits = [
506502
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
507503
RecursiveMemoryEffects, SingleBlock
508504
], clauses = [
509-
// TODO: Sort clauses alphabetically.
510-
OpenMP_DistScheduleClause, OpenMP_AllocateClause, OpenMP_OrderClause,
505+
OpenMP_AllocateClause, OpenMP_DistScheduleClause, OpenMP_OrderClause,
511506
OpenMP_PrivateClause
512507
], singleRegion = true> {
513508
let summary = "distribute construct";
@@ -560,11 +555,9 @@ def TaskOp : OpenMP_Op<"task", traits = [
560555
OutlineableOpenMPOpInterface
561556
], clauses = [
562557
// TODO: Complete clause list (affinity, detach).
563-
// TODO: Sort clauses alphabetically.
564-
OpenMP_IfClause, OpenMP_FinalClause, OpenMP_UntiedClause,
565-
OpenMP_MergeableClause, OpenMP_InReductionClause,
566-
OpenMP_PriorityClause, OpenMP_DependClause, OpenMP_AllocateClause,
567-
OpenMP_PrivateClause
558+
OpenMP_AllocateClause, OpenMP_DependClause, OpenMP_FinalClause,
559+
OpenMP_IfClause, OpenMP_InReductionClause, OpenMP_MergeableClause,
560+
OpenMP_PriorityClause, OpenMP_PrivateClause, OpenMP_UntiedClause
568561
], singleRegion = true> {
569562
let summary = "task construct";
570563
let description = [{

mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,16 +444,16 @@ struct ParallelOpLowering : public OpRewritePattern<scf::ParallelOp> {
444444
// Create the parallel wrapper.
445445
auto ompParallel = rewriter.create<omp::ParallelOp>(
446446
loc,
447-
/* if_expr = */ Value{},
448-
/* num_threads = */ numThreadsVar,
449447
/* allocate_vars = */ llvm::SmallVector<Value>{},
450448
/* allocator_vars = */ llvm::SmallVector<Value>{},
449+
/* if_expr = */ Value{},
450+
/* num_threads = */ numThreadsVar,
451+
/* private_vars = */ ValueRange(),
452+
/* private_syms = */ nullptr,
453+
/* proc_bind_kind = */ omp::ClauseProcBindKindAttr{},
451454
/* reduction_vars = */ llvm::SmallVector<Value>{},
452455
/* reduction_byref = */ DenseBoolArrayAttr{},
453-
/* reduction_syms = */ ArrayAttr{},
454-
/* proc_bind_kind = */ omp::ClauseProcBindKindAttr{},
455-
/* private_vars = */ ValueRange(),
456-
/* private_syms = */ nullptr);
456+
/* reduction_syms = */ ArrayAttr{});
457457
{
458458

459459
OpBuilder::InsertionGuard guard(rewriter);

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,25 +1475,25 @@ LogicalResult TargetOp::verify() {
14751475

14761476
void ParallelOp::build(OpBuilder &builder, OperationState &state,
14771477
ArrayRef<NamedAttribute> attributes) {
1478-
ParallelOp::build(
1479-
builder, state, /*if_expr=*/nullptr, /*num_threads=*/nullptr,
1480-
/*allocate_vars=*/ValueRange(), /*allocator_vars=*/ValueRange(),
1481-
/*reduction_vars=*/ValueRange(), /*reduction_byref=*/nullptr,
1482-
/*reduction_syms=*/nullptr, /*proc_bind_kind=*/nullptr,
1483-
/*private_vars=*/ValueRange(), /*private_syms=*/nullptr);
1478+
ParallelOp::build(builder, state, /*allocate_vars=*/ValueRange(),
1479+
/*allocator_vars=*/ValueRange(), /*if_expr=*/nullptr,
1480+
/*num_threads=*/nullptr, /*private_vars=*/ValueRange(),
1481+
/*private_syms=*/nullptr, /*proc_bind_kind=*/nullptr,
1482+
/*reduction_vars=*/ValueRange(),
1483+
/*reduction_byref=*/nullptr, /*reduction_syms=*/nullptr);
14841484
state.addAttributes(attributes);
14851485
}
14861486

14871487
void ParallelOp::build(OpBuilder &builder, OperationState &state,
14881488
const ParallelOperands &clauses) {
14891489
MLIRContext *ctx = builder.getContext();
14901490

1491-
ParallelOp::build(
1492-
builder, state, clauses.ifVar, clauses.numThreads, clauses.allocateVars,
1493-
clauses.allocatorVars, clauses.reductionVars,
1494-
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
1495-
makeArrayAttr(ctx, clauses.reductionSyms), clauses.procBindKind,
1496-
clauses.privateVars, makeArrayAttr(ctx, clauses.privateSyms));
1491+
ParallelOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
1492+
clauses.ifVar, clauses.numThreads, clauses.privateVars,
1493+
makeArrayAttr(ctx, clauses.privateSyms),
1494+
clauses.procBindKind, clauses.reductionVars,
1495+
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
1496+
makeArrayAttr(ctx, clauses.reductionSyms));
14971497
}
14981498

14991499
template <typename OpType>
@@ -1582,12 +1582,13 @@ void TeamsOp::build(OpBuilder &builder, OperationState &state,
15821582
const TeamsOperands &clauses) {
15831583
MLIRContext *ctx = builder.getContext();
15841584
// TODO Store clauses in op: privateVars, privateSyms.
1585-
TeamsOp::build(builder, state, clauses.numTeamsLower, clauses.numTeamsUpper,
1586-
clauses.ifVar, clauses.threadLimit, clauses.allocateVars,
1587-
clauses.allocatorVars, clauses.reductionVars,
1585+
TeamsOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
1586+
clauses.ifVar, clauses.numTeamsLower, clauses.numTeamsUpper,
1587+
/*private_vars=*/{},
1588+
/*private_syms=*/nullptr, clauses.reductionVars,
15881589
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
1589-
makeArrayAttr(ctx, clauses.reductionSyms), /*private_vars=*/{},
1590-
/*private_syms=*/nullptr);
1590+
makeArrayAttr(ctx, clauses.reductionSyms),
1591+
clauses.threadLimit);
15911592
}
15921593

15931594
LogicalResult TeamsOp::verify() {
@@ -1630,11 +1631,11 @@ void SectionsOp::build(OpBuilder &builder, OperationState &state,
16301631
const SectionsOperands &clauses) {
16311632
MLIRContext *ctx = builder.getContext();
16321633
// TODO Store clauses in op: privateVars, privateSyms.
1633-
SectionsOp::build(builder, state, clauses.reductionVars,
1634+
SectionsOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
1635+
clauses.nowait, /*private_vars=*/{},
1636+
/*private_syms=*/nullptr, clauses.reductionVars,
16341637
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
1635-
makeArrayAttr(ctx, clauses.reductionSyms),
1636-
clauses.allocateVars, clauses.allocatorVars, clauses.nowait,
1637-
/*private_vars=*/{}, /*private_syms=*/nullptr);
1638+
makeArrayAttr(ctx, clauses.reductionSyms));
16381639
}
16391640

16401641
LogicalResult SectionsOp::verify() {
@@ -1715,14 +1716,14 @@ void printWsloop(OpAsmPrinter &p, Operation *op, Region &region,
17151716

17161717
void WsloopOp::build(OpBuilder &builder, OperationState &state,
17171718
ArrayRef<NamedAttribute> attributes) {
1718-
build(builder, state, /*linear_vars=*/ValueRange(),
1719-
/*linear_step_vars=*/ValueRange(), /*reduction_vars=*/ValueRange(),
1720-
/*reduction_byref=*/nullptr, /*reduction_syms=*/nullptr,
1721-
/*schedule_kind=*/nullptr, /*schedule_chunk=*/nullptr,
1722-
/*schedule_mod=*/nullptr, /*schedule_simd=*/false, /*nowait=*/false,
1723-
/*ordered=*/nullptr, /*order=*/nullptr, /*order_mod=*/nullptr,
1724-
/*allocate_vars=*/{}, /*allocator_vars=*/{}, /*private_vars=*/{},
1725-
/*private_syms=*/nullptr);
1719+
build(builder, state, /*allocate_vars=*/{}, /*allocator_vars=*/{},
1720+
/*linear_vars=*/ValueRange(), /*linear_step_vars=*/ValueRange(),
1721+
/*nowait=*/false, /*order=*/nullptr, /*order_mod=*/nullptr,
1722+
/*ordered=*/nullptr, /*private_vars=*/{}, /*private_syms=*/nullptr,
1723+
/*reduction_vars=*/ValueRange(), /*reduction_byref=*/nullptr,
1724+
/*reduction_syms=*/nullptr, /*schedule_kind=*/nullptr,
1725+
/*schedule_chunk=*/nullptr, /*schedule_mod=*/nullptr,
1726+
/*schedule_simd=*/false);
17261727
state.addAttributes(attributes);
17271728
}
17281729

@@ -1731,15 +1732,15 @@ void WsloopOp::build(OpBuilder &builder, OperationState &state,
17311732
MLIRContext *ctx = builder.getContext();
17321733
// TODO: Store clauses in op: allocateVars, allocatorVars, privateVars,
17331734
// privateSyms.
1734-
WsloopOp::build(builder, state, clauses.linearVars, clauses.linearStepVars,
1735-
clauses.reductionVars,
1736-
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
1737-
makeArrayAttr(ctx, clauses.reductionSyms),
1738-
clauses.scheduleKind, clauses.scheduleChunk,
1739-
clauses.scheduleMod, clauses.scheduleSimd, clauses.nowait,
1740-
clauses.ordered, clauses.order, clauses.orderMod,
1741-
/*allocate_vars=*/{}, /*allocator_vars=*/{},
1742-
/*private_vars=*/{}, /*private_syms=*/nullptr);
1735+
WsloopOp::build(
1736+
builder, state,
1737+
/*allocate_vars=*/{}, /*allocator_vars=*/{}, clauses.linearVars,
1738+
clauses.linearStepVars, clauses.nowait, clauses.order, clauses.orderMod,
1739+
clauses.ordered, /*private_vars=*/{}, /*private_syms=*/nullptr,
1740+
clauses.reductionVars,
1741+
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
1742+
makeArrayAttr(ctx, clauses.reductionSyms), clauses.scheduleKind,
1743+
clauses.scheduleChunk, clauses.scheduleMod, clauses.scheduleSimd);
17431744
}
17441745

17451746
LogicalResult WsloopOp::verify() {
@@ -1804,10 +1805,10 @@ LogicalResult SimdOp::verify() {
18041805
void DistributeOp::build(OpBuilder &builder, OperationState &state,
18051806
const DistributeOperands &clauses) {
18061807
// TODO Store clauses in op: privateVars, privateSyms.
1807-
DistributeOp::build(builder, state, clauses.distScheduleStatic,
1808-
clauses.distScheduleChunkSize, clauses.allocateVars,
1809-
clauses.allocatorVars, clauses.order, clauses.orderMod,
1810-
/*private_vars=*/{}, /*private_syms=*/nullptr);
1808+
DistributeOp::build(
1809+
builder, state, clauses.allocateVars, clauses.allocatorVars,
1810+
clauses.distScheduleStatic, clauses.distScheduleChunkSize, clauses.order,
1811+
clauses.orderMod, /*private_vars=*/{}, /*private_syms=*/nullptr);
18111812
}
18121813

18131814
LogicalResult DistributeOp::verify() {
@@ -1934,13 +1935,13 @@ void TaskOp::build(OpBuilder &builder, OperationState &state,
19341935
const TaskOperands &clauses) {
19351936
MLIRContext *ctx = builder.getContext();
19361937
// TODO Store clauses in op: privateVars, privateSyms.
1937-
TaskOp::build(builder, state, clauses.ifVar, clauses.final, clauses.untied,
1938-
clauses.mergeable, clauses.inReductionVars,
1939-
makeDenseBoolArrayAttr(ctx, clauses.inReductionByref),
1940-
makeArrayAttr(ctx, clauses.inReductionSyms), clauses.priority,
1938+
TaskOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars,
19411939
makeArrayAttr(ctx, clauses.dependKinds), clauses.dependVars,
1942-
clauses.allocateVars, clauses.allocatorVars,
1943-
/*private_vars=*/{}, /*private_syms=*/nullptr);
1940+
clauses.final, clauses.ifVar, clauses.inReductionVars,
1941+
makeDenseBoolArrayAttr(ctx, clauses.inReductionByref),
1942+
makeArrayAttr(ctx, clauses.inReductionSyms), clauses.mergeable,
1943+
clauses.priority, /*private_vars=*/{}, /*private_syms=*/nullptr,
1944+
clauses.untied);
19441945
}
19451946

19461947
LogicalResult TaskOp::verify() {

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ func.func @omp_teams_allocate(%data_var : memref<i32>) {
13941394
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
13951395
"omp.teams" (%data_var) ({
13961396
omp.terminator
1397-
}) {operandSegmentSizes = array<i32: 0,0,0,0,1,0,0,0>} : (memref<i32>) -> ()
1397+
}) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0>} : (memref<i32>) -> ()
13981398
omp.terminator
13991399
}
14001400
return
@@ -1407,7 +1407,7 @@ func.func @omp_teams_num_teams1(%lb : i32) {
14071407
// expected-error @below {{expected num_teams upper bound to be defined if the lower bound is defined}}
14081408
"omp.teams" (%lb) ({
14091409
omp.terminator
1410-
}) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0>} : (i32) -> ()
1410+
}) {operandSegmentSizes = array<i32: 0,0,0,1,0,0,0,0>} : (i32) -> ()
14111411
omp.terminator
14121412
}
14131413
return
@@ -1432,7 +1432,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () {
14321432
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
14331433
"omp.sections" (%data_var) ({
14341434
omp.terminator
1435-
}) {operandSegmentSizes = array<i32: 0,1,0,0>} : (memref<i32>) -> ()
1435+
}) {operandSegmentSizes = array<i32: 1,0,0,0>} : (memref<i32>) -> ()
14361436
return
14371437
}
14381438

@@ -1442,7 +1442,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () {
14421442
// expected-error @below {{expected as many reduction symbol references as reduction variables}}
14431443
"omp.sections" (%data_var) ({
14441444
omp.terminator
1445-
}) {operandSegmentSizes = array<i32: 1,0,0,0>} : (memref<i32>) -> ()
1445+
}) {operandSegmentSizes = array<i32: 0,0,0,1>} : (memref<i32>) -> ()
14461446
return
14471447
}
14481448

@@ -1623,7 +1623,7 @@ func.func @omp_task_depend(%data_var: memref<i32>) {
16231623
// expected-error @below {{op expected as many depend values as depend variables}}
16241624
"omp.task"(%data_var) ({
16251625
"omp.terminator"() : () -> ()
1626-
}) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 0, 0, 1, 0, 0, 0>} : (memref<i32>) -> ()
1626+
}) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0>} : (memref<i32>) -> ()
16271627
"func.return"() : () -> ()
16281628
}
16291629

@@ -2137,7 +2137,7 @@ func.func @omp_target_depend(%data_var: memref<i32>) {
21372137

21382138
func.func @omp_distribute_schedule(%chunk_size : i32) -> () {
21392139
// expected-error @below {{op chunk size set without dist_schedule_static being present}}
2140-
"omp.distribute"(%chunk_size) <{operandSegmentSizes = array<i32: 1, 0, 0, 0>}> ({
2140+
"omp.distribute"(%chunk_size) <{operandSegmentSizes = array<i32: 0, 0, 1, 0>}> ({
21412141
"omp.terminator"() : () -> ()
21422142
}) : (i32) -> ()
21432143
}
@@ -2146,7 +2146,7 @@ func.func @omp_distribute_schedule(%chunk_size : i32) -> () {
21462146

21472147
func.func @omp_distribute_allocate(%data_var : memref<i32>) -> () {
21482148
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
2149-
"omp.distribute"(%data_var) <{operandSegmentSizes = array<i32: 0, 1, 0, 0>}> ({
2149+
"omp.distribute"(%data_var) <{operandSegmentSizes = array<i32: 1, 0, 0, 0>}> ({
21502150
"omp.terminator"() : () -> ()
21512151
}) : (memref<i32>) -> ()
21522152
}
@@ -2340,7 +2340,7 @@ func.func @undefined_privatizer(%arg0: index) {
23402340
// -----
23412341
func.func @undefined_privatizer(%arg0: !llvm.ptr) {
23422342
// expected-error @below {{inconsistent number of private variables and privatizer op symbols, private vars: 1 vs. privatizer op symbols: 2}}
2343-
"omp.parallel"(%arg0) <{operandSegmentSizes = array<i32: 0, 0, 0, 0, 0, 1>, private_syms = [@x.privatizer, @y.privatizer]}> ({
2343+
"omp.parallel"(%arg0) <{operandSegmentSizes = array<i32: 0, 0, 0, 0, 1, 0>, private_syms = [@x.privatizer, @y.privatizer]}> ({
23442344
^bb0(%arg2: !llvm.ptr):
23452345
omp.terminator
23462346
}) : (!llvm.ptr) -> ()

0 commit comments

Comments
 (0)