Fix: Optimize before visualizing IR

When you do
```
cargo run -- --simplify-cfg --irviz test.png test.c
```
The `kecc` first tries to visualize the IR, then apply optimizations.
This should not be intended, as right now there's no way to visualize
the IR after optimizations.
This commit is contained in:
Murad Bashirov
2023-01-02 17:15:09 +09:00
parent 55ebcad347
commit bf39604eff

View File

@@ -141,6 +141,26 @@ fn compile_ir(
return;
}
if matches.optimize {
O1::default().optimize(input);
} else {
if matches.simplify_cfg {
SimplifyCfg::default().optimize(input);
}
if matches.mem2reg {
Mem2reg::default().optimize(input);
}
if matches.deadcode {
Deadcode::default().optimize(input);
}
if matches.gvn {
Gvn::default().optimize(input);
}
}
if let Some(path) = &matches.irviz {
assert_eq!(
Path::new(&path).extension(),
@@ -181,26 +201,6 @@ fn compile_ir(
temp_dir.close().expect("temp dir deletion failed");
}
if matches.optimize {
O1::default().optimize(input);
} else {
if matches.simplify_cfg {
SimplifyCfg::default().optimize(input);
}
if matches.mem2reg {
Mem2reg::default().optimize(input);
}
if matches.deadcode {
Deadcode::default().optimize(input);
}
if matches.gvn {
Gvn::default().optimize(input);
}
}
if matches.iroutput {
write(input, output).unwrap();
return;