Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new data type that adds an abstraction to a region as AoS or SoA #272

Merged
merged 10 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions gibbon-compiler/examples/soa_ir_examples/addList.gibbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- AoS list representation of add1
{meta: FunMeta {funRec = Rec, funInline = NoInline, funCanTriggerGC = False}}
add1 :: List -> List
{locvars [LRM {lrmLoc = Single "loc_154",
lrmReg = AoSR (VarR "r_156"),
lrmMode = Input},
LRM {lrmLoc = Single "loc_155",
lrmReg = AoSR (VarR "r_157"),
lrmMode = Output}],
effs: [],
locrets: [],
parallel: False}
add1 lst_17_96_134 =
letloc (Single "loc_218") = ((Single "loc_155") + 1) in
letloc (Single "loc_219") = ((Single "loc_218") + 8) in
case lst_17_96_134 of
Nil ->
(Nil (Single "loc_155"))
Cons i_18_97_135::(Single "case_213") rst_19_98_136::(Single "case_214") ->
let i1_20_99_137 :: Int = i_18_97_135 + 1 in
let fltPkd_102_138 :: (Packed List (Single "loc_219")) = (add1 [(Single "case_214"),(Single "loc_219")] rst_19_98_136) in
(Cons (Single "loc_155") i1_20_99_137 fltPkd_102_138)

-- SoA list representation of add1
{meta: FunMeta {funRec = Rec, funInline = NoInline, funCanTriggerGC = False}}
add1 :: List -> List
{locvars [LRM {lrmLoc = SoA "loc_154" [(("Cons", 0), "loc_156")],
lrmReg = SoAR (VarR "r_156") [(("Cons", 0)), (VarR "r_158")],
lrmMode = Input},
LRM {lrmLoc = SoA "loc_155" [(("Cons", 0), "loc_157")] ,
lrmReg = SoAR (VarR "r_157") [(("Cons", 0), (VarR "r_159"))],
lrmMode = Output}],
effs: [],
locrets: [],
parallel: False}
add1 lst_17_96_134 =
letloc (SoA "loc_218" [(("Cons", 0), "loc_219")]) = (SoA ("loc_155" + 1) [(("Cons", 0), ("loc_157" + 8))]) in
case lst_17_96_134 of
Nil ->
(Nil (SoA "loc_155" [(("Cons", 0), "loc_157")]))
Cons i_18_97_135::(Single "case_213") rst_19_98_136::(Single "case_214") ->
let i1_20_99_137 :: Int = i_18_97_135 + 1 in
let fltPkd_102_138 :: (Packed List (SoA "loc_218" [(("Cons", 0), "loc_219")])) = (add1 [(Single "case_213"), (Single "case_214"),(SoA "loc_218" [(("Cons", 0), "loc_219")])] rst_19_98_136) in
(Cons (SoA "loc_155" [(("Cons", 0), "loc_157")]) i1_20_99_137 fltPkd_102_138)

39 changes: 39 additions & 0 deletions gibbon-compiler/examples/soa_ir_examples/mkList.gibbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- AoS IR representation
{meta: FunMeta {funRec = Rec, funInline = NoInline, funCanTriggerGC = False}}
mkList :: Int -> List
{locvars [LRM {lrmLoc = Single "loc_140",
lrmReg = AoSR (VarR "r_141"),
lrmMode = Output}],
effs: [],
locrets: [],
parallel: False}
mkList length_14_82_117 =
letloc (Single "loc_175") = ((Single "loc_140") + 1) in
letloc (Single "loc_176") = ((Single "loc_175") + 8) in
let fltIf_97_118 :: Bool = <=(length_14_82_117, 0) in
if fltIf_97_118
then (Nil (Single "loc_140"))
else let fltAppE_98_119 :: Int = length_14_82_117 - 1 in
let rst_15_83_120 :: (Packed List (Single "loc_176")) = (mkList [(Single "loc_176")] fltAppE_98_119) in
(Cons (Single "loc_140") length_14_82_117 rst_15_83_120)


