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 EABI { 77 Unknown, 78 Default, // Default means not specified 79 EABI4, // Target-specific (either 4, 5 or gnu depending on triple). 80 EABI5, 81 GNU 82 }; 83 84 /// Identify a debugger for "tuning" the debug info. 85 /// 86 /// The "debugger tuning" concept allows us to present a more intuitive 87 /// interface that unpacks into different sets of defaults for the various 88 /// individual feature-flag settings, that suit the preferences of the 89 /// various debuggers. However, it's worth remembering that debuggers are 90 /// not the only consumers of debug info, and some variations in DWARF might 91 /// better be treated as target/platform issues. Fundamentally, 92 /// o if the feature is useful (or not) to a particular debugger, regardless 93 /// of the target, that's a tuning decision; 94 /// o if the feature is useful (or not) on a particular platform, regardless 95 /// of the debugger, that's a target decision. 96 /// It's not impossible to see both factors in some specific case. 97 enum class DebuggerKind { 98 Default, ///< No specific tuning requested. 99 GDB, ///< Tune debug info for gdb. 100 LLDB, ///< Tune debug info for lldb. 101 SCE, ///< Tune debug info for SCE targets (e.g. PS4). 102 DBX ///< Tune debug info for dbx. 103 }; 104 105 /// Enable abort calls when global instruction selection fails to lower/select 106 /// an instruction. 107 enum class GlobalISelAbortMode { 108 Disable, // Disable the abort. 109 Enable, // Enable the abort. 110 DisableWithDiag // Disable the abort but emit a diagnostic on failure. 111 }; 112 113 /// Indicates when and how the Swift async frame pointer bit should be set. 114 enum class SwiftAsyncFramePointerMode { 115 /// Determine whether to set the bit statically or dynamically based 116 /// on the deployment target. 117 DeploymentBased, 118 /// Always set the bit. 119 Always, 120 /// Never set the bit. 121 Never, 122 }; 123 124 /// \brief Enumeration value for AMDGPU code object version, which is the 125 /// code object version times 100. 126 enum CodeObjectVersionKind { 127 COV_None, 128 COV_2 = 200, // Unsupported. 129 COV_3 = 300, // Unsupported. 130 COV_4 = 400, 131 COV_5 = 500, 132 COV_6 = 600, 133 }; 134 135 class TargetOptions { 136 public: TargetOptions()137 TargetOptions() 138 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false), 139 NoTrappingFPMath(true), NoSignedZerosFPMath(false), 140 ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false), 141 HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false), 142 GuaranteedTailCallOpt(false), StackSymbolOrdering(true), 143 EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), 144 DisableIntegratedAS(false), FunctionSections(false), 145 DataSections(false), IgnoreXCOFFVisibility(false), 146 XCOFFTracebackTable(true), UniqueSectionNames(true), 147 UniqueBasicBlockSectionNames(false), SeparateNamedSections(false), 148 TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0), 149 EmulatedTLS(false), EnableTLSDESC(false), EnableIPRA(false), 150 EmitStackSizeSection(false), EnableMachineOutliner(false), 151 EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false), 152 EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false), 153 SupportsDebugEntryValues(false), EnableDebugEntryValues(false), 154 ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false), 155 XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false), 156 PPCGenScalarMASSEntries(false), JMCInstrument(false), 157 EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false), 158 FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {} 159 160 /// DisableFramePointerElim - This returns true if frame pointer elimination 161 /// optimization should be disabled for the given machine function. 162 bool DisableFramePointerElim(const MachineFunction &MF) const; 163 164 /// FramePointerIsReserved - This returns true if the frame pointer must 165 /// always either point to a new frame record or be un-modified in the given 166 /// function. 167 bool FramePointerIsReserved(const MachineFunction &MF) const; 168 169 /// If greater than 0, override the default value of 170 /// MCAsmInfo::BinutilsVersion. 171 std::pair<int, int> BinutilsVersion{0, 0}; 172 173 /// UnsafeFPMath - This flag is enabled when the 174 /// -enable-unsafe-fp-math flag is specified on the command line. When 175 /// this flag is off (the default), the code generator is not allowed to 176 /// produce results that are "less precise" than IEEE allows. This includes 177 /// use of X86 instructions like FSIN and FCOS instead of libcalls. 178 unsigned UnsafeFPMath : 1; 179 180 /// NoInfsFPMath - This flag is enabled when the 181 /// -enable-no-infs-fp-math flag is specified on the command line. When 182 /// this flag is off (the default), the code generator is not allowed to 183 /// assume the FP arithmetic arguments and results are never +-Infs. 184 unsigned NoInfsFPMath : 1; 185 186 /// NoNaNsFPMath - This flag is enabled when the 187 /// -enable-no-nans-fp-math flag is specified on the command line. When 188 /// this flag is off (the default), the code generator is not allowed to 189 /// assume the FP arithmetic arguments and results are never NaNs. 190 unsigned NoNaNsFPMath : 1; 191 192 /// NoTrappingFPMath - This flag is enabled when the 193 /// -enable-no-trapping-fp-math is specified on the command line. This 194 /// specifies that there are no trap handlers to handle exceptions. 195 unsigned NoTrappingFPMath : 1; 196 197 /// NoSignedZerosFPMath - This flag is enabled when the 198 /// -enable-no-signed-zeros-fp-math is specified on the command line. This 199 /// specifies that optimizations are allowed to treat the sign of a zero 200 /// argument or result as insignificant. 201 unsigned NoSignedZerosFPMath : 1; 202 203 /// ApproxFuncFPMath - This flag is enabled when the 204 /// -enable-approx-func-fp-math is specified on the command line. This 205 /// specifies that optimizations are allowed to substitute math functions 206 /// with approximate calculations 207 unsigned ApproxFuncFPMath : 1; 208 209 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is 210 /// specified. The code generator is then able to use both volatile and 211 /// nonvolitle vector registers. When false, the code generator only uses 212 /// volatile vector registers which is the default setting on AIX. 213 unsigned EnableAIXExtendedAltivecABI : 1; 214 215 /// HonorSignDependentRoundingFPMath - This returns true when the 216 /// -enable-sign-dependent-rounding-fp-math is specified. If this returns 217 /// false (the default), the code generator is allowed to assume that the 218 /// rounding behavior is the default (round-to-zero for all floating point 219 /// to integer conversions, and round-to-nearest for all other arithmetic 220 /// truncations). If this is enabled (set to true), the code generator must 221 /// assume that the rounding mode may dynamically change. 222 unsigned HonorSignDependentRoundingFPMathOption : 1; 223 bool HonorSignDependentRoundingFPMath() const; 224 225 /// NoZerosInBSS - By default some codegens place zero-initialized data to 226 /// .bss section. This flag disables such behaviour (necessary, e.g. for 227 /// crt*.o compiling). 228 unsigned NoZerosInBSS : 1; 229 230 /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is 231 /// specified on the commandline. When the flag is on, participating targets 232 /// will perform tail call optimization on all calls which use the fastcc 233 /// calling convention and which satisfy certain target-independent 234 /// criteria (being at the end of a function, having the same return type 235 /// as their parent function, etc.), using an alternate ABI if necessary. 236 unsigned GuaranteedTailCallOpt : 1; 237 238 /// StackSymbolOrdering - When true, this will allow CodeGen to order 239 /// the local stack symbols (for code size, code locality, or any other 240 /// heuristics). When false, the local symbols are left in whatever order 241 /// they were generated. Default is true. 242 unsigned StackSymbolOrdering : 1; 243 244 /// EnableFastISel - This flag enables fast-path instruction selection 245 /// which trades away generated code quality in favor of reducing 246 /// compile time. 247 unsigned EnableFastISel : 1; 248 249 /// EnableGlobalISel - This flag enables global instruction selection. 250 unsigned EnableGlobalISel : 1; 251 252 /// EnableGlobalISelAbort - Control abort behaviour when global instruction 253 /// selection fails to lower/select an instruction. 254 GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable; 255 256 /// Control when and how the Swift async frame pointer bit should 257 /// be set. 258 SwiftAsyncFramePointerMode SwiftAsyncFramePointer = 259 SwiftAsyncFramePointerMode::Always; 260 261 /// UseInitArray - Use .init_array instead of .ctors for static 262 /// constructors. 263 unsigned UseInitArray : 1; 264 265 /// Disable the integrated assembler. 266 unsigned DisableIntegratedAS : 1; 267 268 /// Emit functions into separate sections. 269 unsigned FunctionSections : 1; 270 271 /// Emit data into separate sections. 272 unsigned DataSections : 1; 273 274 /// Do not emit visibility attribute for xcoff. 275 unsigned IgnoreXCOFFVisibility : 1; 276 277 /// Emit XCOFF traceback table. 278 unsigned XCOFFTracebackTable : 1; 279 280 unsigned UniqueSectionNames : 1; 281 282 /// Use unique names for basic block sections. 283 unsigned UniqueBasicBlockSectionNames : 1; 284 285 /// Emit named sections with the same name into different sections. 286 unsigned SeparateNamedSections : 1; 287 288 /// Emit target-specific trap instruction for 'unreachable' IR instructions. 289 unsigned TrapUnreachable : 1; 290 291 /// Do not emit a trap instruction for 'unreachable' IR instructions behind 292 /// noreturn calls, even if TrapUnreachable is true. 293 unsigned NoTrapAfterNoreturn : 1; 294 295 /// Bit size of immediate TLS offsets (0 == use the default). 296 unsigned TLSSize : 8; 297 298 /// EmulatedTLS - This flag enables emulated TLS model, using emutls 299 /// function in the runtime library.. 300 unsigned EmulatedTLS : 1; 301 302 /// EnableTLSDESC - This flag enables TLS Descriptors. 303 unsigned EnableTLSDESC : 1; 304 305 /// This flag enables InterProcedural Register Allocation (IPRA). 306 unsigned EnableIPRA : 1; 307 308 /// Emit section containing metadata on function stack sizes. 309 unsigned EmitStackSizeSection : 1; 310 311 /// Enables the MachineOutliner pass. 312 unsigned EnableMachineOutliner : 1; 313 314 /// Enables the MachineFunctionSplitter pass. 315 unsigned EnableMachineFunctionSplitter : 1; 316 317 /// Set if the target supports default outlining behaviour. 318 unsigned SupportsDefaultOutlining : 1; 319 320 /// Emit address-significance table. 321 unsigned EmitAddrsig : 1; 322 323 // Emit the SHT_LLVM_BB_ADDR_MAP section containing basic block address 324 // which can be used to map virtual addresses to machine basic blocks. 325 unsigned BBAddrMap : 1; 326 327 /// Emit basic blocks into separate sections. 328 BasicBlockSection BBSections = BasicBlockSection::None; 329 330 /// Memory Buffer that contains information on sampled basic blocks and used 331 /// to selectively generate basic block sections. 332 std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf; 333 334 /// The flag enables call site info production. It is used only for debug 335 /// info, and it is restricted only to optimized code. This can be used for 336 /// something else, so that should be controlled in the frontend. 337 unsigned EmitCallSiteInfo : 1; 338 /// Set if the target supports the debug entry values by default. 339 unsigned SupportsDebugEntryValues : 1; 340 /// When set to true, the EnableDebugEntryValues option forces production 341 /// of debug entry values even if the target does not officially support 342 /// it. Useful for testing purposes only. This flag should never be checked 343 /// directly, always use \ref ShouldEmitDebugEntryValues instead. 344 unsigned EnableDebugEntryValues : 1; 345 /// NOTE: There are targets that still do not support the debug entry values 346 /// production. 347 bool ShouldEmitDebugEntryValues() const; 348 349 // When set to true, use experimental new debug variable location tracking, 350 // which seeks to follow the values of variables rather than their location, 351 // post isel. 352 unsigned ValueTrackingVariableLocations : 1; 353 354 /// Emit DWARF debug frame section. 355 unsigned ForceDwarfFrameSection : 1; 356 357 /// Emit XRay Function Index section 358 unsigned XRayFunctionIndex : 1; 359 360 /// When set to true, don't use DWARF extensions in later DWARF versions. 361 /// By default, it is set to false. 362 unsigned DebugStrictDwarf : 1; 363 364 /// Emit the hotpatch flag in CodeView debug. 365 unsigned Hotpatch : 1; 366 367 /// Enables scalar MASS conversions 368 unsigned PPCGenScalarMASSEntries : 1; 369 370 /// Enable JustMyCode instrumentation. 371 unsigned JMCInstrument : 1; 372 373 /// Enable the CFIFixup pass. 374 unsigned EnableCFIFixup : 1; 375 376 /// When set to true, enable MisExpect Diagnostics 377 /// By default, it is set to false 378 unsigned MisExpect : 1; 379 380 /// When set to true, const objects with relocatable address values are put 381 /// into the RO data section. 382 unsigned XCOFFReadOnlyPointers : 1; 383 384 /// Name of the stack usage file (i.e., .su file) if user passes 385 /// -fstack-usage. If empty, it can be implied that -fstack-usage is not 386 /// passed on the command line. 387 std::string StackUsageOutput; 388 389 /// If greater than 0, override TargetLoweringBase::PrefLoopAlignment. 390 unsigned LoopAlignment = 0; 391 392 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied 393 /// on the command line. This setting may either be Default, Soft, or Hard. 394 /// Default selects the target's default behavior. Soft selects the ABI for 395 /// software floating point, but does not indicate that FP hardware may not 396 /// be used. Such a combination is unfortunately popular (e.g. 397 /// arm-apple-darwin). Hard presumes that the normal FP ABI is used. 398 FloatABI::ABIType FloatABIType = FloatABI::Default; 399 400 /// AllowFPOpFusion - This flag is set by the -fp-contract=xxx option. 401 /// This controls the creation of fused FP ops that store intermediate 402 /// results in higher precision than IEEE allows (E.g. FMAs). 403 /// 404 /// Fast mode - allows formation of fused FP ops whenever they're 405 /// profitable. 406 /// Standard mode - allow fusion only for 'blessed' FP ops. At present the 407 /// only blessed op is the fmuladd intrinsic. In the future more blessed ops 408 /// may be added. 409 /// Strict mode - allow fusion only if/when it can be proven that the excess 410 /// precision won't effect the result. 411 /// 412 /// Note: This option only controls formation of fused ops by the 413 /// optimizers. Fused operations that are explicitly specified (e.g. FMA 414 /// via the llvm.fma.* intrinsic) will always be honored, regardless of 415 /// the value of this option. 416 FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard; 417 418 /// ThreadModel - This flag specifies the type of threading model to assume 419 /// for things like atomics 420 ThreadModel::Model ThreadModel = ThreadModel::POSIX; 421 422 /// EABIVersion - This flag specifies the EABI version 423 EABI EABIVersion = EABI::Default; 424 425 /// Which debugger to tune for. 426 DebuggerKind DebuggerTuning = DebuggerKind::Default; 427 428 private: 429 /// Flushing mode to assume in default FP environment. 430 DenormalMode FPDenormalMode; 431 432 /// Flushing mode to assume in default FP environment, for float/vector of 433 /// float. 434 DenormalMode FP32DenormalMode; 435 436 public: setFPDenormalMode(DenormalMode Mode)437 void setFPDenormalMode(DenormalMode Mode) { 438 FPDenormalMode = Mode; 439 } 440 setFP32DenormalMode(DenormalMode Mode)441 void setFP32DenormalMode(DenormalMode Mode) { 442 FP32DenormalMode = Mode; 443 } 444 getRawFPDenormalMode()445 DenormalMode getRawFPDenormalMode() const { 446 return FPDenormalMode; 447 } 448 getRawFP32DenormalMode()449 DenormalMode getRawFP32DenormalMode() const { 450 return FP32DenormalMode; 451 } 452 453 DenormalMode getDenormalMode(const fltSemantics &FPType) const; 454 455 /// What exception model to use 456 ExceptionHandling ExceptionModel = ExceptionHandling::None; 457 458 /// Machine level options. 459 MCTargetOptions MCOptions; 460 461 /// Stores the filename/path of the final .o/.obj file, to be written in the 462 /// debug information. This is used for emitting the CodeView S_OBJNAME 463 /// record. 464 std::string ObjectFilenameForDebug; 465 }; 466 467 } // End llvm namespace 468 469 #endif 470