Skip to content

Commit 2de5134

Browse files
committed
MCFragment: Add addFixup to replace getFixups().push_back()
to not expose SmallVector to the callers. We will make fixup storage out of line.
1 parent cd075a4 commit 2de5134

File tree

10 files changed

+33
-38
lines changed

10 files changed

+33
-38
lines changed

llvm/include/llvm/MC/MCFragment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class MCEncodedFragmentWithFixups : public MCEncodedFragment {
190190
void appendContents(size_t Num, char Elt) { Contents.append(Num, Elt); }
191191
void setContents(ArrayRef<char> C) { Contents.assign(C.begin(), C.end()); }
192192

193+
void addFixup(MCFixup Fixup) { Fixups.push_back(Fixup); }
193194
SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
194195
const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
195196

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void MCObjectStreamer::resolvePendingFixups() {
8282
.push_back(PendingFixup.Fixup);
8383
break;
8484
default:
85-
PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
85+
PendingFixup.DF->addFixup(PendingFixup.Fixup);
8686
break;
8787
}
8888
}
@@ -201,8 +201,8 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
201201
emitIntValue(AbsValue, Size);
202202
return;
203203
}
204-
DF->getFixups().push_back(MCFixup::create(
205-
DF->getContents().size(), Value, MCFixup::getDataKindForSize(Size), Loc));
204+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
205+
MCFixup::getDataKindForSize(Size), Loc));
206206
DF->appendContents(Size, 0);
207207
}
208208

@@ -400,7 +400,7 @@ void MCObjectStreamer::emitInstToData(const MCInst &Inst,
400400
auto CodeOffset = DF->getContents().size();
401401
for (MCFixup &Fixup : Fixups) {
402402
Fixup.setOffset(Fixup.getOffset() + CodeOffset);
403-
DF->getFixups().push_back(Fixup);
403+
DF->addFixup(Fixup);
404404
}
405405
DF->setHasInstructions(STI);
406406
DF->appendContents(Code);
@@ -707,8 +707,7 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
707707
if (OffsetVal.isAbsolute()) {
708708
if (OffsetVal.getConstant() < 0)
709709
return std::make_pair(false, std::string(".reloc offset is negative"));
710-
DF->getFixups().push_back(
711-
MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
710+
DF->addFixup(MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
712711
return std::nullopt;
713712
}
714713
if (OffsetVal.getSubSym())
@@ -724,9 +723,8 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
724723
if (Error != std::nullopt)
725724
return Error;
726725

727-
DF->getFixups().push_back(
728-
MCFixup::create(SymbolOffset + OffsetVal.getConstant(),
729-
Expr, Kind, Loc));
726+
DF->addFixup(MCFixup::create(SymbolOffset + OffsetVal.getConstant(), Expr,
727+
Kind, Loc));
730728
return std::nullopt;
731729
}
732730

llvm/lib/MC/MCWin64EH.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
338338
auto *MCE = MCUnwindV2EpilogTargetExpr::create(*info, Epilog.second,
339339
EpilogSize, context);
340340
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_2);
341-
DF->getFixups().push_back(Fixup);
341+
DF->addFixup(Fixup);
342342
DF->appendContents(2, 0);
343343
}
344344
}

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void MCWinCOFFStreamer::emitCOFFSectionIndex(const MCSymbol *Symbol) {
282282
MCDataFragment *DF = getOrCreateDataFragment();
283283
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
284284
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_2);
285-
DF->getFixups().push_back(Fixup);
285+
DF->addFixup(Fixup);
286286
DF->appendContents(2, 0);
287287
}
288288

@@ -299,7 +299,7 @@ void MCWinCOFFStreamer::emitCOFFSecRel32(const MCSymbol *Symbol,
299299
// Build the secrel32 relocation.
300300
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_SecRel_4);
301301
// Record the relocation.
302-
DF->getFixups().push_back(Fixup);
302+
DF->addFixup(Fixup);
303303
// Emit 4 bytes (zeros) to the object file.
304304
DF->appendContents(4, 0);
305305
}
@@ -318,7 +318,7 @@ void MCWinCOFFStreamer::emitCOFFImgRel32(const MCSymbol *Symbol,
318318
// Build the imgrel relocation.
319319
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
320320
// Record the relocation.
321-
DF->getFixups().push_back(Fixup);
321+
DF->addFixup(Fixup);
322322
// Emit 4 bytes (zeros) to the object file.
323323
DF->appendContents(4, 0);
324324
}
@@ -332,7 +332,7 @@ void MCWinCOFFStreamer::emitCOFFSecNumber(MCSymbol const *Symbol) {
332332
// Build the relocation.
333333
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
334334
// Record the relocation.
335-
DF->getFixups().push_back(Fixup);
335+
DF->addFixup(Fixup);
336336
// Emit 4 bytes (zeros) to the object file.
337337
DF->appendContents(4, 0);
338338
}
@@ -346,7 +346,7 @@ void MCWinCOFFStreamer::emitCOFFSecOffset(MCSymbol const *Symbol) {
346346
// Build the relocation.
347347
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
348348
// Record the relocation.
349-
DF->getFixups().push_back(Fixup);
349+
DF->addFixup(Fixup);
350350
// Emit 4 bytes (zeros) to the object file.
351351
DF->appendContents(4, 0);
352352
}

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void MCXCOFFStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) {
9898

9999
MCFixupKind Kind = *MaybeKind;
100100
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, Kind);
101-
DF->getFixups().push_back(Fixup);
101+
DF->addFixup(Fixup);
102102
}
103103

