OpenASIP 2.2
Loading...
Searching...
No Matches
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
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 */
65
66/**
67 * Returns true if dag is the simplest possible.
68 *
69 * @return true if dag is the simplest possible.
70 */
71bool
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 */
107int
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}
virtual Edge & inEdge(const Node &node, const int index) const
virtual int inDegree(const Node &node) const
virtual int outDegree(const Node &node) const
virtual Node & tailNode(const Edge &edge) const
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
OperationDAG::NodeSet endNodes_
Set of root nodes of DAG, must be cleared if dag is changed.
std::map< const OperationDAGNode *, int, OperationDAGNode::Comparator > stepMap_
Map of known step counts, if dag is changed this must be cleared.
virtual ~OperationDAG()
static OperationDAG null
const OperationDAG::NodeSet & endNodes() const
bool isTrivial() const
int stepsToRoot(const OperationDAGNode &node) const