-// $Id$ -*-C++-*-
-//***************************************************************************
-// File:
-// SchedPriorities.h
+//===-- SchedPriorities.h - Encapsulate scheduling heuristics -------------===//
//
-// Purpose:
-// Encapsulate heuristics for instruction scheduling.
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// Strategy:
// Priority ordering rules:
// (3) Instruction that has the maximum number of dependent instructions.
// Note that rules 2 and 3 are only used if issue conflicts prevent
// choosing a higher priority instruction by rule 1.
-//
-// History:
-// 7/30/01 - Vikram Adve - Created
-//**************************************************************************/
+//
+//===----------------------------------------------------------------------===//
#include "SchedPriorities.h"
-#include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
+#include "llvm/CodeGen/FunctionLiveVarInfo.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h"
-#include <iostream>
using std::cerr;
+std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) {
+ return os << "Delay for node " << nd->node->getNodeId()
+ << " = " << (long)nd->delay << "\n";
+}
+
+
SchedPriorities::SchedPriorities(const Function *, const SchedGraph *G,
FunctionLiveVarInfo &LVI)
: curTime(0), graph(G), methodLiveVarInfo(LVI),
nodeDelayVec(G->getNumNodes(), INVALID_LATENCY), // make errors obvious
- earliestForNode(G->getNumNodes(), 0),
+ earliestReadyTimeForNode(G->getNumNodes(), 0),
earliestReadyTime(0),
- nextToTry(candsAsHeap.begin()) {
+ nextToTry(candsAsHeap.begin())
+{
computeDelays(graph);
}
const SchedGraphNode* node = *poIter;
cycles_t nodeDelay;
if (node->beginOutEdges() == node->endOutEdges())
- nodeDelay = node->getLatency();
+ nodeDelay = node->getLatency();
else
{
// Iterate over the out-edges of the node to compute delay
for (SchedGraphNode::const_iterator E=node->beginOutEdges();
E != node->endOutEdges(); ++E)
{
- cycles_t sinkDelay = getNodeDelayRef((*E)->getSink());
+ cycles_t sinkDelay = getNodeDelay((SchedGraphNode*)(*E)->getSink());
nodeDelay = std::max(nodeDelay, sinkDelay + (*E)->getMinDelay());
}
}
void
SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
{
- const SchedGraphNode* graphRoot = graph->getRoot();
+ const SchedGraphNode* graphRoot = (const SchedGraphNode*)graph->getRoot();
assert(graphRoot->getMachineInstr() == NULL && "Expect dummy root");
// Insert immediate successors of dummy root, which are the actual roots
candsAsSet.insert(node);
mcands.clear(); // ensure reset choices is called before any more choices
earliestReadyTime = std::min(earliestReadyTime,
- earliestForNode[node->getNodeId()]);
+ getEarliestReadyTimeForNode(node));
if (SchedDebugLevel >= Sched_PrintSchedTrace)
{
cerr << " Node " << node->getNodeId() << " will be ready in Cycle "
- << earliestForNode[node->getNodeId()] << "; "
- << " Delay = " <<(long)getNodeDelayRef(node) << "; Instruction: \n";
+ << getEarliestReadyTimeForNode(node) << "; "
+ << " Delay = " <<(long)getNodeDelay(node) << "; Instruction: \n";
cerr << " " << *node->getMachineInstr() << "\n";
}
}
candsAsSet.erase(node);
mcands.clear(); // ensure reset choices is called before any more choices
- if (earliestReadyTime == getEarliestForNodeRef(node))
+ if (earliestReadyTime == getEarliestReadyTimeForNode(node))
{// earliestReadyTime may have been due to this node, so recompute it
earliestReadyTime = HUGE_LATENCY;
for (NodeHeap::const_iterator I=candsAsHeap.begin();
I != candsAsHeap.end(); ++I)
if (candsAsHeap.getNode(I))
earliestReadyTime = std::min(earliestReadyTime,
- getEarliestForNodeRef(candsAsHeap.getNode(I)));
+ getEarliestReadyTimeForNode(candsAsHeap.getNode(I)));
}
// Now update ready times for successors
for (SchedGraphNode::const_iterator E=node->beginOutEdges();
E != node->endOutEdges(); ++E)
{
- cycles_t& etime = getEarliestForNodeRef((*E)->getSink());
+ cycles_t& etime = getEarliestReadyTimeForNodeRef((SchedGraphNode*)(*E)->getSink());
etime = std::max(etime, curTime + (*E)->getMinDelay());
}
}
// If not, remove it from mcands and continue. Refill mcands if
// it becomes empty.
nextChoice = candsAsHeap.getNode(mcands[nextIdx]);
- if (getEarliestForNodeRef(nextChoice) > curTime
+ if (getEarliestReadyTimeForNode(nextChoice) > curTime
|| ! instrIsFeasible(S, nextChoice->getMachineInstr()->getOpCode()))
{
mcands.erase(mcands.begin() + nextIdx);
const SchedGraphNode* graphNode) {
const MachineInstr *MI = graphNode->getMachineInstr();
- std::hash_map<const MachineInstr*, bool>::const_iterator
+ hash_map<const MachineInstr*, bool>::const_iterator
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 BasicBlock* bb = graphNode->getMachineBasicBlock().getBasicBlock();
const ValueSet &LVs = LVI.getLiveVarSetBeforeMInst(MI, bb);
for (MachineInstr::const_val_op_iterator OI = MI->begin(), OE = MI->end();