OpenASIP  2.0
MoveNodeGroup.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file MoveNodeGroup.cc
26  *
27  * Implementation of MoveNodeGroup class
28  *
29  * @author Heikki Kultala 2006 (heikki.kultala-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2011
31  * @note rating: red
32  */
33 
34 #include <climits>
35 
36 #include "MoveNodeGroup.hh"
37 #include "Application.hh"
38 #include "DataDependenceGraph.hh"
39 #include "POMDisassembler.hh"
40 #include "ProgramOperation.hh"
41 #include "Move.hh"
42 /**
43  * Constructor.
44  */
46 }
47 
48 /**
49  * Constructor.
50  *
51  * @param ddg The data dependence graph the moves in the group belong to.
52  */
54  ddg_(&ddg) {
55 }
56 
57 
58 /**
59  * Destructor.
60  */
62 }
63 
64 /**
65  * Adds a node to the MoveNodeGroup.
66  *
67  * @param node The MoveNode being added to the group.
68  */
69 void
71  nodes_.push_back(&node);
72 }
73 
74 /**
75  * Calculates the last cycle in which dependences make it possible to
76  * try schedule the leader node.
77  *
78  * @return The earliest possible cycle
79  */
80 int
82  abortWithError("Not yet implemented");
83  return 0;
84 }
85 
86 /**
87  * Calculates the earliest cycle in which dependences make it possible to
88  * try schedule the leader node.
89  *
90  * In case the MoveNodeGroup is not (known) to be part of a DDG, or
91  * at least one of the predecessors of the MoveNodeGroup are unscheduled,
92  * this function returns INT_MAX. If the node is a root node, the function
93  * returns 0.
94  *
95  * @todo What is the "leader node", in general, in an unassigned operation?
96  *
97  * @param assumeBypassing If set to true, assume we can software bypass all
98  * inputs from the original source.
99  * @return The earliest possible cycle all nodes could be scheduled according
100  * to their precedences.
101  */
102 int
103 MoveNodeGroup::earliestCycle(bool assumeBypassing) const {
104 
105  if (ddg_ == NULL)
106  return INT_MAX;
107 
108  int cycle = 0;
109  // check the predecessors of all nodes in the MoveNodeGroup
110  for (std::size_t i = 0; i < nodes_.size(); ++i) {
111  MoveNode& node = *nodes_.at(i);
112  int nodeCycle =
114  node, UINT_MAX, false, false, false, false, false,
115  assumeBypassing);
116 
117  Application::logStream() << "EC " << nodeCycle << " for "
118  << node.toString() << std::endl;
119 
120  // the result read moves have unscheduled predecessors in case
121  // the operand moves are not yet scheduled, ignore that
122  if (nodeCycle == INT_MAX) {
123  if (!node.isSourceOperation()) {
124  return INT_MAX;
125  }
126  } else {
127  cycle = std::max(nodeCycle, cycle);
128  }
129  }
130 
131  return cycle;
132 }
133 
134 /**
135  * Returns the number of movenodes in the group
136  *
137  * @return The number of nodes.
138  */
139 int
141  return nodes_.size();
142 }
143 
144 /**
145  * Returns one MoveNode contained in this group.
146  *
147  * @param index The index of node which to return
148  *
149  * @return The node being returned.
150  */
151 MoveNode&
152 MoveNodeGroup::node(int index) const {
153  return *nodes_.at(index);
154 }
155 
156 /**
157  * Returns true if all moves in the move group have been scheduled.
158  *
159  * An empty MoveNodeGroup is considered always scheduled.
160  *
161  * @return True if scheduled.
162  */
163 bool
165  for (std::size_t i = 0; i < nodes_.size(); ++i) {
166  if (!nodes_.at(i)->isScheduled())
167  return false;
168  }
169  return true;
170 }
171 
172 bool
174  for (std::size_t i = 0; i < nodes_.size(); ++i) {
175  if (!nodes_.at(i)->isPlaced())
176  return false;
177  }
178  return true;
179 }
180 
181 
182 /**
183  * Returns true if all moves in the move group are alive.
184  *
185  * An empty MoveNodeGroup is considered always alive.
186  *
187  * @return True if scheduled.
188  */
189 bool
191  if (ddg_ != NULL) {
192  for (std::size_t i = 0; i < nodes_.size(); ++i) {
193  if (!ddg_->hasNode(*nodes_.at(i))) {
194  return false;
195  }
196  }
197  }
198  return true;
199 }
200 
201 /**
202  * Returns the maximum distance from any movenode in the group to any sink.
203  *
204  * Calling this may cause forever loop if the DDG has loops.
205  *
206  * @return maximum distance from any movenode in the group to any sink.
207  */
208 int
210  if (ddg_ == NULL) {
211  return 0;
212  }
213  int maxSD = 0;
214  for (int i = 0; i < nodeCount(); i++) {
215  int sinkDistance = ddg_->maxSinkDistance(node(i));
216  maxSD = std::max (maxSD, sinkDistance);
217  }
218  return maxSD;
219 }
220 
221 /**
222  * Returns the maximum distance from any source node to any movenode
223  * in the group.
224  *
225  * Calling this may cause forever loop if the DDG has loops.
226  *
227  * @return maximum distance from any source node to any node in the group.
228  */
229 int
231  if (ddg_ == NULL) {
232  return 0;
233  }
234  int maxSD = 0;
235  for (int i = 0; i < nodeCount(); i++) {
236  int sourceDistance = ddg_->maxSourceDistance(node(i));
237  maxSD = std::max (maxSD, sourceDistance);
238  }
239  return maxSD;
240 }
241 
242 /**
243  * Returns the disassembly of moves in NodeGroup as a string.
244  *
245  * @return string with disasembly of NodeGroup moves.
246  */
247 std::string
249  std::string result = "";
250  for (int i = 0; i < nodeCount(); i++) {
251  result += node(i).toString() + " ; ";
252  }
253 
254  if (isOperation()) {
255  result += "[PO: " + programOperationPtr()->toString() + "] ";
256  }
257  return result;
258 }
259 
261  if (ddg_ == nullptr) return false;
262  for (auto n: nodes_) {
263  if (!ddg_->hasNode(*n)) continue;
265  for (auto e: outEdges) {
266  if (e->guardUse() && e->edgeReason() == DataDependenceEdge::EDGE_REGISTER &&
267  !e->isFalseDep() && !e->headPseudo() && !e->tailPseudo()) {
268  MoveNode& head = ddg_->headNode(*e);
269  if (head.isMove() && head.move().isControlFlowMove()) {
270  return true;
271  }
272  }
273  }
274  }
275  return false;
276 }
MoveNodeGroup::isAlive
bool isAlive() const
Definition: MoveNodeGroup.cc:190
MoveNodeGroup::ddg_
const DataDependenceGraph * ddg_
The data dependence graph the moves in this group belong to (optional).
Definition: MoveNodeGroup.hh:82
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
MoveNodeGroup::node
MoveNode & node(int index) const
Definition: MoveNodeGroup.cc:152
BoostGraph::headNode
virtual Node & headNode(const Edge &edge) const
BoostGraph::maxSourceDistance
int maxSourceDistance(const GraphNode &node) const
MoveNodeGroup.hh
MoveNodeGroup::nodes_
std::vector< MoveNode * > nodes_
Definition: MoveNodeGroup.hh:79
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
MoveNodeGroup::maxSinkDistance
int maxSinkDistance() const
Definition: MoveNodeGroup.cc:209
DataDependenceEdge::EDGE_REGISTER
@ EDGE_REGISTER
Definition: DataDependenceEdge.hh:53
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
MoveNodeGroup::nodeCount
int nodeCount() const
Definition: MoveNodeGroup.cc:140
POMDisassembler.hh
MoveNodeGroup::programOperationPtr
ProgramOperationPtr programOperationPtr() const
Definition: MoveNodeGroup.hh:75
MoveNode::isMove
bool isMove() const
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
TTAProgram::Move::isControlFlowMove
bool isControlFlowMove() const
Definition: Move.cc:233
BoostGraph< MoveNode, DataDependenceEdge >::EdgeSet
std::set< DataDependenceEdge *, typename DataDependenceEdge ::Comparator > EdgeSet
Definition: BoostGraph.hh:87
MoveNodeGroup::maxSourceDistance
int maxSourceDistance() const
Definition: MoveNodeGroup.cc:230
MoveNodeGroup::isOperation
bool isOperation() const
Definition: MoveNodeGroup.hh:74
MoveNodeGroup::MoveNodeGroup
MoveNodeGroup()
Definition: MoveNodeGroup.cc:45
Application.hh
BoostGraph::maxSinkDistance
int maxSinkDistance(const GraphNode &node) const
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
MoveNodeGroup::writesJumpGuard
bool writesJumpGuard() const
Definition: MoveNodeGroup.cc:260
BoostGraph::hasNode
bool hasNode(const Node &) const
MoveNodeGroup::toString
std::string toString() const
Definition: MoveNodeGroup.cc:248
DataDependenceGraph::earliestCycle
int earliestCycle(const MoveNode &moveNode, unsigned int ii=UINT_MAX, bool ignoreRegWaRs=false, bool ignoreRegWaWs=false, bool ignoreGuards=false, bool ignoreFUDeps=false, bool ignoreSameOperationEdges=false, bool assumeBypassing=false) const
Definition: DataDependenceGraph.cc:388
ProgramOperation.hh
MoveNodeGroup::addNode
void addNode(MoveNode &node)
Definition: MoveNodeGroup.cc:70
MoveNodeGroup::latestCycle
int latestCycle() const
Definition: MoveNodeGroup.cc:81
BoostGraph::outEdges
virtual EdgeSet outEdges(const Node &node) const
MoveNode::move
TTAProgram::Move & move()
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
MoveNodeGroup::isPlaced
bool isPlaced() const
Definition: MoveNodeGroup.cc:173
MoveNodeGroup::isScheduled
bool isScheduled() const
Definition: MoveNodeGroup.cc:164
Move.hh
MoveNodeGroup::earliestCycle
int earliestCycle(bool assumeBypassing=false) const
Definition: MoveNodeGroup.cc:103
MoveNodeGroup::~MoveNodeGroup
virtual ~MoveNodeGroup()
Definition: MoveNodeGroup.cc:61