From b2950e03b551d82d62ec25eb232284aaf121b4e2 Mon Sep 17 00:00:00 2001 From: Sebastian Graf Date: Fri, 23 Nov 2018 16:24:18 +0100 Subject: Implement late lambda lift Summary: This implements a selective lambda-lifting pass late in the STG pipeline. Lambda lifting has the effect of avoiding closure allocation at the cost of having to make former free vars available at call sites, possibly enlarging closures surrounding call sites in turn. We identify beneficial cases by means of an analysis that estimates closure growth. There's a Wiki page at https://ghc.haskell.org/trac/ghc/wiki/LateLamLift. Reviewers: simonpj, bgamari, simonmar Reviewed By: simonpj Subscribers: rwbarton, carter GHC Trac Issues: #9476 Differential Revision: https://phabricator.haskell.org/D5224 --- compiler/codeGen/StgCmm.hs | 4 ++-- compiler/codeGen/StgCmmBind.hs | 7 ++----- compiler/codeGen/StgCmmExpr.hs | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'compiler/codeGen') diff --git a/compiler/codeGen/StgCmm.hs b/compiler/codeGen/StgCmm.hs index 59ceba8706..acd2aee5f4 100644 --- a/compiler/codeGen/StgCmm.hs +++ b/compiler/codeGen/StgCmm.hs @@ -45,7 +45,7 @@ import Module import Outputable import Stream import BasicTypes -import VarSet ( isEmptyVarSet ) +import VarSet ( isEmptyDVarSet ) import OrdList import MkGraph @@ -156,7 +156,7 @@ cgTopRhs dflags _rec bndr (StgRhsCon _cc con args) -- see Note [Post-unarisation invariants] in UnariseStg cgTopRhs dflags rec bndr (StgRhsClosure fvs cc upd_flag args body) - = ASSERT(isEmptyVarSet fvs) -- There should be no free variables + = ASSERT(isEmptyDVarSet fvs) -- There should be no free variables cgTopRhsClosure dflags rec bndr cc upd_flag args body diff --git a/compiler/codeGen/StgCmmBind.hs b/compiler/codeGen/StgCmmBind.hs index dba122fd0c..9e14311d42 100644 --- a/compiler/codeGen/StgCmmBind.hs +++ b/compiler/codeGen/StgCmmBind.hs @@ -44,7 +44,7 @@ import Name import Module import ListSetOps import Util -import UniqSet ( nonDetEltsUniqSet ) +import VarSet import BasicTypes import Outputable import FastString @@ -209,10 +209,7 @@ cgRhs id (StgRhsCon cc con args) {- See Note [GC recovery] in compiler/codeGen/StgCmmClosure.hs -} cgRhs id (StgRhsClosure fvs cc upd_flag args body) = do dflags <- getDynFlags - mkRhsClosure dflags id cc (nonVoidIds (nonDetEltsUniqSet fvs)) upd_flag args body - -- It's OK to use nonDetEltsUniqSet here because we're not aiming for - -- bit-for-bit determinism. - -- See Note [Unique Determinism and code generation] + mkRhsClosure dflags id cc (nonVoidIds (dVarSetElems fvs)) upd_flag args body ------------------------------------------------------------------------ -- Non-constructor right hand sides diff --git a/compiler/codeGen/StgCmmExpr.hs b/compiler/codeGen/StgCmmExpr.hs index 2430a0ddf9..5844161fc1 100644 --- a/compiler/codeGen/StgCmmExpr.hs +++ b/compiler/codeGen/StgCmmExpr.hs @@ -81,8 +81,8 @@ cgExpr (StgTick t e) = cgTick t >> cgExpr e cgExpr (StgLit lit) = do cmm_lit <- cgLit lit emitReturn [CmmLit cmm_lit] -cgExpr (StgLet binds expr) = do { cgBind binds; cgExpr expr } -cgExpr (StgLetNoEscape binds expr) = +cgExpr (StgLet _ binds expr) = do { cgBind binds; cgExpr expr } +cgExpr (StgLetNoEscape _ binds expr) = do { u <- newUnique ; let join_id = mkBlockId u ; cgLneBinds join_id binds -- cgit v1.2.1