From dc65e7c5a93cd581bed0b39ed93933e8988cfd26 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Thu, 2 Feb 2023 17:41:35 +0000 Subject: [PATCH] [aliasing] Make InferAliasForStores use the visitor infra No need for InferAliasForStores to know about the semantics of each instruction anymore. It's just a simple pass that iterates over every operand and lvalue. The FunctionExpression is special cased because it's slightly different but I have a follow up that removes this special casing. --- .../src/Inference/InferAliasForStores.ts | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/compiler/forget/src/Inference/InferAliasForStores.ts b/compiler/forget/src/Inference/InferAliasForStores.ts index b258303f81..c54448d556 100644 --- a/compiler/forget/src/Inference/InferAliasForStores.ts +++ b/compiler/forget/src/Inference/InferAliasForStores.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import DisjointSet from "../Utils/DisjointSet"; import { Effect, HIRFunction, @@ -12,6 +11,8 @@ import { InstructionId, Place, } from "../HIR/HIR"; +import { eachInstructionValueOperand } from "../HIR/visitors"; +import DisjointSet from "../Utils/DisjointSet"; export function inferAliasForStores( func: HIRFunction, @@ -24,28 +25,14 @@ export function inferAliasForStores( continue; } switch (value.kind) { - case "Identifier": { - maybeAlias(aliases, lvalue.place, value, instr.id); - break; - } - case "ArrayExpression": { - for (const item of value.elements) { - maybeAlias(aliases, lvalue.place, item, instr.id); - } - break; - } - case "ObjectExpression": { - if (value.properties !== null) { - for (const [, property] of value.properties) { - maybeAlias(aliases, lvalue.place, property, instr.id); - } - } - break; - } + case "Identifier": + case "ArrayExpression": + case "ObjectExpression": case "ComputedStore": case "PropertyStore": { - maybeAlias(aliases, lvalue.place, value.value, instr.id); - maybeAlias(aliases, lvalue.place, value.object, instr.id); + for (const operand of eachInstructionValueOperand(value)) { + maybeAlias(aliases, lvalue.place, operand, instr.id); + } break; } case "FunctionExpression": {