OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
BUMoveNodeSelector Class Reference

#include <BUMoveNodeSelector.hh>

Inheritance diagram for BUMoveNodeSelector:
Inheritance graph
Collaboration diagram for BUMoveNodeSelector:
Collaboration graph

Public Member Functions

 BUMoveNodeSelector (TTAProgram::BasicBlock &bb, const TTAMachine::Machine &machine)
 
 BUMoveNodeSelector (DataDependenceGraph &bigDDG, TTAProgram::BasicBlock &bb, const TTAMachine::Machine &machine)
 
 BUMoveNodeSelector (DataDependenceGraph &ddg, const TTAMachine::Machine &machine)
 
virtual ~BUMoveNodeSelector ()
 
virtual MoveNodeGroup candidates ()
 
virtual void notifyScheduled (MoveNode &node)
 
virtual void mightBeReady (MoveNode &node)
 
virtual DataDependenceGraphdataDependenceGraph ()
 
virtual void initializeReadylist ()
 Initializes ready list from nodes that are ready.
 
- Public Member Functions inherited from MoveNodeSelector
 MoveNodeSelector ()
 
virtual ~MoveNodeSelector ()
 

Static Public Member Functions

static void queueOperation (ProgramOperation &po, const DataDependenceGraph::NodeSet &nodes, DataDependenceGraph::NodeSet &queue)
 

Private Member Functions

bool isReadyToBeScheduled (DataDependenceGraph::NodeSet &nodes) const
 
bool isReadyToBeScheduled (MoveNode &mn, DataDependenceGraph::NodeSet &nodes) const
 
virtual bool isReadyToBeScheduled (MoveNodeGroup &nodes) const
 

Private Attributes

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

Detailed Description

Selects move nodes from a basic block and prioritizes move nodes on the critical path of the data dependence graph. This version prioritiezed for bottom up scheduling.

Definition at line 70 of file BUMoveNodeSelector.hh.

Constructor & Destructor Documentation

◆ BUMoveNodeSelector() [1/3]

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

Constructor.

Parameters
bbThe basic block from which to select moves.

Definition at line 109 of file BUMoveNodeSelector.cc.

110 :
111 ddgOwned_(true) {
113 ddg_ = ddgBuilder.build(
117#if 0
118 ddg_->setCycleGrouping(true);
119 ddg_->writeToDotFile("ddg.dot");
120#endif
121}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
DataDependenceGraph * ddg_
The data dependence graph built from the basic block.
virtual void initializeReadylist()
Initializes ready list from nodes that are ready.
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)
virtual void setCycleGrouping(bool flag)
void setMachine(const TTAMachine::Machine &machine)
virtual void writeToDotFile(const TCEString &fileName) const

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:

◆ BUMoveNodeSelector() [2/3]

BUMoveNodeSelector::BUMoveNodeSelector ( 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 88 of file BUMoveNodeSelector.cc.

91 : ddgOwned_(true) {
92 try {
93 ddg_ = bigDDG.createSubgraph(bb);
95 } catch (InstanceNotFound& inf) {
97 __FILE__,__LINE__,__func__,"Creation of subgraph failed");
98 e.setCause(inf);
99 throw e;
100 }
102}
#define __func__
DataDependenceGraph * createSubgraph(NodeSet &nodes, bool includeLoops=false)

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

Here is the call graph for this function:

◆ BUMoveNodeSelector() [3/3]

