Fix warnings in CgStackery
[ghc-hetmet.git] / compiler / codeGen / CgTicky.hs
index 0be58dd..5422127 100644 (file)
@@ -1,3 +1,10 @@
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 -----------------------------------------------------------------------------
 --
 -- Code generation for ticky-ticky profiling
@@ -36,7 +43,6 @@ module CgTicky (
        staticTickyHdr,
   ) where
 
-#include "HsVersions.h"
 #include "../includes/DerivedConstants.h"
        -- For REP_xxx constants, which are MachReps
 
@@ -46,12 +52,12 @@ import CgMonad
 import SMRep
 
 import Cmm
-import MachOp
 import CmmUtils
 import CLabel
 
 import Name
 import Id
+import IdInfo
 import StaticFlags
 import BasicTypes
 import FastString
@@ -89,9 +95,9 @@ emitTickyCounter cl_info args on_stk
 -- krc: note that all the fields are I32 now; some were I16 before, 
 -- but the code generator wasn't handling that properly and it led to chaos, 
 -- panic and disorder.
-           [ CmmInt 0 I32,
-             CmmInt (fromIntegral (length args)) I32,  -- Arity
-             CmmInt (fromIntegral on_stk) I32,         -- Words passed on stack
+           [ mkIntCLit 0,
+             mkIntCLit (length args),-- Arity
+             mkIntCLit on_stk, -- Words passed on stack
              fun_descr_lit,
              arg_descr_lit,
              zeroCLit,                 -- Entry count
@@ -100,7 +106,7 @@ emitTickyCounter cl_info args on_stk
            ] }
   where
     name = closureName cl_info
-    ticky_ctr_label = mkRednCountsLabel name
+    ticky_ctr_label = mkRednCountsLabel name NoCafRefs
     arg_descr = map (showTypeCategory . idType) args
     fun_descr mod_name = ppr_for_ticky_name mod_name name
 
@@ -114,17 +120,17 @@ ppr_for_ticky_name mod_name name
 -- -----------------------------------------------------------------------------
 -- Ticky stack frames
 
-tickyPushUpdateFrame    = ifTicky $ bumpTickyCounter SLIT("UPDF_PUSHED_ctr")
-tickyUpdateFrameOmitted = ifTicky $ bumpTickyCounter SLIT("UPDF_OMITTED_ctr")
+tickyPushUpdateFrame    = ifTicky $ bumpTickyCounter (sLit "UPDF_PUSHED_ctr")
+tickyUpdateFrameOmitted = ifTicky $ bumpTickyCounter (sLit "UPDF_OMITTED_ctr")
 
 -- -----------------------------------------------------------------------------
 -- Ticky entries
 
-tickyEnterDynCon      = ifTicky $ bumpTickyCounter SLIT("ENT_DYN_CON_ctr")
-tickyEnterDynThunk    = ifTicky $ bumpTickyCounter SLIT("ENT_DYN_THK_ctr")
-tickyEnterStaticCon   = ifTicky $ bumpTickyCounter SLIT("ENT_STATIC_CON_ctr")
-tickyEnterStaticThunk = ifTicky $ bumpTickyCounter SLIT("ENT_STATIC_THK_ctr")
-tickyEnterViaNode     = ifTicky $ bumpTickyCounter SLIT("ENT_VIA_NODE_ctr")
+tickyEnterDynCon      = ifTicky $ bumpTickyCounter (sLit "ENT_DYN_CON_ctr")
+tickyEnterDynThunk    = ifTicky $ bumpTickyCounter (sLit "ENT_DYN_THK_ctr")
+tickyEnterStaticCon   = ifTicky $ bumpTickyCounter (sLit "ENT_STATIC_CON_ctr")
+tickyEnterStaticThunk = ifTicky $ bumpTickyCounter (sLit "ENT_STATIC_THK_ctr")
+tickyEnterViaNode     = ifTicky $ bumpTickyCounter (sLit "ENT_VIA_NODE_ctr")
 
 tickyEnterThunk :: ClosureInfo -> Code
 tickyEnterThunk cl_info
@@ -135,14 +141,14 @@ tickyBlackHole :: Bool{-updatable-} -> Code
 tickyBlackHole updatable
   = ifTicky (bumpTickyCounter ctr)
   where
