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

llvm/lib/MC/MCSPIRVStreamer.cpp

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

1717
using namespace llvm;
1818

19-
void MCSPIRVStreamer::emitInstToData(const MCInst &Inst,
20-
const MCSubtargetInfo &STI) {
21-
MCAssembler &Assembler = getAssembler();
22-
SmallVector<MCFixup, 0> Fixups;
23-
SmallString<256> Code;
24-
Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
25-
26-
// Append the encoded instruction to the current data fragment (or create a
27-
// new such fragment if the current fragment is not a data fragment).
28-
MCDataFragment *DF = getOrCreateDataFragment();
29-
30-
DF->setHasInstructions(STI);
31-
DF->appendContents(Code);
32-
}
33-
3419
MCStreamer *llvm::createSPIRVStreamer(MCContext &Context,
3520
std::unique_ptr<MCAsmBackend> &&MAB,
3621
std::unique_ptr<MCObjectWriter> &&OW,

llvm/lib/MC/MCWasmStreamer.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,6 @@ void MCWasmStreamer::emitIdent(StringRef IdentString) {
151151
// sections in the object format
152152
}
153153

154-
void MCWasmStreamer::emitInstToData(const MCInst &Inst,
155-
const MCSubtargetInfo &STI) {
156-
MCAssembler &Assembler = getAssembler();
157-
SmallVector<MCFixup, 4> Fixups;
158-
SmallString<256> Code;
159-
Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
160-
161-
// Append the encoded instruction to the current data fragment (or create a
162-
// new such fragment if the current fragment is not a data fragment).
163-
MCDataFragment *DF = getOrCreateDataFragment();
164-
165-
// Add the fixups and data.
166-
for (MCFixup &Fixup : Fixups) {
167-
Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
168-
DF->getFixups().push_back(Fixup);
169-
}
170-
DF->setHasInstructions(STI);
171-
DF->appendContents(Code);
172-
}
173-
174154
void MCWasmStreamer::finishImpl() {
175155
emitFrames(nullptr);
176156

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ WinCOFFObjectWriter &MCWinCOFFStreamer::getWriter() {
136136
return static_cast<WinCOFFObjectWriter &>(getAssembler().getWriter());
137137
}
138138

139-
void MCWinCOFFStreamer::emitInstToData(const MCInst &Inst,
140-
const MCSubtargetInfo &STI) {
141-
MCDataFragment *DF = getOrCreateDataFragment();
142-
143-
SmallVector<MCFixup, 4> Fixups;
144-
SmallString<256> Code;
145-
getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
146-
147-
// Add the fixups and data.
148-
for (MCFixup &Fixup : Fixups) {
149-
Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
150-
DF->getFixups().push_back(Fixup);
151-
}
152-
DF->setHasInstructions(STI);
153-
DF->appendContents(Code);
154-
}
155-
156139
void MCWinCOFFStreamer::initSections(bool NoExecStack,
157140
const MCSubtargetInfo &STI) {
158141
// FIXME: this is identical to the ELF one.

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,6 @@ void MCXCOFFStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
138138
emitZeros(Size);
139139
}
140140

141-
void MCXCOFFStreamer::emitInstToData(const MCInst &Inst,
142-
const MCSubtargetInfo &STI) {
143-
MCAssembler &Assembler = getAssembler();
144-
SmallVector<MCFixup, 4> Fixups;
145-
SmallString<256> Code;
146-
Assembler.getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
147-
148-
// Add the fixups and data.
149-
MCDataFragment *DF = getOrCreateDataFragment(&STI);
150-
const size_t ContentsSize = DF->getContents().size();
151-
auto &DataFragmentFixups = DF->getFixups();
152-
for (auto &Fixup : Fixups) {
153-
Fixup.setOffset(Fixup.getOffset() + ContentsSize);
154-
DataFragmentFixups.push_back(Fixup);
155-
}
156-
157-
DF->setHasInstructions(STI);
158-
DF->appendContents(Code);
159-
}
160-
161141
void MCXCOFFStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym,
162142
uint64_t Size,
163143
MCSymbol *CsectSym,

0 commit comments

Comments
 (0)