-\subsection{Figuring out things about expressions}
-%* *
-%************************************************************************
-
-\begin{code}
-data FormSummary
- = VarForm -- Expression is a variable (or scc var, etc)
- | ValueForm -- Expression is a value: i.e. a value-lambda,constructor, or literal
- | BottomForm -- Expression is guaranteed to be bottom. We're more gung
- -- ho about inlining such things, because it can't waste work
- | OtherForm -- Anything else
-
-instance Outputable FormSummary where
- ppr VarForm = ptext SLIT("Var")
- ppr ValueForm = ptext SLIT("Value")
- ppr BottomForm = ptext SLIT("Bot")
- ppr OtherForm = ptext SLIT("Other")
-
-mkFormSummary ::GenCoreExpr bndr Id flexi -> FormSummary
-
-mkFormSummary expr
- = go (0::Int) expr -- The "n" is the number of (value) arguments so far
- where
- go n (Lit _) = ASSERT(n==0) ValueForm
- go n (Con _ _) = ASSERT(n==0) ValueForm
- go n (Prim _ _) = OtherForm
- go n (SCC _ e) = go n e
- go n (Coerce _ _ e) = go n e
-
- go n (Let (NonRec b r) e) | exprIsTrivial r = go n e -- let f = f' alpha in (f,g)
- -- should be treated as a value
- go n (Let _ e) = OtherForm
- go n (Case _ _) = OtherForm
-
- go 0 (Lam (ValBinder x) e) = ValueForm -- NB: \x.bottom /= bottom!
- go n (Lam (ValBinder x) e) = go (n-1) e -- Applied lambda
- go n (Lam other_binder e) = go n e
-
- go n (App fun arg) | isValArg arg = go (n+1) fun
- go n (App fun other_arg) = go n fun
-
- go n (Var f) | isBottomingId f = BottomForm
- | isDataCon f = ValueForm -- Can happen inside imported unfoldings
- go 0 (Var f) = VarForm
- go n (Var f) = case getIdArity f of
- ArityExactly a | n < a -> ValueForm
- ArityAtLeast a | n < a -> ValueForm
- other -> OtherForm
-
-whnfOrBottom :: FormSummary -> Bool
-whnfOrBottom VarForm = True
-whnfOrBottom ValueForm = True
-whnfOrBottom BottomForm = True
-whnfOrBottom OtherForm = False
-\end{code}
-
-@exprIsTrivial@ is true of expressions we are unconditionally happy to duplicate;
-simple variables and constants, and type applications.
-
-\begin{code}
-exprIsTrivial (Var v) = True
-exprIsTrivial (Lit lit) = not (isNoRepLit lit)
-exprIsTrivial (App e (TyArg _)) = exprIsTrivial e
-exprIsTrivial (Coerce _ _ e) = exprIsTrivial e
-exprIsTrivial other = False
-\end{code}
-
-\begin{code}
-exprSmallEnoughToDup (Con _ _) = True -- Could check # of args
-exprSmallEnoughToDup (Prim op _) = not (fragilePrimOp op) -- Could check # of args
-exprSmallEnoughToDup (Lit lit) = not (isNoRepLit lit)
-exprSmallEnoughToDup (Coerce _ _ e) = exprSmallEnoughToDup e
-exprSmallEnoughToDup expr
- = case (collectArgs expr) of { (fun, _, vargs) ->
- case fun of
- Var v | length vargs <= 4 -> True
- _ -> False
- }
-
-\end{code}
-
-
-%************************************************************************
-%* *