-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional Push In #713
Merged
Merged
Conditional Push In #713
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
161 changes: 161 additions & 0 deletions
161
dag_in_context/src/optimizations/conditional_push_in.egg
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,161 @@ | ||
(ruleset push-in) | ||
|
||
; new version of the rule where one side of bop is constant | ||
(rule ( | ||
(= if_e (If pred orig_inputs thn els)) | ||
(ContextOf if_e outer_ctx) | ||
(= (Bop o (Const c ty outer_ctx) x) (Get orig_inputs i)) | ||
(HasArgType thn (TupleT tylist)) | ||
(HasArgType els (TupleT tylist)) | ||
(HasType x (Base x_ty)) | ||
) | ||
( | ||
; New inputs | ||
(let new_ins (Concat orig_inputs (Single x))) | ||
(let new_ins_ty (TupleT (TLConcat tylist (TCons x_ty (TNil))))) | ||
|
||
; New contexts | ||
(let if_tr (InIf true pred new_ins)) | ||
(let if_fa (InIf false pred new_ins)) | ||
|
||
; New args | ||
(let arg_tr (Arg new_ins_ty if_tr)) | ||
(let arg_fa (Arg new_ins_ty if_fa)) | ||
|
||
; SubTuple | ||
(let orig_ins_len (TypeList-length tylist)) | ||
(let st_tr (SubTuple arg_tr 0 orig_ins_len)) | ||
(let st_fa (SubTuple arg_fa 0 orig_ins_len)) | ||
|
||
; New regions | ||
(let new_thn (Subst if_tr st_tr thn)) | ||
(let new_els (Subst if_fa st_fa els)) | ||
|
||
; Union the original input with Bop(c, x) in the new regions | ||
(union (Get arg_tr i) (Bop o (Const c new_ins_ty if_tr) (Get arg_tr orig_ins_len))) | ||
(union (Get arg_fa i) (Bop o (Const c new_ins_ty if_fa) (Get arg_fa orig_ins_len))) | ||
|
||
; Union the ifs | ||
(union if_e (If pred new_ins new_thn new_els)) | ||
) | ||
:ruleset push-in) | ||
|
||
(rule ( | ||
(= if_e (If pred orig_inputs thn els)) | ||
(ContextOf if_e outer_ctx) | ||
(= (Bop o x (Const c ty outer_ctx)) (Get orig_inputs i)) | ||
(HasArgType thn (TupleT tylist)) | ||
(HasArgType els (TupleT tylist)) | ||
(HasType x (Base x_ty)) | ||
) | ||
( | ||
; New inputs | ||
(let new_ins (Concat orig_inputs (Single x))) | ||
(let new_ins_ty (TupleT (TLConcat tylist (TCons x_ty (TNil))))) | ||
|
||
; New contexts | ||
(let if_tr (InIf true pred new_ins)) | ||
(let if_fa (InIf false pred new_ins)) | ||
|
||
; New args | ||
(let arg_tr (Arg new_ins_ty if_tr)) | ||
(let arg_fa (Arg new_ins_ty if_fa)) | ||
|
||
; SubTuple | ||
(let orig_ins_len (TypeList-length tylist)) | ||
(let st_tr (SubTuple arg_tr 0 orig_ins_len)) | ||
(let st_fa (SubTuple arg_fa 0 orig_ins_len)) | ||
|
||
; New regions | ||
(let new_thn (Subst if_tr st_tr thn)) | ||
(let new_els (Subst if_fa st_fa els)) | ||
|
||
; Union the original input with Bop(x, c) in the new regions | ||
(union (Get arg_tr i) (Bop o (Get arg_tr orig_ins_len) (Const c new_ins_ty if_tr))) | ||
(union (Get arg_fa i) (Bop o (Get arg_fa orig_ins_len) (Const c new_ins_ty if_fa))) | ||
|
||
; Union the ifs | ||
(union if_e (If pred new_ins new_thn new_els)) | ||
) | ||
:ruleset push-in) | ||
|
||
(rule ( | ||
(= if_e (If pred orig_inputs thn els)) | ||
(ContextOf if_e outer_ctx) | ||
(= (Uop o x) (Get orig_inputs i)) | ||
(HasArgType thn (TupleT tylist)) | ||
(HasArgType els (TupleT tylist)) | ||
(HasType x (Base x_ty)) | ||
) | ||
( | ||
; New inputs | ||
(let new_ins (Concat orig_inputs (Single x))) | ||
(let new_ins_ty (TupleT (TLConcat tylist (TCons x_ty (TNil))))) | ||
|
||
; New contexts | ||
(let if_tr (InIf true pred new_ins)) | ||
(let if_fa (InIf false pred new_ins)) | ||
|
||
; New args | ||
(let arg_tr (Arg new_ins_ty if_tr)) | ||
(let arg_fa (Arg new_ins_ty if_fa)) | ||
|
||
; SubTuple | ||
(let orig_ins_len (TypeList-length tylist)) | ||
(let st_tr (SubTuple arg_tr 0 orig_ins_len)) | ||
(let st_fa (SubTuple arg_fa 0 orig_ins_len)) | ||
|
||
; New regions | ||
(let new_thn (Subst if_tr st_tr thn)) | ||
(let new_els (Subst if_fa st_fa els)) | ||
|
||
; Union the original input with Uop(x) in the new regions | ||
(union (Get arg_tr i) (Uop o (Get arg_tr orig_ins_len))) | ||
(union (Get arg_fa i) (Uop o (Get arg_fa orig_ins_len))) | ||
|
||
; Union the ifs | ||
(union if_e (If pred new_ins new_thn new_els)) | ||
) | ||
:ruleset push-in) | ||
|
||
; OLD VERSION - Too slow for now | ||
; ; push bop input into region | ||
; (rule ( | ||
; (= if_e (If pred orig_inputs thn els)) | ||
; (ContextOf if_e outer_ctx) | ||
; (= (Bop o x y) (Get orig_inputs i)) | ||
; (HasArgType thn (TupleT tylist)) | ||
; (HasArgType els (TupleT tylist)) | ||
; (HasType x (Base x_ty)) | ||
; (HasType y (Base y_ty)) | ||
; ) | ||
; ( | ||
; ; New inputs | ||
; (let new_ins (Concat orig_inputs (Concat (Single x) (Single y)))) | ||
; (let new_ins_ty (TupleT (TLConcat tylist (TCons x_ty (TCons y_ty (TNil)))))) | ||
|
||
; ; New contexts | ||
; (let if_tr (InIf true pred new_ins)) | ||
; (let if_fa (InIf false pred new_ins)) | ||
|
||
; ; New args | ||
; (let arg_tr (Arg new_ins_ty if_tr)) | ||
; (let arg_fa (Arg new_ins_ty if_fa)) | ||
|
||
; ; SubTuple | ||
; (let orig_ins_len (TypeList-length tylist)) | ||
; (let st_tr (SubTuple arg_tr 0 orig_ins_len)) | ||
; (let st_fa (SubTuple arg_fa 0 orig_ins_len)) | ||
|
||
; ; New regions | ||
; (let new_thn (Subst if_tr st_tr thn)) | ||
; (let new_els (Subst if_fa st_fa els)) | ||
|
||
; ; Union the original input with Bop(x, y) in the new regions | ||
; (union (Get arg_tr i) (Bop o (Get arg_tr orig_ins_len) (Get arg_tr (+ orig_ins_len 1)))) | ||
; (union (Get arg_fa i) (Bop o (Get arg_fa orig_ins_len) (Get arg_fa (+ orig_ins_len 1)))) | ||
|
||
; ; Union the ifs | ||
; (union if_e (If pred new_ins new_thn new_els)) | ||
; ) | ||
; :ruleset push-in) |
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,17 @@ | ||
// ARGS: 20 | ||
fn main(input: i64) { | ||
let a: i64 = input * 2; | ||
if (input > 0) { | ||
let x: i64 = a * 5; | ||
} else { | ||
let x: i64 = a * -3; | ||
} | ||
|
||
if (x >= 0) { | ||
let res: i64 = x * 10; | ||
} else { | ||
let res: i64 = x * 37; | ||
} | ||
|
||
println!("{}", res); | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't interval analysis handle pushing constants in already?