[llvm] e5062a6 - [XCOFF][AIX] Put each jump table in an independent section if -ffunction-sections is specified
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 07:31:52 PDT 2020
Author: jasonliu
Date: 2020-08-06T14:31:04Z
New Revision: e5062a6caf754de30b4ecba5bf670ee250f78554
URL: https://github.com/llvm/llvm-project/commit/e5062a6caf754de30b4ecba5bf670ee250f78554
DIFF: https://github.com/llvm/llvm-project/commit/e5062a6caf754de30b4ecba5bf670ee250f78554.diff
LOG: [XCOFF][AIX] Put each jump table in an independent section if -ffunction-sections is specified
If a function is in a unique section, putting all jump tables in
.rodata will prevent functions that have a jump table to get
garbage collect by the linker.
Therefore, we need to put jump table into a unique section as well.
Reviewed By: Xiangling_L
Differential Revision: https://reviews.llvm.org/D84761
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 8ef91250423f..fc08fb95123b 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2085,11 +2085,18 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
MCSection *TargetLoweringObjectFileXCOFF::getSectionForJumpTable(
const Function &F, const TargetMachine &TM) const {
- assert (!TM.getFunctionSections() && "Unique sections not supported on XCOFF"
- " yet.");
assert (!F.getComdat() && "Comdat not supported on XCOFF.");
- //TODO: Enable emiting jump table to unique sections when we support it.
- return ReadOnlySection;
+
+ if (!TM.getFunctionSections())
+ return ReadOnlySection;
+
+ // If the function can be removed, produce a unique section so that
+ // the table doesn't prevent the removal.
+ SmallString<128> NameStr(".rodata.jmp..");
+ getNameWithPrefix(NameStr, &F, TM);
+ return getContext().getXCOFFSection(NameStr, XCOFF::XMC_RO, XCOFF::XTY_SD,
+ XCOFF::C_HIDEXT,
+ SectionKind::getReadOnly());
}
bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection(
diff --git a/llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll b/llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
index b4a09459d2af..1163d61d463c 100644
--- a/llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
@@ -26,6 +26,12 @@
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -code-model=large < %s | FileCheck \
; RUN: --check-prefixes=64LARGE-ASM,CHECK %s
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff -function-sections < %s | FileCheck \
+; RUN: --check-prefixes=FUNC-ASM,CHECK %s
+
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -function-sections < %s | FileCheck \
+; RUN: --check-prefixes=FUNC-ASM,CHECK %s
+
define i32 @jump_table(i32 %a) {
entry:
switch i32 %a, label %sw.epilog [
@@ -184,5 +190,21 @@
; 64LARGE-ASM: .vbyte 4, L..BB0_4-L..JTI0_0
; 64LARGE-ASM: .vbyte 4, L..BB0_5-L..JTI0_0
+; FUNC-ASM: .csect .jump_table[PR],2
+; FUNC-ASM: L..BB0_2:
+; FUNC-ASM: L..BB0_3:
+; FUNC-ASM: L..BB0_4:
+; FUNC-ASM: L..BB0_5:
+; FUNC-ASM: L..BB0_6:
+; FUNC-ASM: li 3, 0
+; FUNC-ASM: blr
+; FUNC-ASM: .csect .rodata.jmp..jump_table[RO],2
+; FUNC-ASM: .align 2
+; FUNC-ASM: L..JTI0_0:
+; FUNC-ASM: .vbyte 4, L..BB0_2-L..JTI0_0
+; FUNC-ASM: .vbyte 4, L..BB0_3-L..JTI0_0
+; FUNC-ASM: .vbyte 4, L..BB0_4-L..JTI0_0
+; FUNC-ASM: .vbyte 4, L..BB0_5-L..JTI0_0
+
; CHECK: .toc
; CHECK: .tc L..JTI0_0[TC],L..JTI0_0
More information about the llvm-commits
mailing list