clang  19.0.0git
Driver.h
Go to the documentation of this file.
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"
14 #include "clang/Basic/LLVM.h"
15 #include "clang/Driver/Action.h"
17 #include "clang/Driver/InputInfo.h"
18 #include "clang/Driver/Options.h"
19 #include "clang/Driver/Phases.h"
20 #include "clang/Driver/ToolChain.h"
21 #include "clang/Driver/Types.h"
22 #include "clang/Driver/Util.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/STLFunctionalExtras.h"
25 #include "llvm/ADT/StringMap.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/Option/Arg.h"
28 #include "llvm/Option/ArgList.h"
29 #include "llvm/Support/StringSaver.h"
30 
31 #include <map>
32 #include <set>
33 #include <string>
34 #include <vector>
35 
36 namespace llvm {
37 class Triple;
38 namespace vfs {
39 class FileSystem;
40 }
41 namespace cl {
42 class ExpansionContext;
43 }
44 } // namespace llvm
45 
46 namespace clang {
47 
48 namespace driver {
49 
51 
52 class Command;
53 class Compilation;
54 class JobAction;
55 class ToolChain;
56 
57 /// Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
58 enum LTOKind {
63 };
64 
65 /// Whether headers used to construct C++20 module units should be looked
66 /// up by the path supplied on the command line, or in the user or system
67 /// search paths.
73 };
74 
75 /// Driver - Encapsulate logic for constructing compilation processes
76 /// from a set of gcc-driver-like command line arguments.
77 class Driver {
78  DiagnosticsEngine &Diags;
79 
81 
82  bool DumpDeviceCode;
83 
84  enum DriverMode {
85  GCCMode,
86  GXXMode,
87  CPPMode,
88  CLMode,
89  FlangMode,
90  DXCMode
91  } Mode;
92 
93  enum SaveTempsMode {
94  SaveTempsNone,
95  SaveTempsCwd,
96  SaveTempsObj
97  } SaveTemps;
98 
99  enum BitcodeEmbedMode {
100  EmbedNone,
101  EmbedMarker,
102  EmbedBitcode
103  } BitcodeEmbed;
104 
105  enum OffloadMode {
106  OffloadHostDevice,
107  OffloadHost,
108  OffloadDevice,
109  } Offload;
110 
111  /// Header unit mode set by -fmodule-header={user,system}.
112  ModuleHeaderMode CXX20HeaderType;
113 
114  /// Set if we should process inputs and jobs with C++20 module
115  /// interpretation.
116  bool ModulesModeCXX20;
117 
118  /// LTO mode selected via -f(no-)?lto(=.*)? options.
119  LTOKind LTOMode;
120 
121  /// LTO mode selected via -f(no-offload-)?lto(=.*)? options.
122  LTOKind OffloadLTOMode;
123 
124 public:
126  /// An unknown OpenMP runtime. We can't generate effective OpenMP code
127  /// without knowing what runtime to target.
129 
130  /// The LLVM OpenMP runtime. When completed and integrated, this will become
131  /// the default for Clang.
133 
134  /// The GNU OpenMP runtime. Clang doesn't support generating OpenMP code for
135  /// this runtime but can swallow the pragmas, and find and link against the
136  /// runtime library itself.
138 
139  /// The legacy name for the LLVM OpenMP runtime from when it was the Intel
140  /// OpenMP runtime. We support this mode for users with existing
141  /// dependencies on this runtime library name.
143  };
144 
145  // Diag - Forwarding function for diagnostics.
146  DiagnosticBuilder Diag(unsigned DiagID) const {
147  return Diags.Report(DiagID);
148  }
149 
150  // FIXME: Privatize once interface is stable.
151 public:
152  /// The name the driver was invoked as.
153  std::string Name;
154 
155  /// The path the driver executable was in, as invoked from the
156  /// command line.
157  std::string Dir;
158 
159  /// The original path to the clang executable.
160  std::string ClangExecutable;
161 
162  /// Target and driver mode components extracted from clang executable name.
164 
165  /// The path to the compiler resource directory.
166  std::string ResourceDir;
167 
168  /// System directory for config files.
169  std::string SystemConfigDir;
170 
171  /// User directory for config files.
172  std::string UserConfigDir;
173 
174  /// A prefix directory used to emulate a limited subset of GCC's '-Bprefix'
175  /// functionality.
176  /// FIXME: This type of customization should be removed in favor of the
177  /// universal driver when it is ready.
180 
181  /// sysroot, if present
182  std::string SysRoot;
183 
184  /// Dynamic loader prefix, if present
185  std::string DyldPrefix;
186 
187  /// Driver title to use with help.
188  std::string DriverTitle;
189 
190  /// Information about the host which can be overridden by the user.
192 
193  /// The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
195 
196  /// The file to log CC_PRINT_INTERNAL_STAT_FILE output to, if enabled.
198 
199  /// The file to log CC_PRINT_OPTIONS output to, if enabled.
201 
202  /// The file to log CC_PRINT_HEADERS output to, if enabled.
204 
205  /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
207 
208  /// An input type and its arguments.
209  using InputTy = std::pair<types::ID, const llvm::opt::Arg *>;
210 
211  /// A list of inputs and their types for the given arguments.
213 
214  /// Whether the driver should follow g++ like behavior.
215  bool CCCIsCXX() const { return Mode == GXXMode; }
216 
217  /// Whether the driver is just the preprocessor.
218  bool CCCIsCPP() const { return Mode == CPPMode; }
219 
220  /// Whether the driver should follow gcc like behavior.
221  bool CCCIsCC() const { return Mode == GCCMode; }
222 
223  /// Whether the driver should follow cl.exe like behavior.
224  bool IsCLMode() const { return Mode == CLMode; }
225 
226  /// Whether the driver should invoke flang for fortran inputs.
227  /// Other modes fall back to calling gcc which in turn calls gfortran.
228  bool IsFlangMode() const { return Mode == FlangMode; }
229 
230  /// Whether the driver should follow dxc.exe like behavior.
231  bool IsDXCMode() const { return Mode == DXCMode; }
232 
233  /// Only print tool bindings, don't build any jobs.
234  LLVM_PREFERRED_TYPE(bool)
236 
237  /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to
238  /// CCPrintOptionsFilename or to stderr.
239  LLVM_PREFERRED_TYPE(bool)
240  unsigned CCPrintOptions : 1;
241 
242  /// The format of the header information that is emitted. If CC_PRINT_HEADERS
243  /// is set, the format is textual. Otherwise, the format is determined by the
244  /// enviroment variable CC_PRINT_HEADERS_FORMAT.
246 
247  /// This flag determines whether clang should filter the header information
248  /// that is emitted. If enviroment variable CC_PRINT_HEADERS_FILTERING is set
249  /// to "only-direct-system", only system headers that are directly included
250  /// from non-system headers are emitted.
252 
253  /// Name of the library that provides implementations of
254  /// IEEE-754 128-bit float math functions used by Fortran F128
255  /// runtime library. It should be linked as needed by the linker job.
257 
258  /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics
259  /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable
260  /// format.
261  LLVM_PREFERRED_TYPE(bool)
262  unsigned CCLogDiagnostics : 1;
263 
264  /// Whether the driver is generating diagnostics for debugging purposes.
265  LLVM_PREFERRED_TYPE(bool)
266  unsigned CCGenDiagnostics : 1;
267 
268  /// Set CC_PRINT_PROC_STAT mode, which causes the driver to dump
269  /// performance report to CC_PRINT_PROC_STAT_FILE or to stdout.
270  LLVM_PREFERRED_TYPE(bool)
271  unsigned CCPrintProcessStats : 1;
272 
273  /// Set CC_PRINT_INTERNAL_STAT mode, which causes the driver to dump internal
274  /// performance report to CC_PRINT_INTERNAL_STAT_FILE or to stdout.
275  LLVM_PREFERRED_TYPE(bool)
276  unsigned CCPrintInternalStats : 1;
277 
278  /// Pointer to the ExecuteCC1Tool function, if available.
279  /// When the clangDriver lib is used through clang.exe, this provides a
280  /// shortcut for executing the -cc1 command-line directly, in the same
281  /// process.
282  using CC1ToolFunc =
283  llvm::function_ref<int(SmallVectorImpl<const char *> &ArgV)>;
284  CC1ToolFunc CC1Main = nullptr;
285 
286 private:
287  /// Raw target triple.
288  std::string TargetTriple;
289 
290  /// Name to use when invoking gcc/g++.
291  std::string CCCGenericGCCName;
292 
293  /// Paths to configuration files used.
294  std::vector<std::string> ConfigFiles;
295 
296  /// Allocator for string saver.
297  llvm::BumpPtrAllocator Alloc;
298 
299  /// Object that stores strings read from configuration file.
300  llvm::StringSaver Saver;
301 
302  /// Arguments originated from configuration file.
303  std::unique_ptr<llvm::opt::InputArgList> CfgOptions;
304 
305  /// Arguments originated from command line.
306  std::unique_ptr<llvm::opt::InputArgList> CLOptions;
307 
308  /// If this is non-null, the driver will prepend this argument before
309  /// reinvoking clang. This is useful for the llvm-driver where clang's
310  /// realpath will be to the llvm binary and not clang, so it must pass
311  /// "clang" as it's first argument.
312  const char *PrependArg;
313 
314  /// Whether to check that input files exist when constructing compilation
315  /// jobs.
316  LLVM_PREFERRED_TYPE(bool)
317  unsigned CheckInputsExist : 1;
318  /// Whether to probe for PCH files on disk, in order to upgrade
319  /// -include foo.h to -include-pch foo.h.pch.
320  LLVM_PREFERRED_TYPE(bool)
321  unsigned ProbePrecompiled : 1;
322 
323 public:
324  // getFinalPhase - Determine which compilation mode we are in and record
325  // which option we used to determine the final phase.
326  // TODO: Much of what getFinalPhase returns are not actually true compiler
327  // modes. Fold this functionality into Types::getCompilationPhases and
328  // handleArguments.
329  phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL,
330  llvm::opt::Arg **FinalPhaseArg = nullptr) const;
331 
332 private:
333  /// Certain options suppress the 'no input files' warning.
334  LLVM_PREFERRED_TYPE(bool)
335  unsigned SuppressMissingInputWarning : 1;
336 
337  /// Cache of all the ToolChains in use by the driver.
338  ///
339  /// This maps from the string representation of a triple to a ToolChain
340  /// created targeting that triple. The driver owns all the ToolChain objects
341  /// stored in it, and will clean them up when torn down.
342  mutable llvm::StringMap<std::unique_ptr<ToolChain>> ToolChains;
343 
344  /// Cache of known offloading architectures for the ToolChain already derived.
345  /// This should only be modified when we first initialize the offloading
346  /// toolchains.
347  llvm::DenseMap<const ToolChain *, llvm::DenseSet<llvm::StringRef>> KnownArchs;
348 
349 private:
350  /// TranslateInputArgs - Create a new derived argument list from the input
351  /// arguments, after applying the standard argument translations.
352  llvm::opt::DerivedArgList *
353  TranslateInputArgs(const llvm::opt::InputArgList &Args) const;
354 
355  // handleArguments - All code related to claiming and printing diagnostics
356  // related to arguments to the driver are done here.
357  void handleArguments(Compilation &C, llvm::opt::DerivedArgList &Args,
358  const InputList &Inputs, ActionList &Actions) const;
359 
360  // Before executing jobs, sets up response files for commands that need them.
361  void setUpResponseFiles(Compilation &C, Command &Cmd);
362 
363  void generatePrefixedToolNames(StringRef Tool, const ToolChain &TC,
364  SmallVectorImpl<std::string> &Names) const;
365 
366  /// Find the appropriate .crash diagonostic file for the child crash
367  /// under this driver and copy it out to a temporary destination with the
368  /// other reproducer related files (.sh, .cache, etc). If not found, suggest a
369  /// directory for the user to look at.
370  ///
371  /// \param ReproCrashFilename The file path to copy the .crash to.
372  /// \param CrashDiagDir The suggested directory for the user to look at
373  /// in case the search or copy fails.
374  ///
375  /// \returns If the .crash is found and successfully copied return true,
376  /// otherwise false and return the suggested directory in \p CrashDiagDir.
377  bool getCrashDiagnosticFile(StringRef ReproCrashFilename,
378  SmallString<128> &CrashDiagDir);
379 
380 public:
381 
382  /// Takes the path to a binary that's either in bin/ or lib/ and returns
383  /// the path to clang's resource directory.
384  static std::string GetResourcesPath(StringRef BinaryPath,
385  StringRef CustomResourceDir = "");
386 
387  Driver(StringRef ClangExecutable, StringRef TargetTriple,
388  DiagnosticsEngine &Diags, std::string Title = "clang LLVM compiler",
389  IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
390 
391  /// @name Accessors
392  /// @{
393 
394  /// Name to use when invoking gcc/g++.
395  const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; }
396 
398  return ConfigFiles;
399  }
400 
401  const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); }
402 
403  DiagnosticsEngine &getDiags() const { return Diags; }
404 
405  llvm::vfs::FileSystem &getVFS() const { return *VFS; }
406 
407  bool getCheckInputsExist() const { return CheckInputsExist; }
408 
409  void setCheckInputsExist(bool Value) { CheckInputsExist = Value; }
410 
411  bool getProbePrecompiled() const { return ProbePrecompiled; }
412  void setProbePrecompiled(bool Value) { ProbePrecompiled = Value; }
413 
414  const char *getPrependArg() const { return PrependArg; }
415  void setPrependArg(const char *Value) { PrependArg = Value; }
416 
418 
419  const std::string &getTitle() { return DriverTitle; }
420  void setTitle(std::string Value) { DriverTitle = std::move(Value); }
421 
422  std::string getTargetTriple() const { return TargetTriple; }
423 
424  /// Get the path to the main clang executable.
425  const char *getClangProgramPath() const {
426  return ClangExecutable.c_str();
427  }
428 
429  bool isDumpDeviceCodeEnabled() const { return DumpDeviceCode; }
430 
431  bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
432  bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
433 
434  bool embedBitcodeEnabled() const { return BitcodeEmbed != EmbedNone; }
435  bool embedBitcodeInObject() const { return (BitcodeEmbed == EmbedBitcode); }
436  bool embedBitcodeMarkerOnly() const { return (BitcodeEmbed == EmbedMarker); }
437 
438  bool offloadHostOnly() const { return Offload == OffloadHost; }
439  bool offloadDeviceOnly() const { return Offload == OffloadDevice; }
440 
441  void setFlangF128MathLibrary(std::string name) {
442  FlangF128MathLibrary = std::move(name);
443  }
444  StringRef getFlangF128MathLibrary() const { return FlangF128MathLibrary; }
445 
446  /// Compute the desired OpenMP runtime from the flags provided.
447  OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const;
448 
449  /// @}
450  /// @name Primary Functionality
451  /// @{
452 
453  /// CreateOffloadingDeviceToolChains - create all the toolchains required to
454  /// support offloading devices given the programming models specified in the
455  /// current compilation. Also, update the host tool chain kind accordingly.
457 
458  /// BuildCompilation - Construct a compilation object for a command
459  /// line argument vector.
460  ///
461  /// \return A compilation, or 0 if none was built for the given
462  /// argument vector. A null return value does not necessarily
463  /// indicate an error condition, the diagnostics should be queried
464  /// to determine if an error occurred.
466 
467  /// ParseArgStrings - Parse the given list of strings into an
468  /// ArgList.
469  llvm::opt::InputArgList ParseArgStrings(ArrayRef<const char *> Args,
470  bool UseDriverMode,
471  bool &ContainsError);
472 
473  /// BuildInputs - Construct the list of inputs and their types from
474  /// the given arguments.
475  ///
476  /// \param TC - The default host tool chain.
477  /// \param Args - The input arguments.
478  /// \param Inputs - The list to store the resulting compilation
479  /// inputs onto.
480  void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args,
481  InputList &Inputs) const;
482 
483  /// BuildActions - Construct the list of actions to perform for the
484  /// given arguments, which are only done for a single architecture.
485  ///
486  /// \param C - The compilation that is being built.
487  /// \param Args - The input arguments.
488  /// \param Actions - The list to store the resulting actions onto.
489  void BuildActions(Compilation &C, llvm::opt::DerivedArgList &Args,
490  const InputList &Inputs, ActionList &Actions) const;
491 
492  /// BuildUniversalActions - Construct the list of actions to perform
493  /// for the given arguments, which may require a universal build.
494  ///
495  /// \param C - The compilation that is being built.
496  /// \param TC - The default host tool chain.
497  void BuildUniversalActions(Compilation &C, const ToolChain &TC,
498  const InputList &BAInputs) const;
499 
500  /// BuildOffloadingActions - Construct the list of actions to perform for the
501  /// offloading toolchain that will be embedded in the host.
502  ///
503  /// \param C - The compilation that is being built.
504  /// \param Args - The input arguments.
505  /// \param Input - The input type and arguments
506  /// \param HostAction - The host action used in the offloading toolchain.
508  llvm::opt::DerivedArgList &Args,
509  const InputTy &Input,
510  Action *HostAction) const;
511 
512  /// Returns the set of bound architectures active for this offload kind.
513  /// If there are no bound architctures we return a set containing only the
514  /// empty string. The \p SuppressError option is used to suppress errors.
516  getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
518  bool SuppressError = false) const;
519 
520  /// Check that the file referenced by Value exists. If it doesn't,
521  /// issue a diagnostic and return false.
522  /// If TypoCorrect is true and the file does not exist, see if it looks
523  /// like a likely typo for a flag and if so print a "did you mean" blurb.
524  bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args,
525  StringRef Value, types::ID Ty,
526  bool TypoCorrect) const;
527 
528  /// BuildJobs - Bind actions to concrete tools and translate
529  /// arguments to form the list of jobs to run.
530  ///
531  /// \param C - The compilation that is being built.
532  void BuildJobs(Compilation &C) const;
533 
534  /// ExecuteCompilation - Execute the compilation according to the command line
535  /// arguments and return an appropriate exit code.
536  ///
537  /// This routine handles additional processing that must be done in addition
538  /// to just running the subprocesses, for example reporting errors, setting
539  /// up response files, removing temporary files, etc.
541  SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands);
542 
543  /// Contains the files in the compilation diagnostic report generated by
544  /// generateCompilationDiagnostics.
547  };
548 
549  /// generateCompilationDiagnostics - Generate diagnostics information
550  /// including preprocessed source file(s).
551  ///
553  Compilation &C, const Command &FailingCommand,
554  StringRef AdditionalInformation = "",
555  CompilationDiagnosticReport *GeneratedReport = nullptr);
556 
557  enum class CommandStatus {
558  Crash = 1,
559  Error,
560  Ok,
561  };
562 
563  enum class ReproLevel {
564  Off = 0,
565  OnCrash = static_cast<int>(CommandStatus::Crash),
566  OnError = static_cast<int>(CommandStatus::Error),
567  Always = static_cast<int>(CommandStatus::Ok),
568  };
569 
572  const Command &FailingCommand, StringRef AdditionalInformation = "",
573  CompilationDiagnosticReport *GeneratedReport = nullptr) {
574  if (static_cast<int>(CS) > static_cast<int>(Level))
575  return false;
576  if (CS != CommandStatus::Crash)
577  Diags.Report(diag::err_drv_force_crash)
578  << !::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH");
579  // Hack to ensure that diagnostic notes get emitted.
580  Diags.setLastDiagnosticIgnored(false);
581  generateCompilationDiagnostics(C, FailingCommand, AdditionalInformation,
582  GeneratedReport);
583  return true;
584  }
585 
586  /// @}
587  /// @name Helper Methods
588  /// @{
589 
590  /// MakeSYCLDeviceTriple - Returns the SYCL device triple for the
591  /// specified subarch
592  llvm::Triple MakeSYCLDeviceTriple(StringRef TargetArch = "spir64") const;
593 
594  /// PrintActions - Print the list of actions.
595  void PrintActions(const Compilation &C) const;
596 
597  /// PrintHelp - Print the help text.
598  ///
599  /// \param ShowHidden - Show hidden options.
600  void PrintHelp(bool ShowHidden) const;
601 
602  /// PrintSYCLToolHelp - Print help text from offline compiler tools.
603  void PrintSYCLToolHelp(const Compilation &C) const;
604 
605  /// PrintVersion - Print the driver version.
606  void PrintVersion(const Compilation &C, raw_ostream &OS) const;
607 
608  /// GetFilePath - Lookup \p Name in the list of file search paths.
609  ///
610  /// \param TC - The tool chain for additional information on
611  /// directories to search.
612  //
613  // FIXME: This should be in CompilationInfo.
614  std::string GetFilePath(StringRef Name, const ToolChain &TC) const;
615 
616  /// GetProgramPath - Lookup \p Name in the list of program search paths.
617  ///
618  /// \param TC - The provided tool chain for additional information on
619  /// directories to search.
620  //
621  // FIXME: This should be in CompilationInfo.
622  std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
623 
624  /// Lookup the path to the Standard library module manifest.
625  ///
626  /// \param C - The compilation.
627  /// \param TC - The tool chain for additional information on
628  /// directories to search.
629  //
630  // FIXME: This should be in CompilationInfo.
631  std::string GetStdModuleManifestPath(const Compilation &C,
632  const ToolChain &TC) const;
633 
634  /// HandleAutocompletions - Handle --autocomplete by searching and printing
635  /// possible flags, descriptions, and its arguments.
636  void HandleAutocompletions(StringRef PassedFlags) const;
637 
638  /// HandleImmediateArgs - Handle any arguments which should be
639  /// treated before building actions or binding tools.
640  ///
641  /// \return Whether any compilation should be built for this
642  /// invocation.
643  bool HandleImmediateArgs(const Compilation &C);
644 
645  /// ConstructAction - Construct the appropriate action to do for
646  /// \p Phase on the \p Input, taking in to account arguments
647  /// like -fsyntax-only or --analyze.
649  Compilation &C, const llvm::opt::ArgList &Args, phases::ID Phase,
650  Action *Input,
651  Action::OffloadKind TargetDeviceOffloadKind = Action::OFK_None) const;
652 
653  /// BuildJobsForAction - Construct the jobs to perform for the action \p A and
654  /// return an InputInfo for the result of running \p A. Will only construct
655  /// jobs for a given (Action, ToolChain, BoundArch, DeviceKind) tuple once.
657  Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
658  bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
659  std::map<std::pair<const Action *, std::string>, InputInfoList>
660  &CachedResults,
661  Action::OffloadKind TargetDeviceOffloadKind) const;
662 
663  /// Returns the default name for linked images (e.g., "a.out").
664  const char *getDefaultImageName() const;
665 
666  /// Creates a temp file.
667  /// 1. If \p MultipleArch is false or \p BoundArch is empty, the temp file is
668  /// in the temporary directory with name $Prefix-%%%%%%.$Suffix.
669  /// 2. If \p MultipleArch is true and \p BoundArch is not empty,
670  /// 2a. If \p NeedUniqueDirectory is false, the temp file is in the
671  /// temporary directory with name $Prefix-$BoundArch-%%%%%.$Suffix.
672  /// 2b. If \p NeedUniqueDirectory is true, the temp file is in a unique
673  /// subdiretory with random name under the temporary directory, and
674  /// the temp file itself has name $Prefix-$BoundArch.$Suffix.
675  const char *CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix,
676  bool MultipleArchs = false,
677  StringRef BoundArch = {},
678  types::ID Type = types::TY_Nothing,
679  bool NeedUniqueDirectory = false) const;
680 
681  /// GetNamedOutputPath - Return the name to use for the output of
682  /// the action \p JA. The result is appended to the compilation's
683  /// list of temporary or result files, as appropriate.
684  ///
685  /// \param C - The compilation.
686  /// \param JA - The action of interest.
687  /// \param BaseInput - The original input file that this action was
688  /// triggered by.
689  /// \param BoundArch - The bound architecture.
690  /// \param AtTopLevel - Whether this is a "top-level" action.
691  /// \param MultipleArchs - Whether multiple -arch options were supplied.
692  /// \param NormalizedTriple - The normalized triple of the relevant target.
693  const char *GetNamedOutputPath(Compilation &C, const JobAction &JA,
694  const char *BaseInput, StringRef BoundArch,
695  bool AtTopLevel, bool MultipleArchs,
696  StringRef NormalizedTriple) const;
697 
698  /// GetTemporaryPath - Return the pathname of a temporary file to use
699  /// as part of compilation; the file will have the given prefix and suffix.
700  ///
701  /// GCC goes to extra lengths here to be a bit more robust.
702  std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const;
703 
704  /// GetUniquePath = Return the pathname of a unique file to use
705  /// as part of compilation. The file will have the given base name (BaseName)
706  /// and extension (Ext).
707  std::string GetUniquePath(StringRef BaseName, StringRef Ext) const;
708 
709  /// GetTemporaryDirectory - Return the pathname of a temporary directory to
710  /// use as part of compilation; the directory will have the given prefix.
711  std::string GetTemporaryDirectory(StringRef Prefix) const;
712 
713  /// Return the pathname of the pch file in clang-cl mode.
714  std::string GetClPchPath(Compilation &C, StringRef BaseName) const;
715 
716  /// ShouldUseClangCompiler - Should the clang compiler be used to
717  /// handle this action.
718  bool ShouldUseClangCompiler(const JobAction &JA) const;
719 
720  /// ShouldUseFlangCompiler - Should the flang compiler be used to
721  /// handle this action.
722  bool ShouldUseFlangCompiler(const JobAction &JA) const;
723 
724  /// ShouldEmitStaticLibrary - Should the linker emit a static library.
725  bool ShouldEmitStaticLibrary(const llvm::opt::ArgList &Args) const;
726 
727  /// Returns true if the user has indicated a C++20 header unit mode.
728  bool hasHeaderMode() const { return CXX20HeaderType != HeaderMode_None; }
729 
730  /// Get the mode for handling headers as set by fmodule-header{=}.
731  ModuleHeaderMode getModuleHeaderMode() const { return CXX20HeaderType; }
732 
733  /// Returns true if we are performing any kind of LTO.
734  bool isUsingLTO(bool IsOffload = false) const {
735  return getLTOMode(IsOffload) != LTOK_None;
736  }
737 
738  /// Get the specific kind of LTO being performed.
739  LTOKind getLTOMode(bool IsOffload = false) const {
740  return IsOffload ? OffloadLTOMode : LTOMode;
741  }
742 
743  // FPGA Offload Modes.
744  enum DeviceMode {
749 
750  bool IsFPGAHWMode() const { return OffloadCompileMode == FPGAHWMode; }
751 
752  bool IsFPGAEmulationMode() const {
754  }
755 
757  OffloadCompileMode = ModeValue;
758  }
759 
761 
762 private:
763 
764  /// Tries to load options from configuration files.
765  ///
766  /// \returns true if error occurred.
767  bool loadConfigFiles();
768 
769  /// Tries to load options from default configuration files (deduced from
770  /// executable filename).
771  ///
772  /// \returns true if error occurred.
773  bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
774 
775  /// Read options from the specified file.
776  ///
777  /// \param [in] FileName File to read.
778  /// \param [in] Search and expansion options.
779  /// \returns true, if error occurred while reading.
780  bool readConfigFile(StringRef FileName, llvm::cl::ExpansionContext &ExpCtx);
781 
782  /// Set the driver mode (cl, gcc, etc) from the value of the `--driver-mode`
783  /// option.
784  void setDriverMode(StringRef DriverModeValue);
785 
786  /// Set the resource directory, depending on which driver is being used.
787  void setResourceDirectory();
788 
789  /// Parse the \p Args list for LTO options and record the type of LTO
790  /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
791  void setLTOMode(const llvm::opt::ArgList &Args);
792 
793  /// Retrieves a ToolChain for a particular \p Target triple.
794  ///
795  /// Will cache ToolChains for the life of the driver object, and create them
796  /// on-demand.
797  const ToolChain &getToolChain(const llvm::opt::ArgList &Args,
798  const llvm::Triple &Target) const;
799 
800  /// @}
801 
802  /// Retrieves a ToolChain for a particular device \p Target triple
803  ///
804  /// \param[in] HostTC is the host ToolChain paired with the device
805  ///
806  /// \param[in] TargetDeviceOffloadKind (e.g. OFK_Cuda/OFK_OpenMP/OFK_SYCL) is
807  /// an Offloading action that is optionally passed to a ToolChain (used by
808  /// CUDA, to specify if it's used in conjunction with OpenMP)
809  ///
810  /// Will cache ToolChains for the life of the driver object, and create them
811  /// on-demand.
812  const ToolChain &getOffloadingDeviceToolChain(
813  const llvm::opt::ArgList &Args, const llvm::Triple &Target,
814  const ToolChain &HostTC,
815  const Action::OffloadKind &TargetDeviceOffloadKind) const;
816 
817  /// Get bitmasks for which option flags to include and exclude based on
818  /// the driver mode.
820  getOptionVisibilityMask(bool UseDriverMode = true) const;
821 
822  /// Helper used in BuildJobsForAction. Doesn't use the cache when building
823  /// jobs specifically for the given action, but will use the cache when
824  /// building jobs for the Action's inputs.
825  InputInfoList BuildJobsForActionNoCache(
826  Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
827  bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
828  std::map<std::pair<const Action *, std::string>, InputInfoList>
829  &CachedResults,
830  Action::OffloadKind TargetDeviceOffloadKind) const;
831 
832  /// Static offload library seen.
833  bool OffloadStaticLibSeen = false;
834 
835  void setOffloadStaticLibSeen() { OffloadStaticLibSeen = true; }
836 
837  /// Use the new offload driver for OpenMP
838  bool UseNewOffloadingDriver = false;
839  void setUseNewOffloadingDriver() { UseNewOffloadingDriver = true; }
840 
841  /// The inclusion of the default SYCL device triple is dependent on either
842  /// the discovery of an existing object/archive that contains the device code
843  /// or if a user explicitly turns this on with -fsycl-add-spirv.
844  /// We need to keep track of this so any use of any generic target option
845  /// setting is only applied to the user specified triples.
846  bool SYCLDefaultTripleImplied = false;
847  void setSYCLDefaultTriple(bool IsDefaultImplied) {
848  SYCLDefaultTripleImplied = IsDefaultImplied;
849  }
850 
851  /// Returns true if an offload binary is found that contains the default
852  /// triple for SYCL (spir64)
853  bool checkForSYCLDefaultDevice(Compilation &C,
854  llvm::opt::DerivedArgList &Args) const;
855 
856  /// Returns true if an offload static library is found.
857  bool checkForOffloadStaticLib(Compilation &C,
858  llvm::opt::DerivedArgList &Args) const;
859 
860  /// Checks for any mismatch of targets and provided input binaries.
861  void checkForOffloadMismatch(Compilation &C,
862  llvm::opt::DerivedArgList &Args) const;
863 
864  /// Track filename used for the FPGA dependency info.
865  mutable llvm::StringMap<const std::string> FPGATempDepFiles;
866 
867  /// A list of inputs and their corresponding integration headers. These
868  /// files are generated during the device compilation and are consumed
869  /// by the host compilation.
870  mutable llvm::StringMap<const std::pair<StringRef, StringRef>>
871  IntegrationFileList;
872 
873  /// Unique ID used for SYCL compilations. Each file will use a different
874  /// unique ID, but the same ID will be used for different compilation
875  /// targets.
876  mutable llvm::StringMap<StringRef> SYCLUniqueIDList;
877 
878  /// Vector of Macros that need to be added to the Host compilation in a
879  /// SYCL based offloading scenario. These macros are gathered during
880  /// construction of the device compilations.
881  mutable std::vector<std::string> SYCLTargetMacroArgs;
882 
883  /// Vector of Macros related to Device Traits that need to be added to the
884  /// device compilation in a SYCL based offloading scenario. These macros are
885  /// gathered during creation of offloading device toolchains.
886  mutable llvm::opt::ArgStringList SYCLDeviceTraitsMacrosArgs;
887 
888  /// Return the typical executable name for the specified driver \p Mode.
889  static const char *getExecutableForDriverMode(DriverMode Mode);
890 
891 public:
892  /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
893  /// return the grouped values as integers. Numbers which are not
894  /// provided are set to 0.
895  ///
896  /// \return True if the entire string was parsed (9.2), or all
897  /// groups were parsed (10.3.5extrastuff). HadExtra is true if all
898  /// groups were parsed but extra characters remain at the end.
899  static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor,
900  unsigned &Micro, bool &HadExtra);
901 
902  /// Parse digits from a string \p Str and fulfill \p Digits with
903  /// the parsed numbers. This method assumes that the max number of
904  /// digits to look for is equal to Digits.size().
905  ///
906  /// \return True if the entire string was parsed and there are
907  /// no extra characters remaining at the end.
908  static bool GetReleaseVersion(StringRef Str,
909  MutableArrayRef<unsigned> Digits);
910  /// Compute the default -fmodule-cache-path.
911  /// \return True if the system provides a default cache directory.
912  static bool getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
913 
914  bool getOffloadStaticLibSeen() const { return OffloadStaticLibSeen; };
915 
916  /// getUseNewOffloadingDriver - use the new offload driver for OpenMP.
917  bool getUseNewOffloadingDriver() const { return UseNewOffloadingDriver; };
918 
919  /// addFPGATempDepFile - Add a file to be added to the bundling step of
920  /// an FPGA object.
921  void addFPGATempDepFile(const std::string &DepName,
922  const std::string &FileName) const {
923  FPGATempDepFiles.insert({FileName, DepName});
924  }
925  /// getFPGATempDepFile - Get a file to be added to the bundling step of
926  /// an FPGA object.
927  const std::string getFPGATempDepFile(const std::string &FileName) const {
928  return FPGATempDepFiles[FileName];
929  }
930 
931  /// isSYCLDefaultTripleImplied - The default SYCL triple (spir64) has been
932  /// added or should be added given proper criteria.
933  bool isSYCLDefaultTripleImplied() const { return SYCLDefaultTripleImplied; };
934 
935  /// addIntegrationFiles - Add the integration files that will be populated
936  /// by the device compilation and used by the host compile.
937  void addIntegrationFiles(StringRef IntHeaderName, StringRef IntFooterName,
938  StringRef FileName) const {
939  IntegrationFileList.insert(
940  {FileName, std::make_pair(IntHeaderName, IntFooterName)});
941  }
942  /// getIntegrationHeader - Get the integration header file
943  StringRef getIntegrationHeader(StringRef FileName) const {
944  return IntegrationFileList[FileName].first;
945  }
946  /// getIntegrationFooter - Get the integration footer file
947  StringRef getIntegrationFooter(StringRef FileName) const {
948  return IntegrationFileList[FileName].second;
949  }
950  /// createAppendedFooterInput - Create new source file.
952  const llvm::opt::ArgList &Args) const;
953 
954  /// addSYCLTargetMacroArg - Add the given macro to the vector of args to be
955  /// added to the host compilation step.
956  void addSYCLTargetMacroArg(const llvm::opt::ArgList &Args,
957  StringRef Macro) const {
958  SYCLTargetMacroArgs.push_back(Args.MakeArgString(Macro));
959  }
960  /// getSYCLTargetMacroArgs - return the previously gathered macro target args.
962  return SYCLTargetMacroArgs;
963  }
964 
965  /// setSYCLUniqueID - set the Unique ID that is used for all FE invocations
966  /// when performing compilations for SYCL.
967  void addSYCLUniqueID(StringRef UniqueID, StringRef FileName) const {
968  SYCLUniqueIDList.insert({FileName, UniqueID});
969  }
970  /// getSYCLUniqueID - Get the Unique ID associated with the file.
971  StringRef getSYCLUniqueID(StringRef FileName) const {
972  return SYCLUniqueIDList[FileName];
973  }
974 
975  /// SYCLDeviceTraitMacroArg - Add the given macro to the vector of args to be
976  /// added to the device compilation step.
977  void addSYCLDeviceTraitsMacroArg(const llvm::opt::ArgList &Args,
978  StringRef Macro) const {
979  SYCLDeviceTraitsMacrosArgs.push_back(Args.MakeArgString(Macro));
980  }
981  llvm::opt::ArgStringList getDeviceTraitsMacrosArgs() const {
982  return SYCLDeviceTraitsMacrosArgs;
983  }
984 };
985 
986 /// \return True if the last defined optimization level is -Ofast.
987 /// And False otherwise.
988 bool isOptimizationLevelFast(const llvm::opt::ArgList &Args);
989 
990 /// \return True if the filename has a valid object file extension.
991 bool isObjectFile(std::string FileName);
992 
993 /// \return True if the filename has a static archive/lib extension.
994 bool isStaticArchiveFile(const StringRef &FileName);
995 
996 /// \return True if the argument combination will end up generating remarks.
997 bool willEmitRemarks(const llvm::opt::ArgList &Args);
998 
999 /// Returns the driver mode option's value, i.e. `X` in `--driver-mode=X`. If \p
1000 /// Args doesn't mention one explicitly, tries to deduce from `ProgName`.
1001 /// Returns empty on failure.
1002 /// Common values are "gcc", "g++", "cpp", "cl" and "flang". Returned value need
1003 /// not be one of these.
1004 llvm::StringRef getDriverMode(StringRef ProgName, ArrayRef<const char *> Args);
1005 
1006 /// Checks whether the value produced by getDriverMode is for CL mode.
1007 bool IsClangCL(StringRef DriverMode);
1008 
1009 /// Expand response files from a clang driver or cc1 invocation.
1010 ///
1011 /// \param Args The arguments that will be expanded.
1012 /// \param ClangCLMode Whether clang is in CL mode.
1013 /// \param Alloc Allocator for new arguments.
1014 /// \param FS Filesystem to use when expanding files.
1016  bool ClangCLMode, llvm::BumpPtrAllocator &Alloc,
1017  llvm::vfs::FileSystem *FS = nullptr);
1018 
1019 /// Apply a space separated list of edits to the input argument lists.
1020 /// See applyOneOverrideOption.
1022  const char *OverrideOpts,
1023  llvm::StringSet<> &SavedStrings,
1024  raw_ostream *OS = nullptr);
1025 
1026 } // end namespace driver
1027 } // end namespace clang
1028 
1029 #endif
static char ID
Definition: Arena.cpp:183
Defines the Diagnostic-related interfaces.
Defines enums used when emitting included header information.
CompileCommand Cmd
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Target Target
Definition: MachO.h:50
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1277
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:193
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1553
void setLastDiagnosticIgnored(bool Ignored)
Pretend that the last diagnostic issued was ignored, so any subsequent notes will be suppressed,...
Definition: Diagnostic.h:767
The base class of the type hierarchy.
Definition: Type.h:1813
Action - Represent an abstract compilation step to perform.
Definition: Action.h:49
Command - An executable path/name and argument vector to execute.
Definition: Job.h:107
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
llvm::Triple MakeSYCLDeviceTriple(StringRef TargetArch="spir64") const
MakeSYCLDeviceTriple - Returns the SYCL device triple for the specified subarch.
Definition: Driver.cpp:2408
std::string SysRoot
sysroot, if present
Definition: Driver.h:182
std::string CCPrintInternalStatReportFilename
The file to log CC_PRINT_INTERNAL_STAT_FILE output to, if enabled.
Definition: Driver.h:197
SmallVector< InputTy, 16 > InputList
A list of inputs and their types for the given arguments.
Definition: Driver.h:212
std::string UserConfigDir
User directory for config files.
Definition: Driver.h:172
void addSYCLDeviceTraitsMacroArg(const llvm::opt::ArgList &Args, StringRef Macro) const
SYCLDeviceTraitMacroArg - Add the given macro to the vector of args to be added to the device compila...
Definition: Driver.h:977
Action * ConstructPhaseAction(Compilation &C, const llvm::opt::ArgList &Args, phases::ID Phase, Action *Input, Action::OffloadKind TargetDeviceOffloadKind=Action::OFK_None) const
ConstructAction - Construct the appropriate action to do for Phase on the Input, taking in to account...
Definition: Driver.cpp:8060
std::string HostRelease
Definition: Driver.h:191
void BuildUniversalActions(Compilation &C, const ToolChain &TC, const InputList &BAInputs) const
BuildUniversalActions - Construct the list of actions to perform for the given arguments,...
Definition: Driver.cpp:2927
const char * CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix, bool MultipleArchs=false, StringRef BoundArch={}, types::ID Type=types::TY_Nothing, bool NeedUniqueDirectory=false) const
Creates a temp file.
Definition: Driver.cpp:9377
Action * BuildOffloadingActions(Compilation &C, llvm::opt::DerivedArgList &Args, const InputTy &Input, Action *HostAction) const
BuildOffloadingActions - Construct the list of actions to perform for the offloading toolchain that w...
Definition: Driver.cpp:7873
void PrintHelp(bool ShowHidden) const
PrintHelp - Print the help text.
Definition: Driver.cpp:2399
bool offloadDeviceOnly() const
Definition: Driver.h:439
void addSYCLTargetMacroArg(const llvm::opt::ArgList &Args, StringRef Macro) const
addSYCLTargetMacroArg - Add the given macro to the vector of args to be added to the host compilation...
Definition: Driver.h:956
const std::string & getCCCGenericGCCName() const
Name to use when invoking gcc/g++.
Definition: Driver.h:395
bool isSaveTempsEnabled() const
Definition: Driver.h:431
llvm::DenseSet< StringRef > getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args, Action::OffloadKind Kind, const ToolChain *TC, bool SuppressError=false) const
Returns the set of bound architectures active for this offload kind.
Definition: Driver.cpp:7769
void BuildJobs(Compilation &C) const
BuildJobs - Bind actions to concrete tools and translate arguments to form the list of jobs to run.
Definition: Driver.cpp:8224
InputInfoList BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch, bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput, std::map< std::pair< const Action *, std::string >, InputInfoList > &CachedResults, Action::OffloadKind TargetDeviceOffloadKind) const
BuildJobsForAction - Construct the jobs to perform for the action A and return an InputInfo for the r...
Definition: Driver.cpp:8782
StringRef getIntegrationFooter(StringRef FileName) const
getIntegrationFooter - Get the integration footer file
Definition: Driver.h:947
std::string GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
Definition: Driver.cpp:9776
void PrintSYCLToolHelp(const Compilation &C) const
PrintSYCLToolHelp - Print help text from offline compiler tools.
Definition: Driver.cpp:2425
void setCheckInputsExist(bool Value)
Definition: Driver.h:409
unsigned CCPrintProcessStats
Set CC_PRINT_PROC_STAT mode, which causes the driver to dump performance report to CC_PRINT_PROC_STAT...
Definition: Driver.h:271
const char * getPrependArg() const
Definition: Driver.h:414
void PrintActions(const Compilation &C) const
PrintActions - Print the list of actions.
Definition: Driver.cpp:2911
const char * GetNamedOutputPath(Compilation &C, const JobAction &JA, const char *BaseInput, StringRef BoundArch, bool AtTopLevel, bool MultipleArchs, StringRef NormalizedTriple) const
GetNamedOutputPath - Return the name to use for the output of the action JA.
Definition: Driver.cpp:9440
void setFlangF128MathLibrary(std::string name)
Definition: Driver.h:441
std::string CCPrintOptionsFilename
The file to log CC_PRINT_OPTIONS output to, if enabled.
Definition: Driver.h:200
CC1ToolFunc CC1Main
Definition: Driver.h:284
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:405
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
Definition: Driver.cpp:791
std::string GetTemporaryDirectory(StringRef Prefix) const
GetTemporaryDirectory - Return the pathname of a temporary directory to use as part of compilation; t...
Definition: Driver.cpp:9946
bool IsDXCMode() const
Whether the driver should follow dxc.exe like behavior.
Definition: Driver.h:231
const char * getDefaultImageName() const
Returns the default name for linked images (e.g., "a.out").
Definition: Driver.cpp:9328
bool IsCLMode() const
Whether the driver should follow cl.exe like behavior.
Definition: Driver.h:224
std::string DyldPrefix
Dynamic loader prefix, if present.
Definition: Driver.h:185
void addFPGATempDepFile(const std::string &DepName, const std::string &FileName) const
addFPGATempDepFile - Add a file to be added to the bundling step of an FPGA object.
Definition: Driver.h:921
bool ShouldEmitStaticLibrary(const llvm::opt::ArgList &Args) const
ShouldEmitStaticLibrary - Should the linker emit a static library.
Definition: Driver.cpp:10263
std::string DriverTitle
Driver title to use with help.
Definition: Driver.h:188
unsigned CCCPrintBindings
Only print tool bindings, don't build any jobs.
Definition: Driver.h:235
unsigned CCLogDiagnostics
Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics to CCLogDiagnosticsFilename...
Definition: Driver.h:262
StringRef getSYCLUniqueID(StringRef FileName) const
getSYCLUniqueID - Get the Unique ID associated with the file.
Definition: Driver.h:971
void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args, InputList &Inputs) const
BuildInputs - Construct the list of inputs and their types from the given arguments.
Definition: Driver.cpp:3106
static bool getDefaultModuleCachePath(SmallVectorImpl< char > &Result)
Compute the default -fmodule-cache-path.
Definition: Clang.cpp:3950
unsigned CCGenDiagnostics
Whether the driver is generating diagnostics for debugging purposes.
Definition: Driver.h:266
llvm::ArrayRef< std::string > getSYCLTargetMacroArgs() const
getSYCLTargetMacroArgs - return the previously gathered macro target args.
Definition: Driver.h:961
void addIntegrationFiles(StringRef IntHeaderName, StringRef IntFooterName, StringRef FileName) const
addIntegrationFiles - Add the integration files that will be populated by the device compilation and ...
Definition: Driver.h:937
int ExecuteCompilation(Compilation &C, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands)
ExecuteCompilation - Execute the compilation according to the command line arguments and return an ap...
Definition: Driver.cpp:2313
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:146
std::string SystemConfigDir
System directory for config files.
Definition: Driver.h:169
ParsedClangName ClangNameParts
Target and driver mode components extracted from clang executable name.
Definition: Driver.h:163
unsigned CCPrintInternalStats
Set CC_PRINT_INTERNAL_STAT mode, which causes the driver to dump internal performance report to CC_PR...
Definition: Driver.h:276
static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)
GetReleaseVersion - Parse (([0-9]+)(.
Definition: Driver.cpp:10275
bool isSYCLDefaultTripleImplied() const
isSYCLDefaultTripleImplied - The default SYCL triple (spir64) has been added or should be added given...
Definition: Driver.h:933
std::string Name
The name the driver was invoked as.
Definition: Driver.h:153
bool getOffloadStaticLibSeen() const
Definition: Driver.h:914
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, llvm::opt::Arg **FinalPhaseArg=nullptr) const
Definition: Driver.cpp:370
const std::string & getTitle()
Definition: Driver.h:419
std::string GetClPchPath(Compilation &C, StringRef BaseName) const
Return the pathname of the pch file in clang-cl mode.
Definition: Driver.cpp:9957
std::string ClangExecutable
The original path to the clang executable.
Definition: Driver.h:160
StringRef getIntegrationHeader(StringRef FileName) const
getIntegrationHeader - Get the integration header file
Definition: Driver.h:943
void setPrependArg(const char *Value)
Definition: Driver.h:415
StringRef getFlangF128MathLibrary() const
Definition: Driver.h:444
llvm::ArrayRef< std::string > getConfigFiles() const
Definition: Driver.h:397
void BuildActions(Compilation &C, llvm::opt::DerivedArgList &Args, const InputList &Inputs, ActionList &Actions) const
BuildActions - Construct the list of actions to perform for the given arguments, which are only done ...
Definition: Driver.cpp:7284
bool offloadHostOnly() const
Definition: Driver.h:438
void addSYCLUniqueID(StringRef UniqueID, StringRef FileName) const
setSYCLUniqueID - set the Unique ID that is used for all FE invocations when performing compilations ...
Definition: Driver.h:967
ModuleHeaderMode getModuleHeaderMode() const
Get the mode for handling headers as set by fmodule-header{=}.
Definition: Driver.h:731
void generateCompilationDiagnostics(Compilation &C, const Command &FailingCommand, StringRef AdditionalInformation="", CompilationDiagnosticReport *GeneratedReport=nullptr)
generateCompilationDiagnostics - Generate diagnostics information including preprocessed source file(...
Definition: Driver.cpp:2067
bool hasHeaderMode() const
Returns true if the user has indicated a C++20 header unit mode.
Definition: Driver.h:728
SmallVector< std::string, 4 > prefix_list
A prefix directory used to emulate a limited subset of GCC's '-Bprefix' functionality.
Definition: Driver.h:178
void createAppendedFooterInput(Action *&Input, Compilation &C, const llvm::opt::ArgList &Args) const
createAppendedFooterInput - Create new source file.
void PrintVersion(const Compilation &C, raw_ostream &OS) const
PrintVersion - Print the driver version.
Definition: Driver.cpp:2477
bool ShouldUseFlangCompiler(const JobAction &JA) const
ShouldUseFlangCompiler - Should the flang compiler be used to handle this action.
Definition: Driver.cpp:10249
LTOKind getLTOMode(bool IsOffload=false) const
Get the specific kind of LTO being performed.
Definition: Driver.h:739
bool DiagnoseInputExistence(const llvm::opt::DerivedArgList &Args, StringRef Value, types::ID Ty, bool TypoCorrect) const
Check that the file referenced by Value exists.
Definition: Driver.cpp:3015
bool getUseNewOffloadingDriver() const
getUseNewOffloadingDriver - use the new offload driver for OpenMP.
Definition: Driver.h:917
bool HandleImmediateArgs(const Compilation &C)
HandleImmediateArgs - Handle any arguments which should be treated before building actions or binding...
Definition: Driver.cpp:2607
DeviceMode getOffloadCompileMode()
Definition: Driver.h:760
std::pair< types::ID, const llvm::opt::Arg * > InputTy
An input type and its arguments.
Definition: Driver.h:209
llvm::opt::ArgStringList getDeviceTraitsMacrosArgs() const
Definition: Driver.h:981
const std::string getFPGATempDepFile(const std::string &FileName) const
getFPGATempDepFile - Get a file to be added to the bundling step of an FPGA object.
Definition: Driver.h:927
bool embedBitcodeEnabled() const
Definition: Driver.h:434
bool IsFPGAHWMode() const
Definition: Driver.h:750
DiagnosticsEngine & getDiags() const
Definition: Driver.h:403
llvm::opt::InputArgList ParseArgStrings(ArrayRef< const char * > Args, bool UseDriverMode, bool &ContainsError)
ParseArgStrings - Parse the given list of strings into an ArgList.
Definition: Driver.cpp:275
void CreateOffloadingDeviceToolChains(Compilation &C, InputList &Inputs)
CreateOffloadingDeviceToolChains - create all the toolchains required to support offloading devices g...
Definition: Driver.cpp:866
std::string GetUniquePath(StringRef BaseName, StringRef Ext) const
GetUniquePath = Return the pathname of a unique file to use as part of compilation.
Definition: Driver.cpp:9934
std::string GetProgramPath(StringRef Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
Definition: Driver.cpp:9836
std::string CCLogDiagnosticsFilename
The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
Definition: Driver.h:206
bool isSaveTempsObj() const
Definition: Driver.h:432
std::string CCPrintHeadersFilename
The file to log CC_PRINT_HEADERS output to, if enabled.
Definition: Driver.h:203
void HandleAutocompletions(StringRef PassedFlags) const
HandleAutocompletions - Handle –autocomplete by searching and printing possible flags,...
Definition: Driver.cpp:2520
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:401
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:166
unsigned CCPrintOptions
Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to CCPrintOptionsFilename or to std...
Definition: Driver.h:240
bool ShouldUseClangCompiler(const JobAction &JA) const
ShouldUseClangCompiler - Should the clang compiler be used to handle this action.
Definition: Driver.cpp:10234
bool isUsingLTO(bool IsOffload=false) const
Returns true if we are performing any kind of LTO.
Definition: Driver.h:734
std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const
GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file wi...
Definition: Driver.cpp:9923
void setProbePrecompiled(bool Value)
Definition: Driver.h:412
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition: Driver.h:157
bool maybeGenerateCompilationDiagnostics(CommandStatus CS, ReproLevel Level, Compilation &C, const Command &FailingCommand, StringRef AdditionalInformation="", CompilationDiagnosticReport *GeneratedReport=nullptr)
Definition: Driver.h:570
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
Definition: Driver.h:142
@ OMPRT_OMP
The LLVM OpenMP runtime.
Definition: Driver.h:132
@ OMPRT_Unknown
An unknown OpenMP runtime.
Definition: Driver.h:128
@ OMPRT_GOMP
The GNU OpenMP runtime.
Definition: Driver.h:137
std::string HostBits
Information about the host which can be overridden by the user.
Definition: Driver.h:191
static std::string GetResourcesPath(StringRef BinaryPath, StringRef CustomResourceDir="")
Takes the path to a binary that's either in bin/ or lib/ and returns the path to clang's resource dir...
Definition: Driver.cpp:173
HeaderIncludeFormatKind CCPrintHeadersFormat
The format of the header information that is emitted.
Definition: Driver.h:245
bool isDumpDeviceCodeEnabled() const
Definition: Driver.h:429
std::string getTargetTriple() const
Definition: Driver.h:422
bool getCheckInputsExist() const
Definition: Driver.h:407
bool CCCIsCC() const
Whether the driver should follow gcc like behavior.
Definition: Driver.h:221
void setTargetAndMode(const ParsedClangName &TM)
Definition: Driver.h:417
std::string GetStdModuleManifestPath(const Compilation &C, const ToolChain &TC) const
Lookup the path to the Standard library module manifest.
Definition: Driver.cpp:9878
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
Definition: Driver.h:228
bool embedBitcodeMarkerOnly() const
Definition: Driver.h:436
void setTitle(std::string Value)
Definition: Driver.h:420
llvm::function_ref< int(SmallVectorImpl< const char * > &ArgV)> CC1ToolFunc
Pointer to the ExecuteCC1Tool function, if available.
Definition: Driver.h:283
bool IsFPGAEmulationMode() const
Definition: Driver.h:752
prefix_list PrefixDirs
Definition: Driver.h:179
const char * getClangProgramPath() const
Get the path to the main clang executable.
Definition: Driver.h:425
Compilation * BuildCompilation(ArrayRef< const char * > Args)
BuildCompilation - Construct a compilation object for a command line argument vector.
Definition: Driver.cpp:1559
HeaderIncludeFilteringKind CCPrintHeadersFiltering
This flag determines whether clang should filter the header information that is emitted.
Definition: Driver.h:251
void setOffloadCompileMode(DeviceMode ModeValue)
Definition: Driver.h:756
enum clang::driver::Driver::DeviceMode OffloadCompileMode
std::string HostMachine
Definition: Driver.h:191
bool embedBitcodeInObject() const
Definition: Driver.h:435
std::string CCPrintStatReportFilename
The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
Definition: Driver.h:194
bool CCCIsCPP() const
Whether the driver is just the preprocessor.
Definition: Driver.h:218
std::string HostSystem
Definition: Driver.h:191
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:215
bool getProbePrecompiled() const
Definition: Driver.h:411
std::string FlangF128MathLibrary
Name of the library that provides implementations of IEEE-754 128-bit float math functions used by Fo...
Definition: Driver.h:256
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
ID
ID - Ordered values for successive stages in the compilation process which interact with user options...
Definition: Phases.h:17
ModuleHeaderMode
Whether headers used to construct C++20 module units should be looked up by the path supplied on the ...
Definition: Driver.h:68
@ HeaderMode_System
Definition: Driver.h:72
@ HeaderMode_None
Definition: Driver.h:69
@ HeaderMode_Default
Definition: Driver.h:70
@ HeaderMode_User
Definition: Driver.h:71
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
Definition: Driver.h:58
@ LTOK_Unknown
Definition: Driver.h:62
SmallVector< InputInfo, 4 > InputInfoList
Definition: Driver.h:50
bool isStaticArchiveFile(const StringRef &FileName)
Definition: Driver.cpp:10383
bool isObjectFile(std::string FileName)
Definition: Driver.cpp:10369
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
void applyOverrideOptions(SmallVectorImpl< const char * > &Args, const char *OverrideOpts, llvm::StringSet<> &SavedStrings, raw_ostream *OS=nullptr)
Apply a space separated list of edits to the input argument lists.
Definition: Driver.cpp:10587
llvm::StringRef getDriverMode(StringRef ProgName, ArrayRef< const char * > Args)
Returns the driver mode option's value, i.e.
Definition: Driver.cpp:10416
llvm::Error expandResponseFiles(SmallVectorImpl< const char * > &Args, bool ClangCLMode, llvm::BumpPtrAllocator &Alloc, llvm::vfs::FileSystem *FS=nullptr)
Expand response files from a clang driver or cc1 invocation.
Definition: Driver.cpp:10433
const llvm::opt::OptTable & getDriverOptTable()
bool willEmitRemarks(const llvm::opt::ArgList &Args)
bool IsClangCL(StringRef DriverMode)
Checks whether the value produced by getDriverMode is for CL mode.
Definition: Driver.cpp:10431
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
The JSON file list parser is used to communicate input to InstallAPI.
HeaderIncludeFilteringKind
Whether header information is filtered or not.
Definition: HeaderInclude.h:27
@ HIFIL_None
Definition: HeaderInclude.h:27
HeaderIncludeFormatKind
The format in which header information is emitted.
Definition: HeaderInclude.h:22
@ HIFMT_None
Definition: HeaderInclude.h:22
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Definition: Format.h:5427
Contains the files in the compilation diagnostic report generated by generateCompilationDiagnostics.
Definition: Driver.h:545
llvm::SmallVector< std::string, 4 > TemporaryFiles
Definition: Driver.h:546
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...
Definition: ToolChain.h:65