| | 371 | |
| | 372 | == Notes on future development == |
| | 373 | === Handling GC === |
| | 374 | {{{ |
| | 375 | stg_gc_gen = mkRtsApFastLabel SLIT("stg_gc_gen") |
| | 376 | |
| | 377 | stg_gc_fun_v = mkRtsApFastLabel SLIT("stg_gc_fun_v") |
| | 378 | stg_gc_fun_n = mkRtsApFastLabel SLIT("stg_gc_fun_n") |
| | 379 | stg_gc_fun_f = mkRtsApFastLabel SLIT("stg_gc_fun_f") |
| | 380 | stg_gc_fun_d = mkRtsApFastLabel SLIT("stg_gc_fun_d") |
| | 381 | stg_gc_fun_l = mkRtsApFastLabel SLIT("stg_gc_fun_l") |
| | 382 | stg_gc_fun_p = mkRtsApFastLabel SLIT("stg_gc_fun_p") |
| | 383 | stg_gc_fun_pp = mkRtsApFastLabel SLIT("stg_gc_fun_pp") |
| | 384 | stg_gc_fun_ppp = mkRtsApFastLabel SLIT("stg_gc_fun_ppp") |
| | 385 | stg_gc_fun_pppp = mkRtsApFastLabel SLIT("stg_gc_fun_pppp") |
| | 386 | stg_gc_fun_ppppp = mkRtsApFastLabel SLIT("stg_gc_fun_ppppp") |
| | 387 | stg_gc_fun_pppppp = mkRtsApFastLabel SLIT("stg_gc_fun_pppppp") |
| | 388 | |
| | 389 | stg_gc_ret_v = stg_gc_gen -- Conceptually different but practically the same |
| | 390 | stg_gc_ret_n = mkRtsApFastLabel SLIT("stg_gc_ret_n") |
| | 391 | stg_gc_ret_f = mkRtsApFastLabel SLIT("stg_gc_ret_f") |
| | 392 | stg_gc_ret_d = mkRtsApFastLabel SLIT("stg_gc_ret_d") |
| | 393 | stg_gc_ret_l = mkRtsApFastLabel SLIT("stg_gc_ret_l") |
| | 394 | stg_gc_ret_p = mkRtsApFastLabel SLIT("stg_gc_ret_p") |
| | 395 | stg_gc_ret_pp = mkRtsApFastLabel SLIT("stg_gc_ret_pp") |
| | 396 | stg_gc_ret_ppp = mkRtsApFastLabel SLIT("stg_gc_ret_ppp") |
| | 397 | stg_gc_ret_pppp = mkRtsApFastLabel SLIT("stg_gc_ret_pppp") |
| | 398 | stg_gc_ret_ppppp = mkRtsApFastLabel SLIT("stg_gc_ret_ppppp") |
| | 399 | stg_gc_ret_pppppp = mkRtsApFastLabel SLIT("stg_gc_ret_pppppp") |
| | 400 | |
| | 401 | call stg_gc_fun_gen() -> stg_gc_gen |
| | 402 | jump stg_gc_fun_v(f') |
| | 403 | jump stg_gc_fun_p(f', p) |
| | 404 | jump stg_gc_fun_n(f', n) |
| | 405 | |
| | 406 | gcFunPattern [] = Just stg_gc_fun_v |
| | 407 | gcFunPattern [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 |
| | 412 | gcFunPattern 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 |
| | 422 | gcFunPattern xs = Nothing |
| | 423 | |
| | 424 | case gcFunPattern formals of |
| | 425 | Nothing -> [stg_gc_gen_call srt, CmmJump target formals] |
| | 426 | Just gc -> [stg_gc_fun_spec_jump gc formals] |
| | 427 | |
| | 428 | stg_gc_gen_call srt = |
| | 429 | CmmCall (CmmForeignCall (CmmLit (CmmLabel stg_gc_gen)) CmmCallConv) |
| | 430 | [] [] (CmmSafe srt) |
| | 431 | stg_gc_fun_spec_jump gc formals = |
| | 432 | CmmJump (CmmLit (CmmLabel gc)) (map formal_to_actual formals) |
| | 433 | |
| | 434 | isNonPtr x = kind x == KindNonPtr |
| | 435 | matchRep x rep = localRep x == argMachrep rep |
| | 436 | |
| | 437 | call stg_gc_ret_gen() -> stg_gc_gen |
| | 438 | call stg_gc_ret_v() -> stg_gc_gen |
| | 439 | call p = stg_gc_ret_p(p) |
| | 440 | call n = stg_gc_ret_n(n) |
| | 441 | }}} |
| | 442 | |
| | 443 | |
| | 444 | {{{ |
| | 445 | hpStkCheck: |
| | 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 | |
| | 453 | altHeapCheck: |
| | 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 | |
| | 479 | unbxTupleHeapCheck: |
| | 480 | rts_label = CmmLit (CmmLabel (mkRtsCodeLabel SLIT("stg_gc_ut"))) |
| | 481 | |
| | 482 | hpChkGen: |
| | 483 | stg_gc_gen |
| | 484 | |
| | 485 | hpChkNodePointsAssignSp0: |
| | 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 | |
| | 490 | stkChkGen: |
| | 491 | stg_gc_gen |
| | 492 | |
| | 493 | stkChkNodePoints: |
| | 494 | stg_gc_enter1 |
| | 495 | |
| | 496 | -------- |
| | 497 | -- hpStkCheck (is_fun) |
| | 498 | stg_gc_fun = CmmReg (CmmGlobal GCFun) |
| | 499 | -- hpStkCheck (no is_fun), altHeapCheck (AlgAlt), hpChkNodePointsAssignSp0, stkChkNodePoints |
| | 500 | stg_gc_enter1 = CmmReg (CmmGlobal GCEnter1) |
| | 501 | -- hpChkGen, stkChkGen |
| | 502 | stg_gc_gen = CmmLit (CmmLabel (mkRtsCodeLabel SLIT("stg_gc_gen"))) |
| | 503 | -- unbxTupleHeapCheck |
| | 504 | stg_gc_ut = CmmLit (CmmLabel (mkRtsCodeLabel SLIT("stg_gc_ut"))) |
| | 505 | |
| | 506 | -- altHeapCheck (PrimAlt) |
| | 507 | -- VoidArg |
| | 508 | stg_gc_noregs = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_noregs"))) |
| | 509 | -- FloatArg |
| | 510 | stg_gc_f1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_f1"))) |
| | 511 | -- DoubleArg |
| | 512 | stg_gc_d1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_d1"))) |
| | 513 | -- LongArg |
| | 514 | stg_gc_l1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_l1"))) |
| | 515 | -- PtrArg and PolyAlt |
| | 516 | stg_gc_unpt_r1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_unpt_r1"))) |
| | 517 | -- NonPtrArg |
| | 518 | stg_gc_unbx_r1 = CmmLit (CmmLabel (mkRtsCodeLabel SLIT( "stg_gc_unbx_r1"))) |
| | 519 | }}} |