X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FabsCSyn%2FCosts.lhs;h=17ea6d57f49163e0df8f535b33dc2c80896e97d1;hb=553e90d9a32ee1b1809430f260c401cc4169c6c7;hp=063fe130d8192476eb8cf3341814009d8f2c32be;hpb=4a91d102be99778efcab80211ca5de3f2cf6619a;p=ghc-hetmet.git diff --git a/ghc/compiler/absCSyn/Costs.lhs b/ghc/compiler/absCSyn/Costs.lhs index 063fe13..17ea6d5 100644 --- a/ghc/compiler/absCSyn/Costs.lhs +++ b/ghc/compiler/absCSyn/Costs.lhs @@ -1,7 +1,7 @@ % % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -% $Id: Costs.lhs,v 1.27 2000/10/24 07:35:00 simonpj Exp $ +% $Id: Costs.lhs,v 1.33 2003/07/28 16:05:30 simonmar Exp $ % % Only needed in a GranSim setup -- HWL % --------------------------------------------------------------------------- @@ -62,6 +62,7 @@ module Costs( costs, #include "HsVersions.h" import AbsCSyn +import StgSyn ( StgOp(..) ) import PrimOp ( primOpNeedsWrapper, PrimOp(..) ) import Panic ( trace ) @@ -88,10 +89,6 @@ instance Num CostRes where mapOp :: (Int -> Int) -> CostRes -> CostRes mapOp g ( Cost (i, b, l, s, f) ) = Cost (g i, g b, g l, g s, g f) -foldrOp :: (Int -> a -> a) -> a -> CostRes -> a -foldrOp o x ( Cost (i1, b1, l1, s1, f1) ) = - i1 `o` ( b1 `o` ( l1 `o` ( s1 `o` ( f1 `o` x)))) - binOp :: (Int -> Int -> Int) -> CostRes -> CostRes -> CostRes binOp o ( Cost (i1, b1, l1, s1, f1) ) ( Cost (i2, b2, l2, s2, f2) ) = ( Cost (i1 `o` i2, b1 `o` b2, l1 `o` l2, s1 `o` s2, f1 `o` f2) ) @@ -170,7 +167,7 @@ costs absC = CCodeBlock _ absC -> costs absC - CInitHdr cl_info reg_rel cost_centre -> 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! @@ -185,7 +182,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 op modes_args _ -> {- let n = length modes_res @@ -198,9 +195,7 @@ costs absC = -} foldl (+) nullCosts [addrModeCosts mode Lhs | mode <- modes_res] + foldl (+) nullCosts [addrModeCosts mode Rhs | mode <- modes_args] + - primOpCosts primOp + - if primOpNeedsWrapper primOp then SAVE_COSTS + RESTORE_COSTS - else nullCosts + opCosts op CSimultaneous absC -> costs absC @@ -220,15 +215,15 @@ costs absC = -- *** the next three [or so...] are DATA (those above are CODE) *** -- as they are data rather than code they all have nullCosts -- HWL - CCallTypedef _ _ _ _ -> nullCosts + CCallTypedef _ _ _ _ _ -> nullCosts CStaticClosure _ _ _ _ -> nullCosts CSRT _ _ -> nullCosts - CBitmap _ _ -> nullCosts + CBitmap _ -> nullCosts - CClosureInfoAndCode _ _ _ _ -> nullCosts + CClosureInfoAndCode _ _ -> nullCosts CRetVector _ _ _ _ -> nullCosts @@ -242,6 +237,7 @@ costs absC = _ -> trace ("Costs.costs") nullCosts + -- --------------------------------------------------------------------------- addrModeCosts :: CAddrMode -> Side -> CostRes @@ -305,7 +301,6 @@ exprMacroCosts side macro mode_list = ENTRY_CODE -> nullCosts -- nothing ARG_TAG -> nullCosts -- nothing GET_TAG -> Cost (0, 0, 1, 0, 0) -- indirect load - UPD_FRAME_UPDATEE -> Cost (0, 0, 1, 0, 0) -- indirect load -- --------------------------------------------------------------------------- @@ -313,15 +308,10 @@ stmtMacroCosts :: CStmtMacro -> [CAddrMode] -> CostRes stmtMacroCosts macro modes = case macro of - 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 -> Cost (2, 1, 0, 0, 0) {- StgMacros.lh -} UPD_CAF -> Cost (7, 0, 1, 3, 0) {- SMupdate.lh -} UPD_BH_UPDATABLE -> Cost (3, 0, 0, 1, 0) {- SMupdate.lh -} UPD_BH_SINGLE_ENTRY -> Cost (3, 0, 0, 1, 0) {- SMupdate.lh -} PUSH_UPD_FRAME -> Cost (3, 0, 0, 4, 0) {- Updates.h -} - PUSH_SEQ_FRAME -> Cost (2, 0, 0, 3, 0) {- StgMacros.h !-} - UPDATE_SU_FROM_UPD_FRAME -> Cost (1, 0, 1, 0, 0) {- StgMacros.h !-} SET_TAG -> nullCosts {- COptRegs.lh -} GRAN_FETCH -> nullCosts {- GrAnSim bookkeeping -} GRAN_RESCHEDULE -> nullCosts {- GrAnSim bookkeeping -} @@ -358,7 +348,7 @@ floatOps = gmpOps :: [PrimOp] gmpOps = [ IntegerAddOp , IntegerSubOp , IntegerMulOp - , IntegerQuotRemOp , IntegerDivModOp , IntegerNegOp + , IntegerQuotRemOp , IntegerDivModOp , IntegerCmpOp , Integer2IntOp , Int2IntegerOp ] @@ -368,17 +358,24 @@ umul_costs = Cost (21,4,0,0,0) -- due to spy counts rem_costs = Cost (30,15,0,0,0) -- due to spy counts div_costs = Cost (30,15,0,0,0) -- due to spy counts -primOpCosts :: PrimOp -> CostRes --- Special cases -primOpCosts (CCallOp _) = SAVE_COSTS + RESTORE_COSTS - -- don't guess costs of ccall proper - -- for exact costing use a GRAN_EXEC - -- in the C code +-- --------------------------------------------------------------------------- + +opCosts :: StgOp -> CostRes --- Usually 3 mov instructions are needed to get args and res in right place. +opCosts (StgFCallOp _ _) = SAVE_COSTS + RESTORE_COSTS + -- Don't guess costs of ccall proper + -- for exact costing use a GRAN_EXEC in the C code +opCosts (StgPrimOp primop) + = primOpCosts primop + + if primOpNeedsWrapper primop then SAVE_COSTS + RESTORE_COSTS + else nullCosts + +primOpCosts :: PrimOp -> CostRes + +-- Usually 3 mov instructions are needed to get args and res in right place. primOpCosts IntMulOp = Cost (3, 1, 0, 0, 0) + umul_costs primOpCosts IntQuotOp = Cost (3, 1, 0, 0, 0) + div_costs primOpCosts IntRemOp = Cost (3, 1, 0, 0, 0) + rem_costs @@ -421,19 +418,4 @@ primOpCosts primOp | primOp `elem` gmpOps = Cost (30, 5, 10, 10, 0) :: CostRes -- GUESS; check it | otherwise = Cost (1, 0, 0, 0, 0) --- --------------------------------------------------------------------------- -{- HWL: currently unused - -costsByKind :: PrimRep -> Side -> CostRes - --- The following PrimKinds say that the data is already in a reg - -costsByKind CharRep _ = nullCosts -costsByKind IntRep _ = nullCosts -costsByKind WordRep _ = nullCosts -costsByKind AddrRep _ = nullCosts -costsByKind FloatRep _ = nullCosts -costsByKind DoubleRep _ = nullCosts --} --- --------------------------------------------------------------------------- \end{code}