-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #727 from egraphs-good/mem-simple
- Loading branch information
Showing
29 changed files
with
925 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
(ruleset mem-simple) | ||
|
||
; ============================ | ||
; NoAlias analysis | ||
; ============================ | ||
|
||
(relation NoAlias (Expr Expr)) | ||
|
||
(rule ((Bop (PtrAdd) e i) | ||
(= (lo-bound i) (IntB lo)) | ||
(> lo 0)) | ||
((NoAlias e (Bop (PtrAdd) e i))) | ||
:ruleset mem-simple) | ||
|
||
(rule ((Bop (PtrAdd) e i) | ||
(= (hi-bound i) (IntB hi)) | ||
(< hi 0)) | ||
((NoAlias e (Bop (PtrAdd) e i))) | ||
:ruleset mem-simple) | ||
|
||
(rule ((= p1 (Bop (PtrAdd) p i)) | ||
(= p2 (Bop (PtrAdd) p (Bop (Add) i diff))) | ||
(= (lo-bound diff) (IntB lo)) | ||
(> lo 0)) | ||
((NoAlias p1 p2)) | ||
:ruleset mem-simple) | ||
|
||
(rule ((= p1 (Bop (PtrAdd) p i)) | ||
(= p2 (Bop (PtrAdd) p (Bop (Add) i diff))) | ||
(= (hi-bound diff) (IntB hi)) | ||
(< hi 0)) | ||
((NoAlias p1 p2)) | ||
:ruleset mem-simple) | ||
|
||
(rule ((= p1 (Bop (PtrAdd) p i)) | ||
(= p2 (Bop (PtrAdd) p (Bop (Sub) i diff))) | ||
(= (lo-bound diff) (IntB lo)) | ||
(> lo 0)) | ||
((NoAlias p1 p2)) | ||
:ruleset mem-simple) | ||
|
||
(rule ((= p1 (Bop (PtrAdd) p i)) | ||
(= p2 (Bop (PtrAdd) p (Bop (Sub) i diff))) | ||
(= (hi-bound diff) (IntB hi)) | ||
(< hi 0)) | ||
((NoAlias p1 p2)) | ||
:ruleset mem-simple) | ||
|
||
(rule ((NoAlias x y)) | ||
((NoAlias y x)) | ||
:ruleset mem-simple) | ||
|
||
; ============================ | ||
; Memory optimizations | ||
; ============================ | ||
|
||
(relation DidMemOptimization (String)) | ||
|
||
; A write then a load to different addresses can be swapped | ||
(rule ((NoAlias write-addr load-addr) | ||
(= write (Top (Write) write-addr write-val state)) | ||
(= load (Bop (Load) load-addr write))) | ||
((let new-load (Bop (Load) load-addr state)) | ||
(union | ||
(Get load 1) | ||
(Top (Write) write-addr write-val (Get new-load 1))) | ||
(union (Get load 0) (Get new-load 0)) | ||
(DidMemOptimization "commute write then load") | ||
) | ||
:ruleset mem-simple) | ||
|
||
; A load then a write to different addresses can be swapped | ||
; Actually, does this break WeaklyLinear if the stored value depends on the | ||
; loaded value? Commenting this out for now. | ||
; (rule ((NoAlias load-addr write-addr) | ||
; (= load (Bop (Load) load-addr state)) | ||
; (= write (Top (Write) write-addr write-val (Get load 1)))) | ||
; ((let new-write (Top (Write) write-addr write-val state)) | ||
; (let new-load (Bop (Load) load-addr new-write)) | ||
; (union write (Get new-load 1)) | ||
; (union (Get load 0) (Get new-load 0)) | ||
; (DidMemOptimization "commute load then write") | ||
; ) | ||
; :ruleset mem-simple) | ||
|
||
; Two loads to the same address can be compressed | ||
(rule ((= first-load (Bop (Load) addr state)) | ||
(= second-load (Bop (Load) addr first-load))) | ||
((union (Get first-load 0) (Get second-load 0)) | ||
(union (Get first-load 1) (Get second-load 1)) | ||
(DidMemOptimization "duplicate load") | ||
) | ||
:ruleset mem-simple) | ||
|
||
; A write and a load to the same address can be forwarded | ||
(rule ((= write (Top (Write) addr write-val state)) | ||
(= load (Bop (Load) addr write))) | ||
((union (Get load 0) write-val) | ||
(union (Get load 1) write) | ||
(DidMemOptimization "store forward") | ||
) | ||
:ruleset mem-simple) | ||
|
||
; Two writes of the same value to the same address can be compressed | ||
(rule ((= first-write (Top (Write) addr write-val state)) | ||
(= second-write (Top (Write) addr write-val first-write))) | ||
((union first-write second-write) | ||
(DidMemOptimization "duplicate write")) | ||
:ruleset mem-simple) | ||
|
||
; A write shadows a previous write to the same address | ||
(rule ((= first-write (Top (Write) addr shadowed-val state)) | ||
(= second-write (Top (Write) addr write-val first-write))) | ||
((union second-write (Top (Write) addr write-val state)) | ||
(DidMemOptimization "shadowed write")) | ||
:ruleset mem-simple) | ||
|
||
; A load doesn't change the state | ||
; TODO: why does this break weaklylinear? | ||
; (rule ((= load (Bop (Load) addr state))) | ||
; ((union (Get load 1) state)) | ||
; :ruleset mem-simple) | ||
|
||
; (rule ((DidMemOptimization _)) | ||
; ((panic "DidMemOptimization")) | ||
; :ruleset mem-simple) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,4 +107,4 @@ | |
((subsume (If a b c d))) | ||
:ruleset subsume-after-helpers) | ||
|
||
|
||
(ruleset add-to-debug-expr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# ARGS: 100000 | ||
|
||
@main(halfinput : int) { | ||
two: int = const 2; | ||
input: int = mul halfinput two; | ||
zero: int = const 0; | ||
one: int = const 1; | ||
vals: ptr<int> = alloc input; | ||
store vals zero; | ||
vals_1: ptr<int> = ptradd vals one; | ||
store vals_1 one; | ||
i: int = const 2; | ||
.loop: | ||
cond: bool = lt i input; | ||
br cond .body .done; | ||
.body: | ||
neg_one: int = const -1; | ||
one: int = const 1; | ||
two: int = const 2; | ||
|
||
vals_i: ptr<int> = ptradd vals i; | ||
vals_i_minus_one: ptr<int> = ptradd vals_i neg_one; | ||
tmp: int = load vals_i_minus_one; | ||
tmp: int = add tmp one; | ||
store vals_i tmp; | ||
i: int = add i one; | ||
|
||
vals_i: ptr<int> = ptradd vals i; | ||
vals_i_minus_one: ptr<int> = ptradd vals_i neg_one; | ||
tmp: int = load vals_i_minus_one; | ||
tmp: int = add tmp one; | ||
store vals_i tmp; | ||
i: int = add i one; | ||
jmp .loop; | ||
.done: | ||
last_plus_one: ptr<int> = ptradd vals i; | ||
neg_one: int = const -1; | ||
last: ptr<int> = ptradd last_plus_one neg_one; | ||
tmp: int = load last; | ||
free vals; | ||
print tmp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# ARGS: 100000 | ||
|
||
@main(input : int) { | ||
zero: int = const 0; | ||
one: int = const 1; | ||
vals: ptr<int> = alloc input; | ||
store vals zero; | ||
vals_i: ptr<int> = ptradd vals one; | ||
store vals_i one; | ||
i: int = const 2; | ||
.loop: | ||
cond: bool = lt i input; | ||
br cond .body .done; | ||
.body: | ||
neg_one: int = const -1; | ||
neg_two: int = const -2; | ||
vals_i: ptr<int> = ptradd vals i; | ||
vals_i_minus_one: ptr<int> = ptradd vals_i neg_one; | ||
vals_i_minus_two: ptr<int> = ptradd vals_i neg_two; | ||
tmp: int = load vals_i_minus_one; | ||
tmp2: int = load vals_i_minus_two; | ||
tmp: int = add tmp tmp2; | ||
store vals_i tmp; | ||
i: int = add i one; | ||
cond: bool = lt i input; | ||
br cond .body2 .done; | ||
.body2: | ||
neg_one: int = const -1; | ||
neg_two: int = const -2; | ||
vals_i: ptr<int> = ptradd vals i; | ||
vals_i_minus_one: ptr<int> = ptradd vals_i neg_one; | ||
vals_i_minus_two: ptr<int> = ptradd vals_i neg_two; | ||
tmp: int = load vals_i_minus_one; | ||
tmp2: int = load vals_i_minus_two; | ||
tmp: int = add tmp tmp2; | ||
store vals_i tmp; | ||
i: int = add i one; | ||
jmp .loop; | ||
.done: | ||
last_plus_one: ptr<int> = ptradd vals i; | ||
neg_one_: int = const -1; | ||
last: ptr<int> = ptradd last_plus_one neg_one_; | ||
tmp: int = load last; | ||
free vals; | ||
print tmp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ARGS: 100000 | ||
|
||
@main(input : int) { | ||
zero: int = const 0; | ||
one: int = const 1; | ||
vals: ptr<int> = alloc input; | ||
store vals zero; | ||
vals_i: ptr<int> = ptradd vals one; | ||
store vals_i one; | ||
i: int = const 2; | ||
.loop: | ||
cond: bool = lt i input; | ||
br cond .body .done; | ||
.body: | ||
neg_one: int = const -1; | ||
neg_two: int = const -2; | ||
vals_i: ptr<int> = ptradd vals i; | ||
vals_i_minus_one: ptr<int> = ptradd vals_i neg_one; | ||
vals_i_minus_two: ptr<int> = ptradd vals_i neg_two; | ||
tmp: int = load vals_i_minus_one; | ||
tmp2: int = load vals_i_minus_two; | ||
tmp: int = add tmp tmp2; | ||
store vals_i tmp; | ||
i: int = add i one; | ||
jmp .loop; | ||
.done: | ||
last_plus_one: ptr<int> = ptradd vals i; | ||
neg_one_: int = const -1; | ||
last: ptr<int> = ptradd last_plus_one neg_one_; | ||
tmp: int = load last; | ||
free vals; | ||
print tmp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.