Skip to content

Commit 1c373ef

Browse files
authored
Merge pull request #2599 from clash-lang/fix2598
flattenLet applied in bottomup traversal
2 parents 1323074 + 5652ae3 commit 1c373ef

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

benchmark/clash-benchmark.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ library
2626
clash-lib,
2727
clash-prelude
2828

29+
if impl(ghc >= 9.0.0)
30+
build-depends: ghc-boot
31+
2932
executable clash-benchmark-normalization
3033
main-is: benchmark-normalization.hs
3134
default-language: Haskell2010

benchmark/common/BenchmarkCommon.hs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE TypeApplications #-}
23

34
module BenchmarkCommon where
@@ -17,6 +18,22 @@ import Clash.GHC.NetlistTypes
1718

1819
import qualified Control.Concurrent.Supply as Supply
1920

21+
#if MIN_VERSION_ghc(9,2,0)
22+
import qualified GHC.Driver.Monad as GHC
23+
import qualified GHC.Driver.Session as GHC
24+
import qualified GHC.Driver.Env.Types as GHC
25+
import qualified GHC.LanguageExtensions as LangExt
26+
import qualified GHC.Settings as GHC
27+
import qualified GHC.Utils.Fingerprint as GHC
28+
#elif MIN_VERSION_ghc(9,0,0)
29+
import qualified GHC.Driver.Monad as GHC
30+
import qualified GHC.Driver.Session as GHC
31+
import qualified GHC.Driver.Types as GHC
32+
import qualified GHC.LanguageExtensions as LangExt
33+
import qualified GHC.Settings as GHC
34+
import qualified GHC.Utils.Fingerprint as GHC
35+
#endif
36+
2037
defaultTests :: [FilePath]
2138
defaultTests =
2239
[ "examples/FIR.hs"
@@ -49,7 +66,34 @@ runInputStage idirs src = do
4966
let o = opts idirs
5067
let backend = initBackend @VHDLState o
5168
pds <- primDirs backend
52-
generateBindings o (return ()) pds (opt_importPaths o) [] (hdlKind backend) src Nothing
69+
generateBindings o action pds (opt_importPaths o) [] (hdlKind backend) src Nothing
70+
where
71+
#if MIN_VERSION_ghc(9,0,0)
72+
action = do
73+
env <- GHC.getSession
74+
let df0 = GHC.hsc_dflags env
75+
#if MIN_VERSION_ghc(9,4,0)
76+
df1 = addOptP "-DCLASH_OPAQUE=OPAQUE" df0
77+
#else
78+
df1 = addOptP "-DCLASH_OPAQUE=NOINLINE" df0
79+
#endif
80+
df2 = GHC.xopt_set df1 LangExt.Cpp
81+
GHC.setSession (env {GHC.hsc_dflags = df2})
82+
83+
addOptP :: String -> GHC.DynFlags -> GHC.DynFlags
84+
addOptP f = alterToolSettings $ \s -> s
85+
{ GHC.toolSettings_opt_P = f : GHC.toolSettings_opt_P s
86+
, GHC.toolSettings_opt_P_fingerprint = fingerprintStrings (f : GHC.toolSettings_opt_P s)
87+
}
88+
89+
alterToolSettings :: (GHC.ToolSettings -> GHC.ToolSettings) -> GHC.DynFlags -> GHC.DynFlags
90+
alterToolSettings f dynFlags = dynFlags { GHC.toolSettings = f (GHC.toolSettings dynFlags) }
91+
92+
fingerprintStrings :: [String] -> GHC.Fingerprint
93+
fingerprintStrings ss = GHC.fingerprintFingerprints $ map GHC.fingerprintString ss
94+
#else
95+
action = return ()
96+
#endif
5397

5498
runNormalisationStage
5599
:: [FilePath]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXED: Name duplication in generated Verilog involving reset synchronizer [#2598](https://github.com/clash-lang/clash-compiler/issues/2598)

clash-lib/src/Clash/Normalize.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Copyright : (C) 2012-2016, University of Twente,
33
2016 , Myrtle Software Ltd,
44
2017 , Google Inc.,
5-
2021-2022, QBayLogic B.V.
5+
2021-2023, QBayLogic B.V.
66
License : BSD2 (see the file LICENSE)
77
Maintainer : QBayLogic B.V. <[email protected]>
88
@@ -71,7 +71,8 @@ import Clash.Normalize.Strategy
7171
import Clash.Normalize.Transformations
7272
import Clash.Normalize.Types
7373
import Clash.Normalize.Util
74-
import Clash.Rewrite.Combinators ((>->),(!->),repeatR,topdownR)
74+
import Clash.Rewrite.Combinators
75+
((>->), (!->), bottomupR, repeatR, topdownR)
7576
import Clash.Rewrite.Types
7677
(RewriteEnv (..), RewriteState (..), bindings, debugOpts, extra,
7778
tcCache, topEntities, newInlineStrategy)
@@ -378,8 +379,8 @@ flattenCallTree (CBranch (nm,(Binding nm' sp inl pr tm r)) used) = do
378379
apply "caseCon" caseCon >->
379380
(apply "reduceConst" reduceConst !-> apply "deadcode" deadCode) >->
380381
apply "reduceNonRepPrim" reduceNonRepPrim >->
381-
apply "removeUnusedExpr" removeUnusedExpr >->
382-
apply "flattenLet" flattenLet)) !->
382+
apply "removeUnusedExpr" removeUnusedExpr) >->
383+
bottomupR (apply "flattenLet" flattenLet)) !->
383384
topdownSucR (apply "topLet" topLet)
384385

385386
goCheap c@(CLeaf (nm2,(Binding _ _ inl2 _ e _)))

0 commit comments

Comments
 (0)