clang 24.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
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
42class LLVM_LIBRARY_VISIBILITY ARM64XObjcopy : public Tool {
43public:
45 : Tool("ARM64XObjcopy", "llvm-objcopy", TC) {}
46
47 bool hasIntegratedCPP() const override { return false; }
48
49 void ConstructJob(Compilation &C, const JobAction &JA,
50 const InputInfo &Output, const InputInfoList &Inputs,
51 const llvm::opt::ArgList &TCArgs,
52 const char *LinkingOutput) const override;
53};
54
55} // end namespace tools
56
57namespace toolchains {
58
59class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
60public:
61 MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
62 const llvm::opt::ArgList &Args);
63
65 getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
66 bool isPICDefault() const override;
67 bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
68 bool isPICDefaultForced() const override;
69
70 /// Set CodeView as the default debug info format for non-MachO binary
71 /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
72 /// override the default.
73 llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
74 return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
75 : llvm::codegenoptions::DIF_DWARF;
76 }
77
78 /// Set the debugger tuning to "default", since we're definitely not tuning
79 /// for GDB.
80 llvm::DebuggerKind getDefaultDebuggerTuning() const override {
81 return llvm::DebuggerKind::Default;
82 }
83
84 unsigned GetDefaultDwarfVersion() const override {
85 return 4;
86 }
87
88 std::string getSubDirectoryPath(llvm::SubDirectoryType Type,
89 llvm::StringRef SubdirParent = "") const;
90 std::string getSubDirectoryPath(llvm::SubDirectoryType Type,
91 llvm::Triple::ArchType TargetArch) const;
92
93 bool getIsVS2017OrNewer() const {
94 return VSLayout == llvm::ToolsetLayout::VS2017OrNewer;
95 }
96
97 void
98 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
99 llvm::opt::ArgStringList &CC1Args) const override;
100 llvm::StringRef
101 GetCXXStdlibName(const llvm::opt::ArgList &DriverArgs) const override;
102 void AddClangCXXStdlibIncludeArgs(
103 const llvm::opt::ArgList &DriverArgs,
104 llvm::opt::ArgStringList &CC1Args) const override;
105
106 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
107 llvm::opt::ArgStringList &CC1Args) const override;
108
109 void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
110 llvm::opt::ArgStringList &CC1Args) const override;
111
112 void addOffloadRTLibs(unsigned ActiveKinds, const llvm::opt::ArgList &Args,
113 llvm::opt::ArgStringList &CmdArgs) const override;
114
115 void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
116 llvm::opt::ArgStringList &CC1Args) const override;
117
118 bool getWindowsSDKLibraryPath(
119 const llvm::opt::ArgList &Args, std::string &path) const;
120 bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
121 std::string &path) const;
122 bool useUniversalCRT() const;
123 VersionTuple
124 computeMSVCVersion(const Driver *D,
125 const llvm::opt::ArgList &Args) const override;
126
127 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
128 BoundArch BA,
129 types::ID InputType) const override;
131 getSupportedSanitizers(BoundArch BA,
132 Action::OffloadKind DeviceOffloadKind) const override;
133
134 void printVerboseInfo(raw_ostream &OS) const override;
135
136 bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
137
138 void
139 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
140 llvm::opt::ArgStringList &CC1Args, BoundArch BA,
141 Action::OffloadKind DeviceOffloadKind) const override;
142
143protected:
144 void AddMSVCStdlibMultilibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
145 llvm::opt::ArgStringList &CC1Args,
146 bool HonorNostdincxx) const;
147 void AddMSVCStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
148 llvm::opt::ArgStringList &CC1Args) const;
149
150 void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
151 llvm::opt::ArgStringList &CC1Args,
152 const std::string &folder,
153 const Twine &subfolder1,
154 const Twine &subfolder2 = "",
155 const Twine &subfolder3 = "") const;
156
157 Tool *getTool(Action::ActionClass AC) const override;
158 Tool *buildLinker() const override;
159 Tool *buildAssembler() const override;
160
161private:
162 std::optional<llvm::StringRef> WinSdkDir, WinSdkVersion, WinSysRoot;
163 std::string VCToolChainPath;
164 llvm::ToolsetLayout VSLayout = llvm::ToolsetLayout::OlderVS;
168 mutable std::unique_ptr<tools::ARM64XObjcopy> Objcopy;
169};
170
171} // end namespace toolchains
172} // end namespace driver
173} // end namespace clang
174
175#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
static StringRef getTriple(const Command &Job)
Simple wrapper for toolchain detector with costly initialization.
The base class of the type hierarchy.
Definition TypeBase.h:1879
Compilation - A set of tasks to perform for a single driver invocation.
Definition Compilation.h:46
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:93
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:93
Tool - Information on a specific compilation tool.
Definition Tool.h:31
Tool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition Tool.cpp:13
UnwindTableLevel getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override
How detailed should the unwind tables be by default.
Definition MSVC.cpp:586
unsigned GetDefaultDwarfVersion() const override
Definition MSVC.h:84
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition MSVC.cpp:601
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition MSVC.cpp:610
MSVCToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition MSVC.cpp:530
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition MSVC.cpp:606
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:73
llvm::DebuggerKind getDefaultDebuggerTuning() const override
Set the debugger tuning to "default", since we're definitely not tuning for GDB.
Definition MSVC.h:80
ARM64XObjcopy(const ToolChain &TC)
Definition MSVC.h:44
bool hasIntegratedCPP() const override
Definition MSVC.h:47
bool hasIntegratedCPP() const override
Definition MSVC.h:32
bool isLinkJob() const override
Definition MSVC.h:33
Visual studio tools.
Definition MSVC.h:27
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:49
Top level wrappers for InstallAPI frontend operations.
Represents a bound architecture for offload / multiple architecture compilation.