PTX: Emit global arrays with proper sizes

- Emit all arrays as type .b8 and proper sizes in bytes to conform
  to the output of nvcc

llvm-svn: 127584
This commit is contained in:
Justin Holewinski 2011-03-14 15:40:11 +00:00
parent 0a36f4d654
commit fbc8d301bf
3 changed files with 74 additions and 45 deletions

View File

@ -316,13 +316,42 @@ void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) {
decl += " ";
}
decl += getTypeName(gv->getType());
decl += " ";
decl += gvsym->getName();
if (PointerType::classof(gv->getType())) {
const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
const Type* elementTy = pointerTy->getElementType();
if (ArrayType::classof(gv->getType()) || PointerType::classof(gv->getType()))
decl += "[]";
assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
elementTy = arrayTy->getElementType();
// FIXME: isPrimitiveType() == false for i16?
assert(elementTy->isSingleValueType() &&
"Non-primitive types are not handled");
// Compute the size of the array, in bytes.
uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
* arrayTy->getNumElements();
decl += ".b8 ";
decl += gvsym->getName();
decl += "[";
decl += utostr(arraySize);
decl += "]";
}
else {
// Note: this is currently the fall-through case and most likely generates
// incorrect code.
decl += getTypeName(gv->getType());
decl += " ";
decl += gvsym->getName();
if (ArrayType::classof(gv->getType()) ||
PointerType::classof(gv->getType()))
decl += "[]";
}
decl += ";";

View File

@ -1,63 +1,63 @@
; RUN: llc < %s -march=ptx | FileCheck %s
;CHECK: .extern .global .u16 array_i16[];
;CHECK: .extern .global .b8 array_i16[20];
@array_i16 = external global [10 x i16]
;CHECK: .extern .const .u16 array_constant_i16[];
;CHECK: .extern .const .b8 array_constant_i16[20];
@array_constant_i16 = external addrspace(1) constant [10 x i16]
;CHECK: .extern .local .u16 array_local_i16[];
;CHECK: .extern .local .b8 array_local_i16[20];
@array_local_i16 = external addrspace(2) global [10 x i16]
;CHECK: .extern .shared .u16 array_shared_i16[];
;CHECK: .extern .shared .b8 array_shared_i16[20];
@array_shared_i16 = external addrspace(4) global [10 x i16]
;CHECK: .extern .global .u32 array_i32[];
;CHECK: .extern .global .b8 array_i32[40];
@array_i32 = external global [10 x i32]
;CHECK: .extern .const .u32 array_constant_i32[];
;CHECK: .extern .const .b8 array_constant_i32[40];
@array_constant_i32 = external addrspace(1) constant [10 x i32]
;CHECK: .extern .local .u32 array_local_i32[];
;CHECK: .extern .local .b8 array_local_i32[40];
@array_local_i32 = external addrspace(2) global [10 x i32]
;CHECK: .extern .shared .u32 array_shared_i32[];
;CHECK: .extern .shared .b8 array_shared_i32[40];
@array_shared_i32 = external addrspace(4) global [10 x i32]
;CHECK: .extern .global .u64 array_i64[];
;CHECK: .extern .global .b8 array_i64[80];
@array_i64 = external global [10 x i64]
;CHECK: .extern .const .u64 array_constant_i64[];
;CHECK: .extern .const .b8 array_constant_i64[80];
@array_constant_i64 = external addrspace(1) constant [10 x i64]
;CHECK: .extern .local .u64 array_local_i64[];
;CHECK: .extern .local .b8 array_local_i64[80];
@array_local_i64 = external addrspace(2) global [10 x i64]
;CHECK: .extern .shared .u64 array_shared_i64[];
;CHECK: .extern .shared .b8 array_shared_i64[80];
@array_shared_i64 = external addrspace(4) global [10 x i64]
;CHECK: .extern .global .f32 array_float[];
;CHECK: .extern .global .b8 array_float[40];
@array_float = external global [10 x float]
;CHECK: .extern .const .f32 array_constant_float[];
;CHECK: .extern .const .b8 array_constant_float[40];
@array_constant_float = external addrspace(1) constant [10 x float]
;CHECK: .extern .local .f32 array_local_float[];
;CHECK: .extern .local .b8 array_local_float[40];
@array_local_float = external addrspace(2) global [10 x float]
;CHECK: .extern .shared .f32 array_shared_float[];
;CHECK: .extern .shared .b8 array_shared_float[40];
@array_shared_float = external addrspace(4) global [10 x float]
;CHECK: .extern .global .f64 array_double[];
;CHECK: .extern .global .b8 array_double[80];
@array_double = external global [10 x double]
;CHECK: .extern .const .f64 array_constant_double[];
;CHECK: .extern .const .b8 array_constant_double[80];
@array_constant_double = external addrspace(1) constant [10 x double]
;CHECK: .extern .local .f64 array_local_double[];
;CHECK: .extern .local .b8 array_local_double[80];
@array_local_double = external addrspace(2) global [10 x double]
;CHECK: .extern .shared .f64 array_shared_double[];
;CHECK: .extern .shared .b8 array_shared_double[80];
@array_shared_double = external addrspace(4) global [10 x double]

