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