OpenASIP  2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CriticalPathBBMoveNodeSelector Class Reference

#include <CriticalPathBBMoveNodeSelector.hh>

Inheritance diagram for CriticalPathBBMoveNodeSelector:
Inheritance graph
Collaboration diagram for CriticalPathBBMoveNodeSelector:
Collaboration graph

Public Member Functions

 CriticalPathBBMoveNodeSelector (TTAProgram::BasicBlock &bb, const TTAMachine::Machine &machine)
 
 CriticalPathBBMoveNodeSelector (DataDependenceGraph &bigDDG, TTAProgram::BasicBlock &bb, const TTAMachine::Machine &machine)
 
 CriticalPathBBMoveNodeSelector (DataDependenceGraph &ddg, const TTAMachine::Machine &machine)
 
virtual ~CriticalPathBBMoveNodeSelector ()
 
virtual MoveNodeGroup candidates ()
 
virtual void notifyScheduled (MoveNode &node)
 
virtual DataDependenceGraphdataDependenceGraph ()
 
void mightBeReady (MoveNode &node)
 
- Public Member Functions inherited from MoveNodeSelector
 MoveNodeSelector ()
 
virtual ~MoveNodeSelector ()
 

Private Member Functions

bool isReadyToBeScheduled (MoveNode &node) const
 
void initializeReadylist ()
 Initializes ready list from nodes that are ready. More...
 

Private Attributes

DataDependenceGraphddg_
 The data dependence graph built from the basic block. More...
 
ReadyMoveNodeGroupList readyList_
 The prioritized ready list. More...
 
bool ddgOwned_
 

Detailed Description

Selects move nodes from a basic block and prioritizes move nodes on the critical path of the data dependence graph.

Definition at line 70 of file CriticalPathBBMoveNodeSelector.hh.

Constructor & Destructor Documentation

◆ CriticalPathBBMoveNodeSelector() [1/3]

CriticalPathBBMoveNodeSelector::CriticalPathBBMoveNodeSelector ( TTAProgram::BasicBlock bb,
const TTAMachine::Machine machine 
)

Constructor.

Parameters
bbThe basic block from which to select moves.

Definition at line 96 of file CriticalPathBBMoveNodeSelector.cc.

97  :
98  ddgOwned_(true) {
99 
100  DataDependenceGraphBuilder ddgBuilder;
101  ddg_ = ddgBuilder.build(
104 
105 #ifdef WRITE_DOT_SNAPSHOTS
106  ddg_->setCycleGrouping(true);
107  ddg_->writeToDotFile("ddg.dot");
108 #endif
109 
111 }

References DataDependenceGraphBuilder::build(), ddg_, initializeReadylist(), DataDependenceGraph::INTRA_BB_ANTIDEPS, machine, DataDependenceGraph::setCycleGrouping(), DataDependenceGraph::setMachine(), and GraphBase< GraphNode, GraphEdge >::writeToDotFile().

Here is the call graph for this function:

◆ CriticalPathBBMoveNodeSelector() [2/3]

CriticalPathBBMoveNodeSelector::CriticalPathBBMoveNodeSelector ( DataDependenceGraph bigDDG,
TTAProgram::BasicBlock bb,
const TTAMachine::Machine machine 
)

Constructor. Creates subgraph of the given big graph

Parameters
bigDDGbig ddg containing more than just the basic block
bbbasic block for this selector.

Definition at line 75 of file CriticalPathBBMoveNodeSelector.cc.

78  : ddgOwned_(true) {
79  try {
80  ddg_ = bigDDG.createSubgraph(bb);
82  } catch (InstanceNotFound& inf) {
84  __FILE__,__LINE__,__func__,"Creation of subgraph failed");
85  e.setCause(inf);
86  throw e;
87  }
89 }

References __func__, DataDependenceGraph::createSubgraph(), ddg_, initializeReadylist(), machine, Exception::setCause(), and DataDependenceGraph::setMachine().

Here is the call graph for this function:

◆ CriticalPathBBMoveNodeSelector() [3/3]

CriticalPathBBMoveNodeSelector::CriticalPathBBMoveNodeSelector ( DataDependenceGraph ddg,
const TTAMachine::Machine machine 
)

Constructor.

Parameters
ddgThe data dependence graph from which to select moves. Selector does not take the ownership of the ddg.

Definition at line 119 of file CriticalPathBBMoveNodeSelector.cc.

