aboutsummaryrefslogtreecommitdiff
path: root/flang/examples
diff options
context:
space:
mode:
authorJosh Mottley <josh.mottley@arm.com>2021-10-20 12:20:25 +0000
committerJosh Mottley <Josh.Mottley@arm.com>2021-11-04 14:23:50 +0000
commit2aec2549e8e52f57bc9e9b082be06ece69be61ad (patch)
tree707c0737fdb5e016fb3fdfac9fc9c16a0aa36237 /flang/examples
parent7323d07483f201b2d73009deef45d2eff4dcd856 (diff)
downloadllvm-2aec2549e8e52f57bc9e9b082be06ece69be61ad.zip
llvm-2aec2549e8e52f57bc9e9b082be06ece69be61ad.tar.gz
llvm-2aec2549e8e52f57bc9e9b082be06ece69be61ad.tar.bz2
[flang][flang-omp-report] Remove the loop workarounds for nowait clause
In a "Worksharing-loop construct", one can add a nowait clause at the end of the loop (i.e. at the loop tail). This clause wasn't associated with the corresponding loop when originally worked on in flang-omp-report. Note that this refers to parsing and parse-tree generation. To work around it, it was needed to track such clauses and the loops. This should no longer be required (and in fact no longer works) and so was removed. This results in 'curLoopLogRecord' and 'loopLogRecordStack' and all references to them being removed. This also allows for 'constructClauses' to be swapped from std::deque to llvm::SmallVector. Lastly a new test has been added testing the "nowait" clauses in a variety of ways. Reviewed By: awarzynski, kiranchandramohan Differential Revision: https://reviews.llvm.org/D112217
Diffstat (limited to 'flang/examples')
-rw-r--r--flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp44
-rw-r--r--flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h17
-rw-r--r--flang/examples/flang-omp-report-plugin/flang-omp-report.cpp4
3 files changed, 4 insertions, 61 deletions
diff --git a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
index f49e72f..32dcef2 100644
--- a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
+++ b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
@@ -156,11 +156,6 @@ bool OpenMPCounterVisitor::Pre(const OpenMPConstruct &c) {
ompWrapperStack.push_back(ow);
return true;
}
-bool OpenMPCounterVisitor::Pre(const OmpEndLoopDirective &c) { return true; }
-bool OpenMPCounterVisitor::Pre(const DoConstruct &) {
- loopLogRecordStack.push_back(curLoopLogRecord);
- return true;
-}
void OpenMPCounterVisitor::Post(const OpenMPDeclarativeConstruct &) {
PostConstructsCommon();
@@ -178,27 +173,11 @@ void OpenMPCounterVisitor::PostConstructsCommon() {
clauseStrings[curConstruct]};
constructClauses.push_back(r);
- // Keep track of loop log records if it can potentially have the
- // nowait clause added on later.
- if (const auto *oc = std::get_if<const OpenMPConstruct *>(curConstruct)) {
- if (const auto *olc = std::get_if<OpenMPLoopConstruct>(&(*oc)->u)) {
- const auto &beginLoopDir{
- std::get<Fortran::parser::OmpBeginLoopDirective>(olc->t)};
- const auto &beginDir{
- std::get<Fortran::parser::OmpLoopDirective>(beginLoopDir.t)};
- if (beginDir.v == llvm::omp::Directive::OMPD_do ||
- beginDir.v == llvm::omp::Directive::OMPD_do_simd) {
- curLoopLogRecord = &constructClauses.back();
- }
- }
- }
-
auto it = clauseStrings.find(curConstruct);
clauseStrings.erase(it);
ompWrapperStack.pop_back();
delete curConstruct;
}
-void OpenMPCounterVisitor::Post(const OmpEndLoopDirective &c) {}
void OpenMPCounterVisitor::Post(const OmpProcBindClause::Type &c) {
clauseDetails += "type=" + OmpProcBindClause::EnumToString(c) + ";";
@@ -242,26 +221,9 @@ void OpenMPCounterVisitor::Post(const OmpClause &c) {
clauseDetails.clear();
}
void OpenMPCounterVisitor::PostClauseCommon(const ClauseInfo &ci) {
- // The end loop construct (!$omp end do) can contain a nowait clause.
- // The flang parser does not parse the end loop construct as part of
- // the OpenMP construct for the loop construct. So the end loop is left
- // hanging as a separate executable construct. If a nowait clause is seen in
- // an end loop construct we have to find the associated loop construct and
- // add nowait to its list of clauses. Note: This is not a bug in flang, the
- // parse tree is corrected during semantic analysis.
- if (ci.clause == "nowait") {
- assert(curLoopLogRecord &&
- "loop Construct should be visited before a nowait clause");
- curLoopLogRecord->clauses.push_back(ci);
- } else {
- assert(!ompWrapperStack.empty() &&
- "Construct should be visited before clause");
- clauseStrings[ompWrapperStack.back()].push_back(ci);
- }
-}
-void OpenMPCounterVisitor::Post(const DoConstruct &) {
- curLoopLogRecord = loopLogRecordStack.back();
- loopLogRecordStack.pop_back();
+ assert(
+ !ompWrapperStack.empty() && "Construct should be visited before clause");
+ clauseStrings[ompWrapperStack.back()].push_back(ci);
}
} // namespace parser
} // namespace Fortran
diff --git a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h
index 188e8f9..d31fa8cc 100644
--- a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h
+++ b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h
@@ -17,7 +17,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
-#include <deque>
#include <string>
namespace Fortran {
@@ -62,13 +61,10 @@ struct OpenMPCounterVisitor {
template <typename A> void Post(const A &) {}
bool Pre(const OpenMPDeclarativeConstruct &c);
bool Pre(const OpenMPConstruct &c);
- bool Pre(const OmpEndLoopDirective &c);
- bool Pre(const DoConstruct &);
void Post(const OpenMPDeclarativeConstruct &);
void Post(const OpenMPConstruct &);
void PostConstructsCommon();
- void Post(const OmpEndLoopDirective &c);
void Post(const OmpProcBindClause::Type &c);
void Post(const OmpDefaultClause::Type &c);
@@ -83,20 +79,9 @@ struct OpenMPCounterVisitor {
void Post(const OmpCancelType::Type &c);
void Post(const OmpClause &c);
void PostClauseCommon(const ClauseInfo &ci);
- void Post(const DoConstruct &);
std::string clauseDetails{""};
-
- // curLoopLogRecord and loopLogRecordStack store
- // pointers to this datastructure's entries. Hence a
- // vector cannot be used since pointers are invalidated
- // on resize. Next best option seems to be deque. Also a
- // list cannot be used since YAML gen requires a
- // datastructure which can be accessed through indices.
- std::deque<LogRecord> constructClauses;
-
- LogRecord *curLoopLogRecord{nullptr};
- llvm::SmallVector<LogRecord *> loopLogRecordStack;
+ llvm::SmallVector<LogRecord> constructClauses;
llvm::SmallVector<OmpWrapperType *> ompWrapperStack;
llvm::DenseMap<OmpWrapperType *, llvm::SmallVector<ClauseInfo>> clauseStrings;
Parsing *parsing{nullptr};
diff --git a/flang/examples/flang-omp-report-plugin/flang-omp-report.cpp b/flang/examples/flang-omp-report-plugin/flang-omp-report.cpp
index 0654513..9ee8eb1 100644
--- a/flang/examples/flang-omp-report-plugin/flang-omp-report.cpp
+++ b/flang/examples/flang-omp-report-plugin/flang-omp-report.cpp
@@ -33,10 +33,6 @@ namespace llvm {
namespace yaml {
using llvm::yaml::IO;
using llvm::yaml::MappingTraits;
-template <typename T>
-struct SequenceTraits<std::deque<T>,
- std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
- : SequenceTraitsImpl<std::deque<T>, SequenceElementTraits<T>::flow> {};
template <> struct MappingTraits<ClauseInfo> {
static void mapping(IO &io, ClauseInfo &info) {
io.mapRequired("clause", info.clause);