fregel-1.2.0: compiler/IR.hs
module IR where
import Debug.Trace
import Spec
import ASTData
data IRType = IRSimpleType (DType ())
| IRGenericsType String [IRType] -- vector<int> $B$J$I$N$D$b$j(B
| IRUserType String [IRType] -- Pair, Tuple, Record$B$?$A(B
| IRVoidType
deriving (Eq, Show)
-- type IRType = DType ()
type IRNameAndType = (String, IRType)
-- Emoto 2018/01/16: added the origianl state ID
type IRNameAndTypeWithId = (IRNameAndType, Int)
type IRVertexComputeState = (Int, Int) -- Phase number and Step number
-- $BA4BN(B
data IRProg = IRProg String -- $B%W%m%0%i%`L>(B
[IRTypeDecl] -- $B3F%U%'!<%:$,;H$&%G!<%?7?(B
IRVertexStruct -- $BD:E@$N%G!<%?7?(B
IREdgeStruct -- $B;^$NCM$N%G!<%?7?(B
IRMsgStruct -- $B%a%C%;!<%8$N%G!<%?7?(B
IRAggStruct -- Aggregator $B$N%G!<%?7?(B
Bool -- $B5U8~$-JU$r;H$($P(B True $B$=$&$G$J$1$l$P(B False
[String] -- message names to put message tag
OptimizeInfo -- optimization information
[IRConstant] -- $BDj?t(B
IRPhaseCompute -- Vertex.compute() / Master.compute() $B$r@8@.(B
IRVertexComputeState -- $B=i4|>uBV(B
[IRMethod] -- $BB>$N%a%=%C%I(B
deriving (Eq, Show)
------------------------------------------------------------------------
-- $B7?Dj5A4X78(B
------------------------------------------------------------------------
-- $B%G!<%?7?Dj5A(B
data IRTypeDecl = IRTypeDecl String -- $B9=B$BNL>(B
[IRNameAndType] -- $B9=B$BN%a%s%P!<(B ($BL>A0!$7?(B)
deriving (Eq, Show)
-- $BD:E@$N%G!<%?7?(B
data IRVertexStruct =
IRVertexStruct String -- "NData_??"
String -- $B%U%'!<%:HV9f(B
String -- $B%9%F%C%WHV9f(B
-- Emoto 2018/01/16: modified to add the origianl pahse ids for fields
[IRNameAndTypeWithId] -- $B9=B$BN%a%s%P!<(B ($BL>A0!$7?(B) : Prev/Curr $BIU$-$N$b$N(B
[IRNameAndTypeWithId] -- $B9=B$BN%a%s%P!<(B ($BL>A0!$7?(B) : val + Prev/Curr $B$J$7$G$h$$$b$N(B
deriving (Eq, Show)
-- $B;^$NCM$N%G!<%?7?(B
data IREdgeStruct =
IREdgeStruct String -- "EdgeData_??"
[IRNameAndType] -- $B9=B$BN%a%s%P!<(B ($BL>A0!$7?(B)
deriving (Eq, Show)
-- $BD:E@4V%a%C%;!<%8$N%G!<%?7?(B
-- data IRMsgStruct = IRMsgStruct [IRNameAndType] -- $B9=B$BN%a%s%P!<(B ($BL>A0!$7?(B)
-- deriving (Eq, Show)
data IRMsgStruct = IRMsgStruct String -- MsgData_??
[IRNameAndType] -- $B9=B$BN%a%s%P!<(B ($BL>A0!$7?(B)
deriving (Eq, Show)
-- $BHw9M(B
-- [("m1", int), ("m2", double)]
-- sendToNeighbor(("m1", ival));
-- sendToNeighbor(("m2", dval));
-- class MsgData extends Writable {
-- int mtype;
-- IntWritable m1;
-- DoubleWritable m2;
-- serialize() {
-- if (mtype == 1) { new IntWritable(1).serim1.serialize(); m1.serialize(); }
-- }
-- Aggregate $B$9$k%G!<%?(B
-- data IRAggStruct = IRAggStruct [(IRNameAndType, -- $B$=$l$>$l$NL>A0$H7?(B
-- IRAggOp)] -- $BMQ$$$k1i;;(B
-- deriving (Eq, Show)
data IRAggStruct = IRAggStruct String -- AggData_??
[(IRNameAndType, -- $B$=$l$>$l$NL>A0$H7?(B
IRAggOp)] -- $BMQ$$$k1i;;(B
deriving (Eq, Show)
-- $BDj?t(B
data IRConstant = IRConstant IRNameAndType -- $B7?$HL>A0(B
IRExpr -- $B<0(B
deriving (Eq, Show)
getIRConstantVar (IRConstant v e) = v
getIRConstantExp (IRConstant v e) = e
------------------------------------------------------------------------
-- $B%a%=%C%IDj5A(B
------------------------------------------------------------------------
data IRMethod = IRMethod IRType -- $BJV$jCM$N7?(B
String -- $B%a%=%C%IL>(B
[IRNameAndType] -- $B0z?t$NL>A0$H7?(B
IRBlock -- $BK\BN(B
deriving (Eq, Show)
data IRPhaseCompute =
IRPhaseCompute [IRPhaseComputeProcess] -- $B3F(B (phase,step) $B$K$*$1$k=hM}FbMF(B
deriving (Eq, Show)
data IRPhaseComputeProcess =
IRPhaseComputeProcess IRVertexComputeState -- Phase $BHV9f!$(BStep $BHV9f(B
Bool -- termination condition == Fix?
[IRNameAndType] -- $BI,MW$J6I=jJQ?t(B
IRBlock -- $BK\BN(B ($B4^$`<u?.=hM}(B)
[(IRExpr, IRVertexComputeState, IRBlock)] -- $BA+0\>r7o!$(B(Phase, Step), $BDL?.(B
deriving (Eq, Show)
data IRBlock = IRBlock [IRNameAndType] -- $B6I=jJQ?t(B
[IRStatement] -- $BK\BN(B
deriving (Eq, Show)
data IRStatement = IRStatementLocal IRVar IRExpr -- $B%m!<%+%k$J7W;;$K$h$kCM$NJQ?t$X$NBeF~(B
| IRStatementMsg IRVar IRAggOp IRExpr -- $BNY@\D:E@$NCM$N=8Ls(B
| IRStatementReturn IRExpr -- return$BJ8(B
| IRStatementVTH -- voteToHalt
| IRStatementAggr IRNameAndType IRExpr [IRExpr] -- Aggregator $B$X$N=q$-9~$_(B
| IRStatementSendN IRNameAndType IRExpr [IRExpr] -- ($BDL>o$NJU$K1h$C$?(B) $BAw?.%a%C%;!<%8$N%a%s%P!<$NL>A0(B/$B7?$HCM(B
| IRStatementSendR IRNameAndType IRExpr [IRExpr] -- ($BJU$r5U9T$9$k(B) $BAw?.%a%C%;!<%8$N%a%s%P!<$NL>A0(B/$B7?$HCM(B
| IRStatementIfThen IRExpr IRBlock
deriving (Eq, Show)
-- IRStatementMsg "v.foo" min (mval + 1)
-- $B$3$N$/$i$$$N>pJs$+$i<!$N%3!<%I$r=P$7$?$$(B
-- int foo = Integer.MAX_VALUE;
-- for (IntWritable msg : messages) {
-- foo = Math.min(foo, msg.getValue());
-- }
-- v.foo = new IntWritable(foo);
data IRVar = IRVarLocal IRNameAndType -- $B6I=jJQ?t(B
-- | IRVarVertex IRNameAndType -- $BD:E@$N%a%s%P!<(B
| IRVarVertex IRNameAndType IRPrevCurr [IRNameAndType] -- $BD:E@$N%a%s%P!<(B
| IRVarEdge IRNameAndType [IRNameAndType] -- $B;^$NCM!$%U%#!<%k%I%"%/%;%9(B
| IRVarAggr IRNameAndType -- Aggregator
deriving (Eq, Show)
data IRPrevCurr = IRPrev -- prev
| IRCurr -- curr
| IRNone
deriving (Eq, Show)
data IRExpr = IRIf IRExpr IRExpr IRExpr
| IRFunAp IRFun [IRExpr]
| IRVExp IRVar
| IRMVal IRNameAndType -- $BAw?.%a%C%;!<%8MQ(B
| IRCExp IRType IRConst
| IRAggr IRNameAndType
deriving (Show, Eq)
data IRFun = IRFun String
| IRBinOp String
deriving (Show, Eq)
data IRAggOp = IRAggMin
| IRAggMax
| IRAggSum
| IRAggProd
| IRAggAnd
| IRAggOr
| IRAggChoice IRConst -- used?
| IRTupledAgg [IRAggOp] -- for internal use?
deriving (Show, Eq)
data IRConst = IRCInt Int
| IRCBool Bool
| IRCString String
| IRCDouble Double
deriving (Eq, Show)