Index: include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- include/clang/Basic/DiagnosticDriverKinds.td +++ include/clang/Basic/DiagnosticDriverKinds.td @@ -196,6 +196,9 @@ def warn_drv_omp_offload_target_duplicate : Warning< "The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">, InGroup; +def remark_drv_omp_offload_target_missingbcruntime : Warning< + "Expect degraded performance on the target device due to missing libomptarget-nvptx.bc in library path.">, + InGroup; def err_drv_bitcode_unsupported_on_toolchain : Error< "-fembed-bitcode is not supported on versions of iOS prior to 6.0">; Index: lib/Driver/ToolChains/Cuda.cpp =================================================================== --- lib/Driver/ToolChains/Cuda.cpp +++ lib/Driver/ToolChains/Cuda.cpp @@ -529,6 +529,35 @@ CC1Args.push_back("-target-feature"); CC1Args.push_back("+ptx42"); } + + if (DeviceOffloadingKind == Action::OFK_OpenMP) { + SmallVector LibraryPaths; + if (char *env = ::getenv("LIBRARY_PATH")) { + StringRef CompilerPath = env; + while (!CompilerPath.empty()) { + std::pair Split = + CompilerPath.split(llvm::sys::EnvPathSeparator); + LibraryPaths.push_back(Split.first); + CompilerPath = Split.second; + } + } + + std::string LibOmpTargetName = + "libomptarget-nvptx-" + GpuArch.str() + ".bc"; + bool FoundBCLibrary = false; + for (std::string LibraryPath : LibraryPaths) { + SmallString<128> LibOmpTargetFile(LibraryPath); + llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName); + if (llvm::sys::fs::exists(LibOmpTargetFile)) { + CC1Args.push_back("-mlink-cuda-bitcode"); + CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile)); + FoundBCLibrary = true; + break; + } + } + if (!FoundBCLibrary) + getDriver().Diag(diag::remark_drv_omp_offload_target_missingbcruntime); + } } void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,