llvm.org GIT mirror llvm / b31edea
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259279 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Lebar 4 years ago
4 changed file(s) with 40 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
801801 }
802802 }
803803
804 static bool isEmptyXXStructor(GlobalVariable *GV) {
805 if (!GV) return true;
806 const ConstantArray *InitList = dyn_cast(GV->getInitializer());
807 if (!InitList) return true; // Not an array; we don't know how to parse.
808 return InitList->getNumOperands() == 0;
809 }
810
804811 bool NVPTXAsmPrinter::doInitialization(Module &M) {
805812 // Construct a default subtarget off of the TargetMachine defaults. The
806813 // rest of NVPTX isn't friendly to change subtargets per function and
814821 if (M.alias_size()) {
815822 report_fatal_error("Module has aliases, which NVPTX does not support.");
816823 return true; // error
824 }
825 if (!isEmptyXXStructor(M.getNamedGlobal("llvm.global_ctors"))) {
826 report_fatal_error(
827 "Module has a nontrivial global ctor, which NVPTX does not support.");
828 return true; // error
829 }
830 if (!isEmptyXXStructor(M.getNamedGlobal("llvm.global_dtors"))) {
831 report_fatal_error(
832 "Module has a nontrivial global dtor, which NVPTX does not support.");
833 return true; // error
817834 }
818835
819836 SmallString<128> Str1;
0 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 2>&1
1
2 ; Check that llc doesn't die when given an empty global ctor / dtor.
3 @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] []
4 @llvm.global_dtors = appending global [0 x { i32, void ()*, i8* }] []
0 ; RUN: not llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s
1
2 ; Check that llc dies when given a nonempty global ctor.
3 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
4
5 ; CHECK: ERROR: Module has a nontrivial global ctor
6 define internal void @foo() {
7 ret void
8 }
0 ; RUN: not llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s
1
2 ; Check that llc dies when given a nonempty global dtor.
3 @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
4
5 ; CHECK: ERROR: Module has a nontrivial global dtor
6 define internal void @foo() {
7 ret void
8 }