@samitouri / QOS-React-2 / commits / dc65e7c5a9

[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.

Sathya Gunasekaran committed Feb 2, 2023 at 17:41 UTC dc65e7c5a93cd581bed0b39ed93933e8988cfd26
1 file changed +8 -21
compiler/forget/src/Inference/InferAliasForStores.ts
+8 -21
@@ -4,7 +4,6 @@
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7 -import DisjointSet from "../Utils/DisjointSet";
7 import {
8 Effect,
9 HIRFunction,
@@ -12,6 +11,8 @@ import {
11 InstructionId,
12 Place,
13 } from "../HIR/HIR";
14 +import { eachInstructionValueOperand } from "../HIR/visitors";
15 +import DisjointSet from "../Utils/DisjointSet";
16
17 export function inferAliasForStores(
18 func: HIRFunction,
@@ -24,28 +25,14 @@ export function inferAliasForStores(
25 continue;
26 }
27 switch (value.kind) {
27 - case "Identifier": {
28 - maybeAlias(aliases, lvalue.place, value, instr.id);
29 - break;
30 - }
31 - case "ArrayExpression": {
32 - for (const item of value.elements) {
33 - maybeAlias(aliases, lvalue.place, item, instr.id);
34 - }
35 - break;
36 - }
37 - case "ObjectExpression": {
38 - if (value.properties !== null) {
39 - for (const [, property] of value.properties) {
40 - maybeAlias(aliases, lvalue.place, property, instr.id);
41 - }
42 - }
43 - break;
44 - }
28 + case "Identifier":
29 + case "ArrayExpression":
30 + case "ObjectExpression":
31 case "ComputedStore":
32 case "PropertyStore": {
47 - maybeAlias(aliases, lvalue.place, value.value, instr.id);
48 - maybeAlias(aliases, lvalue.place, value.object, instr.id);
33 + for (const operand of eachInstructionValueOperand(value)) {
34 + maybeAlias(aliases, lvalue.place, operand, instr.id);
35 + }
36 break;
37 }
38 case "FunctionExpression": {