Closed
Description
Quoted from Basic Blocks and CFG, the definition of extended basic block (EBB):
- Extended basic block a maximal sequence of instructions beginning with a leader that contains no join nodes other than its first node.
- Has a single entry, but possible multiple exit points.
- Some optimizations are more effective on extended basic blocks.

We can identify loops by using dominators:
- a node A in the flowgraph dominates a node B if every path from entry node to B includes A.
- This relations is antisymmetric, reflexive, and transitive.

back edge: An edge in the flow graph, whose head dominates its tail (example - edge from B6 to B4).
A loop consists of all nodes dominated by its entry node (head of the back edge) and having exactly one back edge in it.
Intercept contains an effective dominator implementation. See
Usage:
void codegen_optimise(CodegenContext *ctx) {
opt_inline_global_vars(ctx);
opt_analyse_functions(ctx);
/// Optimise each function individually.
do {
foreach_ptr (IRFunction*, f, ctx->functions) {
if (f->is_extern) continue;
DominatorInfo dom = {0};
do {
build_dominator_tree(f, &dom, true);
opt_reorder_blocks(f, &dom);
} while (
opt_const_folding_and_strengh_reduction(f) ||
opt_dce(f) ||
opt_mem2reg(f) ||
opt_jump_threading(f, &dom) ||
opt_tail_call_elim(f)
);
free_dominator_info(&dom);
}
}
/// Cross-function optimisations.
while (opt_inline_global_vars(ctx) || opt_analyse_functions(ctx));
}
Similarly, blink comes with an approach to detect loops during code generation.
Metadata
Metadata
Assignees
Labels
No labels