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