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