Skip to content

Commit

Permalink
Remove StgBinderInfo and related computation in CoreToStg
Browse files Browse the repository at this point in the history
- The StgBinderInfo type was never used in the code gen, so the type, related
  computation in CoreToStg, and some comments about it are removed. See #15770
  for more details.

- Simplified CoreToStg after removing the StgBinderInfo computation: removed
  StgBinderInfo arguments and mfix stuff.

The StgBinderInfo values were not used in the code gen, but I still run nofib
just to make sure: 0.0% change in allocations and binary sizes.

Test Plan: Validated locally

Reviewers: simonpj, simonmar, bgamari, sgraf

Reviewed By: sgraf

Subscribers: AndreasK, sgraf, rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5232
  • Loading branch information
osa1 committed Nov 12, 2018
1 parent 13ff0b7 commit d30352a
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 248 deletions.
4 changes: 2 additions & 2 deletions compiler/codeGen/StgCmm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ cgTopRhs dflags _rec bndr (StgRhsCon _cc con args)
-- con args are always non-void,
-- see Note [Post-unarisation invariants] in UnariseStg

cgTopRhs dflags rec bndr (StgRhsClosure cc bi fvs upd_flag args body)
cgTopRhs dflags rec bndr (StgRhsClosure cc fvs upd_flag args body)
= ASSERT(null fvs) -- There should be no free variables
cgTopRhsClosure dflags rec bndr cc bi upd_flag args body
cgTopRhsClosure dflags rec bndr cc upd_flag args body


---------------------------------------------------------------
Expand Down
15 changes: 7 additions & 8 deletions compiler/codeGen/StgCmmBind.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ cgTopRhsClosure :: DynFlags
-> RecFlag -- member of a recursive group?
-> Id
-> CostCentreStack -- Optional cost centre annotation
-> StgBinderInfo
-> UpdateFlag
-> [Id] -- Args
-> StgExpr
-> (CgIdInfo, FCode ())

cgTopRhsClosure dflags rec id ccs _ upd_flag args body =
cgTopRhsClosure dflags rec id ccs upd_flag args body =
let closure_label = mkLocalClosureLabel (idName id) (idCafInfo id)
cg_id_info = litIdInfo dflags id lf_info (CmmLabel closure_label)
lf_info = mkClosureLFInfo dflags id TopLevel [] upd_flag args
Expand Down Expand Up @@ -207,15 +206,15 @@ cgRhs id (StgRhsCon cc con args)
-- see Note [Post-unarisation invariants] in UnariseStg

{- See Note [GC recovery] in compiler/codeGen/StgCmmClosure.hs -}
cgRhs id (StgRhsClosure cc bi fvs upd_flag args body)
cgRhs id (StgRhsClosure cc fvs upd_flag args body)
= do dflags <- getDynFlags
mkRhsClosure dflags id cc bi (nonVoidIds fvs) upd_flag args body
mkRhsClosure dflags id cc (nonVoidIds fvs) upd_flag args body

------------------------------------------------------------------------
-- Non-constructor right hand sides
------------------------------------------------------------------------

mkRhsClosure :: DynFlags -> Id -> CostCentreStack -> StgBinderInfo
mkRhsClosure :: DynFlags -> Id -> CostCentreStack
-> [NonVoid Id] -- Free vars
-> UpdateFlag
-> [Id] -- Args
Expand Down Expand Up @@ -258,7 +257,7 @@ for semi-obvious reasons.
-}

---------- Note [Selectors] ------------------
mkRhsClosure dflags bndr _cc _bi
mkRhsClosure dflags bndr _cc
[NonVoid the_fv] -- Just one free var
upd_flag -- Updatable thunk
[] -- A thunk
Expand Down Expand Up @@ -291,7 +290,7 @@ mkRhsClosure dflags bndr _cc _bi
in cgRhsStdThunk bndr lf_info [StgVarArg the_fv]

---------- Note [Ap thunks] ------------------
mkRhsClosure dflags bndr _cc _bi
mkRhsClosure dflags bndr _cc
fvs
upd_flag
[] -- No args; a thunk
Expand Down Expand Up @@ -323,7 +322,7 @@ mkRhsClosure dflags bndr _cc _bi
payload = StgVarArg fun_id : args

---------- Default case ------------------
mkRhsClosure dflags bndr cc _ fvs upd_flag args body
mkRhsClosure dflags bndr cc fvs upd_flag args body
= do { let lf_info = mkClosureLFInfo dflags bndr NotTopLevel fvs upd_flag args
; (id_info, reg) <- rhsIdInfo bndr lf_info
; return (id_info, gen_code lf_info reg) }
Expand Down
86 changes: 0 additions & 86 deletions compiler/codeGen/StgCmmClosure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -622,92 +622,6 @@ getCallMethod _ _name _ LFLetNoEscape _n_args _v_args (LneLoc blk_id lne_regs)

getCallMethod _ _ _ _ _ _ _ _ = panic "Unknown call method"

-----------------------------------------------------------------------------
-- staticClosureRequired
-----------------------------------------------------------------------------

