Skip to content

Commit ee22fac

Browse files
authored
BE-232: HashQL: Implement dataflow analysis framework with liveness analysis (#8168)
1 parent 29b970f commit ee22fac

File tree

34 files changed

+2657
-33
lines changed

34 files changed

+2657
-33
lines changed

libs/@local/hashql/compiletest/src/suite/mir_pass_analysis_data_dependency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hashql_diagnostics::DiagnosticIssues;
66
use hashql_mir::{
77
context::MirContext,
88
intern::Interner,
9-
pass::{Pass as _, analysis::DataDependencyAnalysis},
9+
pass::{AnalysisPass as _, analysis::DataDependencyAnalysis},
1010
};
1111

1212
use super::{RunContext, Suite, SuiteDiagnostic};

libs/@local/hashql/compiletest/src/suite/mir_pass_transform_cfg_simplify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use hashql_mir::{
1111
context::MirContext,
1212
def::{DefId, DefIdSlice, DefIdVec},
1313
intern::Interner,
14-
pass::{Pass as _, transform::CfgSimplify},
14+
pass::{TransformPass as _, transform::CfgSimplify},
1515
};
1616

1717
use super::{RunContext, Suite, SuiteDiagnostic, common::process_issues, mir_reify::mir_reify};

libs/@local/hashql/core/src/id/bit_vec/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,16 @@ impl<T: Id> MixedBitSet<T> {
12511251
}
12521252
}
12531253

1254+
#[inline]
1255+
#[must_use]
1256+
pub fn new_filled(domain_size: usize) -> Self {
1257+
if domain_size <= CHUNK_BITS {
1258+
Self::Small(DenseBitSet::new_filled(domain_size))
1259+
} else {
1260+
Self::Large(ChunkedBitSet::new_filled(domain_size))
1261+
}
1262+
}
1263+
12541264
#[inline]
12551265
#[must_use]
12561266
pub fn is_empty(&self) -> bool {

libs/@local/hashql/mir/src/body/terminator/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use self::{
1818
goto::Goto,
1919
graph::{GraphRead, GraphReadBody, GraphReadHead, GraphReadLocation, GraphReadTail},
2020
r#return::Return,
21-
switch_int::{SwitchIf, SwitchInt, SwitchTargets},
21+
switch_int::{SwitchIf, SwitchInt, SwitchIntValue, SwitchTargets},
2222
target::Target,
2323
};
2424
use super::basic_block::BasicBlockId;

libs/@local/hashql/mir/src/body/terminator/switch_int.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ pub struct SwitchIf<'heap> {
2626
pub r#else: Target<'heap>,
2727
}
2828

29+
/// Represents which branch of a [`SwitchInt`] terminator is being taken.
30+
///
31+
/// Used by dataflow analyses to apply edge-specific effects when propagating
32+
/// state through switch branches. See
33+
/// [`apply_switch_int_edge_effect`](crate::pass::analysis::dataflow::framework::DataflowAnalysis::apply_switch_int_edge_effect).
34+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
35+
pub enum SwitchIntValue {
36+
/// An explicit case with the given discriminant value.
37+
Direct(u128),
38+
39+
/// The default/otherwise branch for unmatched values.
40+
Otherwise,
41+
}
42+
2943
/// A mapping from integer discriminant values to control flow targets.
3044
///
3145
/// Maps integer discriminant values to [`Target`]s for multi-way control flow.

libs/@local/hashql/mir/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
int_roundings,
2121
iter_array_chunks,
2222
iter_collect_into,
23+
iter_intersperse,
24+
string_from_utf8_lossy_owned,
2325
try_trait_v2,
2426
)]
2527
#![expect(clippy::indexing_slicing)]

libs/@local/hashql/mir/src/pass/analysis/data_dependency/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::{
5454
},
5555
context::MirContext,
5656
intern::Interner,
57-
pass::Pass,
57+
pass::AnalysisPass,
5858
visit::Visitor,
5959
};
6060

@@ -427,8 +427,8 @@ impl Default for DataDependencyAnalysis<'_> {
427427
}
428428
}
429429

430-
impl<'env, 'heap, A: Allocator> Pass<'env, 'heap> for DataDependencyAnalysis<'heap, A> {
431-
fn run(&mut self, context: &mut MirContext<'env, 'heap>, body: &mut Body<'heap>) {
430+
impl<'env, 'heap, A: Allocator> AnalysisPass<'env, 'heap> for DataDependencyAnalysis<'heap, A> {
431+
fn run(&mut self, context: &mut MirContext<'env, 'heap>, body: &Body<'heap>) {
432432
self.graph.derive(&body.local_decls, |id, _| id);
433433

434434
let Ok(()) = DataDependencyAnalysisVisitor {

libs/@local/hashql/mir/src/pass/analysis/data_dependency/tests.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ use hashql_hir::node::operation::InputOp;
77
use insta::{Settings, assert_snapshot};
88

99
use super::DataDependencyAnalysis;
10-
use crate::{body::Body, context::MirContext, pass::Pass as _, scaffold};
10+
use crate::{body::Body, context::MirContext, pass::AnalysisPass as _, scaffold};
1111

1212
#[track_caller]
1313
fn assert_data_dependency<'heap>(
1414
name: &'static str,
15-
body: Body<'heap>,
15+
body: &Body<'heap>,
1616
context: &mut MirContext<'_, 'heap>,
1717
) {
18-
let mut body = body;
19-
2018
let mut analysis = DataDependencyAnalysis::new();
21-
analysis.run(context, &mut body);
19+
analysis.run(context, body);
2220
let graph = analysis.finish();
2321
let transient = graph.transient(context.interner);
2422

@@ -63,7 +61,7 @@ fn load_simple() {
6361

6462
assert_data_dependency(
6563
"load_simple",
66-
body,
64+
&body,
6765
&mut MirContext {
6866
heap: &heap,
6967
env: &env,
@@ -108,7 +106,7 @@ fn load_chain() {
108106

109107
assert_data_dependency(
110108
"load_chain",
111-
body,
109+
&body,
112110
&mut MirContext {
113111
heap: &heap,
114112
env: &env,
@@ -156,7 +154,7 @@ fn load_with_projection() {
156154

157155
assert_data_dependency(
158156
"load_with_projection",
159-
body,
157+
&body,
160158
&mut MirContext {
161159
heap: &heap,
162160
env: &env,
@@ -211,7 +209,7 @@ fn load_then_projection() {
211209

212210
assert_data_dependency(
213211
"load_then_projection",
214-
body,
212+
&body,
215213
&mut MirContext {
216214
heap: &heap,
217215
env: &env,

0 commit comments

Comments
 (0)