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/Target/TargetRecip.h" 19 #include "llvm/MC/MCTargetOptions.h" 20 #include <string> 21 22 namespace llvm { 23 class MachineFunction; 24 class Module; 25 class StringRef; 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 class TargetOptions { 62 public: TargetOptions()63 TargetOptions() 64 : PrintMachineCode(false), 65 LessPreciseFPMADOption(false), UnsafeFPMath(false), 66 NoInfsFPMath(false), NoNaNsFPMath(false), 67 HonorSignDependentRoundingFPMathOption(false), 68 NoZerosInBSS(false), 69 GuaranteedTailCallOpt(false), 70 StackAlignmentOverride(0), 71 EnableFastISel(false), PositionIndependentExecutable(false), 72 UseInitArray(false), DisableIntegratedAS(false), 73 CompressDebugSections(false), FunctionSections(false), 74 DataSections(false), UniqueSectionNames(true), TrapUnreachable(false), 75 FloatABIType(FloatABI::Default), 76 AllowFPOpFusion(FPOpFusion::Standard), Reciprocals(TargetRecip()), 77 JTType(JumpTable::Single), 78 ThreadModel(ThreadModel::POSIX) {} 79 80 /// PrintMachineCode - This flag is enabled when the -print-machineinstrs 81 /// option is specified on the command line, and should enable debugging 82 /// output from the code generator. 83 unsigned PrintMachineCode : 1; 84 85 /// DisableFramePointerElim - This returns true if frame pointer elimination 86 /// optimization should be disabled for the given machine function. 87 bool DisableFramePointerElim(const MachineFunction &MF) const; 88 89 /// LessPreciseFPMAD - This flag is enabled when the 90 /// -enable-fp-mad is specified on the command line. When this flag is off 91 /// (the default), the code generator is not allowed to generate mad 92 /// (multiply add) if the result is "less precise" than doing those 93 /// operations individually. 94 unsigned LessPreciseFPMADOption : 1; 95 bool LessPreciseFPMAD() const; 96 97 /// UnsafeFPMath - This flag is enabled when the 98 /// -enable-unsafe-fp-math flag is specified on the command line. When 99 /// this flag is off (the default), the code generator is not allowed to 100 /// produce results that are "less precise" than IEEE allows. This includes 101 /// use of X86 instructions like FSIN and FCOS instead of libcalls. 102 /// UnsafeFPMath implies LessPreciseFPMAD. 103 unsigned UnsafeFPMath : 1; 104 105 /// NoInfsFPMath - This flag is enabled when the 106 /// -enable-no-infs-fp-math flag is specified on the command line. When 107 /// this flag is off (the default), the code generator is not allowed to 108 /// assume the FP arithmetic arguments and results are never +-Infs. 109 unsigned NoInfsFPMath : 1; 110 111 /// NoNaNsFPMath - This flag is enabled when the 112 /// -enable-no-nans-fp-math flag is specified on the command line. When 113 /// this flag is off (the default), the code generator is not allowed to 114 /// assume the FP arithmetic arguments and results are never NaNs. 115 unsigned NoNaNsFPMath : 1; 116 117 /// HonorSignDependentRoundingFPMath - This returns true when the 118 /// -enable-sign-dependent-rounding-fp-math is specified. If this returns 119 /// false (the default), the code generator is allowed to assume that the 120 /// rounding behavior is the default (round-to-zero for all floating point 121 /// to integer conversions, and round-to-nearest for all other arithmetic 122 /// truncations). If this is enabled (set to true), the code generator must 123 /// assume that the rounding mode may dynamically change. 124 unsigned HonorSignDependentRoundingFPMathOption : 1; 125 bool HonorSignDependentRoundingFPMath() const; 126 127 /// NoZerosInBSS - By default some codegens place zero-initialized data to 128 /// .bss section. This flag disables such behaviour (necessary, e.g. for 129 /// crt*.o compiling). 130 unsigned NoZerosInBSS : 1; 131 132 /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is 133 /// specified on the commandline. When the flag is on, participating targets 134 /// will perform tail call optimization on all calls which use the fastcc 135 /// calling convention and which satisfy certain target-independent 136 /// criteria (being at the end of a function, having the same return type 137 /// as their parent function, etc.), using an alternate ABI if necessary. 138 unsigned GuaranteedTailCallOpt : 1; 139 140 /// StackAlignmentOverride - Override default stack alignment for target. 141 unsigned StackAlignmentOverride; 142 143 /// EnableFastISel - This flag enables fast-path instruction selection 144 /// which trades away generated code quality in favor of reducing 145 /// compile time. 146 unsigned EnableFastISel : 1; 147 148 /// PositionIndependentExecutable - This flag indicates whether the code 149 /// will eventually be linked into a single executable, despite the PIC 150 /// relocation model being in use. It's value is undefined (and irrelevant) 151 /// if the relocation model is anything other than PIC. 152 unsigned PositionIndependentExecutable : 1; 153 154 /// UseInitArray - Use .init_array instead of .ctors for static 155 /// constructors. 156 unsigned UseInitArray : 1; 157 158 /// Disable the integrated assembler. 159 unsigned DisableIntegratedAS : 1; 160 161 /// Compress DWARF debug sections. 162 unsigned CompressDebugSections : 1; 163 164 /// Emit functions into separate sections. 165 unsigned FunctionSections : 1; 166 167 /// Emit data into separate sections. 168 unsigned DataSections : 1; 169 170 unsigned UniqueSectionNames : 1; 171 172 /// Emit target-specific trap instruction for 'unreachable' IR instructions. 173 unsigned TrapUnreachable : 1; 174 175 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied 176 /// on the command line. This setting may either be Default, Soft, or Hard. 177 /// Default selects the target's default behavior. Soft selects the ABI for 178 /// software floating point, but does not indicate that FP hardware may not 179 /// be used. Such a combination is unfortunately popular (e.g. 180 /// arm-apple-darwin). Hard presumes that the normal FP ABI is used. 181 FloatABI::ABIType FloatABIType; 182 183 /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option. 184 /// This controls the creation of fused FP ops that store intermediate 185 /// results in higher precision than IEEE allows (E.g. FMAs). 186 /// 187 /// Fast mode - allows formation of fused FP ops whenever they're 188 /// profitable. 189 /// Standard mode - allow fusion only for 'blessed' FP ops. At present the 190 /// only blessed op is the fmuladd intrinsic. In the future more blessed ops 191 /// may be added. 192 /// Strict mode - allow fusion only if/when it can be proven that the excess 193 /// precision won't effect the result. 194 /// 195 /// Note: This option only controls formation of fused ops by the 196 /// optimizers. Fused operations that are explicitly specified (e.g. FMA 197 /// via the llvm.fma.* intrinsic) will always be honored, regardless of 198 /// the value of this option. 199 FPOpFusion::FPOpFusionMode AllowFPOpFusion; 200 201 /// This class encapsulates options for reciprocal-estimate code generation. 202 TargetRecip Reciprocals; 203 204 /// JTType - This flag specifies the type of jump-instruction table to 205 /// create for functions that have the jumptable attribute. 206 JumpTable::JumpTableType JTType; 207 208 /// ThreadModel - This flag specifies the type of threading model to assume 209 /// for things like atomics 210 ThreadModel::Model ThreadModel; 211 212 /// Machine level options. 213 MCTargetOptions MCOptions; 214 }; 215 216 // Comparison operators: 217 218 219 inline bool operator==(const TargetOptions &LHS, 220 const TargetOptions &RHS) { 221 #define ARE_EQUAL(X) LHS.X == RHS.X 222 return 223 ARE_EQUAL(UnsafeFPMath) && 224 ARE_EQUAL(NoInfsFPMath) && 225 ARE_EQUAL(NoNaNsFPMath) && 226 ARE_EQUAL(HonorSignDependentRoundingFPMathOption) && 227 ARE_EQUAL(NoZerosInBSS) && 228 ARE_EQUAL(GuaranteedTailCallOpt) && 229 ARE_EQUAL(StackAlignmentOverride) && 230 ARE_EQUAL(EnableFastISel) && 231 ARE_EQUAL(PositionIndependentExecutable) && 232 ARE_EQUAL(UseInitArray) && 233 ARE_EQUAL(TrapUnreachable) && 234 ARE_EQUAL(FloatABIType) && 235 ARE_EQUAL(AllowFPOpFusion) && 236 ARE_EQUAL(Reciprocals) && 237 ARE_EQUAL(JTType) && 238 ARE_EQUAL(ThreadModel) && 239 ARE_EQUAL(MCOptions); 240 #undef ARE_EQUAL 241 } 242 243 inline bool operator!=(const TargetOptions &LHS, 244 const TargetOptions &RHS) { 245 return !(LHS == RHS); 246 } 247 248 } // End llvm namespace 249 250 #endif 251