As Chris and Evan pointed out, BreakCriticalMachineEdges doesn't really need
authorOwen Anderson <resistor@mac.com>
Mon, 12 Nov 2007 01:05:09 +0000 (01:05 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 12 Nov 2007 01:05:09 +0000 (01:05 +0000)
to be a pass of its own.  Instead, move it out into a helper method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44002 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/BreakCriticalMachineEdge.h [new file with mode: 0644]
include/llvm/CodeGen/Passes.h
lib/CodeGen/BreakCriticalMachineEdges.cpp [deleted file]
lib/CodeGen/StrongPHIElimination.cpp
lib/CodeGen/TwoAddressInstructionPass.cpp

diff --git a/include/llvm/CodeGen/BreakCriticalMachineEdge.h b/include/llvm/CodeGen/BreakCriticalMachineEdge.h
new file mode 100644 (file)
index 0000000..c02eaa7
--- /dev/null
@@ -0,0 +1,94 @@
+//===--------- BreakCriticalMachineEdges.h - Break critical edges ---------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Fernando Pereira and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===---------------------------------------------------------------------===//
+//
+// Helper function to break a critical machine edge.
+//
+//===---------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_ASMPRINTER_H
+#define LLVM_CODEGEN_ASMPRINTER_H
+
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineJumpTableInfo.h"
+#include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/Compiler.h"
+
+namespace llvm {
+
+MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src,
+                                            MachineBasicBlock* dst) {
+  const BasicBlock* srcBB = src->getBasicBlock();
+
+  MachineBasicBlock* crit_mbb = new MachineBasicBlock(srcBB);
+
+  // modify the llvm control flow graph
+  src->removeSuccessor(dst);
+  src->addSuccessor(crit_mbb);
+  crit_mbb->addSuccessor(dst);
+
+  // insert the new block into the machine function.
+  src->getParent()->getBasicBlockList().insert(src->getParent()->end(),
+                                               crit_mbb);
+
+  // insert a unconditional branch linking the new block to dst
+  const TargetMachine& TM = src->getParent()->getTarget();
+  const TargetInstrInfo* TII = TM.getInstrInfo();
+  std::vector<MachineOperand> emptyConditions;
+  TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0, emptyConditions);
+
+  // modify every branch in src that points to dst to point to the new
+  // machine basic block instead:
+  MachineBasicBlock::iterator mii = src->end();
+  bool found_branch = false;
+  while (mii != src->begin()) {
+    mii--;
+    // if there are no more branches, finish the loop
+    if (!TII->isTerminatorInstr(mii->getOpcode())) {
+      break;
+    }
+    
+    // Scan the operands of this branch, replacing any uses of dst with
+    // crit_mbb.
+    for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) {
+      MachineOperand & mo = mii->getOperand(i);
+      if (mo.isMachineBasicBlock() &&
+          mo.getMachineBasicBlock() == dst) {
+        found_branch = true;
+        mo.setMachineBasicBlock(crit_mbb);
+      }
+    }
+  }
+
+  // TODO: This is tentative. It may be necessary to fix this code. Maybe
+  // I am inserting too many gotos, but I am trusting that the asm printer
+  // will optimize the unnecessary gotos.
+  if(!found_branch) {
+    TII->InsertBranch(*src, crit_mbb, (MachineBasicBlock*)0, emptyConditions);
+  }
+
+  /// Change all the phi functions in dst, so that the incoming block be
+  /// crit_mbb, instead of src
+  for(mii = dst->begin(); mii != dst->end(); mii++) {
+    /// the first instructions are always phi functions.
+    if(mii->getOpcode() != TargetInstrInfo::PHI)
+      break;
+    
+    for (unsigned u = 0; u != mii->getNumOperands(); ++u)
+      if (mii->getOperand(u).isMachineBasicBlock() &&
+          mii->getOperand(u).getMachineBasicBlock() == src)
+        mii->getOperand(u).setMachineBasicBlock(crit_mbb);
+  }
+  
+  return crit_mbb;
+}
+
+}
+
+#endif
index 89e8ba9b37a0f4a0d24f35143fd4e59bd60abc0e..5e93525ab479b104dd173488c4edae7360e8378c 100644 (file)
@@ -58,10 +58,6 @@ namespace llvm {
   ///
   extern const PassInfo *SimpleRegisterCoalescingID;
 
-  /// BreakCriticalMachineEdges pass.  Breaks critical edges between
-  /// machine basic blocks.
-  extern const PassInfo *BreakCriticalMachineEdgesID;
-
   /// TwoAddressInstruction pass - This pass reduces two-address instructions to
   /// use two operands. This destroys SSA information but it is desired by
   /// register allocators.
diff --git a/lib/CodeGen/BreakCriticalMachineEdges.cpp b/lib/CodeGen/BreakCriticalMachineEdges.cpp
deleted file mode 100644 (file)
index 21d9dbb..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-//===----------- BreakCriticalMachineEdges - Break critical edges ---------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by Fernando Pereira and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===---------------------------------------------------------------------===//
-//
-// Break all of the critical edges in the CFG by inserting a dummy basic block. 
-// This pass may be "required" by passes that cannot deal with critical edges.
-// Notice that this pass invalidates the CFG, because the same BasicBlock is 
-// used as parameter for the src MachineBasicBlock and the new dummy
-// MachineBasicBlock.
-//
-//===---------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/Passes.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineJumpTableInfo.h"
-#include "llvm/Target/TargetInstrInfo.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/ADT/Statistic.h"
-#include "llvm/Support/Compiler.h"
-
-using namespace llvm;
-
-namespace {
-  struct VISIBILITY_HIDDEN BreakCriticalMachineEdges :
-                           public MachineFunctionPass {
-    static char ID; // Pass identification
-    BreakCriticalMachineEdges() : MachineFunctionPass((intptr_t)&ID) {}
-    
-    bool runOnMachineFunction(MachineFunction& Fn);
-    void splitCriticalEdge(MachineBasicBlock* A, MachineBasicBlock* B);
-  };
-  
-  char BreakCriticalMachineEdges::ID = 0;
-  RegisterPass<BreakCriticalMachineEdges> X("critical-machine-edges",
-                                            "Break critical machine code edges");
-}
-
-const PassInfo *llvm::BreakCriticalMachineEdgesID = X.getPassInfo();
-
-void BreakCriticalMachineEdges::splitCriticalEdge(MachineBasicBlock* src,
-                                                  MachineBasicBlock* dst) {
-  const BasicBlock* srcBB = src->getBasicBlock();
-
-  MachineBasicBlock* crit_mbb = new MachineBasicBlock(srcBB);
-
-  // modify the llvm control flow graph
-  src->removeSuccessor(dst);
-  src->addSuccessor(crit_mbb);
-  crit_mbb->addSuccessor(dst);
-
-  // insert the new block into the machine function.
-  src->getParent()->getBasicBlockList().insert(src->getParent()->end(),
-                                               crit_mbb);
-
-  // insert a unconditional branch linking the new block to dst
-  const TargetMachine& TM = src->getParent()->getTarget();
-  const TargetInstrInfo* TII = TM.getInstrInfo();
-  std::vector<MachineOperand> emptyConditions;
-  TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0, emptyConditions);
-
-  // modify every branch in src that points to dst to point to the new
-  // machine basic block instead:
-  MachineBasicBlock::iterator mii = src->end();
-  bool found_branch = false;
-  while (mii != src->begin()) {
-    mii--;
-    // if there are no more branches, finish the loop
-    if (!TII->isTerminatorInstr(mii->getOpcode())) {
-      break;
-    }
-    
-    // Scan the operands of this branch, replacing any uses of dst with
-    // crit_mbb.
-    for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) {
-      MachineOperand & mo = mii->getOperand(i);
-      if (mo.isMachineBasicBlock() &&
-          mo.getMachineBasicBlock() == dst) {
-        found_branch = true;
-        mo.setMachineBasicBlock(crit_mbb);
-      }
-    }
-  }
-
-  // TODO: This is tentative. It may be necessary to fix this code. Maybe
-  // I am inserting too many gotos, but I am trusting that the asm printer
-  // will optimize the unnecessary gotos.
-  if(!found_branch) {
-    TII->InsertBranch(*src, crit_mbb, (MachineBasicBlock*)0, emptyConditions);
-  }
-
-  /// Change all the phi functions in dst, so that the incoming block be
-  /// crit_mbb, instead of src
-  for(mii = dst->begin(); mii != dst->end(); mii++) {
-    /// the first instructions are always phi functions.
-    if(mii->getOpcode() != TargetInstrInfo::PHI)
-      break;
-    
-    for (unsigned u = 0; u != mii->getNumOperands(); ++u)
-      if (mii->getOperand(u).isMachineBasicBlock() &&
-          mii->getOperand(u).getMachineBasicBlock() == src)
-        mii->getOperand(u).setMachineBasicBlock(crit_mbb);
-  }
-}
-
-bool BreakCriticalMachineEdges::runOnMachineFunction(MachineFunction& F) {
-  std::vector<MachineBasicBlock *> SourceBlocks;
-  std::vector<MachineBasicBlock *> DestBlocks;
-
-  for(MachineFunction::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) {
-    for(MachineBasicBlock::succ_iterator SI = FI->succ_begin(),
-        SE = FI->succ_end(); SI != SE; ++SI) {
-      // predecessor with multiple successors, successor with multiple
-      // predecessors.
-      if (FI->succ_size() > 1 && (*SI)->pred_size() > 1) {
-        SourceBlocks.push_back(FI);
-        DestBlocks.push_back(*SI);
-      }
-    }
-  }
-
-  for(unsigned u = 0; u < SourceBlocks.size(); u++)
-    splitCriticalEdge(SourceBlocks[u], DestBlocks[u]);
-
-  return false;
-}
index 5f84b586cb8a0aea9ec2da00837703309692862e..f64186e8e8cdc17b48d6e1798b847bebd3cb9740 100644 (file)
@@ -21,6 +21,7 @@
 
 #define DEBUG_TYPE "strongphielim"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/CodeGen/BreakCriticalMachineEdge.h"
 #include "llvm/CodeGen/LiveVariables.h"
 #include "llvm/CodeGen/MachineDominators.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
index defd6ce6fbe7a55c016bfb34655623ed4832bc04..b8d38dc229ef4b6e15fb145824988c2ae258df3b 100644 (file)
@@ -70,7 +70,6 @@ void TwoAddressInstructionPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<LiveVariables>();
   AU.addPreserved<LiveVariables>();
   AU.addPreservedID(PHIEliminationID);
-  AU.addPreservedID(BreakCriticalMachineEdgesID);
   MachineFunctionPass::getAnalysisUsage(AU);
 }