Add option to disable scheduling.
[oota-llvm.git] / lib / CodeGen / InstrSched / SchedPriorities.cpp
index 8cde2521151c1b72d24d4c3cd703102a33735961..ef9f9e459972bb2b01c3f2ce341926fd18a872fc 100644 (file)
 //**************************************************************************/
 
 #include "SchedPriorities.h"
+#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
+#include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 #include <iostream>
 using std::cerr;
 
-SchedPriorities::SchedPriorities(const Method* method,
-                                const SchedGraph* _graph)
-  : curTime(0),
-    graph(_graph),
-    methodLiveVarInfo(method),                           // expensive!
-    nodeDelayVec(_graph->getNumNodes(), INVALID_LATENCY), // make errors obvious
-    earliestForNode(_graph->getNumNodes(), 0),
+SchedPriorities::SchedPriorities(const Method *method, const SchedGraph *G,
+                                 MethodLiveVarInfo &LVI)
+  : curTime(0), graph(G), methodLiveVarInfo(LVI),
+    nodeDelayVec(G->getNumNodes(), INVALID_LATENCY), // make errors obvious
+    earliestForNode(G->getNumNodes(), 0),
     earliestReadyTime(0),
-    nextToTry(candsAsHeap.begin())
-{
-  methodLiveVarInfo.analyze();
+    nextToTry(candsAsHeap.begin()) {
   computeDelays(graph);
 }
 
@@ -267,29 +265,26 @@ SchedPriorities::findSetWithMaxDelay(std::vector<candIndex>& mcands,
 
 bool
 SchedPriorities::instructionHasLastUse(MethodLiveVarInfo& methodLiveVarInfo,
-                                      const SchedGraphNode* graphNode)
-{
-  const MachineInstr* minstr = graphNode->getMachineInstr();
+                                      const SchedGraphNode* graphNode) {
+  const MachineInstr *MI = graphNode->getMachineInstr();
   
   std::hash_map<const MachineInstr*, bool>::const_iterator
-    ui = lastUseMap.find(minstr);
+    ui = lastUseMap.find(MI);
   if (ui != lastUseMap.end())
     return ui->second;
   
   // else check if instruction is a last use and save it in the hash_map
   bool hasLastUse = false;
   const BasicBlock* bb = graphNode->getBB();
-  const LiveVarSet* liveVars =
-    methodLiveVarInfo.getLiveVarSetBeforeMInst(minstr, bb);
-  
-  for (MachineInstr::val_const_op_iterator vo(minstr); ! vo.done(); ++vo)
-    if (liveVars->find(*vo) == liveVars->end())
-      {
-       hasLastUse = true;
-       break;
-      }
+  const ValueSet &LVs = methodLiveVarInfo.getLiveVarSetBeforeMInst(MI, bb);
   
-  lastUseMap[minstr] = hasLastUse;
-  return hasLastUse;
+  for (MachineInstr::const_val_op_iterator OI = MI->begin(), OE = MI->end();
+       OI != OE; ++OI)
+    if (!LVs.count(*OI)) {
+      hasLastUse = true;
+      break;
+    }
+
+  return lastUseMap[MI] = hasLastUse;
 }