[LLVMdev] Problem adding a MachineBasicBlock during X86 EmitPrologue
arlencox at gmail.com
Fri Jun 18 10:42:45 PDT 2010
I'm attempting to add an error handler to functions with a custom
calling convention. This error is checked upon function entry, before
any code is run (specifically, I cannot allow any stack operations).
Because of this, I figured a good place to do this code insertion is
in EmitPrologue. I also, at this time, create the block that handles
the error case.
// create a new block for the overflow handling code
MF.overflowBlock = MF.CreateMachineBasicBlock();
MachineFunction::iterator obinsert = MF.begin();
// on overflow jump to a new block to handle overflow
BuildMI(MBB, MBBI, DL, TII.get(X86::JAE_4)).addMBB(MF.overflowBlock);
//add dummy instruction to overflow block
BuildMI(MF.overflowBlock, DL, TII.get(X86::RET));
The problem is that the block doesn't appear in generate code if the
code starts with more than one basic block. I get x86 code that looks
something like this:
There is no label created "LBB1_-1" and the block containing the ret
instruction is missing.
If I attempt to do an insertion operation, assuming it doesn't insert
at the end() of the machine function, the code in MF.overflowBlock
replaces the code in the block that the iterator points to.
How am I doing this wrong?
More information about the llvm-dev