-- SoA IR representation
{meta: FunMeta {funRec = Rec, funInline = NoInline, funCanTriggerGC = False}}
mkList :: Int -> List
{locvars [LRM {lrmLoc = SoA "loc_140" [(("Cons", 0), "loc_141")],
lrmReg = SoAR (VarR "r_141") [("Cons", 0), (VarR "r_142")],
lrmMode = Output}],
effs: [],
locrets: [],
parallel: False}
mkList length_14_82_117 =
-- This may need a new IR primitive?? to increment an SoA loc.
letloc (SoA "loc_175" [(("Cons", 0), "loc_176")]) = (SoA ("loc_175" + 1) [(("Cons", 0), ("loc_141" + 8))]) in
let fltIf_97_118 :: Bool = <=(length_14_82_117, 0) in
if fltIf_97_118
then (Nil (SoA "loc_140" [(("Cons", 0), "loc_141")]))
else let fltAppE_98_119 :: Int = length_14_82_117 - 1 in
let rst_15_83_120 :: (Packed List (SoA "loc_175" [(("Cons", 0), "loc_176")])) = (mkList [(SoA "loc_175" [(("Cons", 0), "loc_176")])] fltAppE_98_119) in
(Cons (SoA "loc_140" [(("Cons", 0), "loc_141")]) length_14_82_117 rst_15_83_120)

