Move the decision logic whether it's a good idea to split a critical edge to clients...
authorEvan Cheng <evan.cheng@apple.com>
Tue, 17 Aug 2010 17:43:50 +0000 (17:43 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Tue, 17 Aug 2010 17:43:50 +0000 (17:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111256 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MachineBasicBlock.cpp
lib/CodeGen/PHIElimination.cpp
lib/CodeGen/PHIElimination.h

index f506f12050aa7ecb824574edae06290298dd9698..d351db59e69000c1cf82e87df39a7c20ace4e88c 100644 (file)
@@ -439,14 +439,6 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) {
   if (TII->AnalyzeBranch(*this, TBB, FBB, Cond))
     return NULL;
 
-  // Avoid splitting backedges of loops. It would introduce small out-of-line
-  // blocks into the loop which is very bad for code placement.
-  if (this == Succ)
-    return NULL;
-  MachineLoopInfo *MLI = P->getAnalysisIfAvailable<MachineLoopInfo>();
-  if (MLI->isLoopHeader(Succ))
-    return NULL;
-
   MachineBasicBlock *NMBB = MF->CreateMachineBasicBlock();
   MF->insert(llvm::next(MachineFunction::iterator(this)), NMBB);
   DEBUG(dbgs() << "Splitting critical edge:"
@@ -479,7 +471,7 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) {
         P->getAnalysisIfAvailable<MachineDominatorTree>())
     MDT->addNewBlock(NMBB, this);
 
-  if (MLI)
+  if (MachineLoopInfo *MLI = P->getAnalysisIfAvailable<MachineLoopInfo>())
     if (MachineLoop *TIL = MLI->getLoopFor(this)) {
       // If one or the other blocks were not in a loop, the new block is not
       // either, and thus LI doesn't need to be updated.
index 105f20b44898fff42f603e335765ca4fff52314a..11566c2d866bc4208b3a042572c976a7c3a82b45 100644 (file)
@@ -53,6 +53,7 @@ void llvm::PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
 
 bool llvm::PHIElimination::runOnMachineFunction(MachineFunction &MF) {
   MRI = &MF.getRegInfo();
+  MLI = getAnalysisIfAvailable<MachineLoopInfo>();
 
   bool Changed = false;
 
@@ -392,8 +393,14 @@ bool llvm::PHIElimination::SplitPHIEdges(MachineFunction &MF,
       // We break edges when registers are live out from the predecessor block
       // (not considering PHI nodes). If the register is live in to this block
       // anyway, we would gain nothing from splitting.
-      if (!LV.isLiveIn(Reg, MBB) && LV.isLiveOut(Reg, *PreMBB))
-        Changed |= PreMBB->SplitCriticalEdge(&MBB, this) != 0;
+      // Avoid splitting backedges of loops. It would introduce small
+      // out-of-line blocks into the loop which is very bad for code placement.
+      if (PreMBB != &MBB &&
+          !LV.isLiveIn(Reg, MBB) && LV.isLiveOut(Reg, *PreMBB)) {
+        if (!(MLI->getLoopFor(PreMBB) == MLI->getLoopFor(&MBB) &&
+              MLI->isLoopHeader(&MBB)))
+          Changed |= PreMBB->SplitCriticalEdge(&MBB, this) != 0;
+      }
     }
   }
   return true;
index f183de6149ccbbb5f567ef3ae28bce28ddf95ad1..b054732dace526972fc11894117342357e8ab5c8 100644 (file)
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/MachineRegisterInfo.h"
 
 namespace llvm {
   class LiveVariables;
+  class MachineRegisterInfo;
+  class MachineLoopInfo;
   
   /// Lower PHI instructions to copies.  
   class PHIElimination : public MachineFunctionPass {
-    MachineRegisterInfo  *MRI; // Machine register information
+    MachineRegisterInfo *MRI; // Machine register information
+    MachineLoopInfo     *MLI;
 
   public:
     static char ID; // Pass identification, replacement for typeid