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