Skip to content

Commit

Permalink
revert change to L2 IR for AfterConstant and AfterVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Dec 5, 2024
1 parent 947bdc4 commit dc0f88e
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 172 deletions.
110 changes: 55 additions & 55 deletions gibbon-compiler/src/Gibbon/L2/Examples.hs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gibbon-compiler/src/Gibbon/L2/Interp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ interpExt sizeEnv rc env ddefs fenv ext =
Just _ ->
go (M.insert (unwrapLocVar loc) (VLoc (regionToVar reg) 0) env) sizeEnv bod

AfterConstantLE i _ loc2 -> do
AfterConstantLE i loc2 -> do
case M.lookup (unwrapLocVar loc2) env of
Nothing -> error $ "L2.Interp: Unbound location: " ++ sdoc loc2
Just (VLoc reg offset) ->
go (M.insert (unwrapLocVar loc) (VLoc reg (offset + i)) env) sizeEnv bod
Just val ->
error $ "L2.Interp: Unexpected value for " ++ sdoc loc2 ++ ":" ++ sdoc val

AfterVariableLE v _ loc2 _ -> do
AfterVariableLE v loc2 _ -> do
case M.lookup (unwrapLocVar loc2) env of
Nothing -> error $ "L2.Interp: Unbound location: " ++ sdoc loc2
Just (VLoc reg offset) ->
Expand Down
24 changes: 11 additions & 13 deletions gibbon-compiler/src/Gibbon/L2/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,20 @@ data E2Ext loc dec
-- | Define a location in terms of a different location.
data PreLocExp loc = StartOfRegionLE Region
| AfterConstantLE Int -- Number of bytes after. (In case of an SoA loc, this is the offset into the data constructor buffer)
[Int] -- Optional list with offset bytes, these offsets can be used for bumping field locations for an SoA location.
loc -- Location which this location is offset from.

| AfterVariableLE Var -- Name of variable v. This loc is size(v) bytes after.
[Var] -- Optional list with offset bytes, each size(v) bytes, these can be used for bumping field locations for an SoA location.
loc -- Location which this location is offset from.
Bool -- Whether it's running in a stolen continuation i.e
-- whether this should return an index in a fresh region or not.
-- It's True by default and flipped by ParAlloc if required.
| InRegionLE Region
| FreeLE
| FromEndLE loc

| AfterVectorLE [PreLocExp loc]


deriving (Read, Show, Eq, Ord, Functor, Generic, NFData)

type LocExp = PreLocExp LocVar
Expand All @@ -211,7 +214,7 @@ instance FreeVars (E2Ext l d) where
LetRegionE _ _ _ bod -> gFreeVars bod
LetParRegionE _ _ _ bod -> gFreeVars bod
LetLocE _ rhs bod -> (case rhs of
AfterVariableLE v vs _loc _ -> S.singleton v `S.union` S.fromList vs
AfterVariableLE v _loc _ -> S.singleton v
_ -> S.empty)
`S.union`
gFreeVars bod
Expand All @@ -232,8 +235,8 @@ instance FreeVars (E2Ext l d) where
instance FreeVars LocExp where
gFreeVars e =
case e of
AfterConstantLE _ _ loc -> S.singleton $ unwrapLocVar loc
AfterVariableLE v vs loc _ -> S.fromList [v, unwrapLocVar loc] `S.union` S.fromList vs
AfterConstantLE _ loc -> S.singleton $ unwrapLocVar loc
AfterVariableLE v loc _ -> S.fromList [v, unwrapLocVar loc]
_ -> S.empty

