InstIterator

Hello,

Is there an iterator to iterate over a “range” of instructions in a Function?

“range” meaning from an instruction::iterator up to an other instruction::iterator which either:

  • point to instructions in the same basic block (the first one first, second one second)
  • point to instructions in different basic block (the BB of the first dominate the BB of the second, and the BB of the second post-dominate the BB of the first)

I’m not sure if I can trick InstIterator into doing that for me (with a custom BB type?).

Within a basic block this is just normal iterator usage/manipulation:

for (instr : llvm::make_range(FromInstruction.getIterator(), ToInstruction.getIterator())) { … }

Use std::next() on ToInstruction.getIterator() if you want it included.

  • Matthias

Hi Matthias,

Sorry, my original question may have been ambiguously formulated.
I would like a range that handle any of those two cases transparently so that I can simply iterate without having to handle two different cases.

Today we can build an InstIterator that, for a given set of BB, will iterate over all of the instructions in each of them. This almost match my need except that when I am in the BB that contains the “begin” instruction I need to start from that one, and when I am in the BB that contains the “end” instruction I need to stop right before.
In addition, I need to build that list of BB from the DomTree and PostDomTree (Ideally I don’t need the PostDomTree, maybe I can simply iterate on all BB dominated by the entry until I reach the exit instruction, which is guaranteed to finish thanks to the post-dominance property?).