[llvm] 9569a14 - [PowerPC] Move .got2/.toc logic from PPCLinuxAsmPrinter::doFinalization() to emitEndOfAsmFile()
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 29 17:12:49 PST 2020
Author: Fangrui Song
Date: 2020-02-29T17:12:36-08:00
New Revision: 9569a1472ee7fee37f7f991d34634c5d8d1f3559
URL: https://github.com/llvm/llvm-project/commit/9569a1472ee7fee37f7f991d34634c5d8d1f3559
DIFF: https://github.com/llvm/llvm-project/commit/9569a1472ee7fee37f7f991d34634c5d8d1f3559.diff
LOG: [PowerPC] Move .got2/.toc logic from PPCLinuxAsmPrinter::doFinalization() to emitEndOfAsmFile()
Delete redundant .p2align 2 and improve tests.
Added:
Modified:
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/test/CodeGen/PowerPC/mcm-2.ll
llvm/test/CodeGen/PowerPC/mcm-3.ll
llvm/test/CodeGen/PowerPC/mcm-6.ll
llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 885c625557d5..904751801d58 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -137,8 +137,8 @@ class PPCLinuxAsmPrinter : public PPCAsmPrinter {
return "Linux PPC Assembly Printer";
}
- bool doFinalization(Module &M) override;
void emitStartOfAsmFile(Module &M) override;
+ void emitEndOfAsmFile(Module &) override;
void emitFunctionEntryLabel() override;
@@ -1396,7 +1396,7 @@ void PPCLinuxAsmPrinter::emitFunctionEntryLabel() {
OutStreamer->SwitchSection(Current.first, Current.second);
}
-bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
+void PPCLinuxAsmPrinter::emitEndOfAsmFile(Module &M) {
const DataLayout &DL = getDataLayout();
bool isPPC64 = DL.getPointerSizeInBits() == 64;
@@ -1405,31 +1405,26 @@ bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
static_cast<PPCTargetStreamer &>(*OutStreamer->getTargetStreamer());
if (!TOC.empty()) {
- MCSectionELF *Section;
-
- if (isPPC64)
- Section = OutStreamer->getContext().getELFSection(
- ".toc", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
- else
- Section = OutStreamer->getContext().getELFSection(
- ".got2", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
+ const char *Name = isPPC64 ? ".toc" : ".got2";
+ MCSectionELF *Section = OutContext.getELFSection(
+ Name, ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
OutStreamer->SwitchSection(Section);
+ if (!isPPC64)
+ OutStreamer->emitValueToAlignment(4);
for (const auto &TOCMapPair : TOC) {
const MCSymbol *const TOCEntryTarget = TOCMapPair.first;
MCSymbol *const TOCEntryLabel = TOCMapPair.second;
OutStreamer->emitLabel(TOCEntryLabel);
- if (isPPC64) {
+ if (isPPC64)
TS.emitTCEntry(*TOCEntryTarget);
- } else {
- OutStreamer->emitValueToAlignment(4);
+ else
OutStreamer->emitSymbolValue(TOCEntryTarget, 4);
- }
}
}
- return AsmPrinter::doFinalization(M);
+ PPCAsmPrinter::emitEndOfAsmFile(M);
}
/// EmitFunctionBodyStart - Emit a global entry point prefix for ELFv2.
diff --git a/llvm/test/CodeGen/PowerPC/mcm-2.ll b/llvm/test/CodeGen/PowerPC/mcm-2.ll
index 3fcf34169382..980fcb7caa10 100644
--- a/llvm/test/CodeGen/PowerPC/mcm-2.ll
+++ b/llvm/test/CodeGen/PowerPC/mcm-2.ll
@@ -30,8 +30,9 @@ entry:
; LARGE: ld [[REG2:[0-9]+]], [[VAR]]@toc at l([[REG1]])
; LARGE: lwz {{[0-9]+}}, 0([[REG2]])
; LARGE: stw {{[0-9]+}}, 0([[REG2]])
-; LARGE: [[VAR]]:
-; LARGE: .tc [[VAR2:[a-z0-9A-Z_.]+]][TC],[[VAR2]]
-; LARGE: .type [[VAR2]], at object
-; LARGE: .lcomm [[VAR2]],4,4
+; LARGE: .type test_fn_static.si, at object
+; LARGE-NEXT: .lcomm test_fn_static.si,4,4
+; LARGE: .section .toc,"aw", at progbits
+; LARGE-NEXT: [[VAR]]:
+; LARGE-NEXT: .tc test_fn_static.si[TC],test_fn_static.si
diff --git a/llvm/test/CodeGen/PowerPC/mcm-3.ll b/llvm/test/CodeGen/PowerPC/mcm-3.ll
index 0d1d00bd16fd..562cbff286c5 100644
--- a/llvm/test/CodeGen/PowerPC/mcm-3.ll
+++ b/llvm/test/CodeGen/PowerPC/mcm-3.ll
@@ -33,11 +33,13 @@ entry:
; LARGE: ld [[REG2:[0-9]+]], [[VAR]]@toc at l([[REG1]])
; LARGE: lwz {{[0-9]+}}, 0([[REG2]])
; LARGE: stw {{[0-9]+}}, 0([[REG2]])
-; LARGE: [[VAR]]:
-; LARGE: .tc [[VAR2:[a-z0-9A-Z_.]+]][TC],[[VAR2]]
-; LARGE: .type [[VAR2]], at object
-; LARGE: .data
-; LARGE: .globl [[VAR2]]
-; LARGE: [[VAR2]]:
-; LARGE: .long 5
+; LARGE: .type gi, at object
+; LARGE-NEXT: .data
+; LARGE-NEXT: .globl gi
+; LARGE-NEXT: .p2align 2
+; LARGE-NEXT: gi:
+; LARGE-NEXT: .long 5
+; LARGE: .section .toc,"aw", at progbits
+; LARGE-NEXT: [[VAR]]:
+; LARGE-NEXT: .tc gi[TC],gi
diff --git a/llvm/test/CodeGen/PowerPC/mcm-6.ll b/llvm/test/CodeGen/PowerPC/mcm-6.ll
index a8fe9c332b16..0572f107dff4 100644
--- a/llvm/test/CodeGen/PowerPC/mcm-6.ll
+++ b/llvm/test/CodeGen/PowerPC/mcm-6.ll
@@ -22,7 +22,7 @@ entry:
; CHECK: ld [[REG2:[0-9]+]], .LC[[TOCNUM]]@toc at l([[REG1]])
; CHECK: lwz {{[0-9]+}}, 0([[REG2]])
; CHECK: stw {{[0-9]+}}, 0([[REG2]])
-; CHECK: .section .toc
-; CHECK: .LC[[TOCNUM]]:
-; CHECK: .tc [[VAR:[a-z0-9A-Z_.]+]][TC],{{[a-z0-9A-Z_.]+}}
-; CHECK: .comm [[VAR]],4,4
+; CHECK: .comm ti,4,4
+; CHECK: .section .toc,"aw", at progbits
+; CHECK-NEXT: .LC[[TOCNUM]]:
+; CHECK-NEXT: .tc ti[TC],ti
diff --git a/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll b/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
index 266d539024ea..1a36ac3c8913 100644
--- a/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
+++ b/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
@@ -33,8 +33,9 @@ entry:
; LARGE-BSS-DAG: lwz {{[0-9]+}}, 0([[VREG]])
; LARGE-BSS-DAG: stw {{[0-9]+}}, 8(1)
; LARGE-BSS: lwz 30, 24(1)
-; LARGE-BSS: [[VREF]]:
-; LARGE-BSS-NEXT: .p2align 2
+; LARGE-BSS: .section .got2,"aw", at progbits
+; LARGE-BSS-NEXT: .p2align 2
+; LARGE-BSS-NEXT: [[VREF]]:
; LARGE-BSS-NEXT: .long bar
; LARGE-SECUREPLT: addis 30, 30, .LTOC-.L0$pb at ha
; LARGE-SECUREPLT: addi 30, 30, .LTOC-.L0$pb at l
More information about the llvm-commits
mailing list