Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flattenLet applied in bottomup traversal #2599

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmark/clash-benchmark.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ library
clash-lib,
clash-prelude

if impl(ghc >= 9.0.0)
build-depends: ghc-boot

executable clash-benchmark-normalization
main-is: benchmark-normalization.hs
default-language: Haskell2010
Expand Down
46 changes: 45 additions & 1 deletion benchmark/common/BenchmarkCommon.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeApplications #-}

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

import qualified Control.Concurrent.Supply as Supply

#if MIN_VERSION_ghc(9,2,0)
import qualified GHC.Driver.Monad as GHC
import qualified GHC.Driver.Session as GHC
import qualified GHC.Driver.Env.Types as GHC
import qualified GHC.LanguageExtensions as LangExt
import qualified GHC.Settings as GHC
import qualified GHC.Utils.Fingerprint as GHC
#elif MIN_VERSION_ghc(9,0,0)
import qualified GHC.Driver.Monad as GHC
import qualified GHC.Driver.Session as GHC
import qualified GHC.Driver.Types as GHC
import qualified GHC.LanguageExtensions as LangExt
import qualified GHC.Settings as GHC
import qualified GHC.Utils.Fingerprint as GHC
#endif

defaultTests :: [FilePath]
defaultTests =
[ "examples/FIR.hs"
Expand Down Expand Up @@ -49,7 +66,34 @@ runInputStage idirs src = do
let o = opts idirs
let backend = initBackend @VHDLState o
pds <- primDirs backend
generateBindings o (return ()) pds (opt_importPaths o) [] (hdlKind backend) src Nothing
generateBindings o action pds (opt_importPaths o) [] (hdlKind backend) src Nothing
where
#if MIN_VERSION_ghc(9,0,0)
action = do
env <- GHC.getSession
let df0 = GHC.hsc_dflags env
#if MIN_VERSION_ghc(9,4,0)
df1 = addOptP "-DCLASH_OPAQUE=OPAQUE" df0
#else
df1 = addOptP "-DCLASH_OPAQUE=NOINLINE" df0
#endif
df2 = GHC.xopt_set df1 LangExt.Cpp
GHC.setSession (env {GHC.hsc_dflags = df2})

addOptP :: String -> GHC.DynFlags -> GHC.DynFlags
addOptP f = alterToolSettings $ \s -> s
{ GHC.toolSettings_opt_P = f : GHC.toolSettings_opt_P s
, GHC.toolSettings_opt_P_fingerprint = fingerprintStrings (f : GHC.toolSettings_opt_P s)
}

alterToolSettings :: (GHC.ToolSettings -> GHC.ToolSettings) -> GHC.DynFlags -> GHC.DynFlags
alterToolSettings f dynFlags = dynFlags { GHC.toolSettings = f (GHC.toolSettings dynFlags) }

fingerprintStrings :: [String] -> GHC.Fingerprint
fingerprintStrings ss = GHC.fingerprintFingerprints $ map GHC.fingerprintString ss
#else
action = return ()
#endif

runNormalisationStage
:: [FilePath]
Expand Down
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