[PATCH] D64969: [llvm-objdump][NFC] Make the PrettyPrinter::printInst() output buffered

Seiya Nuta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 20:43:55 PDT 2019


seiya created this revision.
Herald added subscribers: llvm-commits, rupprecht, kristof.beyls, javed.absar.
Herald added a reviewer: alexshap.
Herald added a project: LLVM.

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:

$ 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.126 s ±  0.024 s    [User: 1.472 s, System: 0.650 s]
  Range (min … max):    2.106 s …  2.187 s    10 runs

Benchmark #2: ./bin/llvm-objdump -d ./bin/llvm-objcopy

  Time (mean ± σ):     599.7 ms ±   6.5 ms    [User: 592.3 ms, System: 4.5 ms]
  Range (min … max):   592.4 ms … 616.0 ms    10 runs

Summary

  './bin/llvm-objdump -d ./bin/llvm-objcopy' ran
    3.55 ± 0.06 times faster than './llvm-objdump-master -d ./bin/llvm-objcopy'


https://reviews.llvm.org/D64969

Files:
  llvm/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1224,6 +1224,9 @@
     SmallString<40> Comments;
     raw_svector_ostream CommentStream(Comments);
 
+    SmallString<128> InstString;
+    raw_svector_ostream InstStringStream(InstString);
+
     ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(
         unwrapOrError(Section.getContents(), Obj->getFileName()));
 
@@ -1383,9 +1386,10 @@
 
         PIP.printInst(
             *IP, Disassembled ? &Inst : nullptr, Bytes.slice(Index, Size),
-            {SectionAddr + Index + VMAAdjustment, Section.getIndex()}, outs(),
-            "", *STI, &SP, &Rels);
-        outs() << CommentStream.str();
+            {SectionAddr + Index + VMAAdjustment, Section.getIndex()},
+            InstStringStream, "", *STI, &SP, &Rels);
+        outs() << InstStringStream.str() << CommentStream.str();
+        InstString.clear();
         Comments.clear();
 
         // Try to resolve the target of a call, tail call, etc. to a specific


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64969.210730.patch
Type: text/x-patch
Size: 1136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190719/cc4b3d0a/attachment.bin>


More information about the llvm-commits mailing list