[llvm-dev] Determining the order of instructions in BB

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 7 09:50:48 PST 2019

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

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.

On Thu, Feb 7, 2019 at 9:46 AM Paweł Bylica via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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ł
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190207/69a49990/attachment.html>

More information about the llvm-dev mailing list