Skip to content

Commit

Permalink
Remove vectored returns.
Browse files Browse the repository at this point in the history
We recently discovered that they aren't a win any more, and just cost
code size.
  • Loading branch information
Simon Marlow committed Feb 28, 2007
1 parent 6a7778b commit 9ff7653
Show file tree
Hide file tree
Showing 35 changed files with 156 additions and 704 deletions.
2 changes: 0 additions & 2 deletions compiler/cmm/CLabel.hs
Expand Up @@ -48,7 +48,6 @@ module CLabel (
mkSplitMarkerLabel,
mkDirty_MUT_VAR_Label,
mkUpdInfoLabel,
mkSeqInfoLabel,
mkIndStaticInfoLabel,
mkMainCapabilityLabel,
mkMAP_FROZEN_infoLabel,
Expand Down Expand Up @@ -358,7 +357,6 @@ mkPlainModuleInitLabel this_pkg mod
mkSplitMarkerLabel = RtsLabel (RtsCode SLIT("__stg_split_marker"))
mkDirty_MUT_VAR_Label = RtsLabel (RtsCode SLIT("dirty_MUT_VAR"))
mkUpdInfoLabel = RtsLabel (RtsInfo SLIT("stg_upd_frame"))
mkSeqInfoLabel = RtsLabel (RtsInfo SLIT("stg_seq_frame"))
mkIndStaticInfoLabel = RtsLabel (RtsInfo SLIT("stg_IND_STATIC"))
mkMainCapabilityLabel = RtsLabel (RtsData SLIT("MainCapability"))
mkMAP_FROZEN_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_FROZEN0"))
Expand Down
15 changes: 5 additions & 10 deletions compiler/cmm/CmmParse.y
Expand Up @@ -230,12 +230,8 @@ info :: { ExtFCode (CLabel, [CmmLit],[CmmLit]) }
-- selector, closure type, description, type
{ basicInfo $3 (mkIntCLit (fromIntegral $5)) 0 $7 $9 $11 }

| 'INFO_TABLE_RET' '(' NAME ',' INT ',' INT ',' INT maybe_vec ')'
{ retInfo $3 $5 $7 $9 $10 }

maybe_vec :: { [CmmLit] }
: {- empty -} { [] }
| ',' NAME maybe_vec { CmmLabel (mkRtsCodeLabelFS $2) : $3 }
| 'INFO_TABLE_RET' '(' NAME ',' INT ',' INT ',' INT ')'
{ retInfo $3 $5 $7 $9 }

body :: { ExtCode }
: {- empty -} { return () }
Expand Down Expand Up @@ -473,8 +469,7 @@ exprMacros = listToUFM [
( FSLIT("GET_FUN_INFO"), \ [x] -> funInfoTable (closureInfoPtr x) ),
( FSLIT("INFO_TYPE"), \ [x] -> infoTableClosureType x ),
( FSLIT("INFO_PTRS"), \ [x] -> infoTablePtrs x ),
( FSLIT("INFO_NPTRS"), \ [x] -> infoTableNonPtrs x ),
( FSLIT("RET_VEC"), \ [info, conZ] -> retVec info conZ )
( FSLIT("INFO_NPTRS"), \ [x] -> infoTableNonPtrs x )
]
-- we understand a subset of C-- primitives:
Expand Down Expand Up @@ -709,11 +704,11 @@ forkLabelledCodeEC ec = do
stmts <- getCgStmtsEC ec
code (forkCgStmts stmts)

retInfo name size live_bits cl_type vector = do
retInfo name size live_bits cl_type = do
let liveness = smallLiveness (fromIntegral size) (fromIntegral live_bits)
info_lbl = mkRtsRetInfoLabelFS name
(info1,info2) = mkRetInfoTable info_lbl liveness NoC_SRT
(fromIntegral cl_type) vector
(fromIntegral cl_type)
return (info_lbl, info1, info2)

stdInfo name ptrs nptrs srt_bitmap cl_type desc_str ty_str =
Expand Down
34 changes: 3 additions & 31 deletions compiler/codeGen/CgCallConv.hs
Expand Up @@ -25,8 +25,6 @@ module CgCallConv (
constructSlowCall, slowArgs, slowCallPattern,

-- Returns
CtrlReturnConvention(..),
ctrlReturnConvAlg,
dataReturnConvPrim,
getSequelAmode
) where
Expand All @@ -48,7 +46,6 @@ import CmmUtils
import Maybes
import Id
import Name
import TyCon
import Bitmap
import Util
import StaticFlags
Expand Down Expand Up @@ -215,10 +212,6 @@ constructSlowCall amodes
stg_ap_pat = mkRtsApFastLabel arg_pat
(arg_pat, these, rest) = matchSlowPattern amodes

enterRtsRetLabel arg_pat
| tablesNextToCode = mkRtsRetInfoLabel arg_pat
| otherwise = mkRtsRetLabel arg_pat

-- | 'slowArgs' takes a list of function arguments and prepares them for
-- pushing on the stack for "extra" arguments to a function which requires
-- fewer arguments than we currently have.
Expand Down Expand Up @@ -257,26 +250,6 @@ slowCallPattern _ = panic "CgStackery.slowCallPattern"
--
-------------------------------------------------------------------------

-- A @CtrlReturnConvention@ says how {\em control} is returned.

data CtrlReturnConvention
= VectoredReturn Int -- size of the vector table (family size)
| UnvectoredReturn Int -- family size

ctrlReturnConvAlg :: TyCon -> CtrlReturnConvention
ctrlReturnConvAlg tycon
= case (tyConFamilySize tycon) of
size -> -- we're supposed to know...
if (size > (1::Int) && size <= mAX_FAMILY_SIZE_FOR_VEC_RETURNS) then
VectoredReturn size
else
UnvectoredReturn size
-- NB: unvectored returns Include size 0 (no constructors), so that
-- the following perverse code compiles (it crashed GHC in 5.02)
-- data T1
-- data T2 = T2 !T1 Int
-- The only value of type T1 is bottom, which never returns anyway.

dataReturnConvPrim :: CgRep -> CmmReg
dataReturnConvPrim PtrArg = CmmGlobal (VanillaReg 1)
dataReturnConvPrim NonPtrArg = CmmGlobal (VanillaReg 1)
Expand All @@ -287,7 +260,7 @@ dataReturnConvPrim VoidArg = panic "dataReturnConvPrim: void"


-- getSequelAmode returns an amode which refers to an info table. The info
-- table will always be of the RET(_VEC)?_(BIG|SMALL) kind. We're careful
-- table will always be of the RET_(BIG|SMALL) kind. We're careful
-- not to handle real code pointers, just in case we're compiling for
-- an unregisterised/untailcallish architecture, where info pointers and
-- code pointers aren't the same.
Expand All @@ -304,9 +277,8 @@ getSequelAmode
OnStack -> do { sp_rel <- getSpRelOffset virt_sp
; returnFC (CmmLoad sp_rel wordRep) }

UpdateCode -> returnFC (CmmLit (CmmLabel mkUpdInfoLabel))
CaseAlts lbl _ _ True -> returnFC (CmmLit (CmmLabel mkSeqInfoLabel))
CaseAlts lbl _ _ False -> returnFC (CmmLit (CmmLabel lbl))
UpdateCode -> returnFC (CmmLit (CmmLabel mkUpdInfoLabel))
CaseAlts lbl _ _ -> returnFC (CmmLit (CmmLabel lbl))
}

