clang  14.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 
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 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.
62  return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
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  enum class SubDirectoryType {
73  Bin,
74  Include,
75  Lib,
76  };
77  std::string getSubDirectoryPath(SubDirectoryType Type,
78  llvm::StringRef SubdirParent,
79  llvm::Triple::ArchType TargetArch) const;
80 
81  // Convenience overload.
82  // Uses the current target arch.
84  llvm::StringRef SubdirParent = "") const {
85  return getSubDirectoryPath(Type, SubdirParent, getArch());
86  }
87 
88  enum class ToolsetLayout {
89  OlderVS,
90  VS2017OrNewer,
91  DevDivInternal,
92  };
93  bool getIsVS2017OrNewer() const { return VSLayout == ToolsetLayout::VS2017OrNewer; }
94 
95  void
96  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
97  llvm::opt::ArgStringList &CC1Args) const override;
98  void AddClangCXXStdlibIncludeArgs(
99  const llvm::opt::ArgList &DriverArgs,
100  llvm::opt::ArgStringList &CC1Args) const override;
101 
102  void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
103  llvm::opt::ArgStringList &CC1Args) const override;
104 
105  void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
106  llvm::opt::ArgStringList &CC1Args) const override;
107 
108  bool getWindowsSDKLibraryPath(
109  const llvm::opt::ArgList &Args, std::string &path) const;
110  bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
111  std::string &path) const;
112  bool useUniversalCRT() const;
113  VersionTuple
114  computeMSVCVersion(const Driver *D,
115  const llvm::opt::ArgList &Args) const override;
116 
117  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
118  types::ID InputType) const override;
119  SanitizerMask getSupportedSanitizers() const override;
120 
121  void printVerboseInfo(raw_ostream &OS) const override;
122 
123  bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
124 
125  void
126  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
127  llvm::opt::ArgStringList &CC1Args,
128  Action::OffloadKind DeviceOffloadKind) const override;
129 
130 protected:
131  void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
132  llvm::opt::ArgStringList &CC1Args,
133  const std::string &folder,
134  const Twine &subfolder1,
135  const Twine &subfolder2 = "",
136  const Twine &subfolder3 = "") const;
137 
138  Tool *buildLinker() const override;
139  Tool *buildAssembler() const override;
140 private:
141  std::string VCToolChainPath;
142  ToolsetLayout VSLayout = ToolsetLayout::OlderVS;
143  CudaInstallationDetector CudaInstallation;
144  RocmInstallationDetector RocmInstallation;
145 };
146 
147 } // end namespace toolchains
148 } // end namespace driver
149 } // end namespace clang
150 
151 #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:43
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
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:93
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
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:30
Tool.h
AMDGPU.h
clang::driver::toolchains::MSVCToolChain::FoundMSVCInstall
bool FoundMSVCInstall() const
Definition: MSVC.h:123
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:27
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:61
clang::driver::types::ID
ID
Definition: Types.h:23
clang::driver::toolchains::MSVCToolChain::getSubDirectoryPath
std::string getSubDirectoryPath(SubDirectoryType Type, llvm::StringRef SubdirParent="") const
Definition: MSVC.h:83
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:27
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:59
DebugInfoOptions.h
clang::driver::tools::visualstudio::Linker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: MSVC.h:29
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:68
clang::driver::toolchains::MSVCToolChain::ToolsetLayout
ToolsetLayout
Definition: MSVC.h:88
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:85
clang::driver::JobAction
Definition: Action.h:380
clang::driver::tools::visualstudio::Linker
Definition: MSVC.h:25
clang::driver::toolchains::MSVCToolChain::SubDirectoryType
SubDirectoryType
Definition: MSVC.h:72
clang::SanitizerMask
Definition: Sanitizers.h:30
Cuda.h