[project @ 2000-04-20 15:34:17 by simonmar]
[ghc-hetmet.git] / ghc / compiler / profiling / CostCentre.lhs
index 3bed2f8..15cd2af 100644 (file)
@@ -5,7 +5,7 @@
 
 \begin{code}
 module CostCentre (
-       CostCentre(..), CcName, IsDupdCC(..), IsCafCC(..), IsDictCC(..),
+       CostCentre(..), CcName, IsDupdCC(..), IsCafCC(..),
                -- All abstract except to friend: ParseIface.y
 
        CostCentreStack,
@@ -13,9 +13,9 @@ module CostCentre (
        noCostCentre, noCCAttached,
        noCCSAttached, isCurrentCCS,  isSubsumedCCS, currentOrSubsumedCCS,
 
-       mkUserCC, mkAutoCC, mkDictCC, mkAllCafsCC, mkAllDictsCC,
+       mkUserCC, mkAutoCC, mkAllCafsCC, 
        mkSingletonCCS, cafifyCC, dupifyCC,
-       isCafCC, isDictCC, isDupdCC, isEmptyCC, isCafCCS,
+       isCafCC, isDupdCC, isEmptyCC, isCafCCS,
        isSccCountCostCentre,
        sccAbleCostCentre,
        ccFromThisModule,
@@ -29,9 +29,13 @@ module CostCentre (
 
 import Var             ( Id )
 import Name            ( UserFS, EncodedFS, encodeFS, decode,
-                         Module, getOccName, occNameFS, pprModule, moduleUserString
+                         getOccName, occNameFS
+                       )
+import Module          ( Module, ModuleName, moduleName,
+                         pprModuleName, moduleNameUserString
                        )
 import Outputable      
+import CStrings                ( pprStringInCStyle )
 import Util            ( thenCmp )
 \end{code}
 
@@ -95,42 +99,23 @@ data CostCentreStack
 A Cost Centre is the argument of an _scc_ expression.
  
 \begin{code}
-type Group = FAST_STRING       -- "Group" that this CC is in; eg directory
-
 data CostCentre
   = NoCostCentre       -- Having this constructor avoids having
                        -- to use "Maybe CostCentre" all the time.
 
   | NormalCC {  
-               cc_name :: CcName,              -- Name of the cost centre itself
-               cc_mod  :: Module,              -- Name of module defining this CC.
-               cc_grp  :: Group,               -- "Group" that this CC is in.
-               cc_is_dict :: IsDictCC,         -- see below
-               cc_is_dupd :: IsDupdCC,         -- see below
-               cc_is_caf  :: IsCafCC           -- see below
+               cc_name :: CcName,      -- Name of the cost centre itself
+               cc_mod  :: ModuleName,  -- Name of module defining this CC.
+               cc_is_dupd :: IsDupdCC, -- see below
+               cc_is_caf  :: IsCafCC   -- see below
     }
 
   | AllCafsCC {        
-               cc_mod  :: Module,              -- Name of module defining this CC.
-               cc_grp  :: Group                -- "Group" that this CC is in
-                       -- Again, one "big" CAF cc per module, where all
-                       -- CAF costs are attributed unless the user asked for
-                       -- per-individual-CAF cost attribution.
-    }
-
-  | AllDictsCC {
-               cc_mod  :: Module,              -- Name of module defining this CC.
-               cc_grp  :: Group,               -- "Group" that this CC is in.
-                       -- Again, one "big" DICT cc per module, where all
-                       -- DICT costs are attributed unless the user asked for
-                       -- per-individual-DICT cost attribution.
-               cc_is_dupd :: IsDupdCC
+               cc_mod  :: ModuleName   -- Name of module defining this CC.
     }
 
 type CcName = EncodedFS
 
-data IsDictCC = DictCC | VanillaCC
-
 data IsDupdCC
   = OriginalCC -- This says how the CC is *used*.  Saying that
   | DupdCC             -- it is DupdCC doesn't make it a different
@@ -186,9 +171,6 @@ isSubsumedCCS _                             = False
 isCafCCS (SingletonCCS cc)             = isCafCC cc
 isCafCCS _                             = False
 
-isDictCCS (SingletonCCS cc)            = isDictCC cc
-isDictCCS _                            = False
-
 currentOrSubsumedCCS SubsumedCCS       = True
 currentOrSubsumedCCS CurrentCCS                = True
 currentOrSubsumedCCS _                 = False
@@ -197,38 +179,27 @@ currentOrSubsumedCCS _                    = False
 Building cost centres
 
 \begin{code}
-mkUserCC :: UserFS -> Module -> Group -> CostCentre
+mkUserCC :: UserFS -> Module -> CostCentre
 
-mkUserCC cc_name module_name group_name
-  = NormalCC { cc_name = encodeFS cc_name,
-              cc_mod =  module_name, cc_grp = group_name,
-              cc_is_dict = VanillaCC, cc_is_dupd = OriginalCC, cc_is_caf = NotCafCC {-might be changed-}
+mkUserCC cc_name mod
+  = NormalCC { cc_name = encodeFS cc_name, cc_mod =  moduleName mod,
+              cc_is_dupd = OriginalCC, cc_is_caf = NotCafCC {-might be changed-}
     }
 
-mkDictCC, mkAutoCC :: Id -> Module -> Group -> IsCafCC -> CostCentre
+mkAutoCC :: Id -> Module -> IsCafCC -> CostCentre
 
-mkDictCC id module_name group_name is_caf
-  = NormalCC { cc_name = occNameFS (getOccName id),
-              cc_mod =  module_name, cc_grp = group_name,
-              cc_is_dict = DictCC, cc_is_dupd = OriginalCC, cc_is_caf = is_caf
+mkAutoCC id mod is_caf
+  = NormalCC { cc_name = occNameFS (getOccName id), cc_mod =  moduleName mod,
+              cc_is_dupd = OriginalCC, cc_is_caf = is_caf
     }
 
-mkAutoCC id module_name group_name is_caf
-  = NormalCC { cc_name = occNameFS (getOccName id), 
-              cc_mod =  module_name, cc_grp = group_name,
-              cc_is_dict = VanillaCC, cc_is_dupd = OriginalCC, cc_is_caf = is_caf
-    }
-
-mkAllCafsCC  m g         = AllCafsCC  { cc_mod = m, cc_grp = g }
-mkAllDictsCC m g is_dupd  = AllDictsCC { cc_mod = m, cc_grp = g, 
-                                        cc_is_dupd = if is_dupd then DupdCC else OriginalCC }
+mkAllCafsCC m = AllCafsCC  { cc_mod = moduleName m }
 
 mkSingletonCCS :: CostCentre -> CostCentreStack
 mkSingletonCCS cc = SingletonCCS cc
 
 cafifyCC, dupifyCC  :: CostCentre -> CostCentre
 
-cafifyCC cc@(AllDictsCC {}) = cc
 cafifyCC cc@(NormalCC {cc_is_caf = is_caf})
   = ASSERT(not_a_caf_already is_caf)
     cc {cc_is_caf = CafCC}
@@ -239,7 +210,7 @@ cafifyCC cc = pprPanic "cafifyCC" (ppr cc)
 
 dupifyCC cc = cc {cc_is_dupd = DupdCC}
 
-isEmptyCC, isCafCC, isDictCC, isDupdCC :: CostCentre -> Bool
+isEmptyCC, isCafCC, isDupdCC :: CostCentre -> Bool
 
 isEmptyCC (NoCostCentre)               = True
 isEmptyCC _                            = False
@@ -248,11 +219,6 @@ isCafCC (AllCafsCC {})                      = True
 isCafCC (NormalCC {cc_is_caf = CafCC}) = True
 isCafCC _                               = False
 
-isDictCC (AllDictsCC {})                 = True
-isDictCC (NormalCC {cc_is_dict = DictCC}) = True
-isDictCC _                               = False
-
-isDupdCC (AllDictsCC {cc_is_dupd = DupdCC}) = True
 isDupdCC (NormalCC   {cc_is_dupd = DupdCC}) = True
 isDupdCC _                                  = False
 
@@ -264,7 +230,6 @@ isSccCountCostCentre NoCostCentre  = panic "isSccCount:NoCostCentre"
 #endif
 isSccCountCostCentre cc | isCafCC cc  = False
                         | isDupdCC cc = False
-                       | isDictCC cc = True
                        | otherwise   = True
 
 sccAbleCostCentre :: CostCentre -> Bool
@@ -277,7 +242,7 @@ sccAbleCostCentre cc | isCafCC cc = False
                     | otherwise  = True
 
 ccFromThisModule :: CostCentre -> Module -> Bool
-ccFromThisModule cc m = cc_mod cc == m
+ccFromThisModule cc m = cc_mod cc == moduleName m
 \end{code}
 
 \begin{code}
@@ -290,7 +255,6 @@ instance Ord CostCentre where
 cmpCostCentre :: CostCentre -> CostCentre -> Ordering
 
 cmpCostCentre (AllCafsCC  {cc_mod = m1}) (AllCafsCC  {cc_mod = m2}) = m1 `compare` m2
-cmpCostCentre (AllDictsCC {cc_mod = m1}) (AllDictsCC {cc_mod = m2}) = m1 `compare` m2
 
 cmpCostCentre (NormalCC {cc_name = n1, cc_mod =  m1, cc_is_caf = c1}) 
              (NormalCC {cc_name = n2, cc_mod =  m2, cc_is_caf = c2}) 
@@ -307,7 +271,6 @@ cmpCostCentre other_1 other_2
   where
     tag_CC (NormalCC   {}) = (ILIT(1) :: FAST_INT)
     tag_CC (AllCafsCC  {}) = ILIT(2)
-    tag_CC (AllDictsCC {}) = ILIT(3)
 
 cmp_caf NotCafCC CafCC     = LT
 cmp_caf NotCafCC NotCafCC  = EQ
@@ -329,19 +292,15 @@ instance Outputable CostCentreStack where
                NoCCS           -> ptext SLIT("NO_CCS")
                CurrentCCS      -> ptext SLIT("CCCS")
                OverheadCCS     -> ptext SLIT("CCS_OVERHEAD")
-               DontCareCCS     -> ptext SLIT("CCS_DONTZuCARE")
+               DontCareCCS     -> ptext SLIT("CCS_DONT_CARE")
                SubsumedCCS     -> ptext SLIT("CCS_SUBSUMED")
-               SingletonCCS cc -> ptext SLIT("CCS_") <> ppr cc
+               SingletonCCS cc -> ppr cc <> ptext SLIT("_ccs")
 
 pprCostCentreStackDecl :: CostCentreStack -> SDoc
 pprCostCentreStackDecl ccs@(SingletonCCS cc)
-  = let
-       is_subsumed = ccSubsumed cc
-    in
-    hcat [ ptext SLIT("CCS_DECLARE"), char '(',
+  = hcat [ ptext SLIT("CCS_DECLARE"), char '(',
           ppr ccs,             comma,  -- better be codeStyle
           ppCostCentreLbl cc,  comma,
-          ptext is_subsumed,   comma,
           empty,       -- Now always externally visible
           text ");"
         ]
@@ -372,24 +331,17 @@ instance Outputable CostCentre where
           else text (costCentreUserName cc)
 
 -- Printing in an interface file or in Core generally
-pprCostCentreCore (AllCafsCC {cc_mod = m, cc_grp = g})
-  = text "__sccC" <+> braces (pprModule m <+> doubleQuotes (ptext g))
-pprCostCentreCore (AllDictsCC {cc_mod = m, cc_grp = g, cc_is_dupd = dup})
-  = text "__sccD" <+> braces (pprModule m <+> doubleQuotes (ptext g) <+> pp_dup dup)
-pprCostCentreCore (NormalCC {cc_name = n, cc_mod = m, cc_grp = g,
-                            cc_is_dict = dic, cc_is_caf = caf, cc_is_dupd = dup})
+pprCostCentreCore (AllCafsCC {cc_mod = m})
+  = text "__sccC" <+> braces (pprModuleName m)
+pprCostCentreCore (NormalCC {cc_name = n, cc_mod = m,
+                            cc_is_caf = caf, cc_is_dupd = dup})
   = text "__scc" <+> braces (hsep [
        ptext n,
-       pprModule m,    
-       doubleQuotes (ptext g),
-       pp_dict dic,
+       pprModuleName m,        
        pp_dup dup,
        pp_caf caf
     ])
 
-pp_dict DictCC = text "__A"
-pp_dict other  = empty
-
 pp_dup DupdCC = char '!'
 pp_dup other   = empty
 
@@ -398,17 +350,17 @@ pp_caf other   = empty
 
 
 -- Printing as a C label
-ppCostCentreLbl (NoCostCentre)                      = text "CC_NONE"
-ppCostCentreLbl (AllCafsCC  {cc_mod = m})           = text "CC_CAFs_"  <> pprModule m
-ppCostCentreLbl (AllDictsCC {cc_mod = m})           = text "CC_DICTs_" <> pprModule m
-ppCostCentreLbl (NormalCC {cc_name = n, cc_mod = m}) = text "CC_" <> pprModule m <> ptext n
+ppCostCentreLbl (NoCostCentre)           = text "NONE_cc"
+ppCostCentreLbl (AllCafsCC  {cc_mod = m}) = pprModuleName m <> text "_CAFs_cc"
+ppCostCentreLbl (NormalCC {cc_name = n, cc_mod = m, cc_is_caf = is_caf}) 
+  = pprModuleName m <> ptext n <> 
+       text (case is_caf of { CafCC -> "_CAF"; _ -> "" }) <> text "_cc"
 
 -- This is the name to go in the user-displayed string, 
 -- recorded in the cost centre declaration
 costCentreUserName (NoCostCentre)  = "NO_CC"
-costCentreUserName (AllCafsCC {})  = "CAFs_in_..."
-costCentreUserName (AllDictsCC {}) = "DICTs_in_..."
-costCentreUserName (NormalCC {cc_name = name, cc_is_caf = is_caf})
+costCentreUserName (AllCafsCC {})  = "CAF"
+costCentreUserName cc@(NormalCC {cc_name = name, cc_is_caf = is_caf})
   =  case is_caf of { CafCC -> "CAF:";   _ -> "" } ++ decode (_UNPK_ name)
 \end{code}
 
@@ -423,11 +375,10 @@ pprCostCentreDecl is_local cc
   = if is_local then
        hcat [
            ptext SLIT("CC_DECLARE"),char '(',
-           cc_ident,                                           comma,
-           text (costCentreUserName cc),                       comma,
-           doubleQuotes (text (moduleUserString mod_name)),    comma,
-           doubleQuotes (ptext grp_name),                      comma,
-           ptext is_subsumed,                                  comma,
+           cc_ident,                                                   comma,
+           pprStringInCStyle (costCentreUserName cc),                  comma,
+           pprStringInCStyle (moduleNameUserString mod_name),          comma,
+           ptext is_subsumed,                                          comma,
            empty,      -- Now always externally visible
            text ");"]
     else
@@ -435,11 +386,9 @@ pprCostCentreDecl is_local cc
   where
     cc_ident    = ppCostCentreLbl cc
     mod_name   = cc_mod cc
-    grp_name   = cc_grp cc
     is_subsumed = ccSubsumed cc
 
 ccSubsumed :: CostCentre -> FAST_STRING                -- subsumed value
 ccSubsumed cc | isCafCC  cc = SLIT("CC_IS_CAF")
-             | isDictCC cc = SLIT("CC_IS_DICT")
              | otherwise   = SLIT("CC_IS_BORING")
 \end{code}