Commit 619941b4 authored by Simon Marlow's avatar Simon Marlow
Browse files

Add a builtin rule for seq# when its argument is a manifest

head-normal-form, and similarly for spark#.
parent be544179
......@@ -24,9 +24,10 @@ import Id
import Literal
import PrimOp ( PrimOp(..), tagToEnumKey )
import TysWiredIn
import TysPrim
import TyCon ( tyConDataCons_maybe, isEnumerationTyCon, isNewTyCon )
import DataCon ( dataConTag, dataConTyCon, dataConWorkId, fIRST_TAG )
import CoreUtils ( cheapEqExpr )
import CoreUtils ( cheapEqExpr, exprIsHNF )
import CoreUnfold ( exprIsConApp_maybe )
import Type
import OccName ( occNameFS )
......@@ -37,6 +38,7 @@ import Outputable
import FastString
import StaticFlags ( opt_SimplExcessPrecision )
import Constants
import BasicTypes
import Data.Bits as Bits
import Data.Int ( Int64 )
......@@ -174,9 +176,10 @@ primOpRules op op_name = primop_rule op
primop_rule WordEqOp = relop (==)
primop_rule WordNeOp = relop (/=)
primop_rule _ = []
primop_rule SeqOp = mkBasicRule op_name 4 seqRule
primop_rule SparkOp = mkBasicRule op_name 4 sparkRule
primop_rule _ = []
\end{code}
%************************************************************************
......@@ -538,6 +541,27 @@ dataToTagRule id_unf [_, val_arg]
dataToTagRule _ _ = Nothing
\end{code}
%************************************************************************
%* *
\subsection{Rules for seq# and spark#}
%* *
%************************************************************************
\begin{code}
-- seq# :: forall a s . a -> State# s -> (# State# s, a #)
seqRule :: IdUnfoldingFun -> [CoreExpr] -> Maybe CoreExpr
seqRule _ [ty_a, Type ty_s, a, s] | exprIsHNF a
= Just (mkConApp (tupleCon Unboxed 2)
[Type (mkStatePrimTy ty_s), ty_a, s, a])
seqRule _ _ = Nothing
-- spark# :: forall a s . a -> State# s -> (# State# s, a #)
sparkRule :: IdUnfoldingFun -> [CoreExpr] -> Maybe CoreExpr
sparkRule = seqRule -- reduce on HNF, just the same
-- XXX perhaps we shouldn't do this, because a spark eliminated by
-- this rule won't be counted as a dud at runtime?
\end{code}
%************************************************************************
%* *
\subsection{Built in rules}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment