%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
-% $Id: CgClosure.lhs,v 1.20 1998/12/02 13:17:47 simonm Exp $
+% $Id: CgClosure.lhs,v 1.26 1999/03/22 16:58:19 simonm Exp $
%
\section[CgClosure]{Code generation for closures}
import CostCentre
import Id ( Id, idName, idType, idPrimRep )
import Name ( Name )
+import Module ( Module, pprModule )
import ListSetOps ( minusList )
import PrimRep ( PrimRep(..) )
-import Type ( showTypeCategory )
+import PprType ( showTypeCategory )
import Util ( isIn )
import CmdLineOpts ( opt_SccProfilingOn )
import Outputable
cgTopRhsClosure :: Id
-> CostCentreStack -- Optional cost centre annotation
-> StgBinderInfo
- -> SRT
-> [Id] -- Args
-> StgExpr
-> LambdaFormInfo
-> FCode (Id, CgIdInfo)
-cgTopRhsClosure id ccs binder_info srt args body lf_info
+cgTopRhsClosure id ccs binder_info args body lf_info
= -- LAY OUT THE OBJECT
let
closure_info = layOutStaticNoFVClosure name lf_info
`thenC`
-- GENERATE THE INFO TABLE (IF NECESSARY)
- forkClosureBody (closureCodeBody binder_info srt closure_info
+ forkClosureBody (closureCodeBody binder_info closure_info
ccs args body)
) `thenC`
:: Id
-> CostCentreStack -- Optional cost centre annotation
-> StgBinderInfo
- -> SRT -- SRT info
-> [Id] -- Free vars
-> [Id] -- Args
-> StgExpr
-> [StgArg] -- payload
-> FCode (Id, CgIdInfo)
-cgStdRhsClosure binder cc binder_info srt fvs args body lf_info payload
+cgStdRhsClosure binder cc binder_info fvs args body lf_info payload
-- AHA! A STANDARD-FORM THUNK
= (
-- LAY OUT THE OBJECT
cgRhsClosure :: Id
-> CostCentreStack -- Optional cost centre annotation
-> StgBinderInfo
- -> SRT -- SRT info
-> [Id] -- Free vars
-> [Id] -- Args
-> StgExpr
-> LambdaFormInfo
-> FCode (Id, CgIdInfo)
-cgRhsClosure binder cc binder_info srt fvs args body lf_info
+cgRhsClosure binder cc binder_info fvs args body lf_info
= (
-- LAY OUT THE OBJECT
--
nopC) `thenC`
-- Compile the body
- closureCodeBody binder_info srt closure_info cc args body
+ closureCodeBody binder_info closure_info cc args body
) `thenC`
-- BUILD THE OBJECT
\begin{code}
closureCodeBody :: StgBinderInfo
- -> SRT
-> ClosureInfo -- Lots of information about this closure
-> CostCentreStack -- Optional cost centre attached to closure
-> [Id]
are the same.
\begin{code}
-closureCodeBody binder_info srt closure_info cc [] body
+closureCodeBody binder_info closure_info cc [] body
= -- thunks cannot have a primitive type!
getAbsC body_code `thenFC` \ body_absC ->
moduleName `thenFC` \ mod_name ->
- getSRTLabel `thenFC` \ srt_label ->
absC (CClosureInfoAndCode closure_info body_absC Nothing
- (srt_label, srt) (cl_descr mod_name))
+ (cl_descr mod_name))
where
cl_descr mod_name = closureDescription mod_name (closureName closure_info)
Node points to closure is available. -- HWL
\begin{code}
-closureCodeBody binder_info srt closure_info cc all_args body
+closureCodeBody binder_info closure_info cc all_args body
= getEntryConvention name lf_info
(map idPrimRep all_args) `thenFC` \ entry_conv ->
fast_entry_code
= profCtrC SLIT("TICK_ENT_FUN_DIRECT") [
- CLbl (mkRednCountsLabel name) PtrRep,
+ mkIntCLit stg_arity -- total # of args
+
+ {- CLbl (mkRednCountsLabel name) PtrRep,
CString (_PK_ (showSDoc (ppr name))),
mkIntCLit stg_arity, -- total # of args
mkIntCLit sp_stk_args, -- # passed on stk
CString (_PK_ (map (showTypeCategory . idType) all_args)),
CString SLIT(""), CString SLIT("")
+ -}
-- Nuked for now; see comment at end of file
-- CString (_PK_ (show_wrapper_name wrapper_maybe)),
`thenFC` \ slow_abs_c ->
forkAbsC fast_entry_code `thenFC` \ fast_abs_c ->
moduleName `thenFC` \ mod_name ->
- getSRTLabel `thenFC` \ srt_label ->
-- Now either construct the info table, or put the fast code in alone
-- (We never have slow code without an info table)
absC (
if info_table_needed then
CClosureInfoAndCode closure_info slow_abs_c (Just fast_abs_c)
- (srt_label, srt) (cl_descr mod_name)
+ (cl_descr mod_name)
else
CCodeBlock fast_label fast_abs_c
)
\begin{code}
data IsThunk = IsThunk | IsFunction -- Bool-like, local
---#ifdef DEBUG
+-- #ifdef DEBUG
deriving Eq
---#endif
+-- #endif
enterCostCentreCode :: ClosureInfo -> CostCentreStack -> IsThunk -> Code
costCentresC SLIT("ENTER_CCS_FSUB") []
else if isCurrentCCS ccs then
- -- get CCC out of the closure, where we put it when we alloc'd
- case is_thunk of
- IsThunk -> costCentresC SLIT("ENTER_CCS_TCL") [CReg node]
- IsFunction -> costCentresC SLIT("ENTER_CCS_FCL") [CReg node]
+ if re_entrant
+ then costCentresC SLIT("ENTER_CCS_FCL") [CReg node]
+ else costCentresC SLIT("ENTER_CCS_TCL") [CReg node]
else if isCafCCS ccs && isToplevClosure closure_info then
ASSERT(is_thunk == IsThunk)
- costCentresC SLIT("ENTER_CCS_CAF") c_ccs
+ -- might be a PAP, in which case we want to subsume costs
+ if re_entrant
+ then costCentresC SLIT("ENTER_CCS_FSUB") []
+ else costCentresC SLIT("ENTER_CCS_CAF") c_ccs
else -- we've got a "real" cost centre right here in our hands...
case is_thunk of
else costCentresC SLIT("ENTER_CCS_FLOAD") c_ccs
where
c_ccs = [mkCCostCentreStack ccs]
+ re_entrant = closureReEntrant closure_info
\end{code}
%************************************************************************
binding information.
\begin{code}
-closureDescription :: FAST_STRING -- Module
+closureDescription :: Module -- Module
-> Name -- Id of closure binding
-> String
closureDescription mod_name name
= showSDoc (
hcat [char '<',
- ptext mod_name,
+ pprModule mod_name,
char '.',
ppr name,
char '>'])