Machine basic blocks

Hi,

I have a couple of questions about MachineBasicBlocks:

  • If I have a pointer to an MBB, is there an easy way to find which block that precedes it in the MachineFunction blocks list? (without iterating through all of the MF’s basic blocks)

  • Does LLVM make any effort to ensure that MBB’s predecessors and successors lists are semantically correct? For example, what happens if an MBB “falls through” into the next block, but the next block is not on its’ successors list?

thanks!

Hi,

- If I have a pointer to an MBB, is there an easy way to find which block
that precedes it in the MachineFunction blocks list? (without iterating
through all of the MF's basic blocks)

You should be able to construct a MachineFunction::iterator directly
from your basic block and move backwards/forwards using that (E.g.
"std::prev(MachineFunction::iterator(MyBB))" at its most basic).

- Does LLVM make any effort to ensure that MBB's predecessors and successors
lists are semantically correct?

Yes. Within a pass you can usually save up the adjustments for later
(depending on what support calls you make), but you need to maintain
this information if you're modifying the block structure.

For example, what happens if an MBB "falls
through" into the next block, but the next block is not on its' successors
list?

I think that shouldn't happen and would be a bug. Is this
hypothetical, or do you have an example where we're doing this at the
moment?

Cheers.

Tim.

Hi Vadim,

Hi,
I have a couple of questions about MachineBasicBlocks:

- If I have a pointer to an MBB, is there an easy way to find which
block that precedes it in the MachineFunction blocks list? (without
iterating through all of the MF's basic blocks)

You can use MachineBasicBlock's predecessors() method (or pred_begin() / pred_end()).

- Does LLVM make any effort to ensure that MBB's predecessors and
successors lists are semantically correct? For example, what
happens if an MBB "falls through" into the next block, but the next
block is not on its' successors list?

This would be invalid. There is a MachineVerifier pass to check for such errors in the machine code.

thanks!

-Manuel

Hypothetical. I am trying to figure out what my code needs to be deal
with. Sounds like this one would not be a concern then.

thanks,
Vadim