104104
void MCXCOFFStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,

llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,7 @@ inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
12101210

12111211
void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
12121212
MCDataFragment *Frag = getOrCreateDataFragment();
1213-
Frag->getFixups().push_back(MCFixup::create(Frag->getContents().size(), Expr,
1214-
Kind));
1213+
Frag->addFixup(MCFixup::create(Frag->getContents().size(), Expr, Kind));
12151214
}
12161215

12171216
void ARMELFStreamer::EHReset() {
@@ -1299,7 +1298,7 @@ void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
12991298

13001299
visitUsedExpr(*PersonalityRef);
13011300
MCDataFragment *DF = getOrCreateDataFragment();
1302-
DF->getFixups().push_back(
1301+
DF->addFixup(
13031302
MCFixup::create(DF->getContents().size(), PersonalityRef, FK_Data_4));
13041303
}
13051304

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ std::pair<bool, bool> LoongArchAsmBackend::relaxLEB128(MCLEBFragment &LF,
287287
const MCExpr &Expr = LF.getValue();
288288
if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, *Asm))
289289
return std::make_pair(false, false);
290-
LF.getFixups().push_back(
291-
MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
290+
LF.addFixup(MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
292291
return std::make_pair(true, true);
293292
}
294293

llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,43 +1034,43 @@ MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
10341034

10351035
void MipsTargetELFStreamer::emitGPRel32Value(const MCExpr *Value) {
10361036
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
1037-
DF->getFixups().push_back(MCFixup::create(
1038-
DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_GPREL32)));
1037+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1038+
MCFixupKind(Mips::fixup_Mips_GPREL32)));
10391039
DF->appendContents(4, 0);
10401040
}
10411041

10421042
void MipsTargetELFStreamer::emitGPRel64Value(const MCExpr *Value) {
10431043
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
1044-
DF->getFixups().push_back(MCFixup::create(
1045-
DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_GPREL32)));
1044+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1045+
MCFixupKind(Mips::fixup_Mips_GPREL32)));
10461046
DF->appendContents(8, 0);
10471047
}
10481048

10491049
void MipsTargetELFStreamer::emitDTPRel32Value(const MCExpr *Value) {
10501050
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
1051-
DF->getFixups().push_back(MCFixup::create(
1052-
DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_DTPREL32)));
1051+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1052+
MCFixupKind(Mips::fixup_Mips_DTPREL32)));
10531053
DF->appendContents(4, 0);
10541054
}
10551055

10561056
void MipsTargetELFStreamer::emitDTPRel64Value(const MCExpr *Value) {
10571057
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
1058-
DF->getFixups().push_back(MCFixup::create(
1059-
DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_DTPREL64)));
1058+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1059+
MCFixupKind(Mips::fixup_Mips_DTPREL64)));
10601060
DF->appendContents(8, 0);
10611061
}
10621062

10631063
void MipsTargetELFStreamer::emitTPRel32Value(const MCExpr *Value) {
10641064
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
1065-
DF->getFixups().push_back(MCFixup::create(
1066-
DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_TPREL32)));
1065+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1066+
MCFixupKind(Mips::fixup_Mips_TPREL32)));
10671067
DF->appendContents(4, 0);
10681068
}
10691069

10701070
void MipsTargetELFStreamer::emitTPRel64Value(const MCExpr *Value) {
10711071
MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
1072-
DF->getFixups().push_back(MCFixup::create(
1073-
DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_TPREL64)));
1072+
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1073+
MCFixupKind(Mips::fixup_Mips_TPREL64)));
10741074
DF->appendContents(8, 0);
10751075
}
10761076

llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) {
159159
assert(DF && "Expecting a valid data fragment.");
160160
MCFixupKind FixupKind = static_cast<MCFixupKind>(FirstLiteralRelocationKind +
161161
ELF::R_PPC64_PCREL_OPT);
162-
DF->getFixups().push_back(
163-
MCFixup::create(LabelSym->getOffset() - 8, SubExpr2,
164-
FixupKind, Inst.getLoc()));
162+
DF->addFixup(MCFixup::create(LabelSym->getOffset() - 8, SubExpr2, FixupKind,
163+
Inst.getLoc()));
165164
emitLabel(CurrentLocation, Inst.getLoc());
166165
}
167166

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(MCLEBFragment &LF,
395395
return std::make_pair(false, false);
396396
const MCExpr &Expr = LF.getValue();
397397
if (ULEB128Reloc) {
398-
LF.getFixups().push_back(
399-
MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
398+
LF.addFixup(MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
400399
}
401400
return std::make_pair(Expr.evaluateKnownAbsolute(Value, *Asm), false);
402401
}

0 commit comments

Comments
 (0)