clang  19.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"
14 #include "LazyDetector.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 private:
40  void constructMSVCLibCommand(Compilation &C, const JobAction &JA,
41  const InputInfo &Output,
42  const InputInfoList &InputFiles,
43  const llvm::opt::ArgList &Args) const;
44 };
45 } // end namespace visualstudio
46 
47 } // end namespace tools
48 
49 namespace toolchains {
50 
51 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
52 public:
53  MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
54  const llvm::opt::ArgList &Args);
55 
56  llvm::opt::DerivedArgList *
57  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
58  Action::OffloadKind DeviceOffloadKind) const override;
59 
61  getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
62  bool isPICDefault() const override;
63  bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
64  bool isPICDefaultForced() const override;
65 
66  /// Set CodeView as the default debug info format for non-MachO binary
67  /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
68  /// override the default.
69  llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
70  return getTriple().isOSBinFormatMachO()
71  ? llvm::codegenoptions::DIF_DWARF
72  : llvm::codegenoptions::DIF_CodeView;
73  }
74 
75  /// Set the debugger tuning to "default", since we're definitely not tuning
76  /// for GDB.
77  llvm::DebuggerKind getDefaultDebuggerTuning() const override {
78  return llvm::DebuggerKind::Default;
79  }
80 
81  unsigned GetDefaultDwarfVersion() const override {
82  return 4;
83  }
84 
85  std::string getSubDirectoryPath(llvm::SubDirectoryType Type,
86  llvm::StringRef SubdirParent = "") const;
87  std::string getSubDirectoryPath(llvm::SubDirectoryType Type,
88  llvm::Triple::ArchType TargetArch) const;
89 
90  bool getIsVS2017OrNewer() const {
91  return VSLayout == llvm::ToolsetLayout::VS2017OrNewer;
92  }
93 
94  void
95  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
96  llvm::opt::ArgStringList &CC1Args) const override;
97  void AddClangCXXStdlibIncludeArgs(
98  const llvm::opt::ArgList &DriverArgs,
99  llvm::opt::ArgStringList &CC1Args) const override;
100 
101  void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
102  llvm::opt::ArgStringList &CC1Args) const override;
103 
104  void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
105  llvm::opt::ArgStringList &CC1Args) const override;
106 
107  void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args,
108  llvm::opt::ArgStringList &CmdArgs) const override;
109 
110  bool getWindowsSDKLibraryPath(
111  const llvm::opt::ArgList &Args, std::string &path) const;
112  bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
113  std::string &path) const;
114  bool useUniversalCRT() const;
115  VersionTuple
116  computeMSVCVersion(const Driver *D,
117  const llvm::opt::ArgList &Args) const override;
118 
119  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
120  types::ID InputType) const override;
121  SanitizerMask getSupportedSanitizers() const override;
122 
123  void printVerboseInfo(raw_ostream &OS) const override;
124 
125  bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
126 
127  void
128  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
129  llvm::opt::ArgStringList &CC1Args,
130  Action::OffloadKind DeviceOffloadKind) const override;
131 
132 protected:
133  void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
134  llvm::opt::ArgStringList &CC1Args,
135  const std::string &folder,
136  const Twine &subfolder1,
137  const Twine &subfolder2 = "",
138  const Twine &subfolder3 = "") const;
139 
140  Tool *buildLinker() const override;
141  Tool *buildAssembler() const override;
142 private:
143  std::optional<llvm::StringRef> WinSdkDir, WinSdkVersion, WinSysRoot;
144  std::string VCToolChainPath;
145  llvm::ToolsetLayout VSLayout = llvm::ToolsetLayout::OlderVS;
148 };
149 
150 } // end namespace toolchains
151 } // end namespace driver
152 } // end namespace clang
153 
154 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
Simple wrapper for toolchain detector with costly initialization.
Definition: LazyDetector.h:21
The base class of the type hierarchy.
Definition: Type.h:1813
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
unsigned GetDefaultDwarfVersion() const override
Definition: MSVC.h:81
llvm::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:69
llvm::DebuggerKind getDefaultDebuggerTuning() const override
Set the debugger tuning to "default", since we're definitely not tuning for GDB.
Definition: MSVC.h:77
bool hasIntegratedCPP() const override
Definition: MSVC.h:31
bool isLinkJob() const override
Definition: MSVC.h:32
The JSON file list parser is used to communicate input to InstallAPI.