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