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