mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-24 12:29:33 +00:00
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235689 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d83b3b1a8d
commit
b55e9545f2
@ -1179,7 +1179,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
|
||||
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 Constant *CPV, int Bytes,
|
||||
}
|
||||
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 Constant *CPV, int Bytes,
|
||||
}
|
||||
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 Constant *CPV, int Bytes,
|
||||
}
|
||||
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);
|
||||
|
@ -86,6 +86,14 @@ class LLVM_LIBRARY_VISIBILITY NVPTXAsmPrinter : public AsmPrinter {
|
||||
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 NVPTXAsmPrinter : public AsmPrinter {
|
||||
}
|
||||
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 NVPTXAsmPrinter : public AsmPrinter {
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
@g4 = constant {i32*, i32*} {i32* null, i32* addrspacecast (i32 addrspace(1)* @g to i32*)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user