Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===--- CodeGenOptions.h ---------------------------------------*- 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 | // This file defines the CodeGenOptions interface, which holds the |
10 | // configuration for LLVM's middle-end and back-end. It controls LLVM's code |
11 | // generation into assembly or machine code. |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef FORTRAN_FRONTEND_CODEGENOPTIONS_H |
16 | #define FORTRAN_FRONTEND_CODEGENOPTIONS_H |
17 | |
18 | #include "llvm/Frontend/Debug/Options.h" |
19 | #include "llvm/Frontend/Driver/CodeGenOptions.h" |
20 | #include "llvm/Support/CodeGen.h" |
21 | #include "llvm/Support/Regex.h" |
22 | #include "llvm/Target/TargetOptions.h" |
23 | #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h" |
24 | #include <map> |
25 | #include <memory> |
26 | #include <optional> |
27 | #include <string> |
28 | #include <vector> |
29 | |
30 | namespace Fortran::frontend { |
31 | |
32 | /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure |
33 | /// that this large collection of bitfields is a trivial class type. |
34 | class CodeGenOptionsBase { |
35 | |
36 | public: |
37 | #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits; |
38 | #define ENUM_CODEGENOPT(Name, Type, Bits, Default) |
39 | #include "flang/Frontend/CodeGenOptions.def" |
40 | |
41 | protected: |
42 | #define CODEGENOPT(Name, Bits, Default) |
43 | #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits; |
44 | #include "flang/Frontend/CodeGenOptions.def" |
45 | }; |
46 | |
47 | /// Tracks various options which control how the code is optimized and passed |
48 | /// to the LLVM backend. |
49 | class CodeGenOptions : public CodeGenOptionsBase { |
50 | |
51 | public: |
52 | /// The paths to the pass plugins that were registered using -fpass-plugin. |
53 | std::vector<std::string> LLVMPassPlugins; |
54 | |
55 | /// List of filenames passed in using the -fembed-offload-object option. These |
56 | /// are offloading binaries containing device images and metadata. |
57 | std::vector<std::string> OffloadObjects; |
58 | |
59 | /// The directory where temp files are stored if specified by -save-temps |
60 | std::optional<std::string> SaveTempsDir; |
61 | |
62 | /// The name of the file to which the backend should save YAML optimization |
63 | /// records. |
64 | std::string OptRecordFile; |
65 | |
66 | /// The regex that filters the passes that should be saved to the optimization |
67 | /// records. |
68 | std::string OptRecordPasses; |
69 | |
70 | /// The format used for serializing remarks (default: YAML) |
71 | std::string OptRecordFormat; |
72 | |
73 | /// Options to add to the linker for the object file |
74 | std::vector<std::string> DependentLibs; |
75 | |
76 | // The RemarkKind enum class and OptRemark struct are identical to what Clang |
77 | // has |
78 | // TODO: Share with clang instead of re-implementing here |
79 | enum class RemarkKind { |
80 | RK_Missing, // Remark argument not present on the command line. |
81 | RK_Enabled, // Remark enabled via '-Rgroup', i.e. -Rpass, -Rpass-missed, |
82 | // -Rpass-analysis |
83 | RK_Disabled, // Remark disabled via '-Rno-group', i.e. -Rno-pass, |
84 | // -Rno-pass-missed, -Rno-pass-analysis. |
85 | RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'. |
86 | }; |
87 | |
88 | /// \brief Code object version for AMDGPU. |
89 | llvm::CodeObjectVersionKind CodeObjectVersion = |
90 | llvm::CodeObjectVersionKind::COV_5; |
91 | |
92 | /// Optimization remark with an optional regular expression pattern. |
93 | struct OptRemark { |
94 | RemarkKind Kind = RemarkKind::RK_Missing; |
95 | std::string Pattern; |
96 | std::shared_ptr<llvm::Regex> Regex; |
97 | |
98 | /// By default, optimization remark is missing. |
99 | OptRemark() = default; |
100 | |
101 | /// Returns true iff the optimization remark holds a valid regular |
102 | /// expression. |
103 | bool hasValidPattern() const { return Regex != nullptr; } |
104 | |
105 | /// Matches the given string against the regex, if there is some. |
106 | bool patternMatches(llvm::StringRef string) const { |
107 | return hasValidPattern() && Regex->match(string); |
108 | } |
109 | }; |
110 | |
111 | // The OptRemark fields provided here are identical to Clang. |
112 | |
113 | /// Selected optimizations for which we should enable optimization remarks. |
114 | /// Transformation passes whose name matches the contained (optional) regular |
115 | /// expression (and support this feature), will emit a diagnostic whenever |
116 | /// they perform a transformation. |
117 | OptRemark OptimizationRemark; |
118 | |
119 | /// Selected optimizations for which we should enable missed optimization |
120 | /// remarks. Transformation passes whose name matches the contained (optional) |
121 | /// regular expression (and support this feature), will emit a diagnostic |
122 | /// whenever they tried but failed to perform a transformation. |
123 | OptRemark OptimizationRemarkMissed; |
124 | |
125 | /// Selected optimizations for which we should enable optimization analyses. |
126 | /// Transformation passes whose name matches the contained (optional) regular |
127 | /// expression (and support this feature), will emit a diagnostic whenever |
128 | /// they want to explain why they decided to apply or not apply a given |
129 | /// transformation. |
130 | OptRemark OptimizationRemarkAnalysis; |
131 | |
132 | // Define accessors/mutators for code generation options of enumeration type. |
133 | #define CODEGENOPT(Name, Bits, Default) |
134 | #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ |
135 | Type get##Name() const { return static_cast<Type>(Name); } \ |
136 | void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } |
137 | #include "flang/Frontend/CodeGenOptions.def" |
138 | |
139 | CodeGenOptions(); |
140 | }; |
141 | |
142 | } // end namespace Fortran::frontend |
143 | |
144 | #endif // FORTRAN_FRONTEND_CODEGENOPTIONS_H |
145 |
Warning: This file is not a C or C++ file. It does not have highlighting.