[llvm] r235689 - [NVPTX] Emits "generic()" depending on the original address space
Jingyue Wu
jingyue at google.com
Thu Apr 23 19:57:31 PDT 2015
Author: jingyue
Date: Thu Apr 23 21:57:30 2015
New Revision: 235689
URL: http://llvm.org/viewvc/llvm-project?rev=235689&view=rev
Log:
[NVPTX] Emits "generic()" depending on the original address space
Summary:
Fixes a bug in the NVPTX codegen. The code used to miss necessary "generic()"
on aggregates of addrspacecasts.
Test Plan: addrspacecast-gvar.ll
Reviewers: eliben, jholewinski
Reviewed By: jholewinski
Subscribers: jholewinski, llvm-commits
Differential Revision: http://reviews.llvm.org/D9130
Modified:
llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.h
llvm/trunk/test/CodeGen/NVPTX/addrspacecast-gvar.ll
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=235689&r1=235688&r2=235689&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Thu Apr 23 21:57:30 2015
@@ -1179,7 +1179,7 @@ void NVPTXAsmPrinter::printModuleLevelGV
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.
+ // 'undef' is treated as there is no value specified.
if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
O << " = ";
printScalarConstant(Initializer, O);
@@ -1788,7 +1788,7 @@ void NVPTXAsmPrinter::bufferLEByte(const
}
if (Cexpr->getOpcode() == Instruction::PtrToInt) {
Value *v = Cexpr->getOperand(0)->stripPointerCasts();
- aggBuffer->addSymbol(v);
+ aggBuffer->addSymbol(v, Cexpr->getOperand(0));
aggBuffer->addZeros(4);
break;
}
@@ -1810,7 +1810,7 @@ void NVPTXAsmPrinter::bufferLEByte(const
}
if (Cexpr->getOpcode() == Instruction::PtrToInt) {
Value *v = Cexpr->getOperand(0)->stripPointerCasts();
- aggBuffer->addSymbol(v);
+ aggBuffer->addSymbol(v, Cexpr->getOperand(0));
aggBuffer->addZeros(8);
break;
}
@@ -1839,10 +1839,10 @@ void NVPTXAsmPrinter::bufferLEByte(const
}
case Type::PointerTyID: {
if (const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) {
- aggBuffer->addSymbol(GVar);
+ aggBuffer->addSymbol(GVar, GVar);
} else if (const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
const Value *v = Cexpr->stripPointerCasts();
- aggBuffer->addSymbol(v);
+ aggBuffer->addSymbol(v, Cexpr);
}
unsigned int s = TD->getTypeAllocSize(CPV->getType());
aggBuffer->addZeros(s);
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.h?rev=235689&r1=235688&r2=235689&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.h Thu Apr 23 21:57:30 2015
@@ -86,6 +86,14 @@ class LLVM_LIBRARY_VISIBILITY NVPTXAsmPr
std::vector<unsigned char> buffer; // the buffer
SmallVector<unsigned, 4> symbolPosInBuffer;
SmallVector<const Value *, 4> Symbols;
+ // SymbolsBeforeStripping[i] is the original form of Symbols[i] before
+ // stripping pointer casts, i.e.,
+ // Symbols[i] == SymbolsBeforeStripping[i]->stripPointerCasts().
+ //
+ // We need to keep these values because AggBuffer::print decides whether to
+ // emit a "generic()" cast for Symbols[i] depending on the address space of
+ // SymbolsBeforeStripping[i].
+ SmallVector<const Value *, 4> SymbolsBeforeStripping;
unsigned curpos;
raw_ostream &O;
NVPTXAsmPrinter &AP;
@@ -119,9 +127,10 @@ class LLVM_LIBRARY_VISIBILITY NVPTXAsmPr
}
return curpos;
}
- void addSymbol(const Value *GVar) {
+ void addSymbol(const Value *GVar, const Value *GVarBeforeStripping) {
symbolPosInBuffer.push_back(curpos);
Symbols.push_back(GVar);
+ SymbolsBeforeStripping.push_back(GVarBeforeStripping);
numSymbols++;
}
void print() {
@@ -145,10 +154,11 @@ class LLVM_LIBRARY_VISIBILITY NVPTXAsmPr
O << ", ";
if (pos == nextSymbolPos) {
const Value *v = Symbols[nSym];
+ const Value *v0 = SymbolsBeforeStripping[nSym];
if (const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
MCSymbol *Name = AP.getSymbol(GVar);
- PointerType *PTy = dyn_cast<PointerType>(GVar->getType());
- bool IsNonGenericPointer = false;
+ PointerType *PTy = dyn_cast<PointerType>(v0->getType());
+ bool IsNonGenericPointer = false; // Is v0 a non-generic pointer?
if (PTy && PTy->getAddressSpace() != 0) {
IsNonGenericPointer = true;
}
Modified: llvm/trunk/test/CodeGen/NVPTX/addrspacecast-gvar.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/addrspacecast-gvar.ll?rev=235689&r1=235688&r2=235689&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/addrspacecast-gvar.ll (original)
+++ llvm/trunk/test/CodeGen/NVPTX/addrspacecast-gvar.ll Thu Apr 23 21:57:30 2015
@@ -3,7 +3,9 @@
; CHECK: .visible .global .align 4 .u32 g = 42;
; 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)};
@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
+ at g4 = constant {i32*, i32*} {i32* null, i32* addrspacecast (i32 addrspace(1)* @g to i32*)}
More information about the llvm-commits
mailing list