LLVM API Documentation

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/MC/MCTargetOptions.h"
00019 #include <string>
00020 
00021 namespace llvm {
00022   class MachineFunction;
00023   class StringRef;
00024 
00025   // Possible float ABI settings. Used with FloatABIType in TargetOptions.h.
00026   namespace FloatABI {
00027     enum ABIType {
00028       Default, // Target-specific (either soft or hard depending on triple,etc).
00029       Soft, // Soft float.
00030       Hard  // Hard float.
00031     };
00032   }
00033 
00034   namespace FPOpFusion {
00035     enum FPOpFusionMode {
00036       Fast,     // Enable fusion of FP ops wherever it's profitable.
00037       Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd).
00038       Strict    // Never fuse FP-ops.
00039     };
00040   }
00041 
00042   namespace JumpTable {
00043     enum JumpTableType {
00044       Single,          // Use a single table for all indirect jumptable calls.
00045       Arity,           // Use one table per number of function parameters.
00046       Simplified,      // Use one table per function type, with types projected
00047                        // into 4 types: pointer to non-function, struct,
00048                        // primitive, and function pointer.
00049       Full             // Use one table per unique function type
00050     };
00051   }
00052 
00053   namespace ThreadModel {
00054     enum Model {
00055       POSIX,  // POSIX Threads
00056       Single  // Single Threaded Environment
00057     };
00058   }
00059 
00060   enum class CFIntegrity {
00061     Sub,             // Use subtraction-based checks.
00062     Ror,             // Use rotation-based checks.
00063     Add              // Use addition-based checks. This depends on having
00064                      // sufficient alignment in the code and is usually not
00065                      // feasible.
00066   };
00067 
00068   class TargetOptions {
00069   public:
00070     TargetOptions()
00071         : PrintMachineCode(false), NoFramePointerElim(false),
00072           LessPreciseFPMADOption(false), UnsafeFPMath(false),
00073           NoInfsFPMath(false), NoNaNsFPMath(false),
00074           HonorSignDependentRoundingFPMathOption(false), UseSoftFloat(false),
00075           NoZerosInBSS(false), JITEmitDebugInfo(false),
00076           JITEmitDebugInfoToDisk(false), GuaranteedTailCallOpt(false),
00077           DisableTailCalls(false), StackAlignmentOverride(0),
00078           EnableFastISel(false), PositionIndependentExecutable(false),
00079           UseInitArray(false), DisableIntegratedAS(false),
00080           CompressDebugSections(false), FunctionSections(false),
00081           DataSections(false), TrapUnreachable(false), TrapFuncName(),
00082           ABIName(), FloatABIType(FloatABI::Default),
00083           AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single),
00084           FCFI(false), ThreadModel(ThreadModel::POSIX),
00085           CFIType(CFIntegrity::Sub), CFIEnforcing(false), CFIFuncName() {}
00086 
00087     /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
00088     /// option is specified on the command line, and should enable debugging
00089     /// output from the code generator.
00090     unsigned PrintMachineCode : 1;
00091 
00092     /// NoFramePointerElim - This flag is enabled when the -disable-fp-elim is
00093     /// specified on the command line.  If the target supports the frame pointer
00094     /// elimination optimization, this option should disable it.
00095     unsigned NoFramePointerElim : 1;
00096 
00097     /// DisableFramePointerElim - This returns true if frame pointer elimination
00098     /// optimization should be disabled for the given machine function.
00099     bool DisableFramePointerElim(const MachineFunction &MF) const;
00100 
00101     /// LessPreciseFPMAD - This flag is enabled when the
00102     /// -enable-fp-mad is specified on the command line.  When this flag is off
00103     /// (the default), the code generator is not allowed to generate mad
00104     /// (multiply add) if the result is "less precise" than doing those
00105     /// operations individually.
00106     unsigned LessPreciseFPMADOption : 1;
00107     bool LessPreciseFPMAD() const;
00108 
00109     /// UnsafeFPMath - This flag is enabled when the
00110     /// -enable-unsafe-fp-math flag is specified on the command line.  When
00111     /// this flag is off (the default), the code generator is not allowed to
00112     /// produce results that are "less precise" than IEEE allows.  This includes
00113     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
00114     /// UnsafeFPMath implies LessPreciseFPMAD.
00115     unsigned UnsafeFPMath : 1;
00116 
00117     /// NoInfsFPMath - This flag is enabled when the
00118     /// -enable-no-infs-fp-math flag is specified on the command line. When
00119     /// this flag is off (the default), the code generator is not allowed to
00120     /// assume the FP arithmetic arguments and results are never +-Infs.
00121     unsigned NoInfsFPMath : 1;
00122 
00123     /// NoNaNsFPMath - This flag is enabled when the
00124     /// -enable-no-nans-fp-math flag is specified on the command line. When
00125     /// this flag is off (the default), the code generator is not allowed to
00126     /// assume the FP arithmetic arguments and results are never NaNs.
00127     unsigned NoNaNsFPMath : 1;
00128 
00129     /// HonorSignDependentRoundingFPMath - This returns true when the
00130     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
00131     /// false (the default), the code generator is allowed to assume that the
00132     /// rounding behavior is the default (round-to-zero for all floating point
00133     /// to integer conversions, and round-to-nearest for all other arithmetic
00134     /// truncations).  If this is enabled (set to true), the code generator must
00135     /// assume that the rounding mode may dynamically change.
00136     unsigned HonorSignDependentRoundingFPMathOption : 1;
00137     bool HonorSignDependentRoundingFPMath() const;
00138 
00139     /// UseSoftFloat - This flag is enabled when the -soft-float flag is
00140     /// specified on the command line.  When this flag is on, the code generator
00141     /// will generate libcalls to the software floating point library instead of
00142     /// target FP instructions.
00143     unsigned UseSoftFloat : 1;
00144 
00145     /// NoZerosInBSS - By default some codegens place zero-initialized data to
00146     /// .bss section. This flag disables such behaviour (necessary, e.g. for
00147     /// crt*.o compiling).
00148     unsigned NoZerosInBSS : 1;
00149 
00150     /// JITEmitDebugInfo - This flag indicates that the JIT should try to emit
00151     /// debug information and notify a debugger about it.
00152     unsigned JITEmitDebugInfo : 1;
00153 
00154     /// JITEmitDebugInfoToDisk - This flag indicates that the JIT should write
00155     /// the object files generated by the JITEmitDebugInfo flag to disk.  This
00156     /// flag is hidden and is only for debugging the debug info.
00157     unsigned JITEmitDebugInfoToDisk : 1;
00158 
00159     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
00160     /// specified on the commandline. When the flag is on, participating targets
00161     /// will perform tail call optimization on all calls which use the fastcc
00162     /// calling convention and which satisfy certain target-independent
00163     /// criteria (being at the end of a function, having the same return type
00164     /// as their parent function, etc.), using an alternate ABI if necessary.
00165     unsigned GuaranteedTailCallOpt : 1;
00166 
00167     /// DisableTailCalls - This flag controls whether we will use tail calls.
00168     /// Disabling them may be useful to maintain a correct call stack.
00169     unsigned DisableTailCalls : 1;
00170 
00171     /// StackAlignmentOverride - Override default stack alignment for target.
00172     unsigned StackAlignmentOverride;
00173 
00174     /// EnableFastISel - This flag enables fast-path instruction selection
00175     /// which trades away generated code quality in favor of reducing
00176     /// compile time.
00177     unsigned EnableFastISel : 1;
00178 
00179     /// PositionIndependentExecutable - This flag indicates whether the code
00180     /// will eventually be linked into a single executable, despite the PIC
00181     /// relocation model being in use. It's value is undefined (and irrelevant)
00182     /// if the relocation model is anything other than PIC.
00183     unsigned PositionIndependentExecutable : 1;
00184 
00185     /// UseInitArray - Use .init_array instead of .ctors for static
00186     /// constructors.
00187     unsigned UseInitArray : 1;
00188 
00189     /// Disable the integrated assembler.
00190     unsigned DisableIntegratedAS : 1;
00191 
00192     /// Compress DWARF debug sections.
00193     unsigned CompressDebugSections : 1;
00194 
00195     /// Emit functions into separate sections.
00196     unsigned FunctionSections : 1;
00197 
00198     /// Emit data into separate sections.
00199     unsigned DataSections : 1;
00200 
00201     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
00202     unsigned TrapUnreachable : 1;
00203 
00204     /// getTrapFunctionName - If this returns a non-empty string, this means
00205     /// isel should lower Intrinsic::trap to a call to the specified function
00206     /// name instead of an ISD::TRAP node.
00207     std::string TrapFuncName;
00208     StringRef getTrapFunctionName() const;
00209 
00210     /// getABIName - If this returns a non-empty string this represents the
00211     /// textual name of the ABI that we want the backend to use, e.g. o32, or
00212     /// aapcs-linux.
00213     std::string ABIName;
00214     StringRef getABIName() const;
00215 
00216     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
00217     /// on the command line. This setting may either be Default, Soft, or Hard.
00218     /// Default selects the target's default behavior. Soft selects the ABI for
00219     /// UseSoftFloat, but does not indicate that FP hardware may not be used.
00220     /// Such a combination is unfortunately popular (e.g. arm-apple-darwin).
00221     /// Hard presumes that the normal FP ABI is used.
00222     FloatABI::ABIType FloatABIType;
00223 
00224     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
00225     /// This controls the creation of fused FP ops that store intermediate
00226     /// results in higher precision than IEEE allows (E.g. FMAs).
00227     ///
00228     /// Fast mode - allows formation of fused FP ops whenever they're
00229     /// profitable.
00230     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
00231     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
00232     /// may be added.
00233     /// Strict mode - allow fusion only if/when it can be proven that the excess
00234     /// precision won't effect the result.
00235     ///
00236     /// Note: This option only controls formation of fused ops by the
00237     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
00238     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
00239     /// the value of this option.
00240     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
00241 
00242     /// JTType - This flag specifies the type of jump-instruction table to
00243     /// create for functions that have the jumptable attribute.
00244     JumpTable::JumpTableType JTType;
00245 
00246     /// FCFI - This flags controls whether or not forward-edge control-flow
00247     /// integrity is applied.
00248     bool FCFI;
00249 
00250     /// ThreadModel - This flag specifies the type of threading model to assume
00251     /// for things like atomics
00252     ThreadModel::Model ThreadModel;
00253 
00254     /// CFIType - This flag specifies the type of control-flow integrity check
00255     /// to add as a preamble to indirect calls.
00256     CFIntegrity CFIType;
00257 
00258     /// CFIEnforcing - This flags controls whether or not CFI violations cause
00259     /// the program to halt.
00260     bool CFIEnforcing;
00261 
00262     /// getCFIFuncName - If this returns a non-empty string, then this is the
00263     /// name of the function that will be called for each CFI violation in
00264     /// non-enforcing mode.
00265     std::string CFIFuncName;
00266     StringRef getCFIFuncName() const;
00267 
00268     /// Machine level options.
00269     MCTargetOptions MCOptions;
00270   };
00271 
00272 // Comparison operators:
00273 
00274 
00275 inline bool operator==(const TargetOptions &LHS,
00276                        const TargetOptions &RHS) {
00277 #define ARE_EQUAL(X) LHS.X == RHS.X
00278   return
00279     ARE_EQUAL(UnsafeFPMath) &&
00280     ARE_EQUAL(NoInfsFPMath) &&
00281     ARE_EQUAL(NoNaNsFPMath) &&
00282     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
00283     ARE_EQUAL(UseSoftFloat) &&
00284     ARE_EQUAL(NoZerosInBSS) &&
00285     ARE_EQUAL(JITEmitDebugInfo) &&
00286     ARE_EQUAL(JITEmitDebugInfoToDisk) &&
00287     ARE_EQUAL(GuaranteedTailCallOpt) &&
00288     ARE_EQUAL(DisableTailCalls) &&
00289     ARE_EQUAL(StackAlignmentOverride) &&
00290     ARE_EQUAL(EnableFastISel) &&
00291     ARE_EQUAL(PositionIndependentExecutable) &&
00292     ARE_EQUAL(UseInitArray) &&
00293     ARE_EQUAL(TrapUnreachable) &&
00294     ARE_EQUAL(TrapFuncName) &&
00295     ARE_EQUAL(ABIName) &&
00296     ARE_EQUAL(FloatABIType) &&
00297     ARE_EQUAL(AllowFPOpFusion) &&
00298     ARE_EQUAL(JTType) &&
00299     ARE_EQUAL(FCFI) &&
00300     ARE_EQUAL(ThreadModel) &&
00301     ARE_EQUAL(CFIType) &&
00302     ARE_EQUAL(CFIEnforcing) &&
00303     ARE_EQUAL(CFIFuncName) &&
00304     ARE_EQUAL(MCOptions);
00305 #undef ARE_EQUAL
00306 }
00307 
00308 inline bool operator!=(const TargetOptions &LHS,
00309                        const TargetOptions &RHS) {
00310   return !(LHS == RHS);
00311 }
00312 
00313 } // End llvm namespace
00314 
00315 #endif