[llvm] 75dbda4 - MCAsmBackend: Remove the MCAssembler argument from addReloc

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 23:34:01 PDT 2025


Author: Fangrui Song
Date: 2025-05-23T23:33:55-07:00
New Revision: 75dbda4601a17be1fc05aeeb96322a23f96fd777

URL: https://github.com/llvm/llvm-project/commit/75dbda4601a17be1fc05aeeb96322a23f96fd777
DIFF: https://github.com/llvm/llvm-project/commit/75dbda4601a17be1fc05aeeb96322a23f96fd777.diff

LOG: MCAsmBackend: Remove the MCAssembler argument from addReloc

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCAsmBackend.h
    llvm/lib/MC/MCAsmBackend.cpp
    llvm/lib/MC/MCAssembler.cpp
    llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
    llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCAsmBackend.h b/llvm/include/llvm/MC/MCAsmBackend.h
index 0797adbe3f73d..da7337ebeff56 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -120,8 +120,7 @@ class MCAsmBackend {
     llvm_unreachable("Need to implement hook if target has custom fixups");
   }
 
-  virtual bool addReloc(MCAssembler &Asm, const MCFragment &F,
-                        const MCFixup &Fixup, const MCValue &Target,
+  virtual bool addReloc(const MCFragment &, const MCFixup &, const MCValue &,
                         uint64_t &FixedValue, bool IsResolved);
 
   /// Apply the \p Value for given \p Fixup into the provided data fragment, at

diff  --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index 6f8fceb1a05c9..750358087b5bc 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -120,13 +120,13 @@ bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &,
   return fixupNeedsRelaxation(Fixup, Value);
 }
 
-bool MCAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
-                            const MCFixup &Fixup, const MCValue &Target,
-                            uint64_t &FixedValue, bool IsResolved) {
+bool MCAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
+                            const MCValue &Target, uint64_t &FixedValue,
+                            bool IsResolved) {
   if (IsResolved && shouldForceRelocation(Fixup, Target))
     IsResolved = false;
   if (!IsResolved)
-    Asm.getWriter().recordRelocation(Asm, &F, Fixup, Target, FixedValue);
+    Asm->getWriter().recordRelocation(*Asm, &F, Fixup, Target, FixedValue);
   return IsResolved;
 }
 

diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 73994461ab8eb..d32e012afd381 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -201,8 +201,7 @@ bool MCAssembler::evaluateFixup(const MCFragment *DF, const MCFixup &Fixup,
 
   if (IsResolved && mc::isRelocRelocation(Fixup.getKind()))
     IsResolved = false;
-  IsResolved = getBackend().addReloc(const_cast<MCAssembler &>(*this), *DF,
-                                     Fixup, Target, Value, IsResolved);
+  IsResolved = getBackend().addReloc(*DF, Fixup, Target, Value, IsResolved);
   getBackend().applyFixup(*DF, Fixup, Target, Contents, Value, IsResolved);
   return true;
 }

diff  --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
index 77a9496fdea21..9bed6930c2c4f 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
@@ -368,19 +368,19 @@ AVRAsmBackend::createObjectTargetWriter() const {
   return createAVRELFObjectWriter(MCELFObjectTargetWriter::getOSABI(OSType));
 }
 
-bool AVRAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
-                             const MCFixup &Fixup, const MCValue &Target,
-                             uint64_t &FixedValue, bool IsResolved) {
+bool AVRAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
+                             const MCValue &Target, uint64_t &FixedValue,
+                             bool IsResolved) {
   // AVR sets the fixup value to bypass the assembly time overflow with a
   // relocation.
   if (IsResolved) {
     auto TargetVal = MCValue::get(Target.getAddSym(), Target.getSubSym(),
                                   FixedValue, Target.getSpecifier());
-    if (forceRelocation(Asm, F, Fixup, TargetVal))
+    if (forceRelocation(F, Fixup, TargetVal))
       IsResolved = false;
   }
   if (!IsResolved)
-    Asm.getWriter().recordRelocation(Asm, &F, Fixup, Target, FixedValue);
+    Asm->getWriter().recordRelocation(*Asm, &F, Fixup, Target, FixedValue);
   return IsResolved;
 }
 
