OpenASIP 2.2
Loading...
Searching...
No Matches
ProgramDependenceGraph.hh
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 ProgramDependenceGraph.hh
26 *
27 * Declaration of prototype of graph-based program representation:
28 * declaration of the program dependence graph.
29 *
30 * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#ifndef TTA_PROGRAM_DEPENDENCE_GRAPH_HH
35#define TTA_PROGRAM_DEPENDENCE_GRAPH_HH
36
37#include <boost/graph/filtered_graph.hpp>
38
39#include "BoostGraph.hh"
43#include "AssocTools.hh"
44#include "MoveNode.hh"
45
46namespace TTAProgram {
47 class Terminal;
48}
50
52 public BoostGraph<ProgramDependenceNode, ProgramDependenceEdge> {
53
54public:
56 A_BEFORE_B, // Subgraph A must be scheduled before subgraph B
57 B_BEFORE_A, // vice verse
58 ANY_ORDER, // Any order is acceptable
59 UNORDERABLE, // Can not be ordered, needs additional predicate
60 ERROR // Relation can not be determined! This is error
61 };
62
68 bool serializePDG();
69 void disassemble() const;
70
71private:
72 typedef std::map<const ControlDependenceNode*, ProgramDependenceNode*,
75 typedef std::map<const BasicBlockNode*, ControlDependenceNode*,
77 typedef std::map<const MoveNode*, ProgramDependenceNode*,
79 typedef std::map<const ControlDependenceNode*, std::vector<Node*> >
81
82 /// Filter control dependence edges only
83 template <typename GraphType>
84 struct CDGFilter {
86 CDGFilter(GraphType graph) : graph_(graph) { }
87 template <typename Edge>
88 bool operator()(const Edge& e) const {
89 return graph_[e]->isControlDependence()
90 || graph_[e]->isArtificialControlDependence();
91 }
92 GraphType graph_;
93 };
94
95 /// Type of filtered graph with CD edges only
96 typedef boost::filtered_graph<Graph, CDGFilter<Graph> > FilteredCDG;
97 /// Few types to work with filtered graph
98 typedef boost::graph_traits<FilteredCDG>::in_edge_iterator
100 typedef boost::graph_traits<FilteredCDG>::out_edge_iterator
102 typedef boost::graph_traits<FilteredCDG>::vertex_descriptor
104 typedef std::pair<FilteredInEdgeIter, FilteredInEdgeIter>
106 typedef std::pair<FilteredOutEdgeIter, FilteredOutEdgeIter>
108 /// Stores data to compute post order relation on CDG and strong components
109 typedef std::map<NodeDescriptor, int> PDGOrderMap;
110 typedef boost::associative_property_map<PDGOrderMap> PDGOrder;
111 /// Storage for relations between nodes
112 typedef std::map<NodeDescriptor, NodeDescriptor> DescriptorMap;
113 typedef boost::associative_property_map<DescriptorMap> Descriptors;
114 /// Storage for color property used by dfs
115 typedef std::map <NodeDescriptor, boost::default_color_type > ColorMap;
116 typedef boost::associative_property_map<ColorMap> Color;
117
118 /// Filter nodes of subgraph only
119 template <typename NodeSetType, typename GraphType>
122 SubgraphTypeTest(Node* root, NodeSetType nodes, GraphType graph) :
123 root_(root), subgraphNodes_(nodes), graph_(graph){ }
124 template <typename Node>
125 bool operator()(const Node& n) const {
126 return (graph_[n] != root_) &&
128 }
130 NodeSetType subgraphNodes_;
131 GraphType graph_;
132 };
133
134 /// Filter away back edges
135 template <typename GraphType>
136 struct BackFilter {
138 BackFilter(GraphType graph) : graph_(graph) { }
139 template <typename Edge>
140 bool operator()(const Edge& e) const {
141 return !(graph_[e]->isLoopCloseEdge() ||
142 (graph_[e]->isDataDependence() &&
143 graph_[e]->dataDependenceEdge().isBackEdge()));
144 }
145 GraphType graph_;
146 };
147 typedef boost::filtered_graph<
150
151 template <typename GraphType>
154 BackCFGFilter(GraphType graph) : graph_(graph) { }
155 template <typename Edge>
156 bool operator()(const Edge& e) const {
157 return !(graph_[e]->isBackEdge());
158 }
159 GraphType graph_;
160 };
161 typedef boost::filtered_graph<Graph,BackCFGFilter<Graph> >
163
164
169
172 BBToCD&,
174 MovesInCD&);
175
177 PDGOrderMap& components,
178 DescriptorMap& roots,
179 FilteredCDG& filteredCDG);
181 const PDGOrderMap& orderMap,
182 FilteredCDG& filteredCDG);
183 void computeEECInfo(
184 const PDGOrderMap& orderMap,
185 FilteredCDG& filteredCDG);
186
187 void computeRelations(
188 const PDGOrderMap& orderMap,
189 FilteredCDG& filteredCDG);
191
192 void regionHelper(
193 Node* node,
194 FilteredCDG& filteredCDG,
195 Node::NodesInfo& finalNodesInfo);
196 void processRegion(
197 Node* region,
198 FilteredCDG& filteredCDG);
199 void processPredicate(
200 Node* predicate,
201 FilteredCDG& filteredCDG);
202 void processEntry(BasicBlockNode* firstBB);
205
206 void moveDDGedges(
207 Node& root,
208 NodeSet& subgraphNodes,
209 FilteredCDG& filteredCDG);
210
211 void createJump(
212 BasicBlockNode* from,
213 BasicBlockNode* to,
214 TTAProgram::Terminal* guardReg = NULL,
217 void addLeafEdges(std::vector<BasicBlockNode*> leafs, BasicBlockNode* bb);
218
219 /// Stores original control dependence graph
221 /// Stores original data dependence graph
223 /// Stores pointer to entry node of the PDG graph
225 /// Stored reference to PDG equivalent of DDG ENTRYNODE
227 /// stores nodes present in each of the found components
228 std::vector<std::set<Node*> > strongComponents_;
229 /// Newly created control flow graph
231 /// Counts new instructions when creating basic blocks
233 /// Original Program object, to get instruction reference manager
235
236
237 template <class Name>
239 public:
240 label_writer(Name _name) : name(_name) {}
241 template <class VertexOrEdge>
242 void operator()(std::ostream& out, const
243 VertexOrEdge& v) const {
244 out << "[" << name[v]->dotString() << "]";
245 //"[label=\"" << name[v]->toString() << "\"]";
246 }
247 private:
248 Name name;
249 };
251};
252
253#endif
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, Node *, Edge * > Graph
Internal graph type, providing actual graph-like operations. This type definition relies on bundled p...
std::set< ProgramDependenceNode *, typename GraphNode::Comparator > NodeSet
Definition BoostGraph.hh:86
void operator()(std::ostream &out, const VertexOrEdge &v) const
void moveDDGedges(Node &root, NodeSet &subgraphNodes, FilteredCDG &filteredCDG)
boost::graph_traits< FilteredCDG >::in_edge_iterator FilteredInEdgeIter
Few types to work with filtered graph.
Node * ddgEntryNode_
Stored reference to PDG equivalent of DDG ENTRYNODE.
void removeGuardedJump(ControlToProgram &, ProgramDependenceNode &, ControlDependenceNode &)
void computeEECInfo(const PDGOrderMap &orderMap, FilteredCDG &filteredCDG)
Node * entryNode_
Stores pointer to entry node of the PDG graph.
int detectStrongComponents(PDGOrderMap &components, DescriptorMap &roots, FilteredCDG &filteredCDG)
std::vector< std::set< Node * > > strongComponents_
stores nodes present in each of the found components
boost::graph_traits< FilteredCDG >::vertex_descriptor FilteredVertexDescriptor
void computeRegionInfo(const PDGOrderMap &orderMap, FilteredCDG &filteredCDG)
void processEntry(BasicBlockNode *firstBB)
void addLeafEdges(std::vector< BasicBlockNode * > leafs, BasicBlockNode *bb)
int insCount_
Counts new instructions when creating basic blocks.
void copyRegionEECComponent(ControlToProgram &, BBToCD &, MoveNodeToPDGNode &, MovesInCD &)
void processRegion(Node *region, FilteredCDG &filteredCDG)
std::map< const MoveNode *, ProgramDependenceNode *, MoveNode::Comparator > MoveNodeToPDGNode
std::map< const BasicBlockNode *, ControlDependenceNode *, BasicBlockNode::Comparator > BBToCD
std::map< NodeDescriptor, int > PDGOrderMap
Stores data to compute post order relation on CDG and strong components.
std::map< const ControlDependenceNode *, std::vector< Node * > > MovesInCD
void computeRelations(const PDGOrderMap &orderMap, FilteredCDG &filteredCDG)
std::map< NodeDescriptor, NodeDescriptor > DescriptorMap
Storage for relations between nodes.
boost::associative_property_map< ColorMap > Color
ControlFlowGraph * newCFG_
Newly created control flow graph.
std::pair< FilteredInEdgeIter, FilteredInEdgeIter > FilteredInEdgePair
const ControlDependenceGraph * cdg_
Stores original control dependence graph.
boost::filtered_graph< Graph, BackCFGFilter< Graph > > CFGSubgraph
TTAProgram::Program * program_
Original Program object, to get instruction reference manager.
boost::filtered_graph< Graph, CDGFilter< Graph > > FilteredCDG
Type of filtered graph with CD edges only.
boost::graph_traits< FilteredCDG >::out_edge_iterator FilteredOutEdgeIter
std::pair< FilteredOutEdgeIter, FilteredOutEdgeIter > FilteredOutEdgePair
ProgramDependenceNode & entryNode() const
const DataDependenceGraph * ddg_
Stores original data dependence graph.
CompareResult compareSiblings(Node *a, Node *b)
void processLoopEntry(Node *node, BasicBlockNode *bb)
boost::associative_property_map< PDGOrderMap > PDGOrder
void regionHelper(Node *node, FilteredCDG &filteredCDG, Node::NodesInfo &finalNodesInfo)
std::map< const ControlDependenceNode *, ProgramDependenceNode *, ControlDependenceNode::Comparator > ControlToProgram
void processPredicate(Node *predicate, FilteredCDG &filteredCDG)
void createJump(BasicBlockNode *from, BasicBlockNode *to, TTAProgram::Terminal *guardReg=NULL, ControlFlowEdge::CFGEdgePredicate predicate=ControlFlowEdge::CFLOW_EDGE_NORMAL)
boost::filtered_graph< Graph, BackFilter< Graph >, SubgraphTypeTest< NodeSet, Graph > > Subgraph
std::map< NodeDescriptor, boost::default_color_type > ColorMap
Storage for color property used by dfs.
boost::associative_property_map< DescriptorMap > Descriptors
std::set< ProgramDependenceNode * > NodesInfo
Filter control dependence edges only.
SubgraphTypeTest(Node *root, NodeSetType nodes, GraphType graph)