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     NormalInlining,     // Use the standard function inlining pass.
     48     OnlyHintInlining,   // Inline only (implicitly) hinted functions.
     49     OnlyAlwaysInlining  // Only run the always inlining pass.
     50   };
     51 
     52   enum VectorLibrary {
     53     NoLibrary,  // Don't use any vector library.
     54     Accelerate, // Use the Accelerate framework.
     55     SVML        // Intel short vector math library.
     56   };
     57 
     58 
     59   enum ObjCDispatchMethodKind {
     60     Legacy = 0,
     61     NonLegacy = 1,
     62     Mixed = 2
     63   };
     64 
     65   enum TLSModel {
     66     GeneralDynamicTLSModel,
     67     LocalDynamicTLSModel,
     68     InitialExecTLSModel,
     69     LocalExecTLSModel
     70   };
     71 
     72   enum StructReturnConventionKind {
     73     SRCK_Default,  // No special option was passed.
     74     SRCK_OnStack,  // Small structs on the stack (-fpcc-struct-return).
     75     SRCK_InRegs    // Small structs in registers (-freg-struct-return).
     76   };
     77 
     78   enum ProfileInstrKind {
     79     ProfileNone,       // Profile instrumentation is turned off.
     80     ProfileClangInstr, // Clang instrumentation to generate execution counts
     81                        // to use with PGO.
     82     ProfileIRInstr,    // IR level PGO instrumentation in LLVM.
     83   };
     84 
     85   enum EmbedBitcodeKind {
     86     Embed_Off,      // No embedded bitcode.
     87     Embed_All,      // Embed both bitcode and commandline in the output.
     88     Embed_Bitcode,  // Embed just the bitcode in the output.
     89     Embed_Marker    // Embed a marker as a placeholder for bitcode.
     90   };
     91 
     92   /// The code model to use (-mcmodel).
     93   std::string CodeModel;
     94 
     95   /// The filename with path we use for coverage data files. The runtime
     96   /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
     97   /// environment variables.
     98   std::string CoverageDataFile;
     99 
    100   /// The filename with path we use for coverage notes files.
    101   std::string CoverageNotesFile;
    102 
    103   /// The version string to put into coverage files.
    104   char CoverageVersion[4];
    105 
    106   /// Enable additional debugging information.
    107   std::string DebugPass;
    108 
    109   /// The string to embed in debug information as the current working directory.
    110   std::string DebugCompilationDir;
    111 
    112   /// The string to embed in the debug information for the compile unit, if
    113   /// non-empty.
    114   std::string DwarfDebugFlags;
    115 
    116   std::map<std::string, std::string> DebugPrefixMap;
    117 
    118   /// The ABI to use for passing floating point arguments.
    119   std::string FloatABI;
    120 
    121   /// The floating-point denormal mode to use.
    122   std::string FPDenormalMode;
    123 
    124   /// The float precision limit to use, if non-empty.
    125   std::string LimitFloatPrecision;
    126 
    127   struct BitcodeFileToLink {
    128     /// The filename of the bitcode file to link in.
    129     std::string Filename;
    130     /// If true, we set attributes functions in the bitcode library according to
    131     /// our CodeGenOptions, much as we set attrs on functions that we generate
    132     /// ourselves.
    133     bool PropagateAttrs = false;
    134     /// If true, we use LLVM module internalizer.
    135     bool Internalize = false;
    136     /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
    137     unsigned LinkFlags = 0;
    138   };
    139 
    140   /// The files specified here are linked in to the module before optimizations.
    141   std::vector<BitcodeFileToLink> LinkBitcodeFiles;
    142 
    143   /// The user provided name for the "main file", if non-empty. This is useful
    144   /// in situations where the input file name does not match the original input
    145   /// file, for example with -save-temps.
    146   std::string MainFileName;
    147 
    148   /// The name for the split debug info file that we'll break out. This is used
    149   /// in the backend for setting the name in the skeleton cu.
    150   std::string SplitDwarfFile;
    151 
    152   /// The name of the relocation model to use.
    153   std::string RelocationModel;
    154 
    155   /// The thread model to use
    156   std::string ThreadModel;
    157 
    158   /// If not an empty string, trap intrinsics are lowered to calls to this
    159   /// function instead of to trap instructions.
    160   std::string TrapFuncName;
    161 
    162   /// A list of command-line options to forward to the LLVM backend.
    163   std::vector<std::string> BackendOptions;
    164 
    165   /// A list of dependent libraries.
    166   std::vector<std::string> DependentLibraries;
    167 
    168   /// A list of linker options to embed in the object file.
    169   std::vector<std::string> LinkerOptions;
    170 
    171   /// Name of the profile file to use as output for -fprofile-instr-generate
    172   /// and -fprofile-generate.
    173   std::string InstrProfileOutput;
    174 
    175   /// Name of the profile file to use with -fprofile-sample-use.
    176   std::string SampleProfileFile;
    177 
    178   /// Name of the profile file to use as input for -fprofile-instr-use
    179   std::string ProfileInstrumentUsePath;
    180 
    181   /// Name of the function summary index file to use for ThinLTO function
    182   /// importing.
    183   std::string ThinLTOIndexFile;
    184 
    185   /// Name of a file that can optionally be written with minimized bitcode
    186   /// to be used as input for the ThinLTO thin link step, which only needs
    187   /// the summary and module symbol table (and not, e.g. any debug metadata).
    188   std::string ThinLinkBitcodeFile;
    189 
    190   /// A list of file names passed with -fcuda-include-gpubinary options to
    191   /// forward to CUDA runtime back-end for incorporating them into host-side
    192   /// object file.
    193   std::vector<std::string> CudaGpuBinaryFileNames;
    194 
    195   /// The name of the file to which the backend should save YAML optimization
    196   /// records.
    197   std::string OptRecordFile;
    198 
    199   /// Regular expression to select optimizations for which we should enable
    200   /// optimization remarks. Transformation passes whose name matches this
    201   /// expression (and support this feature), will emit a diagnostic
    202   /// whenever they perform a transformation. This is enabled by the
    203   /// -Rpass=regexp flag.
    204   std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
    205 
    206   /// Regular expression to select optimizations for which we should enable
    207   /// missed optimization remarks. Transformation passes whose name matches this
    208   /// expression (and support this feature), will emit a diagnostic
    209   /// whenever they tried but failed to perform a transformation. This is
    210   /// enabled by the -Rpass-missed=regexp flag.
    211   std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
    212 
    213   /// Regular expression to select optimizations for which we should enable
    214   /// optimization analyses. Transformation passes whose name matches this
    215   /// expression (and support this feature), will emit a diagnostic
    216   /// whenever they want to explain why they decided to apply or not apply
    217   /// a given transformation. This is enabled by the -Rpass-analysis=regexp
    218   /// flag.
    219   std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
    220 
    221   /// Set of files defining the rules for the symbol rewriting.
    222   std::vector<std::string> RewriteMapFiles;
    223 
    224   /// Set of sanitizer checks that are non-fatal (i.e. execution should be
    225   /// continued when possible).
    226   SanitizerSet SanitizeRecover;
    227 
    228   /// Set of sanitizer checks that trap rather than diagnose.
    229   SanitizerSet SanitizeTrap;
    230 
    231   /// List of backend command-line options for -fembed-bitcode.
    232   std::vector<uint8_t> CmdArgs;
    233 
    234   /// \brief A list of all -fno-builtin-* function names (e.g., memset).
    235   std::vector<std::string> NoBuiltinFuncs;
    236 
    237 public:
    238   // Define accessors/mutators for code generation options of enumeration type.
    239 #define CODEGENOPT(Name, Bits, Default)
    240 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
    241   Type get##Name() const { return static_cast<Type>(Name); } \
    242   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
    243 #include "clang/Frontend/CodeGenOptions.def"
    244 
    245   CodeGenOptions();
    246 
    247   /// \brief Is this a libc/libm function that is no longer recognized as a
    248   /// builtin because a -fno-builtin-* option has been specified?
    249   bool isNoBuiltinFunc(const char *Name) const;
    250 
    251   const std::vector<std::string> &getNoBuiltinFuncs() const {
    252     return NoBuiltinFuncs;
    253   }
    254 
    255   /// \brief Check if Clang profile instrumenation is on.
    256   bool hasProfileClangInstr() const {
    257     return getProfileInstr() == ProfileClangInstr;
    258   }
    259 
    260   /// \brief Check if IR level profile instrumentation is on.
    261   bool hasProfileIRInstr() const {
    262     return getProfileInstr() == ProfileIRInstr;
    263   }
    264 
    265   /// \brief Check if Clang profile use is on.
    266   bool hasProfileClangUse() const {
    267     return getProfileUse() == ProfileClangInstr;
    268   }
    269 
    270   /// \brief Check if IR level profile use is on.
    271   bool hasProfileIRUse() const {
    272     return getProfileUse() == ProfileIRInstr;
    273   }
    274 
    275 };
    276 
    277 }  // end namespace clang
    278 
    279 #endif
    280