1 //===- ToolChain.h - Collections of tools for one platform ------*- 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_TOOLCHAIN_H 10 #define LLVM_CLANG_DRIVER_TOOLCHAIN_H 11 12 #include "clang/Basic/DebugInfoOptions.h" 13 #include "clang/Basic/LLVM.h" 14 #include "clang/Basic/LangOptions.h" 15 #include "clang/Basic/Sanitizers.h" 16 #include "clang/Driver/Action.h" 17 #include "clang/Driver/Multilib.h" 18 #include "clang/Driver/Types.h" 19 #include "llvm/ADT/APFloat.h" 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/ADT/FloatingPointMode.h" 22 #include "llvm/ADT/SmallVector.h" 23 #include "llvm/ADT/StringRef.h" 24 #include "llvm/ADT/Triple.h" 25 #include "llvm/MC/MCTargetOptions.h" 26 #include "llvm/Option/Option.h" 27 #include "llvm/Support/VersionTuple.h" 28 #include "llvm/Target/TargetOptions.h" 29 #include <cassert> 30 #include <climits> 31 #include <memory> 32 #include <string> 33 #include <utility> 34 35 namespace llvm { 36 namespace opt { 37 38 class Arg; 39 class ArgList; 40 class DerivedArgList; 41 42 } // namespace opt 43 namespace vfs { 44 45 class FileSystem; 46 47 } // namespace vfs 48 } // namespace llvm 49 50 namespace clang { 51 52 class ObjCRuntime; 53 54 namespace driver { 55 56 class Driver; 57 class InputInfo; 58 class SanitizerArgs; 59 class Tool; 60 class XRayArgs; 61 62 /// Helper structure used to pass information extracted from clang executable 63 /// name such as `i686-linux-android-g++`. 64 struct ParsedClangName { 65 /// Target part of the executable name, as `i686-linux-android`. 66 std::string TargetPrefix; 67 68 /// Driver mode part of the executable name, as `g++`. 69 std::string ModeSuffix; 70 71 /// Corresponding driver mode argument, as '--driver-mode=g++' 72 const char *DriverMode = nullptr; 73 74 /// True if TargetPrefix is recognized as a registered target name. 75 bool TargetIsValid = false; 76 77 ParsedClangName() = default; 78 ParsedClangName(std::string Suffix, const char *Mode) 79 : ModeSuffix(Suffix), DriverMode(Mode) {} 80 ParsedClangName(std::string Target, std::string Suffix, const char *Mode, 81 bool IsRegistered) 82 : TargetPrefix(Target), ModeSuffix(Suffix), DriverMode(Mode), 83 TargetIsValid(IsRegistered) {} 84 85 bool isEmpty() const { 86 return TargetPrefix.empty() && ModeSuffix.empty() && DriverMode == nullptr; 87 } 88 }; 89 90 /// ToolChain - Access to tools for a single platform. 91 class ToolChain { 92 public: 93 using path_list = SmallVector<std::string, 16>; 94 95 enum CXXStdlibType { 96 CST_Libcxx, 97 CST_Libstdcxx 98 }; 99 100 enum RuntimeLibType { 101 RLT_CompilerRT, 102 RLT_Libgcc 103 }; 104 105 enum UnwindLibType { 106 UNW_None, 107 UNW_CompilerRT, 108 UNW_Libgcc 109 }; 110 111 enum RTTIMode { 112 RM_Enabled, 113 RM_Disabled, 114 }; 115 116 enum FileType { FT_Object, FT_Static, FT_Shared }; 117 118 private: 119 friend class RegisterEffectiveTriple; 120 121 const Driver &D; 122 llvm::Triple Triple; 123 const llvm::opt::ArgList &Args; 124 125 // We need to initialize CachedRTTIArg before CachedRTTIMode 126 const llvm::opt::Arg *const CachedRTTIArg; 127 128 const RTTIMode CachedRTTIMode; 129 130 /// The list of toolchain specific path prefixes to search for libraries. 131 path_list LibraryPaths; 132 133 /// The list of toolchain specific path prefixes to search for files. 134 path_list FilePaths; 135 136 /// The list of toolchain specific path prefixes to search for programs. 137 path_list ProgramPaths; 138 139 mutable std::unique_ptr<Tool> Clang; 140 mutable std::unique_ptr<Tool> Flang; 141 mutable std::unique_ptr<Tool> Assemble; 142 mutable std::unique_ptr<Tool> Link; 143 mutable std::unique_ptr<Tool> StaticLibTool; 144 mutable std::unique_ptr<Tool> IfsMerge; 145 mutable std::unique_ptr<Tool> OffloadBundler; 146 mutable std::unique_ptr<Tool> OffloadWrapper; 147 148 Tool *getClang() const; 149 Tool *getFlang() const; 150 Tool *getAssemble() const; 151 Tool *getLink() const; 152 Tool *getStaticLibTool() const; 153 Tool *getIfsMerge() const; 154 Tool *getClangAs() const; 155 Tool *getOffloadBundler() const; 156 Tool *getOffloadWrapper() const; 157 158 mutable std::unique_ptr<SanitizerArgs> SanitizerArguments; 159 mutable std::unique_ptr<XRayArgs> XRayArguments; 160 161 /// The effective clang triple for the current Job. 162 mutable llvm::Triple EffectiveTriple; 163 164 /// Set the toolchain's effective clang triple. 165 void setEffectiveTriple(llvm::Triple ET) const { 166 EffectiveTriple = std::move(ET); 167 } 168 169 mutable llvm::Optional<CXXStdlibType> cxxStdlibType; 170 mutable llvm::Optional<RuntimeLibType> runtimeLibType; 171 mutable llvm::Optional<UnwindLibType> unwindLibType; 172 173 protected: 174 MultilibSet Multilibs; 175 Multilib SelectedMultilib; 176 177 ToolChain(const Driver &D, const llvm::Triple &T, 178 const llvm::opt::ArgList &Args); 179 180 void setTripleEnvironment(llvm::Triple::EnvironmentType Env); 181 182 virtual Tool *buildAssembler() const; 183 virtual Tool *buildLinker() const; 184 virtual Tool *buildStaticLibTool() const; 185 virtual Tool *getTool(Action::ActionClass AC) const; 186 187 virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, 188 StringRef Component, 189 FileType Type, 190 bool AddArch) const; 191 192 /// \name Utilities for implementing subclasses. 193 ///@{ 194 static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, 195 llvm::opt::ArgStringList &CC1Args, 196 const Twine &Path); 197 static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, 198 llvm::opt::ArgStringList &CC1Args, 199 const Twine &Path); 200 static void 201 addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, 202 llvm::opt::ArgStringList &CC1Args, 203 const Twine &Path); 204 static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, 205 llvm::opt::ArgStringList &CC1Args, 206 ArrayRef<StringRef> Paths); 207 ///@} 208 209 public: 210 virtual ~ToolChain(); 211 212 // Accessors 213 214 const Driver &getDriver() const { return D; } 215 llvm::vfs::FileSystem &getVFS() const; 216 const llvm::Triple &getTriple() const { return Triple; } 217 218 /// Get the toolchain's aux triple, if it has one. 219 /// 220 /// Exactly what the aux triple represents depends on the toolchain, but for 221 /// example when compiling CUDA code for the GPU, the triple might be NVPTX, 222 /// while the aux triple is the host (CPU) toolchain, e.g. x86-linux-gnu. 223 virtual const llvm::Triple *getAuxTriple() const { return nullptr; } 224 225 /// Some toolchains need to modify the file name, for example to replace the 226 /// extension for object files with .cubin for OpenMP offloading to Nvidia 227 /// GPUs. 228 virtual std::string getInputFilename(const InputInfo &Input) const; 229 230 llvm::Triple::ArchType getArch() const { return Triple.getArch(); } 231 StringRef getArchName() const { return Triple.getArchName(); } 232 StringRef getPlatform() const { return Triple.getVendorName(); } 233 StringRef getOS() const { return Triple.getOSName(); } 234 235 /// Provide the default architecture name (as expected by -arch) for 236 /// this toolchain. 237 StringRef getDefaultUniversalArchName() const; 238 239 std::string getTripleString() const { 240 return Triple.getTriple(); 241 } 242 243 /// Get the toolchain's effective clang triple. 244 const llvm::Triple &getEffectiveTriple() const { 245 assert(!EffectiveTriple.getTriple().empty() && "No effective triple"); 246 return EffectiveTriple; 247 } 248 249 path_list &getLibraryPaths() { return LibraryPaths; } 250 const path_list &getLibraryPaths() const { return LibraryPaths; } 251 252 path_list &getFilePaths() { return FilePaths; } 253 const path_list &getFilePaths() const { return FilePaths; } 254 255 path_list &getProgramPaths() { return ProgramPaths; } 256 const path_list &getProgramPaths() const { return ProgramPaths; } 257 258 const MultilibSet &getMultilibs() const { return Multilibs; } 259 260 const Multilib &getMultilib() const { return SelectedMultilib; } 261 262 const SanitizerArgs& getSanitizerArgs() const; 263 264 const XRayArgs& getXRayArgs() const; 265 266 // Returns the Arg * that explicitly turned on/off rtti, or nullptr. 267 const llvm::opt::Arg *getRTTIArg() const { return CachedRTTIArg; } 268 269 // Returns the RTTIMode for the toolchain with the current arguments. 270 RTTIMode getRTTIMode() const { return CachedRTTIMode; } 271 272 /// Return any implicit target and/or mode flag for an invocation of 273 /// the compiler driver as `ProgName`. 274 /// 275 /// For example, when called with i686-linux-android-g++, the first element 276 /// of the return value will be set to `"i686-linux-android"` and the second 277 /// will be set to "--driver-mode=g++"`. 278 /// It is OK if the target name is not registered. In this case the return 279 /// value contains false in the field TargetIsValid. 280 /// 281 /// \pre `llvm::InitializeAllTargets()` has been called. 282 /// \param ProgName The name the Clang driver was invoked with (from, 283 /// e.g., argv[0]). 284 /// \return A structure of type ParsedClangName that contains the executable 285 /// name parts. 286 static ParsedClangName getTargetAndModeFromProgramName(StringRef ProgName); 287 288 // Tool access. 289 290 /// TranslateArgs - Create a new derived argument list for any argument 291 /// translations this ToolChain may wish to perform, or 0 if no tool chain 292 /// specific translations are needed. If \p DeviceOffloadKind is specified 293 /// the translation specific for that offload kind is performed. 294 /// 295 /// \param BoundArch - The bound architecture name, or 0. 296 /// \param DeviceOffloadKind - The device offload kind used for the 297 /// translation. 298 virtual llvm::opt::DerivedArgList * 299 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, 300 Action::OffloadKind DeviceOffloadKind) const { 301 return nullptr; 302 } 303 304 /// TranslateOpenMPTargetArgs - Create a new derived argument list for 305 /// that contains the OpenMP target specific flags passed via 306 /// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val 307 virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs( 308 const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost, 309 SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const; 310 311 /// Append the argument following \p A to \p DAL assuming \p A is an Xarch 312 /// argument. If \p AllocatedArgs is null pointer, synthesized arguments are 313 /// added to \p DAL, otherwise they are appended to \p AllocatedArgs. 314 virtual void TranslateXarchArgs( 315 const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A, 316 llvm::opt::DerivedArgList *DAL, 317 SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs = nullptr) const; 318 319 /// Translate -Xarch_ arguments. If there are no such arguments, return 320 /// a null pointer, otherwise return a DerivedArgList containing the 321 /// translated arguments. 322 virtual llvm::opt::DerivedArgList * 323 TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, 324 Action::OffloadKind DeviceOffloadKind, 325 SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const; 326 327 /// Choose a tool to use to handle the action \p JA. 328 /// 329 /// This can be overridden when a particular ToolChain needs to use 330 /// a compiler other than Clang. 331 virtual Tool *SelectTool(const JobAction &JA) const; 332 333 // Helper methods 334 335 std::string GetFilePath(const char *Name) const; 336 std::string GetProgramPath(const char *Name) const; 337 338 /// Returns the linker path, respecting the -fuse-ld= argument to determine 339 /// the linker suffix or name. 340 /// If LinkerIsLLD is non-nullptr, it is set to true if the returned linker 341 /// is LLD. If it's set, it can be assumed that the linker is LLD built 342 /// at the same revision as clang, and clang can make assumptions about 343 /// LLD's supported flags, error output, etc. 344 /// If LinkerIsLLDDarwinNew is non-nullptr, it's set if the linker is 345 /// the new version in lld/MachO. 346 std::string GetLinkerPath(bool *LinkerIsLLD = nullptr, 347 bool *LinkerIsLLDDarwinNew = nullptr) const; 348 349 /// Returns the linker path for emitting a static library. 350 std::string GetStaticLibToolPath() const; 351 352 /// Dispatch to the specific toolchain for verbose printing. 353 /// 354 /// This is used when handling the verbose option to print detailed, 355 /// toolchain-specific information useful for understanding the behavior of 356 /// the driver on a specific platform. 357 virtual void printVerboseInfo(raw_ostream &OS) const {} 358 359 // Platform defaults information 360 361 /// Returns true if the toolchain is targeting a non-native 362 /// architecture. 363 virtual bool isCrossCompiling() const; 364 365 /// HasNativeLTOLinker - Check whether the linker and related tools have 366 /// native LLVM support. 367 virtual bool HasNativeLLVMSupport() const; 368 369 /// LookupTypeForExtension - Return the default language type to use for the 370 /// given extension. 371 virtual types::ID LookupTypeForExtension(StringRef Ext) const; 372 373 /// IsBlocksDefault - Does this tool chain enable -fblocks by default. 374 virtual bool IsBlocksDefault() const { return false; } 375 376 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as 377 /// by default. 378 virtual bool IsIntegratedAssemblerDefault() const { return false; } 379 380 /// Check if the toolchain should use the integrated assembler. 381 virtual bool useIntegratedAs() const; 382 383 /// Check if the toolchain should use AsmParser to parse inlineAsm when 384 /// integrated assembler is not default. 385 virtual bool parseInlineAsmUsingAsmParser() const { return false; } 386 387 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default. 388 virtual bool IsMathErrnoDefault() const { return true; } 389 390 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable 391 /// -fencode-extended-block-signature by default. 392 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; } 393 394 /// IsObjCNonFragileABIDefault - Does this tool chain set 395 /// -fobjc-nonfragile-abi by default. 396 virtual bool IsObjCNonFragileABIDefault() const { return false; } 397 398 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the 399 /// mixed dispatch method be used? 400 virtual bool UseObjCMixedDispatch() const { return false; } 401 402 /// Check whether to enable x86 relax relocations by default. 403 virtual bool useRelaxRelocations() const; 404 405 /// GetDefaultStackProtectorLevel - Get the default stack protector level for 406 /// this tool chain. 407 virtual LangOptions::StackProtectorMode 408 GetDefaultStackProtectorLevel(bool KernelOrKext) const { 409 return LangOptions::SSPOff; 410 } 411 412 /// Get the default trivial automatic variable initialization. 413 virtual LangOptions::TrivialAutoVarInitKind 414 GetDefaultTrivialAutoVarInit() const { 415 return LangOptions::TrivialAutoVarInitKind::Uninitialized; 416 } 417 418 /// GetDefaultLinker - Get the default linker to use. 419 virtual const char *getDefaultLinker() const { return "ld"; } 420 421 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use. 422 virtual RuntimeLibType GetDefaultRuntimeLibType() const { 423 return ToolChain::RLT_Libgcc; 424 } 425 426 virtual CXXStdlibType GetDefaultCXXStdlibType() const { 427 return ToolChain::CST_Libstdcxx; 428 } 429 430 virtual UnwindLibType GetDefaultUnwindLibType() const { 431 return ToolChain::UNW_None; 432 } 433 434 virtual std::string getCompilerRTPath() const; 435 436 virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, 437 StringRef Component, 438 FileType Type = ToolChain::FT_Static) const; 439 440 const char * 441 getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, 442 FileType Type = ToolChain::FT_Static) const; 443 444 std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, 445 StringRef Component, 446 FileType Type = ToolChain::FT_Static) const; 447 448 // Returns target specific runtime path if it exists. 449 virtual std::string getRuntimePath() const; 450 451 // Returns target specific standard library path if it exists. 452 virtual std::string getStdlibPath() const; 453 454 // Returns <ResourceDir>/lib/<OSName>/<arch>. This is used by runtimes (such 455 // as OpenMP) to find arch-specific libraries. 456 std::string getArchSpecificLibPath() const; 457 458 // Returns <OSname> part of above. 459 virtual StringRef getOSLibName() const; 460 461 /// needsProfileRT - returns true if instrumentation profile is on. 462 static bool needsProfileRT(const llvm::opt::ArgList &Args); 463 464 /// Returns true if gcov instrumentation (-fprofile-arcs or --coverage) is on. 465 static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args); 466 467 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables 468 /// by default. 469 virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const; 470 471 /// Test whether this toolchain supports outline atomics by default. 472 virtual bool 473 IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const { 474 return false; 475 } 476 477 /// Test whether this toolchain defaults to PIC. 478 virtual bool isPICDefault() const = 0; 479 480 /// Test whether this toolchain defaults to PIE. 481 virtual bool isPIEDefault() const = 0; 482 483 /// Test whether this toolchaind defaults to non-executable stacks. 484 virtual bool isNoExecStackDefault() const; 485 486 /// Tests whether this toolchain forces its default for PIC, PIE or 487 /// non-PIC. If this returns true, any PIC related flags should be ignored 488 /// and instead the results of \c isPICDefault() and \c isPIEDefault() are 489 /// used exclusively. 490 virtual bool isPICDefaultForced() const = 0; 491 492 /// SupportsProfiling - Does this tool chain support -pg. 493 virtual bool SupportsProfiling() const { return true; } 494 495 /// Complain if this tool chain doesn't support Objective-C ARC. 496 virtual void CheckObjCARC() const {} 497 498 /// Get the default debug info format. Typically, this is DWARF. 499 virtual codegenoptions::DebugInfoFormat getDefaultDebugFormat() const { 500 return codegenoptions::DIF_DWARF; 501 } 502 503 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf 504 /// compile unit information. 505 virtual bool UseDwarfDebugFlags() const { return false; } 506 507 // Return the DWARF version to emit, in the absence of arguments 508 // to the contrary. 509 virtual unsigned GetDefaultDwarfVersion() const { return 4; } 510 511 // Some toolchains may have different restrictions on the DWARF version and 512 // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when host 513 // compilation uses DWARF5. 514 virtual unsigned getMaxDwarfVersion() const { return UINT_MAX; } 515 516 // True if the driver should assume "-fstandalone-debug" 517 // in the absence of an option specifying otherwise, 518 // provided that debugging was requested in the first place. 519 // i.e. a value of 'true' does not imply that debugging is wanted. 520 virtual bool GetDefaultStandaloneDebug() const { return false; } 521 522 // Return the default debugger "tuning." 523 virtual llvm::DebuggerKind getDefaultDebuggerTuning() const { 524 return llvm::DebuggerKind::GDB; 525 } 526 527 /// Does this toolchain supports given debug info option or not. 528 virtual bool supportsDebugInfoOption(const llvm::opt::Arg *) const { 529 return true; 530 } 531 532 /// Adjust debug information kind considering all passed options. 533 virtual void adjustDebugInfoKind(codegenoptions::DebugInfoKind &DebugInfoKind, 534 const llvm::opt::ArgList &Args) const {} 535 536 /// GetExceptionModel - Return the tool chain exception model. 537 virtual llvm::ExceptionHandling 538 GetExceptionModel(const llvm::opt::ArgList &Args) const; 539 540 /// SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode. 541 virtual bool SupportsEmbeddedBitcode() const { return false; } 542 543 /// getThreadModel() - Which thread model does this target use? 544 virtual std::string getThreadModel() const { return "posix"; } 545 546 /// isThreadModelSupported() - Does this target support a thread model? 547 virtual bool isThreadModelSupported(const StringRef Model) const; 548 549 virtual std::string getMultiarchTriple(const Driver &D, 550 const llvm::Triple &TargetTriple, 551 StringRef SysRoot) const { 552 return TargetTriple.str(); 553 } 554 555 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking 556 /// command line arguments into account. 557 virtual std::string 558 ComputeLLVMTriple(const llvm::opt::ArgList &Args, 559 types::ID InputType = types::TY_INVALID) const; 560 561 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this 562 /// target, which may take into account the command line arguments. For 563 /// example, on Darwin the -mmacosx-version-min= command line argument (which 564 /// sets the deployment target) determines the version in the triple passed to 565 /// Clang. 566 virtual std::string ComputeEffectiveClangTriple( 567 const llvm::opt::ArgList &Args, 568 types::ID InputType = types::TY_INVALID) const; 569 570 /// getDefaultObjCRuntime - Return the default Objective-C runtime 571 /// for this platform. 572 /// 573 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 574 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const; 575 576 /// hasBlocksRuntime - Given that the user is compiling with 577 /// -fblocks, does this tool chain guarantee the existence of a 578 /// blocks runtime? 579 /// 580 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction 581 virtual bool hasBlocksRuntime() const { return true; } 582 583 /// Return the sysroot, possibly searching for a default sysroot using 584 /// target-specific logic. 585 virtual std::string computeSysRoot() const; 586 587 /// Add the clang cc1 arguments for system include paths. 588 /// 589 /// This routine is responsible for adding the necessary cc1 arguments to 590 /// include headers from standard system header directories. 591 virtual void 592 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, 593 llvm::opt::ArgStringList &CC1Args) const; 594 595 /// Add options that need to be passed to cc1 for this target. 596 virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, 597 llvm::opt::ArgStringList &CC1Args, 598 Action::OffloadKind DeviceOffloadKind) const; 599 600 /// Add warning options that need to be passed to cc1 for this target. 601 virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const; 602 603 // GetRuntimeLibType - Determine the runtime library type to use with the 604 // given compilation arguments. 605 virtual RuntimeLibType 606 GetRuntimeLibType(const llvm::opt::ArgList &Args) const; 607 608 // GetCXXStdlibType - Determine the C++ standard library type to use with the 609 // given compilation arguments. 610 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const; 611 612 // GetUnwindLibType - Determine the unwind library type to use with the 613 // given compilation arguments. 614 virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const; 615 616 // Detect the highest available version of libc++ in include path. 617 virtual std::string detectLibcxxVersion(StringRef IncludePath) const; 618 619 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 620 /// the include paths to use for the given C++ standard library type. 621 virtual void 622 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, 623 llvm::opt::ArgStringList &CC1Args) const; 624 625 /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set 626 /// the specified include paths for the C++ standard library. 627 void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs, 628 llvm::opt::ArgStringList &CC1Args) const; 629 630 /// Returns if the C++ standard library should be linked in. 631 /// Note that e.g. -lm should still be linked even if this returns false. 632 bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const; 633 634 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use 635 /// for the given C++ standard library type. 636 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, 637 llvm::opt::ArgStringList &CmdArgs) const; 638 639 /// AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option. 640 void AddFilePathLibArgs(const llvm::opt::ArgList &Args, 641 llvm::opt::ArgStringList &CmdArgs) const; 642 643 /// AddCCKextLibArgs - Add the system specific linker arguments to use 644 /// for kernel extensions (Darwin-specific). 645 virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args, 646 llvm::opt::ArgStringList &CmdArgs) const; 647 648 /// If a runtime library exists that sets global flags for unsafe floating 649 /// point math, return true. 650 /// 651 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags. 652 virtual bool isFastMathRuntimeAvailable( 653 const llvm::opt::ArgList &Args, std::string &Path) const; 654 655 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets 656 /// global flags for unsafe floating point math, add it and return true. 657 /// 658 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags. 659 bool addFastMathRuntimeIfAvailable( 660 const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; 661 662 /// addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass 663 /// a suitable profile runtime library to the linker. 664 virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, 665 llvm::opt::ArgStringList &CmdArgs) const; 666 667 /// Add arguments to use system-specific CUDA includes. 668 virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, 669 llvm::opt::ArgStringList &CC1Args) const; 670 671 /// Add arguments to use system-specific HIP includes. 672 virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, 673 llvm::opt::ArgStringList &CC1Args) const; 674 675 /// Add arguments to use MCU GCC toolchain includes. 676 virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, 677 llvm::opt::ArgStringList &CC1Args) const; 678 679 /// On Windows, returns the MSVC compatibility version. 680 virtual VersionTuple computeMSVCVersion(const Driver *D, 681 const llvm::opt::ArgList &Args) const; 682 683 /// Get paths of HIP device libraries. 684 virtual llvm::SmallVector<std::string, 12> 685 getHIPDeviceLibs(const llvm::opt::ArgList &Args) const; 686 687 /// Return sanitizers which are available in this toolchain. 688 virtual SanitizerMask getSupportedSanitizers() const; 689 690 /// Return sanitizers which are enabled by default. 691 virtual SanitizerMask getDefaultSanitizers() const { 692 return SanitizerMask(); 693 } 694 695 /// Returns true when it's possible to split LTO unit to use whole 696 /// program devirtualization and CFI santiizers. 697 virtual bool canSplitThinLTOUnit() const { return true; } 698 699 /// Returns the output denormal handling type in the default floating point 700 /// environment for the given \p FPType if given. Otherwise, the default 701 /// assumed mode for any floating point type. 702 virtual llvm::DenormalMode getDefaultDenormalModeForType( 703 const llvm::opt::ArgList &DriverArgs, const JobAction &JA, 704 const llvm::fltSemantics *FPType = nullptr) const { 705 return llvm::DenormalMode::getIEEE(); 706 } 707 }; 708 709 /// Set a ToolChain's effective triple. Reset it when the registration object 710 /// is destroyed. 711 class RegisterEffectiveTriple { 712 const ToolChain &TC; 713 714 public: 715 RegisterEffectiveTriple(const ToolChain &TC, llvm::Triple T) : TC(TC) { 716 TC.setEffectiveTriple(std::move(T)); 717 } 718 719 ~RegisterEffectiveTriple() { TC.setEffectiveTriple(llvm::Triple()); } 720 }; 721 722 } // namespace driver 723 724 } // namespace clang 725 726 #endif // LLVM_CLANG_DRIVER_TOOLCHAIN_H 727