338291465b6ef7eda7eead113a0092c292cc9c73
[oota-llvm.git] / include / llvm / Target / TargetOptions.h
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 #include <string>
20
21 namespace llvm {
22   class MachineFunction;
23   class StringRef;
24
25   // Possible float ABI settings. Used with FloatABIType in TargetOptions.h.
26   namespace FloatABI {
27     enum ABIType {
28       Default, // Target-specific (either soft or hard depending on triple,etc).
29       Soft, // Soft float.
30       Hard  // Hard float.
31     };
32   }
33
34   namespace FPOpFusion {
35     enum FPOpFusionMode {
36       Fast,     // Enable fusion of FP ops wherever it's profitable.
37       Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd).
38       Strict    // Never fuse FP-ops.
39     };
40   }
41
42   namespace JumpTable {
43     enum JumpTableType {
44       Single,          // Use a single table for all indirect jumptable calls.
45       Arity,           // Use one table per number of function parameters.
46       Simplified,      // Use one table per function type, with types projected
47                        // into 4 types: pointer to non-function, struct,
48                        // primitive, and function pointer.
49       Full             // Use one table per unique function type
50     };
51   }
52
53   namespace ThreadModel {
54     enum Model {
55       POSIX,  // POSIX Threads
56       Single  // Single Threaded Environment
57     };
58   }
59
60   class TargetOptions {
61   public:
62     TargetOptions()
63         : PrintMachineCode(false), NoFramePointerElim(false),
64           LessPreciseFPMADOption(false), UnsafeFPMath(false),
65           NoInfsFPMath(false), NoNaNsFPMath(false),
66           HonorSignDependentRoundingFPMathOption(false), UseSoftFloat(false),
67           NoZerosInBSS(false), JITEmitDebugInfo(false),
68           JITEmitDebugInfoToDisk(false), GuaranteedTailCallOpt(false),
69           DisableTailCalls(false), StackAlignmentOverride(0),
70           EnableFastISel(false), PositionIndependentExecutable(false),
71           UseInitArray(false), DisableIntegratedAS(false),
72           CompressDebugSections(false), FunctionSections(false),
73           DataSections(false), TrapUnreachable(false), TrapFuncName(""),
74           FloatABIType(FloatABI::Default),
75           AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single) {}
76
77     /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
78     /// option is specified on the command line, and should enable debugging
79     /// output from the code generator.
80     unsigned PrintMachineCode : 1;
81
82     /// NoFramePointerElim - This flag is enabled when the -disable-fp-elim is
83     /// specified on the command line.  If the target supports the frame pointer
84     /// elimination optimization, this option should disable it.
85     unsigned NoFramePointerElim : 1;
86
87     /// DisableFramePointerElim - This returns true if frame pointer elimination
88     /// optimization should be disabled for the given machine function.
89     bool DisableFramePointerElim(const MachineFunction &MF) const;
90
91     /// LessPreciseFPMAD - This flag is enabled when the
92     /// -enable-fp-mad is specified on the command line.  When this flag is off
93     /// (the default), the code generator is not allowed to generate mad
94     /// (multiply add) if the result is "less precise" than doing those
95     /// operations individually.
96     unsigned LessPreciseFPMADOption : 1;
97     bool LessPreciseFPMAD() const;
98
99     /// UnsafeFPMath - This flag is enabled when the
100     /// -enable-unsafe-fp-math flag is specified on the command line.  When
101     /// this flag is off (the default), the code generator is not allowed to
102     /// produce results that are "less precise" than IEEE allows.  This includes
103     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
104     /// UnsafeFPMath implies LessPreciseFPMAD.
105     unsigned UnsafeFPMath : 1;
106
107     /// NoInfsFPMath - This flag is enabled when the
108     /// -enable-no-infs-fp-math flag is specified on the command line. When
109     /// this flag is off (the default), the code generator is not allowed to
110     /// assume the FP arithmetic arguments and results are never +-Infs.
111     unsigned NoInfsFPMath : 1;
112
113     /// NoNaNsFPMath - This flag is enabled when the
114     /// -enable-no-nans-fp-math flag is specified on the command line. When
115     /// this flag is off (the default), the code generator is not allowed to
116     /// assume the FP arithmetic arguments and results are never NaNs.
117     unsigned NoNaNsFPMath : 1;
118
119     /// HonorSignDependentRoundingFPMath - This returns true when the
120     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
121     /// false (the default), the code generator is allowed to assume that the
122     /// rounding behavior is the default (round-to-zero for all floating point
123     /// to integer conversions, and round-to-nearest for all other arithmetic
124     /// truncations).  If this is enabled (set to true), the code generator must
125     /// assume that the rounding mode may dynamically change.
126     unsigned HonorSignDependentRoundingFPMathOption : 1;
127     bool HonorSignDependentRoundingFPMath() const;
128
129     /// UseSoftFloat - This flag is enabled when the -soft-float flag is
130     /// specified on the command line.  When this flag is on, the code generator
131     /// will generate libcalls to the software floating point library instead of
132     /// target FP instructions.
133     unsigned UseSoftFloat : 1;
134
135     /// NoZerosInBSS - By default some codegens place zero-initialized data to
136     /// .bss section. This flag disables such behaviour (necessary, e.g. for
137     /// crt*.o compiling).
138     unsigned NoZerosInBSS : 1;
139
140     /// JITEmitDebugInfo - This flag indicates that the JIT should try to emit
141     /// debug information and notify a debugger about it.
142     unsigned JITEmitDebugInfo : 1;
143
144     /// JITEmitDebugInfoToDisk - This flag indicates that the JIT should write
145     /// the object files generated by the JITEmitDebugInfo flag to disk.  This
146     /// flag is hidden and is only for debugging the debug info.
147     unsigned JITEmitDebugInfoToDisk : 1;
148
149     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
150     /// specified on the commandline. When the flag is on, participating targets
151     /// will perform tail call optimization on all calls which use the fastcc
152     /// calling convention and which satisfy certain target-independent
153     /// criteria (being at the end of a function, having the same return type
154     /// as their parent function, etc.), using an alternate ABI if necessary.
155     unsigned GuaranteedTailCallOpt : 1;
156
157     /// DisableTailCalls - This flag controls whether we will use tail calls.
158     /// Disabling them may be useful to maintain a correct call stack.
159     unsigned DisableTailCalls : 1;
160
161     /// StackAlignmentOverride - Override default stack alignment for target.
162     unsigned StackAlignmentOverride;
163
164     /// EnableFastISel - This flag enables fast-path instruction selection
165     /// which trades away generated code quality in favor of reducing
166     /// compile time.
167     unsigned EnableFastISel : 1;
168
169     /// PositionIndependentExecutable - This flag indicates whether the code
170     /// will eventually be linked into a single executable, despite the PIC
171     /// relocation model being in use. It's value is undefined (and irrelevant)
172     /// if the relocation model is anything other than PIC.
173     unsigned PositionIndependentExecutable : 1;
174
175     /// UseInitArray - Use .init_array instead of .ctors for static
176     /// constructors.
177     unsigned UseInitArray : 1;
178
179     /// Disable the integrated assembler.
180     unsigned DisableIntegratedAS : 1;
181
182     /// Compress DWARF debug sections.
183     unsigned CompressDebugSections : 1;
184
185     /// Emit functions into separate sections.
186     unsigned FunctionSections : 1;
187
188     /// Emit data into separate sections.
189     unsigned DataSections : 1;
190
191     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
192     unsigned TrapUnreachable : 1;
193
194     /// getTrapFunctionName - If this returns a non-empty string, this means
195     /// isel should lower Intrinsic::trap to a call to the specified function
196     /// name instead of an ISD::TRAP node.
197     std::string TrapFuncName;
198     StringRef getTrapFunctionName() const;
199
200     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
201     /// on the command line. This setting may either be Default, Soft, or Hard.
202     /// Default selects the target's default behavior. Soft selects the ABI for
203     /// UseSoftFloat, but does not indicate that FP hardware may not be used.
204     /// Such a combination is unfortunately popular (e.g. arm-apple-darwin).
205     /// Hard presumes that the normal FP ABI is used.
206     FloatABI::ABIType FloatABIType;
207
208     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
209     /// This controls the creation of fused FP ops that store intermediate
210     /// results in higher precision than IEEE allows (E.g. FMAs).
211     ///
212     /// Fast mode - allows formation of fused FP ops whenever they're
213     /// profitable.
214     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
215     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
216     /// may be added.
217     /// Strict mode - allow fusion only if/when it can be proven that the excess
218     /// precision won't effect the result.
219     ///
220     /// Note: This option only controls formation of fused ops by the
221     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
222     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
223     /// the value of this option.
224     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
225
226     /// JTType - This flag specifies the type of jump-instruction table to
227     /// create for functions that have the jumptable attribute.
228     JumpTable::JumpTableType JTType;
229
230     /// ThreadModel - This flag specifies the type of threading model to assume
231     /// for things like atomics
232     ThreadModel::Model ThreadModel;
233
234     /// Machine level options.
235     MCTargetOptions MCOptions;
236   };
237
238 // Comparison operators:
239
240
241 inline bool operator==(const TargetOptions &LHS,
242                        const TargetOptions &RHS) {
243 #define ARE_EQUAL(X) LHS.X == RHS.X
244   return
245     ARE_EQUAL(UnsafeFPMath) &&
246     ARE_EQUAL(NoInfsFPMath) &&
247     ARE_EQUAL(NoNaNsFPMath) &&
248     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
249     ARE_EQUAL(UseSoftFloat) &&
250     ARE_EQUAL(NoZerosInBSS) &&
251     ARE_EQUAL(JITEmitDebugInfo) &&
252     ARE_EQUAL(JITEmitDebugInfoToDisk) &&
253     ARE_EQUAL(GuaranteedTailCallOpt) &&
254     ARE_EQUAL(DisableTailCalls) &&
255     ARE_EQUAL(StackAlignmentOverride) &&
256     ARE_EQUAL(EnableFastISel) &&
257     ARE_EQUAL(PositionIndependentExecutable) &&
258     ARE_EQUAL(UseInitArray) &&
259     ARE_EQUAL(TrapUnreachable) &&
260     ARE_EQUAL(TrapFuncName) &&
261     ARE_EQUAL(FloatABIType) &&
262     ARE_EQUAL(AllowFPOpFusion) &&
263     ARE_EQUAL(MCOptions);
264 #undef ARE_EQUAL
265 }
266
267 inline bool operator!=(const TargetOptions &LHS,
268                        const TargetOptions &RHS) {
269   return !(LHS == RHS);
270 }
271
272 } // End llvm namespace
273
274 #endif