+mkInline :: Bool -> CoreExpr -> CoreExpr
+mkInline True body = mkInlineMe body
+mkInline False body = body
+
+addLocalInlines :: [(a, Id, Id)] -> NameSet -> [(Id,CoreExpr)] -> [(Id,CoreExpr)]
+addLocalInlines exports inlines pairs
+ = [(bndr, mkInline (bndr `elemVarSet` local_inlines) rhs) | (bndr,rhs) <- pairs]
+ where
+ local_inlines = mkVarSet [l | (_,g,l) <- exports, idName g `elemNameSet` inlines]
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection[addAutoScc]{Adding automatic sccs}
+%* *
+%************************************************************************
+
+\begin{code}
+data AutoScc
+ = TopLevel
+ | TopLevelAddSccs (Id -> Maybe Id)
+ | NoSccs
+
+addSccs :: AutoScc -> [(a,Id,Id)] -> AutoScc
+addSccs auto_scc@(TopLevelAddSccs _) exports = auto_scc
+addSccs NoSccs exports = NoSccs
+addSccs TopLevel exports
+ = TopLevelAddSccs (\id -> case [ exp | (_,exp,loc) <- exports, loc == id ] of
+ (exp:_) | opt_AutoSccsOnAllToplevs ||
+ (isExportedId exp &&
+ opt_AutoSccsOnExportedToplevs)
+ -> Just exp
+ _ -> Nothing)
+
+addAutoScc :: AutoScc -- if needs be, decorate toplevs?
+ -> (Id, CoreExpr)
+ -> DsM (Id, CoreExpr)
+
+addAutoScc (TopLevelAddSccs auto_scc_fn) pair@(bndr, core_expr)
+ | do_auto_scc
+ = getModuleDs `thenDs` \ mod ->
+ returnDs (bndr, mkSCC (mkAutoCC top_bndr mod NotCafCC) core_expr)
+ where do_auto_scc = isJust maybe_auto_scc
+ maybe_auto_scc = auto_scc_fn bndr
+ (Just top_bndr) = maybe_auto_scc
+
+addAutoScc _ pair
+ = returnDs pair
+\end{code}
+
+If profiling and dealing with a dict binding,
+wrap the dict in @_scc_ DICT <dict>@:
+
+\begin{code}
+addDictScc var rhs = returnDs rhs
+
+{- DISABLED for now (need to somehow make up a name for the scc) -- SDM
+ | not ( opt_SccProfilingOn && opt_AutoSccsOnDicts)