-------------------------------------------------------------------------
Expand Down
32 changes: 12 additions & 20 deletions compiler/codeGen/CgCase.lhs
Expand Up @@ -197,7 +197,7 @@ cgCase (StgApp fun args)
(do { deAllocStackTop retAddrSizeW
; cgEvalAlts maybe_cc_slot bndr srt alt_type alts })
; setEndOfBlockInfo (maybeReserveSeqFrame alt_type scrut_eob_info)
; setEndOfBlockInfo scrut_eob_info
(performTailCall fun_info arg_amodes save_assts) }
\end{code}

Expand Down Expand Up @@ -234,8 +234,7 @@ cgCase expr live_in_whole_case live_in_alts bndr srt alt_type alts
(do { deAllocStackTop retAddrSizeW
; cgEvalAlts maybe_cc_slot bndr srt alt_type alts })
; setEndOfBlockInfo (maybeReserveSeqFrame alt_type scrut_eob_info)
(cgExpr expr)
; setEndOfBlockInfo scrut_eob_info (cgExpr expr)
}
\end{code}

Expand Down Expand Up @@ -265,13 +264,6 @@ consequence of this is that activation records on the stack don't
follow the layout of closures when we're profiling. The CCS could be
anywhere within the record).

\begin{code}
maybeReserveSeqFrame PolyAlt (EndOfBlockInfo args_sp (CaseAlts amode stuff bndr _))
= EndOfBlockInfo (args_sp + retAddrSizeW) (CaseAlts amode stuff bndr True)
maybeReserveSeqFrame other scrut_eob_info = scrut_eob_info
\end{code}


