[PATCH] D84761: [XCOFF][AIX] Put each jump table in an independent section if -ffunction-sections is specified

Jason Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 08:32:17 PDT 2020


jasonliu created this revision.
jasonliu added reviewers: Xiangling_L, DiggerLin, daltenty, hubert.reinterpretcast.
Herald added subscribers: llvm-commits, hiraditya, nemanjai.
Herald added a project: LLVM.
jasonliu requested review of this revision.
Herald added a subscriber: wuzish.

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.


https://reviews.llvm.org/D84761

Files:
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll


Index: llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/aix-lower-jump-table.ll
+++ 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
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2085,11 +2085,18 @@
 
 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(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84761.281245.patch
Type: text/x-patch
Size: 2632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/6ebe92e8/attachment.bin>


More information about the llvm-commits mailing list