-#else
- = if x == y then EQ_ elsid if x < y then LT_ else GT_
-#endif
- cmp_atom (CoLitAtom _) _ = GT_
-\end{code}
-
-\begin{code}
-data UnfoldingDetails
- = NoUnfoldingDetails
-
- | LiteralForm
- BasicLit
-
- | OtherLiteralForm
- [BasicLit] -- It is a literal, but definitely not one of these
-
- | ConstructorForm
- Id -- The constructor
- [UniType] -- Type args
- [OutAtom] -- Value arguments; NB OutAtoms, already cloned
-
- | OtherConstructorForm
- [Id] -- It definitely isn't one of these constructors
- -- This captures the situation in the default branch of
- -- a case: case x of
- -- c1 ... -> ...
- -- c2 ... -> ...
- -- v -> default-rhs
- -- Then in default-rhs we know that v isn't c1 or c2.
- --
- -- NB. In the degenerate: case x of {v -> default-rhs}
- -- x will be bound to
- -- OtherConstructorForm []
- -- which captures the idea that x is eval'd but we don't
- -- know which constructor.
-
-
- | GeneralForm
- Bool -- True <=> At most one textual occurrence of the
- -- binder in its scope, *or*
- -- if we are happy to duplicate this
- -- binding.
- FormSummary -- Tells whether the template is a WHNF or bottom
- TemplateOutExpr -- The template
- UnfoldingGuidance -- Tells about the *size* of the template.
-
- | MagicForm
- FAST_STRING
- MagicUnfoldingFun
-
- {-OLD? Nukable? ("Also turgid" SLPJ)-}
- | IWantToBeINLINEd -- Means this has an INLINE pragma;
- -- Used for things which have a defn in this module
- UnfoldingGuidance -- Guidance from the pragma; usually UnfoldAlways.
-
-data FormSummary
- = WhnfForm -- Expression is WHNF
- | 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 WhnfForm = ppStr "WHNF"
- ppr sty BottomForm = ppStr "Bot"
- ppr sty OtherForm = ppStr "Other"
-
-mkFormSummary :: StrictnessInfo -> CoreExpr bndr Id -> FormSummary
-mkFormSummary si expr
- | manifestlyWHNF expr = WhnfForm
- | bottomIsGuaranteed si = BottomForm
-
- -- Chances are that the Id will be decorated with strictness info
- -- telling that the RHS is definitely bottom. This *might* not be the
- -- case, if it's been a while since strictness analysis, but leaving out
- -- the test for manifestlyBottom makes things a little more efficient.
- -- We can always put it back...
- -- | manifestlyBottom expr = BottomForm
-
- | otherwise = OtherForm
-\end{code}
-
-\begin{code}
-data UnfoldingGuidance
- = UnfoldNever -- Don't do it!
-
- | UnfoldAlways -- There is no "original" definition,
- -- so you'd better unfold. Or: something
- -- so cheap to unfold (e.g., 1#) that
- -- you should do it absolutely always.
-
- | EssentialUnfolding -- Like UnfoldAlways, but you *must* do
- -- it absolutely always.
- -- This is what we use for data constructors
- -- and PrimOps, because we don't feel like
- -- generating curried versions "just in case".
-
- | UnfoldIfGoodArgs Int -- if "m" type args and "n" value args; and
- Int -- those val args are manifestly data constructors
- [Bool] -- the val-arg positions marked True
- -- (i.e., a simplification will definitely
- -- be possible).
- Int -- The "size" of the unfolding; to be elaborated
- -- later. ToDo
-\end{code}
-
-\begin{code}
-instance Outputable UnfoldingGuidance where
- ppr sty UnfoldNever = ppStr "_N_"
- ppr sty UnfoldAlways = ppStr "_ALWAYS_"
- ppr sty EssentialUnfolding = ppStr "_ESSENTIAL_" -- shouldn't appear in an iface
- ppr sty (UnfoldIfGoodArgs t v cs size)
- = ppCat [ppStr "_IF_ARGS_", ppInt t, ppInt v,
- if null cs -- always print *something*
- then ppChar 'X'
- else ppBesides (map pp_c cs),
- ppInt size ]
- where
- pp_c False = ppChar 'X'
- pp_c True = ppChar 'C'
-\end{code}
-
-%************************************************************************
-%* *
-\subsection{@mkGenForm@ and @modifyUnfoldingDetails@}
-%* *
-%************************************************************************
-
-\begin{code}
-mkGenForm :: Bool -- Ok to Dup code down different case branches,
- -- because of either a flag saying so,
- -- or alternatively the object is *SMALL*
- -> BinderInfo --
- -> FormSummary
- -> TemplateOutExpr -- Template
- -> UnfoldingGuidance -- Tells about the *size* of the template.
- -> UnfoldingDetails
-
-mkGenForm safe_to_dup occ_info WhnfForm template guidance
- = GeneralForm (oneTextualOcc safe_to_dup occ_info) WhnfForm template guidance
-
-mkGenForm safe_to_dup occ_info form_summary template guidance
- | oneSafeOcc safe_to_dup occ_info -- Non-WHNF with only safe occurrences
- = GeneralForm True form_summary template guidance
-
- | otherwise -- Not a WHNF, many occurrences
- = NoUnfoldingDetails
-\end{code}
-
-\begin{code}
-modifyUnfoldingDetails
- :: Bool -- OK to dup
- -> BinderInfo -- New occurrence info for the thing
- -> UnfoldingDetails
- -> UnfoldingDetails
-
-modifyUnfoldingDetails ok_to_dup occ_info
- (GeneralForm only_one form_summary template guidance)
- | only_one = mkGenForm ok_to_dup occ_info form_summary template guidance
-
-{- OLD:
- | otherwise = NoUnfoldingDetails
- I can't see why we zap bindings which don't claim to be unique
--}
-
-modifyUnfoldingDetails ok_to_dup occ_info other = other