BUMoveNodeSelector::BUMoveNodeSelector ( 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 129 of file BUMoveNodeSelector.cc.

130 :
131 ddg_(&ddg), ddgOwned_(false) {
134}

References ddg_, initializeReadylist(), machine, and DataDependenceGraph::setMachine().

Here is the call graph for this function:

◆ ~BUMoveNodeSelector()

BUMoveNodeSelector::~BUMoveNodeSelector ( )
virtual

Destructor.

Definition at line 138 of file BUMoveNodeSelector.cc.

138 {
139 if (ddgOwned_) {
140 delete ddg_;
141 }
142}

References ddg_, and ddgOwned_.

Member Function Documentation

◆ candidates()

MoveNodeGroup BUMoveNodeSelector::candidates ( )
virtual

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

Returns
Move node group.

Implements MoveNodeSelector.

Definition at line 157 of file BUMoveNodeSelector.cc.

157 {
158
159 // find a MoveNodeGroup with unscheduled MoveNodes
160 while (readyList_.size() > 0) {
161 MoveNodeGroup moves = readyList_.top();
162 if (!moves.isAlive() || moves.isScheduled() ||
163 !isReadyToBeScheduled(moves))
164 readyList_.pop();
165 else
166 return moves;
167 }
168 // nothing in ready list, let's see if there are "orphan" nodes
169 // still to schedule
170 if (ddg_->nodeCount() - ddg_->scheduledNodeCount() > 0) {
172 for (DataDependenceGraph::NodeSet::iterator i = unscheduled.begin();
173 i != unscheduled.end();
174 ++i) {
175 MoveNode& node = **i;
176#ifdef WARN_ORPHAN_NODES
177 std::cerr << "Found orphan node: " << node.toString() << " max src dist: "
178 << ddg_->maxSourceDistance(node) << " sink dist: " <<
179 ddg_->maxSinkDistance(node) << std::endl;
180 ddg_->writeToDotFile("oprhan.dot");
181#ifdef ABORT_ORPHAN_NODES
182 abortWithError("orphan node!");
183#endif
184#endif
185 mightBeReady(node);
186 }
187 }
188
189 // did we find new nodes?
190 while (readyList_.size() > 0) {
191 MoveNodeGroup moves = readyList_.top();
192 if (moves.isScheduled())
193 readyList_.pop();
194 else
195 return moves;
196 }
197
198 // return an empty move node group
199 return MoveNodeGroup();
200}
#define abortWithError(message)
ReadyMoveNodeGroupListBU readyList_
The prioritized ready list.
virtual void mightBeReady(MoveNode &node)
bool isReadyToBeScheduled(DataDependenceGraph::NodeSet &nodes) const
int maxSourceDistance(const GraphNode &node) const
int nodeCount() const
int maxSinkDistance(const GraphNode &node) const
NodeSet unscheduledMoves() const
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
bool isAlive() const
bool isScheduled() const
std::string toString() const
Definition MoveNode.cc:576

References abortWithError, ddg_, MoveNodeGroup::isAlive(), isReadyToBeScheduled(), MoveNodeGroup::isScheduled(), BoostGraph< GraphNode, GraphEdge >::maxSinkDistance(), BoostGraph< GraphNode, GraphEdge >::maxSourceDistance(), mightBeReady(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), readyList_, DataDependenceGraph::scheduledNodeCount(), MoveNode::toString(), DataDependenceGraph::unscheduledMoves(), and GraphBase< GraphNode, GraphEdge >::writeToDotFile().

Referenced by BUBasicBlockScheduler::handleDDG(), BF2Scheduler::handleLoopDDG(), BUBasicBlockScheduler::handleLoopDDG(), and BF2Scheduler::scheduleDDG().

Here is the call graph for this function:

◆ dataDependenceGraph()

DataDependenceGraph & BUMoveNodeSelector::dataDependenceGraph ( )
virtual

Returns DDG used internally.

Definition at line 148 of file BUMoveNodeSelector.cc.

148 {
149 return *ddg_;
150}

References ddg_.

◆ initializeReadylist()

void BUMoveNodeSelector::initializeReadylist ( )
virtual

Initializes ready list from nodes that are ready.

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

Definition at line 57 of file BUMoveNodeSelector.cc.

57 {
58 while (!readyList_.empty()) {
59 readyList_.pop();
60 }
62 for (DataDependenceGraph::NodeSet::iterator i = sinks.begin();
63 i != sinks.end();
64 ++i) {
65 MoveNode& node = **i;
66
67 // a hack to avoid adding the root operations multiple times
68 // (the count of input moves): only "announce" the move to the first
69 // operand (every operation should have one input operand)
70 if (node.isDestinationOperation() && !node.move().destination().isFUPort()) {
71 std::cerr << "termimal not fuport even though dest op!: " << node.toString();
72 ddg_->writeToDotFile("not_dest_port.dot");
73 }
74 if (!node.isDestinationOperation())
75 mightBeReady(**i);
76 else if (node.move().destination().operationIndex() == 1) {
77 mightBeReady(**i);
78 }
79 }
80}
virtual NodeSet sinkNodes() const
bool isDestinationOperation() const
TTAProgram::Move & move()
Terminal & destination() const
Definition Move.cc:323
virtual int operationIndex() const
Definition Terminal.cc:364
virtual bool isFUPort() const
Definition Terminal.cc:118

References ddg_, TTAProgram::Move::destination(), MoveNode::isDestinationOperation(), TTAProgram::Terminal::isFUPort(), mightBeReady(), MoveNode::move(), TTAProgram::Terminal::operationIndex(), readyList_, BoostGraph< GraphNode, GraphEdge >::sinkNodes(), MoveNode::toString(), and GraphBase< GraphNode, GraphEdge >::writeToDotFile().

Referenced by BUMoveNodeSelector(), BUMoveNodeSelector(), BUMoveNodeSelector(), and BF2Scheduler::handleLoopDDG().

Here is the call graph for this function:

◆ isReadyToBeScheduled() [1/3]

bool BUMoveNodeSelector::isReadyToBeScheduled ( DataDependenceGraph::NodeSet nodes) const
private

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

It should be noted that moves within same operation are treated specially. Additionally, as we are considering a basic block at a time, the branch operation is considered always 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 349 of file BUMoveNodeSelector.cc.

350 {
351
352 for (DataDependenceGraph::NodeSet::iterator i = nodes.begin(); i != nodes.end(); i++) {
353 MoveNode& node = **i;
354 if (!isReadyToBeScheduled(node, nodes)) {
355 return false;
356 }
357 }
358 return true;
359}

References isReadyToBeScheduled().

Referenced by candidates(), isReadyToBeScheduled(), isReadyToBeScheduled(), and mightBeReady().

Here is the call graph for this function:

◆ isReadyToBeScheduled() [2/3]

bool BUMoveNodeSelector::isReadyToBeScheduled ( MoveNode mn,
DataDependenceGraph::NodeSet nodes 
) const
private

Definition at line 362 of file BUMoveNodeSelector.cc.

363 {
364 if (!ddg_->hasNode(node)) {
365 return true;
366 }
367
368 return ddg_->otherSuccessorsScheduled(node, nodes);
369}
bool hasNode(const Node &) const
bool otherSuccessorsScheduled(MoveNode &node, const NodeSet &ignoredNodes) const

References ddg_, BoostGraph< GraphNode, GraphEdge >::hasNode(), and DataDependenceGraph::otherSuccessorsScheduled().

Here is the call graph for this function:

◆ isReadyToBeScheduled() [3/3]

bool BUMoveNodeSelector::isReadyToBeScheduled ( MoveNodeGroup nodes) const
privatevirtual

Definition at line 372 of file BUMoveNodeSelector.cc.

372 {
374 for (int i = 0; i < nodes.nodeCount(); i++) {
375 MoveNode& mn = nodes.node(i);
376 ns.insert(&mn);
377 }
378 return isReadyToBeScheduled(ns);
379}
int nodeCount() const
MoveNode & node(int index) const

References isReadyToBeScheduled(), MoveNodeGroup::node(), and MoveNodeGroup::nodeCount().

Here is the call graph for this function:

◆ mightBeReady()

void BUMoveNodeSelector::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 children in the DDG have been scheduled.

In case the node belongs to an operation, also checks that the other result 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 237 of file BUMoveNodeSelector.cc.

237 {
238
239 if (node.isScheduled()) {
240 return;
241 }
242
245 queue.insert(&node);
246
247 while (!queue.empty()) {
248 MoveNode* mn = *queue.begin();
249 nodes.insert(mn);
250 queue.erase(mn);
251 if (mn->isSourceOperation()) {
252 queueOperation(mn->sourceOperation(), nodes, queue);
253 }
254
255 for (unsigned int i = 0; i < mn->destinationOperationCount(); i++) {
256 queueOperation(mn->destinationOperation(i), nodes, queue);
257 }
258
259 if (mn->move().source().isUniversalMachineRegister()) {
260 if (ddg_->hasNode(*mn)) {
261 MoveNode* bypassSrc =
263 if (bypassSrc != NULL) {
264 if (nodes.find(bypassSrc) == nodes.end()) {
265 queue.insert(bypassSrc);
266 }
267 } else {
268 std::cerr << "Warning: Cannot find source for forced bypass. "
269 << " Instruction scheduler may fail/deadlock" << std::endl;
270 }
271 }
272 }
274 if (ddg_->hasNode(*mn)) {
275 DataDependenceGraph::NodeSet rrDestinations =
276 ddg_->onlyRegisterRawDestinations(*mn, false, false);
277 for (DataDependenceGraph::NodeSet::iterator j =
278 rrDestinations.begin(); j != rrDestinations.end(); j++) {
279 MoveNode* n = *j;
280 if (nodes.find(n) == nodes.end()) {
281 queue.insert(n);
282 }
283 }
284 }
285 }
286 }
287
288 if (!isReadyToBeScheduled(nodes)) {
289 return;
290 }
291
292
293 if (!nodes.empty()) {
294 MoveNodeGroup moves(*ddg_);
295 for (DataDependenceGraph::NodeSet::iterator i = nodes.begin(); i != nodes.end(); i++) {
296 if (!((**i).isScheduled())) {
297 moves.addNode(**i);
298 }
299 }
300 if (moves.nodeCount()) {
301 readyList_.push(moves);
302 }
303 }
304
305}
static void queueOperation(ProgramOperation &po, const DataDependenceGraph::NodeSet &nodes, DataDependenceGraph::NodeSet &queue)
NodeSet onlyRegisterRawDestinations(const MoveNode &mn, bool allowGuardEdges=false, bool allowBackEdges=false) const
MoveNode * onlyRegisterRawSource(const MoveNode &mn, int allowGuardEdges=2, int backEdges=0) const
unsigned int destinationOperationCount() const
ProgramOperation & sourceOperation() const
Definition MoveNode.cc:453
bool isSourceOperation() const
Definition MoveNode.cc:168
bool isScheduled() const
Definition MoveNode.cc:409
ProgramOperation & destinationOperation(unsigned int index=0) const
Terminal & source() const
Definition Move.cc:302
virtual bool isUniversalMachineRegister() const
Definition Terminal.cc:166