instance (Out l, Out d, Show l, Show d) => Expression (E2Ext l d) where
Expand Down Expand Up @@ -909,12 +912,7 @@ occurs w ex =
LetLocE _ le bod ->
let oc_bod = go bod in
case le of
AfterVariableLE v vs _ _ -> let func = (\v accum -> if v `S.member` w
then True || accum
else False || accum
)
reduce = L.foldr func False vs
in reduce || v `S.member` w || oc_bod
AfterVariableLE v _ _ -> v `S.member` w || oc_bod
StartOfRegionLE{} -> oc_bod
AfterConstantLE{} -> oc_bod
InRegionLE{} -> oc_bod
Expand Down Expand Up @@ -1051,8 +1049,8 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty
dep ex =
case ex of
StartOfRegionLE r -> [singleLocVar $ regionToVar r]
AfterConstantLE _ _ loc -> [loc]
AfterVariableLE v vs loc _ -> [singleLocVar v,loc] ++ L.map singleLocVar vs
AfterConstantLE _ loc -> [loc]
AfterVariableLE v loc _ -> [singleLocVar v,loc]
InRegionLE r -> [singleLocVar $ regionToVar r]
FromEndLE loc -> [loc]
FreeLE -> []
Expand Down
4 changes: 2 additions & 2 deletions gibbon-compiler/src/Gibbon/L2/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,14 @@ tcExp ddfs env funs constrs regs tstatein exp =
tstate3 <- removeLoc exp tstate2 (Single loc)
return (ty,tstate3)
{-TODO handle what needs to happen with the wildcard argument, list of offsets in case of soa -}
AfterConstantLE i _ l1 ->
AfterConstantLE i l1 ->
do r <- getRegion exp constrs l1
let tstate1 = extendTS (Single loc) (Output,True) $ setAfter l1 tstatein
let constrs1 = extendConstrs (InRegionC (Single loc) r) $ extendConstrs (AfterConstantC i l1 (Single loc)) constrs
(ty,tstate2) <- tcExp ddfs env' funs constrs1 regs tstate1 e
tstate3 <- removeLoc exp tstate2 (Single loc)
return (ty,tstate3)
AfterVariableLE x _ l1 _ ->
AfterVariableLE x l1 _ ->
do r <- getRegion exp constrs l1
(_xty,tstate1) <- tcExp ddfs env funs constrs regs tstatein $ VarE x
-- NOTE: We now allow aliases (offsets) from scalar vars too. So we can leave out this check
Expand Down
4 changes: 2 additions & 2 deletions gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ fromOldL2Exp ddefs fundefs locenv env2 ex =
toLocArg loc locexp locenv0 =
case locexp of
StartOfRegionLE reg -> New.Loc (New.LREM loc (regionToVar reg) (toEndV (regionToVar reg)) Output)
AfterConstantLE _ _ loc2 ->
AfterConstantLE _ loc2 ->
let (New.Loc lrem) = locenv0 # loc2
in New.Loc (New.LREM loc (New.lremReg lrem) (New.lremEndReg lrem) Output)
AfterVariableLE _ _ loc2 _ ->
AfterVariableLE _ loc2 _ ->
let (New.Loc lrem) = locenv0 # loc2
in New.Loc (New.LREM loc (New.lremReg lrem) (New.lremEndReg lrem) Output)
InRegionLE reg ->
Expand Down
8 changes: 4 additions & 4 deletions gibbon-compiler/src/Gibbon/NewL2/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ toEndFromTaggedV v = (toVar "end_from_tagged_") `varAppend` v
instance FreeVars LocExp where
gFreeVars e =
case e of
Old.AfterConstantLE _ _ loc -> S.singleton $ unwrapLocVar (toLocVar loc)
Old.AfterVariableLE v vs loc _ -> S.fromList [v, unwrapLocVar (toLocVar loc)] `S.union` S.fromList vs
Old.AfterConstantLE _ loc -> S.singleton $ unwrapLocVar (toLocVar loc)
Old.AfterVariableLE v loc _ -> S.fromList [v, unwrapLocVar (toLocVar loc)]
_ -> S.empty


