[llvm-dev] How to use SplitBlockAndInsertIfThen() correctly?
Dipanjan Das via llvm-dev
llvm-dev at lists.llvm.org
Sat Oct 21 07:19:16 PDT 2017
I believe the problem comes from inserting instructions both at the THEN
block and the beginning of the tail block. Any idea how's that possible?
On 21 October 2017 at 01:59, Dipanjan Das <mail.dipanjan.das at gmail.com>
wrote:
>
> 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
>
--
Thanks & Regards,
Dipanjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171021/a69bf6ba/attachment.html>
More information about the llvm-dev
mailing list