|
|
1
|
+{-# LANGUAGE OverloadedStrings #-}
|
|
1
|
2
|
-----------------------------------------------------------------------------
|
|
2
|
3
|
--
|
|
3
|
4
|
-- Stg to C--: heap management functions
|
| ... |
... |
@@ -44,7 +45,7 @@ import GHC.Types.Id ( Id ) |
|
44
|
45
|
import GHC.Unit
|
|
45
|
46
|
import GHC.Platform
|
|
46
|
47
|
import GHC.Platform.Profile
|
|
47
|
|
-import GHC.Data.FastString( mkFastString, fsLit )
|
|
|
48
|
+import GHC.Data.FastString( FastString )
|
|
48
|
49
|
import GHC.Utils.Panic( sorry )
|
|
49
|
50
|
|
|
50
|
51
|
import Control.Monad (when)
|
| ... |
... |
@@ -125,7 +126,7 @@ allocHeapClosure rep info_ptr use_cc payload = do |
|
125
|
126
|
-- ie 1 *before* the info-ptr word of new object.
|
|
126
|
127
|
|
|
127
|
128
|
base <- getHpRelOffset info_offset
|
|
128
|
|
- emitComment $ mkFastString "allocHeapClosure"
|
|
|
129
|
+ emitComment "allocHeapClosure"
|
|
129
|
130
|
emitSetDynHdr base info_ptr use_cc
|
|
130
|
131
|
|
|
131
|
132
|
-- Fill in the fields
|
| ... |
... |
@@ -460,35 +461,41 @@ genericGC checkYield code |
|
460
|
461
|
call <- mkCall generic_gc (GC, GC) [] [] updfr_sz []
|
|
461
|
462
|
heapCheck False checkYield (call <*> mkBranch lretry) code
|
|
462
|
463
|
|
|
|
464
|
+-- | Predefined ("canned") GC functions
|
|
|
465
|
+--
|
|
|
466
|
+-- Functions have been added to cover 99% of the GC calls made in GHC and Cabal.
|
|
|
467
|
+-- See #27142.
|
|
463
|
468
|
cannedGCEntryPoint :: Platform -> [LocalReg] -> Maybe CmmExpr
|
|
464
|
|
-cannedGCEntryPoint platform regs
|
|
465
|
|
- = case map localRegType regs of
|
|
466
|
|
- [] -> Just (mkGcLabel "stg_gc_noregs")
|
|
467
|
|
- [ty]
|
|
468
|
|
- | isGcPtrType ty -> Just (mkGcLabel "stg_gc_unpt_r1")
|
|
469
|
|
- | isFloatType ty -> case width of
|
|
470
|
|
- W32 -> Just (mkGcLabel "stg_gc_f1")
|
|
471
|
|
- W64 -> Just (mkGcLabel "stg_gc_d1")
|
|
472
|
|
- _ -> Nothing
|
|
473
|
|
-
|
|
474
|
|
- | width == wordWidth platform -> Just (mkGcLabel "stg_gc_unbx_r1")
|
|
475
|
|
- | width == W64 -> Just (mkGcLabel "stg_gc_l1")
|
|
476
|
|
- | otherwise -> Nothing
|
|
477
|
|
- where
|
|
478
|
|
- width = typeWidth ty
|
|
479
|
|
- [ty1,ty2]
|
|
480
|
|
- | isGcPtrType ty1
|
|
481
|
|
- && isGcPtrType ty2 -> Just (mkGcLabel "stg_gc_pp")
|
|
482
|
|
- [ty1,ty2,ty3]
|
|
483
|
|
- | isGcPtrType ty1
|
|
484
|
|
- && isGcPtrType ty2
|
|
485
|
|
- && isGcPtrType ty3 -> Just (mkGcLabel "stg_gc_ppp")
|
|
486
|
|
- [ty1,ty2,ty3,ty4]
|
|
487
|
|
- | isGcPtrType ty1
|
|
488
|
|
- && isGcPtrType ty2
|
|
489
|
|
- && isGcPtrType ty3
|
|
490
|
|
- && isGcPtrType ty4 -> Just (mkGcLabel "stg_gc_pppp")
|
|
491
|
|
- _otherwise -> Nothing
|
|
|
469
|
+cannedGCEntryPoint platform regs =
|
|
|
470
|
+ case map localRegType regs of
|
|
|
471
|
+ [] -> ret "stg_gc_noregs"
|
|
|
472
|
+ [ty]
|
|
|
473
|
+ | is_gc ty -> ret "stg_gc_unpt_r1"
|
|
|
474
|
+ | is_f32 ty -> ret "stg_gc_f1"
|
|
|
475
|
+ | is_f64 ty -> ret "stg_gc_d1"
|
|
|
476
|
+ | is_wn ty -> ret "stg_gc_unbx_r1"
|
|
|
477
|
+ | is_w64 ty -> ret "stg_gc_l1"
|
|
|
478
|
+ [ty1,ty2]
|
|
|
479
|
+ | is_gc ty1 && is_gc ty2 -> ret "stg_gc_pp"
|
|
|
480
|
+ | is_gc ty1 && is_wn ty2 -> ret "stg_gc_pi"
|
|
|
481
|
+ | is_wn ty1 && is_gc ty2 -> ret "stg_gc_ip"
|
|
|
482
|
+ | is_wn ty1 && is_wn ty2 -> ret "stg_gc_ii"
|
|
|
483
|
+ [ty1,ty2,ty3]
|
|
|
484
|
+ | is_gc ty1 && is_gc ty2 && is_gc ty3 -> ret "stg_gc_ppp"
|
|
|
485
|
+ | is_w8 ty1 && is_gc ty2 && is_gc ty3 -> ret "stg_gc_bpp"
|
|
|
486
|
+ [ty1,ty2,ty3,ty4]
|
|
|
487
|
+ | is_gc ty1 && is_gc ty2 && is_gc ty3 && is_gc ty4 -> ret "stg_gc_pppp"
|
|
|
488
|
+ [ty1,ty2,ty3,ty4,ty5]
|
|
|
489
|
+ | is_gc ty1 && is_gc ty2 && is_gc ty3 && is_gc ty4 && is_gc ty5 -> ret "stg_gc_ppppp"
|
|
|
490
|
+ _ -> Nothing
|
|
|
491
|
+ where
|
|
|
492
|
+ ret fs = Just (mkGcLabel fs)
|
|
|
493
|
+ is_gc ty = isGcPtrType ty
|
|
|
494
|
+ is_wn ty = isBitsType ty && typeWidth ty == wordWidth platform
|
|
|
495
|
+ is_w8 ty = isBitsType ty && typeWidth ty == W8
|
|
|
496
|
+ is_w64 ty = isBitsType ty && typeWidth ty == W64
|
|
|
497
|
+ is_f32 ty = isFloatType ty && typeWidth ty == W32
|
|
|
498
|
+ is_f64 ty = isFloatType ty && typeWidth ty == W64
|
|
492
|
499
|
|
|
493
|
500
|
-- Note [stg_gc arguments]
|
|
494
|
501
|
-- ~~~~~~~~~~~~~~~~~~~~~~~
|
| ... |
... |
@@ -514,8 +521,8 @@ generic_gc :: CmmExpr |
|
514
|
521
|
generic_gc = mkGcLabel "stg_gc_noregs"
|
|
515
|
522
|
|
|
516
|
523
|
-- | Create a CLabel for calling a garbage collector entry point
|
|
517
|
|
-mkGcLabel :: String -> CmmExpr
|
|
518
|
|
-mkGcLabel s = CmmLit (CmmLabel (mkCmmCodeLabel rtsUnitId (fsLit s)))
|
|
|
524
|
+mkGcLabel :: FastString -> CmmExpr
|
|
|
525
|
+mkGcLabel s = CmmLit (CmmLabel (mkCmmCodeLabel rtsUnitId s))
|
|
519
|
526
|
|
|
520
|
527
|
-------------------------------
|
|
521
|
528
|
heapCheck :: Bool -> Bool -> CmmAGraph -> FCode a -> FCode a
|