[llvm] r259279 - [CUDA] Die if we ask the NVPTX backend to emit a global ctor/dtor.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 17:07:38 PST 2016


Author: jlebar
Date: Fri Jan 29 19:07:38 2016
New Revision: 259279

URL: http://llvm.org/viewvc/llvm-project?rev=259279&view=rev
Log:
[CUDA] Die if we ask the NVPTX backend to emit a global ctor/dtor.

Summary: Previously we'd just silently skip these.

Reviewers: tra, jholewinski

Subscribers: llvm-commits, jhen, echristo,

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

Added:
    llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll
    llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll
    llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll
Modified:
    llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=259279&r1=259278&r2=259279&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Fri Jan 29 19:07:38 2016
@@ -802,6 +802,13 @@ void NVPTXAsmPrinter::recordAndEmitFilen
   }
 }
 
+static bool isEmptyXXStructor(GlobalVariable *GV) {
+  if (!GV) return true;
+  const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
+  if (!InitList) return true;  // Not an array; we don't know how to parse.
+  return InitList->getNumOperands() == 0;
+}
+
 bool NVPTXAsmPrinter::doInitialization(Module &M) {
   // Construct a default subtarget off of the TargetMachine defaults. The
   // rest of NVPTX isn't friendly to change subtargets per function and
@@ -816,6 +823,16 @@ bool NVPTXAsmPrinter::doInitialization(M
     report_fatal_error("Module has aliases, which NVPTX does not support.");
     return true; // error
   }
+  if (!isEmptyXXStructor(M.getNamedGlobal("llvm.global_ctors"))) {
+    report_fatal_error(
+        "Module has a nontrivial global ctor, which NVPTX does not support.");
+    return true;  // error
+  }
+  if (!isEmptyXXStructor(M.getNamedGlobal("llvm.global_dtors"))) {
+    report_fatal_error(
+        "Module has a nontrivial global dtor, which NVPTX does not support.");
+    return true;  // error
+  }
 
   SmallString<128> Str1;
   raw_svector_ostream OS1(Str1);

Added: llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll?rev=259279&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll (added)
+++ llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll Fri Jan 29 19:07:38 2016
@@ -0,0 +1,5 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 2>&1
+
+; Check that llc doesn't die when given an empty global ctor / dtor.
+ at llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] []
+ at llvm.global_dtors = appending global [0 x { i32, void ()*, i8* }] []

Added: llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll?rev=259279&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll (added)
+++ llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll Fri Jan 29 19:07:38 2016
@@ -0,0 +1,9 @@
+; RUN: not llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s
+
+; Check that llc dies when given a nonempty global ctor.
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
+
+; CHECK: ERROR: Module has a nontrivial global ctor
+define internal void @foo() {
+  ret void
+}

Added: llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll?rev=259279&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll (added)
+++ llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll Fri Jan 29 19:07:38 2016
@@ -0,0 +1,9 @@
+; RUN: not llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s
+
+; Check that llc dies when given a nonempty global dtor.
+ at llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
+
+; CHECK: ERROR: Module has a nontrivial global dtor
+define internal void @foo() {
+  ret void
+}




More information about the llvm-commits mailing list