X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FcodeGen%2FStgCmmPrim.hs;h=1c1fab1ba65399007a25671a7f8508a21e55c68b;hp=96467fe7815c827e37cf3242aecac7ca41c7847f;hb=9a82b1ffa35fa4c3927c66a1037a37d436cf6aac;hpb=176fa33f17dd78355cc572e006d2ab26898e2c69 diff --git a/compiler/codeGen/StgCmmPrim.hs b/compiler/codeGen/StgCmmPrim.hs index 96467fe..1c1fab1 100644 --- a/compiler/codeGen/StgCmmPrim.hs +++ b/compiler/codeGen/StgCmmPrim.hs @@ -28,6 +28,7 @@ import CmmUtils import PrimOp import SMRep import Constants +import Module import FastString import Outputable @@ -66,7 +67,9 @@ cgOpApp (StgFCallOp fcall _) stg_args res_ty cgOpApp (StgPrimOp TagToEnumOp) [arg] res_ty = ASSERT(isEnumerationTyCon tycon) - do { amode <- getArgAmode arg + do { args' <- getNonVoidArgAmodes [arg] + ; let amode = case args' of [amode] -> amode + _ -> panic "TagToEnumOp had void arg" ; emitReturn [tagToClosure tycon amode] } where -- If you're reading this code in the attempt to figure @@ -79,8 +82,8 @@ cgOpApp (StgPrimOp TagToEnumOp) [arg] res_ty cgOpApp (StgPrimOp primop) args res_ty | primOpOutOfLine primop = do { cmm_args <- getNonVoidArgAmodes args - ; let fun = CmmLit (CmmLabel (mkRtsPrimOpLabel primop)) - ; emitCall fun cmm_args } + ; let fun = CmmLit (CmmLabel (mkRtsPrimOpLabel primop)) + ; emitCall (PrimOpCall, PrimOpReturn) fun cmm_args } | ReturnsPrim VoidRep <- result_info = do cgPrimOp [] primop args @@ -108,6 +111,11 @@ cgOpApp (StgPrimOp primop) args res_ty where result_info = getPrimOpResultInfo primop +cgOpApp (StgPrimCallOp primcall) args _res_ty + = do { cmm_args <- getNonVoidArgAmodes args + ; let fun = CmmLit (CmmLabel (mkPrimCallLabel primcall)) + ; emitCall (PrimOpCall, PrimOpReturn) fun cmm_args } + --------------------------------------------------- cgPrimOp :: [LocalReg] -- where to put the results -> PrimOp -- the op @@ -194,7 +202,7 @@ emitPrimOp [res] ParOp [arg] -- later, we might want to inline it. emitCCall [(res,NoHint)] - (CmmLit (CmmLabel (mkRtsCodeLabel (sLit "newSpark")))) + (CmmLit (CmmLabel (mkCmmCodeLabel rtsPackageId (fsLit "newSpark")))) [(CmmReg (CmmGlobal BaseReg), AddrHint), (arg,AddrHint)] emitPrimOp [res] ReadMutVarOp [mutv] @@ -209,23 +217,20 @@ emitPrimOp [] WriteMutVarOp [mutv,var] [(CmmReg (CmmGlobal BaseReg), AddrHint), (mutv,AddrHint)] -- #define sizzeofByteArrayzh(r,a) \ --- r = (((StgArrWords *)(a))->words * sizeof(W_)) +-- r = ((StgArrWords *)(a))->bytes emitPrimOp [res] SizeofByteArrayOp [arg] = emit $ - mkAssign (CmmLocal res) (CmmMachOp mo_wordMul [ - cmmLoadIndexW arg fixedHdrSize bWord, - CmmLit (mkIntCLit wORD_SIZE) - ]) + mkAssign (CmmLocal res) (cmmLoadIndexW arg fixedHdrSize bWord) -- #define sizzeofMutableByteArrayzh(r,a) \ --- r = (((StgArrWords *)(a))->words * sizeof(W_)) +-- r = ((StgArrWords *)(a))->bytes emitPrimOp [res] SizeofMutableByteArrayOp [arg] = emitPrimOp [res] SizeofByteArrayOp [arg] -- #define touchzh(o) /* nothing */ -emitPrimOp [] TouchOp [_arg] - = nopC +emitPrimOp res@[] TouchOp args@[_arg] + = do emitPrimCall res MO_Touch args -- #define byteArrayContentszh(r,a) r = BYTE_ARR_CTS(a) emitPrimOp [res] ByteArrayContents_Char [arg] @@ -405,9 +410,9 @@ emitPrimOp [res] op [arg] = emit (mkAssign (CmmLocal res) $ CmmMachOp (mop rep wordWidth) [CmmMachOp (mop wordWidth rep) [arg]]) -emitPrimOp [res] op args +emitPrimOp r@[res] op args | Just prim <- callishOp op - = do emitPrimCall res prim args + = do emitPrimCall r prim args | Just mop <- translateOp op = let stmt = mkAssign (CmmLocal res) (CmmMachOp mop args) in @@ -628,8 +633,21 @@ doWriteByteArrayOp _ _ _ doWritePtrArrayOp :: CmmExpr -> CmmExpr -> CmmExpr -> FCode () doWritePtrArrayOp addr idx val - = do emit (setInfo addr (CmmLit (CmmLabel mkMAP_DIRTY_infoLabel))) - mkBasicIndexedWrite arrPtrsHdrSize Nothing addr idx val + = do mkBasicIndexedWrite arrPtrsHdrSize Nothing addr idx val + emit (setInfo addr (CmmLit (CmmLabel mkMAP_DIRTY_infoLabel))) + -- the write barrier. We must write a byte into the mark table: + -- bits8[a + header_size + StgMutArrPtrs_size(a) + x >> N] + emit $ mkStore ( + cmmOffsetExpr + (cmmOffsetExprW (cmmOffsetB addr arrPtrsHdrSize) + (loadArrPtrsSize addr)) + (CmmMachOp mo_wordUShr [idx, + CmmLit (mkIntCLit mUT_ARR_PTRS_CARD_BITS)]) + ) (CmmLit (CmmInt 1 W8)) + +loadArrPtrsSize :: CmmExpr -> CmmExpr +loadArrPtrsSize addr = CmmLoad (cmmOffsetB addr off) bWord + where off = fixedHdrSize*wORD_SIZE + oFFSET_StgMutArrPtrs_ptrs mkBasicIndexedRead :: ByteOff -> Maybe MachOp -> CmmType -> LocalReg -> CmmExpr -> CmmExpr -> FCode ()