Commit 7d56d2c6 authored by Misha Brukman's avatar Misha Brukman
Browse files

* Eliminate `using' directive

* Make code layout more consistent

llvm-svn: 9427
parent c7b1bce2
Loading
Loading
Loading
Loading
+88 −106
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h"
using std::cerr;

std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) {
  return os << "Delay for node " << nd->node->getNodeId()
@@ -43,29 +42,24 @@ SchedPriorities::SchedPriorities(const Function *, const SchedGraph *G,


void
SchedPriorities::initialize()
{
SchedPriorities::initialize() {
  initializeReadyHeap(graph);
}


void
SchedPriorities::computeDelays(const SchedGraph* graph)
{
SchedPriorities::computeDelays(const SchedGraph* graph) {
  po_iterator<const SchedGraph*> poIter = po_begin(graph), poEnd =po_end(graph);
  for ( ; poIter != poEnd; ++poIter)
    {
  for ( ; poIter != poEnd; ++poIter) {
    const SchedGraphNode* node = *poIter;
    cycles_t nodeDelay;
    if (node->beginOutEdges() == node->endOutEdges())
      nodeDelay = node->getLatency();
      else
	{
    else {
      // Iterate over the out-edges of the node to compute delay
      nodeDelay = 0;
      for (SchedGraphNode::const_iterator E=node->beginOutEdges();
	       E != node->endOutEdges(); ++E)
	    {
           E != node->endOutEdges(); ++E) {
        cycles_t sinkDelay = getNodeDelay((SchedGraphNode*)(*E)->getSink());
        nodeDelay = std::max(nodeDelay, sinkDelay + (*E)->getMinDelay());
      }
@@ -76,8 +70,7 @@ SchedPriorities::computeDelays(const SchedGraph* graph)


void
SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
{
SchedPriorities::initializeReadyHeap(const SchedGraph* graph) {
  const SchedGraphNode* graphRoot = (const SchedGraphNode*)graph->getRoot();
  assert(graphRoot->getMachineInstr() == NULL && "Expect dummy root");
  
@@ -88,9 +81,9 @@ SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
  
#undef TEST_HEAP_CONVERSION
#ifdef TEST_HEAP_CONVERSION
  cerr << "Before heap conversion:\n";
  std::cerr << "Before heap conversion:\n";
  copy(candsAsHeap.begin(), candsAsHeap.end(),
       ostream_iterator<NodeDelayPair*>(cerr,"\n"));
       ostream_iterator<NodeDelayPair*>(std::cerr,"\n"));
#endif
  
  candsAsHeap.makeHeap();
@@ -98,53 +91,52 @@ SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
  nextToTry = candsAsHeap.begin();
  
#ifdef TEST_HEAP_CONVERSION
  cerr << "After heap conversion:\n";
  std::cerr << "After heap conversion:\n";
  copy(candsAsHeap.begin(), candsAsHeap.end(),
       ostream_iterator<NodeDelayPair*>(cerr,"\n"));
       ostream_iterator<NodeDelayPair*>(std::cerr,"\n"));
#endif
}

void
SchedPriorities::insertReady(const SchedGraphNode* node)
{
SchedPriorities::insertReady(const SchedGraphNode* node) {
  candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]);
  candsAsSet.insert(node);
  mcands.clear(); // ensure reset choices is called before any more choices
  earliestReadyTime = std::min(earliestReadyTime,
                       getEarliestReadyTimeForNode(node));
  
  if (SchedDebugLevel >= Sched_PrintSchedTrace)
    {
      cerr << " Node " << node->getNodeId() << " will be ready in Cycle "
  if (SchedDebugLevel >= Sched_PrintSchedTrace) {
    std::cerr << " Node " << node->getNodeId() << " will be ready in Cycle "
              << getEarliestReadyTimeForNode(node) << "; "
	   << " Delay = " <<(long)getNodeDelay(node) << "; Instruction: \n";
      cerr << "        " << *node->getMachineInstr() << "\n";
              << " Delay = " <<(long)getNodeDelay(node) << "; Instruction: \n"
              << "        " << *node->getMachineInstr() << "\n";
  }
}

void
SchedPriorities::issuedReadyNodeAt(cycles_t curTime,
				   const SchedGraphNode* node)
{
				   const SchedGraphNode* node) {
  candsAsHeap.removeNode(node);
  candsAsSet.erase(node);
  mcands.clear(); // ensure reset choices is called before any more choices
  
  if (earliestReadyTime == getEarliestReadyTimeForNode(node))
    {// earliestReadyTime may have been due to this node, so recompute it
  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, 
      if (candsAsHeap.getNode(I)) {
        earliestReadyTime = 
          std::min(earliestReadyTime, 
                   getEarliestReadyTimeForNode(candsAsHeap.getNode(I)));
      }
  }
  
  // Now update ready times for successors
  for (SchedGraphNode::const_iterator E=node->beginOutEdges();
       E != node->endOutEdges(); ++E)
    {
      cycles_t& etime = getEarliestReadyTimeForNodeRef((SchedGraphNode*)(*E)->getSink());
       E != node->endOutEdges(); ++E) {
    cycles_t& etime =
      getEarliestReadyTimeForNodeRef((SchedGraphNode*)(*E)->getSink());
    etime = std::max(etime, curTime + (*E)->getMinDelay());
  }    
}
@@ -160,15 +152,13 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime,
//----------------------------------------------------------------------

inline int
SchedPriorities::chooseByRule1(std::vector<candIndex>& mcands)
{
SchedPriorities::chooseByRule1(std::vector<candIndex>& mcands) {
  return (mcands.size() == 1)? 0	// only one choice exists so take it
			     : -1;	// -1 indicates multiple choices
}

inline int
SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands)
{
SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands) {
  assert(mcands.size() >= 1 && "Should have at least one candidate here.");
  for (unsigned i=0, N = mcands.size(); i < N; i++)
    if (instructionHasLastUse(methodLiveVarInfo,
@@ -178,16 +168,13 @@ SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands)
}

inline int
SchedPriorities::chooseByRule3(std::vector<candIndex>& mcands)
{
SchedPriorities::chooseByRule3(std::vector<candIndex>& mcands) {
  assert(mcands.size() >= 1 && "Should have at least one candidate here.");
  int maxUses = candsAsHeap.getNode(mcands[0])->getNumOutEdges();	
  int indexWithMaxUses = 0;
  for (unsigned i=1, N = mcands.size(); i < N; i++)
    {
  for (unsigned i=1, N = mcands.size(); i < N; i++) {
    int numUses = candsAsHeap.getNode(mcands[i])->getNumOutEdges();
      if (numUses > maxUses)
	{
    if (numUses > maxUses) {
      maxUses = numUses;
      indexWithMaxUses = i;
    }
@@ -197,16 +184,14 @@ SchedPriorities::chooseByRule3(std::vector<candIndex>& mcands)

const SchedGraphNode*
SchedPriorities::getNextHighest(const SchedulingManager& S,
				cycles_t curTime)
{
				cycles_t curTime) {
  int nextIdx = -1;
  const SchedGraphNode* nextChoice = NULL;
  
  if (mcands.size() == 0)
    findSetWithMaxDelay(mcands, S);
  
  while (nextIdx < 0 && mcands.size() > 0)
    {
  while (nextIdx < 0 && mcands.size() > 0) {
    nextIdx = chooseByRule1(mcands);	 // rule 1
      
    if (nextIdx == -1)
@@ -233,12 +218,10 @@ SchedPriorities::getNextHighest(const SchedulingManager& S,
    }
  }
  
  if (nextIdx >= 0)
    {
  if (nextIdx >= 0) {
    mcands.erase(mcands.begin() + nextIdx);
    return nextChoice;
    }
  else
  } else
    return NULL;
}

@@ -258,14 +241,13 @@ SchedPriorities::findSetWithMaxDelay(std::vector<candIndex>& mcands,
      
      nextToTry = next;
      
      if (SchedDebugLevel >= Sched_PrintSchedTrace)
	{
	  cerr << "    Cycle " << (long)getTime() << ": "
      if (SchedDebugLevel >= Sched_PrintSchedTrace) {
        std::cerr << "    Cycle " << (long)getTime() << ": "
                  << "Next highest delay = " << (long)maxDelay << " : "
                  << mcands.size() << " Nodes with this delay: ";
        for (unsigned i=0; i < mcands.size(); i++)
	    cerr << candsAsHeap.getNode(mcands[i])->getNodeId() << ", ";
	  cerr << "\n";
          std::cerr << candsAsHeap.getNode(mcands[i])->getNodeId() << ", ";
        std::cerr << "\n";
      }
    }
}