OpenASIP  2.0
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"
36 #include "ControlDependenceNode.hh"
37 #include "Exception.hh"
38 #include "Conversion.hh"
39 #include "Application.hh"
40 
41 /**
42  * Destructor.
43  */
45  region_.clear();
46  eec_.clear();
47  pseudoPredicateEEC_.clear();
48 }
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  */
71 std::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  */
129 int
131  if (isBBNode()) {
132  return code_->basicBlock().instructionCount();
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 
139 bool
141  return true;
142 }
143 
144 bool
146  return type_ == CDEP_NODE_REGION;
147 }
148 
149 bool
151  return type_ == CDEP_NODE_PREDICATE;
152 }
153 
154 bool
156  /// Predicate nodes are BB which ends with conditional jump in CFG
157  return (type_ == CDEP_NODE_BB) || isPredicateNode();
158 }
159 
160 bool
162  return type_ == CDEP_NODE_BB && code_->isEntryBB();
163 }
164 
165 bool
167  return type_ == CDEP_NODE_BB && code_->isExitBB();
168 }
169 
170 bool
172  return type_ == CDEP_NODE_LOOPENTRY;
173 }
174 
175 bool
178 }
179 
180 bool
182  return type_ == CDEP_NODE_LOOPCLOSE;
183 }
184 
185 void
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  */
211 void
213  region_.insert(&node);
214 }
215 
216 /**
217  * Returns the "region" set for given node
218  *
219  * @return the "region" set for given node
220  */
223  return region_;
224 }
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 
231 void
233  eec_.insert(&node);
234 }
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 
256 void
258  pseudoPredicateEEC_.insert(&node);
259 }
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 
269  return pseudoPredicateEEC_;
270 }
271 
272 void
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 }
ControlDependenceNode::isRegionNode
bool isRegionNode() const
Definition: ControlDependenceNode.cc:145
BasicBlockNode::isExitBB
bool isExitBB() const
Definition: BasicBlockNode.cc:257
ControlDependenceNode::basicBlockNode
BasicBlockNode * basicBlockNode() const
Definition: ControlDependenceNode.cc:116
Exception.hh
ControlDependenceNode::eec
const NodesInfo & eec()
Definition: ControlDependenceNode.cc:243
ControlDependenceNode::isEntryNode
bool isEntryNode() const
Definition: ControlDependenceNode.cc:161
TTAProgram::Instruction
Definition: Instruction.hh:57
BasicBlockNode.hh
GraphNode::nodeID
int nodeID() const
ControlDependenceNode::toString
std::string toString() const
Definition: ControlDependenceNode.cc:72
ControlDependenceNode::addToPseudoPredicateEEC
void addToPseudoPredicateEEC(ControlDependenceNode &node)
Definition: ControlDependenceNode.cc:257
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
Conversion::toString
static std::string toString(const T &source)
ControlDependenceNode::NodesInfo
std::set< ControlDependenceNode * > NodesInfo
Storage type for other nodes of same graph needed to define some non graph relations....
Definition: ControlDependenceNode.hh:73
ControlDependenceNode::instruction
TTAProgram::Instruction & instruction(int index) const
Definition: ControlDependenceNode.cc:56
ControlDependenceNode::type
NodeType type() const
Definition: ControlDependenceNode.cc:202
BasicBlockNode::basicBlock
TTAProgram::BasicBlock & basicBlock()
Definition: BasicBlockNode.cc:126
ControlDependenceNode::pseudoPredicateEEC_
NodesInfo pseudoPredicateEEC_
Stores "shadow" eec information for predicate basic blocks which can be then copied into PDG for node...
Definition: ControlDependenceNode.hh:124
ControlDependenceNode::printRelations
void printRelations() const
Definition: ControlDependenceNode.cc:273
InvalidData
Definition: Exception.hh:149
ControlDependenceNode::region_
NodesInfo region_
Stores "region" information for computing serialization information.
Definition: ControlDependenceNode.hh:118
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
Conversion.hh
ControlDependenceNode::region
const NodesInfo & region()
Definition: ControlDependenceNode.cc:222
Application.hh
__func__
#define __func__
Definition: Application.hh:67
BasicBlockNode
Definition: BasicBlockNode.hh:64
BasicBlockNode::isEntryBB
bool isEntryBB() const
Definition: BasicBlockNode.cc:248
ControlDependenceNode::CDEP_NODE_LOOPENTRY
@ CDEP_NODE_LOOPENTRY
Definition: ControlDependenceNode.hh:67
ControlDependenceNode::setLoopEntryNode
void setLoopEntryNode(int component)
Definition: ControlDependenceNode.cc:186
ControlDependenceNode::CDEP_NODE_PREDICATE
@ CDEP_NODE_PREDICATE
Definition: ControlDependenceNode.hh:65
ControlDependenceNode::component_
int component_
Number of strong component the node belongs to, if any.
Definition: ControlDependenceNode.hh:126
ControlDependenceNode::CDEP_NODE_REGION
@ CDEP_NODE_REGION
Definition: ControlDependenceNode.hh:64
ControlDependenceNode::isPredicateNode
bool isPredicateNode() const
Definition: ControlDependenceNode.cc:150
ControlDependenceNode::addToRegion
void addToRegion(ControlDependenceNode &node)
Definition: ControlDependenceNode.cc:212
ControlDependenceNode::addToEEC
void addToEEC(ControlDependenceNode &node)
Definition: ControlDependenceNode.cc:232
ControlDependenceNode::isLastNode
bool isLastNode() const
Definition: ControlDependenceNode.hh:95
ControlDependenceNode::component
int component() const
Definition: ControlDependenceNode.hh:91
ControlDependenceNode::type_
NodeType type_
Definition: ControlDependenceNode.hh:115
ControlDependenceNode.hh
ControlDependenceNode::CDEP_NODE_LOOPCLOSE
@ CDEP_NODE_LOOPCLOSE
Definition: ControlDependenceNode.hh:68
ControlDependenceNode::~ControlDependenceNode
virtual ~ControlDependenceNode()
Definition: ControlDependenceNode.cc:44
ControlDependenceNode::instructionCount
int instructionCount() const
Definition: ControlDependenceNode.cc:130
TCEString
Definition: TCEString.hh:53
BasicBlock.hh
ControlDependenceNode::isLoopCloseNode
bool isLoopCloseNode() const
Definition: ControlDependenceNode.cc:181
TTAProgram::CodeSnippet::instructionAtIndex
virtual Instruction & instructionAtIndex(int index) const
Definition: CodeSnippet.cc:285
ControlDependenceNode::pseudoPredicateEEC
const NodesInfo & pseudoPredicateEEC()
Definition: ControlDependenceNode.cc:268
ControlDependenceNode::isExitNode
bool isExitNode() const
Definition: ControlDependenceNode.cc:166
ControlDependenceNode::isControlDependenceNode
bool isControlDependenceNode() const
Definition: ControlDependenceNode.cc:140
ControlDependenceNode::isBBNode
bool isBBNode() const
Definition: ControlDependenceNode.cc:155
ControlDependenceNode
Definition: ControlDependenceNode.hh:61
ControlDependenceNode::eec_
NodesInfo eec_
Stores "eec" information for computing serialization information.
Definition: ControlDependenceNode.hh:120
ControlDependenceNode::NodeType
NodeType
Definition: ControlDependenceNode.hh:63
ControlDependenceNode::isLoopEntryNode
bool isLoopEntryNode() const
Definition: ControlDependenceNode.cc:171
ControlDependenceNode::code_
BasicBlockNode * code_
Definition: ControlDependenceNode.hh:116
BasicBlockNode::toString
std::string toString() const
Definition: BasicBlockNode.cc:185
ControlDependenceNode::CDEP_NODE_BB
@ CDEP_NODE_BB
Definition: ControlDependenceNode.hh:66