forked from noir-lang/noir
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fv): Add SSA pass which updates dfg's values
We now run a SSA pass which updates the values map. We do this because we found out that the value ids for instructions inside of fv attributes were not matching with their expected value. This was a bug but somehow it didn't cause us any problems until the implementation for indexing arrays of composite types. Now that it's fixed we removed the "hack" which was circumventing the issue inside of the `calculate_index` function.
- Loading branch information
1 parent
da99902
commit 5bef5b6
Showing
5 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
compiler/noirc_evaluator/src/ssa/opt/fv_opts/fix_value_map.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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::ssa::{ | ||
ir::{ | ||
dfg::DataFlowGraph, | ||
instruction::InstructionId, | ||
types::Type, | ||
value::{Value, ValueId}, | ||
}, | ||
ssa_gen::Ssa, | ||
}; | ||
|
||
impl Ssa { | ||
pub(crate) fn update_value_map(mut self) -> Self { | ||
let mut values_to_update: Vec<(Vec<ValueId>, Vec<Value>)> = Vec::new(); | ||
for (_, function) in &mut self.functions { | ||
values_to_update.clear(); | ||
|
||
for (fv_instruction_id, _) in function.dfg.get_fv_instructions_with_ids() { | ||
let values_ids = function.dfg.instruction_results(fv_instruction_id); | ||
|
||
let instr_as_values = transform_instruction_to_value( | ||
fv_instruction_id, | ||
values_ids.len(), | ||
&function.dfg, | ||
); | ||
|
||
values_to_update.push((values_ids.to_vec(), instr_as_values)); | ||
} | ||
|
||
for (values_ids, instructions) in values_to_update.iter() { | ||
values_ids.iter().zip(instructions.iter()).for_each(|(value_id, instruction)| { | ||
function.dfg.update_value_at_id(*value_id, instruction.clone()); | ||
}); | ||
} | ||
} | ||
self | ||
} | ||
} | ||
|
||
fn transform_instruction_to_value( | ||
instruction_id: InstructionId, | ||
number_of_return_values: usize, | ||
dfg: &DataFlowGraph, | ||
) -> Vec<Value> { | ||
let instruction_types: Vec<Type> = dfg | ||
.instruction_results(instruction_id) | ||
.iter() | ||
.map(|val_id| dfg[*val_id].get_type().clone()) | ||
.collect(); | ||
|
||
let mut instruction_as_values: Vec<Value> = Vec::new(); | ||
|
||
for i in 0..number_of_return_values { | ||
instruction_as_values.push(Value::Instruction { | ||
instruction: instruction_id, | ||
position: i, | ||
typ: instruction_types[i].clone(), | ||
}); | ||
} | ||
|
||
instruction_as_values | ||
} |
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,2 +1,2 @@ | ||
mod fv_inline_calls; | ||
// mod fix_value_map; | ||
mod fix_value_map; |
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