|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Computes post-dominator tree and post-dominance frontiers of a digraph using the Lengauer-Tarjan algorithm on the reversed graph. More...
#include <Dominators.H>
Public Member Functions | |
| Lengauer_Tarjan_Post_Dominators (SA __sa=SA()) | |
| Construct a post-dominator computation instance. | |
| Lengauer_Tarjan_Post_Dominators (const Lengauer_Tarjan_Post_Dominators &)=delete | |
| Post-dominator instances should not be copied (they hold internal state) | |
| Lengauer_Tarjan_Post_Dominators & | operator= (const Lengauer_Tarjan_Post_Dominators &)=delete |
| Lengauer_Tarjan_Post_Dominators (Lengauer_Tarjan_Post_Dominators &&)=default | |
| Move is allowed. | |
| Lengauer_Tarjan_Post_Dominators & | operator= (Lengauer_Tarjan_Post_Dominators &&)=default |
| DynList< std::pair< Node *, Node * > > | compute_ipdom (const GT &g, Node *exit_node) |
| Compute immediate post-dominators. | |
| void | build_tree (const GT &g, Node *exit_node, GT &tree) |
| Build the post-dominator tree as a separate graph. | |
| Node * | get_ipdom (const GT &g, Node *exit_node, Node *node) |
| Get the immediate post-dominator of a specific node. | |
| bool | post_dominates (const GT &g, Node *exit_node, Node *d, Node *v) |
| Test whether node d post-dominates node v. | |
| DynMapTree< Node *, DynSetTree< Node * > > | post_dominance_frontiers (const GT &g, Node *exit_node) |
| Compute post-dominance frontiers for all reachable nodes. | |
| void | operator() (const GT &g, Node *exit_node, GT &tree) |
| Build post-dominator tree (operator() alias). | |
Accessors | |
| SA & | get_filter () noexcept |
| Get the arc filter. | |
| const SA & | get_filter () const noexcept |
| Get the arc filter (const). | |
| bool | has_computation () const noexcept |
| Check if a computation has been performed. | |
| GT * | get_graph () const noexcept |
| Get the graph of the last computation. | |
| Node * | get_exit () const noexcept |
| Get the exit node of the last computation. | |
Private Types | |
| using | Node = typename GT::Node |
| using | Arc = typename GT::Arc |
Private Member Functions | |
| Node * | to_rev (Node *orig) const |
| Map original node to reversed graph node. | |
| Node * | to_orig (Node *rev_n) const |
| Map reversed graph node to original node. | |
| void | ensure_computed (const GT &g, Node *exit_node) |
| Ensure computation is up to date. | |
Private Attributes | |
| SA | sa |
| GT | rev |
| Lengauer_Tarjan_Dominators< GT, SA > | dom |
| GT * | gptr = nullptr |
| Node * | exit_ptr = nullptr |
| bool | is_computed = false |
| DynMapTree< Node *, Node * > | orig_to_rev |
| DynMapTree< Node *, Node * > | rev_to_orig |
Computes post-dominator tree and post-dominance frontiers of a digraph using the Lengauer-Tarjan algorithm on the reversed graph.
A node d post-dominates v if every path from v to a designated exit node passes through d. The post-dominator tree is the dominator tree of the reversed graph rooted at the exit node.
This class internally inverts the digraph with invert_digraph() and runs Lengauer_Tarjan_Dominators on the result. Results are transparently mapped back to the original graph nodes.
Each method computes the post-dominators again, with a new reversed graph, so that a change of the graph is always seen.
| GT | The directed graph type. |
| SA | Arc filter class for the internal iterator. |
| Operation | Time | Space |
|---|---|---|
| Post-dominator tree | O(E * alpha(V)) | O(V + E) |
| Post-dominance frontiers | O(V + E) additional | O(V + |PDF|) |
Definition at line 748 of file Dominators.H.
|
private |
Definition at line 753 of file Dominators.H.
|
private |
Definition at line 752 of file Dominators.H.
|
inline |
Construct a post-dominator computation instance.
| __sa | Arc filter functor. Defaults to Dft_Show_Arc<GT>. |
| bad_alloc | if there is not enough memory for the arrays. |
| anything | that the copy or the move of the filter throws. |
Definition at line 832 of file Dominators.H.
|
delete |
Post-dominator instances should not be copied (they hold internal state)
|
default |
Move is allowed.
|
inline |
Build the post-dominator tree as a separate graph.
Creates a new directed graph tree where each node that can reach the exit in the original graph is represented, and arcs go from ipdom to child. Nodes are mapped via NODE_COOKIE between the original graph and the tree.
| g | The directed graph. | |
| exit_node | Exit node. | |
| [out] | tree | Output post-dominator tree (cleared first). |
| std::domain_error | If exit_node is null. |
Definition at line 890 of file Dominators.H.
References Aleph::clear_graph(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::dom, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::DynMapTree< Key, Data, Tree, Compare >::find(), Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), GraphCommon< GT, Node, Arc >::map_nodes(), NODE_COOKIE, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_orig(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
Referenced by Aleph::build_post_dominator_tree(), and main().
|
inline |
Compute immediate post-dominators.
Returns a list of (node, ipdom) pairs for every node that can reach the exit node. The exit node's ipdom is nullptr.
| g | The directed graph. |
| exit_node | Exit node for post-dominator computation. |
| std::domain_error | If exit_node is null. |
Definition at line 860 of file Dominators.H.
References Aleph::DynList< T >::append(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::dom, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_orig(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
Referenced by Aleph::compute_post_dominators(), and main().
|
inlineprivate |
Ensure computation is up to date.
Inverts the graph and runs dominator computation on the reversed graph from the exit node.
invert_digraph creates a new graph with fresh Arc objects. If the arc filter SA depends on the identity (address) of the original arcs, it will fail or filter incorrectly on the reversed graph. Stateless filters (like Dft_Show_Arc) or those depending only on Node identities are safe.| g | The directed graph. |
| exit_node | Exit node (must not be null). |
Definition at line 794 of file Dominators.H.
References ah_domain_error_if, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::dom, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::exit_ptr, GraphCommon< GT, Node, Arc >::get_node_it(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::gptr, Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), Aleph::invert_digraph(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::is_computed, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::orig_to_rev, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev_to_orig, and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::build_tree(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::compute_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominance_frontiers(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominates().
|
inlinenoexcept |
Get the exit node of the last computation.
Definition at line 1042 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::exit_ptr.
|
inlinenoexcept |
Get the arc filter (const).
Definition at line 1033 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::sa.
|
inlinenoexcept |
Get the arc filter.
Definition at line 1030 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::sa.
|
inlinenoexcept |
Get the graph of the last computation.
Definition at line 1039 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::gptr.
|
inline |
Get the immediate post-dominator of a specific node.
| g | The directed graph. |
| exit_node | Exit node. |
| node | The node whose ipdom is queried. |
| std::domain_error | If exit_node or node is null. |
Definition at line 939 of file Dominators.H.
References ah_domain_error_if, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::dom, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_orig(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
Referenced by TEST().
|
inlinenoexcept |
Check if a computation has been performed.
Definition at line 1036 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::is_computed.
|
inline |
Build post-dominator tree (operator() alias).
| g | The directed graph. | |
| exit_node | Exit node. | |
| [out] | tree | Output post-dominator tree. |
Definition at line 1021 of file Dominators.H.
References build_tree().
|
delete |
|
default |
|
inline |
Compute post-dominance frontiers for all reachable nodes.
The post-dominance frontier PDF(x) of a node x is the set of nodes y where x post-dominates a successor of y but does not strictly post-dominate y. This is the key data structure for constructing the control dependence graph (CDG).
| g | The directed graph. |
| exit_node | Exit node. |
| std::domain_error | If exit_node is null. |
Definition at line 995 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::dom, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_orig(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
Referenced by Aleph::compute_post_dominance_frontiers(), and main().
|
inline |
Test whether node d post-dominates node v.
Post-dominance is reflexive: every node post-dominates itself.
| g | The directed graph. |
| exit_node | Exit node. |
| d | Potential post-dominator. |
| v | Potential post-dominated node. |
| std::domain_error | If exit_node is null. |
Definition at line 966 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::dom, Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev, and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
|
inlineprivate |
Map reversed graph node to original node.
Definition at line 774 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::rev_to_orig, and Aleph::DynMapTree< Key, Data, Tree, Compare >::search().
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::build_tree(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::compute_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_ipdom(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominance_frontiers().
|
inlineprivate |
Map original node to reversed graph node.
Definition at line 767 of file Dominators.H.
References Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::orig_to_rev, and Aleph::DynMapTree< Key, Data, Tree, Compare >::search().
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::build_tree(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::compute_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominance_frontiers(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominates().
|
private |
Definition at line 756 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::build_tree(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::compute_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominance_frontiers(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominates().
|
private |
Definition at line 759 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_exit().
|
private |
Definition at line 758 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_graph().
|
private |
Definition at line 760 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::has_computation().
|
private |
Definition at line 763 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_rev().
|
private |
Definition at line 755 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::build_tree(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::compute_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_ipdom(), Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominance_frontiers(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::post_dominates().
|
private |
Definition at line 764 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::ensure_computed(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::to_orig().
|
private |
Definition at line 750 of file Dominators.H.
Referenced by Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_filter(), and Aleph::Lengauer_Tarjan_Post_Dominators< GT, SA >::get_filter().