@@ -3975,6 +3975,58 @@ llvm::LogicalResult omp::TargetAllocMemOp::verify() {
39753975 return mlir::success ();
39763976}
39773977
3978+ // ===----------------------------------------------------------------------===//
3979+ // WorkdistributeOp
3980+ // ===----------------------------------------------------------------------===//
3981+
3982+ LogicalResult WorkdistributeOp::verify () {
3983+ // Check that region exists and is not empty
3984+ Region ®ion = getRegion ();
3985+ if (region.empty ())
3986+ return emitOpError (" region cannot be empty" );
3987+ // Verify single entry point.
3988+ Block &entryBlock = region.front ();
3989+ if (entryBlock.empty ())
3990+ return emitOpError (" region must contain a structured block" );
3991+ // Verify single exit point.
3992+ bool hasTerminator = false ;
3993+ for (Block &block : region) {
3994+ if (isa<TerminatorOp>(block.back ())) {
3995+ if (hasTerminator) {
3996+ return emitOpError (" region must have exactly one terminator" );
3997+ }
3998+ hasTerminator = true ;
3999+ }
4000+ }
4001+ if (!hasTerminator) {
4002+ return emitOpError (" region must be terminated with omp.terminator" );
4003+ }
4004+ auto walkResult = region.walk ([&](Operation *op) -> WalkResult {
4005+ // No implicit barrier at end
4006+ if (isa<BarrierOp>(op)) {
4007+ return emitOpError (
4008+ " explicit barriers are not allowed in workdistribute region" );
4009+ }
4010+ // Check for invalid nested constructs
4011+ if (isa<ParallelOp>(op)) {
4012+ return emitOpError (
4013+ " nested parallel constructs not allowed in workdistribute" );
4014+ }
4015+ if (isa<TeamsOp>(op)) {
4016+ return emitOpError (
4017+ " nested teams constructs not allowed in workdistribute" );
4018+ }
4019+ return WalkResult::advance ();
4020+ });
4021+ if (walkResult.wasInterrupted ())
4022+ return failure ();
4023+
4024+ Operation *parentOp = (*this )->getParentOp ();
4025+ if (!llvm::dyn_cast<TeamsOp>(parentOp))
4026+ return emitOpError (" workdistribute must be nested under teams" );
4027+ return success ();
4028+ }
4029+
39784030#define GET_ATTRDEF_CLASSES
39794031#include " mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
39804032
0 commit comments