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 HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false), 128 GuaranteedTailCallOpt(false), StackSymbolOrdering(true), 129 EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), 130 DisableIntegratedAS(false), RelaxELFRelocations(false), 131 FunctionSections(false), DataSections(false), 132 IgnoreXCOFFVisibility(false), UniqueSectionNames(true), 133 UniqueBasicBlockSectionNames(false), TrapUnreachable(false), 134 NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false), 135 ExplicitEmulatedTLS(false), EnableIPRA(false), 136 EmitStackSizeSection(false), EnableMachineOutliner(false), 137 EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false), 138 EmitAddrsig(false), EmitCallSiteInfo(false), 139 SupportsDebugEntryValues(false), EnableDebugEntryValues(false), 140 ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false), 141 XRayOmitFunctionIndex(false), 142 FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {} 143 144 /// DisableFramePointerElim - This returns true if frame pointer elimination 145 /// optimization should be disabled for the given machine function. 146 bool DisableFramePointerElim(const MachineFunction &MF) const; 147 148 /// UnsafeFPMath - This flag is enabled when the 149 /// -enable-unsafe-fp-math flag is specified on the command line. When 150 /// this flag is off (the default), the code generator is not allowed to 151 /// produce results that are "less precise" than IEEE allows. This includes 152 /// use of X86 instructions like FSIN and FCOS instead of libcalls. 153 unsigned UnsafeFPMath : 1; 154 155 /// NoInfsFPMath - This flag is enabled when the 156 /// -enable-no-infs-fp-math flag is specified on the command line. When 157 /// this flag is off (the default), the code generator is not allowed to 158 /// assume the FP arithmetic arguments and results are never +-Infs. 159 unsigned NoInfsFPMath : 1; 160 161 /// NoNaNsFPMath - This flag is enabled when the 162 /// -enable-no-nans-fp-math flag is specified on the command line. When 163 /// this flag is off (the default), the code generator is not allowed to 164 /// assume the FP arithmetic arguments and results are never NaNs. 165 unsigned NoNaNsFPMath : 1; 166 167 /// NoTrappingFPMath - This flag is enabled when the 168 /// -enable-no-trapping-fp-math is specified on the command line. This 169 /// specifies that there are no trap handlers to handle exceptions. 170 unsigned NoTrappingFPMath : 1; 171 172 /// NoSignedZerosFPMath - This flag is enabled when the 173 /// -enable-no-signed-zeros-fp-math is specified on the command line. This 174 /// specifies that optimizations are allowed to treat the sign of a zero 175 /// argument or result as insignificant. 176 unsigned NoSignedZerosFPMath : 1; 177 178 /// HonorSignDependentRoundingFPMath - This returns true when the 179 /// -enable-sign-dependent-rounding-fp-math is specified. If this returns 180 /// false (the default), the code generator is allowed to assume that the 181 /// rounding behavior is the default (round-to-zero for all floating point 182 /// to integer conversions, and round-to-nearest for all other arithmetic 183 /// truncations). If this is enabled (set to true), the code generator must 184 /// assume that the rounding mode may dynamically change. 185 unsigned HonorSignDependentRoundingFPMathOption : 1; 186 bool HonorSignDependentRoundingFPMath() const; 187 188 /// NoZerosInBSS - By default some codegens place zero-initialized data to 189 /// .bss section. This flag disables such behaviour (necessary, e.g. for 190 /// crt*.o compiling). 191 unsigned NoZerosInBSS : 1; 192 193 /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is 194 /// specified on the commandline. When the flag is on, participating targets 195 /// will perform tail call optimization on all calls which use the fastcc 196 /// calling convention and which satisfy certain target-independent 197 /// criteria (being at the end of a function, having the same return type 198 /// as their parent function, etc.), using an alternate ABI if necessary. 199 unsigned GuaranteedTailCallOpt : 1; 200 201 /// StackAlignmentOverride - Override default stack alignment for target. 202 unsigned StackAlignmentOverride = 0; 203 204 /// StackSymbolOrdering - When true, this will allow CodeGen to order 205 /// the local stack symbols (for code size, code locality, or any other 206 /// heuristics). When false, the local symbols are left in whatever order 207 /// they were generated. Default is true. 208 unsigned StackSymbolOrdering : 1; 209 210 /// EnableFastISel - This flag enables fast-path instruction selection 211 /// which trades away generated code quality in favor of reducing 212 /// compile time. 213 unsigned EnableFastISel : 1; 214 215 /// EnableGlobalISel - This flag enables global instruction selection. 216 unsigned EnableGlobalISel : 1; 217 218 /// EnableGlobalISelAbort - Control abort behaviour when global instruction 219 /// selection fails to lower/select an instruction. 220 GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable; 221 222 /// UseInitArray - Use .init_array instead of .ctors for static 223 /// constructors. 224 unsigned UseInitArray : 1; 225 226 /// Disable the integrated assembler. 227 unsigned DisableIntegratedAS : 1; 228 229 /// Compress DWARF debug sections. 230 DebugCompressionType CompressDebugSections = DebugCompressionType::None; 231 232 unsigned RelaxELFRelocations : 1; 233 234 /// Emit functions into separate sections. 235 unsigned FunctionSections : 1; 236 237 /// Emit data into separate sections. 238 unsigned DataSections : 1; 239 240 /// Do not emit visibility attribute for xcoff. 241 unsigned IgnoreXCOFFVisibility : 1; 242 243 unsigned UniqueSectionNames : 1; 244 245 /// Use unique names for basic block sections. 246 unsigned UniqueBasicBlockSectionNames : 1; 247 248 /// Emit target-specific trap instruction for 'unreachable' IR instructions. 249 unsigned TrapUnreachable : 1; 250 251 /// Do not emit a trap instruction for 'unreachable' IR instructions behind 252 /// noreturn calls, even if TrapUnreachable is true. 253 unsigned NoTrapAfterNoreturn : 1; 254 255 /// Bit size of immediate TLS offsets (0 == use the default). 256 unsigned TLSSize : 8; 257 258 /// EmulatedTLS - This flag enables emulated TLS model, using emutls 259 /// function in the runtime library.. 260 unsigned EmulatedTLS : 1; 261 262 /// Whether -emulated-tls or -no-emulated-tls is set. 263 unsigned ExplicitEmulatedTLS : 1; 264 265 /// This flag enables InterProcedural Register Allocation (IPRA). 266 unsigned EnableIPRA : 1; 267 268 /// Emit section containing metadata on function stack sizes. 269 unsigned EmitStackSizeSection : 1; 270 271 /// Enables the MachineOutliner pass. 272 unsigned EnableMachineOutliner : 1; 273 274 /// Enables the MachineFunctionSplitter pass. 275 unsigned EnableMachineFunctionSplitter : 1; 276 277 /// Set if the target supports default outlining behaviour. 278 unsigned SupportsDefaultOutlining : 1; 279 280 /// Emit address-significance table. 281 unsigned EmitAddrsig : 1; 282 283 /// Emit basic blocks into separate sections. 284 BasicBlockSection BBSections = BasicBlockSection::None; 285 286 /// Memory Buffer that contains information on sampled basic blocks and used 287 /// to selectively generate basic block sections. 288 std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf; 289 290 /// The flag enables call site info production. It is used only for debug 291 /// info, and it is restricted only to optimized code. This can be used for 292 /// something else, so that should be controlled in the frontend. 293 unsigned EmitCallSiteInfo : 1; 294 /// Set if the target supports the debug entry values by default. 295 unsigned SupportsDebugEntryValues : 1; 296 /// When set to true, the EnableDebugEntryValues option forces production 297 /// of debug entry values even if the target does not officially support 298 /// it. Useful for testing purposes only. This flag should never be checked 299 /// directly, always use \ref ShouldEmitDebugEntryValues instead. 300 unsigned EnableDebugEntryValues : 1; 301 /// NOTE: There are targets that still do not support the debug entry values 302 /// production. 303 bool ShouldEmitDebugEntryValues() const; 304 305 // When set to true, use experimental new debug variable location tracking, 306 // which seeks to follow the values of variables rather than their location, 307 // post isel. 308 unsigned ValueTrackingVariableLocations : 1; 309 310 /// Emit DWARF debug frame section. 311 unsigned ForceDwarfFrameSection : 1; 312 313 /// Emit XRay Function Index section 314 unsigned XRayOmitFunctionIndex : 1; 315 316 /// Stack protector guard offset to use. 317 unsigned StackProtectorGuardOffset : 32; 318 319 /// Stack protector guard mode to use, e.g. tls, global. 320 StackProtectorGuards StackProtectorGuard = 321 StackProtectorGuards::None; 322 323 /// Stack protector guard reg to use, e.g. usually fs or gs in X86. 324 std::string StackProtectorGuardReg = "None"; 325 326 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied 327 /// on the command line. This setting may either be Default, Soft, or Hard. 328 /// Default selects the target's default behavior. Soft selects the ABI for 329 /// software floating point, but does not indicate that FP hardware may not 330 /// be used. Such a combination is unfortunately popular (e.g. 331 /// arm-apple-darwin). Hard presumes that the normal FP ABI is used. 332 FloatABI::ABIType FloatABIType = FloatABI::Default; 333 334 /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option. 335 /// This controls the creation of fused FP ops that store intermediate 336 /// results in higher precision than IEEE allows (E.g. FMAs). 337 /// 338 /// Fast mode - allows formation of fused FP ops whenever they're 339 /// profitable. 340 /// Standard mode - allow fusion only for 'blessed' FP ops. At present the 341 /// only blessed op is the fmuladd intrinsic. In the future more blessed ops 342 /// may be added. 343 /// Strict mode - allow fusion only if/when it can be proven that the excess 344 /// precision won't effect the result. 345 /// 346 /// Note: This option only controls formation of fused ops by the 347 /// optimizers. Fused operations that are explicitly specified (e.g. FMA 348 /// via the llvm.fma.* intrinsic) will always be honored, regardless of 349 /// the value of this option. 350 FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard; 351 352 /// ThreadModel - This flag specifies the type of threading model to assume 353 /// for things like atomics 354 ThreadModel::Model ThreadModel = ThreadModel::POSIX; 355 356 /// EABIVersion - This flag specifies the EABI version 357 EABI EABIVersion = EABI::Default; 358 359 /// Which debugger to tune for. 360 DebuggerKind DebuggerTuning = DebuggerKind::Default; 361 362 private: 363 /// Flushing mode to assume in default FP environment. 364 DenormalMode FPDenormalMode; 365 366 /// Flushing mode to assume in default FP environment, for float/vector of 367 /// float. 368 DenormalMode FP32DenormalMode; 369 370 public: setFPDenormalMode(DenormalMode Mode)371 void setFPDenormalMode(DenormalMode Mode) { 372 FPDenormalMode = Mode; 373 } 374 setFP32DenormalMode(DenormalMode Mode)375 void setFP32DenormalMode(DenormalMode Mode) { 376 FP32DenormalMode = Mode; 377 } 378 getRawFPDenormalMode()379 DenormalMode getRawFPDenormalMode() const { 380 return FPDenormalMode; 381 } 382 getRawFP32DenormalMode()383 DenormalMode getRawFP32DenormalMode() const { 384 return FP32DenormalMode; 385 } 386 387 DenormalMode getDenormalMode(const fltSemantics &FPType) const; 388 389 /// What exception model to use 390 ExceptionHandling ExceptionModel = ExceptionHandling::None; 391 392 /// Machine level options. 393 MCTargetOptions MCOptions; 394 }; 395 396 } // End llvm namespace 397 398 #endif 399