Commit b8effa7f authored by Michal Terepeta's avatar Michal Terepeta Committed by Ben Gamari

CmmUtils: remove the last dataflow functions

This commit:
- Moves the remaining few methods concerned with dataflow analysis
  from `CmmUtils` to `Hoopl.Dataflow`.
- Refactors the code to not use `FwdPass` and simply pass `FwdTransfer`
  and `DataflowLattice` directly.
Signed-off-by: Michal Terepeta's avatarMichal Terepeta <michal.terepeta@gmail.com>

Test Plan: validate

Reviewers: austin, simonmar, bgamari

Reviewed By: simonmar, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2634
parent 48876ae0
...@@ -107,7 +107,7 @@ cafTransfers = mkBTransfer3 first middle last ...@@ -107,7 +107,7 @@ cafTransfers = mkBTransfer3 first middle last
else s else s
cafAnal :: CmmGraph -> CAFEnv cafAnal :: CmmGraph -> CAFEnv
cafAnal g = dataflowAnalBwd g [] $ analBwd cafLattice cafTransfers cafAnal g = dataflowAnalBwd g [] cafLattice cafTransfers
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Building the SRTs -- Building the SRTs
......
...@@ -18,10 +18,9 @@ where ...@@ -18,10 +18,9 @@ where
import DynFlags import DynFlags
import BlockId import BlockId
import Cmm import Cmm
import CmmUtils
import PprCmmExpr () import PprCmmExpr ()
import Hoopl.Dataflow
import Hoopl
import Maybes import Maybes
import Outputable import Outputable
...@@ -52,14 +51,14 @@ type BlockEntryLiveness r = BlockEnv (CmmLive r) ...@@ -52,14 +51,14 @@ type BlockEntryLiveness r = BlockEnv (CmmLive r)
cmmLocalLiveness :: DynFlags -> CmmGraph -> BlockEntryLiveness LocalReg cmmLocalLiveness :: DynFlags -> CmmGraph -> BlockEntryLiveness LocalReg
cmmLocalLiveness dflags graph = cmmLocalLiveness dflags graph =
check $ dataflowAnalBwd graph [] $ analBwd liveLattice (xferLive dflags) check $ dataflowAnalBwd graph [] liveLattice (xferLive dflags)
where entry = g_entry graph where entry = g_entry graph
check facts = noLiveOnEntry entry check facts = noLiveOnEntry entry
(expectJust "check" $ mapLookup entry facts) facts (expectJust "check" $ mapLookup entry facts) facts
cmmGlobalLiveness :: DynFlags -> CmmGraph -> BlockEntryLiveness GlobalReg cmmGlobalLiveness :: DynFlags -> CmmGraph -> BlockEntryLiveness GlobalReg
cmmGlobalLiveness dflags graph = cmmGlobalLiveness dflags graph =
dataflowAnalBwd graph [] $ analBwd liveLattice (xferLive dflags) dataflowAnalBwd graph [] liveLattice (xferLive dflags)
-- | On entry to the procedure, there had better not be any LocalReg's live-in. -- | On entry to the procedure, there had better not be any LocalReg's live-in.
noLiveOnEntry :: BlockId -> CmmLive LocalReg -> a -> a noLiveOnEntry :: BlockId -> CmmLive LocalReg -> a -> a
......
...@@ -135,7 +135,7 @@ procPointAnalysis :: ProcPointSet -> CmmGraph -> UniqSM (BlockEnv Status) ...@@ -135,7 +135,7 @@ procPointAnalysis :: ProcPointSet -> CmmGraph -> UniqSM (BlockEnv Status)
-- See Note [Proc-point analysis] -- See Note [Proc-point analysis]
procPointAnalysis procPoints g@(CmmGraph {g_graph = graph}) = procPointAnalysis procPoints g@(CmmGraph {g_graph = graph}) =
-- pprTrace "procPointAnalysis" (ppr procPoints) $ -- pprTrace "procPointAnalysis" (ppr procPoints) $
dataflowAnalFwdBlocks g initProcPoints $ analFwd lattice forward return $ dataflowAnalFwdBlocks g initProcPoints lattice forward
where initProcPoints = [(id, ProcPoint) | id <- setElems procPoints, where initProcPoints = [(id, ProcPoint) | id <- setElems procPoints,
id `setMember` labelsInGraph ] id `setMember` labelsInGraph ]
-- See Note [Non-existing proc-points] -- See Note [Non-existing proc-points]
......
...@@ -58,10 +58,6 @@ module CmmUtils( ...@@ -58,10 +58,6 @@ module CmmUtils(
toBlockListEntryFirst, toBlockListEntryFirstFalseFallthrough, toBlockListEntryFirst, toBlockListEntryFirstFalseFallthrough,
foldGraphBlocks, mapGraphNodes, postorderDfs, mapGraphNodes1, foldGraphBlocks, mapGraphNodes, postorderDfs, mapGraphNodes1,
analFwd, analBwd,
dataflowAnalFwd, dataflowAnalBwd,
dataflowAnalFwdBlocks,
-- * Ticks -- * Ticks
blockTicks blockTicks
) where ) where
...@@ -77,7 +73,6 @@ import BlockId ...@@ -77,7 +73,6 @@ import BlockId
import CLabel import CLabel
import Outputable import Outputable
import Unique import Unique
import UniqSupply
import DynFlags import DynFlags
import Util import Util
import CodeGen.Platform import CodeGen.Platform
...@@ -558,41 +553,6 @@ foldGraphBlocks k z g = mapFold k z $ toBlockMap g ...@@ -558,41 +553,6 @@ foldGraphBlocks k z g = mapFold k z $ toBlockMap g
postorderDfs :: CmmGraph -> [CmmBlock] postorderDfs :: CmmGraph -> [CmmBlock]
postorderDfs g = {-# SCC "postorderDfs" #-} postorder_dfs_from (toBlockMap g) (g_entry g) postorderDfs g = {-# SCC "postorderDfs" #-} postorder_dfs_from (toBlockMap g) (g_entry g)
-------------------------------------------------
-- Running dataflow analysis and/or rewrites
-- Constructing forward and backward analysis-only pass
analFwd :: DataflowLattice f -> FwdTransfer n f -> FwdPass UniqSM n f
analBwd :: DataflowLattice f -> BwdTransfer n f -> BwdPass UniqSM n f
analFwd lat xfer =
FwdPass {fp_lattice = lat, fp_transfer = xfer, fp_rewrite = noFwdRewrite}
analBwd lat xfer =
BwdPass {bp_lattice = lat, bp_transfer = xfer, bp_rewrite = noBwdRewrite}
dataflowAnalFwd :: NonLocal n =>
GenCmmGraph n -> [(BlockId, f)]
-> FwdPass UniqSM n f
-> BlockEnv f
dataflowAnalFwd (CmmGraph {g_entry=entry, g_graph=graph}) facts fwd =
analyzeFwd fwd (JustC [entry]) graph (mkFactBase (fp_lattice fwd) facts)
dataflowAnalFwdBlocks :: NonLocal n =>
GenCmmGraph n -> [(BlockId, f)]
-> FwdPass UniqSM n f
-> UniqSM (BlockEnv f)
dataflowAnalFwdBlocks (CmmGraph {g_entry=entry, g_graph=graph}) facts fwd = do
-- (graph, facts, NothingO) <- analyzeAndRewriteFwd fwd (JustC [entry]) graph (mkFactBase (fp_lattice fwd) facts)
-- return facts
return (analyzeFwdBlocks fwd (JustC [entry]) graph (mkFactBase (fp_lattice fwd) facts))
dataflowAnalBwd :: NonLocal n =>
GenCmmGraph n -> [(BlockId, f)]
-> BwdPass UniqSM n f
-> BlockEnv f
dataflowAnalBwd (CmmGraph {g_entry=entry, g_graph=graph}) facts bwd =
analyzeBwd bwd (JustC [entry]) graph (mkFactBase (bp_lattice bwd) facts)
------------------------------------------------- -------------------------------------------------
-- Tick utilities -- Tick utilities
......
...@@ -10,13 +10,9 @@ import Compiler.Hoopl hiding ...@@ -10,13 +10,9 @@ import Compiler.Hoopl hiding
Unique, Unique,
FwdTransfer(..), FwdRewrite(..), FwdPass(..), FwdTransfer(..), FwdRewrite(..), FwdPass(..),
BwdTransfer(..), BwdRewrite(..), BwdPass(..), BwdTransfer(..), BwdRewrite(..), BwdPass(..),
noFwdRewrite, noBwdRewrite,
analyzeAndRewriteFwd, analyzeAndRewriteBwd,
mkFactBase, Fact, mkFactBase, Fact,
mkBRewrite, mkBRewrite3, mkBTransfer, mkBTransfer3, mkBRewrite3, mkBTransfer3,
mkFRewrite, mkFRewrite3, mkFTransfer, mkFTransfer3, mkFRewrite3, mkFTransfer3,
deepFwdRw, deepFwdRw3, thenFwdRw, iterFwdRw,
deepBwdRw, deepBwdRw3, thenBwdRw, iterBwdRw
) )
import Hoopl.Dataflow import Hoopl.Dataflow
......
...@@ -18,32 +18,55 @@ ...@@ -18,32 +18,55 @@
-- --
module Hoopl.Dataflow module Hoopl.Dataflow
( DataflowLattice(..), OldFact(..), NewFact(..), Fact, mkFactBase ( C, O, DataflowLattice(..), OldFact(..), NewFact(..), Fact, FactBase
, mkFactBase
, ChangeFlag(..) , ChangeFlag(..)
, FwdPass(..), FwdTransfer, mkFTransfer, mkFTransfer3, getFTransfer3 , FwdPass(..), FwdTransfer, mkFTransfer3
, BwdPass(..), BwdTransfer, mkBTransfer, mkBTransfer3, getBTransfer3 , BwdPass(..), BwdTransfer, mkBTransfer3
, noBwdRewrite, noFwdRewrite
, dataflowAnalFwdBlocks, dataflowAnalBwd
, analyzeFwd, analyzeFwdBlocks, analyzeBwd , analyzeFwd, analyzeFwdBlocks, analyzeBwd
, changeIf
, joinOutFacts
) )
where where
import UniqSupply import BlockId
import Cmm
import Data.Array import Data.Array
import Compiler.Hoopl hiding (noFwdRewrite, noBwdRewrite) import Compiler.Hoopl
noRewrite :: a -> b -> UniqSM (Maybe c) -- TODO(michalt): This wrapper will go away once we refactor the analyze*
noRewrite _ _ = return Nothing -- methods.
dataflowAnalFwdBlocks
noFwdRewrite :: FwdRewrite UniqSM n f :: NonLocal n
noFwdRewrite = FwdRewrite3 (noRewrite, noRewrite, noRewrite) => GenCmmGraph n
-> [(BlockId, f)]
-> DataflowLattice f
-> FwdTransfer n f
-> BlockEnv f
dataflowAnalFwdBlocks
(CmmGraph {g_entry = entry, g_graph = graph}) facts lattice xfer =
analyzeFwdBlocks
lattice xfer (JustC [entry]) graph (mkFactBase lattice facts)
-- TODO(michalt): This wrapper will go away once we refactor the analyze*
-- methods.
dataflowAnalBwd
:: NonLocal n
=> GenCmmGraph n
-> [(BlockId, f)]
-> DataflowLattice f
-> BwdTransfer n f
-> BlockEnv f
dataflowAnalBwd
(CmmGraph {g_entry = entry, g_graph = graph}) facts lattice xfer =
analyzeBwd lattice xfer (JustC [entry]) graph (mkFactBase lattice facts)
noBwdRewrite :: BwdRewrite UniqSM n f
noBwdRewrite = BwdRewrite3 (noRewrite, noRewrite, noRewrite)
---------------------------------------------------------------- ----------------------------------------------------------------
-- Forward Analysis only -- Forward Analysis only
...@@ -52,14 +75,14 @@ noBwdRewrite = BwdRewrite3 (noRewrite, noRewrite, noRewrite) ...@@ -52,14 +75,14 @@ noBwdRewrite = BwdRewrite3 (noRewrite, noRewrite, noRewrite)
-- | if the graph being analyzed is open at the entry, there must -- | if the graph being analyzed is open at the entry, there must
-- be no other entry point, or all goes horribly wrong... -- be no other entry point, or all goes horribly wrong...
analyzeFwd analyzeFwd
:: forall n f e . NonLocal n => :: forall n f e . NonLocal n
FwdPass UniqSM n f => DataflowLattice f
-> FwdTransfer n f
-> MaybeC e [Label] -> MaybeC e [Label]
-> Graph n e C -> Fact e f -> Graph n e C -> Fact e f
-> FactBase f -> FactBase f
analyzeFwd FwdPass { fp_lattice = lattice, analyzeFwd lattice (FwdTransfer3 (ftr, mtr, ltr)) entries g in_fact =
fp_transfer = FwdTransfer3 (ftr, mtr, ltr) } graph g in_fact
entries g in_fact = graph g in_fact
where where
graph :: Graph n e C -> Fact e f -> FactBase f graph :: Graph n e C -> Fact e f -> FactBase f
graph (GMany entry blockmap NothingO) graph (GMany entry blockmap NothingO)
...@@ -94,14 +117,14 @@ analyzeFwd FwdPass { fp_lattice = lattice, ...@@ -94,14 +117,14 @@ analyzeFwd FwdPass { fp_lattice = lattice,
-- | if the graph being analyzed is open at the entry, there must -- | if the graph being analyzed is open at the entry, there must
-- be no other entry point, or all goes horribly wrong... -- be no other entry point, or all goes horribly wrong...
analyzeFwdBlocks analyzeFwdBlocks
:: forall n f e . NonLocal n => :: forall n f e . NonLocal n
FwdPass UniqSM n f => DataflowLattice f
-> FwdTransfer n f
-> MaybeC e [Label] -> MaybeC e [Label]
-> Graph n e C -> Fact e f -> Graph n e C -> Fact e f
-> FactBase f -> FactBase f
analyzeFwdBlocks FwdPass { fp_lattice = lattice, analyzeFwdBlocks lattice (FwdTransfer3 (ftr, _, ltr)) entries g in_fact =
fp_transfer = FwdTransfer3 (ftr, _, ltr) } graph g in_fact
entries g in_fact = graph g in_fact
where where
graph :: Graph n e C -> Fact e f -> FactBase f graph :: Graph n e C -> Fact e f -> FactBase f
graph (GMany entry blockmap NothingO) graph (GMany entry blockmap NothingO)
...@@ -136,14 +159,14 @@ analyzeFwdBlocks FwdPass { fp_lattice = lattice, ...@@ -136,14 +159,14 @@ analyzeFwdBlocks FwdPass { fp_lattice = lattice,
-- | if the graph being analyzed is open at the entry, there must -- | if the graph being analyzed is open at the entry, there must
-- be no other entry point, or all goes horribly wrong... -- be no other entry point, or all goes horribly wrong...
analyzeBwd analyzeBwd
:: forall n f e . NonLocal n => :: forall n f e . NonLocal n
BwdPass UniqSM n f => DataflowLattice f
-> BwdTransfer n f
-> MaybeC e [Label] -> MaybeC e [Label]
-> Graph n e C -> Fact C f -> Graph n e C -> Fact C f
-> FactBase f -> FactBase f
analyzeBwd BwdPass { bp_lattice = lattice, analyzeBwd lattice (BwdTransfer3 (ftr, mtr, ltr)) entries g in_fact =
bp_transfer = BwdTransfer3 (ftr, mtr, ltr) } graph g in_fact
entries g in_fact = graph g in_fact
where where
graph :: Graph n e C -> Fact C f -> FactBase f graph :: Graph n e C -> Fact C f -> FactBase f
graph (GMany entry blockmap NothingO) graph (GMany entry blockmap NothingO)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment