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 "clang/Basic/DebugInfoOptions.h"
     18 #include "clang/Basic/Sanitizers.h"
     19 #include "llvm/Support/Regex.h"
     20 #include "llvm/Target/TargetOptions.h"
     21 #include <map>
     22 #include <memory>
     23 #include <string>
     24 #include <vector>
     25 
     26 namespace clang {
     27 
     28 /// \brief Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
     29 /// that this large collection of bitfields is a trivial class type.
     30 class CodeGenOptionsBase {
     31 public:
     32 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
     33 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
     34 #include "clang/Frontend/CodeGenOptions.def"
     35 
     36 protected:
     37 #define CODEGENOPT(Name, Bits, Default)
     38 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
     39 #include "clang/Frontend/CodeGenOptions.def"
     40 };
     41 
     42 /// CodeGenOptions - Track various options which control how the code
     43 /// is optimized and passed to the backend.
     44 class CodeGenOptions : public CodeGenOptionsBase {
     45 public:
     46   enum InliningMethod {
     47     NoInlining,         // Perform no inlining whatsoever.
     48     NormalInlining,     // Use the standard function inlining pass.
     49     OnlyHintInlining,   // Inline only (implicitly) hinted functions.
     50     OnlyAlwaysInlining  // Only run the always inlining pass.
     51   };
     52 
     53   enum VectorLibrary {
     54     NoLibrary, // Don't use any vector library.
     55     Accelerate // Use the Accelerate framework.
     56   };
     57 
     58   enum ObjCDispatchMethodKind {
     59     Legacy = 0,
     60     NonLegacy = 1,
     61     Mixed = 2
     62   };
     63 
     64   enum TLSModel {
     65     GeneralDynamicTLSModel,
     66     LocalDynamicTLSModel,
     67     InitialExecTLSModel,
     68     LocalExecTLSModel
     69   };
     70 
     71   enum FPContractModeKind {
     72     FPC_Off,        // Form fused FP ops only where result will not be affected.
     73     FPC_On,         // Form fused FP ops according to FP_CONTRACT rules.
     74     FPC_Fast        // Aggressively fuse FP ops (E.g. FMA).
     75   };
     76 
     77   enum StructReturnConventionKind {
     78     SRCK_Default,  // No special option was passed.
     79     SRCK_OnStack,  // Small structs on the stack (-fpcc-struct-return).
     80     SRCK_InRegs    // Small structs in registers (-freg-struct-return).
     81   };
     82 
     83   enum ProfileInstrKind {
     84     ProfileNone,       // Profile instrumentation is turned off.
     85     ProfileClangInstr, // Clang instrumentation to generate execution counts
     86                        // to use with PGO.
     87     ProfileIRInstr,    // IR level PGO instrumentation in LLVM.
     88   };
     89 
     90   enum EmbedBitcodeKind {
     91     Embed_Off,      // No embedded bitcode.
     92     Embed_All,      // Embed both bitcode and commandline in the output.
     93     Embed_Bitcode,  // Embed just the bitcode in the output.
     94     Embed_Marker    // Embed a marker as a placeholder for bitcode.
     95   };
     96 
     97   /// The code model to use (-mcmodel).
     98   std::string CodeModel;
     99 
    100   /// The filename with path we use for coverage files. The extension will be
    101   /// replaced.
    102   std::string CoverageFile;
    103 
    104   /// The version string to put into coverage files.
    105   char CoverageVersion[4];
    106 
    107   /// Enable additional debugging information.
    108   std::string DebugPass;
    109 
    110   /// The string to embed in debug information as the current working directory.
    111   std::string DebugCompilationDir;
    112 
    113   /// The string to embed in the debug information for the compile unit, if
    114   /// non-empty.
    115   std::string DwarfDebugFlags;
    116 
    117   std::map<std::string, std::string> DebugPrefixMap;
    118 
    119   /// The ABI to use for passing floating point arguments.
    120   std::string FloatABI;
    121 
    122   /// The float precision limit to use, if non-empty.
    123   std::string LimitFloatPrecision;
    124 
    125   /// The name of the bitcode file to link before optzns.
    126   std::vector<std::pair<unsigned, std::string>> LinkBitcodeFiles;
    127 
    128   /// The user provided name for the "main file", if non-empty. This is useful
    129   /// in situations where the input file name does not match the original input
    130   /// file, for example with -save-temps.
    131   std::string MainFileName;
    132 
    133   /// The name for the split debug info file that we'll break out. This is used
    134   /// in the backend for setting the name in the skeleton cu.
    135   std::string SplitDwarfFile;
    136 
    137   /// The name of the relocation model to use.
    138   std::string RelocationModel;
    139 
    140   /// The thread model to use
    141   std::string ThreadModel;
    142 
    143   /// If not an empty string, trap intrinsics are lowered to calls to this
    144   /// function instead of to trap instructions.
    145   std::string TrapFuncName;
    146 
    147   /// A list of command-line options to forward to the LLVM backend.
    148   std::vector<std::string> BackendOptions;
    149 
    150   /// A list of dependent libraries.
    151   std::vector<std::string> DependentLibraries;
    152 
    153   /// A list of linker options to embed in the object file.
    154   std::vector<std::string> LinkerOptions;
    155 
    156   /// Name of the profile file to use as output for -fprofile-instr-generate
    157   /// and -fprofile-generate.
    158   std::string InstrProfileOutput;
    159 
    160   /// Name of the profile file to use with -fprofile-sample-use.
    161   std::string SampleProfileFile;
    162 
    163   /// Name of the profile file to use as input for -fprofile-instr-use
    164   std::string ProfileInstrumentUsePath;
    165 
    166   /// Name of the function summary index file to use for ThinLTO function
    167   /// importing.
    168   std::string ThinLTOIndexFile;
    169 
    170   /// A list of file names passed with -fcuda-include-gpubinary options to
    171   /// forward to CUDA runtime back-end for incorporating them into host-side
    172   /// object file.
    173   std::vector<std::string> CudaGpuBinaryFileNames;
    174 
    175   /// Regular expression to select optimizations for which we should enable
    176   /// optimization remarks. Transformation passes whose name matches this
    177   /// expression (and support this feature), will emit a diagnostic
    178   /// whenever they perform a transformation. This is enabled by the
    179   /// -Rpass=regexp flag.
    180   std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
    181 
    182   /// Regular expression to select optimizations for which we should enable
    183   /// missed optimization remarks. Transformation passes whose name matches this
    184   /// expression (and support this feature), will emit a diagnostic
    185   /// whenever they tried but failed to perform a transformation. This is
    186   /// enabled by the -Rpass-missed=regexp flag.
    187   std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
    188 
    189   /// Regular expression to select optimizations for which we should enable
    190   /// optimization analyses. Transformation passes whose name matches this
    191   /// expression (and support this feature), will emit a diagnostic
    192   /// whenever they want to explain why they decided to apply or not apply
    193   /// a given transformation. This is enabled by the -Rpass-analysis=regexp
    194   /// flag.
    195   std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
    196 
    197   /// Set of files definining the rules for the symbol rewriting.
    198   std::vector<std::string> RewriteMapFiles;
    199 
    200   /// Set of sanitizer checks that are non-fatal (i.e. execution should be
    201   /// continued when possible).
    202   SanitizerSet SanitizeRecover;
    203 
    204   /// Set of sanitizer checks that trap rather than diagnose.
    205   SanitizerSet SanitizeTrap;
    206 
    207   /// List of backend command-line options for -fembed-bitcode.
    208   std::vector<uint8_t> CmdArgs;
    209 
    210   /// \brief A list of all -fno-builtin-* function names (e.g., memset).
    211   std::vector<std::string> NoBuiltinFuncs;
    212 
    213 public:
    214   // Define accessors/mutators for code generation options of enumeration type.
    215 #define CODEGENOPT(Name, Bits, Default)
    216 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
    217   Type get##Name() const { return static_cast<Type>(Name); } \
    218   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
    219 #include "clang/Frontend/CodeGenOptions.def"
    220 
    221   CodeGenOptions();
    222 
    223   /// \brief Is this a libc/libm function that is no longer recognized as a
    224   /// builtin because a -fno-builtin-* option has been specified?
    225   bool isNoBuiltinFunc(const char *Name) const;
    226 
    227   const std::vector<std::string> &getNoBuiltinFuncs() const {
    228     return NoBuiltinFuncs;
    229   }
    230 
    231   /// \brief Check if Clang profile instrumenation is on.
    232   bool hasProfileClangInstr() const {
    233     return getProfileInstr() == ProfileClangInstr;
    234   }
    235 
    236   /// \brief Check if IR level profile instrumentation is on.
    237   bool hasProfileIRInstr() const {
    238     return getProfileInstr() == ProfileIRInstr;
    239   }
    240 
    241   /// \brief Check if Clang profile use is on.
    242   bool hasProfileClangUse() const {
    243     return getProfileUse() == ProfileClangInstr;
    244   }
    245 
    246   /// \brief Check if IR level profile use is on.
    247   bool hasProfileIRUse() const {
    248     return getProfileUse() == ProfileIRInstr;
    249   }
    250 
    251 };
    252 
    253 }  // end namespace clang
    254 
    255 #endif
    256