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

Commits:

2 changed files:

Changes:

  • compiler/GHC/Cmm/Dataflow/Label.hs
    ... ... @@ -35,7 +35,6 @@ module GHC.Cmm.Dataflow.Label
    35 35
         , mapEmpty
    
    36 36
         , mapSingleton
    
    37 37
         , mapInsert
    
    38
    -    , mapInsertLookup
    
    39 38
         , mapInsertWith
    
    40 39
         , mapDelete
    
    41 40
         , mapAlter
    
    ... ... @@ -200,13 +199,6 @@ mapSingleton (Label k) v = LM (M.singleton k v)
    200 199
     mapInsert :: Label -> v -> LabelMap v -> LabelMap v
    
    201 200
     mapInsert (Label k) v (LM m) = LM (M.insert k v m)
    
    202 201
     
    
    203
    --- | Insert a value, also returning the value previously bound to the key (if
    
    204
    --- any). Fuses the insert and lookup into a single traversal of the map.
    
    205
    -mapInsertLookup :: Label -> v -> LabelMap v -> (Maybe v, LabelMap v)
    
    206
    -mapInsertLookup (Label k) v (LM m) =
    
    207
    -  case M.insertLookupWithKey (\_ new _ -> new) k v m of
    
    208
    -    (old, m') -> (old, LM m')
    
    209
    -
    
    210 202
     mapInsertWith :: (v -> v -> v) -> Label -> v -> LabelMap v -> LabelMap v
    
    211 203
     mapInsertWith f (Label k) v (LM m) = LM (M.insertWith f k v m)
    
    212 204
     
    

  • compiler/GHC/CmmToAsm/Reg/Liveness.hs
    ... ... @@ -891,7 +891,7 @@ livenessSCCs _ blockmap done []
    891 891
             = (done, blockmap)
    
    892 892
     
    
    893 893
     livenessSCCs platform blockmap done (AcyclicSCC block : sccs)
    
    894
    - = let  (_, blockmap', block')  = livenessBlock platform blockmap block
    
    894
    + = let  (blockmap', block')     = livenessBlock platform blockmap block
    
    895 895
        in   livenessSCCs platform blockmap' (AcyclicSCC block' : done) sccs
    
    896 896
     
    
    897 897
     livenessSCCs platform blockmap done
    
    ... ... @@ -909,9 +909,8 @@ livenessSCCs platform blockmap done
    909 909
                   | otherwise = (bm', blocks'')
    
    910 910
                   where (changed, bm', blocks'') = linearLiveness bm blocks
    
    911 911
     
    
    912
    -            -- Like @mapAccumL (livenessBlock platform)@, but also OR's together
    
    913
    -            -- the per-block changed flags reported by livenessBlock, so the
    
    914
    -            -- caller can detect the fixed point without comparing block maps.
    
    912
    +            -- Like @mapAccumL (livenessBlock platform)@, but also reports whether
    
    913
    +            -- any of the SCC's blocks changed.
    
    915 914
                 linearLiveness
    
    916 915
                     :: Instruction instr
    
    917 916
                     => BlockMap Regs -> [LiveBasicBlock instr]
    
    ... ... @@ -921,8 +920,10 @@ livenessSCCs platform blockmap done
    921 920
                     go !changed bm [] = (changed, bm, [])
    
    922 921
                     go !changed bm (block : blks') =
    
    923 922
                       case livenessBlock platform bm block of
    
    924
    -                    (blockChanged, bm', block') ->
    
    925
    -                      let !changed' = changed || blockChanged
    
    923
    +                    (bm', block') ->
    
    924
    +                      let bid       = blockId block
    
    925
    +                          !changed' = changed
    
    926
    +                                   || mapLookup bid bm /= mapLookup bid bm'
    
    926 927
                           in case go changed' bm' blks' of
    
    927 928
                                (changed'', bm'', blks'') ->
    
    928 929
                                  (changed'', bm'', block' : blks'')
    
    ... ... @@ -935,23 +936,19 @@ livenessBlock
    935 936
             => Platform
    
    936 937
             -> BlockMap Regs
    
    937 938
             -> LiveBasicBlock instr
    
    938
    -        -> (Bool, BlockMap Regs, LiveBasicBlock instr)
    
    939
    +        -> (BlockMap Regs, LiveBasicBlock instr)
    
    939 940
     
    
    940 941
     livenessBlock platform blockmap (BasicBlock block_id instrs)
    
    941 942
      = let
    
    942 943
             (regsLiveOnEntry, instrs1)
    
    943 944
                 = livenessBack platform noRegs blockmap [] (reverse instrs)
    
    944
    -        -- Fuse the insert with the lookup of the old entry, so the fixpoint
    
    945
    -        -- loop in livenessSCCs can tell whether this block changed for free,
    
    946
    -        -- without a separate map traversal.
    
    947
    -        (oldEntry, blockmap') = mapInsertLookup block_id regsLiveOnEntry blockmap
    
    948
    -        changed         = oldEntry /= Just regsLiveOnEntry
    
    945
    +        blockmap'       = mapInsert block_id regsLiveOnEntry blockmap
    
    949 946
     
    
    950 947
             instrs2         = livenessForward platform regsLiveOnEntry instrs1
    
    951 948
     
    
    952 949
             output          = BasicBlock block_id instrs2
    
    953 950
     
    
    954
    -   in   (changed, blockmap', output)
    
    951
    +   in   ( blockmap', output)
    
    955 952
     
    
    956 953
     -- | Calculate liveness going forwards,
    
    957 954
     --   filling in when regs are born