Simon Jakobi pushed to branch wip/sjakobi/T27437 at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • compiler/GHC/CmmToAsm/Reg/Liveness.hs
    ... ... @@ -62,7 +62,7 @@ import GHC.Types.Unique.DSM
    62 62
     import GHC.Data.Bag
    
    63 63
     import GHC.Utils.Monad.State.Strict
    
    64 64
     
    
    65
    -import Data.List (mapAccumL, sortOn)
    
    65
    +import Data.List (sortOn)
    
    66 66
     import Data.Maybe
    
    67 67
     import Data.IntSet              (IntSet)
    
    68 68
     import GHC.Utils.Misc
    
    ... ... @@ -897,36 +897,33 @@ livenessSCCs platform blockmap done (AcyclicSCC block : sccs)
    897 897
     livenessSCCs platform blockmap done
    
    898 898
             (CyclicSCC blocks : sccs) =
    
    899 899
             livenessSCCs platform blockmap' (CyclicSCC blocks':done) sccs
    
    900
    - where      (blockmap', blocks')
    
    901
    -                = iterateUntilUnchanged linearLiveness equalBlockMaps
    
    902
    -                                      blockmap blocks
    
    900
    + where      (blockmap', blocks') = fixpoint blockmap
    
    903 901
     
    
    904
    -            iterateUntilUnchanged
    
    905
    -                :: (a -> b -> (a,c)) -> (a -> a -> Bool)
    
    906
    -                -> a -> b
    
    907
    -                -> (a,c)
    
    908
    -
    
    909
    -            iterateUntilUnchanged f eq aa b = go aa
    
    910
    -              where
    
    911
    -                go a = if eq a a' then ac else go a'
    
    912
    -                  where
    
    913
    -                    ac@(a', _) = f a b
    
    902
    +            -- Iterate the liveness pass over the SCC until the block map reaches
    
    903
    +            -- a fixed point. Only the SCC's own blocks can change between
    
    904
    +            -- iterations (livenessBlock only inserts the block it processes, and
    
    905
    +            -- earlier SCCs are already finalised).
    
    906
    +            fixpoint bm
    
    907
    +              | changed   = fixpoint bm'
    
    908
    +              | otherwise = (bm', blocks'')
    
    909
    +              where (changed, bm', blocks'') = linearLiveness bm blocks
    
    914 910
     
    
    915 911
                 linearLiveness
    
    916 912
                     :: Instruction instr
    
    917 913
                     => BlockMap Regs -> [LiveBasicBlock instr]
    
    918
    -                -> (BlockMap Regs, [LiveBasicBlock instr])
    
    919
    -
    
    920
    -            linearLiveness = mapAccumL (livenessBlock platform)
    
    921
    -
    
    922
    -                -- probably the least efficient way to compare two
    
    923
    -                -- BlockMaps for equality.
    
    924
    -            equalBlockMaps :: BlockMap Regs -> BlockMap Regs -> Bool
    
    925
    -            equalBlockMaps a b
    
    926
    -                = a' == b'
    
    927
    -              where a' = mapToList a
    
    928
    -                    b' = mapToList b
    
    929
    -                    -- See Note [Unique Determinism and code generation]
    
    914
    +                -> (Bool, BlockMap Regs, [LiveBasicBlock instr])
    
    915
    +            linearLiveness bm0 blks = go False bm0 blks
    
    916
    +              where
    
    917
    +                go !changed bm [] = (changed, bm, [])
    
    918
    +                go !changed bm (block : blks') =
    
    919
    +                  case livenessBlock platform bm block of
    
    920
    +                    (bm', block') ->
    
    921
    +                      let bid       = blockId block
    
    922
    +                          !changed' = changed
    
    923
    +                                   || mapLookup bid bm /= mapLookup bid bm'
    
    924
    +                      in case go changed' bm' blks' of
    
    925
    +                           (changed'', bm'', blks'') ->
    
    926
    +                             (changed'', bm'', block' : blks'')
    
    930 927
     
    
    931 928
     
    
    932 929