Skip to main content

Crate graphity_controlflow

Crate graphity_controlflow 

Source
Expand description

Analyses of control flow: loops, dominance frontiers, control dependence and the placement of phi-nodes.

This crate is the counterpart of the Java module graphity-controlflow, package com.kobayami.graphity.controlflow, released with graphity-core at the same version. Its analyses work on a control-flow graph, with the basic blocks of a method as nodes and an edge wherever control can pass from one block to another:

  • Loops - the loop nesting forest: every loop with its header, its body and its entries, and how the loops nest, irreducible loops included.
  • IteratedDominanceFrontier - the blocks where SSA (static single assignment) form places the phi-nodes of a variable.
  • control_flow - the dominance frontiers as a graph, and from them control dependence: which block decides whether another one runs.

The analyses follow edges against their direction, so they take a BiAdjacentGraph, or the Dominators computed on one; build it once and pass it to all of them. Here, the loop of a method load around its block then, from its control flow cfg and its entry block entry:

// The basic blocks of load are the nodes 0 to 5 of cfg: entry, header, body, then,
// next, exit.

// Find the loops of load, from its entry block.
let loops = Loops::of(&BiAdjacentGraph::of(&cfg), entry);

// Find the loop around the block then, with its header and its body.

// 0 - the for loop, the only loop
let loop_id = loops.innermost_loop_of(then).unwrap();
let header = loops.header_of(loop_id); // 1 - the block header
let blocks = loops.body_of(loop_id); // [1, 2, 3, 4] - header, body, then and next

The crate reads the graph through graphity_core::csr, like the algorithms of the core, and uses nothing but the public API of graphity-core, as the Java module uses nothing but the exported package of the core.

§Errors and panics

The conventions of the core apply (see graphity_core::error). Where Java returns -1 for “none”, a single lookup returns Option<u32>. A node, loop or entry out of its range panics with a message that starts with index out of bounds: . Any other broken contract, such as a graph above the node limit or a result above the largest array, panics with a message that starts with invalid argument: .

Modules§

control_flow
Relations of control flow that follow from Dominators, returned as graphs: the dominance frontiers and, from them, control dependence - Java’s class ControlFlow.

Structs§

IteratedDominanceFrontier
The iterated dominance frontiers of a control-flow graph, which tell where SSA (static single assignment) form places phi-nodes.
Loops
The loop nesting forest of a control-flow graph: its loops, how they nest and where each of them is entered, irreducible loops included.