I need to do an inverse-depth-first iteration over the basic blocks in
a machine function (i.e. starting from the last block and following
predecessor edges) for a liveness analysis I'm writing.
idf_iterator seems like it's almost the class I need, but it starts at
the first block in the function at present, rather than the last one
(because of the specialisiation of GraphTraits for
Inverse<MachineFunction*> - getEntryNode returns mf->front()). That
seems odd to me - you can only ever get to the first block with it
(incrementing the iterator once yields idf_end(mf), and there's no
decrement operation).
Is this behaviour intentional?
If it is I'll need to write some inverse iteration functions myself.
Is there a recommended way to find the final block (the one with
successors={}) in a machine function? (will mf->back() always return
it?)
This isn’t a property of the CFG in the general case. However, the UnifyFunctionExitNodes transformation/analysis provides it. From getAnalysis().getReturnBlock(), you can visit the basic block predecessors recursively.
I need to do an inverse-depth-first iteration over the basic blocks in
a machine function (i.e. starting from the last block and following
predecessor edges) for a liveness analysis I'm writing.
As Gordon mentioned, there isn't a trivial way to do this, as there isn't a single exit node in the MBB CFG.
idf_iterator seems like it's almost the class I need, but it starts at
the first block in the function at present, rather than the last one
(because of the specialisiation of GraphTraits for
Inverse<MachineFunction*> - getEntryNode returns mf->front()). That
seems odd to me - you can only ever get to the first block with it
(incrementing the iterator once yields idf_end(mf), and there's no
decrement operation).
That seems odd to me too. It sounds like Inverse<MF*> should be removed.