1 //===-- llvm/Target/TargetOptions.h - Target Options ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines command line option flags that are shared across various
10 // targets.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TARGET_TARGETOPTIONS_H
15 #define LLVM_TARGET_TARGETOPTIONS_H
16 
17 #include "llvm/ADT/FloatingPointMode.h"
18 #include "llvm/MC/MCTargetOptions.h"
19 
20 #include <memory>
21 
22 namespace llvm {
23   struct fltSemantics;
24   class MachineFunction;
25   class MemoryBuffer;
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 BasicBlockSection {
62     All,    // Use Basic Block Sections for all basic blocks.  A section
63             // for every basic block can significantly bloat object file sizes.
64     List,   // Get list of functions & BBs from a file. Selectively enables
65             // basic block sections for a subset of basic blocks which can be
66             // used to control object size bloats from creating sections.
67     Labels, // Do not use Basic Block Sections but label basic blocks.  This
68             // is useful when associating profile counts from virtual addresses
69             // to basic blocks.
70     Preset, // Similar to list but the blocks are identified by passes which
71             // seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
72             // This option cannot be set via the command line.
73     None    // Do not use Basic Block Sections.
74   };
75 
76   enum class StackProtectorGuards {
77     None,
78     TLS,
79     Global
80   };
81 
82   enum class EABI {
83     Unknown,
84     Default, // Default means not specified
85     EABI4,   // Target-specific (either 4, 5 or gnu depending on triple).
86     EABI5,
87     GNU
88   };
89 
90   /// Identify a debugger for "tuning" the debug info.
91   ///
92   /// The "debugger tuning" concept allows us to present a more intuitive
93   /// interface that unpacks into different sets of defaults for the various
94   /// individual feature-flag settings, that suit the preferences of the
95   /// various debuggers.  However, it's worth remembering that debuggers are
96   /// not the only consumers of debug info, and some variations in DWARF might
97   /// better be treated as target/platform issues. Fundamentally,
98   /// o if the feature is useful (or not) to a particular debugger, regardless
99   ///   of the target, that's a tuning decision;
100   /// o if the feature is useful (or not) on a particular platform, regardless
101   ///   of the debugger, that's a target decision.
102   /// It's not impossible to see both factors in some specific case.
103   ///
104   /// The "tuning" should be used to set defaults for individual feature flags
105   /// in DwarfDebug; if a given feature has a more specific command-line option,
106   /// that option should take precedence over the tuning.
107   enum class DebuggerKind {
108     Default,  // No specific tuning requested.
109     GDB,      // Tune debug info for gdb.
110     LLDB,     // Tune debug info for lldb.
111     SCE       // Tune debug info for SCE targets (e.g. PS4).
112   };
113 
114   /// Enable abort calls when global instruction selection fails to lower/select
115   /// an instruction.
116   enum class GlobalISelAbortMode {
117     Disable,        // Disable the abort.
118     Enable,         // Enable the abort.
119     DisableWithDiag // Disable the abort but emit a diagnostic on failure.
120   };
121 
122   class TargetOptions {
123   public:
TargetOptions()124     TargetOptions()
125         : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
126           NoTrappingFPMath(true), NoSignedZerosFPMath(false),
127           EnableAIXExtendedAltivecABI(false),
128           HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
129           GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
130           EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
131           DisableIntegratedAS(false), RelaxELFRelocations(false),
132           FunctionSections(false), DataSections(false),
133           IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true),
134           UniqueSectionNames(true), UniqueBasicBlockSectionNames(false),
135           TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
136           EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
137           EmitStackSizeSection(false), EnableMachineOutliner(false),
138           EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
139           EmitAddrsig(false), EmitCallSiteInfo(false),
140           SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
141           PseudoProbeForProfiling(false), ValueTrackingVariableLocations(false),
142           ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false),
143           FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
144 
145     /// DisableFramePointerElim - This returns true if frame pointer elimination
146     /// optimization should be disabled for the given machine function.
147     bool DisableFramePointerElim(const MachineFunction &MF) const;
148 
149     /// If greater than 0, override the default value of
150     /// MCAsmInfo::BinutilsVersion.
151     std::pair<int, int> BinutilsVersion{0, 0};
152 
153     /// UnsafeFPMath - This flag is enabled when the
154     /// -enable-unsafe-fp-math flag is specified on the command line.  When
155     /// this flag is off (the default), the code generator is not allowed to
156     /// produce results that are "less precise" than IEEE allows.  This includes
157     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
158     unsigned UnsafeFPMath : 1;
159 
160     /// NoInfsFPMath - This flag is enabled when the
161     /// -enable-no-infs-fp-math flag is specified on the command line. When
162     /// this flag is off (the default), the code generator is not allowed to
163     /// assume the FP arithmetic arguments and results are never +-Infs.
164     unsigned NoInfsFPMath : 1;
165 
166     /// NoNaNsFPMath - This flag is enabled when the
167     /// -enable-no-nans-fp-math flag is specified on the command line. When
168     /// this flag is off (the default), the code generator is not allowed to
169     /// assume the FP arithmetic arguments and results are never NaNs.
170     unsigned NoNaNsFPMath : 1;
171 
172     /// NoTrappingFPMath - This flag is enabled when the
173     /// -enable-no-trapping-fp-math is specified on the command line. This
174     /// specifies that there are no trap handlers to handle exceptions.
175     unsigned NoTrappingFPMath : 1;
176 
177     /// NoSignedZerosFPMath - This flag is enabled when the
178     /// -enable-no-signed-zeros-fp-math is specified on the command line. This
179     /// specifies that optimizations are allowed to treat the sign of a zero
180     /// argument or result as insignificant.
181     unsigned NoSignedZerosFPMath : 1;
182 
183     /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
184     /// specified. The code generator is then able to use both volatile and
185     /// nonvolitle vector regisers. When false, the code generator only uses
186     /// volatile vector registers which is the default setting on AIX.
187     unsigned EnableAIXExtendedAltivecABI : 1;
188 
189     /// HonorSignDependentRoundingFPMath - This returns true when the
190     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
191     /// false (the default), the code generator is allowed to assume that the
192     /// rounding behavior is the default (round-to-zero for all floating point
193     /// to integer conversions, and round-to-nearest for all other arithmetic
194     /// truncations).  If this is enabled (set to true), the code generator must
195     /// assume that the rounding mode may dynamically change.
196     unsigned HonorSignDependentRoundingFPMathOption : 1;
197     bool HonorSignDependentRoundingFPMath() const;
198 
199     /// NoZerosInBSS - By default some codegens place zero-initialized data to
200     /// .bss section. This flag disables such behaviour (necessary, e.g. for
201     /// crt*.o compiling).
202     unsigned NoZerosInBSS : 1;
203 
204     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
205     /// specified on the commandline. When the flag is on, participating targets
206     /// will perform tail call optimization on all calls which use the fastcc
207     /// calling convention and which satisfy certain target-independent
208     /// criteria (being at the end of a function, having the same return type
209     /// as their parent function, etc.), using an alternate ABI if necessary.
210     unsigned GuaranteedTailCallOpt : 1;
211 
212     /// StackAlignmentOverride - Override default stack alignment for target.
213     unsigned StackAlignmentOverride = 0;
214 
215     /// StackSymbolOrdering - When true, this will allow CodeGen to order
216     /// the local stack symbols (for code size, code locality, or any other
217     /// heuristics). When false, the local symbols are left in whatever order
218     /// they were generated. Default is true.
219     unsigned StackSymbolOrdering : 1;
220 
221     /// EnableFastISel - This flag enables fast-path instruction selection
222     /// which trades away generated code quality in favor of reducing
223     /// compile time.
224     unsigned EnableFastISel : 1;
225 
226     /// EnableGlobalISel - This flag enables global instruction selection.
227     unsigned EnableGlobalISel : 1;
228 
229     /// EnableGlobalISelAbort - Control abort behaviour when global instruction
230     /// selection fails to lower/select an instruction.
231     GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable;
232 
233     /// UseInitArray - Use .init_array instead of .ctors for static
234     /// constructors.
235     unsigned UseInitArray : 1;
236 
237     /// Disable the integrated assembler.
238     unsigned DisableIntegratedAS : 1;
239 
240     /// Compress DWARF debug sections.
241     DebugCompressionType CompressDebugSections = DebugCompressionType::None;
242 
243     unsigned RelaxELFRelocations : 1;
244 
245     /// Emit functions into separate sections.
246     unsigned FunctionSections : 1;
247 
248     /// Emit data into separate sections.
249     unsigned DataSections : 1;
250 
251     /// Do not emit visibility attribute for xcoff.
252     unsigned IgnoreXCOFFVisibility : 1;
253 
254     /// Emit XCOFF traceback table.
255     unsigned XCOFFTracebackTable : 1;
256 
257     unsigned UniqueSectionNames : 1;
258 
259     /// Use unique names for basic block sections.
260     unsigned UniqueBasicBlockSectionNames : 1;
261 
262     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
263     unsigned TrapUnreachable : 1;
264 
265     /// Do not emit a trap instruction for 'unreachable' IR instructions behind
266     /// noreturn calls, even if TrapUnreachable is true.
267     unsigned NoTrapAfterNoreturn : 1;
268 
269     /// Bit size of immediate TLS offsets (0 == use the default).
270     unsigned TLSSize : 8;
271 
272     /// EmulatedTLS - This flag enables emulated TLS model, using emutls
273     /// function in the runtime library..
274     unsigned EmulatedTLS : 1;
275 
276     /// Whether -emulated-tls or -no-emulated-tls is set.
277     unsigned ExplicitEmulatedTLS : 1;
278 
279     /// This flag enables InterProcedural Register Allocation (IPRA).
280     unsigned EnableIPRA : 1;
281 
282     /// Emit section containing metadata on function stack sizes.
283     unsigned EmitStackSizeSection : 1;
284 
285     /// Enables the MachineOutliner pass.
286     unsigned EnableMachineOutliner : 1;
287 
288     /// Enables the MachineFunctionSplitter pass.
289     unsigned EnableMachineFunctionSplitter : 1;
290 
291     /// Set if the target supports default outlining behaviour.
292     unsigned SupportsDefaultOutlining : 1;
293 
294     /// Emit address-significance table.
295     unsigned EmitAddrsig : 1;
296 
297     /// Emit basic blocks into separate sections.
298     BasicBlockSection BBSections = BasicBlockSection::None;
299 
300     /// Memory Buffer that contains information on sampled basic blocks and used
301     /// to selectively generate basic block sections.
302     std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
303 
304     /// The flag enables call site info production. It is used only for debug
305     /// info, and it is restricted only to optimized code. This can be used for
306     /// something else, so that should be controlled in the frontend.
307     unsigned EmitCallSiteInfo : 1;
308     /// Set if the target supports the debug entry values by default.
309     unsigned SupportsDebugEntryValues : 1;
310     /// When set to true, the EnableDebugEntryValues option forces production
311     /// of debug entry values even if the target does not officially support
312     /// it. Useful for testing purposes only. This flag should never be checked
313     /// directly, always use \ref ShouldEmitDebugEntryValues instead.
314      unsigned EnableDebugEntryValues : 1;
315     /// NOTE: There are targets that still do not support the debug entry values
316     /// production.
317     bool ShouldEmitDebugEntryValues() const;
318 
319     /// Emit pseudo probes into the binary for sample profiling
320     unsigned PseudoProbeForProfiling : 1;
321 
322     // When set to true, use experimental new debug variable location tracking,
323     // which seeks to follow the values of variables rather than their location,
324     // post isel.
325     unsigned ValueTrackingVariableLocations : 1;
326 
327     /// Emit DWARF debug frame section.
328     unsigned ForceDwarfFrameSection : 1;
329 
330     /// Emit XRay Function Index section
331     unsigned XRayOmitFunctionIndex : 1;
332 
333     /// Stack protector guard offset to use.
334     unsigned StackProtectorGuardOffset : 32;
335 
336     /// Stack protector guard mode to use, e.g. tls, global.
337     StackProtectorGuards StackProtectorGuard =
338                                          StackProtectorGuards::None;
339 
340     /// Stack protector guard reg to use, e.g. usually fs or gs in X86.
341     std::string StackProtectorGuardReg = "None";
342 
343     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
344     /// on the command line. This setting may either be Default, Soft, or Hard.
345     /// Default selects the target's default behavior. Soft selects the ABI for
346     /// software floating point, but does not indicate that FP hardware may not
347     /// be used. Such a combination is unfortunately popular (e.g.
348     /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
349     FloatABI::ABIType FloatABIType = FloatABI::Default;
350 
351     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
352     /// This controls the creation of fused FP ops that store intermediate
353     /// results in higher precision than IEEE allows (E.g. FMAs).
354     ///
355     /// Fast mode - allows formation of fused FP ops whenever they're
356     /// profitable.
357     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
358     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
359     /// may be added.
360     /// Strict mode - allow fusion only if/when it can be proven that the excess
361     /// precision won't effect the result.
362     ///
363     /// Note: This option only controls formation of fused ops by the
364     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
365     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
366     /// the value of this option.
367     FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard;
368 
369     /// ThreadModel - This flag specifies the type of threading model to assume
370     /// for things like atomics
371     ThreadModel::Model ThreadModel = ThreadModel::POSIX;
372 
373     /// EABIVersion - This flag specifies the EABI version
374     EABI EABIVersion = EABI::Default;
375 
376     /// Which debugger to tune for.
377     DebuggerKind DebuggerTuning = DebuggerKind::Default;
378 
379   private:
380     /// Flushing mode to assume in default FP environment.
381     DenormalMode FPDenormalMode;
382 
383     /// Flushing mode to assume in default FP environment, for float/vector of
384     /// float.
385     DenormalMode FP32DenormalMode;
386 
387   public:
setFPDenormalMode(DenormalMode Mode)388     void setFPDenormalMode(DenormalMode Mode) {
389       FPDenormalMode = Mode;
390     }
391 
setFP32DenormalMode(DenormalMode Mode)392     void setFP32DenormalMode(DenormalMode Mode) {
393       FP32DenormalMode = Mode;
394     }
395 
getRawFPDenormalMode()396     DenormalMode getRawFPDenormalMode() const {
397       return FPDenormalMode;
398     }
399 
getRawFP32DenormalMode()400     DenormalMode getRawFP32DenormalMode() const {
401       return FP32DenormalMode;
402     }
403 
404     DenormalMode getDenormalMode(const fltSemantics &FPType) const;
405 
406     /// What exception model to use
407     ExceptionHandling ExceptionModel = ExceptionHandling::None;
408 
409     /// Machine level options.
410     MCTargetOptions MCOptions;
411   };
412 
413 } // End llvm namespace
414 
415 #endif
416