References MoveNodeGroup::addNode(), ddg_, TTAProgram::Move::destination(), MoveNode::destinationOperation(), MoveNode::destinationOperationCount(), BoostGraph< GraphNode, GraphEdge >::hasNode(), isReadyToBeScheduled(), MoveNode::isScheduled(), MoveNode::isSourceOperation(), TTAProgram::Terminal::isUniversalMachineRegister(), MoveNode::move(), MoveNodeGroup::nodeCount(), DataDependenceGraph::onlyRegisterRawDestinations(), DataDependenceGraph::onlyRegisterRawSource(), queueOperation(), readyList_, TTAProgram::Move::source(), and MoveNode::sourceOperation().

Referenced by candidates(), BUBasicBlockScheduler::finalizeSchedule(), initializeReadylist(), notifyScheduled(), and BF2ScheduleFront::scheduleFrontFromMove().

Here is the call graph for this function:

◆ notifyScheduled()

void BUMoveNodeSelector::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 209 of file BUMoveNodeSelector.cc.

209 {
210
211 assert(node.isScheduled() && "Notifying scheduled even though it isn't.");
213 for (DataDependenceGraph::NodeSet::iterator i = pred.begin();
214 i != pred.end(); ++i) {
215 MoveNode& predecessor = **i;
216
217 // we schedule operations as entities, so if the predecessor is a
218 // (operand) move, it's already in the ready list along with the
219 // move itself
220 if (!predecessor.inSameOperation(node))
221 mightBeReady(**i);
222 }
223}
#define assert(condition)
virtual NodeSet predecessors(const Node &node, bool ignoreBackEdges=false, bool ignoreForwardEdges=false) const
bool inSameOperation(const MoveNode &other) const
Definition MoveNode.cc:306

