Skip to content

Commit

Permalink
Revert "[NVPTX] Use .common linkage for common globals (#84416)"
Browse files Browse the repository at this point in the history
This reverts commit 8f0012d.

The common-linkage.ll test fails with ptxas enabled.
  • Loading branch information
Sterling-Augustine committed Mar 15, 2024
1 parent 71e0261 commit d4a8e97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
16 changes: 7 additions & 9 deletions llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,16 +1019,14 @@ 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 @@ -1140,7 +1138,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
}

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

if (isManaged(*GVar)) {
if (STI.getPTXVersion() < 40 || STI.getSmVersion() < 30) {
Expand Down Expand Up @@ -1169,8 +1167,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
// Ptx allows variable initilization only for constant and global state
// spaces.
if (GVar->hasInitializer()) {
if ((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) {
if ((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(PTy->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 @@ -1185,7 +1183,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(GVar->getAddressSpace()) + ")");
Twine(PTy->getAddressSpace()) + ")");
}
}
}
Expand All @@ -1204,8 +1202,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
ElementSize = DL.getTypeStoreSize(ETy);
// Ptx allows variable initilization only for constant and
// global state spaces.
if (((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
if (((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
(PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
GVar->hasInitializer()) {
const Constant *Initializer = GVar->getInitializer();
if (!isa<UndefValue>(Initializer) && !Initializer->isNullValue()) {
Expand Down
26 changes: 0 additions & 26 deletions llvm/test/CodeGen/NVPTX/common-linkage.ll

This file was deleted.

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: .common .global .align 4 .u32 g
; CHECK: .weak .global .align 4 .u32 g
@g = common addrspace(1) global i32 zeroinitializer

define i32 @func0() {
Expand Down

0 comments on commit d4a8e97

Please sign in to comment.