clang  10.0.0svn
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 "Cuda.h"
15 #include "clang/Driver/Tool.h"
16 #include "clang/Driver/ToolChain.h"
17 
18 namespace clang {
19 namespace driver {
20 namespace tools {
21 
22 /// Visual studio tools.
23 namespace visualstudio {
24 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
25 public:
26  Linker(const ToolChain &TC)
27  : Tool("visualstudio::Linker", "linker", TC, RF_Full,
28  llvm::sys::WEM_UTF16) {}
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 
39 class LLVM_LIBRARY_VISIBILITY Compiler : public Tool {
40 public:
41  Compiler(const ToolChain &TC)
42  : Tool("visualstudio::Compiler", "compiler", TC, RF_Full,
43  llvm::sys::WEM_UTF16) {}
44 
45  bool hasIntegratedAssembler() const override { return true; }
46  bool hasIntegratedCPP() const override { return true; }
47  bool isLinkJob() 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  std::unique_ptr<Command> GetCommand(Compilation &C, const JobAction &JA,
55  const InputInfo &Output,
56  const InputInfoList &Inputs,
57  const llvm::opt::ArgList &TCArgs,
58  const char *LinkingOutput) const;
59 };
60 } // end namespace visualstudio
61 
62 } // end namespace tools
63 
64 namespace toolchains {
65 
66 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
67 public:
68  MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
69  const llvm::opt::ArgList &Args);
70 
71  llvm::opt::DerivedArgList *
72  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
73  Action::OffloadKind DeviceOffloadKind) const override;
74 
75  bool IsIntegratedAssemblerDefault() const override;
76  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
77  bool isPICDefault() const override;
78  bool isPIEDefault() const override;
79  bool isPICDefaultForced() const override;
80 
81  /// Set CodeView as the default debug info format for non-MachO binary
82  /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
83  /// override the default.
85  return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
87  }
88 
89  /// Set the debugger tuning to "default", since we're definitely not tuning
90  /// for GDB.
91  llvm::DebuggerKind getDefaultDebuggerTuning() const override {
92  return llvm::DebuggerKind::Default;
93  }
94 
95  enum class SubDirectoryType {
96  Bin,
97  Include,
98  Lib,
99  };
100  std::string getSubDirectoryPath(SubDirectoryType Type,
101  llvm::StringRef SubdirParent,
102  llvm::Triple::ArchType TargetArch) const;
103 
104  // Convenience overload.
105  // Uses the current target arch.
107  llvm::StringRef SubdirParent = "") const {
108  return getSubDirectoryPath(Type, SubdirParent, getArch());
109  }
110 
111  enum class ToolsetLayout {
112  OlderVS,
113  VS2017OrNewer,
114  DevDivInternal,
115  };
116  bool getIsVS2017OrNewer() const { return VSLayout == ToolsetLayout::VS2017OrNewer; }
117 
118  void
119  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
120  llvm::opt::ArgStringList &CC1Args) const override;
121  void AddClangCXXStdlibIncludeArgs(
122  const llvm::opt::ArgList &DriverArgs,
123  llvm::opt::ArgStringList &CC1Args) const override;
124 
125  void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
126  llvm::opt::ArgStringList &CC1Args) const override;
127 
128  bool getWindowsSDKLibraryPath(std::string &path) const;
129  /// Check if Universal CRT should be used if available
130  bool getUniversalCRTLibraryPath(std::string &path) const;
131  bool useUniversalCRT() const;
132  VersionTuple
133  computeMSVCVersion(const Driver *D,
134  const llvm::opt::ArgList &Args) const override;
135 
136  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
137  types::ID InputType) const override;
138  SanitizerMask getSupportedSanitizers() const override;
139 
140  void printVerboseInfo(raw_ostream &OS) const override;
141 
142  bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
143 
144 protected:
145  void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
146  llvm::opt::ArgStringList &CC1Args,
147  const std::string &folder,
148  const Twine &subfolder1,
149  const Twine &subfolder2 = "",
150  const Twine &subfolder3 = "") const;
151 
152  Tool *buildLinker() const override;
153  Tool *buildAssembler() const override;
154 private:
155  std::string VCToolChainPath;
156  ToolsetLayout VSLayout = ToolsetLayout::OlderVS;
157  CudaInstallationDetector CudaInstallation;
158 };
159 
160 } // end namespace toolchains
161 } // end namespace driver
162 } // end namespace clang
163 
164 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
bool hasIntegratedAssembler() const override
Definition: MSVC.h:45
The base class of the type hierarchy.
Definition: Type.h:1436
bool isLinkJob() const override
Definition: MSVC.h:31
llvm::DebuggerKind getDefaultDebuggerTuning() const override
Set the debugger tuning to "default", since we&#39;re definitely not tuning for GDB.
Definition: MSVC.h:91
A class to find a viable CUDA installation.
Definition: Cuda.h:28
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
std::string getSubDirectoryPath(SubDirectoryType Type, llvm::StringRef SubdirParent="") const
Definition: MSVC.h:106
bool hasIntegratedCPP() const override
Definition: MSVC.h:30
Dataflow Directional Tag Classes.
Tool - Information on a specific compilation tool.
Definition: Tool.h:33
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
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:84
bool isLinkJob() const override
Definition: MSVC.h:47
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88
bool hasIntegratedCPP() const override
Definition: MSVC.h:46