120  :
121  ddg_(&ddg), ddgOwned_(false) {
122 
124 
125 #ifdef WRITE_DOT_SNAPSHOTS
126  ddg_->setCycleGrouping(true);
127  ddg_->writeToDotFile("ddg.dot");
128 #endif
129 
131 }

References ddg_, initializeReadylist(), machine, DataDependenceGraph::setCycleGrouping(), DataDependenceGraph::setMachine(), and GraphBase< GraphNode, GraphEdge >::writeToDotFile().

Here is the call graph for this function:

◆ ~CriticalPathBBMoveNodeSelector()

CriticalPathBBMoveNodeSelector::~CriticalPathBBMoveNodeSelector ( )
virtual

Destructor.

Definition at line 136 of file CriticalPathBBMoveNodeSelector.cc.

136  {
137  if (ddgOwned_) {
138  delete ddg_;
139  }
140 }

References ddg_, and ddgOwned_.

Member Function Documentation

◆ candidates()

MoveNodeGroup CriticalPathBBMoveNodeSelector::candidates ( )
virtual

Returns a group of move nodes which should be scheduled next.

Returns
Move node group.

Implements MoveNodeSelector.

Definition at line 148 of file CriticalPathBBMoveNodeSelector.cc.

148  {
149 
150  // find a MoveNodeGroup with unscheduled MoveNodes
151  while (readyList_.size() > 0) {
152  MoveNodeGroup moves = readyList_.top();
153  if (!moves.isAlive() || moves.isScheduled())
154  readyList_.pop();
155  else
156  return moves;
157  }
158  // nothing in ready list, let's see if there are "orphan" nodes
159  // still to schedule
160  if (ddg_->nodeCount() - ddg_->scheduledNodeCount() > 0) {
162  for (DataDependenceGraph::NodeSet::iterator i = unscheduled.begin();
163  i != unscheduled.end();
164  ++i) {
165  MoveNode& node = **i;
166  mightBeReady(node);
167  }
168  }
169 
170  // did we find new nodes?
171  while (readyList_.size() > 0) {
172  MoveNodeGroup moves = readyList_.top();
173  if (moves.isScheduled())
174  readyList_.pop();
175  else
176  return moves;
177  }
178 
179  // return an empty move node group
180  return MoveNodeGroup();
181 }

References ddg_, MoveNodeGroup::isAlive(), MoveNodeGroup::isScheduled(), mightBeReady(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), readyList_, DataDependenceGraph::scheduledNodeCount(), and DataDependenceGraph::unscheduledMoves().

Referenced by BasicBlockScheduler::handleDDG(), BasicBlockScheduler::handleLoopDDG(), and ResourceConstraintAnalyzer::memoryBoundScheduleResourceUsage().

Here is the call graph for this function:

◆ dataDependenceGraph()

DataDependenceGraph & CriticalPathBBMoveNodeSelector::dataDependenceGraph ( )
virtual

Returns the DDG used internally.

This is needed temporarily only until the MoveNodeManager is done.

Returns
The DDG.

Definition at line 191 of file CriticalPathBBMoveNodeSelector.cc.

191  {
192  return *ddg_;
193 }

References ddg_.

◆ initializeReadylist()

void CriticalPathBBMoveNodeSelector::initializeReadylist ( )
private

Initializes ready list from nodes that are ready.

Add the unscheduled root nodes of the DDG to the ready list

Definition at line 50 of file CriticalPathBBMoveNodeSelector.cc.

50  {
52  for (DataDependenceGraph::NodeSet::iterator i = roots.begin();
53  i != roots.end();
54  ++i) {
55  MoveNode& node = **i;
56 
57  // a hack to avoid adding the root operations multiple times
58  // (the count of input moves): only "announce" the move to the first
59  // operand (every operation should have one input operand)
60  if (!node.isDestinationOperation())
61  mightBeReady(**i);
62  else if (node.move().destination().operationIndex() == 1) {
63  mightBeReady(**i);
64  }
65  }
66 
67 }

References ddg_, TTAProgram::Move::destination(), MoveNode::isDestinationOperation(), mightBeReady(), MoveNode::move(), TTAProgram::Terminal::operationIndex(), and BoostGraph< GraphNode, GraphEdge >::rootNodes().

Referenced by CriticalPathBBMoveNodeSelector().

Here is the call graph for this function:

◆ isReadyToBeScheduled()

