[llvm] r292316 - [NVPTX] Support global variables of integer type larger than i64.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 16:29:53 PST 2017


Author: jlebar
Date: Tue Jan 17 18:29:53 2017
New Revision: 292316

URL: http://llvm.org/viewvc/llvm-project?rev=292316&view=rev
Log:
[NVPTX] Support global variables of integer type larger than i64.

Reviewers: tra, majnemer

Subscribers: llvm-commits, jholewinski

Differential Revision: https://reviews.llvm.org/D28825

Added:
    llvm/trunk/test/CodeGen/NVPTX/global-variable-big.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=292316&r1=292315&r2=292316&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Tue Jan 17 18:29:53 2017
@@ -1230,7 +1230,8 @@ void NVPTXAsmPrinter::printModuleLevelGV
   else
     O << " .align " << GVar->getAlignment();
 
-  if (ETy->isFloatingPointTy() || ETy->isIntegerTy() || ETy->isPointerTy()) {
+  if (ETy->isFloatingPointTy() || ETy->isPointerTy() ||
+      (ETy->isIntegerTy() && ETy->getScalarSizeInBits() <= 64)) {
     O << " .";
     // Special case: ABI requires that we use .u8 for predicates
     if (ETy->isIntegerTy(1))
@@ -1271,6 +1272,7 @@ void NVPTXAsmPrinter::printModuleLevelGV
     // targets that support these high level field accesses. Structs, arrays
     // and vectors are lowered into arrays of bytes.
     switch (ETy->getTypeID()) {
+    case Type::IntegerTyID: // Integers larger than 64 bits
     case Type::StructTyID:
     case Type::ArrayTyID:
     case Type::VectorTyID:
@@ -1994,6 +1996,17 @@ void NVPTXAsmPrinter::bufferAggregateCon
   const DataLayout &DL = getDataLayout();
   int Bytes;
 
+  // Integers of arbitrary width
+  if (const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
+    APInt Val = CI->getValue();
+    for (unsigned I = 0, E = DL.getTypeAllocSize(CPV->getType()); I < E; ++I) {
+      uint8_t Byte = Val.getLoBits(8).getZExtValue();
+      aggBuffer->addBytes(&Byte, 1, 1);
+      Val = Val.lshr(8);
+    }
+    return;
+  }
+
   // Old constants
   if (isa<ConstantArray>(CPV) || isa<ConstantVector>(CPV)) {
     if (CPV->getNumOperands())

Added: llvm/trunk/test/CodeGen/NVPTX/global-variable-big.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/global-variable-big.ll?rev=292316&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-variable-big.ll (added)
+++ llvm/trunk/test/CodeGen/NVPTX/global-variable-big.ll Tue Jan 17 18:29:53 2017
@@ -0,0 +1,9 @@
+; RUN: llc < %s | FileCheck %s
+target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
+target triple = "nvptx64-nvidia-cuda"
+
+; Check that we can handle global variables of large integer type.
+
+; (lsb) 0x0102'0304'0506...0F10 (msb)
+ at gv = addrspace(1) externally_initialized global i128 21345817372864405881847059188222722561, align 16
+; CHECK: .visible .global .align 16 .b8 gv[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};




More information about the llvm-commits mailing list