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