[llvm] [PowerPC] Move __ehinfo TOC entries to the end of the TOC section (PR #73586)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 12:28:50 PST 2023


https://github.com/maryammo updated https://github.com/llvm/llvm-project/pull/73586

>From 195e5ad222bfecbb8bee183ef9217aacd9dae52b Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <maryammo at ca.ibm.com>
Date: Mon, 27 Nov 2023 18:01:33 -0500
Subject: [PATCH 1/3] PowerPC] Move __ehinfo TOC entries to the end of the TOC
 section

---
 llvm/include/llvm/MC/MCSymbolXCOFF.h                 |  7 +++++++
 llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp    | 12 ++++++++----
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp            |  1 +
 llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll          |  2 +-
 .../aix-emit-tracebacktable-clobber-register.ll      |  2 +-
 llvm/test/CodeGen/PowerPC/aix-exception.ll           |  2 +-
 6 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/MC/MCSymbolXCOFF.h b/llvm/include/llvm/MC/MCSymbolXCOFF.h
index af5759f72618d..d992ee1dac77b 100644
--- a/llvm/include/llvm/MC/MCSymbolXCOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolXCOFF.h
@@ -17,6 +17,9 @@ namespace llvm {
 class MCSectionXCOFF;
 
 class MCSymbolXCOFF : public MCSymbol {
+
+  enum XCOFFSymbolFlags : uint16_t { SF_EHInfo = 0x0001 };
+
 public:
   MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
       : MCSymbol(SymbolKindXCOFF, Name, isTemporary) {}
@@ -62,6 +65,10 @@ class MCSymbolXCOFF : public MCSymbol {
     return getUnqualifiedName();
   }
 
+  bool isEHInfo() const { return getFlags() & SF_EHInfo; }
+
+  void setEHInfo() const { modifyFlags(SF_EHInfo, SF_EHInfo); }
+
 private:
   std::optional<XCOFF::StorageClass> StorageClass;
   MCSectionXCOFF *RepresentedCsect = nullptr;
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index f3ba380818901..99fe36ce43fd6 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2651,12 +2651,16 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
 MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
     const MCSymbol *Sym, const TargetMachine &TM) const {
   // Use TE storage-mapping class when large code model is enabled so that
-  // the chance of needing -bbigtoc is decreased.
+  // the chance of needing -bbigtoc is decreased. Also, the toc-entry for
+  // EH info is never referenced directly using instructions so it can be
+  // allocated with TE storage-mapping class.
   return getContext().getXCOFFSection(
       cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
-      XCOFF::CsectProperties(
-          TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
-          XCOFF::XTY_SD));
+      XCOFF::CsectProperties((TM.getCodeModel() == CodeModel::Large ||
+                              cast<MCSymbolXCOFF>(Sym)->isEHInfo())
+                                 ? XCOFF::XMC_TE
+                                 : XCOFF::XMC_TC,
+                             XCOFF::XTY_SD));
 }
 
 MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 4f15ba497d84c..2244ea48d48bf 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2459,6 +2459,7 @@ void PPCAIXAsmPrinter::emitTracebackTable() {
     auto &Ctx = OutStreamer->getContext();
     MCSymbol *EHInfoSym =
         TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(MF);
+    cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
     MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(EHInfoSym, TOCType_EHBlock);
     const MCSymbol *TOCBaseSym =
         cast<MCSectionXCOFF>(getObjFileLowering().getTOCBaseSection())
diff --git a/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll b/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll
index dfbc871cbdb99..47b7b957fa1a8 100644
--- a/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll
@@ -47,4 +47,4 @@ attributes #0 = { nounwind }
 attributes #1 = { mustprogress noinline optnone }
 
 ; CHECK: __ehinfo.0:
-; CHECK: .tc __ehinfo.0[TC],__ehinfo.0
+; CHECK: .tc __ehinfo.0[TE],__ehinfo.0
diff --git a/llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll b/llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
index 209c3f154e477..77438147ebf42 100644
--- a/llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
@@ -104,7 +104,7 @@ entry:
 ; COMMON-NEXT:                                         # -- End function
 ; COMMON:       .toc
 ; COMMON:      L..C2:
-; COMMON-NEXT:  .tc __ehinfo.1[TC],__ehinfo.1
+; COMMON-NEXT:  .tc __ehinfo.1[TE],__ehinfo.1
 
 
 ; OBJ-DIS:      9c: 00 00 00 00  	# Traceback table start
diff --git a/llvm/test/CodeGen/PowerPC/aix-exception.ll b/llvm/test/CodeGen/PowerPC/aix-exception.ll
index eabf29b97d017..5035d8e323d15 100644
--- a/llvm/test/CodeGen/PowerPC/aix-exception.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-exception.ll
@@ -180,7 +180,7 @@ eh.resume:                                        ; preds = %catch.dispatch
 ; ASM:  L..C0:
 ; ASM:    .tc _ZTIi[TC],_ZTIi[UA]
 ; ASM:  L..C1:
-; ASM:    .tc __ehinfo.1[TC],__ehinfo.1
+; ASM:    .tc __ehinfo.1[TE],__ehinfo.1
 
 declare ptr @__cxa_allocate_exception(i32)
 declare void @__cxa_throw(ptr, ptr, ptr)

>From 7528c979551e8ee43d196b3742b6b6e3092a2a27 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <maryammo at ca.ibm.com>
Date: Tue, 5 Dec 2023 17:33:36 -0500
Subject: [PATCH 2/3] Address review comments

---
 llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 4 +++-
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp         | 1 -
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 99fe36ce43fd6..d8dc1ca8a59ce 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2317,8 +2317,10 @@ bool TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB(
 
 MCSymbol *
 TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(const MachineFunction *MF) {
-  return MF->getMMI().getContext().getOrCreateSymbol(
+  MCSymbol *EHInfoSym = MF->getMMI().getContext().getOrCreateSymbol(
       "__ehinfo." + Twine(MF->getFunctionNumber()));
+  cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
+  return EHInfoSym;
 }
 
 MCSymbol *
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 2244ea48d48bf..4f15ba497d84c 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2459,7 +2459,6 @@ void PPCAIXAsmPrinter::emitTracebackTable() {
     auto &Ctx = OutStreamer->getContext();
     MCSymbol *EHInfoSym =
         TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(MF);
-    cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
     MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(EHInfoSym, TOCType_EHBlock);
     const MCSymbol *TOCBaseSym =
         cast<MCSectionXCOFF>(getObjFileLowering().getTOCBaseSection())

>From d3f73a93ca96b0894a09855c5ea8f14edc07e5c0 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <maryammo at ca.ibm.com>
Date: Thu, 7 Dec 2023 15:28:19 -0500
Subject: [PATCH 3/3] Testing the storage mapping class of ehinfo using the
 integrated assembler

---
 llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll b/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll
index 47b7b957fa1a8..06faf692cdca4 100644
--- a/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll
@@ -4,6 +4,10 @@
 ; RUN: llc -mtriple powerpc64-ibm-aix -fast-isel -verify-machineinstrs < %s | \
 ; RUN:  FileCheck %s
 
+; RUN: llc -mtriple powerpc64-ibm-aix -verify-machineinstrs  -filetype=obj \
+; RUN:   -o %t.o < %s
+; RUN: llvm-readobj --syms %t.o | FileCheck --check-prefix=SYM %s
+
 ; Function Attrs: nounwind
 declare i32 @func1() #0
 
@@ -48,3 +52,10 @@ attributes #1 = { mustprogress noinline optnone }
 
 ; CHECK: __ehinfo.0:
 ; CHECK: .tc __ehinfo.0[TE],__ehinfo.0
+
+; SYM:    Symbol {
+; SYM:      Name: __ehinfo.0
+; SYM:      CSECT Auxiliary Entry {
+; SYM:        StorageMappingClass: XMC_TE (0x16)
+; SYM:      }
+; SYM:    }



More information about the llvm-commits mailing list