Skip to content

Commit

Permalink
[llvm-objdump][NFC] Make the PrettyPrinter::printInst() output buffered
Browse files Browse the repository at this point in the history
Summary:
Every time PrettyPrinter::printInst is called, stdout is flushed and it makes llvm-objdump slow. This patches adds a string
buffer to prevent stdout from being flushed.

Benchmark results (./llvm-objdump-master: without this patch,  ./bin/llvm-objcopy: with this patch):

  $ hyperfine --warmup 10 './llvm-objdump-master -d ./bin/llvm-objcopy' './bin/llvm-objdump -d ./bin/llvm-objcopy'
  Benchmark #1: ./llvm-objdump-master -d ./bin/llvm-objcopy
    Time (mean ± σ):      2.230 s ±  0.050 s    [User: 1.533 s, System: 0.682 s]
    Range (min … max):    2.115 s …  2.278 s    10 runs

  Benchmark #2: ./bin/llvm-objdump -d ./bin/llvm-objcopy
    Time (mean ± σ):     386.4 ms ±  13.0 ms    [User: 376.6 ms, System: 6.1 ms]
    Range (min … max):   366.1 ms … 407.0 ms    10 runs

  Summary
    './bin/llvm-objdump -d ./bin/llvm-objcopy' ran
      5.77 ± 0.23 times faster than './llvm-objdump-master -d ./bin/llvm-objcopy'

Reviewers: alexshap, Bigcheese, jhenderson, rupprecht, grimar, MaskRay

Reviewed By: jhenderson, MaskRay

Subscribers: dexonsmith, jhenderson, javed.absar, kristof.beyls, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64969

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366984 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
nuta committed Jul 25, 2019
1 parent b43e45f commit 99424ae
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,24 +668,20 @@ class PrettyPrinter {
if (SP && (PrintSource || PrintLines))
SP->printSourceLine(OS, Address);

{
formatted_raw_ostream FOS(OS);
if (!NoLeadingAddr)
FOS << format("%8" PRIx64 ":", Address.Address);
if (!NoShowRawInsn) {
FOS << ' ';
dumpBytes(Bytes, FOS);
}
FOS.flush();
// The output of printInst starts with a tab. Print some spaces so that
// the tab has 1 column and advances to the target tab stop.
unsigned TabStop = NoShowRawInsn ? 16 : 40;
unsigned Column = FOS.getColumn();
FOS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8);

// The dtor calls flush() to ensure the indent comes before printInst().
size_t Start = OS.tell();
if (!NoLeadingAddr)
OS << format("%8" PRIx64 ":", Address.Address);
if (!NoShowRawInsn) {
OS << ' ';
dumpBytes(Bytes, OS);
}

// The output of printInst starts with a tab. Print some spaces so that
// the tab has 1 column and advances to the target tab stop.
unsigned TabStop = NoShowRawInsn ? 16 : 40;
unsigned Column = OS.tell() - Start;
OS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8);

if (MI)
IP.printInst(MI, OS, "", STI);
else
Expand Down

0 comments on commit 99424ae

Please sign in to comment.