-    ctr | updatable = SLIT("UPD_BH_SINGLE_ENTRY_ctr")
-       | otherwise = SLIT("UPD_BH_UPDATABLE_ctr")
+    ctr | updatable = sLit "UPD_BH_SINGLE_ENTRY_ctr"
+       | otherwise = sLit "UPD_BH_UPDATABLE_ctr"
 
 tickyUpdateBhCaf cl_info
   = ifTicky (bumpTickyCounter ctr)
   where
-    ctr | closureUpdReqd cl_info = SLIT("UPD_CAF_BH_SINGLE_ENTRY_ctr")
-       | otherwise              = SLIT("UPD_CAF_BH_UPDATABLE_ctr")
+    ctr | closureUpdReqd cl_info = sLit "UPD_CAF_BH_SINGLE_ENTRY_ctr"
+       | otherwise              = sLit "UPD_CAF_BH_UPDATABLE_ctr"
 
 tickyEnterFun :: ClosureInfo -> Code
 tickyEnterFun cl_info
@@ -153,8 +159,8 @@ tickyEnterFun cl_info
        ; bumpTickyCounter' (cmmLabelOffB fun_ctr_lbl oFFSET_StgEntCounter_entry_count)
         }
   where
-    ctr | isStaticClosure cl_info = SLIT("ENT_STATIC_FUN_DIRECT_ctr")
-       | otherwise               = SLIT("ENT_DYN_FUN_DIRECT_ctr")
+    ctr | isStaticClosure cl_info = sLit "ENT_STATIC_FUN_DIRECT_ctr"
+       | otherwise               = sLit "ENT_DYN_FUN_DIRECT_ctr"
 
 registerTickyCtr :: CLabel -> Code
 -- Register a ticky counter
@@ -166,47 +172,45 @@ registerTickyCtr ctr_lbl
   = emitIf test (stmtsC register_stmts)
   where
     -- krc: code generator doesn't handle Not, so we test for Eq 0 instead
-    test = CmmMachOp (MO_Eq I32)
+    test = CmmMachOp (MO_Eq wordWidth)
               [CmmLoad (CmmLit (cmmLabelOffB ctr_lbl 
-                               oFFSET_StgEntCounter_registeredp)) I32,
+                               oFFSET_StgEntCounter_registeredp)) bWord,
                CmmLit (mkIntCLit 0)]
     register_stmts
       =        [ CmmStore (CmmLit (cmmLabelOffB ctr_lbl oFFSET_StgEntCounter_link))
-                  (CmmLoad ticky_entry_ctrs wordRep)
+                  (CmmLoad ticky_entry_ctrs bWord)
        , CmmStore ticky_entry_ctrs (mkLblExpr ctr_lbl)
        , CmmStore (CmmLit (cmmLabelOffB ctr_lbl 
                                oFFSET_StgEntCounter_registeredp))
                   (CmmLit (mkIntCLit 1)) ]
-    ticky_entry_ctrs = mkLblExpr (mkRtsDataLabel SLIT("ticky_entry_ctrs"))
+    ticky_entry_ctrs = mkLblExpr (mkRtsDataLabel (sLit "ticky_entry_ctrs"))
 
 tickyReturnOldCon, tickyReturnNewCon :: Arity -> Code
 tickyReturnOldCon arity 
-  = ifTicky $ do { bumpTickyCounter SLIT("RET_OLD_ctr")
-                ; bumpHistogram SLIT("RET_OLD_hst") arity }
+  = ifTicky $ do { bumpTickyCounter (sLit "RET_OLD_ctr")
+                ; bumpHistogram (sLit "RET_OLD_hst") arity }
 tickyReturnNewCon arity 
-  | not opt_DoTickyProfiling = nopC
-  | otherwise
-  = ifTicky $ do { bumpTickyCounter SLIT("RET_NEW_ctr")
-                ; bumpHistogram SLIT("RET_NEW_hst") arity }
+  = ifTicky $ do { bumpTickyCounter (sLit "RET_NEW_ctr")
+                ; bumpHistogram (sLit "RET_NEW_hst") arity }
 
 tickyUnboxedTupleReturn :: Int -> Code
 tickyUnboxedTupleReturn arity
-  = ifTicky $ do { bumpTickyCounter SLIT("RET_UNBOXED_TUP_ctr")
-                ; bumpHistogram SLIT("RET_UNBOXED_TUP_hst") arity }
+  = ifTicky $ do { bumpTickyCounter (sLit "RET_UNBOXED_TUP_ctr")
+                ; bumpHistogram (sLit "RET_UNBOXED_TUP_hst") arity }
 
 tickyVectoredReturn :: Int -> Code
 tickyVectoredReturn family_size 
