Home | History | Annotate | Download | only in Frontend
      1 //===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  This file defines the CodeGenOptions interface.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
     15 #define LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
     16 
     17 #include <string>
     18 #include <vector>
     19 
     20 namespace clang {
     21 
     22 /// CodeGenOptions - Track various options which control how the code
     23 /// is optimized and passed to the backend.
     24 class CodeGenOptions {
     25 public:
     26   enum InliningMethod {
     27     NoInlining,         // Perform no inlining whatsoever.
     28     NormalInlining,     // Use the standard function inlining pass.
     29     OnlyAlwaysInlining  // Only run the always inlining pass.
     30   };
     31 
     32   enum ObjCDispatchMethodKind {
     33     Legacy = 0,
     34     NonLegacy = 1,
     35     Mixed = 2
     36   };
     37 
     38   unsigned AsmVerbose        : 1; /// -dA, -fverbose-asm.
     39   unsigned ObjCAutoRefCountExceptions : 1; /// Whether ARC should be EH-safe.
     40   unsigned CUDAIsDevice      : 1; /// Set when compiling for CUDA device.
     41   unsigned CXAAtExit         : 1; /// Use __cxa_atexit for calling destructors.
     42   unsigned CXXCtorDtorAliases: 1; /// Emit complete ctors/dtors as linker
     43                                   /// aliases to base ctors when possible.
     44   unsigned DataSections      : 1; /// Set when -fdata-sections is enabled
     45   unsigned DebugInfo         : 1; /// Should generate debug info (-g).
     46   unsigned LimitDebugInfo    : 1; /// Limit generated debug info to reduce size.
     47   unsigned DisableFPElim     : 1; /// Set when -fomit-frame-pointer is enabled.
     48   unsigned DisableLLVMOpts   : 1; /// Don't run any optimizations, for use in
     49                                   /// getting .bc files that correspond to the
     50                                   /// internal state before optimizations are
     51                                   /// done.
     52   unsigned DisableRedZone    : 1; /// Set when -mno-red-zone is enabled.
     53   unsigned EmitDeclMetadata  : 1; /// Emit special metadata indicating what
     54                                   /// Decl* various IR entities came from.  Only
     55                                   /// useful when running CodeGen as a
     56                                   /// subroutine.
     57   unsigned EmitGcovArcs      : 1; /// Emit coverage data files, aka. GCDA.
     58   unsigned EmitGcovNotes     : 1; /// Emit coverage "notes" files, aka GCNO.
     59   unsigned ForbidGuardVariables : 1; /// Issue errors if C++ guard variables
     60                                   /// are required
     61   unsigned FunctionSections  : 1; /// Set when -ffunction-sections is enabled
     62   unsigned HiddenWeakTemplateVTables : 1; /// Emit weak vtables and RTTI for
     63                                   /// template classes with hidden visibility
     64   unsigned HiddenWeakVTables : 1; /// Emit weak vtables, RTTI, and thunks with
     65                                   /// hidden visibility.
     66   unsigned InstrumentFunctions : 1; /// Set when -finstrument-functions is
     67                                     /// enabled.
     68   unsigned InstrumentForProfiling : 1; /// Set when -pg is enabled
     69   unsigned LessPreciseFPMAD  : 1; /// Enable less precise MAD instructions to be
     70                                   /// generated.
     71   unsigned MergeAllConstants : 1; /// Merge identical constants.
     72   unsigned NoCommon          : 1; /// Set when -fno-common or C++ is enabled.
     73   unsigned NoDwarf2CFIAsm    : 1; /// Set when -fno-dwarf2-cfi-asm is enabled.
     74   unsigned NoDwarfDirectoryAsm : 1; /// Set when -fno-dwarf-directory-asm is
     75                                     /// enabled.
     76   unsigned NoExecStack       : 1; /// Set when -Wa,--noexecstack is enabled.
     77   unsigned NoGlobalMerge     : 1; /// Set when -mno-global-merge is enabled.
     78   unsigned NoImplicitFloat   : 1; /// Set when -mno-implicit-float is enabled.
     79   unsigned NoInfsFPMath      : 1; /// Assume FP arguments, results not +-Inf.
     80   unsigned NoNaNsFPMath      : 1; /// Assume FP arguments, results not NaN.
     81   unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss
     82   unsigned ObjCDispatchMethod : 2; /// Method of Objective-C dispatch to use.
     83   unsigned ObjCRuntimeHasARC : 1; /// The target runtime supports ARC natively
     84   unsigned ObjCRuntimeHasTerminate : 1; /// The ObjC runtime has objc_terminate
     85   unsigned OmitLeafFramePointer : 1; /// Set when -momit-leaf-frame-pointer is
     86                                      /// enabled.
     87   unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
     88   unsigned OptimizeSize      : 2; /// If -Os (==1) or -Oz (==2) is specified.
     89   unsigned RelaxAll          : 1; /// Relax all machine code instructions.
     90   unsigned RelaxedAliasing   : 1; /// Set when -fno-strict-aliasing is enabled.
     91   unsigned SaveTempLabels    : 1; /// Save temporary labels.
     92   unsigned SimplifyLibCalls  : 1; /// Set when -fbuiltin is enabled.
     93   unsigned SoftFloat         : 1; /// -soft-float.
     94   unsigned TimePasses        : 1; /// Set when -ftime-report is enabled.
     95   unsigned UnitAtATime       : 1; /// Unused. For mirroring GCC optimization
     96                                   /// selection.
     97   unsigned UnrollLoops       : 1; /// Control whether loops are unrolled.
     98   unsigned UnsafeFPMath      : 1; /// Allow unsafe floating point optzns.
     99   unsigned UnwindTables      : 1; /// Emit unwind tables.
    100 
    101   /// Attempt to use register sized accesses to bit-fields in structures, when
    102   /// possible.
    103   unsigned UseRegisterSizedBitfieldAccess : 1;
    104 
    105   unsigned VerifyModule      : 1; /// Control whether the module should be run
    106                                   /// through the LLVM Verifier.
    107 
    108   /// The code model to use (-mcmodel).
    109   std::string CodeModel;
    110 
    111   /// The filename with path we use for coverage files. The extension will be
    112   /// replaced.
    113   std::string CoverageFile;
    114 
    115   /// Enable additional debugging information.
    116   std::string DebugPass;
    117 
    118   /// The string to embed in the debug information for the compile unit, if
    119   /// non-empty.
    120   std::string DwarfDebugFlags;
    121 
    122   /// The ABI to use for passing floating point arguments.
    123   std::string FloatABI;
    124 
    125   /// The float precision limit to use, if non-empty.
    126   std::string LimitFloatPrecision;
    127 
    128   /// The kind of inlining to perform.
    129   InliningMethod Inlining;
    130 
    131   /// The user provided name for the "main file", if non-empty. This is useful
    132   /// in situations where the input file name does not match the original input
    133   /// file, for example with -save-temps.
    134   std::string MainFileName;
    135 
    136   /// The name of the relocation model to use.
    137   std::string RelocationModel;
    138 
    139   /// A list of command-line options to forward to the LLVM backend.
    140   std::vector<std::string> BackendOptions;
    141 
    142   /// The user specified number of registers to be used for integral arguments,
    143   /// or 0 if unspecified.
    144   unsigned NumRegisterParameters;
    145 
    146 public:
    147   CodeGenOptions() {
    148     AsmVerbose = 0;
    149     CUDAIsDevice = 0;
    150     CXAAtExit = 1;
    151     CXXCtorDtorAliases = 0;
    152     DataSections = 0;
    153     DebugInfo = 0;
    154     LimitDebugInfo = 0;
    155     DisableFPElim = 0;
    156     DisableLLVMOpts = 0;
    157     DisableRedZone = 0;
    158     EmitDeclMetadata = 0;
    159     EmitGcovArcs = 0;
    160     EmitGcovNotes = 0;
    161     ForbidGuardVariables = 0;
    162     FunctionSections = 0;
    163     HiddenWeakTemplateVTables = 0;
    164     HiddenWeakVTables = 0;
    165     InstrumentFunctions = 0;
    166     InstrumentForProfiling = 0;
    167     LessPreciseFPMAD = 0;
    168     MergeAllConstants = 1;
    169     NoCommon = 0;
    170     NoDwarf2CFIAsm = 0;
    171     NoImplicitFloat = 0;
    172     NoInfsFPMath = 0;
    173     NoNaNsFPMath = 0;
    174     NoZeroInitializedInBSS = 0;
    175     NumRegisterParameters = 0;
    176     ObjCAutoRefCountExceptions = 0;
    177     ObjCDispatchMethod = Legacy;
    178     ObjCRuntimeHasARC = 0;
    179     ObjCRuntimeHasTerminate = 0;
    180     OmitLeafFramePointer = 0;
    181     OptimizationLevel = 0;
    182     OptimizeSize = 0;
    183     RelaxAll = 0;
    184     RelaxedAliasing = 0;
    185     SaveTempLabels = 0;
    186     SimplifyLibCalls = 1;
    187     SoftFloat = 0;
    188     TimePasses = 0;
    189     UnitAtATime = 1;
    190     UnrollLoops = 0;
    191     UnsafeFPMath = 0;
    192     UnwindTables = 0;
    193     UseRegisterSizedBitfieldAccess = 0;
    194     VerifyModule = 1;
    195 
    196     Inlining = NoInlining;
    197     RelocationModel = "pic";
    198   }
    199 
    200   ObjCDispatchMethodKind getObjCDispatchMethod() const {
    201     return ObjCDispatchMethodKind(ObjCDispatchMethod);
    202   }
    203 };
    204 
    205 }  // end namespace clang
    206 
    207 #endif
    208