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           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     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
00211     /// on the command line. This setting may either be Default, Soft, or Hard.
00212     /// Default selects the target's default behavior. Soft selects the ABI for
00213     /// UseSoftFloat, but does not indicate that FP hardware may not be used.
00214     /// Such a combination is unfortunately popular (e.g. arm-apple-darwin).
00215     /// Hard presumes that the normal FP ABI is used.
00216     FloatABI::ABIType FloatABIType;
00217 
00218     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
00219     /// This controls the creation of fused FP ops that store intermediate
00220     /// results in higher precision than IEEE allows (E.g. FMAs).
00221     ///
00222     /// Fast mode - allows formation of fused FP ops whenever they're
00223     /// profitable.
00224     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
00225     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
00226     /// may be added.
00227     /// Strict mode - allow fusion only if/when it can be proven that the excess
00228     /// precision won't effect the result.
00229     ///
00230     /// Note: This option only controls formation of fused ops by the
00231     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
00232     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
00233     /// the value of this option.
00234     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
00235 
00236     /// JTType - This flag specifies the type of jump-instruction table to
00237     /// create for functions that have the jumptable attribute.
00238     JumpTable::JumpTableType JTType;
00239 
00240     /// FCFI - This flags controls whether or not forward-edge control-flow
00241     /// integrity is applied.
00242     bool FCFI;
00243 
00244     /// ThreadModel - This flag specifies the type of threading model to assume
00245     /// for things like atomics
00246     ThreadModel::Model ThreadModel;
00247 
00248     /// CFIType - This flag specifies the type of control-flow integrity check
00249     /// to add as a preamble to indirect calls.
00250     CFIntegrity CFIType;
00251 
00252     /// CFIEnforcing - This flags controls whether or not CFI violations cause
00253     /// the program to halt.
00254     bool CFIEnforcing;
00255 
00256     /// getCFIFuncName - If this returns a non-empty string, then this is the
00257     /// name of the function that will be called for each CFI violation in
00258     /// non-enforcing mode.
00259     std::string CFIFuncName;
00260     StringRef getCFIFuncName() const;
00261 
00262     /// Machine level options.
00263     MCTargetOptions MCOptions;
00264   };
00265 
00266 // Comparison operators:
00267 
00268 
00269 inline bool operator==(const TargetOptions &LHS,
00270                        const TargetOptions &RHS) {
00271 #define ARE_EQUAL(X) LHS.X == RHS.X
00272   return
00273     ARE_EQUAL(UnsafeFPMath) &&
00274     ARE_EQUAL(NoInfsFPMath) &&
00275     ARE_EQUAL(NoNaNsFPMath) &&
00276     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
00277     ARE_EQUAL(UseSoftFloat) &&
00278     ARE_EQUAL(NoZerosInBSS) &&
00279     ARE_EQUAL(JITEmitDebugInfo) &&
00280     ARE_EQUAL(JITEmitDebugInfoToDisk) &&
00281     ARE_EQUAL(GuaranteedTailCallOpt) &&
00282     ARE_EQUAL(DisableTailCalls) &&
00283     ARE_EQUAL(StackAlignmentOverride) &&
00284     ARE_EQUAL(EnableFastISel) &&
00285     ARE_EQUAL(PositionIndependentExecutable) &&
00286     ARE_EQUAL(UseInitArray) &&
00287     ARE_EQUAL(TrapUnreachable) &&
00288     ARE_EQUAL(TrapFuncName) &&
00289     ARE_EQUAL(FloatABIType) &&
00290     ARE_EQUAL(AllowFPOpFusion) &&
00291     ARE_EQUAL(MCOptions);
00292 #undef ARE_EQUAL
00293 }
00294 
00295 inline bool operator!=(const TargetOptions &LHS,
00296                        const TargetOptions &RHS) {
00297   return !(LHS == RHS);
00298 }
00299 
00300 } // End llvm namespace
00301 
00302 #endif