[llvm] [NFC][SystemZ] Update insert() API of the AssociatedDataAreaTable class (PR #174593)

Amy Kwan via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 6 05:55:26 PST 2026


https://github.com/amy-kwan created https://github.com/llvm/llvm-project/pull/174593

This patch updates the insert() calls of the AssociatedDataAreaTable class to return a pair of <const MCSymbol *, uint32_t> instead of just a uint32_t. This API change of including the MCSymbol is needed in subsequent patches to come.

>From c7f24718e30e42c036fc51414ff850dea14d445a Mon Sep 17 00:00:00 2001
From: Amy Kwan <amy.kwan1 at ibm.com>
Date: Tue, 6 Jan 2026 00:40:04 -0500
Subject: [PATCH] [NFC][SystemZ] Update insert() API of the
 AssociatedDataAreaTable class

This patch updates the insert() calls of the AssociatedDataAreaTable class
to return a pair of <const MCSymbol *, uint32_t> instead of just a uint32_t.
This API change of including the MCSymbol is needed in subsequent patches
to come.
---
 llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 28 ++++++++++++-------
 llvm/lib/Target/SystemZ/SystemZAsmPrinter.h   |  9 +++---
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 444bc578a3fab..b36605ec54374 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -170,13 +170,14 @@ void SystemZAsmPrinter::emitCallInformation(CallType CT) {
                      .addReg(SystemZMC::GR64Regs[static_cast<unsigned>(CT)]));
 }
 
-uint32_t SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MCSymbol *Sym,
-                                                            unsigned SlotKind) {
+std::pair<const MCSymbol *, uint32_t>
+SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MCSymbol *Sym,
+                                                   unsigned SlotKind) {
   auto Key = std::make_pair(Sym, SlotKind);
-  auto It = Displacements.find(Key);
+  auto *It = Displacements.find(Key);
 
   if (It != Displacements.end())
-    return (*It).second;
+    return std::pair(Sym, (*It).second);
 
   // Determine length of descriptor.
   uint32_t Length;
@@ -193,14 +194,15 @@ uint32_t SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MCSymbol *Sym,
   Displacements[std::make_pair(Sym, SlotKind)] = NextDisplacement;
   NextDisplacement += Length;
 
-  return Displacement;
+  return std::pair(Sym, Displacement);
 }
 
-uint32_t
+std::pair<const MCSymbol *, uint32_t>
 SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MachineOperand MO) {
   MCSymbol *Sym;
   if (MO.getType() == MachineOperand::MO_GlobalAddress) {
     const GlobalValue *GV = MO.getGlobal();
+    assert(GV->hasName() && "Cannot put unnamed value in ADA");
     Sym = MO.getParent()->getMF()->getTarget().getSymbol(GV);
     assert(Sym && "No symbol");
   } else if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
@@ -347,7 +349,9 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
   case SystemZ::ADA_ENTRY: {
     const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
     const SystemZInstrInfo *TII = Subtarget.getInstrInfo();
-    uint32_t Disp = ADATable.insert(MI->getOperand(1));
+    const MCSymbol *Sym;
+    uint32_t Disp;
+    std::tie(Sym, Disp) = ADATable.insert(MI->getOperand(1));
     Register TargetReg = MI->getOperand(0).getReg();
 
     Register ADAReg = MI->getOperand(2).getReg();
@@ -1562,13 +1566,17 @@ void SystemZAsmPrinter::emitPPA1(MCSymbol *FnEndSym) {
     OutStreamer->AddComment("Flags");
     OutStreamer->emitInt32(0); // LSDA field is a WAS offset
     OutStreamer->AddComment("Personality routine");
-    OutStreamer->emitInt64(ADATable.insert(
-        PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC));
+    // Store only offset of function descriptor
+    OutStreamer->emitInt64(
+        ADATable
+            .insert(PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC)
+            .second);
+    // Store only offset of LSDA
     OutStreamer->AddComment("LSDA location");
     MCSymbol *GCCEH = MF->getContext().getOrCreateSymbol(
         Twine("GCC_except_table") + Twine(MF->getFunctionNumber()));
     OutStreamer->emitInt64(
-        ADATable.insert(GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR));
+        ADATable.insert(GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR).second);
   }
 
   // Emit name length and name optional section (0x01 of flags 4)
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
index cb101e472824f..0611179ee7262 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
@@ -73,16 +73,17 @@ class LLVM_LIBRARY_VISIBILITY SystemZAsmPrinter : public AsmPrinter {
 
     /// @brief Add a function descriptor to the ADA.
     /// @param MI Pointer to an ADA_ENTRY instruction.
-    /// @return The displacement of the descriptor into the ADA.
-    uint32_t insert(const MachineOperand MO);
+    /// @return The symbol and displacement of the descriptor into the ADA.
+    std::pair<const MCSymbol *, uint32_t> insert(const MachineOperand MO);
 
     /// @brief Get the displacement into associated data area (ADA) for a name.
     /// If no  displacement is already associated with the name, assign one and
     /// return it.
     /// @param Sym The symbol for which the displacement should be returned.
     /// @param SlotKind The ADA type.
-    /// @return The displacement of the descriptor into the ADA.
-    uint32_t insert(const MCSymbol *Sym, unsigned SlotKind);
+    /// @return The symbol and displacement of the descriptor into the ADA.
+    std::pair<const MCSymbol *, uint32_t> insert(const MCSymbol *Sym,
+                                                 unsigned SlotKind);
 
     /// Get the table of GOFF displacements.  This is 'const' since it should
     /// never be modified by anything except the APIs on this class.



More information about the llvm-commits mailing list