113 auto entry = cfg.insert_node(
"entry");
114 auto cond = cfg.insert_node(
"cond");
115 auto then_block = cfg.insert_node(
"then");
116 auto else_block = cfg.insert_node(
"else");
117 auto join = cfg.insert_node(
"join");
118 auto loop_header = cfg.insert_node(
"loop_hdr");
119 auto loop_body = cfg.insert_node(
"loop_body");
120 auto exit_block = cfg.insert_node(
"exit");
122 cfg.insert_arc(entry, cond);
123 cfg.insert_arc(cond, then_block);
124 cfg.insert_arc(cond, else_block);
125 cfg.insert_arc(then_block,
join);
126 cfg.insert_arc(else_block,
join);
127 cfg.insert_arc(
join, loop_header);
128 cfg.insert_arc(loop_header, loop_body);
129 cfg.insert_arc(loop_header, exit_block);
130 cfg.insert_arc(loop_body, loop_header);
132 cout <<
"=== Control-Flow Graph ===" << endl;
133 cout <<
"Nodes: " << cfg.get_num_nodes() << endl;
134 cout <<
"Arcs: " << cfg.get_num_arcs() << endl;
136 cout <<
"Edges:" << endl;
137 for (
auto it = cfg.get_arc_it(); it.has_curr(); it.next_ne())
139 auto arc = it.get_curr();
140 cout <<
" " << cfg.get_src_node(arc)->get_info()
141 <<
" -> " << cfg.get_tgt_node(arc)->get_info() << endl;
152 cout <<
"=== Immediate Dominators ===" << endl;
153 for (
auto it = idoms.get_it(); it.has_curr(); it.next_ne())
155 auto [node, idom] = it.get_curr();
156 cout <<
" idom(" << node->get_info() <<
") = "
157 << (idom ? idom->get_info() :
"(root)") << endl;
168 cout <<
"=== Dominator Tree ===" << endl;
169 cout <<
"Nodes: " << dom_tree.get_num_nodes() << endl;
170 cout <<
"Arcs: " << dom_tree.get_num_arcs() << endl;
172 cout <<
"Tree edges (parent -> child):" << endl;
173 for (
auto it = dom_tree.get_arc_it(); it.has_curr(); it.next_ne())
175 auto arc = it.get_curr();
176 cout <<
" " << dom_tree.get_src_node(arc)->get_info()
177 <<
" -> " << dom_tree.get_tgt_node(arc)->get_info() << endl;
187 cout <<
"=== Dominance Frontiers ===" << endl;
188 for (
auto it =
df.get_it(); it.has_curr(); it.next_ne())
190 auto & [node, frontier] = it.get_curr();
191 cout <<
" DF(" << node->get_info() <<
") = ";
192 print_frontier(node, frontier);
201 cout <<
"=== SSA Phi-Function Placement ===" << endl;
202 cout <<
"Blocks where phi-functions would be needed:" << endl;
206 for (
auto it =
df.get_it(); it.has_curr(); it.next_ne())
208 auto & [node, frontier] = it.get_curr();
209 if (not frontier.is_empty())
211 cout <<
" Definitions in '" << node->get_info()
212 <<
"' need phi at: ";
213 print_frontier(node, frontier);
223 cout <<
"=== Dominance Queries ===" << endl;
224 cout <<
" entry dominates exit? "
225 << (dom.
dominates(cfg, entry, entry, exit_block) ?
"yes" :
"no") << endl;
226 cout <<
" cond dominates join? "
227 << (dom.
dominates(cfg, entry, cond,
join) ?
"yes" :
"no") << endl;
228 cout <<
" then dominates join? "
229 << (dom.
dominates(cfg, entry, then_block,
join) ?
"yes" :
"no") << endl;
230 cout <<
" loop_hdr dominates loop_body? "
231 << (dom.
dominates(cfg, entry, loop_header, loop_body) ?
"yes" :
"no") << endl;
241 cout <<
"=== Immediate Post-Dominators (exit = " << exit_block->get_info()
243 for (
auto pit = ipdoms.get_it(); pit.has_curr(); pit.next_ne())
245 auto [node, ipdom] = pit.get_curr();
246 cout <<
" ipdom(" << node->get_info() <<
") = "
247 << (ipdom ? ipdom->get_info() :
"(exit)") << endl;
258 cout <<
"=== Post-Dominator Tree ===" << endl;
259 cout <<
"Nodes: " << pdom_tree.get_num_nodes() << endl;
260 cout <<
"Arcs: " << pdom_tree.get_num_arcs() << endl;
262 cout <<
"Tree edges (parent -> child):" << endl;
263 for (
auto pit = pdom_tree.get_arc_it(); pit.has_curr(); pit.next_ne())
265 auto arc = pit.get_curr();
266 cout <<
" " << pdom_tree.get_src_node(arc)->get_info()
267 <<
" -> " << pdom_tree.get_tgt_node(arc)->get_info() << endl;
277 cout <<
"=== Post-Dominance Frontiers ===" << endl;
278 for (
auto pit = pdf.get_it(); pit.has_curr(); pit.next_ne())
280 auto & [node, frontier] = pit.get_curr();
281 cout <<
" PDF(" << node->get_info() <<
") = ";
282 print_frontier(node, frontier);
291 cout <<
"=== Post-Dominance Queries ===" << endl;
292 cout <<
" exit post-dominates entry? "
293 << (pdom.
post_dominates(cfg, exit_block, exit_block, entry) ?
"yes" :
"no")
295 cout <<
" loop_hdr post-dominates cond? "
296 << (pdom.
post_dominates(cfg, exit_block, loop_header, cond) ?
"yes" :
"no")
298 cout <<
" then post-dominates entry? "
299 << (pdom.
post_dominates(cfg, exit_block, then_block, entry) ?
"yes" :
"no")
Computes post-dominator tree and post-dominance frontiers of a digraph using the Lengauer-Tarjan algo...
DynMapTree< Node *, DynSetTree< Node * > > post_dominance_frontiers(const GT &g, Node *exit_node)
Compute post-dominance frontiers for all reachable nodes.
void build_tree(const GT &g, Node *exit_node, GT &tree)
Build the post-dominator tree as a separate graph.
DynList< std::pair< Node *, Node * > > compute_ipdom(const GT &g, Node *exit_node)
Compute immediate post-dominators.
bool post_dominates(const GT &g, Node *exit_node, Node *d, Node *v)
Test whether node d post-dominates node v.