From bf39604eff79347d64e4b07b555a88c332029221 Mon Sep 17 00:00:00 2001 From: Murad Bashirov Date: Mon, 2 Jan 2023 17:15:09 +0900 Subject: [PATCH] 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. --- bin/kecc.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/bin/kecc.rs b/bin/kecc.rs index ad0e8ec..3b313fa 100644 --- a/bin/kecc.rs +++ b/bin/kecc.rs @@ -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;