Skip to content

Commit 25fef85

Browse files
authored
Merge pull request #29 from arnoox/pr-d/optimizer-infrastructure
feat: add optimizer infrastructure and post-lowering structural passes
2 parents 5cb6c33 + 91051e9 commit 25fef85

6 files changed

Lines changed: 1796 additions & 25 deletions

File tree

crates/herkos-core/src/optimizer/dead_blocks.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,11 @@
44
//! arise naturally during IR translation when code follows an `unreachable` or
55
//! `return` instruction inside a Wasm structured control flow construct.
66
7-
use crate::ir::{BlockId, IrBlock, IrFunction, IrTerminator};
7+
use super::utils::terminator_successors;
8+
use crate::ir::{BlockId, IrBlock, IrFunction};
89
use anyhow::{bail, Result};
910
use std::collections::{HashMap, HashSet};
1011

11-
/// Returns the successor block IDs for a terminator.
12-
fn terminator_successors(term: &IrTerminator) -> Vec<BlockId> {
13-
match term {
14-
IrTerminator::Return { .. } | IrTerminator::Unreachable => vec![],
15-
IrTerminator::Jump { target } => vec![*target],
16-
IrTerminator::BranchIf {
17-
if_true, if_false, ..
18-
} => vec![*if_true, *if_false],
19-
IrTerminator::BranchTable {
20-
targets, default, ..
21-
} => targets
22-
.iter()
23-
.chain(std::iter::once(default))
24-
.copied()
25-
.collect(),
26-
}
27-
}
28-
2912
/// Computes the set of block IDs reachable from the entry block via BFS.
3013
fn reachable_blocks(func: &IrFunction) -> Result<HashSet<BlockId>> {
3114
// Index blocks by ID for O(1) lookup during traversal.
@@ -61,7 +44,7 @@ pub fn eliminate(func: &mut IrFunction) -> Result<()> {
6144
#[cfg(test)]
6245
mod tests {
6346
use super::*;
64-
use crate::ir::{IrInstr, IrValue, TypeIdx, VarId, WasmType};
47+
use crate::ir::{IrInstr, IrTerminator, IrValue, TypeIdx, VarId, WasmType};
6548

6649
/// Build a minimal `IrFunction` with the given blocks.
6750
/// Entry block is always `BlockId(0)`.

0 commit comments

Comments
 (0)