OpenASIP  2.0
OperationDAG.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 OperationDAG.cc
26  *
27  * Implementation of operation directed acyclic graph class
28  *
29  * @author Mikael Lepistö 2007 (mikael.lepisto-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <iostream>
34 
35 #include "OperationDAG.hh"
36 #include "OperationDAGEdge.hh"
37 #include "OperationNode.hh"
38 #include "OperationPimpl.hh"
39 #include "Operation.hh"
40 
42 
45 }
46 
47 /**
48  * Constructor.
49  *
50  * @param name The graph can be named for debugging purposes.
51  */
54  op_(&op) {
55 }
56 
57 /**
58  * Copy constructor.
59  *
60  * @param name The graph can be named for debugging purposes.
61  */
64 }
65 
66 /**
67  * Returns true if dag is the simplest possible.
68  *
69  * @return true if dag is the simplest possible.
70  */
71 bool
73  int opNodeCount = 0;
74  for (int i = 0; i < nodeCount(); i++) {
75 
76  if (dynamic_cast<OperationNode*>(&node(i)) != NULL) {
77  opNodeCount++;
78  if (opNodeCount > 1) {
79  return false;
80  }
81  }
82  }
83  return true;
84 }
85 
86 /**
87  * Destructor.
88  *
89  * Deletes all Nodes. Edges are destroyed by destructor of base class.
90  */
92  for (int i = 0; i < nodeCount(); i++) {
93  delete &node(i);
94  }
95 }
96 
97 /**
98  * Finds recursively step count to root for an operation and writes data to
99  * operation step map.
100  *
101  * Once O(n), after O(log(n))
102  *
103  * @param node Node, whose step count is wanted.
104  * @return Number of maximum steps that are needed to reach this
105  * node from root nodes.
106  */
107 int
109 
110  if (stepMap_.find(&node) == stepMap_.end()) {
111  int maxSteps = 0;
112 
113  for (int i = 0; i < inDegree(node); i++) {
114  OperationDAGNode& rootNode = tailNode(inEdge(node, i));
115  int routeSteps = stepsToRoot(rootNode);
116  if (routeSteps > maxSteps) {
117  maxSteps = routeSteps;
118  }
119  }
120 
121  if (inDegree(node) == 0) {
122  stepMap_[&node] = 0;
123  } else {
124  stepMap_[&node] = maxSteps + 1;
125  }
126  }
127 
128  return stepMap_[&node];
129 }
130 
131 /**
132  * Returns set of end nodes of a DAG.
133  *
134  * @return Set of end nodes of a DAG.
135  */
138  if (endNodes_.empty()) {
139  for (int i = 0; i < nodeCount(); i++) {
140  OperationDAGNode& curr = node(i);
141  if (outDegree(curr) == 0) {
142  endNodes_.insert(&curr);
143  }
144  }
145  }
146  return endNodes_;
147 }
BoostGraph< OperationDAGNode, OperationDAGEdge >::tailNode
virtual Node & tailNode(const Edge &edge) const
BoostGraph< OperationDAGNode, OperationDAGEdge >::node
Node & node(const int index) const
OperationPimpl
Definition: OperationPimpl.hh:54
BoostGraph< OperationDAGNode, OperationDAGEdge >::NodeSet
std::set< OperationDAGNode *, typename OperationDAGNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
OperationDAG::null
static OperationDAG null
Definition: OperationDAG.hh:47
OperationNode
Definition: OperationNode.hh:47
OperationDAGEdge
Definition: OperationDAGEdge.hh:38
OperationDAG::endNodes
const OperationDAG::NodeSet & endNodes() const
Definition: OperationDAG.cc:137
BoostGraph< OperationDAGNode, OperationDAGEdge >::outDegree
virtual int outDegree(const Node &node) const
OperationDAG::OperationDAG
OperationDAG()
Definition: OperationDAG.cc:43
OperationDAGEdge.hh
OperationDAGNode
Definition: OperationDAGNode.hh:45
BoostGraph< OperationDAGNode, OperationDAGEdge >::inEdge
virtual Edge & inEdge(const Node &node, const int index) const
OperationDAG.hh
OperationDAG
Definition: OperationDAG.hh:43
Operation.hh
OperationDAG::isTrivial
bool isTrivial() const
Definition: OperationDAG.cc:72
OperationPimpl.hh
BoostGraph< OperationDAGNode, OperationDAGEdge >::inDegree
virtual int inDegree(const Node &node) const
OperationDAG::~OperationDAG
virtual ~OperationDAG()
Definition: OperationDAG.cc:91
OperationDAG::stepMap_
std::map< const OperationDAGNode *, int, OperationDAGNode::Comparator > stepMap_
Map of known step counts, if dag is changed this must be cleared.
Definition: OperationDAG.hh:66
OperationDAG::stepsToRoot
int stepsToRoot(const OperationDAGNode &node) const
Definition: OperationDAG.cc:108
BoostGraph
Definition: BoostGraph.hh:83
OperationNode.hh
BoostGraph< OperationDAGNode, OperationDAGEdge >::nodeCount
int nodeCount() const
OperationDAG::endNodes_
OperationDAG::NodeSet endNodes_
Set of root nodes of DAG, must be cleared if dag is changed.
Definition: OperationDAG.hh:68