diff options
author | Alexis Engelke <engelke@in.tum.de> | 2023-03-10 15:20:30 +0100 |
---|---|---|
committer | Alexis Engelke <engelke@in.tum.de> | 2023-04-06 16:21:49 +0200 |
commit | 0c049ea60a9f214911eef7901b94bd6343c04409 (patch) | |
tree | 651cb452f0b689efd96efdfd9bea56fb88b3d471 /bolt | |
parent | c471f26e81e0aa7a22ecc7f696957e4cfdf6fdec (diff) | |
download | llvm-0c049ea60a9f214911eef7901b94bd6343c04409.tar.gz |
[MC] Always encode instruction into SmallVector
All users of MCCodeEmitter::encodeInstruction use a raw_svector_ostream
to encode the instruction into a SmallVector. The raw_ostream however
incurs some overhead for the actual encoding.
This change allows an MCCodeEmitter to directly emit an instruction into
a SmallVector without using a raw_ostream and therefore allow for
performance improvments in encoding. A default path that uses existing
raw_ostream implementations is provided.
Reviewed By: MaskRay, Amir
Differential Revision: https://reviews.llvm.org/D145791
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/include/bolt/Core/BinaryContext.h | 3 | ||||
-rw-r--r-- | bolt/lib/Core/BinaryContext.cpp | 3 | ||||
-rw-r--r-- | bolt/lib/Core/BinaryFunction.cpp | 3 |
3 files changed, 3 insertions, 6 deletions
diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h index 26b8a64af3dc..7e2d4d6e045c 100644 --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -1227,8 +1227,7 @@ public: Emitter = this->MCE.get(); SmallString<256> Code; SmallVector<MCFixup, 4> Fixups; - raw_svector_ostream VecOS(Code); - Emitter->encodeInstruction(Inst, VecOS, Fixups, *STI); + Emitter->encodeInstruction(Inst, Code, Fixups, *STI); return Code.size(); } diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 09f59f7ad632..6a9e35e04eec 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -2289,9 +2289,8 @@ bool BinaryContext::validateInstructionEncoding( SmallString<256> Code; SmallVector<MCFixup, 4> Fixups; - raw_svector_ostream VecOS(Code); - MCE->encodeInstruction(Inst, VecOS, Fixups, *STI); + MCE->encodeInstruction(Inst, Code, Fixups, *STI); auto OutputSequence = ArrayRef<uint8_t>((uint8_t *)Code.data(), Code.size()); if (InputSequence != OutputSequence) { if (opts::Verbosity > 1) { diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 69ebd12bd0db..14a10be62d20 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1536,8 +1536,7 @@ bool BinaryFunction::scanExternalRefs() { // Emit the instruction using temp emitter and generate relocations. SmallString<256> Code; SmallVector<MCFixup, 4> Fixups; - raw_svector_ostream VecOS(Code); - Emitter.MCE->encodeInstruction(Instruction, VecOS, Fixups, *BC.STI); + Emitter.MCE->encodeInstruction(Instruction, Code, Fixups, *BC.STI); // Create relocation for every fixup. for (const MCFixup &Fixup : Fixups) { |