xref: /llvm-project/flang/examples/FlangOmpReport/FlangOmpReportVisitor.h (revision 33faa8285f3dc5ca10e35770b288770b4bbc2bc1)
1 //===-- examples/flang-omp-report-plugin/flang-omp-report-visitor.h -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef FORTRAN_FLANG_OMP_REPORT_VISITOR_H
10 #define FORTRAN_FLANG_OMP_REPORT_VISITOR_H
11 
12 #include "flang/Parser/parse-tree-visitor.h"
13 #include "flang/Parser/parse-tree.h"
14 #include "flang/Parser/parsing.h"
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
19 
20 #include <string>
21 
22 namespace Fortran {
23 namespace parser {
24 struct ClauseInfo {
25   std::string clause;
26   std::string clauseDetails;
27   ClauseInfo() {}
28   ClauseInfo(const std::string &c, const std::string &cd)
29       : clause{c}, clauseDetails{cd} {}
30   ClauseInfo(const std::pair<std::string, std::string> &p)
31       : clause{std::get<0>(p)}, clauseDetails{std::get<1>(p)} {}
32 };
33 bool operator<(const ClauseInfo &a, const ClauseInfo &b);
34 bool operator==(const ClauseInfo &a, const ClauseInfo &b);
35 bool operator!=(const ClauseInfo &a, const ClauseInfo &b);
36 
37 struct LogRecord {
38   std::string file;
39   int line;
40   std::string construct;
41   llvm::SmallVector<ClauseInfo> clauses;
42 };
43 bool operator==(const LogRecord &a, const LogRecord &b);
44 bool operator!=(const LogRecord &a, const LogRecord &b);
45 
46 using OmpWrapperType =
47     std::variant<const OpenMPConstruct *, const OpenMPDeclarativeConstruct *>;
48 
49 struct OpenMPCounterVisitor {
50   std::string normalize_construct_name(std::string s);
51   ClauseInfo normalize_clause_name(const llvm::StringRef s);
52   SourcePosition getLocation(const OmpWrapperType &w);
53   SourcePosition getLocation(const OpenMPDeclarativeConstruct &c);
54   SourcePosition getLocation(const OpenMPConstruct &c);
55 
56   std::string getName(const OmpWrapperType &w);
57   std::string getName(const OpenMPDeclarativeConstruct &c);
58   std::string getName(const OpenMPConstruct &c);
59 
60   template <typename A> bool Pre(const A &) { return true; }
61   template <typename A> void Post(const A &) {}
62   bool Pre(const OpenMPDeclarativeConstruct &c);
63   bool Pre(const OpenMPConstruct &c);
64 
65   void Post(const OpenMPDeclarativeConstruct &);
66   void Post(const OpenMPConstruct &);
67   void PostConstructsCommon();
68 
69   void Post(const OmpProcBindClause::AffinityPolicy &c);
70   void Post(const OmpDefaultClause::DataSharingAttribute &c);
71   void Post(const OmpDefaultmapClause::ImplicitBehavior &c);
72   void Post(const OmpVariableCategory::Value &c);
73   void Post(const OmpDeviceTypeClause::DeviceTypeDescription &c);
74   void Post(const OmpChunkModifier::Value &c);
75   void Post(const OmpLinearModifier::Value &c);
76   void Post(const OmpOrderingModifier::Value &c);
77   void Post(const OmpTaskDependenceType::Value &c);
78   void Post(const OmpMapType::Value &c);
79   void Post(const OmpScheduleClause::Kind &c);
80   void Post(const OmpDirectiveNameModifier &c);
81   void Post(const OmpCancelType::Type &c);
82   void Post(const OmpClause &c);
83   void PostClauseCommon(const ClauseInfo &ci);
84 
85   std::string clauseDetails;
86   llvm::SmallVector<LogRecord> constructClauses;
87   llvm::SmallVector<OmpWrapperType *> ompWrapperStack;
88   llvm::DenseMap<OmpWrapperType *, llvm::SmallVector<ClauseInfo>> clauseStrings;
89   Parsing *parsing{nullptr};
90 };
91 } // namespace parser
92 } // namespace Fortran
93 
94 #endif /* FORTRAN_FLANG_OMP_REPORT_VISITOR_H */
95