[llvm] r211943 - [NVPTX] Error out if initializer is given for variable in an address space that does not support initialization

Justin Holewinski jholewinski at nvidia.com
Fri Jun 27 11:36:01 PDT 2014


Author: jholewinski
Date: Fri Jun 27 13:36:01 2014
New Revision: 211943

URL: http://llvm.org/viewvc/llvm-project?rev=211943&view=rev
Log:
[NVPTX] Error out if initializer is given for variable in an address space that does not support initialization

Added:
    llvm/trunk/test/CodeGen/NVPTX/gvar-init.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=211943&r1=211942&r2=211943&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Fri Jun 27 13:36:01 2014
@@ -1502,13 +1502,24 @@ void NVPTXAsmPrinter::printModuleLevelGV
 
     // Ptx allows variable initilization only for constant and global state
     // spaces.
-    if (((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
-         (PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) &&
-        GVar->hasInitializer()) {
-      const Constant *Initializer = GVar->getInitializer();
-      if (!Initializer->isNullValue()) {
-        O << " = ";
-        printScalarConstant(Initializer, O);
+    if (GVar->hasInitializer()) {
+      if ((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
+          (PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) {
+        const Constant *Initializer = GVar->getInitializer();
+        // 'undef' is treated as there is no value spefied.
+        if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
+          O << " = ";
+          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()) {
+          std::string warnMsg = "initial value of '" + GVar->getName().str() +
+              "' is not allowed in addrspace(" +
+              llvm::utostr_32(PTy->getAddressSpace()) + ")";
+          report_fatal_error(warnMsg.c_str());
+        }
       }
     }
   } else {

Added: llvm/trunk/test/CodeGen/NVPTX/gvar-init.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/gvar-init.ll?rev=211943&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/gvar-init.ll (added)
+++ llvm/trunk/test/CodeGen/NVPTX/gvar-init.ll Fri Jun 27 13:36:01 2014
@@ -0,0 +1,5 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
+
+; Error out if initializer is given for address spaces that do not support initializers
+; XFAIL: *
+ at g0 = addrspace(3) global i32 42





More information about the llvm-commits mailing list