OpenASIP 2.2
Loading...
Searching...
No Matches
ControlDependenceGraph.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 ControlDependenceGraph.hh
26 *
27 * Declaration of prototype control dependence graph of TTA program
28 * representation.
29 *
30 * Known limitations are:
31 * - can not create CDG for procedure with indirect jump - multiple out edges
32 * to basic blocks in CFG without edge predicates
33 * - can not create CDG for procedure with unreachable basic block - crt0 with
34 * missing fall through edge after calling __exit
35 *
36 * @author Andrea Cilio 2005 (cilio-no.spam-cs.tut.fi)
37 * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
38 * @note rating: red
39 */
40
41
42#ifndef TTA_CONTROL_DEPENDENCE_GRAPH_HH
43#define TTA_CONTROL_DEPENDENCE_GRAPH_HH
44
45
46#include <map>
47
48#include "CompilerWarnings.hh"
49IGNORE_CLANG_WARNING("-Wunused-local-typedef")
50#include <boost/graph/reverse_graph.hpp>
52
53#include "BaseType.hh"
54#include "Exception.hh"
55#include "NullAddress.hh"
56#include "BoostGraph.hh"
57#include "ControlFlowGraph.hh"
60
61#include "hash_set.hh"
62/**
63 * Graph-based program representation.
64 */
66 BoostGraph<ControlDependenceNode, ControlDependenceEdge> {
67
68public:
70 A_BEFORE_B, // Subgraph A must be scheduled before subgraph B
71 B_BEFORE_A, // vice versa
72 ANY_ORDER, // Any order is acceptable
73 UNORDERABLE, // Can not be ordered, needs additional predicate
74 ERROR // Try again with reordered nodes TODO: remove this!
75 };
76
79
80 int alignment() const;
83 void analyzeCDG();
84 bool analyzed() const { return analyzed_; }
85 int componentCount() const { return strongComponents_.size(); }
86private:
87 /// Stores data to compute post order relation on CFG
88 typedef std::map<ControlFlowGraph::NodeDescriptor, int> PostOrderMap;
89 typedef boost::associative_property_map<PostOrderMap> PostOrder;
90 /// Stores data to compute post order relation on CDG and strong components
91 typedef std::map<NodeDescriptor, int> CDGOrderMap;
92 typedef boost::associative_property_map<CDGOrderMap> CDGOrder;
93 /// Storage for relations between nodes
94 typedef std::map<NodeDescriptor, NodeDescriptor> DescriptorMap;
95 typedef boost::associative_property_map<DescriptorMap> Descriptors;
96 /// Storage for color property used by dfs
97 typedef std::map <NodeDescriptor, boost::default_color_type > ColorMap;
98 typedef boost::associative_property_map<ColorMap> Color;
99
100 typedef std::pair<Node*, Edge::CDGEdgeType> SourceType;
101 typedef std::vector<SourceType> DependentOn;
102 typedef std::vector<BasicBlockNode*> BlockVector;
103
104 typedef std::map<Node*, DependentOn*, Node::Comparator> DependenceMap;
105
106 void computeDependence();
108 BlockVector& nodes,
109 PostOrder& postOrder);
111 BlockVector& nodes,
112 std::vector<Node*>& cdNodes,
113 PostOrder& postOrder,
114 DependenceMap& dependencies);
117 int nearestCommonDom(std::vector<int>& iDom, int node1, int node2) const;
118
120 CDGOrderMap& components,
121 DescriptorMap& roots);
122 void computeRegionInfo(const CDGOrderMap& orderMap);
123 void computeEECInfo(const CDGOrderMap& orderMap);
126 void computeRelations(const CDGOrderMap& orderMap);
127 void processRegion(Node* region);
129 Node& bTail,
130 Node& bHead,
132
133 // Data saved from original procedure object
137
139 std::vector<int> iDomTree_;
140 std::vector<std::set<Node*> > strongComponents_;
141 /// Indicates that CDG already has data required for serialization
143 /// Stores reference to entryNode of the graph
146};
147
148#endif
#define POP_CLANG_DIAGS
#define IGNORE_CLANG_WARNING(X)
std::map< NodeDescriptor, boost::default_color_type > ColorMap
Storage for color property used by dfs.
std::vector< SourceType > DependentOn
ControlDependenceEdge & createControlDependenceEdge(Node &bTail, Node &bHead, Edge::CDGEdgeType edgeValue=Edge::CDEP_EDGE_NORMAL)
int nearestCommonDom(std::vector< int > &iDom, int node1, int node2) const
void computeRegionInfo(const CDGOrderMap &orderMap)
void detectControlDependencies(BlockVector &nodes, std::vector< Node * > &cdNodes, PostOrder &postOrder, DependenceMap &dependencies)
boost::associative_property_map< PostOrderMap > PostOrder
TTAProgram::Program * program_
std::vector< std::set< Node * > > strongComponents_
boost::associative_property_map< DescriptorMap > Descriptors
std::map< NodeDescriptor, int > CDGOrderMap
Stores data to compute post order relation on CDG and strong components.
void computeEECInfo(const CDGOrderMap &orderMap)
std::map< NodeDescriptor, NodeDescriptor > DescriptorMap
Storage for relations between nodes.
void regionHelper(Node *, Node::NodesInfo &)
boost::associative_property_map< CDGOrderMap > CDGOrder
void createPostDominanceTree(BlockVector &nodes, PostOrder &postOrder)
boost::associative_property_map< ColorMap > Color
void computeRelations(const CDGOrderMap &orderMap)
CompareResult compareSiblings(Node *a, Node *b) const
TTAProgram::Program * program() const
std::pair< Node *, Edge::CDGEdgeType > SourceType
std::vector< BasicBlockNode * > BlockVector
TTAProgram::Address startAddress_
Node * entryNode_
Stores reference to entryNode of the graph.
std::map< ControlFlowGraph::NodeDescriptor, int > PostOrderMap
Stores data to compute post order relation on CFG.
int detectStrongComponents(CDGOrderMap &components, DescriptorMap &roots)
bool findSubset(DependentOn *, DependentOn *, Node *)
std::map< Node *, DependentOn *, Node::Comparator > DependenceMap
ControlDependenceNode & entryNode()
bool analyzed_
Indicates that CDG already has data required for serialization.
std::set< ControlDependenceNode * > NodesInfo
Storage type for other nodes of same graph needed to define some non graph relations....