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
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