X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmLiveZ.hs;h=4dc0874eb7c1c1e41920062df23113493a12672c;hb=63179a7b10069d8f69f5bceef27008c9c7fb0aa8;hp=87f6c385f341553a60eaa0238e5275ec2aea3362;hpb=8b7eaa404043294bd4cb4a0322ac1f7115bad6a0;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmLiveZ.hs b/compiler/cmm/CmmLiveZ.hs index 87f6c38..4dc0874 100644 --- a/compiler/cmm/CmmLiveZ.hs +++ b/compiler/cmm/CmmLiveZ.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -Wall -fno-warn-name-shadowing #-} + module CmmLiveZ ( CmmLive , cmmLivenessZ @@ -7,16 +7,19 @@ module CmmLiveZ ) where -import Cmm +import BlockId import CmmExpr import CmmTx import DFMonad -import Maybes +import Monad import PprCmm() import PprCmmZ() -import UniqSet +import ZipCfg import ZipDataflow -import ZipCfgCmm +import ZipCfgCmmRep + +import Maybes +import UniqSet ----------------------------------------------------------------------------- -- Calculating what variables are live on entry to a basic block @@ -36,18 +39,16 @@ liveLattice = DataflowLattice "live LocalReg's" emptyUniqSet add False type BlockEntryLiveness = BlockEnv CmmLive ----------------------------------------------------------------------------- --- | Calculated liveness info for a list of 'CmmBasicBlock' +-- | Calculated liveness info for a CmmGraph ----------------------------------------------------------------------------- -cmmLivenessZ :: CmmGraph -> BlockEntryLiveness -cmmLivenessZ g = env - where env = runDFA liveLattice $ - do run_b_anal transfer g - allFacts - transfer = BComp "liveness analysis" exit last middle first - exit = emptyUniqSet - first live _ = live - middle = flip middleLiveness - last = flip lastLiveness +cmmLivenessZ :: CmmGraph -> FuelMonad BlockEntryLiveness +cmmLivenessZ g = liftM zdfFpFacts $ (res :: FuelMonad (CmmBackwardFixedPoint CmmLive)) + where res = zdfSolveFrom emptyBlockEnv "liveness analysis" liveLattice transfers + emptyUniqSet (graphOfLGraph g) + transfers = BackwardTransfers first middle last + first live _ = live + middle = flip middleLiveness + last = flip lastLiveness -- | The transfer equations use the traditional 'gen' and 'kill' -- notations, which should be familiar from the dragon book. @@ -57,20 +58,20 @@ kill a live = foldRegsUsed delOneFromUniqSet live a middleLiveness :: Middle -> CmmLive -> CmmLive middleLiveness m = middle m - where middle (MidNop) = id - middle (MidComment {}) = id + where middle (MidComment {}) = id middle (MidAssign lhs expr) = gen expr . kill lhs middle (MidStore addr rval) = gen addr . gen rval middle (MidUnsafeCall tgt ress args) = gen tgt . gen args . kill ress + middle (MidAddToContext ra args) = gen ra . gen args middle (CopyIn _ formals _) = kill formals - middle (CopyOut _ formals) = gen formals + middle (CopyOut _ actuals) = gen actuals lastLiveness :: Last -> (BlockId -> CmmLive) -> CmmLive lastLiveness l env = last l - where last (LastReturn ress) = gen ress emptyUniqSet - last (LastJump e args) = gen e $ gen args emptyUniqSet - last (LastBranch id args) = gen args $ env id - last (LastCall tgt args (Just k)) = gen tgt $ gen args $ env k - last (LastCall tgt args Nothing) = gen tgt $ gen args $ emptyUniqSet - last (LastCondBranch e t f) = gen e $ unionUniqSets (env t) (env f) + where last (LastReturn) = emptyUniqSet + last (LastJump e) = gen e $ emptyUniqSet + last (LastBranch id) = env id + last (LastCall tgt (Just k)) = gen tgt $ env k + last (LastCall tgt Nothing) = gen tgt $ emptyUniqSet + last (LastCondBranch e t f) = gen e $ unionUniqSets (env t) (env f) last (LastSwitch e tbl) = gen e $ unionManyUniqSets $ map env (catMaybes tbl)