From 2b5af0dc4588b2e2fdbd160536bbef4c684ffe36 Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Mon, 6 Nov 2023 14:31:05 +0100 Subject: [PATCH] flattenLet applied in bottomup traversal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensures deeply nested let-bindings are flattened first so that let-expressions do not get inlined into argument positions in their unflattened form. Has some minor performance effects. Before: ``` benchmarking normalization of examples/Reducer.hs time 395.2 ms (385.3 ms .. 410.2 ms) 1.000 R² (1.000 R² .. 1.000 R²) mean 401.3 ms (396.8 ms .. 406.4 ms) std dev 5.429 ms (1.784 ms .. 7.434 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking normalization of tests/shouldwork/Basic/AES.hs time 161.3 ms (160.1 ms .. 162.5 ms) 1.000 R² (1.000 R² .. 1.000 R²) mean 164.9 ms (163.1 ms .. 169.4 ms) std dev 4.042 ms (490.2 μs .. 5.968 ms) variance introduced by outliers: 12% (moderately inflated) ``` After: ``` benchmarking normalization of examples/Reducer.hs time 447.0 ms (439.0 ms .. 451.0 ms) 1.000 R² (1.000 R² .. 1.000 R²) mean 454.4 ms (451.0 ms .. 460.9 ms) std dev 6.411 ms (13.17 μs .. 7.496 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking normalization of tests/shouldwork/Basic/AES.hs time 182.2 ms (180.8 ms .. 183.4 ms) 1.000 R² (1.000 R² .. 1.000 R²) mean 185.3 ms (183.9 ms .. 188.1 ms) std dev 2.666 ms (490.4 μs .. 3.715 ms) variance introduced by outliers: 14% (moderately inflated) ``` Fixes #2598 --- changelog/2023-11-06T14_40_14+01_00_fix_2598 | 1 + clash-lib/src/Clash/Normalize.hs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog/2023-11-06T14_40_14+01_00_fix_2598 diff --git a/changelog/2023-11-06T14_40_14+01_00_fix_2598 b/changelog/2023-11-06T14_40_14+01_00_fix_2598 new file mode 100644 index 0000000000..9523b31f8c --- /dev/null +++ b/changelog/2023-11-06T14_40_14+01_00_fix_2598 @@ -0,0 +1 @@ +FIXED: Name duplication in generated Verilog involving reset synchronizer [#2598](https://github.com/clash-lang/clash-compiler/issues/2598) diff --git a/clash-lib/src/Clash/Normalize.hs b/clash-lib/src/Clash/Normalize.hs index bac0abca39..190b97603c 100644 --- a/clash-lib/src/Clash/Normalize.hs +++ b/clash-lib/src/Clash/Normalize.hs @@ -2,7 +2,7 @@ Copyright : (C) 2012-2016, University of Twente, 2016 , Myrtle Software Ltd, 2017 , Google Inc., - 2021-2022, QBayLogic B.V. + 2021-2023, QBayLogic B.V. License : BSD2 (see the file LICENSE) Maintainer : QBayLogic B.V. @@ -71,7 +71,8 @@ import Clash.Normalize.Strategy import Clash.Normalize.Transformations import Clash.Normalize.Types import Clash.Normalize.Util -import Clash.Rewrite.Combinators ((>->),(!->),repeatR,topdownR) +import Clash.Rewrite.Combinators + ((>->), (!->), bottomupR, repeatR, topdownR) import Clash.Rewrite.Types (RewriteEnv (..), RewriteState (..), bindings, debugOpts, extra, tcCache, topEntities, newInlineStrategy) @@ -378,8 +379,8 @@ flattenCallTree (CBranch (nm,(Binding nm' sp inl pr tm r)) used) = do apply "caseCon" caseCon >-> (apply "reduceConst" reduceConst !-> apply "deadcode" deadCode) >-> apply "reduceNonRepPrim" reduceNonRepPrim >-> - apply "removeUnusedExpr" removeUnusedExpr >-> - apply "flattenLet" flattenLet)) !-> + apply "removeUnusedExpr" removeUnusedExpr) >-> + bottomupR (apply "flattenLet" flattenLet)) !-> topdownSucR (apply "topLet" topLet) goCheap c@(CLeaf (nm2,(Binding _ _ inl2 _ e _)))