clang  15.0.0git
MSVC.h
Go to the documentation of this file.
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"
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.
63  return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
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
clang::codegenoptions::DIF_CodeView
@ DIF_CodeView
Definition: DebugInfoOptions.h:17
clang::driver::toolchains::MSVCToolChain
Definition: MSVC.h:44
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
llvm::Optional< llvm::StringRef >
clang::codegenoptions::DebugInfoFormat
DebugInfoFormat
Definition: DebugInfoOptions.h:15
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::toolchains::MSVCToolChain::getIsVS2017OrNewer
bool getIsVS2017OrNewer() const
Definition: MSVC.h:82
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1500
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::tools::visualstudio::Linker::isLinkJob
bool isLinkJob() const override
Definition: MSVC.h:31
Tool.h
AMDGPU.h
clang::driver::toolchains::MSVCToolChain::FoundMSVCInstall
bool FoundMSVCInstall() const
Definition: MSVC.h:117
ToolChain.h
clang::codegenoptions::DIF_DWARF
@ DIF_DWARF
Definition: DebugInfoOptions.h:16
clang::driver::tools::visualstudio::Linker::Linker
Linker(const ToolChain &TC)
Definition: MSVC.h:28
Compilation.h
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::CudaInstallationDetector
A class to find a viable CUDA installation.
Definition: Cuda.h:28
clang::driver::toolchains::MSVCToolChain::getDefaultDebugFormat
codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override
Set CodeView as the default debug info format for non-MachO binary formats, and to DWARF otherwise.
Definition: MSVC.h:62
clang::driver::types::ID
ID
Definition: Types.h:23
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver::RocmInstallationDetector
A class to find a viable ROCM installation TODO: Generalize to handle libclc.
Definition: ROCm.h:47
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:71
DebugInfoOptions.h
clang::driver::tools::visualstudio::Linker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: MSVC.h:30
clang::driver::toolchains::MSVCToolChain::getDefaultDebuggerTuning
llvm::DebuggerKind getDefaultDebuggerTuning() const override
Set the debugger tuning to "default", since we're definitely not tuning for GDB.
Definition: MSVC.h:69
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:88
clang::driver::JobAction
Definition: Action.h:395
clang::driver::tools::visualstudio::Linker
Definition: MSVC.h:26
clang::SanitizerMask
Definition: Sanitizers.h:30
Cuda.h
clang::driver::toolchains::MSVCToolChain::GetDefaultDwarfVersion
unsigned GetDefaultDwarfVersion() const override
Definition: MSVC.h:73