[LLVMdev] MachineBasicBlock insertion
Bin Zeng
ezengbin at gmail.com
Wed Oct 20 10:52:13 PDT 2010
Hi all,
I am really stumped on a problem for long. I could not figure out why.
That is why i am here. OK, here is the problem:
I tried to insert a MachineBasicBlock into a function. Here is the code
snippet:
// insert a machine basic block with the error_label into MF and before I
// Pred is the predecessor of the block to be inserted
// the new basic block is inserted right before I
void X86CFIOptPass::insertBasicBlockBefore(MachineFunction &MF,
MachineBasicBlock *Pred,
MachineFunction::iterator I){
const BasicBlock* LLVM_BB = Pred->getBasicBlock();
MachineBasicBlock * MBB = MF.CreateMachineBasicBlock(LLVM_BB); //
create a MBB
MBB->setNumber(19880616); // set the number of MBB to be 19880616
which is used as an ID
Pred->addSuccessor(MBB);
const TargetInstrInfo *TII = MF.getTarget().getInstrInfo();
DebugLoc dl;
// CALLpcrel32 abort
BuildMI(MBB,dl,TII->get(X86::CALLpcrel32)).addExternalSymbol("abort");
// JNE_4 error_label
BuildMI(MBB,dl,TII->get(X86::JNE_4)).addExternalSymbol("error_label");
// MOV32ri %eax, 0
BuildMI(MBB,dl,TII->get(X86::MOV32ri),X86::EAX).addImm(0);
// CALL32r %eax
// BuildMI(MBB,dl,TII->get(X86::CALL32r)).addReg(X86::EAX);
MF.insert(I,MBB);
}
When I tried to dump the code after the insertion, the program enters an
infinite loop
in the while loop inside MachineRegisterInfo.h:defusechain_iterator
&operator++().
Basically, the CALLpcrel32 instruction has a register operand that
points to itself, that is,
Contents.Reg.Next stores the address of itself. Does anyone knows how to
insert a MachineBasicBlock
into a function? Any advice will be appreciated. Thanks in advance.
~Bin
More information about the llvm-dev
mailing list