1 {-# OPTIONS -Wall -fno-warn-name-shadowing #-}
3 -- This module contains code related to the zipcfg representation.
4 -- The code either has been used or has been thought to be useful
5 -- within the Quick C-- compiler, but as yet no use has been found for
6 -- it within GHC. This module should therefore be considered to be
7 -- full of code that need not be maintained. Should a function in
8 -- this module prove useful, it should not be exported, but rather
9 -- should be migrated back into ZipCfg (or possibly ZipCfgUtil), where
10 -- it can be maintained.
20 import Prelude hiding (zip, unzip, last)
23 exit :: LGraph m l -> FGraph m l -- focus on edge into default exit node
24 -- (fails if there isn't one)
25 focusp :: (Block m l -> Bool) -> LGraph m l -> Maybe (FGraph m l)
26 -- focus on start of block satisfying predicate
27 -- unfocus :: FGraph m l -> LGraph m l -- lose focus
29 -- | We can insert a single-entry, single-exit subgraph at
31 -- The new focus can be at either the entry edge or the exit edge.
34 splice_focus_entry :: FGraph m l -> LGraph m l -> FGraph m l
35 splice_focus_exit :: FGraph m l -> LGraph m l -> FGraph m l
39 _unused = all `seq` ()
40 where all = ( exit, focusp --, unfocus {- , splice_focus_entry, splice_focus_exit -}
41 , foldM_fwd_block (\_ a -> Just a)
44 --unfocus (FGraph e bz bs) = LGraph e (insertBlock (zip bz) bs)
46 focusp p (LGraph entry blocks) =
47 fmap (\(b, bs) -> FGraph entry (unzip b) bs) (splitp_blocks p blocks)
49 exit g@(LGraph eid _) = FGraph eid (ZBlock h (ZLast l)) others
50 where FGraph _ b others = focusp is_exit g `orElse` panic "no exit in flow graph"
55 splice_focus_entry (FGraph eid (ZBlock head tail) blocks) g =
56 let (tail', g') = splice_tail g tail in
57 FGraph eid (ZBlock head tail') (plusUFM (lg_blocks g') blocks)
59 splice_focus_exit (FGraph eid (ZBlock head tail) blocks) g =
60 let (g', head') = splice_head head g in
61 FGraph eid (ZBlock head' tail) (plusUFM (lg_blocks g') blocks)
64 -- | iterate from first to last
66 Monad m => (BlockId -> a -> m a) -> (mid -> a -> m a) -> (ZLast l -> a -> m a) ->
67 Block mid l -> a -> m a
68 foldM_fwd_block first middle last (Block id t) z = do { z <- first id z; tail t z }
69 where tail (ZTail m t) z = do { z <- middle m z; tail t z }
70 tail (ZLast l) z = last l z
72 splitp_blocks :: (Block m l -> Bool) -> BlockEnv (Block m l) ->
73 Maybe (Block m l, BlockEnv (Block m l))
74 splitp_blocks = panic "splitp_blocks" -- implemented in ZipCfg but not exported
75 is_exit :: Block m l -> Bool
76 is_exit = panic "is_exit" -- implemented in ZipCfg but not exported