References assert, ddg_, MoveNode::inSameOperation(), MoveNode::isScheduled(), mightBeReady(), and BoostGraph< GraphNode, GraphEdge >::predecessors().

Referenced by BUBasicBlockScheduler::finalizeSchedule(), and BF2ScheduleFront::scheduleFrontFromMove().

Here is the call graph for this function:

◆ queueOperation()

void BUMoveNodeSelector::queueOperation ( ProgramOperation po,
const DataDependenceGraph::NodeSet nodes,
DataDependenceGraph::NodeSet queue 
)
static

Queues all nodes of PO into queue, if they are not already in another set.

Parameters
poProgramOperation whose nodes to add
nodesnodes where the final result is. if node is here, do not add to queue
queuequque where to add the nodes.

Definition at line 315 of file BUMoveNodeSelector.cc.

318 {
319 for (int j = 0; j < po.inputMoveCount(); j++) {
320 MoveNode& inputMove = po.inputMove(j);
321 // only add if not already added
322 if (nodes.find(&inputMove) == nodes.end()) {
323 queue.insert(&inputMove);
324 }
325 }
326
327 for (int j = 0; j < po.outputMoveCount(); j++) {
328 MoveNode& outputMove = po.outputMove(j);
329 // only add if not already added
330 if (nodes.find(&outputMove) == nodes.end()) {
331 queue.insert(&outputMove);
332 }
333 }
334}
int outputMoveCount() const
int inputMoveCount() const
MoveNode & inputMove(int index) const
MoveNode & outputMove(int index) const

References ProgramOperation::inputMove(), ProgramOperation::inputMoveCount(), ProgramOperation::outputMove(), and ProgramOperation::outputMoveCount().

Referenced by BF2ScheduleFront::allNodesOfSameOperation(), and mightBeReady().

Here is the call graph for this function:

Member Data Documentation

◆ ddg_

DataDependenceGraph* BUMoveNodeSelector::ddg_
private

◆ ddgOwned_

bool BUMoveNodeSelector::ddgOwned_
private

Definition at line 105 of file BUMoveNodeSelector.hh.

Referenced by ~BUMoveNodeSelector().

◆ readyList_

ReadyMoveNodeGroupListBU BUMoveNodeSelector::readyList_
private

The prioritized ready list.

Definition at line 103 of file BUMoveNodeSelector.hh.

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


The documentation for this class was generated from the following files: