clang 20.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"
15#include "SYCL.h"
17#include "clang/Driver/Tool.h"
19#include "llvm/Frontend/Debug/Options.h"
20#include "llvm/WindowsDriver/MSVCPaths.h"
21
22namespace clang {
23namespace driver {
24namespace tools {
25
26/// Visual studio tools.
27namespace visualstudio {
28class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
29public:
30 Linker(const ToolChain &TC) : Tool("visualstudio::Linker", "linker", TC) {}
31
32 bool hasIntegratedCPP() const override { return false; }
33 bool isLinkJob() const override { return true; }
34
35 void ConstructJob(Compilation &C, const JobAction &JA,
36 const InputInfo &Output, const InputInfoList &Inputs,
37 const llvm::opt::ArgList &TCArgs,
38 const char *LinkingOutput) const override;
39};
40} // end namespace visualstudio
41
42} // end namespace tools
43
44namespace toolchains {
45
46class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
47public:
48 MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
49 const llvm::opt::ArgList &Args);
50
51 llvm::opt::DerivedArgList *
52 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
53 Action::OffloadKind DeviceOffloadKind) const override;
54
56 getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
57 bool isPICDefault() const override;
58 bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
59 bool isPICDefaultForced() const override;
60
61 /// Set CodeView as the default debug info format for non-MachO binary
62 /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
63 /// override the default.
64 llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
65 return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
66 : llvm::codegenoptions::DIF_DWARF;
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 void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
105 llvm::opt::ArgStringList &CC1Args) const override;
106
107 bool getWindowsSDKLibraryPath(
108 const llvm::opt::ArgList &Args, std::string &path) const;
109 bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
110 std::string &path) const;
111 bool useUniversalCRT() const;
112 VersionTuple
113 computeMSVCVersion(const Driver *D,
114 const llvm::opt::ArgList &Args) const override;
115
116 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
117 types::ID InputType) const override;
118 SanitizerMask getSupportedSanitizers() const override;
119
120 void printVerboseInfo(raw_ostream &OS) const override;
121
122 bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
123
124 void
125 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
126 llvm::opt::ArgStringList &CC1Args,
127 Action::OffloadKind DeviceOffloadKind) const override;
128
129protected:
130 void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
131 llvm::opt::ArgStringList &CC1Args,
132 const std::string &folder,
133 const Twine &subfolder1,
134 const Twine &subfolder2 = "",
135 const Twine &subfolder3 = "") const;
136
137 Tool *buildLinker() const override;
138 Tool *buildAssembler() const override;
139private:
140 std::optional<llvm::StringRef> WinSdkDir, WinSdkVersion, WinSysRoot;
141 std::string VCToolChainPath;
142 llvm::ToolsetLayout VSLayout = llvm::ToolsetLayout::OlderVS;
146};
147
148} // end namespace toolchains
149} // end namespace driver
150} // end namespace clang
151
152#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
const Decl * D
Simple wrapper for toolchain detector with costly initialization.
Definition: LazyDetector.h:21
The base class of the type hierarchy.
Definition: Type.h:1828
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:75
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:64
llvm::DebuggerKind getDefaultDebuggerTuning() const override
Set the debugger tuning to "default", since we're definitely not tuning for GDB.
Definition: MSVC.h:71
bool hasIntegratedCPP() const override
Definition: MSVC.h:32
bool isLinkJob() const override
Definition: MSVC.h:33
The JSON file list parser is used to communicate input to InstallAPI.