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/MC/MCTargetOptions.h"
00019 #include <string>
00020 
00021 namespace llvm {
00022   class MachineFunction;
00023   class Module;
00024   class StringRef;
00025 
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   class TargetOptions {
00061   public:
00062     TargetOptions()
00063         : PrintMachineCode(false),
00064           LessPreciseFPMADOption(false), UnsafeFPMath(false),
00065           NoInfsFPMath(false), NoNaNsFPMath(false),
00066           HonorSignDependentRoundingFPMathOption(false),
00067           NoZerosInBSS(false),
00068           GuaranteedTailCallOpt(false),
00069           DisableTailCalls(false), StackAlignmentOverride(0),
00070           EnableFastISel(false), PositionIndependentExecutable(false),
00071           UseInitArray(false), DisableIntegratedAS(false),
00072           CompressDebugSections(false), FunctionSections(false),
00073           DataSections(false), UniqueSectionNames(true), TrapUnreachable(false),
00074           TrapFuncName(), FloatABIType(FloatABI::Default),
00075           AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single),
00076           ThreadModel(ThreadModel::POSIX) {}
00077 
00078     /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
00079     /// option is specified on the command line, and should enable debugging
00080     /// output from the code generator.
00081     unsigned PrintMachineCode : 1;
00082 
00083     /// DisableFramePointerElim - This returns true if frame pointer elimination
00084     /// optimization should be disabled for the given machine function.
00085     bool DisableFramePointerElim(const MachineFunction &MF) const;
00086 
00087     /// LessPreciseFPMAD - This flag is enabled when the
00088     /// -enable-fp-mad is specified on the command line.  When this flag is off
00089     /// (the default), the code generator is not allowed to generate mad
00090     /// (multiply add) if the result is "less precise" than doing those
00091     /// operations individually.
00092     unsigned LessPreciseFPMADOption : 1;
00093     bool LessPreciseFPMAD() const;
00094 
00095     /// UnsafeFPMath - This flag is enabled when the
00096     /// -enable-unsafe-fp-math flag is specified on the command line.  When
00097     /// this flag is off (the default), the code generator is not allowed to
00098     /// produce results that are "less precise" than IEEE allows.  This includes
00099     /// use of X86 instructions like FSIN and FCOS instead of libcalls.
00100     /// UnsafeFPMath implies LessPreciseFPMAD.
00101     unsigned UnsafeFPMath : 1;
00102 
00103     /// NoInfsFPMath - This flag is enabled when the
00104     /// -enable-no-infs-fp-math flag is specified on the command line. When
00105     /// this flag is off (the default), the code generator is not allowed to
00106     /// assume the FP arithmetic arguments and results are never +-Infs.
00107     unsigned NoInfsFPMath : 1;
00108 
00109     /// NoNaNsFPMath - This flag is enabled when the
00110     /// -enable-no-nans-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     /// assume the FP arithmetic arguments and results are never NaNs.
00113     unsigned NoNaNsFPMath : 1;
00114 
00115     /// HonorSignDependentRoundingFPMath - This returns true when the
00116     /// -enable-sign-dependent-rounding-fp-math is specified.  If this returns
00117     /// false (the default), the code generator is allowed to assume that the
00118     /// rounding behavior is the default (round-to-zero for all floating point
00119     /// to integer conversions, and round-to-nearest for all other arithmetic
00120     /// truncations).  If this is enabled (set to true), the code generator must
00121     /// assume that the rounding mode may dynamically change.
00122     unsigned HonorSignDependentRoundingFPMathOption : 1;
00123     bool HonorSignDependentRoundingFPMath() const;
00124 
00125     /// NoZerosInBSS - By default some codegens place zero-initialized data to
00126     /// .bss section. This flag disables such behaviour (necessary, e.g. for
00127     /// crt*.o compiling).
00128     unsigned NoZerosInBSS : 1;
00129 
00130     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
00131     /// specified on the commandline. When the flag is on, participating targets
00132     /// will perform tail call optimization on all calls which use the fastcc
00133     /// calling convention and which satisfy certain target-independent
00134     /// criteria (being at the end of a function, having the same return type
00135     /// as their parent function, etc.), using an alternate ABI if necessary.
00136     unsigned GuaranteedTailCallOpt : 1;
00137 
00138     /// DisableTailCalls - This flag controls whether we will use tail calls.
00139     /// Disabling them may be useful to maintain a correct call stack.
00140     unsigned DisableTailCalls : 1;
00141 
00142     /// StackAlignmentOverride - Override default stack alignment for target.
00143     unsigned StackAlignmentOverride;
00144 
00145     /// EnableFastISel - This flag enables fast-path instruction selection
00146     /// which trades away generated code quality in favor of reducing
00147     /// compile time.
00148     unsigned EnableFastISel : 1;
00149 
00150     /// PositionIndependentExecutable - This flag indicates whether the code
00151     /// will eventually be linked into a single executable, despite the PIC
00152     /// relocation model being in use. It's value is undefined (and irrelevant)
00153     /// if the relocation model is anything other than PIC.
00154     unsigned PositionIndependentExecutable : 1;
00155 
00156     /// UseInitArray - Use .init_array instead of .ctors for static
00157     /// constructors.
00158     unsigned UseInitArray : 1;
00159 
00160     /// Disable the integrated assembler.
00161     unsigned DisableIntegratedAS : 1;
00162 
00163     /// Compress DWARF debug sections.
00164     unsigned CompressDebugSections : 1;
00165 
00166     /// Emit functions into separate sections.
00167     unsigned FunctionSections : 1;
00168 
00169     /// Emit data into separate sections.
00170     unsigned DataSections : 1;
00171 
00172     unsigned UniqueSectionNames : 1;
00173 
00174     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
00175     unsigned TrapUnreachable : 1;
00176 
00177     /// getTrapFunctionName - If this returns a non-empty string, this means
00178     /// isel should lower Intrinsic::trap to a call to the specified function
00179     /// name instead of an ISD::TRAP node.
00180     std::string TrapFuncName;
00181     StringRef getTrapFunctionName() const;
00182 
00183     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
00184     /// on the command line. This setting may either be Default, Soft, or Hard.
00185     /// Default selects the target's default behavior. Soft selects the ABI for
00186     /// software floating point, but does not indicate that FP hardware may not
00187     /// be used. Such a combination is unfortunately popular (e.g.
00188     /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
00189     FloatABI::ABIType FloatABIType;
00190 
00191     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
00192     /// This controls the creation of fused FP ops that store intermediate
00193     /// results in higher precision than IEEE allows (E.g. FMAs).
00194     ///
00195     /// Fast mode - allows formation of fused FP ops whenever they're
00196     /// profitable.
00197     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
00198     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
00199     /// may be added.
00200     /// Strict mode - allow fusion only if/when it can be proven that the excess
00201     /// precision won't effect the result.
00202     ///
00203     /// Note: This option only controls formation of fused ops by the
00204     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
00205     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
00206     /// the value of this option.
00207     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
00208 
00209     /// JTType - This flag specifies the type of jump-instruction table to
00210     /// create for functions that have the jumptable attribute.
00211     JumpTable::JumpTableType JTType;
00212 
00213     /// ThreadModel - This flag specifies the type of threading model to assume
00214     /// for things like atomics
00215     ThreadModel::Model ThreadModel;
00216 
00217     /// Machine level options.
00218     MCTargetOptions MCOptions;
00219   };
00220 
00221 // Comparison operators:
00222 
00223 
00224 inline bool operator==(const TargetOptions &LHS,
00225                        const TargetOptions &RHS) {
00226 #define ARE_EQUAL(X) LHS.X == RHS.X
00227   return
00228     ARE_EQUAL(UnsafeFPMath) &&
00229     ARE_EQUAL(NoInfsFPMath) &&
00230     ARE_EQUAL(NoNaNsFPMath) &&
00231     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
00232     ARE_EQUAL(NoZerosInBSS) &&
00233     ARE_EQUAL(GuaranteedTailCallOpt) &&
00234     ARE_EQUAL(DisableTailCalls) &&
00235     ARE_EQUAL(StackAlignmentOverride) &&
00236     ARE_EQUAL(EnableFastISel) &&
00237     ARE_EQUAL(PositionIndependentExecutable) &&
00238     ARE_EQUAL(UseInitArray) &&
00239     ARE_EQUAL(TrapUnreachable) &&
00240     ARE_EQUAL(TrapFuncName) &&
00241     ARE_EQUAL(FloatABIType) &&
00242     ARE_EQUAL(AllowFPOpFusion) &&
00243     ARE_EQUAL(JTType) &&
00244     ARE_EQUAL(ThreadModel) &&
00245     ARE_EQUAL(MCOptions);
00246 #undef ARE_EQUAL
00247 }
00248 
00249 inline bool operator!=(const TargetOptions &LHS,
00250                        const TargetOptions &RHS) {
00251   return !(LHS == RHS);
00252 }
00253 
00254 } // End llvm namespace
00255 
00256 #endif