Skip to content

Commit a59c703

Browse files
committed
Revert "Remove cancel and cancellation point verifiers entirely"
This reverts commit da8639e.
1 parent da8639e commit a59c703

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,8 @@ def CancelOp : OpenMP_Op<"cancel", clauses = [
16551655
let builders = [
16561656
OpBuilder<(ins CArg<"const CancelOperands &">:$clauses)>
16571657
];
1658+
1659+
let hasVerifier = 1;
16581660
}
16591661

16601662
//===----------------------------------------------------------------------===//
@@ -1673,6 +1675,8 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
16731675
let builders = [
16741676
OpBuilder<(ins CArg<"const CancellationPointOperands &">:$clauses)>
16751677
];
1678+
1679+
let hasVerifier = 1;
16761680
}
16771681

16781682
def ScanOp : OpenMP_Op<"scan", [

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,6 +3101,46 @@ void CancelOp::build(OpBuilder &builder, OperationState &state,
31013101
CancelOp::build(builder, state, clauses.cancelDirective, clauses.ifExpr);
31023102
}
31033103

3104+
LogicalResult CancelOp::verify() {
3105+
ClauseCancellationConstructType cct = getCancelDirective();
3106+
Operation *thisOp = (*this).getOperation();
3107+
3108+
if ((cct == ClauseCancellationConstructType::Parallel) &&
3109+
!thisOp->getParentOfType<ParallelOp>()) {
3110+
return emitOpError() << "cancel parallel must appear "
3111+
<< "inside a parallel region";
3112+
}
3113+
if (cct == ClauseCancellationConstructType::Loop) {
3114+
auto wsloopOp = thisOp->getParentOfType<WsloopOp>();
3115+
3116+
if (!wsloopOp) {
3117+
return emitOpError()
3118+
<< "cancel loop must appear inside a worksharing-loop region";
3119+
}
3120+
if (wsloopOp.getNowaitAttr()) {
3121+
return emitError() << "A worksharing construct that is canceled "
3122+
<< "must not have a nowait clause";
3123+
}
3124+
if (wsloopOp.getOrderedAttr()) {
3125+
return emitError() << "A worksharing construct that is canceled "
3126+
<< "must not have an ordered clause";
3127+
}
3128+
3129+
} else if (cct == ClauseCancellationConstructType::Sections) {
3130+
auto sectionsOp = thisOp->getParentOfType<SectionsOp>();
3131+
if (!sectionsOp) {
3132+
return emitOpError() << "cancel sections must appear "
3133+
<< "inside a sections region";
3134+
}
3135+
if (sectionsOp.getNowait()) {
3136+
return emitError() << "A sections construct that is canceled "
3137+
<< "must not have a nowait clause";
3138+
}
3139+
}
3140+
// TODO : Add more when we support taskgroup.
3141+
return success();
3142+
}
3143+
31043144
//===----------------------------------------------------------------------===//
31053145
// CancellationPointOp
31063146
//===----------------------------------------------------------------------===//
@@ -3110,6 +3150,29 @@ void CancellationPointOp::build(OpBuilder &builder, OperationState &state,
31103150
CancellationPointOp::build(builder, state, clauses.cancelDirective);
31113151
}
31123152

3153+
LogicalResult CancellationPointOp::verify() {
3154+
ClauseCancellationConstructType cct = getCancelDirective();
3155+
Operation *thisOp = (*this).getOperation();
3156+
3157+
if ((cct == ClauseCancellationConstructType::Parallel) &&
3158+
!thisOp->getParentOfType<ParallelOp>()) {
3159+
return emitOpError() << "cancellation point parallel must appear "
3160+
<< "inside a parallel region";
3161+
}
3162+
if ((cct == ClauseCancellationConstructType::Loop) &&
3163+
!thisOp->getParentOfType<WsloopOp>()) {
3164+
return emitOpError() << "cancellation point loop must appear "
3165+
<< "inside a worksharing-loop region";
3166+
}
3167+
if ((cct == ClauseCancellationConstructType::Sections) &&
3168+
!thisOp->getParentOfType<SectionsOp>()) {
3169+
return emitOpError() << "cancellation point sections must appear "
3170+
<< "inside a sections region";
3171+
}
3172+
// TODO : Add more when we support taskgroup.
3173+
return success();
3174+
}
3175+
31133176
//===----------------------------------------------------------------------===//
31143177
// MapBoundsOp
31153178
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,121 @@ func.func @omp_task(%mem: memref<1xf32>) {
17101710

17111711
// -----
17121712

1713+
func.func @omp_cancel() {
1714+
omp.sections {
1715+
// expected-error @below {{cancel parallel must appear inside a parallel region}}
1716+
omp.cancel cancellation_construct_type(parallel)
1717+
// CHECK: omp.terminator
1718+
omp.terminator
1719+
}
1720+
return
1721+
}
1722+
1723+
// -----
1724+
1725+
func.func @omp_cancel1() {
1726+
omp.parallel {
1727+
// expected-error @below {{cancel sections must appear inside a sections region}}
1728+
omp.cancel cancellation_construct_type(sections)
1729+
// CHECK: omp.terminator
1730+
omp.terminator
1731+
}
1732+
return
1733+
}
1734+
1735+
// -----
1736+
1737+
func.func @omp_cancel2() {
1738+
omp.sections {
1739+
// expected-error @below {{cancel loop must appear inside a worksharing-loop region}}
1740+
omp.cancel cancellation_construct_type(loop)
1741+
// CHECK: omp.terminator
1742+
omp.terminator
1743+
}
1744+
return
1745+
}
1746+
1747+
// -----
1748+
1749+
func.func @omp_cancel3(%arg1 : i32, %arg2 : i32, %arg3 : i32) -> () {
1750+
omp.wsloop nowait {
1751+
omp.loop_nest (%0) : i32 = (%arg1) to (%arg2) step (%arg3) {
1752+
// expected-error @below {{A worksharing construct that is canceled must not have a nowait clause}}
1753+
omp.cancel cancellation_construct_type(loop)
1754+
// CHECK: omp.yield
1755+
omp.yield
1756+
}
1757+
}
1758+
return
1759+
}
1760+
1761+
// -----
1762+
1763+
func.func @omp_cancel4(%arg1 : i32, %arg2 : i32, %arg3 : i32) -> () {
1764+
omp.wsloop ordered(1) {
1765+
omp.loop_nest (%0) : i32 = (%arg1) to (%arg2) step (%arg3) {
1766+
// expected-error @below {{A worksharing construct that is canceled must not have an ordered clause}}
1767+
omp.cancel cancellation_construct_type(loop)
1768+
// CHECK: omp.yield
1769+
omp.yield
1770+
}
1771+
}
1772+
return
1773+
}
1774+
1775+
// -----
1776+
1777+
func.func @omp_cancel5() -> () {
1778+
omp.sections nowait {
1779+
omp.section {
1780+
// expected-error @below {{A sections construct that is canceled must not have a nowait clause}}
1781+
omp.cancel cancellation_construct_type(sections)
1782+
omp.terminator
1783+
}
1784+
// CHECK: omp.terminator
1785+
omp.terminator
1786+
}
1787+
return
1788+
}
1789+
1790+
// -----
1791+
1792+
func.func @omp_cancellationpoint() {
1793+
omp.sections {
1794+
// expected-error @below {{cancellation point parallel must appear inside a parallel region}}
1795+
omp.cancellation_point cancellation_construct_type(parallel)
1796+
// CHECK: omp.terminator
1797+
omp.terminator
1798+
}
1799+
return
1800+
}
1801+
1802+
// -----
1803+
1804+
func.func @omp_cancellationpoint1() {
1805+
omp.parallel {
1806+
// expected-error @below {{cancellation point sections must appear inside a sections region}}
1807+
omp.cancellation_point cancellation_construct_type(sections)
1808+
// CHECK: omp.terminator
1809+
omp.terminator
1810+
}
1811+
return
1812+
}
1813+
1814+
// -----
1815+
1816+
func.func @omp_cancellationpoint2() {
1817+
omp.sections {
1818+
// expected-error @below {{cancellation point loop must appear inside a worksharing-loop region}}
1819+
omp.cancellation_point cancellation_construct_type(loop)
1820+
// CHECK: omp.terminator
1821+
omp.terminator
1822+
}
1823+
return
1824+
}
1825+
1826+
// -----
1827+
17131828
omp.declare_reduction @add_f32 : f32
17141829
init {
17151830
^bb0(%arg: f32):

0 commit comments

Comments
 (0)