Simon Jakobi pushed to branch wip/sjakobi/cmm-unreachable-blocks-docs at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • compiler/GHC/Cmm.hs
    ... ... @@ -154,7 +154,7 @@ toBlockMap (CmmGraph {g_graph=GMany NothingO body NothingO}) = body
    154 154
     -- | Print the blocks reachable from the entry, in reverse postorder.
    
    155 155
     --
    
    156 156
     -- Under @-dppr-debug@ the unreachable blocks stored in the graph are appended
    
    157
    --- too. See Note [unreachable blocks] in "GHC.Cmm.Pipeline".
    
    157
    +-- too. See Note [Unreachable blocks] in "GHC.Cmm.Pipeline".
    
    158 158
     pprCmmGraph :: Platform -> CmmGraph -> SDoc
    
    159 159
     pprCmmGraph platform g
    
    160 160
        = text "{" <> text "offset"
    

  • compiler/GHC/Cmm/ContFlowOpt.hs
    ... ... @@ -338,11 +338,9 @@ blockConcat splitting_procs g@CmmGraph { g_entry = entry_id }
    338 338
     -- Functions for incrementing and decrementing number of predecessors. If
    
    339 339
     -- decrementing would set the predecessor count to 0, we remove entry from the
    
    340 340
     -- map.
    
    341
    --- Invariant: if a block has no predecessors it should be dropped from the
    
    342
    --- graph because it is unreachable. maybe_concat is constructed to maintain
    
    343
    --- that invariant, but calling replaceLabels may introduce unreachable blocks.
    
    344
    --- We rely on subsequent passes in the Cmm pipeline to remove unreachable
    
    345
    --- blocks.
    
    341
    +-- A block whose predecessor count drops to 0 is unreachable, but stays in the
    
    342
    +-- graph. We rely on subsequent passes in the Cmm pipeline to remove
    
    343
    +-- unreachable blocks.
    
    346 344
     incPreds, decPreds :: BlockId -> LabelMap Int -> LabelMap Int
    
    347 345
     incPreds bid edges = mapInsertWith (+) bid 1 edges
    
    348 346
     decPreds bid edges = case mapLookup bid edges of
    

  • compiler/GHC/Cmm/Pipeline.hs
    ... ... @@ -173,7 +173,7 @@ cpsTop logger platform cfg dus proc =
    173 173
                         then map (cmmCfgOptsProc splitting_proc_points) g
    
    174 174
                         else g
    
    175 175
           g <- return $ map (removeUnreachableBlocksProc platform) g
    
    176
    -           -- See Note [unreachable blocks]
    
    176
    +           -- See Note [Unreachable blocks]
    
    177 177
           dumps Opt_D_dump_cmm_cfg "Post control-flow optimisations (2)" g
    
    178 178
     
    
    179 179
           return (dus, Left (cafEnv, g))
    
    ... ... @@ -351,13 +351,19 @@ _GLOBAL_OFFSET_TABLE_, regardless of which entry point we arrived via.
    351 351
     
    
    352 352
     -}
    
    353 353
     
    
    354
    -{- Note [unreachable blocks]
    
    354
    +{- Note [Unreachable blocks]
    
    355 355
        ~~~~~~~~~~~~~~~~~~~~~~~~~
    
    356 356
     The control-flow optimiser sometimes leaves unreachable blocks behind
    
    357 357
     containing junk code.  These aren't necessarily a problem, but
    
    358 358
     removing them is good because it might save time in the native code
    
    359 359
     generator later.
    
    360 360
     
    
    361
    +Stack layout drops them as a side effect of rebuilding the graph from
    
    362
    +revPostorder, so the passes between control-flow optimisation and stack
    
    363
    +layout may encounter them.  removeUnreachableBlocksProc at the end of
    
    364
    +cpsTop removes the blocks orphaned by the second round of control-flow
    
    365
    +optimisation, along with their info tables.
    
    366
    +
    
    361 367
     To make unreachable blocks visible in -ddump-cmm-* output, add -dppr-debug.
    
    362 368
     -}
    
    363 369
     
    

  • compiler/GHC/CmmToAsm/Reg/Linear.hs
    ... ... @@ -311,10 +311,6 @@ process entry_ids block_live =
    311 311
     
    
    312 312
         go [] next_round accum madeProgress
    
    313 313
           | not madeProgress
    
    314
    -          {- BUGS: There are so many unreachable blocks in the code the warnings are overwhelming.
    
    315
    -             pprTrace "RegAlloc.Linear.Main.process: no progress made, bailing out."
    
    316
    -                (  text "Unreachable blocks:"
    
    317
    -                $$ vcat (map ppr next_round)) -}
    
    318 314
           = return $ reverse accum
    
    319 315
     
    
    320 316
           | otherwise
    
    ... ... @@ -861,12 +857,9 @@ allocateRegsAndSpill reading keep spills alloc (r@(VirtualRegWithFormat vr vrFmt
    861 857
                        | otherwise -> doSpill WriteMem
    
    862 858
                     Nothing | reading   ->
    
    863 859
                        pprPanic "allocateRegsAndSpill: Cannot read from uninitialized register" (ppr vr)
    
    864
    -                   -- NOTE: if the input to the NCG contains some
    
    865
    -                   -- unreachable blocks with junk code, this panic
    
    866
    -                   -- might be triggered.  Make sure you only feed
    
    867
    -                   -- sensible code into the NCG.  In GHC.Cmm.Pipeline we
    
    868
    -                   -- call removeUnreachableBlocks at the end for this
    
    869
    -                   -- reason.
    
    860
    +                   -- NOTE: unreachable blocks with junk code could
    
    861
    +                   -- trigger this panic, so sccBlocks in
    
    862
    +                   -- GHC.CmmToAsm.Reg.Liveness discards them (#7574).
    
    870 863
     
    
    871 864
                             | otherwise -> doSpill WriteNew
    
    872 865