xref: /llvm-project/llvm/include/llvm/Target/TargetOptions.h (revision 3feb724496238ce10d32e8c2bd84b4ea50f9977e)
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     Preset, // Similar to list but the blocks are identified by passes which
68             // seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
69             // This option cannot be set via the command line.
70     None    // Do not use Basic Block Sections.
71   };
72 
73   enum class EABI {
74     Unknown,
75     Default, // Default means not specified
76     EABI4,   // Target-specific (either 4, 5 or gnu depending on triple).
77     EABI5,
78     GNU
79   };
80 
81   /// Identify a debugger for "tuning" the debug info.
82   ///
83   /// The "debugger tuning" concept allows us to present a more intuitive
84   /// interface that unpacks into different sets of defaults for the various
85   /// individual feature-flag settings, that suit the preferences of the
86   /// various debuggers.  However, it's worth remembering that debuggers are
87   /// not the only consumers of debug info, and some variations in DWARF might
88   /// better be treated as target/platform issues. Fundamentally,
89   /// o if the feature is useful (or not) to a particular debugger, regardless
90   ///   of the target, that's a tuning decision;
91   /// o if the feature is useful (or not) on a particular platform, regardless
92   ///   of the debugger, that's a target decision.
93   /// It's not impossible to see both factors in some specific case.
94   enum class DebuggerKind {
95     Default, ///< No specific tuning requested.
96     GDB,     ///< Tune debug info for gdb.
97     LLDB,    ///< Tune debug info for lldb.
98     SCE,     ///< Tune debug info for SCE targets (e.g. PS4).
99     DBX      ///< Tune debug info for dbx.
100   };
101 
102   /// Enable abort calls when global instruction selection fails to lower/select
103   /// an instruction.
104   enum class GlobalISelAbortMode {
105     Disable,        // Disable the abort.
106     Enable,         // Enable the abort.
107     DisableWithDiag // Disable the abort but emit a diagnostic on failure.
108   };
109 
110   /// Indicates when and how the Swift async frame pointer bit should be set.
111   enum class SwiftAsyncFramePointerMode {
112     /// Determine whether to set the bit statically or dynamically based
113     /// on the deployment target.
114     DeploymentBased,
115     /// Always set the bit.
116     Always,
117     /// Never set the bit.
118     Never,
119   };
120 
121   /// \brief Enumeration value for AMDGPU code object version, which is the
122   /// code object version times 100.
123   enum CodeObjectVersionKind {
124     COV_None,
125     COV_2 = 200, // Unsupported.
126     COV_3 = 300, // Unsupported.
127     COV_4 = 400,
128     COV_5 = 500,
129     COV_6 = 600,
130   };
131 
132   class TargetOptions {
133   public:
134     TargetOptions()
135         : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
136           NoTrappingFPMath(true), NoSignedZerosFPMath(false),
137           ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
138           HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
139           GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
140           EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
141           DisableIntegratedAS(false), FunctionSections(false),
142           DataSections(false), IgnoreXCOFFVisibility(false),
143           XCOFFTracebackTable(true), UniqueSectionNames(true),
144           UniqueBasicBlockSectionNames(false), SeparateNamedSections(false),
145           TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
146           EmulatedTLS(false), EnableTLSDESC(false), EnableIPRA(false),
147           EmitStackSizeSection(false), EnableMachineOutliner(false),
148           EnableMachineFunctionSplitter(false),
149           EnableStaticDataPartitioning(false), SupportsDefaultOutlining(false),
150           EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
151           SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
152           ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
153           XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
154           PPCGenScalarMASSEntries(false), JMCInstrument(false),
155           EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
156           VerifyArgABICompliance(true),
157           FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
158 
159     /// DisableFramePointerElim - This returns true if frame pointer elimination
160     /// optimization should be disabled for the given machine function.
161     bool DisableFramePointerElim(const MachineFunction &MF) const;
162 
163     /// FramePointerIsReserved - This returns true if the frame pointer must
164     /// always either point to a new frame record or be un-modified in the given
165     /// function.
166     bool FramePointerIsReserved(const MachineFunction &MF) const;
167 
168     /// If greater than 0, override the default value of
169     /// MCAsmInfo::BinutilsVersion.
170     std::pair<int, int> BinutilsVersion{0, 0};
171 
172     /// UnsafeFPMath - This flag is enabled when the
173     /// -enable-unsafe-fp-math flag is specified on the command line.  When
174     /// this flag is off (the default), the code generator is not allowed to
175     /// produce results that are "less precise" than IEEE allows.  This includes
176     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
177     unsigned UnsafeFPMath : 1;
178 
179     /// NoInfsFPMath - This flag is enabled when the
180     /// -enable-no-infs-fp-math flag is specified on the command line. When
181     /// this flag is off (the default), the code generator is not allowed to
182     /// assume the FP arithmetic arguments and results are never +-Infs.
183     unsigned NoInfsFPMath : 1;
184 
185     /// NoNaNsFPMath - This flag is enabled when the
186     /// -enable-no-nans-fp-math flag is specified on the command line. When
187     /// this flag is off (the default), the code generator is not allowed to
188     /// assume the FP arithmetic arguments and results are never NaNs.
189     unsigned NoNaNsFPMath : 1;
190 
191     /// NoTrappingFPMath - This flag is enabled when the
192     /// -enable-no-trapping-fp-math is specified on the command line. This
193     /// specifies that there are no trap handlers to handle exceptions.
194     unsigned NoTrappingFPMath : 1;
195 
196     /// NoSignedZerosFPMath - This flag is enabled when the
197     /// -enable-no-signed-zeros-fp-math is specified on the command line. This
198     /// specifies that optimizations are allowed to treat the sign of a zero
199     /// argument or result as insignificant.
200     unsigned NoSignedZerosFPMath : 1;
201 
202     /// ApproxFuncFPMath - This flag is enabled when the
203     /// -enable-approx-func-fp-math is specified on the command line. This
204     /// specifies that optimizations are allowed to substitute math functions
205     /// with approximate calculations
206     unsigned ApproxFuncFPMath : 1;
207 
208     /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
209     /// specified. The code generator is then able to use both volatile and
210     /// nonvolitle vector registers. When false, the code generator only uses
211     /// volatile vector registers which is the default setting on AIX.
212     unsigned EnableAIXExtendedAltivecABI : 1;
213 
214     /// HonorSignDependentRoundingFPMath - This returns true when the
215     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
216     /// false (the default), the code generator is allowed to assume that the
217     /// rounding behavior is the default (round-to-zero for all floating point
218     /// to integer conversions, and round-to-nearest for all other arithmetic
219     /// truncations).  If this is enabled (set to true), the code generator must
220     /// assume that the rounding mode may dynamically change.
221     unsigned HonorSignDependentRoundingFPMathOption : 1;
222     bool HonorSignDependentRoundingFPMath() const;
223 
224     /// NoZerosInBSS - By default some codegens place zero-initialized data to
225     /// .bss section. This flag disables such behaviour (necessary, e.g. for
226     /// crt*.o compiling).
227     unsigned NoZerosInBSS : 1;
228 
229     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
230     /// specified on the commandline. When the flag is on, participating targets
231     /// will perform tail call optimization on all calls which use the fastcc
232     /// calling convention and which satisfy certain target-independent
233     /// criteria (being at the end of a function, having the same return type
234     /// as their parent function, etc.), using an alternate ABI if necessary.
235     unsigned GuaranteedTailCallOpt : 1;
236 
237     /// StackSymbolOrdering - When true, this will allow CodeGen to order
238     /// the local stack symbols (for code size, code locality, or any other
239     /// heuristics). When false, the local symbols are left in whatever order
240     /// they were generated. Default is true.
241     unsigned StackSymbolOrdering : 1;
242 
243     /// EnableFastISel - This flag enables fast-path instruction selection
244     /// which trades away generated code quality in favor of reducing
245     /// compile time.
246     unsigned EnableFastISel : 1;
247 
248     /// EnableGlobalISel - This flag enables global instruction selection.
249     unsigned EnableGlobalISel : 1;
250 
251     /// EnableGlobalISelAbort - Control abort behaviour when global instruction
252     /// selection fails to lower/select an instruction.
253     GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable;
254 
255     /// Control when and how the Swift async frame pointer bit should
256     /// be set.
257     SwiftAsyncFramePointerMode SwiftAsyncFramePointer =
258         SwiftAsyncFramePointerMode::Always;
259 
260     /// UseInitArray - Use .init_array instead of .ctors for static
261     /// constructors.
262     unsigned UseInitArray : 1;
263 
264     /// Disable the integrated assembler.
265     unsigned DisableIntegratedAS : 1;
266 
267     /// Emit functions into separate sections.
268     unsigned FunctionSections : 1;
269 
270     /// Emit data into separate sections.
271     unsigned DataSections : 1;
272 
273     /// Do not emit visibility attribute for xcoff.
274     unsigned IgnoreXCOFFVisibility : 1;
275 
276     /// Emit XCOFF traceback table.
277     unsigned XCOFFTracebackTable : 1;
278 
279     unsigned UniqueSectionNames : 1;
280 
281     /// Use unique names for basic block sections.
282     unsigned UniqueBasicBlockSectionNames : 1;
283 
284     /// Emit named sections with the same name into different sections.
285     unsigned SeparateNamedSections : 1;
286 
287     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
288     unsigned TrapUnreachable : 1;
289 
290     /// Do not emit a trap instruction for 'unreachable' IR instructions behind
291     /// noreturn calls, even if TrapUnreachable is true.
292     unsigned NoTrapAfterNoreturn : 1;
293 
294     /// Bit size of immediate TLS offsets (0 == use the default).
295     unsigned TLSSize : 8;
296 
297     /// EmulatedTLS - This flag enables emulated TLS model, using emutls
298     /// function in the runtime library..
299     unsigned EmulatedTLS : 1;
300 
301     /// EnableTLSDESC - This flag enables TLS Descriptors.
302     unsigned EnableTLSDESC : 1;
303 
304     /// This flag enables InterProcedural Register Allocation (IPRA).
305     unsigned EnableIPRA : 1;
306 
307     /// Emit section containing metadata on function stack sizes.
308     unsigned EmitStackSizeSection : 1;
309 
310     /// Enables the MachineOutliner pass.
311     unsigned EnableMachineOutliner : 1;
312 
313     /// Enables the MachineFunctionSplitter pass.
314     unsigned EnableMachineFunctionSplitter : 1;
315 
316     /// Enables the StaticDataSplitter pass.
317     unsigned EnableStaticDataPartitioning : 1;
318 
319     /// Set if the target supports default outlining behaviour.
320     unsigned SupportsDefaultOutlining : 1;
321 
322     /// Emit address-significance table.
323     unsigned EmitAddrsig : 1;
324 
325     // Emit the SHT_LLVM_BB_ADDR_MAP section containing basic block address
326     // which can be used to map virtual addresses to machine basic blocks.
327     unsigned BBAddrMap : 1;
328 
329     /// Emit basic blocks into separate sections.
330     BasicBlockSection BBSections = BasicBlockSection::None;
331 
332     /// Memory Buffer that contains information on sampled basic blocks and used
333     /// to selectively generate basic block sections.
334     std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
335 
336     /// The flag enables call site info production. It is used only for debug
337     /// info, and it is restricted only to optimized code. This can be used for
338     /// something else, so that should be controlled in the frontend.
339     unsigned EmitCallSiteInfo : 1;
340     /// Set if the target supports the debug entry values by default.
341     unsigned SupportsDebugEntryValues : 1;
342     /// When set to true, the EnableDebugEntryValues option forces production
343     /// of debug entry values even if the target does not officially support
344     /// it. Useful for testing purposes only. This flag should never be checked
345     /// directly, always use \ref ShouldEmitDebugEntryValues instead.
346      unsigned EnableDebugEntryValues : 1;
347     /// NOTE: There are targets that still do not support the debug entry values
348     /// production.
349     bool ShouldEmitDebugEntryValues() const;
350 
351     // When set to true, use experimental new debug variable location tracking,
352     // which seeks to follow the values of variables rather than their location,
353     // post isel.
354     unsigned ValueTrackingVariableLocations : 1;
355 
356     /// Emit DWARF debug frame section.
357     unsigned ForceDwarfFrameSection : 1;
358 
359     /// Emit XRay Function Index section
360     unsigned XRayFunctionIndex : 1;
361 
362     /// When set to true, don't use DWARF extensions in later DWARF versions.
363     /// By default, it is set to false.
364     unsigned DebugStrictDwarf : 1;
365 
366     /// Emit the hotpatch flag in CodeView debug.
367     unsigned Hotpatch : 1;
368 
369     /// Enables scalar MASS conversions
370     unsigned PPCGenScalarMASSEntries : 1;
371 
372     /// Enable JustMyCode instrumentation.
373     unsigned JMCInstrument : 1;
374 
375     /// Enable the CFIFixup pass.
376     unsigned EnableCFIFixup : 1;
377 
378     /// When set to true, enable MisExpect Diagnostics
379     /// By default, it is set to false
380     unsigned MisExpect : 1;
381 
382     /// When set to true, const objects with relocatable address values are put
383     /// into the RO data section.
384     unsigned XCOFFReadOnlyPointers : 1;
385 
386     /// When set to true, call/return argument extensions of narrow integers
387     /// are verified in the target backend if it cares about them. This is
388     /// not done with internal tools like llc that run many tests that ignore
389     /// (lack) these extensions.
390     unsigned VerifyArgABICompliance : 1;
391 
392     /// Name of the stack usage file (i.e., .su file) if user passes
393     /// -fstack-usage. If empty, it can be implied that -fstack-usage is not
394     /// passed on the command line.
395     std::string StackUsageOutput;
396 
397     /// If greater than 0, override TargetLoweringBase::PrefLoopAlignment.
398     unsigned LoopAlignment = 0;
399 
400     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
401     /// on the command line. This setting may either be Default, Soft, or Hard.
402     /// Default selects the target's default behavior. Soft selects the ABI for
403     /// software floating point, but does not indicate that FP hardware may not
404     /// be used. Such a combination is unfortunately popular (e.g.
405     /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
406     FloatABI::ABIType FloatABIType = FloatABI::Default;
407 
408     /// AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
409     /// This controls the creation of fused FP ops that store intermediate
410     /// results in higher precision than IEEE allows (E.g. FMAs).
411     ///
412     /// Fast mode - allows formation of fused FP ops whenever they're
413     /// profitable.
414     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
415     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
416     /// may be added.
417     /// Strict mode - allow fusion only if/when it can be proven that the excess
418     /// precision won't effect the result.
419     ///
420     /// Note: This option only controls formation of fused ops by the
421     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
422     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
423     /// the value of this option.
424     FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard;
425 
426     /// ThreadModel - This flag specifies the type of threading model to assume
427     /// for things like atomics
428     ThreadModel::Model ThreadModel = ThreadModel::POSIX;
429 
430     /// EABIVersion - This flag specifies the EABI version
431     EABI EABIVersion = EABI::Default;
432 
433     /// Which debugger to tune for.
434     DebuggerKind DebuggerTuning = DebuggerKind::Default;
435 
436   private:
437     /// Flushing mode to assume in default FP environment.
438     DenormalMode FPDenormalMode;
439 
440     /// Flushing mode to assume in default FP environment, for float/vector of
441     /// float.
442     DenormalMode FP32DenormalMode;
443 
444   public:
445     void setFPDenormalMode(DenormalMode Mode) {
446       FPDenormalMode = Mode;
447     }
448 
449     void setFP32DenormalMode(DenormalMode Mode) {
450       FP32DenormalMode = Mode;
451     }
452 
453     DenormalMode getRawFPDenormalMode() const {
454       return FPDenormalMode;
455     }
456 
457     DenormalMode getRawFP32DenormalMode() const {
458       return FP32DenormalMode;
459     }
460 
461     DenormalMode getDenormalMode(const fltSemantics &FPType) const;
462 
463     /// What exception model to use
464     ExceptionHandling ExceptionModel = ExceptionHandling::None;
465 
466     /// Machine level options.
467     MCTargetOptions MCOptions;
468 
469     /// Stores the filename/path of the final .o/.obj file, to be written in the
470     /// debug information. This is used for emitting the CodeView S_OBJNAME
471     /// record.
472     std::string ObjectFilenameForDebug;
473   };
474 
475 } // End llvm namespace
476 
477 #endif
478