]> granicus.if.org Git - clang/blob - include/clang/Frontend/CodeGenOptions.h
Add an option to save the backend-produced YAML optimization record to a file
[clang] / include / clang / Frontend / CodeGenOptions.h
1 //===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the CodeGenOptions interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
15 #define LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
16
17 #include "clang/Basic/DebugInfoOptions.h"
18 #include "clang/Basic/Sanitizers.h"
19 #include "llvm/Support/Regex.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25
26 namespace clang {
27
28 /// \brief Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
29 /// that this large collection of bitfields is a trivial class type.
30 class CodeGenOptionsBase {
31 public:
32 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
33 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
34 #include "clang/Frontend/CodeGenOptions.def"
35
36 protected:
37 #define CODEGENOPT(Name, Bits, Default)
38 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
39 #include "clang/Frontend/CodeGenOptions.def"
40 };
41
42 /// CodeGenOptions - Track various options which control how the code
43 /// is optimized and passed to the backend.
44 class CodeGenOptions : public CodeGenOptionsBase {
45 public:
46   enum InliningMethod {
47     NoInlining,         // Perform no inlining whatsoever.
48     NormalInlining,     // Use the standard function inlining pass.
49     OnlyHintInlining,   // Inline only (implicitly) hinted functions.
50     OnlyAlwaysInlining  // Only run the always inlining pass.
51   };
52
53   enum VectorLibrary {
54     NoLibrary,  // Don't use any vector library.
55     Accelerate, // Use the Accelerate framework.
56     SVML        // Intel short vector math library.
57   };
58
59
60   enum ObjCDispatchMethodKind {
61     Legacy = 0,
62     NonLegacy = 1,
63     Mixed = 2
64   };
65
66   enum TLSModel {
67     GeneralDynamicTLSModel,
68     LocalDynamicTLSModel,
69     InitialExecTLSModel,
70     LocalExecTLSModel
71   };
72
73   enum FPContractModeKind {
74     FPC_Off,        // Form fused FP ops only where result will not be affected.
75     FPC_On,         // Form fused FP ops according to FP_CONTRACT rules.
76     FPC_Fast        // Aggressively fuse FP ops (E.g. FMA).
77   };
78
79   enum StructReturnConventionKind {
80     SRCK_Default,  // No special option was passed.
81     SRCK_OnStack,  // Small structs on the stack (-fpcc-struct-return).
82     SRCK_InRegs    // Small structs in registers (-freg-struct-return).
83   };
84
85   enum ProfileInstrKind {
86     ProfileNone,       // Profile instrumentation is turned off.
87     ProfileClangInstr, // Clang instrumentation to generate execution counts
88                        // to use with PGO.
89     ProfileIRInstr,    // IR level PGO instrumentation in LLVM.
90   };
91
92   enum EmbedBitcodeKind {
93     Embed_Off,      // No embedded bitcode.
94     Embed_All,      // Embed both bitcode and commandline in the output.
95     Embed_Bitcode,  // Embed just the bitcode in the output.
96     Embed_Marker    // Embed a marker as a placeholder for bitcode.
97   };
98
99   /// The code model to use (-mcmodel).
100   std::string CodeModel;
101
102   /// The filename with path we use for coverage data files. The runtime
103   /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
104   /// environment variables.
105   std::string CoverageDataFile;
106
107   /// The filename with path we use for coverage notes files.
108   std::string CoverageNotesFile;
109
110   /// The version string to put into coverage files.
111   char CoverageVersion[4];
112
113   /// Enable additional debugging information.
114   std::string DebugPass;
115
116   /// The string to embed in debug information as the current working directory.
117   std::string DebugCompilationDir;
118
119   /// The string to embed in the debug information for the compile unit, if
120   /// non-empty.
121   std::string DwarfDebugFlags;
122
123   std::map<std::string, std::string> DebugPrefixMap;
124
125   /// The ABI to use for passing floating point arguments.
126   std::string FloatABI;
127
128   /// The floating-point denormal mode to use.
129   std::string FPDenormalMode;
130
131   /// The float precision limit to use, if non-empty.
132   std::string LimitFloatPrecision;
133
134   /// The name of the bitcode file to link before optzns.
135   std::vector<std::pair<unsigned, std::string>> LinkBitcodeFiles;
136
137   /// The user provided name for the "main file", if non-empty. This is useful
138   /// in situations where the input file name does not match the original input
139   /// file, for example with -save-temps.
140   std::string MainFileName;
141
142   /// The name for the split debug info file that we'll break out. This is used
143   /// in the backend for setting the name in the skeleton cu.
144   std::string SplitDwarfFile;
145
146   /// The name of the relocation model to use.
147   std::string RelocationModel;
148
149   /// The thread model to use
150   std::string ThreadModel;
151
152   /// If not an empty string, trap intrinsics are lowered to calls to this
153   /// function instead of to trap instructions.
154   std::string TrapFuncName;
155
156   /// A list of command-line options to forward to the LLVM backend.
157   std::vector<std::string> BackendOptions;
158
159   /// A list of dependent libraries.
160   std::vector<std::string> DependentLibraries;
161
162   /// A list of linker options to embed in the object file.
163   std::vector<std::string> LinkerOptions;
164
165   /// Name of the profile file to use as output for -fprofile-instr-generate
166   /// and -fprofile-generate.
167   std::string InstrProfileOutput;
168
169   /// Name of the profile file to use with -fprofile-sample-use.
170   std::string SampleProfileFile;
171
172   /// Name of the profile file to use as input for -fprofile-instr-use
173   std::string ProfileInstrumentUsePath;
174
175   /// Name of the function summary index file to use for ThinLTO function
176   /// importing.
177   std::string ThinLTOIndexFile;
178
179   /// A list of file names passed with -fcuda-include-gpubinary options to
180   /// forward to CUDA runtime back-end for incorporating them into host-side
181   /// object file.
182   std::vector<std::string> CudaGpuBinaryFileNames;
183
184   /// The name of the file to which the backend should save YAML optimization
185   /// records.
186   std::string OptRecordFile;
187
188   /// Regular expression to select optimizations for which we should enable
189   /// optimization remarks. Transformation passes whose name matches this
190   /// expression (and support this feature), will emit a diagnostic
191   /// whenever they perform a transformation. This is enabled by the
192   /// -Rpass=regexp flag.
193   std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
194
195   /// Regular expression to select optimizations for which we should enable
196   /// missed optimization remarks. Transformation passes whose name matches this
197   /// expression (and support this feature), will emit a diagnostic
198   /// whenever they tried but failed to perform a transformation. This is
199   /// enabled by the -Rpass-missed=regexp flag.
200   std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
201
202   /// Regular expression to select optimizations for which we should enable
203   /// optimization analyses. Transformation passes whose name matches this
204   /// expression (and support this feature), will emit a diagnostic
205   /// whenever they want to explain why they decided to apply or not apply
206   /// a given transformation. This is enabled by the -Rpass-analysis=regexp
207   /// flag.
208   std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
209
210   /// Set of files definining the rules for the symbol rewriting.
211   std::vector<std::string> RewriteMapFiles;
212
213   /// Set of sanitizer checks that are non-fatal (i.e. execution should be
214   /// continued when possible).
215   SanitizerSet SanitizeRecover;
216
217   /// Set of sanitizer checks that trap rather than diagnose.
218   SanitizerSet SanitizeTrap;
219
220   /// List of backend command-line options for -fembed-bitcode.
221   std::vector<uint8_t> CmdArgs;
222
223   /// \brief A list of all -fno-builtin-* function names (e.g., memset).
224   std::vector<std::string> NoBuiltinFuncs;
225
226 public:
227   // Define accessors/mutators for code generation options of enumeration type.
228 #define CODEGENOPT(Name, Bits, Default)
229 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
230   Type get##Name() const { return static_cast<Type>(Name); } \
231   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
232 #include "clang/Frontend/CodeGenOptions.def"
233
234   CodeGenOptions();
235
236   /// \brief Is this a libc/libm function that is no longer recognized as a
237   /// builtin because a -fno-builtin-* option has been specified?
238   bool isNoBuiltinFunc(const char *Name) const;
239
240   const std::vector<std::string> &getNoBuiltinFuncs() const {
241     return NoBuiltinFuncs;
242   }
243
244   /// \brief Check if Clang profile instrumenation is on.
245   bool hasProfileClangInstr() const {
246     return getProfileInstr() == ProfileClangInstr;
247   }
248
249   /// \brief Check if IR level profile instrumentation is on.
250   bool hasProfileIRInstr() const {
251     return getProfileInstr() == ProfileIRInstr;
252   }
253
254   /// \brief Check if Clang profile use is on.
255   bool hasProfileClangUse() const {
256     return getProfileUse() == ProfileClangInstr;
257   }
258
259   /// \brief Check if IR level profile use is on.
260   bool hasProfileIRUse() const {
261     return getProfileUse() == ProfileIRInstr;
262   }
263
264 };
265
266 }  // end namespace clang
267
268 #endif