ssm-lang / sslang

A language built atop the Sparse Synchronous Model
BSD 3-Clause "New" or "Revised" License
18 stars 0 forks source link

Optimize dup drop #123

Open gschare opened 2 years ago

EmilySillars commented 1 year ago

Greg Next Steps

EmilySillars commented 1 year ago

Greg Next Steps (Updated!)

@gschare follow up with a comment on this draft PR if you have any questions

I. Implement the following helper functions 1) fusePair :: I.Expr I.Type -> Maybe (I.Expr I.Type) Write a description of this elimination pattern including a small example. 2) eliminateConsumptionPat :: I.Expr I.Type -> Maybe (I.Expr I.Type) Write a description of this elimination pattern including a small example. 3) swapAppAndDrop :: I.Expr I.Type -> Maybe (I.Expr I.Type) Write a description of this transformation including a small example. 4) inExpr :: I.Expr -> I.Binder I.Type -> Bool Description: returns whether binder is present in IR sub tree. 5) moveDropInsideLet :: I.Expr I.Type -> Maybe (I.Expr I.Type) Use the inExpr function to Implement moveDropInsideLet. Write a description of this transformation including a small example.

If you are strapped on time, skip helper funcs #4 and #5.

II. Implement a pass over the IR that tries to apply each elimination or transformation on each node of the AST, and records how many times each elimination or transformation was successfully performed.

-- | Dup Drop Monad newtype DupDropFn a = DupDropFn (StateT DuprDropCtx Compiler.Pass a) deriving (Functor) via (StateT DuprDropCtx Compiler.Pass) deriving (Applicative) via (StateT DuprDropCtx Compiler.Pass) deriving (Monad) via (StateT DuprDropCtx Compiler.Pass) deriving (MonadFail) via (StateT DuprDropCtx Compiler.Pass) deriving (MonadError Compiler.Error) via (StateT DuprDropCtx Compiler.Pass) deriving (MonadState DuprDropCtx) via (StateT DuprDropCtx Compiler.Pass)


- Use [DContoFunc.hs](https://github.com/ssm-lang/sslang/blob/main/src/IR/DConToFunc.hs) as reference for how to use everywhereM

**III. Make sure this optimization pass passes all regressions tests and does not cause any memory errors (passes valgrind test, and SSLANG memory management test).** 
- unit tests not needed