Fixed bug where instructions in the kernel were not ordered right to preserve depende...
authorTanya Lattner <tonic@nondot.org>
Sun, 28 Nov 2004 23:36:15 +0000 (23:36 +0000)
committerTanya Lattner <tonic@nondot.org>
Sun, 28 Nov 2004 23:36:15 +0000 (23:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18314 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
lib/Target/SparcV9/ModuloScheduling/MSSchedule.h
lib/Target/SparcV9/ModuloScheduling/MSchedGraph.cpp
lib/Target/SparcV9/ModuloScheduling/MSchedGraph.h

index 7ee77510f06aba1abbe1638cd24f9b94a1700ccf..29aba158c30d31f2cde358c16aa3f730323e0351 100644 (file)
@@ -27,7 +27,8 @@ bool MSSchedule::insert(MSchedGraphNode *node, int cycle) {
     if (schedule[cycle].size() < numIssue) {
       //Now check if all the resources in their respective cycles are available
       if(resourcesFree(node, cycle)) {
-       schedule[cycle].push_back(node);
+       //Insert to preserve dependencies
+       addToSchedule(cycle,node);
        DEBUG(std::cerr << "Found spot in map, and there is an issue slot\n");
        return false;
       }
@@ -49,6 +50,24 @@ bool MSSchedule::insert(MSchedGraphNode *node, int cycle) {
   
 }
 
+void MSSchedule::addToSchedule(int cycle, MSchedGraphNode *node) {
+  std::vector<MSchedGraphNode*> nodesAtCycle = schedule[cycle];
+
+  std::map<unsigned, MSchedGraphNode*> indexMap;
+  for(unsigned i=0; i < nodesAtCycle.size(); ++i) {
+    indexMap[nodesAtCycle[i]->getIndex()] = nodesAtCycle[i];
+  }
+
+  indexMap[node->getIndex()] = node;
+
+  std::vector<MSchedGraphNode*> nodes;
+  for(std::map<unsigned, MSchedGraphNode*>::iterator I = indexMap.begin(), E = indexMap.end(); I != E; ++I)
+    nodes.push_back(I->second);
+  
+  schedule[cycle] =  nodes;
+}
+
+
 bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
   
   //Get Resource usage for this instruction
index 248a74859177bba025d342287da52d3a4459e36d..fcf405d72403d266847ecafd73535b6003d8574c 100644 (file)
@@ -35,6 +35,9 @@ namespace llvm {
     //Max stage count
     int maxStage;
 
+    //add at the right spot in the schedule
+    void addToSchedule(int, MSchedGraphNode*);
+
   public:
     MSSchedule(int num) : numIssue(num) {}
     MSSchedule() : numIssue(4) {}
index a3b02f7821e695d1b4917bb93046009a28145c50..5a415e7546aaec4b371bfd240d899258fd01460f 100644 (file)
@@ -22,9 +22,9 @@
 using namespace llvm;
 
 MSchedGraphNode::MSchedGraphNode(const MachineInstr* inst, 
-                                MSchedGraph *graph, 
+                                MSchedGraph *graph, unsigned idx,
                                 unsigned late, bool isBranch) 
-  : Inst(inst), Parent(graph), latency(late), isBranchInstr(isBranch) {
+  : Inst(inst), Parent(graph), index(idx), latency(late), isBranchInstr(isBranch) {
 
   //Add to the graph
   graph->addNode(inst, this);
@@ -113,7 +113,7 @@ void MSchedGraph::buildNodesAndEdges() {
 
   //Save PHI instructions to deal with later
   std::vector<const MachineInstr*> phiInstrs;
-
+  unsigned index = 0;
   //Loop over instructions in MBB and add nodes and edges
   for (MachineBasicBlock::const_iterator MI = BB->begin(), e = BB->end(); MI != e; ++MI) {
     //Get each instruction of machine basic block, get the delay
@@ -149,7 +149,7 @@ void MSchedGraph::buildNodesAndEdges() {
       isBranch = true;
 
     //Node is created and added to the graph automatically
-    MSchedGraphNode *node =  new MSchedGraphNode(MI, this, delay, isBranch);
+    MSchedGraphNode *node =  new MSchedGraphNode(MI, this, index, delay, isBranch);
 
     DEBUG(std::cerr << "Created Node: " << *node << "\n"); 
 
@@ -211,6 +211,7 @@ void MSchedGraph::buildNodesAndEdges() {
        }
       } 
     }
+    ++index;
   }
   addMemEdges(memInstructions);
   addMachRegEdges(regNumtoNodeMap);
index baa6373510edc164b7a65723ffe68d3c96563592..36b76324cbe903c9c077b62e19fb1167c017eac5 100644 (file)
@@ -58,15 +58,17 @@ namespace llvm {
    
     const MachineInstr* Inst; //Machine Instruction
     MSchedGraph* Parent; //Graph this node belongs to
+    unsigned index; //Index in BB
     unsigned latency; //Latency of Instruction
     bool isBranchInstr; //Is this node the branch instr or not
+    
 
     std::vector<MSchedGraphNode*> Predecessors; //Predecessor Nodes
     std::vector<MSchedGraphEdge> Successors;
 
   public:
     MSchedGraphNode(const MachineInstr *inst, MSchedGraph *graph, 
-                   unsigned late=0, bool isBranch=false);
+                   unsigned index, unsigned late=0, bool isBranch=false);
 
     //Iterators
     typedef std::vector<MSchedGraphNode*>::iterator pred_iterator;
@@ -102,7 +104,7 @@ namespace llvm {
     bool hasSuccessors() { return (Successors.size() > 0); }
     unsigned getLatency() { return latency; }
     unsigned getLatency() const { return latency; }
-
+    unsigned getIndex() { return index; }
     MSchedGraphEdge getInEdge(MSchedGraphNode *pred);
     unsigned getInEdgeNum(MSchedGraphNode *pred);