Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:36

0001 //===-- llvm/Target/TargetOptions.h - Target Options ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines command line option flags that are shared across various
0010 // targets.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_TARGET_TARGETOPTIONS_H
0015 #define LLVM_TARGET_TARGETOPTIONS_H
0016 
0017 #include "llvm/ADT/FloatingPointMode.h"
0018 #include "llvm/MC/MCTargetOptions.h"
0019 
0020 #include <memory>
0021 
0022 namespace llvm {
0023   struct fltSemantics;
0024   class MachineFunction;
0025   class MemoryBuffer;
0026 
0027   namespace FloatABI {
0028     enum ABIType {
0029       Default, // Target-specific (either soft or hard depending on triple, etc).
0030       Soft,    // Soft float.
0031       Hard     // Hard float.
0032     };
0033   }
0034 
0035   namespace FPOpFusion {
0036     enum FPOpFusionMode {
0037       Fast,     // Enable fusion of FP ops wherever it's profitable.
0038       Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd).
0039       Strict    // Never fuse FP-ops.
0040     };
0041   }
0042 
0043   namespace JumpTable {
0044     enum JumpTableType {
0045       Single,          // Use a single table for all indirect jumptable calls.
0046       Arity,           // Use one table per number of function parameters.
0047       Simplified,      // Use one table per function type, with types projected
0048                        // into 4 types: pointer to non-function, struct,
0049                        // primitive, and function pointer.
0050       Full             // Use one table per unique function type
0051     };
0052   }
0053 
0054   namespace ThreadModel {
0055     enum Model {
0056       POSIX,  // POSIX Threads
0057       Single  // Single Threaded Environment
0058     };
0059   }
0060 
0061   enum class BasicBlockSection {
0062     All,    // Use Basic Block Sections for all basic blocks.  A section
0063             // for every basic block can significantly bloat object file sizes.
0064     List,   // Get list of functions & BBs from a file. Selectively enables
0065             // basic block sections for a subset of basic blocks which can be
0066             // used to control object size bloats from creating sections.
0067     Preset, // Similar to list but the blocks are identified by passes which
0068             // seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
0069             // This option cannot be set via the command line.
0070     None    // Do not use Basic Block Sections.
0071   };
0072 
0073   enum class EABI {
0074     Unknown,
0075     Default, // Default means not specified
0076     EABI4,   // Target-specific (either 4, 5 or gnu depending on triple).
0077     EABI5,
0078     GNU
0079   };
0080 
0081   /// Identify a debugger for "tuning" the debug info.
0082   ///
0083   /// The "debugger tuning" concept allows us to present a more intuitive
0084   /// interface that unpacks into different sets of defaults for the various
0085   /// individual feature-flag settings, that suit the preferences of the
0086   /// various debuggers.  However, it's worth remembering that debuggers are
0087   /// not the only consumers of debug info, and some variations in DWARF might
0088   /// better be treated as target/platform issues. Fundamentally,
0089   /// o if the feature is useful (or not) to a particular debugger, regardless
0090   ///   of the target, that's a tuning decision;
0091   /// o if the feature is useful (or not) on a particular platform, regardless
0092   ///   of the debugger, that's a target decision.
0093   /// It's not impossible to see both factors in some specific case.
0094   enum class DebuggerKind {
0095     Default, ///< No specific tuning requested.
0096     GDB,     ///< Tune debug info for gdb.
0097     LLDB,    ///< Tune debug info for lldb.
0098     SCE,     ///< Tune debug info for SCE targets (e.g. PS4).
0099     DBX      ///< Tune debug info for dbx.
0100   };
0101 
0102   /// Enable abort calls when global instruction selection fails to lower/select
0103   /// an instruction.
0104   enum class GlobalISelAbortMode {
0105     Disable,        // Disable the abort.
0106     Enable,         // Enable the abort.
0107     DisableWithDiag // Disable the abort but emit a diagnostic on failure.
0108   };
0109 
0110   /// Indicates when and how the Swift async frame pointer bit should be set.
0111   enum class SwiftAsyncFramePointerMode {
0112     /// Determine whether to set the bit statically or dynamically based
0113     /// on the deployment target.
0114     DeploymentBased,
0115     /// Always set the bit.
0116     Always,
0117     /// Never set the bit.
0118     Never,
0119   };
0120 
0121   /// \brief Enumeration value for AMDGPU code object version, which is the
0122   /// code object version times 100.
0123   enum CodeObjectVersionKind {
0124     COV_None,
0125     COV_2 = 200, // Unsupported.
0126     COV_3 = 300, // Unsupported.
0127     COV_4 = 400,
0128     COV_5 = 500,
0129     COV_6 = 600,
0130   };
0131 
0132   class TargetOptions {
0133   public:
0134     TargetOptions()
0135         : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
0136           NoTrappingFPMath(true), NoSignedZerosFPMath(false),
0137           ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
0138           HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
0139           GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
0140           EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
0141           DisableIntegratedAS(false), FunctionSections(false),
0142           DataSections(false), IgnoreXCOFFVisibility(false),
0143           XCOFFTracebackTable(true), UniqueSectionNames(true),
0144           UniqueBasicBlockSectionNames(false), SeparateNamedSections(false),
0145           TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
0146           EmulatedTLS(false), EnableTLSDESC(false), EnableIPRA(false),
0147           EmitStackSizeSection(false), EnableMachineOutliner(false),
0148           EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
0149           EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
0150           SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
0151           ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
0152           XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
0153           PPCGenScalarMASSEntries(false), JMCInstrument(false),
0154           EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
0155           VerifyArgABICompliance(true),
0156           FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
0157 
0158     /// DisableFramePointerElim - This returns true if frame pointer elimination
0159     /// optimization should be disabled for the given machine function.
0160     bool DisableFramePointerElim(const MachineFunction &MF) const;
0161 
0162     /// FramePointerIsReserved - This returns true if the frame pointer must
0163     /// always either point to a new frame record or be un-modified in the given
0164     /// function.
0165     bool FramePointerIsReserved(const MachineFunction &MF) const;
0166 
0167     /// If greater than 0, override the default value of
0168     /// MCAsmInfo::BinutilsVersion.
0169     std::pair<int, int> BinutilsVersion{0, 0};
0170 
0171     /// UnsafeFPMath - This flag is enabled when the
0172     /// -enable-unsafe-fp-math flag is specified on the command line.  When
0173     /// this flag is off (the default), the code generator is not allowed to
0174     /// produce results that are "less precise" than IEEE allows.  This includes
0175     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
0176     unsigned UnsafeFPMath : 1;
0177 
0178     /// NoInfsFPMath - This flag is enabled when the
0179     /// -enable-no-infs-fp-math flag is specified on the command line. When
0180     /// this flag is off (the default), the code generator is not allowed to
0181     /// assume the FP arithmetic arguments and results are never +-Infs.
0182     unsigned NoInfsFPMath : 1;
0183 
0184     /// NoNaNsFPMath - This flag is enabled when the
0185     /// -enable-no-nans-fp-math flag is specified on the command line. When
0186     /// this flag is off (the default), the code generator is not allowed to
0187     /// assume the FP arithmetic arguments and results are never NaNs.
0188     unsigned NoNaNsFPMath : 1;
0189 
0190     /// NoTrappingFPMath - This flag is enabled when the
0191     /// -enable-no-trapping-fp-math is specified on the command line. This
0192     /// specifies that there are no trap handlers to handle exceptions.
0193     unsigned NoTrappingFPMath : 1;
0194 
0195     /// NoSignedZerosFPMath - This flag is enabled when the
0196     /// -enable-no-signed-zeros-fp-math is specified on the command line. This
0197     /// specifies that optimizations are allowed to treat the sign of a zero
0198     /// argument or result as insignificant.
0199     unsigned NoSignedZerosFPMath : 1;
0200 
0201     /// ApproxFuncFPMath - This flag is enabled when the
0202     /// -enable-approx-func-fp-math is specified on the command line. This
0203     /// specifies that optimizations are allowed to substitute math functions
0204     /// with approximate calculations
0205     unsigned ApproxFuncFPMath : 1;
0206 
0207     /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
0208     /// specified. The code generator is then able to use both volatile and
0209     /// nonvolitle vector registers. When false, the code generator only uses
0210     /// volatile vector registers which is the default setting on AIX.
0211     unsigned EnableAIXExtendedAltivecABI : 1;
0212 
0213     /// HonorSignDependentRoundingFPMath - This returns true when the
0214     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
0215     /// false (the default), the code generator is allowed to assume that the
0216     /// rounding behavior is the default (round-to-zero for all floating point
0217     /// to integer conversions, and round-to-nearest for all other arithmetic
0218     /// truncations).  If this is enabled (set to true), the code generator must
0219     /// assume that the rounding mode may dynamically change.
0220     unsigned HonorSignDependentRoundingFPMathOption : 1;
0221     bool HonorSignDependentRoundingFPMath() const;
0222 
0223     /// NoZerosInBSS - By default some codegens place zero-initialized data to
0224     /// .bss section. This flag disables such behaviour (necessary, e.g. for
0225     /// crt*.o compiling).
0226     unsigned NoZerosInBSS : 1;
0227 
0228     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
0229     /// specified on the commandline. When the flag is on, participating targets
0230     /// will perform tail call optimization on all calls which use the fastcc
0231     /// calling convention and which satisfy certain target-independent
0232     /// criteria (being at the end of a function, having the same return type
0233     /// as their parent function, etc.), using an alternate ABI if necessary.
0234     unsigned GuaranteedTailCallOpt : 1;
0235 
0236     /// StackSymbolOrdering - When true, this will allow CodeGen to order
0237     /// the local stack symbols (for code size, code locality, or any other
0238     /// heuristics). When false, the local symbols are left in whatever order
0239     /// they were generated. Default is true.
0240     unsigned StackSymbolOrdering : 1;
0241 
0242     /// EnableFastISel - This flag enables fast-path instruction selection
0243     /// which trades away generated code quality in favor of reducing
0244     /// compile time.
0245     unsigned EnableFastISel : 1;
0246 
0247     /// EnableGlobalISel - This flag enables global instruction selection.
0248     unsigned EnableGlobalISel : 1;
0249 
0250     /// EnableGlobalISelAbort - Control abort behaviour when global instruction
0251     /// selection fails to lower/select an instruction.
0252     GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable;
0253 
0254     /// Control when and how the Swift async frame pointer bit should
0255     /// be set.
0256     SwiftAsyncFramePointerMode SwiftAsyncFramePointer =
0257         SwiftAsyncFramePointerMode::Always;
0258 
0259     /// UseInitArray - Use .init_array instead of .ctors for static
0260     /// constructors.
0261     unsigned UseInitArray : 1;
0262 
0263     /// Disable the integrated assembler.
0264     unsigned DisableIntegratedAS : 1;
0265 
0266     /// Emit functions into separate sections.
0267     unsigned FunctionSections : 1;
0268 
0269     /// Emit data into separate sections.
0270     unsigned DataSections : 1;
0271 
0272     /// Do not emit visibility attribute for xcoff.
0273     unsigned IgnoreXCOFFVisibility : 1;
0274 
0275     /// Emit XCOFF traceback table.
0276     unsigned XCOFFTracebackTable : 1;
0277 
0278     unsigned UniqueSectionNames : 1;
0279 
0280     /// Use unique names for basic block sections.
0281     unsigned UniqueBasicBlockSectionNames : 1;
0282 
0283     /// Emit named sections with the same name into different sections.
0284     unsigned SeparateNamedSections : 1;
0285 
0286     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
0287     unsigned TrapUnreachable : 1;
0288 
0289     /// Do not emit a trap instruction for 'unreachable' IR instructions behind
0290     /// noreturn calls, even if TrapUnreachable is true.
0291     unsigned NoTrapAfterNoreturn : 1;
0292 
0293     /// Bit size of immediate TLS offsets (0 == use the default).
0294     unsigned TLSSize : 8;
0295 
0296     /// EmulatedTLS - This flag enables emulated TLS model, using emutls
0297     /// function in the runtime library..
0298     unsigned EmulatedTLS : 1;
0299 
0300     /// EnableTLSDESC - This flag enables TLS Descriptors.
0301     unsigned EnableTLSDESC : 1;
0302 
0303     /// This flag enables InterProcedural Register Allocation (IPRA).
0304     unsigned EnableIPRA : 1;
0305 
0306     /// Emit section containing metadata on function stack sizes.
0307     unsigned EmitStackSizeSection : 1;
0308 
0309     /// Enables the MachineOutliner pass.
0310     unsigned EnableMachineOutliner : 1;
0311 
0312     /// Enables the MachineFunctionSplitter pass.
0313     unsigned EnableMachineFunctionSplitter : 1;
0314 
0315     /// Set if the target supports default outlining behaviour.
0316     unsigned SupportsDefaultOutlining : 1;
0317 
0318     /// Emit address-significance table.
0319     unsigned EmitAddrsig : 1;
0320 
0321     // Emit the SHT_LLVM_BB_ADDR_MAP section containing basic block address
0322     // which can be used to map virtual addresses to machine basic blocks.
0323     unsigned BBAddrMap : 1;
0324 
0325     /// Emit basic blocks into separate sections.
0326     BasicBlockSection BBSections = BasicBlockSection::None;
0327 
0328     /// Memory Buffer that contains information on sampled basic blocks and used
0329     /// to selectively generate basic block sections.
0330     std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
0331 
0332     /// The flag enables call site info production. It is used only for debug
0333     /// info, and it is restricted only to optimized code. This can be used for
0334     /// something else, so that should be controlled in the frontend.
0335     unsigned EmitCallSiteInfo : 1;
0336     /// Set if the target supports the debug entry values by default.
0337     unsigned SupportsDebugEntryValues : 1;
0338     /// When set to true, the EnableDebugEntryValues option forces production
0339     /// of debug entry values even if the target does not officially support
0340     /// it. Useful for testing purposes only. This flag should never be checked
0341     /// directly, always use \ref ShouldEmitDebugEntryValues instead.
0342      unsigned EnableDebugEntryValues : 1;
0343     /// NOTE: There are targets that still do not support the debug entry values
0344     /// production.
0345     bool ShouldEmitDebugEntryValues() const;
0346 
0347     // When set to true, use experimental new debug variable location tracking,
0348     // which seeks to follow the values of variables rather than their location,
0349     // post isel.
0350     unsigned ValueTrackingVariableLocations : 1;
0351 
0352     /// Emit DWARF debug frame section.
0353     unsigned ForceDwarfFrameSection : 1;
0354 
0355     /// Emit XRay Function Index section
0356     unsigned XRayFunctionIndex : 1;
0357 
0358     /// When set to true, don't use DWARF extensions in later DWARF versions.
0359     /// By default, it is set to false.
0360     unsigned DebugStrictDwarf : 1;
0361 
0362     /// Emit the hotpatch flag in CodeView debug.
0363     unsigned Hotpatch : 1;
0364 
0365     /// Enables scalar MASS conversions
0366     unsigned PPCGenScalarMASSEntries : 1;
0367 
0368     /// Enable JustMyCode instrumentation.
0369     unsigned JMCInstrument : 1;
0370 
0371     /// Enable the CFIFixup pass.
0372     unsigned EnableCFIFixup : 1;
0373 
0374     /// When set to true, enable MisExpect Diagnostics
0375     /// By default, it is set to false
0376     unsigned MisExpect : 1;
0377 
0378     /// When set to true, const objects with relocatable address values are put
0379     /// into the RO data section.
0380     unsigned XCOFFReadOnlyPointers : 1;
0381 
0382     /// When set to true, call/return argument extensions of narrow integers
0383     /// are verified in the target backend if it cares about them. This is
0384     /// not done with internal tools like llc that run many tests that ignore
0385     /// (lack) these extensions.
0386     unsigned VerifyArgABICompliance : 1;
0387 
0388     /// Name of the stack usage file (i.e., .su file) if user passes
0389     /// -fstack-usage. If empty, it can be implied that -fstack-usage is not
0390     /// passed on the command line.
0391     std::string StackUsageOutput;
0392 
0393     /// If greater than 0, override TargetLoweringBase::PrefLoopAlignment.
0394     unsigned LoopAlignment = 0;
0395 
0396     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
0397     /// on the command line. This setting may either be Default, Soft, or Hard.
0398     /// Default selects the target's default behavior. Soft selects the ABI for
0399     /// software floating point, but does not indicate that FP hardware may not
0400     /// be used. Such a combination is unfortunately popular (e.g.
0401     /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
0402     FloatABI::ABIType FloatABIType = FloatABI::Default;
0403 
0404     /// AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
0405     /// This controls the creation of fused FP ops that store intermediate
0406     /// results in higher precision than IEEE allows (E.g. FMAs).
0407     ///
0408     /// Fast mode - allows formation of fused FP ops whenever they're
0409     /// profitable.
0410     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
0411     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
0412     /// may be added.
0413     /// Strict mode - allow fusion only if/when it can be proven that the excess
0414     /// precision won't effect the result.
0415     ///
0416     /// Note: This option only controls formation of fused ops by the
0417     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
0418     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
0419     /// the value of this option.
0420     FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard;
0421 
0422     /// ThreadModel - This flag specifies the type of threading model to assume
0423     /// for things like atomics
0424     ThreadModel::Model ThreadModel = ThreadModel::POSIX;
0425 
0426     /// EABIVersion - This flag specifies the EABI version
0427     EABI EABIVersion = EABI::Default;
0428 
0429     /// Which debugger to tune for.
0430     DebuggerKind DebuggerTuning = DebuggerKind::Default;
0431 
0432   private:
0433     /// Flushing mode to assume in default FP environment.
0434     DenormalMode FPDenormalMode;
0435 
0436     /// Flushing mode to assume in default FP environment, for float/vector of
0437     /// float.
0438     DenormalMode FP32DenormalMode;
0439 
0440   public:
0441     void setFPDenormalMode(DenormalMode Mode) {
0442       FPDenormalMode = Mode;
0443     }
0444 
0445     void setFP32DenormalMode(DenormalMode Mode) {
0446       FP32DenormalMode = Mode;
0447     }
0448 
0449     DenormalMode getRawFPDenormalMode() const {
0450       return FPDenormalMode;
0451     }
0452 
0453     DenormalMode getRawFP32DenormalMode() const {
0454       return FP32DenormalMode;
0455     }
0456 
0457     DenormalMode getDenormalMode(const fltSemantics &FPType) const;
0458 
0459     /// What exception model to use
0460     ExceptionHandling ExceptionModel = ExceptionHandling::None;
0461 
0462     /// Machine level options.
0463     MCTargetOptions MCOptions;
0464 
0465     /// Stores the filename/path of the final .o/.obj file, to be written in the
0466     /// debug information. This is used for emitting the CodeView S_OBJNAME
0467     /// record.
0468     std::string ObjectFilenameForDebug;
0469   };
0470 
0471 } // End llvm namespace
0472 
0473 #endif