5 changes: 4 additions & 1 deletion gibbon-compiler/src/Gibbon/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module Gibbon.Common
(
-- * Variables
Var(..), LocVar(..), Location
Var(..), LocVar(..), Location, FieldIndex
, RegVar, fromVar, toVar, varAppend, toEndV, toEndVLoc, toSeqV, cleanFunName
, TyVar(..), isUserTv
, Symbol, intern, unintern
Expand Down Expand Up @@ -139,6 +139,9 @@ toSeqV v = varAppend v (toVar "_seq")
-- | A location variable stores the abstract location.
type Location = Var

-- | The position or index of a field in a data constructor value.
type FieldIndex = Int

data LocVar = Single Location
deriving (Show, Ord, Eq, Read, Generic, NFData, Out)

Expand Down
58 changes: 29 additions & 29 deletions gibbon-compiler/src/Gibbon/L2/Examples.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add1Fun = FunDef "add1" [ "tr1"] add1FunTy add1FunBod (FunMeta Rec NoInline Fals

add1FunTy :: ArrowTy2 Ty2
add1FunTy = ArrowTy2
[LRM (Single "lin2") (VarR "r3") Input, LRM (Single "lout4") (VarR "r750") Output]
[LRM (Single "lin2") (AoSR $ VarR "r3") Input, LRM (Single "lout4") (AoSR $ VarR "r750") Output]
[PackedTy "Tree" (Single "lin2")]
S.empty
(PackedTy "Tree" (Single "lout4"))
Expand Down Expand Up @@ -147,7 +147,7 @@ id1Fun = FunDef "id1" [ "tr18"] idFunTy idFunBod (FunMeta NotRec NoInline False)

idFunTy :: ArrowTy2 Ty2
idFunTy = ArrowTy2
[LRM (Single "lin19") (VarR "r20") Input, LRM (Single "lout21") (VarR "r751") Output]
[LRM (Single "lin19") (AoSR $ VarR "r20") Input, LRM (Single "lout21") (AoSR $ VarR "r751") Output]
[PackedTy "Tree" (Single "lin19")]
(S.empty)
(PackedTy "Tree" (Single "lout21"))
Expand All @@ -164,7 +164,7 @@ copyTreeFun :: FunDef2
copyTreeFun = FunDef "copyTree" [ "tr22"] copyFunTy copyBod (FunMeta NotRec NoInline False)
where
copyFunTy = ArrowTy2
[LRM (Single "lin23") (VarR "r24") Input, LRM (Single "lout25") (VarR "r752") Output]
[LRM (Single "lin23") (AoSR $ VarR "r24") Input, LRM (Single "lout25") (AoSR$ VarR "r752") Output]
[PackedTy "Tree" (Single "lin23")]
S.empty
(PackedTy "Tree" (Single "lout25"))
Expand Down Expand Up @@ -215,7 +215,7 @@ id2Fun = FunDef "id2" [ "tr41"] id2Ty id2Bod (FunMeta NotRec NoInline False)
where
id2Ty :: ArrowTy2 Ty2
id2Ty = ArrowTy2
[LRM (Single "lin37") (VarR "r38") Input, LRM (Single "lout39") (VarR "r753") Output]
[LRM (Single "lin37") (AoSR $ VarR "r38") Input, LRM (Single "lout39") (AoSR $ VarR "r753") Output]
[PackedTy "Tree" (Single "lin37")]
(S.empty)
(PackedTy "Tree" (Single "lout39"))
Expand Down Expand Up @@ -313,7 +313,7 @@ leftmostFun = FunDef "leftmost" [ "t111"] leftmostTy leftmostBod (FunMeta Rec No
where
leftmostTy :: ArrowTy2 Ty2
leftmostTy = ArrowTy2
[LRM (Single "lin112") (VarR "r113") Input]
[LRM (Single "lin112") (AoSR $ VarR "r113") Input]
[PackedTy "Tree" (Single "lin112")]
(S.empty)
(IntTy)
Expand Down Expand Up @@ -354,7 +354,7 @@ rightmostFun = FunDef "rightmost" [ "t242"] rightmostTy rightmostBod (FunMeta Re
where
rightmostTy :: ArrowTy2 Ty2
rightmostTy = ArrowTy2
[LRM (Single "lin241") (VarR "r240") Input]
[LRM (Single "lin241") (AoSR $ VarR "r240") Input]
[PackedTy "Tree" (Single "lin241")]
(S.empty)
(IntTy)
Expand Down Expand Up @@ -400,7 +400,7 @@ buildLeafFun = FunDef "buildLeaf" [ "i125"] buildLeafTy buildLeafBod (FunMeta Re
where
buildLeafTy :: ArrowTy2 Ty2
buildLeafTy = ArrowTy2
[LRM (Single "lout126") (VarR "r127") Output]
[LRM (Single "lout126") (AoSR $ VarR "r127") Output]
[IntTy]
(S.empty)
(PackedTy "Tree" (Single "lout126"))
Expand All @@ -427,7 +427,7 @@ buildTreeFun = FunDef "buildTree" [ "i270"] buildTreeTy buildTreeBod (FunMeta Re
where
buildTreeTy :: ArrowTy2 Ty2
buildTreeTy = ArrowTy2
[LRM (Single "lout272") (VarR "r271") Output]
[LRM (Single "lout272") (AoSR $ VarR "r271") Output]
[IntTy]
(S.empty)
(PackedTy "Tree" (Single "lout272"))
Expand Down Expand Up @@ -467,7 +467,7 @@ buildTwoTreesFun = FunDef "buildTwoTrees" [ "i750"] buildTreeTy buildTreeBod (Fu
where
buildTreeTy :: ArrowTy2 Ty2
buildTreeTy = ArrowTy2
[LRM (Single "lout752") (VarR "r751") Output, LRM (Single "lout754") (VarR "r753") Output]
[LRM (Single "lout752") (AoSR $ VarR "r751") Output, LRM (Single "lout754") (AoSR $ VarR "r753") Output]
[IntTy]
(S.empty)
(ProdTy [PackedTy "Tree" (Single "lout752"), PackedTy "Tree" (Single "lout754")])
Expand Down Expand Up @@ -504,7 +504,7 @@ buildTreeSumFun = FunDef "buildTreeSum" [ "i302"] buildTreeSumTy buildTreeSumBod
where
buildTreeSumTy :: ArrowTy2 Ty2
buildTreeSumTy = ArrowTy2
[LRM (Single "lout301") (VarR "r300") Output]
[LRM (Single "lout301") (AoSR $ VarR "r300") Output]
[IntTy]
(S.empty)
(ProdTy [IntTy, PackedTy "Tree" (Single "lout301")])
Expand Down Expand Up @@ -556,7 +556,7 @@ sumTreeFun = FunDef "sumTree" [ "tr762"] sumTreeTy sumTreeBod (FunMeta Rec NoInl
where
sumTreeTy :: ArrowTy2 Ty2
sumTreeTy = ArrowTy2
[LRM (Single "lin761") (VarR "r760") Input]
[LRM (Single "lin761") (AoSR $ VarR "r760") Input]
[PackedTy "Tree" (Single "lin761")]
(S.empty)
(IntTy)
Expand Down Expand Up @@ -646,9 +646,9 @@ addTreesFun = FunDef "addTrees" [ "trees354"] addTreesTy addTreesBod (FunMeta Re
where
addTreesTy :: ArrowTy2 Ty2
addTreesTy = ArrowTy2
[LRM (Single "lin351") (VarR "r350") Input,
LRM (Single "lin352") (VarR "r351") Input,
LRM (Single "lout353") (VarR "r754") Output]
[LRM (Single "lin351") (AoSR $ VarR "r350") Input,
LRM (Single "lin352") (AoSR $ VarR "r351") Input,
LRM (Single "lout353") (AoSR $ VarR "r754") Output]
[ProdTy [PackedTy "Tree" (Single "lin351"), PackedTy "Tree" (Single "lin352")]]
(S.empty)
(PackedTy "Tree" (Single "lout353"))
Expand Down Expand Up @@ -720,7 +720,7 @@ testProdFun :: FunDef2
testProdFun = FunDef "testprod" [ "tup130"] testprodTy testprodBod (FunMeta Rec NoInline False)
where
testprodTy = ArrowTy2
[LRM (Single "lin131") (VarR "r132") Input, LRM (Single "lout133") (VarR "r755") Output]
[LRM (Single "lin131") (AoSR $ VarR "r132") Input, LRM (Single "lout133") (AoSR $ VarR "r755") Output]
[ProdTy [(PackedTy "Tree" (Single "lin131")), IntTy]]
(S.empty)
(ProdTy [(PackedTy "Tree" (Single "lout133")), IntTy])
Expand Down Expand Up @@ -814,7 +814,7 @@ sumUpFun = FunDef "sumUp" [ "tr1"] sumUpFunTy sumUpFunBod (FunMeta Rec NoInline
where
sumUpFunTy :: ArrowTy2 Ty2
sumUpFunTy = ArrowTy2
[LRM (Single "lin501") (VarR "r500") Input, LRM (Single "lout502") (VarR "r756") Output]
[LRM (Single "lin501") (AoSR $ VarR "r500") Input, LRM (Single "lout502") (AoSR $ VarR "r756") Output]
[PackedTy "STree" (Single "lin501")]
(S.empty)
(PackedTy "STree" (Single "lout502"))
Expand Down Expand Up @@ -853,7 +853,7 @@ valueSTreeFun = FunDef "valueSTree" [ "tr522"] valueSTreeFunTy valueSTreeFunBod
where
valueSTreeFunTy :: ArrowTy2 Ty2
valueSTreeFunTy = ArrowTy2
[LRM (Single "lin524") (VarR "r523") Input]
[LRM (Single "lin524") (AoSR $ VarR "r523") Input]
[PackedTy "STree" (Single "lin524")]
(S.empty)
(IntTy)
Expand All @@ -875,7 +875,7 @@ buildSTreeFun = FunDef "buildSTree" [ "i543"] buildSTreeTy buildSTreeBod (FunMet
where
buildSTreeTy :: ArrowTy2 Ty2
buildSTreeTy = ArrowTy2
[LRM (Single "lout541") (VarR "r540") Output]
[LRM (Single "lout541") (AoSR $ VarR "r540") Output]
[IntTy]
(S.empty)
(PackedTy "STree" (Single "lout541"))
Expand Down Expand Up @@ -923,7 +923,7 @@ sumSTreeFun = FunDef "sumSTree" [ "tr762"] sumSTreeTy sumSTreeBod (FunMeta Rec N
where
sumSTreeTy :: ArrowTy2 Ty2
sumSTreeTy = ArrowTy2
[LRM (Single "lin761") (VarR "r760") Input]
[LRM (Single "lin761") (AoSR $ VarR "r760") Input]
[PackedTy "STree" (Single "lin761")]
(S.empty)
(IntTy)
Expand Down Expand Up @@ -1022,7 +1022,7 @@ setEvenFun = FunDef "setEven" [ "tr570"] setEvenFunTy setEvenFunBod (FunMeta Rec
where
setEvenFunTy :: ArrowTy2 Ty2
setEvenFunTy = ArrowTy2
[LRM (Single "lin571") (VarR "r570") Input, LRM (Single "lout572") (VarR "r757") Output]
[LRM (Single "lin571") (AoSR $ VarR "r570") Input, LRM (Single "lout572") (AoSR $ VarR "r757") Output]
[PackedTy "STree" (Single "lin571")]
(S.empty)
(PackedTy "STree" (Single "lout572"))
Expand Down Expand Up @@ -1105,7 +1105,7 @@ sumUpSetEvenFun = FunDef "sumUpSetEven" [ "tr600"] sumUpSetEvenFunTy sumUpSetEve
where
sumUpSetEvenFunTy :: ArrowTy2 Ty2
sumUpSetEvenFunTy = ArrowTy2
[LRM (Single "lin601") (VarR "r600") Input, LRM (Single "lout602") (VarR "r758") Output]
[LRM (Single "lin601") (AoSR $ VarR "r600") Input, LRM (Single "lout602") (AoSR $ VarR "r758") Output]
[PackedTy "STree" (Single "lin601")]
(S.empty)
(ProdTy [PackedTy "STree" (Single "lout602"), IntTy])
Expand Down Expand Up @@ -1198,8 +1198,8 @@ copyExprFun = FunDef "copyExpr" [ "e700"] copyExprFunTy copyExprFunBod (FunMeta
where
copyExprFunTy :: ArrowTy2 Ty2
copyExprFunTy = ArrowTy2
[LRM (Single "lin702") (VarR "r701") Input,
LRM (Single "lout703") (VarR "r759") Output]
[LRM (Single "lin702") (AoSR $ VarR "r701") Input,
LRM (Single "lout703") (AoSR $ VarR "r759") Output]
[PackedTy "Expr" (Single "lin702")]
(S.empty)
(PackedTy "Expr" (Single "lout703"))
Expand Down Expand Up @@ -1230,9 +1230,9 @@ substFun = FunDef "subst" [ "tr653"] substFunTy substFunBod (FunMeta Rec NoInlin
where
substFunTy :: ArrowTy2 Ty2
substFunTy = ArrowTy2
[LRM (Single "lin651") (VarR "r650") Input,
LRM (Single "lin652") (VarR "r650") Input,
LRM (Single "lout653") (VarR "r760") Output]
[LRM (Single "lin651") (AoSR $ VarR "r650") Input,
LRM (Single "lin652") (AoSR $ VarR "r650") Input,
LRM (Single "lout653") (AoSR $ VarR "r760") Output]
[ProdTy [IntTy,
PackedTy "Expr" (Single "lin651"),
PackedTy "Expr" (Single "lin652")]]
Expand Down Expand Up @@ -1325,7 +1325,7 @@ indrBuildTreeFun = FunDef "indrBuildTree" [ "i270"] indrBuildTreeTy indrBuildTre
where
indrBuildTreeTy :: ArrowTy2 Ty2
indrBuildTreeTy = ArrowTy2
[LRM (Single "lout272") (VarR "r271") Output]
[LRM (Single "lout272") (AoSR $ VarR "r271") Output]
[IntTy]
(S.empty)
(PackedTy "Tree" (Single "lout272"))
Expand Down Expand Up @@ -1370,7 +1370,7 @@ indrRightmostFun = FunDef "indrRightmost" [ "t742"] indrRightmostTy indrRightmos
where
indrRightmostTy :: ArrowTy2 Ty2
indrRightmostTy = ArrowTy2
[LRM (Single "lin741") (VarR "r740") Input]
[LRM (Single "lin741") (AoSR $ VarR "r740") Input]
[PackedTy "Tree" (Single "lin741")]
S.empty
IntTy
Expand Down Expand Up @@ -1406,7 +1406,7 @@ indrIDFun = FunDef "indrID" [ "tr800"] indrIDTy indrIDBod (FunMeta NotRec NoInli
where
indrIDTy :: ArrowTy2 Ty2
indrIDTy = ArrowTy2
[LRM (Single "lin802") (VarR "r801") Input, LRM (Single "lout803") (VarR "r803") Output]
[LRM (Single "lin802") (AoSR $ VarR "r801") Input, LRM (Single "lout803") (AoSR $ VarR "r803") Output]
[PackedTy "Tree" (Single "lin802")]
(S.empty)
(PackedTy "Tree" (Single "lout803"))
Expand Down
Loading
Loading