Skip to content

Commit 3d86ab9

Browse files
committed
[X86][MC] Emit instructions into SmallVector
Depends on D145791 Storing instruction bytes directly in a SmallVector instead of a raw_ostream yields better encoding performance (in some applications, the improvment is ~1% of the complete back-end time). Reviewed By: MaskRay, Amir Differential Revision: https://reviews.llvm.org/D145792
1 parent 8e59fe2 commit 3d86ab9

File tree

3 files changed

+161
-159
lines changed

3 files changed

+161
-159
lines changed

llvm/include/llvm/MC/MCCodeEmitter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class MCCodeEmitter {
3737
/// Lifetime management
3838
virtual void reset() {}
3939

40-
/// Emit the prefixes of given instruction on the output stream.
40+
/// Append the prefixes of given instruction to the code buffer.
4141
///
4242
/// \param Inst a single low-level machine instruction.
43-
/// \param OS output stream.
44-
virtual void emitPrefix(const MCInst &Inst, raw_ostream &OS,
43+
/// \param CB code buffer
44+
virtual void emitPrefix(const MCInst &Inst, SmallVectorImpl<char> &CB,
4545
const MCSubtargetInfo &STI) const {}
4646
/// EncodeInstruction - Encode the given \p Inst to bytes and append to \p CB.
4747
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB,

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,7 @@ bool X86AsmBackend::padInstructionViaPrefix(MCRelaxableFragment &RF,
796796
const unsigned MaxPossiblePad = std::min(15 - OldSize, RemainingSize);
797797
const unsigned RemainingPrefixSize = [&]() -> unsigned {
798798
SmallString<15> Code;
799-
raw_svector_ostream VecOS(Code);
800-
Emitter.emitPrefix(RF.getInst(), VecOS, STI);
799+
Emitter.emitPrefix(RF.getInst(), Code, STI);
801800
assert(Code.size() < 15 && "The number of prefixes must be less than 15.");
802801

803802
// TODO: It turns out we need a decent amount of plumbing for the target

0 commit comments

Comments
 (0)