Skip to content

Commit c70f934

Browse files
MaskRayrlavaee
authored andcommitted
MCObjectStreamer: Deduplicate emitInstToData
1 parent 43fd5bb commit c70f934

14 files changed

+17
-107
lines changed

llvm/include/llvm/MC/MCDXContainerStreamer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class MCDXContainerStreamer : public MCObjectStreamer {
3535

3636
bool emitSymbolAttribute(MCSymbol *, MCSymbolAttr) override { return false; }
3737
void emitCommonSymbol(MCSymbol *, uint64_t, Align) override {}
38-
39-
private:
40-
void emitInstToData(const MCInst &, const MCSubtargetInfo &) override;
4138
};
4239

4340
} // end namespace llvm

llvm/include/llvm/MC/MCGOFFStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class MCGOFFStreamer : public MCObjectStreamer {
3535
}
3636
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3737
Align ByteAlignment) override {}
38-
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override {}
3938
};
4039

4140
} // end namespace llvm

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MCObjectStreamer : public MCStreamer {
6060
DenseMap<const MCSymbol *, SmallVector<PendingAssignment, 1>>
6161
pendingAssignments;
6262

63-
virtual void emitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
63+
virtual void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &);
6464
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
6565
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
6666
void emitInstructionImpl(const MCInst &Inst, const MCSubtargetInfo &STI);

llvm/include/llvm/MC/MCSPIRVStreamer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class MCSPIRVStreamer : public MCObjectStreamer {
3535
}
3636
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3737
Align ByteAlignment) override {}
38-
39-
private:
40-
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
4138
};
4239

4340
} // end namespace llvm

llvm/include/llvm/MC/MCWasmStreamer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ class MCWasmStreamer : public MCObjectStreamer {
5858
void finishImpl() override;
5959

6060
private:
61-
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
62-
6361
bool SeenIdent;
6462
};
6563

llvm/include/llvm/MC/MCWinCOFFStreamer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class MCWinCOFFStreamer : public MCObjectStreamer {
7474
protected:
7575
const MCSymbol *CurSymbol;
7676

77-
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
78-
7977
void finalizeCGProfileEntry(const MCSymbolRefExpr *&S);
8078

8179
private:

llvm/include/llvm/MC/MCXCOFFStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class MCXCOFFStreamer : public MCObjectStreamer {
2525
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
2626
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
2727
Align ByteAlignment) override;
28-
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
2928
void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
3029
MCSymbol *CsectSym, Align Alignment) override;
3130
void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,

llvm/lib/MC/MCDXContainerStreamer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
using namespace llvm;
1818

19-
void MCDXContainerStreamer::emitInstToData(const MCInst &,
20-
const MCSubtargetInfo &) {}
21-
2219
MCStreamer *llvm::createDXContainerStreamer(
2320
MCContext &Context, std::unique_ptr<MCAsmBackend> &&MAB,
2421
std::unique_ptr<MCObjectWriter> &&OW, std::unique_ptr<MCCodeEmitter> &&CE) {

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class MCMachOStreamer : public MCObjectStreamer {
5959
/// labels in the middle of the section.
6060
DenseMap<const MCSection*, bool> HasSectionLabel;
6161

62-
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
63-
6462
void emitDataRegion(MachO::DataRegionType Kind);
6563
void emitDataRegionEnd();
6664

@@ -423,23 +421,6 @@ void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
423421
emitZerofill(Section, Symbol, Size, ByteAlignment);
424422
}
425423

426-
void MCMachOStreamer::emitInstToData(const MCInst &Inst,
427-
const MCSubtargetInfo &STI) {
428-
MCDataFragment *DF = getOrCreateDataFragment();
429-
430-
SmallVector<MCFixup, 4> Fixups;
431-
SmallString<256> Code;
432-
getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
433-
434-
// Add the fixups and data.
435-
for (MCFixup &Fixup : Fixups) {
436-
Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
437-
DF->getFixups().push_back(Fixup);
438-
}
439-
DF->setHasInstructions(STI);
440-
DF->appendContents(Code);
441-
}
442-
443424
void MCMachOStreamer::finishImpl() {
444425
emitFrames(&getAssembler().getBackend());
445426

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,22 @@ void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
390390
emitInstToFragment(Inst, STI);
391391
}
392392

393+
void MCObjectStreamer::emitInstToData(const MCInst &Inst,
394+
const MCSubtargetInfo &STI) {
395+
MCDataFragment *DF = getOrCreateDataFragment();
396+
SmallVector<MCFixup, 1> Fixups;
397+
SmallString<256> Code;
398+
getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
399+
400+
auto CodeOffset = DF->getContents().size();
401+
for (MCFixup &Fixup : Fixups) {
402+
Fixup.setOffset(Fixup.getOffset() + CodeOffset);
403+
DF->getFixups().push_back(Fixup);
404+
}
405+
DF->setHasInstructions(STI);
406+
DF->appendContents(Code);
407+
}
408+
393409
void MCObjectStreamer::emitInstToFragment(const MCInst &Inst,
394410
const MCSubtargetInfo &STI) {
395411
// Always create a new, separate fragment here, because its size can change

0 commit comments

Comments
 (0)