[LLVMdev] Merge 2 BasicBlocks

Rinaldini Julien julien.rinaldini at heig-vd.ch
Mon Jul 16 06:33:41 PDT 2012


Hi!

I'm trying to merge 2 basicblocks. I look in BasicBlockUtils.h but the merge function does not what I want.

I'm trying to merge basicblock from a switch where the 'case' have no break, from that:

int a;
switch(c) {
    case 3:
        a=1;
    case 2;
        b=1;
    case 1:
        c=1;
}

to that:

int a;
switch(c) {
    case 3:
        a=1;
        b=1;
        c=1;
        break;
    case 2;
        b=1;
        c=1;
        break;
    case 1:
        c=1;
        break;
}

I use clone() on instruction and insert each cloned instruction onto the right basicblock.
In that simple case, it works great, but when I have some code with pointers like:

int a;
int b[5] = {1,2,3,4,5};
switch(c) {
    case 3:
        a=1;
        b[c] = 1;
    case 2;
        b=1;
        b[c] = 1;
    case 1:
        c=1;
        b[c] = 1;
}

I have a lot of 'Instruction does not dominate all uses!' because the clone() method don't recalculate the dominator tree.

Is there a way to fix that?

Thx,
Cheers




More information about the llvm-dev mailing list