- if (HaveNotEmitted) { // If the copy has not already been emitted, do it.
- assert(MRegisterInfo::isVirtualRegister(opVal.getReg()) &&
- "Machine PHI Operands must all be virtual registers!");
- unsigned SrcReg = opVal.getReg();
- RegInfo->copyRegToReg(opBlock, I, IncomingReg, SrcReg, RC);
-
- // Now update live variable information if we have it.
- if (LV) {
- // We want to be able to insert a kill of the register if this PHI
- // (aka, the copy we just inserted) is the last use of the source
- // value. Live variable analysis conservatively handles this by
- // saying that the value is live until the end of the block the PHI
- // entry lives in. If the value really is dead at the PHI copy, there
- // will be no successor blocks which have the value live-in.
- //
- // Check to see if the copy is the last use, and if so, update the
- // live variables information so that it knows the copy source
- // instruction kills the incoming value.
- //
- LiveVariables::VarInfo &InRegVI = LV->getVarInfo(SrcReg);
-
- // Loop over all of the successors of the basic block, checking to see
- // if the value is either live in the block, or if it is killed in the
- // block. Also check to see if this register is in use by another PHI
- // node which has not yet been eliminated. If so, it will be killed
- // at an appropriate point later.
- //
- bool ValueIsLive = false;
- const BasicBlock *BB = opBlock.getBasicBlock();
- for (succ_const_iterator SI = succ_begin(BB), E = succ_end(BB);
- SI != E && !ValueIsLive; ++SI) {
- const std::pair<MachineBasicBlock*, unsigned> &
- SuccInfo = LV->getBasicBlockInfo(*SI);
-
- // Is it alive in this successor?
- unsigned SuccIdx = SuccInfo.second;
- if (SuccIdx < InRegVI.AliveBlocks.size() &&
- InRegVI.AliveBlocks[SuccIdx]) {
- ValueIsLive = true;
- break;
- }
-
- // Is it killed in this successor?
- MachineBasicBlock *MBB = SuccInfo.first;
- for (unsigned i = 0, e = InRegVI.Kills.size(); i != e; ++i)
- if (InRegVI.Kills[i].first == MBB) {
- ValueIsLive = true;
- break;
- }
-
- // Is it used by any PHI instructions in this block?
- if (ValueIsLive) break;
-
- // Loop over all of the PHIs in this successor, checking to see if
- // the register is being used...
- for (MachineBasicBlock::iterator BBI = MBB->begin(), E=MBB->end();
- BBI != E && BBI->getOpcode() == TargetInstrInfo::PHI;
- ++BBI)
- for (unsigned i = 1, e = BBI->getNumOperands(); i < e; i += 2)
- if (BBI->getOperand(i).getReg() == SrcReg) {
- ValueIsLive = true;
- break;
- }