-  = ifTicky $ do { bumpTickyCounter SLIT("VEC_RETURN_ctr")
-                ; bumpHistogram SLIT("RET_VEC_RETURN_hst") family_size }
+  = ifTicky $ do { bumpTickyCounter (sLit "VEC_RETURN_ctr")
+                ; bumpHistogram (sLit "RET_VEC_RETURN_hst") family_size }
 
 -- -----------------------------------------------------------------------------
 -- Ticky calls
 
 -- Ticks at a *call site*:
-tickyKnownCallTooFewArgs = ifTicky $ bumpTickyCounter SLIT("KNOWN_CALL_TOO_FEW_ARGS_ctr")
-tickyKnownCallExact = ifTicky $ bumpTickyCounter SLIT("KNOWN_CALL_ctr")
-tickyKnownCallExtraArgs = ifTicky $ bumpTickyCounter SLIT("KNOWN_CALL_EXTRA_ARGS_ctr")
-tickyUnknownCall = ifTicky $ bumpTickyCounter SLIT("UNKNOWN_CALL_ctr")
+tickyKnownCallTooFewArgs = ifTicky $ bumpTickyCounter (sLit "KNOWN_CALL_TOO_FEW_ARGS_ctr")
+tickyKnownCallExact = ifTicky $ bumpTickyCounter (sLit "KNOWN_CALL_ctr")
+tickyKnownCallExtraArgs = ifTicky $ bumpTickyCounter (sLit "KNOWN_CALL_EXTRA_ARGS_ctr")
+tickyUnknownCall = ifTicky $ bumpTickyCounter (sLit "UNKNOWN_CALL_ctr")
 
 -- Tick for the call pattern at slow call site (i.e. in addition to
 -- tickyUnknownCall, tickyKnownCallExtraArgs, etc.)
@@ -215,7 +219,7 @@ tickySlowCallPat args = return ()
 {- LATER: (introduces recursive module dependency now).
   case callPattern args of
     (str, True)  -> bumpTickyCounter' (mkRtsSlowTickyCtrLabel pat)
-    (str, False) -> bumpTickyCounter  SLIT("TICK_SLOW_CALL_OTHER")
+    (str, False) -> bumpTickyCounter  (sLit "TICK_SLOW_CALL_OTHER")
 
 callPattern :: [CgRep] -> (String,Bool)
 callPattern reps 
@@ -265,13 +269,13 @@ tickyDynAlloc cl_info
 
 
 tickyAllocPrim :: CmmExpr -> CmmExpr -> CmmExpr -> Code
-tickyAllocPrim hdr goods slop = ifTicky $ panic "ToDo: tickyAllocPrim"
+tickyAllocPrim hdr goods slop = ifTicky $ pprTrace "ToDo: tickyAllocPrim" empty (return ())
 
 tickyAllocThunk :: CmmExpr -> CmmExpr -> Code
-tickyAllocThunk goods slop = ifTicky $ panic "ToDo: tickyAllocThunk"
+tickyAllocThunk goods slop = ifTicky $ pprTrace "ToDo: tickyAllocThunk" empty (return ())
 
 tickyAllocPAP :: CmmExpr -> CmmExpr -> Code
-tickyAllocPAP goods slop = ifTicky $ panic "ToDo: tickyAllocPAP"
+tickyAllocPAP goods slop = ifTicky $ pprTrace "ToDo: tickyAllocPAP" empty (return ())
 
 tickyAllocHeap :: VirtualHpOffset -> Code
 -- Called when doing a heap check [TICK_ALLOC_HEAP]
@@ -282,13 +286,13 @@ tickyAllocHeap hp
          if hp == 0 then []    -- Inside the stmtC to avoid control
          else [                -- dependency on the argument
                -- Bump the allcoation count in the StgEntCounter
-           addToMem REP_StgEntCounter_allocs 
+           addToMem (typeWidth REP_StgEntCounter_allocs)
                        (CmmLit (cmmLabelOffB ticky_ctr 
                                oFFSET_StgEntCounter_allocs)) hp,
                -- Bump ALLOC_HEAP_ctr
-           addToMemLbl cLongRep (mkRtsDataLabel SLIT("ALLOC_HEAP_ctr")) 1,
-               -- Bump ALLOC_HEAP_tot
-           addToMemLbl cLongRep (mkRtsDataLabel SLIT("ALLOC_HEAP_tot")) hp] }
+           addToMemLbl cLongWidth (mkRtsDataLabel $ sLit "ALLOC_HEAP_ctr") 1,
+               -- Bump ALLOC_HEAP_tot
+           addToMemLbl cLongWidth (mkRtsDataLabel $ sLit "ALLOC_HEAP_tot") hp] }
 
 -- -----------------------------------------------------------------------------
 -- Ticky utils
