-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca9cf03
commit a78aeac
Showing
5 changed files
with
83 additions
and
22 deletions.
There are no files selected for viewing
35 changes: 30 additions & 5 deletions
35
compilers/rustyc/optimizer/src/ir_optimizer/pass/gvn/debugger.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
use super::GVNPass; | ||
use crate::ir::function::Function; | ||
use crate::ir::instructions::Instruction; | ||
use crate::ir_optimizer::pass::DebuggerPass; | ||
use crate::ir_optimizer::print_table_helper::{get_max_block_id_len, print_divider, print_header}; | ||
use std::collections::HashMap; | ||
|
||
impl<'a> DebuggerPass for GVNPass<'a> { | ||
fn debugger(&self, _function: &Function) -> String { | ||
let mut output = String::new(); | ||
output.push_str("Remove Inst:\n"); | ||
fn debugger(&self, function: &Function) -> String { | ||
let mut output_string = String::new(); | ||
// get inst len | ||
let inst_map_string: &HashMap<Instruction, String> = &self.cache_inst_strings; | ||
let mut max_len_of_insts = 0 as usize; | ||
for string in &inst_map_string.values().collect::<Vec<_>>() { | ||
if max_len_of_insts < string.len() { | ||
max_len_of_insts = string.len(); | ||
} | ||
} | ||
|
||
let max_block_len = get_max_block_id_len(function); | ||
let row_len = max_len_of_insts + max_block_len + "block ".len() + 2; | ||
output_string.push_str(&print_divider(row_len)); | ||
output_string.push_str(&print_header("GVN Table", row_len)); | ||
output_string.push_str(&print_divider(row_len)); | ||
for (block_id, inst) in &self.need_remove_insts { | ||
output.push_str(format!("block {}: {}\n", block_id.0, inst.0).as_str()); | ||
output_string.push_str(&print_header( | ||
format!( | ||
"block {}: {}", | ||
block_id.0, | ||
inst_map_string.get(inst).unwrap() | ||
) | ||
.as_str(), | ||
row_len, | ||
)); | ||
} | ||
output | ||
output_string.push_str(&print_divider(row_len)); | ||
output_string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
compilers/rustyc/optimizer/tests/fixtures/ir_optimizer/gvn/conrnell_example/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|--------------------------------------| | ||
| GVN Table | | ||
|--------------------------------------| | ||
| block 2: t11 = add t3 t4 | | ||
| block 2: t12 = add t3 t4 | | ||
| block 3: t13 = add t1 t2 | | ||
| block 3: t14 = add t5 t6 | | ||
| block 3: t15 = add t5 t6 | | ||
|block 4: phi t16, block2 t7, block3 t7| | ||
|block 4: phi t18, block2 t8, block3 t9| | ||
| block 4: t20 = add t1 t2 | | ||
|--------------------------------------| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters