summaryrefslogtreecommitdiff
path: root/compiler/codeGen
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@mit.edu>2011-07-07 20:48:48 -0400
committerEdward Z. Yang <ezyang@mit.edu>2011-07-07 20:49:13 -0400
commit82c9f3f0f42e917b113d2174f468e86074b895cc (patch)
tree741b139aa98b301195f51c54aab9c1534ccfb8bd /compiler/codeGen
parentdd391759500ab2b6abd23d502ade7ff8946c780f (diff)
downloadhaskell-82c9f3f0f42e917b113d2174f468e86074b895cc.tar.gz
Port 'Add two new primops seq# and spark#' (be54417) to new codegen.
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Diffstat (limited to 'compiler/codeGen')
-rw-r--r--compiler/codeGen/StgCmmExpr.hs20
-rw-r--r--compiler/codeGen/StgCmmPrim.hs12
2 files changed, 32 insertions, 0 deletions
diff --git a/compiler/codeGen/StgCmmExpr.hs b/compiler/codeGen/StgCmmExpr.hs
index eee4a08bc7..0edcbe48c6 100644
--- a/compiler/codeGen/StgCmmExpr.hs
+++ b/compiler/codeGen/StgCmmExpr.hs
@@ -71,6 +71,10 @@ cgExpr (StgLetNoEscape _ _ binds expr) =
cgExpr (StgCase expr _live_vars _save_vars bndr srt alt_type alts) =
cgCase expr bndr srt alt_type alts
+{- seq# a s ==> a -}
+cgExpr (StgOpApp (StgPrimOp SeqOp) [StgVarArg a, _] _res_ty) =
+ cgIdApp a []
+
cgExpr (StgLam {}) = panic "cgExpr: StgLam"
------------------------------------------------------------------------
@@ -322,6 +326,22 @@ cgCase scrut@(StgApp v []) _ _ (PrimAlt _) _
; emit $ mkComment $ mkFastString "should be unreachable code"
; emit $ withFreshLabel "l" (\l -> mkLabel l <*> mkBranch l)}
+{-
+case seq# a s of v
+ (# s', a' #) -> e
+
+==>
+
+case a of v
+ (# s', a' #) -> e
+
+(taking advantage of the fact that the return convention for (# State#, a #)
+is the same as the return convention for just 'a')
+-}
+cgCase (StgOpApp (StgPrimOp SeqOp) [StgVarArg a, _] _) bndr srt alt_type alts
+ = -- handle seq#, same return convention as vanilla 'a'.
+ cgCase (StgApp a []) bndr srt alt_type alts
+
cgCase scrut bndr srt alt_type alts
= -- the general case
do { up_hp_usg <- getVirtHp -- Upstream heap usage
diff --git a/compiler/codeGen/StgCmmPrim.hs b/compiler/codeGen/StgCmmPrim.hs
index 1a6d05e6e6..c71d285735 100644
--- a/compiler/codeGen/StgCmmPrim.hs
+++ b/compiler/codeGen/StgCmmPrim.hs
@@ -210,6 +210,18 @@ emitPrimOp [res] ParOp [arg]
(CmmLit (CmmLabel (mkCmmCodeLabel rtsPackageId (fsLit "newSpark"))))
[(CmmReg (CmmGlobal BaseReg), AddrHint), (arg,AddrHint)]
+emitPrimOp [res] SparkOp [arg]
+ = do
+ -- returns the value of arg in res. We're going to therefore
+ -- refer to arg twice (once to pass to newSpark(), and once to
+ -- assign to res), so put it in a temporary.
+ tmp <- assignTemp arg
+ emitCCall
+ []
+ (CmmLit (CmmLabel (mkCmmCodeLabel rtsPackageId (fsLit "newSpark"))))
+ [(CmmReg (CmmGlobal BaseReg), AddrHint), ((CmmReg (CmmLocal tmp)), AddrHint)]
+ emit (mkAssign (CmmLocal res) (CmmReg (CmmLocal tmp)))
+
emitPrimOp [res] ReadMutVarOp [mutv]
= emit (mkAssign (CmmLocal res) (cmmLoadIndexW mutv fixedHdrSize gcWord))