bool CriticalPathBBMoveNodeSelector::isReadyToBeScheduled ( MoveNode node) const
private

Returns true in case the move is "data ready", that is, all its predecessors have been scheduled.

It should be noted that moves within same operation are treated specially. Result move is considered ready even if the operands moves are not to allow scheduling all moves in the same operation as a single entity. Additionally, as we are considering a basic block at a time, the branch operation is considered never ready before all the other moves in the basic block have been scheduled.

Parameters
nodeMove to check.
Returns
True if the move is ready to be scheduled.

Definition at line 324 of file CriticalPathBBMoveNodeSelector.cc.

325  {
326 
327  // the control flow move(s) are ready only if all other moves have been
328  // scheduled. In rare case of conditional branching with SPU operation set
329  // branch operation can have 2 moves, condition register and destination.
330  if (node.move().isControlFlowMove() &&
331  ddg_->nodeCount() - ddg_->scheduledNodeCount() > 1) {
332  DataDependenceGraph::NodeSet unscheduledMoves = ddg_->unscheduledMoves();
333  for (DataDependenceGraph::NodeSet::iterator i = unscheduledMoves.begin();
334  i != unscheduledMoves.end(); ++i) {
335  if ((*i)->move().isControlFlowMove() == false) {
336  return false;
337  }
338  }
339  }
340  return ddg_->predecessorsReady(node);
341 }

References ddg_, TTAProgram::Move::isControlFlowMove(), MoveNode::move(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), DataDependenceGraph::predecessorsReady(), DataDependenceGraph::scheduledNodeCount(), and DataDependenceGraph::unscheduledMoves().

Referenced by mightBeReady().

Here is the call graph for this function:

◆ mightBeReady()

void CriticalPathBBMoveNodeSelector::mightBeReady ( MoveNode node)
virtual

Adds the given move node (along with the other possible move nodes in the same operation) to the ready list in case all its parents in the DDG have been scheduled.

In case the node belongs to an operation, also checks that the other operand moves are also ready. In that case adds all the nodes in the said MoveOperation to the ready list in a single MoveNodeGroup.

Parameters
nodeMove node that might be ready.

Implements MoveNodeSelector.

Definition at line 235 of file CriticalPathBBMoveNodeSelector.cc.

235  {
236 
237  if (node.isScheduled()) {
238  return;
239  }
240 
241  if (!isReadyToBeScheduled(node))
242  return;
243 
244  if (node.isDestinationOperation() || node.isSourceOperation()) {
245  // it's a trigger, result, or operand move, let's see if all the
246  // moves of the operation are ready to be scheduled
247  ProgramOperation& operation =
248  (node.isDestinationOperation()?
249  (node.destinationOperation()) : node.sourceOperation());
250  bool allReady = true;
251  MoveNodeGroup moves(*ddg_);
252  for (int inputIndex = 0; inputIndex < operation.inputMoveCount();
253  ++inputIndex) {
254  MoveNode& m = operation.inputMove(inputIndex);
255  if (&m != &node) {
256  if (!isReadyToBeScheduled(m)) {
257  allReady = false;
258  break;
259  }
260  }
261  if (!m.isScheduled())
262  moves.addNode(m);
263  }
264  if (allReady) {
265  // let's add also the output move(s) to the MoveNodeGroup
266  for (int outputIndex = 0;
267  outputIndex < operation.outputMoveCount();
268  ++outputIndex) {
269  MoveNode& m = operation.outputMove(outputIndex);
270  if (&m != &node) {
271  if (!isReadyToBeScheduled(m)) {
272  allReady = false;
273  break;
274  }
275  }
276  if (!m.isScheduled())
277  moves.addNode(m);
278  }
279  if (allReady) {
280  readyList_.push(moves);
281  }
282  }
283  } else if ((node.isSourceVariable() || node.move().source().isRA()) &&
284  (node.isDestinationVariable() ||
285  node.move().destination().isRA())) {
286  // it's a register to register move, we can always schedule these
287  // as soon as all the dependencies are satisfied
288  // handle RA -> ireg also as a register to register move
289  if (isReadyToBeScheduled(node)) {
290  MoveNodeGroup move(*ddg_);
291  move.addNode(node);
292  readyList_.push(move);
293  }
294  } else if (node.isSourceConstant() && node.isDestinationVariable()) {
295  if (isReadyToBeScheduled(node)) {
296  MoveNodeGroup move(*ddg_);
297  move.addNode(node);
298  readyList_.push(move);
299  }
300 
301  } else {
302  throw IllegalProgram(
303  __FILE__, __LINE__, __func__,
304  (boost::format("Illegal move '%s'.") %
305  POMDisassembler::disassemble(node.move())).str());
306  }
307 }

