Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,14 +1019,16 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
const DataLayout &DL = getDataLayout();

// GlobalVariables are always constant pointers themselves.
PointerType *PTy = GVar->getType();
Type *ETy = GVar->getValueType();

if (GVar->hasExternalLinkage()) {
if (GVar->hasInitializer())
O << ".visible ";
else
O << ".extern ";
} else if (GVar->hasCommonLinkage() &&
GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) {
O << ".common ";
} else if (GVar->hasLinkOnceLinkage() || GVar->hasWeakLinkage() ||
GVar->hasAvailableExternallyLinkage() ||
GVar->hasCommonLinkage()) {
Expand Down Expand Up @@ -1138,7 +1140,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
}

O << ".";
emitPTXAddressSpace(PTy->getAddressSpace(), O);
emitPTXAddressSpace(GVar->getAddressSpace(), O);

if (isManaged(*GVar)) {
if (STI.getPTXVersion() < 40 || STI.getSmVersion() < 30) {
Expand Down Expand Up @@ -1167,8 +1169,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
// Ptx allows variable initilization only for constant and global state
// spaces.
if (GVar->hasInitializer()) {
if ((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) {
if ((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) {
const Constant *Initializer = GVar->getInitializer();
// 'undef' is treated as there is no value specified.
if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
Expand All @@ -1183,7 +1185,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
!isa<UndefValue>(GVar->getInitializer())) {
report_fatal_error("initial value of '" + GVar->getName() +
"' is not allowed in addrspace(" +
Twine(PTy->getAddressSpace()) + ")");
Twine(GVar->getAddressSpace()) + ")");
}
}
}
Expand All @@ -1202,8 +1204,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
ElementSize = DL.getTypeStoreSize(ETy);
// Ptx allows variable initilization only for constant and
// global state spaces.
if (((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
if (((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
GVar->hasInitializer()) {
const Constant *Initializer = GVar->getInitializer();
if (!isa<UndefValue>(Initializer) && !Initializer->isNullValue()) {
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/CodeGen/NVPTX/common-linkage.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %}

; CHECK: .common .global .align 4 .u32 g
@g = common addrspace(1) global i32 0, align 4

; CHECK: .weak .const .align 4 .u32 c
@c = common addrspace(4) global i32 0, align 4

; CHECK: .weak .shared .align 4 .u32 s
@s = common addrspace(3) global i32 0, align 4

define i32 @f1() {
%1 = load i32, ptr addrspace(1) @g
ret i32 %1
}

define i32 @f4() {
%1 = load i32, ptr addrspace(4) @c
ret i32 %1
}

define i32 @f3() {
%1 = load i32, ptr addrspace(3) @s
ret i32 %1
}
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/NVPTX/weak-global.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %}

; CHECK: .weak .global .align 4 .u32 g
; CHECK: .common .global .align 4 .u32 g
@g = common addrspace(1) global i32 zeroinitializer

define i32 @func0() {
Expand Down