From a166e4049d45e4e1688baf748e1a82806374a3c0 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 17 Aug 2009 11:28:20 +0200 Subject: [PATCH] Make letremoveunused work for recursive lets again. The non-recursive version is also changed to work for each nested let in turn, instead of running on a bunch of them at the same time. --- "c\316\273ash/CLasH/Normalize.hs" | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git "a/c\316\273ash/CLasH/Normalize.hs" "b/c\316\273ash/CLasH/Normalize.hs" index a7223e3..b16eb7a 100644 --- "a/c\316\273ash/CLasH/Normalize.hs" +++ "b/c\316\273ash/CLasH/Normalize.hs" @@ -248,13 +248,17 @@ letremovesimpletop = everywhere ("letremovesimple", inlinebind (\(b, e) -> Trans -- Unused let binding removal -------------------------------- letremoveunused, letremoveunusedtop :: Transform -letremoveunused expr@(Let _ _) = do +letremoveunused expr@(Let (NonRec b bound) res) = do + let used = expr_uses_binders [b] res + if used + then return expr + else change res +letremoveunused expr@(Let (Rec binds) res) = do -- Filter out all unused binds. let binds' = filter dobind binds -- Only set the changed flag if binds got removed - changeif (length binds' /= length binds) (mkNonRecLets binds' res) + changeif (length binds' /= length binds) (Let (Rec binds') res) where - (binds, res) = flattenLets expr bound_exprs = map snd binds -- For each bind check if the bind is used by res or any of the bound -- expressions -- 2.30.2