Changes For Bug 352
[oota-llvm.git] / lib / CodeGen / ModuloScheduling / MSchedGraph.cpp
index b441bea051256c17a64379ec3387f2510b1f8a66..5bdcc9afcf28dd2707819056ddbec5adb504448e 100644 (file)
@@ -1,4 +1,4 @@
-//===-- MSchedGraph.cpp - Scheduling Graph ------------------------*- C++ -*-===//
+//===-- MSchedGraph.cpp - Scheduling Graph ----------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -16,7 +16,8 @@
 #include "../../Target/SparcV9/SparcV9RegisterInfo.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/Target/TargetInstrInfo.h"
-#include "Support/Debug.h"
+#include "llvm/Support/Debug.h"
+#include <cstdlib>
 using namespace llvm;
 
 MSchedGraphNode::MSchedGraphNode(const MachineInstr* inst, 
@@ -35,13 +36,13 @@ void MSchedGraphNode::print(std::ostream &os) const {
 MSchedGraphEdge MSchedGraphNode::getInEdge(MSchedGraphNode *pred) {
   //Loop over all the successors of our predecessor
   //return the edge the corresponds to this in edge
-  for(MSchedGraphNode::succ_iterator I = pred->succ_begin(), E = pred->succ_end();
-      I != E; ++I) {
-    if(*I == this)
+  for (MSchedGraphNode::succ_iterator I = pred->succ_begin(), 
+         E = pred->succ_end(); I != E; ++I) {
+    if (*I == this)
       return I.getEdge();
   }
   assert(0 && "Should have found edge between this node and its predecessor!");
+  abort();
 }
 
 unsigned MSchedGraphNode::getInEdgeNum(MSchedGraphNode *pred) {
@@ -103,7 +104,7 @@ MSchedGraph::~MSchedGraph () {
 void MSchedGraph::buildNodesAndEdges() {
   
   //Get Machine target information for calculating latency
-  const TargetInstrInfo &MTI = Target.getInstrInfo();
+  const TargetInstrInfo *MTI = Target.getInstrInfo();
 
   std::vector<MSchedGraphNode*> memInstructions;
   std::map<int, std::vector<OpIndexNodePair> > regNumtoNodeMap;
@@ -124,16 +125,16 @@ void MSchedGraph::buildNodesAndEdges() {
 #if 0  // FIXME: LOOK INTO THIS
     //Check if subsequent instructions can be issued before
     //the result is ready, if so use min delay.
-    if(MTI.hasResultInterlock(MIopCode))
-      delay = MTI.minLatency(MIopCode);
+    if(MTI->hasResultInterlock(MIopCode))
+      delay = MTI->minLatency(MIopCode);
     else
 #endif
       //Get delay
-      delay = MTI.maxLatency(opCode);
+      delay = MTI->maxLatency(opCode);
     
     //Create new node for this machine instruction and add to the graph.
     //Create only if not a nop
-    if(MTI.isNop(opCode))
+    if(MTI->isNop(opCode))
       continue;
     
     //Add PHI to phi instruction list to be processed later
@@ -143,7 +144,7 @@ void MSchedGraph::buildNodesAndEdges() {
     bool isBranch = false;
 
     //We want to flag the branch node to treat it special
-    if(MTI.isBranch(opCode))
+    if(MTI->isBranch(opCode))
       isBranch = true;
 
     //Node is created and added to the graph automatically
@@ -152,7 +153,7 @@ void MSchedGraph::buildNodesAndEdges() {
     DEBUG(std::cerr << "Created Node: " << *node << "\n"); 
 
     //Check OpCode to keep track of memory operations to add memory dependencies later.    
-    if(MTI.isLoad(opCode) || MTI.isStore(opCode))
+    if(MTI->isLoad(opCode) || MTI->isStore(opCode))
       memInstructions.push_back(node);
 
     //Loop over all operands, and put them into the register number to
@@ -370,7 +371,7 @@ void MSchedGraph::addMachRegEdges(std::map<int, std::vector<OpIndexNodePair> >&
 void MSchedGraph::addMemEdges(const std::vector<MSchedGraphNode*>& memInst) {
 
   //Get Target machine instruction info
-  const TargetInstrInfoTMI = Target.getInstrInfo();
+  const TargetInstrInfo *TMI = Target.getInstrInfo();
   
   //Loop over all memory instructions in the vector
   //Knowing that they are in execution, add true, anti, and output dependencies
@@ -383,15 +384,15 @@ void MSchedGraph::addMemEdges(const std::vector<MSchedGraphNode*>& memInst) {
     for(unsigned destIndex = srcIndex + 1; destIndex < memInst.size(); ++destIndex) {
        
       //source is a Load, so add anti-dependencies (store after load)
-      if(TMI.isLoad(srcNodeOpCode))
-       if(TMI.isStore(memInst[destIndex]->getInst()->getOpcode()))
+      if(TMI->isLoad(srcNodeOpCode))
+       if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
          memInst[srcIndex]->addOutEdge(memInst[destIndex], 
                              MSchedGraphEdge::MemoryDep, 
                              MSchedGraphEdge::AntiDep);
       
       //If source is a store, add output and true dependencies
-      if(TMI.isStore(srcNodeOpCode)) {
-       if(TMI.isStore(memInst[destIndex]->getInst()->getOpcode()))
+      if(TMI->isStore(srcNodeOpCode)) {
+       if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
           memInst[srcIndex]->addOutEdge(memInst[destIndex], 
                              MSchedGraphEdge::MemoryDep, 
                              MSchedGraphEdge::OutputDep);
@@ -405,13 +406,13 @@ void MSchedGraph::addMemEdges(const std::vector<MSchedGraphNode*>& memInst) {
     //All instructions before the src in execution order have an iteration delay of 1
     for(unsigned destIndex = 0; destIndex < srcIndex; ++destIndex) {
       //source is a Load, so add anti-dependencies (store after load)
-      if(TMI.isLoad(srcNodeOpCode))
-       if(TMI.isStore(memInst[destIndex]->getInst()->getOpcode()))
+      if(TMI->isLoad(srcNodeOpCode))
+       if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
          memInst[srcIndex]->addOutEdge(memInst[destIndex], 
                              MSchedGraphEdge::MemoryDep, 
                              MSchedGraphEdge::AntiDep, 1);
-      if(TMI.isStore(srcNodeOpCode)) {
-       if(TMI.isStore(memInst[destIndex]->getInst()->getOpcode()))
+      if(TMI->isStore(srcNodeOpCode)) {
+       if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
          memInst[srcIndex]->addOutEdge(memInst[destIndex], 
                              MSchedGraphEdge::MemoryDep, 
                              MSchedGraphEdge::OutputDep, 1);