@@ -1964,21 +1964,51 @@ LogicalResult CriticalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1964
1964
// Ordered construct
1965
1965
// ===----------------------------------------------------------------------===//
1966
1966
1967
+ static LogicalResult verifyOrderedParent (Operation &op) {
1968
+ bool hasRegion = op.getNumRegions () > 0 ;
1969
+ auto loopOp = op.getParentOfType <LoopNestOp>();
1970
+ if (!loopOp) {
1971
+ if (hasRegion)
1972
+ return success ();
1973
+
1974
+ // TODO: Consider if this needs to be the case only for the standalone
1975
+ // variant of the ordered construct.
1976
+ return op.emitOpError () << " must be nested inside of a loop" ;
1977
+ }
1978
+
1979
+ Operation *wrapper = loopOp->getParentOp ();
1980
+ if (auto wsloopOp = dyn_cast<WsloopOp>(wrapper)) {
1981
+ IntegerAttr orderedAttr = wsloopOp.getOrderedValAttr ();
1982
+ if (!orderedAttr)
1983
+ return op.emitOpError () << " the enclosing worksharing-loop region must "
1984
+ " have an ordered clause" ;
1985
+
1986
+ if (hasRegion && orderedAttr.getInt () != 0 )
1987
+ return op.emitOpError () << " the enclosing loop's ordered clause must not "
1988
+ " have a parameter present" ;
1989
+
1990
+ if (!hasRegion && orderedAttr.getInt () == 0 )
1991
+ return op.emitOpError () << " the enclosing loop's ordered clause must "
1992
+ " have a parameter present" ;
1993
+ } else if (!isa<SimdOp>(wrapper)) {
1994
+ return op.emitOpError () << " must be nested inside of a worksharing, simd "
1995
+ " or worksharing simd loop" ;
1996
+ }
1997
+ return success ();
1998
+ }
1999
+
1967
2000
void OrderedOp::build (OpBuilder &builder, OperationState &state,
1968
2001
const OrderedOpClauseOps &clauses) {
1969
2002
OrderedOp::build (builder, state, clauses.doacrossDependTypeAttr ,
1970
2003
clauses.doacrossNumLoopsAttr , clauses.doacrossVectorVars );
1971
2004
}
1972
2005
1973
2006
LogicalResult OrderedOp::verify () {
1974
- auto container = (*this )->getParentOfType <WsloopOp>();
1975
- if (!container || !container.getOrderedValAttr () ||
1976
- container.getOrderedValAttr ().getInt () == 0 )
1977
- return emitOpError () << " ordered depend directive must be closely "
1978
- << " nested inside a worksharing-loop with ordered "
1979
- << " clause with parameter present" ;
1980
-
1981
- if (container.getOrderedValAttr ().getInt () != (int64_t )*getNumLoopsVal ())
2007
+ if (failed (verifyOrderedParent (**this )))
2008
+ return failure ();
2009
+
2010
+ auto wrapper = (*this )->getParentOfType <WsloopOp>();
2011
+ if (!wrapper || *wrapper.getOrderedVal () != *getNumLoopsVal ())
1982
2012
return emitOpError () << " number of variables in depend clause does not "
1983
2013
<< " match number of iteration variables in the "
1984
2014
<< " doacross loop" ;
@@ -1996,15 +2026,7 @@ LogicalResult OrderedRegionOp::verify() {
1996
2026
if (getSimd ())
1997
2027
return failure ();
1998
2028
1999
- if (auto container = (*this )->getParentOfType <WsloopOp>()) {
2000
- if (!container.getOrderedValAttr () ||
2001
- container.getOrderedValAttr ().getInt () != 0 )
2002
- return emitOpError () << " ordered region must be closely nested inside "
2003
- << " a worksharing-loop region with an ordered "
2004
- << " clause without parameter present" ;
2005
- }
2006
-
2007
- return success ();
2029
+ return verifyOrderedParent (**this );
2008
2030
}
2009
2031
2010
2032
// ===----------------------------------------------------------------------===//
@@ -2149,15 +2171,19 @@ LogicalResult CancelOp::verify() {
2149
2171
<< " inside a parallel region" ;
2150
2172
}
2151
2173
if (cct == ClauseCancellationConstructType::Loop) {
2152
- if (!isa<WsloopOp>(parentOp)) {
2153
- return emitOpError () << " cancel loop must appear "
2154
- << " inside a worksharing-loop region" ;
2174
+ auto loopOp = dyn_cast<LoopNestOp>(parentOp);
2175
+ auto wsloopOp = llvm::dyn_cast_if_present<WsloopOp>(
2176
+ loopOp ? loopOp->getParentOp () : nullptr );
2177
+
2178
+ if (!wsloopOp) {
2179
+ return emitOpError ()
2180
+ << " cancel loop must appear inside a worksharing-loop region" ;
2155
2181
}
2156
- if (cast<WsloopOp>(parentOp) .getNowaitAttr ()) {
2182
+ if (wsloopOp .getNowaitAttr ()) {
2157
2183
return emitError () << " A worksharing construct that is canceled "
2158
2184
<< " must not have a nowait clause" ;
2159
2185
}
2160
- if (cast<WsloopOp>(parentOp) .getOrderedValAttr ()) {
2186
+ if (wsloopOp .getOrderedValAttr ()) {
2161
2187
return emitError () << " A worksharing construct that is canceled "
2162
2188
<< " must not have an ordered clause" ;
2163
2189
}
@@ -2195,7 +2221,7 @@ LogicalResult CancellationPointOp::verify() {
2195
2221
<< " inside a parallel region" ;
2196
2222
}
2197
2223
if ((cct == ClauseCancellationConstructType::Loop) &&
2198
- !isa<WsloopOp>(parentOp)) {
2224
+ ( !isa<LoopNestOp>(parentOp) || !isa< WsloopOp>(parentOp-> getParentOp ()) )) {
2199
2225
return emitOpError () << " cancellation point loop must appear "
2200
2226
<< " inside a worksharing-loop region" ;
2201
2227
}
0 commit comments