-{-# OPTIONS -Wall -fno-warn-name-shadowing #-}
+
module DFMonad
- ( Txlimit
+ ( OptimizationFuel
, DFTx, runDFTx, lastTxPass, txDecrement, txRemaining, txExhausted
+ , functionalDFTx
, DataflowLattice(..)
, DataflowAnalysis
import PprCmm()
import UniqFM
import UniqSupply
-import ZipCfg hiding (freshBlockId)
+import ZipCfg
import qualified ZipCfg as G
import Outputable
, df_facts_change :: ChangeFlag
}
-data DFTxState = DFTxState { df_txlimit :: Txlimit, df_lastpass :: String }
+data DFTxState = DFTxState { df_txlimit :: OptimizationFuel, df_lastpass :: String }
data DFState f = DFState { df_uniqs :: UniqSupply
, df_rewritten :: ChangeFlag
where f' _ s = let (a, txs) = f (df_txstate s)
in (a, s {df_txstate = txs})
-newtype Txlimit = Txlimit Int
+newtype OptimizationFuel = OptimizationFuel Int
deriving (Ord, Eq, Num, Show, Bounded)
initDFAState :: DFAState f
-- XXX DFTx really needs to be in IO, so we can dump programs in
-- intermediate states of optimization ---NR
-runDFTx :: Txlimit -> DFTx a -> a --- should only be called once per program!
+functionalDFTx :: String -> (OptimizationFuel -> (a, OptimizationFuel)) -> DFTx a
+functionalDFTx name pass = DFTx f
+ where f s = let (a, fuel) = pass (df_txlimit s)
+ in (a, DFTxState fuel name)
+
+runDFTx :: OptimizationFuel -> DFTx a -> a --- should only be called once per program!
runDFTx lim (DFTx f) = fst $ f $ DFTxState lim "<none>"
lastTxPass :: DFTx String
txExhausted = DFTx f
where f s = (df_txlimit s <= 0, s)
-txRemaining :: DFTx Txlimit
+txRemaining :: DFTx OptimizationFuel
txRemaining = DFTx f
where f s = (df_txlimit s, s)
-txDecrement :: String -> Txlimit -> Txlimit -> DFTx ()
+txDecrement :: String -> OptimizationFuel -> OptimizationFuel -> DFTx ()
txDecrement optimizer old new = DFTx f
where f s = ((), s { df_txlimit = lim s, df_lastpass = optimizer })
lim s = if old == df_txlimit s then new
where f _ s = ((), s {df_rewritten = SomeChange})
freshBlockId :: String -> DFM f BlockId
-freshBlockId s = liftUSM $ G.freshBlockId s
+freshBlockId _s = liftUSM $ getUniqueUs >>= return . BlockId
liftUSM :: UniqSM a -> DFM f a
liftUSM uc = DFM f
f4sep (d:ds) = fsep (d : map (nest 4) ds)
-_I_am_abstract :: Int -> Txlimit
-_I_am_abstract = Txlimit -- prevents a warning about Txlimit being unused
+_I_am_abstract :: Int -> OptimizationFuel
+_I_am_abstract = OptimizationFuel -- prevents warning: OptimizationFuel unused