Skip to content

Commit d4a8e97

Browse files
Revert "[NVPTX] Use .common linkage for common globals (#84416)"
This reverts commit 8f0012d. The common-linkage.ll test fails with ptxas enabled.
1 parent 71e0261 commit d4a8e97

File tree

3 files changed

+8
-36
lines changed

3 files changed

+8
-36
lines changed

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,16 +1019,14 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
10191019
const DataLayout &DL = getDataLayout();
10201020

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

10241025
if (GVar->hasExternalLinkage()) {
10251026
if (GVar->hasInitializer())
10261027
O << ".visible ";
10271028
else
10281029
O << ".extern ";
1029-
} else if (GVar->hasCommonLinkage() &&
1030-
GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) {
1031-
O << ".common ";
10321030
} else if (GVar->hasLinkOnceLinkage() || GVar->hasWeakLinkage() ||
10331031
GVar->hasAvailableExternallyLinkage() ||
10341032
GVar->hasCommonLinkage()) {
@@ -1140,7 +1138,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
11401138
}
11411139

11421140
O << ".";
1143-
emitPTXAddressSpace(GVar->getAddressSpace(), O);
1141+
emitPTXAddressSpace(PTy->getAddressSpace(), O);
11441142

11451143
if (isManaged(*GVar)) {
11461144
if (STI.getPTXVersion() < 40 || STI.getSmVersion() < 30) {
@@ -1169,8 +1167,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
11691167
// Ptx allows variable initilization only for constant and global state
11701168
// spaces.
11711169
if (GVar->hasInitializer()) {
1172-
if ((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
1173-
(GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) {
1170+
if ((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
1171+
(PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) {
11741172
const Constant *Initializer = GVar->getInitializer();
11751173
// 'undef' is treated as there is no value specified.
11761174
if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
@@ -1185,7 +1183,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
11851183
!isa<UndefValue>(GVar->getInitializer())) {
11861184
report_fatal_error("initial value of '" + GVar->getName() +
11871185
"' is not allowed in addrspace(" +
1188-
Twine(GVar->getAddressSpace()) + ")");
1186+
Twine(PTy->getAddressSpace()) + ")");
11891187
}
11901188
}
11911189
}
@@ -1204,8 +1202,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
12041202
ElementSize = DL.getTypeStoreSize(ETy);
12051203
// Ptx allows variable initilization only for constant and
12061204
// global state spaces.
1207-
if (((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
1208-
(GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
1205+
if (((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
1206+
(PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
12091207
GVar->hasInitializer()) {
12101208
const Constant *Initializer = GVar->getInitializer();
12111209
if (!isa<UndefValue>(Initializer) && !Initializer->isNullValue()) {

llvm/test/CodeGen/NVPTX/common-linkage.ll

Lines changed: 0 additions & 26 deletions
This file was deleted.

llvm/test/CodeGen/NVPTX/weak-global.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
22
; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %}
33

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

77
define i32 @func0() {

0 commit comments

Comments
 (0)