X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FNormalize.hs;h=6a4825d42406343c5b6eb94191fdaf5b4ed554e0;hb=7d60f355a116d10adef0a66370d8bfa6a859e8b2;hp=dd8244d4d7d4be4d1e90d9a1c78d7f70fb925c09;hpb=40f6fa36c61009396934942a580be62d8cc58da2;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Normalize.hs" "b/c\316\273ash/CLasH/Normalize.hs" index dd8244d..6a4825d 100644 --- "a/c\316\273ash/CLasH/Normalize.hs" +++ "b/c\316\273ash/CLasH/Normalize.hs" @@ -146,6 +146,9 @@ letderectop = everywhere ("letderec", letderec) -- let simplification -------------------------------- letsimpl, letsimpltop :: Transform +-- Don't simplify a let that evaluates to another let, since this is already +-- normal form (and would cause infinite loops with letflat below). +letsimpl expr@(Let _ (Let _ _)) = return expr -- Put the "in ..." value of a let in its own binding, but not when the -- expression is already a local variable, or not representable (to prevent loops with inlinenonrep). letsimpl expr@(Let binds res) = do @@ -169,23 +172,14 @@ letsimpltop = everywhere ("letsimpl", letsimpl) -------------------------------- -- let flattening -------------------------------- +-- Takes a let that binds another let, and turns that into two nested lets. +-- e.g., from: +-- let b = (let b' = expr' in res') in res +-- to: +-- let b' = expr' in (let b = res' in res) letflat, letflattop :: Transform -letflat (Let (Rec binds) expr) = do - -- Turn each binding into a list of bindings (possibly containing just one - -- element, of course) - bindss <- Monad.mapM flatbind binds - -- Concat all the bindings - let binds' = concat bindss - -- Return the new let. We don't use change here, since possibly nothing has - -- changed. If anything has changed, flatbind has already flagged that - -- change. - return $ Let (Rec binds') expr - where - -- Turns a binding of a let into a multiple bindings, or any other binding - -- into a list with just that binding - flatbind :: (CoreBndr, CoreExpr) -> TransformMonad [(CoreBndr, CoreExpr)] - flatbind (b, Let (Rec binds) expr) = change ((b, expr):binds) - flatbind (b, expr) = return [(b, expr)] +letflat (Let (NonRec b (Let (NonRec b' expr') res')) res) = + change $ Let (NonRec b' expr') (Let (NonRec b res') res) -- Leave all other expressions unchanged letflat expr = return expr -- Perform this transform everywhere