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   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), JITEmitDebugInfo(false),
00068           JITEmitDebugInfoToDisk(false), 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), TrapUnreachable(false), TrapFuncName(""),
00074           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     /// JITEmitDebugInfo - This flag indicates that the JIT should try to emit
00142     /// debug information and notify a debugger about it.
00143     unsigned JITEmitDebugInfo : 1;
00144 
00145     /// JITEmitDebugInfoToDisk - This flag indicates that the JIT should write
00146     /// the object files generated by the JITEmitDebugInfo flag to disk.  This
00147     /// flag is hidden and is only for debugging the debug info.
00148     unsigned JITEmitDebugInfoToDisk : 1;
00149 
00150     /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
00151     /// specified on the commandline. When the flag is on, participating targets
00152     /// will perform tail call optimization on all calls which use the fastcc
00153     /// calling convention and which satisfy certain target-independent
00154     /// criteria (being at the end of a function, having the same return type
00155     /// as their parent function, etc.), using an alternate ABI if necessary.
00156     unsigned GuaranteedTailCallOpt : 1;
00157 
00158     /// DisableTailCalls - This flag controls whether we will use tail calls.
00159     /// Disabling them may be useful to maintain a correct call stack.
00160     unsigned DisableTailCalls : 1;
00161 
00162     /// StackAlignmentOverride - Override default stack alignment for target.
00163     unsigned StackAlignmentOverride;
00164 
00165     /// EnableFastISel - This flag enables fast-path instruction selection
00166     /// which trades away generated code quality in favor of reducing
00167     /// compile time.
00168     unsigned EnableFastISel : 1;
00169 
00170     /// PositionIndependentExecutable - This flag indicates whether the code
00171     /// will eventually be linked into a single executable, despite the PIC
00172     /// relocation model being in use. It's value is undefined (and irrelevant)
00173     /// if the relocation model is anything other than PIC.
00174     unsigned PositionIndependentExecutable : 1;
00175 
00176     /// UseInitArray - Use .init_array instead of .ctors for static
00177     /// constructors.
00178     unsigned UseInitArray : 1;
00179 
00180     /// Disable the integrated assembler.
00181     unsigned DisableIntegratedAS : 1;
00182 
00183     /// Compress DWARF debug sections.
00184     unsigned CompressDebugSections : 1;
00185 
00186     /// Emit functions into separate sections.
00187     unsigned FunctionSections : 1;
00188 
00189     /// Emit data into separate sections.
00190     unsigned DataSections : 1;
00191 
00192     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
00193     unsigned TrapUnreachable : 1;
00194 
00195     /// getTrapFunctionName - If this returns a non-empty string, this means
00196     /// isel should lower Intrinsic::trap to a call to the specified function
00197     /// name instead of an ISD::TRAP node.
00198     std::string TrapFuncName;
00199     StringRef getTrapFunctionName() const;
00200 
00201     /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
00202     /// on the command line. This setting may either be Default, Soft, or Hard.
00203     /// Default selects the target's default behavior. Soft selects the ABI for
00204     /// UseSoftFloat, but does not indicate that FP hardware may not be used.
00205     /// Such a combination is unfortunately popular (e.g. arm-apple-darwin).
00206     /// Hard presumes that the normal FP ABI is used.
00207     FloatABI::ABIType FloatABIType;
00208 
00209     /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
00210     /// This controls the creation of fused FP ops that store intermediate
00211     /// results in higher precision than IEEE allows (E.g. FMAs).
00212     ///
00213     /// Fast mode - allows formation of fused FP ops whenever they're
00214     /// profitable.
00215     /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
00216     /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
00217     /// may be added.
00218     /// Strict mode - allow fusion only if/when it can be proven that the excess
00219     /// precision won't effect the result.
00220     ///
00221     /// Note: This option only controls formation of fused ops by the
00222     /// optimizers.  Fused operations that are explicitly specified (e.g. FMA
00223     /// via the llvm.fma.* intrinsic) will always be honored, regardless of
00224     /// the value of this option.
00225     FPOpFusion::FPOpFusionMode AllowFPOpFusion;
00226 
00227     /// JTType - This flag specifies the type of jump-instruction table to
00228     /// create for functions that have the jumptable attribute.
00229     JumpTable::JumpTableType JTType;
00230 
00231     /// ThreadModel - This flag specifies the type of threading model to assume
00232     /// for things like atomics
00233     ThreadModel::Model ThreadModel;
00234 
00235     /// Machine level options.
00236     MCTargetOptions MCOptions;
00237   };
00238 
00239 // Comparison operators:
00240 
00241 
00242 inline bool operator==(const TargetOptions &LHS,
00243                        const TargetOptions &RHS) {
00244 #define ARE_EQUAL(X) LHS.X == RHS.X
00245   return
00246     ARE_EQUAL(UnsafeFPMath) &&
00247     ARE_EQUAL(NoInfsFPMath) &&
00248     ARE_EQUAL(NoNaNsFPMath) &&
00249     ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
00250     ARE_EQUAL(UseSoftFloat) &&
00251     ARE_EQUAL(NoZerosInBSS) &&
00252     ARE_EQUAL(JITEmitDebugInfo) &&
00253     ARE_EQUAL(JITEmitDebugInfoToDisk) &&
00254     ARE_EQUAL(GuaranteedTailCallOpt) &&
00255     ARE_EQUAL(DisableTailCalls) &&
00256     ARE_EQUAL(StackAlignmentOverride) &&
00257     ARE_EQUAL(EnableFastISel) &&
00258     ARE_EQUAL(PositionIndependentExecutable) &&
00259     ARE_EQUAL(UseInitArray) &&
00260     ARE_EQUAL(TrapUnreachable) &&
00261     ARE_EQUAL(TrapFuncName) &&
00262     ARE_EQUAL(FloatABIType) &&
00263     ARE_EQUAL(AllowFPOpFusion) &&
00264     ARE_EQUAL(MCOptions);
00265 #undef ARE_EQUAL
00266 }
00267 
00268 inline bool operator!=(const TargetOptions &LHS,
00269                        const TargetOptions &RHS) {
00270   return !(LHS == RHS);
00271 }
00272 
00273 } // End llvm namespace
00274 
00275 #endif