Skip to content

Commit 435284e

Browse files
committed
[PPC] Make assembler.cpp compile over 30 times faster
Clang was taking around 30 seconds to compile assembler.cpp on my machine, with most of its time spent in code generation for the global initializer for `lookup`. Changing the map key from `std::string` to `std::string_view` drops compile time to under a second. This is because the compiler no longer has to code gen the allocation, initialization, and moves of 2,100 `std::string`s. `std::string_view` is effectively free to initialize in comparison. While I was here I made the map `static const`. It's not required for the build time improvement, but it is more correct and helped me check that no-one is mutating the map.
1 parent 464dda7 commit 435284e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/powerpc/assembler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct info {
4343
uint32_t mask; /* which bits to mutate */
4444
};
4545

46-
map<string, info> lookup = {
46+
static const map<string_view, info> lookup = {
4747
{ "tdi NUM , GPR , NUM",{0x0800000A,0x03FFFFFF}}, // 000010xxxxxxxxxxxxxxxxxxxxxxxxxx tdi 0, r0, 0xa
4848
{ "tdlgti GPR , NUM",{0x08200000,0x001FFFFF}}, // 00001000001xxxxxxxxxxxxxxxxxxxxx tdlgti r0, 0
4949
{ "tdllti GPR , NUM",{0x08400000,0x001FFFFF}}, // 00001000010xxxxxxxxxxxxxxxxxxxxx tdllti r0, 0
@@ -2932,12 +2932,13 @@ int assemble_single(string src, uint32_t addr, uint8_t *result, string& err,
29322932

29332933
MYLOG("src:%s has signature:%s\n", src.c_str(), sig_src.c_str());
29342934

2935-
if(lookup.find(sig_src) == lookup.end()) {
2935+
auto it = lookup.find(sig_src);
2936+
if(it == lookup.end()) {
29362937
err = "invalid syntax in " + sig_src;
29372938
return -1;
29382939
}
29392940

2940-
auto info = lookup[sig_src];
2941+
auto info = it->second;
29412942
uint32_t vary_mask = info.mask;
29422943

29432944
/* for relative branches, shift the target address to 0 */

0 commit comments

Comments
 (0)