Expanding Branch to Indirect Branch

I’m attempting to implement the branching instructions of my custom ISA. The ISA does not have a direct branch instruction, but it does have an indirect branch instruction. I’ve mapped the indirect branch instruction to brind, however, I’m having trouble expanding direct branch instructions.

My intention is to use a load immediate instruction to store the block address in a register, and then use the value in the register as the indirect branch target. I’m having trouble figuring out how to translate a bb to a register value.

In SelectionDAG, you want to set ISD::BR to Custom lowering. From there you can create a new ISD::BRIND using a newly created BlockAddress node as the source (using SelectionDAG::getBlockAddress)

1 Like