]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Driver/ToolChains/Cuda.h
Merge ACPICA 20170728.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Driver / ToolChains / Cuda.h
1 //===--- Cuda.h - Cuda ToolChain Implementations ----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
12
13 #include "clang/Basic/Cuda.h"
14 #include "clang/Basic/VersionTuple.h"
15 #include "clang/Driver/Action.h"
16 #include "clang/Driver/Multilib.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "clang/Driver/Tool.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallSet.h"
21 #include "llvm/Support/Compiler.h"
22 #include <set>
23 #include <vector>
24
25 namespace clang {
26 namespace driver {
27
28 /// A class to find a viable CUDA installation
29 class CudaInstallationDetector {
30 private:
31   const Driver &D;
32   bool IsValid = false;
33   CudaVersion Version = CudaVersion::UNKNOWN;
34   std::string InstallPath;
35   std::string BinPath;
36   std::string LibPath;
37   std::string LibDevicePath;
38   std::string IncludePath;
39   llvm::StringMap<std::string> LibDeviceMap;
40
41   // CUDA architectures for which we have raised an error in
42   // CheckCudaVersionSupportsArch.
43   mutable llvm::SmallSet<CudaArch, 4> ArchsWithVersionTooLowErrors;
44
45 public:
46   CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
47                            const llvm::opt::ArgList &Args);
48
49   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
50                           llvm::opt::ArgStringList &CC1Args) const;
51
52   /// \brief Emit an error if Version does not support the given Arch.
53   ///
54   /// If either Version or Arch is unknown, does not emit an error.  Emits at
55   /// most one error per Arch.
56   void CheckCudaVersionSupportsArch(CudaArch Arch) const;
57
58   /// \brief Check whether we detected a valid Cuda install.
59   bool isValid() const { return IsValid; }
60   /// \brief Print information about the detected CUDA installation.
61   void print(raw_ostream &OS) const;
62
63   /// \brief Get the detected Cuda install's version.
64   CudaVersion version() const { return Version; }
65   /// \brief Get the detected Cuda installation path.
66   StringRef getInstallPath() const { return InstallPath; }
67   /// \brief Get the detected path to Cuda's bin directory.
68   StringRef getBinPath() const { return BinPath; }
69   /// \brief Get the detected Cuda Include path.
70   StringRef getIncludePath() const { return IncludePath; }
71   /// \brief Get the detected Cuda library path.
72   StringRef getLibPath() const { return LibPath; }
73   /// \brief Get the detected Cuda device library path.
74   StringRef getLibDevicePath() const { return LibDevicePath; }
75   /// \brief Get libdevice file for given architecture
76   std::string getLibDeviceFile(StringRef Gpu) const {
77     return LibDeviceMap.lookup(Gpu);
78   }
79 };
80
81 namespace tools {
82 namespace NVPTX {
83
84 // Run ptxas, the NVPTX assembler.
85 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
86  public:
87    Assembler(const ToolChain &TC)
88        : Tool("NVPTX::Assembler", "ptxas", TC, RF_Full, llvm::sys::WEM_UTF8,
89               "--options-file") {}
90
91    bool hasIntegratedCPP() const override { return false; }
92
93    void ConstructJob(Compilation &C, const JobAction &JA,
94                      const InputInfo &Output, const InputInfoList &Inputs,
95                      const llvm::opt::ArgList &TCArgs,
96                      const char *LinkingOutput) const override;
97 };
98
99 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
100 // assembly into a single output file.
101 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
102  public:
103    Linker(const ToolChain &TC)
104        : Tool("NVPTX::Linker", "fatbinary", TC, RF_Full, llvm::sys::WEM_UTF8,
105               "--options-file") {}
106
107    bool hasIntegratedCPP() const override { return false; }
108
109    void ConstructJob(Compilation &C, const JobAction &JA,
110                      const InputInfo &Output, const InputInfoList &Inputs,
111                      const llvm::opt::ArgList &TCArgs,
112                      const char *LinkingOutput) const override;
113 };
114
115 } // end namespace NVPTX
116 } // end namespace tools
117
118 namespace toolchains {
119
120 class LLVM_LIBRARY_VISIBILITY CudaToolChain : public ToolChain {
121 public:
122   CudaToolChain(const Driver &D, const llvm::Triple &Triple,
123                 const ToolChain &HostTC, const llvm::opt::ArgList &Args);
124
125   virtual const llvm::Triple *getAuxTriple() const override {
126     return &HostTC.getTriple();
127   }
128
129   llvm::opt::DerivedArgList *
130   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
131                 Action::OffloadKind DeviceOffloadKind) const override;
132   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
133                              llvm::opt::ArgStringList &CC1Args,
134                              Action::OffloadKind DeviceOffloadKind) const override;
135
136   // Never try to use the integrated assembler with CUDA; always fork out to
137   // ptxas.
138   bool useIntegratedAs() const override { return false; }
139   bool isCrossCompiling() const override { return true; }
140   bool isPICDefault() const override { return false; }
141   bool isPIEDefault() const override { return false; }
142   bool isPICDefaultForced() const override { return false; }
143   bool SupportsProfiling() const override { return false; }
144   bool SupportsObjCGC() const override { return false; }
145
146   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
147                           llvm::opt::ArgStringList &CC1Args) const override;
148
149   void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
150   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
151   void
152   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
153                             llvm::opt::ArgStringList &CC1Args) const override;
154   void AddClangCXXStdlibIncludeArgs(
155       const llvm::opt::ArgList &Args,
156       llvm::opt::ArgStringList &CC1Args) const override;
157   void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
158                            llvm::opt::ArgStringList &CC1Args) const override;
159
160   SanitizerMask getSupportedSanitizers() const override;
161
162   VersionTuple
163   computeMSVCVersion(const Driver *D,
164                      const llvm::opt::ArgList &Args) const override;
165
166   const ToolChain &HostTC;
167   CudaInstallationDetector CudaInstallation;
168
169 protected:
170   Tool *buildAssembler() const override;  // ptxas
171   Tool *buildLinker() const override;     // fatbinary (ok, not really a linker)
172 };
173
174 } // end namespace toolchains
175 } // end namespace driver
176 } // end namespace clang
177
178 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H