[lld] 7379a19 - [ELF] Replace PPC64 writeSequence static variables with bAlloc

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 17:14:34 PST 2024


Author: Fangrui Song
Date: 2024-11-16T17:14:29-08:00
New Revision: 7379a194d5c18de38e32c29ec5c60964e6784296

URL: https://github.com/llvm/llvm-project/commit/7379a194d5c18de38e32c29ec5c60964e6784296
DIFF: https://github.com/llvm/llvm-project/commit/7379a194d5c18de38e32c29ec5c60964e6784296.diff

LOG: [ELF] Replace PPC64 writeSequence static variables with bAlloc

to reduce global state.

Added: 
    

Modified: 
    lld/ELF/Arch/PPC64.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index 984e0d3aac9ed6..ef5c06299e053c 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -265,12 +265,13 @@ static bool addOptional(Ctx &ctx, StringRef name, uint64_t value,
 // If from is 14, write ${prefix}14: firstInsn; ${prefix}15:
 // firstInsn+0x200008; ...; ${prefix}31: firstInsn+(31-14)*0x200008; $tail
 // The labels are defined only if they exist in the symbol table.
-static void writeSequence(Ctx &ctx, MutableArrayRef<uint32_t> buf,
-                          const char *prefix, int from, uint32_t firstInsn,
-                          ArrayRef<uint32_t> tail) {
+static void writeSequence(Ctx &ctx, const char *prefix, int from,
+                          uint32_t firstInsn, ArrayRef<uint32_t> tail) {
   std::vector<Defined *> defined;
   char name[16];
   int first;
+  const size_t size = 32 - from + tail.size();
+  MutableArrayRef<uint32_t> buf(bAlloc(ctx).Allocate<uint32_t>(size), size);
   uint32_t *ptr = buf.data();
   for (int r = from; r < 32; ++r) {
     format("%s%d", prefix, r).snprint(name, sizeof(name));
@@ -310,22 +311,20 @@ static void writeSequence(Ctx &ctx, MutableArrayRef<uint32_t> buf,
 // significant enough to complicate our trunk implementation, so we take the
 // simple approach and synthesize .text sections providing the implementation.
 void elf::addPPC64SaveRestore(Ctx &ctx) {
-  static uint32_t savegpr0[20], restgpr0[21], savegpr1[19], restgpr1[19];
   constexpr uint32_t blr = 0x4e800020, mtlr_0 = 0x7c0803a6;
 
   // _restgpr0_14: ld 14, -144(1); _restgpr0_15: ld 15, -136(1); ...
   // Tail: ld 0, 16(1); mtlr 0; blr
-  writeSequence(ctx, restgpr0, "_restgpr0_", 14, 0xe9c1ff70,
-                {0xe8010010, mtlr_0, blr});
+  writeSequence(ctx, "_restgpr0_", 14, 0xe9c1ff70, {0xe8010010, mtlr_0, blr});
   // _restgpr1_14: ld 14, -144(12); _restgpr1_15: ld 15, -136(12); ...
   // Tail: blr
-  writeSequence(ctx, restgpr1, "_restgpr1_", 14, 0xe9ccff70, {blr});
+  writeSequence(ctx, "_restgpr1_", 14, 0xe9ccff70, {blr});
   // _savegpr0_14: std 14, -144(1); _savegpr0_15: std 15, -136(1); ...
   // Tail: std 0, 16(1); blr
-  writeSequence(ctx, savegpr0, "_savegpr0_", 14, 0xf9c1ff70, {0xf8010010, blr});
+  writeSequence(ctx, "_savegpr0_", 14, 0xf9c1ff70, {0xf8010010, blr});
   // _savegpr1_14: std 14, -144(12); _savegpr1_15: std 15, -136(12); ...
   // Tail: blr
-  writeSequence(ctx, savegpr1, "_savegpr1_", 14, 0xf9ccff70, {blr});
+  writeSequence(ctx, "_savegpr1_", 14, 0xf9ccff70, {blr});
 }
 
 // Find the R_PPC64_ADDR64 in .rela.toc with matching offset.


        


More information about the llvm-commits mailing list