Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libs/@local/hashql/mir/src/pass/analysis/dataflow/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ pub enum Direction {
Backward,
}

impl Direction {
#[must_use]
pub const fn reverse(self) -> Self {
match self {
Self::Forward => Self::Backward,
Self::Backward => Self::Forward,
}
}
}

/// The results of a dataflow analysis after reaching a fixed point.
///
/// Contains the computed abstract state at both entry and exit of each basic block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ impl CyclicPlacementRegion<'_> {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum ConstraintSatisfactionMode {
Initial,
Adjustment,
}

impl ConstraintSatisfactionMode {
const fn config(self) -> CostEstimationConfig {
match self {
Self::Initial => CostEstimationConfig::LOOP,
Self::Adjustment => CostEstimationConfig::TRIVIAL,
}
}
}

/// CSP solver for assigning targets within a cyclic placement region.
///
/// Borrows the parent [`PlacementSolver`] for cost estimation and target resolution.
Expand All @@ -124,6 +139,7 @@ pub(crate) struct ConstraintSatisfaction<'ctx, 'parent, 'alloc, A: Allocator, S:
pub region: CyclicPlacementRegion<'alloc>,

pub depth: usize,
pub mode: ConstraintSatisfactionMode,

// Branch-and-bound state (only used when members.len() <= BNB_CUTOFF)
cost_deltas: [ApproxCost; BNB_CUTOFF],
Expand All @@ -136,6 +152,7 @@ impl<'ctx, 'parent, 'alloc, A: Allocator, S: BumpAllocator>
/// Creates a new CSP solver for the given cyclic `region`.
pub(crate) const fn new(
solver: &'ctx mut PlacementSolver<'parent, 'alloc, A, S>,
mode: ConstraintSatisfactionMode,
id: PlacementRegionId,
region: CyclicPlacementRegion<'alloc>,
) -> Self {
Expand All @@ -144,6 +161,7 @@ impl<'ctx, 'parent, 'alloc, A: Allocator, S: BumpAllocator>
id,
region,
depth: 0,
mode,
cost_deltas: [ApproxCost::ZERO; BNB_CUTOFF],
cost_so_far: ApproxCost::ZERO,
}
Expand Down Expand Up @@ -332,7 +350,7 @@ impl<'ctx, 'parent, 'alloc, A: Allocator, S: BumpAllocator>

self.region.blocks.swap(self.depth, self.depth + offset);
let mut heap = CostEstimation {
config: CostEstimationConfig::LOOP,
config: self.mode.config(),
solver: self.solver,
determine_target: |block| {
if let Some(member) = self.region.find_block(block) {
Expand Down Expand Up @@ -373,7 +391,7 @@ impl<'ctx, 'parent, 'alloc, A: Allocator, S: BumpAllocator>
target: TargetId,
) -> ApproxCost {
let estimator = CostEstimation {
config: CostEstimationConfig::LOOP,
config: self.mode.config(),
solver: self.solver,
determine_target: |block| {
self.region.find_block(block).map_or_else(
Expand Down Expand Up @@ -520,7 +538,7 @@ impl<'ctx, 'parent, 'alloc, A: Allocator, S: BumpAllocator>
self.region.blocks.swap(self.depth, self.depth + offset);

let heap = CostEstimation {
config: CostEstimationConfig::LOOP,
config: self.mode.config(),
solver: self.solver,
determine_target: |block| {
if let Some(member) = self.region.find_block(block) {
Expand Down
Loading
Loading