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