[PATCH] [NVPTX] aggregates of addrspacecast as initializer
Jingyue Wu
jingyue at google.com
Wed Apr 22 10:59:01 PDT 2015
Hi jholewinski, eliben,
Fixes a bug in NVPTXAsmPrinter on dealing with initializers that are aggregates
of addrspacecast. e.g.
constant {i32*, i32*} {null, addrspacecast(gep(...) to i32*)}
http://reviews.llvm.org/D9202
Files:
lib/Target/NVPTX/NVPTXAsmPrinter.h
test/CodeGen/NVPTX/addrspacecast-gvar.ll
Index: lib/Target/NVPTX/NVPTXAsmPrinter.h
===================================================================
--- lib/Target/NVPTX/NVPTXAsmPrinter.h
+++ lib/Target/NVPTX/NVPTXAsmPrinter.h
@@ -155,22 +155,28 @@
if (pos == nextSymbolPos) {
const Value *v = Symbols[nSym];
const Value *v0 = SymbolsBeforeStripping[nSym];
+ PointerType *PTy = dyn_cast<PointerType>(v0->getType());
+ bool IsNonGenericPointer = false; // Is v0 a non-generic pointer?
+ if (PTy && PTy->getAddressSpace() != 0) {
+ IsNonGenericPointer = true;
+ }
if (const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
MCSymbol *Name = AP.getSymbol(GVar);
- PointerType *PTy = dyn_cast<PointerType>(v0->getType());
- bool IsNonGenericPointer = false; // Is v0 a non-generic pointer?
- if (PTy && PTy->getAddressSpace() != 0) {
- IsNonGenericPointer = true;
- }
if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
O << "generic(";
O << *Name;
O << ")";
} else {
O << *Name;
}
} else if (const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(v)) {
- O << *AP.lowerConstant(Cexpr);
+ if (EmitGeneric && !IsNonGenericPointer) {
+ O << "generic(";
+ O << *AP.lowerConstant(Cexpr);
+ O << ")";
+ } else {
+ O << *AP.lowerConstant(Cexpr);
+ }
} else
llvm_unreachable("symbol type unknown");
nSym++;
Index: test/CodeGen/NVPTX/addrspacecast-gvar.ll
===================================================================
--- test/CodeGen/NVPTX/addrspacecast-gvar.ll
+++ test/CodeGen/NVPTX/addrspacecast-gvar.ll
@@ -4,8 +4,10 @@
; CHECK: .visible .global .align 4 .u32 g2 = generic(g);
; CHECK: .visible .global .align 4 .u32 g3 = g;
; CHECK: .visible .global .align 8 .u32 g4[2] = {0, generic(g)};
+; CHECK: .visible .global .align 8 .u32 g5[2] = {0, generic(g+8)};
@g = addrspace(1) global i32 42
@g2 = addrspace(1) global i32* addrspacecast (i32 addrspace(1)* @g to i32*)
@g3 = addrspace(1) global i32 addrspace(1)* @g
@g4 = constant {i32*, i32*} {i32* null, i32* addrspacecast (i32 addrspace(1)* @g to i32*)}
+ at g5 = constant {i32*, i32*} {i32* null, i32* addrspacecast (i32 addrspace(1)* getelementptr (i32, i32 addrspace(1)* @g, i32 2) to i32*)}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9202.24244.patch
Type: text/x-patch
Size: 2585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150422/a46c0140/attachment.bin>
More information about the llvm-commits
mailing list