[project @ 2005-11-25 14:33:12 by simonmar]
[ghc-hetmet.git] / ghc / compiler / stgSyn / StgSyn.lhs
index 40fbef7..f1c50cc 100644 (file)
@@ -33,7 +33,7 @@ module StgSyn (
        SRT(..),
 
        -- utils
-       stgArgHasCafRefs,
+       stgBindHasCafRefs, stgArgHasCafRefs, stgRhsArity,
        isDllConApp, isStgTypeArg,
        stgArgType,
 
@@ -49,10 +49,10 @@ module StgSyn (
 import CostCentre      ( CostCentreStack, CostCentre )
 import VarSet          ( IdSet, isEmptyVarSet )
 import Var             ( isId )
-import Id              ( Id, idName, idPrimRep, idType, idCafInfo )
+import Id              ( Id, idName, idType, idCafInfo )
 import IdInfo          ( mayHaveCafRefs )
-import Name            ( isDllName )
-import Literal         ( Literal, literalType, literalPrimRep )
+import Packages                ( isDllName )
+import Literal         ( Literal, literalType )
 import ForeignCall     ( ForeignCall )
 import DataCon         ( DataCon, dataConName )
 import CoreSyn         ( AltCon )
@@ -65,7 +65,9 @@ import TyCon            ( TyCon )
 import UniqSet         ( isEmptyUniqSet, uniqSetToList, UniqSet )
 import Unique          ( Unique )
 import Bitmap
-import CmdLineOpts     ( opt_SccProfilingOn )
+import DynFlags                ( DynFlags )
+import Packages                ( HomeModules )
+import StaticFlags     ( opt_SccProfilingOn )
 \end{code}
 
 %************************************************************************
@@ -104,17 +106,18 @@ data GenStgArg occ
 isStgTypeArg (StgTypeArg _) = True
 isStgTypeArg other         = False
 
-isDllArg :: StgArg -> Bool
+isDllArg :: HomeModules -> StgArg -> Bool
        -- Does this argument refer to something in a different DLL?
-isDllArg (StgTypeArg v)  = False
-isDllArg (StgVarArg v)   = isDllName (idName v)
-isDllArg (StgLitArg lit) = False
+isDllArg hmods (StgTypeArg v)  = False
+isDllArg hmods (StgVarArg v)   = isDllName hmods (idName v)
+isDllArg hmods (StgLitArg lit) = False
 
-isDllConApp :: DataCon -> [StgArg] -> Bool
+isDllConApp :: HomeModules -> DataCon -> [StgArg] -> Bool
        -- Does this constructor application refer to 
        -- anything in a different DLL?
        -- If so, we can't allocate it statically
-isDllConApp con args = isDllName (dataConName con) || any isDllArg args
+isDllConApp hmods con args
+   = isDllName hmods (dataConName con) || any (isDllArg hmods) args
 
 stgArgType :: StgArg -> Type
        -- Very half baked becase we have lost the type arguments
@@ -324,12 +327,12 @@ And so the code for let(rec)-things:
   | StgLetNoEscape                     -- remember: ``advanced stuff''
        (GenStgLiveVars occ)            -- Live in the whole let-expression
                                        -- Mustn't overwrite these stack slots
-                                       -- *Doesn't* include binders of the let(rec).
+                                       --  *Doesn't* include binders of the let(rec).
 
        (GenStgLiveVars occ)            -- Live in the right hand sides (only)
                                        -- These are the ones which must be saved on
                                        -- the stack if they aren't there already
-                                       -- *Does* include binders of the let(rec) if recursive.
+                                       --  *Does* include binders of the let(rec) if recursive.
 
        (GenStgBinding bndr occ)        -- right hand sides (see below)
        (GenStgExpr bndr occ)           -- body
@@ -396,6 +399,19 @@ The second flavour of right-hand-side is for constructors (simple but important)
 \end{code}
 
 \begin{code}
+stgRhsArity :: StgRhs -> Int
+stgRhsArity (StgRhsClosure _ _ _ _ _ bndrs _) = count isId bndrs
+  -- The arity never includes type parameters, so
+  -- when keeping type arguments and binders in the Stg syntax 
+  -- (opt_RuntimeTypes) we have to fliter out the type binders.
+stgRhsArity (StgRhsCon _ _ _) = 0
+\end{code}
+
+\begin{code}
+stgBindHasCafRefs :: GenStgBinding bndr Id -> Bool
+stgBindHasCafRefs (StgNonRec _ rhs) = rhsHasCafRefs rhs
+stgBindHasCafRefs (StgRec binds)    = any rhsHasCafRefs (map snd binds)
+
 rhsHasCafRefs (StgRhsClosure _ _ _ upd srt _ _) 
   = isUpdatable upd || nonEmptySRT srt
 rhsHasCafRefs (StgRhsCon _ _ args)