-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@(LGraph entry _) =
+ liftM (check . zdfFpFacts) (res :: FuelMonad (CmmBackwardFixedPoint CmmLive))
+ where res = zdfSolveFrom emptyBlockEnv "liveness analysis" liveLattice transfers
+ emptyUniqSet (graphOfLGraph g)
+ transfers = BackwardTransfers (flip const) mid last
+ mid m = gen_kill m . midLive m
+ last l = gen_kill l . lastLive l
+ check facts =
+ noLiveOnEntry entry (expectJust "check" $ lookupBlockEnv facts entry) facts
+
+gen_kill :: (DefinerOfLocalRegs a, UserOfLocalRegs a) => a -> CmmLive -> CmmLive
+gen_kill a = gen a . kill a
+
+middleLiveness :: Middle -> CmmLive -> CmmLive
+middleLiveness = gen_kill
+
+-- | 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)