Switch codegen.

claptrap clap at trap.com
Fri Sep 1 23:54:50 UTC 2023


On Monday, 7 August 2023 at 20:22:06 UTC, claptrap wrote:
>

I've given up looking into this for a number of reasons. Its 
taking me a long time to understand the code and it seems 
IndirectBr is different enough from switch that there's a lot of 
extra work that would need to be done. The case destinations need 
to be basic blocks and I cant figure how to get that from the 
switch cases. Plus it looks like you needs a way to build a 
lookup table with the addresses of the case blocks in. You then 
look up the target in that and pass it to IndirectBr. A lot of 
stuff I couldn't figure out.

And I was looking at this in the switch statement IR gen, so it 
still wouldn't help if the goal was to pull the address 
calculation & bounds check out of an enclosing loop.

It seems like its an optimization that should be done by the 
backend anyway. I mean the LLVM IR is SSA, so the address calc & 
check should be safe to move to where the condition variable is 
defined? If you switch(X), you can move the address lookup to 
where X is defined? Maybe?




More information about the digitalmars-d-ldc mailing list