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.
Diag(unsigned DiagID)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.
CCCIsCXX()179   bool CCCIsCXX() const { return Mode == GXXMode; }
180 
181   /// Whether the driver is just the preprocessor.
CCCIsCPP()182   bool CCCIsCPP() const { return Mode == CPPMode; }
183 
184   /// Whether the driver should follow gcc like behavior.
CCCIsCC()185   bool CCCIsCC() const { return Mode == GCCMode; }
186 
187   /// Whether the driver should follow cl.exe like behavior.
IsCLMode()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.
IsFlangMode()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++.
getCCCGenericGCCName()321   const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; }
322 
getConfigFile()323   const std::string &getConfigFile() const { return ConfigFile; }
324 
getOpts()325   const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); }
326 
getDiags()327   DiagnosticsEngine &getDiags() const { return Diags; }
328 
getVFS()329   llvm::vfs::FileSystem &getVFS() const { return *VFS; }
330 
getCheckInputsExist()331   bool getCheckInputsExist() const { return CheckInputsExist; }
332 
setCheckInputsExist(bool Value)333   void setCheckInputsExist(bool Value) { CheckInputsExist = Value; }
334 
setTargetAndMode(const ParsedClangName & TM)335   void setTargetAndMode(const ParsedClangName &TM) { ClangNameParts = TM; }
336 
getTitle()337   const std::string &getTitle() { return DriverTitle; }
setTitle(std::string Value)338   void setTitle(std::string Value) { DriverTitle = std::move(Value); }
339 
getTargetTriple()340   std::string getTargetTriple() const { return TargetTriple; }
341 
342   /// Get the path to the main clang executable.
getClangProgramPath()343   const char *getClangProgramPath() const {
344     return ClangExecutable.c_str();
345   }
346 
347   /// Get the path to where the clang executable was installed.
getInstalledDir()348   const char *getInstalledDir() const {
349     if (!InstalledDir.empty())
350       return InstalledDir.c_str();
351     return Dir.c_str();
352   }
setInstalledDir(StringRef Value)353   void setInstalledDir(StringRef Value) { InstalledDir = std::string(Value); }
354 
isSaveTempsEnabled()355   bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
isSaveTempsObj()356   bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
357 
embedBitcodeEnabled()358   bool embedBitcodeEnabled() const { return BitcodeEmbed != EmbedNone; }
embedBitcodeInObject()359   bool embedBitcodeInObject() const { return (BitcodeEmbed == EmbedBitcode); }
embedBitcodeMarkerOnly()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   /// ParseArgStrings - Parse the given list of strings into an
384   /// ArgList.
385   llvm::opt::InputArgList ParseArgStrings(ArrayRef<const char *> Args,
386                                           bool IsClCompatMode,
387                                           bool &ContainsError);
388 
389   /// BuildInputs - Construct the list of inputs and their types from
390   /// the given arguments.
391   ///
392   /// \param TC - The default host tool chain.
393   /// \param Args - The input arguments.
394   /// \param Inputs - The list to store the resulting compilation
395   /// inputs onto.
396   void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args,
397                    InputList &Inputs) const;
398 
399   /// BuildActions - Construct the list of actions to perform for the
400   /// given arguments, which are only done for a single architecture.
401   ///
402   /// \param C - The compilation that is being built.
403   /// \param Args - The input arguments.
404   /// \param Actions - The list to store the resulting actions onto.
405   void BuildActions(Compilation &C, llvm::opt::DerivedArgList &Args,
406                     const InputList &Inputs, ActionList &Actions) const;
407 
408   /// BuildUniversalActions - Construct the list of actions to perform
409   /// for the given arguments, which may require a universal build.
410   ///
411   /// \param C - The compilation that is being built.
412   /// \param TC - The default host tool chain.
413   void BuildUniversalActions(Compilation &C, const ToolChain &TC,
414                              const InputList &BAInputs) const;
415 
416   /// Check that the file referenced by Value exists. If it doesn't,
417   /// issue a diagnostic and return false.
418   /// If TypoCorrect is true and the file does not exist, see if it looks
419   /// like a likely typo for a flag and if so print a "did you mean" blurb.
420   bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args,
421                               StringRef Value, types::ID Ty,
422                               bool TypoCorrect) const;
423 
424   /// BuildJobs - Bind actions to concrete tools and translate
425   /// arguments to form the list of jobs to run.
426   ///
427   /// \param C - The compilation that is being built.
428   void BuildJobs(Compilation &C) const;
429 
430   /// ExecuteCompilation - Execute the compilation according to the command line
431   /// arguments and return an appropriate exit code.
432   ///
433   /// This routine handles additional processing that must be done in addition
434   /// to just running the subprocesses, for example reporting errors, setting
435   /// up response files, removing temporary files, etc.
436   int ExecuteCompilation(Compilation &C,
437      SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands);
438 
439   /// Contains the files in the compilation diagnostic report generated by
440   /// generateCompilationDiagnostics.
441   struct CompilationDiagnosticReport {
442     llvm::SmallVector<std::string, 4> TemporaryFiles;
443   };
444 
445   /// generateCompilationDiagnostics - Generate diagnostics information
446   /// including preprocessed source file(s).
447   ///
448   void generateCompilationDiagnostics(
449       Compilation &C, const Command &FailingCommand,
450       StringRef AdditionalInformation = "",
451       CompilationDiagnosticReport *GeneratedReport = nullptr);
452 
453   /// @}
454   /// @name Helper Methods
455   /// @{
456 
457   /// PrintActions - Print the list of actions.
458   void PrintActions(const Compilation &C) const;
459 
460   /// PrintHelp - Print the help text.
461   ///
462   /// \param ShowHidden - Show hidden options.
463   void PrintHelp(bool ShowHidden) const;
464 
465   /// PrintVersion - Print the driver version.
466   void PrintVersion(const Compilation &C, raw_ostream &OS) const;
467 
468   /// GetFilePath - Lookup \p Name in the list of file search paths.
469   ///
470   /// \param TC - The tool chain for additional information on
471   /// directories to search.
472   //
473   // FIXME: This should be in CompilationInfo.
474   std::string GetFilePath(StringRef Name, const ToolChain &TC) const;
475 
476   /// GetProgramPath - Lookup \p Name in the list of program search paths.
477   ///
478   /// \param TC - The provided tool chain for additional information on
479   /// directories to search.
480   //
481   // FIXME: This should be in CompilationInfo.
482   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
483 
484   /// HandleAutocompletions - Handle --autocomplete by searching and printing
485   /// possible flags, descriptions, and its arguments.
486   void HandleAutocompletions(StringRef PassedFlags) const;
487 
488   /// HandleImmediateArgs - Handle any arguments which should be
489   /// treated before building actions or binding tools.
490   ///
491   /// \return Whether any compilation should be built for this
492   /// invocation.
493   bool HandleImmediateArgs(const Compilation &C);
494 
495   /// ConstructAction - Construct the appropriate action to do for
496   /// \p Phase on the \p Input, taking in to account arguments
497   /// like -fsyntax-only or --analyze.
498   Action *ConstructPhaseAction(
499       Compilation &C, const llvm::opt::ArgList &Args, phases::ID Phase,
500       Action *Input,
501       Action::OffloadKind TargetDeviceOffloadKind = Action::OFK_None) const;
502 
503   /// BuildJobsForAction - Construct the jobs to perform for the action \p A and
504   /// return an InputInfo for the result of running \p A.  Will only construct
505   /// jobs for a given (Action, ToolChain, BoundArch, DeviceKind) tuple once.
506   InputInfo
507   BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC,
508                      StringRef BoundArch, bool AtTopLevel, bool MultipleArchs,
509                      const char *LinkingOutput,
510                      std::map<std::pair<const Action *, std::string>, InputInfo>
511                          &CachedResults,
512                      Action::OffloadKind TargetDeviceOffloadKind) const;
513 
514   /// Returns the default name for linked images (e.g., "a.out").
515   const char *getDefaultImageName() const;
516 
517   /// GetNamedOutputPath - Return the name to use for the output of
518   /// the action \p JA. The result is appended to the compilation's
519   /// list of temporary or result files, as appropriate.
520   ///
521   /// \param C - The compilation.
522   /// \param JA - The action of interest.
523   /// \param BaseInput - The original input file that this action was
524   /// triggered by.
525   /// \param BoundArch - The bound architecture.
526   /// \param AtTopLevel - Whether this is a "top-level" action.
527   /// \param MultipleArchs - Whether multiple -arch options were supplied.
528   /// \param NormalizedTriple - The normalized triple of the relevant target.
529   const char *GetNamedOutputPath(Compilation &C, const JobAction &JA,
530                                  const char *BaseInput, StringRef BoundArch,
531                                  bool AtTopLevel, bool MultipleArchs,
532                                  StringRef NormalizedTriple) const;
533 
534   /// GetTemporaryPath - Return the pathname of a temporary file to use
535   /// as part of compilation; the file will have the given prefix and suffix.
536   ///
537   /// GCC goes to extra lengths here to be a bit more robust.
538   std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const;
539 
540   /// GetTemporaryDirectory - Return the pathname of a temporary directory to
541   /// use as part of compilation; the directory will have the given prefix.
542   std::string GetTemporaryDirectory(StringRef Prefix) const;
543 
544   /// Return the pathname of the pch file in clang-cl mode.
545   std::string GetClPchPath(Compilation &C, StringRef BaseName) const;
546 
547   /// ShouldUseClangCompiler - Should the clang compiler be used to
548   /// handle this action.
549   bool ShouldUseClangCompiler(const JobAction &JA) const;
550 
551   /// ShouldUseFlangCompiler - Should the flang compiler be used to
552   /// handle this action.
553   bool ShouldUseFlangCompiler(const JobAction &JA) const;
554 
555   /// ShouldEmitStaticLibrary - Should the linker emit a static library.
556   bool ShouldEmitStaticLibrary(const llvm::opt::ArgList &Args) const;
557 
558   /// Returns true if we are performing any kind of LTO.
559   bool isUsingLTO(bool IsOffload = false) const {
560     return getLTOMode(IsOffload) != LTOK_None;
561   }
562 
563   /// Get the specific kind of LTO being performed.
564   LTOKind getLTOMode(bool IsOffload = false) const {
565     return IsOffload ? OffloadLTOMode : LTOMode;
566   }
567 
568 private:
569 
570   /// Tries to load options from configuration file.
571   ///
572   /// \returns true if error occurred.
573   bool loadConfigFile();
574 
575   /// Read options from the specified file.
576   ///
577   /// \param [in] FileName File to read.
578   /// \returns true, if error occurred while reading.
579   bool readConfigFile(StringRef FileName);
580 
581   /// Set the driver mode (cl, gcc, etc) from the value of the `--driver-mode`
582   /// option.
583   void setDriverMode(StringRef DriverModeValue);
584 
585   /// Parse the \p Args list for LTO options and record the type of LTO
586   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
587   void setLTOMode(const llvm::opt::ArgList &Args);
588 
589   /// Retrieves a ToolChain for a particular \p Target triple.
590   ///
591   /// Will cache ToolChains for the life of the driver object, and create them
592   /// on-demand.
593   const ToolChain &getToolChain(const llvm::opt::ArgList &Args,
594                                 const llvm::Triple &Target) const;
595 
596   /// @}
597 
598   /// Get bitmasks for which option flags to include and exclude based on
599   /// the driver mode.
600   std::pair<unsigned, unsigned> getIncludeExcludeOptionFlagMasks(bool IsClCompatMode) const;
601 
602   /// Helper used in BuildJobsForAction.  Doesn't use the cache when building
603   /// jobs specifically for the given action, but will use the cache when
604   /// building jobs for the Action's inputs.
605   InputInfo BuildJobsForActionNoCache(
606       Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
607       bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
608       std::map<std::pair<const Action *, std::string>, InputInfo>
609           &CachedResults,
610       Action::OffloadKind TargetDeviceOffloadKind) const;
611 
612 public:
613   /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
614   /// return the grouped values as integers. Numbers which are not
615   /// provided are set to 0.
616   ///
617   /// \return True if the entire string was parsed (9.2), or all
618   /// groups were parsed (10.3.5extrastuff). HadExtra is true if all
619   /// groups were parsed but extra characters remain at the end.
620   static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor,
621                                 unsigned &Micro, bool &HadExtra);
622 
623   /// Parse digits from a string \p Str and fulfill \p Digits with
624   /// the parsed numbers. This method assumes that the max number of
625   /// digits to look for is equal to Digits.size().
626   ///
627   /// \return True if the entire string was parsed and there are
628   /// no extra characters remaining at the end.
629   static bool GetReleaseVersion(StringRef Str,
630                                 MutableArrayRef<unsigned> Digits);
631   /// Compute the default -fmodule-cache-path.
632   /// \return True if the system provides a default cache directory.
633   static bool getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
634 };
635 
636 /// \return True if the last defined optimization level is -Ofast.
637 /// And False otherwise.
638 bool isOptimizationLevelFast(const llvm::opt::ArgList &Args);
639 
640 /// \return True if the argument combination will end up generating remarks.
641 bool willEmitRemarks(const llvm::opt::ArgList &Args);
642 
643 /// Returns the driver mode option's value, i.e. `X` in `--driver-mode=X`. If \p
644 /// Args doesn't mention one explicitly, tries to deduce from `ProgName`.
645 /// Returns empty on failure.
646 /// Common values are "gcc", "g++", "cpp", "cl" and "flang". Returned value need
647 /// not be one of these.
648 llvm::StringRef getDriverMode(StringRef ProgName, ArrayRef<const char *> Args);
649 
650 /// Checks whether the value produced by getDriverMode is for CL mode.
651 bool IsClangCL(StringRef DriverMode);
652 
653 } // end namespace driver
654 } // end namespace clang
655 
656 #endif
657