[llvm-dev] How to use SplitBlockAndInsertIfThen() correctly?

Dipanjan Das via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 21 01:59:10 PDT 2017


The way I have used SplitBlockAndInsertIfThen() throws this assertion
error: "Assertion `IDomNode && "Not immediate dominator specified for
block!"' failed". Consider the following abstraction:

=======================
I1
I2
=======================
What I am trying to achieve is:
=======================
I1
I_cond
    I_then1
    I_then2
I_new1
I_new2
I2
=======================

In plain English
   - Split the block between I1 and I2
   - Insert an ICMP at the end of first block
   - Add a couple of instructions (I_then1, I_then2) to the THEN block
   - Add a couple of instruction at the beginning of the last block
preceding I2 (I_new1, I_new2)


My code roughly looks like:

=======================
        Instruction *I2 = I1->getNextNode();     // Next instruction
        TerminatorInst *then_inst;

        if(condition) {
            Value *I_cond = builder.CreateICmpNE(_, _);

            // Split the basic block
            then_inst = SplitBlockAndInsertIfThen(I_cond, I2, false);

            // Set the insert point before terminator of THEN block
            builder.SetInsertPoint(then_inst);

            // Add new instructions
            I_then1
            I_then2
        }

        // Set the insert point before the next instruction
        builder.SetInsertPoint(I2);

       // Add new instructions
        I_new1
        I_new2

=======================

What's wrong with my approach? How to fix it?

-- 

Thanks & Regards,
Dipanjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171021/cc0621f7/attachment.html>


More information about the llvm-dev mailing list