Skip to content

Commit ba8cf35

Browse files
committed
[OpenMP][MLIR] Set omp.composite attr for composite loop wrappers and add verifier checks
This patch sets the omp.composite unit attr for composite wrapper ops and also add appropriate checks to the verifiers of supported ops for the presence/absence of the attribute.
1 parent 047dea1 commit ba8cf35

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,10 +2063,14 @@ static void genCompositeDistributeSimd(
20632063
// TODO: Populate entry block arguments with private variables.
20642064
auto distributeOp = genWrapperOp<mlir::omp::DistributeOp>(
20652065
converter, loc, distributeClauseOps, /*blockArgTypes=*/{});
2066+
llvm::cast<mlir::omp::ComposableOpInterface>(distributeOp.getOperation())
2067+
.setComposite(/*val=*/true);
20662068

20672069
// TODO: Populate entry block arguments with reduction and private variables.
20682070
auto simdOp = genWrapperOp<mlir::omp::SimdOp>(converter, loc, simdClauseOps,
20692071
/*blockArgTypes=*/{});
2072+
llvm::cast<mlir::omp::ComposableOpInterface>(simdOp.getOperation())
2073+
.setComposite(/*val=*/true);
20702074

20712075
// Construct wrapper entry block list and associated symbols. It is important
20722076
// that the symbol order and the block argument order match, so that the
@@ -2111,10 +2115,14 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
21112115
// TODO: Add private variables to entry block arguments.
21122116
auto wsloopOp = genWrapperOp<mlir::omp::WsloopOp>(
21132117
converter, loc, wsloopClauseOps, wsloopReductionTypes);
2118+
llvm::cast<mlir::omp::ComposableOpInterface>(wsloopOp.getOperation())
2119+
.setComposite(/*val=*/true);
21142120

21152121
// TODO: Populate entry block arguments with reduction and private variables.
21162122
auto simdOp = genWrapperOp<mlir::omp::SimdOp>(converter, loc, simdClauseOps,
21172123
/*blockArgTypes=*/{});
2124+
llvm::cast<mlir::omp::ComposableOpInterface>(simdOp.getOperation())
2125+
.setComposite(/*val=*/true);
21182126

21192127
// Construct wrapper entry block list and associated symbols. It is important
21202128
// that the symbol and block argument order match, so that the symbol-value

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,9 @@ LogicalResult ParallelOp::verify() {
15461546
if (!isWrapper())
15471547
return emitOpError() << "must take a loop wrapper role if nested inside "
15481548
"of 'omp.distribute'";
1549+
if (!llvm::cast<ComposableOpInterface>(getOperation()).isComposite())
1550+
return emitError()
1551+
<< "'omp.composite' attribute missing from composite wrapper";
15491552

15501553
if (LoopWrapperInterface nested = getNestedWrapper()) {
15511554
// Check for the allowed leaf constructs that may appear in a composite
@@ -1555,6 +1558,9 @@ LogicalResult ParallelOp::verify() {
15551558
} else {
15561559
return emitOpError() << "must not wrap an 'omp.loop_nest' directly";
15571560
}
1561+
} else if (llvm::cast<ComposableOpInterface>(getOperation()).isComposite()) {
1562+
return emitError()
1563+
<< "'omp.composite' attribute present in non-composite wrapper";
15581564
}
15591565

15601566
if (getAllocateVars().size() != getAllocatorVars().size())
@@ -1749,10 +1755,18 @@ LogicalResult WsloopOp::verify() {
17491755
return emitOpError() << "must be a loop wrapper";
17501756

17511757
if (LoopWrapperInterface nested = getNestedWrapper()) {
1758+
if (!llvm::cast<ComposableOpInterface>(getOperation()).isComposite())
1759+
return emitError()
1760+
<< "'omp.composite' attribute missing from composite wrapper";
1761+
17521762
// Check for the allowed leaf constructs that may appear in a composite
17531763
// construct directly after DO/FOR.
17541764
if (!isa<SimdOp>(nested))
17551765
return emitError() << "only supported nested wrapper is 'omp.simd'";
1766+
1767+
} else if (llvm::cast<ComposableOpInterface>(getOperation()).isComposite()) {
1768+
return emitError()
1769+
<< "'omp.composite' attribute present in non-composite wrapper";
17561770
}
17571771

17581772
return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(),
@@ -1796,6 +1810,10 @@ LogicalResult SimdOp::verify() {
17961810
if (getNestedWrapper())
17971811
return emitOpError() << "must wrap an 'omp.loop_nest' directly";
17981812

1813+
if (llvm::cast<ComposableOpInterface>(getOperation()).isComposite())
1814+
return emitError()
1815+
<< "'omp.composite' attribute present in non-composite wrapper";
1816+
17991817
return success();
18001818
}
18011819

@@ -1825,11 +1843,17 @@ LogicalResult DistributeOp::verify() {
18251843
return emitOpError() << "must be a loop wrapper";
18261844

18271845
if (LoopWrapperInterface nested = getNestedWrapper()) {
1846+
if (!llvm::cast<ComposableOpInterface>(getOperation()).isComposite())
1847+
return emitError()
1848+
<< "'omp.composite' attribute missing from composite wrapper";
18281849
// Check for the allowed leaf constructs that may appear in a composite
18291850
// construct directly after DISTRIBUTE.
18301851
if (!isa<ParallelOp, SimdOp>(nested))
18311852
return emitError() << "only supported nested wrappers are 'omp.parallel' "
18321853
"and 'omp.simd'";
1854+
} else if (llvm::cast<ComposableOpInterface>(getOperation()).isComposite()) {
1855+
return emitError()
1856+
<< "'omp.composite' attribute present in non-composite wrapper";
18331857
}
18341858

18351859
return success();
@@ -2031,11 +2055,19 @@ LogicalResult TaskloopOp::verify() {
20312055
return emitOpError() << "must be a loop wrapper";
20322056

20332057
if (LoopWrapperInterface nested = getNestedWrapper()) {
2058+
if (!llvm::cast<ComposableOpInterface>(getOperation()).isComposite())
2059+
return emitError()
2060+
<< "'omp.composite' attribute missing from composite wrapper";
2061+
20342062
// Check for the allowed leaf constructs that may appear in a composite
20352063
// construct directly after TASKLOOP.
20362064
if (!isa<SimdOp>(nested))
20372065
return emitError() << "only supported nested wrapper is 'omp.simd'";
2066+
} else if (llvm::cast<ComposableOpInterface>(getOperation()).isComposite()) {
2067+
return emitError()
2068+
<< "'omp.composite' attribute present in non-composite wrapper";
20382069
}
2070+
20392071
return success();
20402072
}
20412073

0 commit comments

Comments
 (0)