[llvm-commits] CVS: llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp MSSchedule.h MSchedGraph.cpp MSchedGraph.h

Tanya Brethour tbrethou at cs.uiuc.edu
Sun Nov 28 15:36:31 PST 2004



Changes in directory llvm/lib/Target/SparcV9/ModuloScheduling:

MSSchedule.cpp updated: 1.10 -> 1.11
MSSchedule.h updated: 1.2 -> 1.3
MSchedGraph.cpp updated: 1.10 -> 1.11
MSchedGraph.h updated: 1.5 -> 1.6
---
Log message:

Fixed bug where instructions in the kernel were not ordered right to preserve dependencies in a cycle.


---
Diffs of the changes:  (+32 -7)

Index: llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
diff -u llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp:1.10 llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp:1.11
--- llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp:1.10	Tue Nov 23 19:49:10 2004
+++ llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp	Sun Nov 28 17:36:15 2004
@@ -27,7 +27,8 @@
     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 @@
   
 }
 
+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: llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.h
diff -u llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.h:1.2 llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.h:1.3
--- llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.h:1.2	Sun Oct 10 17:44:35 2004
+++ llvm/lib/Target/SparcV9/ModuloScheduling/MSSchedule.h	Sun Nov 28 17:36:15 2004
@@ -35,6 +35,9 @@
     //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: llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.cpp
diff -u llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.cpp:1.10 llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.cpp:1.11
--- llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.cpp:1.10	Sun Oct 10 18:34:50 2004
+++ llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.cpp	Sun Nov 28 17:36:15 2004
@@ -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 @@
 
   //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 @@
       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 @@
 	}
       } 
     }
+    ++index;
   }
   addMemEdges(memInstructions);
   addMachRegEdges(regNumtoNodeMap);


Index: llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.h
diff -u llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.h:1.5 llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.h:1.6
--- llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.h:1.5	Fri Oct 29 19:39:07 2004
+++ llvm/lib/Target/SparcV9/ModuloScheduling/MSchedGraph.h	Sun Nov 28 17:36:15 2004
@@ -58,15 +58,17 @@
    
     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 @@
     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);
 






More information about the llvm-commits mailing list