r235905 - [cuda] treat file scope __asm as __host__ and ignore it during device-side compilation.

Artem Belevich tra at google.com
Mon Apr 27 11:52:00 PDT 2015

Author: tra
Date: Mon Apr 27 13:52:00 2015
New Revision: 235905

URL: http://llvm.org/viewvc/llvm-project?rev=235905&view=rev
[cuda] treat file scope __asm as __host__ and ignore it during device-side compilation.

Currently clang emits file-scope asm during *both* host and device
compilation modes which is usually a wrong thing to do.

There's no way to attach any attribute to an __asm statement, so
there's no way to differentiate between host-side and device-side
file-scope asm.  This patch makes clang to match nvcc behavior and
emit file-scope-asm only during host-side compilation.

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


Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=235905&r1=235904&r2=235905&view=diff
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 27 13:52:00 2015
@@ -3356,6 +3356,9 @@ void CodeGenModule::EmitTopLevelDecl(Dec
   case Decl::FileScopeAsm: {
+    // File-scope asm is ignored during device-side CUDA compilation.
+    if (LangOpts.CUDA && LangOpts.CUDAIsDevice)
+      break;
     auto *AD = cast<FileScopeAsmDecl>(D);

Modified: cfe/trunk/test/CodeGenCUDA/filter-decl.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/filter-decl.cu?rev=235905&r1=235904&r2=235905&view=diff
--- cfe/trunk/test/CodeGenCUDA/filter-decl.cu (original)
+++ cfe/trunk/test/CodeGenCUDA/filter-decl.cu Mon Apr 27 13:52:00 2015
@@ -3,6 +3,12 @@
 #include "Inputs/cuda.h"
+// This has to be at the top of the file as that's where file-scope
+// asm ends up.
+// CHECK-HOST: module asm "file scope asm is host only"
+// CHECK-DEVICE-NOT: module asm "file scope asm is host only"
+__asm__("file scope asm is host only");
 // CHECK-HOST-NOT: constantdata = global
 // CHECK-DEVICE: constantdata = global
 __constant__ char constantdata[256];

More information about the cfe-commits mailing list