r218688 - CUDA: mark the target of implicit intrinsics properly

Eli Bendersky eliben at google.com
Tue Sep 30 10:38:35 PDT 2014


Author: eliben
Date: Tue Sep 30 12:38:34 2014
New Revision: 218688

URL: http://llvm.org/viewvc/llvm-project?rev=218688&view=rev
Log:
CUDA: mark the target of implicit intrinsics properly

r218624 implemented target inference for implicit special members. However,
other entities can be implicit - for example intrinsics. These can not have
inference running on them, so they should be marked host device as before. This
is the safest and most flexible setting, since by construction these functions
don't invoke anything, and we'd like them to be invokable from both host and
device code. LLVM's intrinsics definitions (where these intrinsics come from in
the case of CUDA/NVPTX) have no notion of target, so both host and device
intrinsics can be supported this way.


Added:
    cfe/trunk/test/SemaCUDA/implicit-intrinsic.cu
Modified:
    cfe/trunk/lib/Sema/SemaCUDA.cpp

Modified: cfe/trunk/lib/Sema/SemaCUDA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCUDA.cpp?rev=218688&r1=218687&r2=218688&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCUDA.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp Tue Sep 30 12:38:34 2014
@@ -48,6 +48,12 @@ Sema::CUDAFunctionTarget Sema::IdentifyC
     if (D->hasAttr<CUDAHostAttr>())
       return CFT_HostDevice;
     return CFT_Device;
+  } else if (D->hasAttr<CUDAHostAttr>()) {
+    return CFT_Host;
+  } else if (D->isImplicit()) {
+    // Some implicit declarations (like intrinsic functions) are not marked.
+    // Set the most lenient target on them for maximal flexibility.
+    return CFT_HostDevice;
   }
 
   return CFT_Host;

Added: cfe/trunk/test/SemaCUDA/implicit-intrinsic.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/implicit-intrinsic.cu?rev=218688&view=auto
==============================================================================
--- cfe/trunk/test/SemaCUDA/implicit-intrinsic.cu (added)
+++ cfe/trunk/test/SemaCUDA/implicit-intrinsic.cu Tue Sep 30 12:38:34 2014
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=gnu++11 -triple nvptx64-unknown-unknown -fsyntax-only -verify %s
+
+#include "Inputs/cuda.h"
+
+// expected-no-diagnostics
+__device__ void __threadfence_system() {
+  // This shouldn't produce an error, since __nvvm_membar_sys is inferred to
+  // be __host__ __device__ and thus callable from device code.
+  __nvvm_membar_sys();
+}





More information about the cfe-commits mailing list