indirect jumps

Hi,

What kind of C/C++ high level code can generate a computed jump, such as:
jmpq *%r14
or
jmpq *(%r14,%rbx,8)
?

I imagine that any calls (including virtual) would use something like ‘call *%r14’,
and the above jumps are mostly from ‘switch’ statements.

Is this correct?
Anything else?

Thank you,
Dan

Ways I can think of to generate computed jumps:
int f1(int (*b)(void)) { return b(); } // Tail call (recently
implemented in LLVM)
void f(void), g(void), h(void), i(void);
void f2(int x) { switch (x) { case 1: f(); case 2: g(); case 3: h();
case 4: i(); } } // switch
void f3(int n) { void* x = { &&L1, &&L2, &&L3 }; goto *x[n]; L1:
f(); L2: g(); L3: h(); } // computed goto

Note that virtual thunks, which show up with C++ class hierarchies,
internally look similar to f1.

-Eli





Hello,



I am trying to clone a machine basic block when I ran into some issues, where I am not able to make some headway. Any of yours help is highly appreciated here:



My question is about Machine Basic Block Duplication:







- Is there a utility to clone a MachineBasicBlock in LLVM? I found utility to clone machineInstrs, but couldn’t find similar utility for MachineBasicBlock. So, I created a utility myself for cloning a MachineBasicBlock, but I am running into an issue when LLVM is trying to destroy the use list for registers (RemoveRegOperandsFromUseLists–> RemoveRegOperandFromRegInfo()–>NextOp->getReg() – where nextOp seems like invalid but not NULL). Its hitting assert in one of the registers that is getting reused in the cloned block



What I am trying to do is to use exact set of virtual registers in both the blocks. Will it cause any issues?







Here is the snippet of what the code does:



MachineBasicBlock* I;



MachineBasicBlock* copy;







copy = createMachineBasicBlock(I->getBasicBlock());







Clone all the instrs from I → copy



Copy all the successor of ‘I’ to ‘copy’ as well







If ‘I’ has 2 predecessors, then update the succ list of the second pred to point to ‘copy’ and insert ‘copy’ after the second pred (‘I’ physically resides after the first pred):







MachineFunction::iterator It = (predMBB+1);



MF.insert(It,copy);



predMBB->addSuccessor(copy);



predMBB->removeSuccessor(I)







MF.RenumberBlocks();







Am I missing anything here?







Please note: I am doing this step as a pass just before the asm printer pass in the target machine layer after all the instructions has been generated, registers has been allocated.







Appreciate your help a lot,







Thanks,



Hisham






>

|

- Is there a utility to clone a MachineBasicBlock in LLVM

There is CloneBasicBlock routine
in ./lib/Transforms/Utils/CloneFunction.cpp

- Sanjiv

Hello Sanjiv,
Thanks a lot for your help. What I am trying to do is to duplicate a MachineBasicBlock(also the BasicBlock which will reside inside MBB) and insert it as a new block in the machine function. Property of the new MBB will be identical to the other existing MBB in the MF. I am using same virtual register numbers for both. By doing this, I am running into some asserts when destroying the register use list

Snippet of Mchine Function Dump:
cond.false.i: 02715A34, LLVM BB @02BBE978, ID#4:
    Predecessors according to CFG: 0271595C (#2)
        %reg1057<def> = IGHAL_MOV_I32_RI 0
        %reg1104<def> = IGHAL_MOV_I32_RR %reg1057
    Successors according to CFG: 02715AA0 (#5)

cond.false.icopy: 0279455C, LLVM BB @02E9DEE8, ID#18:
    Predecessors according to CFG: 027158AC (#1)
        %reg1057<def> = IGHAL_MOV_I32_RI 0
        %reg1104<def> = IGHAL_MOV_I32_RR %reg1057
    Successors according to CFG: 02715AA0 (#5)

cond.end.i: 02715AA0, LLVM BB @02BBEAB8, ID#5:
    Predecessors according to CFG: 027159C8 (#3) 02715A34 (#4) 0279455C (#18)
        %reg1031<def> = IGHAL_MOV_I32_RR %reg1104

The Error i am getting is:
While deleting: label %cond.end.i
Use still stuck around after Def is destroyed: br label %cond.end.i

Assertion failed: use_empty() && "Uses remain when a value is destroyed!", file
c:\ocl\llvm\ms1.0\gfx_opencl_opensource\llvm\lib\vmcore\value.cpp, line 65

Do i need to change the property of the regsiter used inside the copy block to get rid of the error?

Appreciate all the help,