2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
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
10 that 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
20 import Id ( isTopLevId )
22 import Outputable ( isExported )
23 import CostCentre -- ( mkAutoCC )
24 import Util -- for pragmas only
29 :: (GlobalSwitch -> SwitchResult) -- cmd-line switches
30 -> FAST_STRING -- module name
31 -> [PlainCoreBinding] -- input
32 -> [PlainCoreBinding] -- output
34 addAutoCostCentres sw_chkr mod_name binds
35 = if not doing_something then
36 binds -- now *that* was quick...
38 map scc_top_bind binds
40 doing_something = auto_all_switch_on || auto_exported_switch_on
42 auto_all_switch_on = switchIsOn sw_chkr AutoSccsOnAllToplevs -- only use!
43 auto_exported_switch_on = switchIsOn sw_chkr AutoSccsOnExportedToplevs -- only use!
45 grp_name = case (stringSwitchSet sw_chkr SccGroup) of
47 Nothing -> mod_name -- default: module name
49 -----------------------------
50 scc_top_bind (CoNonRec binder rhs)
51 = CoNonRec binder (scc_auto binder rhs)
53 scc_top_bind (CoRec pairs)
54 = CoRec (map scc_pair pairs)
56 scc_pair (binder, rhs) = (binder, scc_auto binder rhs)
58 -----------------------------
59 -- Automatic scc annotation for user-defined top-level Ids
62 = if isTopLevId binder
63 && (auto_all_switch_on || isExported binder)
67 -- park auto SCC inside lambdas; don't put one there
68 -- if there already is one.
72 (tyvars, vars, body) = digForLambdas rhs
75 CoSCC _ _ -> rhs -- leave it
76 CoCon _ _ _ --??? | null vars
78 _ -> mkFunction tyvars vars
79 (CoSCC (mkAutoCC binder mod_name grp_name IsNotCafCC) body)