[project @ 1999-06-24 13:04:13 by simonmar]
[ghc-hetmet.git] / ghc / compiler / absCSyn / Costs.lhs
index 4c0a636..b6d955c 100644 (file)
@@ -1,5 +1,5 @@
 %
-% (c) The GRASP/AQUA Project, Glasgow University, 1994-1996
+% (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
 %     Hans Wolfgang Loidl
 %
 % ---------------------------------------------------------------------------
@@ -44,8 +44,6 @@ These are first suggestions for scaling the costs. But, this scaling should be d
 \end{pseudocode}
 
 \begin{code}
-#include "HsVersions.h"
-
 #define ACCUM_COSTS(i,b,l,s,f) (i+b+l+s+f)
 
 #define NUM_REGS               10 {- PprAbsCSyn.lhs -}       {- runtime/c-as-asm/CallWrap_C.lc -}
@@ -57,10 +55,11 @@ module Costs( costs,
              addrModeCosts, CostRes(Cost), nullCosts, Side(..)
     ) where
 
-IMP_Ubiq(){-uitous-}
+#include "HsVersions.h"
 
 import AbsCSyn
 import PrimOp          ( primOpNeedsWrapper, PrimOp(..) )
+import Panic           ( trace )
 
 -- --------------------------------------------------------------------------
 data CostRes = Cost (Int, Int, Int, Int, Int)
@@ -118,7 +117,7 @@ costs absC =
 
    CAssign (CReg _) (CTemp _ _) -> Cost (1,0,0,0,0)
 
-   CAssign (CReg _) (CAddr _)  -> Cost (1,0,0,0,0)  -- typ.: add %reg1,<adr>,%reg2
+   CAssign (CReg _) source_m   -> addrModeCosts source_m Rhs
 
    CAssign target_m source_m   -> addrModeCosts target_m Lhs +
                                   addrModeCosts source_m Rhs
@@ -169,7 +168,7 @@ costs absC =
 
    CCodeBlock _ absC         -> costs absC
 
-   CInitHdr cl_info reg_rel cost_centre inplace_upd -> initHdrCosts
+   CInitHdr cl_info reg_rel cost_centre -> initHdrCosts
 
                        {- This is more fancy but superflous: The addr modes
                           are fixed and so the costs are const!
@@ -184,7 +183,7 @@ costs absC =
                           For costing the args of this macro
                           see PprAbsC.lhs where args are inserted -}
 
-   COpStmt modes_res primOp modes_args _ _ ->
+   COpStmt modes_res primOp modes_args _ ->
        {-
           let
                n = length modes_res
@@ -203,6 +202,8 @@ costs absC =
 
    CSimultaneous absC       -> costs absC
 
+   CCheck _ amodes code             -> Cost (2, 1, 0, 0, 0)
+
    CMacroStmt  macro modes  -> stmtMacroCosts macro modes
 
    CCallProfCtrMacro   _ _   -> nullCosts
@@ -216,17 +217,14 @@ costs absC =
 
    CStaticClosure _ _ _ _    -> nullCosts
 
-   CClosureInfoAndCode _ _ _ _ _ _ -> nullCosts
-
-   CRetVector _ _ _         -> nullCosts
+   CClosureInfoAndCode _ _ _ _ -> nullCosts
 
-   CRetUnVector _ _         -> nullCosts
+   CRetDirect _ _ _ _       -> nullCosts
 
-   CFlatRetVector _ _       -> nullCosts
+   CRetVector _ _ _ _        -> nullCosts
 
    CCostCentreDecl _ _      -> nullCosts
-
-   CClosureUpdInfo _        -> nullCosts
+   CCostCentreStackDecl _    -> nullCosts
 
    CSplitMarker                     -> nullCosts
 
@@ -244,16 +242,9 @@ addrModeCosts addr_mode side =
     CVal _ _ -> if lhs then Cost (0, 0, 0, 1, 0)
                       else Cost (0, 0, 1, 0, 0)
 
-    CAddr _  -> if lhs then Cost (0, 0, 0, 1, 0)  -- ??unchecked
-                      else Cost (0, 0, 1, 0, 0)
-
     CReg _   -> nullCosts       {- loading from, storing to reg is free ! -}
                                 {- for costing CReg->Creg ops see special -}
                                 {- case in costs fct -}
-    CTableEntry base_mode offset_mode kind ->
-               addrModeCosts base_mode side +
-               addrModeCosts offset_mode side +
-               Cost (1,0,1,0,0)
 
     CTemp _ _  -> nullCosts    {- if lhs then Cost (0, 0, 0, 1, 0)
                                          else Cost (0, 0, 1, 0, 0)  -}
@@ -266,10 +257,6 @@ addrModeCosts addr_mode side =
                  -- Rhs: typically: sethi %hi(lbl),%tmp_reg
                  --                 or    %tmp_reg,%lo(lbl),%target_reg
 
-    CUnVecLbl _ _ -> if lhs then Cost (0, 0, 0, 1, 0)
-                           else Cost (2, 0, 0, 0, 0)
-                    -- same as CLbl
-
     -- Check the following 3 (checked form CLit on)
 
     CCharLike mode -> if lhs then Cost (0, 0, 0, 1, 0)
@@ -278,9 +265,6 @@ addrModeCosts addr_mode side =
     CIntLike mode  -> if lhs then Cost (0, 0, 0, 1, 0)
                             else Cost (0, 0, 1, 0, 0)
 
-    CString _     -> if lhs then Cost (0, 0, 0, 1, 0)
-                            else Cost (0, 0, 1, 0, 0)
-
     CLit    _     -> if lhs then nullCosts            -- should never occur
                             else Cost (1, 0, 0, 0, 0) -- typ.: mov lit,%reg
 
@@ -288,21 +272,11 @@ addrModeCosts addr_mode side =
                             else Cost (1, 0, 0, 0, 0)
                      -- same es CLit
 
-    COffset _     -> if lhs then nullCosts
-                            else Cost (1, 0, 0, 0, 0)
-                     -- same es CLit
-
-    CCode absC    -> costs absC
-
-    CLabelledCode _ absC  ->  costs absC
-
-    CJoinPoint _ _       -> if lhs then Cost (0, 0, 0, 1, 0)
+    CJoinPoint _         -> if lhs then Cost (0, 0, 0, 1, 0)
                                    else Cost (0, 0, 1, 0, 0)
 
     CMacroExpr _ macro mode_list -> exprMacroCosts side macro mode_list
 
-    CCostCentre _ _ -> nullCosts
-
 -- ---------------------------------------------------------------------------
 
 exprMacroCosts :: Side -> CExprMacro -> [CAddrMode] -> CostRes
@@ -314,14 +288,10 @@ exprMacroCosts side macro mode_list =
   in
   arg_costs +
   case macro of
-    INFO_PTR   -> if side == Lhs then Cost (0, 0, 0, 1, 0)
-                                else Cost (0, 0, 1, 0, 0)
     ENTRY_CODE -> nullCosts
-    INFO_TAG   -> if side == Lhs then Cost (0, 0, 0, 1, 0)
-                                else Cost (0, 0, 1, 0, 0)
-    EVAL_TAG   -> if side == Lhs then Cost (1, 0, 0, 1, 0)
-                                else Cost (1, 0, 1, 0, 0)
-                 -- costs of INFO_TAG + (1,0,0,0,0)
+    ARG_TAG -> nullCosts -- XXX
+    GET_TAG -> nullCosts -- XXX
+    
 
 -- ---------------------------------------------------------------------------
 
@@ -333,43 +303,20 @@ stmtMacroCosts macro modes =
                        [addrModeCosts mode Rhs | mode <- modes]
   in
   case macro of
-    ARGS_CHK_A_LOAD_NODE  ->  Cost (2, 1, 0, 0, 0)      {- StgMacros.lh  -}
+    ARGS_CHK_LOAD_NODE  ->  Cost (2, 1, 0, 0, 0)        {- StgMacros.lh  -}
                -- p=probability of PAP (instead of AP): + p*(3,1,0,0,0)
-    ARGS_CHK_A           ->  Cost (2, 1, 0, 0, 0)       {- StgMacros.lh  -}
-               -- p=probability of PAP (instead of AP): + p*(0,1,0,0,0)
-    ARGS_CHK_B_LOAD_NODE  ->  Cost (2, 1, 0, 0, 0)      {- StgMacros.lh  -}
-    ARGS_CHK_B           ->  Cost (2, 1, 0, 0, 0)       {- StgMacros.lh  -}
-    HEAP_CHK             ->  Cost (2, 1, 0, 0, 0)       {- StgMacros.lh  -}
-    -- STK_CHK              ->  (2, 1, 0, 0, 0)       {- StgMacros.lh  -}
-    STK_CHK              ->  Cost (0, 0, 0, 0, 0)       {- StgMacros.lh  -}
+    ARGS_CHK             ->  Cost (2, 1, 0, 0, 0)       {- StgMacros.lh  -}
     UPD_CAF              ->  Cost (7, 0, 1, 3, 0)       {- SMupdate.lh  -}
-    UPD_IND              ->  Cost (8, 2, 2, 0, 0)       {- SMupdate.lh
-                               updatee in old-gen: Cost (4, 1, 1, 0, 0)
-                               updatee in new-gen: Cost (4, 1, 1, 0, 0)
-                               NB: we include costs fo checking if there is
-                                   a BQ, but we omit costs for awakening BQ
-                                   (these probably differ between old-gen and
-                                   new gen) -}
-    UPD_INPLACE_NOPTRS   ->  Cost (13, 3, 3, 2, 0)       {- SMupdate.lh
-                               common for both:    Cost (4, 1, 1, 0, 0)
-                               updatee in old-gen: Cost (14, 3, 2, 4, 0)
-                               updatee in new-gen: Cost (4, 1, 1, 0, 0)   -}
-    UPD_INPLACE_PTRS     ->  Cost (13, 3, 3, 2, 0)       {- SMupdate.lh
-                               common for both:    Cost (4, 1, 1, 0, 0)
-                               updatee in old-gen: Cost (14, 3, 2, 4, 0)
-                               updatee in new-gen: Cost (4, 1, 1, 0, 0)   -}
-
     UPD_BH_UPDATABLE     ->  Cost (3, 0, 0, 1, 0)       {- SMupdate.lh  -}
     UPD_BH_SINGLE_ENTRY          ->  Cost (3, 0, 0, 1, 0)       {- SMupdate.lh  -}
-    PUSH_STD_UPD_FRAME   ->  Cost (3, 0, 0, 4, 0)       {- SMupdate.lh  -}
-    POP_STD_UPD_FRAME    ->  Cost (1, 0, 3, 0, 0)       {- SMupdate.lh  -}
+    PUSH_UPD_FRAME       ->  Cost (3, 0, 0, 4, 0)       {- SMupdate.lh  -}
     SET_TAG              ->  nullCosts             {- COptRegs.lh -}
     GRAN_FETCH                 ->  nullCosts     {- GrAnSim bookkeeping -}
     GRAN_RESCHEDULE            ->  nullCosts     {- GrAnSim bookkeeping -}
     GRAN_FETCH_AND_RESCHEDULE  ->  nullCosts     {- GrAnSim bookkeeping -}
     GRAN_YIELD                 ->  nullCosts     {- GrAnSim bookkeeping -- added SOF -}
     THREAD_CONTEXT_SWITCH      ->  nullCosts     {- GrAnSim bookkeeping -}
-    _ -> trace ("Costs.stmtMacroCosts: "++show macro) nullCosts
+    _ -> trace ("Costs.stmtMacroCosts") nullCosts
 
 -- ---------------------------------------------------------------------------
 
@@ -392,8 +339,8 @@ floatOps =
     , DoubleAsinOp  , DoubleAcosOp  , DoubleAtanOp
     , DoubleSinhOp  , DoubleCoshOp  , DoubleTanhOp
     , DoublePowerOp
-    , FloatEncodeOp  , FloatDecodeOp
-    , DoubleEncodeOp , DoubleDecodeOp
+    , FloatDecodeOp
+    , DoubleDecodeOp
   ]
 
 gmpOps :: [PrimOp]
@@ -417,7 +364,7 @@ primOpCosts :: PrimOp -> CostRes
 
 -- Special cases
 
-primOpCosts (CCallOp _ _ _ _ _) = SAVE_COSTS + RESTORE_COSTS   
+primOpCosts (CCallOp _ _ _ _) = SAVE_COSTS + RESTORE_COSTS     
                                  -- don't guess costs of ccall proper
                                   -- for exact costing use a GRAN_EXEC
                                   -- in the C code
@@ -518,7 +465,7 @@ data PrimOp
     -- Rest is unchecked so far -- HWL
 
     -- Word#-related ops:
-    | AndOp   | OrOp  | NotOp | ShiftLOp | ShiftROp
+    | AndOp   | OrOp  | NotOp | XorOp | ShiftLOp | ShiftROp
     | Int2WordOp | Word2IntOp -- casts
 
     -- Addr#-related ops: