feat: add basic block reordering pass and improve codegen naming

- Implement `reorder_blocks` (BBR) pass using DFS to maximize
fallthroughs.
- Update x86_64 backend to use actual function names in call
instructions instead of generic IDs.
- Replace the GCD test case in main with an iterative factorial test
module.
- Remove redundant validation check at the end of the optimization
pipeline.
This commit is contained in:
2026-04-27 10:56:47 +02:00
parent 9d94e3b81b
commit 5b8a0cb398
5 changed files with 174 additions and 90 deletions
+10 -5
View File
@@ -540,10 +540,7 @@ impl<'a> X86Backend<'a> {
}
}
Instruction::Call {
dest,
func: target_id,
args,
..
dest, func, args, ..
} => {
let arg_regs = ["rdi", "rsi", "rdx", "rcx", "r8", "r9"];
for (i, (_, arg_op)) in args.iter().enumerate() {
@@ -559,7 +556,15 @@ impl<'a> X86Backend<'a> {
}
}
}
writeln!(&mut self.assembly, " call function_{}", target_id.0).unwrap();
let function_name = self
.module
.functions
.iter()
.find_map(|f| (f.id == *func).then(|| f.name.clone()))
.unwrap();
writeln!(&mut self.assembly, " call {}", function_name).unwrap();
if args.len() > 6 {
let cleanup_size = (args.len() - 6) * 8;
writeln!(&mut self.assembly, " addq ${}, %rsp", cleanup_size).unwrap();