Skip to content

Commit

Permalink
# This is a combination of 4 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

add assume test

# This is the commit message #2:

add assume depth notion

# This is the commit message egraphs-good#3:

top down assume list experiment

# This is the commit message egraphs-good#4:

finish writing crappy rules
  • Loading branch information
oflatt committed Feb 8, 2024
1 parent 3d2e95c commit c297900
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tree_assume/src/schedule.egg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(run-schedule
(repeat 6
(saturate assume)
(saturate always-run)
(saturate error-checking)
(run constant_fold)
))
(run constant_fold)))
6 changes: 6 additions & 0 deletions tree_assume/src/schema.egg
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
; The term is in a loop with `input` and `pred_output`.
; input pred_output
(InLoop Expr Expr)
(InFunc String Expr)
; Branch of the switch and the predicate
(InSwitch i64 Expr)
; If the predicate was true, and the predicate
(InIf bool Expr)
; Other assumptions are possible, but not supported yet.
; For example:
; A boolean predicate is true.
Expand All @@ -183,6 +188,7 @@
; Assume allows creating context-specific terms.
; e.g. (Assume (InLet (Const (Int 2))) (Arg)) is equal to (Const (Int 2))
(function Assume (Assumption Expr) Expr)
(function AssumeList (Assumption ListExpr) ListExpr)


; =================================
Expand Down
111 changes: 111 additions & 0 deletions tree_assume/src/utility/assume.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
; This file propogates assume nodes top-down from functions.
; It gives each program path a unique equality relation.
; This can be quite expensive, so be careful running these rules.

(ruleset assume)

(sort AssumeList)
; We collect multiple assumes into one AssumeMulti.
; These happen when there are nested `If` or `Switch` statements.
; When it gets to the bottom, we flatten it back out to multiple `Assume` nodes
; for the convenience of other analyses.
(function AssumeMulti (AssumeList Expr) Expr :unextractable)

(function AssumeCons (Assumption AssumeList) AssumeList :unextractable)
(function AssumeNil () AssumeList :unextractable)

; ################### start top-down assumptions

(rewrite
(Function name in_ty out_ty output)
(Function name in_ty out_ty
(AssumeMulti (AssumeCons (InFunction name) (AssumeNil))
output))
:ruleset assume)


; ################### operations
(rewrite (AssumeMulti asum (Bop op c1 c2))
(Bop op (AssumeMulti asum c1) (AssumeMulti asum c2))
:ruleset assume)
(rewrite (AssumeMulti assum (Uop op c1))
(Uop op (AssumeMulti assum c1))
:ruleset assume)
(rewrite (AssumeMulti assum (Get expr index))
(Get (AssumeMulti assum expr) index)
:ruleset assume)
(rewrite (AssumeMulti assum (Alloc expr ty))
(Alloc (AssumeMulti assum expr) ty)
:ruleset assume)
(rewrite (AssumeMulti assum (Call name expr))
(Call name (AssumeMulti assum expr))
:ruleset assume)

; ################### tuple operations
(rewrite (AssumeMulti assum (Single expr))
(Single (AssumeMulti assum expr))
:ruleset assume)
(rewrite (AssumeMulti assum (Concat order e1 e2))
(Concat order (AssumeMulti assum e1) (AssumeMulti assum e2))
:ruleset assume)

; #################### control flow

; assumptions, predicate, cases, current case
(function SwitchAssume (AssumeList Expr ExprList i64) ExprList :unextractable)

(rewrite (AssumeMulti assum (Switch pred cases))
(Switch (AssumeMulti assum pred)
(SwitchAssume assum
(AssumeMulti assum pred)
cases
0))
:ruleset assume)

(rewrite (SwitchAssume pred assum (Nil) current_case)
(AssumeMulti assum (Nil))
:ruleset assume)

(rewrite (SwitchAssume pred
assum
(Cons current rest)
current_case)
(Cons
(AssumeMulti
(AssumeCons (InSwitch current_case pred) assum)
current)
(SwitchAssume
pred
assum
rest
(+ current_case 1)))
:ruleset assume)

(rewrite (AssumeMulti assum (If pred then else))
(If (AssumeMulti assum pred)
(AssumeMulti
(Cons (InIf true (AssumeMulti assum pred)) assum) then)
(AssumeMulti
(Cons (InIf false (AssumeMulti assum pred)) assum) else))
:ruleset assume)

(rewrite (AssumeMulti assum (Let inputs body))
(Let
(AssumeMulti assum inputs)
(AssumeMulti
; new context, make a list with one assumption in it
(Cons (InLet (AssumeMulti assum inputs)) (Nil))
body))
:ruleset assume)


(rewrite (AssumeMulti assum (DoWhile inputs pred_outputs))
(DoWhile
(AssumeMulti assum inputs)
(AssumeMulti
(Cons (InLoop (AssumeMulti assum inputs) pred_outputs)
(Nil))
pred_outputs))
:ruleset assume)


0 comments on commit c297900

Please sign in to comment.