[PATCH] D106165: [flang][OpenMP] Add semantic check for target nesting

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 30 08:21:32 PDT 2021


kiranchandramohan requested changes to this revision.
kiranchandramohan added a comment.
This revision now requires changes to proceed.

Looks OK. I have a question and a suggestion. Please make the change if you agree otherwise let me know.



================
Comment at: flang/lib/Semantics/check-omp-structure.cpp:481
+  // 2.12.5 Target Construct Restriction
+  bool eligibleTarget{true};
+  llvm::omp::Directive directive;
----------------
Nit:Would eligibleTargetDir be better?


================
Comment at: flang/lib/Semantics/check-omp-structure.cpp:291
     }
+    if (GetTARGETNest() > 0) {
+      CheckTARGETNest(x);
----------------
peixin wrote:
> kiranchandramohan wrote:
> > peixin wrote:
> > > clementval wrote:
> > > > It would be better to have a generic `IsNestedIn` function where you can pass the directive you want to check for. We don't want to have a counter for each construct. 
> > > I am thinking about if we can replace this for loop search with the counter marked for `target` nesting since the for loop is executed for each openmp construct check, which is not efficient. With the design in https://reviews.llvm.org/D106335, I only need add one more element in the enum definition of `directiveNestType`. What do you think?
> > That sounds good to me.
> > 
> > I think ideally, you can do the following.
> > On visiting a target_data, target_update, target_enter_data or target_exit_data directive check if it is nested in a target region using GetDirectiveNest and report a warning if it is nested.
> Thanks for the suggestion. Fixed now.
I was suggesting something like the following to avoid double traversal of OpenMPBlockConstruct. We would be visiting these nodes anyway during regular traversal.
Have you considered this? Feel free to dissent.
```
void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
  const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(c.t)};
  const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
   if (GetDirectiveNest(TargetNest) > 0) {
     if (beginDir.v == llvm::omp::Directive::OMPD_target_data) {
       //print warning
     }
}
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106165/new/

https://reviews.llvm.org/D106165



More information about the llvm-commits mailing list