Skip to content

Commit 00cba1e

Browse files
committed
[NFC][mlir][OpenMP] Remove mentions of target from generic loop rewrite
This removes mentions of `target` from the generic `loop` rewrite pass since there is not need for it anyway. It is enough to detect `loop`'s nesting within `teams` or `parallel` directives.
1 parent 3a4376b commit 00cba1e

File tree

3 files changed

+61
-84
lines changed

3 files changed

+61
-84
lines changed

flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ namespace {
2929
class GenericLoopConversionPattern
3030
: public mlir::OpConversionPattern<mlir::omp::LoopOp> {
3131
public:
32-
enum class GenericLoopCombinedInfo {
33-
Standalone,
34-
TargetTeamsLoop,
35-
TargetParallelLoop
36-
};
32+
enum class GenericLoopCombinedInfo { Standalone, TeamsLoop, ParallelLoop };
3733

3834
using mlir::OpConversionPattern<mlir::omp::LoopOp>::OpConversionPattern;
3935

@@ -55,10 +51,10 @@ class GenericLoopConversionPattern
5551
case GenericLoopCombinedInfo::Standalone:
5652
rewriteStandaloneLoop(loopOp, rewriter);
5753
break;
58-
case GenericLoopCombinedInfo::TargetParallelLoop:
59-
llvm_unreachable("not yet implemented: `parallel loop` direcitve");
54+
case GenericLoopCombinedInfo::ParallelLoop:
55+
llvm_unreachable("not yet implemented: Combined `parallel loop` directive");
6056
break;
61-
case GenericLoopCombinedInfo::TargetTeamsLoop:
57+
case GenericLoopCombinedInfo::TeamsLoop:
6258
rewriteToDistributeParallelDo(loopOp, rewriter);
6359
break;
6460
}
@@ -74,10 +70,10 @@ class GenericLoopConversionPattern
7470
switch (combinedInfo) {
7571
case GenericLoopCombinedInfo::Standalone:
7672
break;
77-
case GenericLoopCombinedInfo::TargetParallelLoop:
73+
case GenericLoopCombinedInfo::ParallelLoop:
7874
return loopOp.emitError(
79-
"not yet implemented: Combined `omp target parallel loop` directive");
80-
case GenericLoopCombinedInfo::TargetTeamsLoop:
75+
"not yet implemented: Combined `parallel loop` directive");
76+
case GenericLoopCombinedInfo::TeamsLoop:
8177
break;
8278
}
8379

@@ -99,7 +95,7 @@ class GenericLoopConversionPattern
9995
if (!loopOp.getReductionVars().empty())
10096
return todo("reduction");
10197

102-
// TODO For `target teams loop`, check similar constrains to what is checked
98+
// TODO For `teams loop`, check similar constrains to what is checked
10399
// by `TeamsLoopChecker` in SemaOpenMP.cpp.
104100
return mlir::success();
105101
}
@@ -111,13 +107,11 @@ class GenericLoopConversionPattern
111107
GenericLoopCombinedInfo result = GenericLoopCombinedInfo::Standalone;
112108

113109
if (auto teamsOp = mlir::dyn_cast_if_present<mlir::omp::TeamsOp>(parentOp))
114-
if (mlir::isa_and_present<mlir::omp::TargetOp>(teamsOp->getParentOp()))
115-
result = GenericLoopCombinedInfo::TargetTeamsLoop;
110+
result = GenericLoopCombinedInfo::TeamsLoop;
116111

117112
if (auto parallelOp =
118113
mlir::dyn_cast_if_present<mlir::omp::ParallelOp>(parentOp))
119-
if (mlir::isa_and_present<mlir::omp::TargetOp>(parallelOp->getParentOp()))
120-
result = GenericLoopCombinedInfo::TargetParallelLoop;
114+
result = GenericLoopCombinedInfo::ParallelLoop;
121115

122116
return result;
123117
}

