OpenASIP
2.0
|
#include <ControlDependenceGraph.hh>
Public Types | |
enum | CompareResult { A_BEFORE_B, B_BEFORE_A, ANY_ORDER, UNORDERABLE, ERROR } |
Public Types inherited from BoostGraph< ControlDependenceNode, ControlDependenceEdge > | |
typedef std::set< ControlDependenceNode *, typename ControlDependenceNode ::Comparator > | NodeSet |
typedef std::set< ControlDependenceEdge *, typename ControlDependenceEdge ::Comparator > | EdgeSet |
typedef ControlDependenceNode | Node |
The (base) node type managed by this graph. More... | |
typedef ControlDependenceEdge | Edge |
The (base) edge type managed by this graph. More... | |
Public Types inherited from GraphBase< ControlDependenceNode, ControlDependenceEdge > | |
typedef std::set< ControlDependenceNode *, typename ControlDependenceNode ::Comparator > | NodeSet |
typedef std::set< ControlDependenceEdge *, typename ControlDependenceEdge ::Comparator > | EdgeSet |
typedef ControlDependenceNode | Node |
Node type of this graph (possibly, a base class). More... | |
typedef ControlDependenceEdge | Edge |
Edge type of this graph (possibly, a base class). More... | |
Public Member Functions | |
ControlDependenceGraph (const ControlFlowGraph &cGraph) | |
virtual | ~ControlDependenceGraph () |
int | alignment () const |
TTAProgram::Program * | program () const |
ControlDependenceNode & | entryNode () |
void | analyzeCDG () |
bool | analyzed () const |
int | componentCount () const |
Public Member Functions inherited from BoostGraph< ControlDependenceNode, ControlDependenceEdge > | |
BoostGraph (bool allowLoopEdges=true) | |
BoostGraph (const TCEString &name, bool allowLoopEdges=true) | |
BoostGraph (const BoostGraph &other, bool allowLoopEdges=true) | |
~BoostGraph () | |
int | nodeCount () const |
int | edgeCount () const |
Node & | node (const int index) const |
Node & | node (const int index, bool cacheResult) const |
virtual Edge & | edge (const int index) const |
virtual void | addNode (Node &node) |
virtual Edge & | outEdge (const Node &node, const int index) const |
virtual Edge & | inEdge (const Node &node, const int index) const |
virtual EdgeSet | outEdges (const Node &node) const |
virtual EdgeSet | inEdges (const Node &node) const |
virtual EdgeSet | rootGraphOutEdges (const Node &node) const |
virtual EdgeSet | rootGraphInEdges (const Node &node) const |
virtual Edge & | rootGraphInEdge (const Node &node, const int index) const |
virtual Edge & | rootGraphOutEdge (const Node &node, const int index) const |
virtual int | rootGraphInDegree (const Node &node) const |
virtual int | rootGraphOutDegree (const Node &node) const |
virtual int | outDegree (const Node &node) const |
virtual int | inDegree (const Node &node) const |
virtual Node & | tailNode (const Edge &edge) const |
virtual Node & | headNode (const Edge &edge) const |
virtual void | connectNodes (const Node &nTail, const Node &nHead, Edge &e) |
virtual void | disconnectNodes (const Node &nTail, const Node &nHead) |
virtual void | moveInEdges (const Node &source, const Node &destination) |
virtual void | moveOutEdges (const Node &source, const Node &destination) |
virtual void | moveInEdge (const Node &source, const Node &destination, Edge &edge, const Node *tail=NULL, bool childs=false) |
virtual void | moveOutEdge (const Node &source, const Node &destination, Edge &edge, const Node *head=NULL, bool childs=false) |
virtual void | copyInEdge (const Node &destination, Edge &edge, const Node *tail=NULL) |
virtual void | copyOutEdge (const Node &destination, Edge &edge, const Node *head=NULL) |
virtual void | removeNode (Node &node) |
virtual void | removeEdge (Edge &e) |
virtual void | dropNode (Node &node) |
virtual void | dropEdge (Edge &edge) |
virtual bool | hasEdge (const Node &nTail, const Node &nHead) const |
virtual NodeSet | rootNodes () const |
useful utility functions More... | |
virtual NodeSet | sinkNodes () const |
virtual NodeSet | successors (const Node &node, bool ignoreBackEdges=false, bool ignoreForwardEdges=false) const |
virtual NodeSet | predecessors (const Node &node, bool ignoreBackEdges=false, bool ignoreForwardEdges=false) const |
int | maxPathLength (const ControlDependenceNode &node) const |
int | maxSinkDistance (const ControlDependenceNode &node) const |
int | maxSourceDistance (const ControlDependenceNode &node) const |
bool | isInCriticalPath (const ControlDependenceNode &node) const |
int | height () const |
void | findAllPaths () const |
void | detachSubgraph (BoostGraph &subGraph) |
BoostGraph * | parentGraph () |
BoostGraph * | rootGraph () |
const BoostGraph * | rootGraph () const |
bool | hasNode (const Node &) const |
virtual const TCEString & | name () const |
void | setName (const TCEString &newName) |
bool | hasPath (ControlDependenceNode &src, const ControlDependenceNode &dest) const |
void | restoreNodeFromParent (ControlDependenceNode &node) |
bool | detectIllegalCycles () const |
EdgeSet | connectingEdges (const Node &nTail, const Node &nHead) const |
Public Member Functions inherited from GraphBase< ControlDependenceNode, ControlDependenceEdge > | |
GraphBase () | |
virtual | ~GraphBase () |
virtual TCEString | dotString () const |
virtual void | writeToDotFile (const TCEString &fileName) const |
Private Types | |
typedef std::map< ControlFlowGraph::NodeDescriptor, int > | PostOrderMap |
Stores data to compute post order relation on CFG. More... | |
typedef boost::associative_property_map< PostOrderMap > | PostOrder |
typedef std::map< NodeDescriptor, int > | CDGOrderMap |
Stores data to compute post order relation on CDG and strong components. More... | |
typedef boost::associative_property_map< CDGOrderMap > | CDGOrder |
typedef std::map< NodeDescriptor, NodeDescriptor > | DescriptorMap |
Storage for relations between nodes. More... | |
typedef boost::associative_property_map< DescriptorMap > | Descriptors |
typedef std::map< NodeDescriptor, boost::default_color_type > | ColorMap |
Storage for color property used by dfs. More... | |
typedef boost::associative_property_map< ColorMap > | Color |
typedef std::pair< Node *, Edge::CDGEdgeType > | SourceType |
typedef std::vector< SourceType > | DependentOn |
typedef std::vector< BasicBlockNode * > | BlockVector |
typedef std::map< Node *, DependentOn *, Node::Comparator > | DependenceMap |
Private Member Functions | |
void | computeDependence () |
void | createPostDominanceTree (BlockVector &nodes, PostOrder &postOrder) |
void | detectControlDependencies (BlockVector &nodes, std::vector< Node * > &cdNodes, PostOrder &postOrder, DependenceMap &dependencies) |
void | eliminateMultipleOutputs () |
bool | findSubset (DependentOn *, DependentOn *, Node *) |
int | nearestCommonDom (std::vector< int > &iDom, int node1, int node2) const |
int | detectStrongComponents (CDGOrderMap &components, DescriptorMap &roots) |
void | computeRegionInfo (const CDGOrderMap &orderMap) |
void | computeEECInfo (const CDGOrderMap &orderMap) |
CompareResult | compareSiblings (Node *a, Node *b) const |
void | regionHelper (Node *, Node::NodesInfo &) |
void | computeRelations (const CDGOrderMap &orderMap) |
void | processRegion (Node *region) |
ControlDependenceEdge & | createControlDependenceEdge (Node &bTail, Node &bHead, Edge::CDGEdgeType edgeValue=Edge::CDEP_EDGE_NORMAL) |
Private Attributes | |
TTAProgram::Program * | program_ |
TTAProgram::Address | startAddress_ |
int | alignment_ |
ControlFlowGraph * | cGraph_ |
std::vector< int > | iDomTree_ |
std::vector< std::set< Node * > > | strongComponents_ |
bool | analyzed_ |
Indicates that CDG already has data required for serialization. More... | |
Node * | entryNode_ |
Stores reference to entryNode of the graph. More... | |
bool | componentsDetected_ |
Additional Inherited Members | |
Protected Types inherited from BoostGraph< ControlDependenceNode, ControlDependenceEdge > | |
typedef std::set< RemovedEdgeDatum > | RemovedEdgeMap |
typedef 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 properties of boost library, which need the host compiler to support partial template specialisation. More... | |
typedef boost::graph_traits< Graph > | GraphTraits |
Traits characterising the internal graph type. More... | |
typedef GraphTraits::out_edge_iterator | OutEdgeIter |
Output edge iterator type. More... | |
typedef GraphTraits::in_edge_iterator | InEdgeIter |
Input edge iterator type. More... | |
typedef GraphTraits::edge_iterator | EdgeIter |
Iterator type for the list of all edges in the graph. More... | |
typedef GraphTraits::vertex_iterator | NodeIter |
Iterator type for the list of all nodes in the graph. More... | |
typedef GraphTraits::edge_descriptor | EdgeDescriptor |
Type with which edges of the graph are seen internally. More... | |
typedef GraphTraits::vertex_descriptor | NodeDescriptor |
Type with which nodes of the graph are seen internally. More... | |
typedef hash_map< const Edge *, EdgeDescriptor, GraphHashFunctions > | EdgeDescMap |
typedef hash_map< const Node *, NodeDescriptor, GraphHashFunctions > | NodeDescMap |
typedef std::vector< std::vector< int > > | PathCache |
Protected Member Functions inherited from BoostGraph< ControlDependenceNode, ControlDependenceEdge > | |
Node & | tailNode (const Edge &edge, const NodeDescriptor &headNode) const |
Node & | headNode (const Edge &edge, const NodeDescriptor &tailNode) const |
virtual void | connectNodes (const Node &nTail, const Node &nHead, Edge &e, GraphBase< ControlDependenceNode, ControlDependenceEdge > *modifier, bool creatingSG=false) |
void | moveInEdges (const Node &source, const Node &destination, BoostGraph *modifierGraph) |
virtual void | moveOutEdges (const Node &source, const Node &destination, BoostGraph *modifierGraph) |
virtual void | removeNode (Node &node, BoostGraph *modifierGraph) |
virtual void | removeEdge (Edge &e, const ControlDependenceNode *tailNode, const ControlDependenceNode *headNode, BoostGraph *modifierGraph=NULL) |
bool | hasEdge (const Node &nTail, const Node &nHead, const Edge &edge) const |
bool | hasEdge (const Edge &edge, const Node *nTail=NULL, const Node *nHead=NULL) const |
void | restoreRemovedEdges (RemovedEdgeMap removedEdges) |
EdgeDescriptor | descriptor (const Edge &e) const |
NodeDescriptor | descriptor (const Node &n) const |
EdgeDescriptor | edgeDescriptor (const NodeDescriptor &tailNode, const Edge &e) const |
EdgeDescriptor | edgeDescriptor (const Edge &e, const NodeDescriptor &headNode) const |
EdgeDescriptor | connectingEdge (const Node &nTail, const Node &nHead) const |
void | replaceNodeWithLastNode (ControlDependenceNode &dest) |
void | calculatePathLengths () const |
void | calculatePathLengthsFast () const |
void | calculateSinkDistance (const ControlDependenceNode &node, int len, bool looping=false) const |
void | calculateSourceDistances (const ControlDependenceNode *startNode=NULL, int startingLength=0, bool looping=false) const |
void | calculatePathLengthsOnConnect (const ControlDependenceNode &nTail, const ControlDependenceNode &nHead, ControlDependenceEdge &e) |
void | sinkDistDecreased (const ControlDependenceNode &n) const |
void | sourceDistDecreased (const ControlDependenceNode &n) const |
virtual int | edgeWeight (ControlDependenceEdge &e, const ControlDependenceNode &n) const |
void | clearDescriptorCache (EdgeSet edges) |
void | constructSubGraph (BoostGraph &subGraph, NodeSet &nodes) |
Protected Attributes inherited from BoostGraph< ControlDependenceNode, ControlDependenceEdge > | |
std::map< const ControlDependenceNode *, int, typename ControlDependenceNode ::Comparator > | sourceDistances_ |
std::map< const ControlDependenceNode *, int, typename ControlDependenceNode ::Comparator > | sinkDistances_ |
std::map< const ControlDependenceNode *, int, typename ControlDependenceNode ::Comparator > | loopingSourceDistances_ |
std::map< const ControlDependenceNode *, int, typename ControlDependenceNode ::Comparator > | loopingSinkDistances_ |
int | height_ |
Graph | graph_ |
The internal graph structure. More... | |
EdgeDescMap | edgeDescriptors_ |
NodeDescMap | nodeDescriptors_ |
BoostGraph< ControlDependenceNode, ControlDependenceEdge > * | parentGraph_ |
std::vector< BoostGraph< ControlDependenceNode, ControlDependenceEdge > * > | childGraphs_ |
TCEString | name_ |
int | sgCounter_ |
std::set< Edge * > | ownedEdges_ |
bool | allowLoopEdges_ |
PathCache * | pathCache_ |
Graph-based program representation.
Definition at line 65 of file ControlDependenceGraph.hh.
|
private |
Definition at line 102 of file ControlDependenceGraph.hh.
|
private |
Definition at line 92 of file ControlDependenceGraph.hh.
|
private |
Stores data to compute post order relation on CDG and strong components.
Definition at line 91 of file ControlDependenceGraph.hh.
|
private |
Definition at line 98 of file ControlDependenceGraph.hh.
|
private |
Storage for color property used by dfs.
Definition at line 97 of file ControlDependenceGraph.hh.
|
private |
Definition at line 104 of file ControlDependenceGraph.hh.
|
private |
Definition at line 101 of file ControlDependenceGraph.hh.
|
private |
Storage for relations between nodes.
Definition at line 94 of file ControlDependenceGraph.hh.
|
private |
Definition at line 95 of file ControlDependenceGraph.hh.
|
private |
Definition at line 89 of file ControlDependenceGraph.hh.
|
private |
Stores data to compute post order relation on CFG.
Definition at line 88 of file ControlDependenceGraph.hh.
|
private |
Definition at line 100 of file ControlDependenceGraph.hh.
Enumerator | |
---|---|
A_BEFORE_B | |
B_BEFORE_A | |
ANY_ORDER | |
UNORDERABLE | |
ERROR |
Definition at line 69 of file ControlDependenceGraph.hh.
ControlDependenceGraph::ControlDependenceGraph | ( | const ControlFlowGraph & | cGraph | ) |
Reads ControlFlowGraph of procedure and creates ControlDependenceGraph
cGraph | Control Flow Graph |
Definition at line 97 of file ControlDependenceGraph.cc.
References ControlFlowGraph::alignment(), alignment_, cGraph_, computeDependence(), ControlFlowGraph::program(), and program_.
|
virtual |
Definition at line 80 of file ControlDependenceGraph.cc.
References BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::nodeCount(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::removeNode(), and strongComponents_.
int ControlDependenceGraph::alignment | ( | ) | const |
Returns an alignment of procedure in original POM
Definition at line 673 of file ControlDependenceGraph.cc.
References alignment_.
void ControlDependenceGraph::analyzeCDG | ( | ) |
Performs serialization of ControlDependenceGraph, turning it into Control Flow Graph.
InvalidData | in case serialization of graph is not possible |
Find all strong components (loops) in a graph, loop entry nodes will have number identifying for which loop component they are entries and the strongComponents_ will contains all nodes that are part of each component
map to store post order information for all the nodes of a graph From now on, post order info in lastMap will not change
map to store color information during dfs
boost::on_finish_vertex will give us post order numbering
Sort nodes in post order, starting from entry node
Computes "region" information, for each node X, set of nodes that are executed when X is executed (for node Z, on all paths from X to entry, if node Z is region all children of Z will be in "region" of X
Computes "eec" information, for each node X, set of nodes that are executed when any node in subgraph of X is executed, computed using region information
Definition at line 745 of file ControlDependenceGraph.cc.
References analyzed(), analyzed_, componentCount(), computeEECInfo(), computeRegionInfo(), computeRelations(), DEBUG_LEVEL, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::descriptor(), detectStrongComponents(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::edgeCount(), entryNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::graph_, Application::logStream(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::name(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::nodeCount(), and Application::verboseLevel().
Referenced by ControlDependenceGraphPass::handleControlDependenceGraph().
|
inline |
Definition at line 84 of file ControlDependenceGraph.hh.
References analyzed_.
Referenced by analyzeCDG(), ProgramDependenceGraph::ProgramDependenceGraph(), and ProgramDependenceGraph::serializePDG().
|
private |
Defined relation between two sibling nodes based on their type and eec info
FIXME: Unique region node rule is broken when creating loop entry nodes (removing loop back edge) and creating new region for incoming edges into loop entry - there can be another region which already has same set of dependences and loop entry was supposed to be child of that, but was not. Problem with detection of subsets of dependencies when creating region nodes!
Definition at line 1215 of file ControlDependenceGraph.cc.
References A_BEFORE_B, ANY_ORDER, B_BEFORE_A, AssocTools::containsKey(), ERROR, and UNORDERABLE.
Referenced by processRegion().
|
inline |
Definition at line 85 of file ControlDependenceGraph.hh.
References strongComponents_.
Referenced by analyzeCDG(), ProgramDependenceGraph::copyRegionEECComponent(), and detectStrongComponents().
|
private |
Compute control flow post-dominance information (in the form of an immediate post-dominator tree). Compute the control dependencies of the control flow graph using the pre-computed tree of immediate post-dominators.
The base algorithm implemented is described in K.D. Cooper, T.J. Harvey, K. Kennedy: "A Simple, Fast Dominance Algorithm" and Ferrante, Ottenstein, Warren: "The Program Dependence Graphs and Its Use in Optimisation"
Throws | InvalidData exception in case CFG can not be analyzed |
Removes artificial Exit node, it is not dependent on anything Move edges from Entry's child region to Entry and delete region
Definition at line 122 of file ControlDependenceGraph.cc.
References __func__, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::addNode(), ControlDependenceNode::CDEP_NODE_REGION, cGraph_, MapTools::containsKey(), createControlDependenceEdge(), createPostDominanceTree(), MapTools::deleteAllKeys(), MapTools::deleteAllValues(), detectControlDependencies(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::edge(), eliminateMultipleOutputs(), findSubset(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::headNode(), iDomTree_, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::inDegree(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::moveOutEdges(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::name(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::nodeCount(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outDegree(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outEdge(), ControlFlowGraph::removeEntryExitEdge(), and BoostGraph< ControlDependenceNode, ControlDependenceEdge >::removeNode().
Referenced by ControlDependenceGraph().
|
private |
Compute the "eec" information for each node of graph. Eec is used to determine order in which sibling subgraphs needs to be scheduled in resulting cfg.
"eec" of node X is set of nodes that will be executed in case any of the nodes in subgraph of X will be executed.
orderMap | post order map of CDG graph, nodes augmented with "region" information, "eec" information will be added. |
eec already exists, skip
Found close node, eec(node) == intersection of all close nodes of same loop region(node) (close node is as leaf node)
Found leaf node, eec(node) == region(node)
if node is predicate we also store pseudo information for part of basic block which does not compute predicate itself, it is just set of statements - leafs
Not a leaf node, eec(x) = intersection(eec(children(x)) \ children(x)
Definition at line 1100 of file ControlDependenceGraph.cc.
References __func__, ControlDependenceNode::addToEEC(), ControlDependenceNode::addToPseudoPredicateEEC(), ControlDependenceNode::component(), ControlDependenceNode::eec(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::graph_, SetTools::intersection(), ControlDependenceNode::isLoopCloseNode(), ControlDependenceNode::isPredicateNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outDegree(), ControlDependenceNode::region(), strongComponents_, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::successors(), and ControlDependenceNode::toString().
Referenced by analyzeCDG().
|
private |
Compute the "region" information for each node of graph. Region is used to compute "eec" to determine order in which sibling subgraphs will be in resulting cfg.
"Region" of node X is set of nodes that will be executed in case is X executed.
orderMap | post order map of CDG graph, nodes will be augmented with "region" information. |
Compute "region" information using reverse post-order processing
For non loop entry nodes, simply compute region info and store it in the node
for loop entry node, find all other entry nodes of the same loop (component) final region info will be intersection of region infos from all the entry nodes in the same loop it will be same for all the nodes too (they are reachable)
Test for loop entries of same component Loop entry of one component can be regular region node of other "larger" loop
Definition at line 1032 of file ControlDependenceGraph.cc.
References __func__, ControlDependenceNode::addToRegion(), ControlDependenceNode::component(), entryNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::graph_, ControlDependenceNode::isLoopEntryNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::name(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), ControlDependenceNode::region(), regionHelper(), and strongComponents_.
Referenced by analyzeCDG().
|
private |
Computes relation between every pair of nodes in a graph that has common parent.
orderMap | Post order map of a graph |
Process nodes in post order, guarantees child nodes will be processed before their parent
MoveNodes are skipped here, they are always child of region
Definition at line 1403 of file ControlDependenceGraph.cc.
References BoostGraph< ControlDependenceNode, ControlDependenceEdge >::graph_, ControlDependenceNode::isLoopEntryNode(), ControlDependenceNode::isPredicateNode(), ControlDependenceNode::isRegionNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), and processRegion().
Referenced by analyzeCDG().
|
private |
Create a control dependence edge between two basic blocks.
Creates new Control Dependence edge between two basic blocks passed as parameters
bTail | The tail basic block. |
bHead | The head basic block. |
Definition at line 332 of file ControlDependenceGraph.cc.
References __func__, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::connectingEdge(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::connectNodes(), Exception::errorMessageStack(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::graph_, and BoostGraph< ControlDependenceNode, ControlDependenceEdge >::hasEdge().
Referenced by computeDependence(), detectStrongComponents(), and eliminateMultipleOutputs().
|
private |
Internal helper. Creates a tree of immediate post dominators for constructing a control dependencies
nodes | Will be filled with pointers to BasicBlocks indexed by post order number |
postOrder | Will be filled by post order numbers |
Definition at line 362 of file ControlDependenceGraph.cc.
References __func__, ControlFlowGraph::addEntryExitEdge(), ControlFlowEdge::CFLOW_EDGE_LOOP_BREAK, cGraph_, BoostGraph< GraphNode, GraphEdge >::connectNodes(), BoostGraph< GraphNode, GraphEdge >::descriptor(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::edge(), ControlFlowGraph::exitNode(), BoostGraph< GraphNode, GraphEdge >::headNode(), iDomTree_, BasicBlockNode::isEntryBB(), nearestCommonDom(), BoostGraph< GraphNode, GraphEdge >::node(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), BoostGraph< GraphNode, GraphEdge >::outDegree(), BoostGraph< GraphNode, GraphEdge >::outEdge(), BoostGraph< GraphNode, GraphEdge >::removeEdge(), and ControlFlowGraph::reversedGraph().
Referenced by computeDependence().
|
private |
Internal helper. Implemented detection of control dependencies.
nodes | Vector of basic block nodes indexed by reverse post order number |
cdNodes | Vector of control dependence nodes indexed by reverse post order number |
postOrder | Post order numbering of nodes |
dependencies | For each node, the list of nodes it is dependent on |
Basic block is either 3way jump - forbidden or it is indirect jump with edges to all data-code rellocations. We can not deal with such situation at the moment. Fix cfg to original form and throw exception
node is not predicate
Basic block is either 3way jump - forbidden or it is indirect jump with edges to all data-code rellocations. We can not deal with such situation at the moment. Fix cfg to original form and throw exception
Definition at line 546 of file ControlDependenceGraph.cc.
References __func__, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::addNode(), ControlDependenceEdge::CDEP_EDGE_FALSE, ControlDependenceEdge::CDEP_EDGE_NORMAL, ControlDependenceEdge::CDEP_EDGE_TRUE, ControlDependenceNode::CDEP_NODE_BB, ControlDependenceNode::CDEP_NODE_PREDICATE, cGraph_, MapTools::containsKey(), BoostGraph< GraphNode, GraphEdge >::descriptor(), BoostGraph< GraphNode, GraphEdge >::headNode(), iDomTree_, BasicBlockNode::isEntryBB(), ControlDependenceEdge::isFalseEdge(), ControlDependenceEdge::isTrueEdge(), BoostGraph< GraphNode, GraphEdge >::node(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), BoostGraph< GraphNode, GraphEdge >::outDegree(), BoostGraph< GraphNode, GraphEdge >::outEdge(), ControlFlowGraph::removeEntryExitEdge(), and BasicBlockNode::toString().
Referenced by computeDependence().
|
private |
Detects all strong components of a CDG graph (loops). Strong components are maximal sets of nodes that are reachable from each other. Each node is member of some component. If it is not in loop then node is components of it's own. Augments graph with loop entry and close nodes. Works iterativly, first detects maximal component, then proceeds to ones that are "embedded".
components | After return contains for each node number of component to which node belongs |
roots | After return contains for each node a node that is root of component to which node belongs |
Will repeat untill all the strong components will be found Including weirdly nested :-)
Node count will change with addition of close nodes
If the number of components is identical to number of nodes there are no loops in graph
Add to strong components only those which are loops Store them as CDNode*, use of descriptors is not possible due to later addition of Nodes which will invalidate descriptors
Detects all loop entry nodes Stores Nodes which are identified as loop entry nodes together with number to which loop they belong
for each entry node, collect edges that points to it from outside the loop, deals only with newly added components
This may change in which component node it
Several nodes points to loop entry node we create dummy region node to collect those edges
Adds close nodes for each loop entry node Node and edge descriptors are invalidated here!
Create one "close" node for each loop entry
Close node is also part of component
Detect edges to loop entry node from inside component and redirect them to close node
Actually redirect edges
Back edge will be added later, after all loops are found
Test if edges were redirected successfully
In case loop entry has multiple incoming edges outside loop, we add new region to group them together
Definition at line 848 of file ControlDependenceGraph.cc.
References __func__, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::addNode(), ControlDependenceEdge::CDEP_EDGE_LOOPCLOSE, ControlDependenceNode::CDEP_NODE_LOOPCLOSE, ControlDependenceNode::CDEP_NODE_REGION, componentCount(), componentsDetected_, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::connectingEdge(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::connectNodes(), createControlDependenceEdge(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::graph_, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::inDegree(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::inEdges(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::moveInEdge(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::nodeCount(), strongComponents_, and BoostGraph< ControlDependenceNode, ControlDependenceEdge >::tailNode().
Referenced by analyzeCDG().
|
private |
Internal helper. Replaces several output edges with same truth value with region node. Combines several output edges without truth value (indirect jumps for example);
Combine all "true" children of predicate with region
Combine all "false" children of predicate with region
Definition at line 693 of file ControlDependenceGraph.cc.
References BoostGraph< ControlDependenceNode, ControlDependenceEdge >::addNode(), ControlDependenceEdge::CDEP_EDGE_FALSE, ControlDependenceEdge::CDEP_EDGE_TRUE, ControlDependenceNode::CDEP_NODE_REGION, createControlDependenceEdge(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::disconnectNodes(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::headNode(), ControlDependenceNode::isBBNode(), ControlDependenceEdge::isFalseEdge(), ControlDependenceEdge::isTrueEdge(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::nodeCount(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outDegree(), and BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outEdge().
Referenced by computeDependence().
ControlDependenceNode & ControlDependenceGraph::entryNode | ( | ) |
Return the entry node of the graph. Cache it after it's found for alter use
InstanceNotFound | if the graph does not have a entry node. |
ModuleRunTimeError | if the graph has multiple nodes that are recognised as entry nodes. |
Definition at line 497 of file ControlDependenceGraph.cc.
References __func__, entryNode_, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::inDegree(), ControlDependenceNode::isEntryNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::name(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::nodeCount(), and ControlDependenceNode::toString().
Referenced by analyzeCDG(), and computeRegionInfo().
|
private |
Internal helper. Find already existing region node in set of dependencies.
Find if set of dependencies contains a subset that has already a region node. If so, modifies dependencies to contain dependence to existing region node.
wholeSet | Set of dependencies for node we want to test |
subSet | Set corresponding to some already existing region node |
regNode | Region node we are testing |
Definition at line 253 of file ControlDependenceGraph.cc.
References ControlDependenceEdge::CDEP_EDGE_NORMAL.
Referenced by computeDependence().
|
private |
Internal hepler. Compute the nearest common dominator of two nodes.
Given two nodes (identified by their traversal order), find the nearest common ancestor that dominates both.
Note: this method should go in separate immediate dominator class.
iDom | Tree of immediate dominators. |
node1 | A graph node. |
node2 | Another graph node. |
Definition at line 304 of file ControlDependenceGraph.cc.
Referenced by createPostDominanceTree().
|
private |
"Sorts" all the child nodes of a region in topological order based on their control and data dependencies.
regionNode | Region node who's child nodes to process |
cdgGraph | Control Dependence subraph |
Get all child nodes of region node
node1 will be compared against all the other previously untested nodes
Test relation between siblings, should never return ERROR twice!
Definition at line 1429 of file ControlDependenceGraph.cc.
References __func__, A_BEFORE_B, ANY_ORDER, B_BEFORE_A, compareSiblings(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::connectNodes(), DEBUG_LEVEL, ERROR, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::headNode(), Application::logStream(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outEdges(), UNORDERABLE, and Application::verboseLevel().
Referenced by computeRelations().
TTAProgram::Program * ControlDependenceGraph::program | ( | ) | const |
Returns the pointer to Program object of POM procedure belongs to.
Definition at line 683 of file ControlDependenceGraph.cc.
References program_.
Referenced by ProgramDependenceGraph::disassemble(), and ProgramDependenceGraph::ProgramDependenceGraph().
|
private |
Helper function to compute actual region information for a node. Called several times for a case when there are loop entry nodes detected.
node | Node for which to compute region info |
cdg | Filtered PDG graph with only control dependence edges |
finalNodesInfo | stores actuall computed region info |
Find all incoming control dependence edges
If parent's region is not yet computed (should be btw) compute it before continuing.
region(node,parent) == region(parent) U childern(parent)
region(node,parent) == region(parent)
fill in final region info with info from first of parents
region(node) = intersection(region(node,parent(node))) for all parents. finalNodesInfo is already initialized from counter 0
Definition at line 1330 of file ControlDependenceGraph.cc.
References __func__, BoostGraph< ControlDependenceNode, ControlDependenceEdge >::headNode(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::inEdges(), SetTools::intersection(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::node(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::outEdges(), BoostGraph< ControlDependenceNode, ControlDependenceEdge >::tailNode(), and ControlDependenceNode::toString().
Referenced by computeRegionInfo().
|
private |
Definition at line 136 of file ControlDependenceGraph.hh.
Referenced by alignment(), and ControlDependenceGraph().
|
private |
Indicates that CDG already has data required for serialization.
Definition at line 142 of file ControlDependenceGraph.hh.
Referenced by analyzeCDG(), and analyzed().
|
private |
Definition at line 138 of file ControlDependenceGraph.hh.
Referenced by computeDependence(), ControlDependenceGraph(), createPostDominanceTree(), and detectControlDependencies().
|
private |
Definition at line 145 of file ControlDependenceGraph.hh.
Referenced by detectStrongComponents().
|
private |
Stores reference to entryNode of the graph.
Definition at line 144 of file ControlDependenceGraph.hh.
Referenced by entryNode().
|
private |
Definition at line 139 of file ControlDependenceGraph.hh.
Referenced by computeDependence(), createPostDominanceTree(), and detectControlDependencies().
|
private |
Definition at line 134 of file ControlDependenceGraph.hh.
Referenced by ControlDependenceGraph(), and program().
|
private |
Definition at line 135 of file ControlDependenceGraph.hh.
|
private |
Definition at line 140 of file ControlDependenceGraph.hh.
Referenced by componentCount(), computeEECInfo(), computeRegionInfo(), detectStrongComponents(), and ~ControlDependenceGraph().