References __func__, MoveNodeGroup::addNode(), ddg_, TTAProgram::Move::destination(), MoveNode::destinationOperation(), POMDisassembler::disassemble(), ProgramOperation::inputMove(), ProgramOperation::inputMoveCount(), MoveNode::isDestinationOperation(), MoveNode::isDestinationVariable(), TTAProgram::Terminal::isRA(), isReadyToBeScheduled(), MoveNode::isScheduled(), MoveNode::isSourceConstant(), MoveNode::isSourceOperation(), MoveNode::isSourceVariable(), MoveNode::move(), ProgramOperation::outputMove(), ProgramOperation::outputMoveCount(), readyList_, TTAProgram::Move::source(), and MoveNode::sourceOperation().

Referenced by candidates(), initializeReadylist(), and notifyScheduled().

Here is the call graph for this function:

◆ notifyScheduled()

void CriticalPathBBMoveNodeSelector::notifyScheduled ( MoveNode node)
virtual

This should be called by the client as soon as a MoveNode is scheduled in order to update the internal state of the selector.

Parameters
nodeThe scheduled MoveNode.

Implements MoveNodeSelector.

Definition at line 202 of file CriticalPathBBMoveNodeSelector.cc.

202  {
203 
204  assert(node.isScheduled() && "Notifying scheduled even though it isn't.");
206  for (DataDependenceGraph::NodeSet::iterator i = succ.begin();
207  i != succ.end(); ++i) {
208  MoveNode& successor = **i;
209 
210  // we schedule operations as entities, so if the successor is a
211  // (result) move, it's already in the ready list along with the
212  // move itself
213  if (!successor.inSameOperation(node))
214  mightBeReady(**i);
215  }
216 
217 #ifdef WRITE_DOT_SNAPSHOTS
218  ddg_->setCycleGrouping(true);
219  ddg_->writeToDotFile("ddg.dot");
220 #endif
221 }

References assert, ddg_, MoveNode::inSameOperation(), MoveNode::isScheduled(), mightBeReady(), DataDependenceGraph::setCycleGrouping(), BoostGraph< GraphNode, GraphEdge >::successors(), and GraphBase< GraphNode, GraphEdge >::writeToDotFile().

Referenced by ResourceConstraintAnalyzer::memoryBoundScheduleResourceUsage().

Here is the call graph for this function:

Member Data Documentation

◆ ddg_

DataDependenceGraph* CriticalPathBBMoveNodeSelector::ddg_
private

◆ ddgOwned_

bool CriticalPathBBMoveNodeSelector::ddgOwned_
private

Definition at line 100 of file CriticalPathBBMoveNodeSelector.hh.

Referenced by ~CriticalPathBBMoveNodeSelector().

◆ readyList_

ReadyMoveNodeGroupList CriticalPathBBMoveNodeSelector::readyList_
private

The prioritized ready list.

Definition at line 98 of file CriticalPathBBMoveNodeSelector.hh.

Referenced by candidates(), and mightBeReady().


