X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FCodeGen%2FBreakCriticalMachineEdge.h;h=a8034275982be28e018793e40bc26fe87093ae6a;hb=4b84086e89d86fb16f562166d9fea8df37db6be7;hp=c02eaa784a9e91a742bef48a8cf3ca8d0a2bfe0b;hpb=fe0c882e5a6ddf4e3c9f771485fdaa4672759539;p=oota-llvm.git diff --git a/include/llvm/CodeGen/BreakCriticalMachineEdge.h b/include/llvm/CodeGen/BreakCriticalMachineEdge.h index c02eaa784a9..a8034275982 100644 --- a/include/llvm/CodeGen/BreakCriticalMachineEdge.h +++ b/include/llvm/CodeGen/BreakCriticalMachineEdge.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Fernando Pereira and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===---------------------------------------------------------------------===// // @@ -14,11 +14,9 @@ #ifndef LLVM_CODEGEN_ASMPRINTER_H #define LLVM_CODEGEN_ASMPRINTER_H -#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Support/Compiler.h" namespace llvm { @@ -35,13 +33,14 @@ MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src, // insert the new block into the machine function. src->getParent()->getBasicBlockList().insert(src->getParent()->end(), - crit_mbb); + crit_mbb); // insert a unconditional branch linking the new block to dst const TargetMachine& TM = src->getParent()->getTarget(); const TargetInstrInfo* TII = TM.getInstrInfo(); std::vector emptyConditions; - TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0, emptyConditions); + TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0, + emptyConditions); // modify every branch in src that points to dst to point to the new // machine basic block instead: @@ -50,18 +49,18 @@ MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src, while (mii != src->begin()) { mii--; // if there are no more branches, finish the loop - if (!TII->isTerminatorInstr(mii->getOpcode())) { + if (!mii->getDesc().isTerminator()) { break; } - + // Scan the operands of this branch, replacing any uses of dst with // crit_mbb. for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) { MachineOperand & mo = mii->getOperand(i); if (mo.isMachineBasicBlock() && - mo.getMachineBasicBlock() == dst) { + mo.getMBB() == dst) { found_branch = true; - mo.setMachineBasicBlock(crit_mbb); + mo.setMBB(crit_mbb); } } } @@ -70,7 +69,8 @@ MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src, // I am inserting too many gotos, but I am trusting that the asm printer // will optimize the unnecessary gotos. if(!found_branch) { - TII->InsertBranch(*src, crit_mbb, (MachineBasicBlock*)0, emptyConditions); + TII->InsertBranch(*src, crit_mbb, (MachineBasicBlock*)0, + emptyConditions); } /// Change all the phi functions in dst, so that the incoming block be @@ -79,13 +79,28 @@ MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src, /// the first instructions are always phi functions. if(mii->getOpcode() != TargetInstrInfo::PHI) break; - + + // Find the operands corresponding to the source block + std::vector toRemove; + unsigned reg = 0; for (unsigned u = 0; u != mii->getNumOperands(); ++u) if (mii->getOperand(u).isMachineBasicBlock() && - mii->getOperand(u).getMachineBasicBlock() == src) - mii->getOperand(u).setMachineBasicBlock(crit_mbb); + mii->getOperand(u).getMBB() == src) { + reg = mii->getOperand(u-1).getReg(); + toRemove.push_back(u-1); + } + // Remove all uses of this MBB + for (std::vector::reverse_iterator I = toRemove.rbegin(), + E = toRemove.rend(); I != E; ++I) { + mii->RemoveOperand(*I+1); + mii->RemoveOperand(*I); + } + + // Add a single use corresponding to the new MBB + mii->addOperand(MachineOperand::CreateReg(reg, false)); + mii->addOperand(MachineOperand::CreateMBB(crit_mbb)); } - + return crit_mbb; }