@@ -513,8 +513,7 @@ bool AVRAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
   return true;
 }
 
-bool AVRAsmBackend::forceRelocation(const MCAssembler &Asm, const MCFragment &F,
-                                    const MCFixup &Fixup,
+bool AVRAsmBackend::forceRelocation(const MCFragment &F, const MCFixup &Fixup,
                                     const MCValue &Target) {
   switch ((unsigned)Fixup.getKind()) {
   default:

diff  --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h
index b31331ec80a13..283f937e1ad87 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h
@@ -37,9 +37,8 @@ class AVRAsmBackend : public MCAsmBackend {
   std::unique_ptr<MCObjectTargetWriter>
   createObjectTargetWriter() const override;
 
-  bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,
-                const MCValue &Target, uint64_t &FixedValue,
-                bool IsResolved) override;
+  bool addReloc(const MCFragment &, const MCFixup &, const MCValue &,
+                uint64_t &FixedValue, bool IsResolved) override;
 
   void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
                   MutableArrayRef<char> Data, uint64_t Value,
@@ -51,8 +50,8 @@ class AVRAsmBackend : public MCAsmBackend {
   bool writeNopData(raw_ostream &OS, uint64_t Count,
                     const MCSubtargetInfo *STI) const override;
 
-  bool forceRelocation(const MCAssembler &Asm, const MCFragment &F,
-                       const MCFixup &Fixup, const MCValue &Target);
+  bool forceRelocation(const MCFragment &F, const MCFixup &Fixup,
+                       const MCValue &Target);
 
 private:
   Triple::OSType OSType;

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index e64903d1ed725..8e910cb99823e 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -432,12 +432,11 @@ bool LoongArchAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
   return true;
 }
 
-bool LoongArchAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
-                                   const MCFixup &Fixup, const MCValue &Target,
-                                   uint64_t &FixedValue, bool IsResolved) {
+bool LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
+                                   const MCValue &Target, uint64_t &FixedValue,
+                                   bool IsResolved) {
   auto Fallback = [&]() {
-    return MCAsmBackend::addReloc(Asm, F, Fixup, Target, FixedValue,
-                                  IsResolved);
+    return MCAsmBackend::addReloc(F, Fixup, Target, FixedValue, IsResolved);
   };
   uint64_t FixedValueA, FixedValueB;
   if (Target.getSubSym()) {
@@ -490,8 +489,8 @@ bool LoongArchAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
     MCValue B = MCValue::get(Target.getSubSym());
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, std::get<0>(FK));
     auto FB = MCFixup::create(Fixup.getOffset(), nullptr, std::get<1>(FK));
-    Asm.getWriter().recordRelocation(Asm, &F, FA, A, FixedValueA);
-    Asm.getWriter().recordRelocation(Asm, &F, FB, B, FixedValueB);
+    Asm->getWriter().recordRelocation(*Asm, &F, FA, A, FixedValueA);
+    Asm->getWriter().recordRelocation(*Asm, &F, FB, B, FixedValueB);
     FixedValue = FixedValueA - FixedValueB;
     return false;
   }
@@ -501,8 +500,8 @@ bool LoongArchAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
   // append a RELAX relocation.
   if (Fixup.isLinkerRelaxable()) {
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_LARCH_RELAX);
-    Asm.getWriter().recordRelocation(Asm, &F, FA, MCValue::get(nullptr),
-                                     FixedValueA);
+    Asm->getWriter().recordRelocation(*Asm, &F, FA, MCValue::get(nullptr),
+                                      FixedValueA);
   }
 
   return true;

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
index ed006c7239573..3c9828accaa66 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
@@ -35,9 +35,8 @@ class LoongArchAsmBackend : public MCAsmBackend {
   LoongArchAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit,
                       const MCTargetOptions &Options);
 
-  bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,
-                const MCValue &Target, uint64_t &FixedValue,
-                bool IsResolved) override;
+  bool addReloc(const MCFragment &, const MCFixup &, const MCValue &,
+                uint64_t &FixedValue, bool IsResolved) override;
 
   void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
                   MutableArrayRef<char> Data, uint64_t Value,

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
index fd91f09bebac0..84cd122488428 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
@@ -134,7 +134,7 @@ class PPCAsmBackend : public MCAsmBackend {
                 : InfosBE)[Kind - FirstTargetFixupKind];
   }
 
