1 //===--- MSVC.h - MSVC ToolChain Implementations ----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
14 #include "clang/Basic/DebugInfoOptions.h"
15 #include "clang/Driver/Compilation.h"
16 #include "clang/Driver/Tool.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/WindowsDriver/MSVCPaths.h"
24 /// Visual studio tools.
25 namespace visualstudio
{
26 class LLVM_LIBRARY_VISIBILITY Linker
: public Tool
{
28 Linker(const ToolChain
&TC
) : Tool("visualstudio::Linker", "linker", TC
) {}
30 bool hasIntegratedCPP() const override
{ return false; }
31 bool isLinkJob() const override
{ return true; }
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
;
38 } // end namespace visualstudio
40 } // end namespace tools
42 namespace toolchains
{
44 class LLVM_LIBRARY_VISIBILITY MSVCToolChain
: public ToolChain
{
46 MSVCToolChain(const Driver
&D
, const llvm::Triple
&Triple
,
47 const llvm::opt::ArgList
&Args
);
49 llvm::opt::DerivedArgList
*
50 TranslateArgs(const llvm::opt::DerivedArgList
&Args
, StringRef BoundArch
,
51 Action::OffloadKind DeviceOffloadKind
) const override
;
53 bool IsIntegratedAssemblerDefault() const override
;
54 bool IsUnwindTablesDefault(const llvm::opt::ArgList
&Args
) const override
;
55 bool isPICDefault() const override
;
56 bool isPIEDefault(const llvm::opt::ArgList
&Args
) const override
;
57 bool isPICDefaultForced() const override
;
59 /// Set CodeView as the default debug info format for non-MachO binary
60 /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
61 /// override the default.
62 codegenoptions::DebugInfoFormat
getDefaultDebugFormat() const override
{
63 return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
64 : codegenoptions::DIF_CodeView
;
67 /// Set the debugger tuning to "default", since we're definitely not tuning
69 llvm::DebuggerKind
getDefaultDebuggerTuning() const override
{
70 return llvm::DebuggerKind::Default
;
73 unsigned GetDefaultDwarfVersion() const override
{
77 std::string
getSubDirectoryPath(llvm::SubDirectoryType Type
,
78 llvm::StringRef SubdirParent
= "") const;
79 std::string
getSubDirectoryPath(llvm::SubDirectoryType Type
,
80 llvm::Triple::ArchType TargetArch
) const;
82 bool getIsVS2017OrNewer() const {
83 return VSLayout
== llvm::ToolsetLayout::VS2017OrNewer
;
87 AddClangSystemIncludeArgs(const llvm::opt::ArgList
&DriverArgs
,
88 llvm::opt::ArgStringList
&CC1Args
) const override
;
89 void AddClangCXXStdlibIncludeArgs(
90 const llvm::opt::ArgList
&DriverArgs
,
91 llvm::opt::ArgStringList
&CC1Args
) const override
;
93 void AddCudaIncludeArgs(const llvm::opt::ArgList
&DriverArgs
,
94 llvm::opt::ArgStringList
&CC1Args
) const override
;
96 void AddHIPIncludeArgs(const llvm::opt::ArgList
&DriverArgs
,
97 llvm::opt::ArgStringList
&CC1Args
) const override
;
99 void AddHIPRuntimeLibArgs(const llvm::opt::ArgList
&Args
,
100 llvm::opt::ArgStringList
&CmdArgs
) const override
;
102 bool getWindowsSDKLibraryPath(
103 const llvm::opt::ArgList
&Args
, std::string
&path
) const;
104 bool getUniversalCRTLibraryPath(const llvm::opt::ArgList
&Args
,
105 std::string
&path
) const;
106 bool useUniversalCRT() const;
108 computeMSVCVersion(const Driver
*D
,
109 const llvm::opt::ArgList
&Args
) const override
;
111 std::string
ComputeEffectiveClangTriple(const llvm::opt::ArgList
&Args
,
112 types::ID InputType
) const override
;
113 SanitizerMask
getSupportedSanitizers() const override
;
115 void printVerboseInfo(raw_ostream
&OS
) const override
;
117 bool FoundMSVCInstall() const { return !VCToolChainPath
.empty(); }
120 addClangTargetOptions(const llvm::opt::ArgList
&DriverArgs
,
121 llvm::opt::ArgStringList
&CC1Args
,
122 Action::OffloadKind DeviceOffloadKind
) const override
;
125 void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList
&DriverArgs
,
126 llvm::opt::ArgStringList
&CC1Args
,
127 const std::string
&folder
,
128 const Twine
&subfolder1
,
129 const Twine
&subfolder2
= "",
130 const Twine
&subfolder3
= "") const;
132 Tool
*buildLinker() const override
;
133 Tool
*buildAssembler() const override
;
135 llvm::Optional
<llvm::StringRef
> WinSdkDir
, WinSdkVersion
, WinSysRoot
;
136 std::string VCToolChainPath
;
137 llvm::ToolsetLayout VSLayout
= llvm::ToolsetLayout::OlderVS
;
138 CudaInstallationDetector CudaInstallation
;
139 RocmInstallationDetector RocmInstallation
;
142 } // end namespace toolchains
143 } // end namespace driver
144 } // end namespace clang
146 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H