[llvm] da23a83 - [FormattedStream] Add ASCII fast path (#117892)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 05:31:28 PST 2024
Author: Nikita Popov
Date: 2024-12-02T14:31:24+01:00
New Revision: da23a8372cd37e1a6280e9e0519bc0be60e2c209
URL: https://github.com/llvm/llvm-project/commit/da23a8372cd37e1a6280e9e0519bc0be60e2c209
DIFF: https://github.com/llvm/llvm-project/commit/da23a8372cd37e1a6280e9e0519bc0be60e2c209.diff
LOG: [FormattedStream] Add ASCII fast path (#117892)
Printing IR spends a large amount of time updating the column count via
generic UTF-8 APIs. Speed it up by adding a fast path for the common
printable ASCII case.
This makes `-print-on-crash -print-module-scope` about two times faster.
Added:
Modified:
llvm/lib/Support/FormattedStream.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/FormattedStream.cpp b/llvm/lib/Support/FormattedStream.cpp
index c50530e76efc0a..4192893b38a763 100644
--- a/llvm/lib/Support/FormattedStream.cpp
+++ b/llvm/lib/Support/FormattedStream.cpp
@@ -75,6 +75,13 @@ void formatted_raw_ostream::UpdatePosition(const char *Ptr, size_t Size) {
// Now scan the rest of the buffer.
unsigned NumBytes;
for (const char *End = Ptr + Size; Ptr < End; Ptr += NumBytes) {
+ // Fast path for printable ASCII characters without special handling.
+ if (*Ptr >= 0x20 && *Ptr <= 0x7e) {
+ NumBytes = 1;
+ ++Column;
+ continue;
+ }
+
NumBytes = getNumBytesForUTF8(*Ptr);
// The buffer might end part way through a UTF-8 code unit sequence for a
More information about the llvm-commits
mailing list