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