1 //===-- llvm/Target/TargetOptions.h - Target Options ------------*- 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 command line option flags that are shared across various 10 // targets. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TARGET_TARGETOPTIONS_H 15 #define LLVM_TARGET_TARGETOPTIONS_H 16 17 #include "llvm/ADT/FloatingPointMode.h" 18 #include "llvm/MC/MCTargetOptions.h" 19 20 #include <memory> 21 22 namespace llvm { 23 struct fltSemantics; 24 class MachineFunction; 25 class MemoryBuffer; 26 27 namespace FloatABI { 28 enum ABIType { 29 Default, // Target-specific (either soft or hard depending on triple, etc). 30 Soft, // Soft float. 31 Hard // Hard float. 32 }; 33 } 34 35 namespace FPOpFusion { 36 enum FPOpFusionMode { 37 Fast, // Enable fusion of FP ops wherever it's profitable. 38 Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd). 39 Strict // Never fuse FP-ops. 40 }; 41 } 42 43 namespace JumpTable { 44 enum JumpTableType { 45 Single, // Use a single table for all indirect jumptable calls. 46 Arity, // Use one table per number of function parameters. 47 Simplified, // Use one table per function type, with types projected 48 // into 4 types: pointer to non-function, struct, 49 // primitive, and function pointer. 50 Full // Use one table per unique function type 51 }; 52 } 53 54 namespace ThreadModel { 55 enum Model { 56 POSIX, // POSIX Threads 57 Single // Single Threaded Environment 58 }; 59 } 60 61 enum class BasicBlockSection { 62 All, // Use Basic Block Sections for all basic blocks. A section 63 // for every basic block can significantly bloat object file sizes. 64 List, // Get list of functions & BBs from a file. Selectively enables 65 // basic block sections for a subset of basic blocks which can be 66 // used to control object size bloats from creating sections. 67 Labels, // Do not use Basic Block Sections but label basic blocks. This 68 // is useful when associating profile counts from virtual addresses 69 // to basic blocks. 70 Preset, // Similar to list but the blocks are identified by passes which 71 // seek to use Basic Block Sections, e.g. MachineFunctionSplitter. 72 // This option cannot be set via the command line. 73 None // Do not use Basic Block Sections. 74 }; 75 76 enum class StackProtectorGuards { 77 None, 78 TLS, 79 Global 80 }; 81 82 enum class EABI { 83 Unknown, 84 Default, // Default means not specified 85 EABI4, // Target-specific (either 4, 5 or gnu depending on triple). 86 EABI5, 87 GNU 88 }; 89 90 /// Identify a debugger for "tuning" the debug info. 91 /// 92 /// The "debugger tuning" concept allows us to present a more intuitive 93 /// interface that unpacks into different sets of defaults for the various 94 /// individual feature-flag settings, that suit the preferences of the 95 /// various debuggers. However, it's worth remembering that debuggers are 96 /// not the only consumers of debug info, and some variations in DWARF might 97 /// better be treated as target/platform issues. Fundamentally, 98 /// o if the feature is useful (or not) to a particular debugger, regardless 99 /// of the target, that's a tuning decision; 100 /// o if the feature is useful (or not) on a particular platform, regardless 101 /// of the debugger, that's a target decision. 102 /// It's not impossible to see both factors in some specific case. 103 /// 104 /// The "tuning" should be used to set defaults for individual feature flags 105 /// in DwarfDebug; if a given feature has a more specific command-line option, 106 /// that option should take precedence over the tuning. 107 enum class DebuggerKind { 108 Default, // No specific tuning requested. 109 GDB, // Tune debug info for gdb. 110 LLDB, // Tune debug info for lldb. 111 SCE // Tune debug info for SCE targets (e.g. PS4). 112 }; 113 114 /// Enable abort calls when global instruction selection fails to lower/select 115 /// an instruction. 116 enum class GlobalISelAbortMode { 117 Disable, // Disable the abort. 118 Enable, // Enable the abort. 119 DisableWithDiag // Disable the abort but emit a diagnostic on failure. 120 }; 121 122 class TargetOptions { 123 public: TargetOptions()124 TargetOptions() 125 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false), 126 NoTrappingFPMath(true), NoSignedZerosFPMath(false), 127 EnableAIXExtendedAltivecABI(false), 128 HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false), 129 GuaranteedTailCallOpt(false), StackSymbolOrdering(true), 130 EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), 131 DisableIntegratedAS(false), RelaxELFRelocations(false), 132 FunctionSections(false), DataSections(false), 133 IgnoreXCOFFVisibility(false), UniqueSectionNames(true), 134 UniqueBasicBlockSectionNames(false), TrapUnreachable(false), 135 NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false), 136 ExplicitEmulatedTLS(false), EnableIPRA(false), 137 EmitStackSizeSection(false), EnableMachineOutliner(false), 138 EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false), 139 EmitAddrsig(false), EmitCallSiteInfo(false), 140 SupportsDebugEntryValues(false), EnableDebugEntryValues(false), 141 PseudoProbeForProfiling(false), ValueTrackingVariableLocations(false), 142 ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false), 143 FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {} 144 145 /// DisableFramePointerElim - This returns true if frame pointer elimination 146 /// optimization should be disabled for the given machine function. 147 bool DisableFramePointerElim(const MachineFunction &MF) const; 148 149 /// UnsafeFPMath - This flag is enabled when the 150 /// -enable-unsafe-fp-math flag is specified on the command line. When 151 /// this flag is off (the default), the code generator is not allowed to 152 /// produce results that are "less precise" than IEEE allows. This includes 153 /// use of X86 instructions like FSIN and FCOS instead of libcalls. 154 unsigned UnsafeFPMath : 1; 155 156 /// NoInfsFPMath - This flag is enabled when the 157 /// -enable-no-infs-fp-math flag is specified on the command line. When 158 /// this flag is off (the default), the code generator is not allowed to 159 /// assume the FP arithmetic arguments and results are never +-Infs. 160 unsigned NoInfsFPMath : 1; 161 162 /// NoNaNsFPMath - This flag is enabled when the 163 /// -enable-no-nans-fp-math flag is specified on the command line. When 164 /// this flag is off (the default), the code generator is not allowed to 165 /// assume the FP arithmetic arguments and results are never NaNs. 166 unsigned NoNaNsFPMath : 1; 167 168 /// NoTrappingFPMath - This flag is enabled when the 169 /// -enable-no-trapping-fp-math is specified on the command line. This 170 /// specifies that there are no trap handlers to handle exceptions. 171 unsigned NoTrappingFPMath : 1; 172 173 /// NoSignedZerosFPMath - This flag is enabled when the 174 /// -enable-no-signed-zeros-fp-math is specified on the command line. This 175 /// specifies that optimizations are allowed to treat the sign of a zero 176 /// argument or result as insignificant. 177 unsigned NoSignedZerosFPMath : 1; 178 179 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is 180 /// specified. The code generator is then able to use both volatile and 181 /// nonvolitle vector regisers. When false, the code generator only uses 182 /// volatile vector registers which is the default setting on AIX. 183 unsigned EnableAIXExtendedAltivecABI : 1; 184 185 /// HonorSignDependentRoundingFPMath - This returns true when the 186 /// -enable-sign-dependent-rounding-fp-math is specified. If this returns 187 /// false (the default), the code generator is allowed to assume that the 188 /// rounding behavior is the default (round-to-zero for all floating point 189 /// to integer conversions, and round-to-nearest for all other arithmetic 190 /// truncations). If this is enabled (set to true), the code generator must 191 /// assume that the rounding mode may dynamically change. 192 unsigned HonorSignDependentRoundingFPMathOption : 1; 193 bool HonorSignDependentRoundingFPMath() const; 194 195 /// NoZerosInBSS - By default some codegens place zero-initialized data to 196 /// .bss section. This flag disables such behaviour (necessary, e.g. for 197 /// crt*.o compiling). 198 unsigned NoZerosInBSS : 1; 199 200 /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is 201 /// specified on the commandline. When the flag is on, participating targets 202 /// will perform tail call optimization on all calls which use the fastcc 203 /// calling convention and which satisfy certain target-independent 204 /// criteria (being at the end of a function, having the same return type 205 /// as their parent function, etc.), using an alternate ABI if necessary. 206 unsigned GuaranteedTailCallOpt : 1; 207 208 /// StackAlignmentOverride - Override default stack alignment for target. 209 unsigned StackAlignmentOverride = 0; 210 211 /// StackSymbolOrdering - When true, this will allow CodeGen to order 212 /// the local stack symbols (for code size, code locality, or any other 213 /// heuristics). When false, the local symbols are left in whatever order 214 /// they were generated. Default is true. 215 unsigned StackSymbolOrdering : 1; 216 217 /// EnableFastISel - This flag enables fast-path instruction selection 218 /// which trades away generated code quality in favor of reducing 219 /// compile time. 220 unsigned EnableFastISel : 1; 221 222 /// EnableGlobalISel - This flag enables global instruction selection. 223 unsigned EnableGlobalISel : 1; 224 225 /// EnableGlobalISelAbort - Control abort behaviour when global instruction 226 /// selection fails to lower/select an instruction. 227 GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable; 228 229 /// UseInitArray - Use .init_array instead of .ctors for static 230 /// constructors. 231 unsigned UseInitArray : 1; 232 233 /// Disable the integrated assembler. 234 unsigned DisableIntegratedAS : 1; 235 236 /// Compress DWARF debug sections. 237 DebugCompressionType CompressDebugSections = DebugCompressionType::None; 238 239 unsigned RelaxELFRelocations : 1; 240 241 /// Emit functions into separate sections. 242 unsigned FunctionSections : 1; 243 244 /// Emit data into separate sections. 245 unsigned DataSections : 1; 246 247 /// Do not emit visibility attribute for xcoff. 248 unsigned IgnoreXCOFFVisibility : 1; 249 250 unsigned UniqueSectionNames : 1; 251 252 /// Use unique names for basic block sections. 253 unsigned UniqueBasicBlockSectionNames : 1; 254 255 /// Emit target-specific trap instruction for 'unreachable' IR instructions. 256 unsigned TrapUnreachable : 1; 257 258 /// Do not emit a trap instruction for 'unreachable' IR instructions behind 259 /// noreturn calls, even if TrapUnreachable is true. 260 unsigned NoTrapAfterNoreturn : 1; 261 262 /// Bit size of immediate TLS offsets (0 == use the default). 263 unsigned TLSSize : 8; 264 265 /// EmulatedTLS - This flag enables emulated TLS model, using emutls 266 /// function in the runtime library.. 267 unsigned EmulatedTLS : 1; 268 269 /// Whether -emulated-tls or -no-emulated-tls is set. 270 unsigned ExplicitEmulatedTLS : 1; 271 272 /// This flag enables InterProcedural Register Allocation (IPRA). 273 unsigned EnableIPRA : 1; 274 275 /// Emit section containing metadata on function stack sizes. 276 unsigned EmitStackSizeSection : 1; 277 278 /// Enables the MachineOutliner pass. 279 unsigned EnableMachineOutliner : 1; 280 281 /// Enables the MachineFunctionSplitter pass. 282 unsigned EnableMachineFunctionSplitter : 1; 283 284 /// Set if the target supports default outlining behaviour. 285 unsigned SupportsDefaultOutlining : 1; 286 287 /// Emit address-significance table. 288 unsigned EmitAddrsig : 1; 289 290 /// Emit basic blocks into separate sections. 291 BasicBlockSection BBSections = BasicBlockSection::None; 292 293 /// Memory Buffer that contains information on sampled basic blocks and used 294 /// to selectively generate basic block sections. 295 std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf; 296 297 /// The flag enables call site info production. It is used only for debug 298 /// info, and it is restricted only to optimized code. This can be used for 299 /// something else, so that should be controlled in the frontend. 300 unsigned EmitCallSiteInfo : 1; 301 /// Set if the target supports the debug entry values by default. 302 unsigned SupportsDebugEntryValues : 1; 303 /// When set to true, the EnableDebugEntryValues option forces production 304 /// of debug entry values even if the target does not officially support 305 /// it. Useful for testing purposes only. This flag should never be checked 306 /// directly, always use \ref ShouldEmitDebugEntryValues instead. 307 unsigned EnableDebugEntryValues : 1; 308 /// NOTE: There are targets that still do not support the debug entry values 309 /// production. 310 bool ShouldEmitDebugEntryValues() const; 311 312 /// Emit pseudo probes into the binary for sample profiling 313 unsigned PseudoProbeForProfiling : 1; 314 315 // When set to true, use experimental new debug variable location tracking, 316 // which seeks to follow the values of variables rather than their location, 317 // post isel. 318 unsigned ValueTrackingVariableLocations : 1; 319 320 /// Emit DWARF debug frame section. 321 unsigned ForceDwarfFrameSection : 1; 322 323 /// Emit XRay Function Index section 324 unsigned XRayOmitFunctionIndex : 1; 325 326 /// Stack protector guard offset to use. 327 unsigned StackProtectorGuardOffset : 32; 328 329 /// Stack protector guard mode to use, e.g. tls, global. 330 StackProtectorGuards StackProtectorGuard = 331 StackProtectorGuards::None; 332 333 /// Stack protector guard reg to use, e.g. usually fs or gs in X86. 334 std::string StackProtectorGuardReg = "None"; 335 336 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied 337 /// on the command line. This setting may either be Default, Soft, or Hard. 338 /// Default selects the target's default behavior. Soft selects the ABI for 339 /// software floating point, but does not indicate that FP hardware may not 340 /// be used. Such a combination is unfortunately popular (e.g. 341 /// arm-apple-darwin). Hard presumes that the normal FP ABI is used. 342 FloatABI::ABIType FloatABIType = FloatABI::Default; 343 344 /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option. 345 /// This controls the creation of fused FP ops that store intermediate 346 /// results in higher precision than IEEE allows (E.g. FMAs). 347 /// 348 /// Fast mode - allows formation of fused FP ops whenever they're 349 /// profitable. 350 /// Standard mode - allow fusion only for 'blessed' FP ops. At present the 351 /// only blessed op is the fmuladd intrinsic. In the future more blessed ops 352 /// may be added. 353 /// Strict mode - allow fusion only if/when it can be proven that the excess 354 /// precision won't effect the result. 355 /// 356 /// Note: This option only controls formation of fused ops by the 357 /// optimizers. Fused operations that are explicitly specified (e.g. FMA 358 /// via the llvm.fma.* intrinsic) will always be honored, regardless of 359 /// the value of this option. 360 FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard; 361 362 /// ThreadModel - This flag specifies the type of threading model to assume 363 /// for things like atomics 364 ThreadModel::Model ThreadModel = ThreadModel::POSIX; 365 366 /// EABIVersion - This flag specifies the EABI version 367 EABI EABIVersion = EABI::Default; 368 369 /// Which debugger to tune for. 370 DebuggerKind DebuggerTuning = DebuggerKind::Default; 371 372 private: 373 /// Flushing mode to assume in default FP environment. 374 DenormalMode FPDenormalMode; 375 376 /// Flushing mode to assume in default FP environment, for float/vector of 377 /// float. 378 DenormalMode FP32DenormalMode; 379 380 public: setFPDenormalMode(DenormalMode Mode)381 void setFPDenormalMode(DenormalMode Mode) { 382 FPDenormalMode = Mode; 383 } 384 setFP32DenormalMode(DenormalMode Mode)385 void setFP32DenormalMode(DenormalMode Mode) { 386 FP32DenormalMode = Mode; 387 } 388 getRawFPDenormalMode()389 DenormalMode getRawFPDenormalMode() const { 390 return FPDenormalMode; 391 } 392 getRawFP32DenormalMode()393 DenormalMode getRawFP32DenormalMode() const { 394 return FP32DenormalMode; 395 } 396 397 DenormalMode getDenormalMode(const fltSemantics &FPType) const; 398 399 /// What exception model to use 400 ExceptionHandling ExceptionModel = ExceptionHandling::None; 401 402 /// Machine level options. 403 MCTargetOptions MCOptions; 404 }; 405 406 } // End llvm namespace 407 408 #endif 409