diff --git a/benchmark/clash-benchmark.cabal b/benchmark/clash-benchmark.cabal index 4c6722f25d..00b605dee4 100644 --- a/benchmark/clash-benchmark.cabal +++ b/benchmark/clash-benchmark.cabal @@ -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 diff --git a/benchmark/common/BenchmarkCommon.hs b/benchmark/common/BenchmarkCommon.hs index 05b65307a7..ed03f8a712 100644 --- a/benchmark/common/BenchmarkCommon.hs +++ b/benchmark/common/BenchmarkCommon.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE TypeApplications #-} module BenchmarkCommon where @@ -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" @@ -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] 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 _)))