Commit 82ada73
authored
[clang] Optimize EmbedExpr child iterator callback (llvm#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).1 parent 3fb490c commit 82ada73
File tree
4 files changed
+6
-4
lines changed- clang
- include/clang/AST
- lib
- AST
- Serialization
4 files changed
+6
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5113 | 5113 | | |
5114 | 5114 | | |
5115 | 5115 | | |
5116 | | - | |
| 5116 | + | |
5117 | 5117 | | |
5118 | | - | |
| 5118 | + | |
5119 | 5119 | | |
5120 | 5120 | | |
5121 | 5121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2395 | 2395 | | |
2396 | 2396 | | |
2397 | 2397 | | |
| 2398 | + | |
2398 | 2399 | | |
2399 | 2400 | | |
2400 | 2401 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
730 | 730 | | |
731 | 731 | | |
732 | 732 | | |
733 | | - | |
| 733 | + | |
734 | 734 | | |
735 | 735 | | |
736 | 736 | | |
| |||
0 commit comments