View File

@ -1,63 +1,63 @@
; RUN: llc < %s -march=ptx | FileCheck %s
;CHECK: .extern .global .u16 array_i16[];
;CHECK: .extern .global .b8 array_i16[20];
@array_i16 = external global [10 x i16]
;CHECK: .extern .const .u16 array_constant_i16[];
;CHECK: .extern .const .b8 array_constant_i16[20];
@array_constant_i16 = external addrspace(1) constant [10 x i16]
;CHECK: .extern .local .u16 array_local_i16[];
;CHECK: .extern .local .b8 array_local_i16[20];
@array_local_i16 = external addrspace(2) global [10 x i16]
;CHECK: .extern .shared .u16 array_shared_i16[];
;CHECK: .extern .shared .b8 array_shared_i16[20];
@array_shared_i16 = external addrspace(4) global [10 x i16]
;CHECK: .extern .global .u32 array_i32[];
;CHECK: .extern .global .b8 array_i32[40];
@array_i32 = external global [10 x i32]
;CHECK: .extern .const .u32 array_constant_i32[];
;CHECK: .extern .const .b8 array_constant_i32[40];
@array_constant_i32 = external addrspace(1) constant [10 x i32]
;CHECK: .extern .local .u32 array_local_i32[];
;CHECK: .extern .local .b8 array_local_i32[40];
@array_local_i32 = external addrspace(2) global [10 x i32]
;CHECK: .extern .shared .u32 array_shared_i32[];
;CHECK: .extern .shared .b8 array_shared_i32[40];
@array_shared_i32 = external addrspace(4) global [10 x i32]
;CHECK: .extern .global .u64 array_i64[];
;CHECK: .extern .global .b8 array_i64[80];
@array_i64 = external global [10 x i64]
;CHECK: .extern .const .u64 array_constant_i64[];
;CHECK: .extern .const .b8 array_constant_i64[80];
@array_constant_i64 = external addrspace(1) constant [10 x i64]
;CHECK: .extern .local .u64 array_local_i64[];
;CHECK: .extern .local .b8 array_local_i64[80];
@array_local_i64 = external addrspace(2) global [10 x i64]
;CHECK: .extern .shared .u64 array_shared_i64[];
;CHECK: .extern .shared .b8 array_shared_i64[80];
@array_shared_i64 = external addrspace(4) global [10 x i64]
;CHECK: .extern .global .f32 array_float[];
;CHECK: .extern .global .b8 array_float[40];
@array_float = external global [10 x float]
;CHECK: .extern .const .f32 array_constant_float[];
;CHECK: .extern .const .b8 array_constant_float[40];
@array_constant_float = external addrspace(1) constant [10 x float]
;CHECK: .extern .local .f32 array_local_float[];
;CHECK: .extern .local .b8 array_local_float[40];
@array_local_float = external addrspace(2) global [10 x float]
;CHECK: .extern .shared .f32 array_shared_float[];
;CHECK: .extern .shared .b8 array_shared_float[40];
@array_shared_float = external addrspace(4) global [10 x float]
;CHECK: .extern .global .f64 array_double[];
;CHECK: .extern .global .b8 array_double[80];
@array_double = external global [10 x double]
;CHECK: .extern .const .f64 array_constant_double[];
;CHECK: .extern .const .b8 array_constant_double[80];
@array_constant_double = external addrspace(1) constant [10 x double]
;CHECK: .extern .local .f64 array_local_double[];
;CHECK: .extern .local .b8 array_local_double[80];
@array_local_double = external addrspace(2) global [10 x double]
;CHECK: .extern .shared .f64 array_shared_double[];
;CHECK: .extern .shared .b8 array_shared_double[80];
@array_shared_double = external addrspace(4) global [10 x double]