mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-23 18:21:38 +03:00
Add codegen to benchmarks
This commit is contained in:
parent
1ea7dad842
commit
f7dc194d79
@ -45,7 +45,8 @@ enum BenchMode {
|
|||||||
Inline,
|
Inline,
|
||||||
/// Benchmarks dead code elimination.
|
/// Benchmarks dead code elimination.
|
||||||
Dce,
|
Dce,
|
||||||
// TODO: Benchmark code generation
|
/// Benchmarks code generation.
|
||||||
|
Codegen,
|
||||||
/// Benchmarks all the above stages.
|
/// Benchmarks all the above stages.
|
||||||
Full,
|
Full,
|
||||||
}
|
}
|
||||||
@ -113,6 +114,7 @@ impl Sample {
|
|||||||
BenchMode::Flatten => self.bench_flattener(c),
|
BenchMode::Flatten => self.bench_flattener(c),
|
||||||
BenchMode::Inline => self.bench_inline(c),
|
BenchMode::Inline => self.bench_inline(c),
|
||||||
BenchMode::Dce => self.bench_dce(c),
|
BenchMode::Dce => self.bench_dce(c),
|
||||||
|
BenchMode::Codegen => self.bench_codegen(c),
|
||||||
BenchMode::Full => self.bench_full(c),
|
BenchMode::Full => self.bench_full(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,6 +276,33 @@ impl Sample {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bench_codegen(&self, c: &mut Criterion) {
|
||||||
|
self.bencher_after_parse(c, "inliner pass", |mut compiler| {
|
||||||
|
let symbol_table = compiler.symbol_table_pass().expect("failed to generate symbol table");
|
||||||
|
let (symbol_table, struct_graph, call_graph) = compiler
|
||||||
|
.type_checker_pass(symbol_table)
|
||||||
|
.expect("failed to run type check pass");
|
||||||
|
let symbol_table = compiler
|
||||||
|
.loop_unrolling_pass(symbol_table)
|
||||||
|
.expect("failed to run loop unrolling pass");
|
||||||
|
let assigner = compiler
|
||||||
|
.static_single_assignment_pass(&symbol_table)
|
||||||
|
.expect("failed to run ssa pass");
|
||||||
|
let assigner = compiler
|
||||||
|
.flattening_pass(&symbol_table, assigner)
|
||||||
|
.expect("failed to run flattener pass");
|
||||||
|
let _ = compiler
|
||||||
|
.function_inlining_pass(&call_graph, assigner)
|
||||||
|
.expect("failed to run inliner pass");
|
||||||
|
compiler.dead_code_elimination_pass().expect("failed to run dce pass");
|
||||||
|
let start = Instant::now();
|
||||||
|
let out = compiler.code_generation_pass(&symbol_table, &struct_graph, &call_graph);
|
||||||
|
let time = start.elapsed();
|
||||||
|
out.expect("failed to run codegen pass");
|
||||||
|
time
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn bench_full(&self, c: &mut Criterion) {
|
fn bench_full(&self, c: &mut Criterion) {
|
||||||
self.bencher(c, "full", |mut compiler| {
|
self.bencher(c, "full", |mut compiler| {
|
||||||
let (input, name) = self.data();
|
let (input, name) = self.data();
|
||||||
@ -282,7 +311,7 @@ impl Sample {
|
|||||||
.parse_program_from_string(input, name)
|
.parse_program_from_string(input, name)
|
||||||
.expect("Failed to parse program");
|
.expect("Failed to parse program");
|
||||||
let symbol_table = compiler.symbol_table_pass().expect("failed to generate symbol table");
|
let symbol_table = compiler.symbol_table_pass().expect("failed to generate symbol table");
|
||||||
let (symbol_table, _struct_graph, call_graph) = compiler
|
let (symbol_table, struct_graph, call_graph) = compiler
|
||||||
.type_checker_pass(symbol_table)
|
.type_checker_pass(symbol_table)
|
||||||
.expect("failed to run type check pass");
|
.expect("failed to run type check pass");
|
||||||
let symbol_table = compiler
|
let symbol_table = compiler
|
||||||
@ -298,6 +327,9 @@ impl Sample {
|
|||||||
.function_inlining_pass(&call_graph, assigner)
|
.function_inlining_pass(&call_graph, assigner)
|
||||||
.expect("failed to run function inlining pass");
|
.expect("failed to run function inlining pass");
|
||||||
compiler.dead_code_elimination_pass().expect("failed to run dce pass");
|
compiler.dead_code_elimination_pass().expect("failed to run dce pass");
|
||||||
|
compiler
|
||||||
|
.code_generation_pass(&symbol_table, &struct_graph, &call_graph)
|
||||||
|
.expect("failed to run codegen pass");
|
||||||
start.elapsed()
|
start.elapsed()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -319,6 +351,7 @@ bench!(bench_ssa, BenchMode::Ssa);
|
|||||||
bench!(bench_flatten, BenchMode::Flatten);
|
bench!(bench_flatten, BenchMode::Flatten);
|
||||||
bench!(bench_inline, BenchMode::Inline);
|
bench!(bench_inline, BenchMode::Inline);
|
||||||
bench!(bench_dce, BenchMode::Dce);
|
bench!(bench_dce, BenchMode::Dce);
|
||||||
|
bench!(bench_codegen, BenchMode::Codegen);
|
||||||
bench!(bench_full, BenchMode::Full);
|
bench!(bench_full, BenchMode::Full);
|
||||||
|
|
||||||
criterion_group!(
|
criterion_group!(
|
||||||
@ -333,6 +366,7 @@ criterion_group!(
|
|||||||
bench_flatten,
|
bench_flatten,
|
||||||
bench_inline,
|
bench_inline,
|
||||||
bench_dce,
|
bench_dce,
|
||||||
|
bench_codegen,
|
||||||
bench_full
|
bench_full
|
||||||
);
|
);
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
@ -312,7 +312,7 @@ pub fn run_tests<T: Runner>(runner: &T, expectation_category: &str) {
|
|||||||
pub fn get_benches() -> Vec<(String, String)> {
|
pub fn get_benches() -> Vec<(String, String)> {
|
||||||
let (mut cases, configs) = TestCases::new("compiler", |config| {
|
let (mut cases, configs) = TestCases::new("compiler", |config| {
|
||||||
(&config.namespace == "Bench" && config.expectation == TestExpectationMode::Pass)
|
(&config.namespace == "Bench" && config.expectation == TestExpectationMode::Pass)
|
||||||
|| (&config.namespace == "Compile"
|
|| ((&config.namespace == "Compile" || &config.namespace == "Execute")
|
||||||
&& !matches!(
|
&& !matches!(
|
||||||
config.expectation,
|
config.expectation,
|
||||||
TestExpectationMode::Fail | TestExpectationMode::Skip
|
TestExpectationMode::Fail | TestExpectationMode::Skip
|
||||||
|
Loading…
Reference in New Issue
Block a user