Bundling MachineInstr instructions before register allocation seems to always give errors

     I am having difficulties to bundle MachineInstr instructions, before register allocation (RA).
     More exactly, I registered a simple pass in addPreRegAlloc() that is trying to create bundles.

     I see that it is written at http://llvm.org/docs/CodeGenerator.html#machineinstr-bundles:
       <<Packing / bundling of MachineInstr’s should be done as part of the register
             allocation super-pass.
         More specifically, the pass which determines what MIs should be bundled
             together must be done after code generator exits SSA form (i.e.
                 after two-address pass, PHI elimination, and copy coalescing).
         Bundles should only be finalized (i.e. adding BUNDLE MIs and input and
             output register MachineOperands) after virtual registers have been
             rewritten into physical registers.
         This requirement eliminates the need to add virtual register operands
             to BUNDLE instructions which would effectively double the virtual
             register def and use lists.>>

     I presume this is the reason why I'm getting always errors after creating bundles in the pass registered in addPreRegAlloc().
     More exactly, my pass seems to be invoked before the "Eliminate PHI nodes for register allocation" pass.

     If however, there is a simple possibility to bundle MachineInstr before RA, please let me know.

   Thank you,

PS: Is there a possibility to bundle MachineInstr instructions before RA and use llvm::finalizeBundle() on these bundles in a pass invoked after RA?

In theory it should be possible. In practice you will run into issues because nobody is really doing that right now so some things like liveness updates are semi-broken. I am currently working on some patches myself for bundling some things pre-ra myself. I should put up some fixes for the infrastructure soon(ish).

- Matthias

     I come back to this more than 1 year old topic on bundles. I need to create bundles before register allocation to avoid generating COPY instructions in the bundle.

     Is now the bundles API more reliable - were the patches for pre-ra support discussed below made mainstream? I ask because, as already discussed, the solution to avoid generating COPY instructions, etc in a block of MachineInstr is to bundle them - this was discussed also at http://lists.llvm.org/pipermail/llvm-dev/2016-October/106553.html ("spills, reloads, splits or further scheduling sneaking instruction in between").

   Thank you,

Hi,have you found the solution for the pre-ra bundle?