llvm-project
82ada737 - [clang] Optimize EmbedExpr child iterator callback (#155803)

Commit
13 days ago
[clang] Optimize EmbedExpr child iterator callback (#155803) Instead of querying the bitwidth and signeness of the integer literal for every iteration, get the bitwidth directly from the `APIntStorage` and assume the signeness to be `true` since we set the type of the `EmbedExpr` to `Ctx.IntTy` and the type of the integer literal to that of the `EmbedExpr`, so it should always be signed, as long as `ASTContext::IntTy` is signed. Before: ``` $ hyperfine -r 50 -w 3 'bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000' Benchmark 1: bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000 Time (mean ± σ): 1.796 s ± 0.090 s [User: 0.961 s, System: 0.834 s] Range (min … max): 1.640 s … 2.150 s 50 runs ``` After: ``` $ hyperfine -r 50 -w 3 'bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000' Benchmark 1: bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000 Time (mean ± σ): 1.700 s ± 0.050 s [User: 0.909 s, System: 0.789 s] Range (min … max): 1.637 s … 1.880 s 50 runs ``` That is roughly .1s less, or whatever, 5% or something. The benchmark is simply: ```c++ constexpr char str[] = { #embed "sqlite3.c" suffix(,0) }; constexpr char str2[] = { #embed "sqlite3.c" suffix(,0) }; constexpr char str3[] = { #embed "sqlite3.c" suffix(,0) }; ``` where `sqlite3.c` contains the sqlite3 amalgamation (roughly 9 million characters).
Author
Parents
Loading