[GHC] #8326: Place heap checks common in case alternatives before the case

GHC ghc-devs at haskell.org
Tue Aug 4 19:48:07 UTC 2015


#8326: Place heap checks common in case alternatives before the case
-------------------------------------+-------------------------------------
        Reporter:  jstolarek         |                   Owner:
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.7
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |               Test Case:
      Blocked By:                    |                Blocking:  8317
 Related Tickets:  #1498             |  Differential Revisions:  Phab:D343
-------------------------------------+-------------------------------------

Comment (by bgamari):

 Simon, indeed tying the knot would at very least require that two labels
 be unconditionally allocated and carried rather deeply into `StgCmmHeap`.

 Another issue is `heapCheck`, which is itself monadic as it ends up
 calling `getHeapUsage`. My initial thought was that `maybeAltHeapCheck`
 could look something like,

 {{{#!hs
 maybeAltHeapCheck :: (GcPlan,ReturnKind) -> FCode a -> FCode a
 maybeAltHeapCheck gc_plan code = do
   label1 <- allocLabelC
   label2 <- allocLabelC
   getHeapUsage $ \hpHw -> do
     emit $ case gc_plan of
       (NoGcInAlts, _)                      -> emptyOL
       (GcInAlts regs, AssignedDirectly)    -> ...
       (GcInAlts regs, ReturnedTo lref off) -> ...
     code
 }}}

 Unfortunately this becomes quite invasive as you must pass those labels
 and the `CgInfoDownwards` pretty deeply into `StgCmmHeap`. It may be that
 a refactoring will help here but it seems a bit messy.

 In summary, as far as I can see there are several paths through the case
 alternative heap-check code (the code path column below shows the number
 of `newLabelC`s appearing in each function in parentheses),

 ||= `gc_plan`  =||= `ret_kind`       =||= canned entrypt =||= labels
 needed =||= code path          =||
 || `NoGcInAlts` || *                  || *                || 0
 || just run the code    ||
 || `GcInAlts`   || `AssignedDirectly` || no               || 1
 || `altOrNoEscapeHeapCheck` -> `genericGC` (1)      ||
 || `GcInAlts`   || `AssignedDirectly` || yes              || 2
 || `altOrNoEscapeHeapCheck` (2) -> `cannedGCReturnsTo` -> `heapCheck` ||
 || `GcInAlts`   || `ReturnedTo`       || no               || 1
 || `altHeapCheckReturnsTo` -> `genericGC` (1) -> `heapCheck` ||
 || `GcInAlts`   || `ReturnedTo`       || yes              || 0
 || `altHeapCheckReturnsTo` -> `cannedGCReturnsTo`  -> `heapCheck` ||

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8326#comment:29>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list