Skip to content

Commit 4091bc6

Browse files
authored
[MLIR][OpenMP] Split region-associated op verification (#112355)
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 b584478 commit 4091bc6

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
//===----------------------------------------------------------------------===//
@@ -2037,9 +2044,6 @@ LogicalResult SimdOp::verify() {
20372044
if (verifyNontemporalClause(*this, getNontemporalVars()).failed())
20382045
return failure();
20392046

2040-
if (getNestedWrapper())
2041-
return emitOpError() << "must wrap an 'omp.loop_nest' directly";
2042-
20432047
bool isCompositeChildLeaf =
20442048
llvm::dyn_cast_if_present<LoopWrapperInterface>((*this)->getParentOp());
20452049

@@ -2054,6 +2058,13 @@ LogicalResult SimdOp::verify() {
20542058
return success();
20552059
}
20562060

2061+
LogicalResult SimdOp::verifyRegions() {
2062+
if (getNestedWrapper())
2063+
return emitOpError() << "must wrap an 'omp.loop_nest' directly";
2064+
2065+
return success();
2066+
}
2067+
20572068
//===----------------------------------------------------------------------===//
20582069
// Distribute construct [2.9.4.1]
20592070
//===----------------------------------------------------------------------===//
@@ -2076,6 +2087,10 @@ LogicalResult DistributeOp::verify() {
20762087
return emitError(
20772088
"expected equal sizes for allocate and allocator variables");
20782089

2090+
return success();
2091+
}
2092+
2093+
LogicalResult DistributeOp::verifyRegions() {
20792094
if (LoopWrapperInterface nested = getNestedWrapper()) {
20802095
if (!isComposite())
20812096
return emitError()
@@ -2281,6 +2296,10 @@ LogicalResult TaskloopOp::verify() {
22812296
"may not appear on the same taskloop directive");
22822297
}
22832298

2299+
return success();
2300+
}
2301+
2302+
LogicalResult TaskloopOp::verifyRegions() {
22842303
if (LoopWrapperInterface nested = getNestedWrapper()) {
22852304
if (!isComposite())
22862305
return emitError()
@@ -2725,7 +2744,7 @@ void PrivateClauseOp::build(OpBuilder &odsBuilder, OperationState &odsState,
27252744
DataSharingClauseType::Private));
27262745
}
27272746

2728-
LogicalResult PrivateClauseOp::verify() {
2747+
LogicalResult PrivateClauseOp::verifyRegions() {
27292748
Type symType = getType();
27302749

27312750
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)