[llvm] [FormattedStream] Add ASCII fast path (PR #117892)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 06:53:21 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/117892.diff
1 Files Affected:
- (modified) llvm/lib/Support/FormattedStream.cpp (+7)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/117892
More information about the llvm-commits
mailing list