%************************************************************************
%* *
Inline primops
Expand Down Expand Up @@ -380,8 +372,8 @@ cgEvalAlts cc_slot bndr srt alt_type@(PrimAlt tycon) alts
; restoreCurrentCostCentre cc_slot True
; cgPrimAlts GCMayHappen alt_type reg alts }
; lbl <- emitDirectReturnTarget (idName bndr) abs_c srt
; returnFC (CaseAlts lbl Nothing bndr False) }
; lbl <- emitReturnTarget (idName bndr) abs_c srt
; returnFC (CaseAlts lbl Nothing bndr) }
cgEvalAlts cc_slot bndr srt (UbxTupAlt _) [(con,args,_,rhs)]
= -- Unboxed tuple case
Expand All @@ -392,7 +384,7 @@ cgEvalAlts cc_slot bndr srt (UbxTupAlt _) [(con,args,_,rhs)]
ASSERT2( case con of { DataAlt _ -> True; other -> False },
text "cgEvalAlts: dodgy case of unboxed tuple type" )
do { -- forkAbsC for the RHS, so that the envt is
-- not changed for the emitDirectReturn call
-- not changed for the emitReturn call
abs_c <- forkProc $ do
{ (live_regs, ptrs, nptrs, _) <- bindUnboxedTupleComponents args
-- Restore the CC *after* binding the tuple components,
Expand All @@ -402,8 +394,8 @@ cgEvalAlts cc_slot bndr srt (UbxTupAlt _) [(con,args,_,rhs)]
-- and finally the code for the alternative
; unbxTupleHeapCheck live_regs ptrs nptrs noStmts
(cgExpr rhs) }
; lbl <- emitDirectReturnTarget (idName bndr) abs_c srt
; returnFC (CaseAlts lbl Nothing bndr False) }
; lbl <- emitReturnTarget (idName bndr) abs_c srt
; returnFC (CaseAlts lbl Nothing bndr) }
cgEvalAlts cc_slot bndr srt alt_type alts
= -- Algebraic and polymorphic case
Expand All @@ -422,13 +414,13 @@ cgEvalAlts cc_slot bndr srt alt_type alts
; (alts, mb_deflt) <- cgAlgAlts GCMayHappen cc_slot alt_type alts
; (lbl, branches) <- emitAlgReturnTarget (idName bndr)
alts mb_deflt srt ret_conv
alts mb_deflt srt fam_sz
; returnFC (CaseAlts lbl branches bndr False) }
; returnFC (CaseAlts lbl branches bndr) }
where
ret_conv = case alt_type of
AlgAlt tc -> ctrlReturnConvAlg tc
PolyAlt -> UnvectoredReturn 0
fam_sz = case alt_type of
AlgAlt tc -> tyConFamilySize tc
PolyAlt -> 0
\end{code}


