[LLVMdev] deleting or replacing a MachineInst

Mehdi Amini mehdi.amini at apple.com
Wed Feb 11 15:13:46 PST 2015


> On Feb 11, 2015, at 3:04 PM, Chris Sears <chris.sears at gmail.com> wrote:
> 
> I made the change to the BuildMI() call. Again, I don't think that matters.
> 
> #define BUILD_INS(opcode, new_reg, i)                               \
>   BuildMI(*MBB, OldMI, MBBI->getDebugLoc(), TII->get(X86::opcode))  \
>     .addReg(X86::new_reg, kill).addImm(i)
> 
> I didn't completely understand your other proposed change:
>>     for (MachineBasicBlock::iterator MBBI = MBB->begin();
>         MBBI != MBB->end(); ) {
>       MachineInstr *NewMI = NULL;
>       OldMI = MBBI;
>       ++MBBI;
> 
> I think you're saying with ++MBBI to step past the old instruction.
> This seems faster speedwise but more of a hack than just restarting the loop.
> But I'll try it. It implies a certain knowledge of the iterator and MBB.

I don’t see this is as a hack.
I believe it is a widespread pattern when iterating on a linked-list and having to delete elements.
You’ll see this pattern everywhere in LLVM.

Mehdi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150211/663817eb/attachment.html>


More information about the llvm-dev mailing list