[libc-commits] [libc] [libc] Template the writing mode for the writer class (PR #111559)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Oct 9 13:09:24 PDT 2024
michaelrj-google wrote:
The long double table isn't even included, it's going to be from multiple copies of the regular double table. I did some size analysis yesterday and the big thing that needs to happen for size improvement is moving the ryu tables into a `.cpp` file so that the same `.o` with the table is linked into everything that needs it, instead of it getting inlined repeatedly.
Even with that optimization I'm seeing about a 29 KiB increase in the size of the final linked binary when I have both `snprintf` and `printf` in my file (with -O3, only ~3 KiB with -O2). I've put instruction on replicating this at the bottom.
My main concern is this: This patch would make printf only support compile-time writer selection, but for CPU use cases it's better to do runtime writer selection. I think the best way to handle this is to allow GPUs to disable the writer modes that it doesn't need, which should hopefully solve your long compile times, while also allowing the CPU targets to have the behavior they want.
Here's how to replicate my size comparison:
Build libc:
`cmake ../runtimes -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_RUNTIMES="libc" -DCMAKE_BUILD_TYPE=Release -DLIBC_COMPILE_OPTIONS_DEFAULT="-O2"`
`ninja libc`
building size_test.c:
```C
#include <stdio.h>
int main() {
char buff[100];
snprintf(buff, 99, "%f", 123.456);
printf("%s, %f\n", buff, 789.012);
}
```
(replace the `-L` path with the correct one for you)
`clang size_test.c -static -Lllvm-project/build-overlay/libc/lib -lllvmlibc -O2 -o size_test_templated.out`
(rebuild libc on main branch)
`clang size_test.c -static -Lllvm-project/build-overlay/libc/lib -lllvmlibc -O2 -o size_test_main.out`
Now for size comparison:
```
bloaty size_test_templated.out -- size_test_main.out
FILE SIZE VM SIZE
-------------- --------------
+87% +3.31Ki [ = ] 0 [Unmapped]
+0.1% +704 +0.1% +704 .text
+0.3% +88 [ = ] 0 .strtab
+0.0% +24 [ = ] 0 .symtab
+0.5% +4.11Ki +0.1% +704 TOTAL
```
https://github.com/llvm/llvm-project/pull/111559
More information about the libc-commits
mailing list