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
else s
cafAnal :: CmmGraph -> CAFEnv
cafAnal g = dataflowAnalBwd g [] $ analBwd cafLattice cafTransfers
cafAnal g = dataflowAnalBwd g [] cafLattice cafTransfers
-----------------------------------------------------------------------
-- Building the SRTs
......
......@@ -18,10 +18,9 @@ where
import DynFlags
import BlockId
import Cmm
import CmmUtils
import PprCmmExpr ()
import Hoopl.Dataflow
import Hoopl
import Maybes
import Outputable
......@@ -52,14 +51,14 @@ type BlockEntryLiveness r = BlockEnv (CmmLive r)
cmmLocalLiveness :: DynFlags -> CmmGraph -> BlockEntryLiveness LocalReg
cmmLocalLiveness dflags graph =
check $ dataflowAnalBwd graph [] $ analBwd liveLattice (xferLive dflags)
check $ dataflowAnalBwd graph [] liveLattice (xferLive dflags)
where entry = g_entry graph
check facts = noLiveOnEntry entry
(expectJust "check" $ mapLookup entry facts) facts
cmmGlobalLiveness :: DynFlags -> CmmGraph -> BlockEntryLiveness GlobalReg
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.
noLiveOnEntry :: BlockId -> CmmLive LocalReg -> a -> a
......
......@@ -135,7 +135,7 @@ procPointAnalysis :: ProcPointSet -> CmmGraph -> UniqSM (BlockEnv Status)
-- See Note [Proc-point analysis]
procPointAnalysis procPoints g@(CmmGraph {g_graph = graph}) =
-- pprTrace "procPointAnalysis" (ppr procPoints) $
dataflowAnalFwdBlocks g initProcPoints $ analFwd lattice forward
return $ dataflowAnalFwdBlocks g initProcPoints lattice forward
where initProcPoints = [(id, ProcPoint) | id <- setElems procPoints,
id `setMember` labelsInGraph ]
-- See Note [Non-existing proc-points]
......
......@@ -58,10 +58,6 @@ module CmmUtils(
toBlockListEntryFirst, toBlockListEntryFirstFalseFallthrough,
foldGraphBlocks, mapGraphNodes, postorderDfs, mapGraphNodes1,
analFwd, analBwd,
dataflowAnalFwd, dataflowAnalBwd,
dataflowAnalFwdBlocks,
-- * Ticks
blockTicks
) where
......@@ -77,7 +73,6 @@ import BlockId
import CLabel
import Outputable
import Unique
import UniqSupply
import DynFlags
import Util
import CodeGen.Platform
......@@ -558,41 +553,6 @@ foldGraphBlocks k z g = mapFold k z $ toBlockMap g
postorderDfs :: CmmGraph -> [CmmBlock]
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
......
......@@ -10,13 +10,9 @@ import Compiler.Hoopl hiding
Unique,
FwdTransfer(..), FwdRewrite(..), FwdPass(..),
BwdTransfer(..), BwdRewrite(..), BwdPass(..),
noFwdRewrite, noBwdRewrite,
analyzeAndRewriteFwd, analyzeAndRewriteBwd,
mkFactBase, Fact,
mkBRewrite, mkBRewrite3, mkBTransfer, mkBTransfer3,
mkFRewrite, mkFRewrite3, mkFTransfer, mkFTransfer3,
deepFwdRw, deepFwdRw3, thenFwdRw, iterFwdRw,
deepBwdRw, deepBwdRw3, thenBwdRw, iterBwdRw
mkBRewrite3, mkBTransfer3,
mkFRewrite3, mkFTransfer3,
)
import Hoopl.Dataflow
......
......@@ -18,32 +18,55 @@
--
module Hoopl.Dataflow
( DataflowLattice(..), OldFact(..), NewFact(..), Fact, mkFactBase
( C, O, DataflowLattice(..), OldFact(..), NewFact(..), Fact, FactBase
, mkFactBase
, ChangeFlag(..)
, FwdPass(..), FwdTransfer, mkFTransfer, mkFTransfer3, getFTransfer3
, FwdPass(..), FwdTransfer, mkFTransfer3
, BwdPass(..), BwdTransfer, mkBTransfer, mkBTransfer3, getBTransfer3
, noBwdRewrite, noFwdRewrite
, BwdPass(..), BwdTransfer, mkBTransfer3
, dataflowAnalFwdBlocks, dataflowAnalBwd
, analyzeFwd, analyzeFwdBlocks, analyzeBwd
, changeIf
, joinOutFacts
)
where
import UniqSupply
import BlockId
import Cmm
import Data.Array
import Compiler.Hoopl hiding (noFwdRewrite, noBwdRewrite)
import Compiler.Hoopl
noRewrite :: a -> b -> UniqSM (Maybe c)
noRewrite _ _ = return Nothing
noFwdRewrite :: FwdRewrite UniqSM n f
noFwdRewrite = FwdRewrite3 (noRewrite, noRewrite, noRewrite)
-- TODO(michalt): This wrapper will go away once we refactor the analyze*
-- methods.
dataflowAnalFwdBlocks
:: NonLocal n
=> 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
......@@ -52,14 +75,14 @@ noBwdRewrite = BwdRewrite3 (noRewrite, noRewrite, noRewrite)
-- | if the graph being analyzed is open at the entry, there must
-- be no other entry point, or all goes horribly wrong...
analyzeFwd
:: forall n f e . NonLocal n =>
FwdPass UniqSM n f
:: forall n f e . NonLocal n
=> DataflowLattice f
-> FwdTransfer n f
-> MaybeC e [Label]
-> Graph n e C -> Fact e f
-> FactBase f
analyzeFwd FwdPass { fp_lattice = lattice,
fp_transfer = FwdTransfer3 (ftr, mtr, ltr) }
entries g in_fact = graph g in_fact
analyzeFwd lattice (FwdTransfer3 (ftr, mtr, ltr)) entries g in_fact =
graph g in_fact
where
graph :: Graph n e C -> Fact e f -> FactBase f
graph (GMany entry blockmap NothingO)
......@@ -94,14 +117,14 @@ analyzeFwd FwdPass { fp_lattice = lattice,
-- | if the graph being analyzed is open at the entry, there must
-- be no other entry point, or all goes horribly wrong...
analyzeFwdBlocks
:: forall n f e . NonLocal n =>
FwdPass UniqSM n f
:: forall n f e . NonLocal n
=> DataflowLattice f
-> FwdTransfer n f
-> MaybeC e [Label]
-> Graph n e C -> Fact e f
-> FactBase f
analyzeFwdBlocks FwdPass { fp_lattice = lattice,
fp_transfer = FwdTransfer3 (ftr, _, ltr) }
entries g in_fact = graph g in_fact
analyzeFwdBlocks lattice (FwdTransfer3 (ftr, _, ltr)) entries g in_fact =
graph g in_fact
where
graph :: Graph n e C -> Fact e f -> FactBase f
graph (GMany entry blockmap NothingO)
......@@ -136,14 +159,14 @@ analyzeFwdBlocks FwdPass { fp_lattice = lattice,
-- | if the graph being analyzed is open at the entry, there must
-- be no other entry point, or all goes horribly wrong...
analyzeBwd
:: forall n f e . NonLocal n =>
BwdPass UniqSM n f
:: forall n f e . NonLocal n
=> DataflowLattice f
-> BwdTransfer n f
-> MaybeC e [Label]
-> Graph n e C -> Fact C f
-> FactBase f
analyzeBwd BwdPass { bp_lattice = lattice,
bp_transfer = BwdTransfer3 (ftr, mtr, ltr) }
entries g in_fact = graph g in_fact
analyzeBwd lattice (BwdTransfer3 (ftr, mtr, ltr)) entries g in_fact =
graph g in_fact
where
graph :: Graph n e C -> Fact C f -> FactBase f
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