The documentation for this class was generated from the following files:
DataDependenceGraph::predecessorsReady
bool predecessorsReady(MoveNode &node) const
Definition: DataDependenceGraph.cc:3176
CriticalPathBBMoveNodeSelector::ddg_
DataDependenceGraph * ddg_
The data dependence graph built from the basic block.
Definition: CriticalPathBBMoveNodeSelector.hh:96
MoveNodeGroup::isAlive
bool isAlive() const
Definition: MoveNodeGroup.cc:190
MoveNode::isDestinationVariable
bool isDestinationVariable() const
Definition: MoveNode.cc:264
DataDependenceGraph::scheduledNodeCount
int scheduledNodeCount() const
Definition: DataDependenceGraph.cc:1859
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
MoveNode::isDestinationOperation
bool isDestinationOperation() const
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
ProgramOperation
Definition: ProgramOperation.hh:70
DataDependenceGraph::setMachine
void setMachine(const TTAMachine::Machine &machine)
Definition: DataDependenceGraph.cc:3116
MoveNode
Definition: MoveNode.hh:65
MoveNode::isSourceConstant
bool isSourceConstant() const
Definition: MoveNode.cc:238
CriticalPathBBMoveNodeSelector::mightBeReady
void mightBeReady(MoveNode &node)
Definition: CriticalPathBBMoveNodeSelector.cc:235
DataDependenceGraph::setCycleGrouping
virtual void setCycleGrouping(bool flag)
Definition: DataDependenceGraph.cc:1738
MoveNode::sourceOperation
ProgramOperation & sourceOperation() const
Definition: MoveNode.cc:453
assert
#define assert(condition)
Definition: Application.hh:86
DataDependenceGraph::createSubgraph
DataDependenceGraph * createSubgraph(NodeSet &nodes, bool includeLoops=false)
Definition: DataDependenceGraph.cc:3377
TTAProgram::Terminal::operationIndex
virtual int operationIndex() const
Definition: Terminal.cc:364
TTAProgram::Move::isControlFlowMove
bool isControlFlowMove() const
Definition: Move.cc:233
CriticalPathBBMoveNodeSelector::readyList_
ReadyMoveNodeGroupList readyList_
The prioritized ready list.
Definition: CriticalPathBBMoveNodeSelector.hh:98
DataDependenceGraph::INTRA_BB_ANTIDEPS
@ INTRA_BB_ANTIDEPS
Definition: DataDependenceGraph.hh:80
IllegalProgram
Definition: Exception.hh:895
__func__
#define __func__
Definition: Application.hh:67
CriticalPathBBMoveNodeSelector::initializeReadylist
void initializeReadylist()
Initializes ready list from nodes that are ready.
Definition: CriticalPathBBMoveNodeSelector.cc:50
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
ModuleRunTimeError
Definition: Exception.hh:1043
ProgramOperation::inputMoveCount
int inputMoveCount() const
Definition: ProgramOperation.cc:600
GraphBase::writeToDotFile
virtual void writeToDotFile(const TCEString &fileName) const
ProgramOperation::outputMoveCount
int outputMoveCount() const
Definition: ProgramOperation.cc:610
MoveNode::isSourceVariable
bool isSourceVariable() const
Definition: MoveNode.cc:196
MoveNode::destinationOperation
ProgramOperation & destinationOperation(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
POMDisassembler::disassemble
static std::string disassemble(const TTAProgram::Move &move)
Definition: POMDisassembler.cc:629
DataDependenceGraphBuilder
Definition: DataDependenceGraphBuilder.hh:70
CriticalPathBBMoveNodeSelector::isReadyToBeScheduled
bool isReadyToBeScheduled(MoveNode &node) const
Definition: CriticalPathBBMoveNodeSelector.cc:324
MoveNode::inSameOperation
bool inSameOperation(const MoveNode &other) const
Definition: MoveNode.cc:306
CriticalPathBBMoveNodeSelector::ddgOwned_
bool ddgOwned_
Definition: CriticalPathBBMoveNodeSelector.hh:100
DataDependenceGraphBuilder::build
virtual DataDependenceGraph * build(ControlFlowGraph &cGraph, DataDependenceGraph::AntidependenceLevel antidependenceLevel, const TTAMachine::Machine &mach, const UniversalMachine *um=NULL, bool createMemAndFUDeps=true, bool createDeathInformation=true, llvm::AliasAnalysis *AA=NULL)
Definition: DataDependenceGraphBuilder.cc:2120
MoveNodeGroup::isScheduled
bool isScheduled() const
Definition: MoveNodeGroup.cc:164
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
MoveNodeGroup
Definition: MoveNodeGroup.hh:48
BoostGraph::rootNodes
virtual NodeSet rootNodes() const
useful utility functions
TTAProgram::Terminal::isRA
virtual bool isRA() const
Definition: Terminal.cc:129
BoostGraph::nodeCount
int nodeCount() const
ProgramOperation::outputMove
MoveNode & outputMove(int index) const
Definition: ProgramOperation.cc:632
DataDependenceGraph::unscheduledMoves
NodeSet unscheduledMoves() const
Definition: DataDependenceGraph.cc:1355
BoostGraph::successors
virtual NodeSet successors(const Node &node, bool ignoreBackEdges=false, bool ignoreForwardEdges=false) const
InstanceNotFound
Definition: Exception.hh:304
ProgramOperation::inputMove
MoveNode & inputMove(int index) const
Definition: ProgramOperation.cc:621