OpenASIP  2.0
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"
49 IGNORE_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"
58 #include "ControlDependenceEdge.hh"
59 #include "ControlDependenceNode.hh"
60 
61 #include "hash_set.hh"
62 /**
63  * Graph-based program representation.
64  */
65 class ControlDependenceGraph : public
66  BoostGraph<ControlDependenceNode, ControlDependenceEdge> {
67 
68 public:
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 
78  virtual ~ControlDependenceGraph();
79 
80  int alignment() const;
83  void analyzeCDG();
84  bool analyzed() const { return analyzed_; }
85  int componentCount() const { return strongComponents_.size(); }
86 private:
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);
124  CompareResult compareSiblings(Node* a, Node* b) const;
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
142  bool analyzed_;
143  /// Stores reference to entryNode of the graph
146 };
147 
148 #endif
ControlDependenceGraph::program
TTAProgram::Program * program() const
Definition: ControlDependenceGraph.cc:683
TTAProgram::Program
Definition: Program.hh:63
POP_CLANG_DIAGS
#define POP_CLANG_DIAGS
Definition: CompilerWarnings.hh:96
ControlDependenceGraph::analyzeCDG
void analyzeCDG()
Definition: ControlDependenceGraph.cc:745
BaseType.hh
ControlDependenceGraph::analyzed_
bool analyzed_
Indicates that CDG already has data required for serialization.
Definition: ControlDependenceGraph.hh:142
ControlDependenceGraph::ANY_ORDER
@ ANY_ORDER
Definition: ControlDependenceGraph.hh:72
TTAProgram::Address
Definition: Address.hh:51
ControlDependenceGraph::BlockVector
std::vector< BasicBlockNode * > BlockVector
Definition: ControlDependenceGraph.hh:102
Exception.hh
ControlDependenceGraph::DependenceMap
std::map< Node *, DependentOn *, Node::Comparator > DependenceMap
Definition: ControlDependenceGraph.hh:104
ControlDependenceGraph::B_BEFORE_A
@ B_BEFORE_A
Definition: ControlDependenceGraph.hh:71
BoostGraph.hh
IGNORE_CLANG_WARNING
#define IGNORE_CLANG_WARNING(X)
Definition: CompilerWarnings.hh:85
ControlDependenceGraph::ERROR
@ ERROR
Definition: ControlDependenceGraph.hh:74
ControlDependenceGraph::regionHelper
void regionHelper(Node *, Node::NodesInfo &)
Definition: ControlDependenceGraph.cc:1330
ControlDependenceGraph::ColorMap
std::map< NodeDescriptor, boost::default_color_type > ColorMap
Storage for color property used by dfs.
Definition: ControlDependenceGraph.hh:97
ControlDependenceGraph::SourceType
std::pair< Node *, Edge::CDGEdgeType > SourceType
Definition: ControlDependenceGraph.hh:100
ControlDependenceGraph::componentCount
int componentCount() const
Definition: ControlDependenceGraph.hh:85
ControlDependenceGraph::CompareResult
CompareResult
Definition: ControlDependenceGraph.hh:69
NullAddress.hh
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
hash_set.hh
ControlDependenceGraph::CDGOrderMap
std::map< NodeDescriptor, int > CDGOrderMap
Stores data to compute post order relation on CDG and strong components.
Definition: ControlDependenceGraph.hh:91
ControlDependenceGraph::Color
boost::associative_property_map< ColorMap > Color
Definition: ControlDependenceGraph.hh:98
ControlDependenceGraph::Descriptors
boost::associative_property_map< DescriptorMap > Descriptors
Definition: ControlDependenceGraph.hh:95
ControlDependenceEdge
Definition: ControlDependenceEdge.hh:44
ControlDependenceGraph::ControlDependenceGraph
ControlDependenceGraph(const ControlFlowGraph &cGraph)
Definition: ControlDependenceGraph.cc:97
ControlDependenceGraph::findSubset
bool findSubset(DependentOn *, DependentOn *, Node *)
Definition: ControlDependenceGraph.cc:253
ControlFlowGraph.hh
ControlDependenceGraph::entryNode
ControlDependenceNode & entryNode()
Definition: ControlDependenceGraph.cc:497
ControlDependenceEdge.hh
ControlDependenceGraph::computeDependence
void computeDependence()
Definition: ControlDependenceGraph.cc:122
ControlDependenceGraph::detectControlDependencies
void detectControlDependencies(BlockVector &nodes, std::vector< Node * > &cdNodes, PostOrder &postOrder, DependenceMap &dependencies)
Definition: ControlDependenceGraph.cc:546
BoostGraph< ControlDependenceNode, ControlDependenceEdge >::Node
ControlDependenceNode Node
The (base) node type managed by this graph.
Definition: BoostGraph.hh:90
ControlDependenceGraph::PostOrder
boost::associative_property_map< PostOrderMap > PostOrder
Definition: ControlDependenceGraph.hh:89
ControlDependenceEdge::CDEP_EDGE_NORMAL
@ CDEP_EDGE_NORMAL
Definition: ControlDependenceEdge.hh:48
ControlDependenceGraph::processRegion
void processRegion(Node *region)
Definition: ControlDependenceGraph.cc:1429
ControlDependenceGraph::startAddress_
TTAProgram::Address startAddress_
Definition: ControlDependenceGraph.hh:135
ControlDependenceGraph::createPostDominanceTree
void createPostDominanceTree(BlockVector &nodes, PostOrder &postOrder)
Definition: ControlDependenceGraph.cc:362
ControlDependenceGraph::entryNode_
Node * entryNode_
Stores reference to entryNode of the graph.
Definition: ControlDependenceGraph.hh:144
ControlDependenceGraph::computeRegionInfo
void computeRegionInfo(const CDGOrderMap &orderMap)
Definition: ControlDependenceGraph.cc:1032
ControlDependenceGraph::CDGOrder
boost::associative_property_map< CDGOrderMap > CDGOrder
Definition: ControlDependenceGraph.hh:92
ControlDependenceGraph::A_BEFORE_B
@ A_BEFORE_B
Definition: ControlDependenceGraph.hh:70
ControlDependenceGraph::compareSiblings
CompareResult compareSiblings(Node *a, Node *b) const
Definition: ControlDependenceGraph.cc:1215
ControlDependenceGraph::strongComponents_
std::vector< std::set< Node * > > strongComponents_
Definition: ControlDependenceGraph.hh:140
ControlDependenceGraph::analyzed
bool analyzed() const
Definition: ControlDependenceGraph.hh:84
ControlDependenceGraph::PostOrderMap
std::map< ControlFlowGraph::NodeDescriptor, int > PostOrderMap
Stores data to compute post order relation on CFG.
Definition: ControlDependenceGraph.hh:88
ControlDependenceNode.hh
ControlDependenceGraph::DependentOn
std::vector< SourceType > DependentOn
Definition: ControlDependenceGraph.hh:101
ControlDependenceGraph::createControlDependenceEdge
ControlDependenceEdge & createControlDependenceEdge(Node &bTail, Node &bHead, Edge::CDGEdgeType edgeValue=Edge::CDEP_EDGE_NORMAL)
Definition: ControlDependenceGraph.cc:332
ControlDependenceEdge::CDGEdgeType
CDGEdgeType
Definition: ControlDependenceEdge.hh:47
ControlDependenceGraph::UNORDERABLE
@ UNORDERABLE
Definition: ControlDependenceGraph.hh:73
ControlDependenceGraph::program_
TTAProgram::Program * program_
Definition: ControlDependenceGraph.hh:134
ControlDependenceGraph::~ControlDependenceGraph
virtual ~ControlDependenceGraph()
Definition: ControlDependenceGraph.cc:80
ControlDependenceGraph::iDomTree_
std::vector< int > iDomTree_
Definition: ControlDependenceGraph.hh:139
ControlDependenceGraph::detectStrongComponents
int detectStrongComponents(CDGOrderMap &components, DescriptorMap &roots)
Definition: ControlDependenceGraph.cc:848
ControlDependenceGraph::alignment_
int alignment_
Definition: ControlDependenceGraph.hh:136
ControlDependenceGraph
Definition: ControlDependenceGraph.hh:65
ControlDependenceGraph::cGraph_
ControlFlowGraph * cGraph_
Definition: ControlDependenceGraph.hh:138
ControlDependenceGraph::alignment
int alignment() const
Definition: ControlDependenceGraph.cc:673
BoostGraph
Definition: BoostGraph.hh:83
ControlDependenceGraph::componentsDetected_
bool componentsDetected_
Definition: ControlDependenceGraph.hh:145
ControlDependenceNode
Definition: ControlDependenceNode.hh:61
ControlDependenceGraph::DescriptorMap
std::map< NodeDescriptor, NodeDescriptor > DescriptorMap
Storage for relations between nodes.
Definition: ControlDependenceGraph.hh:94
ControlDependenceGraph::computeRelations
void computeRelations(const CDGOrderMap &orderMap)
Definition: ControlDependenceGraph.cc:1403
ControlDependenceGraph::computeEECInfo
void computeEECInfo(const CDGOrderMap &orderMap)
Definition: ControlDependenceGraph.cc:1100
CompilerWarnings.hh
ControlFlowGraph
Definition: ControlFlowGraph.hh:100
ControlDependenceGraph::eliminateMultipleOutputs
void eliminateMultipleOutputs()
Definition: ControlDependenceGraph.cc:693
ControlDependenceGraph::nearestCommonDom
int nearestCommonDom(std::vector< int > &iDom, int node1, int node2) const
Definition: ControlDependenceGraph.cc:304