flang/test/Transforms/generic-loop-rewriting-todo.mlir

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
// RUN: fir-opt --omp-generic-loop-conversion -verify-diagnostics %s
22

3-
func.func @_QPtarget_parallel_loop() {
4-
omp.target {
5-
omp.parallel {
6-
%c0 = arith.constant 0 : i32
7-
%c10 = arith.constant 10 : i32
8-
%c1 = arith.constant 1 : i32
9-
// expected-error@below {{not yet implemented: Combined `omp target parallel loop` directive}}
10-
omp.loop {
11-
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
12-
omp.yield
13-
}
3+
func.func @_QPparallel_loop() {
4+
omp.parallel {
5+
%c0 = arith.constant 0 : i32
6+
%c10 = arith.constant 10 : i32
7+
%c1 = arith.constant 1 : i32
8+
// expected-error@below {{not yet implemented: Combined `parallel loop` directive}}
9+
omp.loop {
10+
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
11+
omp.yield
1412
}
15-
omp.terminator
1613
}
1714
omp.terminator
1815
}
1916
return
2017
}
2118

22-
func.func @_QPtarget_loop_bind() {
23-
omp.target {
24-
omp.teams {
25-
%c0 = arith.constant 0 : i32
26-
%c10 = arith.constant 10 : i32
27-
%c1 = arith.constant 1 : i32
28-
// expected-error@below {{not yet implemented: Unhandled clause bind in omp.loop operation}}
29-
omp.loop bind(thread) {
30-
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
31-
omp.yield
32-
}
19+
func.func @_QPloop_bind() {
20+
omp.teams {
21+
%c0 = arith.constant 0 : i32
22+
%c10 = arith.constant 10 : i32
23+
%c1 = arith.constant 1 : i32
24+
// expected-error@below {{not yet implemented: Unhandled clause bind in omp.loop operation}}
25+
omp.loop bind(thread) {
26+
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
27+
omp.yield
3328
}
34-
omp.terminator
3529
}
3630
omp.terminator
3731
}
@@ -48,22 +42,18 @@ omp.declare_reduction @add_reduction_i32 : i32 init {
4842
omp.yield(%0 : i32)
4943
}
5044

51-
func.func @_QPtarget_loop_order() {
45+
func.func @_QPloop_order() {
46+
omp.teams {
47+
%c0 = arith.constant 0 : i32
48+
%c10 = arith.constant 10 : i32
49+
%c1 = arith.constant 1 : i32
50+
%sum = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_orderEi"}
5251

53-
omp.target {
54-
omp.teams {
55-
%c0 = arith.constant 0 : i32
56-
%c10 = arith.constant 10 : i32
57-
%c1 = arith.constant 1 : i32
58-
%sum = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_orderEi"}
59-
60-
// expected-error@below {{not yet implemented: Unhandled clause reduction in omp.loop operation}}
61-
omp.loop reduction(@add_reduction_i32 %sum -> %arg2 : !fir.ref<i32>) {
62-
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
63-
omp.yield
64-
}
52+
// expected-error@below {{not yet implemented: Unhandled clause reduction in omp.loop operation}}
53+
omp.loop reduction(@add_reduction_i32 %sum -> %arg2 : !fir.ref<i32>) {
54+
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
55+
omp.yield
6556
}
66-
omp.terminator
6757
}
6858
omp.terminator
6959
}

flang/test/Transforms/generic-loop-rewriting.mlir

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,48 @@
11
// RUN: fir-opt --omp-generic-loop-conversion %s | FileCheck %s
22

3-
omp.private {type = private} @_QFtarget_teams_loopEi_private_ref_i32 : !fir.ref<i32> alloc {
3+
omp.private {type = private} @_QFteams_loopEi_private_ref_i32 : !fir.ref<i32> alloc {
44
^bb0(%arg0: !fir.ref<i32>):
55
omp.yield(%arg0 : !fir.ref<i32>)
66
}
77

8-
func.func @_QPtarget_teams_loop() {
8+
func.func @_QPteams_loop() {
99
%i = fir.alloca i32
10-
%i_map = omp.map.info var_ptr(%i : !fir.ref<i32>, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !fir.ref<i32> {name = "i"}
11-
omp.target map_entries(%i_map -> %arg0 : !fir.ref<i32>) {
12-
omp.teams {
13-
%c0 = arith.constant 0 : i32
14-
%c10 = arith.constant 10 : i32
15-
%c1 = arith.constant 1 : i32
16-
omp.loop private(@_QFtarget_teams_loopEi_private_ref_i32 %arg0 -> %arg2 : !fir.ref<i32>) {
17-
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
18-
fir.store %arg3 to %arg2 : !fir.ref<i32>
19-
omp.yield
20-
}
10+
omp.teams {
11+
%c0 = arith.constant 0 : i32
12+
%c10 = arith.constant 10 : i32
13+
%c1 = arith.constant 1 : i32
14+
omp.loop private(@_QFteams_loopEi_private_ref_i32 %i -> %arg2 : !fir.ref<i32>) {
15+
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
16+
fir.store %arg3 to %arg2 : !fir.ref<i32>
17+
omp.yield
2118
}
22-
omp.terminator
2319
}
2420
omp.terminator
2521
}
2622
return
2723
}
2824

29-
// CHECK-LABEL: func.func @_QPtarget_teams_loop
30-
// CHECK: omp.target map_entries(
31-
// CHECK-SAME: %{{.*}} -> %[[I_ARG:[^[:space:]]+]] : {{.*}}) {
32-
//
33-
// CHECK: omp.teams {
25+
// CHECK-LABEL: func.func @_QPteams_loop
26+
// CHECK: %[[I:.*]] = fir.alloca i32
27+
// CHECK: omp.teams {
3428
//
3529
// TODO we probably need to move the `loop_nest` bounds ops from the `teams`
3630
// region to the `parallel` region to avoid making these values `shared`. We can
3731
// find the backward slices of these bounds that are within the `teams` region
3832
// and move these slices to the `parallel` op.
3933

40-
// CHECK: %[[LB:.*]] = arith.constant 0 : i32
41-
// CHECK: %[[UB:.*]] = arith.constant 10 : i32
42-
// CHECK: %[[STEP:.*]] = arith.constant 1 : i32
34+
// CHECK: %[[LB:.*]] = arith.constant 0 : i32
35+
// CHECK: %[[UB:.*]] = arith.constant 10 : i32
36+
// CHECK: %[[STEP:.*]] = arith.constant 1 : i32
4337
//
44-
// CHECK: omp.parallel private(@{{.*}} %[[I_ARG]]
45-
// CHECK-SAME: -> %[[I_PRIV_ARG:[^[:space:]]+]] : !fir.ref<i32>) {
46-
// CHECK: omp.distribute {
47-
// CHECK: omp.wsloop {
38+
// CHECK: omp.parallel private(@{{.*}} %[[I]]
39+
// CHECK-SAME: -> %[[I_PRIV_ARG:[^[:space:]]+]] : !fir.ref<i32>) {
40+
// CHECK: omp.distribute {
41+
// CHECK: omp.wsloop {
4842
//
49-
// CHECK: omp.loop_nest (%{{.*}}) : i32 =
50-
// CHECK-SAME: (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
51-
// CHECK: fir.store %{{.*}} to %[[I_PRIV_ARG]] : !fir.ref<i32>
52-
// CHECK: }
43+
// CHECK: omp.loop_nest (%{{.*}}) : i32 =
44+
// CHECK-SAME: (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
45+
// CHECK: fir.store %{{.*}} to %[[I_PRIV_ARG]] : !fir.ref<i32>
5346
// CHECK: }
5447
// CHECK: }
5548
// CHECK: }

0 commit comments

Comments
 (0)