@@ -118,6 +118,53 @@ static T getPerfectlyNested(Operation *op) {
118
118
return nullptr ;
119
119
}
120
120
121
+ // VerifyTargetTeamsWorkdistribute method verifies that
122
+ // omp.target { teams { workdistribute { ... } } } is well formed
123
+ // and fails for function calls that don't have lowering implemented yet.
124
+ static bool
125
+ VerifyTargetTeamsWorkdistribute (omp::WorkdistributeOp workdistribute) {
126
+ OpBuilder rewriter (workdistribute);
127
+ auto teams = dyn_cast<omp::TeamsOp>(workdistribute->getParentOp ());
128
+ if (!teams) {
129
+ workdistribute.emitError () << " workdistribute not nested in teams\n " ;
130
+ return false ;
131
+ }
132
+ if (workdistribute.getRegion ().getBlocks ().size () != 1 ) {
133
+ workdistribute.emitError () << " workdistribute with multiple blocks\n " ;
134
+ return false ;
135
+ }
136
+ if (teams.getRegion ().getBlocks ().size () != 1 ) {
137
+ workdistribute.emitError () << " teams with multiple blocks\n " ;
138
+ return false ;
139
+ }
140
+ omp::TargetOp targetOp = dyn_cast<omp::TargetOp>(teams->getParentOp ());
141
+ // return if not omp.target
142
+ if (!targetOp)
143
+ return true ;
144
+
145
+ for (auto &op : workdistribute.getOps ()) {
146
+ if (auto callOp = dyn_cast<fir::CallOp>(op)) {
147
+ if (isRuntimeCall (&op)) {
148
+ auto funcName = (*callOp.getCallee ()).getRootReference ().getValue ();
149
+ // _FortranAAssign is handled. Other runtime calls are not supported
150
+ // in omp.workdistribute yet.
151
+ if (funcName == " _FortranAAssign" )
152
+ continue ;
153
+ else
154
+ workdistribute.emitError ()
155
+ << " Runtime call " << funcName
156
+ << " lowering not supported for workdistribute yet." ;
157
+ return false ;
158
+ } else {
159
+ workdistribute.emitError () << " Non-runtime fir.call lowering not "
160
+ " supported in workdistribute yet." ;
161
+ return false ;
162
+ }
163
+ }
164
+ }
165
+ return true ;
166
+ }
167
+
121
168
// FissionWorkdistribute method finds the parallelizable ops
122
169
// within teams {workdistribute} region and moves them to their
123
170
// own teams{workdistribute} region.
@@ -154,18 +201,10 @@ static bool FissionWorkdistribute(omp::WorkdistributeOp workdistribute) {
154
201
OpBuilder rewriter (workdistribute);
155
202
auto loc = workdistribute->getLoc ();
156
203
auto teams = dyn_cast<omp::TeamsOp>(workdistribute->getParentOp ());
157
- if (!teams) {
158
- emitError (loc, " workdistribute not nested in teams\n " );
159
- return false ;
160
- }
161
- if (workdistribute.getRegion ().getBlocks ().size () != 1 ) {
162
- emitError (loc, " workdistribute with multiple blocks\n " );
163
- return false ;
164
- }
165
- if (teams.getRegion ().getBlocks ().size () != 1 ) {
166
- emitError (loc, " teams with multiple blocks\n " );
167
- return false ;
168
- }
204
+
205
+ omp::TargetOp targetOp;
206
+ // Get the target op parent of teams
207
+ targetOp = dyn_cast<omp::TargetOp>(teams->getParentOp ());
169
208
170
209
auto *teamsBlock = &teams.getRegion ().front ();
171
210
bool changed = false ;
@@ -1744,6 +1783,11 @@ class LowerWorkdistributePass
1744
1783
auto moduleOp = getOperation ();
1745
1784
bool changed = false ;
1746
1785
SetVector<omp::TargetOp> targetOpsToProcess;
1786
+ moduleOp->walk ([&](mlir::omp::WorkdistributeOp workdistribute) {
1787
+ bool res = VerifyTargetTeamsWorkdistribute (workdistribute);
1788
+ if (!res)
1789
+ signalPassFailure ();
1790
+ });
1747
1791
moduleOp->walk ([&](mlir::omp::WorkdistributeOp workdistribute) {
1748
1792
changed |= FissionWorkdistribute (workdistribute);
1749
1793
});
0 commit comments