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