LLVM  mainline
TargetOptions.h
Go to the documentation of this file.
00001 //===-- llvm/Target/TargetOptions.h - Target Options ------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines command line option flags that are shared across various
00011 // targets.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_TARGET_TARGETOPTIONS_H
00016 #define LLVM_TARGET_TARGETOPTIONS_H
00017 
00018 #include "llvm/Target/TargetRecip.h"
00019 #include "llvm/MC/MCTargetOptions.h"
00020 #include <string>
00021 
00022 namespace llvm {
00023   class MachineFunction;
00024   class Module;
00025   class StringRef;
00026 
00027   namespace FloatABI {
00028     enum ABIType {
00029       Default, // Target-specific (either soft or hard depending on triple, etc).
00030       Soft,    // Soft float.
00031       Hard     // Hard float.
00032     };
00033   }
00034 
00035   namespace FPOpFusion {
00036     enum FPOpFusionMode {
00037       Fast,     // Enable fusion of FP ops wherever it's profitable.
00038       Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd).
00039       Strict    // Never fuse FP-ops.
00040     };
00041   }
00042 
00043   namespace JumpTable {
00044     enum JumpTableType {
00045       Single,          // Use a single table for all indirect jumptable calls.
00046       Arity,           // Use one table per number of function parameters.
00047       Simplified,      // Use one table per function type, with types projected
00048                        // into 4 types: pointer to non-function, struct,
00049                        // primitive, and function pointer.
00050       Full             // Use one table per unique function type
00051     };
00052   }
00053 
00054   namespace ThreadModel {
00055     enum Model {
00056       POSIX,  // POSIX Threads
00057       Single  // Single Threaded Environment
00058     };
00059   }
00060 
00061   enum class EABI {
00062     Unknown,
00063     Default, // Default means not specified
00064     EABI4,   // Target-specific (either 4, 5 or gnu depending on triple).
00065     EABI5,
00066     GNU
00067   };
00068 
00069   /// Identify a debugger for "tuning" the debug info.
00070   ///
00071   /// The "debugger tuning" concept allows us to present a more intuitive
00072   /// interface that unpacks into different sets of defaults for the various
00073   /// individual feature-flag settings, that suit the preferences of the
00074   /// various debuggers.  However, it's worth remembering that debuggers are
00075   /// not the only consumers of debug info, and some variations in DWARF might
00076   /// better be treated as target/platform issues. Fundamentally,
00077   /// o if the feature is useful (or not) to a particular debugger, regardless
00078   ///   of the target, that's a tuning decision;
00079   /// o if the feature is useful (or not) on a particular platform, regardless
00080   ///   of the debugger, that's a target decision.
00081   /// It's not impossible to see both factors in some specific case.
00082   ///
00083   /// The "tuning" should be used to set defaults for individual feature flags
00084   /// in DwarfDebug; if a given feature has a more specific command-line option,
00085   /// that option should take precedence over the tuning.
00086   enum class DebuggerKind {
00087     Default,  // No specific tuning requested.
00088     GDB,      // Tune debug info for gdb.
00089     LLDB,     // Tune debug info for lldb.
00090     SCE       // Tune debug info for SCE targets (e.g. PS4).
00091   };
00092 
00093   class TargetOptions {
00094   public:
00095     TargetOptions()
00096         : PrintMachineCode(false), LessPreciseFPMADOption(false),
00097           UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
00098           HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
00099           GuaranteedTailCallOpt(false), StackAlignmentOverride(0),
00100           EnableFastISel(false), PositionIndependentExecutable(false),
00101           UseInitArray(false), DisableIntegratedAS(false),
00102           CompressDebugSections(false), FunctionSections(false),
00103           DataSections(false), UniqueSectionNames(true), TrapUnreachable(false),
00104           EmulatedTLS(false), FloatABIType(FloatABI::Default),
00105           AllowFPOpFusion(FPOpFusion::Standard), Reciprocals(TargetRecip()),
00106           JTType(JumpTable::Single), ThreadModel(ThreadModel::POSIX),
00107           EABIVersion(EABI::Default), DebuggerTuning(DebuggerKind::Default) {}
00108 
00109     /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
00110     /// option is specified on the command line, and should enable debugging
00111     /// output from the code generator.
00112     unsigned PrintMachineCode : 1;
00113 
00114     /// DisableFramePointerElim - This returns true if frame pointer elimination
00115     /// optimization should be disabled for the given machine function.
00116     bool DisableFramePointerElim(const MachineFunction &MF) const;
00117 
00118     /// LessPreciseFPMAD - This flag is enabled when the
00119     /// -enable-fp-mad is specified on the command line.  When this flag is off
00120     /// (the default), the code generator is not allowed to generate mad
00121     /// (multiply add) if the result is "less precise" than doing those
00122     /// operations individually.
00123     unsigned LessPreciseFPMADOption : 1;
00124     bool LessPreciseFPMAD() const;
00125 
00126     /// UnsafeFPMath - This flag is enabled when the
00127     /// -enable-unsafe-fp-math flag is specified on the command line.  When
00128     /// this flag is off (the default), the code generator is not allowed to
00129     /// produce results that are "less precise" than IEEE allows.  This includes
00130     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
00131     /// UnsafeFPMath implies LessPreciseFPMAD.
00132     unsigned UnsafeFPMath : 1;
00133 
00134     /// NoInfsFPMath - This flag is enabled when the
00135     /// -enable-no-infs-fp-math flag is specified on the command line. When
00136     /// this flag is off (the default), the code generator is not allowed to
00137     /// assume the FP arithmetic arguments and results are never +-Infs.
00138     unsigned NoInfsFPMath : 1;
00139 
00140     /// NoNaNsFPMath - This flag is enabled when the
00141     /// -enable-no-nans-fp-math flag is specified on the command line. When
00142     /// this flag is off (the default), the code generator is not allowed to
00143     /// assume the FP arithmetic arguments and results are never NaNs.
00144     unsigned NoNaNsFPMath : 1;
00145 
00146     /// HonorSignDependentRoundingFPMath - This returns true when the
00147     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
00148     /// false (the default), the code generator is allowed to assume that the
00149     /// rounding behavior is the default (round-to-zero for all floating point
00150     /// to integer conversions, and round-to-nearest for all other arithmetic
00151     /// truncations).  If this is enabled (set to true), the code generator must
00152     /// assume that the rounding mode may dynamically change.
00153     unsigned HonorSignDependentRoundingFPMathOption : 1;
00154     bool HonorSignDependentRoundingFPMath() const;
00155 
00156     /// NoZerosInBSS - By default some codegens place zero-initialized data to
00157     /// .bss section. This flag disables such behaviour (necessary, e.g. for
00158     /// crt*.o compiling).
00159     unsigned NoZerosInBSS : 1;
00160 
00161     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
00162     /// specified on the commandline. When the flag is on, participating targets
00163     /// will perform tail call optimization on all calls which use the fastcc
00164     /// calling convention and which satisfy certain target-independent
00165     /// criteria (being at the end of a function, having the same return type
00166     /// as their parent function, etc.), using an alternate ABI if necessary.
00167     unsigned GuaranteedTailCallOpt : 1;
00168 
00169     /// StackAlignmentOverride - Override default stack alignment for target.
00170     unsigned StackAlignmentOverride;
00171 
00172     /// EnableFastISel - This flag enables fast-path instruction selection
00173     /// which trades away generated code quality in favor of reducing
00174     /// compile time.
00175     unsigned EnableFastISel : 1;
00176 
00177     /// PositionIndependentExecutable - This flag indicates whether the code
00178     /// will eventually be linked into a single executable, despite the PIC
00179     /// relocation model being in use. It's value is undefined (and irrelevant)
00180     /// if the relocation model is anything other than PIC.
00181     unsigned PositionIndependentExecutable : 1;
00182 
00183     /// UseInitArray - Use .init_array instead of .ctors for static
00184     /// constructors.
00185     unsigned UseInitArray : 1;
00186 
00187     /// Disable the integrated assembler.
00188     unsigned DisableIntegratedAS : 1;
00189 
00190     /// Compress DWARF debug sections.
00191     unsigned CompressDebugSections : 1;
00192 
00193     /// Emit functions into separate sections.
00194     unsigned FunctionSections : 1;
00195 
00196     /// Emit data into separate sections.
00197     unsigned DataSections : 1;
00198 
00199     unsigned UniqueSectionNames : 1;
00200 
00201     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
00202     unsigned TrapUnreachable : 1;
00203 
00204     /// EmulatedTLS - This flag enables emulated TLS model, using emutls
00205     /// function in the runtime library..
00206     unsigned EmulatedTLS : 1;
00207 
00208     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
00209     /// on the command line. This setting may either be Default, Soft, or Hard.
00210     /// Default selects the target's default behavior. Soft selects the ABI for
00211     /// software floating point, but does not indicate that FP hardware may not
00212     /// be used. Such a combination is unfortunately popular (e.g.
00213     /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
00214     FloatABI::ABIType FloatABIType;
00215 
00216     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
00217     /// This controls the creation of fused FP ops that store intermediate
00218     /// results in higher precision than IEEE allows (E.g. FMAs).
00219     ///
00220     /// Fast mode - allows formation of fused FP ops whenever they're
00221     /// profitable.
00222     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
00223     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
00224     /// may be added.
00225     /// Strict mode - allow fusion only if/when it can be proven that the excess
00226     /// precision won't effect the result.
00227     ///
00228     /// Note: This option only controls formation of fused ops by the
00229     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
00230     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
00231     /// the value of this option.
00232     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
00233 
00234     /// This class encapsulates options for reciprocal-estimate code generation.
00235     TargetRecip Reciprocals;
00236 
00237     /// JTType - This flag specifies the type of jump-instruction table to
00238     /// create for functions that have the jumptable attribute.
00239     JumpTable::JumpTableType JTType;
00240 
00241     /// ThreadModel - This flag specifies the type of threading model to assume
00242     /// for things like atomics
00243     ThreadModel::Model ThreadModel;
00244 
00245     /// EABIVersion - This flag specifies the EABI version
00246     EABI EABIVersion;
00247 
00248     /// Which debugger to tune for.
00249     DebuggerKind DebuggerTuning;
00250 
00251     /// Machine level options.
00252     MCTargetOptions MCOptions;
00253   };
00254 
00255 // Comparison operators:
00256 
00257 
00258 inline bool operator==(const TargetOptions &LHS,
00259                        const TargetOptions &RHS) {
00260 #define ARE_EQUAL(X) LHS.X == RHS.X
00261   return
00262     ARE_EQUAL(UnsafeFPMath) &&
00263     ARE_EQUAL(NoInfsFPMath) &&
00264     ARE_EQUAL(NoNaNsFPMath) &&
00265     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
00266     ARE_EQUAL(NoZerosInBSS) &&
00267     ARE_EQUAL(GuaranteedTailCallOpt) &&
00268     ARE_EQUAL(StackAlignmentOverride) &&
00269     ARE_EQUAL(EnableFastISel) &&
00270     ARE_EQUAL(PositionIndependentExecutable) &&
00271     ARE_EQUAL(UseInitArray) &&
00272     ARE_EQUAL(TrapUnreachable) &&
00273     ARE_EQUAL(EmulatedTLS) &&
00274     ARE_EQUAL(FloatABIType) &&
00275     ARE_EQUAL(AllowFPOpFusion) &&
00276     ARE_EQUAL(Reciprocals) &&
00277     ARE_EQUAL(JTType) &&
00278     ARE_EQUAL(ThreadModel) &&
00279     ARE_EQUAL(EABIVersion) &&
00280     ARE_EQUAL(DebuggerTuning) &&
00281     ARE_EQUAL(MCOptions);
00282 #undef ARE_EQUAL
00283 }
00284 
00285 inline bool operator!=(const TargetOptions &LHS,
00286                        const TargetOptions &RHS) {
00287   return !(LHS == RHS);
00288 }
00289 
00290 } // End llvm namespace
00291 
00292 #endif