[LLVMdev] assertion in LeakDetector

Bill Wendling isanbard at gmail.com
Wed Jun 3 18:03:47 PDT 2009


On Wed, Jun 3, 2009 at 5:48 PM, Manjunath Kudlur <keveman at gmail.com> wrote:
> Hi Bill,
>
> I am using the following version of BuildMI :
>
> MachineInstrBuilder  BuildMI(MachineFunction &MF,
>                                    const TargetInstrDesc &TID,
>                                    unsigned DestReg)
>
> I do the following :
>
> void createInstrs(std::vector<MachineInstr *>& ilist)
> {
>  Machine Instr *mi;
>
>  mi = BuildMI(MF, someTID, somereg);
>  ilist.push_back(mi);
>  mi = BuildMI(MF, someotherTID, someotherreg);
>  ilist.push_back(mi);
> }
>
> viud insertInto(MachineBasicBlock *BB, MachineBasicBlock::iterator II)
> {
>   std::vector<MachineInstr *> temp;
>   createInstrs(temp);
>
>   for(unsigned i=0, e=temp.size(); i!=e; ++i)
>     BB->insert(II, temp[i]);
> }
>
> I am getting the assertion during BB->insert()
>
Hi Manjunath,

Yep! It's putting them into the basic block for you. Though perhaps
not exactly where you want them to be.

You probably want to use this version of BuildMI:

/// BuildMI - This version of the builder inserts the newly-built
/// instruction before the given position in the given
MachineBasicBlock, and
/// sets up the first operand as a destination virtual register.
///
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
                                   MachineBasicBlock::iterator I,
                                   DebugLoc DL,
                                   const TargetInstrDesc &TID,
                                   unsigned DestReg);

in the 'createInstrs' function and *don't* run the 'for' loop to
re-insert them into the basic block.

-bw




More information about the llvm-dev mailing list