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
22namespace Fortran {
23namespace parser {
24struct 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>(in: p)}, clauseDetails{std::get<1>(in: p)} {}
32};
33bool operator<(const ClauseInfo &a, const ClauseInfo &b);
34bool operator==(const ClauseInfo &a, const ClauseInfo &b);
35bool operator!=(const ClauseInfo &a, const ClauseInfo &b);
36
37struct LogRecord {
38 std::string file;
39 int line;
40 std::string construct;
41 llvm::SmallVector<ClauseInfo> clauses;
42};
43bool operator==(const LogRecord &a, const LogRecord &b);
44bool operator!=(const LogRecord &a, const LogRecord &b);
45
46using OmpWrapperType =
47 std::variant<const OpenMPConstruct *, const OpenMPDeclarativeConstruct *>;
48
49struct 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::Type &c);
70 void Post(const OmpDefaultClause::Type &c);
71 void Post(const OmpDefaultmapClause::ImplicitBehavior &c);
72 void Post(const OmpDefaultmapClause::VariableCategory &c);
73 void Post(const OmpDeviceTypeClause::Type &c);
74 void Post(const OmpScheduleModifierType::ModType &c);
75 void Post(const OmpLinearModifier::Type &c);
76 void Post(const OmpDependenceType::Type &c);
77 void Post(const OmpMapType::Type &c);
78 void Post(const OmpScheduleClause::ScheduleType &c);
79 void Post(const OmpIfClause::DirectiveNameModifier &c);
80 void Post(const OmpCancelType::Type &c);
81 void Post(const OmpClause &c);
82 void PostClauseCommon(const ClauseInfo &ci);
83
84 std::string clauseDetails;
85 llvm::SmallVector<LogRecord> constructClauses;
86 llvm::SmallVector<OmpWrapperType *> ompWrapperStack;
87 llvm::DenseMap<OmpWrapperType *, llvm::SmallVector<ClauseInfo>> clauseStrings;
88 Parsing *parsing{nullptr};
89};
90} // namespace parser
91} // namespace Fortran
92
93#endif /* FORTRAN_FLANG_OMP_REPORT_VISITOR_H */
94

source code of flang/examples/FlangOmpReport/FlangOmpReportVisitor.h