Update model solution.

- Stop calculating operands for & operators.
- Evaluate the lhs of compound operators only once.
- Add `side-effect.c` example.
This commit is contained in:
Jaewoo Kim
2025-04-07 11:03:18 +00:00
parent 7a95032d43
commit 32283f2ed1
26 changed files with 331 additions and 210 deletions

View File

@@ -2,7 +2,7 @@
fun i32 @main () {
init:
bid: b0
allocations:
allocations:
block b0:

View File

@@ -23,22 +23,15 @@ block b0:
%b0:i2:i32* = load %l1:i32**
%b0:i3:i32* = load %l1:i32**
%b0:i4:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i3:i32*)
%b0:i5:i32* = load %l1:i32**
%b0:i6:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i5:i32*)
%b0:i7:i32* = load %l1:i32**
%b0:i8:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i7:i32*)
%b0:i9:i32* = load %l1:i32**
%b0:i10:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i9:i32*)
%b0:i11:i32 = load %b0:i10:i32*
%b0:i12:i32 = add %b0:i11:i32 1:i32
%b0:i13:unit = store %b0:i12:i32 %b0:i6:i32*
%b0:i14:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i2:i32*)
%b0:i15:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i2:i32*)
%b0:i16:i32 = load %b0:i15:i32*
%b0:i17:i32 = add %b0:i16:i32 1:i32
%b0:i18:unit = store %b0:i17:i32 %b0:i14:i32*
%b0:i19:i32 = load %l0:i32*
%b0:i20:u1 = cmp eq %b0:i19:i32 3:i32
%b0:i21:i32 = typecast %b0:i20:u1 to i32
ret %b0:i21:i32
%b0:i5:i32 = load %b0:i4:i32*
%b0:i6:i32 = add %b0:i5:i32 1:i32
%b0:i7:unit = store %b0:i6:i32 %b0:i4:i32*
%b0:i8:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i2:i32*)
%b0:i9:i32 = load %b0:i8:i32*
%b0:i10:i32 = add %b0:i9:i32 1:i32
%b0:i11:unit = store %b0:i10:i32 %b0:i8:i32*
%b0:i12:i32 = load %l0:i32*
%b0:i13:u1 = cmp eq %b0:i12:i32 3:i32
%b0:i14:i32 = typecast %b0:i13:u1 to i32
ret %b0:i14:i32
}

View File

@@ -0,0 +1,29 @@
var i32 @g = 0
fun i32* @foo () {
init:
bid: b0
allocations:
block b0:
%b0:i0:i32 = load @g:i32*
%b0:i1:i32 = add %b0:i0:i32 10:i32
%b0:i2:unit = store %b0:i1:i32 @g:i32*
ret @g:i32*
}
fun i32 @main () {
init:
bid: b0
allocations:
block b0:
%b0:i0:i32* = call @foo:[ret:i32* params:()]*()
%b0:i1:i32 = load %b0:i0:i32*
%b0:i2:i32 = add %b0:i1:i32 1:i32
%b0:i3:unit = store %b0:i2:i32 %b0:i0:i32*
%b0:i4:i32 = load @g:i32*
ret %b0:i4:i32
}