[llvm] 2de5134 - MCFragment: Add addFixup to replace getFixups().push_back()
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 29 16:26:05 PDT 2025
Author: Fangrui Song
Date: 2025-06-29T16:26:00-07:00
New Revision: 2de51345fb3d81db5613419695498bdd829bccc5
URL: https://github.com/llvm/llvm-project/commit/2de51345fb3d81db5613419695498bdd829bccc5
DIFF: https://github.com/llvm/llvm-project/commit/2de51345fb3d81db5613419695498bdd829bccc5.diff
LOG: MCFragment: Add addFixup to replace getFixups().push_back()
to not expose SmallVector to the callers. We will make fixup storage out
of line.
Added:
Modified:
llvm/include/llvm/MC/MCFragment.h
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCWin64EH.cpp
llvm/lib/MC/MCWinCOFFStreamer.cpp
llvm/lib/MC/MCXCOFFStreamer.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h
index 473dec6477df6..7bb090d0c57a1 100644
--- a/llvm/include/llvm/MC/MCFragment.h
+++ b/llvm/include/llvm/MC/MCFragment.h
@@ -190,6 +190,7 @@ class MCEncodedFragmentWithFixups : public MCEncodedFragment {
void appendContents(size_t Num, char Elt) { Contents.append(Num, Elt); }
void setContents(ArrayRef<char> C) { Contents.assign(C.begin(), C.end()); }
+ void addFixup(MCFixup Fixup) { Fixups.push_back(Fixup); }
SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 1af0414b01955..3b2bb594675f0 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -82,7 +82,7 @@ void MCObjectStreamer::resolvePendingFixups() {
.push_back(PendingFixup.Fixup);
break;
default:
- PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
+ PendingFixup.DF->addFixup(PendingFixup.Fixup);
break;
}
}
@@ -201,8 +201,8 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
emitIntValue(AbsValue, Size);
return;
}
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixup::getDataKindForSize(Size), Loc));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixup::getDataKindForSize(Size), Loc));
DF->appendContents(Size, 0);
}
@@ -400,7 +400,7 @@ void MCObjectStreamer::emitInstToData(const MCInst &Inst,
auto CodeOffset = DF->getContents().size();
for (MCFixup &Fixup : Fixups) {
Fixup.setOffset(Fixup.getOffset() + CodeOffset);
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
}
DF->setHasInstructions(STI);
DF->appendContents(Code);
@@ -707,8 +707,7 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
if (OffsetVal.isAbsolute()) {
if (OffsetVal.getConstant() < 0)
return std::make_pair(false, std::string(".reloc offset is negative"));
- DF->getFixups().push_back(
- MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
+ DF->addFixup(MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
return std::nullopt;
}
if (OffsetVal.getSubSym())
@@ -724,9 +723,8 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
if (Error != std::nullopt)
return Error;
- DF->getFixups().push_back(
- MCFixup::create(SymbolOffset + OffsetVal.getConstant(),
- Expr, Kind, Loc));
+ DF->addFixup(MCFixup::create(SymbolOffset + OffsetVal.getConstant(), Expr,
+ Kind, Loc));
return std::nullopt;
}
diff --git a/llvm/lib/MC/MCWin64EH.cpp b/llvm/lib/MC/MCWin64EH.cpp
index 7fc8919d10453..8cc74db9beea4 100644
--- a/llvm/lib/MC/MCWin64EH.cpp
+++ b/llvm/lib/MC/MCWin64EH.cpp
@@ -338,7 +338,7 @@ static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
auto *MCE = MCUnwindV2EpilogTargetExpr::create(*info, Epilog.second,
EpilogSize, context);
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_2);
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
DF->appendContents(2, 0);
}
}
diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index db62ddc3c4ace..3c7566b8ccd55 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -282,7 +282,7 @@ void MCWinCOFFStreamer::emitCOFFSectionIndex(const MCSymbol *Symbol) {
MCDataFragment *DF = getOrCreateDataFragment();
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_2);
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
DF->appendContents(2, 0);
}
@@ -299,7 +299,7 @@ void MCWinCOFFStreamer::emitCOFFSecRel32(const MCSymbol *Symbol,
// Build the secrel32 relocation.
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_SecRel_4);
// Record the relocation.
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
// Emit 4 bytes (zeros) to the object file.
DF->appendContents(4, 0);
}
@@ -318,7 +318,7 @@ void MCWinCOFFStreamer::emitCOFFImgRel32(const MCSymbol *Symbol,
// Build the imgrel relocation.
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
// Record the relocation.
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
// Emit 4 bytes (zeros) to the object file.
DF->appendContents(4, 0);
}
@@ -332,7 +332,7 @@ void MCWinCOFFStreamer::emitCOFFSecNumber(MCSymbol const *Symbol) {
// Build the relocation.
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
// Record the relocation.
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
// Emit 4 bytes (zeros) to the object file.
DF->appendContents(4, 0);
}
@@ -346,7 +346,7 @@ void MCWinCOFFStreamer::emitCOFFSecOffset(MCSymbol const *Symbol) {
// Build the relocation.
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
// Record the relocation.
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
// Emit 4 bytes (zeros) to the object file.
DF->appendContents(4, 0);
}
diff --git a/llvm/lib/MC/MCXCOFFStreamer.cpp b/llvm/lib/MC/MCXCOFFStreamer.cpp
index 8b051ca532b9e..12e6680bcf074 100644
--- a/llvm/lib/MC/MCXCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCXCOFFStreamer.cpp
@@ -98,7 +98,7 @@ void MCXCOFFStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) {
MCFixupKind Kind = *MaybeKind;
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, Kind);
- DF->getFixups().push_back(Fixup);
+ DF->addFixup(Fixup);
}
void MCXCOFFStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
index 73ad62ed79532..0784c0b1161fe 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -1210,8 +1210,7 @@ inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
MCDataFragment *Frag = getOrCreateDataFragment();
- Frag->getFixups().push_back(MCFixup::create(Frag->getContents().size(), Expr,
- Kind));
+ Frag->addFixup(MCFixup::create(Frag->getContents().size(), Expr, Kind));
}
void ARMELFStreamer::EHReset() {
@@ -1299,7 +1298,7 @@ void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
visitUsedExpr(*PersonalityRef);
MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(
+ DF->addFixup(
MCFixup::create(DF->getContents().size(), PersonalityRef, FK_Data_4));
}
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index b1491b75ac5bc..f7bb33d2790a1 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -287,8 +287,7 @@ std::pair<bool, bool> LoongArchAsmBackend::relaxLEB128(MCLEBFragment &LF,
const MCExpr &Expr = LF.getValue();
if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, *Asm))
return std::make_pair(false, false);
- LF.getFixups().push_back(
- MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
+ LF.addFixup(MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
return std::make_pair(true, true);
}
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
index 6097ad8017846..02269f6a56676 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
@@ -1034,43 +1034,43 @@ MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
void MipsTargetELFStreamer::emitGPRel32Value(const MCExpr *Value) {
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_GPREL32)));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixupKind(Mips::fixup_Mips_GPREL32)));
DF->appendContents(4, 0);
}
void MipsTargetELFStreamer::emitGPRel64Value(const MCExpr *Value) {
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_GPREL32)));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixupKind(Mips::fixup_Mips_GPREL32)));
DF->appendContents(8, 0);
}
void MipsTargetELFStreamer::emitDTPRel32Value(const MCExpr *Value) {
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_DTPREL32)));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixupKind(Mips::fixup_Mips_DTPREL32)));
DF->appendContents(4, 0);
}
void MipsTargetELFStreamer::emitDTPRel64Value(const MCExpr *Value) {
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_DTPREL64)));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixupKind(Mips::fixup_Mips_DTPREL64)));
DF->appendContents(8, 0);
}
void MipsTargetELFStreamer::emitTPRel32Value(const MCExpr *Value) {
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_TPREL32)));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixupKind(Mips::fixup_Mips_TPREL32)));
DF->appendContents(4, 0);
}
void MipsTargetELFStreamer::emitTPRel64Value(const MCExpr *Value) {
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(
- DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_TPREL64)));
+ DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
+ MCFixupKind(Mips::fixup_Mips_TPREL64)));
DF->appendContents(8, 0);
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
index 8ffc92c8dd026..3c97205df1656 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
@@ -159,9 +159,8 @@ void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) {
assert(DF && "Expecting a valid data fragment.");
MCFixupKind FixupKind = static_cast<MCFixupKind>(FirstLiteralRelocationKind +
ELF::R_PPC64_PCREL_OPT);
- DF->getFixups().push_back(
- MCFixup::create(LabelSym->getOffset() - 8, SubExpr2,
- FixupKind, Inst.getLoc()));
+ DF->addFixup(MCFixup::create(LabelSym->getOffset() - 8, SubExpr2, FixupKind,
+ Inst.getLoc()));
emitLabel(CurrentLocation, Inst.getLoc());
}
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index a6c2d2fc29119..8ed0aa8b832cf 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -395,8 +395,7 @@ std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(MCLEBFragment &LF,
return std::make_pair(false, false);
const MCExpr &Expr = LF.getValue();
if (ULEB128Reloc) {
- LF.getFixups().push_back(
- MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
+ LF.addFixup(MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
}
return std::make_pair(Expr.evaluateKnownAbsolute(Value, *Asm), false);
}
More information about the llvm-commits
mailing list