Expand Down
8 changes: 3 additions & 5 deletions compiler/codeGen/CgCon.lhs
Expand Up @@ -295,7 +295,7 @@ cgReturnDataCon con amodes
= ASSERT( amodes `lengthIs` dataConRepArity con )
do { EndOfBlockInfo _ sequel <- getEndOfBlockInfo
; case sequel of
CaseAlts _ (Just (alts, deflt_lbl)) bndr _
CaseAlts _ (Just (alts, deflt_lbl)) bndr
-> -- Ho! We know the constructor so we can
-- go straight to the right alternative
case assocMaybe alts (dataConTagZ con) of {
Expand All @@ -317,7 +317,7 @@ cgReturnDataCon con amodes
other_sequel -- The usual case
| isUnboxedTupleCon con -> returnUnboxedTuple amodes
| otherwise -> build_it_then (emitKnownConReturnCode con)
| otherwise -> build_it_then emitReturnInstr
}
where
jump_to lbl = stmtC (CmmJump (CmmLit lbl) [])
Expand Down Expand Up @@ -434,14 +434,12 @@ cgDataCon data_con
body_code = do {
-- NB: We don't set CC when entering data (WDP 94/06)
tickyReturnOldCon (length arg_things)
; performReturn (emitKnownConReturnCode data_con) }
; performReturn emitReturnInstr }
-- noStmts: Ptr to thing already in Node
; whenC (not (isNullaryRepDataCon data_con))
(emit_info dyn_cl_info tickyEnterDynCon)
-- Dynamic-Closure first, to reduce forward references
; emit_info static_cl_info tickyEnterStaticCon }
where
\end{code}
8 changes: 4 additions & 4 deletions compiler/codeGen/CgExpr.lhs
Expand Up @@ -141,7 +141,7 @@ cgExpr (StgOpApp (StgPrimOp TagToEnumOp) [arg] res_ty)
-- so save in a temp if non-trivial
; this_pkg <- getThisPackage
; stmtC (CmmAssign nodeReg (tagToClosure this_pkg tycon amode'))
; performReturn (emitAlgReturnCode tycon amode') }
; performReturn emitReturnInstr }
where
-- If you're reading this code in the attempt to figure
-- out why the compiler panic'ed here, it is probably because
Expand All @@ -157,12 +157,12 @@ cgExpr x@(StgOpApp op@(StgPrimOp primop) args res_ty)
| ReturnsPrim VoidRep <- result_info
= do cgPrimOp [] primop args emptyVarSet
performReturn emitDirectReturnInstr
performReturn emitReturnInstr
| ReturnsPrim rep <- result_info
= do cgPrimOp [dataReturnConvPrim (primRepToCgRep rep)]
primop args emptyVarSet
performReturn emitDirectReturnInstr
performReturn emitReturnInstr
| ReturnsAlg tycon <- result_info, isUnboxedTupleTyCon tycon
= do (reps, regs, _hints) <- newUnboxedTupleRegs res_ty
Expand All @@ -175,7 +175,7 @@ cgExpr x@(StgOpApp op@(StgPrimOp primop) args res_ty)
this_pkg <- getThisPackage
cgPrimOp [tag_reg] primop args emptyVarSet
stmtC (CmmAssign nodeReg (tagToClosure this_pkg tycon (CmmReg tag_reg)))
performReturn (emitAlgReturnCode tycon (CmmReg tag_reg))
performReturn emitReturnInstr
where
result_info = getPrimOpResultInfo primop
\end{code}
Expand Down

0 comments on commit 9ff7653

Please sign in to comment.