Skip to content

Commit 8180edd

Browse files
committed
[MLIR][OpenMP] Split region-associated op verification
This patch moves the part of operation verifiers dependent on the contents of their regions to the corresponding `verifyRegions` method. This ensures these are only triggered after the operations in the region have themselved already been verified in advance, avoiding checks based on invalid nested operations. The `LoopWrapperInterface` is also updated so that its verifier runs after operations in the region of ops with this interface have already been verified.
1 parent c76045d commit 8180edd

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove, RecipeInterface]>
137137
}
138138
}];
139139

140-
let hasVerifier = 1;
140+
let hasRegionVerifier = 1;
141141
}
142142

143143
//===----------------------------------------------------------------------===//
@@ -175,6 +175,7 @@ def ParallelOp : OpenMP_Op<"parallel", traits = [
175175
}];
176176

177177
let hasVerifier = 1;
178+
let hasRegionVerifier = 1;
178179
}
179180

180181
def TerminatorOp : OpenMP_Op<"terminator", [Terminator, Pure]> {
@@ -426,6 +427,7 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
426427
}];
427428

428429
let hasVerifier = 1;
430+
let hasRegionVerifier = 1;
429431
}
430432

431433
//===----------------------------------------------------------------------===//
@@ -479,6 +481,7 @@ def SimdOp : OpenMP_Op<"simd", traits = [
479481
}];
480482

481483
let hasVerifier = 1;
484+
let hasRegionVerifier = 1;
482485
}
483486

484487

@@ -556,6 +559,7 @@ def DistributeOp : OpenMP_Op<"distribute", traits = [
556559
}];
557560

558561
let hasVerifier = 1;
562+
let hasRegionVerifier = 1;
559563
}
560564

561565
//===----------------------------------------------------------------------===//
@@ -693,6 +697,7 @@ def TaskloopOp : OpenMP_Op<"taskloop", traits = [
693697
}] # clausesExtraClassDeclaration;
694698

695699
let hasVerifier = 1;
700+
let hasRegionVerifier = 1;
696701
}
697702

698703
def TaskgroupOp : OpenMP_Op<"taskgroup", traits = [

mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
258258
let verify = [{
259259
return ::llvm::cast<::mlir::omp::LoopWrapperInterface>($_op).verifyImpl();
260260
}];
261+
let verifyWithRegions = 1;
261262
}
262263

263264
def ComposableOpInterface : OpInterface<"ComposableOpInterface"> {

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,18 @@ static LogicalResult verifyPrivateVarList(OpType &op) {
17601760
}
17611761

17621762
LogicalResult ParallelOp::verify() {
1763+
if (getAllocateVars().size() != getAllocatorVars().size())
1764+
return emitError(
1765+
"expected equal sizes for allocate and allocator variables");
1766+
1767+
if (failed(verifyPrivateVarList(*this)))
1768+
return failure();
1769+
1770+
return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(),
1771+
getReductionByref());
1772+
}
1773+
1774+
LogicalResult ParallelOp::verifyRegions() {
17631775
auto distributeChildOps = getOps<DistributeOp>();
17641776
if (!distributeChildOps.empty()) {
17651777
if (!isComposite())
@@ -1780,16 +1792,7 @@ LogicalResult ParallelOp::verify() {
17801792
return emitError()
17811793
<< "'omp.composite' attribute present in non-composite operation";
17821794
}
1783-
1784-
if (getAllocateVars().size() != getAllocatorVars().size())
1785-
return emitError(
1786-
"expected equal sizes for allocate and allocator variables");
1787-
1788-
if (failed(verifyPrivateVarList(*this)))
1789-
return failure();
1790-
1791-
return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(),
1792-
getReductionByref());
1795+
return success();
17931796
}
17941797

17951798
//===----------------------------------------------------------------------===//
@@ -1979,6 +1982,11 @@ void WsloopOp::build(OpBuilder &builder, OperationState &state,
19791982
}
19801983

