Allow emission of names that start with an underscore. This is needed to
[oota-llvm.git] / lib / Target / SparcV9 / InstrSched / SchedGraph.cpp
index 781604eaae7c1f33b25ec7a758c848b6ee674748..c3262c09df0595e3ef939057005377be420fb10c 100644 (file)
@@ -1,16 +1,10 @@
-// $Id$
-//***************************************************************************
-// File:
-//     SchedGraph.cpp
-// 
-// Purpose:
-//     Scheduling graph based on SSA graph plus extra dependence edges
-//     capturing dependences due to machine resources (machine registers,
-//     CC registers, and any others).
-// 
-// History:
-//     7/20/01  -  Vikram Adve  -  Created
-//**************************************************************************/
+//===- SchedGraph.cpp - Scheduling Graph Implementation -------------------===//
+//
+// Scheduling graph based on SSA graph plus extra dependence edges capturing
+// dependences due to machine resources (machine registers, CC registers, and
+// any others).
+//
+//===----------------------------------------------------------------------===//
 
 #include "SchedGraph.h"
 #include "llvm/CodeGen/InstrSelection.h"
 #include "llvm/CodeGen/MachineCodeForBasicBlock.h"
 #include "llvm/Target/MachineRegInfo.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/BasicBlock.h"
 #include "llvm/Function.h"
 #include "llvm/iOther.h"
 #include "Support/StringExtras.h"
 #include "Support/STLExtras.h"
-#include <iostream>
 
 using std::vector;
 using std::pair;
@@ -349,29 +341,31 @@ SchedGraph::addCDEdges(const TerminatorInst* term,
   // Find the first branch instr in the sequence of machine instrs for term
   // 
   unsigned first = 0;
-  while (!mii.isBranch(termMvec[first]->getOpCode()))
+  while (! mii.isBranch(termMvec[first]->getOpCode()) &&
+         ! mii.isReturn(termMvec[first]->getOpCode()))
     ++first;
   assert(first < termMvec.size() &&
-        "No branch instructions for BR?  Ok, but weird!  Delete assertion.");
+        "No branch instructions for terminator?  Ok, but weird!");
   if (first == termMvec.size())
     return;
-  
-  SchedGraphNode* firstBrNode = this->getGraphNodeForInstr(termMvec[first]);
-  
+
+  SchedGraphNode* firstBrNode = getGraphNodeForInstr(termMvec[first]);
+
   // Add CD edges from each instruction in the sequence to the
   // *last preceding* branch instr. in the sequence 
   // Use a latency of 0 because we only need to prevent out-of-order issue.
   // 
-  for (int i = (int) termMvec.size()-1; i > (int) first; i--) 
+  for (unsigned i = termMvec.size(); i > first+1; --i)
     {
-      SchedGraphNode* toNode = this->getGraphNodeForInstr(termMvec[i]);
-      assert(toNode && "No node for instr generated for branch?");
+      SchedGraphNode* toNode = getGraphNodeForInstr(termMvec[i-1]);
+      assert(toNode && "No node for instr generated for branch/ret?");
       
-      for (int j = i-1; j >= 0; j--) 
-       if (mii.isBranch(termMvec[j]->getOpCode()))
+      for (unsigned j = i-1; j != 0; --j) 
+       if (mii.isBranch(termMvec[j-1]->getOpCode()) ||
+            mii.isReturn(termMvec[j-1]->getOpCode()))
          {
-           SchedGraphNode* brNode = this->getGraphNodeForInstr(termMvec[j]);
-           assert(brNode && "No node for instr generated for branch?");
+           SchedGraphNode* brNode = getGraphNodeForInstr(termMvec[j-1]);
+           assert(brNode && "No node for instr generated for branch/ret?");
            (void) new SchedGraphEdge(brNode, toNode, SchedGraphEdge::CtrlDep,
                                      SchedGraphEdge::NonDataDep, 0);
            break;                      // only one incoming edge is enough
@@ -381,9 +375,9 @@ SchedGraph::addCDEdges(const TerminatorInst* term,
   // Add CD edges from each instruction preceding the first branch
   // to the first branch.  Use a latency of 0 as above.
   // 
-  for (int i = first-1; i >= 0; i--) 
+  for (unsigned i = first; i != 0; --i)
     {
-      SchedGraphNode* fromNode = this->getGraphNodeForInstr(termMvec[i]);
+      SchedGraphNode* fromNode = getGraphNodeForInstr(termMvec[i-1]);
       assert(fromNode && "No node for instr generated for branch?");
       (void) new SchedGraphEdge(fromNode, firstBrNode, SchedGraphEdge::CtrlDep,
                                SchedGraphEdge::NonDataDep, 0);
@@ -396,7 +390,7 @@ SchedGraph::addCDEdges(const TerminatorInst* term,
   const MachineCodeForBasicBlock& mvec = MachineCodeForBasicBlock::get(bb);
   for (unsigned i=0, N=mvec.size(); i < N; i++) 
     {
-      if (mvec[i] == termMvec[first]) // reached the first branch
+      if (mvec[i] == termMvec[first])   // reached the first branch
         break;
       
       SchedGraphNode* fromNode = this->getGraphNodeForInstr(mvec[i]);