Skip to content

Commit

Permalink
flattenLet applied in bottomup traversal
Browse files Browse the repository at this point in the history
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
  • Loading branch information
christiaanb committed Nov 6, 2023
1 parent 60d8a78 commit 2b5af0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/2023-11-06T14_40_14+01_00_fix_2598
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIXED: Name duplication in generated Verilog involving reset synchronizer [#2598](https://github.com/clash-lang/clash-compiler/issues/2598)
9 changes: 5 additions & 4 deletions clash-lib/src/Clash/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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. <[email protected]>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 _)))
Expand Down

0 comments on commit 2b5af0d

Please sign in to comment.