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