Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'f> PerFunctionContext<'f> {
// so that for example if the value is an array and contains a reference,
// then that reference gets to keep its last store.
let typ = self.inserter.function.dfg.type_of_value(value);
if Self::contains_references(&typ) {
if typ.contains_reference() {
if let Some(expression) = references.expressions.get(&value) {
if let Some(aliases) = references.aliases.get(expression) {
aliases.for_each(|alias| {
Expand Down Expand Up @@ -528,7 +528,7 @@ impl<'f> PerFunctionContext<'f> {

let array = *array;
let array_typ = self.inserter.function.dfg.type_of_value(array);
if Self::contains_references(&array_typ) {
if array_typ.contains_reference() {
references.for_each_alias_of(array, |_, alias| {
self.instruction_input_references.insert(alias);
});
Expand All @@ -545,7 +545,7 @@ impl<'f> PerFunctionContext<'f> {
references.mark_value_used(*array, self.inserter.function);
let element_type = self.inserter.function.dfg.type_of_value(*value);

if Self::contains_references(&element_type) {
if element_type.contains_reference() {
let result = self.inserter.function.dfg.instruction_results(instruction)[0];
let array = *array;

Expand Down Expand Up @@ -590,7 +590,7 @@ impl<'f> PerFunctionContext<'f> {
Instruction::MakeArray { elements, typ } => {
// If `array` is an array constant that contains reference types, then insert each element
// as a potential alias to the array itself.
if Self::contains_references(typ) {
if typ.contains_reference() {
let array = self.inserter.function.dfg.instruction_results(instruction)[0];

let expr = Expression::ArrayElement(Box::new(Expression::Other(array)));
Expand All @@ -604,7 +604,7 @@ impl<'f> PerFunctionContext<'f> {
let result = self.inserter.function.dfg.instruction_results(instruction)[0];
let result_type = self.inserter.function.dfg.type_of_value(result);

if Self::contains_references(&result_type) {
if result_type.contains_reference() {
let expr = Expression::Other(result);
references.expressions.insert(result, expr.clone());
references.aliases.insert(
Expand All @@ -629,17 +629,6 @@ impl<'f> PerFunctionContext<'f> {
}
}

fn contains_references(typ: &Type) -> bool {
match typ {
Type::Numeric(_) => false,
Type::Function => false,
Type::Reference(_) => true,
Type::Array(elements, _) | Type::Slice(elements) => {
elements.iter().any(Self::contains_references)
}
}
}

fn set_aliases(&self, references: &mut Block, address: ValueId, new_aliases: AliasSet) {
let expression =
references.expressions.entry(address).or_insert(Expression::Other(address));
Expand All @@ -650,7 +639,7 @@ impl<'f> PerFunctionContext<'f> {
fn mark_all_unknown(&self, values: &[ValueId], references: &mut Block) {
for value in values {
let typ = self.inserter.function.dfg.type_of_value(*value);
if Self::contains_references(&typ) {
if typ.contains_reference() {
let value = *value;
references.set_unknown(value);
references.mark_value_used(value, self.inserter.function);
Expand Down
Loading