@@ -298,7 +302,7 @@ ifTicky code
   | opt_DoTickyProfiling = code
   | otherwise           = nopC
 
-addToMemLbl :: MachRep -> CLabel -> Int -> CmmStmt
+addToMemLbl :: Width -> CLabel -> Int -> CmmStmt
 addToMemLbl rep lbl n = addToMem rep (CmmLit (CmmLabel lbl)) n
 
 -- All the ticky-ticky counters are declared "unsigned long" in C
@@ -307,26 +311,28 @@ bumpTickyCounter lbl = bumpTickyCounter' (cmmLabelOffB (mkRtsDataLabel lbl) 0)
 
 bumpTickyCounter' :: CmmLit -> Code
 -- krc: note that we're incrementing the _entry_count_ field of the ticky counter
-bumpTickyCounter' lhs = stmtC (addToMem cLongRep (CmmLit lhs) 1)
-
-addToMemLong = addToMem cLongRep
+bumpTickyCounter' lhs = stmtC (addToMemLong (CmmLit lhs) 1)
 
 bumpHistogram :: LitString -> Int -> Code
 bumpHistogram lbl n 
-  = bumpHistogramE lbl (CmmLit (CmmInt (fromIntegral n) cLongRep))
+--  = bumpHistogramE lbl (CmmLit (CmmInt (fromIntegral n) cLong))
+    = return ()           -- TEMP SPJ Apr 07
 
 bumpHistogramE :: LitString -> CmmExpr -> Code
 bumpHistogramE lbl n 
-  = do  t <- newTemp cLongRep
-       stmtC (CmmAssign t n)
-       emitIf (CmmMachOp (MO_U_Le cLongRep) [CmmReg t, eight]) $
-               stmtC (CmmAssign t eight)
-       stmtC (addToMemLong (cmmIndexExpr cLongRep 
+  = do  t <- newTemp cLong
+       stmtC (CmmAssign (CmmLocal t) n)
+       emitIf (CmmMachOp (MO_U_Le cLongWidth) [CmmReg (CmmLocal t), eight]) $
+               stmtC (CmmAssign (CmmLocal t) eight)
+       stmtC (addToMemLong (cmmIndexExpr cLongWidth
                                (CmmLit (CmmLabel (mkRtsDataLabel lbl)))
-                               (CmmReg t))
+                               (CmmReg (CmmLocal t)))
                            1)
   where 
-   eight = CmmLit (CmmInt 8 cLongRep)
+   eight = CmmLit (CmmInt 8 cLongWidth)
+
+------------------------------------------------------------------
+addToMemLong = addToMem cLongWidth
 
 ------------------------------------------------------------------
 -- Showing the "type category" for ticky-ticky profiling
@@ -365,8 +371,6 @@ showTypeCategory ty
          else if utc == intDataConKey     then 'I'
          else if utc == floatDataConKey   then 'F'
          else if utc == doubleDataConKey  then 'D'
-         else if utc == smallIntegerDataConKey ||
-                 utc == largeIntegerDataConKey   then 'J'
          else if utc == charPrimTyConKey  then 'c'
          else if (utc == intPrimTyConKey || utc == wordPrimTyConKey
                || utc == addrPrimTyConKey)                then 'i'
@@ -375,6 +379,6 @@ showTypeCategory ty
          else if isPrimTyCon tycon {- array, we hope -}   then 'A'     -- Bogus
          else if isEnumerationTyCon tycon                 then 'E'
          else if isTupleTyCon tycon                       then 'T'
-         else if isJust (maybeTyConSingleCon tycon)       then 'S'
+         else if isJust (tyConSingleDataCon_maybe tycon)       then 'S'
          else if utc == listTyConKey                      then 'L'
          else 'M' -- oh, well...