1 | //===- Pass.h - TableGen pass definitions -----------------------*- C++ -*-===// |
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 MLIR_TABLEGEN_PASS_H_ |
10 | #define MLIR_TABLEGEN_PASS_H_ |
11 | |
12 | #include "mlir/Support/LLVM.h" |
13 | #include <vector> |
14 | |
15 | namespace llvm { |
16 | class Record; |
17 | } // namespace llvm |
18 | |
19 | namespace mlir { |
20 | namespace tblgen { |
21 | //===----------------------------------------------------------------------===// |
22 | // PassOption |
23 | //===----------------------------------------------------------------------===// |
24 | class PassOption { |
25 | public: |
26 | explicit PassOption(const llvm::Record *def) : def(def) {} |
27 | |
28 | /// Return the name for the C++ option variable. |
29 | StringRef getCppVariableName() const; |
30 | |
31 | /// Return the command line argument to use for this option. |
32 | StringRef getArgument() const; |
33 | |
34 | /// Return the C++ type of the option. |
35 | StringRef getType() const; |
36 | |
37 | /// Return the default value of the option. |
38 | std::optional<StringRef> getDefaultValue() const; |
39 | |
40 | /// Return the description for this option. |
41 | StringRef getDescription() const; |
42 | |
43 | /// Return the additional flags passed to the option constructor. |
44 | std::optional<StringRef> getAdditionalFlags() const; |
45 | |
46 | /// Flag indicating if this is a list option. |
47 | bool isListOption() const; |
48 | |
49 | private: |
50 | const llvm::Record *def; |
51 | }; |
52 | |
53 | //===----------------------------------------------------------------------===// |
54 | // PassStatistic |
55 | //===----------------------------------------------------------------------===// |
56 | class PassStatistic { |
57 | public: |
58 | explicit PassStatistic(const llvm::Record *def) : def(def) {} |
59 | |
60 | /// Return the name for the C++ statistic variable. |
61 | StringRef getCppVariableName() const; |
62 | |
63 | /// Return the name of the statistic. |
64 | StringRef getName() const; |
65 | |
66 | /// Return the description for this statistic. |
67 | StringRef getDescription() const; |
68 | |
69 | private: |
70 | const llvm::Record *def; |
71 | }; |
72 | |
73 | //===----------------------------------------------------------------------===// |
74 | // Pass |
75 | //===----------------------------------------------------------------------===// |
76 | |
77 | /// Wrapper class providing helper methods for Passes defined in TableGen. |
78 | class Pass { |
79 | public: |
80 | explicit Pass(const llvm::Record *def); |
81 | |
82 | /// Return the command line argument of the pass. |
83 | StringRef getArgument() const; |
84 | |
85 | /// Return the name for the C++ base class. |
86 | StringRef getBaseClass() const; |
87 | |
88 | /// Return the short 1-line summary of the pass. |
89 | StringRef getSummary() const; |
90 | |
91 | /// Return the description of the pass. |
92 | StringRef getDescription() const; |
93 | |
94 | /// Return the C++ constructor call to create an instance of this pass. |
95 | StringRef getConstructor() const; |
96 | |
97 | /// Return the dialects this pass needs to be registered. |
98 | ArrayRef<StringRef> getDependentDialects() const; |
99 | |
100 | /// Return the options provided by this pass. |
101 | ArrayRef<PassOption> getOptions() const; |
102 | |
103 | /// Return the statistics provided by this pass. |
104 | ArrayRef<PassStatistic> getStatistics() const; |
105 | |
106 | const llvm::Record *getDef() const { return def; } |
107 | |
108 | private: |
109 | const llvm::Record *def; |
110 | std::vector<StringRef> dependentDialects; |
111 | std::vector<PassOption> options; |
112 | std::vector<PassStatistic> statistics; |
113 | }; |
114 | |
115 | } // namespace tblgen |
116 | } // namespace mlir |
117 | |
118 | #endif // MLIR_TABLEGEN_PASS_H_ |
119 | |