MSVC.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //===--- MSVC.h - MSVC ToolChain Implementations ----------------*- 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. #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
  9. #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
  10. #include "AMDGPU.h"
  11. #include "Cuda.h"
  12. #include "clang/Basic/DebugInfoOptions.h"
  13. #include "clang/Driver/Compilation.h"
  14. #include "clang/Driver/Tool.h"
  15. #include "clang/Driver/ToolChain.h"
  16. namespace clang {
  17. namespace driver {
  18. namespace tools {
  19. /// Visual studio tools.
  20. namespace visualstudio {
  21. class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
  22. public:
  23. Linker(const ToolChain &TC) : Tool("visualstudio::Linker", "linker", TC) {}
  24. bool hasIntegratedCPP() const override { return false; }
  25. bool isLinkJob() const override { return true; }
  26. void ConstructJob(Compilation &C, const JobAction &JA,
  27. const InputInfo &Output, const InputInfoList &Inputs,
  28. const llvm::opt::ArgList &TCArgs,
  29. const char *LinkingOutput) const override;
  30. };
  31. } // end namespace visualstudio
  32. } // end namespace tools
  33. namespace toolchains {
  34. class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
  35. public:
  36. MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
  37. const llvm::opt::ArgList &Args);
  38. llvm::opt::DerivedArgList *
  39. TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
  40. Action::OffloadKind DeviceOffloadKind) const override;
  41. bool IsIntegratedAssemblerDefault() const override;
  42. bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
  43. bool isPICDefault() const override;
  44. bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
  45. bool isPICDefaultForced() const override;
  46. /// Set CodeView as the default debug info format for non-MachO binary
  47. /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
  48. /// override the default.
  49. codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
  50. return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
  51. : codegenoptions::DIF_CodeView;
  52. }
  53. /// Set the debugger tuning to "default", since we're definitely not tuning
  54. /// for GDB.
  55. llvm::DebuggerKind getDefaultDebuggerTuning() const override {
  56. return llvm::DebuggerKind::Default;
  57. }
  58. unsigned GetDefaultDwarfVersion() const override {
  59. return 4;
  60. }
  61. enum class SubDirectoryType {
  62. Bin,
  63. Include,
  64. Lib,
  65. };
  66. std::string getSubDirectoryPath(SubDirectoryType Type,
  67. llvm::StringRef SubdirParent,
  68. llvm::Triple::ArchType TargetArch) const;
  69. // Convenience overload.
  70. // Uses the current target arch.
  71. std::string getSubDirectoryPath(SubDirectoryType Type,
  72. llvm::StringRef SubdirParent = "") const {
  73. return getSubDirectoryPath(Type, SubdirParent, getArch());
  74. }
  75. enum class ToolsetLayout {
  76. OlderVS,
  77. VS2017OrNewer,
  78. DevDivInternal,
  79. };
  80. bool getIsVS2017OrNewer() const { return VSLayout == ToolsetLayout::VS2017OrNewer; }
  81. void
  82. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  83. llvm::opt::ArgStringList &CC1Args) const override;
  84. void AddClangCXXStdlibIncludeArgs(
  85. const llvm::opt::ArgList &DriverArgs,
  86. llvm::opt::ArgStringList &CC1Args) const override;
  87. void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  88. llvm::opt::ArgStringList &CC1Args) const override;
  89. void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  90. llvm::opt::ArgStringList &CC1Args) const override;
  91. bool getWindowsSDKLibraryPath(
  92. const llvm::opt::ArgList &Args, std::string &path) const;
  93. bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
  94. std::string &path) const;
  95. bool useUniversalCRT() const;
  96. VersionTuple
  97. computeMSVCVersion(const Driver *D,
  98. const llvm::opt::ArgList &Args) const override;
  99. std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
  100. types::ID InputType) const override;
  101. SanitizerMask getSupportedSanitizers() const override;
  102. void printVerboseInfo(raw_ostream &OS) const override;
  103. bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
  104. void
  105. addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  106. llvm::opt::ArgStringList &CC1Args,
  107. Action::OffloadKind DeviceOffloadKind) const override;
  108. protected:
  109. void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  110. llvm::opt::ArgStringList &CC1Args,
  111. const std::string &folder,
  112. const Twine &subfolder1,
  113. const Twine &subfolder2 = "",
  114. const Twine &subfolder3 = "") const;
  115. Tool *buildLinker() const override;
  116. Tool *buildAssembler() const override;
  117. private:
  118. std::string VCToolChainPath;
  119. ToolsetLayout VSLayout = ToolsetLayout::OlderVS;
  120. CudaInstallationDetector CudaInstallation;
  121. RocmInstallationDetector RocmInstallation;
  122. };
  123. } // end namespace toolchains
  124. } // end namespace driver
  125. } // end namespace clang
  126. #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H