Home | History | Annotate | Line # | Download | only in Driver
      1 //===--- Driver.h - Clang GCC Compatible Driver -----------------*- C++ -*-===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 
      9 #ifndef LLVM_CLANG_DRIVER_DRIVER_H
     10 #define LLVM_CLANG_DRIVER_DRIVER_H
     11 
     12 #include "clang/Basic/Diagnostic.h"
     13 #include "clang/Basic/LLVM.h"
     14 #include "clang/Driver/Action.h"
     15 #include "clang/Driver/Options.h"
     16 #include "clang/Driver/Phases.h"
     17 #include "clang/Driver/ToolChain.h"
     18 #include "clang/Driver/Types.h"
     19 #include "clang/Driver/Util.h"
     20 #include "llvm/ADT/StringMap.h"
     21 #include "llvm/ADT/StringRef.h"
     22 #include "llvm/Option/Arg.h"
     23 #include "llvm/Option/ArgList.h"
     24 #include "llvm/Support/StringSaver.h"
     25 
     26 #include <list>
     27 #include <map>
     28 #include <string>
     29 
     30 namespace llvm {
     31 class Triple;
     32 namespace vfs {
     33 class FileSystem;
     34 }
     35 } // namespace llvm
     36 
     37 namespace clang {
     38 
     39 namespace driver {
     40 
     41   class Command;
     42   class Compilation;
     43   class InputInfo;
     44   class JobList;
     45   class JobAction;
     46   class SanitizerArgs;
     47   class ToolChain;
     48 
     49 /// Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
     50 enum LTOKind {
     51   LTOK_None,
     52   LTOK_Full,
     53   LTOK_Thin,
     54   LTOK_Unknown
     55 };
     56 
     57 /// Driver - Encapsulate logic for constructing compilation processes
     58 /// from a set of gcc-driver-like command line arguments.
     59 class Driver {
     60   DiagnosticsEngine &Diags;
     61 
     62   IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
     63 
     64   enum DriverMode {
     65     GCCMode,
     66     GXXMode,
     67     CPPMode,
     68     CLMode,
     69     FlangMode
     70   } Mode;
     71 
     72   enum SaveTempsMode {
     73     SaveTempsNone,
     74     SaveTempsCwd,
     75     SaveTempsObj
     76   } SaveTemps;
     77 
     78   enum BitcodeEmbedMode {
     79     EmbedNone,
     80     EmbedMarker,
     81     EmbedBitcode
     82   } BitcodeEmbed;
     83 
     84   /// LTO mode selected via -f(no-)?lto(=.*)? options.
     85   LTOKind LTOMode;
     86 
     87   /// LTO mode selected via -f(no-offload-)?lto(=.*)? options.
     88   LTOKind OffloadLTOMode;
     89 
     90 public:
     91   enum OpenMPRuntimeKind {
     92     /// An unknown OpenMP runtime. We can't generate effective OpenMP code
     93     /// without knowing what runtime to target.
     94     OMPRT_Unknown,
     95 
     96     /// The LLVM OpenMP runtime. When completed and integrated, this will become
     97     /// the default for Clang.
     98     OMPRT_OMP,
     99 
    100     /// The GNU OpenMP runtime. Clang doesn't support generating OpenMP code for
    101     /// this runtime but can swallow the pragmas, and find and link against the
    102     /// runtime library itself.
    103     OMPRT_GOMP,
    104 
    105     /// The legacy name for the LLVM OpenMP runtime from when it was the Intel
    106     /// OpenMP runtime. We support this mode for users with existing
    107     /// dependencies on this runtime library name.
    108     OMPRT_IOMP5
    109   };
    110 
    111   // Diag - Forwarding function for diagnostics.
    112   DiagnosticBuilder Diag(unsigned DiagID) const {
    113     return Diags.Report(DiagID);
    114   }
    115 
    116   // FIXME: Privatize once interface is stable.
    117 public:
    118   /// The name the driver was invoked as.
    119   std::string Name;
    120 
    121   /// The path the driver executable was in, as invoked from the
    122   /// command line.
    123   std::string Dir;
    124 
    125   /// The original path to the clang executable.
    126   std::string ClangExecutable;
    127 
    128   /// Target and driver mode components extracted from clang executable name.
    129   ParsedClangName ClangNameParts;
    130 
    131   /// The path to the installed clang directory, if any.
    132   std::string InstalledDir;
    133 
    134   /// The path to the compiler resource directory.
    135   std::string ResourceDir;
    136 
    137   /// System directory for config files.
    138   std::string SystemConfigDir;
    139 
    140   /// User directory for config files.
    141   std::string UserConfigDir;
    142 
    143   /// A prefix directory used to emulate a limited subset of GCC's '-Bprefix'
    144   /// functionality.
    145   /// FIXME: This type of customization should be removed in favor of the
    146   /// universal driver when it is ready.
    147   typedef SmallVector<std::string, 4> prefix_list;
    148   prefix_list PrefixDirs;
    149 
    150   /// sysroot, if present
    151   std::string SysRoot;
    152 
    153   /// Dynamic loader prefix, if present
    154   std::string DyldPrefix;
    155 
    156   /// Driver title to use with help.
    157   std::string DriverTitle;
    158 
    159   /// Information about the host which can be overridden by the user.
    160   std::string HostBits, HostMachine, HostSystem, HostRelease;
    161 
    162   /// The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
    163   std::string CCPrintStatReportFilename;
    164 
    165   /// The file to log CC_PRINT_OPTIONS output to, if enabled.
    166   std::string CCPrintOptionsFilename;
    167 
    168   /// The file to log CC_PRINT_HEADERS output to, if enabled.
    169   std::string CCPrintHeadersFilename;
    170 
    171   /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
    172   std::string CCLogDiagnosticsFilename;
    173 
    174   /// A list of inputs and their types for the given arguments.
    175   typedef SmallVector<std::pair<types::ID, const llvm::opt::Arg *>, 16>
    176       InputList;
    177 
    178   /// Whether the driver should follow g++ like behavior.
    179   bool CCCIsCXX() const { return Mode == GXXMode; }
    180 
    181   /// Whether the driver is just the preprocessor.
    182   bool CCCIsCPP() const { return Mode == CPPMode; }
    183 
    184   /// Whether the driver should follow gcc like behavior.
    185   bool CCCIsCC() const { return Mode == GCCMode; }
    186 
    187   /// Whether the driver should follow cl.exe like behavior.
    188   bool IsCLMode() const { return Mode == CLMode; }
    189 
    190   /// Whether the driver should invoke flang for fortran inputs.
    191   /// Other modes fall back to calling gcc which in turn calls gfortran.
    192   bool IsFlangMode() const { return Mode == FlangMode; }
    193 
    194   /// Only print tool bindings, don't build any jobs.
    195   unsigned CCCPrintBindings : 1;
    196 
    197   /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to
    198   /// CCPrintOptionsFilename or to stderr.
    199   unsigned CCPrintOptions : 1;
    200 
    201   /// Set CC_PRINT_HEADERS mode, which causes the frontend to log header include
    202   /// information to CCPrintHeadersFilename or to stderr.
    203   unsigned CCPrintHeaders : 1;
    204 
    205   /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics
    206   /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable
    207   /// format.
    208   unsigned CCLogDiagnostics : 1;
    209 
    210   /// Whether the driver is generating diagnostics for debugging purposes.
    211   unsigned CCGenDiagnostics : 1;
    212 
    213   /// Set CC_PRINT_PROC_STAT mode, which causes the driver to dump
    214   /// performance report to CC_PRINT_PROC_STAT_FILE or to stdout.
    215   unsigned CCPrintProcessStats : 1;
    216 
    217   /// Pointer to the ExecuteCC1Tool function, if available.
    218   /// When the clangDriver lib is used through clang.exe, this provides a
    219   /// shortcut for executing the -cc1 command-line directly, in the same
    220   /// process.
    221   typedef int (*CC1ToolFunc)(SmallVectorImpl<const char *> &ArgV);
    222   CC1ToolFunc CC1Main = nullptr;
    223 
    224 private:
    225   /// Raw target triple.
    226   std::string TargetTriple;
    227 
    228   /// Name to use when invoking gcc/g++.
    229   std::string CCCGenericGCCName;
    230 
    231   /// Name of configuration file if used.
    232   std::string ConfigFile;
    233 
    234   /// Allocator for string saver.
    235   llvm::BumpPtrAllocator Alloc;
    236 
    237   /// Object that stores strings read from configuration file.
    238   llvm::StringSaver Saver;
    239 
    240   /// Arguments originated from configuration file.
    241   std::unique_ptr<llvm::opt::InputArgList> CfgOptions;
    242 
    243   /// Arguments originated from command line.
    244   std::unique_ptr<llvm::opt::InputArgList> CLOptions;
    245 
    246   /// Whether to check that input files exist when constructing compilation
    247   /// jobs.
    248   unsigned CheckInputsExist : 1;
    249 
    250 public:
    251   /// Force clang to emit reproducer for driver invocation. This is enabled
    252   /// indirectly by setting FORCE_CLANG_DIAGNOSTICS_CRASH environment variable
    253   /// or when using the -gen-reproducer driver flag.
    254   unsigned GenReproducer : 1;
    255 
    256 private:
    257   /// Certain options suppress the 'no input files' warning.
    258   unsigned SuppressMissingInputWarning : 1;
    259 
    260   /// Cache of all the ToolChains in use by the driver.
    261   ///
    262   /// This maps from the string representation of a triple to a ToolChain
    263   /// created targeting that triple. The driver owns all the ToolChain objects
    264   /// stored in it, and will clean them up when torn down.
    265   mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
    266 
    267 private:
    268   /// TranslateInputArgs - Create a new derived argument list from the input
    269   /// arguments, after applying the standard argument translations.
    270   llvm::opt::DerivedArgList *
    271   TranslateInputArgs(const llvm::opt::InputArgList &Args) const;
    272 
    273   // getFinalPhase - Determine which compilation mode we are in and record
    274   // which option we used to determine the final phase.
    275   // TODO: Much of what getFinalPhase returns are not actually true compiler
    276   //       modes. Fold this functionality into Types::getCompilationPhases and
    277   //       handleArguments.
    278   phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL,
    279                            llvm::opt::Arg **FinalPhaseArg = nullptr) const;
    280 
    281   // handleArguments - All code related to claiming and printing diagnostics
    282   // related to arguments to the driver are done here.
    283   void handleArguments(Compilation &C, llvm::opt::DerivedArgList &Args,
    284                        const InputList &Inputs, ActionList &Actions) const;
    285 
    286   // Before executing jobs, sets up response files for commands that need them.
    287   void setUpResponseFiles(Compilation &C, Command &Cmd);
    288 
    289   void generatePrefixedToolNames(StringRef Tool, const ToolChain &TC,
    290                                  SmallVectorImpl<std::string> &Names) const;
    291 
    292   /// Find the appropriate .crash diagonostic file for the child crash
    293   /// under this driver and copy it out to a temporary destination with the
    294   /// other reproducer related files (.sh, .cache, etc). If not found, suggest a
    295   /// directory for the user to look at.
    296   ///
    297   /// \param ReproCrashFilename The file path to copy the .crash to.
    298   /// \param CrashDiagDir       The suggested directory for the user to look at
    299   ///                           in case the search or copy fails.
    300   ///
    301   /// \returns If the .crash is found and successfully copied return true,
    302   /// otherwise false and return the suggested directory in \p CrashDiagDir.
    303   bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
    304                               SmallString<128> &CrashDiagDir);
    305 
    306 public:
    307 
    308   /// Takes the path to a binary that's either in bin/ or lib/ and returns
    309   /// the path to clang's resource directory.
    310   static std::string GetResourcesPath(StringRef BinaryPath,
    311                                       StringRef CustomResourceDir = "");
    312 
    313   Driver(StringRef ClangExecutable, StringRef TargetTriple,
    314          DiagnosticsEngine &Diags, std::string Title = "clang LLVM compiler",
    315          IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
    316 
    317   /// @name Accessors
    318   /// @{
    319 
    320   /// Name to use when invoking gcc/g++.
    321   const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; }
    322 
    323   const std::string &getConfigFile() const { return ConfigFile; }
    324 
    325   const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); }
    326 
    327   DiagnosticsEngine &getDiags() const { return Diags; }
    328 
    329   llvm::vfs::FileSystem &getVFS() const { return *VFS; }
    330 
    331   bool getCheckInputsExist() const { return CheckInputsExist; }
    332 
    333   void setCheckInputsExist(bool Value) { CheckInputsExist = Value; }
    334 
    335   void setTargetAndMode(const ParsedClangName &TM) { ClangNameParts = TM; }
    336 
    337   const std::string &getTitle() { return DriverTitle; }
    338   void setTitle(std::string Value) { DriverTitle = std::move(Value); }
    339 
    340   std::string getTargetTriple() const { return TargetTriple; }
    341 
    342   /// Get the path to the main clang executable.
    343   const char *getClangProgramPath() const {
    344     return ClangExecutable.c_str();
    345   }
    346 
    347   /// Get the path to where the clang executable was installed.
    348   const char *getInstalledDir() const {
    349     if (!InstalledDir.empty())
    350       return InstalledDir.c_str();
    351     return Dir.c_str();
    352   }
    353   void setInstalledDir(StringRef Value) { InstalledDir = std::string(Value); }
    354 
    355   bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
    356   bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
    357 
    358   bool embedBitcodeEnabled() const { return BitcodeEmbed != EmbedNone; }
    359   bool embedBitcodeInObject() const { return (BitcodeEmbed == EmbedBitcode); }
    360   bool embedBitcodeMarkerOnly() const { return (BitcodeEmbed == EmbedMarker); }
    361 
    362   /// Compute the desired OpenMP runtime from the flags provided.
    363   OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const;
    364 
    365   /// @}
    366   /// @name Primary Functionality
    367   /// @{
    368 
    369   /// CreateOffloadingDeviceToolChains - create all the toolchains required to
    370   /// support offloading devices given the programming models specified in the
    371   /// current compilation. Also, update the host tool chain kind accordingly.
    372   void CreateOffloadingDeviceToolChains(Compilation &C, InputList &Inputs);
    373 
    374   /// BuildCompilation - Construct a compilation object for a command
    375   /// line argument vector.
    376   ///
    377   /// \return A compilation, or 0 if none was built for the given
    378   /// argument vector. A null return value does not necessarily
    379   /// indicate an error condition, the diagnostics should be queried
    380   /// to determine if an error occurred.
    381   Compilation *BuildCompilation(ArrayRef<const char *> Args);
    382 
    383   /// @name Driver Steps
    384   /// @{
    385 
    386   /// ParseDriverMode - Look for and handle the driver mode option in Args.
    387   void ParseDriverMode(StringRef ProgramName, ArrayRef<const char *> Args);
    388 
    389   /// ParseArgStrings - Parse the given list of strings into an
    390   /// ArgList.
    391   llvm::opt::InputArgList ParseArgStrings(ArrayRef<const char *> Args,
    392                                           bool IsClCompatMode,
    393                                           bool &ContainsError);
    394 
    395   /// BuildInputs - Construct the list of inputs and their types from
    396   /// the given arguments.
    397   ///
    398   /// \param TC - The default host tool chain.
    399   /// \param Args - The input arguments.
    400   /// \param Inputs - The list to store the resulting compilation
    401   /// inputs onto.
    402   void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args,
    403                    InputList &Inputs) const;
    404 
    405   /// BuildActions - Construct the list of actions to perform for the
    406   /// given arguments, which are only done for a single architecture.
    407   ///
    408   /// \param C - The compilation that is being built.
    409   /// \param Args - The input arguments.
    410   /// \param Actions - The list to store the resulting actions onto.
    411   void BuildActions(Compilation &C, llvm::opt::DerivedArgList &Args,
    412                     const InputList &Inputs, ActionList &Actions) const;
    413 
    414   /// BuildUniversalActions - Construct the list of actions to perform
    415   /// for the given arguments, which may require a universal build.
    416   ///
    417   /// \param C - The compilation that is being built.
    418   /// \param TC - The default host tool chain.
    419   void BuildUniversalActions(Compilation &C, const ToolChain &TC,
    420                              const InputList &BAInputs) const;
    421 
    422   /// Check that the file referenced by Value exists. If it doesn't,
    423   /// issue a diagnostic and return false.
    424   /// If TypoCorrect is true and the file does not exist, see if it looks
    425   /// like a likely typo for a flag and if so print a "did you mean" blurb.
    426   bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args,
    427                               StringRef Value, types::ID Ty,
    428                               bool TypoCorrect) const;
    429 
    430   /// BuildJobs - Bind actions to concrete tools and translate
    431   /// arguments to form the list of jobs to run.
    432   ///
    433   /// \param C - The compilation that is being built.
    434   void BuildJobs(Compilation &C) const;
    435 
    436   /// ExecuteCompilation - Execute the compilation according to the command line
    437   /// arguments and return an appropriate exit code.
    438   ///
    439   /// This routine handles additional processing that must be done in addition
    440   /// to just running the subprocesses, for example reporting errors, setting
    441   /// up response files, removing temporary files, etc.
    442   int ExecuteCompilation(Compilation &C,
    443      SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands);
    444 
    445   /// Contains the files in the compilation diagnostic report generated by
    446   /// generateCompilationDiagnostics.
    447   struct CompilationDiagnosticReport {
    448     llvm::SmallVector<std::string, 4> TemporaryFiles;
    449   };
    450 
    451   /// generateCompilationDiagnostics - Generate diagnostics information
    452   /// including preprocessed source file(s).
    453   ///
    454   void generateCompilationDiagnostics(
    455       Compilation &C, const Command &FailingCommand,
    456       StringRef AdditionalInformation = "",
    457       CompilationDiagnosticReport *GeneratedReport = nullptr);
    458 
    459   /// @}
    460   /// @name Helper Methods
    461   /// @{
    462 
    463   /// PrintActions - Print the list of actions.
    464   void PrintActions(const Compilation &C) const;
    465 
    466   /// PrintHelp - Print the help text.
    467   ///
    468   /// \param ShowHidden - Show hidden options.
    469   void PrintHelp(bool ShowHidden) const;
    470 
    471   /// PrintVersion - Print the driver version.
    472   void PrintVersion(const Compilation &C, raw_ostream &OS) const;
    473 
    474   /// GetFilePath - Lookup \p Name in the list of file search paths.
    475   ///
    476   /// \param TC - The tool chain for additional information on
    477   /// directories to search.
    478   //
    479   // FIXME: This should be in CompilationInfo.
    480   std::string GetFilePath(StringRef Name, const ToolChain &TC) const;
    481 
    482   /// GetProgramPath - Lookup \p Name in the list of program search paths.
    483   ///
    484   /// \param TC - The provided tool chain for additional information on
    485   /// directories to search.
    486   //
    487   // FIXME: This should be in CompilationInfo.
    488   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
    489 
    490   /// HandleAutocompletions - Handle --autocomplete by searching and printing
    491   /// possible flags, descriptions, and its arguments.
    492   void HandleAutocompletions(StringRef PassedFlags) const;
    493 
    494   /// HandleImmediateArgs - Handle any arguments which should be
    495   /// treated before building actions or binding tools.
    496   ///
    497   /// \return Whether any compilation should be built for this
    498   /// invocation.
    499   bool HandleImmediateArgs(const Compilation &C);
    500 
    501   /// ConstructAction - Construct the appropriate action to do for
    502   /// \p Phase on the \p Input, taking in to account arguments
    503   /// like -fsyntax-only or --analyze.
    504   Action *ConstructPhaseAction(
    505       Compilation &C, const llvm::opt::ArgList &Args, phases::ID Phase,
    506       Action *Input,
    507       Action::OffloadKind TargetDeviceOffloadKind = Action::OFK_None) const;
    508 
    509   /// BuildJobsForAction - Construct the jobs to perform for the action \p A and
    510   /// return an InputInfo for the result of running \p A.  Will only construct
    511   /// jobs for a given (Action, ToolChain, BoundArch, DeviceKind) tuple once.
    512   InputInfo
    513   BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC,
    514                      StringRef BoundArch, bool AtTopLevel, bool MultipleArchs,
    515                      const char *LinkingOutput,
    516                      std::map<std::pair<const Action *, std::string>, InputInfo>
    517                          &CachedResults,
    518                      Action::OffloadKind TargetDeviceOffloadKind) const;
    519 
    520   /// Returns the default name for linked images (e.g., "a.out").
    521   const char *getDefaultImageName() const;
    522 
    523   /// GetNamedOutputPath - Return the name to use for the output of
    524   /// the action \p JA. The result is appended to the compilation's
    525   /// list of temporary or result files, as appropriate.
    526   ///
    527   /// \param C - The compilation.
    528   /// \param JA - The action of interest.
    529   /// \param BaseInput - The original input file that this action was
    530   /// triggered by.
    531   /// \param BoundArch - The bound architecture.
    532   /// \param AtTopLevel - Whether this is a "top-level" action.
    533   /// \param MultipleArchs - Whether multiple -arch options were supplied.
    534   /// \param NormalizedTriple - The normalized triple of the relevant target.
    535   const char *GetNamedOutputPath(Compilation &C, const JobAction &JA,
    536                                  const char *BaseInput, StringRef BoundArch,
    537                                  bool AtTopLevel, bool MultipleArchs,
    538                                  StringRef NormalizedTriple) const;
    539 
    540   /// GetTemporaryPath - Return the pathname of a temporary file to use
    541   /// as part of compilation; the file will have the given prefix and suffix.
    542   ///
    543   /// GCC goes to extra lengths here to be a bit more robust.
    544   std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const;
    545 
    546   /// GetTemporaryDirectory - Return the pathname of a temporary directory to
    547   /// use as part of compilation; the directory will have the given prefix.
    548   std::string GetTemporaryDirectory(StringRef Prefix) const;
    549 
    550   /// Return the pathname of the pch file in clang-cl mode.
    551   std::string GetClPchPath(Compilation &C, StringRef BaseName) const;
    552 
    553   /// ShouldUseClangCompiler - Should the clang compiler be used to
    554   /// handle this action.
    555   bool ShouldUseClangCompiler(const JobAction &JA) const;
    556 
    557   /// ShouldUseFlangCompiler - Should the flang compiler be used to
    558   /// handle this action.
    559   bool ShouldUseFlangCompiler(const JobAction &JA) const;
    560 
    561   /// ShouldEmitStaticLibrary - Should the linker emit a static library.
    562   bool ShouldEmitStaticLibrary(const llvm::opt::ArgList &Args) const;
    563 
    564   /// Returns true if we are performing any kind of LTO.
    565   bool isUsingLTO(bool IsOffload = false) const {
    566     return getLTOMode(IsOffload) != LTOK_None;
    567   }
    568 
    569   /// Get the specific kind of LTO being performed.
    570   LTOKind getLTOMode(bool IsOffload = false) const {
    571     return IsOffload ? OffloadLTOMode : LTOMode;
    572   }
    573 
    574 private:
    575 
    576   /// Tries to load options from configuration file.
    577   ///
    578   /// \returns true if error occurred.
    579   bool loadConfigFile();
    580 
    581   /// Read options from the specified file.
    582   ///
    583   /// \param [in] FileName File to read.
    584   /// \returns true, if error occurred while reading.
    585   bool readConfigFile(StringRef FileName);
    586 
    587   /// Set the driver mode (cl, gcc, etc) from an option string of the form
    588   /// --driver-mode=<mode>.
    589   void setDriverModeFromOption(StringRef Opt);
    590 
    591   /// Parse the \p Args list for LTO options and record the type of LTO
    592   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
    593   void setLTOMode(const llvm::opt::ArgList &Args);
    594 
    595   /// Retrieves a ToolChain for a particular \p Target triple.
    596   ///
    597   /// Will cache ToolChains for the life of the driver object, and create them
    598   /// on-demand.
    599   const ToolChain &getToolChain(const llvm::opt::ArgList &Args,
    600                                 const llvm::Triple &Target) const;
    601 
    602   /// @}
    603 
    604   /// Get bitmasks for which option flags to include and exclude based on
    605   /// the driver mode.
    606   std::pair<unsigned, unsigned> getIncludeExcludeOptionFlagMasks(bool IsClCompatMode) const;
    607 
    608   /// Helper used in BuildJobsForAction.  Doesn't use the cache when building
    609   /// jobs specifically for the given action, but will use the cache when
    610   /// building jobs for the Action's inputs.
    611   InputInfo BuildJobsForActionNoCache(
    612       Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
    613       bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
    614       std::map<std::pair<const Action *, std::string>, InputInfo>
    615           &CachedResults,
    616       Action::OffloadKind TargetDeviceOffloadKind) const;
    617 
    618 public:
    619   /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
    620   /// return the grouped values as integers. Numbers which are not
    621   /// provided are set to 0.
    622   ///
    623   /// \return True if the entire string was parsed (9.2), or all
    624   /// groups were parsed (10.3.5extrastuff). HadExtra is true if all
    625   /// groups were parsed but extra characters remain at the end.
    626   static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor,
    627                                 unsigned &Micro, bool &HadExtra);
    628 
    629   /// Parse digits from a string \p Str and fulfill \p Digits with
    630   /// the parsed numbers. This method assumes that the max number of
    631   /// digits to look for is equal to Digits.size().
    632   ///
    633   /// \return True if the entire string was parsed and there are
    634   /// no extra characters remaining at the end.
    635   static bool GetReleaseVersion(StringRef Str,
    636                                 MutableArrayRef<unsigned> Digits);
    637   /// Compute the default -fmodule-cache-path.
    638   /// \return True if the system provides a default cache directory.
    639   static bool getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
    640 };
    641 
    642 /// \return True if the last defined optimization level is -Ofast.
    643 /// And False otherwise.
    644 bool isOptimizationLevelFast(const llvm::opt::ArgList &Args);
    645 
    646 /// \return True if the argument combination will end up generating remarks.
    647 bool willEmitRemarks(const llvm::opt::ArgList &Args);
    648 
    649 } // end namespace driver
    650 } // end namespace clang
    651 
    652 #endif
    653