diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 41 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains.h | 4 |
2 files changed, 45 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 34504732a12..531e7900b11 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -1647,6 +1647,31 @@ void Generic_GCC::CudaInstallationDetector::init( D.getVFS().exists(CudaLibDevicePath))) continue; + std::error_code EC; + for (llvm::sys::fs::directory_iterator LI(CudaLibDevicePath, EC), LE; + !EC && LI != LE; LI = LI.increment(EC)) { + StringRef FilePath = LI->path(); + StringRef FileName = llvm::sys::path::filename(FilePath); + // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc + const StringRef LibDeviceName = "libdevice."; + if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) + continue; + StringRef GpuArch = FileName.slice( + LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); + CudaLibDeviceMap[GpuArch] = FilePath.str(); + // Insert map entries for specifc devices with this compute capability. + if (GpuArch == "compute_20") { + CudaLibDeviceMap["sm_20"] = FilePath; + CudaLibDeviceMap["sm_21"] = FilePath; + } else if (GpuArch == "compute_30") { + CudaLibDeviceMap["sm_30"] = FilePath; + CudaLibDeviceMap["sm_32"] = FilePath; + } else if (GpuArch == "compute_35") { + CudaLibDeviceMap["sm_35"] = FilePath; + CudaLibDeviceMap["sm_37"] = FilePath; + } + } + IsValid = true; break; } @@ -4195,6 +4220,22 @@ CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { Linux::addClangTargetOptions(DriverArgs, CC1Args); CC1Args.push_back("-fcuda-is-device"); + + if (DriverArgs.hasArg(options::OPT_nocudalib)) + return; + + std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( + DriverArgs.getLastArgValue(options::OPT_march_EQ)); + if (!LibDeviceFile.empty()) { + CC1Args.push_back("-mlink-cuda-bitcode"); + CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); + + // Libdevice in CUDA-7.0 requires PTX version that's more recent + // than LLVM defaults to. Use PTX4.2 which is the PTX version that + // came with CUDA-7.0. + CC1Args.push_back("-target-feature"); + CC1Args.push_back("+ptx42"); + } } llvm::opt::DerivedArgList * diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index b1b670feb85..b18739ce393 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -166,6 +166,7 @@ protected: std::string CudaLibPath; std::string CudaLibDevicePath; std::string CudaIncludePath; + llvm::StringMap<std::string> CudaLibDeviceMap; public: CudaInstallationDetector(const Driver &D) : IsValid(false), D(D) {} @@ -185,6 +186,9 @@ protected: /// \brief Get the detected Cuda device library path. StringRef getLibDevicePath() const { return CudaLibDevicePath; } /// \brief Get libdevice file for given architecture + StringRef getLibDeviceFile(StringRef Gpu) const { + return CudaLibDeviceMap.lookup(Gpu); + } }; CudaInstallationDetector CudaInstallation; |

