This is an archive of the discontinued LLVM Phabricator instance.

[flang][OpenMP] Check for occurrence of multiple list items in nontemporal clause for simd directive
ClosedPublic

Authored by arnamoy10 on Sep 22 2021, 10:22 AM.

Details

Summary

This patch implements the following semantic check:

A list-item cannot appear in more than one nontemporal clause.

Diff Detail

Event Timeline

arnamoy10 created this revision.Sep 22 2021, 10:22 AM
arnamoy10 requested review of this revision.Sep 22 2021, 10:22 AM
Herald added a project: Restricted Project. · View Herald Transcript
kiranchandramohan requested changes to this revision.Sep 23 2021, 1:57 AM

Thanks @arnamoy10 for this patch. A few comments.

flang/lib/Semantics/check-omp-structure.cpp
176

Move this close to its use. Use braced initialization in all places (here, the line above, for loop variable etc).

184–192

Can you make this a lambda function that takes in a list of variables, with listvars declared inside the lambda and an argument (pass ALIGNED or NONTEMPORAL to it)?

189

Should this break be removed to capture all errors?
!$omp simd nontemporal(a,a,b,b)

This revision now requires changes to proceed.Sep 23 2021, 1:57 AM
arnamoy10 added inline comments.Oct 5 2021, 6:27 AM
flang/lib/Semantics/check-omp-structure.cpp
184–192

Thanks for the comment. I was creating a lambda as per your suggestion and passing alignedClauses/ nonTemporalClauses as the argument and another argument to denote whether we are processing ALIGNED or NONTEMPORAL.

However, in that lambda, how do I declare a generic variable, which will be defined as the following pseudocode based on the passed argument? It cannot be auto e.g. the following will not work.

auto &Clause;
if (arg == ALIGNED) 
  Clause = std::get<parser::OmpClause::Aligned>(itr->second->u)};
else
  Clause = std::get<parser::OmpClause::Aligned>(itr->second->u)};

What will be the type of Clause in this case?

Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 6:27 AM
flang/lib/Semantics/check-omp-structure.cpp
184–192

I think the lambda at that level might not work since templates are not properly supported for lambdas in C++17. I was thinking something like the following (templated functions) will work. It can be called as checkMultiple<parser::OmpClause::Aligned>(*itr, "ALIGNED"). But I see that there is some difference in the way the namelist is constructed. So there are additional checks or conditions required.

const auto &alignedNameList{std::get<std::list<parser::Name>>(alignedClause.v.t)};
const auto &nontempNameList{nontempClause.v};
  template<typename C, typename V>
void checkMultiple(const V &v, const std::string &clauseName) {

    semantics::UnorderedSymbolSet listVars;
  auto checkMultipleOcurrence = [&](const std::list<parser::Name>& nameList, const parser::CharBlock& item) {
    for (auto const &var : nameList) {
      if (listVars.count(*(var.symbol)) == 1) {
        context_.Say(item,
            "List item '%s' present at multiple %s clauses"_err_en_US,
            var.ToString(), clauseName);
        break;
      }
      listVars.insert(*(var.symbol));
    }
  };
    const auto &alignedClause{
        std::get<C>(v.second->u)};
    const auto &alignedNameList{
        std::get<std::list<parser::Name>>(alignedClause.v.t)};
    checkMultipleOcurrence(alignedNameList, v.second->source);

}

Instead, you can try the lambda checkMultipleOcurrence that is there in the function above. I think this is what I suggested.

arnamoy10 updated this revision to Diff 395224.Dec 17 2021, 2:56 PM

Addressing reviewers comments:

  1. Use of lambda
  2. Enhancing the check by not breaking from the loop
  3. Adding a test case to catch the above case
flang/lib/Semantics/check-omp-structure.cpp
184–192

Thank you. However, we could not fit the alignedClause and `alignedNameList' inside the helper because at compile time, the namelist construction could not be controlled. Still used a lambda, please check the updated patch.

Patch LGTM (once @kiranchandramohan's comments have been addressed ). Please run git-clang-format HEAD~ to format.
Also, please rebase with main, it has been long.

flang/lib/Semantics/check-omp-structure.cpp
177

llvm::is_contained?

arnamoy10 updated this revision to Diff 417076.Mar 21 2022, 1:36 PM

@shraiysh Thanks for the comments. I have already addressed @kiranchandramohan 's comments as much as I could. If you are OK, can you please accept this patch, because Kiran might be busy. Thank you

Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2022, 1:36 PM

LGTM. Apologies for the long delay.

This revision is now accepted and ready to land.Mar 24 2022, 10:14 AM
shraiysh accepted this revision.Apr 13 2022, 5:49 AM

Looks good to me. Thank you!

arnamoy10 updated this revision to Diff 432915.May 30 2022, 7:07 AM

Rebase before land