X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmLiveZ.hs;h=70bd51b0fde0440ec07ed5d5b4c9f4514ea18593;hb=da300d714ef9d807933e06c202a5898864734b5a;hp=b239ae37115621e666d5a953e5a70a86a17731e8;hpb=176fa33f17dd78355cc572e006d2ab26898e2c69;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmLiveZ.hs b/compiler/cmm/CmmLiveZ.hs index b239ae3..70bd51b 100644 --- a/compiler/cmm/CmmLiveZ.hs +++ b/compiler/cmm/CmmLiveZ.hs @@ -3,7 +3,7 @@ module CmmLiveZ ( CmmLive , cmmLivenessZ , liveLattice - , middleLiveness, lastLiveness + , middleLiveness, lastLiveness, noLiveOnEntry ) where @@ -19,6 +19,7 @@ import ZipDataflow import ZipCfgCmmRep import Maybes +import Outputable import UniqSet ----------------------------------------------------------------------------- @@ -42,13 +43,22 @@ type BlockEntryLiveness = BlockEnv CmmLive -- | Calculated liveness info for a CmmGraph ----------------------------------------------------------------------------- cmmLivenessZ :: CmmGraph -> FuelMonad BlockEntryLiveness -cmmLivenessZ g = liftM zdfFpFacts $ (res :: FuelMonad (CmmBackwardFixedPoint CmmLive)) +cmmLivenessZ g@(LGraph entry _ _) = + liftM (check . 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 + check facts = + noLiveOnEntry entry (expectJust "check" $ lookupBlockEnv facts entry) facts + +-- | On entry to the procedure, there had better not be any LocalReg's live-in. +noLiveOnEntry :: BlockId -> CmmLive -> a -> a +noLiveOnEntry bid in_fact x = + if isEmptyUniqSet in_fact then x + else pprPanic "LocalReg's live-in to graph" (ppr bid <+> ppr in_fact) -- | The transfer equations use the traditional 'gen' and 'kill' -- notations, which should be familiar from the dragon book. @@ -56,20 +66,18 @@ gen, kill :: UserOfLocalRegs a => a -> RegSet -> RegSet gen a live = foldRegsUsed extendRegSet live a kill a live = foldRegsUsed delOneFromUniqSet live a +-- Why aren't these function using the typeclasses on Middle and Last? middleLiveness :: Middle -> CmmLive -> CmmLive -middleLiveness m = middle m - 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 +middleLiveness (MidComment {}) live = live +middleLiveness (MidAssign lhs expr) live = gen expr $ kill lhs live +middleLiveness (MidStore addr rval) live = gen addr $ gen rval live +middleLiveness (MidForeignCall _ tgt _ args) _ = gen tgt $ gen args emptyUniqSet lastLiveness :: Last -> (BlockId -> CmmLive) -> CmmLive lastLiveness l env = last l - 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) + where last (LastBranch id) = env id + last (LastCall tgt Nothing _ _) = gen tgt $ emptyUniqSet + last (LastCall tgt (Just k) _ _) = gen tgt $ env k + last (LastCondBranch e t f) = gen e $ unionUniqSets (env t) (env f) + last (LastSwitch e tbl) = + gen e $ unionManyUniqSets $ map env (catMaybes tbl)