[llvm] [FormattedStream] Add ASCII fast path (PR #117892)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 06:52:43 PST 2024
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/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.
>From 12f5ccaaf4da7421ceb8e56e4a02f235c5cad253 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 27 Nov 2024 15:40:33 +0100
Subject: [PATCH] [FormattedStream] Add ASCII fast path
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.
---
llvm/lib/Support/FormattedStream.cpp | 7 +++++++
1 file changed, 7 insertions(+)
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