OpenASIP
2.0
|
#include <ProgramDependenceGraph.hh>
Classes | |
struct | BackCFGFilter |
struct | BackFilter |
Filter away back edges. More... | |
struct | CDGFilter |
Filter control dependence edges only. More... | |
class | label_writer |
struct | SubgraphTypeTest |
Filter nodes of subgraph only. More... | |
Public Types | |
enum | CompareResult { A_BEFORE_B, B_BEFORE_A, ANY_ORDER, UNORDERABLE, ERROR } |
Public Types inherited from BoostGraph< ProgramDependenceNode, ProgramDependenceEdge > | |
typedef std::set< ProgramDependenceNode *, typename ProgramDependenceNode ::Comparator > | NodeSet |
typedef std::set< ProgramDependenceEdge *, typename ProgramDependenceEdge ::Comparator > | EdgeSet |
typedef ProgramDependenceNode | Node |
The (base) node type managed by this graph. More... | |
typedef ProgramDependenceEdge | Edge |
The (base) edge type managed by this graph. More... | |
Public Types inherited from GraphBase< ProgramDependenceNode, ProgramDependenceEdge > | |
typedef std::set< ProgramDependenceNode *, typename ProgramDependenceNode ::Comparator > | NodeSet |
typedef std::set< ProgramDependenceEdge *, typename ProgramDependenceEdge ::Comparator > | EdgeSet |
typedef ProgramDependenceNode | Node |
Node type of this graph (possibly, a base class). More... | |
typedef ProgramDependenceEdge | Edge |
Edge type of this graph (possibly, a base class). More... | |
Public Member Functions | |
ProgramDependenceGraph (ControlDependenceGraph &cdg, DataDependenceGraph &ddg) | |
virtual | ~ProgramDependenceGraph () |
ProgramDependenceNode & | entryNode () const |
bool | serializePDG () |
void | disassemble () const |
Public Member Functions inherited from BoostGraph< ProgramDependenceNode, ProgramDependenceEdge > | |
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 ProgramDependenceNode &node) const |
int | maxSinkDistance (const ProgramDependenceNode &node) const |
int | maxSourceDistance (const ProgramDependenceNode &node) const |
bool | isInCriticalPath (const ProgramDependenceNode &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 (ProgramDependenceNode &src, const ProgramDependenceNode &dest) const |
void | restoreNodeFromParent (ProgramDependenceNode &node) |
bool | detectIllegalCycles () const |
EdgeSet | connectingEdges (const Node &nTail, const Node &nHead) const |
Public Member Functions inherited from GraphBase< ProgramDependenceNode, ProgramDependenceEdge > | |
GraphBase () | |
virtual | ~GraphBase () |
virtual TCEString | dotString () const |
virtual void | writeToDotFile (const TCEString &fileName) const |
Private Types | |
typedef std::map< const ControlDependenceNode *, ProgramDependenceNode *, ControlDependenceNode::Comparator > | ControlToProgram |
typedef std::map< const BasicBlockNode *, ControlDependenceNode *, BasicBlockNode::Comparator > | BBToCD |
typedef std::map< const MoveNode *, ProgramDependenceNode *, MoveNode::Comparator > | MoveNodeToPDGNode |
typedef std::map< const ControlDependenceNode *, std::vector< Node * > > | MovesInCD |
typedef boost::filtered_graph< Graph, CDGFilter< Graph > > | FilteredCDG |
Type of filtered graph with CD edges only. More... | |
typedef boost::graph_traits< FilteredCDG >::in_edge_iterator | FilteredInEdgeIter |
Few types to work with filtered graph. More... | |
typedef boost::graph_traits< FilteredCDG >::out_edge_iterator | FilteredOutEdgeIter |
typedef boost::graph_traits< FilteredCDG >::vertex_descriptor | FilteredVertexDescriptor |
typedef std::pair< FilteredInEdgeIter, FilteredInEdgeIter > | FilteredInEdgePair |
typedef std::pair< FilteredOutEdgeIter, FilteredOutEdgeIter > | FilteredOutEdgePair |
typedef std::map< NodeDescriptor, int > | PDGOrderMap |
Stores data to compute post order relation on CDG and strong components. More... | |
typedef boost::associative_property_map< PDGOrderMap > | PDGOrder |
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 boost::filtered_graph< Graph, BackFilter< Graph >, SubgraphTypeTest< NodeSet, Graph > > | Subgraph |
typedef boost::filtered_graph< Graph, BackCFGFilter< Graph > > | CFGSubgraph |
Private Attributes | |
const ControlDependenceGraph * | cdg_ |
Stores original control dependence graph. More... | |
const DataDependenceGraph * | ddg_ |
Stores original data dependence graph. More... | |
Node * | entryNode_ |
Stores pointer to entry node of the PDG graph. More... | |
Node * | ddgEntryNode_ |
Stored reference to PDG equivalent of DDG ENTRYNODE. More... | |
std::vector< std::set< Node * > > | strongComponents_ |
stores nodes present in each of the found components More... | |
ControlFlowGraph * | newCFG_ |
Newly created control flow graph. More... | |
int | insCount_ |
Counts new instructions when creating basic blocks. More... | |
TTAProgram::Program * | program_ |
Original Program object, to get instruction reference manager. More... | |
int | wrongCounter_ |
Additional Inherited Members | |
Protected Types inherited from BoostGraph< ProgramDependenceNode, ProgramDependenceEdge > | |
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< ProgramDependenceNode, ProgramDependenceEdge > | |
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< ProgramDependenceNode, ProgramDependenceEdge > *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 ProgramDependenceNode *tailNode, const ProgramDependenceNode *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 (ProgramDependenceNode &dest) |
void | calculatePathLengths () const |
void | calculatePathLengthsFast () const |
void | calculateSinkDistance (const ProgramDependenceNode &node, int len, bool looping=false) const |
void | calculateSourceDistances (const ProgramDependenceNode *startNode=NULL, int startingLength=0, bool looping=false) const |
void | calculatePathLengthsOnConnect (const ProgramDependenceNode &nTail, const ProgramDependenceNode &nHead, ProgramDependenceEdge &e) |
void | sinkDistDecreased (const ProgramDependenceNode &n) const |
void | sourceDistDecreased (const ProgramDependenceNode &n) const |
virtual int | edgeWeight (ProgramDependenceEdge &e, const ProgramDependenceNode &n) const |
void | clearDescriptorCache (EdgeSet edges) |
void | constructSubGraph (BoostGraph &subGraph, NodeSet &nodes) |
Protected Attributes inherited from BoostGraph< ProgramDependenceNode, ProgramDependenceEdge > | |
std::map< const ProgramDependenceNode *, int, typename ProgramDependenceNode ::Comparator > | sourceDistances_ |
std::map< const ProgramDependenceNode *, int, typename ProgramDependenceNode ::Comparator > | sinkDistances_ |
std::map< const ProgramDependenceNode *, int, typename ProgramDependenceNode ::Comparator > | loopingSourceDistances_ |
std::map< const ProgramDependenceNode *, int, typename ProgramDependenceNode ::Comparator > | loopingSinkDistances_ |
int | height_ |
Graph | graph_ |
The internal graph structure. More... | |
EdgeDescMap | edgeDescriptors_ |
NodeDescMap | nodeDescriptors_ |
BoostGraph< ProgramDependenceNode, ProgramDependenceEdge > * | parentGraph_ |
std::vector< BoostGraph< ProgramDependenceNode, ProgramDependenceEdge > * > | childGraphs_ |
TCEString | name_ |
int | sgCounter_ |
std::set< Edge * > | ownedEdges_ |
bool | allowLoopEdges_ |
PathCache * | pathCache_ |
Definition at line 51 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 76 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 162 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 116 of file ProgramDependenceGraph.hh.
|
private |
Storage for color property used by dfs.
Definition at line 115 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 74 of file ProgramDependenceGraph.hh.
|
private |
Storage for relations between nodes.
Definition at line 112 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 113 of file ProgramDependenceGraph.hh.
|
private |
Type of filtered graph with CD edges only.
Definition at line 96 of file ProgramDependenceGraph.hh.
|
private |
Few types to work with filtered graph.
Definition at line 99 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 105 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 101 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 107 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 103 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 78 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 80 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 110 of file ProgramDependenceGraph.hh.
|
private |
Stores data to compute post order relation on CDG and strong components.
Definition at line 109 of file ProgramDependenceGraph.hh.
|
private |
Definition at line 149 of file ProgramDependenceGraph.hh.
Enumerator | |
---|---|
A_BEFORE_B | |
B_BEFORE_A | |
ANY_ORDER | |
UNORDERABLE | |
ERROR |
Definition at line 55 of file ProgramDependenceGraph.hh.
ProgramDependenceGraph::ProgramDependenceGraph | ( | ControlDependenceGraph & | cdg, |
DataDependenceGraph & | ddg | ||
) |
Constructor. Build Program Dependence Graph from Control and Data Dependence graphs.
cdg | Control Dependence Graph of procedure |
ddg | Data Dependence Graph of procedure |
Ignore unconditional jumps
Found dummy entry node of ddg, connect it to entry node of pdg as well.
If CDG already has analysis of Region and EEC done, just copy results
Definition at line 93 of file ProgramDependenceGraph.cc.
References __func__, abortWithError, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::addNode(), ControlDependenceGraph::analyzed(), assert, ControlDependenceNode::basicBlockNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::connectNodes(), MapTools::containsKey(), copyRegionEECComponent(), ddgEntryNode_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), BoostGraph< GraphNode, GraphEdge >::edge(), BoostGraph< GraphNode, GraphEdge >::edgeCount(), entryNode(), entryNode_, Exception::errorMessageStack(), DataDependenceGraph::getBasicBlockNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::headNode(), BoostGraph< GraphNode, GraphEdge >::headNode(), BoostGraph< GraphNode, GraphEdge >::inDegree(), BoostGraph< GraphNode, GraphEdge >::inEdge(), ControlDependenceNode::isEntryNode(), TTAProgram::Move::isJump(), ControlDependenceNode::isLastNode(), ControlDependenceNode::isLoopCloseNode(), ControlDependenceNode::isLoopEntryNode(), MoveNode::isMove(), ProgramDependenceNode::isMoveNode(), ProgramDependenceNode::isPredicateMoveNode(), ControlDependenceNode::isRegionNode(), MoveNode::move(), ProgramDependenceNode::moveNode(), BoostGraph< GraphNode, GraphEdge >::node(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), ProgramDependenceNode::PDG_NODE_LOOPCLOSE, ProgramDependenceNode::PDG_NODE_LOOPENTRY, ProgramDependenceNode::PDG_NODE_MOVE, ProgramDependenceNode::PDG_NODE_PREDICATE, ProgramDependenceNode::PDG_NODE_REGION, ControlDependenceGraph::program(), program_, removeGuardedJump(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::removeNode(), ProgramDependenceNode::setLastNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::tailNode(), and BoostGraph< GraphNode, GraphEdge >::tailNode().
Referenced by ProgramGraph::ProgramGraph().
|
virtual |
Definition at line 75 of file ProgramDependenceGraph.cc.
References BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::nodeCount(), and strongComponents_.
|
private |
Add edges from 'leaf' blocks of a subgraph to the basic block
leafBlocks | vector of basic blocks to add |
bb | Basic block to which the edges will point to |
One previously tested was predicate or region we have to add edges from all of their leafs to this block
Predicate had only one outgoing edge, we add second with inverse value
Definition at line 1858 of file ProgramDependenceGraph.cc.
References ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_NORMAL, ControlFlowEdge::CFLOW_EDGE_TRUE, BoostGraph< GraphNode, GraphEdge >::connectingEdges(), BoostGraph< GraphNode, GraphEdge >::connectNodes(), createJump(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), Application::logStream(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), newCFG_, BoostGraph< GraphNode, GraphEdge >::outEdges(), and BasicBlockNode::toString().
Referenced by processRegion().
|
private |
Compare sibling nodes and determines their ordering relation based on eec information. In addition, nodes marked as lastNode are always ordered later in case ANY_ORDER is available.
a | First node to compare |
b | Second node to compare |
Both a and b are simple statements, order is given by data dependencies no need to test eec info
Find nodes relations in eec
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 dependencies 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 919 of file ProgramDependenceGraph.cc.
References A_BEFORE_B, ANY_ORDER, B_BEFORE_A, AssocTools::containsKey(), ProgramDependenceNode::eec(), ERROR, ProgramDependenceNode::isLastNode(), ProgramDependenceNode::isLoopCloseNode(), ProgramDependenceNode::isLoopEntryNode(), ProgramDependenceNode::isMoveNode(), ProgramDependenceNode::isPredicateMoveNode(), ProgramDependenceNode::isRegionNode(), Application::logStream(), and UNORDERABLE.
Referenced by processRegion().
|
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 PDG 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)
Close nodes eec must be empty before we get here
Found leaf node, eec(node) == region(node)
Not a leaf node, eec(x) = intersection(eec(children(x)) \ children(x)
Definition at line 806 of file ProgramDependenceGraph.cc.
References __func__, ProgramDependenceNode::addToEEC(), ProgramDependenceNode::component(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), ProgramDependenceNode::eec(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, SetTools::intersection(), ProgramDependenceNode::isLoopCloseNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), ProgramDependenceNode::region(), strongComponents_, and ProgramDependenceNode::toString().
Referenced by serializePDG().
|
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 PDG graph, nodes will be augmented with "region" information. |
cdg | Program Dependence Graph filtered to us only control dependence edges. |
Compute "region" information using reverse post-order processing Node descriptors in filtered graph are identical to original graph we only care about edge filtering here
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 info from all the entry nodes in the same loop it will be same for all the nodes too (they are reachable)
Check if node is loop entry node of tested component
for every entry node of the loop compute region info
Definition at line 734 of file ProgramDependenceGraph.cc.
References __func__, ProgramDependenceNode::addToRegion(), ProgramDependenceNode::component(), entryNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, ProgramDependenceNode::isLoopEntryNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), ProgramDependenceNode::region(), regionHelper(), and strongComponents_.
Referenced by serializePDG().
|
private |
Computes relation between every pair of nodes in a graph that has common parent.
orderMap | Post order map of a graph @parem filteredCDG Filtered PDG with only control dependence edges |
Process nodes in post order, guarantees child region/loopEntry/predicate nodes will be processed before their parent
MoveNodes are skipped here, they are always children of region
Definition at line 1444 of file ProgramDependenceGraph.cc.
References cdg_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, ProgramDependenceNode::isLoopCloseNode(), ProgramDependenceNode::isLoopEntryNode(), ProgramDependenceNode::isPredicateMoveNode(), ProgramDependenceNode::isRegionNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), newCFG_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), processLoopClose(), processPredicate(), processRegion(), program_, GraphBase< ProgramDependenceNode, ProgramDependenceEdge >::writeToDotFile(), and GraphBase< GraphNode, GraphEdge >::writeToDotFile().
|
private |
Copies Region and EEC information from CDG nodes to PDG. Only used if "preprocessing" is done via CDG analysis. Copies also component members.
cDNodeToPNode | Map between CDG nodes and PDG nodes |
bBlockToCDNode | Map between basic blocks and CDG nodes |
moveToPNode | Map between move nodes and their PDG equivalents |
moveToCD | Map between CDG node and all PDG equivalents of it's content |
Find source of region and eec. In case node is move or predicate have to find parent CDG node
No region or eec info in entry
For non basic block/predicate nodes, we copied them so they will also be in 'region' and 'eec'. Set component info for nodes that are part of loop as well
If cdg node is basic block or predicate, all moves inside will be part of same component
If destination in 'region' is CDG node, add it
If destination in 'region' is BB, add all the moves in it
We have node which was in predicate basic block but is not the actual predicate move node. We have to copy "shadow" eec information
any other type of node should have same eec information as it's CDG counterpart or basic block it belonged to
If node was in predicate basic block and is predicate we also test if it is lastNode and set info
Definition at line 1623 of file ProgramDependenceGraph.cc.
References __func__, ProgramDependenceNode::addToEEC(), ProgramDependenceNode::addToRegion(), cdg_, ProgramDependenceNode::cdgNode(), ProgramDependenceNode::component(), ControlDependenceNode::component(), ControlDependenceGraph::componentCount(), MapTools::containsKey(), ddg_, ControlDependenceNode::eec(), entryNode_, DataDependenceGraph::getBasicBlockNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, ControlDependenceNode::isLastNode(), ProgramDependenceNode::isLoopCloseNode(), ProgramDependenceNode::isLoopEntryNode(), ProgramDependenceNode::isPredicateMoveNode(), ControlDependenceNode::isPredicateNode(), ProgramDependenceNode::isRegionNode(), ProgramDependenceNode::moveNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::nodeCount(), ControlDependenceNode::pseudoPredicateEEC(), ControlDependenceNode::region(), ProgramDependenceNode::setComponent(), ProgramDependenceNode::setLastNode(), strongComponents_, and BasicBlockNode::toString().
Referenced by ProgramDependenceGraph().
|
private |
If reference already exists, just return it
Definition at line 1995 of file ProgramDependenceGraph.cc.
References TTAProgram::CodeSnippet::add(), TTAProgram::Instruction::addMove(), BasicBlockNode::basicBlock(), TTAMachine::Machine::busNavigator(), ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_TRUE, TTAMachine::Machine::controlUnit(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAProgram::InstructionReferenceManager::createReference(), TTAProgram::CodeSnippet::firstInstruction(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), TTAProgram::Instruction::hasControlFlowMove(), TTAProgram::Terminal::index(), TTAProgram::Program::instructionReferenceManager(), TTAMachine::Guard::isInverted(), BasicBlockNode::isNormalBB(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAProgram::CodeSnippet::lastInstruction(), Application::logStream(), TTAProgram::Instruction::moveCount(), TTAMachine::FunctionUnit::operation(), program_, TTAProgram::Terminal::registerFile(), TTAMachine::RegisterGuard::registerFile(), TTAMachine::RegisterGuard::registerIndex(), BasicBlockNode::toString(), TTAProgram::Instruction::toString(), UniversalMachine::universalBus(), and TTAProgram::Program::universalMachine().
Referenced by addLeafEdges(), processLoopEntry(), processPredicate(), and processRegion().
|
private |
Detects all strong components of a PDG 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 iteratively, 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 until 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 Node*, 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
tail of the edge is not inside component it is external edge making this node loop entry
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
Redirect edges to loop entry from inside the loop to loop close node. Collect edges that needs redirecting
store edges that will have to be moved
Actually redirect edges
Back edge will be added later, after all loops are found
Close node is also added to unfiltered pdg, as well as edges so we can test it directly there and not on filtered graph
In case loop entry has multiple incoming edges outside loop, we add new region to group them together This can be also on original pdg, no need to use filtered version
Creates new artificial region node without equivalent one in CDG
Add edges from close nodes to their respective loop entries
Definition at line 524 of file ProgramDependenceGraph.cc.
References __func__, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::addNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::connectingEdge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::connectNodes(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::inDegree(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::moveInEdge(), ProgramDependenceEdge::PDG_EDGE_LOOP_CLOSE, ProgramDependenceNode::PDG_NODE_LOOPCLOSE, ProgramDependenceNode::setComponent(), ProgramDependenceNode::setLoopEntryNode(), strongComponents_, and ProgramDependenceNode::toString().
Referenced by serializePDG().
void ProgramDependenceGraph::disassemble | ( | ) | const |
Definition at line 1940 of file ProgramDependenceGraph.cc.
References TTAProgram::Program::addProcedure(), cdg_, ControlFlowGraph::copyToProcedure(), POMDisassembler::disassemble(), TTAProgram::CodeSnippet::endAddress(), UniversalMachine::instructionAddressSpace(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::CodeSnippet::isInProgram(), TTAProgram::Address::location(), Application::logStream(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), newCFG_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), ControlDependenceGraph::program(), TTAProgram::Program::removeProcedure(), TTAProgram::CodeSnippet::startAddress(), sub, and TTAProgram::Program::universalMachine().
ProgramDependenceNode & ProgramDependenceGraph::entryNode | ( | ) | const |
Returns entry node of the graph.
Definition at line 1091 of file ProgramDependenceGraph.cc.
References __func__, and entryNode_.
Referenced by computeRegionInfo(), ProgramDependenceGraph(), and serializePDG().
|
private |
Helper method to move/copy DDG edges that connected subraph nodes with rest of the graph to the root node of subgraph
rootNode | Root node of subgraph |
subgraphNodes | Nodes of the subgraph to test |
filteredCDG | Filtered cdg graph, containing only control dependence nodes |
Do not process root of a subtree, it is child of other node and will be processed later
Test if target is region, predicate or loop node, those prefer copies
gets incoming control dependence edges of node more then one edge means node is reachable from several places
Deal with incoming edges
No need to deal with control dependence edges or data dependence that had been "fixed" - meaning they are between nodes of same subtree (including edges between root of subtree and child node)
Edges with identical properties already exists no need to copy or move, just remove edge
Creates copy of edge from outside subgraph to root of the graph
Edge is duplicate of already existing dependence
Moves edge from outside the subgraph to target root
Edge between nodes in subtree
Deal with outgoing edges
No need to deal with control dependence edges or data dependence that had been "fixed" - meaning they are between nodes of same subtree (including edges between root of subtree and child node)
Edges with identical properties already exists no need to copy or move, just remove edge
Creates copy of edge from outside subgraph to root of the graph if such edge does not exists
Edge is duplicate of already existing dependence
Moves edge from outside the subgraph to target root
Edge between nodes in subtree
Definition at line 1490 of file ProgramDependenceGraph.cc.
References BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::connectingEdges(), AssocTools::containsKey(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::copyInEdge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::copyOutEdge(), ProgramDependenceEdge::dataDependenceEdge(), DataDependenceEdge::dependenceType(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), DataDependenceEdge::edgeReason(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::headNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::inEdges(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::moveInEdge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::moveOutEdge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::outEdges(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::removeEdge(), and BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::tailNode().
Referenced by processPredicate(), and processRegion().
|
private |
When entry node is found during serialization, the artificial Entry and Exit nodes are added to CFG. There is added edge from Entry to first BB and All leaf nodes will have edge to the exit.
Definition at line 1736 of file ProgramDependenceGraph.cc.
References ControlFlowGraph::addExit(), BoostGraph< GraphNode, GraphEdge >::addNode(), BoostGraph< GraphNode, GraphEdge >::connectNodes(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), and newCFG_.
Referenced by processRegion().
|
private |
Add empty instruction, actual jump move will be created when we process corresponding loop entry
Definition at line 1895 of file ProgramDependenceGraph.cc.
References TTAProgram::CodeSnippet::add(), BoostGraph< GraphNode, GraphEdge >::addNode(), BasicBlockNode::basicBlock(), insCount_, newCFG_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), and ProgramDependenceNode::setNewFirstBB().
Referenced by computeRelations().
|
private |
Add edge from loop close node to corresponding loop entry
Definition at line 1916 of file ProgramDependenceGraph.cc.
References ProgramDependenceNode::component(), BoostGraph< GraphNode, GraphEdge >::connectNodes(), createJump(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), newCFG_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), and BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::predecessors().
Referenced by processPredicate(), and processRegion().
|
private |
Process predicate node of the graph.
Add edges from predicate to one or two child region nodes and fill in next basic block with last BB of first child region and fall through BB with last BB of second child (if exists), otherwise predicate BB itself. Also moves DDG edges between child nodes and out of subtree to point to predicate for topological sorting of region where predicate itself belongs.
predicate | Predicate node to process |
filteredCDG | Filtered graph from where we get child nodes of predicate |
Get all child nodes of predicate node
Store all child nodes, we will need to collect all edges to and from subgraph rooted by predicate
Create basic block with predicate, it will be also first to execute
In case one of branches had only single absolute jump to "exit" of procedure, there is no child basic block
One of the outgoing edges is missing, we will have to add edge from predicate itself to next BB
Move/copy edges between nodes "inside" subgraph and nodes outside the subgraph
Definition at line 1760 of file ProgramDependenceGraph.cc.
References __func__, TTAProgram::CodeSnippet::add(), ProgramDependenceNode::addLeafBlock(), TTAProgram::Instruction::addMove(), BoostGraph< GraphNode, GraphEdge >::addNode(), assert, BasicBlockNode::basicBlock(), ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_NORMAL, ControlFlowEdge::CFLOW_EDGE_TRUE, BoostGraph< GraphNode, GraphEdge >::connectNodes(), ProgramDependenceEdge::controlDependenceEdge(), createJump(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), TTAProgram::Move::destination(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, insCount_, ProgramDependenceEdge::isArtificialControlDependence(), ProgramDependenceNode::isLoopCloseNode(), ProgramDependenceNode::isLoopEntryNode(), ControlDependenceEdge::isTrueEdge(), MoveNode::move(), moveDDGedges(), ProgramDependenceNode::moveNode(), MoveNode::movePtr(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), newCFG_, ProgramDependenceNode::newFirstBB(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), processLoopEntry(), ProgramDependenceNode::setNewFirstBB(), and ProgramDependenceNode::toString().
Referenced by computeRelations().
|
private |
"Sorts" all the child nodes of a region in topological order based on their control and data dependencies.
regionNode | Region/Predicate node who's child nodes to process |
filteredCDG | Control Dependence subraph |
Get all child nodes of region node
Store all child nodes, we will need to collect all edges to and from subgraph rooted by region
node1 will be compared against all the other previously untested nodes
Test relation between siblings, should never return ERROR!
Move/copy edges between nodes "inside" subgraph and nodes outside the subgraph
Add actual control dependence edges for serialization
Nodes of subgraph without it's root
No loop close edges or DDG loop edges
Create filtered graph
Sort nodes of subgraph topologically
In case topological sort fails with graph not being DAG Write it out
It is first block so we add it as new first also to parent
There was some previous node tested, we have to add edges
Previously, statements created single basic block so we add edge from that to this one
If previous block ended with call we add CALL type of edge
clear lastBB, the edge was already added
leafs were processed, this node should have some leafs as well
if we got this far, lastBB should be NULL
Accessed node is loop entry, we add edge from corresponding loop close node to it.
We found single statement, time to add it to basic block
Time to create new BB
We just created first BB for children of region so we set it as first BB
Previous BB ended with CALL, so we link it to new one with call edge
Block just created is current lastBB
Leaf blocks were added, we can clear them
Definition at line 1190 of file ProgramDependenceGraph.cc.
References __func__, A_BEFORE_B, TTAProgram::CodeSnippet::add(), ProgramDependenceNode::addLeafBlock(), ProgramDependenceNode::addLeafBlocks(), addLeafEdges(), TTAProgram::Instruction::addMove(), BoostGraph< GraphNode, GraphEdge >::addNode(), ANY_ORDER, assert, B_BEFORE_A, BasicBlockNode::basicBlock(), ControlFlowEdge::CFLOW_EDGE_CALL, ControlFlowEdge::CFLOW_EDGE_NORMAL, compareSiblings(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::connectNodes(), BoostGraph< GraphNode, GraphEdge >::connectNodes(), createJump(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edge(), entryNode_, ERROR, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, insCount_, TTAProgram::Move::isCall(), ProgramDependenceNode::isLoopEntryNode(), MoveNode::isMove(), ProgramDependenceNode::isMoveNode(), ProgramDependenceNode::leafBlocks(), Application::logStream(), MoveNode::move(), moveDDGedges(), ProgramDependenceNode::moveNode(), MoveNode::movePtr(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), newCFG_, ProgramDependenceNode::newFirstBB(), ProgramDependenceNode::printRelations(), processEntry(), processLoopEntry(), ProgramDependenceNode::setNewFirstBB(), sub, Conversion::toString(), ProgramDependenceNode::toString(), UNORDERABLE, Application::verboseLevel(), GraphBase< ProgramDependenceNode, ProgramDependenceEdge >::writeToDotFile(), and wrongCounter_.
Referenced by computeRelations().
|
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 actual computed region info |
Find all incoming control dependence edges
There is no Region info for Entry node
If parent's region is not yet computed (should be btw) compute it before continuing.
region(node,parent) == region(parent) U children(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 1110 of file ProgramDependenceGraph.cc.
References ProgramDependenceNode::addToRegion(), assert, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), entryNode_, SetTools::intersection(), ProgramDependenceNode::isLoopCloseNode(), ProgramDependenceNode::isLoopEntryNode(), ProgramDependenceNode::isPredicateMoveNode(), ProgramDependenceNode::isRegionNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::node(), and ProgramDependenceNode::region().
Referenced by computeRegionInfo(), and serializePDG().
|
private |
Remove guarded jumps from the graph, makes guard generating operation a predicated node and fixes the true and false edges in case the jump had inverted guard.
cToP | mapping between Control Dependence nodes of original CDG and newly created Program Dependence nodes in PDG. |
pNode | Program Dependence Node containing guarded jump |
cNode | Control Dependence node which included guarded jump in CDG |
This used to be error, but now it possible
All incoming control dependence edges into the predicate node are also incoming edges to the guard, since they were in same block in CDG
Definition at line 327 of file ProgramDependenceGraph.cc.
References __func__, cdg_, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::connectNodes(), Exception::errorMessageStack(), TTAProgram::Move::guard(), BoostGraph< GraphNode, GraphEdge >::headNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::inDegree(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::inEdge(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::inEdges(), ControlDependenceEdge::invertEdgePredicate(), ProgramDependenceEdge::isDataDependence(), TTAProgram::MoveGuard::isInverted(), ControlDependenceNode::isLoopCloseNode(), ControlDependenceNode::isLoopEntryNode(), ControlDependenceNode::isRegionNode(), Application::logStream(), MoveNode::move(), ProgramDependenceNode::moveNode(), BoostGraph< GraphNode, GraphEdge >::outDegree(), BoostGraph< GraphNode, GraphEdge >::outEdge(), ProgramDependenceNode::setPredicateMoveNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::tailNode(), ProgramDependenceNode::toString(), and Application::verboseLevel().
Referenced by ProgramDependenceGraph().
bool ProgramDependenceGraph::serializePDG | ( | ) |
Performs serialization of ProgramDependenceGraph, turning it into Control Flow Graph.
InvalidData | in case serialization of graph is not possible |
Created filtered PDG graph containing only control dependence edges
Detect strong components if they were not detected in CDG and transferred
Modifies graph_ with added close nodes and close edges
map to store post order information for all the nodes of a graph
map to store color information during dfs
boost::on_finish_vertex will give us post order numbering
Computes post order of all the nodes in PDG
If not computed on CDG and copied, computes 'region' information for all nodes of a graph
If not computed on CDG and copied, computes 'eec' information for all nodes of a graph
If CDG comes analyzed we need to add region and eec info for dummy ENTRYNODE of DDG. By it's definition, ENTRYNODE is leaf in terms of control dependence, region == eec
Definition at line 401 of file ProgramDependenceGraph.cc.
References ProgramDependenceNode::addToEEC(), ProgramDependenceNode::addToRegion(), ControlDependenceGraph::analyzed(), cdg_, computeEECInfo(), computeRegionInfo(), ddgEntryNode_, DEBUG_LEVEL, BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::descriptor(), detectStrongComponents(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::edgeCount(), entryNode(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::graph_, Application::logStream(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name(), BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::nodeCount(), regionHelper(), and Application::verboseLevel().
|
private |
Stores original control dependence graph.
Definition at line 220 of file ProgramDependenceGraph.hh.
Referenced by computeRelations(), copyRegionEECComponent(), disassemble(), removeGuardedJump(), and serializePDG().
|
private |
Stores original data dependence graph.
Definition at line 222 of file ProgramDependenceGraph.hh.
Referenced by copyRegionEECComponent().
|
private |
Stored reference to PDG equivalent of DDG ENTRYNODE.
Definition at line 226 of file ProgramDependenceGraph.hh.
Referenced by ProgramDependenceGraph(), and serializePDG().
|
private |
Stores pointer to entry node of the PDG graph.
Definition at line 224 of file ProgramDependenceGraph.hh.
Referenced by copyRegionEECComponent(), entryNode(), processRegion(), ProgramDependenceGraph(), and regionHelper().
|
private |
Counts new instructions when creating basic blocks.
Definition at line 232 of file ProgramDependenceGraph.hh.
Referenced by processLoopClose(), processPredicate(), and processRegion().
|
private |
Newly created control flow graph.
Definition at line 230 of file ProgramDependenceGraph.hh.
Referenced by addLeafEdges(), computeRelations(), disassemble(), processEntry(), processLoopClose(), processLoopEntry(), processPredicate(), and processRegion().
|
private |
Original Program object, to get instruction reference manager.
Definition at line 234 of file ProgramDependenceGraph.hh.
Referenced by computeRelations(), createJump(), and ProgramDependenceGraph().
|
private |
stores nodes present in each of the found components
Definition at line 228 of file ProgramDependenceGraph.hh.
Referenced by computeEECInfo(), computeRegionInfo(), copyRegionEECComponent(), detectStrongComponents(), and ~ProgramDependenceGraph().
|
private |
Definition at line 250 of file ProgramDependenceGraph.hh.
Referenced by processRegion().