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