llvm.org GIT mirror llvm / 24387df
Fixes for BreakCriticalMachineCodeEdge by Fernando. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46419 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
1 changed file(s) with 15 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
3232
3333 // insert the new block into the machine function.
3434 src->getParent()->getBasicBlockList().insert(src->getParent()->end(),
35 crit_mbb);
35 crit_mbb);
3636
3737 // insert a unconditional branch linking the new block to dst
3838 const TargetMachine& TM = src->getParent()->getTarget();
3939 const TargetInstrInfo* TII = TM.getInstrInfo();
4040 std::vector emptyConditions;
41 TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0, emptyConditions);
41 TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0,
42 emptyConditions);
4243
4344 // modify every branch in src that points to dst to point to the new
4445 // machine basic block instead:
4748 while (mii != src->begin()) {
4849 mii--;
4950 // if there are no more branches, finish the loop
50 if (!TII->isTerminatorInstr(mii->getOpcode())) {
51 if (!mii->getDesc().isTerminator()) {
5152 break;
5253 }
53
54
5455 // Scan the operands of this branch, replacing any uses of dst with
5556 // crit_mbb.
5657 for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) {
5758 MachineOperand & mo = mii->getOperand(i);
5859 if (mo.isMachineBasicBlock() &&
59 mo.getMachineBasicBlock() == dst) {
60 mo.getMBB() == dst) {
6061 found_branch = true;
61 mo.setMachineBasicBlock(crit_mbb);
62 mo.setMBB(crit_mbb);
6263 }
6364 }
6465 }
6768 // I am inserting too many gotos, but I am trusting that the asm printer
6869 // will optimize the unnecessary gotos.
6970 if(!found_branch) {
70 TII->InsertBranch(*src, crit_mbb, (MachineBasicBlock*)0, emptyConditions);
71 TII->InsertBranch(*src, crit_mbb, (MachineBasicBlock*)0,
72 emptyConditions);
7173 }
7274
7375 /// Change all the phi functions in dst, so that the incoming block be
7678 /// the first instructions are always phi functions.
7779 if(mii->getOpcode() != TargetInstrInfo::PHI)
7880 break;
79
81
8082 // Find the operands corresponding to the source block
8183 std::vector toRemove;
8284 unsigned reg = 0;
8385 for (unsigned u = 0; u != mii->getNumOperands(); ++u)
8486 if (mii->getOperand(u).isMachineBasicBlock() &&
85 mii->getOperand(u).getMachineBasicBlock() == src) {
87 mii->getOperand(u).getMBB() == src) {
8688 reg = mii->getOperand(u-1).getReg();
8789 toRemove.push_back(u-1);
8890 }
89
9091 // Remove all uses of this MBB
9192 for (std::vector::reverse_iterator I = toRemove.rbegin(),
9293 E = toRemove.rend(); I != E; ++I) {
9394 mii->RemoveOperand(*I+1);
9495 mii->RemoveOperand(*I);
9596 }
96
97
9798 // Add a single use corresponding to the new MBB
98 mii->addRegOperand(reg, false);
99 mii->addMachineBasicBlockOperand(crit_mbb);
99 mii->addOperand(MachineOperand::CreateReg(reg, false));
100 mii->addOperand(MachineOperand::CreateMBB(crit_mbb));
100101 }
101
102
102103 return crit_mbb;
103104 }
104105