19811984
LogicalResult WsloopOp::verify() {
1985+
return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(),
1986+
getReductionByref());
1987+
}
1988+
1989+
LogicalResult WsloopOp::verifyRegions() {
19821990
bool isCompositeChildLeaf =
19831991
llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp());
19841992

@@ -2000,8 +2008,7 @@ LogicalResult WsloopOp::verify() {
20002008
<< "'omp.composite' attribute missing from composite wrapper";
20012009
}
20022010

2003-
return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(),
2004-
getReductionByref());
2011+
return success();
20052012
}
20062013

20072014
//===----------------------------------------------------------------------===//
@@ -2035,9 +2042,6 @@ LogicalResult SimdOp::verify() {
20352042
if (verifyNontemporalClause(*this, getNontemporalVars()).failed())
20362043
return failure();
20372044

2038-
if (getNestedWrapper())
2039-
return emitOpError() << "must wrap an 'omp.loop_nest' directly";
2040-
20412045
bool isCompositeChildLeaf =
20422046
llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp());
20432047

@@ -2052,6 +2056,13 @@ LogicalResult SimdOp::verify() {
20522056
return success();
20532057
}
20542058

2059+
LogicalResult SimdOp::verifyRegions() {
2060+
if (getNestedWrapper())
2061+
return emitOpError() << "must wrap an 'omp.loop_nest' directly";
2062+
2063+
return success();
2064+
}
2065+
20552066
//===----------------------------------------------------------------------===//
20562067
// Distribute construct [2.9.4.1]
20572068
//===----------------------------------------------------------------------===//
@@ -2074,6 +2085,10 @@ LogicalResult DistributeOp::verify() {
20742085
return emitError(
20752086
"expected equal sizes for allocate and allocator variables");
20762087

2088+
return success();
2089+
}
2090+
2091+
LogicalResult DistributeOp::verifyRegions() {
20772092
if (LoopWrapperInterface nested = getNestedWrapper()) {
20782093
if (!isComposite())
20792094
return emitError()
@@ -2279,6 +2294,10 @@ LogicalResult TaskloopOp::verify() {
22792294
"may not appear on the same taskloop directive");
22802295
}
22812296

2297+
return success();
2298+
}
2299+
2300+
LogicalResult TaskloopOp::verifyRegions() {
22822301
if (LoopWrapperInterface nested = getNestedWrapper()) {
22832302
if (!isComposite())
22842303
return emitError()
@@ -2723,7 +2742,7 @@ void PrivateClauseOp::build(OpBuilder &odsBuilder, OperationState &odsState,
27232742
DataSharingClauseType::Private));
27242743
}
27252744

2726-
LogicalResult PrivateClauseOp::verify() {
2745+
LogicalResult PrivateClauseOp::verifyRegions() {
27272746
Type symType = getType();
27282747

27292748
auto verifyTerminator = [&](Operation *terminator,

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ func.func @invalid_nested_wrapper(%lb : index, %ub : index, %step : index) {
136136
// expected-error @below {{only supported nested wrapper is 'omp.simd'}}
137137
omp.wsloop {
138138
omp.distribute {
139-
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
140-
omp.yield
141-
}
139+
omp.simd {
140+
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
141+
omp.yield
142+
}
143+
} {omp.composite}
142144
} {omp.composite}
143145
} {omp.composite}
144146
}
@@ -1975,7 +1977,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) {
19751977
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
19761978
omp.yield
19771979
}
1978-
} {omp.composite}
1980+
}
19791981
} {omp.composite}
19801982
return
19811983
}
@@ -2188,7 +2190,7 @@ func.func @omp_distribute_nested_wrapper2(%lb: index, %ub: index, %step: index)
21882190
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
21892191
"omp.yield"() : () -> ()
21902192
}
2191-
}) {omp.composite} : () -> ()
2193+
}) : () -> ()
21922194
} {omp.composite}
21932195
}
21942196

0 commit comments

Comments
 (0)