{- staticClosureRequired is never called (hence commented out)
SimonMar writes (Sept 07) It's an optimisation we used to apply at
one time, I believe, but it got lost probably in the rewrite of
the RTS/code generator. I left that code there to remind me to
look into whether it was worth doing sometime
{- Avoiding generating entries and info tables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At present, for every function we generate all of the following,
just in case. But they aren't always all needed, as noted below:
[NB1: all of this applies only to *functions*. Thunks always
have closure, info table, and entry code.]
[NB2: All are needed if the function is *exported*, just to play safe.]
* Fast-entry code ALWAYS NEEDED
* Slow-entry code
Needed iff (a) we have any un-saturated calls to the function
OR (b) the function is passed as an arg
OR (c) we're in the parallel world and the function has free vars
[Reason: in parallel world, we always enter functions
with free vars via the closure.]
* The function closure
Needed iff (a) we have any un-saturated calls to the function
OR (b) the function is passed as an arg
OR (c) if the function has free vars (ie not top level)
Why case (a) here? Because if the arg-satis check fails,
UpdatePAP stuffs a pointer to the function closure in the PAP.
[Could be changed; UpdatePAP could stuff in a code ptr instead,
but doesn't seem worth it.]
[NB: these conditions imply that we might need the closure
without the slow-entry code. Here's how.
f x y = let g w = ...x..y..w...
in
...(g t)...
Here we need a closure for g which contains x and y,
but since the calls are all saturated we just jump to the
fast entry point for g, with R1 pointing to the closure for g.]
* Standard info table
Needed iff (a) we have any un-saturated calls to the function
OR (b) the function is passed as an arg
OR (c) the function has free vars (ie not top level)
NB. In the sequential world, (c) is only required so that the function closure has
an info table to point to, to keep the storage manager happy.
If (c) alone is true we could fake up an info table by choosing
one of a standard family of info tables, whose entry code just
bombs out.
[NB In the parallel world (c) is needed regardless because
we enter functions with free vars via the closure.]
If (c) is retained, then we'll sometimes generate an info table
(for storage mgr purposes) without slow-entry code. Then we need
to use an error label in the info table to substitute for the absent
slow entry code.
-}
staticClosureRequired
:: Name
-> StgBinderInfo
-> LambdaFormInfo
-> Bool
staticClosureRequired binder bndr_info
(LFReEntrant top_level _ _ _ _) -- It's a function
= ASSERT( isTopLevel top_level )
-- Assumption: it's a top-level, no-free-var binding
not (satCallsOnly bndr_info)
staticClosureRequired binder other_binder_info other_lf_info = True
-}

-----------------------------------------------------------------------------
-- Data types for closure information
-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion compiler/codeGen/StgCmmExpr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ cgLetNoEscapeRhsBody
-> Id
-> StgRhs
-> FCode (CgIdInfo, FCode ())
cgLetNoEscapeRhsBody local_cc bndr (StgRhsClosure cc _bi _ _upd args body)
cgLetNoEscapeRhsBody local_cc bndr (StgRhsClosure cc _ _upd args body)
= cgLetNoEscapeClosure bndr local_cc cc (nonVoidIds args) body
cgLetNoEscapeRhsBody local_cc bndr (StgRhsCon cc con args)
= cgLetNoEscapeClosure bndr local_cc cc []
Expand Down
8 changes: 4 additions & 4 deletions compiler/simplStg/StgCse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ stgCseTopLvl in_scope (StgTopLifted (StgRec eqs))
where in_scope' = in_scope `extendInScopeSetList` [ bndr | (bndr, _) <- eqs ]

stgCseTopLvlRhs :: InScopeSet -> InStgRhs -> OutStgRhs
stgCseTopLvlRhs in_scope (StgRhsClosure ccs info occs upd args body)
stgCseTopLvlRhs in_scope (StgRhsClosure ccs occs upd args body)
= let body' = stgCseExpr (initEnv in_scope) body
in StgRhsClosure ccs info occs upd args body'
in StgRhsClosure ccs occs upd args body'
stgCseTopLvlRhs _ (StgRhsCon ccs dataCon args)
= StgRhsCon ccs dataCon args

Expand Down Expand Up @@ -402,11 +402,11 @@ stgCseRhs env bndr (StgRhsCon ccs dataCon args)
pair = (bndr, StgRhsCon ccs dataCon args')
in (Just pair, env')
where args' = substArgs env args
stgCseRhs env bndr (StgRhsClosure ccs info occs upd args body)
stgCseRhs env bndr (StgRhsClosure ccs occs upd args body)
= let (env1, args') = substBndrs env args
env2 = forgetCse env1 -- See note [Free variables of an StgClosure]
body' = stgCseExpr env2 body
in (Just (substVar env bndr, StgRhsClosure ccs info occs' upd args' body'), env)
in (Just (substVar env bndr, StgRhsClosure ccs occs' upd args' body'), env)
where occs' = substVars env occs


Expand Down
2 changes: 1 addition & 1 deletion compiler/simplStg/StgStats.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ statRhs :: Bool -> (Id, StgRhs) -> StatEnv
statRhs top (_, StgRhsCon _ _ _)
= countOne (ConstructorBinds top)

statRhs top (_, StgRhsClosure _ _ fv u _ body)
statRhs top (_, StgRhsClosure _ fv u _ body)
= statExpr body `combineSE`
countN FreeVariables (length fv) `combineSE`
countOne (
Expand Down
4 changes: 2 additions & 2 deletions compiler/simplStg/UnariseStg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ unariseBinding rho (StgRec xrhss)
= StgRec <$> mapM (\(x, rhs) -> (x,) <$> unariseRhs rho rhs) xrhss

unariseRhs :: UnariseEnv -> StgRhs -> UniqSM StgRhs
unariseRhs rho (StgRhsClosure ccs b_info fvs update_flag args expr)
unariseRhs rho (StgRhsClosure ccs fvs update_flag args expr)
= do (rho', args1) <- unariseFunArgBinders rho args
expr' <- unariseExpr rho' expr
let fvs' = unariseFreeVars rho fvs
return (StgRhsClosure ccs b_info fvs' update_flag args1 expr')
return (StgRhsClosure ccs fvs' update_flag args1 expr')

unariseRhs rho (StgRhsCon ccs con args)
= ASSERT(not (isUnboxedTupleCon con || isUnboxedSumCon con))
Expand Down
Loading

0 comments on commit d30352a

Please sign in to comment.