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