mirror of
https://github.com/anoma/juvix.git
synced 2024-12-02 23:43:01 +03:00
parent
336a934d18
commit
185937fc7d
@ -1,6 +1,5 @@
|
||||
module Juvix.Compiler.Core.Data.IdentDependencyInfo where
|
||||
|
||||
import Data.HashMap.Strict qualified as HashMap
|
||||
import Data.HashSet qualified as HashSet
|
||||
import Juvix.Compiler.Core.Data.InfoTable
|
||||
import Juvix.Compiler.Core.Extra.Utils
|
||||
@ -24,7 +23,7 @@ createIdentDependencyInfo tab = createDependencyInfo graph startVertices
|
||||
startVertices = HashSet.fromList syms
|
||||
|
||||
syms :: [Symbol]
|
||||
syms = map (^. identifierSymbol) (HashMap.elems (tab ^. infoIdentifiers))
|
||||
syms = maybe [] singleton (tab ^. infoMain)
|
||||
|
||||
recursiveIdents :: InfoTable -> HashSet Symbol
|
||||
recursiveIdents = nodesOnCycles . createIdentDependencyInfo
|
||||
|
@ -0,0 +1,14 @@
|
||||
module Juvix.Compiler.Core.Transformation.Optimize.FilterUnreachable where
|
||||
|
||||
import Data.HashMap.Strict qualified as HashMap
|
||||
import Juvix.Compiler.Core.Data.IdentDependencyInfo
|
||||
import Juvix.Compiler.Core.Transformation.Base
|
||||
|
||||
filterUnreachable :: InfoTable -> InfoTable
|
||||
filterUnreachable tab = pruneInfoTable $ over infoIdentifiers goFilter tab
|
||||
where
|
||||
depInfo = createIdentDependencyInfo tab
|
||||
|
||||
goFilter :: HashMap Symbol IdentifierInfo -> HashMap Symbol IdentifierInfo
|
||||
goFilter idents =
|
||||
HashMap.filterWithKey (\sym _ -> isReachable depInfo sym) idents
|
@ -3,18 +3,20 @@ module Juvix.Compiler.Core.Transformation.Optimize.Phase.Main where
|
||||
import Juvix.Compiler.Core.Data.IdentDependencyInfo
|
||||
import Juvix.Compiler.Core.Options
|
||||
import Juvix.Compiler.Core.Transformation.Base
|
||||
import Juvix.Compiler.Core.Transformation.Optimize.FilterUnreachable
|
||||
import Juvix.Compiler.Core.Transformation.Optimize.Inlining
|
||||
import Juvix.Compiler.Core.Transformation.Optimize.LambdaFolding
|
||||
import Juvix.Compiler.Core.Transformation.Optimize.LetFolding
|
||||
|
||||
optimize' :: CoreOptions -> InfoTable -> InfoTable
|
||||
optimize' CoreOptions {..} tab =
|
||||
compose
|
||||
(4 * _optOptimizationLevel)
|
||||
( compose 2 (letFolding' (isInlineableLambda _optInliningDepth))
|
||||
. lambdaFolding
|
||||
. inlining' _optInliningDepth (recursiveIdents tab)
|
||||
)
|
||||
filterUnreachable
|
||||
. compose
|
||||
(4 * _optOptimizationLevel)
|
||||
( compose 2 (letFolding' (isInlineableLambda _optInliningDepth))
|
||||
. lambdaFolding
|
||||
. inlining' _optInliningDepth (recursiveIdents tab)
|
||||
)
|
||||
. letFolding
|
||||
$ tab
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user