Skip to content

Commit 2d09a69

Browse files
committed
Add more mlir tests. Set collapse value when lowering from SCF to OpenMP.
1 parent 753653d commit 2d09a69

File tree

5 files changed

+92
-2
lines changed

5 files changed

+92
-2
lines changed

mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ struct ParallelOpLowering : public OpRewritePattern<scf::ParallelOp> {
493493
// Create loop nest and populate region with contents of scf.parallel.
494494
auto loopOp = rewriter.create<omp::LoopNestOp>(
495495
parallelOp.getLoc(), parallelOp.getLowerBound(),
496-
parallelOp.getUpperBound(), parallelOp.getStep(), false, 1,
496+
parallelOp.getUpperBound(), parallelOp.getStep(), false,
497+
parallelOp.getLowerBound().size(),
497498
nullptr);
498499

499500
rewriter.inlineRegionBefore(parallelOp.getRegion(), loopOp.getRegion(),

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,18 @@ LogicalResult LoopNestOp::verify() {
30413041
<< "range argument type does not match corresponding IV type";
30423042
}
30433043

3044+
uint64_t numIVs = getIVs().size();
3045+
3046+
if (const auto &numCollapse = getNumCollapse())
3047+
if (numCollapse > numIVs)
3048+
return emitOpError()
3049+
<< "collapse value is larger than the number of loops";
3050+
3051+
if (const auto &tiles = getTileSizes())
3052+
if (tiles.value().size() > numIVs)
3053+
return emitOpError()
3054+
<< "number of tilings is larger than the number of loops";
3055+
30443056
if (!llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp()))
30453057
return emitOpError() << "expects parent op to be a loop wrapper";
30463058

mlir/test/Conversion/SCFToOpenMP/scf-to-openmp.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func.func @parallel(%arg0: index, %arg1: index, %arg2: index,
66
// CHECK: %[[FOUR:.+]] = llvm.mlir.constant(4 : i32) : i32
77
// CHECK: omp.parallel num_threads(%[[FOUR]] : i32) {
88
// CHECK: omp.wsloop {
9-
// CHECK: omp.loop_nest (%[[LVAR1:.*]], %[[LVAR2:.*]]) : index = (%arg0, %arg1) to (%arg2, %arg3) step (%arg4, %arg5) {
9+
// CHECK: omp.loop_nest (%[[LVAR1:.*]], %[[LVAR2:.*]]) : index = (%arg0, %arg1) to (%arg2, %arg3) step (%arg4, %arg5) collapse(2) {
1010
// CHECK: memref.alloca_scope
1111
scf.parallel (%i, %j) = (%arg0, %arg1) to (%arg2, %arg3) step (%arg4, %arg5) {
1212
// CHECK: "test.payload"(%[[LVAR1]], %[[LVAR2]]) : (index, index) -> ()

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ func.func @no_loops(%lb : index, %ub : index, %step : index) {
157157
}
158158
}
159159

160+
// -----
161+
162+
func.func @collapse_size(%lb : index, %ub : index, %step : index) {
163+
omp.wsloop {
164+
// expected-error@+1 {{collapse value is larger than the number of loops}}
165+
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) collapse(4) {
166+
omp.yield
167+
}
168+
}
169+
}
170+
171+
// -----
172+
173+
func.func @tiles_length(%lb : index, %ub : index, %step : index) {
174+
omp.wsloop {
175+
// expected-error@+1 {{number of tilings is larger than the number of loops}}
176+
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) tiles(2, 4) {
177+
omp.yield
178+
}
179+
}
180+
}
181+
182+
160183
// -----
161184

162185
func.func @inclusive_not_a_clause(%lb : index, %ub : index, %step : index) {

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,60 @@ func.func @omp_loop_nest_pretty_multiple(%lb1 : i32, %ub1 : i32, %step1 : i32,
376376
return
377377
}
378378

379+
// CHECK-LABEL: omp_loop_nest_pretty_multiple_collapse
380+
func.func @omp_loop_nest_pretty_multiple_collapse(%lb1 : i32, %ub1 : i32, %step1 : i32,
381+
%lb2 : i32, %ub2 : i32, %step2 : i32, %data1 : memref<?xi32>) -> () {
382+
383+
omp.wsloop {
384+
// CHECK: omp.loop_nest (%{{.*}}, %{{.*}}) : i32 = (%{{.*}}, %{{.*}}) to (%{{.*}}, %{{.*}}) step (%{{.*}}, %{{.*}}) collapse(2)
385+
omp.loop_nest (%iv1, %iv2) : i32 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) collapse(2) {
386+
%1 = "test.payload"(%iv1) : (i32) -> (index)
387+
%2 = "test.payload"(%iv2) : (i32) -> (index)
388+
memref.store %iv1, %data1[%1] : memref<?xi32>
389+
memref.store %iv2, %data1[%2] : memref<?xi32>
390+
omp.yield
391+
}
392+
}
393+
394+
return
395+
}
396+
397+
// CHECK-LABEL: omp_loop_nest_pretty_multiple_tiles
398+
func.func @omp_loop_nest_pretty_multiple_tiles(%lb1 : i32, %ub1 : i32, %step1 : i32,
399+
%lb2 : i32, %ub2 : i32, %step2 : i32, %data1 : memref<?xi32>) -> () {
400+
401+
omp.wsloop {
402+
// CHECK: omp.loop_nest (%{{.*}}, %{{.*}}) : i32 = (%{{.*}}, %{{.*}}) to (%{{.*}}, %{{.*}}) step (%{{.*}}, %{{.*}}) tiles(5, 10)
403+
omp.loop_nest (%iv1, %iv2) : i32 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) tiles(5, 10) {
404+
%1 = "test.payload"(%iv1) : (i32) -> (index)
405+
%2 = "test.payload"(%iv2) : (i32) -> (index)
406+
memref.store %iv1, %data1[%1] : memref<?xi32>
407+
memref.store %iv2, %data1[%2] : memref<?xi32>
408+
omp.yield
409+
}
410+
}
411+
412+
return
413+
}
414+
415+
// CHECK-LABEL: omp_loop_nest_pretty_multiple_collapse_tiles
416+
func.func @omp_loop_nest_pretty_multiple_collapse_tiles(%lb1 : i32, %ub1 : i32, %step1 : i32,
417+
%lb2 : i32, %ub2 : i32, %step2 : i32, %data1 : memref<?xi32>) -> () {
418+
419+
omp.wsloop {
420+
// CHECK: omp.loop_nest (%{{.*}}, %{{.*}}) : i32 = (%{{.*}}, %{{.*}}) to (%{{.*}}, %{{.*}}) step (%{{.*}}, %{{.*}}) collapse(2) tiles(5, 10)
421+
omp.loop_nest (%iv1, %iv2) : i32 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) collapse(2) tiles(5, 10) {
422+
%1 = "test.payload"(%iv1) : (i32) -> (index)
423+
%2 = "test.payload"(%iv2) : (i32) -> (index)
424+
memref.store %iv1, %data1[%1] : memref<?xi32>
425+
memref.store %iv2, %data1[%2] : memref<?xi32>
426+
omp.yield
427+
}
428+
}
429+
430+
return
431+
}
432+
379433
// CHECK-LABEL: omp_wsloop
380434
func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memref<i32>, %linear_var : i32, %chunk_var : i32) -> () {
381435

0 commit comments

Comments
 (0)