1 //===-- llvm/Target/TargetOptions.h - Target Options ------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines command line option flags that are shared across various 11 // targets. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TARGET_TARGETOPTIONS_H 16 #define LLVM_TARGET_TARGETOPTIONS_H 17 18 #include "llvm/MC/MCTargetOptions.h" 19 20 namespace llvm { 21 class MachineFunction; 22 class Module; 23 24 namespace FloatABI { 25 enum ABIType { 26 Default, // Target-specific (either soft or hard depending on triple, etc). 27 Soft, // Soft float. 28 Hard // Hard float. 29 }; 30 } 31 32 namespace FPOpFusion { 33 enum FPOpFusionMode { 34 Fast, // Enable fusion of FP ops wherever it's profitable. 35 Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd). 36 Strict // Never fuse FP-ops. 37 }; 38 } 39 40 namespace JumpTable { 41 enum JumpTableType { 42 Single, // Use a single table for all indirect jumptable calls. 43 Arity, // Use one table per number of function parameters. 44 Simplified, // Use one table per function type, with types projected 45 // into 4 types: pointer to non-function, struct, 46 // primitive, and function pointer. 47 Full // Use one table per unique function type 48 }; 49 } 50 51 namespace ThreadModel { 52 enum Model { 53 POSIX, // POSIX Threads 54 Single // Single Threaded Environment 55 }; 56 } 57 58 namespace FPDenormal { 59 enum DenormalMode { 60 IEEE, // IEEE 754 denormal numbers 61 PreserveSign, // the sign of a flushed-to-zero number is preserved in 62 // the sign of 0 63 PositiveZero // denormals are flushed to positive zero 64 }; 65 } 66 67 enum class EABI { 68 Unknown, 69 Default, // Default means not specified 70 EABI4, // Target-specific (either 4, 5 or gnu depending on triple). 71 EABI5, 72 GNU 73 }; 74 75 /// Identify a debugger for "tuning" the debug info. 76 /// 77 /// The "debugger tuning" concept allows us to present a more intuitive 78 /// interface that unpacks into different sets of defaults for the various 79 /// individual feature-flag settings, that suit the preferences of the 80 /// various debuggers. However, it's worth remembering that debuggers are 81 /// not the only consumers of debug info, and some variations in DWARF might 82 /// better be treated as target/platform issues. Fundamentally, 83 /// o if the feature is useful (or not) to a particular debugger, regardless 84 /// of the target, that's a tuning decision; 85 /// o if the feature is useful (or not) on a particular platform, regardless 86 /// of the debugger, that's a target decision. 87 /// It's not impossible to see both factors in some specific case. 88 /// 89 /// The "tuning" should be used to set defaults for individual feature flags 90 /// in DwarfDebug; if a given feature has a more specific command-line option, 91 /// that option should take precedence over the tuning. 92 enum class DebuggerKind { 93 Default, // No specific tuning requested. 94 GDB, // Tune debug info for gdb. 95 LLDB, // Tune debug info for lldb. 96 SCE // Tune debug info for SCE targets (e.g. PS4). 97 }; 98 99 class TargetOptions { 100 public: TargetOptions()101 TargetOptions() 102 : PrintMachineCode(false), UnsafeFPMath(false), NoInfsFPMath(false), 103 NoNaNsFPMath(false), NoTrappingFPMath(false), 104 NoSignedZerosFPMath(false), 105 HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false), 106 GuaranteedTailCallOpt(false), StackSymbolOrdering(true), 107 EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), 108 DisableIntegratedAS(false), RelaxELFRelocations(false), 109 FunctionSections(false), DataSections(false), 110 UniqueSectionNames(true), TrapUnreachable(false), 111 NoTrapAfterNoreturn(false), EmulatedTLS(false), 112 ExplicitEmulatedTLS(false), EnableIPRA(false), 113 EmitStackSizeSection(false), EnableMachineOutliner(false), 114 SupportsDefaultOutlining(false), EmitAddrsig(false) {} 115 116 /// PrintMachineCode - This flag is enabled when the -print-machineinstrs 117 /// option is specified on the command line, and should enable debugging 118 /// output from the code generator. 119 unsigned PrintMachineCode : 1; 120 121 /// DisableFramePointerElim - This returns true if frame pointer elimination 122 /// optimization should be disabled for the given machine function. 123 bool DisableFramePointerElim(const MachineFunction &MF) const; 124 125 /// UnsafeFPMath - This flag is enabled when the 126 /// -enable-unsafe-fp-math flag is specified on the command line. When 127 /// this flag is off (the default), the code generator is not allowed to 128 /// produce results that are "less precise" than IEEE allows. This includes 129 /// use of X86 instructions like FSIN and FCOS instead of libcalls. 130 unsigned UnsafeFPMath : 1; 131 132 /// NoInfsFPMath - This flag is enabled when the 133 /// -enable-no-infs-fp-math flag is specified on the command line. When 134 /// this flag is off (the default), the code generator is not allowed to 135 /// assume the FP arithmetic arguments and results are never +-Infs. 136 unsigned NoInfsFPMath : 1; 137 138 /// NoNaNsFPMath - This flag is enabled when the 139 /// -enable-no-nans-fp-math flag is specified on the command line. When 140 /// this flag is off (the default), the code generator is not allowed to 141 /// assume the FP arithmetic arguments and results are never NaNs. 142 unsigned NoNaNsFPMath : 1; 143 144 /// NoTrappingFPMath - This flag is enabled when the 145 /// -enable-no-trapping-fp-math is specified on the command line. This 146 /// specifies that there are no trap handlers to handle exceptions. 147 unsigned NoTrappingFPMath : 1; 148 149 /// NoSignedZerosFPMath - This flag is enabled when the 150 /// -enable-no-signed-zeros-fp-math is specified on the command line. This 151 /// specifies that optimizations are allowed to treat the sign of a zero 152 /// argument or result as insignificant. 153 unsigned NoSignedZerosFPMath : 1; 154 155 /// HonorSignDependentRoundingFPMath - This returns true when the 156 /// -enable-sign-dependent-rounding-fp-math is specified. If this returns 157 /// false (the default), the code generator is allowed to assume that the 158 /// rounding behavior is the default (round-to-zero for all floating point 159 /// to integer conversions, and round-to-nearest for all other arithmetic 160 /// truncations). If this is enabled (set to true), the code generator must 161 /// assume that the rounding mode may dynamically change. 162 unsigned HonorSignDependentRoundingFPMathOption : 1; 163 bool HonorSignDependentRoundingFPMath() const; 164 165 /// NoZerosInBSS - By default some codegens place zero-initialized data to 166 /// .bss section. This flag disables such behaviour (necessary, e.g. for 167 /// crt*.o compiling). 168 unsigned NoZerosInBSS : 1; 169 170 /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is 171 /// specified on the commandline. When the flag is on, participating targets 172 /// will perform tail call optimization on all calls which use the fastcc 173 /// calling convention and which satisfy certain target-independent 174 /// criteria (being at the end of a function, having the same return type 175 /// as their parent function, etc.), using an alternate ABI if necessary. 176 unsigned GuaranteedTailCallOpt : 1; 177 178 /// StackAlignmentOverride - Override default stack alignment for target. 179 unsigned StackAlignmentOverride = 0; 180 181 /// StackSymbolOrdering - When true, this will allow CodeGen to order 182 /// the local stack symbols (for code size, code locality, or any other 183 /// heuristics). When false, the local symbols are left in whatever order 184 /// they were generated. Default is true. 185 unsigned StackSymbolOrdering : 1; 186 187 /// EnableFastISel - This flag enables fast-path instruction selection 188 /// which trades away generated code quality in favor of reducing 189 /// compile time. 190 unsigned EnableFastISel : 1; 191 192 /// EnableGlobalISel - This flag enables global instruction selection. 193 unsigned EnableGlobalISel : 1; 194 195 /// UseInitArray - Use .init_array instead of .ctors for static 196 /// constructors. 197 unsigned UseInitArray : 1; 198 199 /// Disable the integrated assembler. 200 unsigned DisableIntegratedAS : 1; 201 202 /// Compress DWARF debug sections. 203 DebugCompressionType CompressDebugSections = DebugCompressionType::None; 204 205 unsigned RelaxELFRelocations : 1; 206 207 /// Emit functions into separate sections. 208 unsigned FunctionSections : 1; 209 210 /// Emit data into separate sections. 211 unsigned DataSections : 1; 212 213 unsigned UniqueSectionNames : 1; 214 215 /// Emit target-specific trap instruction for 'unreachable' IR instructions. 216 unsigned TrapUnreachable : 1; 217 218 /// Do not emit a trap instruction for 'unreachable' IR instructions behind 219 /// noreturn calls, even if TrapUnreachable is true. 220 unsigned NoTrapAfterNoreturn : 1; 221 222 /// EmulatedTLS - This flag enables emulated TLS model, using emutls 223 /// function in the runtime library.. 224 unsigned EmulatedTLS : 1; 225 226 /// Whether -emulated-tls or -no-emulated-tls is set. 227 unsigned ExplicitEmulatedTLS : 1; 228 229 /// This flag enables InterProcedural Register Allocation (IPRA). 230 unsigned EnableIPRA : 1; 231 232 /// Emit section containing metadata on function stack sizes. 233 unsigned EmitStackSizeSection : 1; 234 235 /// Enables the MachineOutliner pass. 236 unsigned EnableMachineOutliner : 1; 237 238 /// Set if the target supports default outlining behaviour. 239 unsigned SupportsDefaultOutlining : 1; 240 241 /// Emit address-significance table. 242 unsigned EmitAddrsig : 1; 243 244 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied 245 /// on the command line. This setting may either be Default, Soft, or Hard. 246 /// Default selects the target's default behavior. Soft selects the ABI for 247 /// software floating point, but does not indicate that FP hardware may not 248 /// be used. Such a combination is unfortunately popular (e.g. 249 /// arm-apple-darwin). Hard presumes that the normal FP ABI is used. 250 FloatABI::ABIType FloatABIType = FloatABI::Default; 251 252 /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option. 253 /// This controls the creation of fused FP ops that store intermediate 254 /// results in higher precision than IEEE allows (E.g. FMAs). 255 /// 256 /// Fast mode - allows formation of fused FP ops whenever they're 257 /// profitable. 258 /// Standard mode - allow fusion only for 'blessed' FP ops. At present the 259 /// only blessed op is the fmuladd intrinsic. In the future more blessed ops 260 /// may be added. 261 /// Strict mode - allow fusion only if/when it can be proven that the excess 262 /// precision won't effect the result. 263 /// 264 /// Note: This option only controls formation of fused ops by the 265 /// optimizers. Fused operations that are explicitly specified (e.g. FMA 266 /// via the llvm.fma.* intrinsic) will always be honored, regardless of 267 /// the value of this option. 268 FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard; 269 270 /// ThreadModel - This flag specifies the type of threading model to assume 271 /// for things like atomics 272 ThreadModel::Model ThreadModel = ThreadModel::POSIX; 273 274 /// EABIVersion - This flag specifies the EABI version 275 EABI EABIVersion = EABI::Default; 276 277 /// Which debugger to tune for. 278 DebuggerKind DebuggerTuning = DebuggerKind::Default; 279 280 /// FPDenormalMode - This flags specificies which denormal numbers the code 281 /// is permitted to require. 282 FPDenormal::DenormalMode FPDenormalMode = FPDenormal::IEEE; 283 284 /// What exception model to use 285 ExceptionHandling ExceptionModel = ExceptionHandling::None; 286 287 /// Machine level options. 288 MCTargetOptions MCOptions; 289 }; 290 291 } // End llvm namespace 292 293 #endif 294