-\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 sty VarForm = ppStr "Var"
- ppr sty ValueForm = ppStr "Value"
- ppr sty BottomForm = ppStr "Bot"
- ppr sty OtherForm = ppStr "Other"
-
-mkFormSummary ::GenCoreExpr bndr Id tyvar uvar -> 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 _ 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
- 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 :: GenCoreExpr bndr Id tyvar uvar -> Bool
-whnfOrBottom e = case mkFormSummary e of
- VarForm -> True
- ValueForm -> True
- BottomForm -> True
- OtherForm -> 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 expr
- = case (collectArgs expr) of { (fun, _, _, vargs) ->
- case fun of
- Var v | length vargs == 0 -> True
- _ -> False
- }
-
-{- LATER:
-WAS: MORE CLEVER:
-exprSmallEnoughToDup expr -- for now, just: <var> applied to <args>
- = case (collectArgs expr) of { (fun, _, _, vargs) ->
- case fun of
- Var v -> v /= buildId
- && v /= augmentId
- && length vargs <= 6 -- or 10 or 1 or 4 or anything smallish.
- _ -> False
- }
--}
-\end{code}
-Question (ADR): What is the above used for? Is a _ccall_ really small
-enough?
-
-%************************************************************************
-%* *