diff options
Diffstat (limited to 'lib/CodeGen/PHIElimination.cpp')
| -rw-r--r-- | lib/CodeGen/PHIElimination.cpp | 47 | 
1 files changed, 24 insertions, 23 deletions
| diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp index dcd907229528..c8d0819ad13c 100644 --- a/lib/CodeGen/PHIElimination.cpp +++ b/lib/CodeGen/PHIElimination.cpp @@ -13,7 +13,6 @@  //  //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "phielim"  #include "llvm/CodeGen/Passes.h"  #include "PHIEliminationUtils.h"  #include "llvm/ADT/STLExtras.h" @@ -35,6 +34,8 @@  #include <algorithm>  using namespace llvm; +#define DEBUG_TYPE "phielim" +  static cl::opt<bool>  DisableEdgeSplitting("disable-phi-elim-edge-splitting", cl::init(false),                       cl::Hidden, cl::desc("Disable critical edge splitting " @@ -57,8 +58,8 @@ namespace {        initializePHIEliminationPass(*PassRegistry::getPassRegistry());      } -    virtual bool runOnMachineFunction(MachineFunction &Fn); -    virtual void getAnalysisUsage(AnalysisUsage &AU) const; +    bool runOnMachineFunction(MachineFunction &Fn) override; +    void getAnalysisUsage(AnalysisUsage &AU) const override;    private:      /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions @@ -186,7 +187,7 @@ bool PHIElimination::EliminatePHINodes(MachineFunction &MF,    // Get an iterator to the first instruction after the last PHI node (this may    // also be the end of the basic block).    MachineBasicBlock::iterator LastPHIIt = -    prior(MBB.SkipPHIsAndLabels(MBB.begin())); +    std::prev(MBB.SkipPHIsAndLabels(MBB.begin()));    while (MBB.front().isPHI())      LowerPHINode(MBB, LastPHIIt); @@ -198,9 +199,8 @@ bool PHIElimination::EliminatePHINodes(MachineFunction &MF,  /// This includes registers with no defs.  static bool isImplicitlyDefined(unsigned VirtReg,                                  const MachineRegisterInfo *MRI) { -  for (MachineRegisterInfo::def_iterator DI = MRI->def_begin(VirtReg), -       DE = MRI->def_end(); DI != DE; ++DI) -    if (!DI->isImplicitDef()) +  for (MachineInstr &DI : MRI->def_instructions(VirtReg)) +    if (!DI.isImplicitDef())        return false;    return true;  } @@ -222,7 +222,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,                                    MachineBasicBlock::iterator LastPHIIt) {    ++NumLowered; -  MachineBasicBlock::iterator AfterPHIsIt = llvm::next(LastPHIIt); +  MachineBasicBlock::iterator AfterPHIsIt = std::next(LastPHIIt);    // Unlink the PHI node from the basic block, but don't delete the PHI yet.    MachineInstr *MPhi = MBB.remove(MBB.begin()); @@ -267,7 +267,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,    // Update live variable information if there is any.    if (LV) { -    MachineInstr *PHICopy = prior(AfterPHIsIt); +    MachineInstr *PHICopy = std::prev(AfterPHIsIt);      if (IncomingReg) {        LiveVariables::VarInfo &VI = LV->getVarInfo(IncomingReg); @@ -306,7 +306,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,    // Update LiveIntervals for the new copy or implicit def.    if (LIS) { -    MachineInstr *NewInstr = prior(AfterPHIsIt); +    MachineInstr *NewInstr = std::prev(AfterPHIsIt);      SlotIndex DestCopyIndex = LIS->InsertMachineInstrInMaps(NewInstr);      SlotIndex MBBStartIndex = LIS->getMBBStartIdx(&MBB); @@ -378,7 +378,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,        findPHICopyInsertPoint(&opBlock, &MBB, SrcReg);      // Insert the copy. -    MachineInstr *NewSrcInstr = 0; +    MachineInstr *NewSrcInstr = nullptr;      if (!reusedIncoming && IncomingReg) {        if (SrcUndef) {          // The source register is undefined, so there is no need for a real @@ -444,7 +444,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,            }          } else {            // We just inserted this copy. -          KillInst = prior(InsertPos); +          KillInst = std::prev(InsertPos);          }        }        assert(KillInst->readsRegister(SrcReg) && "Cannot find kill instruction"); @@ -504,7 +504,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,                }              } else {                // We just inserted this copy. -              KillInst = prior(InsertPos); +              KillInst = std::prev(InsertPos);              }            }            assert(KillInst->readsRegister(SrcReg) && @@ -532,13 +532,14 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,  /// used later to determine when the vreg is killed in the BB.  ///  void PHIElimination::analyzePHINodes(const MachineFunction& MF) { -  for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); -       I != E; ++I) -    for (MachineBasicBlock::const_iterator BBI = I->begin(), BBE = I->end(); -         BBI != BBE && BBI->isPHI(); ++BBI) -      for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) -        ++VRegPHIUseCount[BBVRegPair(BBI->getOperand(i+1).getMBB()->getNumber(), -                                     BBI->getOperand(i).getReg())]; +  for (const auto &MBB : MF) +    for (const auto &BBI : MBB) { +      if (!BBI.isPHI()) +        break; +      for (unsigned i = 1, e = BBI.getNumOperands(); i != e; i += 2) +        ++VRegPHIUseCount[BBVRegPair(BBI.getOperand(i+1).getMBB()->getNumber(), +                                     BBI.getOperand(i).getReg())]; +    }  }  bool PHIElimination::SplitPHIEdges(MachineFunction &MF, @@ -547,7 +548,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF,    if (MBB.empty() || !MBB.front().isPHI() || MBB.isLandingPad())      return false;   // Quick exit for basic blocks without PHIs. -  const MachineLoop *CurLoop = MLI ? MLI->getLoopFor(&MBB) : 0; +  const MachineLoop *CurLoop = MLI ? MLI->getLoopFor(&MBB) : nullptr;    bool IsLoopHeader = CurLoop && &MBB == CurLoop->getHeader();    bool Changed = false; @@ -564,7 +565,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF,        // out-of-line blocks into the loop which is very bad for code placement.        if (PreMBB == &MBB && !SplitAllCriticalEdges)          continue; -      const MachineLoop *PreLoop = MLI ? MLI->getLoopFor(PreMBB) : 0; +      const MachineLoop *PreLoop = MLI ? MLI->getLoopFor(PreMBB) : nullptr;        if (IsLoopHeader && PreLoop == CurLoop && !SplitAllCriticalEdges)          continue; @@ -607,7 +608,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF,        if (!ShouldSplit)          continue;        if (!PreMBB->SplitCriticalEdge(&MBB, this)) { -        DEBUG(dbgs() << "Failed to split ciritcal edge.\n"); +        DEBUG(dbgs() << "Failed to split critical edge.\n");          continue;        }        Changed = true; | 
