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   enum class EABI {
62     Unknown,
63     Default, // Default means not specified
64     EABI4,   // Target-specific (either 4, 5 or gnu depending on triple).
65     EABI5,
66     GNU
67   };
68 
69   /// Identify a debugger for "tuning" the debug info.
70   ///
71   /// The "debugger tuning" concept allows us to present a more intuitive
72   /// interface that unpacks into different sets of defaults for the various
73   /// individual feature-flag settings, that suit the preferences of the
74   /// various debuggers.  However, it's worth remembering that debuggers are
75   /// not the only consumers of debug info, and some variations in DWARF might
76   /// better be treated as target/platform issues. Fundamentally,
77   /// o if the feature is useful (or not) to a particular debugger, regardless
78   ///   of the target, that's a tuning decision;
79   /// o if the feature is useful (or not) on a particular platform, regardless
80   ///   of the debugger, that's a target decision.
81   /// It's not impossible to see both factors in some specific case.
82   ///
83   /// The "tuning" should be used to set defaults for individual feature flags
84   /// in DwarfDebug; if a given feature has a more specific command-line option,
85   /// that option should take precedence over the tuning.
86   enum class DebuggerKind {
87     Default,  // No specific tuning requested.
88     GDB,      // Tune debug info for gdb.
89     LLDB,     // Tune debug info for lldb.
90     SCE       // Tune debug info for SCE targets (e.g. PS4).
91   };
92 
93   class TargetOptions {
94   public:
TargetOptions()95     TargetOptions()
96         : PrintMachineCode(false), LessPreciseFPMADOption(false),
97           UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
98           HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
99           GuaranteedTailCallOpt(false), StackAlignmentOverride(0),
100           EnableFastISel(false), PositionIndependentExecutable(false),
101           UseInitArray(false), DisableIntegratedAS(false),
102           CompressDebugSections(false), FunctionSections(false),
103           DataSections(false), UniqueSectionNames(true), TrapUnreachable(false),
104           EmulatedTLS(false), FloatABIType(FloatABI::Default),
105           AllowFPOpFusion(FPOpFusion::Standard), Reciprocals(TargetRecip()),
106           JTType(JumpTable::Single), ThreadModel(ThreadModel::POSIX),
107           EABIVersion(EABI::Default), DebuggerTuning(DebuggerKind::Default) {}
108 
109     /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
110     /// option is specified on the command line, and should enable debugging
111     /// output from the code generator.
112     unsigned PrintMachineCode : 1;
113 
114     /// DisableFramePointerElim - This returns true if frame pointer elimination
115     /// optimization should be disabled for the given machine function.
116     bool DisableFramePointerElim(const MachineFunction &MF) const;
117 
118     /// LessPreciseFPMAD - This flag is enabled when the
119     /// -enable-fp-mad is specified on the command line.  When this flag is off
120     /// (the default), the code generator is not allowed to generate mad
121     /// (multiply add) if the result is "less precise" than doing those
122     /// operations individually.
123     unsigned LessPreciseFPMADOption : 1;
124     bool LessPreciseFPMAD() const;
125 
126     /// UnsafeFPMath - This flag is enabled when the
127     /// -enable-unsafe-fp-math flag is specified on the command line.  When
128     /// this flag is off (the default), the code generator is not allowed to
129     /// produce results that are "less precise" than IEEE allows.  This includes
130     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
131     /// UnsafeFPMath implies LessPreciseFPMAD.
132     unsigned UnsafeFPMath : 1;
133 
134     /// NoInfsFPMath - This flag is enabled when the
135     /// -enable-no-infs-fp-math flag is specified on the command line. When
136     /// this flag is off (the default), the code generator is not allowed to
137     /// assume the FP arithmetic arguments and results are never +-Infs.
138     unsigned NoInfsFPMath : 1;
139 
140     /// NoNaNsFPMath - This flag is enabled when the
141     /// -enable-no-nans-fp-math flag is specified on the command line. When
142     /// this flag is off (the default), the code generator is not allowed to
143     /// assume the FP arithmetic arguments and results are never NaNs.
144     unsigned NoNaNsFPMath : 1;
145 
146     /// HonorSignDependentRoundingFPMath - This returns true when the
147     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
148     /// false (the default), the code generator is allowed to assume that the
149     /// rounding behavior is the default (round-to-zero for all floating point
150     /// to integer conversions, and round-to-nearest for all other arithmetic
151     /// truncations).  If this is enabled (set to true), the code generator must
152     /// assume that the rounding mode may dynamically change.
153     unsigned HonorSignDependentRoundingFPMathOption : 1;
154     bool HonorSignDependentRoundingFPMath() const;
155 
156     /// NoZerosInBSS - By default some codegens place zero-initialized data to
157     /// .bss section. This flag disables such behaviour (necessary, e.g. for
158     /// crt*.o compiling).
159     unsigned NoZerosInBSS : 1;
160 
161     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
162     /// specified on the commandline. When the flag is on, participating targets
163     /// will perform tail call optimization on all calls which use the fastcc
164     /// calling convention and which satisfy certain target-independent
165     /// criteria (being at the end of a function, having the same return type
166     /// as their parent function, etc.), using an alternate ABI if necessary.
167     unsigned GuaranteedTailCallOpt : 1;
168 
169     /// StackAlignmentOverride - Override default stack alignment for target.
170     unsigned StackAlignmentOverride;
171 
172     /// EnableFastISel - This flag enables fast-path instruction selection
173     /// which trades away generated code quality in favor of reducing
174     /// compile time.
175     unsigned EnableFastISel : 1;
176 
177     /// PositionIndependentExecutable - This flag indicates whether the code
178     /// will eventually be linked into a single executable, despite the PIC
179     /// relocation model being in use. It's value is undefined (and irrelevant)
180     /// if the relocation model is anything other than PIC.
181     unsigned PositionIndependentExecutable : 1;
182 
183     /// UseInitArray - Use .init_array instead of .ctors for static
184     /// constructors.
185     unsigned UseInitArray : 1;
186 
187     /// Disable the integrated assembler.
188     unsigned DisableIntegratedAS : 1;
189 
190     /// Compress DWARF debug sections.
191     unsigned CompressDebugSections : 1;
192 
193     /// Emit functions into separate sections.
194     unsigned FunctionSections : 1;
195 
196     /// Emit data into separate sections.
197     unsigned DataSections : 1;
198 
199     unsigned UniqueSectionNames : 1;
200 
201     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
202     unsigned TrapUnreachable : 1;
203 
204     /// EmulatedTLS - This flag enables emulated TLS model, using emutls
205     /// function in the runtime library..
206     unsigned EmulatedTLS : 1;
207 
208     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
209     /// on the command line. This setting may either be Default, Soft, or Hard.
210     /// Default selects the target's default behavior. Soft selects the ABI for
211     /// software floating point, but does not indicate that FP hardware may not
212     /// be used. Such a combination is unfortunately popular (e.g.
213     /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
214     FloatABI::ABIType FloatABIType;
215 
216     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
217     /// This controls the creation of fused FP ops that store intermediate
218     /// results in higher precision than IEEE allows (E.g. FMAs).
219     ///
220     /// Fast mode - allows formation of fused FP ops whenever they're
221     /// profitable.
222     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
223     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
224     /// may be added.
225     /// Strict mode - allow fusion only if/when it can be proven that the excess
226     /// precision won't effect the result.
227     ///
228     /// Note: This option only controls formation of fused ops by the
229     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
230     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
231     /// the value of this option.
232     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
233 
234     /// This class encapsulates options for reciprocal-estimate code generation.
235     TargetRecip Reciprocals;
236 
237     /// JTType - This flag specifies the type of jump-instruction table to
238     /// create for functions that have the jumptable attribute.
239     JumpTable::JumpTableType JTType;
240 
241     /// ThreadModel - This flag specifies the type of threading model to assume
242     /// for things like atomics
243     ThreadModel::Model ThreadModel;
244 
245     /// EABIVersion - This flag specifies the EABI version
246     EABI EABIVersion;
247 
248     /// Which debugger to tune for.
249     DebuggerKind DebuggerTuning;
250 
251     /// Machine level options.
252     MCTargetOptions MCOptions;
253   };
254 
255 // Comparison operators:
256 
257 
258 inline bool operator==(const TargetOptions &LHS,
259                        const TargetOptions &RHS) {
260 #define ARE_EQUAL(X) LHS.X == RHS.X
261   return
262     ARE_EQUAL(UnsafeFPMath) &&
263     ARE_EQUAL(NoInfsFPMath) &&
264     ARE_EQUAL(NoNaNsFPMath) &&
265     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
266     ARE_EQUAL(NoZerosInBSS) &&
267     ARE_EQUAL(GuaranteedTailCallOpt) &&
268     ARE_EQUAL(StackAlignmentOverride) &&
269     ARE_EQUAL(EnableFastISel) &&
270     ARE_EQUAL(PositionIndependentExecutable) &&
271     ARE_EQUAL(UseInitArray) &&
272     ARE_EQUAL(TrapUnreachable) &&
273     ARE_EQUAL(EmulatedTLS) &&
274     ARE_EQUAL(FloatABIType) &&
275     ARE_EQUAL(AllowFPOpFusion) &&
276     ARE_EQUAL(Reciprocals) &&
277     ARE_EQUAL(JTType) &&
278     ARE_EQUAL(ThreadModel) &&
279     ARE_EQUAL(EABIVersion) &&
280     ARE_EQUAL(DebuggerTuning) &&
281     ARE_EQUAL(MCOptions);
282 #undef ARE_EQUAL
283 }
284 
285 inline bool operator!=(const TargetOptions &LHS,
286                        const TargetOptions &RHS) {
287   return !(LHS == RHS);
288 }
289 
290 } // End llvm namespace
291 
292 #endif
293