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_BASIC_CODEGENOPTIONS_H 15 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H 16 17 #include "clang/Basic/DebugInfoOptions.h" 18 #include "clang/Basic/Sanitizers.h" 19 #include "clang/Basic/XRayInstr.h" 20 #include "llvm/Support/CodeGen.h" 21 #include "llvm/Support/Regex.h" 22 #include "llvm/Target/TargetOptions.h" 23 #include <map> 24 #include <memory> 25 #include <string> 26 #include <vector> 27 28 namespace clang { 29 30 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure 31 /// that this large collection of bitfields is a trivial class type. 32 class CodeGenOptionsBase { 33 public: 34 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits; 35 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) 36 #include "clang/Basic/CodeGenOptions.def" 37 38 protected: 39 #define CODEGENOPT(Name, Bits, Default) 40 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits; 41 #include "clang/Basic/CodeGenOptions.def" 42 }; 43 44 /// CodeGenOptions - Track various options which control how the code 45 /// is optimized and passed to the backend. 46 class CodeGenOptions : public CodeGenOptionsBase { 47 public: 48 enum InliningMethod { 49 NormalInlining, // Use the standard function inlining pass. 50 OnlyHintInlining, // Inline only (implicitly) hinted functions. 51 OnlyAlwaysInlining // Only run the always inlining pass. 52 }; 53 54 enum VectorLibrary { 55 NoLibrary, // Don't use any vector library. 56 Accelerate, // Use the Accelerate framework. 57 SVML // Intel short vector math library. 58 }; 59 60 61 enum ObjCDispatchMethodKind { 62 Legacy = 0, 63 NonLegacy = 1, 64 Mixed = 2 65 }; 66 67 enum TLSModel { 68 GeneralDynamicTLSModel, 69 LocalDynamicTLSModel, 70 InitialExecTLSModel, 71 LocalExecTLSModel 72 }; 73 74 enum DwarfFissionKind { NoFission, SplitFileFission, SingleFileFission }; 75 76 /// Clang versions with different platform ABI conformance. 77 enum class ClangABI { 78 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x 79 /// (SVN r257626). This causes <1 x long long> to be passed in an 80 /// integer register instead of an SSE register on x64_64. 81 Ver3_8, 82 83 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x 84 /// (SVN r291814). This causes move operations to be ignored when 85 /// determining whether a class type can be passed or returned directly. 86 Ver4, 87 88 /// Conform to the underlying platform's C and C++ ABIs as closely 89 /// as we can. 90 Latest 91 }; 92 93 enum StructReturnConventionKind { 94 SRCK_Default, // No special option was passed. 95 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return). 96 SRCK_InRegs // Small structs in registers (-freg-struct-return). 97 }; 98 99 enum ProfileInstrKind { 100 ProfileNone, // Profile instrumentation is turned off. 101 ProfileClangInstr, // Clang instrumentation to generate execution counts 102 // to use with PGO. 103 ProfileIRInstr, // IR level PGO 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 /// and -fprofile-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 /// Regular expression to select optimizations for which we should enable 242 /// optimization remarks. Transformation passes whose name matches this 243 /// expression (and support this feature), will emit a diagnostic 244 /// whenever they perform a transformation. This is enabled by the 245 /// -Rpass=regexp flag. 246 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern; 247 248 /// Regular expression to select optimizations for which we should enable 249 /// missed optimization remarks. Transformation passes whose name matches this 250 /// expression (and support this feature), will emit a diagnostic 251 /// whenever they tried but failed to perform a transformation. This is 252 /// enabled by the -Rpass-missed=regexp flag. 253 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern; 254 255 /// Regular expression to select optimizations for which we should enable 256 /// optimization analyses. Transformation passes whose name matches this 257 /// expression (and support this feature), will emit a diagnostic 258 /// whenever they want to explain why they decided to apply or not apply 259 /// a given transformation. This is enabled by the -Rpass-analysis=regexp 260 /// flag. 261 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern; 262 263 /// Set of files defining the rules for the symbol rewriting. 264 std::vector<std::string> RewriteMapFiles; 265 266 /// Set of sanitizer checks that are non-fatal (i.e. execution should be 267 /// continued when possible). 268 SanitizerSet SanitizeRecover; 269 270 /// Set of sanitizer checks that trap rather than diagnose. 271 SanitizerSet SanitizeTrap; 272 273 /// List of backend command-line options for -fembed-bitcode. 274 std::vector<uint8_t> CmdArgs; 275 276 /// A list of all -fno-builtin-* function names (e.g., memset). 277 std::vector<std::string> NoBuiltinFuncs; 278 279 std::vector<std::string> Reciprocals; 280 281 /// The preferred width for auto-vectorization transforms. This is intended to 282 /// override default transforms based on the width of the architected vector 283 /// registers. 284 std::string PreferVectorWidth; 285 286 /// Set of XRay instrumentation kinds to emit. 287 XRayInstrSet XRayInstrumentationBundle; 288 289 std::vector<std::string> DefaultFunctionAttrs; 290 291 public: 292 // Define accessors/mutators for code generation options of enumeration type. 293 #define CODEGENOPT(Name, Bits, Default) 294 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ 295 Type get##Name() const { return static_cast<Type>(Name); } \ 296 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } 297 #include "clang/Basic/CodeGenOptions.def" 298 299 CodeGenOptions(); 300 301 /// Is this a libc/libm function that is no longer recognized as a 302 /// builtin because a -fno-builtin-* option has been specified? 303 bool isNoBuiltinFunc(const char *Name) const; 304 getNoBuiltinFuncs()305 const std::vector<std::string> &getNoBuiltinFuncs() const { 306 return NoBuiltinFuncs; 307 } 308 309 /// Check if Clang profile instrumenation is on. hasProfileClangInstr()310 bool hasProfileClangInstr() const { 311 return getProfileInstr() == ProfileClangInstr; 312 } 313 314 /// Check if IR level profile instrumentation is on. hasProfileIRInstr()315 bool hasProfileIRInstr() const { 316 return getProfileInstr() == ProfileIRInstr; 317 } 318 319 /// Check if Clang profile use is on. hasProfileClangUse()320 bool hasProfileClangUse() const { 321 return getProfileUse() == ProfileClangInstr; 322 } 323 324 /// Check if IR level profile use is on. hasProfileIRUse()325 bool hasProfileIRUse() const { 326 return getProfileUse() == ProfileIRInstr; 327 } 328 329 }; 330 331 } // end namespace clang 332 333 #endif 334