ControlFlowGraph
struct ControlFlowGraph : Sendable
extension ControlFlowGraph: CustomStringConvertible
A control-flow graph.
This data structure describes relation between the basic blocks of a function. The direction of
the graph’s edges denotes the direction of the control flow from one block to another: there an
edge from A to B if the former’s terminator points to the latter.
-
A node in the graph.
Declaration
Swift
typealias Vertex = Block.ID -
An control edge label.
See moreDeclaration
Swift
enum Label : Sendable -
The way a control-flow relation is represented internally.
-
The relation encoded by the graph.
Declaration
Swift
private var relation: Relation -
The type of action to perform after exploring a vertex.
Declaration
-
Creates an empty control flow graph.
Declaration
Swift
init() -
Defines
sourceas a predecessor oftarget. -
Removes
sourcefrom the predecessors oftarget. -
Returns the successors of
source. -
Returns the predecessors of
target. -
A collection where the vertex at index
i + 1is predecessor of the vertex at indexi.Declaration
Swift
typealias PredecessorPath = [Vertex] -
Returns the paths originating at
ancestorand reachingdestinationexcluding those that containdestination.Declaration
Swift
func paths(to destination: Vertex, from ancestor: Vertex) -> [PredecessorPath] -
Returns the paths originating at
ancestorand reachingdestinationexcluding those that contain the vertices invisited.Declaration
Swift
private func paths( to destination: Vertex, from ancestor: Vertex, notContaining visited: inout Set<Vertex>, cachingResultsTo cache: inout [Vertex: [PredecessorPath]] ) -> [PredecessorPath] -
Iterates over all blocks reachable from
start, in the direction indicated byforward.Declaration
-
Explores the graph in a breadth-first manner starting from
start, callingactionfor each visited block.When calling
action, the block’s ID and its successors are passed as arguments. The return value ofactiondetermines how the exploration continues.If
forwardisfalse, the graph is explored in the reverse direction, following predecessor edges instead of successor edges.Use this method when a simple exploration with
iterateFrom()is not sufficient, for example to skip parts of the graph or to stop the exploration early.Declaration
Swift
func withBFS( _ start: [Block.ID], forward: Bool = true, _ action: (Block.ID, [Block.ID]) -> ExplorationContinuation ) -
The Graphviz (dot) representation of the graph.
Declaration
Swift
var description: String { get }
View on GitHub