llvm.org GIT mirror llvm / 8f72235
Move PHIElimination::isLiveOut method to LiveVariables. We want LiveVariables clients to use methods rather than accessing the getVarInfo data structure directly. That way it will be possible to change the LiveVariables representation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90240 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 10 years ago
4 changed file(s) with 52 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
282282 return getVarInfo(Reg).isLiveIn(MBB, Reg, *MRI);
283283 }
284284
285 /// isLiveOut - Determine if Reg is live out from MBB, when not considering
286 /// PHI nodes. This means that Reg is either killed by a successor block or
287 /// passed through one.
288 bool isLiveOut(unsigned Reg, const MachineBasicBlock &MBB);
289
285290 /// addNewBlock - Add a new basic block BB between DomBB and SuccBB. All
286291 /// variables that are live out of DomBB and live into SuccBB will be marked
287292 /// as passing live through BB. This method assumes that the machine code is
719719 return findKill(&MBB);
720720 }
721721
722 bool LiveVariables::isLiveOut(unsigned Reg, const MachineBasicBlock &MBB) {
723 LiveVariables::VarInfo &VI = getVarInfo(Reg);
724
725 // Loop over all of the successors of the basic block, checking to see if
726 // the value is either live in the block, or if it is killed in the block.
727 std::vector OpSuccBlocks;
728 for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
729 E = MBB.succ_end(); SI != E; ++SI) {
730 MachineBasicBlock *SuccMBB = *SI;
731
732 // Is it alive in this successor?
733 unsigned SuccIdx = SuccMBB->getNumber();
734 if (VI.AliveBlocks.test(SuccIdx))
735 return true;
736 OpSuccBlocks.push_back(SuccMBB);
737 }
738
739 // Check to see if this value is live because there is a use in a successor
740 // that kills it.
741 switch (OpSuccBlocks.size()) {
742 case 1: {
743 MachineBasicBlock *SuccMBB = OpSuccBlocks[0];
744 for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i)
745 if (VI.Kills[i]->getParent() == SuccMBB)
746 return true;
747 break;
748 }
749 case 2: {
750 MachineBasicBlock *SuccMBB1 = OpSuccBlocks[0], *SuccMBB2 = OpSuccBlocks[1];
751 for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i)
752 if (VI.Kills[i]->getParent() == SuccMBB1 ||
753 VI.Kills[i]->getParent() == SuccMBB2)
754 return true;
755 break;
756 }
757 default:
758 std::sort(OpSuccBlocks.begin(), OpSuccBlocks.end());
759 for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i)
760 if (std::binary_search(OpSuccBlocks.begin(), OpSuccBlocks.end(),
761 VI.Kills[i]->getParent()))
762 return true;
763 }
764 return false;
765 }
766
722767 /// addNewBlock - Add a new basic block BB as an empty succcessor to DomBB. All
723768 /// variables that are live out of DomBB will be marked as passing live through
724769 /// BB.
286286
287287 // Okay, if we now know that the value is not live out of the block, we can
288288 // add a kill marker in this block saying that it kills the incoming value!
289 if (!ValueIsUsed && !isLiveOut(SrcReg, opBlock, *LV)) {
289 if (!ValueIsUsed && !LV->isLiveOut(SrcReg, opBlock)) {
290290 // In our final twist, we have to decide which instruction kills the
291291 // register. In most cases this is the copy, however, the first
292292 // terminator instruction at the end of the block may also use the value.
352352 // We break edges when registers are live out from the predecessor block
353353 // (not considering PHI nodes). If the register is live in to this block
354354 // anyway, we would gain nothing from splitting.
355 if (!LV.isLiveIn(Reg, MBB) && isLiveOut(Reg, *PreMBB, LV))
355 if (!LV.isLiveIn(Reg, MBB) && LV.isLiveOut(Reg, *PreMBB))
356356 SplitCriticalEdge(PreMBB, &MBB);
357357 }
358358 }
359359 return true;
360 }
361
362 bool llvm::PHIElimination::isLiveOut(unsigned Reg, const MachineBasicBlock &MBB,
363 LiveVariables &LV) {
364 LiveVariables::VarInfo &VI = LV.getVarInfo(Reg);
365
366 // Loop over all of the successors of the basic block, checking to see if
367 // the value is either live in the block, or if it is killed in the block.
368 std::vector OpSuccBlocks;
369 for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
370 E = MBB.succ_end(); SI != E; ++SI) {
371 MachineBasicBlock *SuccMBB = *SI;
372
373 // Is it alive in this successor?
374 unsigned SuccIdx = SuccMBB->getNumber();
375 if (VI.AliveBlocks.test(SuccIdx))
376 return true;
377 OpSuccBlocks.push_back(SuccMBB);
378 }
379
380 // Check to see if this value is live because there is a use in a successor
381 // that kills it.
382 switch (OpSuccBlocks.size()) {
383 case 1: {
384 MachineBasicBlock *SuccMBB = OpSuccBlocks[0];
385 for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i)
386 if (VI.Kills[i]->getParent() == SuccMBB)
387 return true;
388 break;
389 }
390 case 2: {
391 MachineBasicBlock *SuccMBB1 = OpSuccBlocks[0], *SuccMBB2 = OpSuccBlocks[1];
392 for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i)
393 if (VI.Kills[i]->getParent() == SuccMBB1 ||
394 VI.Kills[i]->getParent() == SuccMBB2)
395 return true;
396 break;
397 }
398 default:
399 std::sort(OpSuccBlocks.begin(), OpSuccBlocks.end());
400 for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i)
401 if (std::binary_search(OpSuccBlocks.begin(), OpSuccBlocks.end(),
402 VI.Kills[i]->getParent()))
403 return true;
404 }
405 return false;
406360 }
407361
408362 MachineBasicBlock *PHIElimination::SplitCriticalEdge(MachineBasicBlock *A,
9292 bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
9393 LiveVariables &LV);
9494
95 /// isLiveOut - Determine if Reg is live out from MBB, when not
96 /// considering PHI nodes. This means that Reg is either killed by
97 /// a successor block or passed through one.
98 bool isLiveOut(unsigned Reg, const MachineBasicBlock &MBB,
99 LiveVariables &LV);
100
10195 /// SplitCriticalEdge - Split a critical edge from A to B by
10296 /// inserting a new MBB. Update branches in A and PHI instructions
10397 /// in B. Return the new block.