[LLVMdev] Changing order of instructions

Duncan Sands baldrick at free.fr
Wed Dec 7 01:57:08 PST 2011

Hi Evandro,

> Given a segment of a MachineBasicBlock containing the instructions [MI4,
> MI5, MI6] at an arbitrary point, what would be the best way to change
> this segment with the same instructions in a different order, say, [MI5,
> MI6, MI4]?
> I looked into splice(), but it was impossible to hold iterators that
> remained valid before and after the splicing.  I tried erase/remove()
> with insert/insertAfter(), but I ended up with the instructions being
> destroyed.

I don't know the answer, but perhaps you can do it earlier.  When the basic
block is in SDag form there is no ordering between instructions except what
is logically necessary: operands of an instruction need to come before the
instruction.  It is instruction scheduling that determines the order in
which instructions actually occur - perhaps you can tweak that to improve the
order in which your instructions are output?

Ciao, Duncan.

More information about the llvm-dev mailing list