| 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. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H |
| 14 | #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H |
| 15 | |
| 16 | #include "clang/Basic/DebugInfoOptions.h" |
| 17 | #include "clang/Basic/Sanitizers.h" |
| 18 | #include "clang/Basic/XRayInstr.h" |
| 19 | #include "llvm/Support/CodeGen.h" |
| 20 | #include "llvm/Support/Regex.h" |
| 21 | #include "llvm/Target/TargetOptions.h" |
| 22 | #include <map> |
| 23 | #include <memory> |
| 24 | #include <string> |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace clang { |
| 28 | |
| 29 | /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure |
| 30 | /// that this large collection of bitfields is a trivial class type. |
| 31 | class CodeGenOptionsBase { |
| 32 | public: |
| 33 | #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits; |
| 34 | #define ENUM_CODEGENOPT(Name, Type, Bits, Default) |
| 35 | #include "clang/Basic/CodeGenOptions.def" |
| 36 | |
| 37 | protected: |
| 38 | #define CODEGENOPT(Name, Bits, Default) |
| 39 | #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits; |
| 40 | #include "clang/Basic/CodeGenOptions.def" |
| 41 | }; |
| 42 | |
| 43 | /// CodeGenOptions - Track various options which control how the code |
| 44 | /// is optimized and passed to the backend. |
| 45 | class CodeGenOptions : public CodeGenOptionsBase { |
| 46 | public: |
| 47 | enum InliningMethod { |
| 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 DwarfFissionKind { NoFission, SplitFileFission, SingleFileFission }; |
| 74 | |
| 75 | /// Clang versions with different platform ABI conformance. |
| 76 | enum class ClangABI { |
| 77 | /// Attempt to be ABI-compatible with code generated by Clang 3.8.x |
| 78 | /// (SVN r257626). This causes <1 x long long> to be passed in an |
| 79 | /// integer register instead of an SSE register on x64_64. |
| 80 | Ver3_8, |
| 81 | |
| 82 | /// Attempt to be ABI-compatible with code generated by Clang 4.0.x |
| 83 | /// (SVN r291814). This causes move operations to be ignored when |
| 84 | /// determining whether a class type can be passed or returned directly. |
| 85 | Ver4, |
| 86 | |
| 87 | /// Conform to the underlying platform's C and C++ ABIs as closely |
| 88 | /// as we can. |
| 89 | Latest |
| 90 | }; |
| 91 | |
| 92 | enum StructReturnConventionKind { |
| 93 | SRCK_Default, // No special option was passed. |
| 94 | SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return). |
| 95 | SRCK_InRegs // Small structs in registers (-freg-struct-return). |
| 96 | }; |
| 97 | |
| 98 | enum ProfileInstrKind { |
| 99 | ProfileNone, // Profile instrumentation is turned off. |
| 100 | ProfileClangInstr, // Clang instrumentation to generate execution counts |
| 101 | // to use with PGO. |
| 102 | ProfileIRInstr, // IR level PGO instrumentation in LLVM. |
| 103 | ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in LLVM. |
| 104 | }; |
| 105 | |
| 106 | enum EmbedBitcodeKind { |
| 107 | Embed_Off, // No embedded bitcode. |
| 108 | Embed_All, // Embed both bitcode and commandline in the output. |
| 109 | Embed_Bitcode, // Embed just the bitcode in the output. |
| 110 | Embed_Marker // Embed a marker as a placeholder for bitcode. |
| 111 | }; |
| 112 | |
| 113 | enum SignReturnAddressScope { |
| 114 | None, // No signing for any function |
| 115 | NonLeaf, // Sign the return address of functions that spill LR |
| 116 | All // Sign the return address of all functions |
| 117 | }; |
| 118 | |
| 119 | enum SignReturnAddressKeyValue { AKey, BKey }; |
| 120 | |
| 121 | /// The code model to use (-mcmodel). |
| 122 | std::string CodeModel; |
| 123 | |
| 124 | /// The filename with path we use for coverage data files. The runtime |
| 125 | /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP |
| 126 | /// environment variables. |
| 127 | std::string CoverageDataFile; |
| 128 | |
| 129 | /// The filename with path we use for coverage notes files. |
| 130 | std::string CoverageNotesFile; |
| 131 | |
| 132 | /// Regexes separated by a semi-colon to filter the files to instrument. |
| 133 | std::string ProfileFilterFiles; |
| 134 | |
| 135 | /// Regexes separated by a semi-colon to filter the files to not instrument. |
| 136 | std::string ProfileExcludeFiles; |
| 137 | |
| 138 | /// The version string to put into coverage files. |
| 139 | char CoverageVersion[4]; |
| 140 | |
| 141 | /// Enable additional debugging information. |
| 142 | std::string DebugPass; |
| 143 | |
| 144 | /// The string to embed in debug information as the current working directory. |
| 145 | std::string DebugCompilationDir; |
| 146 | |
| 147 | /// The string to embed in the debug information for the compile unit, if |
| 148 | /// non-empty. |
| 149 | std::string DwarfDebugFlags; |
| 150 | |
| 151 | /// The string containing the commandline for the llvm.commandline metadata, |
| 152 | /// if non-empty. |
| 153 | std::string RecordCommandLine; |
| 154 | |
| 155 | std::map<std::string, std::string> DebugPrefixMap; |
| 156 | |
| 157 | /// The ABI to use for passing floating point arguments. |
| 158 | std::string FloatABI; |
| 159 | |
| 160 | /// The floating-point denormal mode to use. |
| 161 | std::string FPDenormalMode; |
| 162 | |
| 163 | /// The float precision limit to use, if non-empty. |
| 164 | std::string LimitFloatPrecision; |
| 165 | |
| 166 | struct BitcodeFileToLink { |
| 167 | /// The filename of the bitcode file to link in. |
| 168 | std::string Filename; |
| 169 | /// If true, we set attributes functions in the bitcode library according to |
| 170 | /// our CodeGenOptions, much as we set attrs on functions that we generate |
| 171 | /// ourselves. |
| 172 | bool PropagateAttrs = false; |
| 173 | /// If true, we use LLVM module internalizer. |
| 174 | bool Internalize = false; |
| 175 | /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker. |
| 176 | unsigned LinkFlags = 0; |
| 177 | }; |
| 178 | |
| 179 | /// The files specified here are linked in to the module before optimizations. |
| 180 | std::vector<BitcodeFileToLink> LinkBitcodeFiles; |
| 181 | |
| 182 | /// The user provided name for the "main file", if non-empty. This is useful |
| 183 | /// in situations where the input file name does not match the original input |
| 184 | /// file, for example with -save-temps. |
| 185 | std::string MainFileName; |
| 186 | |
| 187 | /// The name for the split debug info file that we'll break out. This is used |
| 188 | /// in the backend for setting the name in the skeleton cu. |
| 189 | std::string SplitDwarfFile; |
| 190 | |
| 191 | /// The name of the relocation model to use. |
| 192 | llvm::Reloc::Model RelocationModel; |
| 193 | |
| 194 | /// The thread model to use |
| 195 | std::string ThreadModel; |
| 196 | |
| 197 | /// If not an empty string, trap intrinsics are lowered to calls to this |
| 198 | /// function instead of to trap instructions. |
| 199 | std::string TrapFuncName; |
| 200 | |
| 201 | /// A list of dependent libraries. |
| 202 | std::vector<std::string> DependentLibraries; |
| 203 | |
| 204 | /// A list of linker options to embed in the object file. |
| 205 | std::vector<std::string> LinkerOptions; |
| 206 | |
| 207 | /// Name of the profile file to use as output for -fprofile-instr-generate, |
| 208 | /// -fprofile-generate, and -fcs-profile-generate. |
| 209 | std::string InstrProfileOutput; |
| 210 | |
| 211 | /// Name of the profile file to use with -fprofile-sample-use. |
| 212 | std::string SampleProfileFile; |
| 213 | |
| 214 | /// Name of the profile file to use as input for -fprofile-instr-use |
| 215 | std::string ProfileInstrumentUsePath; |
| 216 | |
| 217 | /// Name of the profile remapping file to apply to the profile data supplied |
| 218 | /// by -fprofile-sample-use or -fprofile-instr-use. |
| 219 | std::string ProfileRemappingFile; |
| 220 | |
| 221 | /// Name of the function summary index file to use for ThinLTO function |
| 222 | /// importing. |
| 223 | std::string ThinLTOIndexFile; |
| 224 | |
| 225 | /// Name of a file that can optionally be written with minimized bitcode |
| 226 | /// to be used as input for the ThinLTO thin link step, which only needs |
| 227 | /// the summary and module symbol table (and not, e.g. any debug metadata). |
| 228 | std::string ThinLinkBitcodeFile; |
| 229 | |
| 230 | /// Prefix to use for -save-temps output. |
| 231 | std::string SaveTempsFilePrefix; |
| 232 | |
| 233 | /// Name of file passed with -fcuda-include-gpubinary option to forward to |
| 234 | /// CUDA runtime back-end for incorporating them into host-side object file. |
| 235 | std::string CudaGpuBinaryFileName; |
| 236 | |
| 237 | /// The name of the file to which the backend should save YAML optimization |
| 238 | /// records. |
| 239 | std::string OptRecordFile; |
| 240 | |
| 241 | /// The regex that filters the passes that should be saved to the optimization |
| 242 | /// records. |
| 243 | std::string OptRecordPasses; |
| 244 | |
| 245 | /// Regular expression to select optimizations for which we should enable |
| 246 | /// optimization remarks. Transformation passes whose name matches this |
| 247 | /// expression (and support this feature), will emit a diagnostic |
| 248 | /// whenever they perform a transformation. This is enabled by the |
| 249 | /// -Rpass=regexp flag. |
| 250 | std::shared_ptr<llvm::Regex> OptimizationRemarkPattern; |
| 251 | |
| 252 | /// Regular expression to select optimizations for which we should enable |
| 253 | /// missed optimization remarks. Transformation passes whose name matches this |
| 254 | /// expression (and support this feature), will emit a diagnostic |
| 255 | /// whenever they tried but failed to perform a transformation. This is |
| 256 | /// enabled by the -Rpass-missed=regexp flag. |
| 257 | std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern; |
| 258 | |
| 259 | /// Regular expression to select optimizations for which we should enable |
| 260 | /// optimization analyses. Transformation passes whose name matches this |
| 261 | /// expression (and support this feature), will emit a diagnostic |
| 262 | /// whenever they want to explain why they decided to apply or not apply |
| 263 | /// a given transformation. This is enabled by the -Rpass-analysis=regexp |
| 264 | /// flag. |
| 265 | std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern; |
| 266 | |
| 267 | /// Set of files defining the rules for the symbol rewriting. |
| 268 | std::vector<std::string> RewriteMapFiles; |
| 269 | |
| 270 | /// Set of sanitizer checks that are non-fatal (i.e. execution should be |
| 271 | /// continued when possible). |
| 272 | SanitizerSet SanitizeRecover; |
| 273 | |
| 274 | /// Set of sanitizer checks that trap rather than diagnose. |
| 275 | SanitizerSet SanitizeTrap; |
| 276 | |
| 277 | /// List of backend command-line options for -fembed-bitcode. |
| 278 | std::vector<uint8_t> CmdArgs; |
| 279 | |
| 280 | /// A list of all -fno-builtin-* function names (e.g., memset). |
| 281 | std::vector<std::string> NoBuiltinFuncs; |
| 282 | |
| 283 | std::vector<std::string> Reciprocals; |
| 284 | |
| 285 | /// The preferred width for auto-vectorization transforms. This is intended to |
| 286 | /// override default transforms based on the width of the architected vector |
| 287 | /// registers. |
| 288 | std::string PreferVectorWidth; |
| 289 | |
| 290 | /// Set of XRay instrumentation kinds to emit. |
| 291 | XRayInstrSet XRayInstrumentationBundle; |
| 292 | |
| 293 | std::vector<std::string> DefaultFunctionAttrs; |
| 294 | |
| 295 | /// List of dynamic shared object files to be loaded as pass plugins. |
| 296 | std::vector<std::string> PassPlugins; |
| 297 | |
| 298 | public: |
| 299 | // Define accessors/mutators for code generation options of enumeration type. |
| 300 | #define CODEGENOPT(Name, Bits, Default) |
| 301 | #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ |
| 302 | Type get##Name() const { return static_cast<Type>(Name); } \ |
| 303 | void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } |
| 304 | #include "clang/Basic/CodeGenOptions.def" |
| 305 | |
| 306 | CodeGenOptions(); |
| 307 | |
| 308 | /// Is this a libc/libm function that is no longer recognized as a |
| 309 | /// builtin because a -fno-builtin-* option has been specified? |
| 310 | bool isNoBuiltinFunc(const char *Name) const; |
| 311 | |
| 312 | const std::vector<std::string> &getNoBuiltinFuncs() const { |
| 313 | return NoBuiltinFuncs; |
| 314 | } |
| 315 | |
| 316 | /// Check if Clang profile instrumenation is on. |
| 317 | bool hasProfileClangInstr() const { |
| 318 | return getProfileInstr() == ProfileClangInstr; |
| 319 | } |
| 320 | |
| 321 | /// Check if IR level profile instrumentation is on. |
| 322 | bool hasProfileIRInstr() const { |
| 323 | return getProfileInstr() == ProfileIRInstr; |
| 324 | } |
| 325 | |
| 326 | /// Check if CS IR level profile instrumentation is on. |
| 327 | bool hasProfileCSIRInstr() const { |
| 328 | return getProfileInstr() == ProfileCSIRInstr; |
| 329 | } |
| 330 | |
| 331 | /// Check if Clang profile use is on. |
| 332 | bool hasProfileClangUse() const { |
| 333 | return getProfileUse() == ProfileClangInstr; |
| 334 | } |
| 335 | |
| 336 | /// Check if IR level profile use is on. |
| 337 | bool hasProfileIRUse() const { |
| 338 | return getProfileUse() == ProfileIRInstr || |
| 339 | getProfileUse() == ProfileCSIRInstr; |
| 340 | } |
| 341 | |
| 342 | /// Check if CSIR profile use is on. |
| 343 | bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; } |
| 344 | }; |
| 345 | |
| 346 | } // end namespace clang |
| 347 | |
| 348 | #endif |
| 349 |