clang 17.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"
18#include "llvm/WindowsDriver/MSVCPaths.h"
19
20namespace clang {
21namespace driver {
22namespace tools {
23
24/// Visual studio tools.
25namespace visualstudio {
26class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
27public:
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
42namespace toolchains {
43
44class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
45public:
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;
55 getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
56 bool isPICDefault() const override;
57 bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
58 bool isPICDefaultForced() const override;
59
60 /// Set CodeView as the default debug info format for non-MachO binary
61 /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
62 /// override the default.
64 return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
65 : codegenoptions::DIF_CodeView;
66 }
67
68 /// Set the debugger tuning to "default", since we're definitely not tuning
69 /// for GDB.
70 llvm::DebuggerKind getDefaultDebuggerTuning() const override {
71 return llvm::DebuggerKind::Default;
72 }
73
74 unsigned GetDefaultDwarfVersion() const override {
75 return 4;
76 }
77
78 std::string getSubDirectoryPath(llvm::SubDirectoryType Type,
79 llvm::StringRef SubdirParent = "") const;
80 std::string getSubDirectoryPath(llvm::SubDirectoryType Type,
81 llvm::Triple::ArchType TargetArch) const;
82
83 bool getIsVS2017OrNewer() const {
84 return VSLayout == llvm::ToolsetLayout::VS2017OrNewer;
85 }
86
87 void
88 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
89 llvm::opt::ArgStringList &CC1Args) const override;
90 void AddClangCXXStdlibIncludeArgs(
91 const llvm::opt::ArgList &DriverArgs,
92 llvm::opt::ArgStringList &CC1Args) const override;
93
94 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
95 llvm::opt::ArgStringList &CC1Args) const override;
96
97 void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
98 llvm::opt::ArgStringList &CC1Args) const override;
99
100 void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args,
101 llvm::opt::ArgStringList &CmdArgs) const override;
102
103 bool getWindowsSDKLibraryPath(
104 const llvm::opt::ArgList &Args, std::string &path) const;
105 bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
106 std::string &path) const;
107 bool useUniversalCRT() const;
108 VersionTuple
109 computeMSVCVersion(const Driver *D,
110 const llvm::opt::ArgList &Args) const override;
111
112 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
113 types::ID InputType) const override;
114 SanitizerMask getSupportedSanitizers() const override;
115
116 void printVerboseInfo(raw_ostream &OS) const override;
117
118 bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
119
120 void
121 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
122 llvm::opt::ArgStringList &CC1Args,
123 Action::OffloadKind DeviceOffloadKind) const override;
124
125protected:
126 void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
127 llvm::opt::ArgStringList &CC1Args,
128 const std::string &folder,
129 const Twine &subfolder1,
130 const Twine &subfolder2 = "",
131 const Twine &subfolder3 = "") const;
132
133 Tool *buildLinker() const override;
134 Tool *buildAssembler() const override;
135private:
136 std::optional<llvm::StringRef> WinSdkDir, WinSdkVersion, WinSysRoot;
137 std::string VCToolChainPath;
138 llvm::ToolsetLayout VSLayout = llvm::ToolsetLayout::OlderVS;
139 CudaInstallationDetector CudaInstallation;
140 RocmInstallationDetector RocmInstallation;
141};
142
143} // end namespace toolchains
144} // end namespace driver
145} // end namespace clang
146
147#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
The base class of the type hierarchy.
Definition: Type.h:1566
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
A class to find a viable CUDA installation.
Definition: Cuda.h:27
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:76
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
A class to find a viable ROCM installation TODO: Generalize to handle libclc.
Definition: ROCm.h:47
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
unsigned GetDefaultDwarfVersion() const override
Definition: MSVC.h:74
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:63
llvm::DebuggerKind getDefaultDebuggerTuning() const override
Set the debugger tuning to "default", since we're definitely not tuning for GDB.
Definition: MSVC.h:70
bool hasIntegratedCPP() const override
Definition: MSVC.h:30
bool isLinkJob() const override
Definition: MSVC.h:31