r264965 - [CUDA] Don't initialize the CUDA toolchain if we don't have any CUDA inputs.

Justin Lebar via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 30 16:30:25 PDT 2016


Author: jlebar
Date: Wed Mar 30 18:30:25 2016
New Revision: 264965

URL: http://llvm.org/viewvc/llvm-project?rev=264965&view=rev
Log:
[CUDA] Don't initialize the CUDA toolchain if we don't have any CUDA inputs.

Summary:
This prevents errors when you invoke clang with a flag that the NVPTX
toolchain doesn't support.  For example, on x86-64,

  clang -mthread-model single -x c++ /dev/null -o /dev/null

should output just one error about "invalid thread model 'single' in
'-mthread-model single' for this target"; x86-64 doesn't support
-mthread-model, but we shouldn't also instantiate a NVPTX target!

Reviewers: echristo

Subscribers: tra, sunfish, cfe-commits

Differential Revision: http://reviews.llvm.org/D18629

Modified:
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=264965&r1=264964&r2=264965&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Mar 30 18:30:25 2016
@@ -507,10 +507,6 @@ Compilation *Driver::BuildCompilation(Ar
   // The compilation takes ownership of Args.
   Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs);
 
-  C->setCudaDeviceToolChain(
-      &getToolChain(C->getArgs(), llvm::Triple(TC.getTriple().isArch64Bit()
-                                                   ? "nvptx64-nvidia-cuda"
-                                                   : "nvptx-nvidia-cuda")));
   if (!HandleImmediateArgs(*C))
     return C;
 
@@ -518,6 +514,19 @@ Compilation *Driver::BuildCompilation(Ar
   InputList Inputs;
   BuildInputs(C->getDefaultToolChain(), *TranslatedArgs, Inputs);
 
+  // Initialize the CUDA device TC only if we have any CUDA Inputs.  This is
+  // necessary so that we don't break compilations that pass flags that are
+  // incompatible with the NVPTX TC (e.g. -mthread-model single).
+  if (llvm::any_of(Inputs, [](const std::pair<types::ID, const Arg *> &I) {
+        return I.first == types::TY_CUDA || I.first == types::TY_PP_CUDA ||
+               I.first == types::TY_CUDA_DEVICE;
+      })) {
+    C->setCudaDeviceToolChain(
+        &getToolChain(C->getArgs(), llvm::Triple(TC.getTriple().isArch64Bit()
+                                                     ? "nvptx64-nvidia-cuda"
+                                                     : "nvptx-nvidia-cuda")));
+  }
+
   // Construct the list of abstract actions to perform for this compilation. On
   // MachO targets this uses the driver-driver and universal actions.
   if (TC.getTriple().isOSBinFormatMachO())




More information about the cfe-commits mailing list