OpenASIP 2.2
Loading...
Searching...
No Matches
ControlDependenceNode.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 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 ControlDependenceNode.cc
26 *
27 * Prototype control dependence graph of TTA program representation:
28 * implementation of graph node.
29 *
30 * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include "BasicBlockNode.hh"
35#include "BasicBlock.hh"
37#include "Exception.hh"
38#include "Conversion.hh"
39#include "Application.hh"
40
41/**
42 * Destructor.
43 */
49/**
50 * Returns instruction at given index in basic block.
51 *
52 * @param index Index of instruction in basic block
53 * @return The instruction at given index
54 */
57 if (!isBBNode()) {
58 std::string msg =
59 "Trying to read from non basic block node" + toString() + "!";
60 throw InvalidData(__FILE__, __LINE__, __func__, msg);
61 }
62 return code_->basicBlock().instructionAtIndex(index);
63}
64
65/**
66 * Returns the type of basic block as string.
67 *
68 * @note Used in writting graph to .dot file.
69 * @return The type of basic block
70 */
71std::string
73 TCEString result = "";
74 if (isRegionNode()) {
75 result += "Region " + Conversion::toString(nodeID());
76 if (isLastNode()) {
77 result += "_LAST";
78 }
79 return result;
80 }
81 if (isLoopEntryNode()) {
82 result += "Loop Entry " + Conversion::toString(nodeID());
83 return result;
84 }
85 if (isEntryNode()) {
86 result += "Entry";
87 return result;
88 }
89 if (isLoopCloseNode()) {
90 result += "Close " + Conversion::toString(nodeID());
91 return result;
92 }
93
94 if (isExitNode()) {
95 result += "Exit";
96 return result;
97 }
98 if (isPredicateNode()) {
99 result += "Predicate(" + code_->toString() +")";
100 if (isLastNode()) {
101 result += "_LAST";
102 }
103 return result;
104 }
105 if (isBBNode()) {
106 return code_->toString();
107 }
108 return result;
109}
110
111/**
112 * Returns a basic block refered by the control dependence node
113 * @return the Basic block
114 */
117 if (isBBNode() || isPredicateNode()) {
118 return code_;
119 }
120 std::string msg = "Trying to read from non basic block node!";
121 throw InvalidData(__FILE__, __LINE__, __func__, msg);
122 return NULL;
123}
124
125/**
126 * Returns number of instructions in basic block
127 * @return number of instructions
128 */
129int
131 if (isBBNode()) {
133 }
134 std::string msg = "Trying to read from non basic block node!";
135 throw InvalidData(__FILE__, __LINE__, __func__, msg);
136 return 0;
137}
138
139bool
143
144bool
148
149bool
153
154bool
156 /// Predicate nodes are BB which ends with conditional jump in CFG
157 return (type_ == CDEP_NODE_BB) || isPredicateNode();
158}
159
160bool
164
165bool
169
170bool
174
175bool
179
180bool
184
185void
187 if (!isRegionNode() && !isEntryNode()) {
188 TCEString msg = "Loop entry node \'" + toString();
189 msg += "\' is not a Region node!";
190 throw InvalidData(
191 __FILE__, __LINE__, __func__, msg);
192 } else {
194 }
195 /// In case node was previously in other component as regular
196 /// region, mark it as loop entry of current component
197 if (component_ != component) {
199 }
200}
203 return type_;
204}
205
206/**
207 * Add CDG node to "region" set for computing serialization information
208 *
209 * @param node Control Dependence Node to add to the set
210 */
211void
215
216/**
217 * Returns the "region" set for given node
218 *
219 * @return the "region" set for given node
220 */
225/**
226 * Add CDG node to "eec" set for computing serialization information
227 *
228 * @param node Control Dependence Node to add to the set
229 */
230
231void
235
236/**
237 * Returns the "eec" set for given node
238 *
239 * @return the "eec" set for given node
240 */
241
244 return eec_;
245}
246
247/**
248 * Add CDG node to "pseduo eec" set for computing serialization information
249 * case node is predicate basic block. Only actuall predicate move will have
250 * predicate eec, rest of moves of basic block needs regular 'leaf' eec
251 * computation
252 *
253 * @param node Control Dependence Node to add to the set
254 */
255
256void
260
261/**
262 * Returns the "pseudo eec" set for given node, applicable for predicate nodes
263 *
264 * @return the "eec" set for given node
265 */
266
271
272void
274 Application::logStream() << "Relations: ";
275 for (NodesInfo::const_iterator iter = region_.begin();
276 iter != region_.end();
277 iter ++) {
278 Application::logStream() << (*iter)->toString() << ", ";
279 }
280 Application::logStream() << std::endl;
281 Application::logStream() << "EEC: ";
282 for (NodesInfo::const_iterator iter = eec_.begin();
283 iter != eec_.end();
284 iter ++) {
285 Application::logStream() << (*iter)->toString() << ", ";
286 }
287 Application::logStream() << std::endl;
288
289}
#define __func__
static std::ostream & logStream()
TTAProgram::BasicBlock & basicBlock()
bool isExitBB() const
bool isEntryBB() const
std::string toString() const
void addToRegion(ControlDependenceNode &node)
NodesInfo region_
Stores "region" information for computing serialization information.
std::string toString() const
TTAProgram::Instruction & instruction(int index) const
int component_
Number of strong component the node belongs to, if any.
NodesInfo pseudoPredicateEEC_
Stores "shadow" eec information for predicate basic blocks which can be then copied into PDG for node...
const NodesInfo & pseudoPredicateEEC()
std::set< ControlDependenceNode * > NodesInfo
Storage type for other nodes of same graph needed to define some non graph relations....
NodesInfo eec_
Stores "eec" information for computing serialization information.
void addToEEC(ControlDependenceNode &node)
void setLoopEntryNode(int component)
BasicBlockNode * basicBlockNode() const
void addToPseudoPredicateEEC(ControlDependenceNode &node)
static std::string toString(const T &source)
int nodeID() const
virtual int instructionCount() const
virtual Instruction & instructionAtIndex(int index) const