From: Jan Kratochvil Date: Wed, 26 Aug 2020 07:57:53 +0000 (+0200) Subject: [Support] Speedup llvm-dwarfdump 3.9x X-Git-Tag: llvmorg-13-init~13727 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b20a4e293c3b617d0890657b3c46edcc7410c8fd;p=platform%2Fupstream%2Fllvm.git [Support] Speedup llvm-dwarfdump 3.9x Currently `strace llvm-dwarfdump x.debug >/tmp/file`: ioctl(1, TCGETS, 0x7ffd64d7f340) = -1 ENOTTY (Inappropriate ioctl for device) write(1, " DW_AT_decl_line\t(89)\n"..., 4096) = 4096 ioctl(1, TCGETS, 0x7ffd64d7f400) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(1, TCGETS, 0x7ffd64d7f410) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(1, TCGETS, 0x7ffd64d7f400) = -1 ENOTTY (Inappropriate ioctl for device) After this patch: write(1, "0000000000001102 \"strlen\")\n "..., 4096) = 4096 write(1, "site\n DW_AT_low"..., 4096) = 4096 write(1, "d53)\n\n0x000e4d4d: DW_TAG_G"..., 4096) = 4096 The same speedup can be achieved by `--color=0` but that is not much convenient. This implementation has been suggested by Joerg Sonnenberger. Differential Revision: https://reviews.llvm.org/D86406 --- diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h index e9c710d..cae5743 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -412,6 +412,7 @@ class raw_fd_ostream : public raw_pwrite_stream { int FD; bool ShouldClose; bool SupportsSeeking = false; + mutable Optional HasColors; #ifdef _WIN32 /// True if this fd refers to a Windows console device. Mintty and other diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index 86c4899..83050c8 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -858,7 +858,9 @@ bool raw_fd_ostream::is_displayed() const { } bool raw_fd_ostream::has_colors() const { - return sys::Process::FileDescriptorHasColors(FD); + if (!HasColors) + HasColors = sys::Process::FileDescriptorHasColors(FD); + return *HasColors; } Expected raw_fd_ostream::lock() {