Skip to content

Commit 255c5ab

Browse files
authored
Merge pull request #164 from Tcode-Motion/bolt-builder-pred-opt-6542923888462175577
⚡ Bolt: O(N) block predecessor mapping optimization
2 parents 5e2ca46 + fd9e01b commit 255c5ab

3 files changed

Lines changed: 102 additions & 2 deletions

File tree

‎Cargo.lock‎

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎compiler/ir/Cargo.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ serde = { workspace = true }
1616
techscript_lexer = { path = "../lexer" }
1717
techscript_parser = { path = "../parser" }
1818
techscript_semantic = { path = "../semantic" }
19+
criterion = "0.5"
20+
21+
[[bench]]
22+
name = "builder_bench"
23+
harness = false
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use techscript_ir::builder::IRBuilder;
3+
use techscript_ir::types::IRType;
4+
5+
fn criterion_benchmark(c: &mut Criterion) {
6+
c.bench_function("seal_function 10000 blocks", |b| {
7+
b.iter(|| {
8+
let mut builder = IRBuilder::new();
9+
builder.start_function("bench_func".to_string(), IRType::Void);
10+
11+
let num_blocks = 10000;
12+
let mut blocks = vec![];
13+
for i in 0..num_blocks {
14+
let block_id = builder.new_block(format!("block_{}", i));
15+
blocks.push(block_id);
16+
}
17+
18+
for i in 0..(num_blocks - 1) {
19+
builder.enter_block(blocks[i], format!("block_{}", i));
20+
builder.emit_terminator(
21+
techscript_ir::instruction::TerminatorKind::Jump(blocks[i + 1]),
22+
techscript_common::Span { start: 0, end: 0 },
23+
);
24+
}
25+
26+
builder.enter_block(blocks[num_blocks - 1], format!("block_{}", num_blocks - 1));
27+
builder.emit_terminator(
28+
techscript_ir::instruction::TerminatorKind::Return(None),
29+
techscript_common::Span { start: 0, end: 0 },
30+
);
31+
32+
builder.seal_function();
33+
});
34+
});
35+
}
36+
37+
criterion_group!(benches, criterion_benchmark);
38+
criterion_main!(benches);

0 commit comments

Comments
 (0)