Expand Down Expand Up @@ -510,8 +510,8 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty
dep ex =
case ex of
Old.StartOfRegionLE r -> [Old.regionToVar r]
Old.AfterConstantLE _ _ loc -> [unwrapLocVar $ toLocVar loc]
Old.AfterVariableLE v vs loc _ -> [v, unwrapLocVar $ toLocVar loc] ++ vs
Old.AfterConstantLE _ loc -> [unwrapLocVar $ toLocVar loc]
Old.AfterVariableLE v loc _ -> [v, unwrapLocVar $ toLocVar loc]
Old.InRegionLE r -> [Old.regionToVar r]
Old.FromEndLE loc -> [unwrapLocVar $ toLocVar loc]
Old.FreeLE -> []
Expand Down
4 changes: 2 additions & 2 deletions gibbon-compiler/src/Gibbon/Passes/AddRAN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ we need random access for that type.
let reg = case rhs of
StartOfRegionLE r -> regionToVar r
InRegionLE r -> regionToVar r
AfterConstantLE _ _ lc -> renv # lc
AfterVariableLE _ _ lc _ -> renv # lc
AfterConstantLE _ lc -> renv # lc
AfterVariableLE _ lc _ -> renv # lc
FromEndLE lc -> renv # lc -- TODO: This needs to be fixed
in needsRANExp ddefs fundefs env2 (M.insert loc reg renv) tcenv parlocss bod
_ -> S.empty
Expand Down
4 changes: 2 additions & 2 deletions gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ addTraversalsExp ddefs fundefs env2 renv context ex =
let reg = case locexp of
StartOfRegionLE r -> regionToVar r
InRegionLE r -> regionToVar r
AfterConstantLE _ _ lc -> renv # lc
AfterVariableLE _ _ lc _ -> renv # lc
AfterConstantLE _ lc -> renv # lc
AfterVariableLE _ lc _ -> renv # lc
FromEndLE lc -> renv # lc -- TODO: This needs to be fixed
in Ext <$> LetLocE loc locexp <$>
addTraversalsExp ddefs fundefs env2 (M.insert loc reg renv) context bod
Expand Down
4 changes: 2 additions & 2 deletions gibbon-compiler/src/Gibbon/Passes/CalculateBounds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ calculateBoundsExp ddefs env2 varSzEnv varLocEnv locRegEnv locOffEnv regSzEnv re
let (re, off) = case locExp of
(StartOfRegionLE r ) -> (regionToVar r, BoundedSize 0)
-- [2024.12.04] VS: currently discarding offsets for SoA representation
(AfterConstantLE n _ l ) -> (locRegEnv # l, locOffEnv # l <> BoundedSize n)
(AfterConstantLE n l ) -> (locRegEnv # l, locOffEnv # l <> BoundedSize n)
-- [2022.12.26] CSK: the lookup in varSzEnv always fails since the
-- pass never inserts anything into it. Disabling it for now.
-- [2024.12.04] VS: currently discarding offsets for SoA representation
(AfterVariableLE v _ l _) -> (locRegEnv # l, locOffEnv # (varLocEnv # v)) -- <> varSzEnv # v
(AfterVariableLE v l _) -> (locRegEnv # l, locOffEnv # (varLocEnv # v)) -- <> varSzEnv # v
(InRegionLE r ) -> (regionToVar r, Undefined)
(FromEndLE l ) -> (locRegEnv # l, Undefined)
FreeLE -> undefined
Expand Down
8 changes: 3 additions & 5 deletions gibbon-compiler/src/Gibbon/Passes/Cursorize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,12 @@ cursorizeReadPackedFile ddfs fundefs denv tenv senv isPackedContext v path tyc r
cursorizeLocExp :: DepEnv -> TyEnv Var Ty2 -> SyncEnv -> LocVar -> LocExp -> Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv)
cursorizeLocExp denv tenv senv lvar locExp =
case locExp of
AfterConstantLE i [] loc ->
AfterConstantLE i loc ->
let rhs = Ext $ AddCursor ((unwrapLocVar . toLocVar) loc) (LitE i)
in if isBound ((toLocVar) loc) tenv
then Right (rhs, [], tenv, senv)
else Left$ M.insertWith (++) ((toLocVar) loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv
AfterConstantLE i irst loc -> error "cursorizeLocExp :: AfterConstantLE Bounds for SoA not implemented."

-- TODO: handle product types here

{- [2018.03.07]:
Expand All @@ -712,7 +712,7 @@ For BigInfinite regions, this is simple:
But Infinite regions do not support sizes yet. Re-enable this later.
-}
AfterVariableLE v [] locarg was_stolen -> do
AfterVariableLE v locarg was_stolen -> do
let vty = case M.lookup v tenv of
Just ty -> ty
Nothing -> case M.lookup v senv of
Expand Down Expand Up @@ -764,8 +764,6 @@ But Infinite regions do not support sizes yet. Re-enable this later.
Right (bod, bnds, tenv', M.delete v senv)
else Left $ M.insertWith (++) loc [((unwrapLocVar lvar),[],CursorTy,bod)] denv

AfterVariableLE v vrst locarg was_stolen -> error "TODO: cursorizeLocExp: AfterVariableLE offsets for SoA not implemented yet."

FromEndLE locarg ->
let loc = toLocVar locarg in
if isBound loc tenv
Expand Down
8 changes: 4 additions & 4 deletions gibbon-compiler/src/Gibbon/Passes/FindWitnesses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ findWitnesses p@Prog{fundefs} = mapMExprs fn p
then Ext $ LetLocE loc locexp $ goE (Set.insert loc bound) mp bod
else
case locexp of
AfterVariableLE v vs loc2 b ->
(go (Map.insert loc (DelayLoc (loc, (AfterVariableLE v vs loc2 b))) mp) bod)
AfterConstantLE i irst loc2 ->
go (Map.insert loc (DelayLoc (loc, (AfterConstantLE i irst loc2))) mp) bod
AfterVariableLE v loc2 b ->
(go (Map.insert loc (DelayLoc (loc, (AfterVariableLE v loc2 b))) mp) bod)
AfterConstantLE i loc2 ->
go (Map.insert loc (DelayLoc (loc, (AfterConstantLE i loc2))) mp) bod
_ -> Ext $ LetLocE loc locexp $ goE (Set.insert loc bound) mp bod
LetRegionE r sz ty bod -> Ext $ LetRegionE r sz ty $ go mp bod
LetParRegionE r sz ty bod -> Ext $ LetParRegionE r sz ty $ go mp bod
Expand Down
2 changes: 1 addition & 1 deletion gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ followPtrs (Prog ddefs fundefs mainExp) = do
let in_locs = foldr (\loc acc -> if loc == scrt_loc then ((Single indir_ptrv) : acc) else (loc : acc)) [] (inLocVars funTy)
let out_locs = outLocVars funTy
wc <- gensym "wildcard"
let indir_bod = Ext $ LetLocE (Single jump) (AfterConstantLE 8 [] (Single indir_ptrloc)) $
let indir_bod = Ext $ LetLocE (Single jump) (AfterConstantLE 8 (Single indir_ptrloc)) $
(if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->i ")]) else id) $
LetE (callv,endofs',out_ty,AppE funName (in_locs ++ out_locs) args) $
Ext (RetE ret_endofs callv)
Expand Down
Loading

0 comments on commit dc0f88e

Please sign in to comment.