llvm-project
2e34b799 - [clang][bytecode] Only count taken jumps as steps (#201845)

Commit
13 hours ago
[clang][bytecode] Only count taken jumps as steps (#201845) There are several large array declarations in llvm-libc. They usually look similar to this: ```c++ alignas(16) inline constexpr LogRR LOG_TABLE = { { {Sign::POS, 0, 0_u128}, {Sign::POS, -134, 0x8080abac'46f38946'662d417c'ed007a46_u128}, {Sign::POS, -133, 0x8102b2c4'9ac23a4f'91d082dc'e3ddcd38_u128}, {Sign::POS, -133, 0xc2492946'4655f45c'da5f3cc0'b3251dbd_u128}, {Sign::POS, -132, 0x820aec4f'3a222380'b9e3aea6'c444ef07_u128}, // ... ``` the `_u128` is a user-defined literal, so the hex constant to the left of it is actually a `StringLiteral` and the UDL converts that to a different type by iterating over all chars. It calls one function per char, and that function contains the usual switch statement over all ASCII characters. This was problematic with the bytecode interpreter. Support for `-fconstexpr-steps` is implemented by counting the amount of jumps, but switch statements are implemented by comparing the switch condition to all case values and jumping to the case body if the two values match. This caused the amount of steps to increase rapidly as we were _also_ counting jumps we didn't take. This commit changes this to only count the jumps we take. The attached test case uses roughly 4'000 steps in the current interpreter but used to use over 8'000 with the bytecode interpreter. It now only uses 400 in the bytecode interpreter (which might be too low again but anyway). This fixes compiling llvm with the bytecode interpreter.
Author
Parents
Loading