OpenASIP  2.0
ProgramDependenceNode.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 ProgramDependenceNode.cc
26  *
27  * Implementation of prototype of graph-based program representation:
28  * declaration of the program dependence node.
29  *
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "ProgramDependenceNode.hh"
35 #include "Move.hh"
36 #include "MoveNode.hh"
37 #include "Conversion.hh"
38 #include "Application.hh"
39 
40 /**
41  * Constructor creating Program Dependence Node which is empty.
42  * Does not have related CDG node. For example Loop Close node.
43  * @param type Type of the node
44  */
46  NodeType type)
47  : GraphNode(), type_(type), component_(-1), newFirstBB_(NULL),
48  lastNode_(false) {
49  mNode_ = NULL;
50  cdgNode_ = NULL;
51 }
52 
53 /**
54  * Constructor creating Program Dependence Node from Control Dependence
55  * region node.
56  * @param cdgNode node of CDG
57  * @param type Type of the node
58  */
60  ControlDependenceNode& cdgNode,
61  NodeType type)
62  : GraphNode(), cdgNode_(&cdgNode), type_(type), component_(-1),
63  newFirstBB_(NULL), lastNode_(false) {
64  mNode_ = NULL;
65 }
66 
67 /**
68  * Constructor creating Program Dependence Node from Data Dependence node.
69  * @param mNode MoveNode of DDG
70  * @param type Type of the node
71  */
73  MoveNode& mNode,
74  NodeType type)
75  : GraphNode(), mNode_(&mNode), type_(type), component_(-1),
76  newFirstBB_(NULL), lastNode_(false) {
77  cdgNode_ = NULL;
78 }
79 
80 /**
81  * Empty destructor.
82  */
84  region_.clear();
85  eec_.clear();
86 }
87 
88 /**
89  * Returns content of a node as a string.
90  * @return string representing content of a node
91  */
92 std::string
94  TCEString result;
95  if (isRegionNode()) {
96  if (cdgNode_ != NULL) {
97  result += cdgNode_->toString() + ": " +
99  } else {
100  /// Node added during strong components detection
101  /// to collect edges pointing to loop entry from outside the loop.
102  /// Do not have cdg equivalent if analysis was done directly on pdg
103  result += "Collect_" + Conversion::toString(nodeID());
104  }
105  }
106  if (isLoopEntryNode()) {
107  /// Loop entry is region node converted during detection of loops
108  /// Exists in CDG even if loop detection was done on PDG
109  result += "LoopEntry_" + Conversion::toString(nodeID()) +
110  ": " + cdgNode_->toString();
111  }
112  if (isLoopCloseNode()) {
113  /// Node added during strong components detection
114  /// to collect edges pointing to loop entry from inside the loop.
115  /// Do not have cdg equivalent if analysis was done directly on pdg
116  if (cdgNode_ != NULL) {
117  result += "LoopClose_" + Conversion::toString(nodeID()) +
118  ": " + cdgNode_->toString();
119  } else {
120  result += "LoopClose_" + Conversion::toString(nodeID());
121  }
122  }
123  if (isPredicateMoveNode()) {
124  result += "Predicate: " + mNode_->toString() + ": " +
126  }
127  if (isLastNode()) {
128  result += "_LAST";
129  }
130  if (mNode_ != NULL && !isPredicateMoveNode()) {
131  result+= mNode_->toString() + ": " + Conversion::toString(nodeID());
132  }
133  return result;
134 }
135 /**
136  * Returns content of a node as a string in .dot format.
137  * @return string representing content of a node in .dot format
138  */
139 std::string
141  if (isPredicateMoveNode()) {
142  return TCEString("label=\"") +
143  toString() + "\",shape=box,color=green";
144  }
145  if (isRegionNode()) {
146  return TCEString("label=\"")
147  + toString() + "\",shape=box,color=blue";
148  }
149  if (isMoveNode() && moveNode().isMove() && moveNode().move().isCall()) {
150  return TCEString("label=\"")
151  + toString() + "\",shape=box,color=red";
152  }
153  if (isLoopEntryNode()) {
154  return TCEString("label=\"")
155  + toString() + "\",shape=box,color=red";
156  }
157  if (isLoopCloseNode()) {
158  return TCEString("label=\"")
159  + toString() + "\",shape=box,color=yellow";
160  }
161 
162  return TCEString("label=\"") + toString() + "\"";
163 }
164 /**
165  * Sets node to be predicate node
166  */
167 void
170  TCEString msg = "Trying to create predicate move from Region in ";
171  msg += toString() + "!";
172  throw InvalidData(__FILE__, __LINE__, __func__, msg);
173  }
175 }
176 
177 /**
178  * Returns MoveNode corresponding to given node in DDG.
179  * @return MoveNode corresponding to given node in DDG
180  */
181 MoveNode&
184  && mNode_ != NULL) {
185  return *mNode_;
186  } else {
187  TCEString msg = "MoveNode type does not contain move in ";
188  msg += toString() + "!";
189  throw InvalidData(__FILE__, __LINE__, __func__, msg);
190  }
191 }
192 
193 /**
194  * Returns MoveNode corresponding to given node in DDG as constant.
195  * @return MoveNode corresponding to given node in DDG as constant
196  */
197 const MoveNode&
200  && mNode_ != NULL) {
201  return *mNode_;
202  } else {
203  TCEString msg = "MoveNode type does not contain move in ";
204  msg += toString() + "!";
205  throw InvalidData(__FILE__, __LINE__, __func__, msg);
206  }
207 }
208 
209 /**
210  * Returns CDGNode corresponding to given node in CDG.
211  * @return CDGNode corresponding to given node in CDG
212  */
215  if ((type_ == PDG_NODE_REGION
218  && cdgNode_ != NULL) {
219  return *cdgNode_;
220  } else {
221  TCEString msg = "ControlNode type does not contain CDGNode in ";
222  msg += toString() + "!";
223  throw InvalidData(__FILE__, __LINE__, __func__, msg);
224  }
225 }
226 /**
227  * Returns CDGNode corresponding to given node in CDG as constant.
228  * @return CDGNode corresponding to given node in CDG as constant
229  */
232  if ((type_ == PDG_NODE_REGION
235  && cdgNode_ != NULL) {
236  return *cdgNode_;
237  } else {
238  TCEString msg = "ControlNode type does not contain CDGNode in ";
239  msg += toString() + "!";
240  throw InvalidData(__FILE__, __LINE__, __func__, msg);
241  }
242 }
243 
244 /**
245  * Add node to "region" set for computing serialization information
246  *
247  * @param node Node to add to the set
248  */
249 void
251  region_.insert(&node);
252 }
253 
254 /**
255  * Returns the "region" set for given node
256  *
257  * @return the "region" set for given node
258  */
261  return region_;
262 }
263 /**
264  * Add node to "eec" set for computing serialization information
265  *
266  * @param node Node to add to the set
267  */
268 
269 void
271  eec_.insert(&node);
272 }
273 
274 /**
275  * Returns the "eec" set for given node
276  *
277  * @return the "eec" set for given node
278  */
279 
282  return eec_;
283 }
284 
285 /**
286  * Sets the node to be loop entry node of a given component (loop)
287  *
288  * @param component Component of which the node is loop entry node
289  *
290  */
291 void
295 }
296 void
298  Application::logStream() << "Relations: ";
299  for (NodesInfo::const_iterator iter = region_.begin();
300  iter != region_.end();
301  iter ++) {
302  Application::logStream() << (*iter)->toString() << ", ";
303  }
304  Application::logStream() << std::endl;
305  Application::logStream() << "EEC: ";
306  for (NodesInfo::const_iterator iter = eec_.begin();
307  iter != eec_.end();
308  iter ++) {
309  Application::logStream() << (*iter)->toString() << ", ";
310  }
311  Application::logStream() << std::endl;
312 
313 }
ProgramDependenceNode::isRegionNode
bool isRegionNode() const
Definition: ProgramDependenceNode.hh:65
ProgramDependenceNode::isPredicateMoveNode
bool isPredicateMoveNode() const
Definition: ProgramDependenceNode.hh:66
ProgramDependenceNode::toString
std::string toString() const
Definition: ProgramDependenceNode.cc:93
ProgramDependenceNode::PDG_NODE_PREDICATE
@ PDG_NODE_PREDICATE
Definition: ProgramDependenceNode.hh:47
ProgramDependenceNode::type_
NodeType type_
Definition: ProgramDependenceNode.hh:104
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
ProgramDependenceNode::isLoopEntryNode
bool isLoopEntryNode() const
Definition: ProgramDependenceNode.hh:68
ProgramDependenceNode::dotString
std::string dotString() const
Definition: ProgramDependenceNode.cc:140
ProgramDependenceNode::~ProgramDependenceNode
virtual ~ProgramDependenceNode()
Definition: ProgramDependenceNode.cc:83
ProgramDependenceNode::PDG_NODE_REGION
@ PDG_NODE_REGION
Definition: ProgramDependenceNode.hh:46
ProgramDependenceNode::setLoopEntryNode
void setLoopEntryNode(int component)
Definition: ProgramDependenceNode.cc:292
ProgramDependenceNode::PDG_NODE_LOOPENTRY
@ PDG_NODE_LOOPENTRY
Definition: ProgramDependenceNode.hh:49
GraphNode::nodeID
int nodeID() const
ControlDependenceNode::toString
std::string toString() const
Definition: ControlDependenceNode.cc:72
MoveNode
Definition: MoveNode.hh:65
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
ProgramDependenceNode::ProgramDependenceNode
ProgramDependenceNode(NodeType type=PDG_NODE_REGION)
Definition: ProgramDependenceNode.cc:45
ProgramDependenceNode::eec
const NodesInfo & eec()
Definition: ProgramDependenceNode.cc:281
ProgramDependenceNode::moveNode
MoveNode & moveNode()
Definition: ProgramDependenceNode.cc:182
Conversion::toString
static std::string toString(const T &source)
ProgramDependenceNode::NodesInfo
std::set< ProgramDependenceNode * > NodesInfo
Definition: ProgramDependenceNode.hh:64
ProgramDependenceNode::region
const NodesInfo & region()
Definition: ProgramDependenceNode.cc:260
ProgramDependenceNode::printRelations
void printRelations() const
Definition: ProgramDependenceNode.cc:297
InvalidData
Definition: Exception.hh:149
ProgramDependenceNode::component
int component() const
Definition: ProgramDependenceNode.hh:76
Conversion.hh
ProgramDependenceNode::component_
int component_
Number of strong component the node belongs to. Node can be part of several strong components so this...
Definition: ProgramDependenceNode.hh:116
Application.hh
ProgramDependenceNode::cdgNode
ControlDependenceNode & cdgNode()
Definition: ProgramDependenceNode.cc:214
ProgramDependenceNode::region_
NodesInfo region_
Stores "region" information for computing serialization information.
Definition: ProgramDependenceNode.hh:106
__func__
#define __func__
Definition: Application.hh:67
ProgramDependenceNode.hh
ProgramDependenceNode::addToEEC
void addToEEC(ProgramDependenceNode &node)
Definition: ProgramDependenceNode.cc:270
ProgramDependenceNode::isMoveNode
bool isMoveNode() const
Definition: ProgramDependenceNode.hh:67
ProgramDependenceNode::cdgNode_
ControlDependenceNode * cdgNode_
Definition: ProgramDependenceNode.hh:103
ProgramDependenceNode::PDG_NODE_LOOPCLOSE
@ PDG_NODE_LOOPCLOSE
Definition: ProgramDependenceNode.hh:50
ProgramDependenceNode::setPredicateMoveNode
void setPredicateMoveNode()
Definition: ProgramDependenceNode.cc:168
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
ProgramDependenceNode::isLastNode
bool isLastNode() const
Definition: ProgramDependenceNode.hh:72
TCEString
Definition: TCEString.hh:53
ProgramDependenceNode::addToRegion
void addToRegion(ProgramDependenceNode &node)
Definition: ProgramDependenceNode.cc:250
ProgramDependenceNode::isLoopCloseNode
bool isLoopCloseNode() const
Definition: ProgramDependenceNode.hh:71
ProgramDependenceNode
Definition: ProgramDependenceNode.hh:43
ProgramDependenceNode::mNode_
MoveNode * mNode_
Definition: ProgramDependenceNode.hh:102
GraphNode
Definition: GraphNode.hh:42
Move.hh
ControlDependenceNode
Definition: ControlDependenceNode.hh:61
MoveNode.hh
ProgramDependenceNode::eec_
NodesInfo eec_
Stores "eec" information for computing serialization information.
Definition: ProgramDependenceNode.hh:108
ProgramDependenceNode::NodeType
NodeType
Definition: ProgramDependenceNode.hh:45
ProgramDependenceNode::PDG_NODE_MOVE
@ PDG_NODE_MOVE
Definition: ProgramDependenceNode.hh:48