[llvm] 0e9571d - M68kMCCodeEmitter: Standardize how fixups are appended

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 4 20:30:27 PDT 2025


Author: Fangrui Song
Date: 2025-07-04T20:30:22-07:00
New Revision: 0e9571df982fb0527cac2c6a6d21ff502f5d4668

URL: https://github.com/llvm/llvm-project/commit/0e9571df982fb0527cac2c6a6d21ff502f5d4668
DIFF: https://github.com/llvm/llvm-project/commit/0e9571df982fb0527cac2c6a6d21ff502f5d4668.diff

LOG: M68kMCCodeEmitter: Standardize how fixups are appended

This helper will facilitate future fixup data structure optimizations.

Added: 
    

Modified: 
    llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp
index abc7a9af6c555..1a4ed8dcd63b4 100644
--- a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp
+++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp
@@ -103,6 +103,11 @@ template <unsigned Size> static unsigned getBytePosition(unsigned BitPos) {
   }
 }
 
+static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
+                     const MCExpr *Value, uint16_t Kind, bool PCRel = false) {
+  Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
+}
+
 // We need special handlings for relocatable & pc-relative operands that are
 // larger than a word.
 // A M68k instruction is aligned by word (16 bits). That means, 32-bit
@@ -139,8 +144,8 @@ void M68kMCCodeEmitter::encodeRelocImm(const MCInst &MI, unsigned OpIdx,
 
     // Relocatable address
     unsigned InsertByte = getBytePosition<Size>(InsertPos);
-    Fixups.push_back(MCFixup::create(InsertByte, Expr,
-                                     getFixupForSize(Size, /*IsPCRel=*/false)));
+    addFixup(Fixups, InsertByte, Expr,
+             getFixupForSize(Size, /*IsPCRel=*/false));
   }
 }
 
@@ -174,8 +179,7 @@ void M68kMCCodeEmitter::encodePCRelImm(const MCInst &MI, unsigned OpIdx,
             Expr, MCConstantExpr::create(LabelOffset, Ctx), Ctx);
     }
 
-    Fixups.push_back(MCFixup::create(InsertByte, Expr,
-                                     getFixupForSize(Size, /*IsPCRel=*/true)));
+    addFixup(Fixups, InsertByte, Expr, getFixupForSize(Size, true), true);
   }
 }
 


        


More information about the llvm-commits mailing list