[ssa] Update lvalue based on whether it has a memberPath or not

The semantics of lvalue changes based on whether lvalue.place.memberPath is null 
or not. If it's null, then lvalue.place acts as the lvalue for the instruction, 
otherwise it's just a reference to the memberPath specified location. 

Ideally we'd have an MemberExpression IR that lowers this complex lvalue into a 
temporary Place, uses this temporary place and stores back to the 
MemberExpression. 

Working around for now, will refactor to create a MemberExpression in the future 
if necessary for other analysis.
This commit is contained in:
Sathya Gunasekaran
2022-10-27 14:11:23 +01:00
parent c8aaa7f172
commit de6afc2c52
2 changed files with 10 additions and 5 deletions
+6 -1
View File
@@ -174,7 +174,12 @@ export default function buildSSA(func: HIRFunction, env: Environment) {
if (instr.lvalue != null) {
const oldPlace = instr.lvalue.place;
const newPlace: Place = builder.definePlace(oldPlace);
let newPlace: Place;
if (oldPlace.memberPath !== null) {
newPlace = builder.getPlace(oldPlace);
} else {
newPlace = builder.definePlace(oldPlace);
}
instr.lvalue.place = newPlace;
}
}
@@ -17,8 +17,8 @@ function foo() {
bb0:
Const mutate x$3 = Array []
Const mutate y$4 = Object { }
Reassign mutate y$5.x = read x$3
Return freeze y$5
Reassign mutate y$4.x = read x$3
Return freeze y$4
```
## Code
@@ -27,8 +27,8 @@ bb0:
function foo$0() {
const x$3 = [];
const y$4 = {};
y$5 = x$3;
return y$5;
y$4 = x$3;
return y$4;
}
```