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