From 8601733c1cec09bbda859129eb00a560dca034bb Mon Sep 17 00:00:00 2001 From: Artem Belevich Date: Tue, 17 Nov 2015 22:28:55 +0000 Subject: [CUDA] Make CUDA compilation usable by default. Currently clang requires several additional command line options in order to enable new features needed during CUDA compilation. This patch makes these options default. * Automatically include cuda_runtime.h if we've found a valid CUDA installation. * Disable automatic CUDA header inclusion during unit tests. * Added test case for command line construction. * Enabled target overloads and relaxed call checks that are needed in order to include CUDA headers. * Added CUDA-7.5 installation path to the CUDA installation search list. * Define __CUDA__ macro to indicate CUDA compilation. llvm-svn: 253389 --- clang/lib/Driver/ToolChains.cpp | 6 +++++- clang/lib/Driver/Tools.cpp | 2 ++ clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'clang/lib') diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 531e7900b11..78a611e56d4 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -1629,6 +1629,7 @@ void Generic_GCC::CudaInstallationDetector::init( Args.getLastArgValue(options::OPT_cuda_path_EQ)); else { CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); + CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); } @@ -4134,8 +4135,11 @@ void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, if (DriverArgs.hasArg(options::OPT_nocudainc)) return; - if (CudaInstallation.isValid()) + if (CudaInstallation.isValid()) { addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); + CC1Args.push_back("-include"); + CC1Args.push_back("cuda_runtime.h"); + } } bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 5df8efafd5a..ab85d0f65e6 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3292,6 +3292,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, assert(AuxToolChain != nullptr && "No aux toolchain."); CmdArgs.push_back("-aux-triple"); CmdArgs.push_back(Args.MakeArgString(AuxToolChain->getTriple().str())); + CmdArgs.push_back("-fcuda-target-overloads"); + CmdArgs.push_back("-fcuda-disable-target-call-checks"); } if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm || diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 30bf118bc29..15aa54607ce 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -411,6 +411,8 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI, // Not "standard" per se, but available even with the -undef flag. if (LangOpts.AsmPreprocessor) Builder.defineMacro("__ASSEMBLER__"); + if (LangOpts.CUDA) + Builder.defineMacro("__CUDA__"); } /// Initialize the predefined C++ language feature test macros defined in -- cgit v1.2.3