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