Skip to content

Commit 975a0d7

Browse files
committed
Emit a proper error message for CFG in workshare
1 parent e56dbd6 commit 975a0d7

File tree

4 files changed

+55
-43
lines changed

4 files changed

+55
-43
lines changed

flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19+
#include "flang/Optimizer/Builder/Todo.h"
1920
#include <flang/Optimizer/Builder/FIRBuilder.h>
2021
#include <flang/Optimizer/Dialect/FIROps.h>
2122
#include <flang/Optimizer/Dialect/FIRType.h>
@@ -416,8 +417,18 @@ LogicalResult lowerWorkshare(mlir::omp::WorkshareOp wsOp, DominanceInfo &di) {
416417

417418
parallelizeRegion(wsOp.getRegion(), newOp.getRegion(), rootMapping, loc, di);
418419

420+
// FIXME Currently, we only support workshare constructs with structured
421+
// control flow. The transformation itself supports CFG, however, once we
422+
// transform the MLIR region in the omp.workshare, we need to inline that
423+
// region in the parent block. We have no guarantees at this point of the
424+
// pipeline that the parent op supports CFG (e.g. fir.if), thus this is not
425+
// generally possible. The alternative is to put the lowered region in an
426+
// operation akin to scf.execute_region, which will get lowered at the same
427+
// time when fir ops get lowered to CFG. However, SCF is not registered in
428+
// flang so we cannot use it. Remove this requirement once we have
429+
// scf.execute_region or an alternative operation available.
419430
if (wsOp.getRegion().getBlocks().size() != 1)
420-
return failure();
431+
TODO(wsOp->getLoc(), "omp workshare with unstructured control flow");
421432

422433
// Inline the contents of the placeholder workshare op into its parent block.
423434
Block *theBlock = &newOp.getRegion().front();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: fir-opt --lower-workshare --allow-unregistered-dialect %s 2>&1 | FileCheck %s
2+
3+
// CHECK: not yet implemented: omp workshare with unstructured control flow
4+
5+
// Check that the definition of %r dominates its use post-transform
6+
func.func @wsfunc() {
7+
%a = fir.alloca i32
8+
omp.parallel {
9+
omp.workshare {
10+
^bb1:
11+
%c1 = arith.constant 1 : i32
12+
cf.br ^bb3(%c1: i32)
13+
^bb2:
14+
"test.test2"(%r) : (i32) -> ()
15+
omp.terminator
16+
^bb3(%arg1: i32):
17+
%r = "test.test2"(%arg1) : (i32) -> i32
18+
cf.br ^bb2
19+
}
20+
omp.terminator
21+
}
22+
return
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: fir-opt --lower-workshare --allow-unregistered-dialect %s 2>&1 | FileCheck %s
2+
3+
// CHECK: not yet implemented: omp workshare with unstructured control flow
4+
5+
// Check transforming a simple CFG
6+
func.func @wsfunc() {
7+
%a = fir.alloca i32
8+
omp.parallel {
9+
omp.workshare {
10+
^bb1:
11+
%c1 = arith.constant 1 : i32
12+
cf.br ^bb3(%c1: i32)
13+
^bb3(%arg1: i32):
14+
"test.test2"(%arg1) : (i32) -> ()
15+
omp.terminator
16+
}
17+
omp.terminator
18+
}
19+
return
20+
}

flang/test/Transforms/OpenMP/lower-workshare5.mlir

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)