[PATCH] D12242: [NVPTX] Allow undef value as global initializer

Xuetian Weng via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 11:11:57 PDT 2015


wengxt updated this revision to Diff 32846.
wengxt added a comment.

update comments.


http://reviews.llvm.org/D12242

Files:
  lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  test/CodeGen/NVPTX/global-addrspace.ll

Index: test/CodeGen/NVPTX/global-addrspace.ll
===================================================================
--- /dev/null
+++ test/CodeGen/NVPTX/global-addrspace.ll
@@ -0,0 +1,12 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s --check-prefix=PTX32
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix=PTX64
+
+; PTX32: .visible .global .align 4 .u32 i;
+; PTX32: .visible .const .align 4 .u32 j;
+; PTX32: .visible .shared .align 4 .u32 k;
+; PTX64: .visible .global .align 4 .u32 i;
+; PTX64: .visible .const .align 4 .u32 j;
+; PTX64: .visible .shared .align 4 .u32 k;
+ at i = addrspace(1) externally_initialized global i32 0, align 4
+ at j = addrspace(4) externally_initialized global i32 0, align 4
+ at k = addrspace(3) global i32 undef, align 4
Index: lib/Target/NVPTX/NVPTXAsmPrinter.cpp
===================================================================
--- lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1183,9 +1183,11 @@
           printScalarConstant(Initializer, O);
         }
       } else {
-        // The frontend adds zero-initializer to variables that don't have an
-        // initial value, so skip warning for this case.
-        if (!GVar->getInitializer()->isNullValue()) {
+        // The frontend adds zero-initializer to device and constant variables
+        // that don't have an initial value, and UndefValue to shared
+        // variables, so skip warning for this case.
+        if (!GVar->getInitializer()->isNullValue() &&
+            !isa<UndefValue>(GVar->getInitializer())) {
           report_fatal_error("initial value of '" + GVar->getName() +
                              "' is not allowed in addrspace(" +
                              Twine(PTy->getAddressSpace()) + ")");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12242.32846.patch
Type: text/x-patch
Size: 1788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150821/18c049ba/attachment.bin>


More information about the llvm-commits mailing list