Determining the order of instructions in BB

Hi,

Having two instructions in the same basic block is there a way to determine in what order they are in the basic block?

// Paweł

There are a few ways to do this, but in general there is not an O(1) way to do this if your transform is doing arbitrary instruction insertion and removal.

The basic approach is to iterate the list, so this is O(bb length). DominatorTree::dominates(Instruction*,Instruction*) will do this for you. The next is to use OrderedBasicBlock (or OrderedInstructions for a whole function) to cache the instruction ordering.

Finally, I have this patch that I haven’t found time to work on which caches the numbering in Instruction itself: https://reviews.llvm.org/D51664 Just needs a few days of work to make it happen.