2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[SCCauto]{Automated SCC annotations}
6 Automatic insertion of \tr{_scc_} annotations for top-level bindings.
8 Automatic insertion of \tr{_scc_} annotations on CAFs is better left
9 until STG land. We do DICT annotations there, too, but maybe that
10 will turn out to be a bummer... (WDP 94/06)
12 This is a Core-to-Core pass (usually run {\em last}).
15 #include "HsVersions.h"
17 module SCCauto ( addAutoCostCentres ) where
21 import CmdLineOpts ( opt_AutoSccsOnAllToplevs,
22 opt_AutoSccsOnExportedToplevs,
26 import CostCentre ( mkAutoCC, IsCafCC(..) )
27 import Id ( isTopLevId, GenId{-instances-} )
28 import Name ( isExported )
33 :: FAST_STRING -- module name
34 -> [CoreBinding] -- input
35 -> [CoreBinding] -- output
37 addAutoCostCentres mod_name binds
38 = if not doing_something then
39 binds -- now *that* was quick...
41 map scc_top_bind binds
43 doing_something = auto_all_switch_on || auto_exported_switch_on
45 auto_all_switch_on = opt_AutoSccsOnAllToplevs -- only use!
46 auto_exported_switch_on = opt_AutoSccsOnExportedToplevs -- only use!
49 = case opt_SccGroup of
51 Nothing -> mod_name -- default: module name
53 -----------------------------
54 scc_top_bind (NonRec binder rhs)
55 = NonRec binder (scc_auto binder rhs)
57 scc_top_bind (Rec pairs)
58 = Rec (map scc_pair pairs)
60 scc_pair (binder, rhs) = (binder, scc_auto binder rhs)
62 -----------------------------
63 -- Automatic scc annotation for user-defined top-level Ids
66 = if isTopLevId binder
67 && (auto_all_switch_on || isExported binder)
71 -- park auto SCC inside lambdas; don't put one there
72 -- if there already is one.
76 (usevars, tyvars, vars, body) = collectBinders rhs
79 SCC _ _ -> rhs -- leave it
81 _ -> mkUseLam usevars (mkLam tyvars vars
82 (SCC (mkAutoCC binder mod_name grp_name IsNotCafCC) body))