diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2011-07-04 00:13:36 +0000 | 
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2011-07-04 00:13:36 +0000 | 
| commit | 79dc4e7709d513f5b437487252237994455d139c (patch) | |
| tree | 80e34e9080fd2a7df306129c04dc06485257e1fc /llvm/lib/CodeGen | |
| parent | 71a3a003dd9856c789a3d39e2235acb38167e550 (diff) | |
| download | bcm5719-llvm-79dc4e7709d513f5b437487252237994455d139c.tar.gz bcm5719-llvm-79dc4e7709d513f5b437487252237994455d139c.zip | |
Reduce indentation and fix the count of how many PHIs we have inserted.
llvm-svn: 134370
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/TailDuplication.cpp | 155 | 
1 files changed, 80 insertions, 75 deletions
| diff --git a/llvm/lib/CodeGen/TailDuplication.cpp b/llvm/lib/CodeGen/TailDuplication.cpp index 6fe4bd739b1..95ce2a66489 100644 --- a/llvm/lib/CodeGen/TailDuplication.cpp +++ b/llvm/lib/CodeGen/TailDuplication.cpp @@ -201,93 +201,98 @@ bool TailDuplicatePass::TailDuplicateBlocks(MachineFunction &MF) {      SmallVector<MachineBasicBlock*, 8> TDBBs;      SmallVector<MachineInstr*, 16> Copies; -    if (TailDuplicate(MBB, MF, TDBBs, Copies)) { -      ++NumTails; - -      // TailBB's immediate successors are now successors of those predecessors -      // which duplicated TailBB. Add the predecessors as sources to the PHI -      // instructions. -      bool isDead = MBB->pred_empty() && !MBB->hasAddressTaken(); -      if (PreRegAlloc) -        UpdateSuccessorsPHIs(MBB, isDead, TDBBs, Succs); +    if (!TailDuplicate(MBB, MF, TDBBs, Copies)) +      continue; -      // If it is dead, remove it. -      if (isDead) { -        NumInstrDups -= MBB->size(); -        RemoveDeadBlock(MBB); -        ++NumDeadBlocks; -      } +    ++NumTails; -      // Update SSA form. -      if (!SSAUpdateVRs.empty()) { -        for (unsigned i = 0, e = SSAUpdateVRs.size(); i != e; ++i) { -          unsigned VReg = SSAUpdateVRs[i]; -          SSAUpdate.Initialize(VReg); - -          // If the original definition is still around, add it as an available -          // value. -          MachineInstr *DefMI = MRI->getVRegDef(VReg); -          MachineBasicBlock *DefBB = 0; -          if (DefMI) { -            DefBB = DefMI->getParent(); -            SSAUpdate.AddAvailableValue(DefBB, VReg); -          } +    // TailBB's immediate successors are now successors of those predecessors +    // which duplicated TailBB. Add the predecessors as sources to the PHI +    // instructions. +    bool isDead = MBB->pred_empty() && !MBB->hasAddressTaken(); +    if (PreRegAlloc) +      UpdateSuccessorsPHIs(MBB, isDead, TDBBs, Succs); -          // Add the new vregs as available values. -          DenseMap<unsigned, AvailableValsTy>::iterator LI = -            SSAUpdateVals.find(VReg);   -          for (unsigned j = 0, ee = LI->second.size(); j != ee; ++j) { -            MachineBasicBlock *SrcBB = LI->second[j].first; -            unsigned SrcReg = LI->second[j].second; -            SSAUpdate.AddAvailableValue(SrcBB, SrcReg); -          } +    // If it is dead, remove it. +    if (isDead) { +      NumInstrDups -= MBB->size(); +      RemoveDeadBlock(MBB); +      ++NumDeadBlocks; +    } -          // Rewrite uses that are outside of the original def's block. -          MachineRegisterInfo::use_iterator UI = MRI->use_begin(VReg); -          while (UI != MRI->use_end()) { -            MachineOperand &UseMO = UI.getOperand(); -            MachineInstr *UseMI = &*UI; -            ++UI; -            if (UseMI->isDebugValue()) { -              // SSAUpdate can replace the use with an undef. That creates -              // a debug instruction that is a kill. -              // FIXME: Should it SSAUpdate job to delete debug instructions -              // instead of replacing the use with undef? -              UseMI->eraseFromParent(); -              continue; -            } -            if (UseMI->getParent() == DefBB && !UseMI->isPHI()) -              continue; -            SSAUpdate.RewriteUse(UseMO); -          } +    // Update SSA form. +    if (!SSAUpdateVRs.empty()) { +      NewPHIs.clear(); +      for (unsigned i = 0, e = SSAUpdateVRs.size(); i != e; ++i) { +        unsigned VReg = SSAUpdateVRs[i]; +        SSAUpdate.Initialize(VReg); + +        // If the original definition is still around, add it as an available +        // value. +        MachineInstr *DefMI = MRI->getVRegDef(VReg); +        MachineBasicBlock *DefBB = 0; +        if (DefMI) { +          DefBB = DefMI->getParent(); +          SSAUpdate.AddAvailableValue(DefBB, VReg);          } -        SSAUpdateVRs.clear(); -        SSAUpdateVals.clear(); -      } +        // Add the new vregs as available values. +        DenseMap<unsigned, AvailableValsTy>::iterator LI = +          SSAUpdateVals.find(VReg);   +        for (unsigned j = 0, ee = LI->second.size(); j != ee; ++j) { +          MachineBasicBlock *SrcBB = LI->second[j].first; +          unsigned SrcReg = LI->second[j].second; +          SSAUpdate.AddAvailableValue(SrcBB, SrcReg); +        } -      // Eliminate some of the copies inserted by tail duplication to maintain -      // SSA form. -      for (unsigned i = 0, e = Copies.size(); i != e; ++i) { -        MachineInstr *Copy = Copies[i]; -        if (!Copy->isCopy()) -          continue; -        unsigned Dst = Copy->getOperand(0).getReg(); -        unsigned Src = Copy->getOperand(1).getReg(); -        MachineRegisterInfo::use_iterator UI = MRI->use_begin(Src); -        if (++UI == MRI->use_end()) { -          // Copy is the only use. Do trivial copy propagation here. -          MRI->replaceRegWith(Dst, Src); -          Copy->eraseFromParent(); +        // Rewrite uses that are outside of the original def's block. +        MachineRegisterInfo::use_iterator UI = MRI->use_begin(VReg); +        while (UI != MRI->use_end()) { +          MachineOperand &UseMO = UI.getOperand(); +          MachineInstr *UseMI = &*UI; +          ++UI; +          if (UseMI->isDebugValue()) { +            // SSAUpdate can replace the use with an undef. That creates +            // a debug instruction that is a kill. +            // FIXME: Should it SSAUpdate job to delete debug instructions +            // instead of replacing the use with undef? +            UseMI->eraseFromParent(); +            continue; +          } +          if (UseMI->getParent() == DefBB && !UseMI->isPHI()) +            continue; +          SSAUpdate.RewriteUse(UseMO);          }        } -      if (PreRegAlloc && TailDupVerify) -        VerifyPHIs(MF, false); -      MadeChange = true; +      SSAUpdateVRs.clear(); +      SSAUpdateVals.clear();      } + +    // Eliminate some of the copies inserted by tail duplication to maintain +    // SSA form. +    for (unsigned i = 0, e = Copies.size(); i != e; ++i) { +      MachineInstr *Copy = Copies[i]; +      if (!Copy->isCopy()) +        continue; +      unsigned Dst = Copy->getOperand(0).getReg(); +      unsigned Src = Copy->getOperand(1).getReg(); +      MachineRegisterInfo::use_iterator UI = MRI->use_begin(Src); +      if (++UI == MRI->use_end()) { +        // Copy is the only use. Do trivial copy propagation here. +        MRI->replaceRegWith(Dst, Src); +        Copy->eraseFromParent(); +      } +    } + +    if (PreRegAlloc && TailDupVerify) +      VerifyPHIs(MF, false); +    MadeChange = true; + +    if (NewPHIs.size()) +      NumAddedPHIs += NewPHIs.size();    } -  NumAddedPHIs += NewPHIs.size(); +    return MadeChange;  } | 