-  bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,
+  bool addReloc(const MCFragment &F, const MCFixup &Fixup,
                 const MCValue &TargetVal, uint64_t &FixedValue,
                 bool IsResolved) override {
     // In PPC64 ELFv1, .quad .TOC. at tocbase in the .opd section is expected to
@@ -142,8 +142,7 @@ class PPCAsmBackend : public MCAsmBackend {
     auto Target = TargetVal;
     if (Target.getSpecifier() == PPCMCExpr::VK_TOCBASE)
       Target.setAddSym(nullptr);
-    return MCAsmBackend::addReloc(Asm, F, Fixup, Target, FixedValue,
-                                  IsResolved);
+    return MCAsmBackend::addReloc(F, Fixup, Target, FixedValue, IsResolved);
   }
 
   void applyFixup(const MCFragment &, const MCFixup &Fixup,

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 6b19a2a26e2c7..7b015c649f2fe 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -618,9 +618,9 @@ bool RISCVAsmBackend::evaluateTargetFixup(const MCAssembler &Asm,
          isPCRelFixupResolved(Asm, AUIPCTarget.getAddSym(), *AUIPCDF);
 }
 
-bool RISCVAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
-                               const MCFixup &Fixup, const MCValue &Target,
-                               uint64_t &FixedValue, bool IsResolved) {
+bool RISCVAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
+                               const MCValue &Target, uint64_t &FixedValue,
+                               bool IsResolved) {
   uint64_t FixedValueA, FixedValueB;
   if (Target.getSubSym()) {
     assert(Target.getSpecifier() == 0 &&
@@ -654,8 +654,8 @@ bool RISCVAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
     MCValue B = MCValue::get(Target.getSubSym());
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, TA);
     auto FB = MCFixup::create(Fixup.getOffset(), nullptr, TB);
-    Asm.getWriter().recordRelocation(Asm, &F, FA, A, FixedValueA);
-    Asm.getWriter().recordRelocation(Asm, &F, FB, B, FixedValueB);
+    Asm->getWriter().recordRelocation(*Asm, &F, FA, A, FixedValueA);
+    Asm->getWriter().recordRelocation(*Asm, &F, FB, B, FixedValueB);
     FixedValue = FixedValueA - FixedValueB;
     return false;
   }
@@ -666,14 +666,13 @@ bool RISCVAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
     IsResolved = false;
   if (IsResolved &&
       (getFixupKindInfo(Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel))
-    IsResolved = isPCRelFixupResolved(Asm, Target.getAddSym(), F);
-  IsResolved =
-      MCAsmBackend::addReloc(Asm, F, Fixup, Target, FixedValue, IsResolved);
+    IsResolved = isPCRelFixupResolved(*Asm, Target.getAddSym(), F);
+  IsResolved = MCAsmBackend::addReloc(F, Fixup, Target, FixedValue, IsResolved);
 
   if (Fixup.isLinkerRelaxable()) {
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_RISCV_RELAX);
-    Asm.getWriter().recordRelocation(Asm, &F, FA, MCValue::get(nullptr),
-                                     FixedValueA);
+    Asm->getWriter().recordRelocation(*Asm, &F, FA, MCValue::get(nullptr),
+                                      FixedValueA);
   }
 
   return false;

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
index b651341b02e4f..94d82df970199 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
@@ -49,9 +49,8 @@ class RISCVAsmBackend : public MCAsmBackend {
                            const MCFragment *DF, const MCValue &Target,
                            uint64_t &Value) override;
 
-  bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,
-                const MCValue &Target, uint64_t &FixedValue,
-                bool IsResolved) override;
+  bool addReloc(const MCFragment &, const MCFixup &, const MCValue &,
+                uint64_t &FixedValue, bool IsResolved) override;
 
   void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
                   MutableArrayRef<char> Data, uint64_t Value,


        


More information about the llvm-commits mailing list