OpenASIP 2.2
Loading...
Searching...
No Matches
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"
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 */
63
64/**
65 * Adds a node to the MoveNodeGroup.
66 *
67 * @param node The MoveNode being added to the group.
68 */
69void
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 */
80int
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 */
102int
103MoveNodeGroup::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 */
139int
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 */
152MoveNodeGroup::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 */
163bool
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
172bool
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 */
189bool
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 */
208int
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 */
229int
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 */
247std::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}
#define abortWithError(message)
static std::ostream & logStream()
int maxSourceDistance(const GraphNode &node) const
virtual Node & headNode(const Edge &edge) const
int maxSinkDistance(const GraphNode &node) const
bool hasNode(const Node &) const
virtual EdgeSet outEdges(const Node &node) const
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
std::set< GraphEdge *, typename GraphEdge::Comparator > EdgeSet
Definition Graph.hh:54
int earliestCycle(bool assumeBypassing=false) const
ProgramOperationPtr programOperationPtr() const
int nodeCount() const
virtual ~MoveNodeGroup()
int maxSinkDistance() const
MoveNode & node(int index) const
void addNode(MoveNode &node)
std::string toString() const
int maxSourceDistance() const
bool writesJumpGuard() const
std::vector< MoveNode * > nodes_
int latestCycle() const
const DataDependenceGraph * ddg_
The data dependence graph the moves in this group belong to (optional).
bool isOperation() const
bool isPlaced() const
bool isAlive() const
bool isScheduled() const
bool isMove() const
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
bool isSourceOperation() const
Definition MoveNode.cc:168
bool isControlFlowMove() const
Definition Move.cc:233