Skip to content

Commit 36302e2

Browse files
committed
edits helper function
1 parent cceed08 commit 36302e2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

gibbon-compiler/src/Gibbon/L3/Syntax.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Gibbon.L3.Syntax
2323
, getCursorizeTyFromRegVar''
2424
, getCursorizeTyFromRegVar'''
2525
, getIndexPositionOfSoALocVar
26+
, linearizeLocVar
2627
, module Gibbon.Language
2728
)
2829
where
@@ -318,6 +319,11 @@ getIndexPositionOfSoALocVar flds loc = foldl (\(s, e, b) (_, fl) -> if b
318319
in (e, e + sz, seen)
319320
) (1, 1, False) flds
320321

322+
linearizeLocVar :: LocVar -> [LocVar]
323+
linearizeLocVar loc = case loc of
324+
Single{} -> [loc]
325+
SoA dcloc flocs -> let flinear = concatMap (\(_, fl) -> linearizeLocVar fl) flocs
326+
in [singleLocVar dcloc] ++ flinear
321327

322328
getCursorizeTyFromLocVar :: LocVar -> Ty3
323329
getCursorizeTyFromLocVar lc = case lc of

gibbon-compiler/src/Gibbon/Passes/Cursorize.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,33 @@ mangle :: [Var] -> Var
150150
mangle vars = toVar $ "mangle" ++ (L.foldr (\v acc -> acc ++ "_" ++ (fromVar v)) "" vars)
151151

152152

153+
-- The LocVar here is the field location, which we need to generate code for.
154+
-- (Int, Int) is the start and end locations of that field.
155+
handleIndexingSoACursors :: (Int, Int) -> LocVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var, [(Var, [()], Ty3, Exp3)])
156+
handleIndexingSoACursors (start, end) locvar var_env = do
157+
let par_var = case (M.lookup (fromLocVarToFreeVarsTy locvar) var_env) of
158+
Just v -> v
159+
Nothing -> case locvar of
160+
Single l -> l
161+
SoA{} -> error "Expected variable name for parent array!"
162+
case locvar of
163+
Single{} -> do
164+
return (var_env, [(par_var, [], CursorTy, Ext $ IndexCursorArray par_var start)])
165+
SoA{} -> do
166+
(bnds, var_env') <- foldlM (\(b, env) (i, l) -> do
167+
(lvar, fenv') <- case (M.lookup (fromLocVarToFreeVarsTy l) var_env) of
168+
Just v -> return (v, env)
169+
Nothing -> do
170+
new_var <- gensym "unpack"
171+
let env' = M.insert (fromLocVarToFreeVarsTy l) new_var env
172+
return (new_var, env')
173+
pure $ (b ++ [(lvar, [], CursorTy, Ext $ IndexCursorArray par_var i)], fenv')
174+
175+
176+
) ([], var_env) (zip [start..end] (linearizeLocVar locvar))
177+
return (var_env, bnds)
178+
179+
153180
cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3
154181
cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do
155182
let inLocs = inLocVars funTy

0 commit comments

Comments
 (0)