Changes between Version 18 and Version 19 of Commentary/Compiler/CPS


Ignore:
Timestamp:
Jul 5, 2007 11:05:46 AM (8 years ago)
Author:
Michael D. Adams
Comment:

Added notes about handling GC

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/CPS

    v18 v19  
    369369
    370370In the future it would be nice to have a more satisfactory way to handle both these issues.
     371
     372== Notes on future development ==
     373=== Handling GC ===
     374{{{
     375stg_gc_gen        = mkRtsApFastLabel SLIT("stg_gc_gen")
     376
     377stg_gc_fun_v      = mkRtsApFastLabel SLIT("stg_gc_fun_v")
     378stg_gc_fun_n      = mkRtsApFastLabel SLIT("stg_gc_fun_n")
     379stg_gc_fun_f      = mkRtsApFastLabel SLIT("stg_gc_fun_f")
     380stg_gc_fun_d      = mkRtsApFastLabel SLIT("stg_gc_fun_d")
     381stg_gc_fun_l      = mkRtsApFastLabel SLIT("stg_gc_fun_l")
     382stg_gc_fun_p      = mkRtsApFastLabel SLIT("stg_gc_fun_p")
     383stg_gc_fun_pp     = mkRtsApFastLabel SLIT("stg_gc_fun_pp")
     384stg_gc_fun_ppp    = mkRtsApFastLabel SLIT("stg_gc_fun_ppp")
     385stg_gc_fun_pppp   = mkRtsApFastLabel SLIT("stg_gc_fun_pppp")
     386stg_gc_fun_ppppp  = mkRtsApFastLabel SLIT("stg_gc_fun_ppppp")
     387stg_gc_fun_pppppp = mkRtsApFastLabel SLIT("stg_gc_fun_pppppp")
     388
     389stg_gc_ret_v      = stg_gc_gen -- Conceptually different but practically the same
     390stg_gc_ret_n      = mkRtsApFastLabel SLIT("stg_gc_ret_n")
     391stg_gc_ret_f      = mkRtsApFastLabel SLIT("stg_gc_ret_f")
     392stg_gc_ret_d      = mkRtsApFastLabel SLIT("stg_gc_ret_d")
     393stg_gc_ret_l      = mkRtsApFastLabel SLIT("stg_gc_ret_l")
     394stg_gc_ret_p      = mkRtsApFastLabel SLIT("stg_gc_ret_p")
     395stg_gc_ret_pp     = mkRtsApFastLabel SLIT("stg_gc_ret_pp")
     396stg_gc_ret_ppp    = mkRtsApFastLabel SLIT("stg_gc_ret_ppp")
     397stg_gc_ret_pppp   = mkRtsApFastLabel SLIT("stg_gc_ret_pppp")
     398stg_gc_ret_ppppp  = mkRtsApFastLabel SLIT("stg_gc_ret_ppppp")
     399stg_gc_ret_pppppp = mkRtsApFastLabel SLIT("stg_gc_ret_pppppp")
     400
     401call stg_gc_fun_gen() -> stg_gc_gen
     402jump stg_gc_fun_v(f')
     403jump stg_gc_fun_p(f', p)
     404jump stg_gc_fun_n(f', n)
     405
     406gcFunPattern []                        = Just stg_gc_fun_v
     407gcFunPattern [x]
     408  | isNonPtr x && matchRep x NonPtrArg = Just stg_gc_fun_n
     409  | isNonPtr x && matchRep x LongArg   = Just stg_gc_fun_l
     410  | isNonPtr x && matchRep x FloatArg  = Just stg_gc_fun_f
     411  | isNonPtr x && matchRep x DoubleArg = Just stg_gc_fun_d
     412gcFunPattern xs
     413  | all (\x -> isPtr x && matchRep x PtrArg)
     414  = case length xs of
     415      1 -> Just stg_gc_fun_p
     416      2 -> Just stg_gc_fun_pp
     417      3 -> Just stg_gc_fun_ppp
     418      4 -> Just stg_gc_fun_pppp
     419      5 -> Just stg_gc_fun_ppppp
     420      6 -> Just stg_gc_fun_pppppp
     421      _ -> Nothing
     422gcFunPattern xs = Nothing
     423
     424case gcFunPattern formals of
     425  Nothing -> [stg_gc_gen_call srt, CmmJump target formals]
     426  Just gc -> [stg_gc_fun_spec_jump gc formals]
     427
     428stg_gc_gen_call srt =
     429  CmmCall (CmmForeignCall (CmmLit (CmmLabel stg_gc_gen)) CmmCallConv)
     430          [] [] (CmmSafe srt)
     431stg_gc_fun_spec_jump gc formals =
     432  CmmJump (CmmLit (CmmLabel gc)) (map formal_to_actual formals)
     433
     434isNonPtr x = kind x == KindNonPtr
     435matchRep x rep = localRep x == argMachrep rep
     436
     437call stg_gc_ret_gen() -> stg_gc_gen
     438call stg_gc_ret_v() -> stg_gc_gen
     439call p = stg_gc_ret_p(p)
     440call n = stg_gc_ret_n(n)
     441}}}
     442
     443
     444{{{
     445hpStkCheck:
     446    rts_label | is_fun    = CmmReg (CmmGlobal GCFun)
     447                                -- Function entry point
     448              | otherwise = CmmReg (CmmGlobal GCEnter1)
     449                                -- Thunk or case return
     450        -- In the thunk/case-return case, R1 points to a closure
     451        -- which should be (re)-entered after GC
     452
     453altHeapCheck:
     454    rts_label PolyAlt = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_unpt_r1")))
     455        -- Do *not* enter R1 after a heap check in
     456        -- a polymorphic case.  It might be a function
     457        -- and the entry code for a function (currently)
     458        -- applies it
     459        --
     460        -- However R1 is guaranteed to be a pointer
     461
     462    rts_label (AlgAlt tc) = stg_gc_enter1
     463        -- Enter R1 after the heap check; it's a pointer
     464       
     465    rts_label (PrimAlt tc)
     466      = CmmLit $ CmmLabel $
     467        case primRepToCgRep (tyConPrimRep tc) of
     468          VoidArg   -> mkRtsCodeLabel SLIT( "stg_gc_noregs")
     469          FloatArg  -> mkRtsCodeLabel SLIT( "stg_gc_f1")
     470          DoubleArg -> mkRtsCodeLabel SLIT( "stg_gc_d1")
     471          LongArg   -> mkRtsCodeLabel SLIT( "stg_gc_l1")
     472                                -- R1 is boxed but unlifted:
     473          PtrArg    -> mkRtsCodeLabel SLIT( "stg_gc_unpt_r1")
     474                                -- R1 is unboxed:
     475          NonPtrArg -> mkRtsCodeLabel SLIT( "stg_gc_unbx_r1")
     476
     477    rts_label (UbxTupAlt _) = panic "altHeapCheck"
     478
     479unbxTupleHeapCheck:
     480    rts_label       = CmmLit (CmmLabel (mkRtsCodeLabel SLIT("stg_gc_ut")))
     481
     482hpChkGen:
     483  stg_gc_gen
     484
     485hpChkNodePointsAssignSp0:
     486-- a heap check where R1 points to the closure to enter on return, and
     487-- we want to assign to Sp[0] on failure (used in AutoApply.cmm:BUILD_PAP).
     488  stg_gc_enter1
     489
     490stkChkGen:
     491  stg_gc_gen
     492
     493stkChkNodePoints:
     494  stg_gc_enter1
     495
     496--------
     497-- hpStkCheck (is_fun)
     498stg_gc_fun = CmmReg (CmmGlobal GCFun)
     499-- hpStkCheck (no is_fun), altHeapCheck (AlgAlt), hpChkNodePointsAssignSp0, stkChkNodePoints
     500stg_gc_enter1 = CmmReg (CmmGlobal GCEnter1)
     501-- hpChkGen, stkChkGen
     502stg_gc_gen = CmmLit (CmmLabel (mkRtsCodeLabel SLIT("stg_gc_gen")))
     503-- unbxTupleHeapCheck
     504stg_gc_ut = CmmLit (CmmLabel (mkRtsCodeLabel SLIT("stg_gc_ut")))
     505
     506-- altHeapCheck (PrimAlt)
     507--  VoidArg
     508stg_gc_noregs = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_noregs")))
     509--  FloatArg
     510stg_gc_f1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_f1")))
     511--  DoubleArg
     512stg_gc_d1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_d1")))
     513--  LongArg
     514stg_gc_l1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_l1")))
     515--  PtrArg and PolyAlt
     516stg_gc_unpt_r1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_unpt_r1")))
     517--  NonPtrArg
     518stg_gc_unbx_r1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_unbx_r1")))
     519}}}