Skip to main content

DataflowGraph

Struct DataflowGraph 

Source
pub struct DataflowGraph { /* private fields */ }
Expand description

A dataflow graph built from an IR function’s statements.

Nodes correspond to statements and edges represent data/control dependencies between them.

Implementations§

Source§

impl DataflowGraph

Source

pub fn build(func: &Function) -> Self

Build a dataflow graph from an IR function.

Walks statements in order, computes read/write sets, and creates dependency edges:

  • RAW (DataFlow): a write followed by a read of the same expression
  • WAR (AntiDependency): a read followed by a write of the same expression
  • WAW (OutputDependency): two writes to the same expression
  • Control: barriers create control edges to all subsequent memory operations
Source

pub fn nodes(&self) -> &[DfgNode]

Returns the nodes in this graph.

Source

pub fn edges(&self) -> &[DfgEdge]

Returns the edges in this graph.

Source

pub fn node_count(&self) -> usize

Returns the number of nodes.

Source

pub fn edge_count(&self) -> usize

Returns the number of edges.

Source

pub fn successors(&self, node_id: usize) -> Vec<&DfgEdge>

Returns all edges originating from the given node.

Source

pub fn predecessors(&self, node_id: usize) -> Vec<&DfgEdge>

Returns all edges pointing to the given node.

Source

pub fn topological_sort(&self) -> Result<Vec<usize>, DataflowError>

Perform topological sort using Kahn’s algorithm.

Returns nodes in a valid execution order respecting all dependencies.

§Errors

Returns DataflowError::CycleDetected if the graph contains a cycle.

Source

pub fn critical_path(&self) -> CriticalPathResult

Compute the critical path through the DFG.

Assigns a unit cost of 1 to each node and computes the longest path from any source node (no predecessors) to any sink node (no successors).

Returns the cost for each node (longest path from any source to that node) and the critical path length.

Source

pub fn critical_path_with_costs(&self, costs: &[usize]) -> CriticalPathResult

Compute the critical path with custom per-node costs.

costs[i] is the execution cost of node i.

Returns the cost for each node and the critical path length.

Source

pub fn parallel_groups(&self) -> Vec<Vec<usize>>

Identify groups of independent nodes that can execute concurrently.

Returns a list of groups, where each group contains node IDs that have no dependencies between them and can execute in parallel.

Trait Implementations§

Source§

impl Clone for DataflowGraph

Source§

fn clone(&self) -> DataflowGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataflowGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DataflowGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.