module GHC.StgToCmm.Bind (
cgTopRhsClosure,
cgBind,
emitBlackHoleCode,
pushUpdateFrame, emitUpdateFrame
) where
import GHC.Prelude hiding ((<*>))
import GHC.Platform
import GHC.StgToCmm.Expr
import GHC.StgToCmm.Monad
import GHC.StgToCmm.Env
import GHC.StgToCmm.DataCon
import GHC.StgToCmm.Heap
import GHC.StgToCmm.Prof (ldvEnterClosure, enterCostCentreFun, enterCostCentreThunk,
initUpdFrameProf)
import GHC.StgToCmm.Ticky
import GHC.StgToCmm.Layout
import GHC.StgToCmm.Utils
import GHC.StgToCmm.Closure
import GHC.StgToCmm.Foreign (emitPrimCall)
import GHC.Cmm.Graph
import GHC.Core ( AltCon(..), tickishIsCode )
import GHC.Cmm.BlockId
import GHC.Runtime.Heap.Layout
import GHC.Cmm
import GHC.Cmm.Info
import GHC.Cmm.Utils
import GHC.Cmm.CLabel
import GHC.Stg.Syntax
import GHC.Types.CostCentre
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Types.Name
import GHC.Unit.Module
import GHC.Data.List.SetOps
import GHC.Utils.Misc
import GHC.Types.Var.Set
import GHC.Types.Basic
import GHC.Utils.Outputable
import GHC.Data.FastString
import GHC.Driver.Session
import Control.Monad
cgTopRhsClosure :: DynFlags
-> RecFlag
-> Id
-> CostCentreStack
-> UpdateFlag
-> [Id]
-> CgStgExpr
-> (CgIdInfo, FCode ())
cgTopRhsClosure :: DynFlags
-> RecFlag
-> Id
-> CostCentreStack
-> UpdateFlag
-> [Id]
-> CgStgExpr
-> (CgIdInfo, FCode ())
cgTopRhsClosure DynFlags
dflags RecFlag
rec Id
id CostCentreStack
ccs UpdateFlag
upd_flag [Id]
args CgStgExpr
body =
let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
closure_label :: CLabel
closure_label = Name -> CafInfo -> CLabel
mkLocalClosureLabel (Id -> Name
idName Id
id) (Id -> CafInfo
idCafInfo Id
id)
cg_id_info :: CgIdInfo
cg_id_info = DynFlags -> Id -> LambdaFormInfo -> CmmLit -> CgIdInfo
litIdInfo DynFlags
dflags Id
id LambdaFormInfo
lf_info (CLabel -> CmmLit
CmmLabel CLabel
closure_label)
lf_info :: LambdaFormInfo
lf_info = Platform
-> Id
-> TopLevelFlag
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> LambdaFormInfo
mkClosureLFInfo Platform
platform Id
id TopLevelFlag
TopLevel [] UpdateFlag
upd_flag [Id]
args
in (CgIdInfo
cg_id_info, DynFlags -> LambdaFormInfo -> CLabel -> FCode ()
gen_code DynFlags
dflags LambdaFormInfo
lf_info CLabel
closure_label)
where
gen_code :: DynFlags -> LambdaFormInfo -> CLabel -> FCode ()
gen_code DynFlags
_ LambdaFormInfo
_ CLabel
closure_label
| StgApp Id
f [] <- CgStgExpr
body, [Id] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Id]
args, RecFlag -> Bool
isNonRec RecFlag
rec
= do
CgIdInfo
cg_info <- Id -> FCode CgIdInfo
getCgIdInfo Id
f
CLabel -> CmmInfoTable -> CostCentreStack -> [CmmLit] -> FCode ()
emitDataCon CLabel
closure_label CmmInfoTable
indStaticInfoTable CostCentreStack
ccs [CmmExpr -> CmmLit
unLit (CgIdInfo -> CmmExpr
idInfoToAmode CgIdInfo
cg_info)]
gen_code DynFlags
dflags LambdaFormInfo
lf_info CLabel
_closure_label
= do { let name :: Name
name = Id -> Name
idName Id
id
; Module
mod_name <- FCode Module
getModuleName
; let descr :: String
descr = DynFlags -> Module -> Name -> String
closureDescription DynFlags
dflags Module
mod_name Name
name
closure_info :: ClosureInfo
closure_info = DynFlags
-> Bool
-> Id
-> LambdaFormInfo
-> WordOff
-> WordOff
-> String
-> ClosureInfo
mkClosureInfo DynFlags
dflags Bool
True Id
id LambdaFormInfo
lf_info WordOff
0 WordOff
0 String
descr
; let fv_details :: [(NonVoid Id, ByteOff)]
header :: ClosureHeader
header = if LambdaFormInfo -> Bool
isLFThunk LambdaFormInfo
lf_info then ClosureHeader
ThunkHeader else ClosureHeader
StdHeader
(WordOff
_, WordOff
_, [(NonVoid Id, WordOff)]
fv_details) = DynFlags
-> ClosureHeader
-> [NonVoid (PrimRep, Id)]
-> (WordOff, WordOff, [(NonVoid Id, WordOff)])
forall a.
DynFlags
-> ClosureHeader
-> [NonVoid (PrimRep, a)]
-> (WordOff, WordOff, [(NonVoid a, WordOff)])
mkVirtHeapOffsets DynFlags
dflags ClosureHeader
header []
; FCode () -> FCode ()
forkClosureBody (Bool
-> Id
-> ClosureInfo
-> CostCentreStack
-> [Id]
-> CgStgExpr
-> [(NonVoid Id, WordOff)]
-> FCode ()
closureCodeBody Bool
True Id
id ClosureInfo
closure_info CostCentreStack
ccs
[Id]
args CgStgExpr
body [(NonVoid Id, WordOff)]
fv_details)
; () -> FCode ()
forall (m :: * -> *) a. Monad m => a -> m a
return () }
unLit :: CmmExpr -> CmmLit
unLit (CmmLit CmmLit
l) = CmmLit
l
unLit CmmExpr
_ = String -> CmmLit
forall a. String -> a
panic String
"unLit"
cgBind :: CgStgBinding -> FCode ()
cgBind :: CgStgBinding -> FCode ()
cgBind (StgNonRec BinderP 'CodeGen
name GenStgRhs 'CodeGen
rhs)
= do { (CgIdInfo
info, FCode CmmAGraph
fcode) <- Id -> GenStgRhs 'CodeGen -> FCode (CgIdInfo, FCode CmmAGraph)
cgRhs Id
BinderP 'CodeGen
name GenStgRhs 'CodeGen
rhs
; CgIdInfo -> FCode ()
addBindC CgIdInfo
info
; CmmAGraph
init <- FCode CmmAGraph
fcode
; CmmAGraph -> FCode ()
emit CmmAGraph
init }
cgBind (StgRec [(BinderP 'CodeGen, GenStgRhs 'CodeGen)]
pairs)
= do { [(CgIdInfo, FCode CmmAGraph)]
r <- [FCode (CgIdInfo, FCode CmmAGraph)]
-> FCode [(CgIdInfo, FCode CmmAGraph)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([FCode (CgIdInfo, FCode CmmAGraph)]
-> FCode [(CgIdInfo, FCode CmmAGraph)])
-> [FCode (CgIdInfo, FCode CmmAGraph)]
-> FCode [(CgIdInfo, FCode CmmAGraph)]
forall a b. (a -> b) -> a -> b
$ (Id -> GenStgRhs 'CodeGen -> FCode (CgIdInfo, FCode CmmAGraph))
-> [(Id, GenStgRhs 'CodeGen)]
-> [FCode (CgIdInfo, FCode CmmAGraph)]
forall a b c. (a -> b -> c) -> [(a, b)] -> [c]
unzipWith Id -> GenStgRhs 'CodeGen -> FCode (CgIdInfo, FCode CmmAGraph)
cgRhs [(Id, GenStgRhs 'CodeGen)]
[(BinderP 'CodeGen, GenStgRhs 'CodeGen)]
pairs
; let ([CgIdInfo]
id_infos, [FCode CmmAGraph]
fcodes) = [(CgIdInfo, FCode CmmAGraph)] -> ([CgIdInfo], [FCode CmmAGraph])
forall a b. [(a, b)] -> ([a], [b])
unzip [(CgIdInfo, FCode CmmAGraph)]
r
; [CgIdInfo] -> FCode ()
addBindsC [CgIdInfo]
id_infos
; ([CmmAGraph]
inits, CmmAGraph
body) <- FCode [CmmAGraph] -> FCode ([CmmAGraph], CmmAGraph)
forall a. FCode a -> FCode (a, CmmAGraph)
getCodeR (FCode [CmmAGraph] -> FCode ([CmmAGraph], CmmAGraph))
-> FCode [CmmAGraph] -> FCode ([CmmAGraph], CmmAGraph)
forall a b. (a -> b) -> a -> b
$ [FCode CmmAGraph] -> FCode [CmmAGraph]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [FCode CmmAGraph]
fcodes
; CmmAGraph -> FCode ()
emit ([CmmAGraph] -> CmmAGraph
catAGraphs [CmmAGraph]
inits CmmAGraph -> CmmAGraph -> CmmAGraph
<*> CmmAGraph
body) }
cgRhs :: Id
-> CgStgRhs
-> FCode (
CgIdInfo
, FCode CmmAGraph
)
cgRhs :: Id -> GenStgRhs 'CodeGen -> FCode (CgIdInfo, FCode CmmAGraph)
cgRhs Id
id (StgRhsCon CostCentreStack
cc DataCon
con [StgArg]
args)
= Name
-> DataCon
-> FCode (CgIdInfo, FCode CmmAGraph)
-> FCode (CgIdInfo, FCode CmmAGraph)
forall a. Name -> DataCon -> FCode a -> FCode a
withNewTickyCounterCon (Id -> Name
idName Id
id) DataCon
con (FCode (CgIdInfo, FCode CmmAGraph)
-> FCode (CgIdInfo, FCode CmmAGraph))
-> FCode (CgIdInfo, FCode CmmAGraph)
-> FCode (CgIdInfo, FCode CmmAGraph)
forall a b. (a -> b) -> a -> b
$
Id
-> Bool
-> CostCentreStack
-> DataCon
-> [NonVoid StgArg]
-> FCode (CgIdInfo, FCode CmmAGraph)
buildDynCon Id
id Bool
True CostCentreStack
cc DataCon
con ([StgArg] -> [NonVoid StgArg]
assertNonVoidStgArgs [StgArg]
args)
cgRhs Id
id (StgRhsClosure XRhsClosure 'CodeGen
fvs CostCentreStack
cc UpdateFlag
upd_flag [BinderP 'CodeGen]
args CgStgExpr
body)
= do DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
DynFlags
-> Id
-> CostCentreStack
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> CgStgExpr
-> FCode (CgIdInfo, FCode CmmAGraph)
mkRhsClosure DynFlags
dflags Id
id CostCentreStack
cc ([Id] -> [NonVoid Id]
nonVoidIds (DVarSet -> [Id]
dVarSetElems DVarSet
XRhsClosure 'CodeGen
fvs)) UpdateFlag
upd_flag [Id]
[BinderP 'CodeGen]
args CgStgExpr
body
mkRhsClosure :: DynFlags -> Id -> CostCentreStack
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> CgStgExpr
-> FCode (CgIdInfo, FCode CmmAGraph)
mkRhsClosure :: DynFlags
-> Id
-> CostCentreStack
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> CgStgExpr
-> FCode (CgIdInfo, FCode CmmAGraph)
mkRhsClosure DynFlags
dflags Id
bndr CostCentreStack
_cc
[NonVoid Id
the_fv]
UpdateFlag
upd_flag
[]
CgStgExpr
expr
| let strip :: GenStgExpr p -> GenStgExpr p
strip = (Tickish Id -> Bool) -> GenStgExpr p -> GenStgExpr p
forall (p :: StgPass).
(Tickish Id -> Bool) -> GenStgExpr p -> GenStgExpr p
stripStgTicksTopE (Bool -> Bool
not (Bool -> Bool) -> (Tickish Id -> Bool) -> Tickish Id -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tickish Id -> Bool
forall id. Tickish id -> Bool
tickishIsCode)
, StgCase (StgApp Id
scrutinee [])
BinderP 'CodeGen
_
(AlgAlt TyCon
_)
[(DataAlt DataCon
_, [BinderP 'CodeGen]
params, CgStgExpr
sel_expr)] <- CgStgExpr -> CgStgExpr
forall {p :: StgPass}. GenStgExpr p -> GenStgExpr p
strip CgStgExpr
expr
, StgApp Id
selectee [] <- CgStgExpr -> CgStgExpr
forall {p :: StgPass}. GenStgExpr p -> GenStgExpr p
strip CgStgExpr
sel_expr
, Id
the_fv Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
== Id
scrutinee
, let (WordOff
_, WordOff
_, [(NonVoid Id, WordOff)]
params_w_offsets) = DynFlags
-> [NonVoid (PrimRep, Id)]
-> (WordOff, WordOff, [(NonVoid Id, WordOff)])
forall a.
DynFlags
-> [NonVoid (PrimRep, a)]
-> (WordOff, WordOff, [(NonVoid a, WordOff)])
mkVirtConstrOffsets DynFlags
dflags ([NonVoid Id] -> [NonVoid (PrimRep, Id)]
addIdReps ([Id] -> [NonVoid Id]
assertNonVoidIds [Id]
[BinderP 'CodeGen]
params))
, Just WordOff
the_offset <- [(NonVoid Id, WordOff)] -> NonVoid Id -> Maybe WordOff
forall a b. Eq a => Assoc a b -> a -> Maybe b
assocMaybe [(NonVoid Id, WordOff)]
params_w_offsets (Id -> NonVoid Id
forall a. a -> NonVoid a
NonVoid Id
selectee)
, let offset_into_int :: WordOff
offset_into_int = Platform -> WordOff -> WordOff
bytesToWordsRoundUp (DynFlags -> Platform
targetPlatform DynFlags
dflags) WordOff
the_offset
WordOff -> WordOff -> WordOff
forall a. Num a => a -> a -> a
- DynFlags -> WordOff
fixedHdrSizeW DynFlags
dflags
, WordOff
offset_into_int WordOff -> WordOff -> Bool
forall a. Ord a => a -> a -> Bool
<= DynFlags -> WordOff
mAX_SPEC_SELECTEE_SIZE DynFlags
dflags
=
let lf_info :: LambdaFormInfo
lf_info = Id -> WordOff -> Bool -> LambdaFormInfo
mkSelectorLFInfo Id
bndr WordOff
offset_into_int (UpdateFlag -> Bool
isUpdatable UpdateFlag
upd_flag)
in Id
-> LambdaFormInfo -> [StgArg] -> FCode (CgIdInfo, FCode CmmAGraph)
cgRhsStdThunk Id
bndr LambdaFormInfo
lf_info [Id -> StgArg
StgVarArg Id
the_fv]
mkRhsClosure DynFlags
dflags Id
bndr CostCentreStack
_cc
[NonVoid Id]
fvs
UpdateFlag
upd_flag
[]
(StgApp Id
fun_id [StgArg]
args)
| [StgArg]
args [StgArg] -> WordOff -> Bool
forall a. [a] -> WordOff -> Bool
`lengthIs` (WordOff
n_fvsWordOff -> WordOff -> WordOff
forall a. Num a => a -> a -> a
-WordOff
1)
, (NonVoid Id -> Bool) -> [NonVoid Id] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (PrimRep -> Bool
isGcPtrRep (PrimRep -> Bool) -> (NonVoid Id -> PrimRep) -> NonVoid Id -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Id -> PrimRep
idPrimRep (Id -> PrimRep) -> (NonVoid Id -> Id) -> NonVoid Id -> PrimRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonVoid Id -> Id
forall a. NonVoid a -> a
fromNonVoid) [NonVoid Id]
fvs
, UpdateFlag -> Bool
isUpdatable UpdateFlag
upd_flag
, WordOff
n_fvs WordOff -> WordOff -> Bool
forall a. Ord a => a -> a -> Bool
<= DynFlags -> WordOff
mAX_SPEC_AP_SIZE DynFlags
dflags
, Bool -> Bool
not (DynFlags -> Bool
sccProfilingEnabled DynFlags
dflags)
, Id -> WordOff
idArity Id
fun_id WordOff -> WordOff -> Bool
forall a. Eq a => a -> a -> Bool
== WordOff
unknownArity
= Id
-> LambdaFormInfo -> [StgArg] -> FCode (CgIdInfo, FCode CmmAGraph)
cgRhsStdThunk Id
bndr LambdaFormInfo
lf_info [StgArg]
payload
where
n_fvs :: WordOff
n_fvs = [NonVoid Id] -> WordOff
forall (t :: * -> *) a. Foldable t => t a -> WordOff
length [NonVoid Id]
fvs
lf_info :: LambdaFormInfo
lf_info = Id -> UpdateFlag -> WordOff -> LambdaFormInfo
mkApLFInfo Id
bndr UpdateFlag
upd_flag WordOff
n_fvs
payload :: [StgArg]
payload = Id -> StgArg
StgVarArg Id
fun_id StgArg -> [StgArg] -> [StgArg]
forall a. a -> [a] -> [a]
: [StgArg]
args
mkRhsClosure DynFlags
dflags Id
bndr CostCentreStack
cc [NonVoid Id]
fvs UpdateFlag
upd_flag [Id]
args CgStgExpr
body
= do { let lf_info :: LambdaFormInfo
lf_info = Platform
-> Id
-> TopLevelFlag
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> LambdaFormInfo
mkClosureLFInfo Platform
platform Id
bndr TopLevelFlag
NotTopLevel [NonVoid Id]
fvs UpdateFlag
upd_flag [Id]
args
; (CgIdInfo
id_info, LocalReg
reg) <- Id -> LambdaFormInfo -> FCode (CgIdInfo, LocalReg)
rhsIdInfo Id
bndr LambdaFormInfo
lf_info
; (CgIdInfo, FCode CmmAGraph) -> FCode (CgIdInfo, FCode CmmAGraph)
forall (m :: * -> *) a. Monad m => a -> m a
return (CgIdInfo
id_info, LambdaFormInfo -> LocalReg -> FCode CmmAGraph
gen_code LambdaFormInfo
lf_info LocalReg
reg) }
where
platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
gen_code :: LambdaFormInfo -> LocalReg -> FCode CmmAGraph
gen_code LambdaFormInfo
lf_info LocalReg
reg
= do {
; let reduced_fvs :: [NonVoid Id]
reduced_fvs = (NonVoid Id -> Bool) -> [NonVoid Id] -> [NonVoid Id]
forall a. (a -> Bool) -> [a] -> [a]
filter (Id -> NonVoid Id
forall a. a -> NonVoid a
NonVoid Id
bndr NonVoid Id -> NonVoid Id -> Bool
forall a. Eq a => a -> a -> Bool
/=) [NonVoid Id]
fvs
; Module
mod_name <- FCode Module
getModuleName
; let name :: Name
name = Id -> Name
idName Id
bndr
descr :: String
descr = DynFlags -> Module -> Name -> String
closureDescription DynFlags
dflags Module
mod_name Name
name
fv_details :: [(NonVoid Id, ByteOff)]
header :: ClosureHeader
header = if LambdaFormInfo -> Bool
isLFThunk LambdaFormInfo
lf_info then ClosureHeader
ThunkHeader else ClosureHeader
StdHeader
(WordOff
tot_wds, WordOff
ptr_wds, [(NonVoid Id, WordOff)]
fv_details)
= DynFlags
-> ClosureHeader
-> [NonVoid (PrimRep, Id)]
-> (WordOff, WordOff, [(NonVoid Id, WordOff)])
forall a.
DynFlags
-> ClosureHeader
-> [NonVoid (PrimRep, a)]
-> (WordOff, WordOff, [(NonVoid a, WordOff)])
mkVirtHeapOffsets DynFlags
dflags ClosureHeader
header ([NonVoid Id] -> [NonVoid (PrimRep, Id)]
addIdReps [NonVoid Id]
reduced_fvs)
closure_info :: ClosureInfo
closure_info = DynFlags
-> Bool
-> Id
-> LambdaFormInfo
-> WordOff
-> WordOff
-> String
-> ClosureInfo
mkClosureInfo DynFlags
dflags Bool
False
Id
bndr LambdaFormInfo
lf_info WordOff
tot_wds WordOff
ptr_wds
String
descr
; FCode () -> FCode ()
forkClosureBody (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$
Bool
-> Id
-> ClosureInfo
-> CostCentreStack
-> [Id]
-> CgStgExpr
-> [(NonVoid Id, WordOff)]
-> FCode ()
closureCodeBody Bool
False Id
bndr ClosureInfo
closure_info CostCentreStack
cc [Id]
args
CgStgExpr
body [(NonVoid Id, WordOff)]
fv_details
; let use_cc :: CmmExpr
use_cc = CmmExpr
cccsExpr; blame_cc :: CmmExpr
blame_cc = CmmExpr
cccsExpr
; CmmAGraph -> FCode ()
emit (FastString -> CmmAGraph
mkComment (FastString -> CmmAGraph) -> FastString -> CmmAGraph
forall a b. (a -> b) -> a -> b
$ String -> FastString
mkFastString String
"calling allocDynClosure")
; let toVarArg :: (NonVoid Id, b) -> (NonVoid StgArg, b)
toVarArg (NonVoid Id
a, b
off) = (StgArg -> NonVoid StgArg
forall a. a -> NonVoid a
NonVoid (Id -> StgArg
StgVarArg Id
a), b
off)
; let info_tbl :: CmmInfoTable
info_tbl = ClosureInfo -> Id -> CostCentreStack -> CmmInfoTable
mkCmmInfo ClosureInfo
closure_info Id
bndr CostCentreStack
currentCCS
; CmmExpr
hp_plus_n <- Maybe Id
-> CmmInfoTable
-> LambdaFormInfo
-> CmmExpr
-> CmmExpr
-> [(NonVoid StgArg, WordOff)]
-> FCode CmmExpr
allocDynClosure (Id -> Maybe Id
forall a. a -> Maybe a
Just Id
bndr) CmmInfoTable
info_tbl LambdaFormInfo
lf_info CmmExpr
use_cc CmmExpr
blame_cc
(((NonVoid Id, WordOff) -> (NonVoid StgArg, WordOff))
-> [(NonVoid Id, WordOff)] -> [(NonVoid StgArg, WordOff)]
forall a b. (a -> b) -> [a] -> [b]
map (NonVoid Id, WordOff) -> (NonVoid StgArg, WordOff)
forall {b}. (NonVoid Id, b) -> (NonVoid StgArg, b)
toVarArg [(NonVoid Id, WordOff)]
fv_details)
; CmmAGraph -> FCode CmmAGraph
forall (m :: * -> *) a. Monad m => a -> m a
return (DynFlags -> LocalReg -> LambdaFormInfo -> CmmExpr -> CmmAGraph
mkRhsInit DynFlags
dflags LocalReg
reg LambdaFormInfo
lf_info CmmExpr
hp_plus_n) }
cgRhsStdThunk
:: Id
-> LambdaFormInfo
-> [StgArg]
-> FCode (CgIdInfo, FCode CmmAGraph)
cgRhsStdThunk :: Id
-> LambdaFormInfo -> [StgArg] -> FCode (CgIdInfo, FCode CmmAGraph)
cgRhsStdThunk Id
bndr LambdaFormInfo
lf_info [StgArg]
payload
= do { (CgIdInfo
id_info, LocalReg
reg) <- Id -> LambdaFormInfo -> FCode (CgIdInfo, LocalReg)
rhsIdInfo Id
bndr LambdaFormInfo
lf_info
; (CgIdInfo, FCode CmmAGraph) -> FCode (CgIdInfo, FCode CmmAGraph)
forall (m :: * -> *) a. Monad m => a -> m a
return (CgIdInfo
id_info, LocalReg -> FCode CmmAGraph
gen_code LocalReg
reg)
}
where
gen_code :: LocalReg -> FCode CmmAGraph
gen_code LocalReg
reg
= Bool -> Name -> FCode CmmAGraph -> FCode CmmAGraph
forall a. Bool -> Name -> FCode a -> FCode a
withNewTickyCounterStdThunk (LambdaFormInfo -> Bool
lfUpdatable LambdaFormInfo
lf_info) (Id -> Name
idName Id
bndr) (FCode CmmAGraph -> FCode CmmAGraph)
-> FCode CmmAGraph -> FCode CmmAGraph
forall a b. (a -> b) -> a -> b
$
do
{
Module
mod_name <- FCode Module
getModuleName
; DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; let header :: ClosureHeader
header = if LambdaFormInfo -> Bool
isLFThunk LambdaFormInfo
lf_info then ClosureHeader
ThunkHeader else ClosureHeader
StdHeader
(WordOff
tot_wds, WordOff
ptr_wds, [(NonVoid StgArg, WordOff)]
payload_w_offsets)
= DynFlags
-> ClosureHeader
-> [NonVoid (PrimRep, StgArg)]
-> (WordOff, WordOff, [(NonVoid StgArg, WordOff)])
forall a.
DynFlags
-> ClosureHeader
-> [NonVoid (PrimRep, a)]
-> (WordOff, WordOff, [(NonVoid a, WordOff)])
mkVirtHeapOffsets DynFlags
dflags ClosureHeader
header
([NonVoid StgArg] -> [NonVoid (PrimRep, StgArg)]
addArgReps ([StgArg] -> [NonVoid StgArg]
nonVoidStgArgs [StgArg]
payload))
descr :: String
descr = DynFlags -> Module -> Name -> String
closureDescription DynFlags
dflags Module
mod_name (Id -> Name
idName Id
bndr)
closure_info :: ClosureInfo
closure_info = DynFlags
-> Bool
-> Id
-> LambdaFormInfo
-> WordOff
-> WordOff
-> String
-> ClosureInfo
mkClosureInfo DynFlags
dflags Bool
False
Id
bndr LambdaFormInfo
lf_info WordOff
tot_wds WordOff
ptr_wds
String
descr
; let use_cc :: CmmExpr
use_cc = CmmExpr
cccsExpr; blame_cc :: CmmExpr
blame_cc = CmmExpr
cccsExpr
; let info_tbl :: CmmInfoTable
info_tbl = ClosureInfo -> Id -> CostCentreStack -> CmmInfoTable
mkCmmInfo ClosureInfo
closure_info Id
bndr CostCentreStack
currentCCS
; CmmExpr
hp_plus_n <- Maybe Id
-> CmmInfoTable
-> LambdaFormInfo
-> CmmExpr
-> CmmExpr
-> [(NonVoid StgArg, WordOff)]
-> FCode CmmExpr
allocDynClosure (Id -> Maybe Id
forall a. a -> Maybe a
Just Id
bndr) CmmInfoTable
info_tbl LambdaFormInfo
lf_info
CmmExpr
use_cc CmmExpr
blame_cc [(NonVoid StgArg, WordOff)]
payload_w_offsets
; CmmAGraph -> FCode CmmAGraph
forall (m :: * -> *) a. Monad m => a -> m a
return (DynFlags -> LocalReg -> LambdaFormInfo -> CmmExpr -> CmmAGraph
mkRhsInit DynFlags
dflags LocalReg
reg LambdaFormInfo
lf_info CmmExpr
hp_plus_n) }
mkClosureLFInfo :: Platform
-> Id
-> TopLevelFlag
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> LambdaFormInfo
mkClosureLFInfo :: Platform
-> Id
-> TopLevelFlag
-> [NonVoid Id]
-> UpdateFlag
-> [Id]
-> LambdaFormInfo
mkClosureLFInfo Platform
platform Id
bndr TopLevelFlag
top [NonVoid Id]
fvs UpdateFlag
upd_flag [Id]
args
| [Id] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Id]
args =
Type -> TopLevelFlag -> [Id] -> UpdateFlag -> LambdaFormInfo
mkLFThunk (Id -> Type
idType Id
bndr) TopLevelFlag
top ((NonVoid Id -> Id) -> [NonVoid Id] -> [Id]
forall a b. (a -> b) -> [a] -> [b]
map NonVoid Id -> Id
forall a. NonVoid a -> a
fromNonVoid [NonVoid Id]
fvs) UpdateFlag
upd_flag
| Bool
otherwise =
TopLevelFlag -> [Id] -> [Id] -> ArgDescr -> LambdaFormInfo
mkLFReEntrant TopLevelFlag
top ((NonVoid Id -> Id) -> [NonVoid Id] -> [Id]
forall a b. (a -> b) -> [a] -> [b]
map NonVoid Id -> Id
forall a. NonVoid a -> a
fromNonVoid [NonVoid Id]
fvs) [Id]
args (Platform -> [Id] -> ArgDescr
mkArgDescr Platform
platform [Id]
args)
closureCodeBody :: Bool
-> Id
-> ClosureInfo
-> CostCentreStack
-> [Id]
-> CgStgExpr
-> [(NonVoid Id, ByteOff)]
-> FCode ()
closureCodeBody :: Bool
-> Id
-> ClosureInfo
-> CostCentreStack
-> [Id]
-> CgStgExpr
-> [(NonVoid Id, WordOff)]
-> FCode ()
closureCodeBody Bool
top_lvl Id
bndr ClosureInfo
cl_info CostCentreStack
cc [] CgStgExpr
body [(NonVoid Id, WordOff)]
fv_details
= Bool -> Bool -> Name -> FCode () -> FCode ()
forall a. Bool -> Bool -> Name -> FCode a -> FCode a
withNewTickyCounterThunk
(ClosureInfo -> Bool
isStaticClosure ClosureInfo
cl_info)
(ClosureInfo -> Bool
closureUpdReqd ClosureInfo
cl_info)
(ClosureInfo -> Name
closureName ClosureInfo
cl_info) (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$
Bool
-> Id
-> LambdaFormInfo
-> CmmInfoTable
-> [NonVoid Id]
-> ((WordOff, LocalReg, [LocalReg]) -> FCode ())
-> FCode ()
emitClosureProcAndInfoTable Bool
top_lvl Id
bndr LambdaFormInfo
lf_info CmmInfoTable
info_tbl [] (((WordOff, LocalReg, [LocalReg]) -> FCode ()) -> FCode ())
-> ((WordOff, LocalReg, [LocalReg]) -> FCode ()) -> FCode ()
forall a b. (a -> b) -> a -> b
$
\(WordOff
_, LocalReg
node, [LocalReg]
_) -> ClosureInfo
-> [(NonVoid Id, WordOff)]
-> CostCentreStack
-> LocalReg
-> CgStgExpr
-> FCode ()
thunkCode ClosureInfo
cl_info [(NonVoid Id, WordOff)]
fv_details CostCentreStack
cc LocalReg
node CgStgExpr
body
where
lf_info :: LambdaFormInfo
lf_info = ClosureInfo -> LambdaFormInfo
closureLFInfo ClosureInfo
cl_info
info_tbl :: CmmInfoTable
info_tbl = ClosureInfo -> Id -> CostCentreStack -> CmmInfoTable
mkCmmInfo ClosureInfo
cl_info Id
bndr CostCentreStack
cc
closureCodeBody Bool
top_lvl Id
bndr ClosureInfo
cl_info CostCentreStack
cc args :: [Id]
args@(Id
arg0:[Id]
_) CgStgExpr
body [(NonVoid Id, WordOff)]
fv_details
= let nv_args :: [NonVoid Id]
nv_args = [Id] -> [NonVoid Id]
nonVoidIds [Id]
args
arity :: WordOff
arity = [Id] -> WordOff
forall (t :: * -> *) a. Foldable t => t a -> WordOff
length [Id]
args
in
Bool -> Name -> [NonVoid Id] -> FCode () -> FCode ()
forall a. Bool -> Name -> [NonVoid Id] -> FCode a -> FCode a
withNewTickyCounterFun (Id -> Bool
isOneShotBndr Id
arg0) (ClosureInfo -> Name
closureName ClosureInfo
cl_info)
[NonVoid Id]
nv_args (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ do {
; let
lf_info :: LambdaFormInfo
lf_info = ClosureInfo -> LambdaFormInfo
closureLFInfo ClosureInfo
cl_info
info_tbl :: CmmInfoTable
info_tbl = ClosureInfo -> Id -> CostCentreStack -> CmmInfoTable
mkCmmInfo ClosureInfo
cl_info Id
bndr CostCentreStack
cc
; Bool
-> Id
-> LambdaFormInfo
-> CmmInfoTable
-> [NonVoid Id]
-> ((WordOff, LocalReg, [LocalReg]) -> FCode ())
-> FCode ()
emitClosureProcAndInfoTable Bool
top_lvl Id
bndr LambdaFormInfo
lf_info CmmInfoTable
info_tbl [NonVoid Id]
nv_args (((WordOff, LocalReg, [LocalReg]) -> FCode ()) -> FCode ())
-> ((WordOff, LocalReg, [LocalReg]) -> FCode ()) -> FCode ()
forall a b. (a -> b) -> a -> b
$
\(WordOff
_offset, LocalReg
node, [LocalReg]
arg_regs) -> do
{ Id -> ClosureInfo -> [LocalReg] -> FCode ()
mkSlowEntryCode Id
bndr ClosureInfo
cl_info [LocalReg]
arg_regs
; DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; Platform
platform <- FCode Platform
getPlatform
; let node_points :: Bool
node_points = DynFlags -> LambdaFormInfo -> Bool
nodeMustPointToIt DynFlags
dflags LambdaFormInfo
lf_info
node' :: Maybe LocalReg
node' = if Bool
node_points then LocalReg -> Maybe LocalReg
forall a. a -> Maybe a
Just LocalReg
node else Maybe LocalReg
forall a. Maybe a
Nothing
; BlockId
loop_header_id <- FCode BlockId
forall (m :: * -> *). MonadUnique m => m BlockId
newBlockId
; SelfLoopInfo -> FCode () -> FCode ()
forall a. SelfLoopInfo -> FCode a -> FCode a
withSelfLoop (Id
bndr, BlockId
loop_header_id, [LocalReg]
arg_regs) (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ do
{
; ClosureInfo
-> Maybe LocalReg -> WordOff -> [LocalReg] -> FCode () -> FCode ()
entryHeapCheck ClosureInfo
cl_info Maybe LocalReg
node' WordOff
arity [LocalReg]
arg_regs (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ do
{
Bool -> FCode () -> FCode ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
node_points (ClosureInfo -> CmmReg -> FCode ()
ldvEnterClosure ClosureInfo
cl_info (LocalReg -> CmmReg
CmmLocal LocalReg
node))
; ClosureInfo -> FCode ()
tickyEnterFun ClosureInfo
cl_info
; CostCentreStack -> CmmExpr -> FCode ()
enterCostCentreFun CostCentreStack
cc
(MachOp -> [CmmExpr] -> CmmExpr
CmmMachOp (Platform -> MachOp
mo_wordSub Platform
platform)
[ CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
node)
, Platform -> WordOff -> CmmExpr
mkIntExpr Platform
platform (DynFlags -> ClosureInfo -> WordOff
funTag DynFlags
dflags ClosureInfo
cl_info) ])
; [(LocalReg, WordOff)]
fv_bindings <- ((NonVoid Id, WordOff) -> FCode (LocalReg, WordOff))
-> [(NonVoid Id, WordOff)] -> FCode [(LocalReg, WordOff)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (NonVoid Id, WordOff) -> FCode (LocalReg, WordOff)
bind_fv [(NonVoid Id, WordOff)]
fv_details
; Bool -> FCode () -> FCode ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
node_points (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ LocalReg -> LambdaFormInfo -> [(LocalReg, WordOff)] -> FCode ()
load_fvs LocalReg
node LambdaFormInfo
lf_info [(LocalReg, WordOff)]
fv_bindings
; FCode ReturnKind -> FCode ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (FCode ReturnKind -> FCode ()) -> FCode ReturnKind -> FCode ()
forall a b. (a -> b) -> a -> b
$ CgStgExpr -> FCode ReturnKind
cgExpr CgStgExpr
body
}}}
}
bind_fv :: (NonVoid Id, ByteOff) -> FCode (LocalReg, ByteOff)
bind_fv :: (NonVoid Id, WordOff) -> FCode (LocalReg, WordOff)
bind_fv (NonVoid Id
id, WordOff
off) = do { LocalReg
reg <- NonVoid Id -> FCode LocalReg
rebindToReg NonVoid Id
id; (LocalReg, WordOff) -> FCode (LocalReg, WordOff)
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalReg
reg, WordOff
off) }
load_fvs :: LocalReg -> LambdaFormInfo -> [(LocalReg, ByteOff)] -> FCode ()
load_fvs :: LocalReg -> LambdaFormInfo -> [(LocalReg, WordOff)] -> FCode ()
load_fvs LocalReg
node LambdaFormInfo
lf_info = ((LocalReg, WordOff) -> FCode ())
-> [(LocalReg, WordOff)] -> FCode ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (LocalReg
reg, WordOff
off) ->
do DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
Platform
platform <- FCode Platform
getPlatform
let tag :: WordOff
tag = DynFlags -> LambdaFormInfo -> WordOff
lfDynTag DynFlags
dflags LambdaFormInfo
lf_info
CmmAGraph -> FCode ()
emit (CmmAGraph -> FCode ()) -> CmmAGraph -> FCode ()
forall a b. (a -> b) -> a -> b
$ Platform -> LocalReg -> LocalReg -> WordOff -> WordOff -> CmmAGraph
mkTaggedObjectLoad Platform
platform LocalReg
reg LocalReg
node WordOff
off WordOff
tag)
mkSlowEntryCode :: Id -> ClosureInfo -> [LocalReg] -> FCode ()
mkSlowEntryCode :: Id -> ClosureInfo -> [LocalReg] -> FCode ()
mkSlowEntryCode Id
bndr ClosureInfo
cl_info [LocalReg]
arg_regs
| Just (WordOff
_, ArgGen Liveness
_) <- ClosureInfo -> Maybe (WordOff, ArgDescr)
closureFunInfo ClosureInfo
cl_info
= do DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
Platform
platform <- FCode Platform
getPlatform
let node :: LocalReg
node = Platform -> NonVoid Id -> LocalReg
idToReg Platform
platform (Id -> NonVoid Id
forall a. a -> NonVoid a
NonVoid Id
bndr)
slow_lbl :: CLabel
slow_lbl = ClosureInfo -> CLabel
closureSlowEntryLabel ClosureInfo
cl_info
fast_lbl :: CLabel
fast_lbl = Platform -> ClosureInfo -> CLabel
closureLocalEntryLabel Platform
platform ClosureInfo
cl_info
jump :: CmmAGraph
jump = DynFlags
-> Convention -> CmmExpr -> [CmmExpr] -> WordOff -> CmmAGraph
mkJump DynFlags
dflags Convention
NativeNodeCall
(CLabel -> CmmExpr
mkLblExpr CLabel
fast_lbl)
((LocalReg -> CmmExpr) -> [LocalReg] -> [CmmExpr]
forall a b. (a -> b) -> [a] -> [b]
map (CmmReg -> CmmExpr
CmmReg (CmmReg -> CmmExpr) -> (LocalReg -> CmmReg) -> LocalReg -> CmmExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalReg -> CmmReg
CmmLocal) (LocalReg
node LocalReg -> [LocalReg] -> [LocalReg]
forall a. a -> [a] -> [a]
: [LocalReg]
arg_regs))
(Platform -> WordOff
initUpdFrameOff Platform
platform)
CmmTickScope
tscope <- FCode CmmTickScope
getTickScope
Convention
-> Maybe CmmInfoTable
-> CLabel
-> [LocalReg]
-> CmmAGraphScoped
-> FCode ()
emitProcWithConvention Convention
Slow Maybe CmmInfoTable
forall a. Maybe a
Nothing CLabel
slow_lbl
(LocalReg
node LocalReg -> [LocalReg] -> [LocalReg]
forall a. a -> [a] -> [a]
: [LocalReg]
arg_regs) (CmmAGraph
jump, CmmTickScope
tscope)
| Bool
otherwise = () -> FCode ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
thunkCode :: ClosureInfo -> [(NonVoid Id, ByteOff)] -> CostCentreStack
-> LocalReg -> CgStgExpr -> FCode ()
thunkCode :: ClosureInfo
-> [(NonVoid Id, WordOff)]
-> CostCentreStack
-> LocalReg
-> CgStgExpr
-> FCode ()
thunkCode ClosureInfo
cl_info [(NonVoid Id, WordOff)]
fv_details CostCentreStack
_cc LocalReg
node CgStgExpr
body
= do { DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; let node_points :: Bool
node_points = DynFlags -> LambdaFormInfo -> Bool
nodeMustPointToIt DynFlags
dflags (ClosureInfo -> LambdaFormInfo
closureLFInfo ClosureInfo
cl_info)
node' :: Maybe LocalReg
node' = if Bool
node_points then LocalReg -> Maybe LocalReg
forall a. a -> Maybe a
Just LocalReg
node else Maybe LocalReg
forall a. Maybe a
Nothing
; ClosureInfo -> CmmReg -> FCode ()
ldvEnterClosure ClosureInfo
cl_info (LocalReg -> CmmReg
CmmLocal LocalReg
node)
; ClosureInfo
-> Maybe LocalReg -> WordOff -> [LocalReg] -> FCode () -> FCode ()
entryHeapCheck ClosureInfo
cl_info Maybe LocalReg
node' WordOff
0 [] (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ do
{
; ClosureInfo -> FCode ()
tickyEnterThunk ClosureInfo
cl_info
; Bool -> FCode () -> FCode ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ClosureInfo -> Bool
blackHoleOnEntry ClosureInfo
cl_info Bool -> Bool -> Bool
&& Bool
node_points)
(LocalReg -> FCode ()
blackHoleIt LocalReg
node)
; ClosureInfo -> LocalReg -> FCode () -> FCode ()
setupUpdate ClosureInfo
cl_info LocalReg
node (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$
do { CmmExpr -> FCode ()
enterCostCentreThunk (CmmReg -> CmmExpr
CmmReg CmmReg
nodeReg)
; let lf_info :: LambdaFormInfo
lf_info = ClosureInfo -> LambdaFormInfo
closureLFInfo ClosureInfo
cl_info
; [(LocalReg, WordOff)]
fv_bindings <- ((NonVoid Id, WordOff) -> FCode (LocalReg, WordOff))
-> [(NonVoid Id, WordOff)] -> FCode [(LocalReg, WordOff)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (NonVoid Id, WordOff) -> FCode (LocalReg, WordOff)
bind_fv [(NonVoid Id, WordOff)]
fv_details
; LocalReg -> LambdaFormInfo -> [(LocalReg, WordOff)] -> FCode ()
load_fvs LocalReg
node LambdaFormInfo
lf_info [(LocalReg, WordOff)]
fv_bindings
; FCode ReturnKind -> FCode ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (FCode ReturnKind -> FCode ()) -> FCode ReturnKind -> FCode ()
forall a b. (a -> b) -> a -> b
$ CgStgExpr -> FCode ReturnKind
cgExpr CgStgExpr
body }}}
blackHoleIt :: LocalReg -> FCode ()
blackHoleIt :: LocalReg -> FCode ()
blackHoleIt LocalReg
node_reg
= CmmExpr -> FCode ()
emitBlackHoleCode (CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
node_reg))
emitBlackHoleCode :: CmmExpr -> FCode ()
emitBlackHoleCode :: CmmExpr -> FCode ()
emitBlackHoleCode CmmExpr
node = do
DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
let eager_blackholing :: Bool
eager_blackholing = Bool -> Bool
not (DynFlags -> Bool
sccProfilingEnabled DynFlags
dflags)
Bool -> Bool -> Bool
&& GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_EagerBlackHoling DynFlags
dflags
Bool -> FCode () -> FCode ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
eager_blackholing (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ do
FCode () -> FCode ()
forall a. FCode a -> FCode ()
whenUpdRemSetEnabled (FCode () -> FCode ()) -> FCode () -> FCode ()
forall a b. (a -> b) -> a -> b
$ CmmExpr -> FCode ()
emitUpdRemSetPushThunk CmmExpr
node
CmmExpr -> CmmExpr -> FCode ()
emitStore (Platform -> CmmExpr -> WordOff -> CmmExpr
cmmOffsetW Platform
platform CmmExpr
node (DynFlags -> WordOff
fixedHdrSizeW DynFlags
dflags)) CmmExpr
currentTSOExpr
[LocalReg] -> CallishMachOp -> [CmmExpr] -> FCode ()
emitPrimCall [] CallishMachOp
MO_WriteBarrier []
CmmExpr -> CmmExpr -> FCode ()
emitStore CmmExpr
node (CmmReg -> CmmExpr
CmmReg (GlobalReg -> CmmReg
CmmGlobal GlobalReg
EagerBlackholeInfo))
setupUpdate :: ClosureInfo -> LocalReg -> FCode () -> FCode ()
setupUpdate :: ClosureInfo -> LocalReg -> FCode () -> FCode ()
setupUpdate ClosureInfo
closure_info LocalReg
node FCode ()
body
| Bool -> Bool
not (LambdaFormInfo -> Bool
lfUpdatable (ClosureInfo -> LambdaFormInfo
closureLFInfo ClosureInfo
closure_info))
= FCode ()
body
| Bool -> Bool
not (ClosureInfo -> Bool
isStaticClosure ClosureInfo
closure_info)
= if Bool -> Bool
not (ClosureInfo -> Bool
closureUpdReqd ClosureInfo
closure_info)
then do FCode ()
tickyUpdateFrameOmitted; FCode ()
body
else do
FCode ()
tickyPushUpdateFrame
DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let
bh :: Bool
bh = ClosureInfo -> Bool
blackHoleOnEntry ClosureInfo
closure_info Bool -> Bool -> Bool
&&
Bool -> Bool
not (DynFlags -> Bool
sccProfilingEnabled DynFlags
dflags) Bool -> Bool -> Bool
&&
GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_EagerBlackHoling DynFlags
dflags
lbl :: CLabel
lbl | Bool
bh = CLabel
mkBHUpdInfoLabel
| Bool
otherwise = CLabel
mkUpdInfoLabel
CLabel -> CmmExpr -> FCode () -> FCode ()
pushUpdateFrame CLabel
lbl (CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
node)) FCode ()
body
| Bool
otherwise
= do { ClosureInfo -> FCode ()
tickyUpdateBhCaf ClosureInfo
closure_info
; if ClosureInfo -> Bool
closureUpdReqd ClosureInfo
closure_info
then do
{ CmmExpr
upd_closure <- LocalReg -> FCode CmmExpr
link_caf LocalReg
node
; CLabel -> CmmExpr -> FCode () -> FCode ()
pushUpdateFrame CLabel
mkBHUpdInfoLabel CmmExpr
upd_closure FCode ()
body }
else do {FCode ()
tickyUpdateFrameOmitted; FCode ()
body}
}
pushUpdateFrame :: CLabel -> CmmExpr -> FCode () -> FCode ()
pushUpdateFrame :: CLabel -> CmmExpr -> FCode () -> FCode ()
pushUpdateFrame CLabel
lbl CmmExpr
updatee FCode ()
body
= do
WordOff
updfr <- FCode WordOff
getUpdFrameOff
DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let
hdr :: WordOff
hdr = DynFlags -> WordOff
fixedHdrSize DynFlags
dflags
frame :: WordOff
frame = WordOff
updfr WordOff -> WordOff -> WordOff
forall a. Num a => a -> a -> a
+ WordOff
hdr WordOff -> WordOff -> WordOff
forall a. Num a => a -> a -> a
+ DynFlags -> WordOff
sIZEOF_StgUpdateFrame_NoHdr DynFlags
dflags
DynFlags -> CmmExpr -> CLabel -> CmmExpr -> FCode ()
emitUpdateFrame DynFlags
dflags (Area -> WordOff -> CmmExpr
CmmStackSlot Area
Old WordOff
frame) CLabel
lbl CmmExpr
updatee
WordOff -> FCode () -> FCode ()
forall a. WordOff -> FCode a -> FCode a
withUpdFrameOff WordOff
frame FCode ()
body
emitUpdateFrame :: DynFlags -> CmmExpr -> CLabel -> CmmExpr -> FCode ()
emitUpdateFrame :: DynFlags -> CmmExpr -> CLabel -> CmmExpr -> FCode ()
emitUpdateFrame DynFlags
dflags CmmExpr
frame CLabel
lbl CmmExpr
updatee = do
let
hdr :: WordOff
hdr = DynFlags -> WordOff
fixedHdrSize DynFlags
dflags
off_updatee :: WordOff
off_updatee = WordOff
hdr WordOff -> WordOff -> WordOff
forall a. Num a => a -> a -> a
+ DynFlags -> WordOff
oFFSET_StgUpdateFrame_updatee DynFlags
dflags
platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
CmmExpr -> CmmExpr -> FCode ()
emitStore CmmExpr
frame (CLabel -> CmmExpr
mkLblExpr CLabel
lbl)
CmmExpr -> CmmExpr -> FCode ()
emitStore (Platform -> CmmExpr -> WordOff -> CmmExpr
cmmOffset Platform
platform CmmExpr
frame WordOff
off_updatee) CmmExpr
updatee
CmmExpr -> FCode ()
initUpdFrameProf CmmExpr
frame
link_caf :: LocalReg
-> FCode CmmExpr
link_caf :: LocalReg -> FCode CmmExpr
link_caf LocalReg
node = do
{ DynFlags
dflags <- FCode DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; let newCAF_lbl :: CLabel
newCAF_lbl = FastString
-> Maybe WordOff -> ForeignLabelSource -> FunctionOrData -> CLabel
mkForeignLabel (String -> FastString
fsLit String
"newCAF") Maybe WordOff
forall a. Maybe a
Nothing
ForeignLabelSource
ForeignLabelInExternalPackage FunctionOrData
IsFunction
; let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
; LocalReg
bh <- CmmType -> FCode LocalReg
forall (m :: * -> *). MonadUnique m => CmmType -> m LocalReg
newTemp (Platform -> CmmType
bWord Platform
platform)
; [(LocalReg, ForeignHint)]
-> CLabel -> [(CmmExpr, ForeignHint)] -> Bool -> FCode ()
emitRtsCallGen [(LocalReg
bh,ForeignHint
AddrHint)] CLabel
newCAF_lbl
[ (CmmExpr
baseExpr, ForeignHint
AddrHint),
(CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
node), ForeignHint
AddrHint) ]
Bool
False
; WordOff
updfr <- FCode WordOff
getUpdFrameOff
; let target :: CmmExpr
target = Platform -> CmmExpr -> CmmExpr
entryCode Platform
platform (DynFlags -> CmmExpr -> CmmExpr
closureInfoPtr DynFlags
dflags (CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
node)))
; CmmAGraph -> FCode ()
emit (CmmAGraph -> FCode ()) -> FCode CmmAGraph -> FCode ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CmmExpr -> CmmAGraph -> FCode CmmAGraph
mkCmmIfThen
(Platform -> CmmExpr -> CmmExpr -> CmmExpr
cmmEqWord Platform
platform (CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
bh)) (Platform -> CmmExpr
zeroExpr Platform
platform))
(DynFlags
-> Convention -> CmmExpr -> [CmmExpr] -> WordOff -> CmmAGraph
mkJump DynFlags
dflags Convention
NativeNodeCall CmmExpr
target [] WordOff
updfr)
; CmmExpr -> FCode CmmExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CmmReg -> CmmExpr
CmmReg (LocalReg -> CmmReg
CmmLocal LocalReg
bh)) }
closureDescription :: DynFlags
-> Module
-> Name
-> String
closureDescription :: DynFlags -> Module -> Name -> String
closureDescription DynFlags
dflags Module
mod_name Name
name
= DynFlags -> SDoc -> String
showSDocDump DynFlags
dflags (Char -> SDoc
char Char
'<' SDoc -> SDoc -> SDoc
<>
(if Name -> Bool
isExternalName Name
name
then Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name
else Module -> SDoc
pprModule Module
mod_name SDoc -> SDoc -> SDoc
<> Char -> SDoc
char Char
'.' SDoc -> SDoc -> SDoc
<> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
<>
Char -> SDoc
char Char
'>')