|
|
|||
File indexing completed on 2026-05-10 08:36:48
0001 //===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file defines the CodeGenOptions interface. 0010 // 0011 //===----------------------------------------------------------------------===// 0012 0013 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H 0014 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H 0015 0016 #include "clang/Basic/CFProtectionOptions.h" 0017 #include "clang/Basic/PointerAuthOptions.h" 0018 #include "clang/Basic/Sanitizers.h" 0019 #include "clang/Basic/XRayInstr.h" 0020 #include "llvm/ADT/FloatingPointMode.h" 0021 #include "llvm/Frontend/Debug/Options.h" 0022 #include "llvm/Frontend/Driver/CodeGenOptions.h" 0023 #include "llvm/Support/CodeGen.h" 0024 #include "llvm/Support/Regex.h" 0025 #include "llvm/Target/TargetOptions.h" 0026 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h" 0027 #include <map> 0028 #include <memory> 0029 #include <string> 0030 #include <vector> 0031 0032 namespace llvm { 0033 class PassBuilder; 0034 } 0035 namespace clang { 0036 0037 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure 0038 /// that this large collection of bitfields is a trivial class type. 0039 class CodeGenOptionsBase { 0040 friend class CompilerInvocation; 0041 friend class CompilerInvocationBase; 0042 0043 public: 0044 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits; 0045 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) 0046 #include "clang/Basic/CodeGenOptions.def" 0047 0048 protected: 0049 #define CODEGENOPT(Name, Bits, Default) 0050 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits; 0051 #include "clang/Basic/CodeGenOptions.def" 0052 }; 0053 0054 /// CodeGenOptions - Track various options which control how the code 0055 /// is optimized and passed to the backend. 0056 class CodeGenOptions : public CodeGenOptionsBase { 0057 public: 0058 enum InliningMethod { 0059 NormalInlining, // Use the standard function inlining pass. 0060 OnlyHintInlining, // Inline only (implicitly) hinted functions. 0061 OnlyAlwaysInlining // Only run the always inlining pass. 0062 }; 0063 0064 enum ObjCDispatchMethodKind { 0065 Legacy = 0, 0066 NonLegacy = 1, 0067 Mixed = 2 0068 }; 0069 0070 enum TLSModel { 0071 GeneralDynamicTLSModel, 0072 LocalDynamicTLSModel, 0073 InitialExecTLSModel, 0074 LocalExecTLSModel 0075 }; 0076 0077 enum StructReturnConventionKind { 0078 SRCK_Default, // No special option was passed. 0079 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return). 0080 SRCK_InRegs // Small structs in registers (-freg-struct-return). 0081 }; 0082 0083 enum ProfileInstrKind { 0084 ProfileNone, // Profile instrumentation is turned off. 0085 ProfileClangInstr, // Clang instrumentation to generate execution counts 0086 // to use with PGO. 0087 ProfileIRInstr, // IR level PGO instrumentation in LLVM. 0088 ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in LLVM. 0089 }; 0090 0091 enum EmbedBitcodeKind { 0092 Embed_Off, // No embedded bitcode. 0093 Embed_All, // Embed both bitcode and commandline in the output. 0094 Embed_Bitcode, // Embed just the bitcode in the output. 0095 Embed_Marker // Embed a marker as a placeholder for bitcode. 0096 }; 0097 0098 enum class ExtendVariableLivenessKind { 0099 None, 0100 This, 0101 All, 0102 }; 0103 0104 enum InlineAsmDialectKind { 0105 IAD_ATT, 0106 IAD_Intel, 0107 }; 0108 0109 enum DebugSrcHashKind { 0110 DSH_MD5, 0111 DSH_SHA1, 0112 DSH_SHA256, 0113 }; 0114 0115 // This field stores one of the allowed values for the option 0116 // -fbasic-block-sections=. The allowed values with this option are: 0117 // {"all", "list=<file>", "none"}. 0118 // 0119 // "all" : Generate basic block sections for all basic blocks. 0120 // "list=<file>": Generate basic block sections for a subset of basic blocks. 0121 // The functions and the machine basic block ids are specified 0122 // in the file. 0123 // "none": Disable sections for basic blocks. 0124 std::string BBSections; 0125 0126 // If set, override the default value of MCAsmInfo::BinutilsVersion. If 0127 // DisableIntegratedAS is specified, the assembly output will consider GNU as 0128 // support. "none" means that all ELF features can be used, regardless of 0129 // binutils support. 0130 std::string BinutilsVersion; 0131 0132 enum class FramePointerKind { 0133 None, // Omit all frame pointers. 0134 Reserved, // Maintain valid frame pointer chain. 0135 NonLeaf, // Keep non-leaf frame pointers. 0136 All, // Keep all frame pointers. 0137 }; 0138 0139 static StringRef getFramePointerKindName(FramePointerKind Kind) { 0140 switch (Kind) { 0141 case FramePointerKind::None: 0142 return "none"; 0143 case FramePointerKind::Reserved: 0144 return "reserved"; 0145 case FramePointerKind::NonLeaf: 0146 return "non-leaf"; 0147 case FramePointerKind::All: 0148 return "all"; 0149 } 0150 0151 llvm_unreachable("invalid FramePointerKind"); 0152 } 0153 0154 enum class SwiftAsyncFramePointerKind { 0155 Auto, // Choose Swift async extended frame info based on deployment target. 0156 Always, // Unconditionally emit Swift async extended frame info. 0157 Never, // Don't emit Swift async extended frame info. 0158 Default = Always, 0159 }; 0160 0161 enum FiniteLoopsKind { 0162 Language, // Not specified, use language standard. 0163 Always, // All loops are assumed to be finite. 0164 Never, // No loop is assumed to be finite. 0165 }; 0166 0167 enum AssignmentTrackingOpts { 0168 Disabled, 0169 Enabled, 0170 Forced, 0171 }; 0172 0173 /// The code model to use (-mcmodel). 0174 std::string CodeModel; 0175 0176 /// The code model-specific large data threshold to use 0177 /// (-mlarge-data-threshold). 0178 uint64_t LargeDataThreshold; 0179 0180 /// The filename with path we use for coverage data files. The runtime 0181 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP 0182 /// environment variables. 0183 std::string CoverageDataFile; 0184 0185 /// The filename with path we use for coverage notes files. 0186 std::string CoverageNotesFile; 0187 0188 /// Regexes separated by a semi-colon to filter the files to instrument. 0189 std::string ProfileFilterFiles; 0190 0191 /// Regexes separated by a semi-colon to filter the files to not instrument. 0192 std::string ProfileExcludeFiles; 0193 0194 /// The version string to put into coverage files. 0195 char CoverageVersion[4] = {'0', '0', '0', '0'}; 0196 0197 /// Enable additional debugging information. 0198 std::string DebugPass; 0199 0200 /// The string to embed in debug information as the current working directory. 0201 std::string DebugCompilationDir; 0202 0203 /// The string to embed in coverage mapping as the current working directory. 0204 std::string CoverageCompilationDir; 0205 0206 /// The string to embed in the debug information for the compile unit, if 0207 /// non-empty. 0208 std::string DwarfDebugFlags; 0209 0210 /// The string containing the commandline for the llvm.commandline metadata, 0211 /// if non-empty. 0212 std::string RecordCommandLine; 0213 0214 llvm::SmallVector<std::pair<std::string, std::string>, 0> DebugPrefixMap; 0215 0216 /// Prefix replacement map for source-based code coverage to remap source 0217 /// file paths in coverage mapping. 0218 llvm::SmallVector<std::pair<std::string, std::string>, 0> CoveragePrefixMap; 0219 0220 /// The ABI to use for passing floating point arguments. 0221 std::string FloatABI; 0222 0223 /// The file to use for dumping bug report by `Debugify` for original 0224 /// debug info. 0225 std::string DIBugsReportFilePath; 0226 0227 /// The floating-point denormal mode to use. 0228 llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::getIEEE(); 0229 0230 /// The floating-point denormal mode to use, for float. 0231 llvm::DenormalMode FP32DenormalMode = llvm::DenormalMode::getIEEE(); 0232 0233 /// The float precision limit to use, if non-empty. 0234 std::string LimitFloatPrecision; 0235 0236 struct BitcodeFileToLink { 0237 /// The filename of the bitcode file to link in. 0238 std::string Filename; 0239 /// If true, we set attributes functions in the bitcode library according to 0240 /// our CodeGenOptions, much as we set attrs on functions that we generate 0241 /// ourselves. 0242 bool PropagateAttrs = false; 0243 /// If true, we use LLVM module internalizer. 0244 bool Internalize = false; 0245 /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker. 0246 unsigned LinkFlags = 0; 0247 }; 0248 0249 /// The files specified here are linked in to the module before optimizations. 0250 std::vector<BitcodeFileToLink> LinkBitcodeFiles; 0251 0252 /// The user provided name for the "main file", if non-empty. This is useful 0253 /// in situations where the input file name does not match the original input 0254 /// file, for example with -save-temps. 0255 std::string MainFileName; 0256 0257 /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name 0258 /// attribute in the skeleton CU. 0259 std::string SplitDwarfFile; 0260 0261 /// Output filename for the split debug info, not used in the skeleton CU. 0262 std::string SplitDwarfOutput; 0263 0264 /// Output filename used in the COFF debug information. 0265 std::string ObjectFilenameForDebug; 0266 0267 /// The name of the relocation model to use. 0268 llvm::Reloc::Model RelocationModel; 0269 0270 /// If not an empty string, trap intrinsics are lowered to calls to this 0271 /// function instead of to trap instructions. 0272 std::string TrapFuncName; 0273 0274 /// A list of dependent libraries. 0275 std::vector<std::string> DependentLibraries; 0276 0277 /// A list of linker options to embed in the object file. 0278 std::vector<std::string> LinkerOptions; 0279 0280 /// Name of the profile file to use as output for -fprofile-instr-generate, 0281 /// -fprofile-generate, and -fcs-profile-generate. 0282 std::string InstrProfileOutput; 0283 0284 /// Name of the profile file to use with -fprofile-sample-use. 0285 std::string SampleProfileFile; 0286 0287 /// Name of the profile file to use as output for with -fmemory-profile. 0288 std::string MemoryProfileOutput; 0289 0290 /// Name of the profile file to use as input for -fmemory-profile-use. 0291 std::string MemoryProfileUsePath; 0292 0293 /// Name of the profile file to use as input for -fprofile-instr-use 0294 std::string ProfileInstrumentUsePath; 0295 0296 /// Name of the profile remapping file to apply to the profile data supplied 0297 /// by -fprofile-sample-use or -fprofile-instr-use. 0298 std::string ProfileRemappingFile; 0299 0300 /// Name of the function summary index file to use for ThinLTO function 0301 /// importing. 0302 std::string ThinLTOIndexFile; 0303 0304 /// Name of a file that can optionally be written with minimized bitcode 0305 /// to be used as input for the ThinLTO thin link step, which only needs 0306 /// the summary and module symbol table (and not, e.g. any debug metadata). 0307 std::string ThinLinkBitcodeFile; 0308 0309 /// Prefix to use for -save-temps output. 0310 std::string SaveTempsFilePrefix; 0311 0312 /// Name of file passed with -fcuda-include-gpubinary option to forward to 0313 /// CUDA runtime back-end for incorporating them into host-side object file. 0314 std::string CudaGpuBinaryFileName; 0315 0316 /// List of filenames passed in using the -fembed-offload-object option. These 0317 /// are offloading binaries containing device images and metadata. 0318 std::vector<std::string> OffloadObjects; 0319 0320 /// The name of the file to which the backend should save YAML optimization 0321 /// records. 0322 std::string OptRecordFile; 0323 0324 /// The regex that filters the passes that should be saved to the optimization 0325 /// records. 0326 std::string OptRecordPasses; 0327 0328 /// The format used for serializing remarks (default: YAML) 0329 std::string OptRecordFormat; 0330 0331 /// The name of the partition that symbols are assigned to, specified with 0332 /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html). 0333 std::string SymbolPartition; 0334 0335 enum RemarkKind { 0336 RK_Missing, // Remark argument not present on the command line. 0337 RK_Enabled, // Remark enabled via '-Rgroup'. 0338 RK_EnabledEverything, // Remark enabled via '-Reverything'. 0339 RK_Disabled, // Remark disabled via '-Rno-group'. 0340 RK_DisabledEverything, // Remark disabled via '-Rno-everything'. 0341 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'. 0342 }; 0343 0344 /// Optimization remark with an optional regular expression pattern. 0345 struct OptRemark { 0346 RemarkKind Kind = RK_Missing; 0347 std::string Pattern; 0348 std::shared_ptr<llvm::Regex> Regex; 0349 0350 /// By default, optimization remark is missing. 0351 OptRemark() = default; 0352 0353 /// Returns true iff the optimization remark holds a valid regular 0354 /// expression. 0355 bool hasValidPattern() const { return Regex != nullptr; } 0356 0357 /// Matches the given string against the regex, if there is some. 0358 bool patternMatches(StringRef String) const { 0359 return hasValidPattern() && Regex->match(String); 0360 } 0361 }; 0362 0363 /// Selected optimizations for which we should enable optimization remarks. 0364 /// Transformation passes whose name matches the contained (optional) regular 0365 /// expression (and support this feature), will emit a diagnostic whenever 0366 /// they perform a transformation. 0367 OptRemark OptimizationRemark; 0368 0369 /// Selected optimizations for which we should enable missed optimization 0370 /// remarks. Transformation passes whose name matches the contained (optional) 0371 /// regular expression (and support this feature), will emit a diagnostic 0372 /// whenever they tried but failed to perform a transformation. 0373 OptRemark OptimizationRemarkMissed; 0374 0375 /// Selected optimizations for which we should enable optimization analyses. 0376 /// Transformation passes whose name matches the contained (optional) regular 0377 /// expression (and support this feature), will emit a diagnostic whenever 0378 /// they want to explain why they decided to apply or not apply a given 0379 /// transformation. 0380 OptRemark OptimizationRemarkAnalysis; 0381 0382 /// Set of sanitizer checks that are non-fatal (i.e. execution should be 0383 /// continued when possible). 0384 SanitizerSet SanitizeRecover; 0385 0386 /// Set of sanitizer checks that trap rather than diagnose. 0387 SanitizerSet SanitizeTrap; 0388 0389 /// Set of sanitizer checks that can merge handlers (smaller code size at 0390 /// the expense of debuggability). 0391 SanitizerSet SanitizeMergeHandlers; 0392 0393 /// Set of thresholds in a range [0.0, 1.0]: the top hottest code responsible 0394 /// for the given fraction of PGO counters will be excluded from sanitization 0395 /// (0.0 [default] to skip none, 1.0 to skip all). 0396 SanitizerMaskCutoffs SanitizeSkipHotCutoffs; 0397 0398 /// List of backend command-line options for -fembed-bitcode. 0399 std::vector<uint8_t> CmdArgs; 0400 0401 /// A list of all -fno-builtin-* function names (e.g., memset). 0402 std::vector<std::string> NoBuiltinFuncs; 0403 0404 std::vector<std::string> Reciprocals; 0405 0406 /// Configuration for pointer-signing. 0407 PointerAuthOptions PointerAuth; 0408 0409 /// The preferred width for auto-vectorization transforms. This is intended to 0410 /// override default transforms based on the width of the architected vector 0411 /// registers. 0412 std::string PreferVectorWidth; 0413 0414 /// Set of XRay instrumentation kinds to emit. 0415 XRayInstrSet XRayInstrumentationBundle; 0416 0417 std::vector<std::string> DefaultFunctionAttrs; 0418 0419 /// List of dynamic shared object files to be loaded as pass plugins. 0420 std::vector<std::string> PassPlugins; 0421 0422 /// List of pass builder callbacks. 0423 std::vector<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks; 0424 0425 /// List of global variables explicitly specified by the user as toc-data. 0426 std::vector<std::string> TocDataVarsUserSpecified; 0427 0428 /// List of global variables that over-ride the toc-data default. 0429 std::vector<std::string> NoTocDataVars; 0430 0431 /// Path to allowlist file specifying which objects 0432 /// (files, functions) should exclusively be instrumented 0433 /// by sanitizer coverage pass. 0434 std::vector<std::string> SanitizeCoverageAllowlistFiles; 0435 0436 /// The guard style used for stack protector to get a initial value, this 0437 /// value usually be gotten from TLS or get from __stack_chk_guard, or some 0438 /// other styles we may implement in the future. 0439 std::string StackProtectorGuard; 0440 0441 /// The TLS base register when StackProtectorGuard is "tls", or register used 0442 /// to store the stack canary for "sysreg". 0443 /// On x86 this can be "fs" or "gs". 0444 /// On AArch64 this can only be "sp_el0". 0445 std::string StackProtectorGuardReg; 0446 0447 /// Specify a symbol to be the guard value. 0448 std::string StackProtectorGuardSymbol; 0449 0450 /// Path to ignorelist file specifying which objects 0451 /// (files, functions) listed for instrumentation by sanitizer 0452 /// coverage pass should actually not be instrumented. 0453 std::vector<std::string> SanitizeCoverageIgnorelistFiles; 0454 0455 /// Path to ignorelist file specifying which objects 0456 /// (files, functions) listed for instrumentation by sanitizer 0457 /// binary metadata pass should not be instrumented. 0458 std::vector<std::string> SanitizeMetadataIgnorelistFiles; 0459 0460 /// Name of the stack usage file (i.e., .su file) if user passes 0461 /// -fstack-usage. If empty, it can be implied that -fstack-usage is not 0462 /// passed on the command line. 0463 std::string StackUsageOutput; 0464 0465 /// Executable and command-line used to create a given CompilerInvocation. 0466 /// Most of the time this will be the full -cc1 command. 0467 const char *Argv0 = nullptr; 0468 std::vector<std::string> CommandLineArgs; 0469 0470 /// The minimum hotness value a diagnostic needs in order to be included in 0471 /// optimization diagnostics. 0472 /// 0473 /// The threshold is an Optional value, which maps to one of the 3 states: 0474 /// 1. 0 => threshold disabled. All remarks will be printed. 0475 /// 2. positive int => manual threshold by user. Remarks with hotness exceed 0476 /// threshold will be printed. 0477 /// 3. None => 'auto' threshold by user. The actual value is not 0478 /// available at command line, but will be synced with 0479 /// hotness threshold from profile summary during 0480 /// compilation. 0481 /// 0482 /// If threshold option is not specified, it is disabled by default. 0483 std::optional<uint64_t> DiagnosticsHotnessThreshold = 0; 0484 0485 /// The maximum percentage profiling weights can deviate from the expected 0486 /// values in order to be included in misexpect diagnostics. 0487 std::optional<uint32_t> DiagnosticsMisExpectTolerance = 0; 0488 0489 /// The name of a file to use with \c .secure_log_unique directives. 0490 std::string AsSecureLogFile; 0491 0492 public: 0493 // Define accessors/mutators for code generation options of enumeration type. 0494 #define CODEGENOPT(Name, Bits, Default) 0495 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ 0496 Type get##Name() const { return static_cast<Type>(Name); } \ 0497 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } 0498 #include "clang/Basic/CodeGenOptions.def" 0499 0500 CodeGenOptions(); 0501 0502 const std::vector<std::string> &getNoBuiltinFuncs() const { 0503 return NoBuiltinFuncs; 0504 } 0505 0506 /// Check if Clang profile instrumenation is on. 0507 bool hasProfileClangInstr() const { 0508 return getProfileInstr() == ProfileClangInstr; 0509 } 0510 0511 /// Check if IR level profile instrumentation is on. 0512 bool hasProfileIRInstr() const { 0513 return getProfileInstr() == ProfileIRInstr; 0514 } 0515 0516 /// Check if CS IR level profile instrumentation is on. 0517 bool hasProfileCSIRInstr() const { 0518 return getProfileInstr() == ProfileCSIRInstr; 0519 } 0520 0521 /// Check if any form of instrumentation is on. 0522 bool hasProfileInstr() const { return getProfileInstr() != ProfileNone; } 0523 0524 /// Check if Clang profile use is on. 0525 bool hasProfileClangUse() const { 0526 return getProfileUse() == ProfileClangInstr; 0527 } 0528 0529 /// Check if IR level profile use is on. 0530 bool hasProfileIRUse() const { 0531 return getProfileUse() == ProfileIRInstr || 0532 getProfileUse() == ProfileCSIRInstr; 0533 } 0534 0535 /// Check if CSIR profile use is on. 0536 bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; } 0537 0538 /// Check if type and variable info should be emitted. 0539 bool hasReducedDebugInfo() const { 0540 return getDebugInfo() >= llvm::codegenoptions::DebugInfoConstructor; 0541 } 0542 0543 /// Check if maybe unused type info should be emitted. 0544 bool hasMaybeUnusedDebugInfo() const { 0545 return getDebugInfo() >= llvm::codegenoptions::UnusedTypeInfo; 0546 } 0547 0548 // Check if any one of SanitizeCoverage* is enabled. 0549 bool hasSanitizeCoverage() const { 0550 return SanitizeCoverageType || SanitizeCoverageIndirectCalls || 0551 SanitizeCoverageTraceCmp || SanitizeCoverageTraceLoads || 0552 SanitizeCoverageTraceStores || SanitizeCoverageControlFlow; 0553 } 0554 0555 // Check if any one of SanitizeBinaryMetadata* is enabled. 0556 bool hasSanitizeBinaryMetadata() const { 0557 return SanitizeBinaryMetadataCovered || SanitizeBinaryMetadataAtomics || 0558 SanitizeBinaryMetadataUAR; 0559 } 0560 0561 /// Reset all of the options that are not considered when building a 0562 /// module. 0563 void resetNonModularOptions(StringRef ModuleFormat); 0564 }; 0565 0566 } // end namespace clang 0567 0568 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|