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