How to generate branch tables from SSA form?

I've added this question to StackExchange. I've been wondering if there is any good theory behind making the branch tables when coming from SSA form (which should lose the information that there even existed a switch statement in the source code). Does anybody know any references on that?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Branching in SSA

As stated ("How to generate branch tables from SSA form?") this should be pretty straightforward. There's nothing that precludes having a "switch" kind of instruction in SSA form (you just need to have phi nodes at the join points on the other end, but that has nothing to do with the switch instruction per se).

So then you can generate a jump table from such an instruction the same way you would if you weren't using SSA.

Given how simple this is, I assume that you actually intend to ask something else. Could you clarify that? Are you (for example) trying to infer a switch instruction from a series of consecutive conditional branches?

Hm, yeah, I've oversimplified

Hm, yeah, I've oversimplified; though what you said ought to be obvious, I did not really of that because I was picturing a simpler SSA form with only unconditional and single-conditional branching (so no builtin notion of multi-branch instruction). I do believe this would be useful for uniformity: we get a simpler intermediate language, where a series of if statements in the source language would be compiled to a branch table as well (as Clang seems to do, but it certainly has a pass to lower several if instructions to a switch instruction).