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