xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/Driver/ToolChains/MSVC.h (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
17330f729Sjoerg //===--- MSVC.h - MSVC ToolChain Implementations ----------------*- C++ -*-===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg 
97330f729Sjoerg #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
107330f729Sjoerg #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
117330f729Sjoerg 
12*e038c9c4Sjoerg #include "AMDGPU.h"
137330f729Sjoerg #include "Cuda.h"
147330f729Sjoerg #include "clang/Basic/DebugInfoOptions.h"
157330f729Sjoerg #include "clang/Driver/Compilation.h"
167330f729Sjoerg #include "clang/Driver/Tool.h"
177330f729Sjoerg #include "clang/Driver/ToolChain.h"
187330f729Sjoerg 
197330f729Sjoerg namespace clang {
207330f729Sjoerg namespace driver {
217330f729Sjoerg namespace tools {
227330f729Sjoerg 
237330f729Sjoerg /// Visual studio tools.
247330f729Sjoerg namespace visualstudio {
257330f729Sjoerg class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
267330f729Sjoerg public:
Linker(const ToolChain & TC)27*e038c9c4Sjoerg   Linker(const ToolChain &TC) : Tool("visualstudio::Linker", "linker", TC) {}
287330f729Sjoerg 
hasIntegratedCPP()297330f729Sjoerg   bool hasIntegratedCPP() const override { return false; }
isLinkJob()307330f729Sjoerg   bool isLinkJob() const override { return true; }
317330f729Sjoerg 
327330f729Sjoerg   void ConstructJob(Compilation &C, const JobAction &JA,
337330f729Sjoerg                     const InputInfo &Output, const InputInfoList &Inputs,
347330f729Sjoerg                     const llvm::opt::ArgList &TCArgs,
357330f729Sjoerg                     const char *LinkingOutput) const override;
367330f729Sjoerg };
377330f729Sjoerg } // end namespace visualstudio
387330f729Sjoerg 
397330f729Sjoerg } // end namespace tools
407330f729Sjoerg 
417330f729Sjoerg namespace toolchains {
427330f729Sjoerg 
437330f729Sjoerg class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
447330f729Sjoerg public:
457330f729Sjoerg   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
467330f729Sjoerg                 const llvm::opt::ArgList &Args);
477330f729Sjoerg 
487330f729Sjoerg   llvm::opt::DerivedArgList *
497330f729Sjoerg   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
507330f729Sjoerg                 Action::OffloadKind DeviceOffloadKind) const override;
517330f729Sjoerg 
527330f729Sjoerg   bool IsIntegratedAssemblerDefault() const override;
537330f729Sjoerg   bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
547330f729Sjoerg   bool isPICDefault() const override;
557330f729Sjoerg   bool isPIEDefault() const override;
567330f729Sjoerg   bool isPICDefaultForced() const override;
577330f729Sjoerg 
587330f729Sjoerg   /// Set CodeView as the default debug info format for non-MachO binary
597330f729Sjoerg   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
607330f729Sjoerg   /// override the default.
getDefaultDebugFormat()617330f729Sjoerg   codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
627330f729Sjoerg     return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
637330f729Sjoerg                                             : codegenoptions::DIF_CodeView;
647330f729Sjoerg   }
657330f729Sjoerg 
667330f729Sjoerg   /// Set the debugger tuning to "default", since we're definitely not tuning
677330f729Sjoerg   /// for GDB.
getDefaultDebuggerTuning()687330f729Sjoerg   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
697330f729Sjoerg     return llvm::DebuggerKind::Default;
707330f729Sjoerg   }
717330f729Sjoerg 
727330f729Sjoerg   enum class SubDirectoryType {
737330f729Sjoerg     Bin,
747330f729Sjoerg     Include,
757330f729Sjoerg     Lib,
767330f729Sjoerg   };
777330f729Sjoerg   std::string getSubDirectoryPath(SubDirectoryType Type,
787330f729Sjoerg                                   llvm::StringRef SubdirParent,
797330f729Sjoerg                                   llvm::Triple::ArchType TargetArch) const;
807330f729Sjoerg 
817330f729Sjoerg   // Convenience overload.
827330f729Sjoerg   // Uses the current target arch.
837330f729Sjoerg   std::string getSubDirectoryPath(SubDirectoryType Type,
847330f729Sjoerg                                   llvm::StringRef SubdirParent = "") const {
857330f729Sjoerg     return getSubDirectoryPath(Type, SubdirParent, getArch());
867330f729Sjoerg   }
877330f729Sjoerg 
887330f729Sjoerg   enum class ToolsetLayout {
897330f729Sjoerg     OlderVS,
907330f729Sjoerg     VS2017OrNewer,
917330f729Sjoerg     DevDivInternal,
927330f729Sjoerg   };
getIsVS2017OrNewer()937330f729Sjoerg   bool getIsVS2017OrNewer() const { return VSLayout == ToolsetLayout::VS2017OrNewer; }
947330f729Sjoerg 
957330f729Sjoerg   void
967330f729Sjoerg   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
977330f729Sjoerg                             llvm::opt::ArgStringList &CC1Args) const override;
987330f729Sjoerg   void AddClangCXXStdlibIncludeArgs(
997330f729Sjoerg       const llvm::opt::ArgList &DriverArgs,
1007330f729Sjoerg       llvm::opt::ArgStringList &CC1Args) const override;
1017330f729Sjoerg 
1027330f729Sjoerg   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
1037330f729Sjoerg                           llvm::opt::ArgStringList &CC1Args) const override;
1047330f729Sjoerg 
105*e038c9c4Sjoerg   void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
106*e038c9c4Sjoerg                          llvm::opt::ArgStringList &CC1Args) const override;
107*e038c9c4Sjoerg 
108*e038c9c4Sjoerg   bool getWindowsSDKLibraryPath(
109*e038c9c4Sjoerg       const llvm::opt::ArgList &Args, std::string &path) const;
110*e038c9c4Sjoerg   bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
111*e038c9c4Sjoerg                                   std::string &path) const;
1127330f729Sjoerg   bool useUniversalCRT() const;
1137330f729Sjoerg   VersionTuple
1147330f729Sjoerg   computeMSVCVersion(const Driver *D,
1157330f729Sjoerg                      const llvm::opt::ArgList &Args) const override;
1167330f729Sjoerg 
1177330f729Sjoerg   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
1187330f729Sjoerg                                           types::ID InputType) const override;
1197330f729Sjoerg   SanitizerMask getSupportedSanitizers() const override;
1207330f729Sjoerg 
1217330f729Sjoerg   void printVerboseInfo(raw_ostream &OS) const override;
1227330f729Sjoerg 
FoundMSVCInstall()1237330f729Sjoerg   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
1247330f729Sjoerg 
1257330f729Sjoerg protected:
1267330f729Sjoerg   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
1277330f729Sjoerg                                      llvm::opt::ArgStringList &CC1Args,
1287330f729Sjoerg                                      const std::string &folder,
1297330f729Sjoerg                                      const Twine &subfolder1,
1307330f729Sjoerg                                      const Twine &subfolder2 = "",
1317330f729Sjoerg                                      const Twine &subfolder3 = "") const;
1327330f729Sjoerg 
1337330f729Sjoerg   Tool *buildLinker() const override;
1347330f729Sjoerg   Tool *buildAssembler() const override;
1357330f729Sjoerg private:
1367330f729Sjoerg   std::string VCToolChainPath;
1377330f729Sjoerg   ToolsetLayout VSLayout = ToolsetLayout::OlderVS;
1387330f729Sjoerg   CudaInstallationDetector CudaInstallation;
139*e038c9c4Sjoerg   RocmInstallationDetector RocmInstallation;
1407330f729Sjoerg };
1417330f729Sjoerg 
1427330f729Sjoerg } // end namespace toolchains
1437330f729Sjoerg } // end namespace driver
1447330f729Sjoerg } // end namespace clang
1457330f729Sjoerg 
1467330f729Sjoerg #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
147