From ce1f676c49dd65e26a284a21a2fa4881104b2b1d Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Wed, 10 Sep 2025 21:29:48 -0400 Subject: [PATCH 01/60] Hoist BoundsChecking --- .../src/Gibbon/Passes/HoistExpressions.hs | 345 ++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 gibbon-compiler/src/Gibbon/Passes/HoistExpressions.hs diff --git a/gibbon-compiler/src/Gibbon/Passes/HoistExpressions.hs b/gibbon-compiler/src/Gibbon/Passes/HoistExpressions.hs new file mode 100644 index 000000000..9720928c4 --- /dev/null +++ b/gibbon-compiler/src/Gibbon/Passes/HoistExpressions.hs @@ -0,0 +1,345 @@ +module Gibbon.Passes.HoistExpressions (hoistBoundsCheckProg, hoistBoundsCheck) where + +import Data.Foldable (foldlM) +import qualified Data.Map as M +import qualified Data.Set as S +import Gibbon.Common +import Gibbon.NewL2.Syntax as NewL2 + +--------------------------------------------------------------------------- +-- Hoist the bounds check expression to the top of each function + +-- | Map to store variables in scope +type BoundEnv = S.Set FreeVarsTy + +-- | The type of expressions that can be hoisted to the top +data HoistableExpr + = BoundsCheckExpr Int LocArg LocArg + | BoundsCheckVectorExpr [(Int, LocArg, LocArg)] + | LetLocExpr LocVar (PreLocExp LocArg) + | LetRegExpr RegVar (PreRegExp LocArg) + | LetExpr (Var, [LocArg], Ty2, PreExp E2Ext LocArg Ty2) + | LetRegionExpr Region RegionSize (Maybe RegionType) + deriving (Eq, Ord) + +-- | Stores all the expressions that can be hoisted to the top of the function +type HoistAbleExprMap = M.Map HoistableExpr (S.Set FreeVarsTy) + +mergeHoistExprMaps :: [HoistAbleExprMap] -> HoistAbleExprMap +mergeHoistExprMaps = foldr (M.unionWith S.union) M.empty + +fromLocArgToFreeVarsTy' :: LocArg -> [FreeVarsTy] +fromLocArgToFreeVarsTy' arg = + case arg of + Loc lrm -> [fromLocVarToFreeVarsTy $ lremLoc lrm, fromRegVarToFreeVarsTy $ lremReg lrm] + EndWitness _ v -> [fromLocVarToFreeVarsTy v] + Reg v _ -> [fromRegVarToFreeVarsTy v] + EndOfReg v1 _ v2 -> [fromRegVarToFreeVarsTy v1, fromRegVarToFreeVarsTy v2] + EndOfReg_Tagged v -> [fromRegVarToFreeVarsTy v] + +-- | In order to move all bounds check expressions, we store them in the env. +-- In addition, we also need to store all dependent variables the bounds check +-- depends on in the env. +-- We reuturn the updated expression and map. +collectBoundsCheckExprs :: HoistAbleExprMap -> BoundEnv -> NewL2.Exp2 -> PassM (NewL2.Exp2, HoistAbleExprMap) +collectBoundsCheckExprs env benv ex = do + case ex of + AppE f applocs args -> do + res <- mapM (collectBoundsCheckExprs env benv) args + let args' = map fst res + let envs = map snd res + let env' = mergeHoistExprMaps envs + return (AppE f applocs args', env') + LetE bnd@(v, locs, ty, rhs) bod -> do + case rhs of + Ext (BoundsCheck sz bound cur) -> do + let free_vars_in_bound_expr = S.fromList $ concat [fromLocArgToFreeVarsTy' cur, fromLocArgToFreeVarsTy' bound] + if (S.isSubsetOf free_vars_in_bound_expr benv) + then do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (LetE bnd bod', env') + else do + let delayBind = BoundsCheckExpr sz bound cur + let env' = M.insert delayBind free_vars_in_bound_expr env + (bod', env'') <- collectBoundsCheckExprs env' benv bod + return (bod', env'') + Ext (BoundsCheckVector bounds) -> do + let free_vars_in_bound_expr = S.fromList $ concatMap (\(_, bound, cur) -> concat [fromLocArgToFreeVarsTy' bound, fromLocArgToFreeVarsTy' cur]) bounds + if (S.isSubsetOf free_vars_in_bound_expr benv) + then do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (LetE bnd bod', env') + else do + let delayBind = BoundsCheckVectorExpr bounds + let env' = M.insert delayBind free_vars_in_bound_expr env + (bod', env'') <- collectBoundsCheckExprs env' benv bod + return (bod', env'') + _ -> do + (rhs', env') <- collectBoundsCheckExprs env benv rhs + (bod', env'') <- collectBoundsCheckExprs env' benv bod + return (LetE (v, locs, ty, rhs') bod', env'') + WithArenaE v e -> do + (e', env') <- collectBoundsCheckExprs env benv e + return (WithArenaE v e', env') + Ext ext -> + case ext of + AddFixed {} -> return (ex, env) + LetLocE loc rhs bod -> do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (Ext $ LetLocE loc rhs bod', env') + LetRegE reg rhs bod -> do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (Ext $ LetRegE reg rhs bod', env') + RetE {} -> return (ex, env) + TagCursor {} -> return (ex, env) + LetRegionE r sz ty bod -> do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (Ext $ LetRegionE r sz ty bod', env') + LetParRegionE r sz ty bod -> do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (Ext $ LetParRegionE r sz ty bod', env') + FromEndE {} -> return (ex, env) + BoundsCheck {} -> return (ex, env) + IndirectionE {} -> return (ex, env) + GetCilkWorkerNum -> return (ex, env) + LetAvail vs bod -> do + (bod', env') <- collectBoundsCheckExprs env benv bod + return (Ext $ LetAvail vs bod', env') + AllocateTagHere {} -> return (ex, env) + AllocateScalarsHere {} -> pure (ex, env) + SSPush {} -> pure (ex, env) + SSPop {} -> pure (ex, env) + _ -> pure (ex, env) + -- Straightforward recursion + VarE {} -> return (ex, env) + LitE {} -> return (ex, env) + CharE {} -> return (ex, env) + FloatE {} -> return (ex, env) + LitSymE {} -> return (ex, env) + PrimAppE {} -> return (ex, env) + DataConE {} -> return (ex, env) + ProjE i e -> do + (e', env') <- collectBoundsCheckExprs env benv e + return (ProjE i e', env') + IfE a b c -> do + (a', env') <- collectBoundsCheckExprs env benv a + (b', env'') <- collectBoundsCheckExprs env benv b + (c', env''') <- collectBoundsCheckExprs env benv c + let env'''' = mergeHoistExprMaps [env', env'', env'''] + return (IfE a' b' c', env'''') + MkProdE ls -> do + res <- mapM (collectBoundsCheckExprs env benv) ls + let ls' = map fst res + let env' = mergeHoistExprMaps $ (map snd res) ++ [env] + return (MkProdE ls', env') + CaseE scrt mp -> do + res <- + mapM + ( \(c, args, ae) -> do + (ae', env') <- collectBoundsCheckExprs env benv ae + return ((c, args, ae'), env') + ) + mp + let mp' = map fst res + let env' = mergeHoistExprMaps $ map snd res + return (CaseE scrt mp', env') + TimeIt e ty b -> do + (e', env') <- collectBoundsCheckExprs env benv e + return (TimeIt e' ty b, env') + SpawnE {} -> error "collectBoundsCheckExprs: TODO SpawnE" + SyncE -> pure (ex, env) + MapE {} -> error $ "collectBoundsCheckExprs: TODO MapE" + FoldE {} -> error $ "collectBoundsCheckExprs: TODO FoldE" + +-- | store a expression that needs to be hoisted in the env. +-- We return the updated map and weather the bind was needed or not +storeHoistableExpr :: FreeVarsTy -> FreeVarsTy -> S.Set FreeVarsTy -> HoistableExpr -> HoistAbleExprMap -> (HoistAbleExprMap, Bool) +storeHoistableExpr v1 v2 dependentVars hoistableExpr env + | v1 == v2 = (M.insert hoistableExpr dependentVars env, True) + | otherwise = (env, False) + +-- | Function that stores all defined vars in the env and returns an expression without the defined variable. +collectVarsForBoundsCheck :: FreeVarsTy -> HoistAbleExprMap -> NewL2.Exp2 -> PassM (NewL2.Exp2, HoistAbleExprMap) +collectVarsForBoundsCheck vars env ex = do + case ex of + AppE f applocs args -> do + res <- mapM (collectVarsForBoundsCheck vars env) args + let args' = map fst res + let envs = map snd res + let env' = mergeHoistExprMaps envs + return (AppE f applocs args', env') + LetE (v, locs, ty, rhs) bod -> do + let (env', store) = storeHoistableExpr (fromVarToFreeVarsTy v) vars (allFreeVars rhs) (LetExpr (v, locs, ty, rhs)) env + if store + then do + (bod', env'') <- collectVarsForBoundsCheck vars env' bod + return (bod', env'') + else do + (rhs', env'') <- collectVarsForBoundsCheck vars env' rhs + (bod', env''') <- collectVarsForBoundsCheck vars env'' bod + return (LetE (v, locs, ty, rhs') bod', env''') + WithArenaE v e -> do + (e', env') <- collectVarsForBoundsCheck vars env e + return (WithArenaE v e', env') + Ext ext -> + case ext of + AddFixed {} -> return (ex, env) + LetLocE loc rhs bod -> do + let (env', store) = storeHoistableExpr (fromLocVarToFreeVarsTy loc) vars (freeVarsInLocExp rhs) (LetLocExpr loc rhs) env + (bod', env'') <- collectVarsForBoundsCheck vars env' bod + if store + then do + return (bod', env'') + else do + return (Ext $ LetLocE loc rhs bod', env'') + LetRegE reg rhs bod -> do + let (env', store) = storeHoistableExpr (fromRegVarToFreeVarsTy reg) vars S.empty (LetRegExpr reg rhs) env + (bod', env'') <- collectVarsForBoundsCheck vars env' bod + if store + then do + return (bod', env'') + else do + return (Ext $ LetRegE reg rhs bod', env'') + RetE {} -> return (ex, env) + TagCursor {} -> return (ex, env) + LetRegionE r sz ty bod -> do + let (env', store) = storeHoistableExpr (fromRegVarToFreeVarsTy (regionToVar r)) vars S.empty (LetRegionExpr r sz ty) env + (bod', env'') <- collectVarsForBoundsCheck vars env' bod + if store + then do + return (bod', env'') + else do + return (Ext $ LetRegionE r sz ty bod', env'') + LetParRegionE r sz ty bod -> do + (bod', env') <- collectVarsForBoundsCheck vars env bod + return (Ext $ LetParRegionE r sz ty bod', env') + FromEndE {} -> return (ex, env) + BoundsCheck {} -> return (ex, env) + IndirectionE {} -> return (ex, env) + GetCilkWorkerNum -> return (ex, env) + LetAvail vs bod -> do + (bod', env') <- collectVarsForBoundsCheck vars env bod + return (Ext $ LetAvail vs bod', env') + AllocateTagHere {} -> return (ex, env) + AllocateScalarsHere {} -> pure (ex, env) + SSPush {} -> pure (ex, env) + SSPop {} -> pure (ex, env) + _ -> pure (ex, env) + -- Straightforward recursion + VarE {} -> return (ex, env) + LitE {} -> return (ex, env) + CharE {} -> return (ex, env) + FloatE {} -> return (ex, env) + LitSymE {} -> return (ex, env) + PrimAppE {} -> return (ex, env) + DataConE {} -> return (ex, env) + ProjE i e -> do + (e', env') <- collectVarsForBoundsCheck vars env e + return (ProjE i e', env') + IfE a b c -> do + (a', env') <- collectVarsForBoundsCheck vars env a + (b', env'') <- collectVarsForBoundsCheck vars env b + (c', env''') <- collectVarsForBoundsCheck vars env c + let env'''' = mergeHoistExprMaps [env', env'', env'''] + return (IfE a' b' c', env'''') + MkProdE ls -> do + res <- mapM (collectVarsForBoundsCheck vars env) ls + let ls' = map fst res + let env' = mergeHoistExprMaps $ (map snd res) ++ [env] + return (MkProdE ls', env') + CaseE scrt mp -> do + res <- + mapM + ( \(c, args, ae) -> do + (ae', env') <- collectVarsForBoundsCheck vars env ae + return ((c, args, ae'), env') + ) + mp + let mp' = map fst res + let env' = mergeHoistExprMaps $ map snd res + return (CaseE scrt mp', env') + TimeIt e ty b -> do + (e', env') <- collectVarsForBoundsCheck vars env e + return (TimeIt e' ty b, env') + SyncE -> pure (ex, env) + SpawnE {} -> error "collectVarsForBoundsCheck: TODO SpawnE" + MapE {} -> error $ "collectVarsForBoundsCheck: TODO MapE" + FoldE {} -> error $ "collectVarsForBoundsCheck: TODO FoldE" + +freeVarsInLocExp :: LocExp -> S.Set FreeVarsTy +freeVarsInLocExp expr = case expr of + StartOfRegionLE r -> S.singleton $ fromRegVarToFreeVarsTy (regionToVar r) + AfterConstantLE _ loc -> S.fromList (fromLocArgToFreeVarsTy' loc) + AfterVariableLE v loc _ -> S.fromList $ concat [[fromVarToFreeVarsTy v], (fromLocArgToFreeVarsTy' loc)] + InRegionLE _ -> S.empty + FreeLE -> S.empty + FromEndLE loc -> S.fromList (fromLocArgToFreeVarsTy' loc) + GenSoALoc loc flocs -> + let env = S.fromList (fromLocArgToFreeVarsTy' loc) + env' = S.fromList $ concatMap (\(_, l) -> fromLocArgToFreeVarsTy' l) flocs + in S.union env env' + GetDataConLocSoA loc -> S.fromList (fromLocArgToFreeVarsTy' loc) + GetFieldLocSoA _ loc -> S.fromList (fromLocArgToFreeVarsTy' loc) + AssignLE loc -> S.fromList (fromLocArgToFreeVarsTy' loc) + +hoistBoundsCheckProg :: NewL2.Prog2 -> PassM NewL2.Prog2 +hoistBoundsCheckProg Prog {ddefs, fundefs, mainExp} = do + fds' <- mapM (hoistBoundsCheckFun) $ M.elems fundefs + let fundefs' = M.fromList $ map (\f -> (funName f, f)) fds' + mainExp' <- case mainExp of + Nothing -> return Nothing + Just (mn, ty) -> do + mn' <- hoistBoundsCheck mn S.empty + return $ Just (mn', ty) + return $ Prog ddefs fundefs' mainExp' + +hoistBoundsCheckFun :: NewL2.FunDef2 -> PassM NewL2.FunDef2 +hoistBoundsCheckFun f@FunDef {funTy, funBody} = do + let initBoundEnv = S.fromList $ map (\(LRM l _ _) -> fromLocVarToFreeVarsTy l) (locVars funTy) + funBody' <- hoistBoundsCheck funBody initBoundEnv + return $ f {funBody = funBody'} + +-- | recursive function to make sure we release all dependencies for a particular hoistable expression. +-- We return the new expression and updates map (removed binds that were released) +hoistBoundsCheckHelper :: S.Set HoistableExpr -> HoistAbleExprMap -> NewL2.Exp2 -> PassM (NewL2.Exp2, S.Set HoistableExpr) +hoistBoundsCheckHelper visited env l2exp = do + let boundCheckExprs = M.toList env + (exp', visited') <- + foldlM + ( \(expr, vmap) (boundsCheck, dependentVars) -> do + -- recursively release all dependent vars + (expr', lets) <- + foldlM + ( \(exp'', letenv) var -> do + (exp''', lets) <- collectVarsForBoundsCheck var M.empty exp'' + let letenv' = M.union letenv lets + pure (exp''', letenv') + ) + (expr, M.empty) + (S.toList dependentVars) + let expr'' = + if S.member boundsCheck vmap + then Nothing + else case boundsCheck of + BoundsCheckExpr i bound cur -> Just $ LetE ("_", [], MkTy2 IntTy, (Ext $ BoundsCheck i bound cur)) expr' + BoundsCheckVectorExpr bounds -> Just $ LetE ("_", [], MkTy2 IntTy, (Ext $ BoundsCheckVector bounds)) expr' + LetLocExpr l rhs -> Just $ Ext $ LetLocE l rhs expr' + LetRegExpr r rhs -> Just $ Ext $ LetRegE r rhs expr' + LetRegionExpr r sz ty -> Just $ Ext $ LetRegionE r sz ty expr' + _ -> error "hoistBoundsCheckHelper: Did not expect expression!" + -- release all lets + -- call function recursively + let vmap' = S.insert boundsCheck vmap + case expr'' of + Nothing -> pure (expr', vmap') + Just expression -> hoistBoundsCheckHelper vmap' lets expression + ) + (l2exp, visited) + boundCheckExprs + pure (exp', visited') + +hoistBoundsCheck :: NewL2.Exp2 -> BoundEnv -> PassM NewL2.Exp2 +hoistBoundsCheck inexp benv = do + (exp', m) <- collectBoundsCheckExprs M.empty benv inexp + (exp'', _) <- hoistBoundsCheckHelper S.empty m exp' + pure exp'' From b99da199f7ad4e583ad0e3a225a7309e59a8842b Mon Sep 17 00:00:00 2001 From: vidush Date: Fri, 12 Sep 2025 18:11:36 -0400 Subject: [PATCH 02/60] Wip: Introduce mutable cursors for updating cursor value in place --- gibbon-compiler/src/Gibbon/L2/Syntax.hs | 2 + gibbon-compiler/src/Gibbon/L3/Syntax.hs | 8 +- gibbon-compiler/src/Gibbon/L3/Typecheck.hs | 17 ++++- gibbon-compiler/src/Gibbon/L4/Syntax.hs | 7 ++ gibbon-compiler/src/Gibbon/Language/Syntax.hs | 4 +- .../src/Gibbon/Passes/AddCastInstructions.hs | 27 ++++++- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 28 ++++++- .../src/Gibbon/Passes/Cursorize.hs | 73 +++++++++++++++---- gibbon-compiler/src/Gibbon/Passes/Lower.hs | 17 ++++- .../src/Gibbon/Passes/ThreadRegions2.hs | 7 +- gibbon-compiler/src/Gibbon/Pretty.hs | 1 + 11 files changed, 165 insertions(+), 26 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index 096401717..73d7c564e 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -1001,6 +1001,7 @@ mapPacked fn t = PtrTy -> PtrTy CursorTy -> CursorTy CursorArrayTy size -> CursorArrayTy size + MutCursorTy -> MutCursorTy ArenaTy -> ArenaTy VectorTy elty -> VectorTy elty ListTy elty -> ListTy elty @@ -1023,6 +1024,7 @@ constPacked c t = PtrTy -> PtrTy CursorTy -> CursorTy CursorArrayTy size -> CursorArrayTy size + MutCursorTy -> MutCursorTy ArenaTy -> ArenaTy VectorTy el_ty -> VectorTy (constPacked c el_ty) ListTy el_ty -> ListTy (constPacked c el_ty) diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index e09c95db0..4f5b1dcf6 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -69,6 +69,8 @@ data E3Ext loc dec = | MakeCursorArray Int [Var] -- ^ Make a Cursor Array from a list of Cursors. Returns a new variable for Cursor Array. | IndexCursorArray Var Int -- ^ Index into a Cursor Array | AddCursor Var (PreExp E3Ext loc dec) -- ^ Add a constant offset to a cursor variable + | AddrOfCursor (PreExp E3Ext loc dec) -- ^ Take the address of a Cursor. + | DerefMutCursor Var -- ^ Explicitly de-reference a mutable cursor | CastPtr Var dec -- ^ Cast a pointer to the specified type | SubPtr Var Var -- ^ Pointer subtraction | NewBuffer L2.Multiplicity -- ^ Create a new buffer, and return a cursor @@ -81,7 +83,7 @@ data E3Ext loc dec = -- we'll probably represent (sizeof x) as (end_x - start_x) / INT | SizeOfScalar Var -- ^ sizeof(var) | BoundsCheck Int Var Var -- ^ Bytes required, region, write cursor - | BoundsCheckVector [(Int, Var, Var)] -- ^ Bytes required, region, write cursor but for a vector of cursors and regions + | BoundsCheckVector [(Int, Var, Var, (Var, Var))] -- ^ Bytes required, region, write cursor but for a vector of cursors and regions | IndirectionBarrier TyCon (Var,Var,Var,Var) -- ^ Do one of the following: -- (1) If it's a old-to-young indirection, record it in the remembered set. @@ -288,11 +290,13 @@ cursorizeTy ty = PDictTy k v -> PDictTy (cursorizeTy k) (cursorizeTy v) PackedTy _ l -> case l of Single _ -> ProdTy [CursorTy, CursorTy] - SoA _ flds -> ProdTy [CursorArrayTy (1 + length flds), CursorArrayTy (1 + length flds)] + SoA _ flds -> ProdTy [CursorArrayTy (1 + length flds), CursorArrayTy (1 + length flds)] VectorTy el_ty' -> VectorTy $ cursorizeTy el_ty' ListTy el_ty' -> ListTy $ cursorizeTy el_ty' PtrTy -> PtrTy CursorTy -> CursorTy + CursorArrayTy sz -> CursorArrayTy sz + MutCursorTy -> MutCursorTy ArenaTy -> ArenaTy SymSetTy -> SymSetTy SymHashTy-> SymHashTy diff --git a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs index 17f0c5fe0..677495763 100644 --- a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs @@ -160,9 +160,11 @@ tcExp isSoA isPacked ddfs env exp = do cty <- lookupVar env cur exp ensureEqualTyModCursor isSoA exp cty CursorTy return IntTy - + + {- VS: Ignoring the types of the arguments to gib grow region -} + {- Should we check these? -} BoundsCheckVector bounds -> do - _ <- mapM (\(_, bound, cur) -> do + _ <- mapM (\(_, bound, cur, _) -> do rty <- lookupVar env bound exp ensureEqualTyModCursor isSoA exp rty CursorTy cty <- lookupVar env cur exp @@ -249,6 +251,17 @@ tcExp isSoA isPacked ddfs env exp = do ensureEqualTyModCursor isSoA exp vty vty return CursorTy + AddrOfCursor expr -> do + ety <- go expr + ensureEqualTyModCursor isSoA expr ety CursorTy + return MutCursorTy + + DerefMutCursor v -> do + vty <- lookupVar env v exp + ensureEqualTyModCursor isSoA exp vty MutCursorTy + return CursorTy + + MakeCursorArray _ vars -> do tys <- mapM (\v -> lookupVar env v exp) vars unless (all (== CursorTy) tys) $ throwError $ GenericTC ("Expected all vars to be of type CursorTy. Got: " ++ sdoc tys) exp diff --git a/gibbon-compiler/src/Gibbon/L4/Syntax.hs b/gibbon-compiler/src/Gibbon/L4/Syntax.hs index 82bc1faf4..3892d1e09 100644 --- a/gibbon-compiler/src/Gibbon/L4/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L4/Syntax.hs @@ -31,6 +31,7 @@ import Gibbon.Common import qualified Gibbon.Language as L import qualified Gibbon.L2.Syntax as L2 import qualified Gibbon.L3.Syntax as L3 +import Gibbon.L3.Syntax (E3Ext(DerefMutCursor)) -------------------------------------------------------------------------------- @@ -61,6 +62,7 @@ data Triv | SymTriv Word16 -- ^ An index into the symbol table. | ProdTriv [Triv] -- ^ Tuples | ProjTriv Int Triv -- ^ Projections + | IndexCursorArrayTriv Int Triv -- ^ Indexing operation deriving (Show, Ord, Eq, Generic, NFData, Out) typeOfTriv :: M.Map Var Ty -> Triv -> Ty @@ -73,6 +75,7 @@ typeOfTriv env trv = BoolTriv{} -> BoolTy TagTriv{} -> TagTyPacked SymTriv{} -> SymTy + IndexCursorArrayTriv{} -> CursorTy ProdTriv ts -> ProdTy (map (typeOfTriv env) ts) ProjTriv i trv1 -> case typeOfTriv env trv1 of ProdTy tys -> tys !! i @@ -201,6 +204,7 @@ data Ty | RegionTy -- ^ Region start and a refcount | ChunkTy -- ^ Start and end pointers | CursorArrayTy Int + | MutCursorTy -- TODO: Make Ptrs more type safe like this: -- | StructPtrTy { fields :: [Ty] } -- ^ A pointer to a struct containing the given fields. @@ -369,6 +373,8 @@ data Prim | IndexCursorArray | MakeCursorArray | CastPtr + | AddrOfCursor + | DerefMutCursor deriving (Show, Ord, Eq, Generic, NFData, Out) @@ -449,6 +455,7 @@ fromL3Ty ty = L.PtrTy -> PtrTy L.CursorTy -> CursorTy L.CursorArrayTy size -> CursorArrayTy size + L.MutCursorTy -> MutCursorTy -- L.PackedTy{} -> error "fromL3Ty: Cannot convert PackedTy" L.VectorTy el_ty -> VectorTy (fromL3Ty el_ty) _ -> IntTy -- [2019.06.10]: CSK, Why do we need this? diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 3b85ba94a..648bead8c 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -631,7 +631,9 @@ data UrTy loc | CursorArrayTy Int -- ^ An array of cursors for reading or writing multiple cursors. -- ^ The cursor may point to an unkwown type or to a fraction of a complete value. -- ^ It is a machine pointer that can point to any byte. - -- ^ The Int is the number of cursors in the array. + -- ^ The Int is the number of cursors in the array. + | MutCursorTy -- ^ A reference to a CursorTy. This can be mutated in place. + deriving (Show, Read, Ord, Eq, Generic, NFData, Functor, Foldable, Traversable, Out) diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index 181e6cde7..ced2779dc 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -49,6 +49,18 @@ addCastsExp fundef cenv env ex = bod' <- addCastsExp fundef cenv' env' bod let ex' = foldr (\expr acc -> expr acc) bod' let_expr pure $ ex' + + LetE (v, locs, ty, rhs@(Ext (AddrOfCursor (Ext (IndexCursorArray _ _)))) ) bod -> do + let new_env = extendVEnv v ty env + (let_expr, cenv', env') <- case ty of + MutCursorTy -> return $ ([LetE (v, locs, ty, rhs)], cenv, new_env) + CursorTy -> error "Did not expect lhs of address of expression to be a cursor." + CursorArrayTy _ -> error "Cannot take address of a CursorArray!\n" + _ -> error "addCastsExp: Casting expressions others than cursors hot handled!\n" + bod' <- addCastsExp fundef cenv' env' bod + let ex' = foldr (\expr acc -> expr acc) bod' let_expr + pure $ ex' + LetE (v, locs, ty, (Ext (MakeCursorArray len vars))) bod -> do let new_env = extendVEnv v ty env (new_insts, cenv', env', vars') <- @@ -301,6 +313,11 @@ addCastsExp fundef cenv env ex = Nothing -> v e' <- go e pure (Ext $ AddCursor nv e') + Ext (DerefMutCursor v) -> do + let nv = case (M.lookup v cenv) of + Just v' -> v' + Nothing -> v + pure (Ext $ DerefMutCursor nv) Ext (SubPtr a b) -> do let na = case (M.lookup a cenv) of Just v' -> v' @@ -343,14 +360,20 @@ addCastsExp fundef cenv env ex = Ext (BoundsCheckVector bounds) -> do bounds' <- mapM - ( \(i, a, b) -> do + ( \(i, a, b, (a', b')) -> do let na = case (M.lookup a cenv) of Just v' -> v' Nothing -> a let nb = case (M.lookup b cenv) of Just v' -> v' Nothing -> b - return $ (i, na, nb) + let na' = case (M.lookup a' cenv) of + Just v' -> v' + Nothing -> a' + let nb' = case (M.lookup b' cenv) of + Just v' -> v' + Nothing -> b' + return $ (i, na, nb, (na', nb')) ) bounds pure $ Ext (BoundsCheckVector bounds') diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index 57c979eaf..3c816ff12 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -31,6 +31,7 @@ import qualified Gibbon.Language as GL import Gibbon.DynFlags import Gibbon.L2.Syntax ( Multiplicity(..) ) import Gibbon.L4.Syntax +import Language.Haskell.Exts (var) -------------------------------------------------------------------------------- @@ -480,6 +481,7 @@ codegenTriv venv (ProdTriv ls) = codegenTriv venv (ProjTriv i trv) = let field = "field" ++ show i in [cexp| $(codegenTriv venv trv).$id:field |] +codegenTriv venv (IndexCursorArrayTriv idx v) = [cexp| $(codegenTriv venv v)[$int:idx] |] -- Type environment @@ -1072,11 +1074,17 @@ codegenTail venv fenv sort_fns (LetPrimCallT bnds prm rnds body) ty sync_deps = --_new_chunk <- gensym "new_chunk" --_chunk_start <- gensym "chunk_start" --_chunk_end <- gensym "chunk_end" - ifConds <- mapM (\(ProdTriv [(IntTriv i),(VarTriv bound), (VarTriv cur)]) -> + ifConds <- mapM (\(ProdTriv [(IntTriv i),(VarTriv bound), (VarTriv cur), _]) -> pure [cexp| ($id:cur + $int:i) > $id:bound |] ) rnds - ifBody <- mapM (\(ProdTriv [(IntTriv i),(VarTriv bound), (VarTriv cur)]) -> - pure [ C.BlockStm [cstm| gib_grow_region(& $id:cur, & $id:bound); |] ] + ifBody <- mapM (\(ProdTriv [_, _, _, ProdTriv [(VarTriv b), (VarTriv c)]]) -> do + {- TODO: VS: Maybe we should check loc too, but i think we desinged this such that it is + not needed! -} + let bty = M.lookup b venv + case bty of + Just CursorTy -> pure [ C.BlockStm [cstm| gib_grow_region(& $id:c, & $id:b); |] ] + Just MutCursorTy -> pure [ C.BlockStm [cstm| gib_grow_region(& $id:c, $id:b); |] ] + _ -> error "Did not expect variable type in gib_grow_region!\n" ) rnds let condExpr = foldr1 (\c1 c2 -> [cexp| $exp:c1 || $exp:c2 |]) ifConds let ifBody' = concat ifBody @@ -1572,6 +1580,18 @@ codegenTail venv fenv sort_fns (LetPrimCallT bnds prm rnds body) ty sync_deps = [ptr] = rnds ptr' = codegenTriv venv ptr return [ C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV = ($ty:(codegenTy outT)) $exp:ptr'; |] ] + + AddrOfCursor -> do + let [(outV, outT)] = bnds + [expr] = rnds + expr' = codegenTriv venv expr + return [ C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV = &($exp:expr'); |] ] + + DerefMutCursor -> do + let [(outV, outT)] = bnds + [var] = rnds + var' = codegenTriv venv var + return [ C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV = *($exp:var'); |] ] _ -> error $ "codegen: " ++ show prm ++ " unhandled." @@ -1654,6 +1674,7 @@ codegenTy SymTy = [cty|typename GibSym|] codegenTy PtrTy = [cty|typename GibPtr|] -- char* - Hack, this could be void* if we have enough casts. [2016.11.06] codegenTy CursorTy = [cty|typename GibCursor|] codegenTy (CursorArrayTy size) = [cty|typename GibCursor* |] +codegenTy MutCursorTy = [cty|typename GibCursor* |] codegenTy RegionTy = [cty|typename GibChunk|] codegenTy ChunkTy = [cty|typename GibChunk|] codegenTy (ProdTy []) = [cty|unsigned char|] @@ -1679,6 +1700,7 @@ makeName' SymTy = "GibSym" makeName' BoolTy = "GibBool" makeName' CursorTy = "GibCursor" makeName' (CursorArrayTy{}) = "GibCursorPtr" +makeName' (MutCursorTy) = "GibMutCursor" makeName' TagTyPacked = "GibPackedTag" makeName' TagTyBoxed = "GibBoxedTag" makeName' PtrTy = "GibPtr" diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 0cca653a5..4774ee5f8 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -761,11 +761,20 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Nothing -> case bound_reg of SingleR vr -> vr SoARv _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv + let bound_var_ty = M.lookup bound_var tenv + (additional_bnds, bound_var') <- do + case bound_var_ty of + Just (MkTy2 MutCursorTy) -> do + dereference_bound_var <- gensym "deref" + let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] + pure (bnd, dereference_bound_var) + Nothing -> error "expected variable to have type!" + _ -> pure ([], bound_var) let cur_loc = toLocVar cur let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of Just v -> v Nothing -> error $ "cursorizeExp: BoundsCheck: unexpected location variable" ++ sdoc cur_loc ++ " " ++ show freeVarToVarEnv - exp' <- return $ Ext $ L3.BoundsCheck i bound_var cur_var + exp' <- return $ mkLets additional_bnds <$> Ext $ L3.BoundsCheck i bound_var' cur_var --exp' <- if isBound cur_var tenv -- then return $ Ext $ L3.BoundsCheck i bound_var cur_var -- else do @@ -774,7 +783,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = return exp' Gibbon.NewL2.Syntax.BoundsCheckVector bounds -> do - bounds' <- mapM (\(i, bound, cur) -> do + (bounds', lets) <- foldrM (\(i, bound, cur) (b, l) -> do let bound_loc = toLocVar bound let bound_reg = fromLocVarToRegVar bound_loc let bound_var = case (M.lookup (fromRegVarToFreeVarsTy bound_reg) freeVarToVarEnv) of @@ -782,15 +791,24 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Nothing -> case bound_reg of SingleR vr -> vr SoARv _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv + let bound_var_ty = M.lookup bound_var tenv + (additional_bnds, bound_var') <- do + case bound_var_ty of + Just (MkTy2 MutCursorTy) -> do + dereference_bound_var <- gensym "deref" + let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] + pure (bnd, dereference_bound_var) + Nothing -> error "expected variable to have type!" + _ -> pure ([], bound_var) let cur_loc = toLocVar cur let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of Just v -> v Nothing -> case cur_loc of Single vr -> vr SoA _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv - return $ (i, bound_var, cur_var) - ) bounds - exp' <- return $ Ext $ L3.BoundsCheckVector bounds' + return (b ++ [(i, bound_var', cur_var, (bound_var, cur_var))], l ++ additional_bnds) + ) ([], []) bounds + exp' <- return $ mkLets lets <$> Ext $ L3.BoundsCheckVector bounds' return exp' FromEndE{} -> error $ "cursorizeExp: TODO FromEndE" ++ sdoc ext @@ -820,9 +838,23 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = {- Right now i just skip the let region, just recurse on the body-} LetRegE loc rhs bod -> do --let loc = fromRegVarToLocVar reg_var + -- VS: Hack, assume that these are always Mutable cursors. + -- TODO: We should have a pass to decide what we should make mutable + -- vs: what we should not not make mutable. + -- let ty_of_loc = case loc of + -- SingleR _ -> CursorTy + -- SoARv _ flds -> CursorArrayTy (1 + length flds) + -- let ty2_of_loc :: Ty2 = case loc of + -- SingleR _ -> MkTy2 CursorTy + -- SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) + -- In case we unpack single regions, we make them mutable since they may + -- be updated by bounds check. let ty_of_loc = case loc of - SingleR _ -> CursorTy + SingleR _ -> MutCursorTy SoARv _ flds -> CursorArrayTy (1 + length flds) + let ty2_of_loc :: Ty2 = case loc of + SingleR _ -> MkTy2 MutCursorTy + SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) freeVarToVarEnv' <- do case loc of SingleR l -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv @@ -848,8 +880,11 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = SoARv _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" case rhs of -- Discharge bindings that were waiting on 'loc'. - _ -> mkLets (bnds' ++ [(locs_var,[],ty_of_loc,rhs')] ++ bnds) <$> - cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 CursorTy) tenv''') senv' bod + _ -> case ty_of_loc of + MutCursorTy -> mkLets (bnds' ++ [(locs_var,[],ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds) <$> + cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + _ -> mkLets (bnds' ++ [(locs_var,[],ty_of_loc,rhs')] ++ bnds) <$> + cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod -- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod Left denv' -> (mkLets bnds) <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod @@ -1389,9 +1424,15 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = {- Right now i just skip the let region, just recurse on the body-} LetRegE loc rhs bod -> do --let loc = fromRegVarToLocVar reg_var + -- let ty_of_loc = case loc of + -- SingleR _ -> CursorTy + -- SoARv _ flds -> CursorArrayTy (1 + length flds) let ty_of_loc = case loc of - SingleR _ -> CursorTy + SingleR _ -> MutCursorTy SoARv _ flds -> CursorArrayTy (1 + length flds) + let ty2_of_loc :: Ty2 = case loc of + SingleR _ -> MkTy2 MutCursorTy + SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) freeVarToVarEnv' <- do case loc of SingleR l -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv @@ -1417,8 +1458,13 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = SoARv _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" case rhs of -- Discharge bindings that were waiting on 'loc'. - _ -> onDi (mkLets (bnds' ++ [(locs_var,[],ty_of_loc,rhs')] ++ bnds)) <$> - go freeVarToVarEnv' (M.insert locs_var (MkTy2 CursorTy) tenv''') senv' bod + _ -> do + case ty_of_loc of + MutCursorTy -> onDi (mkLets (bnds' ++ [(locs_var,[],ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds)) <$> + go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + _ -> onDi (mkLets (bnds' ++ [(locs_var,[],ty_of_loc,rhs')] ++ bnds)) <$> + go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + Left denv' -> onDi (mkLets bnds) <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod -- case reg_var of @@ -1702,7 +1748,8 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = in if isBound reg_var tenv then Right (rhs, [], tenv, senv) -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) - else Left$ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name,[],CursorTy,rhs)] denv + -- VS: Hack: We always want to get a reference to the region. + else Left$ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name,[],MutCursorTy,rhs)] denv GetFieldRegSoA i loc -> {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let loc_from_locarg = toLocVar loc @@ -1724,7 +1771,7 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx) {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -} in if isBound loc_var tenv then Right (rhs, [], tenv, senv) - else Left$ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name,[],CursorTy,rhs)] denv + else Left$ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name,[],MutCursorTy,rhs)] denv diff --git a/gibbon-compiler/src/Gibbon/Passes/Lower.hs b/gibbon-compiler/src/Gibbon/Passes/Lower.hs index 92071757a..fb25050a0 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Lower.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Lower.hs @@ -29,6 +29,7 @@ import Gibbon.DynFlags import Gibbon.L3.Syntax import qualified Gibbon.L3.Syntax as L3 import qualified Gibbon.L4.Syntax as T +import Language.Haskell.Exts.Build (sym) -- Generating unpack functions from Packed->Pointer representation: ------------------------------------------------------------------------------- @@ -528,6 +529,8 @@ lower Prog{fundefs,ddefs,mainExp} = do MakeCursorArray len vars -> syms IndexCursorArray var idx -> syms CastPtr var ty -> syms + AddrOfCursor rhs -> go rhs + DerefMutCursor{} -> syms _ -> error $ "Unexpected Ext: " ++ sdoc ex MapE{} -> syms FoldE{} -> syms @@ -764,6 +767,16 @@ lower Prog{fundefs,ddefs,mainExp} = do , triv sym_tbl "index_into_base_pointer" (LitE idx)] <$> tail free_reg sym_tbl bod + LetE (v, _, _, (Ext (AddrOfCursor i@(Ext (IndexCursorArray cur idx))))) bod -> do + --i' <- tail free_reg sym_tbl i + T.LetPrimCallT [(v, T.MutCursorTy)] T.AddrOfCursor [triv sym_tbl "addofexpr" i ] <$> + tail free_reg sym_tbl bod + + LetE (v, _, _, (Ext (DerefMutCursor cur))) bod -> + T.LetPrimCallT [(v, T.CursorTy)] T.DerefMutCursor [triv sym_tbl "deref address" (VarE cur)] <$> + tail free_reg sym_tbl bod + + LetE (v, _, _, (Ext (CastPtr cur ty))) bod -> T.LetPrimCallT [(v, T.fromL3Ty ty)] T.CastPtr [triv sym_tbl "cast pointer" (VarE cur)] <$> tail free_reg sym_tbl bod @@ -856,10 +869,11 @@ lower Prog{fundefs,ddefs,mainExp} = do T.LetPrimCallT [] T.BoundsCheck args <$> tail free_reg sym_tbl bod LetE(_,_,_, (Ext (BoundsCheckVector bounds))) bod -> do - let args = map (\(i, bound, cur) -> + let args = map (\(i, bound, cur, (b', c')) -> T.ProdTriv [ T.IntTriv (fromIntegral i) , T.VarTriv bound , T.VarTriv cur + , T.ProdTriv [T.VarTriv b', T.VarTriv c'] ] ) bounds T.LetPrimCallT [] T.BoundsCheckVector args <$> tail free_reg sym_tbl bod @@ -1096,6 +1110,7 @@ triv sym_tbl msg ( e0) = (MkProdE []) -> T.IntTriv 0 (MkProdE ls) -> T.ProdTriv (map (\x -> triv sym_tbl (show x) x) ls) (ProjE ix e) -> T.ProjTriv ix (triv sym_tbl "proje argument" e) + (Ext (IndexCursorArray cur idx)) -> T.IndexCursorArrayTriv idx (triv sym_tbl "index_into" (VarE cur)) _ | isTrivial e0 -> error $ "lower/triv: this function is written wrong. "++ "It won't handle the following, which satisfies 'isTriv':\n "++sdoc e0++ "\nMessage: "++msg diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index 1444b19da..1c18e7e45 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -226,7 +226,8 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod -- in [("_",[],MkTy2 IntTy, Ext $ BoundsCheck (size_of_ty) (NewL2.EndOfReg freg mode (toEndVRegVar freg)) (NewL2.Loc (LREM floc freg (toEndVRegVar freg) mode)))] -- -- ) $ zip fieldLocs' fieldRegs' - boundsCheckDcon = [(1, dcRegArg, dcLocArg)] + -- VS: 1 byte for constructor, 1 byte for redirection, 8 bytes for pointer + 2 to be safe + boundsCheckDcon = [(12, dcRegArg, dcLocArg)] boundsCheckFields = concatMap ( \(((dcon, idx), floc), freg) -> @@ -235,7 +236,9 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod PackedTy {} -> [] _ -> let size_of_ty = fromJust $ sizeOfTy (unTy2 ty) - in [(size_of_ty, (NewL2.EndOfReg freg mode (toEndVRegVar freg)), (NewL2.Loc (LREM floc freg (toEndVRegVar freg) mode)))] + -- VS: 1 byte for redirection, 8 for redirection pointer + 2 to be safe + -- Some large offset to be safe + in [(2 * (size_of_ty + 11), (NewL2.EndOfReg freg mode (toEndVRegVar freg)), (NewL2.Loc (LREM floc freg (toEndVRegVar freg) mode)))] ) $ zip fieldLocs' fieldRegs' boundsCheckVector = [("_", [], MkTy2 IntTy, Ext $ BoundsCheckVector (boundsCheckDcon ++ boundsCheckFields))] diff --git a/gibbon-compiler/src/Gibbon/Pretty.hs b/gibbon-compiler/src/Gibbon/Pretty.hs index 7f51a7497..acaf1476f 100644 --- a/gibbon-compiler/src/Gibbon/Pretty.hs +++ b/gibbon-compiler/src/Gibbon/Pretty.hs @@ -301,6 +301,7 @@ instance (Pretty l) => Pretty (UrTy l) where PtrTy -> text "Ptr" CursorTy -> text "Cursor" CursorArrayTy size -> text "CursorArray[" <> int size <> text "]" + MutCursorTy -> text "MutCursor" ArenaTy -> case sty of PPHaskell -> text "()" PPInternal -> text "Arena" From 006e8d47e2510c1cb0398aa4f1c4eac23a1fd3dd Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 14 Sep 2025 00:12:11 -0400 Subject: [PATCH 03/60] add all possible correct answers --- gibbon-compiler/examples/simple_tests/list.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gibbon-compiler/examples/simple_tests/list.hs b/gibbon-compiler/examples/simple_tests/list.hs index a81424c87..60fa88f8d 100644 --- a/gibbon-compiler/examples/simple_tests/list.hs +++ b/gibbon-compiler/examples/simple_tests/list.hs @@ -35,11 +35,11 @@ sumList lst = case lst of gibbon_main = let lst = mkList 20000 - --lst' = iterate (add1 lst) - _ = printPacked lst + lst' = iterate (add1 lst) + _ = printPacked lst' _ = printsym (quote "NEWLINE") --(val, lst'') = fieldDep lst' - in sumList lst --() --printPacked lst' --val --sumList lst' + in sumList lst' --() --printPacked lst' --val --sumList lst' From d9a25a4882e246952358dce77c17b23cb9167e25 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 14 Sep 2025 14:07:51 -0400 Subject: [PATCH 04/60] save --- gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index 37e13b536..b20527eb5 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -59,6 +59,14 @@ followPtrs (Prog ddefs fundefs mainExp) = do [] funArgs let in_locs = foldr (\loc acc -> if loc == scrt_loc then ((indir_ptrloc) : acc) else (loc : acc)) [] (inLocVars funTy) let out_locs = outLocVars funTy + -- [VS: 09/14/2025] + -- In case an output location, that's passed to the function call. + -- for an SoA location, we cannot simply pass this directly. + -- Since we do this by value, we need to update the SoA location, + -- because bounds checking may have updated the value of the location. + -- Note that we only need to update the non packed locations + the data constructor buffer. + -- Other packed types will be updated by the function that traverses it. + let redir_dcon = fst $ fromJust $ L.find (isRedirectionTag . fst) dataCons let redir_bod = (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->r ")]) else id) $ LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ From 8bc6eab0df970e3c0a1b9708821b8ebc3cdf7eff Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 14 Sep 2025 16:19:07 -0400 Subject: [PATCH 05/60] Make sure output locations are re-written to in redirection case --- gibbon-compiler/examples/simple_tests/tree.hs | 4 +- .../src/Gibbon/Passes/Cursorize.hs | 2 +- .../src/Gibbon/Passes/FollowPtrs.hs | 39 +++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/gibbon-compiler/examples/simple_tests/tree.hs b/gibbon-compiler/examples/simple_tests/tree.hs index 2167cdab3..715628676 100644 --- a/gibbon-compiler/examples/simple_tests/tree.hs +++ b/gibbon-compiler/examples/simple_tests/tree.hs @@ -30,7 +30,7 @@ sumTree tr = gibbon_main = let tree = mkTree 10 - -- _ = printPacked tree + --_ = printPacked tree tree' = add1Tree tree --_ = printPacked tree' val = sumTree tree' @@ -40,4 +40,4 @@ gibbon_main = rmost = rightmost tree' _ = printint rmost _ = printsym (quote ")\n\n") - in sumTree tree' + in () --sumTree tree diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 4774ee5f8..5a831aa3f 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -2707,7 +2707,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))] --generate binds for all fields. - binds_flields = L.foldr (\((_, idx), var) (index, res) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon + binds_flields = L.foldl (\(index, res) ((_, idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor (vars_next_fields !! index)) else error $ "unpackRegularDataCon: cursorty without indirection/redirection." tmpf = tmp_flds !! index diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index b20527eb5..cbcdfdfe0 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -5,13 +5,14 @@ module Gibbon.Passes.FollowPtrs import qualified Data.Map as M -- import qualified Data.Set as S import qualified Data.List as L --- import Data.Foldable ( foldrM ) +import Data.Foldable ( foldrM ) import Data.Maybe ( fromJust ) import Gibbon.Common import Gibbon.Language import Gibbon.L2.Syntax as L2 import Gibbon.DynFlags +import Gibbon.L3.Syntax (E3Ext(AddCursor)) -------------------------------------------------------------------------------- @@ -66,12 +67,44 @@ followPtrs (Prog ddefs fundefs mainExp) = do -- because bounds checking may have updated the value of the location. -- Note that we only need to update the non packed locations + the data constructor buffer. -- Other packed types will be updated by the function that traverses it. + (new_out_locs, new_loc_bnds) <- foldrM (\locvar (nl, bnds) -> case locvar of + SoA dloc flocs -> do + -- unpack all locations in the SoA location. + let unpack_dcon = LetLocE (singleLocVar dloc) (GetDataConLocSoA locvar) + let unpack_flds = map (\((dcon, idx), floc) -> do + let flet = LetLocE floc (GetFieldLocSoA (dcon, idx) locvar) + in flet + ) flocs + -- make a new name for this loc_var + new_locvar <- freshCommonLoc "copy" locvar + let new_don_loc = getDconLoc new_locvar + -- The data con loc should be unpacked and updated by bounds check. + -- from design of the compiler + let new_don_let = LetLocE new_don_loc (AfterConstantLE 0 (singleLocVar dloc)) + let new_fld_locs = getAllFieldLocsSoA new_locvar + new_fld_lets <- foldrM (\((dcon, idx), nfloc) flts -> do + let ty = (lookupDataCon ddefs dcon) !! idx + in case (ty) of + PackedTy{} -> do + let let_for_fld = LetLocE nfloc (GetFieldLocSoA (dcon, idx) locvar) + in pure $ flts ++ [let_for_fld] + _ -> do + let let_for_fld = LetLocE nfloc (AfterConstantLE 0 (getFieldLoc (dcon, idx) locvar)) + in pure $ flts ++ [let_for_fld] + ) [] new_fld_locs + let new_soa_loc_let = LetLocE new_locvar (GenSoALoc new_don_loc new_fld_locs) + return $ (nl ++ [new_locvar], bnds ++ [unpack_dcon] ++ unpack_flds ++ [new_don_let] ++ new_fld_lets ++ [new_soa_loc_let]) + + -- no need to update single location variables + Single{} -> return $ (nl ++ [locvar], bnds) + ) ([], []) out_locs let redir_dcon = fst $ fromJust $ L.find (isRedirectionTag . fst) dataCons let redir_bod = (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->r ")]) else id) $ - LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ + LetE (callv,endofs,out_ty,AppE funName (in_locs ++ new_out_locs) args) $ Ext (RetE endofs callv) - let redir_br = (redir_dcon,[(indir_ptrv,(indir_ptrloc))],redir_bod) + let redir_bod' = foldr (\bnd bod -> Ext $ bnd bod) redir_bod new_loc_bnds + let redir_br = (redir_dcon,[(indir_ptrv,(indir_ptrloc))],redir_bod') ---------------------------------------- (pure (CaseE scrt (brs ++ [redir_br]))) else do From 1f39a216dfb4f747257ebaf3444c348695474345 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 14 Sep 2025 17:09:36 -0400 Subject: [PATCH 06/60] add region to type env --- .../src/Gibbon/Passes/Cursorize.hs | 66 ++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 5a831aa3f..2faca5d3d 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -745,7 +745,37 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Exactly same as cursorizePackedExp LetRegionE reg sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False reg sz - mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv bod + let reg_var = regionToVar reg + let reg_ty = case reg_var of + SingleR{} -> MkTy2 CursorTy + SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) + + reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return v + SoARv{} -> do + n <- gensym "region_cursor_ptr" + return n + + -- For end of the region + reg_var_name_end <- case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return $ toEndV v + SoARv{} -> do + n <- gensym "region_cursor_ptr_end" + return n + + let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_var) reg_var_name freeVarToVarEnv' + let freeVarToVarEnv''' = M.insert (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) reg_var_name_end freeVarToVarEnv'' + + + let tenv' = M.insert reg_var_name reg_ty tenv + let tenv'' = M.insert reg_var_name_end reg_ty tenv' + mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv''' lenv ddfs fundefs denv tenv'' senv bod LetParRegionE reg sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv True reg sz @@ -768,7 +798,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = dereference_bound_var <- gensym "deref" let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] pure (bnd, dereference_bound_var) - Nothing -> error "expected variable to have type!" + Nothing -> error $ "expected variable to have type!: " ++ show bound_var _ -> pure ([], bound_var) let cur_loc = toLocVar cur let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of @@ -1501,7 +1531,37 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False r sz - onDi (mkLets (region_lets)) <$> go freeVarToVarEnv' tenv senv bod + let reg_var = regionToVar r + let reg_ty = case reg_var of + SingleR{} -> MkTy2 CursorTy + SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) + + reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return v + SoARv{} -> do + n <- gensym "region_cursor_ptr" + return n + + -- For end of the region + reg_var_name_end <- case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return $ toEndV v + SoARv{} -> do + n <- gensym "region_cursor_ptr_end" + return n + + let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_var) reg_var_name freeVarToVarEnv' + let freeVarToVarEnv''' = M.insert (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) reg_var_name_end freeVarToVarEnv'' + + + let tenv' = M.insert reg_var_name reg_ty tenv + let tenv'' = M.insert reg_var_name_end reg_ty tenv' + onDi (mkLets (region_lets)) <$> go freeVarToVarEnv''' tenv'' senv bod LetParRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv True r sz From dbaecd4686dbf2cdb41a0982beb119ed3dd32f98 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 14 Sep 2025 23:12:58 -0400 Subject: [PATCH 07/60] edit error message --- gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index ced2779dc..103a15c9b 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -77,7 +77,7 @@ addCastsExp fundef cenv env ex = let cast_ins = Ext $ CastPtr var cursory_ty3 let cast_inst = [LetE (casted_var, [], CursorTy, cast_ins)] pure (insts ++ cast_inst, nfcenv, nfenv, nvars ++ [casted_var]) - _ -> error "Unexpected type!" + _ -> error $ "Unexpected type!" ++ show ex ) ([], cenv, new_env, []) vars From e1e569b1996adaf71d618293f201b9763dab3669 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 15 Sep 2025 22:01:47 -0400 Subject: [PATCH 08/60] fix dereferencing mutable cursor, add nested soa examples, add colobus with redirections to test suite --- .../examples/simple_tests/packedBuggyTree.hs | 92 ---------------- .../soa_examples/.list.aos.c.kate-swp | Bin 0 -> 106 bytes .../examples/soa_examples/MonoTree.hs | 29 ++++++ .../{simple_tests => soa_examples}/list.hs | 9 +- .../packedBinaryTree.hs | 2 +- .../packedList.hs | 6 +- .../packedTree.hs | 0 .../examples/soa_examples/test_list.ans | 1 + .../soa_examples/test_packed_list.ans | 1 + .../soa_examples/test_packed_tree.ans | 1 + .../examples/soa_examples/test_tree.ans | 3 + .../{simple_tests => soa_examples}/tree.hs | 10 +- .../src/Gibbon/Passes/AddCastInstructions.hs | 4 + .../src/Gibbon/Passes/Cursorize.hs | 26 +++-- gibbon-compiler/tests/BenchRunner.hs | 2 +- gibbon-compiler/tests/TestRunner.hs | 14 ++- .../tests/test-gibbon-examples.yaml | 98 +++++++++++------- 17 files changed, 137 insertions(+), 161 deletions(-) delete mode 100644 gibbon-compiler/examples/simple_tests/packedBuggyTree.hs create mode 100644 gibbon-compiler/examples/soa_examples/.list.aos.c.kate-swp create mode 100644 gibbon-compiler/examples/soa_examples/MonoTree.hs rename gibbon-compiler/examples/{simple_tests => soa_examples}/list.hs (75%) rename gibbon-compiler/examples/{simple_tests => soa_examples}/packedBinaryTree.hs (98%) rename gibbon-compiler/examples/{simple_tests => soa_examples}/packedList.hs (87%) rename gibbon-compiler/examples/{simple_tests => soa_examples}/packedTree.hs (100%) create mode 100644 gibbon-compiler/examples/soa_examples/test_list.ans create mode 100644 gibbon-compiler/examples/soa_examples/test_packed_list.ans create mode 100644 gibbon-compiler/examples/soa_examples/test_packed_tree.ans create mode 100644 gibbon-compiler/examples/soa_examples/test_tree.ans rename gibbon-compiler/examples/{simple_tests => soa_examples}/tree.hs (84%) diff --git a/gibbon-compiler/examples/simple_tests/packedBuggyTree.hs b/gibbon-compiler/examples/simple_tests/packedBuggyTree.hs deleted file mode 100644 index 58d40c4ea..000000000 --- a/gibbon-compiler/examples/simple_tests/packedBuggyTree.hs +++ /dev/null @@ -1,92 +0,0 @@ -data List = Cons Int List | Nil -data FloatList = FCons Float FloatList | FNil -data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf - - -mkList :: Int -> List -mkList len = if len <= 0 - then Nil - else Cons len (mkList (len - 1)) - -mkFloatList :: Int -> FloatList -mkFloatList len = if len <= 0 - then FNil - else FCons (intToFloat len) (mkFloatList (len - 1)) - -mkTree :: Int -> Tree -mkTree d = if (d <= 0) - then Leaf - else Node d 1.0 (mkFloatList d) (mkList d) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) - -add1List :: List -> List -add1List lst = case lst of - Nil -> Nil - Cons x rst -> Cons (x+1) (add1List rst) - -add1FloatList :: FloatList -> FloatList -add1FloatList lst = case lst of - FNil -> FNil - FCons y rst -> FCons (y .+. 1.0) (add1FloatList rst) - -add1Tree :: Tree -> Tree -add1Tree tree = case tree of - Leaf -> Leaf - Node x y flst lst l r rr -> Node (x+1) (y .+. 2.0) (add1FloatList flst) (add1List lst) (add1Tree l) (add1Tree r) (add1Tree rr) - - -intToFloat :: Int -> Float -intToFloat val = if (val == 1) - then 1.0 - else if (val == 2) - then 2.0 - else if (val == 3) - then 3.0 - else if (val == 4) - then 4.0 - else if (val == 5) - then 5.0 - else if (val == 6) - then 6.0 - else if (val == 7) - then 7.0 - else if (val == 8) - then 8.0 - else if (val == 9) - then 9.0 - else 10.0 - --- VS: Things break if i use a function that does not traverse the packed type. TODO: Fix this -sumTree :: Tree -> Int -sumTree tree = case tree of - Leaf -> 0 - Node x y l1 l2 l r rr -> x + (floatToInt y) + (getIntConstantFromFloatList l1) + (sumIntList l2) + (sumTree l) + (sumTree r) + (sumTree rr) - - -floatToInt :: Float -> Int -floatToInt x = 10 - -sumIntList :: List -> Int -sumIntList lst = case lst of - Nil -> 0 - Cons x rst -> x + (sumIntList rst) - -getIntConstantFromFloatList :: FloatList -> Int -getIntConstantFromFloatList lst = 10 - --- VS: If this becomes a function that does not traverse the list, The compiler fails. --- TODO: If some fields are not traverse, we don't really need to generate traversal functions for those fields. --- This will require an update of the pass that handles generating traversals for unsed fields. -sumFloatList :: FloatList -> Int -sumFloatList lst = lengthFloatList lst - - -lengthFloatList :: FloatList -> Int -lengthFloatList lst = case lst of - FNil -> 0 - FCons x rst -> 1 + (lengthFloatList rst) - -gibbon_main = - let tree = mkTree 5 - tree' = add1Tree tree - in sumTree tree' - diff --git a/gibbon-compiler/examples/soa_examples/.list.aos.c.kate-swp b/gibbon-compiler/examples/soa_examples/.list.aos.c.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..230684583a164ce05741a94f7d461a7bfa7c9060 GIT binary patch literal 106 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?VnsrThDeH7MrqC>Ln#L8Tr&h$1;{l Tree +mkTree d = + if d == 0 + then Leaf 1 + else Node d (mkTree (d-1)) (mkTree (d-1)) + +add1Tree :: Tree -> Tree +add1Tree t = + case t of + Leaf x -> Leaf (x + 1) + Node d x1 x2 -> Node (d + 1) (add1Tree x1) (add1Tree x2) + +sumTree :: Tree -> Int +sumTree tr = + case tr of + Leaf n -> n + Node d l r -> d + (sumTree l) + (sumTree r) + +gibbon_main = sumTree (mkTree 18) --sumTree (add1Tree (mkTree 18)) + +main :: IO () +main = print gibbon_main diff --git a/gibbon-compiler/examples/simple_tests/list.hs b/gibbon-compiler/examples/soa_examples/list.hs similarity index 75% rename from gibbon-compiler/examples/simple_tests/list.hs rename to gibbon-compiler/examples/soa_examples/list.hs index 60fa88f8d..92a1b1ac3 100644 --- a/gibbon-compiler/examples/simple_tests/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -34,12 +34,9 @@ sumList lst = case lst of in i + sumRst gibbon_main = let - lst = mkList 20000 - lst' = iterate (add1 lst) - _ = printPacked lst' - _ = printsym (quote "NEWLINE") - --(val, lst'') = fieldDep lst' - in sumList lst' --() --printPacked lst' --val --sumList lst' + lst = mkList 100 + lst' = add1 lst + in sumList lst' diff --git a/gibbon-compiler/examples/simple_tests/packedBinaryTree.hs b/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs similarity index 98% rename from gibbon-compiler/examples/simple_tests/packedBinaryTree.hs rename to gibbon-compiler/examples/soa_examples/packedBinaryTree.hs index b0d3d4b69..f0080a5ff 100644 --- a/gibbon-compiler/examples/simple_tests/packedBinaryTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs @@ -70,7 +70,7 @@ sumFloatList :: FloatList -> Int sumFloatList lst = 10 gibbon_main = - let tree = mkTree 5 + let tree = mkTree 12 tree' = add1Tree tree in sumTree tree' diff --git a/gibbon-compiler/examples/simple_tests/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs similarity index 87% rename from gibbon-compiler/examples/simple_tests/packedList.hs rename to gibbon-compiler/examples/soa_examples/packedList.hs index 36519f842..4ad55dadb 100644 --- a/gibbon-compiler/examples/simple_tests/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -42,11 +42,9 @@ sumList lst = case lst of gibbon_main = let pi = mkPackedInt 10 - lst = mkList 10 + lst = mkList 100 lst' = add1 lst - -- _ = printPacked lst' - --(val, lst'') = fieldDep lst' - in (sumList lst') --printPacked lst' --val --sumList lst' + in (sumList lst') diff --git a/gibbon-compiler/examples/simple_tests/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs similarity index 100% rename from gibbon-compiler/examples/simple_tests/packedTree.hs rename to gibbon-compiler/examples/soa_examples/packedTree.hs diff --git a/gibbon-compiler/examples/soa_examples/test_list.ans b/gibbon-compiler/examples/soa_examples/test_list.ans new file mode 100644 index 000000000..03753f4e0 --- /dev/null +++ b/gibbon-compiler/examples/soa_examples/test_list.ans @@ -0,0 +1 @@ +5150 diff --git a/gibbon-compiler/examples/soa_examples/test_packed_list.ans b/gibbon-compiler/examples/soa_examples/test_packed_list.ans new file mode 100644 index 000000000..18e1a4057 --- /dev/null +++ b/gibbon-compiler/examples/soa_examples/test_packed_list.ans @@ -0,0 +1 @@ +10300 diff --git a/gibbon-compiler/examples/soa_examples/test_packed_tree.ans b/gibbon-compiler/examples/soa_examples/test_packed_tree.ans new file mode 100644 index 000000000..048efdb52 --- /dev/null +++ b/gibbon-compiler/examples/soa_examples/test_packed_tree.ans @@ -0,0 +1 @@ +919 diff --git a/gibbon-compiler/examples/soa_examples/test_tree.ans b/gibbon-compiler/examples/soa_examples/test_tree.ans new file mode 100644 index 000000000..aab9f6ad5 --- /dev/null +++ b/gibbon-compiler/examples/soa_examples/test_tree.ans @@ -0,0 +1,3 @@ +(sum: 54604, rightmost: 1) + +'#() diff --git a/gibbon-compiler/examples/simple_tests/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs similarity index 84% rename from gibbon-compiler/examples/simple_tests/tree.hs rename to gibbon-compiler/examples/soa_examples/tree.hs index 715628676..8f0e55479 100644 --- a/gibbon-compiler/examples/simple_tests/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -29,15 +29,13 @@ sumTree tr = Node i j k _ l r ll rr -> i + j + k + (sumTree l) + (sumTree r) + (sumTree ll) + (sumTree rr) gibbon_main = - let tree = mkTree 10 - --_ = printPacked tree - tree' = add1Tree tree - --_ = printPacked tree' + let tree = mkTree 7 + tree' = add1Tree tree val = sumTree tree' - _ = printsym (quote "\n\n(sum: ") + _ = printsym (quote "(sum: ") _ = printint val _ = printsym (quote ", rightmost: ") rmost = rightmost tree' _ = printint rmost _ = printsym (quote ")\n\n") - in () --sumTree tree + in () diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index 103a15c9b..0062c2296 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -77,6 +77,10 @@ addCastsExp fundef cenv env ex = let cast_ins = Ext $ CastPtr var cursory_ty3 let cast_inst = [LetE (casted_var, [], CursorTy, cast_ins)] pure (insts ++ cast_inst, nfcenv, nfenv, nvars ++ [casted_var]) + MutCursorTy -> do + name_for_deref <- gensym "deref" + let derefMuteCursor = LetE (name_for_deref, [], CursorTy, Ext $ DerefMutCursor var) + pure (insts ++ [derefMuteCursor], fcenv, fenv, nvars ++ [name_for_deref]) _ -> error $ "Unexpected type!" ++ show ex ) ([], cenv, new_env, []) diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 2faca5d3d..62cfd81fb 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -2767,18 +2767,24 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))] --generate binds for all fields. - binds_flields = L.foldl (\(index, res) ((_, idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon + binds_flields = L.foldl (\(index, res) ((dcon', idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor (vars_next_fields !! index)) else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - tmpf = tmp_flds !! index - new_binds = [(vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - --((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index) , [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy , ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))] - in (index + 1, res ++ new_binds) + tmpf = tmp_flds !! index + ty_of_field = (lookupDataCon ddfs dcon') !! idx + in case ty_of_field of + (MkTy2 PackedTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + (MkTy2 CursorArrayTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + _ -> let new_binds = [(vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + --((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index) , [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy , ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))] + in (index + 1, res ++ new_binds) ) (0, []) _field_cur soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] diff --git a/gibbon-compiler/tests/BenchRunner.hs b/gibbon-compiler/tests/BenchRunner.hs index d99f54292..9d853e83e 100644 --- a/gibbon-compiler/tests/BenchRunner.hs +++ b/gibbon-compiler/tests/BenchRunner.hs @@ -76,7 +76,7 @@ bench_main :: TestConfig -> Tests -> IO () bench_main tc (Tests tests) = do putStrLn "Executing BenchRunner...\n" let benchmarks = filter (not . skip) $ filter isBenchmark tests - modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus] -- Omit MPL for now + modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus1, Colobus2] -- Omit MPL for now results <- mapM (go modesToBench) benchmarks mc <- getHostname let csvs = map (\arg -> intercalate "," (mc:arg)) (concat results) diff --git a/gibbon-compiler/tests/TestRunner.hs b/gibbon-compiler/tests/TestRunner.hs index 66607cfad..a19894ee3 100644 --- a/gibbon-compiler/tests/TestRunner.hs +++ b/gibbon-compiler/tests/TestRunner.hs @@ -161,7 +161,7 @@ data Result = Pass | Fail -- Not used atm. -- | Gibbon mode to run programs in -data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus +data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus1 | Colobus2 deriving (Show, Eq, Read, Ord, Bounded, Enum) instance FromJSON Mode where @@ -179,13 +179,15 @@ readMode s = "pointer" -> Pointer "interp1" -> Interp1 "gibbon1" -> Gibbon1 - "colobus" -> Colobus + "colobus1" -> Colobus1 + "colobus2" -> Colobus2 "mpl" -> MPL _ -> error $ "readMode: " ++ show s -- Must match the flag expected by Gibbon. modeRunFlags :: Mode -> [String] -modeRunFlags Colobus = ["--run", "--packed", "--gibbon1", "--SoA"] +modeRunFlags Colobus1 = ["--run", "--packed", "--gibbon1", "--SoA"] +modeRunFlags Colobus2 = ["--run", "--packed", "--no-rcopies", "--no-ran", "--SoA"] modeRunFlags Gibbon3 = ["--run", "--packed", "--gen-gc"] modeRunFlags Gibbon2 = ["--run", "--packed"] modeRunFlags Pointer = ["--run", "--pointer"] @@ -195,7 +197,8 @@ modeRunFlags MPL = ["--mpl-run"] -- Must match the flag expected by Gibbon. modeExeFlags :: Mode -> [String] -modeExeFlags Colobus = ["--to-exe", "--packed", "--gibbon1", "--SoA"] +modeExeFlags Colobus1 = ["--to-exe", "--packed", "--gibbon1", "--SoA"] +modeExeFlags Colobus2 = ["--to-exe", "--packed", "--no-rcopies", "--no-ran", "--SoA"] modeExeFlags Gibbon3 = ["--to-exe", "--packed", "--gen-gc"] modeExeFlags Gibbon2 = ["--to-exe", "--packed"] modeExeFlags Pointer = ["--to-exe", "--pointer"] @@ -204,7 +207,8 @@ modeExeFlags Gibbon1 = ["--to-exe", "--packed", "--gibbon1"] modeExeFlags MPL = ["--mpl-exe"] modeFileSuffix :: Mode -> String -modeFileSuffix Colobus = "_colobus" +modeFileSuffix Colobus1 = "_colobus1" +modeFileSuffix Colobus2 = "_colobus2" modeFileSuffix Gibbon3 = "_gibbon3" modeFileSuffix Gibbon2 = "_gibbon2" modeFileSuffix Pointer = "_ptr" diff --git a/gibbon-compiler/tests/test-gibbon-examples.yaml b/gibbon-compiler/tests/test-gibbon-examples.yaml index ac93c77ba..32610395e 100644 --- a/gibbon-compiler/tests/test-gibbon-examples.yaml +++ b/gibbon-compiler/tests/test-gibbon-examples.yaml @@ -71,15 +71,15 @@ tests: - name: test11f_funrec.gib - name: test11_fundata.gib - name: test12b_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] - name: test12c_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] - name: test13b_build.gib - name: test13_build.gib - name: Test185.hs answer-file: examples/Test185.ans # Scalar fields after packed not allowed - failing: [gibbon1,gibbon2,gibbon3, colobus] + failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2] - name: SS.hs dir: examples/gc answer-file: examples/gc/SS.ans @@ -137,11 +137,11 @@ tests: - name: test29b_list.gib - name: test30_twitter.gib # ThreadRegions bug. - failing: [colobus] + failing: [colobus1, colobus2] - name: test_buildstree.gib - name: test_buildtree.gib - name: test_buildtreesum.gib - failing: [colobus] + failing: [colobus1, colobus2] - name: test_ddtree.gib - name: test_stree.gib - name: test_sumstree.gib @@ -258,7 +258,7 @@ tests: - name: Poly1.hs dir: examples/poly answer-file: examples/poly/Poly1.ans - failing: [gibbon1, gibbon2, gibbon3, interp1,colobus] + failing: [gibbon1, gibbon2, gibbon3, interp1,colobus1, colobus2] # - name: measure_mode.hs # answer-file: examples/measure_mode.ans @@ -288,7 +288,7 @@ tests: dir: examples/poly answer-file: examples/poly/CurriedFns.ans skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] - name: T127.hs dir: examples/poly @@ -308,19 +308,19 @@ tests: - name: unariser_bug1.hs answer-file: examples/unariser_bug1.ans - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] skip: true - name: ParseLinearTypes.hs test-flags: ["--ghc-tc"] dir: examples/lineartypes/ - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] - name: EqBench.hs answer-file: examples/EqBench.ans - name: test_parse.hs - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] - name: toplevel_value.hs answer-file: examples/toplevel_value.ans @@ -357,7 +357,7 @@ tests: dir: examples answer-file: examples/test_printpacked.ans # gibbon3 and gibbon2: Inferlocations bug. - failing: [interp1,gibbon1,pointer, colobus] + failing: [interp1,gibbon1,pointer, colobus1, colobus2] ## FAILING: Multiple packed outputs. - name: TupleTest.hs @@ -371,7 +371,7 @@ tests: ## FAILING: Scalar field after a packed field. - name: test12_skip.gib - failing: [gibbon1, colobus] + failing: [gibbon1, colobus1, colobus2] skip: true - name: test12b_traverse.gib skip: true @@ -401,7 +401,7 @@ tests: skip: true - name: test29d_list.gib skip: true - failing: [gibbon1, colobus] + failing: [gibbon1, colobus1, colobus2] - name: test_unpacking.gib skip: true @@ -409,46 +409,46 @@ tests: ## Shouldn't typecheck - name: Fail1.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] - name: Fail2.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] - name: Fail3.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] ## Fusion2 tests - name: test_sumup_seteven.gib skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] test-flags: ["--fusion"] - name: render_tree.hs dir: examples/fusion-benchmarks skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree.ans - name: render_tree_two_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_two_passes.ans - name: render_tree_four_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_four_passes.ans - name: render_tree_five_passes.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, pointer, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, colobus1, colobus2] ## [2020.05.27]: It never finishes on Travis... skip: true test-flags: ["--fusion"] @@ -456,7 +456,7 @@ tests: - name: LC.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] test-flags: ["--fusion"] skip: true # gibbon2: segfaults in free_region @@ -494,29 +494,29 @@ tests: ## AST benchmarks - name: C1.hs dir: examples/ast - failing: [gibbon1, gibbon2, colobus] + failing: [gibbon1, gibbon2, colobus1, colobus2] answer-file: examples/ast/C1.ans skip: true ## Tests that only work with some backend: - name: test18f_flip.gib - failing: [gibbon1, gibbon2, gibbon3, colobus] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] - name: pp_projs.gib skip: true - name: test12_skip.gib - failing: [gibbon1, colobus] + failing: [gibbon1, colobus1, colobus2] skip: true # Tests that actually work but we can't generate answers with Racket - name: test08_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] - name: test08b_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] - name: test08c_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] - name: test08d_sharedict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] # - name: test08f_dict.gib # - name: test08f2_dict.gib @@ -524,13 +524,13 @@ tests: # This test depends on real symbols, which we don't support atm. - name: test27b_subst.gib - failing: [gibbon1,gibbon2,gibbon3, colobus] + failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2] skip: true # printing symbols is broken atm # No gensym, or real symbols. - name: test28_copyprop.gib - failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus] + failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus1, colobus2] # sym-append not implemented in the RTS - name: test15b_symappend.gib @@ -555,15 +555,15 @@ tests: failing: [interp1] - name: test_153.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2] answer-file: examples/test_153.ans - name: test_164.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2] answer-file: examples/test_164.ans - name: test_166.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2] answer-file: examples/test_166.ans - name: test_167.hs @@ -580,12 +580,38 @@ tests: - name: test_power.hs answer-file: examples/test_power.ans # gib_alloc_region_on_heap: gib_alloc failed - failing: [gibbon1, colobus] + failing: [gibbon1, colobus1, colobus2] # Vidush: unskip this, thing hangs because of all the debug print statements skip: true - name: test_191.hs answer-file: examples/test_191.ans # Gibbon2 and Gibbon3 modes don't pass the L2 typechecker. - failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus] + failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus1, colobus2] run-modes: ["gibbon2"] + + #simple SoA benchmarks + - name: list.hs + dir: examples/soa_examples + failing: [] + answer-file: examples/soa_examples/test_list.ans + + - name: tree.hs + dir: examples/soa_examples + failing: ["gibbon2", "gibbon3", "interp1"] + answer-file: examples/soa_examples/test_tree.ans + + - name: packedList.hs + dir: examples/soa_examples + failing: [] + answer-file: examples/soa_examples/test_packed_list.ans + + - name: packedTree.hs + dir: examples/soa_examples + failing: [] + answer-file: examples/soa_examples/test_packed_tree.ans + + + + + From f410dc6d38777d66ad726e3ee20af879b871bb0f Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 15 Sep 2025 22:05:42 -0400 Subject: [PATCH 09/60] remove swp file --- .../examples/soa_examples/.list.aos.c.kate-swp | Bin 106 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 gibbon-compiler/examples/soa_examples/.list.aos.c.kate-swp diff --git a/gibbon-compiler/examples/soa_examples/.list.aos.c.kate-swp b/gibbon-compiler/examples/soa_examples/.list.aos.c.kate-swp deleted file mode 100644 index 230684583a164ce05741a94f7d461a7bfa7c9060..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 106 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?VnsrThDeH7MrqC>Ln#L8Tr&h$1;{l Date: Wed, 10 Sep 2025 21:29:48 -0400 Subject: [PATCH 10/60] Hoist BoundsChecking --- gibbon-compiler/examples/soa_examples/list.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 92a1b1ac3..30b5968a0 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -34,9 +34,18 @@ sumList lst = case lst of in i + sumRst gibbon_main = let +<<<<<<< HEAD:gibbon-compiler/examples/soa_examples/list.hs lst = mkList 100 lst' = add1 lst in sumList lst' +======= + lst = mkList 20000 + --lst' = iterate (add1 lst) + _ = printPacked lst + _ = printsym (quote "NEWLINE") + --(val, lst'') = fieldDep lst' + in sumList lst --() --printPacked lst' --val --sumList lst' +>>>>>>> f352266b (Hoist BoundsChecking):gibbon-compiler/examples/simple_tests/list.hs From e1793a667518e6672c4e9736c58fd4c8925b542b Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Fri, 19 Sep 2025 22:44:08 -0400 Subject: [PATCH 11/60] fix redirections case --- gibbon-compiler/examples/soa_examples/list.hs | 18 +-- .../src/Gibbon/Passes/AddCastInstructions.hs | 40 ++++- .../src/Gibbon/Passes/Cursorize.hs | 143 ++++++++++++------ .../src/Gibbon/Passes/FollowPtrs.hs | 48 ++++-- 4 files changed, 172 insertions(+), 77 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 30b5968a0..68f7e5e52 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -33,19 +33,13 @@ sumList lst = case lst of Cons i rst -> let sumRst = sumList rst in i + sumRst +id :: List -> List +id lst = lst + gibbon_main = let -<<<<<<< HEAD:gibbon-compiler/examples/soa_examples/list.hs - lst = mkList 100 - lst' = add1 lst - in sumList lst' -======= - lst = mkList 20000 - --lst' = iterate (add1 lst) - _ = printPacked lst - _ = printsym (quote "NEWLINE") - --(val, lst'') = fieldDep lst' - in sumList lst --() --printPacked lst' --val --sumList lst' ->>>>>>> f352266b (Hoist BoundsChecking):gibbon-compiler/examples/simple_tests/list.hs + lst = mkList 100 + lst' = id (add1 lst) + in sumList lst' diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index 0062c2296..f1fd035ee 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -1,6 +1,6 @@ module Gibbon.Passes.AddCastInstructions (addCasts) where -import Data.Foldable (foldrM) +import Data.Foldable (foldrM, foldlM) import qualified Data.List as L import qualified Data.Map as M import Gibbon.Common @@ -49,6 +49,24 @@ addCastsExp fundef cenv env ex = bod' <- addCastsExp fundef cenv' env' bod let ex' = foldr (\expr acc -> expr acc) bod' let_expr pure $ ex' + + LetE (v, locs, ty, rhs@(VarE v')) bod -> do + let new_env = extendVEnv v ty env + let tyv' = lookupVEnv v' env + (let_expr, cenv', env') <- case (ty == tyv') of + True -> return $ ([LetE (v, locs, ty, rhs)], cenv, new_env) + False -> do + casted_var <- gensym "cast" + let ncenv = M.insert v' v cenv + let cursory_ty3 :: Ty3 = CursorTy + let nenv = extendVEnv casted_var cursory_ty3 new_env + let cast_ins = Ext $ CastPtr casted_var ty + -- let new_inst = [LetE (v, locs, ty, rhs)] ++ [LetE (casted_var, [], CursorTy, cast_ins)] + let new_inst = [LetE (casted_var, locs, CursorTy, rhs)] ++ [LetE (v, [], ty, cast_ins)] + pure $ (new_inst, ncenv, nenv) + bod' <- addCastsExp fundef cenv' env' bod + let ex' = foldr (\expr acc -> expr acc) bod' let_expr + pure $ ex' LetE (v, locs, ty, rhs@(Ext (AddrOfCursor (Ext (IndexCursorArray _ _)))) ) bod -> do let new_env = extendVEnv v ty env @@ -204,7 +222,25 @@ addCastsExp fundef cenv env ex = CharE {} -> pure ex FloatE {} -> pure ex LitSymE {} -> pure ex - AppE f locs args -> AppE f locs <$> mapM go args + AppE f locs args -> do + let funTy = lookupFEnv f env + let args_zip_ty = zip args (fst funTy ++ [snd funTy]) + (lets, new_args) <- foldlM (\(l, args') zipped -> case zipped of + (VarE arg, ty) -> do + let argTy = lookupVEnv arg env + if argTy == ty + then + return $ (l, args' ++ [VarE arg]) + else do + let new_arg = case (M.lookup arg cenv) of + Just v' -> VarE v' + Nothing -> error "TODO : Cast not found in env!!" + return $ (l, args' ++ [new_arg]) + _ -> return $ (l, args' ++ [fst zipped]) + ) ([], []) args_zip_ty + -- Expecting AppE to be flat, so only variables are present in AppE. + return $ AppE f locs new_args + PrimAppE pr args -> PrimAppE pr <$> mapM go args IfE a b c -> do a' <- go a diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 62cfd81fb..ed0e6090f 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -2737,63 +2737,106 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- An indirection or redirection pointer. -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. CursorTy -> do - tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" - tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur - loc_var <- lookupVariable loc fenv - var_dcon_next <- gensym "dcon_next" - vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur - redirection_var_dcon <- gensym "dcon_redir" - redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur - --let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - --let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + if isRedirectionTag dcon + then do + tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" + tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur + loc_var <- lookupVariable loc fenv + var_dcon_next <- gensym "dcon_next" + vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur + redirection_var_dcon <- gensym "dcon_redir" + redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + --let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + --let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), --((loc_var) , MkTy2 CursorTy), (redirection_var_dcon , MkTy2 CursorTy), (toEndV redirection_var_dcon, MkTy2 CursorTy), (toTagV redirection_var_dcon, MkTy2 IntTy), (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy)]) - tenv - read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor var_dcon_next) - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - -- v is the variable i want to send to the call. - -- In this case v is the soa variable where all redirections are unpacked. - binds = [(var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), - (tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - ((loc_var) , [], CursorTy, VarE dcur), - (redirection_var_dcon , [], CursorTy, ProjE 0 (VarE tmp)), - (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), - (toTagV redirection_var_dcon, [], IntTy , ProjE 2 (VarE tmp)), - (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))] - - --generate binds for all fields. - binds_flields = L.foldl (\(index, res) ((dcon', idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor (vars_next_fields !! index)) - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - tmpf = tmp_flds !! index - ty_of_field = (lookupDataCon ddfs dcon') !! idx - in case ty_of_field of - (MkTy2 PackedTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] - in (index + 1, res ++ new_binds) - (MkTy2 CursorArrayTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + tenv + read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + -- v is the variable i want to send to the call. + -- In this case v is the soa variable where all redirections are unpacked. + binds = [(var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + ((loc_var) , [], CursorTy, VarE dcur), + (redirection_var_dcon , [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV redirection_var_dcon, [], IntTy , ProjE 2 (VarE tmp)), + (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))] + + --generate binds for all fields. + binds_flields = L.foldl (\(index, res) ((dcon', idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor (vars_next_fields !! index)) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + tmpf = tmp_flds !! index + ty_of_field = (lookupDataCon ddfs dcon') !! idx + in case ty_of_field of + (MkTy2 PackedTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + (MkTy2 CursorArrayTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + _ -> let new_binds = [(vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + --((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index) , [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy , ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))] in (index + 1, res ++ new_binds) - _ -> let new_binds = [(vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - --((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index) , [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy , ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))] - in (index + 1, res ++ new_binds) - - ) (0, []) _field_cur - soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] - tenv'' = M.union (M.fromList [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) - ] ) - tenv - bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) - return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod + ) (0, []) _field_cur + soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] + tenv'' = M.union (M.fromList [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) + ] ) + tenv + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod + else if isIndirectionTag dcon + then + do + tmp <- gensym "readcursor_indir" + loc_var <- lookupVariable loc fenv + let locs_ty = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + + let locs_ty3 :: Ty3 = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + + --let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + --let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + var_dcon_next <- gensym "dcon_next" + + let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + ((loc_var) , MkTy2 locs_ty), + (v , MkTy2 locs_ty) + --(toEndV v, MkTy2 CursorTy), + --(toTagV v, MkTy2 IntTy), + --(toEndFromTaggedV v, MkTy2 CursorTy) + ]) + tenv + read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + binds = [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (v , [], CursorTy, ProjE 0 (VarE tmp)), + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), + -- End of region needs to be calculated differently + -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), + ((loc_var) , [], locs_ty3, VarE v) + ] + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) + return $ mkLets binds bod + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." VectorTy el_ty -> do tmp <- gensym "read_vec_tuple" diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index cbcdfdfe0..8f1a1c499 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -109,37 +109,59 @@ followPtrs (Prog ddefs fundefs mainExp) = do (pure (CaseE scrt (brs ++ [redir_br]))) else do indir_ptrv <- gensym "indr" - indir_ptrloc <- gensym "case" - jump <- gensym "jump" + indir_ptrv_loc <- freshCommonLoc "indr" scrt_loc + indir_ptrloc <- freshCommonLoc "case" scrt_loc + jump <- freshCommonLoc "jump" scrt_loc callv <- gensym "call" let _effs = arrEffs funTy - endofs <- mapM (\_ -> gensym "endof") (locRets funTy) - let endofs' = map Single endofs + endofs <- mapM (\lr -> case lr of + EndOf lrm -> do + let loc = lrmLoc lrm + freshCommonLoc "endof" loc + ) (locRets funTy) + --let endofs' = map Single endofs let ret_endofs = foldr (\(end, (EndOf (LRM loc _ _))) acc -> if loc == scrt_loc - then (Single jump) : acc + then (jump) : acc else end : acc) [] - (zip endofs' (locRets funTy)) + (zip endofs (locRets funTy)) let args = foldr (\v acc -> if v == scrtv then ((VarE indir_ptrv) : acc) else (VarE v : acc)) [] funArgs - let in_locs = foldr (\loc acc -> if loc == scrt_loc then ((Single indir_ptrv) : acc) else (loc : acc)) [] (inLocVars funTy) + let in_locs = foldr (\loc acc -> if loc == scrt_loc then ((indir_ptrloc) : 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)) $ + -- TODO, VS: the jump location should change + -- We need to unpack the SoA location of the scrut + -- We only need to do this for the data constructor. + -- the assumption is that the SoA cursor will be + -- written after the tag. So its going to be a + -- Cursor Array. We will cast pass this to the + -- call a cast should be added automatically. + + -- Get data con loc of scrut (indir_ptrloc) + -- Bump this up by 8 + -- Make the new SoA location with the data con loc + -- Field locs will all be the same. + let data_con_let = LetLocE (getDconLoc indir_ptrloc) (GetDataConLocSoA indir_ptrloc) + let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE 8 ((getDconLoc indir_ptrloc))) + let unpack_fld_lets = foldr (\((dcon, idx), lc) acc -> acc ++ [LetLocE lc (GetFieldLocSoA (dcon, idx) indir_ptrloc)]) [] (getAllFieldLocsSoA indir_ptrloc) + + let indir_bod = Ext $ LetLocE (jump) (GenSoALoc (getDconLoc jump) (getAllFieldLocsSoA 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) $ + LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ Ext (RetE ret_endofs callv) + let indir_bod' = foldr (\l b -> Ext $ l b) indir_bod ([data_con_let] ++ [new_jump_dloc] ++ unpack_fld_lets) let indir_dcon = fst $ fromJust $ L.find (isIndirectionTag . fst) dataCons - let indir_br = (indir_dcon,[(indir_ptrv,(Single indir_ptrloc))],indir_bod) + let indir_br = (indir_dcon,[(indir_ptrv,(indir_ptrloc))],indir_bod') ---------------------------------------- let redir_dcon = fst $ fromJust $ L.find (isRedirectionTag . fst) dataCons let redir_bod = (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->r ")]) else id) $ - LetE (callv,endofs',out_ty,AppE funName (in_locs ++ out_locs) args) $ - Ext (RetE endofs' callv) - let redir_br = (redir_dcon,[(indir_ptrv,(Single indir_ptrloc))],redir_bod) + LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ + Ext (RetE endofs callv) + let redir_br = (redir_dcon,[(indir_ptrv,(indir_ptrloc))],redir_bod) ---------------------------------------- (pure (CaseE scrt (brs ++ [indir_br,redir_br]))) IfE a b c -> do From da11f7e3e4baebb587fa321093814e0ed9638b78 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Fri, 19 Sep 2025 23:21:37 -0400 Subject: [PATCH 12/60] fix indirection in case bindings --- .../src/Gibbon/Passes/FollowPtrs.hs | 76 +++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index 8f1a1c499..78575a49e 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -98,7 +98,6 @@ followPtrs (Prog ddefs fundefs mainExp) = do -- no need to update single location variables Single{} -> return $ (nl ++ [locvar], bnds) ) ([], []) out_locs - let redir_dcon = fst $ fromJust $ L.find (isRedirectionTag . fst) dataCons let redir_bod = (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->r ")]) else id) $ LetE (callv,endofs,out_ty,AppE funName (in_locs ++ new_out_locs) args) $ @@ -144,24 +143,73 @@ followPtrs (Prog ddefs fundefs mainExp) = do -- Get data con loc of scrut (indir_ptrloc) -- Bump this up by 8 -- Make the new SoA location with the data con loc - -- Field locs will all be the same. - let data_con_let = LetLocE (getDconLoc indir_ptrloc) (GetDataConLocSoA indir_ptrloc) - let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE 8 ((getDconLoc indir_ptrloc))) - let unpack_fld_lets = foldr (\((dcon, idx), lc) acc -> acc ++ [LetLocE lc (GetFieldLocSoA (dcon, idx) indir_ptrloc)]) [] (getAllFieldLocsSoA indir_ptrloc) + -- Field locs will all be the same + indir_br <- case scrt_loc of + SoA{} -> do + let data_con_let = LetLocE (getDconLoc scrt_loc) (GetDataConLocSoA scrt_loc) + let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE 9 ((getDconLoc scrt_loc))) + let unpack_fld_lets = foldr (\((dcon, idx), lc) acc -> acc ++ [LetLocE lc (GetFieldLocSoA (dcon, idx) scrt_loc)]) [] (getAllFieldLocsSoA scrt_loc) - let indir_bod = Ext $ LetLocE (jump) (GenSoALoc (getDconLoc jump) (getAllFieldLocsSoA 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) - let indir_bod' = foldr (\l b -> Ext $ l b) indir_bod ([data_con_let] ++ [new_jump_dloc] ++ unpack_fld_lets) - let indir_dcon = fst $ fromJust $ L.find (isIndirectionTag . fst) dataCons - let indir_br = (indir_dcon,[(indir_ptrv,(indir_ptrloc))],indir_bod') + let indir_bod = Ext $ LetLocE (jump) (GenSoALoc (getDconLoc jump) (getAllFieldLocsSoA scrt_loc) ) $ + (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) + let indir_bod' = foldr (\l b -> Ext $ l b) indir_bod ([data_con_let] ++ [new_jump_dloc] ++ unpack_fld_lets) + let indir_dcon = fst $ fromJust $ L.find (isIndirectionTag . fst) dataCons + return $ (indir_dcon,[(indir_ptrv,(indir_ptrloc))],indir_bod') + Single{} -> do + let indir_bod = Ext $ LetLocE (jump) (AfterConstantLE 8 (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) + let indir_dcon = fst $ fromJust $ L.find (isIndirectionTag . fst) dataCons + return $ (indir_dcon,[(indir_ptrv,(indir_ptrloc))],indir_bod) + ---------------------------------------- + -- [VS: 09/14/2025] + -- In case an output location, that's passed to the function call. + -- for an SoA location, we cannot simply pass this directly. + -- Since we do this by value, we need to update the SoA location, + -- because bounds checking may have updated the value of the location. + -- Note that we only need to update the non packed locations + the data constructor buffer. + -- Other packed types will be updated by the function that traverses it. + (new_out_locs, new_loc_bnds) <- foldrM (\locvar (nl, bnds) -> case locvar of + SoA dloc flocs -> do + -- unpack all locations in the SoA location. + let unpack_dcon = LetLocE (singleLocVar dloc) (GetDataConLocSoA locvar) + let unpack_flds = map (\((dcon, idx), floc) -> do + let flet = LetLocE floc (GetFieldLocSoA (dcon, idx) locvar) + in flet + ) flocs + -- make a new name for this loc_var + new_locvar <- freshCommonLoc "copy" locvar + let new_don_loc = getDconLoc new_locvar + -- The data con loc should be unpacked and updated by bounds check. + -- from design of the compiler + let new_don_let = LetLocE new_don_loc (AfterConstantLE 0 (singleLocVar dloc)) + let new_fld_locs = getAllFieldLocsSoA new_locvar + new_fld_lets <- foldrM (\((dcon, idx), nfloc) flts -> do + let ty = (lookupDataCon ddefs dcon) !! idx + in case (ty) of + PackedTy{} -> do + let let_for_fld = LetLocE nfloc (GetFieldLocSoA (dcon, idx) locvar) + in pure $ flts ++ [let_for_fld] + _ -> do + let let_for_fld = LetLocE nfloc (AfterConstantLE 0 (getFieldLoc (dcon, idx) locvar)) + in pure $ flts ++ [let_for_fld] + ) [] new_fld_locs + let new_soa_loc_let = LetLocE new_locvar (GenSoALoc new_don_loc new_fld_locs) + return $ (nl ++ [new_locvar], bnds ++ [unpack_dcon] ++ unpack_flds ++ [new_don_let] ++ new_fld_lets ++ [new_soa_loc_let]) + + -- no need to update single location variables + Single{} -> return $ (nl ++ [locvar], bnds) + ) ([], []) out_locs let redir_dcon = fst $ fromJust $ L.find (isRedirectionTag . fst) dataCons let redir_bod = (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->r ")]) else id) $ - LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ + LetE (callv,endofs,out_ty,AppE funName (in_locs ++ new_out_locs) args) $ Ext (RetE endofs callv) - let redir_br = (redir_dcon,[(indir_ptrv,(indir_ptrloc))],redir_bod) + let redir_bod' = foldr (\bnd bod -> Ext $ bnd bod) redir_bod new_loc_bnds + let redir_br = (redir_dcon,[(indir_ptrv,(indir_ptrloc))],redir_bod') ---------------------------------------- (pure (CaseE scrt (brs ++ [indir_br,redir_br]))) IfE a b c -> do From 67398467c7407f0538a2751d50c7c65e553d8e2c Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sat, 20 Sep 2025 15:12:22 -0400 Subject: [PATCH 13/60] edits --- gibbon-compiler/examples/soa_examples/list.hs | 6 ++--- .../src/Gibbon/Passes/Cursorize.hs | 25 +++++++++++++------ .../src/Gibbon/Passes/RemoveCopies.hs | 11 ++++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 68f7e5e52..2c772960a 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -37,9 +37,9 @@ id :: List -> List id lst = lst gibbon_main = let - lst = mkList 100 - lst' = id (add1 lst) - in sumList lst' + lst = mkList 100 + lst' = id (add1 lst) + in sumList lst' diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index ed0e6090f..cb19f21d3 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1348,7 +1348,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let_assign_write_cur <$> LetE (d',[], CursorTy, Ext $ WriteVector write_vector_at rnd' (stripTyLocs el_ty)) <$> go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst - _ -> error $ "TODO: Cursorize: cursorizePackedExp: Ty not implemented!! " ++ show (ty) + -- _ -> error $ "TODO: Cursorize: cursorizePackedExp: Ty not implemented!! " ++ show (ty) -- -- Write a pointer to a vector -- ListTy el_ty -> do @@ -1356,12 +1356,17 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- LetE (d',[], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> -- go2 marker_added d' rst - -- -- shortcut pointer - -- CursorTy -> do - -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd - -- LetE (d',[], CursorTy, Ext $ WriteTaggedCursor d rnd') <$> - -- go2 marker_added d' rst - -- _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty + -- shortcut pointer + -- SoA case + -- Fix case for indirection/shortcut pointers + CursorTy -> do + rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + after_indirection <- gensym "aft_indirection" + LetE (d',[], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') <$> + LetE (after_indirection,[], CursorTy, VarE d') <$> --Ext $ AddCursor aft_dloc (L3.LitE 8) + go2 marker_added freeVarToVarEnv after_indirection from_rec_end aft_flocs rst + + _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty @@ -1576,7 +1581,11 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = if gopt Opt_DisableGC dflags -- || (from_reg == "dummy" || to_reg == "dummy") -- HACK!!! -- [2022.03.02]: ckoparkar:WTH does this hack enable? - then go freeVarToVarEnv tenv senv (DataConE from dcon [VarE (((unwrapLocVar . toLocVar)) to)]) + then do + let locs_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + go freeVarToVarEnv tenv senv (DataConE from dcon [VarE locs_var]) else do start <- gensym "start" end <- gensym "end" diff --git a/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs b/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs index 61869d21c..add0283b6 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs @@ -37,7 +37,6 @@ removeCopiesFn :: DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef2 removeCopiesFn ddefs fundefs f@FunDef{funArgs,funTy,funBody} = do let initLocEnv = M.fromList $ map (\(LRM lc r _) -> case r of _ -> (lc, regionToVar r) - SoAR _ _ -> error "TODO: removeCopiesFn structure of arrays not implemented yet." ) (locVars funTy) initTyEnv = M.fromList $ zip funArgs (arrIns funTy) env2 = Env2 initTyEnv (initFunEnv fundefs) @@ -59,14 +58,14 @@ removeCopiesExp ddefs fundefs lenv env2 ex = [] -> error $ "removeCopies: No indirection constructor found for: " ++ sdoc tycon [dcon] -> do let reg_lout = case (lenv # lout) of - SingleR v -> v - SoARv _ _ -> error "removeCopies: structure of arrays not implemented yet." + SingleR v -> fromRegVarToLocVar $ (SingleR v) + r@(SoARv _ _) -> fromRegVarToLocVar r let reg_lin = case (lenv # lin) of - SingleR v -> v - SoARv _ _ -> error "removeCopies: structure of arrays not implemented yet." + SingleR v -> fromRegVarToLocVar $ (SingleR v) + r@(SoARv _ _) -> fromRegVarToLocVar r return $ mkLets ([(indirection,[],PackedTy tycon lout, - Ext $ IndirectionE tycon dcon (lout , singleLocVar $ reg_lout) (lin, singleLocVar $ reg_lin) arg)]) + Ext $ IndirectionE tycon dcon (lout , reg_lout) (lin, reg_lin) arg)]) (VarE indirection) oth -> error $ "removeCopies: Multiple indirection constructors: " ++ sdoc oth From 71bbc740194451b3e81c2daf2f120801fbdc4fa1 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sat, 20 Sep 2025 17:56:45 -0400 Subject: [PATCH 14/60] support SoA indirections when GC is off --- .../examples/soa_examples/packedList.hs | 6 ++- gibbon-compiler/examples/soa_examples/tree.hs | 9 ++-- .../src/Gibbon/Passes/AddCastInstructions.hs | 1 + .../src/Gibbon/Passes/Cursorize.hs | 42 +++++++++++++++---- .../src/Gibbon/Passes/ThreadRegions2.hs | 18 ++++---- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index 4ad55dadb..a2100ad14 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -40,10 +40,14 @@ sumList lst = case lst of sumRst = sumList rst in j + i' + sumRst +id :: List -> List +id lst = lst + + gibbon_main = let pi = mkPackedInt 10 lst = mkList 100 - lst' = add1 lst + lst' = id (add1 lst) in (sumList lst') diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index 8f0e55479..5ac65013a 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -28,9 +28,12 @@ sumTree tr = Leaf n m -> n Node i j k _ l r ll rr -> i + j + k + (sumTree l) + (sumTree r) + (sumTree ll) + (sumTree rr) +id :: Tree -> Tree +id tree = tree + gibbon_main = - let tree = mkTree 7 - tree' = add1Tree tree + let tree = id (mkTree 7) + tree' = id (add1Tree tree) val = sumTree tree' _ = printsym (quote "(sum: ") _ = printint val @@ -38,4 +41,4 @@ gibbon_main = rmost = rightmost tree' _ = printint rmost _ = printsym (quote ")\n\n") - in () + in val diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index f1fd035ee..743a16267 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -456,6 +456,7 @@ addCastsExp fundef cenv env ex = Ext (Assert e) -> do e' <- go e pure $ Ext $ Assert e' + Ext (CastPtr v ty) -> pure ex Ext {} -> error $ "addCastsExp : Unexpected instruction " ++ show ex MapE {} -> error "addCastsExp: MapE TODO" FoldE {} -> error "addCastsExp: FoldE TODO" diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index cb19f21d3..f295fc5f9 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1362,7 +1362,12 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = CursorTy -> do rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd after_indirection <- gensym "aft_indirection" - LetE (d',[], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') <$> + casted_var <- gensym "cast" + let rnd_var = case rnd' of + VarE v -> v + _ -> error "Did not expected variable!" + LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> + LetE (d',[], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) <$> LetE (after_indirection,[], CursorTy, VarE d') <$> --Ext $ AddCursor aft_dloc (L3.LitE 8) go2 marker_added freeVarToVarEnv after_indirection from_rec_end aft_flocs rst @@ -1587,13 +1592,34 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Just var -> var go freeVarToVarEnv tenv senv (DataConE from dcon [VarE locs_var]) else do - start <- gensym "start" - end <- gensym "end" - return $ Di $ - (mkLets [("_",[],ProdTy [],Ext (IndirectionBarrier tycon (((unwrapLocVar . toLocVar) from),((unwrapLocVar . toLocVar) from_reg),((unwrapLocVar . toLocVar) to),((unwrapLocVar . toLocVar) to_reg)))), - (start, [], CursorTy, VarE ((unwrapLocVar . toLocVar) from)), - (end, [], CursorTy, Ext $ AddCursor ((unwrapLocVar . toLocVar) from) (L3.LitE 9))] - (MkProdE [VarE start, VarE end])) + case (toLocVar from) of + Single{} -> do + start <- gensym "start" + end <- gensym "end" + let from_var = case M.lookup (fromLocArgToFreeVarsTy from) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let to_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let reg_from_reg = fromLocVarToRegVar (toLocVar from_reg) + let reg_to_reg = fromLocVarToRegVar (toLocVar to_reg) + let from_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_from_reg) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let to_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_to_reg) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + -- VS : [09/20/2025 -- For SoA case, indirection with gc need a bit more thinking] + -- One way could be to call indirection barrier seperately on every buffer/region + -- Then follow them seperately for every region in the case. + -- For now i'm erroring out but this needs more thought. + return $ Di $ + (mkLets [("_",[],ProdTy [],Ext (IndirectionBarrier tycon ((from_var),(from_reg_var),(to_var),(to_reg_var)))), + (start, [], CursorTy, VarE (from_var)), + (end, [], CursorTy, Ext $ AddCursor (from_var) (L3.LitE 9))] + (MkProdE [VarE start, VarE end])) + SoA _ flds -> error "Indirection when GC is enabled is not implemented for SoA! Please turn off the GC!" AddFixed{} -> error "cursorizePackedExp: AddFixed not handled." diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index 1c18e7e45..ef8f16f86 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -687,13 +687,17 @@ threadRegionsExp ddefs fundefs fnLocArgs renv env2 lfenv rlocs_env wlocs_env pkd rlocs_env' = updRLocsEnv (unTy2 ty) rlocs_env wlocs_env' = foldr (\loc2 acc -> M.delete loc2 acc) wlocs_env (NewL2.locsInTy ty) bod' <- threadRegionsExp ddefs fundefs fnLocArgs renv env2' lfenv rlocs_env' wlocs_env' pkd_env' region_locs ran_env indirs redirs bod - let boundscheck = - let locarg = a' - regarg = b' - -- bc = boundsCheck ddefs tcon - bc = 18 - in LetE ("_", [], MkTy2 IntTy, Ext $ BoundsCheck bc regarg locarg) - pure $ boundscheck $ LetE (v, locs, ty, (Ext (IndirectionE tcon dcon (a', b') (c', d') cpy))) bod' + -- VS: 09/20/2025 + -- Removing bounds check for now since assuming that the function should do this and may not need this. + -- TODO: this might not be true though + --let boundscheck = + -- let locarg = a' + -- regarg = b' + -- -- bc = boundsCheck ddefs tcon + -- bc = 18 + -- in LetE ("_", [], MkTy2 IntTy, Ext $ BoundsCheck bc regarg locarg) + --pure $ boundscheck $ LetE (v, locs, ty, (Ext (IndirectionE tcon dcon (a', b') (c', d') cpy))) bod' + pure $ LetE (v, locs, ty, (Ext (IndirectionE tcon dcon (a', b') (c', d') cpy))) bod' Ext (StartOfPkdCursor cur) -> do let (PackedTy _ loc) = unTy2 (lookupVEnvLocVar (fromVarToFreeVarsTy cur) env2) case M.lookup loc pkd_env of From 6d6b42d2bc25351c9f7ce8ccf6426a36444f3f06 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sat, 20 Sep 2025 18:39:16 -0400 Subject: [PATCH 15/60] add new version of colobus to test suite with indirections without gc --- .../examples/soa_examples/packedTree.hs | 5 +- gibbon-compiler/tests/BenchRunner.hs | 2 +- gibbon-compiler/tests/TestRunner.hs | 6 +- .../tests/test-gibbon-examples.yaml | 72 +++++++++---------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index 9be6a989b..cb324acad 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -74,8 +74,11 @@ sumFloatList lst = case lst of FNil -> 0 FCons x rst -> 1 + (sumFloatList rst) +id :: Tree -> Tree +id tree = tree + gibbon_main = let tree = mkTree 5 - tree' = add1Tree tree + tree' = id (add1Tree tree) in sumTree tree' diff --git a/gibbon-compiler/tests/BenchRunner.hs b/gibbon-compiler/tests/BenchRunner.hs index 9d853e83e..b6ff06a75 100644 --- a/gibbon-compiler/tests/BenchRunner.hs +++ b/gibbon-compiler/tests/BenchRunner.hs @@ -76,7 +76,7 @@ bench_main :: TestConfig -> Tests -> IO () bench_main tc (Tests tests) = do putStrLn "Executing BenchRunner...\n" let benchmarks = filter (not . skip) $ filter isBenchmark tests - modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus1, Colobus2] -- Omit MPL for now + modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus1, Colobus2, Colobus3] -- Omit MPL for now results <- mapM (go modesToBench) benchmarks mc <- getHostname let csvs = map (\arg -> intercalate "," (mc:arg)) (concat results) diff --git a/gibbon-compiler/tests/TestRunner.hs b/gibbon-compiler/tests/TestRunner.hs index a19894ee3..bccf29098 100644 --- a/gibbon-compiler/tests/TestRunner.hs +++ b/gibbon-compiler/tests/TestRunner.hs @@ -161,7 +161,7 @@ data Result = Pass | Fail -- Not used atm. -- | Gibbon mode to run programs in -data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus1 | Colobus2 +data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus1 | Colobus2 | Colobus3 deriving (Show, Eq, Read, Ord, Bounded, Enum) instance FromJSON Mode where @@ -181,6 +181,7 @@ readMode s = "gibbon1" -> Gibbon1 "colobus1" -> Colobus1 "colobus2" -> Colobus2 + "colobus3" -> Colobus3 "mpl" -> MPL _ -> error $ "readMode: " ++ show s @@ -188,6 +189,7 @@ readMode s = modeRunFlags :: Mode -> [String] modeRunFlags Colobus1 = ["--run", "--packed", "--gibbon1", "--SoA"] modeRunFlags Colobus2 = ["--run", "--packed", "--no-rcopies", "--no-ran", "--SoA"] +modeRunFlags Colobus3 = ["--run", "--packed", "--no-gc", "--no-ran", "--SoA"] modeRunFlags Gibbon3 = ["--run", "--packed", "--gen-gc"] modeRunFlags Gibbon2 = ["--run", "--packed"] modeRunFlags Pointer = ["--run", "--pointer"] @@ -199,6 +201,7 @@ modeRunFlags MPL = ["--mpl-run"] modeExeFlags :: Mode -> [String] modeExeFlags Colobus1 = ["--to-exe", "--packed", "--gibbon1", "--SoA"] modeExeFlags Colobus2 = ["--to-exe", "--packed", "--no-rcopies", "--no-ran", "--SoA"] +modeExeFlags Colobus2 = ["--to-exe", "--packed", "--no-gc", "--no-ran", "--SoA"] modeExeFlags Gibbon3 = ["--to-exe", "--packed", "--gen-gc"] modeExeFlags Gibbon2 = ["--to-exe", "--packed"] modeExeFlags Pointer = ["--to-exe", "--pointer"] @@ -209,6 +212,7 @@ modeExeFlags MPL = ["--mpl-exe"] modeFileSuffix :: Mode -> String modeFileSuffix Colobus1 = "_colobus1" modeFileSuffix Colobus2 = "_colobus2" +modeFileSuffix Colobus3 = "_colobus3" modeFileSuffix Gibbon3 = "_gibbon3" modeFileSuffix Gibbon2 = "_gibbon2" modeFileSuffix Pointer = "_ptr" diff --git a/gibbon-compiler/tests/test-gibbon-examples.yaml b/gibbon-compiler/tests/test-gibbon-examples.yaml index 32610395e..dc7478bf8 100644 --- a/gibbon-compiler/tests/test-gibbon-examples.yaml +++ b/gibbon-compiler/tests/test-gibbon-examples.yaml @@ -71,15 +71,15 @@ tests: - name: test11f_funrec.gib - name: test11_fundata.gib - name: test12b_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] - name: test12c_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] - name: test13b_build.gib - name: test13_build.gib - name: Test185.hs answer-file: examples/Test185.ans # Scalar fields after packed not allowed - failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2] + failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] - name: SS.hs dir: examples/gc answer-file: examples/gc/SS.ans @@ -137,11 +137,11 @@ tests: - name: test29b_list.gib - name: test30_twitter.gib # ThreadRegions bug. - failing: [colobus1, colobus2] + failing: [colobus1, colobus2, colobus3] - name: test_buildstree.gib - name: test_buildtree.gib - name: test_buildtreesum.gib - failing: [colobus1, colobus2] + failing: [colobus1, colobus2, colobus3] - name: test_ddtree.gib - name: test_stree.gib - name: test_sumstree.gib @@ -258,7 +258,7 @@ tests: - name: Poly1.hs dir: examples/poly answer-file: examples/poly/Poly1.ans - failing: [gibbon1, gibbon2, gibbon3, interp1,colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, interp1,colobus1, colobus2, colobus3] # - name: measure_mode.hs # answer-file: examples/measure_mode.ans @@ -288,7 +288,7 @@ tests: dir: examples/poly answer-file: examples/poly/CurriedFns.ans skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] - name: T127.hs dir: examples/poly @@ -308,19 +308,19 @@ tests: - name: unariser_bug1.hs answer-file: examples/unariser_bug1.ans - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] skip: true - name: ParseLinearTypes.hs test-flags: ["--ghc-tc"] dir: examples/lineartypes/ - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] - name: EqBench.hs answer-file: examples/EqBench.ans - name: test_parse.hs - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] - name: toplevel_value.hs answer-file: examples/toplevel_value.ans @@ -357,7 +357,7 @@ tests: dir: examples answer-file: examples/test_printpacked.ans # gibbon3 and gibbon2: Inferlocations bug. - failing: [interp1,gibbon1,pointer, colobus1, colobus2] + failing: [interp1,gibbon1,pointer, colobus1, colobus2, colobus3] ## FAILING: Multiple packed outputs. - name: TupleTest.hs @@ -371,7 +371,7 @@ tests: ## FAILING: Scalar field after a packed field. - name: test12_skip.gib - failing: [gibbon1, colobus1, colobus2] + failing: [gibbon1, colobus1, colobus2, colobus3] skip: true - name: test12b_traverse.gib skip: true @@ -401,7 +401,7 @@ tests: skip: true - name: test29d_list.gib skip: true - failing: [gibbon1, colobus1, colobus2] + failing: [gibbon1, colobus1, colobus2, colobus3] - name: test_unpacking.gib skip: true @@ -409,46 +409,46 @@ tests: ## Shouldn't typecheck - name: Fail1.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] - name: Fail2.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] - name: Fail3.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] ## Fusion2 tests - name: test_sumup_seteven.gib skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] test-flags: ["--fusion"] - name: render_tree.hs dir: examples/fusion-benchmarks skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree.ans - name: render_tree_two_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_two_passes.ans - name: render_tree_four_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_four_passes.ans - name: render_tree_five_passes.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, pointer, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, pointer, colobus1, colobus2, colobus3] ## [2020.05.27]: It never finishes on Travis... skip: true test-flags: ["--fusion"] @@ -456,7 +456,7 @@ tests: - name: LC.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] test-flags: ["--fusion"] skip: true # gibbon2: segfaults in free_region @@ -494,29 +494,29 @@ tests: ## AST benchmarks - name: C1.hs dir: examples/ast - failing: [gibbon1, gibbon2, colobus1, colobus2] + failing: [gibbon1, gibbon2, colobus1, colobus2, colobus3] answer-file: examples/ast/C1.ans skip: true ## Tests that only work with some backend: - name: test18f_flip.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] - name: pp_projs.gib skip: true - name: test12_skip.gib - failing: [gibbon1, colobus1, colobus2] + failing: [gibbon1, colobus1, colobus2, colobus3] skip: true # Tests that actually work but we can't generate answers with Racket - name: test08_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] - name: test08b_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] - name: test08c_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] - name: test08d_sharedict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] # - name: test08f_dict.gib # - name: test08f2_dict.gib @@ -524,13 +524,13 @@ tests: # This test depends on real symbols, which we don't support atm. - name: test27b_subst.gib - failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2] + failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] skip: true # printing symbols is broken atm # No gensym, or real symbols. - name: test28_copyprop.gib - failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus1, colobus2] + failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus1, colobus2, colobus3] # sym-append not implemented in the RTS - name: test15b_symappend.gib @@ -555,15 +555,15 @@ tests: failing: [interp1] - name: test_153.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3] answer-file: examples/test_153.ans - name: test_164.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3] answer-file: examples/test_164.ans - name: test_166.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3] answer-file: examples/test_166.ans - name: test_167.hs @@ -580,14 +580,14 @@ tests: - name: test_power.hs answer-file: examples/test_power.ans # gib_alloc_region_on_heap: gib_alloc failed - failing: [gibbon1, colobus1, colobus2] + failing: [gibbon1, colobus1, colobus2, colobus3] # Vidush: unskip this, thing hangs because of all the debug print statements skip: true - name: test_191.hs answer-file: examples/test_191.ans # Gibbon2 and Gibbon3 modes don't pass the L2 typechecker. - failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus1, colobus2] + failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus1, colobus2, colobus3] run-modes: ["gibbon2"] #simple SoA benchmarks From 1f413e8dc5a73bd2490bab4c225fdc6266d65984 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sat, 20 Sep 2025 18:52:03 -0400 Subject: [PATCH 16/60] restore test --- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index 5ac65013a..c46530f0e 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -41,4 +41,4 @@ gibbon_main = rmost = rightmost tree' _ = printint rmost _ = printsym (quote ")\n\n") - in val + in () From 9829a27d91af8f69d087acb9735943ef27d16c35 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sat, 20 Sep 2025 22:57:14 -0400 Subject: [PATCH 17/60] fix failing tests --- gibbon-compiler/src/Gibbon/Common.hs | 2 +- gibbon-compiler/src/Gibbon/L2/Syntax.hs | 6 +++-- .../src/Gibbon/Passes/AddTraversals.hs | 14 ++++++++++- .../src/Gibbon/Passes/RemoveCopies.hs | 23 +++++++++++++++---- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Common.hs b/gibbon-compiler/src/Gibbon/Common.hs index c55ef98e6..7665ed54b 100644 --- a/gibbon-compiler/src/Gibbon/Common.hs +++ b/gibbon-compiler/src/Gibbon/Common.hs @@ -539,7 +539,7 @@ truePrinted = "#t" falsePrinted :: String falsePrinted = "#f" -unwrapLocVar :: LocVar -> Var +unwrapLocVar :: HasCallStack => LocVar -> Var unwrapLocVar locvar = case locvar of Single loc -> loc SoA dcon fieldLocs -> diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index 73d7c564e..6489bc66f 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -973,8 +973,10 @@ occurs w ex = FromEndE{} -> False BoundsCheck{} -> False AddFixed v _ -> v `S.member` w - IndirectionE _ _ (_,v1) (_,v2) ib -> - (unwrapLocVar v1) `S.member` w || (unwrapLocVar v2) `S.member` w || go ib + + -- (unwrapLocVar v1) `S.member` w || (unwrapLocVar v2) `S.member` w || + -- v1, v2 are not strictly variables, these are regions. + IndirectionE _ _ (_,v1) (_,v2) ib -> go ib GetCilkWorkerNum -> False LetAvail _ bod -> go bod AllocateTagHere{} -> False diff --git a/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs b/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs index 1f22010a5..3e4f2cdf1 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs @@ -49,7 +49,6 @@ addTraversalsFn ddefs fundefs f@FunDef{funName, funArgs, funTy, funBody} = do tyenv = M.fromList $ fragileZip funArgs (inTys funTy) env2 = Env2 tyenv funenv renv = M.fromList $ L.map (\lrm -> case (lrmReg lrm) of - SoAR _ _ -> error "TODO: addTraversalsFn structure of arrays not implemented yet." _ -> (lrmLoc lrm, regionToVar (lrmReg lrm)) ) @@ -104,6 +103,19 @@ addTraversalsExp ddefs fundefs env2 renv context ex = AfterConstantLE _ lc -> renv # lc AfterVariableLE _ lc _ -> renv # lc FromEndLE lc -> renv # lc -- TODO: This needs to be fixed + GetDataConLocSoA lc -> + let rlc = renv # lc + in getDataConRegFromRegVar rlc + GetFieldLocSoA (dcon, idx) lc -> + let rlc = renv # lc + in getFieldRegFromRegVar (dcon, idx) rlc + AssignLE lc -> renv # lc + GenSoALoc dconLoc fieldLocs -> + let dconReg = renv # dconLoc + fldRegs = L.map (\((dcon, idx), fl) -> let rl = renv # fl + in ((dcon, idx), rl) + ) fieldLocs + in SoARv dconReg fldRegs in Ext <$> LetLocE loc locexp <$> addTraversalsExp ddefs fundefs env2 (M.insert loc reg renv) context bod _ -> return ex diff --git a/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs b/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs index add0283b6..8d9289f92 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs @@ -76,12 +76,12 @@ removeCopiesExp ddefs fundefs lenv env2 ex = [] -> error $ "removeCopies: No indirection constructor found for: " ++ sdoc tycon [dcon] -> do let reg_lout = case (lenv # lout) of - SingleR v -> v - SoARv _ _ -> error "removeCopies: structure of arrays not implemented yet." + SingleR vr -> fromRegVarToLocVar $ (SingleR vr) + r@(SoARv _ _) -> fromRegVarToLocVar r let reg_lin = case (lenv # lin) of - SingleR v -> v - SoARv _ _ -> error "removeCopies: structure of arrays not implemented yet." - LetE (v,locs,ty, Ext $ IndirectionE tycon dcon (lout , singleLocVar $ reg_lout) (lin, singleLocVar $ reg_lin) arg) <$> + SingleR vr -> fromRegVarToLocVar $ (SingleR vr) + r@(SoARv _ _) -> fromRegVarToLocVar r + LetE (v,locs,ty, Ext $ IndirectionE tycon dcon (lout , reg_lout) (lin, reg_lin) arg) <$> removeCopiesExp ddefs fundefs lenv (extendVEnv v ty env2) bod oth -> error $ "removeCopies: Multiple indirection constructors: " ++ sdoc oth @@ -100,6 +100,19 @@ removeCopiesExp ddefs fundefs lenv env2 ex = AfterConstantLE _ lc -> lenv # lc AfterVariableLE _ lc _ -> lenv # lc FromEndLE lc -> lenv # lc -- TODO: This needs to be fixed + GetDataConLocSoA lc -> + let rlc = lenv # lc + in getDataConRegFromRegVar rlc + GetFieldLocSoA (dcon, idx) lc -> + let rlc = lenv # lc + in getFieldRegFromRegVar (dcon, idx) rlc + AssignLE lc -> lenv # lc + GenSoALoc dconLoc fieldLocs -> + let dconReg = lenv # dconLoc + fldRegs = map (\((dcon, idx), fl) -> let rl = lenv # fl + in ((dcon, idx), rl) + ) fieldLocs + in SoARv dconReg fldRegs Ext <$> LetLocE loc rhs <$> removeCopiesExp ddefs fundefs (M.insert loc reg lenv) env2 bod -- Straightforward recursion From 977b09ff8b462d81aa91e97cfa60dd3112eeb43b Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 22 Sep 2025 10:38:28 -0400 Subject: [PATCH 18/60] fixing indirections --- gibbon-compiler/src/Gibbon/Language/Syntax.hs | 3 +- .../src/Gibbon/Passes/Cursorize.hs | 35 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 648bead8c..488f13bfc 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -72,6 +72,7 @@ import System.IO.Unsafe (unsafePerformIO) --import qualified Data.Typeable as Typeable import Gibbon.Common +import GHC.Stack (HasCallStack) -------------------------------------------------------------------------------- -- Data type definitions @@ -356,7 +357,7 @@ extendsVEnv mp (Env2 ve fe) = Env2 (M.union mp ve) fe extendsVEnvLocVar :: M.Map FreeVarsTy a -> Env2 FreeVarsTy a -> Env2 FreeVarsTy a extendsVEnvLocVar mp (Env2 ve fe) = Env2 (M.union mp ve) fe -lookupVEnv :: Out a => Var -> Env2 Var a -> a +lookupVEnv :: (HasCallStack, Out a) => Var -> Env2 Var a -> a lookupVEnv v env2 = (vEnv env2) # v lookupVEnvLocVar :: Out a => FreeVarsTy -> Env2 FreeVarsTy a -> a diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index f295fc5f9..b007e78f6 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -17,6 +17,7 @@ import Gibbon.L3.Syntax hiding ( BoundsCheck, RetE, GetCilkWorkerNum, import qualified Gibbon.L3.Syntax as L3 import Gibbon.Passes.AddRAN ( numRANsDataCon ) import Data.Set (Set) +import GHC.RTS.Flags (MiscFlags(generateCrashDumpFile)) {- @@ -1202,10 +1203,10 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = sloc = case (M.lookup (fromLocVarToFreeVarsTy sloc_loc) freeVarToVarEnv) of Just v -> v Nothing -> error $ "cursorizeExp(1056): DataConE: unexpected location variable" ++ "(" ++ show sloc_loc ++ ")" ++ show freeVarToVarEnv - sloc_dcon = case (M.lookup (fromLocVarToFreeVarsTy dcon_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> case dcon_loc of - Single l -> l + (sloc_dcon, present) = case (M.lookup (fromLocVarToFreeVarsTy dcon_loc) freeVarToVarEnv) of + Just v -> (v, True) + Nothing -> case dcon_loc of + Single l -> (l, False) _ -> error $ "cursorizeExp(1059): DataConE: unexpected dcon location variable" ++ "(" ++ show (dcon, dcon_loc) ++ ")" ++ show freeVarToVarEnv -- Return (start,end) cursors -- The final return value lives at the position of the out cursors: @@ -1389,13 +1390,37 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = loc = L.lookup key field_locs in (key, loc, e) ) exp_f_tys + let additional_bnds = if present + then [] + else [(sloc_dcon, [], CursorTy, Ext $ IndexCursorArray sloc 0)] + (additional_bnds', freeVarToVarEnv', _) <- foldlM (\(b, env, idx') ((dcon, _), loc) -> do + (var_for_loc, present, env') <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of + Just v -> return $ (v, True, env) + Nothing -> case loc of + Single l -> return $ (l, False, env) + SoA{} -> do + new_name <- gensym "field_cursor" + let env'' = M.insert (fromLocVarToFreeVarsTy loc) new_name env + return $ (new_name, False, env'') + let b' = if present + then b + else b ++ [(var_for_loc, [], CursorTy, Ext $ IndexCursorArray sloc idx')] + pure (b', env', idx' + 1) + + + ) (additional_bnds, freeVarToVarEnv, 1) field_locs + dl <$> + -- Make sure that the field locations and data locations are released here + -- We can clean them up later. + -- data con location + mkLets additional_bnds' <$> LetE (start_tag_alloc,[],ProdTy [], Ext $ StartTagAllocation (sloc)) <$> LetE (writetag,[], CursorTy, Ext $ WriteTag dcon (sloc_dcon)) <$> LetE (end_tag_alloc,[],ProdTy [], Ext $ EndTagAllocation (sloc)) <$> LetE (start_scalars_alloc,[],ProdTy [], Ext $ StartScalarsAllocation (sloc)) <$> LetE (after_tag,[], CursorTy, Ext $ AddCursor (sloc_dcon) (L3.LitE 1)) <$> - go2 False freeVarToVarEnv after_tag Nothing field_locs locs_tys + go2 False freeVarToVarEnv' after_tag Nothing field_locs locs_tys -- go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> [((DataCon, Int), Location, (Exp2, Ty2))] -> [((DataCon, Int), Location, (Exp2, Ty2))] -> PassM Exp3 -- go2 False after_tag (zip args (lookupDataCon ddfs dcon)) From 2401ed18ba08c3bdfbba2939ca42bd48d9ca9066 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 22 Sep 2025 10:38:51 -0400 Subject: [PATCH 19/60] new test --- .../examples/soa_examples/test_copy.hs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 gibbon-compiler/examples/soa_examples/test_copy.hs diff --git a/gibbon-compiler/examples/soa_examples/test_copy.hs b/gibbon-compiler/examples/soa_examples/test_copy.hs new file mode 100644 index 000000000..1d45baf2a --- /dev/null +++ b/gibbon-compiler/examples/soa_examples/test_copy.hs @@ -0,0 +1,23 @@ +data Tree = Node Int Tree Tree | Leaf Int + +foo :: Int -> Tree +foo i = let tree = Node i (Leaf i) (Leaf (i+1)) + in tree + +make_node :: Tree -> Tree -> Tree +make_node t1 t2 = Node 10 t1 t2 + +foo' :: Tree -> Tree +foo' tree = case tree of + Leaf v -> tree + Node i x y -> tree + +gibbon_main = + let t1 = foo 20 + t2 = foo 50 + t3 = make_node t1 t2 + t4 = foo' t3 + t5 = Node 12 t4 (Node 12 (Leaf 1) (Leaf 2)) + in printPacked t5 + + From 028e5747e8fd9f6994b423b1846d5dfdd0f430bc Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 22 Sep 2025 23:41:47 -0400 Subject: [PATCH 20/60] fixing indirections --- .../examples/soa_examples/test_copy.hs | 10 ++-- .../src/Gibbon/Passes/Cursorize.hs | 26 +++++----- .../src/Gibbon/Passes/InferLocations.hs | 47 +++++++++++-------- .../tests/test-gibbon-examples.yaml | 2 +- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/test_copy.hs b/gibbon-compiler/examples/soa_examples/test_copy.hs index 1d45baf2a..a48a133b3 100644 --- a/gibbon-compiler/examples/soa_examples/test_copy.hs +++ b/gibbon-compiler/examples/soa_examples/test_copy.hs @@ -8,16 +8,18 @@ make_node :: Tree -> Tree -> Tree make_node t1 t2 = Node 10 t1 t2 foo' :: Tree -> Tree -foo' tree = case tree of - Leaf v -> tree - Node i x y -> tree +foo' tree = tree + gibbon_main = let t1 = foo 20 + --t4' = Node 12 (Leaf 1) (Leaf 1) t2 = foo 50 t3 = make_node t1 t2 + -- t4' = Node 12 (Leaf 1) (Leaf 1) t4 = foo' t3 - t5 = Node 12 t4 (Node 12 (Leaf 1) (Leaf 2)) + t4' = Node 12 (Leaf 1) (Leaf 2) + t5 = Node 10 (Node 12 t4 t4') (Node 10 (Leaf 1) (Leaf 1)) in printPacked t5 diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index b007e78f6..4abd16e75 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1203,10 +1203,10 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = sloc = case (M.lookup (fromLocVarToFreeVarsTy sloc_loc) freeVarToVarEnv) of Just v -> v Nothing -> error $ "cursorizeExp(1056): DataConE: unexpected location variable" ++ "(" ++ show sloc_loc ++ ")" ++ show freeVarToVarEnv - (sloc_dcon, present) = case (M.lookup (fromLocVarToFreeVarsTy dcon_loc) freeVarToVarEnv) of - Just v -> (v, True) + (sloc_dcon, present, freeVarToVarEnv') = case (M.lookup (fromLocVarToFreeVarsTy dcon_loc) freeVarToVarEnv) of + Just v -> (v, True, freeVarToVarEnv) Nothing -> case dcon_loc of - Single l -> (l, False) + Single l -> (l, False, (M.insert (fromLocVarToFreeVarsTy dcon_loc) l freeVarToVarEnv)) _ -> error $ "cursorizeExp(1059): DataConE: unexpected dcon location variable" ++ "(" ++ show (dcon, dcon_loc) ++ ")" ++ show freeVarToVarEnv -- Return (start,end) cursors -- The final return value lives at the position of the out cursors: @@ -1291,7 +1291,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let cur_ty = case l of Single _ -> CursorTy SoA _ fields -> CursorArrayTy (1 + length (fields)) - rnd' <- go freeVarToVarEnv tenv senv rnd + rnd' <- go freeVarToVarEnv' tenv senv rnd end_scalars_alloc <- gensym "end_scalars_alloc" (if not marker_added then LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation (sloc)) @@ -1300,7 +1300,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = go2 True fvarenv aft_dloc (Just d') aft_flocs rst _ | isScalarTy ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd -- get the location variable where the scalar must be written let floc_loc = case floc of Just l -> l @@ -1326,7 +1326,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Write a pointer to a vector VectorTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd -- get the location variable where the scalar must be written let floc_loc = case floc of Just l -> l @@ -1361,7 +1361,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- SoA case -- Fix case for indirection/shortcut pointers CursorTy -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd after_indirection <- gensym "aft_indirection" casted_var <- gensym "cast" let rnd_var = case rnd' of @@ -1370,7 +1370,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> LetE (d',[], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) <$> LetE (after_indirection,[], CursorTy, VarE d') <$> --Ext $ AddCursor aft_dloc (L3.LitE 8) - go2 marker_added freeVarToVarEnv after_indirection from_rec_end aft_flocs rst + go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty @@ -1393,8 +1393,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let additional_bnds = if present then [] else [(sloc_dcon, [], CursorTy, Ext $ IndexCursorArray sloc 0)] - (additional_bnds', freeVarToVarEnv', _) <- foldlM (\(b, env, idx') ((dcon, _), loc) -> do - (var_for_loc, present, env') <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of + (additional_bnds', freeVarToVarEnv'', _) <- foldlM (\(b, env, idx') ((_, _), loc) -> do + (var_for_loc, present', env') <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of Just v -> return $ (v, True, env) Nothing -> case loc of Single l -> return $ (l, False, env) @@ -1402,13 +1402,13 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = new_name <- gensym "field_cursor" let env'' = M.insert (fromLocVarToFreeVarsTy loc) new_name env return $ (new_name, False, env'') - let b' = if present + let b' = if present' then b else b ++ [(var_for_loc, [], CursorTy, Ext $ IndexCursorArray sloc idx')] pure (b', env', idx' + 1) - ) (additional_bnds, freeVarToVarEnv, 1) field_locs + ) (additional_bnds, freeVarToVarEnv', 1) field_locs dl <$> -- Make sure that the field locations and data locations are released here @@ -1420,7 +1420,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetE (end_tag_alloc,[],ProdTy [], Ext $ EndTagAllocation (sloc)) <$> LetE (start_scalars_alloc,[],ProdTy [], Ext $ StartScalarsAllocation (sloc)) <$> LetE (after_tag,[], CursorTy, Ext $ AddCursor (sloc_dcon) (L3.LitE 1)) <$> - go2 False freeVarToVarEnv' after_tag Nothing field_locs locs_tys + go2 False freeVarToVarEnv'' after_tag Nothing field_locs locs_tys -- go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> [((DataCon, Int), Location, (Exp2, Ty2))] -> [((DataCon, Int), Location, (Exp2, Ty2))] -> PassM Exp3 -- go2 False after_tag (zip args (lookupDataCon ddfs dcon)) diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index 2ffa4927c..3e8e6229d 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -535,12 +535,22 @@ inferExp' ddefs env exp bound dest= ) get_loc_keys dconLoc = LetLocE lv1 (AfterConstantLE 1 lv2) exprs' = [LetLocE lv2 (GetDataConLocSoA slv2)] ++ exprs ++ [dconLoc] - fieldLocExps = P.map (\c -> case c of - AfterConstantL lv1 v lv2 -> LetLocE lv1 (AfterConstantLE v lv2) - AfterVariableL lv1 v lv2 -> LetLocE lv1 (AfterVariableLE v lv2 True) - AssignL lv1 lv2 -> LetLocE lv1 (AssignLE lv2) - _ -> error "InferLocations : bindAllLocations : AfterSoALE: unexpected locatin constraint." - ) flst + (fieldLocExps, a') = L.foldl (\(acc, ba) c -> case c of + AfterConstantL lv1 v lv2 -> (acc ++ [LetLocE lv1 (AfterConstantLE v lv2)], ba) + AfterVariableL lv1 v lv2 -> (acc ++ [LetLocE lv1 (AfterVariableLE v lv2 True)], ba) + AssignL lv1 lv2 -> (acc ++ [LetLocE lv1 (AssignLE lv2)], ba) + AfterCopyL lv1 v1 v' lv2 f lvs -> + let arrty = arrOut $ lookupFEnv f env + -- Substitute the location occurring at the call site + -- in place of the one in the function's return type + copyRetTy = case arrty of + PackedTy _ loc -> substLoc (M.singleton loc lv2) arrty + _ -> error "bindAllLocations: Not a packed type" + a' = subst v1 (VarE v') a + bod = Ext $ (LetLocE lv1 (AfterVariableLE v' lv2 True) a') + in (acc, LetE (v',[],copyRetTy, AppE f lvs [VarE v1]) bod) + _ -> error $ "InferLocations : bindAllLocations : AfterSoALE: unexpected locatin constraint: " ++ show c + ) ([], a) flst --new_field_locs = P.foldr (\c accum -> case c of -- AfterConstantL lv1 v lv2 -> let flcs = (getFieldLocs slv2) -- -- This is wrong!! @@ -561,12 +571,13 @@ inferExp' ddefs env exp bound dest= exprs'' = exprs' ++ fieldLocExps ++ [LetLocE slv1 (GenSoALoc lv1 flcs')] -- [LetSoALocE slv1] lambda = (\lst base -> case lst of [] -> base - x:rst -> let rst' = lambda rst base - in Ext (x rst') - + x:rst -> let rst' = lambda rst base + in Ext $ x rst' ) + + - returned = lambda exprs'' a + returned = lambda exprs'' a' in dbgTrace minChatLvl " BindAllLocations: " dbgTrace minChatLvl (sdoc (get_loc_keys, returned)) dbgTrace minChatLvl "End bindAllLocations.\n" returned _ -> error "bindAllLocations: AfterSoALE: unexpected tag constraint." AfterConstantL lv1 v lv2 -> Ext (LetLocE lv1 (AfterConstantLE v lv2) a) @@ -644,26 +655,25 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = b3 <- notFixedLoc lv2' b3' <- notFixedLoc lv2' if b1 && b2 && b3 - then do cs' <- tryInRegion' fcs cs + then do cs' <- dbgTrace minChatLvl "tryInRegion' AfterSoAL: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2', fcs)) dbgTrace minChatLvl "End tryInRegion' AfterSoAL.\n" tryInRegion' fcs cs r <- getNewRegion lv2' let c' = StartRegionL lv2' r return (c':c:cs') - else do cs' <- tryInRegion' fcs cs + else do cs' <- dbgTrace minChatLvl "tryInRegion' AfterSoAL: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2', fcs)) dbgTrace minChatLvl "End tryInRegion' AfterSoAL.\n" tryInRegion' fcs cs return (c:cs') AfterTagL lv1 lv2 -> do lv1' <- finalLocVar lv1 lv2' <- finalLocVar lv2 b1 <- noBeforeLoc lv2' fcs b2 <- noRegionStart lv2' fcs - b3 <- notFixedLoc lv2' - -- dbgTrace minChatLvl "tryInRegion' aftertag: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2')) dbgTrace minChatLvl "End tryInRegion' afterTag.\n" + b3 <- notFixedLoc lv2 b3' <- notFixedLoc lv2' if b1 && b2 && b3 - then do cs' <- tryInRegion' fcs cs + then do cs' <- dbgTrace minChatLvl "tryInRegion' aftertag: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2')) dbgTrace minChatLvl "End tryInRegion' afterTag.\n" tryInRegion' fcs cs r <- lift $ lift $ freshRegVar let c' = StartRegionL lv2' r return (c':c:cs') - else do cs' <- tryInRegion' fcs cs + else do cs' <- dbgTrace minChatLvl "tryInRegion' aftertag: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2')) dbgTrace minChatLvl "End tryInRegion' afterTag.\n" tryInRegion' fcs cs return (c:cs') _ -> do cs' <- tryInRegion' fcs cs return (c:cs') @@ -1283,16 +1293,15 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = Single _ -> AfterConstantL loc_new 0 loc_old _ -> AssignL loc_new loc_old ) pair_new_old - - let soac = AfterSoAL hloc tagc (fieldConstraints ++ fieldConstraints' ++ fieldConstraints_unsed) d let afvarc = (mapMaybe afterVar $ zip3 dcArgDconBuf ((map Just rstlocs) ++ [Nothing]) (map Just locsDconBuf) ) + let soac = AfterSoAL hloc tagc (fieldConstraints ++ fieldConstraints' ++ fieldConstraints_unsed ++ afvarc) d -- , locsFields, fieldLocVarsAfter -- dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (argLsAfterSoALoc, locsFields, fieldLocVarsAfter, fieldConstraints')) dbgTrace minChatLvl "End line 1171\n" - dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (soac, fieldLocVarsAfter, idxsFields', ls', fieldConstraints', fieldConstraints, fieldConstraints_unsed)) dbgTrace minChatLvl "End line 1171\n" return ([tagc], [soac], afvarc) + dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (soac, fieldLocVarsAfter, idxsFields', afvarc, fieldConstraints', fieldConstraints, fieldConstraints_unsed)) dbgTrace minChatLvl "End line 1171\n" return ([tagc], [soac], afvarc) -- Generate the constraints around the field buffers. -- dbgTrace minChatLvl "Print tuple line: 1061" dbgTrace minChatLvl (sdoc (fieldLocVars, fieldConstraints)) dbgTrace minChatLvl "End line 1061\n" let constrs = concat $ [c | (_,_,c) <- ls'] diff --git a/gibbon-compiler/tests/test-gibbon-examples.yaml b/gibbon-compiler/tests/test-gibbon-examples.yaml index dc7478bf8..65807b57a 100644 --- a/gibbon-compiler/tests/test-gibbon-examples.yaml +++ b/gibbon-compiler/tests/test-gibbon-examples.yaml @@ -357,7 +357,7 @@ tests: dir: examples answer-file: examples/test_printpacked.ans # gibbon3 and gibbon2: Inferlocations bug. - failing: [interp1,gibbon1,pointer, colobus1, colobus2, colobus3] + failing: [interp1,gibbon1,pointer, colobus1, colobus2] ## FAILING: Multiple packed outputs. - name: TupleTest.hs From d52c8f1ccdd3ea551dffe3895c207240b596b247 Mon Sep 17 00:00:00 2001 From: vidush Date: Wed, 24 Sep 2025 21:39:53 -0400 Subject: [PATCH 21/60] wip : fixing abs ran access --- .../examples/soa_examples/MonoTree.hs | 7 +- gibbon-compiler/src/Gibbon/Common.hs | 4 +- gibbon-compiler/src/Gibbon/Compiler.hs | 36 ++-- gibbon-compiler/src/Gibbon/L0/Specialize2.hs | 5 +- gibbon-compiler/src/Gibbon/L2/Syntax.hs | 15 +- gibbon-compiler/src/Gibbon/L2/Typecheck.hs | 2 +- gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs | 4 +- gibbon-compiler/src/Gibbon/NewL2/Syntax.hs | 6 +- .../src/Gibbon/Passes/Cursorize.hs | 28 ++- .../src/Gibbon/Passes/InferLocations.hs | 189 +++++++++++++++--- .../src/Gibbon/Passes/RouteEnds.hs | 3 + .../src/Gibbon/Passes/ThreadRegions.hs | 10 +- .../src/Gibbon/Passes/ThreadRegions2.hs | 13 +- 13 files changed, 245 insertions(+), 77 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 48326ee86..34671d4ff 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -17,13 +17,18 @@ add1Tree t = Leaf x -> Leaf (x + 1) Node d x1 x2 -> Node (d + 1) (add1Tree x1) (add1Tree x2) +rightMost :: Tree -> Int +rightMost t = case t of + Leaf x -> x + Node d x1 x2 -> rightMost x2 + sumTree :: Tree -> Int sumTree tr = case tr of Leaf n -> n Node d l r -> d + (sumTree l) + (sumTree r) -gibbon_main = sumTree (mkTree 18) --sumTree (add1Tree (mkTree 18)) +gibbon_main = rightMost (mkTree 18) --sumTree (add1Tree (mkTree 18)) main :: IO () main = print gibbon_main diff --git a/gibbon-compiler/src/Gibbon/Common.hs b/gibbon-compiler/src/Gibbon/Common.hs index 7665ed54b..805f04f7b 100644 --- a/gibbon-compiler/src/Gibbon/Common.hs +++ b/gibbon-compiler/src/Gibbon/Common.hs @@ -568,11 +568,11 @@ getDconLoc loc = case loc of SoA dcon fieldLocs -> Single dcon Single lc -> loc -getFieldLoc :: (DataCon, FieldIndex) -> LocVar -> LocVar +getFieldLoc :: HasCallStack => (DataCon, FieldIndex) -> LocVar -> LocVar getFieldLoc (dcon, idx) loc = case loc of SoA _ fieldLocs -> case Prelude.lookup (dcon, idx) fieldLocs of Just loc -> loc - Nothing -> error "getFieldLoc : Field location not found!" + Nothing -> error $ "getFieldLoc : Field location not found!" ++ show (dcon, idx, loc) Single lc -> error "getFieldLoc : Did not expect a non SoA location!" getAllFieldLocsSoA :: LocVar -> [((DataCon, Int), LocVar)] diff --git a/gibbon-compiler/src/Gibbon/Compiler.hs b/gibbon-compiler/src/Gibbon/Compiler.hs index 7bef167cf..37fb93373 100644 --- a/gibbon-compiler/src/Gibbon/Compiler.hs +++ b/gibbon-compiler/src/Gibbon/Compiler.hs @@ -710,13 +710,13 @@ passes config@Config{dynflags} l0 = do l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- go "fixRANs" fixRANs l2 l2 <- goE2 "reorderLetExprs2" reorderLetExprs l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "L2.flatten" flattenL2 l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- if gibbon1 || no_rcopies then return l2 else do l2 <- go "removeCopies" removeCopies l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 return l2 l2 <- goE2 "inferEffects" inferEffects l2 @@ -751,9 +751,9 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. if gibbon1 || noRAN then do l2 <- goE2 "addTraversals" addTraversals l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "inferEffects2" inferEffects l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "repairProgram" (pure . id) l2 pure l2 else do @@ -768,28 +768,28 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. l2 <- goE2 "reorderLetExprs3" reorderLetExprs l2 l2 <- go "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- go "fixRANs" fixRANs l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- go "regionsInwards" regionsInwards l2 l2 <- go "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- goE2 "+" reorderLetExprs l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 -- VS : This pass is causing a bug --l2 <- go "L2.flatten" flattenL2 l2 l2 <- go "findWitnesses" findWitnesses l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "L2.flatten" flattenL2 l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- if no_rcopies then return l2 else do l2 <- goE2 "removeCopies" removeCopies l2 return l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "inferEffects2" inferEffects l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "addTraversals" addTraversals l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "repairProgram" (pure . id) l2 pure l2 @@ -805,20 +805,20 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. then pure l2 else goE2 "parAlloc" parAlloc l2 lift $ dumpIfSet config Opt_D_Dump_ParAlloc (pprender l2) - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "inferRegScope" inferRegScope l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- go "writeOrderMarkers" writeOrderMarkers l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "routeEnds" routeEnds l2 l2 <- goE2 "L2.flatten" flattenL2 l2 l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- goE2 "reorderLetExprs4" reorderLetExprs l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- go "inferFunAllocs" inferFunAllocs l2 - l2 <- go "L2.typecheck" L2.tcProg l2 + --l2 <- go "L2.typecheck" L2.tcProg l2 -- L2 program no longer typechecks while these next passes run {- VS: The Argument to simplify loc binds used to be False, why doesn't true work ? -} l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 diff --git a/gibbon-compiler/src/Gibbon/L0/Specialize2.hs b/gibbon-compiler/src/Gibbon/L0/Specialize2.hs index 103dd9b7c..de3ca9aa0 100644 --- a/gibbon-compiler/src/Gibbon/L0/Specialize2.hs +++ b/gibbon-compiler/src/Gibbon/L0/Specialize2.hs @@ -1568,10 +1568,11 @@ addRepairFns (Prog dfs fds me) = do newFns <- concat <$> mapM (\d -> do copy_fn <- genCopyFn d - copy2_fn <- genCopySansPtrsFn d + -- copy2_fn <- genCopySansPtrsFn d trav_fn <- genTravFn d print_fn <- genPrintFn d - return [copy_fn, copy2_fn, trav_fn, print_fn]) + -- copy2_fn + return [copy_fn, trav_fn, print_fn]) (filter (not . isVoidDDef) (M.elems dfs)) let fds' = fds `M.union` (M.fromList $ map (\f -> (funName f, f)) newFns) pure $ Prog dfs fds' me diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index 6489bc66f..a0b35101f 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -187,7 +187,7 @@ data E2Ext loc dec | StartOfPkdCursor Var -- Cursor to a packed value, created by AddRAN. - | TagCursor Var Var -- Create a tagged cursor. + | TagCursor loc loc -- Create a tagged cursor. | GetCilkWorkerNum -- ^ Translates to __cilkrts_get_worker_number(). @@ -253,7 +253,7 @@ instance FreeVars (E2Ext l d) where `S.union` gFreeVars bod StartOfPkdCursor cur -> S.singleton cur - TagCursor a b -> S.fromList [a,b] + TagCursor _ _ -> S.empty RetE _ vr -> S.singleton vr FromEndE _ -> S.empty AddFixed vr _ -> S.singleton vr @@ -900,7 +900,7 @@ revertExp ex = LetParRegionE _ _ _ bod -> revertExp bod LetLocE _ _ bod -> revertExp bod StartOfPkdCursor cur -> Ext (L1.StartOfPkdCursor cur) - TagCursor a _b -> Ext (L1.StartOfPkdCursor a) + TagCursor a _b -> error "revertExp: Cannot revert TagCursor!" --Ext (L1.StartOfPkdCursor a) RetE _ v -> VarE v AddFixed{} -> error "revertExp: TODO AddFixed." FromEndE{} -> error "revertExp: TODO FromEndLE" @@ -968,7 +968,7 @@ occurs w ex = FromEndLE{} -> oc_bod _ -> oc_bod StartOfPkdCursor v -> v `S.member` w - TagCursor a b -> a `S.member` w || b `S.member` w + TagCursor a b -> False --a `S.member` w || b `S.member` w RetE _ v -> v `S.member` w FromEndE{} -> False BoundsCheck{} -> False @@ -1111,7 +1111,10 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty SSPush{} -> acc SSPop{} -> acc StartOfPkdCursor w -> go acc (VarE w) - TagCursor a b -> go (go acc (VarE a)) (VarE b) + TagCursor a b -> let + acc' = M.insertWith (++) (fromLocVarToFreeVarsTy a) [fromLocVarToFreeVarsTy a] acc + acc'' = M.insertWith (++) (fromLocVarToFreeVarsTy b) [fromLocVarToFreeVarsTy b] acc' + in acc'' dep :: PreLocExp LocVar -> [FreeVarsTy] dep ex = @@ -1164,7 +1167,7 @@ allFreeVars ex = vars_locexp = S.map fromVarToFreeVarsTy (gFreeVars locexp) in S.delete (fromLocVarToFreeVarsTy loc) (allFreeVars bod `S.union` locs_locexp `S.union` vars_locexp) StartOfPkdCursor cur -> S.singleton (V cur) - TagCursor a b -> S.fromList [V a, V b] + TagCursor a b -> S.fromList [FL a, FL b] RetE locs v -> S.insert (V v) (S.fromList (map fromLocVarToFreeVarsTy locs)) FromEndE loc -> S.singleton (fromLocVarToFreeVarsTy loc) BoundsCheck _ reg cur -> S.fromList [(fromLocVarToFreeVarsTy reg),(fromLocVarToFreeVarsTy cur)] diff --git a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs index 6befbc6ef..cc008ba61 100644 --- a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs @@ -901,7 +901,7 @@ tcExp ddfs env funs constrs regs tstatein exp = ty -> throwError $ GenericTC ("Expected PackedTy, got " ++ sdoc ty) exp Ext (TagCursor a _b) -> do - case M.lookup (fromVarToFreeVarsTy a) (vEnv env) of + case M.lookup (fromLocVarToFreeVarsTy a) (vEnv env) of Just (PackedTy{}) -> pure (CursorTy, tstatein) ty -> throwError $ GenericTC ("Expected PackedTy, got " ++ sdoc ty) exp diff --git a/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs b/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs index 7c6d837cd..b1a2981f1 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs @@ -195,7 +195,7 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = AddFixed v i -> pure $ Ext $ AddFixed v i - TagCursor a b -> pure $ Ext $ TagCursor a b + TagCursor a b -> pure $ Ext $ TagCursor (locenv # a) (locenv # b) StartOfPkdCursor cur -> pure $ Ext $ StartOfPkdCursor cur @@ -397,7 +397,7 @@ toOldL2Exp ex = pure $ Ext $ StartOfPkdCursor cur TagCursor a b -> do - pure $ Ext $ TagCursor a b + pure $ Ext $ TagCursor (New.toLocVar a) (New.toLocVar b) RetE locs v -> do let locargs = map New.toLocVar locs diff --git a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs index 760af6671..6d6da2d46 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs @@ -464,7 +464,7 @@ revertExp ex = Old.LetRegionE _ _ _ bod -> revertExp bod Old.LetParRegionE _ _ _ bod -> revertExp bod Old.LetLocE _ _ bod -> revertExp bod - Old.TagCursor a _b -> Ext (L1.StartOfPkdCursor a) + Old.TagCursor a _b -> error "revertExp cannot revert TagCursor" --Ext (L1.StartOfPkdCursor a) Old.StartOfPkdCursor v -> Ext (L1.StartOfPkdCursor v) Old.RetE _ v -> VarE v Old.AddFixed{} -> error "revertExp: TODO AddFixed." @@ -552,7 +552,7 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty Old.SSPush{} -> acc Old.SSPop{} -> acc Old.StartOfPkdCursor cur -> M.insertWith (++) (fromVarToFreeVarsTy cur) [(fromVarToFreeVarsTy cur)] acc - Old.TagCursor a b -> M.insertWith (++) (fromVarToFreeVarsTy b) [(fromVarToFreeVarsTy b)] (M.insertWith (++) (fromVarToFreeVarsTy a) [(fromVarToFreeVarsTy a)] acc) + Old.TagCursor a b -> acc --M.insertWith (++) (fromVarToFreeVarsTy b) [(fromVarToFreeVarsTy b)] (M.insertWith (++) (fromVarToFreeVarsTy a) [(fromVarToFreeVarsTy a)] acc) dep :: Old.PreLocExp LocArg -> [FreeVarsTy] dep ex = @@ -589,7 +589,7 @@ allFreeVars ex = Old.LetParRegionE r _ _ bod -> S.delete ((fromRegVarToFreeVarsTy . Old.regionToVar) r) (allFreeVars bod) Old.LetLocE loc locexp bod -> S.difference ((S.singleton . fromLocVarToFreeVarsTy) loc) (allFreeVars bod `S.union` (S.map fromVarToFreeVarsTy $ gFreeVars locexp)) Old.StartOfPkdCursor v -> S.singleton (fromVarToFreeVarsTy v) - Old.TagCursor a b-> S.fromList [(fromVarToFreeVarsTy a),(fromVarToFreeVarsTy b)] + Old.TagCursor a b-> S.fromList [((fromLocVarToFreeVarsTy . toLocVar) a),((fromLocVarToFreeVarsTy . toLocVar) b)] Old.RetE locs v -> S.insert (fromVarToFreeVarsTy v) (S.fromList (map (fromLocVarToFreeVarsTy . toLocVar) locs)) Old.FromEndE loc -> S.singleton ((fromLocVarToFreeVarsTy . toLocVar) loc) Old.BoundsCheck _ reg cur -> S.fromList (map (fromLocVarToFreeVarsTy . toLocVar) [reg, cur]) diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 4abd16e75..343c0e7c7 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -678,7 +678,19 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = StartOfPkdCursor cur -> return (VarE cur) - TagCursor a b -> return $ Ext $ L3.TagCursor a b + TagCursor a b -> do + let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar a) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let b_var = case (M.lookup (fromRegVarToFreeVarsTy ((fromLocVarToRegVar . toLocVar) b)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar b) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + + return $ Ext $ L3.TagCursor a_var b_var -- All locations are transformed into cursors here. Location arithmetic -- is expressed in terms of corresponding cursor operations. @@ -1538,7 +1550,19 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = StartOfPkdCursor cur -> return $ dl $ VarE cur - TagCursor a b -> return $ dl $ Ext $ L3.TagCursor a b + TagCursor a b -> do + let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar a) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let b_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar b)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar b) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + + return $ dl $ Ext $ L3.TagCursor a_var b_var -- ASSUMPTION: RetE forms are inserted at the tail position of functions, -- and we safely just return ends-witnesses & ends of the dilated expressions diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index 3e8e6229d..3de844d78 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -193,6 +193,26 @@ getSoARegionFromLocVar loc = do let region = SoAR (VarR (dcRegionVariable)) fieldRegions return region + +filterRanDcons :: [DataCon] -> [DataCon] +filterRanDcons dcons = let to_ignore = map (\dcon -> if L.isSuffixOf "^" dcon + then Just $ init dcon + else Nothing + ) dcons + ignored_set = catMaybes to_ignore + buffered_dcon = map (\dcon -> if L.elem dcon ignored_set then Nothing else Just dcon) dcons + in catMaybes buffered_dcon + +filterRanDatacons :: [(DataCon, [(IsBoxed, a)])] -> [(DataCon, [(IsBoxed, a)])] +filterRanDatacons dcons = let to_ignore = map (\(dcon, ty) -> if L.isSuffixOf "^" dcon + then Just $ init dcon + else Nothing + ) dcons + ignored_set = catMaybes to_ignore + buffered_dcon = map (\(dcon, ty) -> if L.elem dcon ignored_set then Nothing else Just (dcon, ty)) dcons + in catMaybes buffered_dcon + + convertTy :: DDefs1 -> Bool -> Ty1 -> PassM Ty2 convertTy ddefs useSoA ty = case useSoA of False -> traverse (const (freshLocVar "loc")) ty @@ -200,11 +220,8 @@ convertTy ddefs useSoA ty = case useSoA of PackedTy tycon _ -> do dconBuff <- freshLocVar "loc" let dcons = getConOrdering ddefs tycon - -- let dcons' = concatMap (\dcon -> if ('^' `elem` dcon) - -- then [] - -- else [dcon] - -- ) dcons - locsForFields <- convertTyHelperSoAParent tycon ddefs dcons + let dcons' = filterRanDcons dcons + locsForFields <- convertTyHelperSoAParent tycon ddefs dcons' let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields dbgTrace minChatLvl "Print ty: " dbgTrace minChatLvl (sdoc (PackedTy tycon soaLocation)) dbgTrace minChatLvl "End ty.\n" return $ PackedTy tycon soaLocation _ -> traverse (const (freshLocVar "loc")) ty @@ -246,13 +263,13 @@ convertTyHelperSoAChild tycon ddefs dcon = do then return (flds, idx + 1) else do dconBuff <- freshLocVar "loc" - let dcons = getConOrdering ddefs tycon' + let dcons = filterRanDcons $ getConOrdering ddefs tycon' locsForFields <- convertTyHelperSoAParent tycon' ddefs dcons let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields return (flds ++ [((dcon, idx), soaLocation)], idx + 1) - - CursorTy -> return (flds, idx+1) - CursorArrayTy _ -> return (flds, idx+1) + -- For ran pointers, we are skipping making buffers for them. + CursorTy -> return (flds, idx + 1) + CursorArrayTy _ -> return (flds, idx + 1) _ -> do info <- convertTyHelperGetLocForField' dcon idx (show f) return (flds ++ [info], idx + 1) @@ -433,8 +450,8 @@ freshTyLocs ty ddefs = do --let newSoALoc = SoA (unwrapLocVar dbuf') rst' --return $ PackedTy tc newSoALoc dbuf' <- fresh - let dcons = getConOrdering ddefs tc - locsForFields <- lift $ lift $convertTyHelperSoAParent tc ddefs dcons + let dcons = filterRanDcons $ getConOrdering ddefs tc + locsForFields <- lift $ lift $ convertTyHelperSoAParent tc ddefs dcons let soaLocation = SoA (unwrapLocVar dbuf') locsForFields return $ PackedTy tc soaLocation Single _ -> do @@ -461,7 +478,7 @@ fixType_ ty = _ -> return () -- | get the field locs from the SoA locs -getFieldLocs :: LocVar -> [((DataCon, FieldIndex), LocVar)] +getFieldLocs :: HasCallStack => LocVar -> [((DataCon, FieldIndex), LocVar)] getFieldLocs loc = case loc of SoA dcon fieldLocs -> fieldLocs Single lc -> error $ "InferLocations : getFieldLocs : Did not expect a non SoA location!" ++ show loc @@ -506,7 +523,7 @@ inferExp' ddefs env exp bound dest= bindAllLocations (expr,ty,constrs) = return $ (expr',ty,[]) where constrs' = L.nub $ constrs expr' = foldr addLetLoc expr constrs' - addLetLoc i a = + addLetLoc i a = dbgTrace (minChatLvl) "Print constraints in bindAllLocation!" dbgTrace (minChatLvl) (sdoc constrs') dbgTrace (minChatLvl) "End in bindAllLocations!\n" case i of -- AfterSoALE (PreLocExp loc) [PreLocExp loc] loc -- TODO: This might need to better capture the handling of SoA location. @@ -520,7 +537,7 @@ inferExp' ddefs env exp bound dest= -- ) fieldConstrs -- in Ext (LetLocE lv1 (AfterVectorLE dataConExpression fieldLocExprs lv2) a) AfterSoAL slv1 dconConstr fieldConstrs slv2 -> case (dconConstr, fieldConstrs) of - (AfterTagL lv1 lv2, flst) -> -- First let use get all the locations from the fieldConstrs + (dconstr, flst) -> -- First let use get all the locations from the fieldConstrs let used_field_locs = P.map (\c -> case c of AfterConstantL lv1 v lv2 -> lv2 AfterVariableL lv1 v lv2 -> lv2 @@ -533,8 +550,11 @@ inferExp' ddefs env exp bound dest= ) (getFieldLocs slv2) exprs = P.map (\(key, l) -> LetLocE l (GetFieldLocSoA key slv2) ) get_loc_keys - dconLoc = LetLocE lv1 (AfterConstantLE 1 lv2) - exprs' = [LetLocE lv2 (GetDataConLocSoA slv2)] ++ exprs ++ [dconLoc] + (lv1, lv2, dconLoc) = case dconstr of + AfterTagL lv1 lv2 -> (lv1, lv2, LetLocE lv1 (AfterConstantLE 1 lv2)) + AfterConstantL lv1 i lv2 -> (lv1, lv2, LetLocE lv1 (AfterConstantLE i lv2)) + _ -> error "Not implemented!" + exprs' = [LetLocE (getDconLoc slv2) (GetDataConLocSoA slv2)] ++ exprs ++ [dconLoc] (fieldLocExps, a') = L.foldl (\(acc, ba) c -> case c of AfterConstantL lv1 v lv2 -> (acc ++ [LetLocE lv1 (AfterConstantLE v lv2)], ba) AfterVariableL lv1 v lv2 -> (acc ++ [LetLocE lv1 (AfterVariableLE v lv2 True)], ba) @@ -584,7 +604,11 @@ inferExp' ddefs env exp bound dest= AssignL lv1 lv2 -> Ext (LetLocE lv1 (AssignLE lv2) a) AfterVariableL lv1 v lv2 -> Ext (LetLocE lv1 (AfterVariableLE v lv2 True) a) StartRegionL lv r -> Ext (LetRegionE r Undefined Nothing (Ext (LetLocE lv (StartOfRegionLE r) a))) - AfterTagL lv1 lv2 -> Ext (LetLocE lv1 (AfterConstantLE 1 lv2) a) {- VS: I think it may be fine to hardcode [] since AfterTagL is reserved for a Tag loc?-} + AfterTagL lv1 lv2 -> case lv2 of + Single{} -> Ext (LetLocE lv1 (AfterConstantLE 1 lv2) a) + SoA dloc flds -> let get_dcon_loc = LetLocE (Single dloc) (GetDataConLocSoA lv2) + after_tag_let = LetLocE lv1 (AfterConstantLE 1 (Single dloc)) + in Ext (get_dcon_loc (Ext $ after_tag_let a)) FreeL lv -> Ext (LetLocE lv FreeLE a) AfterCopyL lv1 v1 v' lv2 f lvs -> let arrty = arrOut $ lookupFEnv f env @@ -1146,7 +1170,10 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = argLs <- forM [a | (a,_,_) <- ls'] $ \arg -> case arg of (VarE v) -> case lookupVEnv v env of - CursorTy -> return $ ArgFixed 0 + -- both, cursor array and cursorArrty + -- are reserved for shortcut pointers + CursorTy -> return $ ArgFixed 8 + CursorArrayTy{} -> return $ ArgFixed 8 --CursorTy -> return $ ArgFixed 8 IntTy -> return $ ArgFixed 0 --IntTy -> return $ ArgFixed (fromJust $ sizeOfTy IntTy) @@ -1190,9 +1217,12 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = afterVar _ = Nothing -- dbgTrace minChatLvl "Print DataConE SoA case argsLs: " dbgTrace minChatLvl (sdoc (d, argLs, newLocs)) dbgTrace minChatLvl "End DataConE SoA case argLs.\n" let dataBufferLoc = Single dataBufferVar + -- VS: September 24th, 2025 -- Some locs need to be sequentialized with respect to the -- data contructor buffer. These are the recursive fields, - -- the same datatype. + -- the same datatype. + -- In addition, we want the random access pointers to reside + -- inside the data constructor buffer as well. (idxsWriteDconBuf, idxsFields) = L.foldr (\(res@(_, ty, _), idx) (w, f) -> case ty of PackedTy tycon _ -> if tycon == tyConOfDataCon then (w ++ [Just idx], f) @@ -1235,12 +1265,22 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = (fieldLocVars) ) -- AfterTagConstraints - (aftagc, sc, aftvarc) <- case locsDconBuf of + (shortcut_ptr_ctrs, locsDconBuf') = foldl (\(s, dcs) l -> case l of + Single{} -> (s ++ [l], dcs) + SoA{} -> (s, dcs ++ [l]) + ) ([], []) locsDconBuf + (shortcut_ptr_dcargs, dcArgDconBuf') = foldl (\(s, dcs) (l, arg) -> case l of + Single{} -> (s ++ [arg], dcs) + SoA{} -> (s, dcs ++ [arg]) + ) ([], []) (zip locsDconBuf dcArgDconBuf) + + (aftagc, sc, aftvarc) <- case (shortcut_ptr_ctrs, locsDconBuf') of -- No recursion in the data type -- dbgTrace minChatLvl "Found a DataConE with no recursion." dbgTrace minChatLvl (sdoc (k)) dbgTrace minChatLvl "End line 1134.\n" - [] -> do + ([], []) -> do return ([],fieldConstraints, []) - hloc:rstlocs -> do + (sptrs, []) -> error "TODO: add constraints for all the shotcut pointers!\n" + ([], hloc:rstlocs) -> do let tagc = AfterTagL (getDconLoc hloc) (getDconLoc d) let fieldLocVarsAfter = P.map (\(Just idx) -> let fldloc = lookup (k, idx) (getFieldLocs hloc) in case fldloc of @@ -1293,15 +1333,95 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = Single _ -> AfterConstantL loc_new 0 loc_old _ -> AssignL loc_new loc_old ) pair_new_old + + let soac = AfterSoAL hloc tagc (fieldConstraints ++ fieldConstraints' ++ fieldConstraints_unsed) d let afvarc = (mapMaybe afterVar $ zip3 - dcArgDconBuf + dcArgDconBuf' ((map Just rstlocs) ++ [Nothing]) - (map Just locsDconBuf) + (map Just locsDconBuf') ) - let soac = AfterSoAL hloc tagc (fieldConstraints ++ fieldConstraints' ++ fieldConstraints_unsed ++ afvarc) d -- , locsFields, fieldLocVarsAfter -- dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (argLsAfterSoALoc, locsFields, fieldLocVarsAfter, fieldConstraints')) dbgTrace minChatLvl "End line 1171\n" - dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (soac, fieldLocVarsAfter, idxsFields', afvarc, fieldConstraints', fieldConstraints, fieldConstraints_unsed)) dbgTrace minChatLvl "End line 1171\n" return ([tagc], [soac], afvarc) + dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (soac, fieldLocVarsAfter, idxsFields', ls', fieldConstraints', fieldConstraints, fieldConstraints_unsed)) dbgTrace minChatLvl "End line 1171\n" return ([tagc], [soac], afvarc) + + (sptrs, hloc:rstlocs) -> do + -- make after tag constraint for the first + let first_shortcut = Sf.headErr sptrs + let tail_shortcut = tail sptrs + let last_shortcut = last sptrs + let tagc_shortcut_first_c = AfterTagL (first_shortcut) d + let fields_d = getFieldLocs d + -- let after_shortcut_soa = SoA (unwrapLocVar last_shortcut) fields_d + let constratints_short_cut_rst = (mapMaybe afterVar $ zip3 + shortcut_ptr_dcargs + ((map Just tail_shortcut) ++ [Nothing]) + (map Just sptrs) + ) + + -- let after_shortcut_all_dcon = AfterConstantL last_shortcut (8 * length sptrs) (getDconLoc d) + -- let after_shorcut_constr = AfterSoAL after_shortcut_soa after_shortcut_all_dcon [] d + + -- The tag constraint will change to an after constant constraint + let tagc = AfterConstantL (getDconLoc hloc) (8) (last_shortcut) + let fieldLocVarsAfter = P.map (\(Just idx) -> let fldloc = lookup (k, idx) (getFieldLocs hloc) + in case fldloc of + Just location -> Just location + Nothing -> error $ "inferExp: fieldLocVars did not expect Nothing! Datacon: " ++ k ++ "," ++ show idxsFields' ++ ", fieldLocs: " ++ show (hloc, locs, (getFieldLocs hloc), DataConE () k ls) + ) idxsFields' + argLsAfterSoALoc <- forM [a | (a,_,_) <- argsLsFields] $ \arg -> + case arg of + (VarE v) -> case lookupVEnv v env of + CursorTy -> return $ ArgFixed 8 + IntTy -> return $ ArgFixed (fromJust $ sizeOfTy IntTy) + FloatTy -> return $ ArgFixed (fromJust $ sizeOfTy FloatTy) + SymTy -> return $ ArgFixed (fromJust $ sizeOfTy SymTy) + BoolTy -> return $ ArgFixed (fromJust $ sizeOfTy BoolTy) + CharTy -> return $ ArgFixed (fromJust $ sizeOfTy CharTy) + VectorTy elt -> return $ ArgFixed (fromJust $ sizeOfTy (VectorTy elt)) + ListTy elt -> return $ ArgFixed (fromJust $ sizeOfTy (ListTy elt)) + PackedTy ttyy loccc -> return $ ArgVar v + --if ttyy == tyConOfDataCon + -- then return $ ArgVar v + -- else return $ ArgFixed 0 + _ -> return $ ArgVar v --error $ "inferExp: DataConE SoA: offset for type not implemented! var: " ++ show v + -- TODO: fix these to get the correct offset for an SoA loc. + (LitE _) -> return $ ArgFixed (fromJust $ sizeOfTy IntTy) + (FloatE _) -> return $ ArgFixed (fromJust $ sizeOfTy FloatTy) + (LitSymE _) -> return $ ArgFixed (fromJust $ sizeOfTy SymTy) + (PrimAppE MkTrue []) -> return $ ArgFixed (fromJust $ sizeOfTy BoolTy) + (PrimAppE MkFalse []) -> return $ ArgFixed (fromJust $ sizeOfTy BoolTy) + (AppE f lvs [(VarE v)]) -> do + v' <- lift $ lift $ freshLocVar "cpy" + return $ ArgCopy v (unwrapLocVar v') f lvs + _ -> err $ "Expected argument to be trivial, got " ++ (show arg) + let fieldConstraints' = (mapMaybe afterVar $ zip3 + argLsAfterSoALoc + ((fieldLocVarsAfter)) + (map Just locsFields) + ) + -- handle field of other data constructors in the final SoA loc passed to the recursive call. + let fields_hloc = getFieldLocs hloc + let pair_new_old = concatMap (\(ks@(dcon, idx), loc1) -> if dcon /= k + then + let loc2 = case (L.lookup (dcon, idx) fields_d) of + Just loc2 -> loc2 + Nothing -> error "inferExp: fieldLocVars did not expect Nothing!" + in [(ks, loc1, loc2)] + else [] + ) fields_hloc + let fieldConstraints_unsed = map (\(k, loc_new, loc_old) -> case loc_new of + Single _ -> AfterConstantL loc_new 0 loc_old + _ -> AssignL loc_new loc_old + ) pair_new_old + let afvarc = (mapMaybe afterVar $ zip3 + dcArgDconBuf' + ((map Just rstlocs) ++ [Nothing]) + (map Just locsDconBuf') + ) + let soac = AfterSoAL hloc tagc (fieldConstraints ++ fieldConstraints' ++ fieldConstraints_unsed ++ afvarc) d + -- , locsFields, fieldLocVarsAfter + -- dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (argLsAfterSoALoc, locsFields, fieldLocVarsAfter, fieldConstraints')) dbgTrace minChatLvl "End line 1171\n" + dbgTrace minChatLvl "Print tuple line: 1171" dbgTrace minChatLvl (sdoc (soac, fieldLocVarsAfter, idxsFields', afvarc, fieldConstraints', fieldConstraints, fieldConstraints_unsed)) dbgTrace minChatLvl "End line 1171\n" return ([tagc], [tagc_shortcut_first_c] ++ constratints_short_cut_rst ++ [soac], afvarc) -- Generate the constraints around the field buffers. -- dbgTrace minChatLvl "Print tuple line: 1061" dbgTrace minChatLvl (sdoc (fieldLocVars, fieldConstraints)) dbgTrace minChatLvl "End line 1061\n" let constrs = concat $ [c | (_,_,c) <- ls'] @@ -2365,6 +2485,9 @@ freshSoALocHelper ddefs tyvar lst = do newLoc <- freshSoALoc2 ddefs tyc let Just idx = L.elemIndex e flds return $ [((a, idx), newLoc)] + -- no new buffers for shortcut pointers + CursorTy -> return [] + CursorArrayTy{} -> return [] _ -> do newLoc <- fresh let Just idx = L.elemIndex e flds @@ -2377,7 +2500,8 @@ freshSoALoc2 :: DDefs Ty2 -> TyCon -> TiM LocVar freshSoALoc2 ddfs tyc = do -- let (tyc, (don, flds)) = lkp ddfs con let DDef{dataCons} = lookupDDef ddfs tyc - fields <- freshSoALocHelper ddfs tyc dataCons + let dataCons' = filterRanDatacons dataCons + fields <- freshSoALocHelper ddfs tyc dataCons' newdcLoc <- fresh return $ SoA (unwrapLocVar newdcLoc) fields @@ -2399,6 +2523,9 @@ freshSoALocHelper3 ddefs tyvar lst = do newLoc <- freshSoALoc3 "new" Nothing ddefs tyc --let Just idx = L.elemIndex e flds return $ [((a, idx), newLoc)] + -- shortcut pointers + CursorTy -> return [] + CursorArrayTy{} -> return [] _ -> do newLoc <- fresh --let Just idx = L.elemIndex e flds @@ -2411,7 +2538,8 @@ freshSoALoc3 :: Var -> Maybe DataCon -> DDefs Ty1 -> TyCon -> TiM LocVar freshSoALoc3 str (Just currDcon) ddfs tyc = do -- let (tyc, (don, flds)) = lkp ddfs con let DDef{dataCons} = lookupDDef ddfs tyc - let curr_dcon_info = L.lookup currDcon dataCons + let dataCons' = filterRanDatacons dataCons + let curr_dcon_info = L.lookup currDcon dataCons' in case curr_dcon_info of Nothing -> error "Expected data con information!" Just dinfo -> do @@ -2419,8 +2547,9 @@ freshSoALoc3 str (Just currDcon) ddfs tyc = do newdcLoc <- lift $ lift $ gensym str dbgTrace minChatLvl "Print in freshSoALoc3: " dbgTrace minChatLvl (sdoc (fields, currDcon, dinfo)) dbgTrace minChatLvl "End freshSoALoc3.\n" return $ SoA newdcLoc fields freshSoALoc3 str Nothing ddfs tyc = do - let DDef{dataCons} = lookupDDef ddfs tyc - fields <- freshSoALocHelper3 ddfs tyc dataCons + let DDef{dataCons} = lookupDDef ddfs tyc + let dataCons' = filterRanDatacons dataCons + fields <- freshSoALocHelper3 ddfs tyc dataCons' newdcLoc <- lift $ lift $ gensym str return $ SoA newdcLoc fields diff --git a/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs b/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs index 1e5ab3d92..8851f73a8 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs @@ -494,6 +494,9 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do else do return (eorr, ee, seen, bnds) -- PackedTy tycon _ -> return (eorr, ee, seen) + -- shortcut pointers.. + CursorTy -> return (eorr, ee, seen, bnds) + CursorArrayTy{} -> return (eorr, ee, seen, bnds) _ -> do let jump_loc = getFieldLoc (dc, idx) final_soa_loc -- let l2loc = l2 diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions.hs index 24e7fba64..ad79ef198 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions.hs @@ -446,14 +446,14 @@ threadRegionsExp ddefs fundefs fnLocArgs renv env2 lfenv rlocs_env wlocs_env pkd {-Unsafe : unwrapLocVar loc, semantics for L3 need to change-} Just reg -> do {-Undafe, what if this is an SoA region? Terrible hack-} - let reg' = case reg of - SingleR v -> v - SoARv _ _ -> error "threadRegionsExp: (StartOfPkdCursor) SoARv not implemented yet." + let end_reg = toEndVRegVar reg -- TagCursor's type is TagCuror Var Var -- This is too narrow to represent a SoA region at the moment. -- I also don't think this is used in the L2 IR atm. -- I but in case it is, then its type needs to be changed. - dbgTraceIt "Print TagCursor: " dbgTraceIt (sdoc(loc)) dbgTraceIt "End TagCursor\n" return $ Ext $ TagCursor (unwrapLocVar loc) (toEndV reg') + let locarg = NewL2.Loc (LREM loc reg end_reg Output) + let regarg = NewL2.EndOfReg reg Output end_reg + dbgTraceIt "Print TagCursor: " dbgTraceIt (sdoc(loc)) dbgTraceIt "End TagCursor\n" return $ Ext $ TagCursor (locarg) (regarg) Nothing -> error $ "threadRegionsExp: unbound " ++ sdoc (loc, pkd_env) @@ -854,7 +854,7 @@ allFreeVars_sans_datacon_args ex = LetParRegionE r _sz _ty bod -> S.delete (fromRegVarToFreeVarsTy $ regionToVar r) (allFreeVars_sans_datacon_args bod) LetLocE loc locexp bod -> S.delete (fromLocVarToFreeVarsTy loc) (allFreeVars_sans_datacon_args bod `S.union` (S.map fromVarToFreeVarsTy $ gFreeVars locexp)) StartOfPkdCursor cur -> S.singleton (fromVarToFreeVarsTy cur) - TagCursor a b-> S.fromList [fromVarToFreeVarsTy a, fromVarToFreeVarsTy b] + TagCursor a b-> S.fromList [(fromLocVarToFreeVarsTy . toLocVar) a, (fromLocVarToFreeVarsTy . toLocVar) b] RetE locs v -> S.insert (fromVarToFreeVarsTy v) (S.fromList (map (fromLocVarToFreeVarsTy . toLocVar) locs)) FromEndE loc -> S.singleton ((fromLocVarToFreeVarsTy . toLocVar) loc) BoundsCheck _ reg cur -> S.fromList [(fromLocVarToFreeVarsTy . toLocVar) reg, (fromLocVarToFreeVarsTy . toLocVar) cur] diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index ef8f16f86..218fec224 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -703,15 +703,18 @@ threadRegionsExp ddefs fundefs fnLocArgs renv env2 lfenv rlocs_env wlocs_env pkd case M.lookup loc pkd_env of {-Unsafe : unwrapLocVar loc, semantics for L3 need to change-} Just reg -> do + let end_reg = toEndVRegVar reg {-Undafe, what if this is an SoA region? Terrible hack-} - let reg' = case reg of - SingleR v -> v - SoARv _ _ -> error "threadRegionsExp: (StartOfPkdCursor) SoARv not implemented yet." + --let reg' = case reg of + -- SingleR v -> v + -- SoARv _ _ -> error "threadRegionsExp: (StartOfPkdCursor) SoARv not implemented yet." -- TagCursor's type is TagCuror Var Var -- This is too narrow to represent a SoA region at the moment. -- I also don't think this is used in the L2 IR atm. -- I but in case it is, then its type needs to be changed. - dbgTrace (minChatLvl) "Print TagCursor: " dbgTrace (minChatLvl) (sdoc (loc)) dbgTrace (minChatLvl) "End TagCursor\n" return $ Ext $ TagCursor (unwrapLocVar loc) (toEndV reg') + let locarg = NewL2.Loc (LREM loc reg end_reg Output) + let regarg = NewL2.EndOfReg reg Output end_reg + dbgTrace (minChatLvl) "Print TagCursor: " dbgTrace (minChatLvl) (sdoc (loc)) dbgTrace (minChatLvl) "End TagCursor\n" return $ Ext $ TagCursor (locarg) (regarg) Nothing -> error $ "threadRegionsExp: unbound " ++ sdoc (loc, pkd_env) -- Sometimes, this expression can have RetE forms. We should collect and update @@ -1248,7 +1251,7 @@ allFreeVars_sans_datacon_args ex = LetParRegionE r _sz _ty bod -> S.delete (fromRegVarToFreeVarsTy $ regionToVar r) (allFreeVars_sans_datacon_args bod) LetLocE loc locexp bod -> S.delete (fromLocVarToFreeVarsTy loc) (allFreeVars_sans_datacon_args bod `S.union` (S.map fromVarToFreeVarsTy $ gFreeVars locexp)) StartOfPkdCursor cur -> S.singleton (fromVarToFreeVarsTy cur) - TagCursor a b -> S.fromList [fromVarToFreeVarsTy a, fromVarToFreeVarsTy b] + TagCursor a b -> S.fromList [(fromLocVarToFreeVarsTy . toLocVar) a, (fromLocVarToFreeVarsTy . toLocVar) b] RetE locs v -> S.insert (fromVarToFreeVarsTy v) (S.fromList (map (fromLocVarToFreeVarsTy . toLocVar) locs)) FromEndE loc -> S.singleton ((fromLocVarToFreeVarsTy . toLocVar) loc) BoundsCheck _ reg cur -> S.fromList [(fromLocVarToFreeVarsTy . toLocVar) reg, (fromLocVarToFreeVarsTy . toLocVar) cur] From 967741e1b50253ae8ebafbf99e94b08ff33c0786 Mon Sep 17 00:00:00 2001 From: vidush Date: Thu, 25 Sep 2025 14:56:18 -0400 Subject: [PATCH 22/60] wip --- .../src/Gibbon/Passes/Cursorize.hs | 5939 +++++++++-------- 1 file changed, 3256 insertions(+), 2683 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 343c0e7c7..e019f56af 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1,23 +1,29 @@ -module Gibbon.Passes.Cursorize - (cursorize) where +module Gibbon.Passes.Cursorize (cursorize) where -import Control.Monad (forM) +import Control.Monad (forM) +import Data.Foldable (foldlM, foldrM) import qualified Data.List as L import qualified Data.Map as M -import Data.Maybe (fromJust, listToMaybe) -import Text.PrettyPrint.GenericPretty -import Data.Foldable ( foldlM, foldrM ) - -import Gibbon.DynFlags -import Gibbon.Common -import Gibbon.NewL2.Syntax -import Gibbon.L3.Syntax hiding ( BoundsCheck, RetE, GetCilkWorkerNum, LetAvail, - AllocateTagHere, AllocateScalarsHere, SSPush, SSPop, - TagCursor ) -import qualified Gibbon.L3.Syntax as L3 -import Gibbon.Passes.AddRAN ( numRANsDataCon ) +import Data.Maybe (fromJust, listToMaybe) import Data.Set (Set) -import GHC.RTS.Flags (MiscFlags(generateCrashDumpFile)) +import GHC.RTS.Flags (MiscFlags (generateCrashDumpFile)) +import Gibbon.Common +import Gibbon.DynFlags +import Gibbon.L3.Syntax hiding + ( AllocateScalarsHere, + AllocateTagHere, + BoundsCheck, + GetCilkWorkerNum, + LetAvail, + RetE, + SSPop, + SSPush, + TagCursor, + ) +import qualified Gibbon.L3.Syntax as L3 +import Gibbon.NewL2.Syntax +import Gibbon.Passes.AddRAN (numRANsDataCon) +import Text.PrettyPrint.GenericPretty {- @@ -41,9 +47,8 @@ context. When the type of the current expression satisfies `hasPacked`, that's when we're in packed context. And, when in packed context, we return dilated values. - E.g. - + type Tree = Leaf Int | Node Tree Tree add1 :: Tree -> Tree @@ -73,13 +78,13 @@ for every packed type in the return value. Every packed return value becomes a if the functions "traverses" it's input (more details in the paer). [VS] - -- SoA representation + -- SoA representation -- char* type Cursor = Ptr Char - type CursorArray_${Int} = Cursor[Int] + type CursorArray_${Int} = Cursor[Int] CursorArray_2 = {Cursor, Cursor} - where: + where: CursorArray_2[0] = tag buffer cursor CursorArray_2[1] = integer buffer cursor (Leaf) @@ -94,7 +99,6 @@ if the functions "traverses" it's input (more details in the paer). Node -> ... -} - -- | Track variables depending on location variables. -- -- If we have to create binding of the form `let v = loc` (in case expressions for example), @@ -102,49 +106,50 @@ if the functions "traverses" it's input (more details in the paer). -- This is a stupid/simple way to get rid of FindWitnesses. -- See `FindWitnesses.hs` for why that is needed. -- For both locs and regions -type DepEnv = M.Map FreeVarsTy [(Var,[()],Ty3,Exp3)] +type DepEnv = M.Map FreeVarsTy [(Var, [()], Ty3, Exp3)] -- | Things we cannot define until we see a join point. There's a Ty2 to so that -- we can extend the environment. -type SyncEnv = M.Map Var [(Var,[()],Ty3,Ty2,Exp3)] +type SyncEnv = M.Map Var [(Var, [()], Ty3, Ty2, Exp3)] type OldTy2 = UrTy LocVar data WindowIntoCursor = AoSWin Var | SoAWin Var [((DataCon, Int), Var)] --- | cursorize :: Prog2 -> PassM Prog3 -cursorize Prog{ddefs,fundefs,mainExp} = do +cursorize Prog {ddefs, fundefs, mainExp} = do dflags <- getDynFlags let useSoA = gopt Opt_Packed_SoA dflags fns' <- mapM (cursorizeFunDef useSoA ddefs fundefs . snd) (M.toList fundefs) let fundefs' = M.fromList $ L.map (\f -> (funName f, f)) fns' - ddefs' = M.map eraseLocMarkers ddefs + ddefs' = M.map eraseLocMarkers ddefs - {- VS: TODO: Ensure that the map passed to these functions contains the correct values, rn just passing empty maps -} + {- VS: TODO: Ensure that the map passed to these functions contains the correct values, rn just passing empty maps -} mainExp' <- case mainExp of - Nothing -> return Nothing - Just (e,ty) -> do - if hasPacked (unTy2 ty) - then Just . (, stripTyLocs (unTy2 ty)) <$> - fromDi <$> cursorizePackedExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e - else Just . (,stripTyLocs (unTy2 ty)) <$> - cursorizeExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e + Nothing -> return Nothing + Just (e, ty) -> do + if hasPacked (unTy2 ty) + then + Just . (,stripTyLocs (unTy2 ty)) + <$> fromDi + <$> cursorizePackedExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e + else + Just . (,stripTyLocs (unTy2 ty)) + <$> cursorizeExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e pure (Prog ddefs' fundefs' mainExp') -mangle :: [Var] -> Var +mangle :: [Var] -> Var mangle vars = toVar $ "mangle" ++ (L.foldr (\v acc -> acc ++ "_" ++ (fromVar v)) "" vars) --- | cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 -cursorizeFunDef useSoA ddefs fundefs FunDef{funName,funTy,funArgs,funBody,funMeta} = do - let inLocs = inLocVars funTy +cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do + let inLocs = inLocVars funTy outLocs = outLocVars funTy outRegs = outRegVars funTy - inRegs = inRegVars funTy - in_tys = arrIns funTy - out_ty = arrOut funTy - funTy' = cursorizeArrowTy useSoA funTy + inRegs = inRegVars funTy + in_tys = arrIns funTy + out_ty = arrOut funTy + funTy' = cursorizeArrowTy useSoA funTy -- [2019.03.04] CSK: the order of these new cursor/region arguments isn't -- intuitive and can be improved. @@ -158,108 +163,139 @@ cursorizeFunDef useSoA ddefs fundefs FunDef{funName,funTy,funArgs,funBody,funMet freeVarToVarEnv = M.empty freeVarsInScope = (L.map fromLocVarToFreeVarsTy outCurBinds) ++ (L.map fromRegVarToFreeVarsTy regBinds) ++ (L.map fromVarToFreeVarsTy funArgs) ++ (L.map fromLocVarToFreeVarsTy inLocs) - -- freeVarToVarEnv' = L.foldr (\fv acc -> case fv of - -- V v -> M.insert fv v acc - -- FL l -> case l of - -- Single loc -> M.insert fv loc acc - -- SoA _ _ -> let name = mangle (varsInLocVar l) - -- in M.insert fv name acc - -- R r -> case r of - -- SingleR v -> M.insert fv v acc - -- SoARv _ _ -> let name = mangle (varsInRegVar r) - -- in M.insert fv name acc - -- ) freeVarToVarEnv freeVarsInScope - - freeVarToVarEnv' <- foldrM (\fv acc -> do - case fv of - V v -> return $ M.insert fv v acc - FL l -> case l of - Single loc -> return $ M.insert fv loc acc - SoA _ _ -> do - name <- gensym "cursor_ptr" - return $ M.insert fv name acc - R r -> case r of - SingleR v -> return $ M.insert fv v acc - SoARv _ _ -> do - name <- gensym "cursor_ptr" - return $ M.insert fv name acc - ) freeVarToVarEnv freeVarsInScope - - -- Then the input cursors. Bind an input cursor for every packed argument. + -- freeVarToVarEnv' = L.foldr (\fv acc -> case fv of + -- V v -> M.insert fv v acc + -- FL l -> case l of + -- Single loc -> M.insert fv loc acc + -- SoA _ _ -> let name = mangle (varsInLocVar l) + -- in M.insert fv name acc + -- R r -> case r of + -- SingleR v -> M.insert fv v acc + -- SoARv _ _ -> let name = mangle (varsInRegVar r) + -- in M.insert fv name acc + -- ) freeVarToVarEnv freeVarsInScope + + freeVarToVarEnv' <- + foldrM + ( \fv acc -> do + case fv of + V v -> return $ M.insert fv v acc + FL l -> case l of + Single loc -> return $ M.insert fv loc acc + SoA _ _ -> do + name <- gensym "cursor_ptr" + return $ M.insert fv name acc + R r -> case r of + SingleR v -> return $ M.insert fv v acc + SoARv _ _ -> do + name <- gensym "cursor_ptr" + return $ M.insert fv name acc + ) + freeVarToVarEnv + freeVarsInScope + + -- Then the input cursors. Bind an input cursor for every packed argument. let inCurBinds = case inLocs of - [] -> mkLets [] - _ -> - let projs = concatMap (\(e,t) -> mkInProjs e t) (zip (map VarE funArgs) in_tys) - bnds = zipWith (\loc proj -> let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected location variable" - packed_cursor_ty = case loc of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) - in (var_for_loc, [], packed_cursor_ty, proj) - ) inLocs projs -- [((unwrapLocVar loc),[],CursorTy,proj) | (loc,proj) <- zip inLocs projs] - in mkLets bnds - - initTyEnv = M.fromList $ (map (\(a,b) -> (a,MkTy2 (cursorizeInTy (unTy2 b)))) $ zip funArgs in_tys) ++ - (concatMap (\(LRM l r _) -> let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy l) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected location variable" - packed_cursor_ty = case l of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) - loc_entry = (var_for_loc, MkTy2 packed_cursor_ty) - var_for_reg = case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar $ regionToVar r)) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected region variable" - reg_entry = (var_for_reg, MkTy2 packed_cursor_ty) - in [loc_entry, reg_entry] - ) (locVars funTy) - ) - - initTyEnvl = M.fromList $ (map (\(a,b) -> case (unTy2 b) of - PackedTy _ l -> (a, Just l) - _ -> (a, Nothing) - - ) $ zip funArgs in_tys) ++ - (concatMap (\(LRM l r _) -> let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy l) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected location variable" - packed_cursor_ty = case l of - Single _ -> Just l - SoA _ fields -> Just l - loc_entry = (var_for_loc, packed_cursor_ty) - var_for_reg = case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar $ regionToVar r)) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected region variable" - reg_entry = (var_for_reg, packed_cursor_ty) - in [loc_entry, reg_entry] - ) (locVars funTy) - ) - - - funargs = (L.map (\r -> case (M.lookup (fromRegVarToFreeVarsTy r) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected region variable" - ) regBinds - ) ++ (L.map (\b -> case (M.lookup (fromLocVarToFreeVarsTy b) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected location variable" - ) outCurBinds) ++ (L.map (\v -> case (M.lookup (fromVarToFreeVarsTy v) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeFunDef: unexpected variable" - ) funArgs) - + [] -> mkLets [] + _ -> + let projs = concatMap (\(e, t) -> mkInProjs e t) (zip (map VarE funArgs) in_tys) + bnds = + zipWith + ( \loc proj -> + let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected location variable" + packed_cursor_ty = case loc of + Single _ -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length (fields)) + in (var_for_loc, [], packed_cursor_ty, proj) + ) + inLocs + projs -- [((unwrapLocVar loc),[],CursorTy,proj) | (loc,proj) <- zip inLocs projs] + in mkLets bnds + + initTyEnv = + M.fromList $ + (map (\(a, b) -> (a, MkTy2 (cursorizeInTy (unTy2 b)))) $ zip funArgs in_tys) + ++ ( concatMap + ( \(LRM l r _) -> + let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy l) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected location variable" + packed_cursor_ty = case l of + Single _ -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length (fields)) + loc_entry = (var_for_loc, MkTy2 packed_cursor_ty) + var_for_reg = case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar $ regionToVar r)) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected region variable" + reg_entry = (var_for_reg, MkTy2 packed_cursor_ty) + in [loc_entry, reg_entry] + ) + (locVars funTy) + ) + + initTyEnvl = + M.fromList $ + ( map + ( \(a, b) -> case (unTy2 b) of + PackedTy _ l -> (a, Just l) + _ -> (a, Nothing) + ) + $ zip funArgs in_tys + ) + ++ ( concatMap + ( \(LRM l r _) -> + let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy l) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected location variable" + packed_cursor_ty = case l of + Single _ -> Just l + SoA _ fields -> Just l + loc_entry = (var_for_loc, packed_cursor_ty) + var_for_reg = case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar $ regionToVar r)) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected region variable" + reg_entry = (var_for_reg, packed_cursor_ty) + in [loc_entry, reg_entry] + ) + (locVars funTy) + ) + + funargs = + ( L.map + ( \r -> case (M.lookup (fromRegVarToFreeVarsTy r) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected region variable" + ) + regBinds + ) + ++ ( L.map + ( \b -> case (M.lookup (fromLocVarToFreeVarsTy b) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected location variable" + ) + outCurBinds + ) + ++ ( L.map + ( \v -> case (M.lookup (fromVarToFreeVarsTy v) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeFunDef: unexpected variable" + ) + funArgs + ) + {- Get the regions out before hand, these can be eliminated later on -} - - bod <- if hasPacked (unTy2 out_ty) - then fromDi <$> cursorizePackedExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody - else cursorizeExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody + + bod <- + if hasPacked (unTy2 out_ty) + then fromDi <$> cursorizePackedExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody + else cursorizeExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody let bod' = inCurBinds bod fn = FunDef funName funargs funTy' bod' funMeta dbgTrace (minChatLvl) "Print in cursorizeFunDef: " dbgTrace (minChatLvl) (sdoc (initTyEnv, locVars funTy)) dbgTrace (minChatLvl) "End cursorizeFunDef\n" return fn - where - -- | The only difference between this and L3.cursorizeTy is that here, + -- \| The only difference between this and L3.cursorizeTy is that here, -- packed types are replaced by a single CursorTy instead of -- a tuple (CursorTy,CursorTy). This is because only `start` cursors are -- passed in for packed function arguments. @@ -267,461 +303,507 @@ cursorizeFunDef useSoA ddefs fundefs FunDef{funName,funTy,funArgs,funBody,funMet cursorizeInTy :: UrTy LocVar -> UrTy b cursorizeInTy ty = case ty of - IntTy -> IntTy - CharTy -> CharTy - FloatTy -> FloatTy - SymTy -> SymTy - BoolTy -> BoolTy + IntTy -> IntTy + CharTy -> CharTy + FloatTy -> FloatTy + SymTy -> SymTy + BoolTy -> BoolTy ProdTy ls -> ProdTy $ L.map cursorizeInTy ls SymDictTy ar _ty -> SymDictTy ar CursorTy PDictTy k v -> PDictTy (cursorizeInTy k) (cursorizeInTy v) - PackedTy _ l -> case l of - Single _ -> CursorTy - SoA _ fieldLocs -> CursorArrayTy (1 + (length fieldLocs)) + PackedTy _ l -> case l of + Single _ -> CursorTy + SoA _ fieldLocs -> CursorArrayTy (1 + (length fieldLocs)) VectorTy el_ty -> VectorTy $ cursorizeInTy el_ty ListTy el_ty -> ListTy $ cursorizeInTy el_ty PtrTy -> PtrTy - CursorTy -> CursorTy + CursorTy -> CursorTy CursorArrayTy size -> CursorArrayTy size - ArenaTy -> ArenaTy - SymSetTy -> SymSetTy + ArenaTy -> ArenaTy + SymSetTy -> SymSetTy SymHashTy -> SymHashTy IntHashTy -> IntHashTy -{- + {- -Build projections for packed values in the input type -This is used to create bindings for input location variables. + Build projections for packed values in the input type + This is used to create bindings for input location variables. - >>> mkInProjs e (PackedTy "T" "l") - [VarE (Var "funArg")] + >>> mkInProjs e (PackedTy "T" "l") + [VarE (Var "funArg")] - >>> mkInProjs e (ProdTy [IntTy,PackedTy "T" "l"]) - [ProjE 1 VarE (Var "funArg")] + >>> mkInProjs e (ProdTy [IntTy,PackedTy "T" "l"]) + [ProjE 1 VarE (Var "funArg")] - >>> mkInProje e (ProdTy [ProdTy [PackedTy "T" "l", PackedTy "T" "l"], IntTy]) - [ProjE 0 ProjE 0 e, ProjE 1 ProjE 0 e] + >>> mkInProje e (ProdTy [ProdTy [PackedTy "T" "l", PackedTy "T" "l"], IntTy]) + [ProjE 0 ProjE 0 e, ProjE 1 ProjE 0 e] - >>> mkInProje e (ProdTy [PackedTy "T" "l", - IntTy, - ProdTy [PackedTy "T" "l", - ProdTy [PackedTy "T" "l", PackedTy "T" "l"]]]) - [ProjE 0 e,ProjE 0 ProjE 2 e,ProjE 0 ProjE 1 ProjE 2 e,ProjE 1 ProjE 1 ProjE 2 e] + >>> mkInProje e (ProdTy [PackedTy "T" "l", + IntTy, + ProdTy [PackedTy "T" "l", + ProdTy [PackedTy "T" "l", PackedTy "T" "l"]]]) + [ProjE 0 e,ProjE 0 ProjE 2 e,ProjE 0 ProjE 1 ProjE 2 e,ProjE 1 ProjE 1 ProjE 2 e] --} + -} mkInProjs :: Exp3 -> Ty2 -> [Exp3] mkInProjs e0 ty0 = go [] e0 ty0 - where - go :: [Exp3] -> Exp3 -> Ty2 -> [Exp3] - go acc e ty = - case unTy2 ty of - PackedTy{} -> acc ++ [e] - ProdTy tys -> L.foldl (\acc2 (ty',n) -> go acc2 (mkProj n e) ty') - acc (zip (map MkTy2 tys) [0..]) - _ -> acc - - cursorizeArrowTy :: Bool -> ArrowTy2 Ty2 -> ([Ty3] , Ty3) - cursorizeArrowTy useSoA ty@ArrowTy2{arrIns,arrOut,locVars,locRets} = - let - -- Regions corresponding to ouput cursors. (See [Threading regions]) + where + go :: [Exp3] -> Exp3 -> Ty2 -> [Exp3] + go acc e ty = + case unTy2 ty of + PackedTy {} -> acc ++ [e] + ProdTy tys -> + L.foldl + (\acc2 (ty', n) -> go acc2 (mkProj n e) ty') + acc + (zip (map MkTy2 tys) [0 ..]) + _ -> acc + + cursorizeArrowTy :: Bool -> ArrowTy2 Ty2 -> ([Ty3], Ty3) + cursorizeArrowTy useSoA ty@ArrowTy2 {arrIns, arrOut, locVars, locRets} = + let -- Regions corresponding to ouput cursors. (See [Threading regions]) numOutRegs = length (outRegVars ty) - --outRegs = L.map (\_ -> CursorTy) [1..numOutRegs] - - outRegs = L.map (\r -> case r of - SingleR v -> CursorTy - SoARv dcr frs -> CursorArrayTy (1 + length frs) - ) (outRegVars ty) - - + -- outRegs = L.map (\_ -> CursorTy) [1..numOutRegs] + outRegs = + L.map + ( \r -> case r of + SingleR v -> CursorTy + SoARv dcr frs -> CursorArrayTy (1 + length frs) + ) + (outRegVars ty) -- Adding additional outputs corresponding to end-of-input-value witnesses -- We've already computed additional location return value in RouteEnds -- ret_curs = L.map (\_ -> CursorTy) locRets - ret_curs = L.map (\lret -> case lret of - EndOf (LRM l _ _) -> case l of - Single _ -> CursorTy - SoA dcl flocs -> CursorArrayTy (1 + length flocs) - - ) locRets + ret_curs = + L.map + ( \lret -> case lret of + EndOf (LRM l _ _) -> case l of + Single _ -> CursorTy + SoA dcl flocs -> CursorArrayTy (1 + length flocs) + ) + locRets out_curs = inRegs ++ outRegs ++ ret_curs out_ty = case out_curs of - [] -> unTy2 arrOut - _ -> ProdTy $ out_curs ++ [unTy2 arrOut] + [] -> unTy2 arrOut + _ -> ProdTy $ out_curs ++ [unTy2 arrOut] -- Packed types in the output then become end-cursors for those same destinations. - newOut = mapPacked (\var loc -> case loc of - Single _ -> ProdTy [CursorTy, CursorTy] - SoA _ fields -> ProdTy [CursorArrayTy (1 + length fields), CursorArrayTy (1 + length fields)] - - ) out_ty + newOut = + mapPacked + ( \var loc -> case loc of + Single _ -> ProdTy [CursorTy, CursorTy] + SoA _ fields -> ProdTy [CursorArrayTy (1 + length fields), CursorArrayTy (1 + length fields)] + ) + out_ty newOut' = case newOut of - SymDictTy a _ -> SymDictTy a CursorTy - _ -> newOut + SymDictTy a _ -> SymDictTy a CursorTy + _ -> newOut -- Adding additional input arguments for the destination cursors to which outputs -- are written. - outCurs = filter (\(LRM _ _ m) -> m == Output) locVars - outCurTys = map (\(LRM l _ _) -> case l of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) - ) outCurs - inRegs = map (\r -> case r of - SingleR _ -> CursorTy - SoARv _ frs -> CursorArrayTy (1 + length frs) - ) (inRegVars ty) - in_tys = inRegs ++ outRegs ++ outCurTys ++ (map unTy2 arrIns) + outCurs = filter (\(LRM _ _ m) -> m == Output) locVars + outCurTys = + map + ( \(LRM l _ _) -> case l of + Single _ -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length (fields)) + ) + outCurs + inRegs = + map + ( \r -> case r of + SingleR _ -> CursorTy + SoARv _ frs -> CursorArrayTy (1 + length frs) + ) + (inRegVars ty) + in_tys = inRegs ++ outRegs ++ outCurTys ++ (map unTy2 arrIns) -- Packed types in the input now become (read-only) cursors. - newIns = if useSoA - then map (cursorizeInTy) in_tys - else map (constPacked CursorTy) in_tys - - in dbgTrace (minChatLvl) "Print in_tys" dbgTrace (minChatLvl) (sdoc (out_ty, in_tys)) dbgTrace (minChatLvl) "End in_tys\n" (map stripTyLocs newIns, stripTyLocs newOut') - + newIns = + if useSoA + then map (cursorizeInTy) in_tys + else map (constPacked CursorTy) in_tys + in dbgTrace (minChatLvl) "Print in_tys" dbgTrace (minChatLvl) (sdoc (out_ty, in_tys)) dbgTrace (minChatLvl) "End in_tys\n" (map stripTyLocs newIns, stripTyLocs newOut') -- | Cursorize expressions NOT producing `Packed` values -cursorizeExp :: M.Map FreeVarsTy Var -> TyEnv Var (Maybe LocVar) -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 - -> PassM Exp3 +cursorizeExp :: + M.Map FreeVarsTy Var -> + TyEnv Var (Maybe LocVar) -> + DDefs Ty2 -> + FunDefs2 -> + DepEnv -> + TyEnv Var Ty2 -> + SyncEnv -> + Exp2 -> + PassM Exp3 cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case ex of - VarE v -> return $ VarE v - LitE n -> return $ LitE n - CharE c -> return $ CharE c - FloatE n -> return $ FloatE n + VarE v -> return $ VarE v + LitE n -> return $ LitE n + CharE c -> return $ CharE c + FloatE n -> return $ FloatE n LitSymE n -> return $ LitSymE n - - AppE{} -> cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex - + AppE {} -> cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex PrimAppE RequestSizeOf [arg] -> do let (VarE v) = arg case M.lookup v tenv of Nothing -> error $ "cursorizeExp: Unbound variable: " ++ sdoc v - Just ty -> if isPackedTy (unTy2 ty) - then pure $ Ext $ SubPtr (toEndV v) v - else pure $ LitE $ fromJust $ sizeOfTy (unTy2 ty) - + Just ty -> + if isPackedTy (unTy2 ty) + then pure $ Ext $ SubPtr (toEndV v) v + else pure $ LitE $ fromJust $ sizeOfTy (unTy2 ty) PrimAppE pr args -> PrimAppE (toL3Prim pr) <$> mapM go args - - LetE (v,_locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + LetE (v, _locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs cursorizeReadPackedFile freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod - - LetE (_v,_locs,_ty, (MkProdE _ls)) _bod -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + LetE (_v, _locs, _ty, (MkProdE _ls)) _bod -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs cursorizeProd freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex - - LetE (_v,_locs, ty, ProjE{}) _bod | isPackedTy (unTy2 ty) -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + LetE (_v, _locs, ty, ProjE {}) _bod | isPackedTy (unTy2 ty) -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs cursorizeProj freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex - - LetE (_v,_locs, _ty, SpawnE{}) _bod -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + LetE (_v, _locs, _ty, SpawnE {}) _bod -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs cursorizeSpawn freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex - - LetE (_v,_locs, _ty, SyncE) _bod -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + LetE (_v, _locs, _ty, SyncE) _bod -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs cursorizeSync freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex - - LetE (v,_locs,ty, rhs@(Ext (SSPush _ start _ _))) bod -> do + LetE (v, _locs, ty, rhs@(Ext (SSPush _ start _ _))) bod -> do case M.lookup (unwrapLocVar start) tenv of Nothing -> go bod - Just{} -> do + Just {} -> do rhs' <- go rhs bod' <- go bod let ty' = cursorizeTy (unTy2 ty) - return $ LetE (v,[],ty',rhs') bod' - - LetE (v,_locs,ty, rhs@(Ext (SSPop _ start _))) bod -> + return $ LetE (v, [], ty', rhs') bod' + LetE (v, _locs, ty, rhs@(Ext (SSPop _ start _))) bod -> case M.lookup (unwrapLocVar start) tenv of Nothing -> go bod - Just{} -> do + Just {} -> do rhs' <- go rhs bod' <- go bod let ty' = cursorizeTy (unTy2 ty) - return $ LetE (v,[],ty',rhs') bod' + return $ LetE (v, [], ty', rhs') bod' - -- LetE bnd@(v, _locs, ty, rhs) bod -> case rhs of - -- Ext (BoundsCheck i bound cur) -> do + -- LetE bnd@(v, _locs, ty, rhs) bod -> case rhs of + -- Ext (BoundsCheck i bound cur) -> do -- let bound_loc = toLocVar bound - -- let bound_var = case (M.lookup (fromLocVarToFreeVarsTy bound_loc) freeVarToVarEnv) of - -- Just v -> v + -- let bound_var = case (M.lookup (fromLocVarToFreeVarsTy bound_loc) freeVarToVarEnv) of + -- Just v -> v -- Nothing -> error $ "cursorizeExp: BoundsCheck: unexpected location variable" ++ sdoc bound_loc -- let cur_loc = toLocVar cur - -- let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of - -- Just v -> v - -- Nothing -> error $ "cursorizeExp: BoundsCheck: unexpected location variable" ++ sdoc cur_loc + -- let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of + -- Just v -> v + -- Nothing -> error $ "cursorizeExp: BoundsCheck: unexpected location variable" ++ sdoc cur_loc -- exp' <- return $Ext $ L3.BoundsCheck i bound_var cur_var -- --exp' <- if isBound cur_var tenv -- -- then return $ Ext $ L3.BoundsCheck i bound_var cur_var - -- -- else do + -- -- else do -- -- let denv' = M.insertWith (++) (cur_loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv -- -- return $ Ext $ L3.BoundsCheck i bound_var cur_var --Left$ M.insertWith (++) ((toLocVar) loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv -- return exp' -- _ -> cursorizeLet freeVarToVarEnv False ddfs fundefs denv tenv senv bnd bod - LetE bnd@(_,_locs,_, _) bod -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + LetE bnd@(_, _locs, _, _) bod -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs cursorizeLet freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv bnd bod - - IfE a b c -> IfE <$> go a <*> go b <*> go c - + IfE a b c -> IfE <$> go a <*> go b <*> go c MkProdE ls -> MkProdE <$> mapM go ls - - ProjE i e -> ProjE i <$> go e - + ProjE i e -> ProjE i <$> go e -- Eg. leftmost CaseE scrt brs -> do -- ASSUMPTION: scrt is flat - freeVarToVarEnv' <- foldrM (\(dcon,vlocs,rhs) acc -> do - case vlocs of - [] -> return acc - _ -> do - acc' <- foldrM (\(v, l) acc'' -> do - case (toLocVar l) of - Single l' -> return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) l' acc'' - SoA _ _ -> do - if M.member (fromLocVarToFreeVarsTy (toLocVar l)) acc'' - then return acc'' - else do - name <- gensym "cursor_ptr" - return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) name acc'' - ) acc vlocs - return acc' - - - ) freeVarToVarEnv brs - let (VarE v) = scrt - let ty_of_scrut = case (M.lookup v tenv) of - Just (MkTy2 ty) -> ty - Nothing -> error "unpackDataCon: unexpected location variable" + freeVarToVarEnv' <- + foldrM + ( \(dcon, vlocs, rhs) acc -> do + case vlocs of + [] -> return acc + _ -> do + acc' <- + foldrM + ( \(v, l) acc'' -> do + case (toLocVar l) of + Single l' -> return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) l' acc'' + SoA _ _ -> do + if M.member (fromLocVarToFreeVarsTy (toLocVar l)) acc'' + then return acc'' + else do + name <- gensym "cursor_ptr" + return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) name acc'' + ) + acc + vlocs + return acc' + ) + freeVarToVarEnv + brs + let (VarE v) = scrt + let ty_of_scrut = case (M.lookup v tenv) of + Just (MkTy2 ty) -> ty + Nothing -> error "unpackDataCon: unexpected location variable" dcon_var <- gensym "dcon" {-VS: TODO: get location of scrutinee, send it to unpack data con. Get the L2 location!!!-} let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray v 0)] let dcon_let_bind = mkLets dcon_let - case ty_of_scrut of - CursorTy -> CaseE (VarE $ v) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - CursorArrayTy{} -> dcon_let_bind <$> CaseE (VarE $ dcon_var) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - PackedTy _ scrutLoc -> case scrutLoc of - Single _ -> CaseE (VarE $ v) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - SoA _ _ -> dcon_let_bind <$> CaseE (VarE $ dcon_var) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - _ -> CaseE (VarE $ v) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - - - DataConE _ _ _ -> error $ "cursorizeExp: Should not have encountered DataConE if type is not packed: "++ndoc ex - + case ty_of_scrut of + CursorTy -> + CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + CursorArrayTy {} -> + dcon_let_bind + <$> CaseE (VarE $ dcon_var) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + PackedTy _ scrutLoc -> case scrutLoc of + Single _ -> + CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + SoA _ _ -> + dcon_let_bind + <$> CaseE (VarE $ dcon_var) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + _ -> + CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + DataConE _ _ _ -> error $ "cursorizeExp: Should not have encountered DataConE if type is not packed: " ++ ndoc ex TimeIt e ty b -> TimeIt <$> go e <*> pure (stripTyLocs (unTy2 ty)) <*> pure b - WithArenaE v e -> do e' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv (M.insert v (MkTy2 ArenaTy) tenv) senv e return $ WithArenaE v e' - - SpawnE{} -> error "cursorizeExp: Unbound SpawnE" - SyncE{} -> error "cursorizeExp: Unbound SyncE" - + SpawnE {} -> error "cursorizeExp: Unbound SpawnE" + SyncE {} -> error "cursorizeExp: Unbound SyncE" -- Eg. leftmost Ext ext -> case ext of AddFixed v i -> return $ Ext $ L3.AddCursor v (L3.LitE i) RetE locs v -> case locs of - [] -> return (VarE v) - _ -> return $ L3.MkProdE $ (map (\loc -> let loc_to_free_var = fromLocArgToFreeVarsTy loc - locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar loc) of - Single lvarr -> lvarr - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - in VarE locs_variable - ) locs) ++ [VarE v] - + [] -> return (VarE v) + _ -> + return $ + L3.MkProdE $ + ( map + ( \loc -> + let loc_to_free_var = fromLocArgToFreeVarsTy loc + locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar loc) of + Single lvarr -> lvarr + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + in VarE locs_variable + ) + locs + ) + ++ [VarE v] StartOfPkdCursor cur -> return (VarE cur) + TagCursor a b -> do + let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar a) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let b_var = case (M.lookup (fromRegVarToFreeVarsTy ((fromLocVarToRegVar . toLocVar) b)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar b) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - TagCursor a b -> do - let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar a) of - Single l -> l - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - let b_var = case (M.lookup (fromRegVarToFreeVarsTy ((fromLocVarToRegVar . toLocVar) b)) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar b) of - Single l -> l - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - return $ Ext $ L3.TagCursor a_var b_var -- All locations are transformed into cursors here. Location arithmetic -- is expressed in terms of corresponding cursor operations. -- See `cursorizeLocExp` LetLocE loc rhs bod -> do - let ty2_of_loc = case loc of - Single l -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length fields) - let ty3_of_loc :: Ty3 = case loc of - Single l -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length fields) - freeVarToVarEnv' <- do - case loc of - Single l -> if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv - then return freeVarToVarEnv - else return $ M.insert (fromLocVarToFreeVarsTy loc) l freeVarToVarEnv - SoA _ _ -> if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv - then return $ freeVarToVarEnv - else do - name <- gensym "cursor_ptr" - return $ M.insert (fromLocVarToFreeVarsTy loc) name freeVarToVarEnv - let locs_variable = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of - Just v -> v - Nothing -> case loc of - Single lvarrr -> lvarrr - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - let rhs_either = cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs - let (bnds,tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of - Nothing -> ([],tenv) - Just vs -> let extended = M.fromList [ (v,MkTy2 CursorTy) | (v,_,CursorTy,_) <- vs] - in (vs, M.union extended tenv) + let ty2_of_loc = case loc of + Single l -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length fields) + let ty3_of_loc :: Ty3 = case loc of + Single l -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length fields) + freeVarToVarEnv' <- do + case loc of + Single l -> + if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv + then return freeVarToVarEnv + else return $ M.insert (fromLocVarToFreeVarsTy loc) l freeVarToVarEnv + SoA _ _ -> + if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv + then return $ freeVarToVarEnv + else do + name <- gensym "cursor_ptr" + return $ M.insert (fromLocVarToFreeVarsTy loc) name freeVarToVarEnv + let locs_variable = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of + Just v -> v + Nothing -> case loc of + Single lvarrr -> lvarrr + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let rhs_either = cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs + let (bnds, tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of + Nothing -> ([], tenv) + Just vs -> + let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] + in (vs, M.union extended tenv) case rhs_either of -- Check if the location is already bound before. If so, don't -- create a duplicate binding. This only happens when we @@ -738,240 +820,249 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Right (rhs', bnds', tenv'', senv') -> do let tenv''' = M.union tenv' tenv'' - let locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of - Just v -> v - Nothing -> case loc of - Single lvarrr -> lvarrr - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of + Just v -> v + Nothing -> case loc of + Single lvarrr -> lvarrr + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" case rhs of - FromEndLE{} -> + FromEndLE {} -> if isBound locs_var tenv - then cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod - -- Discharge bindings that were waiting on 'loc'. - else mkLets (bnds' ++ [(locs_var,[],ty3_of_loc,rhs')] ++ bnds) <$> - cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod + then cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod + -- Discharge bindings that were waiting on 'loc'. + else + mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) + <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod -- Discharge bindings that were waiting on 'loc'. - _ -> mkLets (bnds' ++ [(locs_var,[],ty3_of_loc,rhs')] ++ bnds) <$> - cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv bod + _ -> + mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) + <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv bod Left denv' -> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod -- Exactly same as cursorizePackedExp LetRegionE reg sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False reg sz let reg_var = regionToVar reg - let reg_ty = case reg_var of - SingleR{} -> MkTy2 CursorTy - SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) - - reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of - Just var -> return var - Nothing -> do - case reg_var of - SingleR v -> return v - SoARv{} -> do - n <- gensym "region_cursor_ptr" - return n - - -- For end of the region - reg_var_name_end <- case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) freeVarToVarEnv') of - Just var -> return var - Nothing -> do - case reg_var of - SingleR v -> return $ toEndV v - SoARv{} -> do - n <- gensym "region_cursor_ptr_end" - return n + let reg_ty = case reg_var of + SingleR {} -> MkTy2 CursorTy + SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) + + reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return v + SoARv {} -> do + n <- gensym "region_cursor_ptr" + return n + + -- For end of the region + reg_var_name_end <- case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return $ toEndV v + SoARv {} -> do + n <- gensym "region_cursor_ptr_end" + return n let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_var) reg_var_name freeVarToVarEnv' let freeVarToVarEnv''' = M.insert (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) reg_var_name_end freeVarToVarEnv'' - let tenv' = M.insert reg_var_name reg_ty tenv let tenv'' = M.insert reg_var_name_end reg_ty tenv' - mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv''' lenv ddfs fundefs denv tenv'' senv bod - + mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv''' lenv ddfs fundefs denv tenv'' senv bod LetParRegionE reg sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv True reg sz mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv bod - + {- VS: TODO: variables are not in env-} {- TODO: End of reg needs fixing is broken -} - BoundsCheck i bound cur -> do - let bound_loc = toLocVar bound - let bound_reg = fromLocVarToRegVar bound_loc - let bound_var = case (M.lookup (fromRegVarToFreeVarsTy bound_reg) freeVarToVarEnv) of - Just v -> v - Nothing -> case bound_reg of - SingleR vr -> vr - SoARv _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv - let bound_var_ty = M.lookup bound_var tenv - (additional_bnds, bound_var') <- do - case bound_var_ty of - Just (MkTy2 MutCursorTy) -> do - dereference_bound_var <- gensym "deref" - let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] - pure (bnd, dereference_bound_var) - Nothing -> error $ "expected variable to have type!: " ++ show bound_var - _ -> pure ([], bound_var) - let cur_loc = toLocVar cur - let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeExp: BoundsCheck: unexpected location variable" ++ sdoc cur_loc ++ " " ++ show freeVarToVarEnv - exp' <- return $ mkLets additional_bnds <$> Ext $ L3.BoundsCheck i bound_var' cur_var - --exp' <- if isBound cur_var tenv - -- then return $ Ext $ L3.BoundsCheck i bound_var cur_var - -- else do - -- let denv' = M.insertWith (++) (cur_loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv - -- return $ Ext $ L3.BoundsCheck i bound_var cur_var --Left$ M.insertWith (++) ((toLocVar) loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv - return exp' - + BoundsCheck i bound cur -> do + let bound_loc = toLocVar bound + let bound_reg = fromLocVarToRegVar bound_loc + let bound_var = case (M.lookup (fromRegVarToFreeVarsTy bound_reg) freeVarToVarEnv) of + Just v -> v + Nothing -> case bound_reg of + SingleR vr -> vr + SoARv _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv + let bound_var_ty = M.lookup bound_var tenv + (additional_bnds, bound_var') <- do + case bound_var_ty of + Just (MkTy2 MutCursorTy) -> do + dereference_bound_var <- gensym "deref" + let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] + pure (bnd, dereference_bound_var) + Nothing -> error $ "expected variable to have type!: " ++ show bound_var + _ -> pure ([], bound_var) + let cur_loc = toLocVar cur + let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeExp: BoundsCheck: unexpected location variable" ++ sdoc cur_loc ++ " " ++ show freeVarToVarEnv + exp' <- return $ mkLets additional_bnds <$> Ext $ L3.BoundsCheck i bound_var' cur_var + -- exp' <- if isBound cur_var tenv + -- then return $ Ext $ L3.BoundsCheck i bound_var cur_var + -- else do + -- let denv' = M.insertWith (++) (cur_loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv + -- return $ Ext $ L3.BoundsCheck i bound_var cur_var --Left$ M.insertWith (++) ((toLocVar) loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv + return exp' Gibbon.NewL2.Syntax.BoundsCheckVector bounds -> do - (bounds', lets) <- foldrM (\(i, bound, cur) (b, l) -> do - let bound_loc = toLocVar bound - let bound_reg = fromLocVarToRegVar bound_loc - let bound_var = case (M.lookup (fromRegVarToFreeVarsTy bound_reg) freeVarToVarEnv) of - Just v -> v - Nothing -> case bound_reg of - SingleR vr -> vr - SoARv _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv - let bound_var_ty = M.lookup bound_var tenv - (additional_bnds, bound_var') <- do - case bound_var_ty of - Just (MkTy2 MutCursorTy) -> do - dereference_bound_var <- gensym "deref" - let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] - pure (bnd, dereference_bound_var) - Nothing -> error "expected variable to have type!" - _ -> pure ([], bound_var) - let cur_loc = toLocVar cur - let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> case cur_loc of - Single vr -> vr - SoA _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv - return (b ++ [(i, bound_var', cur_var, (bound_var, cur_var))], l ++ additional_bnds) - ) ([], []) bounds - exp' <- return $ mkLets lets <$> Ext $ L3.BoundsCheckVector bounds' - return exp' - - FromEndE{} -> error $ "cursorizeExp: TODO FromEndE" ++ sdoc ext - - IndirectionE{} -> error $ "cursorizeExp: Unexpected IndirectionE" - + (bounds', lets) <- + foldrM + ( \(i, bound, cur) (b, l) -> do + let bound_loc = toLocVar bound + let bound_reg = fromLocVarToRegVar bound_loc + let bound_var = case (M.lookup (fromRegVarToFreeVarsTy bound_reg) freeVarToVarEnv) of + Just v -> v + Nothing -> case bound_reg of + SingleR vr -> vr + SoARv _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv + let bound_var_ty = M.lookup bound_var tenv + (additional_bnds, bound_var') <- do + case bound_var_ty of + Just (MkTy2 MutCursorTy) -> do + dereference_bound_var <- gensym "deref" + let bnd = [(dereference_bound_var, [], CursorTy, Ext $ DerefMutCursor bound_var)] + pure (bnd, dereference_bound_var) + Nothing -> error "expected variable to have type!" + _ -> pure ([], bound_var) + let cur_loc = toLocVar cur + let cur_var = case (M.lookup (fromLocVarToFreeVarsTy cur_loc) freeVarToVarEnv) of + Just v -> v + Nothing -> case cur_loc of + Single vr -> vr + SoA _ _ -> error $ "cursorizeExp: BoundsCheck: unexpected region variable " ++ sdoc bound_loc ++ " " ++ show freeVarToVarEnv + return (b ++ [(i, bound_var', cur_var, (bound_var, cur_var))], l ++ additional_bnds) + ) + ([], []) + bounds + exp' <- return $ mkLets lets <$> Ext $ L3.BoundsCheckVector bounds' + return exp' + FromEndE {} -> error $ "cursorizeExp: TODO FromEndE" ++ sdoc ext + IndirectionE {} -> error $ "cursorizeExp: Unexpected IndirectionE" GetCilkWorkerNum -> return $ Ext $ L3.GetCilkWorkerNum - - LetAvail vs bod -> Ext <$> L3.LetAvail vs <$> go bod - - AllocateTagHere v tycon -> do - let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeExp: AllocateTagHere: unexpected location variable" - pure $ Ext $ L3.AllocateTagHere (variable_name) tycon - - AllocateScalarsHere v -> do - let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeExp: AllocateTagHere: unexpected location variable" - pure $ Ext $ L3.AllocateScalarsHere (variable_name) - + LetAvail vs bod -> Ext <$> L3.LetAvail vs <$> go bod + AllocateTagHere v tycon -> do + let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeExp: AllocateTagHere: unexpected location variable" + pure $ Ext $ L3.AllocateTagHere (variable_name) tycon + AllocateScalarsHere v -> do + let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeExp: AllocateTagHere: unexpected location variable" + pure $ Ext $ L3.AllocateScalarsHere (variable_name) SSPush a b c d -> pure $ Ext $ L3.SSPush a (unwrapLocVar b) (unwrapLocVar c) d SSPop a b c -> pure $ Ext $ L3.SSPop a (unwrapLocVar b) (unwrapLocVar c) - - {-VS: TODO: This needs to be fixed to produce the correct L3 expression. See above. -} - {- Right now i just skip the let region, just recurse on the body-} + {-VS: TODO: This needs to be fixed to produce the correct L3 expression. See above. -} + {- Right now i just skip the let region, just recurse on the body-} LetRegE loc rhs bod -> do - --let loc = fromRegVarToLocVar reg_var + -- let loc = fromRegVarToLocVar reg_var -- VS: Hack, assume that these are always Mutable cursors. -- TODO: We should have a pass to decide what we should make mutable -- vs: what we should not not make mutable. - -- let ty_of_loc = case loc of + -- let ty_of_loc = case loc of -- SingleR _ -> CursorTy -- SoARv _ flds -> CursorArrayTy (1 + length flds) - -- let ty2_of_loc :: Ty2 = case loc of + -- let ty2_of_loc :: Ty2 = case loc of -- SingleR _ -> MkTy2 CursorTy -- SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) - -- In case we unpack single regions, we make them mutable since they may + -- In case we unpack single regions, we make them mutable since they may -- be updated by bounds check. - let ty_of_loc = case loc of - SingleR _ -> MutCursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - let ty2_of_loc :: Ty2 = case loc of - SingleR _ -> MkTy2 MutCursorTy - SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) - freeVarToVarEnv' <- do - case loc of - SingleR l -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv - then return freeVarToVarEnv - else return $ M.insert (fromRegVarToFreeVarsTy loc) l freeVarToVarEnv - SoARv _ _ -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv - then return $ freeVarToVarEnv - else do - name <- gensym "cursor_ptr" - return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv + let ty_of_loc = case loc of + SingleR _ -> MutCursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + let ty2_of_loc :: Ty2 = case loc of + SingleR _ -> MkTy2 MutCursorTy + SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) + freeVarToVarEnv' <- do + case loc of + SingleR l -> + if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv + then return freeVarToVarEnv + else return $ M.insert (fromRegVarToFreeVarsTy loc) l freeVarToVarEnv + SoARv _ _ -> + if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv + then return $ freeVarToVarEnv + else do + name <- gensym "cursor_ptr" + return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv let rhs_either = cursorizeRegExp freeVarToVarEnv' denv tenv senv loc rhs - (bnds,tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of - Nothing -> ([],tenv) - Just vs -> let extended = M.fromList [ (v, MkTy2 CursorTy) | (v,_,CursorTy,_) <- vs] - in (vs, M.union extended tenv) + (bnds, tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of + Nothing -> ([], tenv) + Just vs -> + let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] + in (vs, M.union extended tenv) case rhs_either of Right (rhs', bnds', tenv'', senv') -> do let tenv''' = M.union tenv' tenv'' - let locs_var = case (M.lookup (fromRegVarToFreeVarsTy loc) freeVarToVarEnv') of - Just v -> v - Nothing -> case loc of - SingleR lvarrr -> lvarrr - SoARv _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let locs_var = case (M.lookup (fromRegVarToFreeVarsTy loc) freeVarToVarEnv') of + Just v -> v + Nothing -> case loc of + SingleR lvarrr -> lvarrr + SoARv _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" case rhs of - -- Discharge bindings that were waiting on 'loc'. - _ -> case ty_of_loc of - MutCursorTy -> mkLets (bnds' ++ [(locs_var,[],ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds) <$> - cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - _ -> mkLets (bnds' ++ [(locs_var,[],ty_of_loc,rhs')] ++ bnds) <$> - cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - -- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod - Left denv' -> (mkLets bnds) <$> - cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod - -- case reg_var of - -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod - -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod + -- Discharge bindings that were waiting on 'loc'. + _ -> case ty_of_loc of + MutCursorTy -> + mkLets (bnds' ++ [(locs_var, [], ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds) + <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + _ -> + mkLets (bnds' ++ [(locs_var, [], ty_of_loc, rhs')] ++ bnds) + <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + -- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod + Left denv' -> + (mkLets bnds) + <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + -- case reg_var of + -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod + -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod _ -> error $ "Unpexected Expression: " ++ show ext - - MapE{} -> error $ "TODO: cursorizeExp MapE" - FoldE{} -> error $ "TODO: cursorizeExp FoldE" - + MapE {} -> error $ "TODO: cursorizeExp MapE" + FoldE {} -> error $ "TODO: cursorizeExp FoldE" where go = cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv - - insertRegInVarEnv :: RegVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var) -insertRegInVarEnv reg_var env = do - case reg_var of - SingleR l -> if M.member (fromRegVarToFreeVarsTy reg_var) env - then return env - else return $ M.insert (fromRegVarToFreeVarsTy reg_var) l env - SoARv _ _ -> if M.member (fromRegVarToFreeVarsTy reg_var) env - then return $ env - else do - name <- gensym "reg_cursor_ptr" - return $ M.insert (fromRegVarToFreeVarsTy reg_var) name env +insertRegInVarEnv reg_var env = do + case reg_var of + SingleR l -> + if M.member (fromRegVarToFreeVarsTy reg_var) env + then return env + else return $ M.insert (fromRegVarToFreeVarsTy reg_var) l env + SoARv _ _ -> + if M.member (fromRegVarToFreeVarsTy reg_var) env + then return $ env + else do + name <- gensym "reg_cursor_ptr" + return $ M.insert (fromRegVarToFreeVarsTy reg_var) name env insertLocInVarEnv :: LocVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var) -insertLocInVarEnv loc env = do - case loc of - Single l -> if M.member (fromLocVarToFreeVarsTy loc) env - then return env - else return $ M.insert (fromLocVarToFreeVarsTy loc) l env - SoA _ _ -> if M.member (fromLocVarToFreeVarsTy loc) env - then return $ env - else do - name <- gensym "loc_cursor_ptr" - return $ M.insert (fromLocVarToFreeVarsTy loc) name env +insertLocInVarEnv loc env = do + case loc of + Single l -> + if M.member (fromLocVarToFreeVarsTy loc) env + then return env + else return $ M.insert (fromLocVarToFreeVarsTy loc) l env + SoA _ _ -> + if M.member (fromLocVarToFreeVarsTy loc) env + then return $ env + else do + name <- gensym "loc_cursor_ptr" + return $ M.insert (fromLocVarToFreeVarsTy loc) name env -- Cursorize expressions producing `Packed` values -cursorizePackedExp :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 - -> PassM (DiExp Exp3) +cursorizePackedExp :: + M.Map FreeVarsTy Var -> + M.Map Var (Maybe LocVar) -> + DDefs Ty2 -> + FunDefs2 -> + DepEnv -> + TyEnv Var Ty2 -> + SyncEnv -> + Exp2 -> + PassM (DiExp Exp3) cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case ex of -- Here the allocation has already been performed: @@ -979,107 +1070,102 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- end here: VarE v -> do let ty = case M.lookup v tenv of - Just t -> t - Nothing -> error $ sdoc v ++ " not found." + Just t -> t + Nothing -> error $ sdoc v ++ " not found." if isPackedTy (unTy2 ty) - then return $ mkDi (VarE v) [ VarE (toEndV v) ] - else return $ dl $ VarE v - - LitE _n -> error $ "Shouldn't encounter LitE in packed context:" ++ sdoc ex - CharE _n -> error $ "Shouldn't encounter CharE in packed context:" ++ sdoc ex - FloatE{} -> error $ "Shouldn't encounter FloatE in packed context:" ++ sdoc ex + then return $ mkDi (VarE v) [VarE (toEndV v)] + else return $ dl $ VarE v + LitE _n -> error $ "Shouldn't encounter LitE in packed context:" ++ sdoc ex + CharE _n -> error $ "Shouldn't encounter CharE in packed context:" ++ sdoc ex + FloatE {} -> error $ "Shouldn't encounter FloatE in packed context:" ++ sdoc ex LitSymE _n -> error $ "Shouldn't encounter LitSymE in packed context:" ++ sdoc ex - - AppE{} -> dl <$> cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex - + AppE {} -> dl <$> cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex -- DictLookup returns a packed value bound to a free location. -- PrimAppE (DictLookupP (PackedTy _ ploc)) vs -> -- do vs' <- forM vs $ \v -> cursorizeExp ddfs fundefs denv tenv v -- return $ mkDi (PrimAppE (DictLookupP CursorTy) vs') [ Ext NullCursor ] PrimAppE _ _ -> error $ "cursorizePackedExp: unexpected PrimAppE in packed context:" ++ sdoc ex - -- The only (other) primitive that returns packed data is ReadPackedFile: -- This is simpler than TimeIt below. While it's out-of-line, -- it doesn't need memory allocation (NewBuffer/ScopedBuffer). -- This is more like the witness case below. - LetE (v,_locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> - Di <$> cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod - - LetE (v,_locs,_ty, (PrimAppE (DictLookupP (MkTy2 (PackedTy _ ploc))) vs)) bod -> - do vs' <- forM vs $ \w -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv w - let bnd = mkLets [((unwrapLocVar ploc), [], CursorTy, (PrimAppE (DictLookupP CursorTy) vs')) - ,(v, [], CursorTy, VarE (unwrapLocVar ploc))] - tenv' = M.insert (unwrapLocVar ploc) (MkTy2 CursorTy) $ M.insert v (MkTy2 CursorTy) tenv - onDi bnd <$> go freeVarToVarEnv tenv' senv bod - - LetE (_v,_locs,_ty, (MkProdE _ls)) _bod -> + LetE (v, _locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> + Di <$> cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod + LetE (v, _locs, _ty, (PrimAppE (DictLookupP (MkTy2 (PackedTy _ ploc))) vs)) bod -> + do + vs' <- forM vs $ \w -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv w + let bnd = + mkLets + [ ((unwrapLocVar ploc), [], CursorTy, (PrimAppE (DictLookupP CursorTy) vs')), + (v, [], CursorTy, VarE (unwrapLocVar ploc)) + ] + tenv' = M.insert (unwrapLocVar ploc) (MkTy2 CursorTy) $ M.insert v (MkTy2 CursorTy) tenv + onDi bnd <$> go freeVarToVarEnv tenv' senv bod + LetE (_v, _locs, _ty, (MkProdE _ls)) _bod -> dl <$> cursorizeProd freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex - - LetE (_v,_locs,ty, ProjE{}) _bod | isPackedTy (unTy2 ty) -> - dl <$> cursorizeProj freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex - - + LetE (_v, _locs, ty, ProjE {}) _bod + | isPackedTy (unTy2 ty) -> + dl <$> cursorizeProj freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex MkProdE ls -> do let tys = L.map (gRecoverType ddfs (Env2 tenv M.empty)) ls - es <- forM (zip tys ls) $ \(ty,e) -> do - case ty of - _ | isPackedTy (unTy2 ty) -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e - _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + es <- forM (zip tys ls) $ \(ty, e) -> do + case ty of + _ | isPackedTy (unTy2 ty) -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e let rhs' = MkProdE es return $ Di rhs' -- Not sure if we need to replicate all the checks from Cursorize1 ProjE i e -> dl <$> ProjE i <$> fromDi <$> go freeVarToVarEnv tenv senv e - - LetE (_v,_locs, _ty, SpawnE{}) _bod -> + LetE (_v, _locs, _ty, SpawnE {}) _bod -> dl <$> cursorizeSpawn freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex - - LetE (_v,_locs, _ty, SyncE) _bod -> + LetE (_v, _locs, _ty, SyncE) _bod -> dl <$> cursorizeSync freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex - - LetE (v,_locs,ty, rhs@(Ext (SSPush _ start _ _))) bod -> + LetE (v, _locs, ty, rhs@(Ext (SSPush _ start _ _))) bod -> case M.lookup (unwrapLocVar start) tenv of Nothing -> go freeVarToVarEnv tenv senv bod - Just{} -> do + Just {} -> do rhs' <- go freeVarToVarEnv tenv senv rhs let ty' = cursorizeTy (unTy2 ty) bod' <- go freeVarToVarEnv (M.insert v ty tenv) senv bod - return $ Di (LetE (v,[], ty', fromDi rhs') (fromDi bod')) - - LetE (v,_locs,ty, rhs@(Ext (SSPop _ start _))) bod -> + return $ Di (LetE (v, [], ty', fromDi rhs') (fromDi bod')) + LetE (v, _locs, ty, rhs@(Ext (SSPop _ start _))) bod -> case M.lookup (unwrapLocVar start) tenv of Nothing -> go freeVarToVarEnv tenv senv bod - Just{} -> do + Just {} -> do rhs' <- go freeVarToVarEnv tenv senv rhs let ty' = cursorizeTy (unTy2 ty) bod' <- go freeVarToVarEnv (M.insert v ty tenv) senv bod - return $ Di (LetE (v,[],ty', fromDi rhs') (fromDi bod')) - - LetE bnd@(_,_locs,_, _) bod -> do - freeVarToVarEnv' <- foldrM (\loc env -> case loc of - EndOfReg r _ er -> do - env' <- insertRegInVarEnv r env - env'' <- insertRegInVarEnv er env' - return env'' - EndWitness lrem loc -> do - env' <- insertLocInVarEnv loc env - env'' <- insertLocInVarEnv (lremLoc lrem) env' - env''' <- insertRegInVarEnv (lremEndReg lrem) env'' - env'''' <- insertRegInVarEnv (lremReg lrem) env''' - return env'''' - Loc lrem -> do - env' <- insertLocInVarEnv (lremLoc lrem) env - env'' <- insertRegInVarEnv (lremEndReg lrem) env' - env''' <- insertRegInVarEnv (lremReg lrem) env'' - return env''' - Reg r _ -> do - env' <- insertRegInVarEnv r env - return env' - EndOfReg_Tagged r -> do - env' <- insertRegInVarEnv r env - return env' - ) freeVarToVarEnv _locs + return $ Di (LetE (v, [], ty', fromDi rhs') (fromDi bod')) + LetE bnd@(_, _locs, _, _) bod -> do + freeVarToVarEnv' <- + foldrM + ( \loc env -> case loc of + EndOfReg r _ er -> do + env' <- insertRegInVarEnv r env + env'' <- insertRegInVarEnv er env' + return env'' + EndWitness lrem loc -> do + env' <- insertLocInVarEnv loc env + env'' <- insertLocInVarEnv (lremLoc lrem) env' + env''' <- insertRegInVarEnv (lremEndReg lrem) env'' + env'''' <- insertRegInVarEnv (lremReg lrem) env''' + return env'''' + Loc lrem -> do + env' <- insertLocInVarEnv (lremLoc lrem) env + env'' <- insertRegInVarEnv (lremEndReg lrem) env' + env''' <- insertRegInVarEnv (lremReg lrem) env'' + return env''' + Reg r _ -> do + env' <- insertRegInVarEnv r env + return env' + EndOfReg_Tagged r -> do + env' <- insertRegInVarEnv r env + return env' + ) + freeVarToVarEnv + _locs dl <$> cursorizeLet freeVarToVarEnv' lenv True ddfs fundefs denv tenv senv bnd bod -- Here we route the dest cursor to both braches. We switch @@ -1087,7 +1173,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = IfE a b c -> do Di b' <- go freeVarToVarEnv tenv senv b Di c' <- go freeVarToVarEnv tenv senv c - a' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv a + a' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv a return $ Di $ IfE a' b' c' -- A case expression is eventually transformed into a ReadTag + switch stmt. @@ -1098,470 +1184,511 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = CaseE scrt brs -> do -- ASSUMPTION: scrutinee is always flat let (VarE v) = scrt - - freeVarToVarEnv' <- foldrM (\(dcon,vlocs,rhs) acc -> do - case vlocs of - [] -> return acc - _ -> do - acc' <- foldrM (\(v, l) acc'' -> do - case (toLocVar l) of - Single l' -> return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) l' acc'' - SoA _ _ -> do - if M.member (fromLocVarToFreeVarsTy (toLocVar l)) acc'' - then return acc'' - else do - name <- gensym "cursor_ptr" - return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) name acc'' - ) acc vlocs - return acc' - - - ) freeVarToVarEnv brs - let ty_of_scrut = case (M.lookup v tenv) of - Just (MkTy2 ty) -> ty - Nothing -> error "unpackDataCon: unexpected location variable" + + freeVarToVarEnv' <- + foldrM + ( \(dcon, vlocs, rhs) acc -> do + case vlocs of + [] -> return acc + _ -> do + acc' <- + foldrM + ( \(v, l) acc'' -> do + case (toLocVar l) of + Single l' -> return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) l' acc'' + SoA _ _ -> do + if M.member (fromLocVarToFreeVarsTy (toLocVar l)) acc'' + then return acc'' + else do + name <- gensym "cursor_ptr" + return $ M.insert (fromLocVarToFreeVarsTy (toLocVar l)) name acc'' + ) + acc + vlocs + return acc' + ) + freeVarToVarEnv + brs + let ty_of_scrut = case (M.lookup v tenv) of + Just (MkTy2 ty) -> ty + Nothing -> error "unpackDataCon: unexpected location variable" dcon_var <- gensym "dcon" let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray v 0)] - let dcon_let_bind = mkLets dcon_let - case ty_of_scrut of - CursorTy -> dl <$> - CaseE (VarE $ v) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs - CursorArrayTy{} -> dl <$> dcon_let_bind <$> - CaseE (VarE $ dcon_var) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs - PackedTy _ scrutLoc -> case scrutLoc of - Single _ -> dl <$> CaseE (VarE $ v) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs - SoA _ _ -> dl <$> dcon_let_bind <$> - CaseE (VarE $ dcon_var) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs - _ -> dl <$> CaseE (VarE $ v) <$> - mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs - - + let dcon_let_bind = mkLets dcon_let + case ty_of_scrut of + CursorTy -> + dl + <$> CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + CursorArrayTy {} -> + dl + <$> dcon_let_bind + <$> CaseE (VarE $ dcon_var) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + PackedTy _ scrutLoc -> case scrutLoc of + Single _ -> + dl + <$> CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + SoA _ _ -> + dl + <$> dcon_let_bind + <$> CaseE (VarE $ dcon_var) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + _ -> + dl + <$> CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs DataConE slocarg dcon args -> do if (not (isSoALoc (toLocVar slocarg))) - then do - let sloc_loc = toLocVar slocarg - sloc = case (M.lookup (fromLocVarToFreeVarsTy sloc_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeExp(988): DataConE: unexpected location variable" ++ "(" ++ show sloc_loc ++ ")" ++ show freeVarToVarEnv - -- Return (start,end) cursors - -- The final return value lives at the position of the out cursors: - go2 :: Bool -> Var -> [(Exp2, Ty2)] -> PassM Exp3 - go2 marker_added d [] = - if not (marker_added) - then do - end_scalars_alloc <- gensym "end_scalars_alloc" - return (LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation sloc) - (MkProdE [VarE (sloc), VarE d])) - else return (MkProdE [VarE (sloc), VarE d]) - - go2 marker_added d ((rnd, (MkTy2 ty)):rst) = do - d' <- gensym "writecur" - case ty of - _ | isPackedTy ty -> do - - rnd' <- go freeVarToVarEnv tenv senv rnd - end_scalars_alloc <- gensym "end_scalars_alloc" - (if not marker_added - then LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation (sloc)) - else id) <$> - LetE (d',[], CursorTy, projEnds rnd') <$> - go2 True d' rst - - -- Int, Float, Sym, or Bool - _ | isScalarTy ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd - LetE (d',[], CursorTy, Ext $ WriteScalar (mkScalar ty) d rnd') <$> - go2 marker_added d' rst - - -- Write a pointer to a vector - VectorTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd - LetE (d',[], CursorTy, Ext $ WriteVector d rnd' (stripTyLocs el_ty)) <$> - go2 marker_added d' rst - - -- Write a pointer to a vector - ListTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd - LetE (d',[], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> - go2 marker_added d' rst - - -- shortcut pointer - CursorTy -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd - LetE (d',[], CursorTy, Ext $ WriteTaggedCursor d rnd') <$> - go2 marker_added d' rst - _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty - - writetag <- gensym "writetag" - after_tag <- gensym "after_tag" - start_tag_alloc <- gensym "start_tag_alloc" - end_tag_alloc <- gensym "end_tag_alloc" - start_scalars_alloc <- gensym "start_scalars_alloc" - dl <$> - LetE (start_tag_alloc,[],ProdTy [], Ext $ StartTagAllocation (sloc)) <$> - LetE (writetag,[], CursorTy, Ext $ WriteTag dcon (sloc)) <$> - LetE (end_tag_alloc,[],ProdTy [], Ext $ EndTagAllocation (sloc)) <$> - LetE (start_scalars_alloc,[],ProdTy [], Ext $ StartScalarsAllocation (sloc)) <$> - LetE (after_tag,[], CursorTy, Ext $ AddCursor (sloc) (L3.LitE 1)) <$> - go2 False after_tag (zip args (lookupDataCon ddfs dcon)) - else do - let sloc_loc = toLocVar slocarg - dcon_loc = getDconLoc sloc_loc - field_locs = getAllFieldLocsSoA sloc_loc - sloc = case (M.lookup (fromLocVarToFreeVarsTy sloc_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeExp(1056): DataConE: unexpected location variable" ++ "(" ++ show sloc_loc ++ ")" ++ show freeVarToVarEnv - (sloc_dcon, present, freeVarToVarEnv') = case (M.lookup (fromLocVarToFreeVarsTy dcon_loc) freeVarToVarEnv) of - Just v -> (v, True, freeVarToVarEnv) - Nothing -> case dcon_loc of - Single l -> (l, False, (M.insert (fromLocVarToFreeVarsTy dcon_loc) l freeVarToVarEnv)) - _ -> error $ "cursorizeExp(1059): DataConE: unexpected dcon location variable" ++ "(" ++ show (dcon, dcon_loc) ++ ")" ++ show freeVarToVarEnv - -- Return (start,end) cursors - -- The final return value lives at the position of the out cursors: - -- go2 :: Bool -> Var -> [(Exp2, Ty2)] -> PassM Exp3 - -- go2 marker_added d [] = - -- if not (marker_added) - -- then do - -- end_scalars_alloc <- gensym "end_scalars_alloc" - -- return (LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation sloc) - -- (MkProdE [VarE (sloc), VarE d])) - -- else return (MkProdE [VarE (sloc), VarE d]) - - -- go2 marker_added d ((rnd, (MkTy2 ty)):rst) = do - -- d' <- gensym "writecur" - -- case ty of - -- _ | isPackedTy ty -> do - - -- rnd' <- go freeVarToVarEnv tenv senv rnd - -- end_scalars_alloc <- gensym "end_scalars_alloc" - -- (if not marker_added - -- then LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation (sloc)) - -- else id) <$> - -- LetE (d',[], CursorTy, projEnds rnd') <$> - -- go2 True d' rst - - -- -- Int, Float, Sym, or Bool - -- _ | isScalarTy ty -> do - -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd - -- LetE (d',[], CursorTy, Ext $ WriteScalar (mkScalar ty) d rnd') <$> - -- go2 marker_added d' rst - - -- -- Write a pointer to a vector - -- VectorTy el_ty -> do - -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd - -- LetE (d',[], CursorTy, Ext $ WriteVector d rnd' (stripTyLocs el_ty)) <$> - -- go2 marker_added d' rst - - -- -- Write a pointer to a vector - -- ListTy el_ty -> do - -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd - -- LetE (d',[], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> - -- go2 marker_added d' rst - - -- -- shortcut pointer - -- CursorTy -> do - -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd - -- LetE (d',[], CursorTy, Ext $ WriteTaggedCursor d rnd') <$> - -- go2 marker_added d' rst - -- _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty - - dummy :: PassM Exp3 - dummy = return $ VarE (sloc) - - - go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> Maybe Var -> [((DataCon, Int), LocVar)] -> [((DataCon, Int), Maybe LocVar, (Exp2, Ty2))] -> PassM Exp3 - go2 marker_added fvarenv aft_dloc from_rec_end aft_flocs [] = do - let curr_soa_loc = sloc - if not (marker_added) - then do - after_soa_loc <- gensym "aft_soa_loc" - let after_flocs_to_vars = map (\(_, floc) -> case (M.lookup (fromLocVarToFreeVarsTy $ floc) fvarenv) of - Just v -> v - Nothing -> case floc of - Single l -> l - _ -> error $ "cursorizeExp (1123): DataConE: unexpected location variable" ++ "(" ++ show (dcon, floc) ++ ")" ++ show fvarenv - ) aft_flocs - let makeCurArr = Ext $ MakeCursorArray (1 + length (aft_flocs)) ([aft_dloc] ++ after_flocs_to_vars) - let let_mk_cur_arr = LetE (after_soa_loc, [], CursorArrayTy (1 + length (aft_flocs)), makeCurArr) - end_scalars_alloc <- gensym "end_scalars_alloc" - return (let_mk_cur_arr $ LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation (curr_soa_loc)) - (MkProdE [VarE (curr_soa_loc), VarE (after_soa_loc)])) - else do - let rec_end_var = case from_rec_end of - Just v -> v - Nothing -> error "cursorizeExp: go2: expected a recursive end." - return (MkProdE [VarE (curr_soa_loc), VarE (rec_end_var)]) - - go2 marker_added fvarenv aft_dloc from_rec_end aft_flocs (((dcon, index), floc, (rnd, (MkTy2 ty))):rst) = do - d' <- gensym "writecur" - case ty of - PackedTy _ l -> do - let cur_ty = case l of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) - rnd' <- go freeVarToVarEnv' tenv senv rnd - end_scalars_alloc <- gensym "end_scalars_alloc" - (if not marker_added - then LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation (sloc)) - else id) <$> - LetE (d', [], cur_ty, projEnds rnd') <$> - go2 True fvarenv aft_dloc (Just d') aft_flocs rst - - _ | isScalarTy ty -> do - rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd - -- get the location variable where the scalar must be written - let floc_loc = case floc of - Just l -> l - Nothing -> error "cursorizeExp: DataConE: expected a location for scalar buffer" - let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv) of - Just v -> v - Nothing -> case floc_loc of - Single l -> l - SoA _ _ -> error $ "cursorizePackedExp: DataConE(" ++ show dcon ++ ") : unexpected location variable " ++ ":" ++ show floc_loc ++ "\n\n" ++ show fvarenv - write_scalars_at <- gensym "write_scalars_at" - let let_assign_write_cur = LetE (write_scalars_at, [], CursorTy, (VarE floc_var)) - {- Update, aft_flocs with the correct location for the scalar field -} - {- TODO: Audit aft_flocs' and fvarenv'-} - {- TODO: Check if its fine to use singleLocVar d' here!! -} - let aft_flocs' = map (\((d, idx'), l) -> if d == dcon && idx' == index - then ((d, idx'), singleLocVar d') - else ((d, idx'), l) - ) aft_flocs - let fvarenv' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv - let_assign_write_cur <$> LetE (d',[], CursorTy, Ext $ WriteScalar (mkScalar ty) write_scalars_at rnd') <$> - go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst - - - -- Write a pointer to a vector - VectorTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd - -- get the location variable where the scalar must be written - let floc_loc = case floc of - Just l -> l - Nothing -> error "cursorizeExp: DataConE: expected a location for scalar buffer" - let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv) of - Just v -> v - Nothing -> case floc_loc of - Single l -> l - SoA _ _ -> error $ "cursorizePackedExp: DataConE(" ++ show dcon ++ ") : unexpected location variable " ++ ":" ++ show floc_loc ++ "\n\n" ++ show fvarenv - write_vector_at <- gensym "write_vector_at" - let let_assign_write_cur = LetE (write_vector_at, [], CursorTy, (VarE floc_var)) - {- Update, aft_flocs with the correct location for the scalar field -} - {- TODO: Audit aft_flocs' and fvarenv'-} - {- TODO: Check if its fine to use singleLocVar d' here!! -} - let aft_flocs' = map (\((d, idx'), l) -> if d == dcon && idx' == index - then ((d, idx'), singleLocVar d') - else ((d, idx'), l) - ) aft_flocs - let fvarenv' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv - let_assign_write_cur <$> LetE (d',[], CursorTy, Ext $ WriteVector write_vector_at rnd' (stripTyLocs el_ty)) <$> - go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst - - -- _ -> error $ "TODO: Cursorize: cursorizePackedExp: Ty not implemented!! " ++ show (ty) - - -- -- Write a pointer to a vector - -- ListTy el_ty -> do - -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd - -- LetE (d',[], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> - -- go2 marker_added d' rst - - -- shortcut pointer - -- SoA case - -- Fix case for indirection/shortcut pointers - CursorTy -> do - rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd - after_indirection <- gensym "aft_indirection" - casted_var <- gensym "cast" - let rnd_var = case rnd' of - VarE v -> v - _ -> error "Did not expected variable!" - LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> - LetE (d',[], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) <$> - LetE (after_indirection,[], CursorTy, VarE d') <$> --Ext $ AddCursor aft_dloc (L3.LitE 8) - go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst - - _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty - - - - writetag <- gensym "writetag" - after_tag <- gensym "after_tag" - start_tag_alloc <- gensym "start_tag_alloc" - end_tag_alloc <- gensym "end_tag_alloc" - start_scalars_alloc <- gensym "start_scalars_alloc" - let exp_f_tys = zip args (lookupDataCon ddfs dcon) - -- [((DataCon, Int), Maybe Location, (Exp2, Ty2))] - let locs_tys = map (\e@(rnd, (MkTy2 ty)) -> let idx = case (L.elemIndex e exp_f_tys) of - Just idx -> idx - Nothing -> error "cursorizeExp: DataConE: field not found!" - key = (dcon, idx) - loc = L.lookup key field_locs - in (key, loc, e) - ) exp_f_tys - let additional_bnds = if present - then [] - else [(sloc_dcon, [], CursorTy, Ext $ IndexCursorArray sloc 0)] - (additional_bnds', freeVarToVarEnv'', _) <- foldlM (\(b, env, idx') ((_, _), loc) -> do - (var_for_loc, present', env') <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of - Just v -> return $ (v, True, env) - Nothing -> case loc of - Single l -> return $ (l, False, env) - SoA{} -> do - new_name <- gensym "field_cursor" - let env'' = M.insert (fromLocVarToFreeVarsTy loc) new_name env - return $ (new_name, False, env'') - let b' = if present' - then b - else b ++ [(var_for_loc, [], CursorTy, Ext $ IndexCursorArray sloc idx')] - pure (b', env', idx' + 1) - - - ) (additional_bnds, freeVarToVarEnv', 1) field_locs - - dl <$> - -- Make sure that the field locations and data locations are released here - -- We can clean them up later. - -- data con location - mkLets additional_bnds' <$> - LetE (start_tag_alloc,[],ProdTy [], Ext $ StartTagAllocation (sloc)) <$> - LetE (writetag,[], CursorTy, Ext $ WriteTag dcon (sloc_dcon)) <$> - LetE (end_tag_alloc,[],ProdTy [], Ext $ EndTagAllocation (sloc)) <$> - LetE (start_scalars_alloc,[],ProdTy [], Ext $ StartScalarsAllocation (sloc)) <$> - LetE (after_tag,[], CursorTy, Ext $ AddCursor (sloc_dcon) (L3.LitE 1)) <$> - go2 False freeVarToVarEnv'' after_tag Nothing field_locs locs_tys - - -- go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> [((DataCon, Int), Location, (Exp2, Ty2))] -> [((DataCon, Int), Location, (Exp2, Ty2))] -> PassM Exp3 - -- go2 False after_tag (zip args (lookupDataCon ddfs dcon)) - + then do + let sloc_loc = toLocVar slocarg + sloc = case (M.lookup (fromLocVarToFreeVarsTy sloc_loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeExp(988): DataConE: unexpected location variable" ++ "(" ++ show sloc_loc ++ ")" ++ show freeVarToVarEnv + -- Return (start,end) cursors + -- The final return value lives at the position of the out cursors: + go2 :: Bool -> Var -> [(Exp2, Ty2)] -> PassM Exp3 + go2 marker_added d [] = + if not (marker_added) + then do + end_scalars_alloc <- gensym "end_scalars_alloc" + return + ( LetE + (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation sloc) + (MkProdE [VarE (sloc), VarE d]) + ) + else return (MkProdE [VarE (sloc), VarE d]) + go2 marker_added d ((rnd, (MkTy2 ty)) : rst) = do + d' <- gensym "writecur" + case ty of + _ | isPackedTy ty -> do + rnd' <- go freeVarToVarEnv tenv senv rnd + end_scalars_alloc <- gensym "end_scalars_alloc" + ( if not marker_added + then LetE (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation (sloc)) + else id + ) + <$> LetE (d', [], CursorTy, projEnds rnd') + <$> go2 True d' rst + + -- Int, Float, Sym, or Bool + _ | isScalarTy ty -> do + rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + LetE (d', [], CursorTy, Ext $ WriteScalar (mkScalar ty) d rnd') + <$> go2 marker_added d' rst + + -- Write a pointer to a vector + VectorTy el_ty -> do + rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + LetE (d', [], CursorTy, Ext $ WriteVector d rnd' (stripTyLocs el_ty)) + <$> go2 marker_added d' rst + + -- Write a pointer to a vector + ListTy el_ty -> do + rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + LetE (d', [], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) + <$> go2 marker_added d' rst + + -- shortcut pointer + CursorTy -> do + rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + LetE (d', [], CursorTy, Ext $ WriteTaggedCursor d rnd') + <$> go2 marker_added d' rst + _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty + + writetag <- gensym "writetag" + after_tag <- gensym "after_tag" + start_tag_alloc <- gensym "start_tag_alloc" + end_tag_alloc <- gensym "end_tag_alloc" + start_scalars_alloc <- gensym "start_scalars_alloc" + dl + <$> LetE (start_tag_alloc, [], ProdTy [], Ext $ StartTagAllocation (sloc)) + <$> LetE (writetag, [], CursorTy, Ext $ WriteTag dcon (sloc)) + <$> LetE (end_tag_alloc, [], ProdTy [], Ext $ EndTagAllocation (sloc)) + <$> LetE (start_scalars_alloc, [], ProdTy [], Ext $ StartScalarsAllocation (sloc)) + <$> LetE (after_tag, [], CursorTy, Ext $ AddCursor (sloc) (L3.LitE 1)) + <$> go2 False after_tag (zip args (lookupDataCon ddfs dcon)) + else do + let sloc_loc = toLocVar slocarg + dcon_loc = getDconLoc sloc_loc + field_locs = getAllFieldLocsSoA sloc_loc + sloc = case (M.lookup (fromLocVarToFreeVarsTy sloc_loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeExp(1056): DataConE: unexpected location variable" ++ "(" ++ show sloc_loc ++ ")" ++ show freeVarToVarEnv + (sloc_dcon, present, freeVarToVarEnv') = case (M.lookup (fromLocVarToFreeVarsTy dcon_loc) freeVarToVarEnv) of + Just v -> (v, True, freeVarToVarEnv) + Nothing -> case dcon_loc of + Single l -> (l, False, (M.insert (fromLocVarToFreeVarsTy dcon_loc) l freeVarToVarEnv)) + _ -> error $ "cursorizeExp(1059): DataConE: unexpected dcon location variable" ++ "(" ++ show (dcon, dcon_loc) ++ ")" ++ show freeVarToVarEnv + -- Return (start,end) cursors + -- The final return value lives at the position of the out cursors: + -- go2 :: Bool -> Var -> [(Exp2, Ty2)] -> PassM Exp3 + -- go2 marker_added d [] = + -- if not (marker_added) + -- then do + -- end_scalars_alloc <- gensym "end_scalars_alloc" + -- return (LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation sloc) + -- (MkProdE [VarE (sloc), VarE d])) + -- else return (MkProdE [VarE (sloc), VarE d]) + + -- go2 marker_added d ((rnd, (MkTy2 ty)):rst) = do + -- d' <- gensym "writecur" + -- case ty of + -- _ | isPackedTy ty -> do + + -- rnd' <- go freeVarToVarEnv tenv senv rnd + -- end_scalars_alloc <- gensym "end_scalars_alloc" + -- (if not marker_added + -- then LetE (end_scalars_alloc,[],ProdTy [],Ext $ EndScalarsAllocation (sloc)) + -- else id) <$> + -- LetE (d',[], CursorTy, projEnds rnd') <$> + -- go2 True d' rst + + -- -- Int, Float, Sym, or Bool + -- _ | isScalarTy ty -> do + -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd + -- LetE (d',[], CursorTy, Ext $ WriteScalar (mkScalar ty) d rnd') <$> + -- go2 marker_added d' rst + + -- -- Write a pointer to a vector + -- VectorTy el_ty -> do + -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd + -- LetE (d',[], CursorTy, Ext $ WriteVector d rnd' (stripTyLocs el_ty)) <$> + -- go2 marker_added d' rst + + -- -- Write a pointer to a vector + -- ListTy el_ty -> do + -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd + -- LetE (d',[], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> + -- go2 marker_added d' rst + + -- -- shortcut pointer + -- CursorTy -> do + -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd + -- LetE (d',[], CursorTy, Ext $ WriteTaggedCursor d rnd') <$> + -- go2 marker_added d' rst + -- _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty + + dummy :: PassM Exp3 + dummy = return $ VarE (sloc) + + go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> Maybe Var -> [((DataCon, Int), LocVar)] -> [((DataCon, Int), Maybe LocVar, (Exp2, Ty2))] -> PassM Exp3 + go2 marker_added fvarenv aft_dloc from_rec_end aft_flocs [] = do + let curr_soa_loc = sloc + if not (marker_added) + then do + after_soa_loc <- gensym "aft_soa_loc" + let after_flocs_to_vars = + map + ( \(_, floc) -> case (M.lookup (fromLocVarToFreeVarsTy $ floc) fvarenv) of + Just v -> v + Nothing -> case floc of + Single l -> l + _ -> error $ "cursorizeExp (1123): DataConE: unexpected location variable" ++ "(" ++ show (dcon, floc) ++ ")" ++ show fvarenv + ) + aft_flocs + let makeCurArr = Ext $ MakeCursorArray (1 + length (aft_flocs)) ([aft_dloc] ++ after_flocs_to_vars) + let let_mk_cur_arr = LetE (after_soa_loc, [], CursorArrayTy (1 + length (aft_flocs)), makeCurArr) + end_scalars_alloc <- gensym "end_scalars_alloc" + return + ( let_mk_cur_arr $ + LetE + (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation (curr_soa_loc)) + (MkProdE [VarE (curr_soa_loc), VarE (after_soa_loc)]) + ) + else do + let rec_end_var = case from_rec_end of + Just v -> v + Nothing -> error "cursorizeExp: go2: expected a recursive end." + return (MkProdE [VarE (curr_soa_loc), VarE (rec_end_var)]) + go2 marker_added fvarenv aft_dloc from_rec_end aft_flocs (((dcon, index), floc, (rnd, (MkTy2 ty))) : rst) = do + d' <- gensym "writecur" + case ty of + PackedTy _ l -> do + let cur_ty = case l of + Single _ -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length (fields)) + rnd' <- go freeVarToVarEnv' tenv senv rnd + end_scalars_alloc <- gensym "end_scalars_alloc" + ( if not marker_added + then LetE (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation (sloc)) + else id + ) + <$> LetE (d', [], cur_ty, projEnds rnd') + <$> go2 True fvarenv aft_dloc (Just d') aft_flocs rst + _ | isScalarTy ty -> do + rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd + -- get the location variable where the scalar must be written + let floc_loc = case floc of + Just l -> l + Nothing -> error "cursorizeExp: DataConE: expected a location for scalar buffer" + let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv) of + Just v -> v + Nothing -> case floc_loc of + Single l -> l + SoA _ _ -> error $ "cursorizePackedExp: DataConE(" ++ show dcon ++ ") : unexpected location variable " ++ ":" ++ show floc_loc ++ "\n\n" ++ show fvarenv + write_scalars_at <- gensym "write_scalars_at" + let let_assign_write_cur = LetE (write_scalars_at, [], CursorTy, (VarE floc_var)) + {- Update, aft_flocs with the correct location for the scalar field -} + {- TODO: Audit aft_flocs' and fvarenv'-} + {- TODO: Check if its fine to use singleLocVar d' here!! -} + let aft_flocs' = + map + ( \((d, idx'), l) -> + if d == dcon && idx' == index + then ((d, idx'), singleLocVar d') + else ((d, idx'), l) + ) + aft_flocs + let fvarenv' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv + let_assign_write_cur + <$> LetE (d', [], CursorTy, Ext $ WriteScalar (mkScalar ty) write_scalars_at rnd') + <$> go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst + + -- Write a pointer to a vector + VectorTy el_ty -> do + rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd + -- get the location variable where the scalar must be written + let floc_loc = case floc of + Just l -> l + Nothing -> error "cursorizeExp: DataConE: expected a location for scalar buffer" + let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv) of + Just v -> v + Nothing -> case floc_loc of + Single l -> l + SoA _ _ -> error $ "cursorizePackedExp: DataConE(" ++ show dcon ++ ") : unexpected location variable " ++ ":" ++ show floc_loc ++ "\n\n" ++ show fvarenv + write_vector_at <- gensym "write_vector_at" + let let_assign_write_cur = LetE (write_vector_at, [], CursorTy, (VarE floc_var)) + {- Update, aft_flocs with the correct location for the scalar field -} + {- TODO: Audit aft_flocs' and fvarenv'-} + {- TODO: Check if its fine to use singleLocVar d' here!! -} + let aft_flocs' = + map + ( \((d, idx'), l) -> + if d == dcon && idx' == index + then ((d, idx'), singleLocVar d') + else ((d, idx'), l) + ) + aft_flocs + let fvarenv' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv + let_assign_write_cur + <$> LetE (d', [], CursorTy, Ext $ WriteVector write_vector_at rnd' (stripTyLocs el_ty)) + <$> go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst + + -- _ -> error $ "TODO: Cursorize: cursorizePackedExp: Ty not implemented!! " ++ show (ty) + + -- -- Write a pointer to a vector + -- ListTy el_ty -> do + -- rnd' <- cursorizeExp freeVarToVarEnv ddfs fundefs denv tenv senv rnd + -- LetE (d',[], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> + -- go2 marker_added d' rst + + -- shortcut pointer + -- SoA case + -- Fix case for indirection/shortcut pointers + CursorTy -> do + rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd + after_indirection <- gensym "aft_indirection" + casted_var <- gensym "cast" + let rnd_var = case rnd' of + VarE v -> v + _ -> error "Did not expected variable!" + LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) + <$> LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) + <$> LetE (after_indirection, [], CursorTy, VarE d') + <$> go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty + + writetag <- gensym "writetag" + after_tag <- gensym "after_tag" + start_tag_alloc <- gensym "start_tag_alloc" + end_tag_alloc <- gensym "end_tag_alloc" + start_scalars_alloc <- gensym "start_scalars_alloc" + let exp_f_tys = zip args (lookupDataCon ddfs dcon) + -- [((DataCon, Int), Maybe Location, (Exp2, Ty2))] + let locs_tys = + map + ( \e@(rnd, (MkTy2 ty)) -> + let idx = case (L.elemIndex e exp_f_tys) of + Just idx -> idx + Nothing -> error "cursorizeExp: DataConE: field not found!" + key = (dcon, idx) + loc = L.lookup key field_locs + in (key, loc, e) + ) + exp_f_tys + let additional_bnds = + if present + then [] + else [(sloc_dcon, [], CursorTy, Ext $ IndexCursorArray sloc 0)] + (additional_bnds', freeVarToVarEnv'', _) <- + foldlM + ( \(b, env, idx') ((_, _), loc) -> do + (var_for_loc, present', env') <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of + Just v -> return $ (v, True, env) + Nothing -> case loc of + Single l -> return $ (l, False, env) + SoA {} -> do + new_name <- gensym "field_cursor" + let env'' = M.insert (fromLocVarToFreeVarsTy loc) new_name env + return $ (new_name, False, env'') + let b' = + if present' + then b + else b ++ [(var_for_loc, [], CursorTy, Ext $ IndexCursorArray sloc idx')] + pure (b', env', idx' + 1) + ) + (additional_bnds, freeVarToVarEnv', 1) + field_locs + + dl + <$> + -- Make sure that the field locations and data locations are released here + -- We can clean them up later. + -- data con location + mkLets additional_bnds' + <$> LetE (start_tag_alloc, [], ProdTy [], Ext $ StartTagAllocation (sloc)) + <$> LetE (writetag, [], CursorTy, Ext $ WriteTag dcon (sloc_dcon)) + <$> LetE (end_tag_alloc, [], ProdTy [], Ext $ EndTagAllocation (sloc)) + <$> LetE (start_scalars_alloc, [], ProdTy [], Ext $ StartScalarsAllocation (sloc)) + <$> LetE (after_tag, [], CursorTy, Ext $ AddCursor (sloc_dcon) (L3.LitE 1)) + <$> go2 False freeVarToVarEnv'' after_tag Nothing field_locs locs_tys + + -- go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> [((DataCon, Int), Location, (Exp2, Ty2))] -> [((DataCon, Int), Location, (Exp2, Ty2))] -> PassM Exp3 + -- go2 False after_tag (zip args (lookupDataCon ddfs dcon)) TimeIt e t b -> do Di e' <- go freeVarToVarEnv tenv senv e return $ Di $ TimeIt e' (cursorizeTy (unTy2 t)) b - WithArenaE v e -> do Di e' <- go freeVarToVarEnv (M.insert v (MkTy2 ArenaTy) tenv) senv e return $ Di $ WithArenaE v e' - - SpawnE{} -> error "cursorizePackedExp: Unbound SpawnE" - SyncE{} -> error "cursorizePackedExp: Unbound SyncE" - + SpawnE {} -> error "cursorizePackedExp: Unbound SpawnE" + SyncE {} -> error "cursorizePackedExp: Unbound SyncE" Ext ext -> case ext of -- All locations are transformed into cursors here. Location arithmetic -- is expressed in terms of corresponding cursor operations. -- See `cursorizeLocExp` LetLocE loc rhs bod -> do - freeVarToVarEnv' <- do - case loc of - Single l -> if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv - then return freeVarToVarEnv - else return $ M.insert (fromLocVarToFreeVarsTy loc) l freeVarToVarEnv - SoA _ _ -> if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv - then return $ freeVarToVarEnv - else do - name <- gensym "cursor_ptr" - return $ M.insert (fromLocVarToFreeVarsTy loc) name freeVarToVarEnv + freeVarToVarEnv' <- do + case loc of + Single l -> + if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv + then return freeVarToVarEnv + else return $ M.insert (fromLocVarToFreeVarsTy loc) l freeVarToVarEnv + SoA _ _ -> + if M.member (fromLocVarToFreeVarsTy loc) freeVarToVarEnv + then return $ freeVarToVarEnv + else do + name <- gensym "cursor_ptr" + return $ M.insert (fromLocVarToFreeVarsTy loc) name freeVarToVarEnv let rhs_either = dbgTrace (minChatLvl) "Print env" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv')) dbgTrace (minChatLvl) "End env\n" cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs - (bnds,tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of - Nothing -> ([],tenv) - Just vs -> let extended = M.fromList [ (v, MkTy2 CursorTy) | (v,_,CursorTy,_) <- vs] - in (vs, M.union extended tenv) + (bnds, tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of + Nothing -> ([], tenv) + Just vs -> + let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] + in (vs, M.union extended tenv) case rhs_either of Right (rhs', bnds', tenv'', senv') -> do let tenv''' = M.union tenv' tenv'' - let locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of - Just v -> v - Nothing -> case loc of - Single lvarrr -> lvarrr - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of + Just v -> v + Nothing -> case loc of + Single lvarrr -> lvarrr + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" let locs_ty3 :: Ty3 = case loc of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) + Single _ -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length (fields)) let locs_ty2 = case loc of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) + Single _ -> CursorTy + SoA _ fields -> CursorArrayTy (1 + length (fields)) case rhs of - FromEndLE{} -> + FromEndLE {} -> if isBound locs_var tenv - then go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod + then go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod -- Discharge bindings that were waiting on 'loc'. - else onDi (mkLets (bnds' ++ [(locs_var,[],locs_ty3,rhs')] ++ bnds)) <$> - go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv') senv' bod - -- Discharge bindings that were waiting on 'loc'. - _ -> onDi (mkLets (bnds' ++ [(locs_var,[],locs_ty3,rhs')] ++ bnds)) <$> - go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod - Left denv' -> onDi (mkLets bnds) <$> - cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod - - {-VS: TODO: This needs to be fixed to produce the correct L3 expression. See above. -} - {- Right now i just skip the let region, just recurse on the body-} + else + onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) + <$> go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv') senv' bod + -- Discharge bindings that were waiting on 'loc'. + _ -> + onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) + <$> go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod + Left denv' -> + onDi (mkLets bnds) + <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + + {-VS: TODO: This needs to be fixed to produce the correct L3 expression. See above. -} + {- Right now i just skip the let region, just recurse on the body-} LetRegE loc rhs bod -> do - --let loc = fromRegVarToLocVar reg_var - -- let ty_of_loc = case loc of + -- let loc = fromRegVarToLocVar reg_var + -- let ty_of_loc = case loc of -- SingleR _ -> CursorTy -- SoARv _ flds -> CursorArrayTy (1 + length flds) - let ty_of_loc = case loc of - SingleR _ -> MutCursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - let ty2_of_loc :: Ty2 = case loc of - SingleR _ -> MkTy2 MutCursorTy - SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) - freeVarToVarEnv' <- do - case loc of - SingleR l -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv - then return freeVarToVarEnv - else return $ M.insert (fromRegVarToFreeVarsTy loc) l freeVarToVarEnv - SoARv _ _ -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv - then return $ freeVarToVarEnv - else do - name <- gensym "cursor_ptr" - return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv + let ty_of_loc = case loc of + SingleR _ -> MutCursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + let ty2_of_loc :: Ty2 = case loc of + SingleR _ -> MkTy2 MutCursorTy + SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) + freeVarToVarEnv' <- do + case loc of + SingleR l -> + if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv + then return freeVarToVarEnv + else return $ M.insert (fromRegVarToFreeVarsTy loc) l freeVarToVarEnv + SoARv _ _ -> + if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv + then return $ freeVarToVarEnv + else do + name <- gensym "cursor_ptr" + return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv let rhs_either = cursorizeRegExp freeVarToVarEnv' denv tenv senv loc rhs - (bnds,tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of - Nothing -> ([],tenv) - Just vs -> let extended = M.fromList [ (v, MkTy2 CursorTy) | (v,_,CursorTy,_) <- vs] - in (vs, M.union extended tenv) + (bnds, tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of + Nothing -> ([], tenv) + Just vs -> + let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] + in (vs, M.union extended tenv) case rhs_either of Right (rhs', bnds', tenv'', senv') -> do let tenv''' = M.union tenv' tenv'' - let locs_var = case (M.lookup (fromRegVarToFreeVarsTy loc) freeVarToVarEnv') of - Just v -> v - Nothing -> case loc of - SingleR lvarrr -> lvarrr - SoARv _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let locs_var = case (M.lookup (fromRegVarToFreeVarsTy loc) freeVarToVarEnv') of + Just v -> v + Nothing -> case loc of + SingleR lvarrr -> lvarrr + SoARv _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" case rhs of - -- Discharge bindings that were waiting on 'loc'. + -- Discharge bindings that were waiting on 'loc'. _ -> do - case ty_of_loc of - MutCursorTy -> onDi (mkLets (bnds' ++ [(locs_var,[],ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds)) <$> - go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - _ -> onDi (mkLets (bnds' ++ [(locs_var,[],ty_of_loc,rhs')] ++ bnds)) <$> - go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - - Left denv' -> onDi (mkLets bnds) <$> - cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod - -- case reg_var of - -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod - -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod + case ty_of_loc of + MutCursorTy -> + onDi (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds)) + <$> go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + _ -> + onDi (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, rhs')] ++ bnds)) + <$> go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + Left denv' -> + onDi (mkLets bnds) + <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + -- case reg_var of + -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod + -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod StartOfPkdCursor cur -> return $ dl $ VarE cur - TagCursor a b -> do - let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar a) of - Single l -> l - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - let b_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar b)) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar b) of - Single l -> l - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - + let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar a) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + let b_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar b)) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar b) of + Single l -> l + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + return $ dl $ Ext $ L3.TagCursor a_var b_var -- ASSUMPTION: RetE forms are inserted at the tail position of functions, @@ -1569,144 +1696,157 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = RetE locs v -> do v' <- go freeVarToVarEnv tenv senv (VarE v) case locs of - [] -> return v' + [] -> return v' [loc] -> do - let loc_to_free_var = fromLocArgToFreeVarsTy loc - let locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar loc) of - Single lvarr -> lvarr - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - - pure $ mkDi (VarE (locs_variable)) [ fromDi v' ] - _ -> return $ Di $ L3.MkProdE $ L.foldr (\loc acc -> let loc_to_free_var = fromLocArgToFreeVarsTy loc - locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of - Just v -> v - Nothing -> case (toLocVar loc) of - Single lvarr -> lvarr - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - in (VarE (locs_variable)):acc - ) [fromDi v'] locs - + let loc_to_free_var = fromLocArgToFreeVarsTy loc + let locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar loc) of + Single lvarr -> lvarr + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + + pure $ mkDi (VarE (locs_variable)) [fromDi v'] + _ -> + return $ + Di $ + L3.MkProdE $ + L.foldr + ( \loc acc -> + let loc_to_free_var = fromLocArgToFreeVarsTy loc + locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of + Just v -> v + Nothing -> case (toLocVar loc) of + Single lvarr -> lvarr + SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + in (VarE (locs_variable)) : acc + ) + [fromDi v'] + locs LetRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False r sz let reg_var = regionToVar r - let reg_ty = case reg_var of - SingleR{} -> MkTy2 CursorTy - SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) - - reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of - Just var -> return var - Nothing -> do - case reg_var of - SingleR v -> return v - SoARv{} -> do - n <- gensym "region_cursor_ptr" - return n - - -- For end of the region - reg_var_name_end <- case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) freeVarToVarEnv') of - Just var -> return var - Nothing -> do - case reg_var of - SingleR v -> return $ toEndV v - SoARv{} -> do - n <- gensym "region_cursor_ptr_end" - return n + let reg_ty = case reg_var of + SingleR {} -> MkTy2 CursorTy + SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) + + reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return v + SoARv {} -> do + n <- gensym "region_cursor_ptr" + return n + + -- For end of the region + reg_var_name_end <- case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) freeVarToVarEnv') of + Just var -> return var + Nothing -> do + case reg_var of + SingleR v -> return $ toEndV v + SoARv {} -> do + n <- gensym "region_cursor_ptr_end" + return n let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_var) reg_var_name freeVarToVarEnv' let freeVarToVarEnv''' = M.insert (fromRegVarToFreeVarsTy (toEndVRegVar reg_var)) reg_var_name_end freeVarToVarEnv'' - let tenv' = M.insert reg_var_name reg_ty tenv let tenv'' = M.insert reg_var_name_end reg_ty tenv' onDi (mkLets (region_lets)) <$> go freeVarToVarEnv''' tenv'' senv bod - LetParRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv True r sz onDi (mkLets (region_lets)) <$> go freeVarToVarEnv' tenv senv bod - - FromEndE{} -> error $ "cursorizePackedExp: TODO " ++ sdoc ext - + FromEndE {} -> error $ "cursorizePackedExp: TODO " ++ sdoc ext BoundsCheck i bound cur -> return <$> dl <$> Ext $ L3.BoundsCheck i (((unwrapLocVar . toLocVar)) bound) (((unwrapLocVar . toLocVar)) cur) - - IndirectionE tycon dcon (from,from_reg) (to,to_reg) _ -> do + IndirectionE tycon dcon (from, from_reg) (to, to_reg) _ -> do dflags <- getDynFlags if gopt Opt_DisableGC dflags - -- || (from_reg == "dummy" || to_reg == "dummy") -- HACK!!! - -- [2022.03.02]: ckoparkar:WTH does this hack enable? - then do - let locs_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of - Nothing -> error "Did not find variable for location!" - Just var -> var - go freeVarToVarEnv tenv senv (DataConE from dcon [VarE locs_var]) - else do - case (toLocVar from) of - Single{} -> do - start <- gensym "start" - end <- gensym "end" - let from_var = case M.lookup (fromLocArgToFreeVarsTy from) freeVarToVarEnv of - Nothing -> error "Did not find variable for location!" - Just var -> var - let to_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of - Nothing -> error "Did not find variable for location!" - Just var -> var - let reg_from_reg = fromLocVarToRegVar (toLocVar from_reg) - let reg_to_reg = fromLocVarToRegVar (toLocVar to_reg) - let from_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_from_reg) freeVarToVarEnv of - Nothing -> error "Did not find variable for location!" - Just var -> var - let to_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_to_reg) freeVarToVarEnv of - Nothing -> error "Did not find variable for location!" - Just var -> var - -- VS : [09/20/2025 -- For SoA case, indirection with gc need a bit more thinking] - -- One way could be to call indirection barrier seperately on every buffer/region - -- Then follow them seperately for every region in the case. - -- For now i'm erroring out but this needs more thought. - return $ Di $ - (mkLets [("_",[],ProdTy [],Ext (IndirectionBarrier tycon ((from_var),(from_reg_var),(to_var),(to_reg_var)))), - (start, [], CursorTy, VarE (from_var)), - (end, [], CursorTy, Ext $ AddCursor (from_var) (L3.LitE 9))] - (MkProdE [VarE start, VarE end])) - SoA _ flds -> error "Indirection when GC is enabled is not implemented for SoA! Please turn off the GC!" - - AddFixed{} -> error "cursorizePackedExp: AddFixed not handled." - + -- \|| (from_reg == "dummy" || to_reg == "dummy") -- HACK!!! + -- [2022.03.02]: ckoparkar:WTH does this hack enable? + then do + let locs_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + go freeVarToVarEnv tenv senv (DataConE from dcon [VarE locs_var]) + else do + case (toLocVar from) of + Single {} -> do + start <- gensym "start" + end <- gensym "end" + let from_var = case M.lookup (fromLocArgToFreeVarsTy from) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let to_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let reg_from_reg = fromLocVarToRegVar (toLocVar from_reg) + let reg_to_reg = fromLocVarToRegVar (toLocVar to_reg) + let from_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_from_reg) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let to_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_to_reg) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + -- VS : [09/20/2025 -- For SoA case, indirection with gc need a bit more thinking] + -- One way could be to call indirection barrier seperately on every buffer/region + -- Then follow them seperately for every region in the case. + -- For now i'm erroring out but this needs more thought. + return $ + Di $ + ( mkLets + [ ("_", [], ProdTy [], Ext (IndirectionBarrier tycon ((from_var), (from_reg_var), (to_var), (to_reg_var)))), + (start, [], CursorTy, VarE (from_var)), + (end, [], CursorTy, Ext $ AddCursor (from_var) (L3.LitE 9)) + ] + (MkProdE [VarE start, VarE end]) + ) + SoA _ flds -> error "Indirection when GC is enabled is not implemented for SoA! Please turn off the GC!" + AddFixed {} -> error "cursorizePackedExp: AddFixed not handled." GetCilkWorkerNum -> pure $ Di (Ext L3.GetCilkWorkerNum) - - LetAvail vs bod -> do + LetAvail vs bod -> do onDi (Ext . L3.LetAvail vs) <$> go freeVarToVarEnv tenv senv bod - AllocateTagHere v tycon -> pure <$> dl <$> Ext $ L3.AllocateTagHere (unwrapLocVar v) tycon - AllocateScalarsHere v -> pure <$> dl <$> Ext $ L3.AllocateScalarsHere (unwrapLocVar v) - SSPush a b c d -> pure <$> dl <$> Ext $ L3.SSPush a (unwrapLocVar b) (unwrapLocVar c) d SSPop a b c -> pure <$> dl <$> Ext $ L3.SSPop a (unwrapLocVar b) (unwrapLocVar c) - - MapE{} -> error $ "TODO: cursorizePackedExp MapE" - FoldE{} -> error $ "TODO: cursorizePackedExp FoldE" - - where go env = cursorizePackedExp env lenv ddfs fundefs denv - dl = Di - - -cursorizeReadPackedFile :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Bool -> Var - -> Maybe FilePath -> TyCon -> Maybe Var -> Ty2 -> Exp2 - -> PassM Exp3 + MapE {} -> error $ "TODO: cursorizePackedExp MapE" + FoldE {} -> error $ "TODO: cursorizePackedExp FoldE" + where + go env = cursorizePackedExp env lenv ddfs fundefs denv + dl = Di + +cursorizeReadPackedFile :: + M.Map FreeVarsTy Var -> + M.Map Var (Maybe LocVar) -> + DDefs Ty2 -> + FunDefs2 -> + DepEnv -> + TyEnv Var Ty2 -> + SyncEnv -> + Bool -> + Var -> + Maybe FilePath -> + TyCon -> + Maybe Var -> + Ty2 -> + Exp2 -> + PassM Exp3 cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv isPackedContext v path tyc reg ty2 bod = do case reg of Nothing -> error $ "cursorizePackedExp: InferLocations did not set the reg for ReadPackedFile." Just reg_var -> - mkLets [ (v, [], CursorTy, PrimAppE (toL3Prim $ ReadPackedFile path tyc reg ty2) []) - , (reg_var, [], CursorTy, VarE v) - , (toEndV reg_var, [], CursorTy, Ext$ AddCursor reg_var (Ext $ MMapFileSize v))] <$> - go (M.insert v (MkTy2 CursorTy) tenv) bod - + mkLets + [ (v, [], CursorTy, PrimAppE (toL3Prim $ ReadPackedFile path tyc reg ty2) []), + (reg_var, [], CursorTy, VarE v), + (toEndV reg_var, [], CursorTy, Ext $ AddCursor reg_var (Ext $ MMapFileSize v)) + ] + <$> go (M.insert v (MkTy2 CursorTy) tenv) bod where - go t e = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv e - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv e + go t e = + if isPackedContext + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv e + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv e -- We may sometimes encounter a letloc which uses an unbound location. -- @@ -1718,246 +1858,246 @@ cursorizeLocExp :: M.Map FreeVarsTy Var -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = case locExp of AfterConstantLE i loc -> - let locs_var = case (M.lookup ((fromLocVarToFreeVarsTy . toLocVar) loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (toLocVar loc)) ++ ")" ++ show freeVarToVarEnv + let locs_var = case (M.lookup ((fromLocVarToFreeVarsTy . toLocVar) loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (toLocVar loc)) ++ ")" ++ show freeVarToVarEnv rhs = Ext $ AddCursor locs_var (LitE i) - lvar_to_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show lvar) ++ ")" ++ show freeVarToVarEnv + lvar_to_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show lvar) ++ ")" ++ show freeVarToVarEnv in if isBound locs_var tenv - then Right (rhs, [], tenv, senv) - else Left$ M.insertWith (++) ((fromLocVarToFreeVarsTy . toLocVar) loc) [(lvar_to_name,[],CursorTy,rhs)] denv + then Right (rhs, [], tenv, senv) + else Left $ M.insertWith (++) ((fromLocVarToFreeVarsTy . toLocVar) loc) [(lvar_to_name, [], CursorTy, rhs)] denv -- TODO: handle product types here -{- [2018.03.07]: + {- [2018.03.07]: -Changing it's meaning to just be "after a variable", but not offset from any -particular location. Such an offset requires calculating the size of the variable. -For BigInfinite regions, this is simple: + Changing it's meaning to just be "after a variable", but not offset from any + particular location. Such an offset requires calculating the size of the variable. + For BigInfinite regions, this is simple: - size = (endof v) - v + size = (endof v) - v -But Infinite regions do not support sizes yet. Re-enable this later. --} + But Infinite regions do not support sizes yet. Re-enable this later. + -} AfterVariableLE v locarg was_stolen -> do let vty = case M.lookup v tenv of - Just ty -> ty - Nothing -> case M.lookup v senv of - Just pending_bnds -> - let tenv' = foldr (\(v1,_,_,ty2,_) env -> M.insert v1 ty2 env) tenv pending_bnds - in case M.lookup v tenv' of - Nothing -> error ("cursorizeLocExp: AfterVariableLE, undound var: " ++ sdoc v) - Just ty -> ty - Nothing -> error $ "cursorizeLocExp: Var " ++ sdoc v ++ " not found. " + Just ty -> ty + Nothing -> case M.lookup v senv of + Just pending_bnds -> + let tenv' = foldr (\(v1, _, _, ty2, _) env -> M.insert v1 ty2 env) tenv pending_bnds + in case M.lookup v tenv' of + Nothing -> error ("cursorizeLocExp: AfterVariableLE, undound var: " ++ sdoc v) + Just ty -> ty + Nothing -> error $ "cursorizeLocExp: Var " ++ sdoc v ++ " not found. " loc = toLocVar locarg - locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: AfterConstantLE: unexpected location variable" + locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: AfterConstantLE: unexpected location variable" bod = case unTy2 vty of - PackedTy{} -> VarE (toEndV v) - CursorTy -> VarE (toEndV v) -{- - IntTy -> let sizeVal = LitE (fromJust $ sizeOfTy IntTy) - rhs = Ext $ AddCursor loc sizeVal - in rhs - FloatTy -> let sizeVal = LitE (fromJust $ sizeOfTy FloatTy) - rhs = Ext $ AddCursor loc sizeVal - in rhs - BoolTy -> let sizeVal = LitE (fromJust $ sizeOfTy BoolTy) - rhs = Ext $ AddCursor loc sizeVal - in rhs - CharTy -> let sizeVal = LitE (fromJust $ sizeOfTy CharTy) - rhs = Ext $ AddCursor loc sizeVal - in rhs - SymTy -> let sizeVal = LitE (fromJust $ sizeOfTy SymTy) - rhs = Ext $ AddCursor loc sizeVal - in rhs - VectorTy elty -> let sizeVal = LitE (fromJust $ sizeOfTy (VectorTy elty)) - rhs = Ext $ AddCursor loc sizeVal - in rhs - ListTy elty -> let sizeVal = LitE (fromJust $ sizeOfTy (ListTy elty)) - rhs = Ext $ AddCursor loc sizeVal - in rhs --} - oth -> error $ "cursorizeLocExp: AfterVariable TODO " ++ sdoc oth - lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv + PackedTy {} -> VarE (toEndV v) + CursorTy -> VarE (toEndV v) + {- + IntTy -> let sizeVal = LitE (fromJust $ sizeOfTy IntTy) + rhs = Ext $ AddCursor loc sizeVal + in rhs + FloatTy -> let sizeVal = LitE (fromJust $ sizeOfTy FloatTy) + rhs = Ext $ AddCursor loc sizeVal + in rhs + BoolTy -> let sizeVal = LitE (fromJust $ sizeOfTy BoolTy) + rhs = Ext $ AddCursor loc sizeVal + in rhs + CharTy -> let sizeVal = LitE (fromJust $ sizeOfTy CharTy) + rhs = Ext $ AddCursor loc sizeVal + in rhs + SymTy -> let sizeVal = LitE (fromJust $ sizeOfTy SymTy) + rhs = Ext $ AddCursor loc sizeVal + in rhs + VectorTy elty -> let sizeVal = LitE (fromJust $ sizeOfTy (VectorTy elty)) + rhs = Ext $ AddCursor loc sizeVal + in rhs + ListTy elty -> let sizeVal = LitE (fromJust $ sizeOfTy (ListTy elty)) + rhs = Ext $ AddCursor loc sizeVal + in rhs + -} + oth -> error $ "cursorizeLocExp: AfterVariable TODO " ++ sdoc oth + lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv if isBound locs_var tenv - then if was_stolen - then Right (bod, [], tenv, senv) - -- The continuation was not stolen. It's safe to discharge all - -- pending bindings of this particular variable. - else do + then + if was_stolen + then Right (bod, [], tenv, senv) + -- The continuation was not stolen. It's safe to discharge all + -- pending bindings of this particular variable. + else do case M.lookup v senv of Nothing -> Right (bod, [], tenv, senv) Just pending_bnds -> do - let tenv' = foldr (\(v1,_,_,ty2,_) env -> M.insert v1 ty2 env) tenv pending_bnds - bnds = map (\(a,b,c,_,e) -> (a,b,c,e)) pending_bnds + let tenv' = foldr (\(v1, _, _, ty2, _) env -> M.insert v1 ty2 env) tenv pending_bnds + bnds = map (\(a, b, c, _, e) -> (a, b, c, e)) pending_bnds Right (bod, bnds, tenv', M.delete v senv) - else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name,[],CursorTy,bod)] denv - + else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name, [], CursorTy, bod)] denv FromEndLE locarg -> - let loc = toLocVar locarg - locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeLocExp: FromEndLE: unexpected location variable" ++ "(" ++ show locExp ++ ", Location: " ++ (show (loc)) ++ ")" ++ show freeVarToVarEnv - lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv - in if isBound locs_var tenv - then Right (VarE locs_var, [], tenv, senv) - else Left$ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name,[],CursorTy,VarE locs_var)] denv - StartOfRegionLE r -> case r of - GlobR v _ -> Right (VarE v, [], tenv, senv) - VarR v -> Right (VarE v, [], tenv, senv) - DynR v _ -> Right (VarE v, [], tenv, senv) - -- TODO: docs - MMapR _v -> Left denv - {- VS: TODO: This needs to be fixed. There should be an env. for tracking complex regions liks SoA regs-} - SoAR dr fregs -> - let regions_var = case (M.lookup (fromRegVarToFreeVarsTy (regionToVar r)) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: StartOfRegionLE: unexpected location variable" - - in Right (VarE (regions_var), [], tenv, senv) - - + let loc = toLocVar locarg + locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeLocExp: FromEndLE: unexpected location variable" ++ "(" ++ show locExp ++ ", Location: " ++ (show (loc)) ++ ")" ++ show freeVarToVarEnv + lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv + in if isBound locs_var tenv + then Right (VarE locs_var, [], tenv, senv) + else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name, [], CursorTy, VarE locs_var)] denv + StartOfRegionLE r -> case r of + GlobR v _ -> Right (VarE v, [], tenv, senv) + VarR v -> Right (VarE v, [], tenv, senv) + DynR v _ -> Right (VarE v, [], tenv, senv) + -- TODO: docs + MMapR _v -> Left denv + {- VS: TODO: This needs to be fixed. There should be an env. for tracking complex regions liks SoA regs-} + SoAR dr fregs -> + let regions_var = case (M.lookup (fromRegVarToFreeVarsTy (regionToVar r)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: StartOfRegionLE: unexpected location variable" + in Right (VarE (regions_var), [], tenv, senv) FreeLE -> Left denv -- AUDIT: should we just throw away this information? - - InRegionLE{} -> error $ "cursorizeExp: TODO InRegionLE" - GetDataConLocSoA loc -> + InRegionLE {} -> error $ "cursorizeExp: TODO InRegionLE" + GetDataConLocSoA loc -> {- VS: TODO: instead of using unwrap loc var, we should keep an env mapping a SoA loc to a L3 variable -} let loc_from_logarg = toLocVar loc - loc_var = case (M.lookup (fromLocVarToFreeVarsTy loc_from_logarg) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: GetDataConLocSoA: unexpected location variable" - lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv + loc_var = case (M.lookup (fromLocVarToFreeVarsTy loc_from_logarg) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: GetDataConLocSoA: unexpected location variable" + lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv rhs = Ext $ IndexCursorArray loc_var 0 in if isBound loc_var tenv - then Right (rhs, [], tenv, senv) - -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) - else Left$ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_logarg) [(lvar_name,[],CursorTy,rhs)] denv - GetFieldLocSoA i loc -> + then Right (rhs, [], tenv, senv) + -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) + else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_logarg) [(lvar_name, [], CursorTy, rhs)] denv + GetFieldLocSoA i loc -> {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let loc_from_locarg = toLocVar loc - field_locs = getAllFieldLocsSoA loc_from_locarg - loc_var = case (M.lookup (fromLocVarToFreeVarsTy loc_from_locarg) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: GetDataConLocSoA: unexpected location variable" - field_loc = case L.lookup i field_locs of - Just loc -> loc - Nothing -> error "cursorizeLocExp: GetFieldLocSoA: field location not found!" + field_locs = getAllFieldLocsSoA loc_from_locarg + loc_var = case (M.lookup (fromLocVarToFreeVarsTy loc_from_locarg) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: GetDataConLocSoA: unexpected location variable" + field_loc = case L.lookup i field_locs of + Just loc -> loc + Nothing -> error "cursorizeLocExp: GetFieldLocSoA: field location not found!" field_loc_elem = (i, field_loc) - elem_idx = case (L.elemIndex field_loc_elem field_locs) of - Just idx -> idx - Nothing -> error "cursorizeLocExp: GetFieldLocSoA: field location not found!" - lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv - rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx) {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -} + elem_idx = case (L.elemIndex field_loc_elem field_locs) of + Just idx -> idx + Nothing -> error "cursorizeLocExp: GetFieldLocSoA: field location not found!" + lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv + rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -}) in if isBound loc_var tenv - then Right (rhs, [], tenv, senv) - else Left$ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_locarg) [(lvar_name,[],CursorTy,rhs)] denv + then Right (rhs, [], tenv, senv) + else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_locarg) [(lvar_name, [], CursorTy, rhs)] denv GenSoALoc dloc flocs -> - {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} - let dcloc_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar dloc)) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected data constructor location variable" - field_vars = map (\(_, loc) -> case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" - ) flocs - rhs = Ext $ MakeCursorArray (1 + length flocs) ([dcloc_var] ++ field_vars) - in dbgTrace (minChatLvl) "Print freeVarEnv GenSoALoc:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" Right (rhs, [], tenv, senv) - + {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} + let dcloc_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar dloc)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected data constructor location variable" + field_vars = + map + ( \(_, loc) -> case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" + ) + flocs + rhs = Ext $ MakeCursorArray (1 + length flocs) ([dcloc_var] ++ field_vars) + in dbgTrace (minChatLvl) "Print freeVarEnv GenSoALoc:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" Right (rhs, [], tenv, senv) _ -> error $ "cursorizeLocExp: Unexpected locExp: " ++ sdoc locExp cursorizeRegExp :: M.Map FreeVarsTy Var -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> RegVar -> RegExp -> Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv) -cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = - case regExp of - GetDataConRegSoA loc -> - let loc_from_logarg = toLocVar loc - reg_from_loc = fromLocVarToRegVar loc_from_logarg - reg_var = case (M.lookup (fromRegVarToFreeVarsTy reg_from_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (reg_from_loc)) ++ ")" ++ show freeVarToVarEnv - rhs = Ext $ IndexCursorArray reg_var 0 - lvar_name = case (M.lookup (fromRegVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv - in if isBound reg_var tenv +cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = + case regExp of + GetDataConRegSoA loc -> + let loc_from_logarg = toLocVar loc + reg_from_loc = fromLocVarToRegVar loc_from_logarg + reg_var = case (M.lookup (fromRegVarToFreeVarsTy reg_from_loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (reg_from_loc)) ++ ")" ++ show freeVarToVarEnv + rhs = Ext $ IndexCursorArray reg_var 0 + lvar_name = case (M.lookup (fromRegVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv + in if isBound reg_var tenv then Right (rhs, [], tenv, senv) -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) -- VS: Hack: We always want to get a reference to the region. - else Left$ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name,[],MutCursorTy,rhs)] denv - GetFieldRegSoA i loc -> - {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} - let loc_from_locarg = toLocVar loc - field_locs = getAllFieldLocsSoA loc_from_locarg - reg_from_loc = fromLocVarToRegVar loc_from_locarg - loc_var = case (M.lookup (fromRegVarToFreeVarsTy reg_from_loc) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeRegExp: GetFieldRegSoA: unexpected location variable" - field_loc = case L.lookup i field_locs of - Just loc -> loc - Nothing -> error "cursorizeRegExp: GetFieldLocSoA: field location not found!" - field_loc_elem = (i, field_loc) - elem_idx = case (L.elemIndex field_loc_elem field_locs) of - Just idx -> idx - Nothing -> error "cursorizeRegExp: GetFieldLocSoA: field location not found!" - lvar_name = case (M.lookup (fromRegVarToFreeVarsTy lvar) freeVarToVarEnv) of - Just v -> v - Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv - rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx) {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -} - in if isBound loc_var tenv + else Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], MutCursorTy, rhs)] denv + GetFieldRegSoA i loc -> + {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} + let loc_from_locarg = toLocVar loc + field_locs = getAllFieldLocsSoA loc_from_locarg + reg_from_loc = fromLocVarToRegVar loc_from_locarg + loc_var = case (M.lookup (fromRegVarToFreeVarsTy reg_from_loc) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeRegExp: GetFieldRegSoA: unexpected location variable" + field_loc = case L.lookup i field_locs of + Just loc -> loc + Nothing -> error "cursorizeRegExp: GetFieldLocSoA: field location not found!" + field_loc_elem = (i, field_loc) + elem_idx = case (L.elemIndex field_loc_elem field_locs) of + Just idx -> idx + Nothing -> error "cursorizeRegExp: GetFieldLocSoA: field location not found!" + lvar_name = case (M.lookup (fromRegVarToFreeVarsTy lvar) freeVarToVarEnv) of + Just v -> v + Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv + rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -}) + in if isBound loc_var tenv then Right (rhs, [], tenv, senv) - else Left$ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name,[],MutCursorTy,rhs)] denv - - + else Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], MutCursorTy, rhs)] denv findSoAParent :: FreeVarsTy -> M.Map FreeVarsTy Var -> Maybe FreeVarsTy findSoAParent fvar freeVarEnv = case fvar of - R r -> let allKeys = M.keys freeVarEnv - parent = foldr (\k acc -> case k of - R r' -> case (findRegInRegion r' r) of - Just regg -> Just regg - Nothing -> acc - FL l -> acc - V v -> acc - ) Nothing allKeys - in case parent of - Just p -> Just $ R p - Nothing -> Nothing - FL l -> Nothing - V v -> Nothing + R r -> + let allKeys = M.keys freeVarEnv + parent = + foldr + ( \k acc -> case k of + R r' -> case (findRegInRegion r' r) of + Just regg -> Just regg + Nothing -> acc + FL l -> acc + V v -> acc + ) + Nothing + allKeys + in case parent of + Just p -> Just $ R p + Nothing -> Nothing + FL l -> Nothing + V v -> Nothing -- findSoAParentHelper :: FreeVarsTy -> FreeVarsTy -> Maybe FreeVarsTy -- findSoAParentHelper a b = case (a, b) of --- (R r1, R r2) -> if r1 == r2 --- then Just a --- else case r1 of --- SingleR _ -> Nothing +-- (R r1, R r2) -> if r1 == r2 +-- then Just a +-- else case r1 of +-- SingleR _ -> Nothing -- SoAR dcReg fieldRegs -> let check_fields = map (\r -> if r == r2 then Just r else Nothing) fieldRegs --- in +-- in -- FL l -> --- V v -> - - -findRegInRegion :: RegVar -> RegVar -> Maybe RegVar -findRegInRegion r1 r2 = if r1 == r2 - then Just r1 - else case r1 of - SingleR _ -> Nothing - SoARv dcReg fieldRegs -> case r2 of - SingleR _ -> if dcReg == r2 then Just r1 else Nothing - SoARv _ _ -> let found = foldr (\(_ , fr) acc -> if fr == r2 then Just r1 else acc) Nothing fieldRegs - in found - - +-- V v -> + +findRegInRegion :: RegVar -> RegVar -> Maybe RegVar +findRegInRegion r1 r2 = + if r1 == r2 + then Just r1 + else case r1 of + SingleR _ -> Nothing + SoARv dcReg fieldRegs -> case r2 of + SingleR _ -> if dcReg == r2 then Just r1 else Nothing + SoARv _ _ -> + let found = foldr (\(_, fr) acc -> if fr == r2 then Just r1 else acc) Nothing fieldRegs + in found -- ASSUMPTIONS: -- (1) `locs` has [in_regions, out_regions, in_locs, out_locs] for the function. @@ -1970,124 +2110,145 @@ cursorizeAppE :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> DDefs Ty2 - cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case ex of AppE f locs args -> do - let fnTy = case M.lookup f fundefs of - Just g -> funTy g - Nothing -> error $ "Unknown function: " ++ sdoc f - in_tys = arrIns fnTy - inLocs = inLocVars fnTy + let fnTy = case M.lookup f fundefs of + Just g -> funTy g + Nothing -> error $ "Unknown function: " ++ sdoc f + in_tys = arrIns fnTy + inLocs = inLocVars fnTy numRegs = length (outRegVars fnTy) + length (inRegVars fnTy) -- Drop input locations, but keep everything else - outs = (L.take numRegs locs) ++ (L.drop numRegs $ L.drop (length inLocs) $ locs) - argTys = dbgTrace (minChatLvl) "Print locs in cursorize AppE " dbgTrace (minChatLvl) (sdoc (f, locs)) dbgTrace (minChatLvl) "End cursorize AppE\n" map (gRecoverType ddfs (Env2 tenv M.empty)) args - (freeVarToVarEnv', newInsts) <- foldrM (\loc (acc, acc') -> do - let loc_var = fromLocArgToFreeVarsTy loc - nacc <- case (M.lookup (loc_var) freeVarToVarEnv) of - Just v -> return (acc, acc') - Nothing -> case loc_var of - R r -> case r of - SingleR v -> return $ (M.insert loc_var v acc, acc') - SoARv dconReg fieldRegions -> do - -- let us try to find if the SoA region belongs to any other SoA region in the environment. - let parentRegion = findSoAParent loc_var acc - ret <- case parentRegion of - Just par_reg -> do - let name_par_reg = case (M.lookup par_reg acc) of - Just v -> v - Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding parent region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc - name <- gensym "cursor_reg_ptr" - let instrs = [LetE (name, [], CursorArrayTy (1 + length fieldRegions), Ext $ IndexCursorArray (name_par_reg) 1)] - return $ (M.insert loc_var name acc, acc' ++ instrs) - Nothing -> do - (dconReg_var, dcon_insts) <- case (M.lookup (fromRegVarToFreeVarsTy dconReg) acc) of - Just v -> return (v, []) - Nothing -> do - let parent_dcon_end = findSoAParent (fromRegVarToFreeVarsTy dconReg) acc - name_dcon <- case dconReg of - SingleR s -> return s - SoARv _ _ -> do - dnew_name <- gensym "dcon_end" - return dnew_name - case parent_dcon_end of - Just p -> do - let p_var_name = case (M.lookup p acc) of - Just v -> v - Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding parent region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc - let instrs = [LetE (name_dcon, [], CursorTy, Ext $ IndexCursorArray (p_var_name) 0)] - return (name_dcon, instrs) - - -- Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding datacon region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc - let fieldReg_vars = map (\(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy field_reg) acc) of - Just v -> v - Nothing -> error "cursorizeAppE: Did not find an end of region variable for the corresponding field region.\n" - ) fieldRegions - name <- gensym "cursor_reg_ptr" - let instrs = dcon_insts ++ [LetE (name, [], CursorArrayTy (1 + length fieldReg_vars), Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] - dbgTrace (minChatLvl) "Print Reg: " dbgTrace (minChatLvl) (sdoc (f, dconReg, fieldRegions)) dbgTrace (minChatLvl) "End soa Reg\n" return $ (M.insert loc_var name acc, acc' ++ instrs) - pure ret - - - - -- may need to generate instructions to fetch correct end of regions here. - -- Right now I am just leaving this to one level of nesting, in the future this may need to be recursive. - -- let dconReg_var = case (M.lookup (fromRegVarToFreeVarsTy dconReg) acc) of - -- Just v -> v - -- Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding datacon region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc - -- let fieldReg_vars = map (\(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy field_reg) acc) of - -- Just v -> v - -- Nothing -> error "cursorizeAppE: Did not find an end of region variable for the corresponding field region.\n" - -- ) fieldRegions - --name <- gensym "cursor_reg_ptr" - --let instrs = [LetE (name, [], CursorArrayTy (1 + length fieldReg_vars), Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] - --dbgTrace (minChatLvl) "Print Reg: " dbgTrace (minChatLvl) (sdoc (f, dconReg, fieldRegions)) dbgTrace (minChatLvl) "End soa Reg\n" return $ (M.insert loc_var name acc, acc' ++ instrs) - FL l -> case l of - Single v -> return $ (M.insert loc_var v acc, acc') - SoA _ _ -> do - name <- gensym "cursor_ptr" - return $ (M.insert loc_var name acc, acc') - V v -> return $ (M.insert loc_var v acc, acc') - return nacc - ) (freeVarToVarEnv, []) locs - args' <- mapM - (\(t,a) -> if hasPacked (unTy2 t) - then fromDi <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a - else cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a) - (zip in_tys args) + outs = (L.take numRegs locs) ++ (L.drop numRegs $ L.drop (length inLocs) $ locs) + argTys = dbgTrace (minChatLvl) "Print locs in cursorize AppE " dbgTrace (minChatLvl) (sdoc (f, locs)) dbgTrace (minChatLvl) "End cursorize AppE\n" map (gRecoverType ddfs (Env2 tenv M.empty)) args + (freeVarToVarEnv', newInsts) <- + foldrM + ( \loc (acc, acc') -> do + let loc_var = fromLocArgToFreeVarsTy loc + nacc <- case (M.lookup (loc_var) freeVarToVarEnv) of + Just v -> return (acc, acc') + Nothing -> case loc_var of + R r -> case r of + SingleR v -> return $ (M.insert loc_var v acc, acc') + SoARv dconReg fieldRegions -> do + -- let us try to find if the SoA region belongs to any other SoA region in the environment. + let parentRegion = findSoAParent loc_var acc + ret <- case parentRegion of + Just par_reg -> do + let name_par_reg = case (M.lookup par_reg acc) of + Just v -> v + Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding parent region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc + name <- gensym "cursor_reg_ptr" + let instrs = [LetE (name, [], CursorArrayTy (1 + length fieldRegions), Ext $ IndexCursorArray (name_par_reg) 1)] + return $ (M.insert loc_var name acc, acc' ++ instrs) + Nothing -> do + (dconReg_var, dcon_insts) <- case (M.lookup (fromRegVarToFreeVarsTy dconReg) acc) of + Just v -> return (v, []) + Nothing -> do + let parent_dcon_end = findSoAParent (fromRegVarToFreeVarsTy dconReg) acc + name_dcon <- case dconReg of + SingleR s -> return s + SoARv _ _ -> do + dnew_name <- gensym "dcon_end" + return dnew_name + case parent_dcon_end of + Just p -> do + let p_var_name = case (M.lookup p acc) of + Just v -> v + Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding parent region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc + let instrs = [LetE (name_dcon, [], CursorTy, Ext $ IndexCursorArray (p_var_name) 0)] + return (name_dcon, instrs) + + -- Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding datacon region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc + let fieldReg_vars = + map + ( \(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy field_reg) acc) of + Just v -> v + Nothing -> error "cursorizeAppE: Did not find an end of region variable for the corresponding field region.\n" + ) + fieldRegions + name <- gensym "cursor_reg_ptr" + let instrs = dcon_insts ++ [LetE (name, [], CursorArrayTy (1 + length fieldReg_vars), Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] + dbgTrace (minChatLvl) "Print Reg: " dbgTrace (minChatLvl) (sdoc (f, dconReg, fieldRegions)) dbgTrace (minChatLvl) "End soa Reg\n" return $ (M.insert loc_var name acc, acc' ++ instrs) + pure ret + + -- may need to generate instructions to fetch correct end of regions here. + -- Right now I am just leaving this to one level of nesting, in the future this may need to be recursive. + -- let dconReg_var = case (M.lookup (fromRegVarToFreeVarsTy dconReg) acc) of + -- Just v -> v + -- Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding datacon region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc + -- let fieldReg_vars = map (\(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy field_reg) acc) of + -- Just v -> v + -- Nothing -> error "cursorizeAppE: Did not find an end of region variable for the corresponding field region.\n" + -- ) fieldRegions + -- name <- gensym "cursor_reg_ptr" + -- let instrs = [LetE (name, [], CursorArrayTy (1 + length fieldReg_vars), Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] + -- dbgTrace (minChatLvl) "Print Reg: " dbgTrace (minChatLvl) (sdoc (f, dconReg, fieldRegions)) dbgTrace (minChatLvl) "End soa Reg\n" return $ (M.insert loc_var name acc, acc' ++ instrs) + FL l -> case l of + Single v -> return $ (M.insert loc_var v acc, acc') + SoA _ _ -> do + name <- gensym "cursor_ptr" + return $ (M.insert loc_var name acc, acc') + V v -> return $ (M.insert loc_var v acc, acc') + return nacc + ) + (freeVarToVarEnv, []) + locs + args' <- + mapM + ( \(t, a) -> + if hasPacked (unTy2 t) + then fromDi <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a + else cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a + ) + (zip in_tys args) let starts = zipWith giveStarts (map unTy2 argTys) args' - --let loc_var = toLocVar loc - --let loc_to_variable = case (M.lookup (fromLocVarToFreeVarsTy loc_var) freeVarToVarEnv) of - -- Just v -> v + -- let loc_var = toLocVar loc + -- let loc_to_variable = case (M.lookup (fromLocVarToFreeVarsTy loc_var) freeVarToVarEnv) of + -- Just v -> v -- Nothing -> error "cursorizeAppE: unexpected location variable" let bod = case locs of - [] -> AppE f [] starts - _ -> AppE f [] (map (\loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of - Just v -> v - Nothing -> error $ "cursorizeAppE: no variable for location" ++ show loc_var - in VarE (loc_to_variable) - ) outs ++ starts) - asserts <- foldrM (\loc acc -> - case loc of - Loc LREM{lremEndReg,lremLoc} -> do - let lremEndRegToVar = case (M.lookup (fromRegVarToFreeVarsTy lremEndReg) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeAppE: unexpected location variable" - let lremLocToVar = case (M.lookup (fromLocVarToFreeVarsTy lremLoc) freeVarToVarEnv') of - Just v -> v - Nothing -> error "cursorizeAppE: unexpected location variable" - chk <- gensym "chk" - pure $ - LetE (chk,[],BoolTy,PrimAppE LtP [VarE (lremLocToVar), VarE lremEndRegToVar]) $ - LetE ("_",[],ProdTy [], Ext $ Assert (VarE chk)) $ - acc - _ -> pure acc) - bod locs + [] -> AppE f [] starts + _ -> + AppE + f + [] + ( map + ( \loc -> + let loc_var = fromLocArgToFreeVarsTy loc + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of + Just v -> v + Nothing -> error $ "cursorizeAppE: no variable for location" ++ show loc_var + in VarE (loc_to_variable) + ) + outs + ++ starts + ) + asserts <- + foldrM + ( \loc acc -> + case loc of + Loc LREM {lremEndReg, lremLoc} -> do + let lremEndRegToVar = case (M.lookup (fromRegVarToFreeVarsTy lremEndReg) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeAppE: unexpected location variable" + let lremLocToVar = case (M.lookup (fromLocVarToFreeVarsTy lremLoc) freeVarToVarEnv') of + Just v -> v + Nothing -> error "cursorizeAppE: unexpected location variable" + chk <- gensym "chk" + pure $ + LetE (chk, [], BoolTy, PrimAppE LtP [VarE (lremLocToVar), VarE lremEndRegToVar]) $ + LetE ("_", [], ProdTy [], Ext $ Assert (VarE chk)) $ + acc + _ -> pure acc + ) + bod + locs dflags <- getDynFlags if gopt Opt_RtsDebug dflags then do asserts' <- foldrM (\exprs body -> pure $ exprs body) asserts newInsts pure asserts' - else do - bod' <- foldrM (\exprs body -> pure $ exprs body) bod newInsts + else do + bod' <- foldrM (\exprs body -> pure $ exprs body) bod newInsts pure bod' _ -> error $ "cursorizeAppE: Unexpected " ++ sdoc ex @@ -2113,27 +2274,29 @@ Reason: unariser can only eliminate direct projections of this form. cursorizeProj :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeProj freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = case ex of - LetE (v,_locs,ty, rhs@ProjE{}) bod | isPackedTy (unTy2 ty) -> do + LetE (v, _locs, ty, rhs@ProjE {}) bod | isPackedTy (unTy2 ty) -> do rhs' <- go tenv rhs - let ty' = gRecoverType ddfs (Env2 tenv M.empty) rhs + let ty' = gRecoverType ddfs (Env2 tenv M.empty) rhs ty'' = cursorizeTy (unTy2 ty') - bnds = if isPackedTy (unTy2 ty') - then [ (v ,[], projValTy ty'' , mkProj 0 rhs') - , (toEndV v,[], projEndsTy ty'', mkProj 1 rhs') ] - else [(v,[], ty'', rhs')] - tenv' = if isPackedTy (unTy2 ty') - then M.union (M.fromList [(v,ty'), (toEndV v, MkTy2 (projEndsTy (unTy2 ty')))]) tenv - else M.insert v ty' tenv + bnds = + if isPackedTy (unTy2 ty') + then + [ (v, [], projValTy ty'', mkProj 0 rhs'), + (toEndV v, [], projEndsTy ty'', mkProj 1 rhs') + ] + else [(v, [], ty'', rhs')] + tenv' = + if isPackedTy (unTy2 ty') + then M.union (M.fromList [(v, ty'), (toEndV v, MkTy2 (projEndsTy (unTy2 ty')))]) tenv + else M.insert v ty' tenv bod' <- go tenv' bod return $ mkLets bnds bod' - _ -> error $ "cursorizeProj: Unexpected expression: " ++ sdoc ex - where - go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x - + go t x = + if isPackedContext + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x {- @@ -2152,25 +2315,23 @@ cursorizeProd :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDe cursorizeProd freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = case ex of LetE (v, _locs, MkTy2 (ProdTy tys), rhs@(MkProdE ls)) bod -> do - es <- forM (zip tys ls) $ \(ty,e) -> do - case ty of - _ | isPackedTy ty -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e - _ | hasPacked ty -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e - _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + es <- forM (zip tys ls) $ \(ty, e) -> do + case ty of + _ | isPackedTy ty -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + _ | hasPacked ty -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e let rhs' = MkProdE es - ty = gRecoverType ddfs (Env2 tenv M.empty) rhs - ty' = cursorizeTy (unTy2 ty) + ty = gRecoverType ddfs (Env2 tenv M.empty) rhs + ty' = cursorizeTy (unTy2 ty) tenv' = M.insert v ty tenv bod' <- go tenv' bod - return $ mkLets [(v,[], ty', rhs')] bod' - + return $ mkLets [(v, [], ty', rhs')] bod' _ -> error $ "cursorizeProj: Unexpected expression: " ++ sdoc ex - where - go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x - + go t x = + if isPackedContext + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x {- @@ -2186,115 +2347,125 @@ cursorizeSpawn :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DD cursorizeSpawn freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = do case ex of LetE (v, locs, MkTy2 ty, (SpawnE fn applocs args)) bod - | isPackedTy ty -> do rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) let rhs'' = case rhs' of - AppE fn' applocs' args' -> SpawnE fn' applocs' args' - _ -> error "cursorizeSpawn" + AppE fn' applocs' args' -> SpawnE fn' applocs' args' + _ -> error "cursorizeSpawn" fresh <- gensym "tup_packed" let ty' = case locs of - [] -> cursorizeTy ty - xs -> ProdTy ([CursorTy | _ <- xs] ++ [cursorizeTy ty]) + [] -> cursorizeTy ty + xs -> ProdTy ([CursorTy | _ <- xs] ++ [cursorizeTy ty]) tenv' = M.union (M.fromList [(fresh, MkTy2 ty')]) tenv - -- L.foldr (\(a,b) acc -> M.insert a b acc) tenv $ - -- [(v, ty),(fresh, ty'),(toEndV v, projTy 1 ty')] ++ [(loc,CursorTy) | loc <- locs] + -- L.foldr (\(a,b) acc -> M.insert a b acc) tenv $ + -- [(v, ty),(fresh, ty'),(toEndV v, projTy 1 ty')] ++ [(loc,CursorTy) | loc <- locs] -- TyEnv Ty2 and L3 expresssions are tagged with different types - ty'' = curDict $ stripTyLocs ty' + ty'' = curDict $ stripTyLocs ty' fresh_rhs = VarE fresh (bnds, pending_bnds) = - case locs of - [] -> ([ (fresh , [], ty'' , rhs'' ) ], - [ (v , [], projTy 0 ty'', MkTy2 ty , mkProj 0 fresh_rhs) - , (toEndV v, [], projTy 1 ty'', MkTy2 (projTy 1 ty'), mkProj 1 fresh_rhs)]) - _ -> let nLocs = length locs - locBnds = [((unwrapLocVar . toLocVar) loc ,[], CursorTy, MkTy2 CursorTy, mkProj n fresh_rhs) - | (loc,n) <- zip locs [0..]] - bnds' = [(fresh ,[], ty'', rhs'') ] - pending_bnds' = [(v ,[], projTy 0 $ projTy nLocs ty'', MkTy2 ty, mkProj 0 $ mkProj nLocs fresh_rhs) - ,(toEndV v,[], projTy 1 $ projTy nLocs ty'', MkTy2 (projTy 0 $ projTy nLocs ty'), mkProj 1 $ mkProj nLocs fresh_rhs)] - ++ locBnds - in (bnds', pending_bnds') + case locs of + [] -> + ( [(fresh, [], ty'', rhs'')], + [ (v, [], projTy 0 ty'', MkTy2 ty, mkProj 0 fresh_rhs), + (toEndV v, [], projTy 1 ty'', MkTy2 (projTy 1 ty'), mkProj 1 fresh_rhs) + ] + ) + _ -> + let nLocs = length locs + locBnds = + [ ((unwrapLocVar . toLocVar) loc, [], CursorTy, MkTy2 CursorTy, mkProj n fresh_rhs) + | (loc, n) <- zip locs [0 ..] + ] + bnds' = [(fresh, [], ty'', rhs'')] + pending_bnds' = + [ (v, [], projTy 0 $ projTy nLocs ty'', MkTy2 ty, mkProj 0 $ mkProj nLocs fresh_rhs), + (toEndV v, [], projTy 1 $ projTy nLocs ty'', MkTy2 (projTy 0 $ projTy nLocs ty'), mkProj 1 $ mkProj nLocs fresh_rhs) + ] + ++ locBnds + in (bnds', pending_bnds') case M.lookup (fromVarToFreeVarsTy (toEndV v)) denv of Just xs -> error $ "cursorizeSpawn todo: " ++ sdoc xs Nothing -> return () let senv' = M.insert v pending_bnds senv - bod' <- go tenv' senv' bod + bod' <- go tenv' senv' bod let bod'' = updateAvailVars [v] [fresh] bod' return $ mkLets bnds bod'' - | hasPacked ty -> do rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) let rhs'' = case rhs' of - AppE fn' applocs' args' -> SpawnE fn' applocs' args' - _ -> error $ "cursorizeSpawn: this should've been an AppE. Got" ++ sdoc rhs' + AppE fn' applocs' args' -> SpawnE fn' applocs' args' + _ -> error $ "cursorizeSpawn: this should've been an AppE. Got" ++ sdoc rhs' fresh <- gensym "tup_haspacked" let ty' = case locs of - [] -> cursorizeTy ty - xs -> ProdTy ([CursorTy | _ <- xs] ++ [cursorizeTy ty]) - ty'' = stripTyLocs ty' + [] -> cursorizeTy ty + xs -> ProdTy ([CursorTy | _ <- xs] ++ [cursorizeTy ty]) + ty'' = stripTyLocs ty' tenv' = M.insert v (MkTy2 ty) tenv case locs of - [] -> LetE (v,[], ty'', rhs'') <$> - go tenv' senv bod - _ -> do + [] -> + LetE (v, [], ty'', rhs'') + <$> go tenv' senv bod + _ -> do let (bnds, pending_bnds) = - ([(fresh, [], ty'', rhs'')], - [((unwrapLocVar . toLocVar) loc,[],CursorTy, MkTy2 CursorTy, ProjE n (VarE fresh)) | (loc,n) <- (zip locs [0..])] ++ - [(v ,[], projTy (length locs) ty'', MkTy2 ty, ProjE (length locs) (VarE fresh))]) + ( [(fresh, [], ty'', rhs'')], + [((unwrapLocVar . toLocVar) loc, [], CursorTy, MkTy2 CursorTy, ProjE n (VarE fresh)) | (loc, n) <- (zip locs [0 ..])] + ++ [(v, [], projTy (length locs) ty'', MkTy2 ty, ProjE (length locs) (VarE fresh))] + ) senv' = M.insert v pending_bnds senv mkLets bnds <$> go tenv' senv' bod - | otherwise -> do rhs' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) let rhs'' = case rhs' of - AppE fn' applocs' args' -> SpawnE fn' applocs' args' - _ -> error "cursorizeSpawn" + AppE fn' applocs' args' -> SpawnE fn' applocs' args' + _ -> error "cursorizeSpawn" case locs of - [] -> LetE (v,[],curDict $ stripTyLocs ty, rhs'') <$> - go (M.insert v (MkTy2 ty) tenv) senv bod + [] -> + LetE (v, [], curDict $ stripTyLocs ty, rhs'') + <$> go (M.insert v (MkTy2 ty) tenv) senv bod [loc] -> do fresh <- gensym "par_tup_scalar" let ty' :: OldTy2 - ty' = ProdTy ([CursorTy | _ <- locs] ++ [cursorizeTy ty]) + ty' = ProdTy ([CursorTy | _ <- locs] ++ [cursorizeTy ty]) tenv' = M.union (M.fromList [(fresh, MkTy2 ty')]) tenv ty'' :: Ty3 ty'' = stripTyLocs ty' rhs''' = Di (VarE fresh) - locs_name = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeSpawn: unexpected location variable" - pending_bnds = [ (locs_name ,[] , projTy 0 ty'', MkTy2 (projTy 0 ty') , projVal rhs''') - -- [2022.09.21]: Shouldn't this be projTy 1 ty'? - , (v ,[] , projTy 1 ty'', MkTy2 (projTy 1 ty') , projEnds rhs''')] + locs_name = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeSpawn: unexpected location variable" + pending_bnds = + [ (locs_name, [], projTy 0 ty'', MkTy2 (projTy 0 ty'), projVal rhs'''), + -- [2022.09.21]: Shouldn't this be projTy 1 ty'? + (v, [], projTy 1 ty'', MkTy2 (projTy 1 ty'), projEnds rhs''') + ] senv' = M.insert v pending_bnds senv bod' <- go tenv' senv' bod - return $ mkLets [(fresh,[] , ty'', rhs'')] bod' - + return $ mkLets [(fresh, [], ty'', rhs'')] bod' _ -> error "TODO: cursorizeSpawn" - _ -> error "cursorizeSpawn: Unbound SpawnE" - - where go t s x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t s x - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t s x + where + go t s x = + if isPackedContext + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t s x + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t s x cursorizeSync :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeSync freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = do case ex of LetE (v, _locs, MkTy2 ty, SyncE) bod -> do let pending_bnds = concat (M.elems senv) - tenv' = foldr (\(v1,_,_,ty2,_) env -> M.insert v1 ty2 env) tenv pending_bnds + tenv' = foldr (\(v1, _, _, ty2, _) env -> M.insert v1 ty2 env) tenv pending_bnds -- Discharge bindings that depending on the join point. - bnds = map (\(a,b,c,_,e) -> (a,b,c,e)) pending_bnds - bnds' = (v,[],stripTyLocs ty, SyncE) : bnds + bnds = map (\(a, b, c, _, e) -> (a, b, c, e)) pending_bnds + bnds' = (v, [], stripTyLocs ty, SyncE) : bnds bod' <- go tenv' bod return $ mkLets bnds' bod' _ -> error "cursorizeSpawn: Unbound SyncE" - where go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x - + where + go t x = + if isPackedContext + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x {- @@ -2318,209 +2489,283 @@ we can take a shortcut here and directly bind `v` to the tagged location. Other bindings are straightforward projections of the processed RHS. -} -cursorizeLet :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv - -> (Var, [LocArg], Ty2, Exp2) -> Exp2 -> PassM Exp3 -cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v,locs,(MkTy2 ty),rhs) bod - | isPackedTy ty = do - rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs - fresh <- dbgTrace (minChatLvl) "Print locs in cursorize Let " dbgTrace (minChatLvl) (sdoc (locs)) dbgTrace (minChatLvl) "End cursorize Let\n" gensym "tup_packed" - let cursor_ty_locs = map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - cursorType = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) - in cursorType - ) locs - let cursor_ty_locs' = map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - cursorType :: Ty3 = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) - in cursorType - ) locs - let ty' = case locs of - [] -> cursorizeTy ty - xs -> ProdTy ( cursor_ty_locs ++ [cursorizeTy ty]) - - tenv' = L.foldr (\(a,b) acc -> M.insert a b acc) tenv $ - [(v, MkTy2 ty),(fresh, MkTy2 ty'),(toEndV v, MkTy2 (projTy 1 ty'))] ++ - map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - var = case (M.lookup free_var freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLet: unexpected location variable" - cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) - in (var, MkTy2 cursorType) - ) locs - - -- TyEnv Ty2 and L3 expresssions are tagged with different types - ty'' = curDict $ stripTyLocs ty' - rhs'' = VarE fresh - - bnds = case locs of - [] -> [ (fresh , [], ty'' , rhs' ) - , (v , [], projTy 0 ty'' , mkProj 0 rhs'') - , (toEndV v, [], projTy 1 ty'' , mkProj 1 rhs'')] - - _ -> let nLocs = length locs - locBnds = map (\(loc, n) -> let loc_var = fromLocArgToFreeVarsTy loc - cursor_ty = cursor_ty_locs' !! n - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLet: unexpected location variable" - in (loc_to_variable, [], cursor_ty, mkProj n rhs'') - ) (zip locs [0..]) - bnds' = [(fresh ,[], ty'' , rhs') - ,(v ,[], projTy 0 $ projTy nLocs ty'' , mkProj 0 $ mkProj nLocs rhs'') - ,(toEndV v,[], projTy 1 $ projTy nLocs ty'' , mkProj 1 $ mkProj nLocs rhs'')] - in bnds' ++ locBnds - case M.lookup (fromVarToFreeVarsTy (toEndV v)) denv of - Just xs -> error $ "todo: " ++ sdoc xs - Nothing -> return () - bod' <- go tenv' bod - return $ mkLets bnds bod' - - | hasPacked ty = do - let cursor_ty_locs = map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - cursorType = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) - in cursorType - ) locs - let cursor_ty_locs' = map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - cursorType :: Ty3 = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) - in cursorType - ) locs - rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs - fresh <- gensym "tup_haspacked" - let ty' = case locs of - [] -> cursorizeTy ty - xs -> ProdTy (cursor_ty_locs ++ [cursorizeTy ty]) - ty'' = stripTyLocs ty' - tenv' = M.union (M.insert v (MkTy2 ty) tenv) (M.fromList $ map (\loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLet: unexpected location variable" - cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) - in (loc_to_variable, MkTy2 cursorType) - ) locs) - case locs of - [] -> LetE (v,[], ty'', rhs') <$> - go tenv' bod - _ -> do - let tenv'' = M.union tenv' $ - M.fromList $ map (\loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" - cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) - in (loc_to_variable, MkTy2 cursorType) - ) locs - - bnds = [(fresh, [], ty'', rhs')] ++ - map (\(loc, n) -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" - cursorType = cursor_ty_locs' !! n - in (loc_to_variable, [], cursorType, ProjE n (VarE fresh)) - - ) (zip locs [0..]) - ++ [(v,[], projTy (length locs) ty'', ProjE (length locs) (VarE fresh))] - mkLets bnds <$> go tenv'' bod +cursorizeLet :: + M.Map FreeVarsTy Var -> + M.Map Var (Maybe LocVar) -> + Bool -> + DDefs Ty2 -> + FunDefs2 -> + DepEnv -> + TyEnv Var Ty2 -> + SyncEnv -> + (Var, [LocArg], Ty2, Exp2) -> + Exp2 -> + PassM Exp3 +cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v, locs, (MkTy2 ty), rhs) bod + | isPackedTy ty = do + rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + fresh <- dbgTrace (minChatLvl) "Print locs in cursorize Let " dbgTrace (minChatLvl) (sdoc (locs)) dbgTrace (minChatLvl) "End cursorize Let\n" gensym "tup_packed" + let cursor_ty_locs = + map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + cursorType = case free_var of + R r -> case r of + SingleR _ -> CursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." + FL l -> case l of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + length flds) + in cursorType + ) + locs + let cursor_ty_locs' = + map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + cursorType :: Ty3 = case free_var of + R r -> case r of + SingleR _ -> CursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." + FL l -> case l of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + length flds) + in cursorType + ) + locs + let ty' = case locs of + [] -> cursorizeTy ty + xs -> ProdTy (cursor_ty_locs ++ [cursorizeTy ty]) + + tenv' = + L.foldr (\(a, b) acc -> M.insert a b acc) tenv $ + [(v, MkTy2 ty), (fresh, MkTy2 ty'), (toEndV v, MkTy2 (projTy 1 ty'))] + ++ map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + var = case (M.lookup free_var freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLet: unexpected location variable" + cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) + in (var, MkTy2 cursorType) + ) + locs + + -- TyEnv Ty2 and L3 expresssions are tagged with different types + ty'' = curDict $ stripTyLocs ty' + rhs'' = VarE fresh + + bnds = case locs of + [] -> + [ (fresh, [], ty'', rhs'), + (v, [], projTy 0 ty'', mkProj 0 rhs''), + (toEndV v, [], projTy 1 ty'', mkProj 1 rhs'') + ] + _ -> + let nLocs = length locs + locBnds = + map + ( \(loc, n) -> + let loc_var = fromLocArgToFreeVarsTy loc + cursor_ty = cursor_ty_locs' !! n + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLet: unexpected location variable" + in (loc_to_variable, [], cursor_ty, mkProj n rhs'') + ) + (zip locs [0 ..]) + bnds' = + [ (fresh, [], ty'', rhs'), + (v, [], projTy 0 $ projTy nLocs ty'', mkProj 0 $ mkProj nLocs rhs''), + (toEndV v, [], projTy 1 $ projTy nLocs ty'', mkProj 1 $ mkProj nLocs rhs'') + ] + in bnds' ++ locBnds + case M.lookup (fromVarToFreeVarsTy (toEndV v)) denv of + Just xs -> error $ "todo: " ++ sdoc xs + Nothing -> return () + bod' <- go tenv' bod + return $ mkLets bnds bod' + | hasPacked ty = do + let cursor_ty_locs = + map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + cursorType = case free_var of + R r -> case r of + SingleR _ -> CursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." + FL l -> case l of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + length flds) + in cursorType + ) + locs + let cursor_ty_locs' = + map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + cursorType :: Ty3 = case free_var of + R r -> case r of + SingleR _ -> CursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." + FL l -> case l of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + length flds) + in cursorType + ) + locs + rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + fresh <- gensym "tup_haspacked" + let ty' = case locs of + [] -> cursorizeTy ty + xs -> ProdTy (cursor_ty_locs ++ [cursorizeTy ty]) + ty'' = stripTyLocs ty' + tenv' = + M.union + (M.insert v (MkTy2 ty) tenv) + ( M.fromList $ + map + ( \loc -> + let loc_var = fromLocArgToFreeVarsTy loc + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLet: unexpected location variable" + cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) + in (loc_to_variable, MkTy2 cursorType) + ) + locs + ) + case locs of + [] -> + LetE (v, [], ty'', rhs') + <$> go tenv' bod + _ -> do + let tenv'' = + M.union tenv' $ + M.fromList $ + map + ( \loc -> + let loc_var = fromLocArgToFreeVarsTy loc + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeLet: unexpected location variable" + cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) + in (loc_to_variable, MkTy2 cursorType) + ) + locs + + bnds = + [(fresh, [], ty'', rhs')] + ++ map + ( \(loc, n) -> + let loc_var = fromLocArgToFreeVarsTy loc + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeLet: unexpected location variable" + cursorType = cursor_ty_locs' !! n + in (loc_to_variable, [], cursorType, ProjE n (VarE fresh)) + ) + (zip locs [0 ..]) + ++ [(v, [], projTy (length locs) ty'', ProjE (length locs) (VarE fresh))] + mkLets bnds <$> go tenv'' bod {- -This was a scalar binding before, but now has been transformed to -also return an end_read cursor. So the type of the binding now -becomes: - - ProdTy [CursorTy, old_ty] - -Also, the binding itself now changes to: - - end_read -> ProjE 0 RHS' - v -> ProjE 1 RHS' - -`rightmost` is an example of a program that does this. - --} - - | otherwise = do - let cursor_ty_locs = map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - cursorType = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) - in cursorType - ) locs - let cursor_ty_locs' = map (\loc -> let free_var = fromLocArgToFreeVarsTy loc - cursorType :: Ty3 = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) - in cursorType - ) locs - rhs' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs - case locs of - [] -> LetE (v,[],curDict $ stripTyLocs ty, rhs') <$> - go (M.insert v (MkTy2 ty) tenv) bod - _ -> do - fresh <- gensym "tup_scalar" - let rhs'' = VarE fresh - ty' = ProdTy (cursor_ty_locs ++ [cursorizeTy ty]) - -- We cannot resuse ty' here because TyEnv Ty2 and expresssions are - -- tagged with different - ty'' = stripTyLocs ty' - tenv' = M.union (M.insert v (MkTy2 ty) tenv) $ - M.fromList $ map (\loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLet: unexpected location variable" - cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) - in (loc_to_variable, MkTy2 cursorType)) locs - bnds = [ (fresh, [] , ty'' , rhs') ] ++ - map (\(loc, n) -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLet: unexpected location variable" - cursorType = cursor_ty_locs' !! n - in (loc_to_variable, [], cursorType, ProjE n rhs'') - ) (zip locs [0..]) ++ - [ (v,[], projTy (length locs) ty'', ProjE (length locs) rhs'') ] - bod' <- go tenv' bod - return $ mkLets bnds bod' - - where go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + This was a scalar binding before, but now has been transformed to + also return an end_read cursor. So the type of the binding now + becomes: + + ProdTy [CursorTy, old_ty] + + Also, the binding itself now changes to: + + end_read -> ProjE 0 RHS' + v -> ProjE 1 RHS' + + `rightmost` is an example of a program that does this. + + -} + + | otherwise = do + let cursor_ty_locs = + map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + cursorType = case free_var of + R r -> case r of + SingleR _ -> CursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." + FL l -> case l of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + length flds) + in cursorType + ) + locs + let cursor_ty_locs' = + map + ( \loc -> + let free_var = fromLocArgToFreeVarsTy loc + cursorType :: Ty3 = case free_var of + R r -> case r of + SingleR _ -> CursorTy + SoARv _ flds -> CursorArrayTy (1 + length flds) + V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." + FL l -> case l of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + length flds) + in cursorType + ) + locs + rhs' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + case locs of + [] -> + LetE (v, [], curDict $ stripTyLocs ty, rhs') + <$> go (M.insert v (MkTy2 ty) tenv) bod + _ -> do + fresh <- gensym "tup_scalar" + let rhs'' = VarE fresh + ty' = ProdTy (cursor_ty_locs ++ [cursorizeTy ty]) + -- We cannot resuse ty' here because TyEnv Ty2 and expresssions are + -- tagged with different + ty'' = stripTyLocs ty' + tenv' = + M.union (M.insert v (MkTy2 ty) tenv) $ + M.fromList $ + map + ( \loc -> + let loc_var = fromLocArgToFreeVarsTy loc + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLet: unexpected location variable" + cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) + in (loc_to_variable, MkTy2 cursorType) + ) + locs + bnds = + [(fresh, [], ty'', rhs')] + ++ map + ( \(loc, n) -> + let loc_var = fromLocArgToFreeVarsTy loc + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLet: unexpected location variable" + cursorType = cursor_ty_locs' !! n + in (loc_to_variable, [], cursorType, ProjE n rhs'') + ) + (zip locs [0 ..]) + ++ [(v, [], projTy (length locs) ty'', ProjE (length locs) rhs'')] + bod' <- go tenv' bod + return $ mkLets bnds bod' + where + go t x = + if isPackedContext + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x {- @@ -2541,105 +2786,160 @@ Consider an example of unpacking of a Node^ pattern: ..TODO.. -} -unpackDataCon :: Var -> M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Bool -> Var - -> (DataCon, [(Var, LocArg)], Exp2) -> PassM (DataCon, [t], Exp3) -unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon,vlocs1,rhs) = do +unpackDataCon :: + Var -> + M.Map FreeVarsTy Var -> + M.Map Var (Maybe LocVar) -> + DDefs Ty2 -> + FunDefs2 -> + DepEnv -> + TyEnv Var Ty2 -> + SyncEnv -> + Bool -> + Var -> + (DataCon, [(Var, LocArg)], Exp2) -> + PassM (DataCon, [t], Exp3) +unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon, vlocs1, rhs) = do field_cur <- gensym "field_cur" - let ty_of_scrut = case (M.lookup scrtCur tenv1) of - Just (MkTy2 ty) -> ty - Nothing -> error "unpackDataCon: unexpected location variable" - case ty_of_scrut of - CursorTy -> dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 1.\n" (dcon, [],) - -- Advance the cursor by 1 byte so that it points to the first field - <$> mkLets [(field_cur,[],CursorTy, Ext $ AddCursor scrtCur (LitE 1))] - <$> (if isAbsRANDataCon dcon - then unpackWithAbsRAN field_cur - else if isRelRANDataCon dcon - then unpackWithRelRAN field_cur - else unpackRegularDataCon (AoSWin field_cur) freeVarToVarEnv) + let ty_of_scrut = case (M.lookup scrtCur tenv1) of + Just (MkTy2 ty) -> ty + Nothing -> error "unpackDataCon: unexpected location variable" + case ty_of_scrut of + CursorTy -> + dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 1.\n" (dcon,[],) + -- Advance the cursor by 1 byte so that it points to the first field + <$> mkLets [(field_cur, [], CursorTy, Ext $ AddCursor scrtCur (LitE 1))] + <$> ( if isAbsRANDataCon dcon + then unpackWithAbsRAN (AoSWin field_cur) freeVarToVarEnv + else + if isRelRANDataCon dcon + then unpackWithRelRAN field_cur + else unpackRegularDataCon (AoSWin field_cur) freeVarToVarEnv + ) CursorArrayTy size -> do - -- dcon_var <- gensym "dcon" - let first_var = dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 2.\n" field_cur - let scrut_loc = case (M.lookup scrtCur lenv) of - Just loc -> case loc of - Just l -> case l of - Single _ -> error "unpackDataCon: Did not expect a single location for a cursor array!" - SoA _ _ -> l - Nothing -> error "unpackDataCon: Did not find a location for scrutinee!" - Nothing -> error "unpackDataCon: Did not find a location for scrutinee!" - - -- let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray scrtCur 0)] - (field_lets, field_v_lst, freeVarToVarEnv') <- dbgTrace (minChatLvl) "Print scrut_loc " dbgTrace (minChatLvl) (sdoc ((dcon, scrut_loc))) dbgTrace (minChatLvl) "end scrut_loc.\n" - foldlM (\(acc1, acc2, acc3) (key@(dcon', idx), loc) -> do - let idx_elem = fromJust $ L.elemIndex (key, loc) (getAllFieldLocsSoA scrut_loc) - field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) - let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 - let field_cursor_ty = case loc of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + L.length (flds)) - let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1+idx_elem))] - let curr_window = [((dcon', idx), field_var)] - return (acc1 ++ field_let , acc2 ++ curr_window, acc3') - ) ([], [], freeVarToVarEnv) (getAllFieldLocsSoA scrut_loc) - bod <- (if isAbsRANDataCon dcon - then unpackWithAbsRAN field_cur - else if isRelRANDataCon dcon - then unpackWithRelRAN field_cur - else unpackRegularDataCon (SoAWin dcon_var field_v_lst) freeVarToVarEnv') - let lets = mkLets (field_lets) bod - dbgTrace (minChatLvl) "Print scrut loc: " dbgTrace (minChatLvl) (sdoc scrut_loc) dbgTrace (minChatLvl) "End loc\n" return (dcon, [], lets) - PackedTy tycon locationVar -> case locationVar of - Single _ -> (dcon, [],) - -- Advance the cursor by 1 byte so that it points to the first field - <$> mkLets [(field_cur,[],CursorTy, Ext $ AddCursor scrtCur (LitE 1))] - <$> (if isAbsRANDataCon dcon - then unpackWithAbsRAN field_cur - else if isRelRANDataCon dcon - then unpackWithRelRAN field_cur - else unpackRegularDataCon (AoSWin field_cur) freeVarToVarEnv) - SoA _ _ -> do - -- dcon_var <- gensym "dcon" - let first_var = dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 2.\n" field_cur - let scrut_loc = locationVar - -- let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray scrtCur 0)] - (field_lets, field_v_lst, freeVarToVarEnv') <- dbgTrace (minChatLvl) "Print scrut_loc " dbgTrace (minChatLvl) (sdoc ((dcon, scrut_loc))) dbgTrace (minChatLvl) "end scrut_loc.\n" - foldlM (\(acc1, acc2, acc3) (key@(dcon', idx), loc) -> do - let idx_elem = fromJust $ L.elemIndex (key, loc) (getAllFieldLocsSoA scrut_loc) - field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) - let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 - let field_cursor_ty = case loc of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + L.length (flds)) - let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1+idx_elem))] - let curr_window = [((dcon', idx), field_var)] - return (acc1 ++ field_let , acc2 ++ curr_window, acc3') - ) ([], [], freeVarToVarEnv) (getAllFieldLocsSoA scrut_loc) - bod <- (if isAbsRANDataCon dcon - then unpackWithAbsRAN field_cur - else if isRelRANDataCon dcon - then unpackWithRelRAN field_cur - else unpackRegularDataCon (SoAWin dcon_var field_v_lst) freeVarToVarEnv') - let lets = mkLets (field_lets) bod - return (dcon, [], lets) - _ -> dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 3.\n" (dcon, [],) - -- Advance the cursor by 1 byte so that it points to the first field - <$> mkLets [(field_cur,[],CursorTy, Ext $ AddCursor scrtCur (LitE 1))] - <$> (if isAbsRANDataCon dcon - then unpackWithAbsRAN field_cur - else if isRelRANDataCon dcon - then unpackWithRelRAN field_cur - else unpackRegularDataCon (AoSWin field_cur) freeVarToVarEnv) - + -- dcon_var <- gensym "dcon" + let first_var = dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 2.\n" field_cur + let scrut_loc = case (M.lookup scrtCur lenv) of + Just loc -> case loc of + Just l -> case l of + Single _ -> error "unpackDataCon: Did not expect a single location for a cursor array!" + SoA _ _ -> l + Nothing -> error "unpackDataCon: Did not find a location for scrutinee!" + Nothing -> error "unpackDataCon: Did not find a location for scrutinee!" + + -- let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray scrtCur 0)] + (field_lets, field_v_lst, freeVarToVarEnv') <- + dbgTrace + (minChatLvl) + "Print scrut_loc " + dbgTrace + (minChatLvl) + (sdoc ((dcon, scrut_loc))) + dbgTrace + (minChatLvl) + "end scrut_loc.\n" + foldlM + ( \(acc1, acc2, acc3) (key@(dcon', idx), loc) -> do + let idx_elem = fromJust $ L.elemIndex (key, loc) (getAllFieldLocsSoA scrut_loc) + field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) + let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 + let field_cursor_ty = case loc of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + L.length (flds)) + let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1 + idx_elem))] + let curr_window = [((dcon', idx), field_var)] + return (acc1 ++ field_let, acc2 ++ curr_window, acc3') + ) + ([], [], freeVarToVarEnv) + (getAllFieldLocsSoA scrut_loc) + dcon_end <- gensym "dcon_end" + let dcon_end_let = (dcon_end, [], CursorTy, Ext $ AddCursor dcon_var (LitE 1)) + bod <- + ( if isAbsRANDataCon dcon + then do + unpackWithAbsRAN (SoAWin dcon_end field_v_lst) freeVarToVarEnv' + else + if isRelRANDataCon dcon + then unpackWithRelRAN field_cur + else unpackRegularDataCon (SoAWin dcon_var field_v_lst) freeVarToVarEnv' + ) + let lets = mkLets ([dcon_end_let] ++ field_lets) bod + dbgTrace (minChatLvl) "Print scrut loc: " dbgTrace (minChatLvl) (sdoc scrut_loc) dbgTrace (minChatLvl) "End loc\n" return (dcon, [], lets) + PackedTy tycon locationVar -> case locationVar of + Single _ -> + (dcon,[],) + -- Advance the cursor by 1 byte so that it points to the first field + <$> mkLets [(field_cur, [], CursorTy, Ext $ AddCursor scrtCur (LitE 1))] + <$> ( if isAbsRANDataCon dcon + then unpackWithAbsRAN (AoSWin field_cur) freeVarToVarEnv + else + if isRelRANDataCon dcon + then unpackWithRelRAN field_cur + else unpackRegularDataCon (AoSWin field_cur) freeVarToVarEnv + ) + SoA _ _ -> do + -- dcon_var <- gensym "dcon" + let first_var = dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 2.\n" field_cur + let scrut_loc = locationVar + -- let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray scrtCur 0)] + (field_lets, field_v_lst, freeVarToVarEnv') <- + dbgTrace + (minChatLvl) + "Print scrut_loc " + dbgTrace + (minChatLvl) + (sdoc ((dcon, scrut_loc))) + dbgTrace + (minChatLvl) + "end scrut_loc.\n" + foldlM + ( \(acc1, acc2, acc3) (key@(dcon', idx), loc) -> do + let idx_elem = fromJust $ L.elemIndex (key, loc) (getAllFieldLocsSoA scrut_loc) + field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) + let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 + let field_cursor_ty = case loc of + Single _ -> CursorTy + SoA _ flds -> CursorArrayTy (1 + L.length (flds)) + let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1 + idx_elem))] + let curr_window = [((dcon', idx), field_var)] + return (acc1 ++ field_let, acc2 ++ curr_window, acc3') + ) + ([], [], freeVarToVarEnv) + (getAllFieldLocsSoA scrut_loc) + dcon_end <- gensym "dcon_end" + let dcon_end_let = (dcon_end, [], CursorTy, Ext $ AddCursor dcon_var (LitE 1)) + bod <- + ( if isAbsRANDataCon dcon + then unpackWithAbsRAN (SoAWin dcon_end field_v_lst) freeVarToVarEnv' + else + if isRelRANDataCon dcon + then unpackWithRelRAN field_cur + else unpackRegularDataCon (SoAWin dcon_var field_v_lst) freeVarToVarEnv' + ) + let lets = mkLets ([dcon_end_let] ++ field_lets) bod + return (dcon, [], lets) + _ -> + dbgTrace (minChatLvl) "Print scrutCur " dbgTrace (minChatLvl) (sdoc (scrtCur, ty_of_scrut, field_cur)) dbgTrace (minChatLvl) "End print scrutCur 3.\n" (dcon,[],) + -- Advance the cursor by 1 byte so that it points to the first field + <$> mkLets [(field_cur, [], CursorTy, Ext $ AddCursor scrtCur (LitE 1))] + <$> ( if isAbsRANDataCon dcon + then unpackWithAbsRAN (AoSWin field_cur) freeVarToVarEnv + else + if isRelRANDataCon dcon + then unpackWithRelRAN field_cur + else unpackRegularDataCon (AoSWin field_cur) freeVarToVarEnv + ) where tys1 = lookupDataCon ddfs dcon - processRhs denv env = if isPacked - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs + processRhs denv env = + if isPacked + then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs + else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs lookupVariable :: FreeVarsTy -> M.Map FreeVarsTy Var -> PassM Var - lookupVariable loc fenv = case (M.lookup loc fenv) of - Just v -> return v - Nothing -> error "lookupVariable: unexpected location variable" + lookupVariable loc fenv = case (M.lookup loc fenv) of + Just v -> return v + Nothing -> error "lookupVariable: unexpected location variable" -- Since this constructor does not have random access nodes, we may not be able -- to unpack all the fields. Basically, anything after the first packed @@ -2654,628 +2954,887 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- to true initially, and we flip it as soon as we see a packed value. -- unpackRegularDataCon :: WindowIntoCursor -> M.Map FreeVarsTy Var -> PassM Exp3 - unpackRegularDataCon field_cur freeVarToVarEnv_unpack = do - let tenv1' = case field_cur of - AoSWin cf -> (M.insert cf (MkTy2 CursorTy) tenv1) - SoAWin dcf fieldfvs -> let tenv1'' = M.insert dcf (MkTy2 CursorTy) tenv1 - in foldr (\(x,y) acc -> M.insert y (MkTy2 CursorTy) acc) tenv1'' fieldfvs + unpackRegularDataCon field_cur freeVarToVarEnv_unpack = do + let tenv1' = case field_cur of + AoSWin cf -> (M.insert cf (MkTy2 CursorTy) tenv1) + SoAWin dcf fieldfvs -> + let tenv1'' = M.insert dcf (MkTy2 CursorTy) tenv1 + in foldr (\(x, y) acc -> M.insert y (MkTy2 CursorTy) acc) tenv1'' fieldfvs exp_unp <- go field_cur freeVarToVarEnv_unpack vlocs1 tys1 True denv1 tenv1' return exp_unp where go :: WindowIntoCursor -> M.Map FreeVarsTy Var -> [(Var, LocArg)] -> [Ty2] -> Bool -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 - go curw fenv vlocs tys canBind denv tenv = do + go curw fenv vlocs tys canBind denv tenv = do case curw of - AoSWin cur -> do + AoSWin cur -> do case (vlocs, tys) of - ([],[]) -> processRhs denv tenv - ((v,locarg):rst_vlocs, (MkTy2 ty):rst_tys) -> + ([], []) -> processRhs denv tenv + ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> let loc = fromLocArgToFreeVarsTy locarg - in case ty of - -- Int, Float, Sym, or Bool - _ | isScalarTy ty -> do - loc_var <- lookupVariable loc fenv - (tenv', binds) <- scalarBinds ty v loc_var tenv - if canBind - then do - -- If the location exists in the environment, it indicates that the - -- corresponding variable was also bound and we shouldn't create duplicate - -- bindings (checked in the LetLocE cases). - loc_var <- lookupVariable loc fenv - let binds' = ((loc_var),[],CursorTy, VarE cur):binds - tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv'' - return $ mkLets binds' bod - else do - -- Cannot read this int. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) binds denv - go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv' tenv' - - -- An indirection or redirection pointer. - -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. - CursorTy -> do - tmp <- gensym "readcursor_indir" - loc_var <- lookupVariable loc fenv - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - ((loc_var) , MkTy2 CursorTy), - (v , MkTy2 CursorTy), - (toEndV v, MkTy2 CursorTy), - (toTagV v, MkTy2 IntTy), - (toEndFromTaggedV v, MkTy2 CursorTy)]) + in case ty of + -- Int, Float, Sym, or Bool + _ | isScalarTy ty -> do + loc_var <- lookupVariable loc fenv + (tenv', binds) <- scalarBinds ty v loc_var tenv + if canBind + then do + -- If the location exists in the environment, it indicates that the + -- corresponding variable was also bound and we shouldn't create duplicate + -- bindings (checked in the LetLocE cases). + loc_var <- lookupVariable loc fenv + let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv'' + return $ mkLets binds' bod + else do + -- Cannot read this int. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) binds denv + go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv' tenv' + + -- An indirection or redirection pointer. + -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. + CursorTy -> do + tmp <- gensym "readcursor_indir" + loc_var <- lookupVariable loc fenv + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + ((loc_var), MkTy2 CursorTy), + (v, MkTy2 CursorTy), + (toEndV v, MkTy2 CursorTy), + (toTagV v, MkTy2 IntTy), + (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor cur) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + binds = + [ (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + ((loc_var), [], CursorTy, VarE cur), + (v, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV v, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))) + ] + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv' + return $ mkLets binds bod + VectorTy el_ty -> do + tmp <- gensym "read_vec_tuple" + loc_var <- lookupVariable loc fenv + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + (v, MkTy2 (VectorTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadVector (loc_var) (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] + if canBind + then do + -- If the location exists in the environment, it indicates that the + -- corresponding variable was also bound and we shouldn't create duplicate + -- bindings (checked in the LetLocE cases). + loc_var <- lookupVariable loc fenv + let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv'' + return $ mkLets binds' bod + else do + -- Cannot read this int. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) binds denv + go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv' tenv' + ListTy el_ty -> do + tmp <- gensym "read_list_tuple" + loc_var <- lookupVariable loc fenv + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [ListTy el_ty, CursorTy])), + (v, MkTy2 (ListTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) tenv - read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor cur) - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - binds = [(tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - ((loc_var) , [], CursorTy, VarE cur), - (v , [], CursorTy, ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), - (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), - (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v)))] - bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv' - return $ mkLets binds bod - - - VectorTy el_ty -> do - tmp <- gensym "read_vec_tuple" - loc_var <- lookupVariable loc fenv - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), - (v , MkTy2 (VectorTy el_ty)), - (toEndV v, MkTy2 CursorTy)]) - tenv - ty' = stripTyLocs ty - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadVector (loc_var) (stripTyLocs el_ty)), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - if canBind - then do - -- If the location exists in the environment, it indicates that the - -- corresponding variable was also bound and we shouldn't create duplicate - -- bindings (checked in the LetLocE cases). - loc_var <- lookupVariable loc fenv - let binds' = ((loc_var),[],CursorTy, VarE cur):binds - tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv'' - return $ mkLets binds' bod - else do - -- Cannot read this int. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) binds denv - go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv' tenv' - - - ListTy el_ty -> do - tmp <- gensym "read_list_tuple" - loc_var <- lookupVariable loc fenv - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [ListTy el_ty, CursorTy])), - (v , MkTy2 (ListTy el_ty)), - (toEndV v, MkTy2 CursorTy)]) - tenv - ty' = stripTyLocs ty - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadList (loc_var) (stripTyLocs el_ty)), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - if canBind - then do - -- If the location exists in the environment, it indicates that the - -- corresponding variable was also bound and we shouldn't create duplicate - -- bindings (checked in the LetLocE cases). - loc_var <- lookupVariable loc fenv - let binds' = ((loc_var),[],CursorTy, VarE cur):binds - tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv'' - return $ mkLets binds' bod - else do - -- Cannot read this int. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) binds denv - go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv' tenv' - - PackedTy _ ploc -> do - let tenv' = M.insert v (MkTy2 CursorTy) tenv - loc_var <- lookupVariable loc fenv - if canBind - then do - let tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - -- Flip canBind to indicate that the subsequent fields - -- should be added to the dependency environment. - bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys False denv tenv'' - return $ mkLets [((loc_var), [], CursorTy, VarE cur) - ,(v , [], CursorTy, VarE (loc_var))] - bod - else do - -- Cannot read this. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) [(v,[],CursorTy,VarE (loc_var))] denv - go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys False denv' tenv' - - _ -> error $ "unpackRegularDataCon: Unexpected field " ++ sdoc (v,loc) ++ ":" ++ sdoc ty - - _ -> error $ "unpackRegularDataCon: Unexpected numnber of varible, type pairs: " ++ show (vlocs,tys) + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadList (loc_var) (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] + if canBind + then do + -- If the location exists in the environment, it indicates that the + -- corresponding variable was also bound and we shouldn't create duplicate + -- bindings (checked in the LetLocE cases). + loc_var <- lookupVariable loc fenv + let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv tenv'' + return $ mkLets binds' bod + else do + -- Cannot read this int. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) binds denv + go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys canBind denv' tenv' + PackedTy _ ploc -> do + let tenv' = M.insert v (MkTy2 CursorTy) tenv + loc_var <- lookupVariable loc fenv + if canBind + then do + let tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + -- Flip canBind to indicate that the subsequent fields + -- should be added to the dependency environment. + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys False denv tenv'' + return $ + mkLets + [ ((loc_var), [], CursorTy, VarE cur), + (v, [], CursorTy, VarE (loc_var)) + ] + bod + else do + -- Cannot read this. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) [(v, [], CursorTy, VarE (loc_var))] denv + go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys False denv' tenv' + _ -> error $ "unpackRegularDataCon: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + _ -> error $ "unpackRegularDataCon: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) {- VS: TODO: handle other cases. Right now, it is only scalar and packed -} - SoAWin dcur _field_cur -> do + SoAWin dcur _field_cur -> do case (vlocs, tys) of - ([],[]) -> processRhs denv tenv - ((v,locarg):rst_vlocs, (MkTy2 ty):rst_tys) -> + ([], []) -> processRhs denv tenv + ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> let loc = fromLocArgToFreeVarsTy locarg - in case ty of - -- Int, Float, Sym, or Bool - _ | isScalarTy ty -> do - loc_var <- lookupVariable loc fenv - (tenv', binds) <- scalarBinds ty v loc_var tenv - let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - let field_cur' = map (\(k@(d, idx), var) -> if (d, idx) == (dcon, field_idx) then (k, (toEndV v)) else (k, var)) _field_cur - let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - if canBind - then do - -- If the location exists in the environment, it indicates that the - -- corresponding variable was also bound and we shouldn't create duplicate - -- bindings (checked in the LetLocE cases). - loc_var <- lookupVariable loc fenv - let binds' = ((loc_var),[],CursorTy, VarE cur):binds - tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - - bod <- go (SoAWin dcur field_cur') fenv rst_vlocs rst_tys canBind denv tenv'' - return $ mkLets binds' bod - else do - -- Cannot read this int. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) binds denv - go (SoAWin dcur field_cur') fenv rst_vlocs rst_tys canBind denv' tenv' - - -- An indirection or redirection pointer. - -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. - CursorTy -> do - if isRedirectionTag dcon - then do - tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" - tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur - loc_var <- lookupVariable loc fenv - var_dcon_next <- gensym "dcon_next" - vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur - redirection_var_dcon <- gensym "dcon_redir" - redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur - --let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - --let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - --((loc_var) , MkTy2 CursorTy), - (redirection_var_dcon , MkTy2 CursorTy), - (toEndV redirection_var_dcon, MkTy2 CursorTy), - (toTagV redirection_var_dcon, MkTy2 IntTy), - (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy)]) - tenv - read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon + in case ty of + -- Int, Float, Sym, or Bool + _ | isScalarTy ty -> do + loc_var <- lookupVariable loc fenv + (tenv', binds) <- scalarBinds ty v loc_var tenv + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + let field_cur' = map (\(k@(d, idx), var) -> if (d, idx) == (dcon, field_idx) then (k, (toEndV v)) else (k, var)) _field_cur + let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + if canBind + then do + -- If the location exists in the environment, it indicates that the + -- corresponding variable was also bound and we shouldn't create duplicate + -- bindings (checked in the LetLocE cases). + loc_var <- lookupVariable loc fenv + let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + + bod <- go (SoAWin dcur field_cur') fenv rst_vlocs rst_tys canBind denv tenv'' + return $ mkLets binds' bod + else do + -- Cannot read this int. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) binds denv + go (SoAWin dcur field_cur') fenv rst_vlocs rst_tys canBind denv' tenv' + + -- An indirection or redirection pointer. + -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. + CursorTy -> do + if isRedirectionTag dcon + then do + tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" + tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur + loc_var <- lookupVariable loc fenv + var_dcon_next <- gensym "dcon_next" + vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur + redirection_var_dcon <- gensym "dcon_redir" + redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + -- ((loc_var) , MkTy2 CursorTy), + (redirection_var_dcon, MkTy2 CursorTy), + (toEndV redirection_var_dcon, MkTy2 CursorTy), + (toTagV redirection_var_dcon, MkTy2 IntTy), + (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + -- v is the variable i want to send to the call. + -- In this case v is the soa variable where all redirections are unpacked. + binds = + [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + ((loc_var), [], CursorTy, VarE dcur), + (redirection_var_dcon, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV redirection_var_dcon, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon))) + ] + + -- generate binds for all fields. + binds_flields = + L.foldl + ( \(index, res) ((dcon', idx), var) -> + let read_cursor_f = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor (vars_next_fields !! index)) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + tmpf = tmp_flds !! index + ty_of_field = (lookupDataCon ddfs dcon') !! idx + in case ty_of_field of + (MkTy2 PackedTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + (MkTy2 CursorArrayTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + _ -> + let new_binds = + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] + in (index + 1, res ++ new_binds) + ) + (0, []) + _field_cur + soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] + tenv'' = + M.union + ( M.fromList + [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) + ] + ) + tenv + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod + else + if isIndirectionTag dcon + then do + tmp <- gensym "readcursor_indir" + loc_var <- lookupVariable loc fenv + let locs_ty = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + + let locs_ty3 :: Ty3 = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + var_dcon_next <- gensym "dcon_next" + + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + ((loc_var), MkTy2 locs_ty), + (v, MkTy2 locs_ty) + -- (toEndV v, MkTy2 CursorTy), + -- (toTagV v, MkTy2 IntTy), + -- (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor var_dcon_next) else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - -- v is the variable i want to send to the call. - -- In this case v is the soa variable where all redirections are unpacked. - binds = [(var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), - (tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - ((loc_var) , [], CursorTy, VarE dcur), - (redirection_var_dcon , [], CursorTy, ProjE 0 (VarE tmp)), - (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), - (toTagV redirection_var_dcon, [], IntTy , ProjE 2 (VarE tmp)), - (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))] - - --generate binds for all fields. - binds_flields = L.foldl (\(index, res) ((dcon', idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor (vars_next_fields !! index)) - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - tmpf = tmp_flds !! index - ty_of_field = (lookupDataCon ddfs dcon') !! idx - in case ty_of_field of - (MkTy2 PackedTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] - in (index + 1, res ++ new_binds) - (MkTy2 CursorArrayTy{}) -> let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] - in (index + 1, res ++ new_binds) - _ -> let new_binds = [(vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - --((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index) , [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy , ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))] - in (index + 1, res ++ new_binds) - - ) (0, []) _field_cur - soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] - tenv'' = M.union (M.fromList [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) - ] ) - tenv - bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) - return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod - else if isIndirectionTag dcon - then - do - tmp <- gensym "readcursor_indir" - loc_var <- lookupVariable loc fenv - let locs_ty = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) - _ -> error "Expected location!" - - let locs_ty3 :: Ty3 = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) - _ -> error "Expected location!" - - --let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - --let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - var_dcon_next <- gensym "dcon_next" - - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - ((loc_var) , MkTy2 locs_ty), - (v , MkTy2 locs_ty) - --(toEndV v, MkTy2 CursorTy), - --(toTagV v, MkTy2 IntTy), - --(toEndFromTaggedV v, MkTy2 CursorTy) - ]) - tenv - read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor var_dcon_next) - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - binds = [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), - (tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - (v , [], CursorTy, ProjE 0 (VarE tmp)), - -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), - -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), - -- End of region needs to be calculated differently - -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), - ((loc_var) , [], locs_ty3, VarE v) + binds = + [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (v, [], CursorTy, ProjE 0 (VarE tmp)), + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), + -- End of region needs to be calculated differently + -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), + ((loc_var), [], locs_ty3, VarE v) ] - bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) - return $ mkLets binds bod - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - - VectorTy el_ty -> do - tmp <- gensym "read_vec_tuple" - loc_var <- lookupVariable loc fenv - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), - (v , MkTy2 (VectorTy el_ty)), - (toEndV v, MkTy2 CursorTy)]) - tenv - ty' = stripTyLocs ty - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadVector (loc_var) (stripTyLocs el_ty)), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - if canBind - then do - -- If the location exists in the environment, it indicates that the - -- corresponding variable was also bound and we shouldn't create duplicate - -- bindings (checked in the LetLocE cases). - loc_var <- lookupVariable loc fenv - let binds' = ((loc_var),[],CursorTy, VarE cur):binds - tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' --(toEndV v) - return $ mkLets binds' bod - else do - -- Cannot read this int. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) binds denv - go curw fenv rst_vlocs rst_tys canBind denv' tenv' --(toEndV v) - - - ListTy el_ty -> do - tmp <- gensym "read_list_tuple" - loc_var <- lookupVariable loc fenv - let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [ListTy el_ty, CursorTy])), - (v , MkTy2 (ListTy el_ty)), - (toEndV v, MkTy2 CursorTy)]) - tenv - ty' = stripTyLocs ty - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadList (loc_var) (stripTyLocs el_ty)), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - if canBind - then do - -- If the location exists in the environment, it indicates that the - -- corresponding variable was also bound and we shouldn't create duplicate - -- bindings (checked in the LetLocE cases). - loc_var <- lookupVariable loc fenv - let binds' = ((loc_var),[],CursorTy, VarE cur):binds - tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' - bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' --(toEndV v) - return $ mkLets binds' bod - else do - -- Cannot read this int. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) binds denv - go curw fenv rst_vlocs rst_tys canBind denv' tenv' --(toEndV v) - - PackedTy tycon ploc -> do - -- Two cases - -- If the PackedTy is the same tycon then - -- If the PackedTy is not the same tycon - let datacons = getConOrdering ddfs tycon - let isSameTycon = if (elem dcon datacons) then True else False - case isSameTycon of - True -> do - let ty3_of_field = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let tenv' = M.insert v (MkTy2 ty3_of_field) tenv - let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - -- let cur = fromJust $ L.lookup (dcon, field_idx) field_cur - let cur = dcur + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) + return $ mkLets binds bod + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + VectorTy el_ty -> do + tmp <- gensym "read_vec_tuple" loc_var <- lookupVariable loc fenv - if canBind - then do - let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' - -- Flip canBind to indicate that the subsequent fields - -- should be added to the dependency environment. - dcon_next <- gensym $ toVar $ (fromVar dcur) ++ "_next" - let end_fields = map (\(key, varr) -> varr ) _field_cur - let makeCurArr = Ext $ MakeCursorArray (1 + length (end_fields)) ([dcon_next] ++ end_fields) - let let_mk_cur_arr = (loc_var, [], CursorArrayTy (1 + length (end_fields)), makeCurArr) - let dcon_nxt = [(dcon_next,[],CursorTy, Ext $ AddCursor dcur (LitE 1))] ++ [let_mk_cur_arr,(v , [], CursorArrayTy (1 + length (end_fields)), VarE (loc_var))] - -- make the new curw type - -- this consists of incrementing the data constructor buffer by one and all the rest of the fields - let curw' = SoAWin dcon_next _field_cur - bod <- go curw' fenv rst_vlocs rst_tys False denv tenv'' --(toEndV v) - return $ mkLets dcon_nxt bod - else do - -- Cannot read this. Instead, we add it to DepEnv. - let denv' = M.insertWith (++) (loc) [(v,[],ty3_of_field2,VarE (loc_var))] denv - go curw fenv rst_vlocs rst_tys False denv' tenv' --(toEndV v) - False -> do - let ty3_of_field = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + (v, MkTy2 (VectorTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadVector (loc_var) (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - -- let cur = dcur + if canBind + then do + -- If the location exists in the environment, it indicates that the + -- corresponding variable was also bound and we shouldn't create duplicate + -- bindings (checked in the LetLocE cases). + loc_var <- lookupVariable loc fenv + let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets binds' bod + else do + -- Cannot read this int. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) binds denv + go curw fenv rst_vlocs rst_tys canBind denv' tenv' -- (toEndV v) + ListTy el_ty -> do + tmp <- gensym "read_list_tuple" loc_var <- lookupVariable loc fenv + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [ListTy el_ty, CursorTy])), + (v, MkTy2 (ListTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadList (loc_var) (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] if canBind - then do - let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' - -- Flip canBind to indicate that the subsequent fields - -- should be added to the dependency environment. - bod <- go curw fenv rst_vlocs rst_tys False denv tenv'' --(toEndV v) - return $ mkLets [((loc_var), [], ty3_of_field2, VarE cur) - ,(v , [], ty3_of_field2, VarE (loc_var))] - bod - else do - -- Cannot read this. Instead, we add it to DepEnv. - let denv' = dbgTrace (minChatLvl) "Printing in packedTy unpack dcon: " dbgTrace (minChatLvl) (sdoc (loc)) dbgTrace (minChatLvl) "End in unpacking dcon.\n" M.insertWith (++) (loc) [((loc_var), [], ty3_of_field2, VarE cur), (v,[],ty3_of_field2,VarE (loc_var))] denv - bod <- go curw fenv rst_vlocs rst_tys False denv' tenv' --(toEndV v) - -- VS: [05.11.2025] This is a hack to ensure that the location variable is not undefined. - -- If we have serialized packed types that are not self recursive, we still have to release - -- The let binding and just adding it to the depenv is not enough. - -- There should be a careful look at why this is and if this is functionally correct. - return $ mkLets [((loc_var), [], ty3_of_field2, VarE cur), (v , [], ty3_of_field2, VarE (loc_var))] - bod - _ -> error $ "unpackRegularDataCon: Unexpected field " ++ sdoc (v,loc) ++ ":" ++ sdoc ty - - _ -> error $ "unpackRegularDataCon: Unexpected numnber of varible, type pairs: " ++ show (vlocs,tys) - - - - + then do + -- If the location exists in the environment, it indicates that the + -- corresponding variable was also bound and we shouldn't create duplicate + -- bindings (checked in the LetLocE cases). + loc_var <- lookupVariable loc fenv + let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets binds' bod + else do + -- Cannot read this int. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) binds denv + go curw fenv rst_vlocs rst_tys canBind denv' tenv' -- (toEndV v) + PackedTy tycon ploc -> do + -- Two cases + -- If the PackedTy is the same tycon then + -- If the PackedTy is not the same tycon + let datacons = getConOrdering ddfs tycon + let isSameTycon = if (elem dcon datacons) then True else False + case isSameTycon of + True -> do + let ty3_of_field = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field2 :: Ty3 = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) field_cur + let cur = dcur + loc_var <- lookupVariable loc fenv + if canBind + then do + let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' + -- Flip canBind to indicate that the subsequent fields + -- should be added to the dependency environment. + dcon_next <- gensym $ toVar $ (fromVar dcur) ++ "_next" + let end_fields = map (\(key, varr) -> varr) _field_cur + let makeCurArr = Ext $ MakeCursorArray (1 + length (end_fields)) ([dcon_next] ++ end_fields) + let let_mk_cur_arr = (loc_var, [], CursorArrayTy (1 + length (end_fields)), makeCurArr) + let dcon_nxt = [(dcon_next, [], CursorTy, Ext $ AddCursor dcur (LitE 1))] ++ [let_mk_cur_arr, (v, [], CursorArrayTy (1 + length (end_fields)), VarE (loc_var))] + -- make the new curw type + -- this consists of incrementing the data constructor buffer by one and all the rest of the fields + let curw' = SoAWin dcon_next _field_cur + bod <- go curw' fenv rst_vlocs rst_tys False denv tenv'' -- (toEndV v) + return $ mkLets dcon_nxt bod + else do + -- Cannot read this. Instead, we add it to DepEnv. + let denv' = M.insertWith (++) (loc) [(v, [], ty3_of_field2, VarE (loc_var))] denv + go curw fenv rst_vlocs rst_tys False denv' tenv' -- (toEndV v) + False -> do + let ty3_of_field = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field2 :: Ty3 = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + -- let cur = dcur + loc_var <- lookupVariable loc fenv + if canBind + then do + let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' + -- Flip canBind to indicate that the subsequent fields + -- should be added to the dependency environment. + bod <- go curw fenv rst_vlocs rst_tys False denv tenv'' -- (toEndV v) + return $ + mkLets + [ ((loc_var), [], ty3_of_field2, VarE cur), + (v, [], ty3_of_field2, VarE (loc_var)) + ] + bod + else do + -- Cannot read this. Instead, we add it to DepEnv. + let denv' = dbgTrace (minChatLvl) "Printing in packedTy unpack dcon: " dbgTrace (minChatLvl) (sdoc (loc)) dbgTrace (minChatLvl) "End in unpacking dcon.\n" M.insertWith (++) (loc) [((loc_var), [], ty3_of_field2, VarE cur), (v, [], ty3_of_field2, VarE (loc_var))] denv + bod <- go curw fenv rst_vlocs rst_tys False denv' tenv' -- (toEndV v) + -- VS: [05.11.2025] This is a hack to ensure that the location variable is not undefined. + -- If we have serialized packed types that are not self recursive, we still have to release + -- The let binding and just adding it to the depenv is not enough. + -- There should be a careful look at why this is and if this is functionally correct. + return $ + mkLets + [((loc_var), [], ty3_of_field2, VarE cur), (v, [], ty3_of_field2, VarE (loc_var))] + bod + _ -> error $ "unpackRegularDataCon: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + _ -> error $ "unpackRegularDataCon: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) -- We have access to all fields in this constructor, and can create -- bindings for everything. We begin by unpacking the random access nodes. - unpackWithAbsRAN :: Var -> PassM Exp3 - unpackWithAbsRAN field_cur = - -- A map from a variable to a tuple containing it's location and - -- the RAN field it depends on. Consider this constructor: - -- - -- (Node^ [(ran_y3, loc_ran_y3), (n1, loc_n1) , (x2 , loc_x2), (y3 , loc_y3)] ...), - -- - -- it will be the map: - -- - -- (y3 -> (loc_y3, ran_y3)) - let ran_mp = - case numRANsDataCon (M.map (fmap unTy2) ddfs) (fromRANDataCon dcon) of - 0 -> M.empty - n -> let -- Random access nodes occur immediately after the tag - ind_vars = L.map fst $ L.take n vlocs1 - -- Everything else is a regular consturctor field, - -- which depends on some random access node - data_fields = reverse $ L.take n (reverse vlocs1) - (vars, var_locargs) = unzip data_fields - var_locs = map (unwrapLocVar . toLocVar) var_locargs - in M.fromList $ zip vars (zip var_locs ind_vars) - in go field_cur vlocs1 tys1 ran_mp denv1 (M.insert field_cur (MkTy2 CursorTy) tenv1) + unpackWithAbsRAN :: WindowIntoCursor -> M.Map FreeVarsTy Var -> PassM Exp3 + unpackWithAbsRAN field_cur freeVarToVarEnv_unpack = + -- A map from a variable to a tuple containing it's location and + -- the RAN field it depends on. Consider this constructor: + -- + -- (Node^ [(ran_y3, loc_ran_y3), (n1, loc_n1) , (x2 , loc_x2), (y3 , loc_y3)] ...), + -- + -- it will be the map: + -- + -- (y3 -> (loc_y3, ran_y3)) + let ran_mp = + case numRANsDataCon (M.map (fmap unTy2) ddfs) (fromRANDataCon dcon) of + 0 -> M.empty + n -> + let -- Random access nodes occur immediately after the tag + ind_vars = L.map fst $ L.take n vlocs1 + -- Everything else is a regular consturctor field, + -- which depends on some random access node + data_fields = reverse $ L.take n (reverse vlocs1) + (vars, var_locargs) = unzip data_fields + var_locs = map (unwrapLocVar . toLocVar) var_locargs + in M.fromList $ zip vars (zip var_locs ind_vars) + tenv1' = case field_cur of + AoSWin cf -> (M.insert cf (MkTy2 CursorTy) tenv1) + SoAWin dcf fieldfvs -> + let tenv1'' = M.insert dcf (MkTy2 CursorTy) tenv1 + in -- VS: TODO: This is assuming that each field is cursorTy + -- we should change this OR we can reply on addCasts to fix casting?? + foldr (\(x, y) acc -> M.insert y (MkTy2 CursorTy) acc) tenv1'' fieldfvs + in go field_cur freeVarToVarEnv_unpack vlocs1 tys1 ran_mp denv1 tenv1' where - go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var,Var) -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 - go cur vlocs tys indirections_env denv tenv = do - case (vlocs, tys) of - ([], []) -> processRhs denv tenv - ((v,locarg):rst_vlocs, (MkTy2 ty):rst_tys) -> - let loc = toLocVar locarg - locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" - in case ty of - -- The random access pointer - -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. -{- - CursorTy -> do - tmp <- gensym "readcursor_shortcut" - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy])), - (loc , MkTy2 CursorTy), - (v , MkTy2 CursorTy), - (toEndV v, MkTy2 CursorTy)]) - tenv - - binds = [(tmp , [], ProdTy [CursorTy, CursorTy], Ext $ ReadCursor cur), - (loc , [], CursorTy, VarE cur), - (v , [], CursorTy, ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' - return $ mkLets binds bod --} - - CursorTy -> do - tmp <- gensym "readcursor_shortcut" - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - (locs_var , MkTy2 CursorTy), - (v , MkTy2 CursorTy), - (toEndV v, MkTy2 CursorTy), - (toTagV v, MkTy2 IntTy), - (toEndFromTaggedV v, MkTy2 CursorTy)]) - tenv - read_cursor = Ext (ReadTaggedCursor cur) - binds = [(tmp , [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - (locs_var , [], CursorTy, VarE cur), - (v , [], CursorTy, ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), - (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), - (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v)))] - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' - return $ mkLets binds bod - - - -- Int, Sym, or Bool - _ | isScalarTy ty -> do - (tenv', binds) <- scalarBinds ty v locs_var tenv - let loc_bind = case M.lookup v indirections_env of - Nothing -> - (locs_var,[],CursorTy, VarE cur) - -- Read this using a random access node - Just (_var_loc, ind_var) -> - (locs_var,[],CursorTy, VarE ind_var) - binds' = loc_bind:binds - tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv'' - return $ mkLets binds' bod - - VectorTy el_ty -> do - tmp <- gensym "read_vec_tuple" - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), - (v , MkTy2 (VectorTy el_ty)), - (toEndV v, MkTy2 CursorTy)]) - tenv - ty' = stripTyLocs ty - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadVector locs_var (stripTyLocs el_ty)), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - loc_bind = case M.lookup v indirections_env of - Nothing -> - (locs_var, [], CursorTy, VarE cur) - Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - binds' = loc_bind : binds - tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv'' - return $ mkLets binds' bod - - ListTy el_ty -> do - tmp <- gensym "read_list_tuple" - let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), - (v , MkTy2 (ListTy el_ty)), - (toEndV v, MkTy2 CursorTy)]) - tenv - ty' = stripTyLocs ty - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadList locs_var (stripTyLocs el_ty)), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] - loc_bind = case M.lookup v indirections_env of - Nothing -> - (locs_var, [], CursorTy, VarE cur) - Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - binds' = loc_bind : binds - tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv'' - return $ mkLets binds' bod - - PackedTy{} -> do - let tenv' = M.union (M.fromList [ (locs_var, MkTy2 CursorTy) - , (v, MkTy2 CursorTy) ]) - tenv - loc_bind = case M.lookup v indirections_env of - -- This is the first packed value. We can unpack this. - Nothing -> - (locs_var, [], CursorTy, VarE cur) - -- We need to access this using a random access node - Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' - return $ mkLets [ loc_bind, (v, [], CursorTy, VarE locs_var) ] bod + go :: WindowIntoCursor -> M.Map FreeVarsTy Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var, Var) -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 + go curw fenv vlocs tys indirections_env denv tenv = do + case curw of + AoSWin cur -> do + case (vlocs, tys) of + ([], []) -> processRhs denv tenv + ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> + let loc = toLocVar locarg + locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeLet: unexpected location variable" + in case ty of + -- The random access pointer + -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. + {- + CursorTy -> do + tmp <- gensym "readcursor_shortcut" + let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy])), + (loc , MkTy2 CursorTy), + (v , MkTy2 CursorTy), + (toEndV v, MkTy2 CursorTy)]) + tenv + + binds = [(tmp , [], ProdTy [CursorTy, CursorTy], Ext $ ReadCursor cur), + (loc , [], CursorTy, VarE cur), + (v , [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] + bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets binds bod + -} + + CursorTy -> do + tmp <- gensym "readcursor_shortcut" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + (locs_var, MkTy2 CursorTy), + (v, MkTy2 CursorTy), + (toEndV v, MkTy2 CursorTy), + (toTagV v, MkTy2 IntTy), + (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = Ext (ReadTaggedCursor cur) + binds = + [ (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (locs_var, [], CursorTy, VarE cur), + (v, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV v, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))) + ] + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets binds bod - _ -> error $ "unpackWitnAbsRAN: Unexpected field " ++ sdoc (v,loc) ++ ":" ++ sdoc ty + -- Int, Sym, or Bool + _ | isScalarTy ty -> do + (tenv', binds) <- scalarBinds ty v locs_var tenv + let loc_bind = case M.lookup v indirections_env of + Nothing -> + (locs_var, [], CursorTy, VarE cur) + -- Read this using a random access node + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + VectorTy el_ty -> do + tmp <- gensym "read_vec_tuple" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + (v, MkTy2 (VectorTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadVector locs_var (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] + loc_bind = case M.lookup v indirections_env of + Nothing -> + (locs_var, [], CursorTy, VarE cur) + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + ListTy el_ty -> do + tmp <- gensym "read_list_tuple" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + (v, MkTy2 (ListTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadList locs_var (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] + loc_bind = case M.lookup v indirections_env of + Nothing -> + (locs_var, [], CursorTy, VarE cur) + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + PackedTy {} -> do + let tenv' = + M.union + ( M.fromList + [ (locs_var, MkTy2 CursorTy), + (v, MkTy2 CursorTy) + ] + ) + tenv + loc_bind = case M.lookup v indirections_env of + -- This is the first packed value. We can unpack this. + Nothing -> + (locs_var, [], CursorTy, VarE cur) + -- We need to access this using a random access node + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets [loc_bind, (v, [], CursorTy, VarE locs_var)] bod + _ -> error $ "unpackWitnAbsRAN: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + _ -> error $ "unpackWitnAbsRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) + SoAWin dcur_end _field_cur -> do + case (vlocs, tys) of + ([], []) -> processRhs denv tenv + ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> + let loc = toLocVar locarg + locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeLet: unexpected location variable" + in case ty of + -- The random access pointer + -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. + {- + CursorTy -> do + tmp <- gensym "readcursor_shortcut" + let tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [CursorTy, CursorTy])), + (loc , MkTy2 CursorTy), + (v , MkTy2 CursorTy), + (toEndV v, MkTy2 CursorTy)]) + tenv + + binds = [(tmp , [], ProdTy [CursorTy, CursorTy], Ext $ ReadCursor cur), + (loc , [], CursorTy, VarE cur), + (v , [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] + bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets binds bod + -} + + CursorTy -> do + tmp <- gensym "readcursor_shortcut" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + (locs_var, MkTy2 CursorTy), + (v, MkTy2 CursorTy), + (toEndV v, MkTy2 CursorTy), + (toTagV v, MkTy2 IntTy), + (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = Ext (ReadTaggedCursor dcur_end) + binds = + [ (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (locs_var, [], CursorTy, VarE dcur_end), + (v, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV v, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))) + ] + let curw' = SoAWin (toEndV v) _field_cur + bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets binds bod - _ -> error $ "unpackWitnAbsRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs,tys) + -- Int, Sym, or Bool + _ | isScalarTy ty -> do + (tenv', binds) <- scalarBinds ty v locs_var tenv + let loc_bind = case M.lookup v indirections_env of + Nothing -> + (locs_var, [], CursorTy, VarE dcur_end) + -- Read this using a random access node + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + + -- _ | isScalarTy ty -> do + -- loc_var <- lookupVariable loc fenv + -- (tenv', binds) <- scalarBinds ty v loc_var tenv + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let field_cur' = map (\(k@(d, idx), var) -> if (d, idx) == (dcon, field_idx) then (k, (toEndV v)) else (k, var)) _field_cur + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + -- if canBind + -- then do + -- -- If the location exists in the environment, it indicates that the + -- -- corresponding variable was also bound and we shouldn't create duplicate + -- -- bindings (checked in the LetLocE cases). + -- loc_var <- lookupVariable loc fenv + -- let binds' = ((loc_var), [], CursorTy, VarE cur) : binds + -- tenv'' = M.insert (loc_var) (MkTy2 CursorTy) tenv' + + -- bod <- go (SoAWin dcur field_cur') fenv rst_vlocs rst_tys canBind denv tenv'' + -- return $ mkLets binds' bod + -- else do + -- -- Cannot read this int. Instead, we add it to DepEnv. + -- let denv' = M.insertWith (++) (loc) binds denv + -- go (SoAWin dcur field_cur') fenv rst_vlocs rst_tys canBind denv' tenv' + + + + + VectorTy el_ty -> do + tmp <- gensym "read_vec_tuple" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + (v, MkTy2 (VectorTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadVector locs_var (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] + loc_bind = case M.lookup v indirections_env of + Nothing -> + (locs_var, [], CursorTy, VarE dcur_end) + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + ListTy el_ty -> do + tmp <- gensym "read_list_tuple" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + (v, MkTy2 (ListTy el_ty)), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + ty' = stripTyLocs ty + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadList locs_var (stripTyLocs el_ty)), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] + loc_bind = case M.lookup v indirections_env of + Nothing -> + (locs_var, [], CursorTy, VarE dcur_end) + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + PackedTy {} -> do + let tenv' = + M.union + ( M.fromList + [ (locs_var, MkTy2 CursorTy), + (v, MkTy2 CursorTy) + ] + ) + tenv + loc_bind = case M.lookup v indirections_env of + -- This is the first packed value. We can unpack this. + Nothing -> + (locs_var, [], CursorTy, VarE dcur_end) + -- We need to access this using a random access node + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets [loc_bind, (v, [], CursorTy, VarE locs_var)] bod + _ -> error $ "unpackWitnAbsRAN: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + _ -> error $ "unpackWitnAbsRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) -- We have access to all fields in this constructor, and can create -- bindings for everything. We begin by unpacking the random access nodes. unpackWithRelRAN :: Var -> PassM Exp3 unpackWithRelRAN field_cur = - -- ran_mp is a map from a variable to a tuple containing it's location and - -- the RAN field it depends on. Consider this constructor: - -- - -- (Node* [(ran_y3, loc_ran_y3), (n1, loc_n1) , (x2 , loc_x2), (y3 , loc_y3)] ...), - -- - -- it will be the map: - -- - -- (y3 -> (loc_y3, ran_y3)) - let ran_mp = - case numRANsDataCon (M.map (fmap unTy2) ddfs) (fromRANDataCon dcon) of - 0 -> M.empty - n -> let -- Random access nodes occur immediately after the tag - inds = L.take n $ L.drop 1 vlocs1 - -- Everything else is a regular consturctor field, - -- which depends on some random access node - data_fields = reverse $ L.take n (reverse vlocs1) - (vars, var_locargs) = unzip data_fields - var_locs = map (\lc_arg -> case (M.lookup (fromLocVarToFreeVarsTy (toLocVar lc_arg)) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" - - ) var_locargs - in M.fromList $ zip vars (zip var_locs (map (\(x,y) -> (x,(unwrapLocVar . toLocVar) y)) inds)) - in go field_cur vlocs1 tys1 ran_mp denv1 (M.insert field_cur (MkTy2 CursorTy) tenv1) + -- ran_mp is a map from a variable to a tuple containing it's location and + -- the RAN field it depends on. Consider this constructor: + -- + -- (Node* [(ran_y3, loc_ran_y3), (n1, loc_n1) , (x2 , loc_x2), (y3 , loc_y3)] ...), + -- + -- it will be the map: + -- + -- (y3 -> (loc_y3, ran_y3)) + let ran_mp = + case numRANsDataCon (M.map (fmap unTy2) ddfs) (fromRANDataCon dcon) of + 0 -> M.empty + n -> + let -- Random access nodes occur immediately after the tag + inds = L.take n $ L.drop 1 vlocs1 + -- Everything else is a regular consturctor field, + -- which depends on some random access node + data_fields = reverse $ L.take n (reverse vlocs1) + (vars, var_locargs) = unzip data_fields + var_locs = + map + ( \lc_arg -> case (M.lookup (fromLocVarToFreeVarsTy (toLocVar lc_arg)) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeLet: unexpected location variable" + ) + var_locargs + in M.fromList $ zip vars (zip var_locs (map (\(x, y) -> (x, (unwrapLocVar . toLocVar) y)) inds)) + in go field_cur vlocs1 tys1 ran_mp denv1 (M.insert field_cur (MkTy2 CursorTy) tenv1) where - go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var,(Var,Var)) -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 + go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var, (Var, Var)) -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 go cur vlocs tys indirections_env denv tenv = do case (vlocs, tys) of ([], []) -> processRhs denv tenv - ((v,locarg):rst_vlocs, (MkTy2 ty):rst_tys) -> + ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> let loc = toLocVar locarg - locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" + locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of + Just v' -> v' + Nothing -> error "cursorizeLet: unexpected location variable" in case ty of - -- Int, Sym, or Bool - _ | isScalarTy ty -> do - (tenv', binds) <- scalarBinds ty v locs_var tenv - let loc_bind = case M.lookup v indirections_env of - -- This appears before the first packed field. Unpack it - -- in the usual way. - Nothing -> - (locs_var,[],CursorTy, VarE cur) - -- We need to read this using a random access node - Just (_var_loc, (ind_var, ind_loc)) -> - (locs_var,[],CursorTy, Ext $ AddCursor ind_loc (VarE ind_var)) - binds' = loc_bind:binds - tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv'' - return $ mkLets binds' bod - - PackedTy{} -> do - tmp_loc <- gensym "loc" - let tenv' = M.union (M.fromList [ (locs_var, MkTy2 CursorTy) - , (v, MkTy2 CursorTy) ]) + -- Int, Sym, or Bool + _ | isScalarTy ty -> do + (tenv', binds) <- scalarBinds ty v locs_var tenv + let loc_bind = case M.lookup v indirections_env of + -- This appears before the first packed field. Unpack it + -- in the usual way. + Nothing -> + (locs_var, [], CursorTy, VarE cur) + -- We need to read this using a random access node + Just (_var_loc, (ind_var, ind_loc)) -> + (locs_var, [], CursorTy, Ext $ AddCursor ind_loc (VarE ind_var)) + binds' = loc_bind : binds + tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv'' + return $ mkLets binds' bod + PackedTy {} -> do + tmp_loc <- gensym "loc" + let tenv' = + M.union + ( M.fromList + [ (locs_var, MkTy2 CursorTy), + (v, MkTy2 CursorTy) + ] + ) tenv - loc_binds = case M.lookup v indirections_env of - -- This is the first packed value. We can unpack this. - Nothing -> - [(locs_var, [], CursorTy, VarE cur)] - -- We need to access this using a random access node - Just (_var_loc, (ind_var, ind_loc)) -> - [ (tmp_loc,[],CursorTy, Ext $ AddCursor ind_loc (VarE ind_var)) - , (locs_var,[],CursorTy, Ext $ AddCursor tmp_loc (LitE 8)) ] - bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' - return $ mkLets (loc_binds ++ [(v, [], CursorTy, VarE locs_var)]) bod - - _ -> error $ "unpackWithRelRAN: Unexpected field " ++ sdoc (v,loc) ++ ":" ++ sdoc ty - - _ -> error $ "unpackWithRelRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs,tys) + loc_binds = case M.lookup v indirections_env of + -- This is the first packed value. We can unpack this. + Nothing -> + [(locs_var, [], CursorTy, VarE cur)] + -- We need to access this using a random access node + Just (_var_loc, (ind_var, ind_loc)) -> + [ (tmp_loc, [], CursorTy, Ext $ AddCursor ind_loc (VarE ind_var)), + (locs_var, [], CursorTy, Ext $ AddCursor tmp_loc (LitE 8)) + ] + bod <- go (toEndV v) rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets (loc_binds ++ [(v, [], CursorTy, VarE locs_var)]) bod + _ -> error $ "unpackWithRelRAN: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + _ -> error $ "unpackWithRelRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) -- Generate bindings for unpacking int fields. A convenient scalarBinds :: OldTy2 -> Var -> Var -> TyEnv Var Ty2 -> PassM (TyEnv Var Ty2, [(Var, [()], Ty3, Exp3)]) @@ -3284,48 +3843,53 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- Note that the location is not added to the type environment here. -- The caller of this fn will do that later, depending on whether we're -- binding the location now or later via DepEnv. - let s = mkScalar ty - tenv' = M.union (M.fromList [(tmp , MkTy2 (ProdTy [ty, CursorTy])), - (v , MkTy2 ty), - (toEndV v, MkTy2 CursorTy)]) - tenv - - ty' = stripTyLocs ty - - binds = [(tmp , [], ProdTy [ty', CursorTy], Ext $ ReadScalar s loc), - (v , [], ty' , ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp))] + let s = mkScalar ty + tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [ty, CursorTy])), + (v, MkTy2 ty), + (toEndV v, MkTy2 CursorTy) + ] + ) + tenv + + ty' = stripTyLocs ty + + binds = + [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadScalar s loc), + (v, [], ty', ProjE 0 (VarE tmp)), + (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + ] return (tenv', binds) giveStarts :: OldTy2 -> Exp3 -> Exp3 giveStarts ty e = case ty of - PackedTy{} -> mkProj 0 e + PackedTy {} -> mkProj 0 e -- NOTE : mkProj . MkProdE == id - ProdTy tys -> MkProdE $ zipWith (\ ty' n -> giveStarts ty' (mkProj n e)) tys [0..] + ProdTy tys -> MkProdE $ zipWith (\ty' n -> giveStarts ty' (mkProj n e)) tys [0 ..] _ -> e - projValTy :: (Out a) => UrTy a -> UrTy a projValTy = projTy 0 projEndsTy :: (Out a) => UrTy a -> UrTy a projEndsTy = projTy 1 - -- -- | Bindings for a letregion -- regionToBinds :: M.Map FreeVarsTy Var -> Bool -> Region -> RegionSize -> PassM [(Var, [()], Ty3, Exp3)] -- regionToBinds freeVarToVarEnv for_parallel_allocs r sz = do -- case r of -- VarR{} -> error $ "Unexpected VarR in Cursorize." ++ sdoc r --- GlobR v mul -> do +-- GlobR v mul -> do -- let mul' = go mul -- let endv = toEndV v -- if for_parallel_allocs -- then return $ [ (v , [], CursorTy, Ext (NewParBuffer mul')) , ((endv), [], CursorTy, Ext (EndOfBuffer mul'))] -- else return $ [ (v , [], CursorTy, Ext (NewBuffer mul')) -- , (endv, [], CursorTy, Ext (EndOfBuffer mul'))] --- DynR v mul -> do +-- DynR v mul -> do -- let mul' = go mul -- if for_parallel_allocs -- then return $ [ (v , [], CursorTy, Ext$ ScopedParBuffer mul') @@ -3334,28 +3898,28 @@ projEndsTy = projTy 1 -- , (toEndV v, [], CursorTy, Ext$ EndOfBuffer mul')] -- -- TODO: docs -- MMapR _v -> return $ [] - + -- -- TODO: SoA Region --- SoAR dcreg fieldRegs -> do +-- SoAR dcreg fieldRegs -> do -- dcreg_binds <- regionToBinds freeVarToVarEnv for_parallel_allocs dcreg sz -- field_binds <- concatMapM (\(key, field_reg) -> regionToBinds freeVarToVarEnv for_parallel_allocs field_reg sz) fieldRegs -- -- Make the cursor array -- let reg_to_reg_var = regionToVar r --- regions_var <- case (M.lookup (fromRegVarToFreeVarsTy reg_to_reg_var) freeVarToVarEnv) of +-- regions_var <- case (M.lookup (fromRegVarToFreeVarsTy reg_to_reg_var) freeVarToVarEnv) of -- Just v -> return $ v -- Nothing -> gensym "reg_ptr" --- field_reg_vars <- mapM (\(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv) of +-- field_reg_vars <- mapM (\(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv) of -- Just v -> v --- Nothing -> case field_reg of +-- Nothing -> case field_reg of -- VarR v -> return $ v -- GlobR v _ -> return $ v -- DynR v _ -> return $ v -- MMapR v -> return $ v -- SoAR _ _ -> gensym "reg_ptr" -- ) fieldRegs --- dc_reg_var <- case (M.lookup (fromRegVarToFreeVarsTy (regionToVar dcreg)) freeVarToVarEnv) of +-- dc_reg_var <- case (M.lookup (fromRegVarToFreeVarsTy (regionToVar dcreg)) freeVarToVarEnv) of -- Just v -> return $ v --- Nothing -> case dcreg of +-- Nothing -> case dcreg of -- VarR v -> return $ v -- GlobR v _ -> return $ v -- DynR v _ -> return $ v @@ -3375,7 +3939,7 @@ projEndsTy = projTy 1 -- regionToBinds freeVarToVarEnv for_parallel_allocs r sz = do -- case r of -- VarR{} -> error $ "Unexpected VarR in Cursorize." ++ sdoc r --- GlobR v mul -> do +-- GlobR v mul -> do -- let mul' = go mul -- let endv = toEndV v -- let bnds = if for_parallel_allocs @@ -3383,7 +3947,7 @@ projEndsTy = projTy 1 -- else [ (v , [], CursorTy, Ext (NewBuffer mul')) -- , (endv, [], CursorTy, Ext (EndOfBuffer mul'))] -- return (bnds, freeVarToVarEnv) --- DynR v mul -> do +-- DynR v mul -> do -- let mul' = go mul -- let bnds = if for_parallel_allocs -- then [ (v , [], CursorTy, Ext (ScopedParBuffer mul')) @@ -3393,37 +3957,37 @@ projEndsTy = projTy 1 -- return (bnds, freeVarToVarEnv) -- -- TODO: docs -- MMapR _v -> return ([], freeVarToVarEnv) - + -- -- TODO: SoA Region --- SoAR dcreg fieldRegs -> do +-- SoAR dcreg fieldRegs -> do -- (dcreg_binds, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv for_parallel_allocs dcreg sz -- field_binds_pairs <- fmap concat $ mapM (\(key, field_reg) -> regionToBinds freeVarToVarEnv for_parallel_allocs field_reg sz) fieldRegs -- let field_binds = map fst field_binds_pairs --- let field_new_maps = map snd field_binds_pairs +-- let field_new_maps = map snd field_binds_pairs -- -- Make the cursor array -- let reg_to_reg_var = regionToVar r --- regions_var <- case M.lookup (fromRegVarToFreeVarsTy reg_to_reg_var) freeVarToVarEnv of +-- regions_var <- case M.lookup (fromRegVarToFreeVarsTy reg_to_reg_var) freeVarToVarEnv of -- Just v -> return v -- Nothing -> gensym "reg_ptr" -- let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_to_reg_var) regions_var freeVarToVarEnv' --- field_reg_keys_vars <- mapM (\(key, field_reg) -> do --- case M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv of +-- field_reg_keys_vars <- mapM (\(key, field_reg) -> do +-- case M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv of -- Just v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) --- Nothing -> case field_reg of +-- Nothing -> case field_reg of -- VarR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) -- GlobR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) -- DynR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) -- MMapR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) --- SoAR _ _ -> do --- new_name <- gensym "reg_ptr" +-- SoAR _ _ -> do +-- new_name <- gensym "reg_ptr" -- return (fromRegVarToFreeVarsTy (regionToVar field_reg), new_name) -- ) fieldRegs -- let field_reg_keys = map fst field_reg_keys_vars -- let field_reg_vars = map snd field_reg_keys_vars -- let freeVarToVarEnv''' = foldr (\(key, var) acc -> M.insert key var acc) freeVarToVarEnv'' field_reg_keys_vars --- dc_reg_var <- case M.lookup (fromRegVarToFreeVarsTy (regionToVar dcreg)) freeVarToVarEnv of +-- dc_reg_var <- case M.lookup (fromRegVarToFreeVarsTy (regionToVar dcreg)) freeVarToVarEnv of -- Just v -> return v --- Nothing -> case dcreg of +-- Nothing -> case dcreg of -- VarR v -> return v -- GlobR v _ -> return v -- DynR v _ -> return v @@ -3443,110 +4007,120 @@ projEndsTy = projTy 1 regionToBinds :: M.Map FreeVarsTy Var -> Bool -> Region -> RegionSize -> PassM ([(Var, [()], Ty3, Exp3)], M.Map FreeVarsTy Var) regionToBinds freeVarToVarEnv for_parallel_allocs r sz = do case r of - VarR{} -> error $ "Unexpected VarR in Cursorize." ++ sdoc r - GlobR v mul -> do - let mul' = go mul - let endv = toEndV v - let bnds = if for_parallel_allocs - then [ (v , [], CursorTy, Ext (NewParBuffer mul')) , (endv, [], CursorTy, Ext (EndOfBuffer mul'))] - else [ (v , [], CursorTy, Ext (NewBuffer mul')) - , (endv, [], CursorTy, Ext (EndOfBuffer mul'))] - return (bnds, freeVarToVarEnv) - DynR v mul -> do - let mul' = go mul - let bnds = if for_parallel_allocs - then [ (v , [], CursorTy, Ext (ScopedParBuffer mul')) - , (toEndV v, [], CursorTy, Ext (EndOfBuffer mul'))] - else [ (v , [], CursorTy, Ext (ScopedBuffer mul')) - , (toEndV v, [], CursorTy, Ext (EndOfBuffer mul'))] - return (bnds, freeVarToVarEnv) + VarR {} -> error $ "Unexpected VarR in Cursorize." ++ sdoc r + GlobR v mul -> do + let mul' = go mul + let endv = toEndV v + let bnds = + if for_parallel_allocs + then [(v, [], CursorTy, Ext (NewParBuffer mul')), (endv, [], CursorTy, Ext (EndOfBuffer mul'))] + else + [ (v, [], CursorTy, Ext (NewBuffer mul')), + (endv, [], CursorTy, Ext (EndOfBuffer mul')) + ] + return (bnds, freeVarToVarEnv) + DynR v mul -> do + let mul' = go mul + let bnds = + if for_parallel_allocs + then + [ (v, [], CursorTy, Ext (ScopedParBuffer mul')), + (toEndV v, [], CursorTy, Ext (EndOfBuffer mul')) + ] + else + [ (v, [], CursorTy, Ext (ScopedBuffer mul')), + (toEndV v, [], CursorTy, Ext (EndOfBuffer mul')) + ] + return (bnds, freeVarToVarEnv) -- TODO: docs - MMapR _v -> return ([], freeVarToVarEnv) - + MMapR _v -> return ([], freeVarToVarEnv) -- TODO: SoA Region - SoAR dcreg fieldRegs -> do - (dcreg_binds, _freeVarToVarEnv) <- regionToBinds freeVarToVarEnv for_parallel_allocs dcreg sz - field_binds_pairs <- mapM (\(key, field_reg) -> regionToBinds _freeVarToVarEnv for_parallel_allocs field_reg sz) fieldRegs - let field_binds = concatMap fst field_binds_pairs - let field_new_maps = map snd field_binds_pairs - let _freeVarToVarEnv' = foldr (\m acc -> M.union m acc) freeVarToVarEnv field_new_maps - let freeVarToVarEnv' = M.union _freeVarToVarEnv' _freeVarToVarEnv - -- Make the cursor array - let reg_to_reg_var = regionToVar r - regions_var <- case M.lookup (fromRegVarToFreeVarsTy reg_to_reg_var) freeVarToVarEnv' of - Just v -> return v - Nothing -> gensym "reg_ptr" - let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_to_reg_var) regions_var freeVarToVarEnv' - field_reg_keys_vars <- mapM (\(key, field_reg) -> do - case M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv'' of - Just v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - Nothing -> case field_reg of - VarR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - GlobR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - DynR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - MMapR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - SoAR _ _ -> do - new_name <- gensym "reg_ptr" - return (fromRegVarToFreeVarsTy (regionToVar field_reg), new_name) - ) fieldRegs - let field_reg_keys = map fst field_reg_keys_vars - let field_reg_vars = map snd field_reg_keys_vars - let field_end_reg_keys = map (\(R r) -> toEndVRegVar r) field_reg_keys - freeVarToVarEnv''' <- foldrM (\key acc -> insertRegInVarEnv key acc) freeVarToVarEnv'' field_end_reg_keys - let field_end_reg_vars = map (\key -> case (M.lookup (fromRegVarToFreeVarsTy key) freeVarToVarEnv''') of - Just v -> v - Nothing -> error "cursorizeExp: regionToBinds: SoAR: unexpected end of region variable" - ) field_end_reg_keys - let freeVarToVarEnv'''' = foldr (\(key, var) acc -> M.insert key var acc) freeVarToVarEnv''' field_reg_keys_vars - dc_reg_var <- case M.lookup (fromRegVarToFreeVarsTy (regionToVar dcreg)) freeVarToVarEnv'''' of - Just v -> return v - Nothing -> case dcreg of - VarR v -> return v - GlobR v _ -> return v - DynR v _ -> return v - MMapR v -> return v - SoAR _ _ -> error "data constructor region cannot be SoA." - let freeVarToVarEnv''''' = M.insert (fromRegVarToFreeVarsTy (regionToVar dcreg)) dc_reg_var freeVarToVarEnv'''' - let dc_reg_end_var = toEndVRegVar (regionToVar dcreg) - freeVarToVarEnv'''''' <- insertRegInVarEnv dc_reg_end_var freeVarToVarEnv''''' - let dc_reg_end_var_name = case (M.lookup (fromRegVarToFreeVarsTy dc_reg_end_var) freeVarToVarEnv'''''') of - Just v -> v - Nothing -> error "cursorizeExp: regionToBinds: SoAR: unexpected end of region variable" - let end_soa_reg = toEndVRegVar (regionToVar r) - freeVarToVarEnv''''''' <- insertRegInVarEnv end_soa_reg freeVarToVarEnv'''''' - let end_soa_reg_name = case (M.lookup (fromRegVarToFreeVarsTy end_soa_reg) freeVarToVarEnv''''''') of - Just v -> v - Nothing -> error "cursorizeExp: regionToBinds: SoAR: unexpected end of region variable" - let make_cur_array_bind = (regions_var, [], CursorArrayTy (1 + length field_reg_vars), Ext $ MakeCursorArray (1 + length field_reg_vars) ([dc_reg_var] ++ field_reg_vars)) - let make_end_cur_array_bind = (end_soa_reg_name, [], CursorArrayTy (1 + length field_end_reg_vars), Ext $ MakeCursorArray (1 + length field_end_reg_vars) ([dc_reg_end_var_name] ++ field_end_reg_vars)) - return (dcreg_binds ++ field_binds ++ [make_cur_array_bind] ++ [make_end_cur_array_bind], freeVarToVarEnv''''''') - - where - go mul = - case sz of - BoundedSize 0 -> mul - BoundedSize x -> Bounded x - Undefined -> mul - + SoAR dcreg fieldRegs -> do + (dcreg_binds, _freeVarToVarEnv) <- regionToBinds freeVarToVarEnv for_parallel_allocs dcreg sz + field_binds_pairs <- mapM (\(key, field_reg) -> regionToBinds _freeVarToVarEnv for_parallel_allocs field_reg sz) fieldRegs + let field_binds = concatMap fst field_binds_pairs + let field_new_maps = map snd field_binds_pairs + let _freeVarToVarEnv' = foldr (\m acc -> M.union m acc) freeVarToVarEnv field_new_maps + let freeVarToVarEnv' = M.union _freeVarToVarEnv' _freeVarToVarEnv + -- Make the cursor array + let reg_to_reg_var = regionToVar r + regions_var <- case M.lookup (fromRegVarToFreeVarsTy reg_to_reg_var) freeVarToVarEnv' of + Just v -> return v + Nothing -> gensym "reg_ptr" + let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_to_reg_var) regions_var freeVarToVarEnv' + field_reg_keys_vars <- + mapM + ( \(key, field_reg) -> do + case M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv'' of + Just v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) + Nothing -> case field_reg of + VarR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) + GlobR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) + DynR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) + MMapR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) + SoAR _ _ -> do + new_name <- gensym "reg_ptr" + return (fromRegVarToFreeVarsTy (regionToVar field_reg), new_name) + ) + fieldRegs + let field_reg_keys = map fst field_reg_keys_vars + let field_reg_vars = map snd field_reg_keys_vars + let field_end_reg_keys = map (\(R r) -> toEndVRegVar r) field_reg_keys + freeVarToVarEnv''' <- foldrM (\key acc -> insertRegInVarEnv key acc) freeVarToVarEnv'' field_end_reg_keys + let field_end_reg_vars = + map + ( \key -> case (M.lookup (fromRegVarToFreeVarsTy key) freeVarToVarEnv''') of + Just v -> v + Nothing -> error "cursorizeExp: regionToBinds: SoAR: unexpected end of region variable" + ) + field_end_reg_keys + let freeVarToVarEnv'''' = foldr (\(key, var) acc -> M.insert key var acc) freeVarToVarEnv''' field_reg_keys_vars + dc_reg_var <- case M.lookup (fromRegVarToFreeVarsTy (regionToVar dcreg)) freeVarToVarEnv'''' of + Just v -> return v + Nothing -> case dcreg of + VarR v -> return v + GlobR v _ -> return v + DynR v _ -> return v + MMapR v -> return v + SoAR _ _ -> error "data constructor region cannot be SoA." + let freeVarToVarEnv''''' = M.insert (fromRegVarToFreeVarsTy (regionToVar dcreg)) dc_reg_var freeVarToVarEnv'''' + let dc_reg_end_var = toEndVRegVar (regionToVar dcreg) + freeVarToVarEnv'''''' <- insertRegInVarEnv dc_reg_end_var freeVarToVarEnv''''' + let dc_reg_end_var_name = case (M.lookup (fromRegVarToFreeVarsTy dc_reg_end_var) freeVarToVarEnv'''''') of + Just v -> v + Nothing -> error "cursorizeExp: regionToBinds: SoAR: unexpected end of region variable" + let end_soa_reg = toEndVRegVar (regionToVar r) + freeVarToVarEnv''''''' <- insertRegInVarEnv end_soa_reg freeVarToVarEnv'''''' + let end_soa_reg_name = case (M.lookup (fromRegVarToFreeVarsTy end_soa_reg) freeVarToVarEnv''''''') of + Just v -> v + Nothing -> error "cursorizeExp: regionToBinds: SoAR: unexpected end of region variable" + let make_cur_array_bind = (regions_var, [], CursorArrayTy (1 + length field_reg_vars), Ext $ MakeCursorArray (1 + length field_reg_vars) ([dc_reg_var] ++ field_reg_vars)) + let make_end_cur_array_bind = (end_soa_reg_name, [], CursorArrayTy (1 + length field_end_reg_vars), Ext $ MakeCursorArray (1 + length field_end_reg_vars) ([dc_reg_end_var_name] ++ field_end_reg_vars)) + return (dcreg_binds ++ field_binds ++ [make_cur_array_bind] ++ [make_end_cur_array_bind], freeVarToVarEnv''''''') + where + go mul = + case sz of + BoundedSize 0 -> mul + BoundedSize x -> Bounded x + Undefined -> mul isBound :: Var -> TyEnv Var Ty2 -> Bool isBound l m = M.member l m - + -- ================================================================================ -- Dilation Conventions -- ================================================================================ -- Everything to do with dilation. It should be possible to change -- the dilated format by changing only this section. - -- | If an expression `e` returns type `T`, then a dilated version of -- `e` returns a tuple (T,Cursors), where cursors contains a flat -- record of end-cursors corresponding exactly to all the components -- of T which are PackedTy. --- newtype DiExp ex = Di ex deriving (Generic, Show, Read, Eq, Ord) ---type DiExp = Exp + +-- type DiExp = Exp instance (Out ex) => Out (DiExp ex) @@ -3556,7 +4130,6 @@ onDi f (Di x) = Di (f x) fromDi :: DiExp ex -> ex fromDi (Di x) = x - -- | Project the cursor package from a dilated expression, contains pointers -- to all the ENDs. projEnds :: DiExp Exp3 -> Exp3 @@ -3569,9 +4142,9 @@ projVal (Di e) = mkProj 0 e -- | Constructor that combines a regular expression with a list of -- corresponding end cursors. mkDi :: Exp3 -> [Exp3] -> DiExp Exp3 -mkDi x [] = Di $ MkProdE [x,MkProdE []] +mkDi x [] = Di $ MkProdE [x, MkProdE []] mkDi x [o] = Di $ MkProdE [x, o] -mkDi x ls = Di $ MkProdE [x, MkProdE ls] +mkDi x ls = Di $ MkProdE [x, MkProdE ls] curDict :: UrTy a -> UrTy a curDict (SymDictTy ar _ty) = SymDictTy ar CursorTy From 66be04951ae281b0703195c809132d9c664f4aae Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 25 Sep 2025 20:26:24 -0400 Subject: [PATCH 23/60] wip fixing ran --- .../examples/soa_examples/MonoTree.hs | 11 +- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- gibbon-compiler/src/Gibbon/Compiler.hs | 15 +- gibbon-compiler/src/Gibbon/L3/Typecheck.hs | 10 +- gibbon-compiler/src/Gibbon/Language/Syntax.hs | 2 +- .../src/Gibbon/Passes/AddCastInstructions.hs | 2 +- .../src/Gibbon/Passes/Cursorize.hs | 352 +++++++++++++----- 7 files changed, 287 insertions(+), 107 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 34671d4ff..335f32fdb 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -4,12 +4,13 @@ module MonoTree where data Tree = Leaf Int | Node Int Tree Tree deriving Show +{-# ANN type Tree "Factored" #-} -mkTree :: Int -> Tree -mkTree d = +mkTree :: Int -> Int -> Tree +mkTree d acc = if d == 0 - then Leaf 1 - else Node d (mkTree (d-1)) (mkTree (d-1)) + then Leaf (acc) + else Node d (mkTree (d-1) (d+acc)) (mkTree (d-1) (d+acc)) add1Tree :: Tree -> Tree add1Tree t = @@ -28,7 +29,7 @@ sumTree tr = Leaf n -> n Node d l r -> d + (sumTree l) + (sumTree r) -gibbon_main = rightMost (mkTree 18) --sumTree (add1Tree (mkTree 18)) +gibbon_main = rightMost (mkTree 18 0) --sumTree (add1Tree (mkTree 18)) main :: IO () main = print gibbon_main diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index c46530f0e..fe4abca31 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -3,7 +3,7 @@ module Tree where data Tree = Leaf Int Float | Node Int Int Int Float Tree Tree Tree Tree deriving Show -{-# ANN type Tree "Factored" #-} +--{-# ANN type Tree "Factored" #-} mkTree :: Int -> Tree mkTree d = diff --git a/gibbon-compiler/src/Gibbon/Compiler.hs b/gibbon-compiler/src/Gibbon/Compiler.hs index 37fb93373..b980dd4a4 100644 --- a/gibbon-compiler/src/Gibbon/Compiler.hs +++ b/gibbon-compiler/src/Gibbon/Compiler.hs @@ -706,7 +706,7 @@ passes config@Config{dynflags} l0 = do --l2 <- go "L2.typecheck" L2.tcProg l2 --l2 <- go "L2.typecheck" L2.tcProg l2 - l2 <- goE2 "reorderLetExprs" reorderLetExprs l2 + l2 <- goE2 "reorderLetExprs1" reorderLetExprs l2 l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- go "fixRANs" fixRANs l2 l2 <- goE2 "reorderLetExprs2" reorderLetExprs l2 @@ -765,16 +765,17 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. -- l1 <- goE1 "copyOutOfOrderPacked" copyOutOfOrderPacked l1 -- l1 <- go "L1.typecheck" L1.tcProg l1 l2 <- go "inferLocations2" inferLocs l1 - l2 <- goE2 "reorderLetExprs3" reorderLetExprs l2 + l2 <- go "regionsInwards2" regionsInwards l2 l2 <- go "simplifyLocBinds" (simplifyLocBinds True) l2 + l2 <- goE2 "reorderLetExprs3" reorderLetExprs l2 l2 <- go "fixRANs" fixRANs l2 --l2 <- go "L2.typecheck" L2.tcProg l2 - l2 <- go "regionsInwards" regionsInwards l2 - l2 <- go "simplifyLocBinds" (simplifyLocBinds True) l2 - l2 <- goE2 "+" reorderLetExprs l2 + --l2 <- go "regionsInwards" regionsInwards l2 + --l2 <- go "simplifyLocBinds" (simplifyLocBinds True) l2 + l2 <- goE2 "reorderLetExprs4" reorderLetExprs l2 --l2 <- go "L2.typecheck" L2.tcProg l2 -- VS : This pass is causing a bug - --l2 <- go "L2.flatten" flattenL2 l2 + l2 <- go "L2.flatten" flattenL2 l2 l2 <- go "findWitnesses" findWitnesses l2 -- l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "L2.flatten" flattenL2 l2 @@ -815,7 +816,7 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. l2 <- goE2 "routeEnds" routeEnds l2 l2 <- goE2 "L2.flatten" flattenL2 l2 l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 - l2 <- goE2 "reorderLetExprs4" reorderLetExprs l2 + l2 <- goE2 "reorderLetExprs5" reorderLetExprs l2 --l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- go "inferFunAllocs" inferFunAllocs l2 --l2 <- go "L2.typecheck" L2.tcProg l2 diff --git a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs index 677495763..5a5cc512f 100644 --- a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs @@ -54,13 +54,15 @@ tcExp isSoA isPacked ddfs env exp = do vty <- lookupVar env v exp ensureEqualTyModCursor isSoA exp vty CursorTy return CursorTy - + + -- VS: the semantics of Tag cursor have changed. TagCursor a b -> do aty <- lookupVar env a exp - ensureEqualTyModCursor isSoA exp aty CursorTy + --ensureEqualTyModCursor isSoA exp aty CursorTy bty <- lookupVar env b exp - ensureEqualTyModCursor isSoA exp bty CursorTy - return CursorTy + --ensureEqualTyModCursor isSoA exp bty CursorTy + ensureEqualTyModCursor isSoA exp aty bty + return aty ReadTaggedCursor v -> do vty <- lookupVar env v exp diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 488f13bfc..febc034a2 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -360,7 +360,7 @@ extendsVEnvLocVar mp (Env2 ve fe) = Env2 (M.union mp ve) fe lookupVEnv :: (HasCallStack, Out a) => Var -> Env2 Var a -> a lookupVEnv v env2 = (vEnv env2) # v -lookupVEnvLocVar :: Out a => FreeVarsTy -> Env2 FreeVarsTy a -> a +lookupVEnvLocVar :: (HasCallStack, Out a) => FreeVarsTy -> Env2 FreeVarsTy a -> a lookupVEnvLocVar v env2 = (vEnv env2) # v mblookupVEnv :: Var -> Env2 Var a -> Maybe a diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index 743a16267..6a55508b7 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -234,7 +234,7 @@ addCastsExp fundef cenv env ex = else do let new_arg = case (M.lookup arg cenv) of Just v' -> VarE v' - Nothing -> error "TODO : Cast not found in env!!" + Nothing -> error $ "TODO : Cast not found in env!!" ++ show arg return $ (l, args' ++ [new_arg]) _ -> return $ (l, args' ++ [fst zipped]) ) ([], []) args_zip_ty diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index e019f56af..b7647687b 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -769,7 +769,18 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Single l -> l SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - return $ Ext $ L3.TagCursor a_var b_var + tag_cur_var <- gensym "tag_cur" + casted_var <- gensym "cast" + let ty3_of_field = case (toLocVar a) of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field2 :: Ty3 = case (toLocVar a) of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) + let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) + let let_bnd = mkLets $ [tag_inst] ++ [cast_inst] + return $ let_bnd (VarE casted_var) -- All locations are transformed into cursors here. Location arithmetic -- is expressed in terms of corresponding cursor operations. @@ -1494,10 +1505,18 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let rnd_var = case rnd' of VarE v -> v _ -> error "Did not expected variable!" - LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) - <$> LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) - <$> LetE (after_indirection, [], CursorTy, VarE d') - <$> go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + if isIndirectionTag dcon + then do + LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> + LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) + <$> LetE (after_indirection, [], CursorTy, VarE d') + <$> go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + else do + LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') + <$> LetE (after_indirection, [], CursorTy, VarE d') + <$> go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + + _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty writetag <- gensym "writetag" @@ -1688,8 +1707,18 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Nothing -> case (toLocVar b) of Single l -> l SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - - return $ dl $ Ext $ L3.TagCursor a_var b_var + tag_cur_var <- gensym "tag_cur" + casted_var <- gensym "cast" + let ty3_of_field = case (toLocVar a) of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field2 :: Ty3 = case (toLocVar a) of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) + let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) + let let_bnd = mkLets $ [tag_inst] ++ [cast_inst] + return $ dl $ let_bnd (VarE casted_var) -- ASSUMPTION: RetE forms are inserted at the tail position of functions, -- and we safely just return ends-witnesses & ends of the dilated expressions @@ -3453,10 +3482,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack case (vlocs, tys) of ([], []) -> processRhs denv tenv ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> - let loc = toLocVar locarg - locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" + let loc = fromLocArgToFreeVarsTy locarg in case ty of -- The random access pointer -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. @@ -3479,6 +3505,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack CursorTy -> do tmp <- gensym "readcursor_shortcut" + locs_var <- lookupVariable loc fenv let tenv' = M.union ( M.fromList @@ -3505,6 +3532,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- Int, Sym, or Bool _ | isScalarTy ty -> do + locs_var <- lookupVariable loc fenv (tenv', binds) <- scalarBinds ty v locs_var tenv let loc_bind = case M.lookup v indirections_env of Nothing -> @@ -3516,7 +3544,9 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv'' return $ mkLets binds' bod + VectorTy el_ty -> do + locs_var <- lookupVariable loc fenv tmp <- gensym "read_vec_tuple" let tenv' = M.union @@ -3542,7 +3572,9 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv'' return $ mkLets binds' bod + ListTy el_ty -> do + locs_var <- lookupVariable loc fenv tmp <- gensym "read_list_tuple" let tenv' = M.union @@ -3568,7 +3600,9 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv'' return $ mkLets binds' bod + PackedTy {} -> do + locs_var <- lookupVariable loc fenv let tenv' = M.union ( M.fromList @@ -3586,16 +3620,15 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (locs_var, [], CursorTy, VarE ind_var) bod <- go (AoSWin (toEndV v)) fenv rst_vlocs rst_tys indirections_env denv tenv' return $ mkLets [loc_bind, (v, [], CursorTy, VarE locs_var)] bod + _ -> error $ "unpackWitnAbsRAN: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + _ -> error $ "unpackWitnAbsRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) SoAWin dcur_end _field_cur -> do case (vlocs, tys) of ([], []) -> processRhs denv tenv ((v, locarg) : rst_vlocs, (MkTy2 ty) : rst_tys) -> - let loc = toLocVar locarg - locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of - Just v' -> v' - Nothing -> error "cursorizeLet: unexpected location variable" + let loc = fromLocArgToFreeVarsTy locarg in case ty of -- The random access pointer -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. @@ -3618,6 +3651,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack CursorTy -> do tmp <- gensym "readcursor_shortcut" + locs_var <- lookupVariable loc fenv let tenv' = M.union ( M.fromList @@ -3645,16 +3679,21 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- Int, Sym, or Bool _ | isScalarTy ty -> do + locs_var <- lookupVariable loc fenv (tenv', binds) <- scalarBinds ty v locs_var tenv + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + let field_cur' = map (\(k@(d, idx), var) -> if (d, idx) == (dcon, field_idx) then (k, (toEndV v)) else (k, var)) _field_cur + let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur let loc_bind = case M.lookup v indirections_env of + -- cannot follow indirection, field Nothing -> - (locs_var, [], CursorTy, VarE dcur_end) + (locs_var, [], CursorTy, VarE cur) -- Read this using a random access node Just (_var_loc, ind_var) -> (locs_var, [], CursorTy, VarE ind_var) binds' = loc_bind : binds tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' + bod <- go (SoAWin dcur_end field_cur') fenv rst_vlocs rst_tys indirections_env denv tenv'' return $ mkLets binds' bod -- _ | isScalarTy ty -> do @@ -3681,78 +3720,215 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack + -- VS: TODO, needs to change for SOA + -- VectorTy el_ty -> do + -- tmp <- gensym "read_vec_tuple" + -- let tenv' = + -- M.union + -- ( M.fromList + -- [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + -- (v, MkTy2 (VectorTy el_ty)), + -- (toEndV v, MkTy2 CursorTy) + -- ] + -- ) + -- tenv + -- ty' = stripTyLocs ty + -- binds = + -- [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadVector locs_var (stripTyLocs el_ty)), + -- (v, [], ty', ProjE 0 (VarE tmp)), + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + -- ] + -- loc_bind = case M.lookup v indirections_env of + -- Nothing -> + -- (locs_var, [], CursorTy, VarE dcur_end) + -- Just (_var_loc, ind_var) -> + -- (locs_var, [], CursorTy, VarE ind_var) + -- binds' = loc_bind : binds + -- tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + -- bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' + -- return $ mkLets binds' bod + + -- ListTy el_ty -> do + -- tmp <- gensym "read_list_tuple" + -- let tenv' = + -- M.union + -- ( M.fromList + -- [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), + -- (v, MkTy2 (ListTy el_ty)), + -- (toEndV v, MkTy2 CursorTy) + -- ] + -- ) + -- tenv + -- ty' = stripTyLocs ty + -- binds = + -- [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadList locs_var (stripTyLocs el_ty)), + -- (v, [], ty', ProjE 0 (VarE tmp)), + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) + -- ] + -- loc_bind = case M.lookup v indirections_env of + -- Nothing -> + -- (locs_var, [], CursorTy, VarE dcur_end) + -- Just (_var_loc, ind_var) -> + -- (locs_var, [], CursorTy, VarE ind_var) + -- binds' = loc_bind : binds + -- tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' + -- bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' + -- return $ mkLets binds' bod - VectorTy el_ty -> do - tmp <- gensym "read_vec_tuple" - let tenv' = - M.union - ( M.fromList - [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), - (v, MkTy2 (VectorTy el_ty)), - (toEndV v, MkTy2 CursorTy) - ] - ) - tenv - ty' = stripTyLocs ty - binds = - [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadVector locs_var (stripTyLocs el_ty)), - (v, [], ty', ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) - ] - loc_bind = case M.lookup v indirections_env of - Nothing -> - (locs_var, [], CursorTy, VarE dcur_end) - Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - binds' = loc_bind : binds - tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' - return $ mkLets binds' bod - ListTy el_ty -> do - tmp <- gensym "read_list_tuple" - let tenv' = - M.union - ( M.fromList - [ (tmp, MkTy2 (ProdTy [VectorTy el_ty, CursorTy])), - (v, MkTy2 (ListTy el_ty)), - (toEndV v, MkTy2 CursorTy) - ] - ) - tenv - ty' = stripTyLocs ty - binds = - [ (tmp, [], ProdTy [ty', CursorTy], Ext $ ReadList locs_var (stripTyLocs el_ty)), - (v, [], ty', ProjE 0 (VarE tmp)), - (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)) - ] - loc_bind = case M.lookup v indirections_env of - Nothing -> - (locs_var, [], CursorTy, VarE dcur_end) - Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - binds' = loc_bind : binds - tenv'' = M.insert locs_var (MkTy2 CursorTy) tenv' - bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv'' - return $ mkLets binds' bod - PackedTy {} -> do - let tenv' = - M.union - ( M.fromList - [ (locs_var, MkTy2 CursorTy), - (v, MkTy2 CursorTy) - ] - ) - tenv - loc_bind = case M.lookup v indirections_env of - -- This is the first packed value. We can unpack this. - Nothing -> - (locs_var, [], CursorTy, VarE dcur_end) - -- We need to access this using a random access node - Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv' - return $ mkLets [loc_bind, (v, [], CursorTy, VarE locs_var)] bod - _ -> error $ "unpackWitnAbsRAN: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty + + + PackedTy tycon ploc -> do + -- Two cases + -- If the packedty is the same tycon, ie, recursive. + -- otherwise if its not the same tycon but another packed field + let datacons = getConOrdering ddfs tycon + let isSameTycon = if (elem dcon datacons) then True else False + locs_var <- lookupVariable loc fenv + case isSameTycon of + -- recursive part + -- availabe in data con buffer + -- we could also take ran pointer to it + True -> do + let ty3_of_field = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field2 :: Ty3 = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + + let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + let cur = dcur_end + let tenv' = + M.union + ( M.fromList + [ (locs_var, MkTy2 ty3_of_field), + (v, MkTy2 ty3_of_field) + ] + ) + tenv + + case M.lookup v indirections_env of + -- This is the first packed value. We can unpack this. + Nothing -> do + dcon_next <- gensym $ toVar $ (fromVar dcur_end) ++ "_next" + let end_fields = map (\(key, varr) -> varr) _field_cur + let makeCurArr = Ext $ MakeCursorArray (1 + length (end_fields)) ([dcon_next] ++ end_fields) + let let_mk_cur_arr = (locs_var, [], CursorArrayTy (1 + length (end_fields)), makeCurArr) + let dcon_nxt = [(dcon_next, [], CursorTy, VarE dcur_end)] ++ [let_mk_cur_arr, (v, [], CursorArrayTy (1 + length (end_fields)), VarE (locs_var))] + let curw' = SoAWin dcon_next _field_cur + bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets dcon_nxt bod + -- We need to access this using a random access node + Just (_var_loc, ind_var) -> do + dcon_next <- gensym $ toVar $ (fromVar dcur_end) ++ "_next" + let end_fields = map (\(key, varr) -> varr) _field_cur + let bnd = (locs_var, [], CursorArrayTy (1 + length (end_fields)), VarE ind_var) + let dcon_nxt = [(dcon_next, [], CursorTy, VarE dcur_end)] ++ [bnd, (v, [], CursorArrayTy (1 + length (end_fields)), VarE (locs_var))] + let curw' = SoAWin dcon_next _field_cur + bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets dcon_nxt bod + -- VS: TODO: needs to be fixed when packed type is not self recursive. + False -> do + let tenv' = + M.union + ( M.fromList + [ (locs_var, MkTy2 CursorTy), + (v, MkTy2 CursorTy) + ] + ) + tenv + loc_bind = case M.lookup v indirections_env of + -- This is the first packed value. We can unpack this. + Nothing -> + (locs_var, [], CursorTy, VarE dcur_end) + -- We need to access this using a random access node + Just (_var_loc, ind_var) -> + (locs_var, [], CursorTy, VarE ind_var) + bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets [loc_bind, (v, [], CursorTy, VarE locs_var)] bod + + + + -- PackedTy tycon ploc -> do + -- -- Two cases + -- -- If the PackedTy is the same tycon then + -- -- If the PackedTy is not the same tycon + -- let datacons = getConOrdering ddfs tycon + -- let isSameTycon = if (elem dcon datacons) then True else False + -- case isSameTycon of + -- True -> do + -- let ty3_of_field = case ploc of + -- Single _ -> CursorTy + -- SoA _ fl -> CursorArrayTy (1 + length fl) + -- let ty3_of_field2 :: Ty3 = case ploc of + -- Single _ -> CursorTy + -- SoA _ fl -> CursorArrayTy (1 + length fl) + + -- let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- -- let cur = fromJust $ L.lookup (dcon, field_idx) field_cur + -- let cur = dcur + -- loc_var <- lookupVariable loc fenv + -- if canBind + -- then do + -- let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' + -- -- Flip canBind to indicate that the subsequent fields + -- -- should be added to the dependency environment. + -- dcon_next <- gensym $ toVar $ (fromVar dcur) ++ "_next" + -- let end_fields = map (\(key, varr) -> varr) _field_cur + -- let makeCurArr = Ext $ MakeCursorArray (1 + length (end_fields)) ([dcon_next] ++ end_fields) + -- let let_mk_cur_arr = (loc_var, [], CursorArrayTy (1 + length (end_fields)), makeCurArr) + -- let dcon_nxt = [(dcon_next, [], CursorTy, Ext $ AddCursor dcur (LitE 1))] ++ [let_mk_cur_arr, (v, [], CursorArrayTy (1 + length (end_fields)), VarE (loc_var))] + -- -- make the new curw type + -- -- this consists of incrementing the data constructor buffer by one and all the rest of the fields + -- let curw' = SoAWin dcon_next _field_cur + -- bod <- go curw' fenv rst_vlocs rst_tys False denv tenv'' -- (toEndV v) + -- return $ mkLets dcon_nxt bod + -- else do + -- -- Cannot read this. Instead, we add it to DepEnv. + -- let denv' = M.insertWith (++) (loc) [(v, [], ty3_of_field2, VarE (loc_var))] denv + -- go curw fenv rst_vlocs rst_tys False denv' tenv' -- (toEndV v) + -- False -> do + -- let ty3_of_field = case ploc of + -- Single _ -> CursorTy + -- SoA _ fl -> CursorArrayTy (1 + length fl) + -- let ty3_of_field2 :: Ty3 = case ploc of + -- Single _ -> CursorTy + -- SoA _ fl -> CursorArrayTy (1 + length fl) + -- let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + -- -- let cur = dcur + -- loc_var <- lookupVariable loc fenv + -- if canBind + -- then do + -- let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' + -- -- Flip canBind to indicate that the subsequent fields + -- -- should be added to the dependency environment. + -- bod <- go curw fenv rst_vlocs rst_tys False denv tenv'' -- (toEndV v) + -- return $ + -- mkLets + -- [ ((loc_var), [], ty3_of_field2, VarE cur), + -- (v, [], ty3_of_field2, VarE (loc_var)) + -- ] + -- bod + -- else do + -- -- Cannot read this. Instead, we add it to DepEnv. + -- let denv' = dbgTrace (minChatLvl) "Printing in packedTy unpack dcon: " dbgTrace (minChatLvl) (sdoc (loc)) dbgTrace (minChatLvl) "End in unpacking dcon.\n" M.insertWith (++) (loc) [((loc_var), [], ty3_of_field2, VarE cur), (v, [], ty3_of_field2, VarE (loc_var))] denv + -- bod <- go curw fenv rst_vlocs rst_tys False denv' tenv' -- (toEndV v) + -- -- VS: [05.11.2025] This is a hack to ensure that the location variable is not undefined. + -- -- If we have serialized packed types that are not self recursive, we still have to release + -- -- The let binding and just adding it to the depenv is not enough. + -- -- There should be a careful look at why this is and if this is functionally correct. + -- return $ + -- mkLets + -- [((loc_var), [], ty3_of_field2, VarE cur), (v, [], ty3_of_field2, VarE (loc_var))] + -- bod + + + + _ -> error $ "unpackWitnAbsRAN: TODO: Unexpected field " ++ sdoc (v, loc) ++ ":" ++ sdoc ty _ -> error $ "unpackWitnAbsRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs, tys) -- We have access to all fields in this constructor, and can create From 04d4a846672f9c0d089e8427c468bece81455107 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 25 Sep 2025 20:45:18 -0400 Subject: [PATCH 24/60] add new func to test --- gibbon-compiler/examples/soa_examples/packedTree.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index cb324acad..34a7caafc 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -18,6 +18,13 @@ mkTree d = if (d <= 0) then Leaf else Node d 1.0 (mkFloatList d) (mkList d) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) + +rightMostTree :: Tree -> Int +rightMostTree tree = case tree of + Node a b c d e f g -> rightMostTree g + Leaf -> 0 + + add1List :: List -> List add1List lst = case lst of Nil -> Nil @@ -80,5 +87,6 @@ id tree = tree gibbon_main = let tree = mkTree 5 tree' = id (add1Tree tree) - in sumTree tree' + val = rightMostTree tree' + in val From 9e90b9e6dcf10031aab2b27dd8a6f5174ea2ff54 Mon Sep 17 00:00:00 2001 From: vidush Date: Sat, 27 Sep 2025 14:23:38 -0400 Subject: [PATCH 25/60] thread loc to var env in cursorize --- .../src/Gibbon/Passes/AddCastInstructions.hs | 14 +- .../src/Gibbon/Passes/Cursorize.hs | 681 +++++++++++------- 2 files changed, 423 insertions(+), 272 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index 6a55508b7..5d6c0d3e3 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -296,13 +296,13 @@ addCastsExp fundef cenv env ex = Nothing -> v pure (Ext $ WriteTag dcon nv) Ext (TagCursor a b) -> do - let na = case (M.lookup a cenv) of - Just v' -> v' - Nothing -> a - let nb = case (M.lookup b cenv) of - Just v' -> v' - Nothing -> b - pure (Ext $ TagCursor na nb) + -- let na = case (M.lookup a cenv) of + -- Just v' -> v' + -- Nothing -> a + -- let nb = case (M.lookup b cenv) of + -- Just v' -> v' + -- Nothing -> b + pure (Ext $ TagCursor a b) Ext (WriteTaggedCursor v e) -> do let nv = case (M.lookup v cenv) of Just v' -> v' diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index b7647687b..4404177a9 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -130,12 +130,16 @@ cursorize Prog {ddefs, fundefs, mainExp} = do Just (e, ty) -> do if hasPacked (unTy2 ty) then - Just . (,stripTyLocs (unTy2 ty)) - <$> fromDi - <$> cursorizePackedExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e + do + (e', _) <- cursorizePackedExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e + Just . (,stripTyLocs (unTy2 ty)) + <$> fromDi + <$> return e' else + do + (e', _) <- cursorizeExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e Just . (,stripTyLocs (unTy2 ty)) - <$> cursorizeExp M.empty M.empty ddefs fundefs M.empty M.empty M.empty e + <$> return e' pure (Prog ddefs' fundefs' mainExp') mangle :: [Var] -> Var @@ -289,8 +293,14 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f bod <- if hasPacked (unTy2 out_ty) - then fromDi <$> cursorizePackedExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody - else cursorizeExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody + then + do + (funBody', _) <- cursorizePackedExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody + return $ fromDi funBody' + else do + (funBody', _) <- cursorizeExp freeVarToVarEnv' initTyEnvl ddefs fundefs M.empty initTyEnv M.empty funBody + return funBody' + let bod' = inCurBinds bod fn = FunDef funName funargs funTy' bod' funMeta dbgTrace (minChatLvl) "Print in cursorizeFunDef: " dbgTrace (minChatLvl) (sdoc (initTyEnv, locVars funTy)) dbgTrace (minChatLvl) "End cursorizeFunDef\n" return fn @@ -441,14 +451,14 @@ cursorizeExp :: TyEnv Var Ty2 -> SyncEnv -> Exp2 -> - PassM Exp3 + PassM (Exp3, M.Map FreeVarsTy Var) cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case ex of - VarE v -> return $ VarE v - LitE n -> return $ LitE n - CharE c -> return $ CharE c - FloatE n -> return $ FloatE n - LitSymE n -> return $ LitSymE n + VarE v -> return $ (VarE v, freeVarToVarEnv) + LitE n -> return $ (LitE n, freeVarToVarEnv) + CharE c -> return $ (CharE c, freeVarToVarEnv) + FloatE n -> return $ (FloatE n, freeVarToVarEnv) + LitSymE n -> return $ (LitSymE n, freeVarToVarEnv) AppE {} -> cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex PrimAppE RequestSizeOf [arg] -> do let (VarE v) = arg @@ -456,9 +466,15 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Nothing -> error $ "cursorizeExp: Unbound variable: " ++ sdoc v Just ty -> if isPackedTy (unTy2 ty) - then pure $ Ext $ SubPtr (toEndV v) v - else pure $ LitE $ fromJust $ sizeOfTy (unTy2 ty) - PrimAppE pr args -> PrimAppE (toL3Prim pr) <$> mapM go args + then pure $ (Ext $ SubPtr (toEndV v) v, freeVarToVarEnv) + else pure $ (LitE $ fromJust $ sizeOfTy (unTy2 ty), freeVarToVarEnv) + PrimAppE pr args -> do + res <- mapM go args + let args' = map fst res + let freeEnvs = map snd res + let freeVarToVarEnv' = M.unions freeEnvs + ret_expr <- return $ PrimAppE (toL3Prim pr) args' + return (ret_expr, freeVarToVarEnv') LetE (v, _locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> do freeVarToVarEnv' <- foldrM @@ -487,7 +503,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - cursorizeReadPackedFile freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod + (ret_e, freeVarToVarEnv'') <- cursorizeReadPackedFile freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod + return (ret_e, freeVarToVarEnv'') LetE (_v, _locs, _ty, (MkProdE _ls)) _bod -> do freeVarToVarEnv' <- foldrM @@ -516,7 +533,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - cursorizeProd freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + (ret_prod, freeVarToVarEnv'') <- cursorizeProd freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + return $ (ret_prod, M.union freeVarToVarEnv' freeVarToVarEnv'') LetE (_v, _locs, ty, ProjE {}) _bod | isPackedTy (unTy2 ty) -> do freeVarToVarEnv' <- foldrM @@ -545,7 +563,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - cursorizeProj freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + (ret_e, freeVarToVarEnv'') <- cursorizeProj freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + return $ (ret_e, M.union freeVarToVarEnv' freeVarToVarEnv'') LetE (_v, _locs, _ty, SpawnE {}) _bod -> do freeVarToVarEnv' <- foldrM @@ -574,7 +593,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - cursorizeSpawn freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + (ret_e, freeVarToVarEnv'') <- cursorizeSpawn freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + return (ret_e, M.union freeVarToVarEnv' freeVarToVarEnv'') LetE (_v, _locs, _ty, SyncE) _bod -> do freeVarToVarEnv' <- foldrM @@ -603,23 +623,24 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - cursorizeSync freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + (ret_e, freeVarToVarEnv'') <- cursorizeSync freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv ex + return $ (ret_e, M.union freeVarToVarEnv' freeVarToVarEnv'') LetE (v, _locs, ty, rhs@(Ext (SSPush _ start _ _))) bod -> do case M.lookup (unwrapLocVar start) tenv of Nothing -> go bod Just {} -> do - rhs' <- go rhs - bod' <- go bod + (rhs', fenv1) <- go rhs + (bod', fenv2) <- go bod let ty' = cursorizeTy (unTy2 ty) - return $ LetE (v, [], ty', rhs') bod' + return $ (LetE (v, [], ty', rhs') bod', M.union fenv1 fenv2) LetE (v, _locs, ty, rhs@(Ext (SSPop _ start _))) bod -> case M.lookup (unwrapLocVar start) tenv of Nothing -> go bod Just {} -> do - rhs' <- go rhs - bod' <- go bod + (rhs', fenv1) <- go rhs + (bod', fenv2) <- go bod let ty' = cursorizeTy (unTy2 ty) - return $ LetE (v, [], ty', rhs') bod' + return $ (LetE (v, [], ty', rhs') bod', M.union fenv1 fenv2) -- LetE bnd@(v, _locs, ty, rhs) bod -> case rhs of -- Ext (BoundsCheck i bound cur) -> do @@ -668,10 +689,21 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - cursorizeLet freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv bnd bod - IfE a b c -> IfE <$> go a <*> go b <*> go c - MkProdE ls -> MkProdE <$> mapM go ls - ProjE i e -> ProjE i <$> go e + (ret_e, freeVarToVarEnv'') <- cursorizeLet freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv bnd bod + return $ (ret_e, freeVarToVarEnv'') + IfE a b c -> do + (a', e1) <- go a + (b', e2) <- go b + (c', e3) <- go c + return (IfE a' b' c', M.unions [e1, e2, e3]) + MkProdE ls -> do + res <- mapM go ls + let ls' = map fst res + let envs = map snd res + return $ (MkProdE ls', M.unions envs) + ProjE i e -> do + (e', env) <- go e + return (ProjE i e', env) -- Eg. leftmost CaseE scrt brs -> do -- ASSUMPTION: scrt is flat @@ -708,41 +740,53 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray v 0)] let dcon_let_bind = mkLets dcon_let case ty_of_scrut of - CursorTy -> - CaseE (VarE $ v) + CursorTy -> do + case_expr <- + CaseE (VarE $ v) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - CursorArrayTy {} -> - dcon_let_bind + return (case_expr, freeVarToVarEnv) + CursorArrayTy {} -> do + case_expr <- dcon_let_bind <$> CaseE (VarE $ dcon_var) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + return (case_expr, freeVarToVarEnv') PackedTy _ scrutLoc -> case scrutLoc of - Single _ -> - CaseE (VarE $ v) - <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - SoA _ _ -> - dcon_let_bind + Single _ -> do + case_expr <- CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + return (case_expr, freeVarToVarEnv') + + SoA _ _ -> do + case_expr <- dcon_let_bind <$> CaseE (VarE $ dcon_var) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs - _ -> - CaseE (VarE $ v) + return (case_expr, freeVarToVarEnv') + + _ -> do + case_expr <- CaseE (VarE $ v) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv False v) brs + return (case_expr, freeVarToVarEnv') + DataConE _ _ _ -> error $ "cursorizeExp: Should not have encountered DataConE if type is not packed: " ++ ndoc ex - TimeIt e ty b -> TimeIt <$> go e <*> pure (stripTyLocs (unTy2 ty)) <*> pure b + TimeIt e ty b -> do + (e', env) <- go e + return (TimeIt e' (stripTyLocs (unTy2 ty)) b, env) + WithArenaE v e -> do - e' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv (M.insert v (MkTy2 ArenaTy) tenv) senv e - return $ WithArenaE v e' + (e', env) <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv (M.insert v (MkTy2 ArenaTy) tenv) senv e + return $ (WithArenaE v e', env) SpawnE {} -> error "cursorizeExp: Unbound SpawnE" SyncE {} -> error "cursorizeExp: Unbound SyncE" -- Eg. leftmost Ext ext -> case ext of - AddFixed v i -> return $ Ext $ L3.AddCursor v (L3.LitE i) + AddFixed v i -> return $ (Ext $ L3.AddCursor v (L3.LitE i), freeVarToVarEnv) RetE locs v -> case locs of - [] -> return (VarE v) + [] -> return (VarE v, freeVarToVarEnv) _ -> - return $ - L3.MkProdE $ + return + (L3.MkProdE $ ( map ( \loc -> let loc_to_free_var = fromLocArgToFreeVarsTy loc @@ -755,19 +799,19 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) locs ) - ++ [VarE v] - StartOfPkdCursor cur -> return (VarE cur) + ++ [VarE v] , freeVarToVarEnv) + StartOfPkdCursor cur -> return (VarE cur, freeVarToVarEnv) TagCursor a b -> do let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of Just v -> v Nothing -> case (toLocVar a) of Single l -> l SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - let b_var = case (M.lookup (fromRegVarToFreeVarsTy ((fromLocVarToRegVar . toLocVar) b)) freeVarToVarEnv) of - Just v -> v + b_var <- case (M.lookup (fromRegVarToFreeVarsTy ((fromLocVarToRegVar . toLocVar) b)) freeVarToVarEnv) of + Just v -> return v Nothing -> case (toLocVar b) of - Single l -> l - SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" + Single l -> return l + SoA _ _ -> error $ "cursorizeExp: LetLocE: unexpected location variable " ++ show ((fromLocVarToRegVar . toLocVar) b) tag_cur_var <- gensym "tag_cur" casted_var <- gensym "cast" @@ -780,7 +824,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) let let_bnd = mkLets $ [tag_inst] ++ [cast_inst] - return $ let_bnd (VarE casted_var) + return (let_bnd (VarE casted_var), freeVarToVarEnv) -- All locations are transformed into cursors here. Location arithmetic -- is expressed in terms of corresponding cursor operations. @@ -842,12 +886,13 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = then cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod -- Discharge bindings that were waiting on 'loc'. else - mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) - <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod + do + (bod, env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod + return (mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) bod, env) -- Discharge bindings that were waiting on 'loc'. - _ -> - mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) - <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv bod + _ -> do + (bod, env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv bod + return (mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) bod, env) Left denv' -> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod -- Exactly same as cursorizePackedExp @@ -882,10 +927,12 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let tenv' = M.insert reg_var_name reg_ty tenv let tenv'' = M.insert reg_var_name_end reg_ty tenv' - mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv''' lenv ddfs fundefs denv tenv'' senv bod + (bod, freeVarToVarEnv'''') <- cursorizeExp freeVarToVarEnv''' lenv ddfs fundefs denv tenv'' senv bod + return (mkLets (region_lets) bod, freeVarToVarEnv'''') LetParRegionE reg sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv True reg sz - mkLets (region_lets) <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv bod + (bod, freeVarToVarEnv'') <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv bod + return (mkLets (region_lets) bod, freeVarToVarEnv'') {- VS: TODO: variables are not in env-} {- TODO: End of reg needs fixing is broken -} @@ -916,7 +963,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- else do -- let denv' = M.insertWith (++) (cur_loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv -- return $ Ext $ L3.BoundsCheck i bound_var cur_var --Left$ M.insertWith (++) ((toLocVar) loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv - return exp' + return (exp', freeVarToVarEnv) Gibbon.NewL2.Syntax.BoundsCheckVector bounds -> do (bounds', lets) <- foldrM @@ -948,23 +995,25 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ([], []) bounds exp' <- return $ mkLets lets <$> Ext $ L3.BoundsCheckVector bounds' - return exp' + return (exp', freeVarToVarEnv) FromEndE {} -> error $ "cursorizeExp: TODO FromEndE" ++ sdoc ext IndirectionE {} -> error $ "cursorizeExp: Unexpected IndirectionE" - GetCilkWorkerNum -> return $ Ext $ L3.GetCilkWorkerNum - LetAvail vs bod -> Ext <$> L3.LetAvail vs <$> go bod + GetCilkWorkerNum -> return (Ext $ L3.GetCilkWorkerNum, freeVarToVarEnv) + LetAvail vs bod -> do + (bod', env) <- go bod + return (Ext $ L3.LetAvail vs bod', env) AllocateTagHere v tycon -> do let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of Just v -> v Nothing -> error "cursorizeExp: AllocateTagHere: unexpected location variable" - pure $ Ext $ L3.AllocateTagHere (variable_name) tycon + pure (Ext $ L3.AllocateTagHere (variable_name) tycon, freeVarToVarEnv) AllocateScalarsHere v -> do let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of Just v -> v Nothing -> error "cursorizeExp: AllocateTagHere: unexpected location variable" - pure $ Ext $ L3.AllocateScalarsHere (variable_name) - SSPush a b c d -> pure $ Ext $ L3.SSPush a (unwrapLocVar b) (unwrapLocVar c) d - SSPop a b c -> pure $ Ext $ L3.SSPop a (unwrapLocVar b) (unwrapLocVar c) + pure (Ext $ L3.AllocateScalarsHere (variable_name), freeVarToVarEnv) + SSPush a b c d -> pure (Ext $ L3.SSPush a (unwrapLocVar b) (unwrapLocVar c) d, freeVarToVarEnv) + SSPop a b c -> pure (Ext $ L3.SSPop a (unwrapLocVar b) (unwrapLocVar c), freeVarToVarEnv) {-VS: TODO: This needs to be fixed to produce the correct L3 expression. See above. -} {- Right now i just skip the let region, just recurse on the body-} LetRegE loc rhs bod -> do @@ -1015,16 +1064,16 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case rhs of -- Discharge bindings that were waiting on 'loc'. _ -> case ty_of_loc of - MutCursorTy -> - mkLets (bnds' ++ [(locs_var, [], ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds) - <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - _ -> - mkLets (bnds' ++ [(locs_var, [], ty_of_loc, rhs')] ++ bnds) - <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + MutCursorTy -> do + (bod', env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + return (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds) bod', env) + _ -> do + (bod', env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + return (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, rhs')] ++ bnds) bod', env) -- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod - Left denv' -> - (mkLets bnds) - <$> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + Left denv' -> do + (bod', env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + return ((mkLets bnds) bod', env) -- case reg_var of -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod @@ -1073,7 +1122,7 @@ cursorizePackedExp :: TyEnv Var Ty2 -> SyncEnv -> Exp2 -> - PassM (DiExp Exp3) + PassM (DiExp Exp3, M.Map FreeVarsTy Var) cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case ex of -- Here the allocation has already been performed: @@ -1084,13 +1133,15 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Just t -> t Nothing -> error $ sdoc v ++ " not found." if isPackedTy (unTy2 ty) - then return $ mkDi (VarE v) [VarE (toEndV v)] - else return $ dl $ VarE v + then return (mkDi (VarE v) [VarE (toEndV v)], freeVarToVarEnv) + else return (dl $ VarE v, freeVarToVarEnv) LitE _n -> error $ "Shouldn't encounter LitE in packed context:" ++ sdoc ex CharE _n -> error $ "Shouldn't encounter CharE in packed context:" ++ sdoc ex FloatE {} -> error $ "Shouldn't encounter FloatE in packed context:" ++ sdoc ex LitSymE _n -> error $ "Shouldn't encounter LitSymE in packed context:" ++ sdoc ex - AppE {} -> dl <$> cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex + AppE {} -> do + (ex', freeVarToVarEnv') <- cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex + return (dl ex', freeVarToVarEnv') -- DictLookup returns a packed value bound to a free location. -- PrimAppE (DictLookupP (PackedTy _ ploc)) vs -> -- do vs' <- forM vs $ \v -> cursorizeExp ddfs fundefs denv tenv v @@ -1101,54 +1152,70 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- This is simpler than TimeIt below. While it's out-of-line, -- it doesn't need memory allocation (NewBuffer/ScopedBuffer). -- This is more like the witness case below. - LetE (v, _locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> - Di <$> cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod + LetE (v, _locs, _ty, (PrimAppE (ReadPackedFile path tyc reg ty2) [])) bod -> do + (bod', freeVarToVarEnv') <- cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod + return (Di bod', freeVarToVarEnv') LetE (v, _locs, _ty, (PrimAppE (DictLookupP (MkTy2 (PackedTy _ ploc))) vs)) bod -> do vs' <- forM vs $ \w -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv w + let vs'' = map (\(a, _) -> a) vs' + let envs' = map (\(_, b) -> b) vs' let bnd = mkLets - [ ((unwrapLocVar ploc), [], CursorTy, (PrimAppE (DictLookupP CursorTy) vs')), + [ ((unwrapLocVar ploc), [], CursorTy, (PrimAppE (DictLookupP CursorTy) vs'')), (v, [], CursorTy, VarE (unwrapLocVar ploc)) ] tenv' = M.insert (unwrapLocVar ploc) (MkTy2 CursorTy) $ M.insert v (MkTy2 CursorTy) tenv - onDi bnd <$> go freeVarToVarEnv tenv' senv bod - LetE (_v, _locs, _ty, (MkProdE _ls)) _bod -> - dl <$> cursorizeProd freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + (bod', freeVarToVarEnv') <- go freeVarToVarEnv tenv' senv bod + return (onDi bnd bod', M.unions $ [freeVarToVarEnv'] ++ envs') + + LetE (_v, _locs, _ty, (MkProdE _ls)) _bod -> do + (ex', freeVarToVarEnv') <- cursorizeProd freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + return (dl ex', freeVarToVarEnv') LetE (_v, _locs, ty, ProjE {}) _bod - | isPackedTy (unTy2 ty) -> - dl <$> cursorizeProj freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + | isPackedTy (unTy2 ty) -> do + (ex', freeVarToVarEnv') <- cursorizeProj freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + return (dl ex', freeVarToVarEnv') MkProdE ls -> do let tys = L.map (gRecoverType ddfs (Env2 tenv M.empty)) ls - es <- forM (zip tys ls) $ \(ty, e) -> do - case ty of - _ | isPackedTy (unTy2 ty) -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e - _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + res <- + forM (zip tys ls) $ \(ty, e) -> do + case ty of + _ | isPackedTy (unTy2 ty) -> do + (e', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + return (fromDi e', freeVarToVarEnv') + _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + let es = map (\(a, _) -> a) res + let envs = map (\(_, b) -> b) res let rhs' = MkProdE es - return $ Di rhs' + return (Di rhs', M.unions envs) -- Not sure if we need to replicate all the checks from Cursorize1 - ProjE i e -> dl <$> ProjE i <$> fromDi <$> go freeVarToVarEnv tenv senv e - LetE (_v, _locs, _ty, SpawnE {}) _bod -> - dl <$> cursorizeSpawn freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex - LetE (_v, _locs, _ty, SyncE) _bod -> - dl <$> cursorizeSync freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + ProjE i e -> do + (e', env) <- go freeVarToVarEnv tenv senv e + return (dl $ ProjE i (fromDi e'), env) + LetE (_v, _locs, _ty, SpawnE {}) _bod -> do + (ex', freeVarToVarEnv') <- cursorizeSpawn freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + return (dl ex', freeVarToVarEnv') + LetE (_v, _locs, _ty, SyncE) _bod -> do + (ex', freeVarToVarEnv') <- cursorizeSync freeVarToVarEnv lenv True ddfs fundefs denv tenv senv ex + return (dl ex', freeVarToVarEnv') LetE (v, _locs, ty, rhs@(Ext (SSPush _ start _ _))) bod -> case M.lookup (unwrapLocVar start) tenv of Nothing -> go freeVarToVarEnv tenv senv bod Just {} -> do - rhs' <- go freeVarToVarEnv tenv senv rhs + (rhs', env1) <- go freeVarToVarEnv tenv senv rhs let ty' = cursorizeTy (unTy2 ty) - bod' <- go freeVarToVarEnv (M.insert v ty tenv) senv bod - return $ Di (LetE (v, [], ty', fromDi rhs') (fromDi bod')) + (bod', env2) <- go freeVarToVarEnv (M.insert v ty tenv) senv bod + return (Di (LetE (v, [], ty', fromDi rhs') (fromDi bod')), M.union env1 env2) LetE (v, _locs, ty, rhs@(Ext (SSPop _ start _))) bod -> case M.lookup (unwrapLocVar start) tenv of Nothing -> go freeVarToVarEnv tenv senv bod Just {} -> do - rhs' <- go freeVarToVarEnv tenv senv rhs + (rhs', env1) <- go freeVarToVarEnv tenv senv rhs let ty' = cursorizeTy (unTy2 ty) - bod' <- go freeVarToVarEnv (M.insert v ty tenv) senv bod - return $ Di (LetE (v, [], ty', fromDi rhs') (fromDi bod')) + (bod', env2) <- go freeVarToVarEnv (M.insert v ty tenv) senv bod + return (Di (LetE (v, [], ty', fromDi rhs') (fromDi bod')), M.union env1 env2) LetE bnd@(_, _locs, _, _) bod -> do freeVarToVarEnv' <- foldrM @@ -1177,15 +1244,16 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) freeVarToVarEnv _locs - dl <$> cursorizeLet freeVarToVarEnv' lenv True ddfs fundefs denv tenv senv bnd bod + (bod', freeVarToVarEnv'') <- cursorizeLet freeVarToVarEnv' lenv True ddfs fundefs denv tenv senv bnd bod + return (dl bod', freeVarToVarEnv'') -- Here we route the dest cursor to both braches. We switch -- back to the other mode for the (non-packed) test condition. IfE a b c -> do - Di b' <- go freeVarToVarEnv tenv senv b - Di c' <- go freeVarToVarEnv tenv senv c - a' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv a - return $ Di $ IfE a' b' c' + (Di b', env1) <- go freeVarToVarEnv tenv senv b + (Di c', env2) <- go freeVarToVarEnv tenv senv c + (a', env3) <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv a + return (Di $ IfE a' b' c', M.unions [env1, env2, env3]) -- A case expression is eventually transformed into a ReadTag + switch stmt. -- We first retrieve the cursor referred to by the scrutinee, and unpack @@ -1227,29 +1295,35 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let dcon_let = [(dcon_var, [], CursorTy, Ext $ IndexCursorArray v 0)] let dcon_let_bind = mkLets dcon_let case ty_of_scrut of - CursorTy -> - dl - <$> CaseE (VarE $ v) - <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs - CursorArrayTy {} -> - dl + CursorTy -> (,) <$> (dl <$> CaseE (VarE $ v)) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + <*> return freeVarToVarEnv + + CursorArrayTy {} -> (,) <$> dl <$> dcon_let_bind <$> CaseE (VarE $ dcon_var) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + <*> return freeVarToVarEnv + PackedTy _ scrutLoc -> case scrutLoc of - Single _ -> - dl - <$> CaseE (VarE $ v) - <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + Single _ -> (,) <$> dl + <$> CaseE (VarE $ v) + <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + <*> return freeVarToVarEnv + SoA _ _ -> - dl + (,) <$> dl <$> dcon_let_bind <$> CaseE (VarE $ dcon_var) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + <*> return freeVarToVarEnv + _ -> - dl + (,) <$> dl <$> CaseE (VarE $ v) <$> mapM (unpackDataCon dcon_var freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v) brs + <*> return freeVarToVarEnv + DataConE slocarg dcon args -> do if (not (isSoALoc (toLocVar slocarg))) then do @@ -1274,7 +1348,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = d' <- gensym "writecur" case ty of _ | isPackedTy ty -> do - rnd' <- go freeVarToVarEnv tenv senv rnd + (rnd', freeVarToVarEnv') <- go freeVarToVarEnv tenv senv rnd end_scalars_alloc <- gensym "end_scalars_alloc" ( if not marker_added then LetE (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation (sloc)) @@ -1285,25 +1359,25 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Int, Float, Sym, or Bool _ | isScalarTy ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + (rnd', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd LetE (d', [], CursorTy, Ext $ WriteScalar (mkScalar ty) d rnd') <$> go2 marker_added d' rst -- Write a pointer to a vector VectorTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + (rnd', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd LetE (d', [], CursorTy, Ext $ WriteVector d rnd' (stripTyLocs el_ty)) <$> go2 marker_added d' rst -- Write a pointer to a vector ListTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + (rnd', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd LetE (d', [], CursorTy, Ext $ WriteList d rnd' (stripTyLocs el_ty)) <$> go2 marker_added d' rst -- shortcut pointer CursorTy -> do - rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd + (rnd', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd LetE (d', [], CursorTy, Ext $ WriteTaggedCursor d rnd') <$> go2 marker_added d' rst _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty @@ -1313,13 +1387,14 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = start_tag_alloc <- gensym "start_tag_alloc" end_tag_alloc <- gensym "end_tag_alloc" start_scalars_alloc <- gensym "start_scalars_alloc" - dl + (,) <$> dl <$> LetE (start_tag_alloc, [], ProdTy [], Ext $ StartTagAllocation (sloc)) <$> LetE (writetag, [], CursorTy, Ext $ WriteTag dcon (sloc)) <$> LetE (end_tag_alloc, [], ProdTy [], Ext $ EndTagAllocation (sloc)) <$> LetE (start_scalars_alloc, [], ProdTy [], Ext $ StartScalarsAllocation (sloc)) <$> LetE (after_tag, [], CursorTy, Ext $ AddCursor (sloc) (L3.LitE 1)) <$> go2 False after_tag (zip args (lookupDataCon ddfs dcon)) + <*> return freeVarToVarEnv else do let sloc_loc = toLocVar slocarg dcon_loc = getDconLoc sloc_loc @@ -1420,21 +1495,21 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let cur_ty = case l of Single _ -> CursorTy SoA _ fields -> CursorArrayTy (1 + length (fields)) - rnd' <- go freeVarToVarEnv' tenv senv rnd + (rnd', fvarenv') <- go fvarenv tenv senv rnd end_scalars_alloc <- gensym "end_scalars_alloc" ( if not marker_added then LetE (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation (sloc)) else id ) <$> LetE (d', [], cur_ty, projEnds rnd') - <$> go2 True fvarenv aft_dloc (Just d') aft_flocs rst + <$> go2 True fvarenv' aft_dloc (Just d') aft_flocs rst _ | isScalarTy ty -> do - rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd + (rnd', fvarenv') <- cursorizeExp fvarenv lenv ddfs fundefs denv tenv senv rnd -- get the location variable where the scalar must be written let floc_loc = case floc of Just l -> l Nothing -> error "cursorizeExp: DataConE: expected a location for scalar buffer" - let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv) of + let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv') of Just v -> v Nothing -> case floc_loc of Single l -> l @@ -1452,14 +1527,14 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else ((d, idx'), l) ) aft_flocs - let fvarenv' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv + let fvarenv'' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv' let_assign_write_cur <$> LetE (d', [], CursorTy, Ext $ WriteScalar (mkScalar ty) write_scalars_at rnd') - <$> go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst + <$> go2 marker_added fvarenv'' aft_dloc from_rec_end aft_flocs' rst -- Write a pointer to a vector VectorTy el_ty -> do - rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd + (rnd', fvarenv') <- cursorizeExp fvarenv lenv ddfs fundefs denv tenv senv rnd -- get the location variable where the scalar must be written let floc_loc = case floc of Just l -> l @@ -1482,10 +1557,10 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else ((d, idx'), l) ) aft_flocs - let fvarenv' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv + let fvarenv'' = M.insert (fromLocVarToFreeVarsTy $ singleLocVar $ d') d' fvarenv' let_assign_write_cur <$> LetE (d', [], CursorTy, Ext $ WriteVector write_vector_at rnd' (stripTyLocs el_ty)) - <$> go2 marker_added fvarenv' aft_dloc from_rec_end aft_flocs' rst + <$> go2 marker_added fvarenv'' aft_dloc from_rec_end aft_flocs' rst -- _ -> error $ "TODO: Cursorize: cursorizePackedExp: Ty not implemented!! " ++ show (ty) @@ -1499,7 +1574,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- SoA case -- Fix case for indirection/shortcut pointers CursorTy -> do - rnd' <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv rnd + (rnd', fvarenv') <- cursorizeExp fvarenv lenv ddfs fundefs denv tenv senv rnd after_indirection <- gensym "aft_indirection" casted_var <- gensym "cast" let rnd_var = case rnd' of @@ -1510,11 +1585,11 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) <$> LetE (after_indirection, [], CursorTy, VarE d') - <$> go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) else do LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') <$> LetE (after_indirection, [], CursorTy, VarE d') - <$> go2 marker_added freeVarToVarEnv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty @@ -1561,7 +1636,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = (additional_bnds, freeVarToVarEnv', 1) field_locs - dl + (,) <$> dl <$> -- Make sure that the field locations and data locations are released here -- We can clean them up later. @@ -1573,16 +1648,17 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = <$> LetE (start_scalars_alloc, [], ProdTy [], Ext $ StartScalarsAllocation (sloc)) <$> LetE (after_tag, [], CursorTy, Ext $ AddCursor (sloc_dcon) (L3.LitE 1)) <$> go2 False freeVarToVarEnv'' after_tag Nothing field_locs locs_tys + <*> return freeVarToVarEnv'' -- go2 :: Bool -> M.Map FreeVarsTy Var -> Var -> [((DataCon, Int), Location, (Exp2, Ty2))] -> [((DataCon, Int), Location, (Exp2, Ty2))] -> PassM Exp3 -- go2 False after_tag (zip args (lookupDataCon ddfs dcon)) TimeIt e t b -> do - Di e' <- go freeVarToVarEnv tenv senv e - return $ Di $ TimeIt e' (cursorizeTy (unTy2 t)) b + (Di e', freeVarToVarEnv') <- go freeVarToVarEnv tenv senv e + return (Di $ TimeIt e' (cursorizeTy (unTy2 t)) b, freeVarToVarEnv') WithArenaE v e -> do - Di e' <- go freeVarToVarEnv (M.insert v (MkTy2 ArenaTy) tenv) senv e - return $ Di $ WithArenaE v e' + (Di e', freeVarToVarEnv') <- go freeVarToVarEnv (M.insert v (MkTy2 ArenaTy) tenv) senv e + return (Di $ WithArenaE v e', freeVarToVarEnv') SpawnE {} -> error "cursorizePackedExp: Unbound SpawnE" SyncE {} -> error "cursorizePackedExp: Unbound SyncE" Ext ext -> @@ -1629,15 +1705,19 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = then go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod -- Discharge bindings that were waiting on 'loc'. else - onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) - <$> go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv') senv' bod + do + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv') senv' bod + return (onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) bod', freeVarToVarEnv'') + -- Discharge bindings that were waiting on 'loc'. _ -> - onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) - <$> go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod - Left denv' -> - onDi (mkLets bnds) - <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + do + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod + return (onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) bod', freeVarToVarEnv'') + + Left denv' -> do + (bod', freeVarToVarEnv'') <- cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + return (onDi (mkLets bnds) bod', freeVarToVarEnv'') {-VS: TODO: This needs to be fixed to produce the correct L3 expression. See above. -} {- Right now i just skip the let region, just recurse on the body-} @@ -1682,20 +1762,21 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Discharge bindings that were waiting on 'loc'. _ -> do case ty_of_loc of - MutCursorTy -> - onDi (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds)) - <$> go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - _ -> - onDi (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, rhs')] ++ bnds)) - <$> go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod - Left denv' -> - onDi (mkLets bnds) - <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + MutCursorTy -> do + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + return (onDi (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, Ext $ AddrOfCursor rhs')] ++ bnds)) bod', freeVarToVarEnv'') + _ -> do + (bod, freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var (ty2_of_loc) tenv''') senv' bod + return (onDi (mkLets (bnds' ++ [(locs_var, [], ty_of_loc, rhs')] ++ bnds)) bod, freeVarToVarEnv'') + + Left denv' -> do + (bod', freeVarToVarEnv'') <- cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod + return (onDi (mkLets bnds) bod', freeVarToVarEnv'') -- case reg_var of -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod - StartOfPkdCursor cur -> return $ dl $ VarE cur + StartOfPkdCursor cur -> return (dl $ VarE cur, freeVarToVarEnv) TagCursor a b -> do let a_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar a)) freeVarToVarEnv) of Just v -> v @@ -1718,31 +1799,31 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) let let_bnd = mkLets $ [tag_inst] ++ [cast_inst] - return $ dl $ let_bnd (VarE casted_var) + return (dl $ let_bnd (VarE casted_var), freeVarToVarEnv) -- ASSUMPTION: RetE forms are inserted at the tail position of functions, -- and we safely just return ends-witnesses & ends of the dilated expressions RetE locs v -> do - v' <- go freeVarToVarEnv tenv senv (VarE v) + (v', freeVarToVarEnv') <- go freeVarToVarEnv tenv senv (VarE v) case locs of - [] -> return v' + [] -> return (v', freeVarToVarEnv') [loc] -> do let loc_to_free_var = fromLocArgToFreeVarsTy loc - let locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of + let locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv') of Just v -> v Nothing -> case (toLocVar loc) of Single lvarr -> lvarr SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - pure $ mkDi (VarE (locs_variable)) [fromDi v'] + pure (mkDi (VarE (locs_variable)) [fromDi v'], freeVarToVarEnv') _ -> return $ - Di $ + (Di $ L3.MkProdE $ L.foldr ( \loc acc -> let loc_to_free_var = fromLocArgToFreeVarsTy loc - locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv) of + locs_variable = case (M.lookup (loc_to_free_var) freeVarToVarEnv') of Just v -> v Nothing -> case (toLocVar loc) of Single lvarr -> lvarr @@ -1751,6 +1832,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) [fromDi v'] locs + , + freeVarToVarEnv') LetRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False r sz let reg_var = regionToVar r @@ -1782,12 +1865,16 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let tenv' = M.insert reg_var_name reg_ty tenv let tenv'' = M.insert reg_var_name_end reg_ty tenv' - onDi (mkLets (region_lets)) <$> go freeVarToVarEnv''' tenv'' senv bod + (bod', freeVarToVarEnv'''') <- go freeVarToVarEnv''' tenv'' senv bod + return (onDi (mkLets (region_lets)) bod', freeVarToVarEnv'''') LetParRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv True r sz - onDi (mkLets (region_lets)) <$> go freeVarToVarEnv' tenv senv bod + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv senv bod + return (onDi (mkLets (region_lets)) bod', freeVarToVarEnv'') FromEndE {} -> error $ "cursorizePackedExp: TODO " ++ sdoc ext - BoundsCheck i bound cur -> return <$> dl <$> Ext $ L3.BoundsCheck i (((unwrapLocVar . toLocVar)) bound) (((unwrapLocVar . toLocVar)) cur) + BoundsCheck i bound cur -> return (dl <$> + Ext $ L3.BoundsCheck i (((unwrapLocVar . toLocVar)) bound) (((unwrapLocVar . toLocVar)) cur) + , freeVarToVarEnv) IndirectionE tycon dcon (from, from_reg) (to, to_reg) _ -> do dflags <- getDynFlags if gopt Opt_DisableGC dflags @@ -1821,7 +1908,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- One way could be to call indirection barrier seperately on every buffer/region -- Then follow them seperately for every region in the case. -- For now i'm erroring out but this needs more thought. - return $ + return ( Di $ ( mkLets [ ("_", [], ProdTy [], Ext (IndirectionBarrier tycon ((from_var), (from_reg_var), (to_var), (to_reg_var)))), @@ -1829,16 +1916,18 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = (end, [], CursorTy, Ext $ AddCursor (from_var) (L3.LitE 9)) ] (MkProdE [VarE start, VarE end]) - ) + ), + freeVarToVarEnv) SoA _ flds -> error "Indirection when GC is enabled is not implemented for SoA! Please turn off the GC!" AddFixed {} -> error "cursorizePackedExp: AddFixed not handled." - GetCilkWorkerNum -> pure $ Di (Ext L3.GetCilkWorkerNum) + GetCilkWorkerNum -> pure (Di (Ext L3.GetCilkWorkerNum), freeVarToVarEnv) LetAvail vs bod -> do - onDi (Ext . L3.LetAvail vs) <$> go freeVarToVarEnv tenv senv bod - AllocateTagHere v tycon -> pure <$> dl <$> Ext $ L3.AllocateTagHere (unwrapLocVar v) tycon - AllocateScalarsHere v -> pure <$> dl <$> Ext $ L3.AllocateScalarsHere (unwrapLocVar v) - SSPush a b c d -> pure <$> dl <$> Ext $ L3.SSPush a (unwrapLocVar b) (unwrapLocVar c) d - SSPop a b c -> pure <$> dl <$> Ext $ L3.SSPop a (unwrapLocVar b) (unwrapLocVar c) + (bod', freeVarToVarEnv') <- go freeVarToVarEnv tenv senv bod + return (onDi (Ext . L3.LetAvail vs) bod', freeVarToVarEnv') + AllocateTagHere v tycon -> pure (dl <$> Ext $ L3.AllocateTagHere (unwrapLocVar v) tycon, freeVarToVarEnv) + AllocateScalarsHere v -> pure (dl <$> Ext $ L3.AllocateScalarsHere (unwrapLocVar v), freeVarToVarEnv) + SSPush a b c d -> pure (dl <$> Ext $ L3.SSPush a (unwrapLocVar b) (unwrapLocVar c) d, freeVarToVarEnv) + SSPop a b c -> pure (dl <$> Ext $ L3.SSPop a (unwrapLocVar b) (unwrapLocVar c), freeVarToVarEnv) MapE {} -> error $ "TODO: cursorizePackedExp MapE" FoldE {} -> error $ "TODO: cursorizePackedExp FoldE" where @@ -1860,21 +1949,27 @@ cursorizeReadPackedFile :: Maybe Var -> Ty2 -> Exp2 -> - PassM Exp3 + PassM (Exp3, M.Map FreeVarsTy Var) cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv isPackedContext v path tyc reg ty2 bod = do case reg of Nothing -> error $ "cursorizePackedExp: InferLocations did not set the reg for ReadPackedFile." - Just reg_var -> - mkLets + Just reg_var -> do + (bod', freeVarToVarEnv') <- go (M.insert v (MkTy2 CursorTy) tenv) bod + return ( + mkLets [ (v, [], CursorTy, PrimAppE (toL3Prim $ ReadPackedFile path tyc reg ty2) []), (reg_var, [], CursorTy, VarE v), (toEndV reg_var, [], CursorTy, Ext $ AddCursor reg_var (Ext $ MMapFileSize v)) - ] - <$> go (M.insert v (MkTy2 CursorTy) tenv) bod + ] bod' + , freeVarToVarEnv') + where go t e = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv e + then + do + (e', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv e + return (fromDi e', freeVarToVarEnv') else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv e -- We may sometimes encounter a letloc which uses an unbound location. @@ -2135,7 +2230,7 @@ findRegInRegion r1 r2 = -- safely drop them from `locs`. -- -- (2) We update `arg` so that all packed values in it only have start cursors. -cursorizeAppE :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeAppE :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM (Exp3, M.Map FreeVarsTy Var) cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = case ex of AppE f locs args -> do @@ -2225,8 +2320,13 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = mapM ( \(t, a) -> if hasPacked (unTy2 t) - then fromDi <$> cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a - else cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a + then + do + (a', _) <- cursorizePackedExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a + fromDi <$> return a' + else do + (a', _) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv tenv senv a + return a' ) (zip in_tys args) let starts = zipWith giveStarts (map unTy2 argTys) args' @@ -2275,10 +2375,10 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = if gopt Opt_RtsDebug dflags then do asserts' <- foldrM (\exprs body -> pure $ exprs body) asserts newInsts - pure asserts' + pure (asserts', freeVarToVarEnv') else do bod' <- foldrM (\exprs body -> pure $ exprs body) bod newInsts - pure bod' + pure (bod', freeVarToVarEnv') _ -> error $ "cursorizeAppE: Unexpected " ++ sdoc ex {- @@ -2300,11 +2400,11 @@ There are two ways in which projections can be cursorized: `cursorizeLet` creates the former, while the special case here outputs the latter. Reason: unariser can only eliminate direct projections of this form. -} -cursorizeProj :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeProj :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM (Exp3, M.Map FreeVarsTy Var) cursorizeProj freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = case ex of LetE (v, _locs, ty, rhs@ProjE {}) bod | isPackedTy (unTy2 ty) -> do - rhs' <- go tenv rhs + (rhs', freeVarToVarEnv') <- go tenv rhs let ty' = gRecoverType ddfs (Env2 tenv M.empty) rhs ty'' = cursorizeTy (unTy2 ty') bnds = @@ -2318,13 +2418,15 @@ cursorizeProj freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv e if isPackedTy (unTy2 ty') then M.union (M.fromList [(v, ty'), (toEndV v, MkTy2 (projEndsTy (unTy2 ty')))]) tenv else M.insert v ty' tenv - bod' <- go tenv' bod - return $ mkLets bnds bod' + (bod', freeVarToVarEnv'') <- go tenv' bod + return (mkLets bnds bod', M.union freeVarToVarEnv' freeVarToVarEnv'') _ -> error $ "cursorizeProj: Unexpected expression: " ++ sdoc ex where go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + then do + (x', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + return (fromDi x', freeVarToVarEnv') else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x {- @@ -2340,26 +2442,34 @@ If it's just `CursorTy`, this packed value doesn't have an end cursor, otherwise, the type is `PackedTy{}`, and it also has an end cursor. -} -cursorizeProd :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeProd :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM (Exp3, M.Map FreeVarsTy Var) cursorizeProd freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = case ex of LetE (v, _locs, MkTy2 (ProdTy tys), rhs@(MkProdE ls)) bod -> do es <- forM (zip tys ls) $ \(ty, e) -> do case ty of - _ | isPackedTy ty -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e - _ | hasPacked ty -> fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + _ | isPackedTy ty -> do + (e', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + return (fromDi e', freeVarToVarEnv') + _ | hasPacked ty -> do + (e', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e + return (fromDi e', freeVarToVarEnv') _ -> cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv e - let rhs' = MkProdE es + let es' = map (\(a, _) -> a) es + rhs' = MkProdE es' + envs = map (\(_, b) -> b) es ty = gRecoverType ddfs (Env2 tenv M.empty) rhs ty' = cursorizeTy (unTy2 ty) tenv' = M.insert v ty tenv - bod' <- go tenv' bod - return $ mkLets [(v, [], ty', rhs')] bod' + (bod', env1) <- go tenv' bod + return (mkLets [(v, [], ty', rhs')] bod', M.unions (envs ++ [env1])) _ -> error $ "cursorizeProj: Unexpected expression: " ++ sdoc ex where go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + then do + (x', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + return (fromDi x', freeVarToVarEnv') else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x {- @@ -2372,12 +2482,14 @@ and add fewer things to the type environemnt because we have to wait until the join point. -} -cursorizeSpawn :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeSpawn :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM (Exp3, M.Map FreeVarsTy Var) cursorizeSpawn freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = do case ex of LetE (v, locs, MkTy2 ty, (SpawnE fn applocs args)) bod | isPackedTy ty -> do - rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) + (rhs', freeVarToVarEnv') <- do + (expr, freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) + return (fromDi expr, freeVarToVarEnv') let rhs'' = case rhs' of AppE fn' applocs' args' -> SpawnE fn' applocs' args' _ -> error "cursorizeSpawn" @@ -2416,11 +2528,13 @@ cursorizeSpawn freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv Just xs -> error $ "cursorizeSpawn todo: " ++ sdoc xs Nothing -> return () let senv' = M.insert v pending_bnds senv - bod' <- go tenv' senv' bod + (bod', freeVarToVarEnv'') <- go tenv' senv' bod let bod'' = updateAvailVars [v] [fresh] bod' - return $ mkLets bnds bod'' + return (mkLets bnds bod'', M.union freeVarToVarEnv' freeVarToVarEnv'') | hasPacked ty -> do - rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) + (rhs', freeVarToVarEnv') <- do + (expr, freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) + return (fromDi expr, freeVarToVarEnv') let rhs'' = case rhs' of AppE fn' applocs' args' -> SpawnE fn' applocs' args' _ -> error $ "cursorizeSpawn: this should've been an AppE. Got" ++ sdoc rhs' @@ -2431,9 +2545,9 @@ cursorizeSpawn freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ty'' = stripTyLocs ty' tenv' = M.insert v (MkTy2 ty) tenv case locs of - [] -> - LetE (v, [], ty'', rhs'') - <$> go tenv' senv bod + [] -> do + (bod', freeVarToVarEnv'') <- go tenv' senv bod + return (LetE (v, [], ty'', rhs'') bod', M.union freeVarToVarEnv' freeVarToVarEnv'') _ -> do let (bnds, pending_bnds) = ( [(fresh, [], ty'', rhs'')], @@ -2441,16 +2555,17 @@ cursorizeSpawn freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ++ [(v, [], projTy (length locs) ty'', MkTy2 ty, ProjE (length locs) (VarE fresh))] ) senv' = M.insert v pending_bnds senv - mkLets bnds <$> go tenv' senv' bod + (bod', freeVarToVarEnv'') <- go tenv' senv' bod + return (mkLets bnds bod', M.union freeVarToVarEnv' freeVarToVarEnv'') | otherwise -> do - rhs' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) + (rhs', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv (AppE fn applocs args) let rhs'' = case rhs' of AppE fn' applocs' args' -> SpawnE fn' applocs' args' _ -> error "cursorizeSpawn" case locs of - [] -> - LetE (v, [], curDict $ stripTyLocs ty, rhs'') - <$> go (M.insert v (MkTy2 ty) tenv) senv bod + [] -> do + (bod', freeVarToVarEnv'') <- go (M.insert v (MkTy2 ty) tenv) senv bod + return (LetE (v, [], curDict $ stripTyLocs ty, rhs'') bod', M.union freeVarToVarEnv'' freeVarToVarEnv') [loc] -> do fresh <- gensym "par_tup_scalar" let ty' :: OldTy2 @@ -2468,17 +2583,19 @@ cursorizeSpawn freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v, [], projTy 1 ty'', MkTy2 (projTy 1 ty'), projEnds rhs''') ] senv' = M.insert v pending_bnds senv - bod' <- go tenv' senv' bod - return $ mkLets [(fresh, [], ty'', rhs'')] bod' + (bod', freeVarToVarEnv'') <- go tenv' senv' bod + return (mkLets [(fresh, [], ty'', rhs'')] bod', M.union freeVarToVarEnv' freeVarToVarEnv'') _ -> error "TODO: cursorizeSpawn" _ -> error "cursorizeSpawn: Unbound SpawnE" where go t s x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t s x + then do + (x', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t s x + return (fromDi x', freeVarToVarEnv') else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t s x -cursorizeSync :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeSync :: M.Map FreeVarsTy Var -> M.Map Var (Maybe LocVar) -> Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM (Exp3, M.Map FreeVarsTy Var) cursorizeSync freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv ex = do case ex of LetE (v, _locs, MkTy2 ty, SyncE) bod -> do @@ -2487,13 +2604,15 @@ cursorizeSync freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv e -- Discharge bindings that depending on the join point. bnds = map (\(a, b, c, _, e) -> (a, b, c, e)) pending_bnds bnds' = (v, [], stripTyLocs ty, SyncE) : bnds - bod' <- go tenv' bod - return $ mkLets bnds' bod' + (bod', freeVarToVarEnv') <- go tenv' bod + return (mkLets bnds' bod', freeVarToVarEnv') _ -> error "cursorizeSpawn: Unbound SyncE" where go t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x + then do + (x', freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x + return (fromDi x', freeVarToVarEnv') else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t M.empty x {- @@ -2529,10 +2648,11 @@ cursorizeLet :: SyncEnv -> (Var, [LocArg], Ty2, Exp2) -> Exp2 -> - PassM Exp3 + PassM (Exp3, M.Map FreeVarsTy Var) cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v, locs, (MkTy2 ty), rhs) bod | isPackedTy ty = do - rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + (_rhs, freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + rhs' <- fromDi <$> return _rhs fresh <- dbgTrace (minChatLvl) "Print locs in cursorize Let " dbgTrace (minChatLvl) (sdoc (locs)) dbgTrace (minChatLvl) "End cursorize Let\n" gensym "tup_packed" let cursor_ty_locs = map @@ -2574,7 +2694,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ++ map ( \loc -> let free_var = fromLocArgToFreeVarsTy loc - var = case (M.lookup free_var freeVarToVarEnv) of + var = case (M.lookup free_var freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeLet: unexpected location variable" cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) @@ -2599,7 +2719,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \(loc, n) -> let loc_var = fromLocArgToFreeVarsTy loc cursor_ty = cursor_ty_locs' !! n - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeLet: unexpected location variable" in (loc_to_variable, [], cursor_ty, mkProj n rhs'') @@ -2614,8 +2734,8 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v case M.lookup (fromVarToFreeVarsTy (toEndV v)) denv of Just xs -> error $ "todo: " ++ sdoc xs Nothing -> return () - bod' <- go tenv' bod - return $ mkLets bnds bod' + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv' bod + return (mkLets bnds bod', freeVarToVarEnv'') | hasPacked ty = do let cursor_ty_locs = map @@ -2647,7 +2767,8 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v in cursorType ) locs - rhs' <- fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + (_rhs, freeVarToVarEnv') <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + rhs' <- fromDi <$> return _rhs fresh <- gensym "tup_haspacked" let ty' = case locs of [] -> cursorizeTy ty @@ -2660,7 +2781,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v map ( \loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeLet: unexpected location variable" cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) @@ -2669,9 +2790,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v locs ) case locs of - [] -> - LetE (v, [], ty'', rhs') - <$> go tenv' bod + [] -> do + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv' bod + return (LetE (v, [], ty'', rhs') bod', freeVarToVarEnv'') _ -> do let tenv'' = M.union tenv' $ @@ -2700,7 +2821,8 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ) (zip locs [0 ..]) ++ [(v, [], projTy (length locs) ty'', ProjE (length locs) (VarE fresh))] - mkLets bnds <$> go tenv'' bod + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv'' bod + return (mkLets bnds bod', freeVarToVarEnv'') {- @@ -2750,11 +2872,11 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v in cursorType ) locs - rhs' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs + (rhs', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs case locs of - [] -> - LetE (v, [], curDict $ stripTyLocs ty, rhs') - <$> go (M.insert v (MkTy2 ty) tenv) bod + [] -> do + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert v (MkTy2 ty) tenv) bod + return (LetE (v, [], curDict $ stripTyLocs ty, rhs') bod', M.union freeVarToVarEnv' freeVarToVarEnv'') _ -> do fresh <- gensym "tup_scalar" let rhs'' = VarE fresh @@ -2788,13 +2910,16 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ) (zip locs [0 ..]) ++ [(v, [], projTy (length locs) ty'', ProjE (length locs) rhs'')] - bod' <- go tenv' bod - return $ mkLets bnds bod' + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv' bod + return (mkLets bnds bod', M.union freeVarToVarEnv' freeVarToVarEnv'') where - go t x = + go fenv t x = if isPackedContext - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv t senv x - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv t senv x + then + do + (x', freeVarToVarEnv') <- cursorizePackedExp fenv lenv ddfs fundefs denv t senv x + return (fromDi x', freeVarToVarEnv') + else cursorizeExp fenv lenv ddfs fundefs denv t senv x {- @@ -2962,8 +3087,12 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tys1 = lookupDataCon ddfs dcon processRhs denv env = if isPacked - then fromDi <$> cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs - else cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs + then do + (rhs', _) <- cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs + fromDi <$> pure rhs' + else do + (rhs', _) <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs + pure rhs' lookupVariable :: FreeVarsTy -> M.Map FreeVarsTy Var -> PassM Var lookupVariable loc fenv = case (M.lookup loc fenv) of @@ -3799,54 +3928,72 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let tenv' = M.insert v (MkTy2 ty3_of_field) tenv let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 let cur = dcur_end - let tenv' = + let tenv'' = M.union ( M.fromList [ (locs_var, MkTy2 ty3_of_field), (v, MkTy2 ty3_of_field) ] ) - tenv + tenv' case M.lookup v indirections_env of -- This is the first packed value. We can unpack this. Nothing -> do - dcon_next <- gensym $ toVar $ (fromVar dcur_end) ++ "_next" + dcon_next <- gensym $ toVar $ (fromVar cur) ++ "_next" let end_fields = map (\(key, varr) -> varr) _field_cur let makeCurArr = Ext $ MakeCursorArray (1 + length (end_fields)) ([dcon_next] ++ end_fields) - let let_mk_cur_arr = (locs_var, [], CursorArrayTy (1 + length (end_fields)), makeCurArr) - let dcon_nxt = [(dcon_next, [], CursorTy, VarE dcur_end)] ++ [let_mk_cur_arr, (v, [], CursorArrayTy (1 + length (end_fields)), VarE (locs_var))] + let let_mk_cur_arr = (locs_var, [], ty3_of_field2, makeCurArr) + let dcon_nxt = [(dcon_next, [], CursorTy, VarE cur)] ++ [let_mk_cur_arr, (v, [], ty3_of_field2, VarE (locs_var))] let curw' = SoAWin dcon_next _field_cur bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' return $ mkLets dcon_nxt bod -- We need to access this using a random access node Just (_var_loc, ind_var) -> do - dcon_next <- gensym $ toVar $ (fromVar dcur_end) ++ "_next" + dcon_next <- gensym $ toVar $ (fromVar cur) ++ "_next" let end_fields = map (\(key, varr) -> varr) _field_cur - let bnd = (locs_var, [], CursorArrayTy (1 + length (end_fields)), VarE ind_var) - let dcon_nxt = [(dcon_next, [], CursorTy, VarE dcur_end)] ++ [bnd, (v, [], CursorArrayTy (1 + length (end_fields)), VarE (locs_var))] + let bnd = (locs_var, [], ty3_of_field2, VarE ind_var) + let dcon_nxt = [(dcon_next, [], CursorTy, VarE cur)] ++ [bnd, (v, [], ty3_of_field2, VarE (locs_var))] let curw' = SoAWin dcon_next _field_cur - bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' + bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv'' return $ mkLets dcon_nxt bod -- VS: TODO: needs to be fixed when packed type is not self recursive. False -> do - let tenv' = + let ty3_of_field = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field2 :: Ty3 = case ploc of + Single _ -> CursorTy + SoA _ fl -> CursorArrayTy (1 + length fl) + let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = M.union ( M.fromList - [ (locs_var, MkTy2 CursorTy), - (v, MkTy2 CursorTy) + [ (locs_var, MkTy2 ty3_of_field), + (v, MkTy2 ty3_of_field) ] ) tenv - loc_bind = case M.lookup v indirections_env of + loc_bind = case M.lookup v indirections_env of -- This is the first packed value. We can unpack this. Nothing -> - (locs_var, [], CursorTy, VarE dcur_end) + (locs_var, [], ty3_of_field2, VarE cur) -- We need to access this using a random access node Just (_var_loc, ind_var) -> - (locs_var, [], CursorTy, VarE ind_var) - bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv' - return $ mkLets [loc_bind, (v, [], CursorTy, VarE locs_var)] bod + (locs_var, [], ty3_of_field2, VarE ind_var) + bod <- go curw fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets [loc_bind, (v, [], ty3_of_field2, VarE locs_var)] bod + + -- Flip canBind to indicate that the subsequent fields + -- -- should be added to the dependency environment. + -- bod <- go curw fenv rst_vlocs rst_tys False denv tenv'' -- (toEndV v) + -- return $ + -- mkLets + -- [ ((loc_var), [], ty3_of_field2, VarE cur), + -- (v, [], ty3_of_field2, VarE (loc_var)) + -- ] + -- bod @@ -3889,6 +4036,10 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- -- Cannot read this. Instead, we add it to DepEnv. -- let denv' = M.insertWith (++) (loc) [(v, [], ty3_of_field2, VarE (loc_var))] denv -- go curw fenv rst_vlocs rst_tys False denv' tenv' -- (toEndV v) + + + + -- False -> do -- let ty3_of_field = case ploc of -- Single _ -> CursorTy From 423e6a63d101a9ef214a9ac5dff00705812c39f5 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sat, 27 Sep 2025 19:29:36 -0400 Subject: [PATCH 26/60] add soa random access to test suite --- .../examples/soa_examples/packedTree.hs | 2 +- gibbon-compiler/gibbon.cabal | 1 + gibbon-compiler/src/Gibbon/Compiler.hs | 36 ++++---- gibbon-compiler/src/Gibbon/L0/Specialize2.hs | 4 +- gibbon-compiler/src/Gibbon/L2/Syntax.hs | 8 ++ gibbon-compiler/src/Gibbon/L2/Typecheck.hs | 10 ++- gibbon-compiler/src/Gibbon/Language/Syntax.hs | 37 ++++---- .../src/Gibbon/Passes/Cursorize.hs | 88 +++++++++++-------- .../src/Gibbon/Passes/InferLocations.hs | 24 +++-- gibbon-compiler/tests/BenchRunner.hs | 2 +- gibbon-compiler/tests/TestRunner.hs | 8 +- .../tests/test-gibbon-examples.yaml | 72 +++++++-------- 12 files changed, 166 insertions(+), 126 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index 34a7caafc..1d467b2d7 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -87,6 +87,6 @@ id tree = tree gibbon_main = let tree = mkTree 5 tree' = id (add1Tree tree) - val = rightMostTree tree' + val = sumTree tree' in val diff --git a/gibbon-compiler/gibbon.cabal b/gibbon-compiler/gibbon.cabal index bfea8dec2..6e56f5020 100644 --- a/gibbon-compiler/gibbon.cabal +++ b/gibbon-compiler/gibbon.cabal @@ -96,6 +96,7 @@ library Gibbon.Passes.HoistBoundsCheck Gibbon.Passes.ReorderLetExprs Gibbon.Passes.AddCastInstructions + Gibbon.Passes.OptimizeL3 other-extensions: DeriveDataTypeable CPP diff --git a/gibbon-compiler/src/Gibbon/Compiler.hs b/gibbon-compiler/src/Gibbon/Compiler.hs index b980dd4a4..fd9bd64ea 100644 --- a/gibbon-compiler/src/Gibbon/Compiler.hs +++ b/gibbon-compiler/src/Gibbon/Compiler.hs @@ -84,6 +84,7 @@ import Gibbon.Passes.ThreadRegions (threadRegions) import Gibbon.Passes.ThreadRegions2 (threadRegions2) import Gibbon.Passes.InferFunAllocs (inferFunAllocs) import Gibbon.Passes.Cursorize (cursorize) +import Gibbon.Passes.OptimizeL3 (removeReDefs) import Gibbon.Passes.FindWitnesses (findWitnesses) -- -- import Gibbon.Passes.ShakeTree (shakeTree) import Gibbon.Passes.HoistNewBuf (hoistNewBuf) @@ -710,13 +711,13 @@ passes config@Config{dynflags} l0 = do l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- go "fixRANs" fixRANs l2 l2 <- goE2 "reorderLetExprs2" reorderLetExprs l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "L2.flatten" flattenL2 l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- if gibbon1 || no_rcopies then return l2 else do l2 <- go "removeCopies" removeCopies l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 return l2 l2 <- goE2 "inferEffects" inferEffects l2 @@ -751,9 +752,9 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. if gibbon1 || noRAN then do l2 <- goE2 "addTraversals" addTraversals l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "inferEffects2" inferEffects l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "repairProgram" (pure . id) l2 pure l2 else do @@ -773,24 +774,24 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. --l2 <- go "regionsInwards" regionsInwards l2 --l2 <- go "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- goE2 "reorderLetExprs4" reorderLetExprs l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 -- VS : This pass is causing a bug l2 <- go "L2.flatten" flattenL2 l2 l2 <- go "findWitnesses" findWitnesses l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "L2.flatten" flattenL2 l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- if no_rcopies then return l2 else do l2 <- goE2 "removeCopies" removeCopies l2 return l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "inferEffects2" inferEffects l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "addTraversals" addTraversals l2 - -- l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "repairProgram" (pure . id) l2 pure l2 @@ -806,20 +807,20 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. then pure l2 else goE2 "parAlloc" parAlloc l2 lift $ dumpIfSet config Opt_D_Dump_ParAlloc (pprender l2) - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "inferRegScope" inferRegScope l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- go "writeOrderMarkers" writeOrderMarkers l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- goE2 "routeEnds" routeEnds l2 l2 <- goE2 "L2.flatten" flattenL2 l2 l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 l2 <- goE2 "reorderLetExprs5" reorderLetExprs l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 l2 <- go "inferFunAllocs" inferFunAllocs l2 - --l2 <- go "L2.typecheck" L2.tcProg l2 + l2 <- go "L2.typecheck" L2.tcProg l2 -- L2 program no longer typechecks while these next passes run {- VS: The Argument to simplify loc binds used to be False, why doesn't true work ? -} l2 <- goE2 "simplifyLocBinds" (simplifyLocBinds True) l2 @@ -856,6 +857,7 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. return l3 l3 <- go "unariser" unariser l3 + l3 <- go "removeReDefinitions" removeReDefs l3 l3 <- go "L3.typecheck" tcProg3 l3 l3 <- go "L3.flatten" flattenL3 l3 l3 <- go "L3.typecheck" tcProg3 l3 diff --git a/gibbon-compiler/src/Gibbon/L0/Specialize2.hs b/gibbon-compiler/src/Gibbon/L0/Specialize2.hs index de3ca9aa0..8302411e5 100644 --- a/gibbon-compiler/src/Gibbon/L0/Specialize2.hs +++ b/gibbon-compiler/src/Gibbon/L0/Specialize2.hs @@ -1568,11 +1568,11 @@ addRepairFns (Prog dfs fds me) = do newFns <- concat <$> mapM (\d -> do copy_fn <- genCopyFn d - -- copy2_fn <- genCopySansPtrsFn d + copy2_fn <- genCopySansPtrsFn d trav_fn <- genTravFn d print_fn <- genPrintFn d -- copy2_fn - return [copy_fn, trav_fn, print_fn]) + return [copy_fn, copy2_fn, trav_fn, print_fn]) (filter (not . isVoidDDef) (M.elems dfs)) let fds' = fds `M.union` (M.fromList $ map (\f -> (funName f, f)) newFns) pure $ Prog dfs fds' me diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index a0b35101f..a74c74327 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -1125,6 +1125,14 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty InRegionLE r -> [fromRegVarToFreeVarsTy (regionToVar r)] FromEndLE loc -> [fromLocVarToFreeVarsTy loc] FreeLE -> [] + GetDataConLocSoA loc -> [fromLocVarToFreeVarsTy loc] + GetFieldLocSoA key loc -> case loc of + SoA _ flocs -> let floc = lookup key flocs + in case floc of + Nothing -> [] + Just floc' -> [fromLocVarToFreeVarsTy floc'] + GenSoALoc floc flocs -> let loc = SoA (unwrapLocVar floc) flocs + in [fromLocVarToFreeVarsTy loc] -- TODO: VS: I don't think region vars are handled properly here. allFreeVars :: Exp2 -> S.Set FreeVarsTy diff --git a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs index cc008ba61..691027181 100644 --- a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs @@ -1224,6 +1224,8 @@ ensurePackedLoc exp ty l = -- | Ensure the locations all line up with the constraints in a data constructor application. -- Includes an expression for error reporting. +-- VS : TODO: +-- the constraints for case when we have random access pointers is not implemented. ensureDataCon :: Exp -> TyCon -> DataCon -> LocVar -> [Ty2] -> ConstraintSet -> TcM () ensureDataCon exp dcty dc linit0 tys cs = case linit0 of Single location -> (go Nothing linit0 tys) @@ -1249,7 +1251,7 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of -- This checking should be fine for a Flat list data type -- data List = Cons Int List | Nil -- TODO: Extend for a Tree data type - SoA dcloc fieldLocs -> do + SoA dcloc fieldLocs -> do let unself_idxs = L.concatMap (\ty -> case ty of PackedTy k _ -> if k == dcty @@ -1263,6 +1265,7 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of PackedTy k _ -> if k == dcty then [fromJust (L.elemIndex ty tys)] else [] + CursorTy -> [fromJust (L.elemIndex ty tys)] _ -> [] ) tys @@ -1279,7 +1282,8 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of case selfTys of [] -> return () x:_ -> case x of - PackedTy _ l -> ensureAfterConstant exp cs (Single dcloc) (getDconLoc l) + PackedTy _ l -> ensureAfterConstant exp cs (Single dcloc) (getDconLoc l) + CursorTy -> return () _ -> error "Did not expected unpacked type!" -- TODO: ensure after constant for all scalar not self recursive fields, with offset 0 -- TODO: ensure after constant for all locs in dest with the next self recursive field. @@ -1303,6 +1307,8 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of -- PackedTy{} -> ensureAfterPacked exp cs l1 l2 -- _ -> ensureAfterConstant exp cs l1 l2) (zip3 aliasLocs nextWriteAtLocs unselfTys) return () + -- TODO: implement for ran access pointers. + CursorTy -> return () -- dbgTraceIt "Print in ensure data con" dbgTraceIt (sdoc (unselfTys, selfTys, unselfWriteAtLocs)) dbgTraceIt "End\n" return () diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index febc034a2..58e6494d5 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -28,7 +28,7 @@ module Gibbon.Language.Syntax -- * Environments , TyEnv, Env2(..), emptyEnv2 - , extendVEnv, extendsVEnv, lookupVEnv, extendFEnv, lookupFEnv, + , extendVEnv, extendsVEnv, lookupVEnv, mblookupVEnv, extendFEnv, lookupFEnv, lookupFEnvLocVar, extendVEnvLocVar, extendsVEnvLocVar, lookupVEnvLocVar -- * Expresssions and thier types @@ -171,22 +171,25 @@ getCursorTypeForDataCon ddefs ddef@DDef{tyName, tyArgs, dataCons, memLayout} = then [] else [e] ) dataCons - in case memLayout of - Linear -> CursorTy - FullyFactored -> - let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon ddefs dcon - c' = foldr (\ty c'' -> case ty of - PackedTy tycon _ -> - if (toVar tycon) == tyName - then c'' - else c'' + 1 - CursorTy -> c'' - CursorArrayTy _ -> c'' - _ -> c'' + 1 - ) c fields - in c' - ) 0 dataCons' - in CursorArrayTy (numFieldBuffers + 1) + in case memLayout of + -- VS: For now, in the design we just always ensure + -- that a random access node is a CursorTy. + _ -> CursorTy + -- Linear -> CursorTy + -- FullyFactored -> + -- let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon ddefs dcon + -- c' = foldr (\ty c'' -> case ty of + -- PackedTy tycon _ -> + -- if (toVar tycon) == tyName + -- then c'' + -- else c'' + 1 + -- CursorTy -> c'' + -- CursorArrayTy _ -> c'' + -- _ -> c'' + 1 + -- ) c fields + -- in c' + -- ) 0 dataCons' + -- in CursorArrayTy (numFieldBuffers + 1) _ -> error "Memory Layout is not implemented!" insertDD :: DDef a -> DDefs a -> DDefs a diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 4404177a9..a5aa37fc7 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -469,7 +469,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = then pure $ (Ext $ SubPtr (toEndV v) v, freeVarToVarEnv) else pure $ (LitE $ fromJust $ sizeOfTy (unTy2 ty), freeVarToVarEnv) PrimAppE pr args -> do - res <- mapM go args + res <- mapM (go freeVarToVarEnv) args let args' = map fst res let freeEnvs = map snd res let freeVarToVarEnv' = M.unions freeEnvs @@ -504,7 +504,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = freeVarToVarEnv _locs (ret_e, freeVarToVarEnv'') <- cursorizeReadPackedFile freeVarToVarEnv' lenv ddfs fundefs denv tenv senv True v path tyc reg ty2 bod - return (ret_e, freeVarToVarEnv'') + return (ret_e, M.union freeVarToVarEnv' freeVarToVarEnv'') LetE (_v, _locs, _ty, (MkProdE _ls)) _bod -> do freeVarToVarEnv' <- foldrM @@ -627,20 +627,20 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = return $ (ret_e, M.union freeVarToVarEnv' freeVarToVarEnv'') LetE (v, _locs, ty, rhs@(Ext (SSPush _ start _ _))) bod -> do case M.lookup (unwrapLocVar start) tenv of - Nothing -> go bod + Nothing -> go freeVarToVarEnv bod Just {} -> do - (rhs', fenv1) <- go rhs - (bod', fenv2) <- go bod + (rhs', fenv1) <- go freeVarToVarEnv rhs + (bod', fenv2) <- go fenv1 bod let ty' = cursorizeTy (unTy2 ty) - return $ (LetE (v, [], ty', rhs') bod', M.union fenv1 fenv2) + return $ (LetE (v, [], ty', rhs') bod', fenv2) LetE (v, _locs, ty, rhs@(Ext (SSPop _ start _))) bod -> case M.lookup (unwrapLocVar start) tenv of - Nothing -> go bod + Nothing -> go freeVarToVarEnv bod Just {} -> do - (rhs', fenv1) <- go rhs - (bod', fenv2) <- go bod + (rhs', fenv1) <- go freeVarToVarEnv rhs + (bod', fenv2) <- go fenv1 bod let ty' = cursorizeTy (unTy2 ty) - return $ (LetE (v, [], ty', rhs') bod', M.union fenv1 fenv2) + return $ (LetE (v, [], ty', rhs') bod', fenv2) -- LetE bnd@(v, _locs, ty, rhs) bod -> case rhs of -- Ext (BoundsCheck i bound cur) -> do @@ -690,19 +690,19 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = freeVarToVarEnv _locs (ret_e, freeVarToVarEnv'') <- cursorizeLet freeVarToVarEnv' lenv False ddfs fundefs denv tenv senv bnd bod - return $ (ret_e, freeVarToVarEnv'') + return $ (ret_e, M.unions [freeVarToVarEnv, freeVarToVarEnv', freeVarToVarEnv'']) IfE a b c -> do - (a', e1) <- go a - (b', e2) <- go b - (c', e3) <- go c - return (IfE a' b' c', M.unions [e1, e2, e3]) + (a', e1) <- go freeVarToVarEnv a + (b', e2) <- go freeVarToVarEnv b + (c', e3) <- go freeVarToVarEnv c + return (IfE a' b' c', M.unions [freeVarToVarEnv, e1, e2, e3]) MkProdE ls -> do - res <- mapM go ls + res <- mapM (go freeVarToVarEnv) ls let ls' = map fst res let envs = map snd res return $ (MkProdE ls', M.unions envs) ProjE i e -> do - (e', env) <- go e + (e', env) <- go freeVarToVarEnv e return (ProjE i e', env) -- Eg. leftmost CaseE scrt brs -> do @@ -769,7 +769,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = DataConE _ _ _ -> error $ "cursorizeExp: Should not have encountered DataConE if type is not packed: " ++ ndoc ex TimeIt e ty b -> do - (e', env) <- go e + (e', env) <- go freeVarToVarEnv e return (TimeIt e' (stripTyLocs (unTy2 ty)) b, env) WithArenaE v e -> do @@ -887,12 +887,12 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Discharge bindings that were waiting on 'loc'. else do - (bod, env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod - return (mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) bod, env) + (bod', env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv' bod + return (mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) bod', env) -- Discharge bindings that were waiting on 'loc'. _ -> do - (bod, env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv bod - return (mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) bod, env) + (bod', env) <- cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv (M.insert locs_var (MkTy2 ty2_of_loc) tenv''') senv bod + return (mkLets (bnds' ++ [(locs_var, [], ty3_of_loc, rhs')] ++ bnds) bod', env) Left denv' -> cursorizeExp freeVarToVarEnv' lenv ddfs fundefs denv' tenv' senv bod -- Exactly same as cursorizePackedExp @@ -1000,7 +1000,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = IndirectionE {} -> error $ "cursorizeExp: Unexpected IndirectionE" GetCilkWorkerNum -> return (Ext $ L3.GetCilkWorkerNum, freeVarToVarEnv) LetAvail vs bod -> do - (bod', env) <- go bod + (bod', env) <- go freeVarToVarEnv bod return (Ext $ L3.LetAvail vs bod', env) AllocateTagHere v tycon -> do let variable_name = case (M.lookup (fromLocVarToFreeVarsTy v) freeVarToVarEnv) of @@ -1082,7 +1082,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = MapE {} -> error $ "TODO: cursorizeExp MapE" FoldE {} -> error $ "TODO: cursorizeExp FoldE" where - go = cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv + go fenv = cursorizeExp fenv lenv ddfs fundefs denv tenv senv insertRegInVarEnv :: RegVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var) insertRegInVarEnv reg_var env = do @@ -1508,7 +1508,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- get the location variable where the scalar must be written let floc_loc = case floc of Just l -> l - Nothing -> error "cursorizeExp: DataConE: expected a location for scalar buffer" + Nothing -> error $ "cursorizeExp: DataConE: expected a location for scalar buffer" ++ show (dcon, index) let floc_var = case (M.lookup (fromLocVarToFreeVarsTy $ floc_loc) fvarenv') of Just v -> v Nothing -> case floc_loc of @@ -1601,13 +1601,23 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = start_scalars_alloc <- gensym "start_scalars_alloc" let exp_f_tys = zip args (lookupDataCon ddfs dcon) -- [((DataCon, Int), Maybe Location, (Exp2, Ty2))] + let tyConOfDataCon = getTyOfDataCon ddfs dcon + let allDataCons = getConOrdering ddfs tyConOfDataCon + -- checks for abs random access nodes + -- VS: relative offsets are turned off in the original compiler so these are also + -- not being handles with the SoA transformation. + let dc' = foldr (\x dc -> if (x == dcon ++ "^") then Just x else dc) Nothing allDataCons + let dcon' = case dc' of + Nothing -> dcon + Just dc -> dc + let numRanNodes = if (("^" `L.isSuffixOf` dcon') && (not ("^" `L.isSuffixOf` dcon)) ) then ((numRANsDataCon (M.map (fmap unTy2) ddfs) dcon)) else 0 let locs_tys = map ( \e@(rnd, (MkTy2 ty)) -> let idx = case (L.elemIndex e exp_f_tys) of Just idx -> idx Nothing -> error "cursorizeExp: DataConE: field not found!" - key = (dcon, idx) + key = (dcon', idx + numRanNodes) loc = L.lookup key field_locs in (key, loc, e) ) @@ -1679,7 +1689,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else do name <- gensym "cursor_ptr" return $ M.insert (fromLocVarToFreeVarsTy loc) name freeVarToVarEnv - let rhs_either = dbgTrace (minChatLvl) "Print env" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv')) dbgTrace (minChatLvl) "End env\n" cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs + let rhs_either = dbgTrace (minChatLvl) "Print env" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv')) dbgTrace (minChatLvl) "End env cursorize\n" cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs (bnds, tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of Nothing -> ([], tenv) Just vs -> @@ -1984,7 +1994,7 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = AfterConstantLE i loc -> let locs_var = case (M.lookup ((fromLocVarToFreeVarsTy . toLocVar) loc) freeVarToVarEnv) of Just v -> v - Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (toLocVar loc)) ++ ")" ++ show freeVarToVarEnv + Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "\n,\n" ++ (show (toLocVar loc, lvar)) ++ "\n)\n" ++ show freeVarToVarEnv rhs = Ext $ AddCursor locs_var (LitE i) lvar_to_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of Just v -> v @@ -2734,7 +2744,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v case M.lookup (fromVarToFreeVarsTy (toEndV v)) denv of Just xs -> error $ "todo: " ++ sdoc xs Nothing -> return () - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv' bod + (bod', freeVarToVarEnv'') <- go (M.union freeVarToVarEnv' freeVarToVarEnv) tenv' bod return (mkLets bnds bod', freeVarToVarEnv'') | hasPacked ty = do let cursor_ty_locs = @@ -2791,7 +2801,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ) case locs of [] -> do - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv' bod + (bod', freeVarToVarEnv'') <- go (M.union freeVarToVarEnv' freeVarToVarEnv) tenv' bod return (LetE (v, [], ty'', rhs') bod', freeVarToVarEnv'') _ -> do let tenv'' = @@ -2800,7 +2810,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v map ( \loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of Just v' -> v' Nothing -> error "cursorizeLet: unexpected location variable" cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) @@ -2813,7 +2823,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ++ map ( \(loc, n) -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of Just v' -> v' Nothing -> error "cursorizeLet: unexpected location variable" cursorType = cursor_ty_locs' !! n @@ -2821,7 +2831,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ) (zip locs [0 ..]) ++ [(v, [], projTy (length locs) ty'', ProjE (length locs) (VarE fresh))] - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv'' bod + (bod', freeVarToVarEnv'') <- go (M.union freeVarToVarEnv' freeVarToVarEnv) tenv'' bod return (mkLets bnds bod', freeVarToVarEnv'') {- @@ -2875,8 +2885,8 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v (rhs', freeVarToVarEnv') <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rhs case locs of [] -> do - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert v (MkTy2 ty) tenv) bod - return (LetE (v, [], curDict $ stripTyLocs ty, rhs') bod', M.union freeVarToVarEnv' freeVarToVarEnv'') + (bod', freeVarToVarEnv'') <- go (M.union freeVarToVarEnv' freeVarToVarEnv) (M.insert v (MkTy2 ty) tenv) bod + return (LetE (v, [], curDict $ stripTyLocs ty, rhs') bod', freeVarToVarEnv'') _ -> do fresh <- gensym "tup_scalar" let rhs'' = VarE fresh @@ -2890,7 +2900,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v map ( \loc -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeLet: unexpected location variable" cursorType = cursor_ty_locs !! (fromJust $ L.elemIndex loc locs) @@ -2902,7 +2912,7 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ++ map ( \(loc, n) -> let loc_var = fromLocArgToFreeVarsTy loc - loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv) of + loc_to_variable = case (M.lookup (loc_var) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeLet: unexpected location variable" cursorType = cursor_ty_locs' !! n @@ -2910,8 +2920,8 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ) (zip locs [0 ..]) ++ [(v, [], projTy (length locs) ty'', ProjE (length locs) rhs'')] - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' tenv' bod - return (mkLets bnds bod', M.union freeVarToVarEnv' freeVarToVarEnv'') + (bod', freeVarToVarEnv'') <- go (M.union freeVarToVarEnv' freeVarToVarEnv) tenv' bod + return (mkLets bnds bod', freeVarToVarEnv'') where go fenv t x = if isPackedContext diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index 3de844d78..0082eabd3 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -100,6 +100,7 @@ import GHC.Stack (HasCallStack) import Gibbon.Common import Gibbon.L1.Syntax as L1 hiding (extendVEnv, extendsVEnv, lookupVEnv, lookupFEnv) +import Gibbon.Passes.AddRAN (numRANsDataCon) import qualified Gibbon.L1.Syntax as L1 import Gibbon.L2.Syntax as L2 hiding (extendVEnv, extendsVEnv, lookupVEnv, lookupFEnv) import Gibbon.Passes.InlineTriv (inlineTriv) @@ -645,7 +646,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = tryBindReg :: Result -> TiM Result tryBindReg (e,ty,((StartRegionL lv r) : cs)) = do lv' <- finalLocVar lv - (e',ty',cs') <- tryBindReg (e,ty,cs) + (e',ty',cs') <- dbgTrace minChatLvl "Print tryBindReg (l, lv): " dbgTrace minChatLvl (sdoc (lv, lv')) dbgTrace minChatLvl "End tryBindReg lv'\n" tryBindReg (e,ty,cs) b1 <- noAfterLoc lv' cs' cs' if b1 then do (e'',ty'',cs'') <- bindTrivialAfterLoc lv' (e',ty',cs') @@ -694,7 +695,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = b3' <- notFixedLoc lv2' if b1 && b2 && b3 then do cs' <- dbgTrace minChatLvl "tryInRegion' aftertag: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2')) dbgTrace minChatLvl "End tryInRegion' afterTag.\n" tryInRegion' fcs cs - r <- lift $ lift $ freshRegVar + r <- getNewRegion lv2' let c' = StartRegionL lv2' r return (c':c:cs') else do cs' <- dbgTrace minChatLvl "tryInRegion' aftertag: " dbgTrace minChatLvl (sdoc (b1, b2, b3, lv2, lv2')) dbgTrace minChatLvl "End tryInRegion' afterTag.\n" tryInRegion' fcs cs @@ -722,8 +723,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = tryNeedRegion :: [LocVar] -> Ty2 -> [Constraint] -> TiM [Constraint] tryNeedRegion (l:ls) ty cs = do lv <- finalLocVar l - -- dbgTrace minChatLvl "Print (l, lv): " dbgTrace minChatLvl (sdoc (l, lv)) dbgTrace minChatLvl "End lv\n" - vls <- mapM finalLocVar (locsInTy ty) + vls <- dbgTrace minChatLvl "Print (l, lv): " dbgTrace minChatLvl (sdoc (l, lv)) dbgTrace minChatLvl "End lv\n" mapM finalLocVar (locsInTy ty) if not (lv `L.elem` vls) then do b1 <- noBeforeLoc lv cs b2 <- noRegionStart lv cs @@ -1166,6 +1166,12 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- Arguments are either a fixed size or a variable -- TODO: audit this! let tyConOfDataCon = getTyOfDataCon ddefs k + let allDataCons = getConOrdering ddefs tyConOfDataCon + let dc' = foldr (\x dc -> if (x == k ++ "^") then Just x else dc) Nothing allDataCons + let k' = case dc' of + Nothing -> k + Just dc -> dc + let numRanNodes = if (("^" `L.isSuffixOf` k') && (not ("^" `L.isSuffixOf` k)) ) then ((numRANsDataCon ddefs k)) else 0 -- dbgTrace minChatLvl "inferExp SoA case: " dbgTrace minChatLvl (sdoc ((ls, locs, ls'))) dbgTrace minChatLvl "End SoA ls'.\n" argLs <- forM [a | (a,_,_) <- ls'] $ \arg -> case arg of @@ -1254,10 +1260,10 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- ) -- in [afterTagConstraint] ++ afterTagConstrsTmp -- dbgTrace minChatLvl "Print tuple line: 1040" dbgTrace minChatLvl (sdoc (argsLsDconBuf, dcArgDconBuf, locsDconBuf, argsLsFields, dcArgFields, locsFields)) dbgTrace minChatLvl "End line 1040\n" - fieldLocVars = P.map (\(Just idx) -> let fldloc = lookup (k, idx) fieldLocs + fieldLocVars = P.map (\(Just idx) -> let fldloc = lookup (k', idx + numRanNodes) fieldLocs in case fldloc of Just location -> Just location - Nothing -> error $ "inferExp: fieldLocVars did not expect Nothing! Datacon: " ++ show (k, idx) ++ " ," ++ show idxsFields' ++ ", fieldLocs: " ++ show fieldLocs + Nothing -> error $ "inferExp: fieldLocVars did not expect Nothing! Datacon: " ++ show (k', idx + numRanNodes) ++ " ," ++ show idxsFields' ++ ", fieldLocs: " ++ show fieldLocs ) idxsFields' fieldConstraints = (mapMaybe afterVar $ zip3 dcArgFields @@ -1282,10 +1288,10 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = (sptrs, []) -> error "TODO: add constraints for all the shotcut pointers!\n" ([], hloc:rstlocs) -> do let tagc = AfterTagL (getDconLoc hloc) (getDconLoc d) - let fieldLocVarsAfter = P.map (\(Just idx) -> let fldloc = lookup (k, idx) (getFieldLocs hloc) + let fieldLocVarsAfter = P.map (\(Just idx) -> let fldloc = lookup (k', idx + numRanNodes) (getFieldLocs hloc) in case fldloc of Just location -> Just location - Nothing -> error $ "inferExp: fieldLocVars did not expect Nothing! Datacon: " ++ k ++ "," ++ show idxsFields' ++ ", fieldLocs: " ++ show (hloc, locs, (getFieldLocs hloc), DataConE () k ls) + Nothing -> error $ "inferExp: fieldLocVars did not expect Nothing! Datacon: " ++ k' ++ "," ++ show idxsFields' ++ ", fieldLocs: " ++ show (hloc, locs, (getFieldLocs hloc), DataConE () k ls) ) idxsFields' argLsAfterSoALoc <- forM [a | (a,_,_) <- argsLsFields] $ \arg -> case arg of @@ -1321,7 +1327,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- handle field of other data constructors in the final SoA loc passed to the recursive call. let fields_hloc = getFieldLocs hloc let fields_d = getFieldLocs d - let pair_new_old = concatMap (\(ks@(dcon, idx), loc1) -> if dcon /= k + let pair_new_old = concatMap (\(ks@(dcon, idx), loc1) -> if dcon /= k' then let loc2 = case (L.lookup (dcon, idx) fields_d) of Just loc2 -> loc2 diff --git a/gibbon-compiler/tests/BenchRunner.hs b/gibbon-compiler/tests/BenchRunner.hs index b6ff06a75..61f252935 100644 --- a/gibbon-compiler/tests/BenchRunner.hs +++ b/gibbon-compiler/tests/BenchRunner.hs @@ -76,7 +76,7 @@ bench_main :: TestConfig -> Tests -> IO () bench_main tc (Tests tests) = do putStrLn "Executing BenchRunner...\n" let benchmarks = filter (not . skip) $ filter isBenchmark tests - modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus1, Colobus2, Colobus3] -- Omit MPL for now + modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus1, Colobus2, Colobus3, Colobus4] -- Omit MPL for now results <- mapM (go modesToBench) benchmarks mc <- getHostname let csvs = map (\arg -> intercalate "," (mc:arg)) (concat results) diff --git a/gibbon-compiler/tests/TestRunner.hs b/gibbon-compiler/tests/TestRunner.hs index bccf29098..ad8defe42 100644 --- a/gibbon-compiler/tests/TestRunner.hs +++ b/gibbon-compiler/tests/TestRunner.hs @@ -161,7 +161,7 @@ data Result = Pass | Fail -- Not used atm. -- | Gibbon mode to run programs in -data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus1 | Colobus2 | Colobus3 +data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus1 | Colobus2 | Colobus3 | Colobus4 deriving (Show, Eq, Read, Ord, Bounded, Enum) instance FromJSON Mode where @@ -182,6 +182,7 @@ readMode s = "colobus1" -> Colobus1 "colobus2" -> Colobus2 "colobus3" -> Colobus3 + "colobus4" -> Colobus4 "mpl" -> MPL _ -> error $ "readMode: " ++ show s @@ -190,6 +191,7 @@ modeRunFlags :: Mode -> [String] modeRunFlags Colobus1 = ["--run", "--packed", "--gibbon1", "--SoA"] modeRunFlags Colobus2 = ["--run", "--packed", "--no-rcopies", "--no-ran", "--SoA"] modeRunFlags Colobus3 = ["--run", "--packed", "--no-gc", "--no-ran", "--SoA"] +modeRunFlags Colobus4 = ["--run", "--packed", "--no-gc", "--SoA"] modeRunFlags Gibbon3 = ["--run", "--packed", "--gen-gc"] modeRunFlags Gibbon2 = ["--run", "--packed"] modeRunFlags Pointer = ["--run", "--pointer"] @@ -201,7 +203,8 @@ modeRunFlags MPL = ["--mpl-run"] modeExeFlags :: Mode -> [String] modeExeFlags Colobus1 = ["--to-exe", "--packed", "--gibbon1", "--SoA"] modeExeFlags Colobus2 = ["--to-exe", "--packed", "--no-rcopies", "--no-ran", "--SoA"] -modeExeFlags Colobus2 = ["--to-exe", "--packed", "--no-gc", "--no-ran", "--SoA"] +modeExeFlags Colobus3 = ["--to-exe", "--packed", "--no-gc", "--no-ran", "--SoA"] +modeExeFlags Colobus4 = ["--to-exe", "--packed", "--no-gc", "--SoA"] modeExeFlags Gibbon3 = ["--to-exe", "--packed", "--gen-gc"] modeExeFlags Gibbon2 = ["--to-exe", "--packed"] modeExeFlags Pointer = ["--to-exe", "--pointer"] @@ -213,6 +216,7 @@ modeFileSuffix :: Mode -> String modeFileSuffix Colobus1 = "_colobus1" modeFileSuffix Colobus2 = "_colobus2" modeFileSuffix Colobus3 = "_colobus3" +modeFileSuffix Colobus4 = "_colobus4" modeFileSuffix Gibbon3 = "_gibbon3" modeFileSuffix Gibbon2 = "_gibbon2" modeFileSuffix Pointer = "_ptr" diff --git a/gibbon-compiler/tests/test-gibbon-examples.yaml b/gibbon-compiler/tests/test-gibbon-examples.yaml index 65807b57a..fcbeb87f8 100644 --- a/gibbon-compiler/tests/test-gibbon-examples.yaml +++ b/gibbon-compiler/tests/test-gibbon-examples.yaml @@ -71,15 +71,15 @@ tests: - name: test11f_funrec.gib - name: test11_fundata.gib - name: test12b_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] - name: test12c_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] - name: test13b_build.gib - name: test13_build.gib - name: Test185.hs answer-file: examples/Test185.ans # Scalar fields after packed not allowed - failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] - name: SS.hs dir: examples/gc answer-file: examples/gc/SS.ans @@ -137,11 +137,11 @@ tests: - name: test29b_list.gib - name: test30_twitter.gib # ThreadRegions bug. - failing: [colobus1, colobus2, colobus3] + failing: [colobus1, colobus2, colobus3, colobus4] - name: test_buildstree.gib - name: test_buildtree.gib - name: test_buildtreesum.gib - failing: [colobus1, colobus2, colobus3] + failing: [colobus1, colobus2, colobus3, colobus4] - name: test_ddtree.gib - name: test_stree.gib - name: test_sumstree.gib @@ -258,7 +258,7 @@ tests: - name: Poly1.hs dir: examples/poly answer-file: examples/poly/Poly1.ans - failing: [gibbon1, gibbon2, gibbon3, interp1,colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, interp1,colobus1, colobus2, colobus3, colobus4] # - name: measure_mode.hs # answer-file: examples/measure_mode.ans @@ -288,7 +288,7 @@ tests: dir: examples/poly answer-file: examples/poly/CurriedFns.ans skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] - name: T127.hs dir: examples/poly @@ -308,19 +308,19 @@ tests: - name: unariser_bug1.hs answer-file: examples/unariser_bug1.ans - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] skip: true - name: ParseLinearTypes.hs test-flags: ["--ghc-tc"] dir: examples/lineartypes/ - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] - name: EqBench.hs answer-file: examples/EqBench.ans - name: test_parse.hs - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] - name: toplevel_value.hs answer-file: examples/toplevel_value.ans @@ -371,7 +371,7 @@ tests: ## FAILING: Scalar field after a packed field. - name: test12_skip.gib - failing: [gibbon1, colobus1, colobus2, colobus3] + failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] skip: true - name: test12b_traverse.gib skip: true @@ -401,7 +401,7 @@ tests: skip: true - name: test29d_list.gib skip: true - failing: [gibbon1, colobus1, colobus2, colobus3] + failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] - name: test_unpacking.gib skip: true @@ -409,46 +409,46 @@ tests: ## Shouldn't typecheck - name: Fail1.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] - name: Fail2.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] - name: Fail3.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] ## Fusion2 tests - name: test_sumup_seteven.gib skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] test-flags: ["--fusion"] - name: render_tree.hs dir: examples/fusion-benchmarks skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree.ans - name: render_tree_two_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_two_passes.ans - name: render_tree_four_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_four_passes.ans - name: render_tree_five_passes.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, pointer, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, pointer, colobus1, colobus2, colobus3, colobus4] ## [2020.05.27]: It never finishes on Travis... skip: true test-flags: ["--fusion"] @@ -456,7 +456,7 @@ tests: - name: LC.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] test-flags: ["--fusion"] skip: true # gibbon2: segfaults in free_region @@ -494,29 +494,29 @@ tests: ## AST benchmarks - name: C1.hs dir: examples/ast - failing: [gibbon1, gibbon2, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, colobus1, colobus2, colobus3, colobus4] answer-file: examples/ast/C1.ans skip: true ## Tests that only work with some backend: - name: test18f_flip.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] - name: pp_projs.gib skip: true - name: test12_skip.gib - failing: [gibbon1, colobus1, colobus2, colobus3] + failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] skip: true # Tests that actually work but we can't generate answers with Racket - name: test08_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] - name: test08b_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] - name: test08c_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] - name: test08d_sharedict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] # - name: test08f_dict.gib # - name: test08f2_dict.gib @@ -524,13 +524,13 @@ tests: # This test depends on real symbols, which we don't support atm. - name: test27b_subst.gib - failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3] + failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] skip: true # printing symbols is broken atm # No gensym, or real symbols. - name: test28_copyprop.gib - failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus1, colobus2, colobus3] + failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus1, colobus2, colobus3, colobus4] # sym-append not implemented in the RTS - name: test15b_symappend.gib @@ -555,15 +555,15 @@ tests: failing: [interp1] - name: test_153.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3, colobus4] answer-file: examples/test_153.ans - name: test_164.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3, colobus4] answer-file: examples/test_164.ans - name: test_166.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3] + failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3, colobus4] answer-file: examples/test_166.ans - name: test_167.hs @@ -580,14 +580,14 @@ tests: - name: test_power.hs answer-file: examples/test_power.ans # gib_alloc_region_on_heap: gib_alloc failed - failing: [gibbon1, colobus1, colobus2, colobus3] + failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] # Vidush: unskip this, thing hangs because of all the debug print statements skip: true - name: test_191.hs answer-file: examples/test_191.ans # Gibbon2 and Gibbon3 modes don't pass the L2 typechecker. - failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus1, colobus2, colobus3] + failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus1, colobus2, colobus3, colobus4] run-modes: ["gibbon2"] #simple SoA benchmarks @@ -598,7 +598,7 @@ tests: - name: tree.hs dir: examples/soa_examples - failing: ["gibbon2", "gibbon3", "interp1"] + failing: ["interp1"] answer-file: examples/soa_examples/test_tree.ans - name: packedList.hs From ffba4ba53fa48ea183016c9f6ef2e749f0d63f60 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 29 Sep 2025 12:37:49 -0400 Subject: [PATCH 27/60] check in file --- .../src/Gibbon/Passes/OptimizeL3.hs | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs diff --git a/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs b/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs new file mode 100644 index 000000000..ac7c51f9f --- /dev/null +++ b/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs @@ -0,0 +1,176 @@ +module Gibbon.Passes.OptimizeL3 (removeReDefs) where + + +import Data.Foldable (foldrM, foldlM) +import qualified Data.List as L +import qualified Data.Map as M +import Gibbon.Common +import Gibbon.L1.Syntax +import Gibbon.L3.Syntax + + +removeReDefs :: Prog3 -> PassM Prog3 +removeReDefs Prog {ddefs, fundefs, mainExp} = do + main' <- case mainExp of + Just (m, t) -> do + m' <- removeReDefsExp (Env2 M.empty funEnv) m + return $ Just (m', t) + Nothing -> return Nothing + fds' <- mapM removeReDefsFn fundefs + return $ Prog ddefs fds' main' + where + funEnv = M.map funTy fundefs + + removeReDefsFn :: FunDef3 -> PassM FunDef3 + removeReDefsFn f@FunDef {funTy, funArgs, funBody} = do + let in_tys = inTys funTy + let env2 = Env2 (M.fromList $ zip funArgs in_tys) funEnv + funBody' <- removeReDefsExp env2 funBody + return $ f {funBody = funBody'} + +removeReDefsExp :: Env2 Var Ty3 -> Exp3 -> PassM Exp3 +removeReDefsExp env ex = + case ex of + LetE (v, locs, ty, rhs) bod -> do + case mblookupVEnv v env of + Nothing -> do + let env' = extendVEnv v ty env + rhs' <- removeReDefsExp env' rhs + bod' <- removeReDefsExp env' bod + pure $ (LetE (v, locs, ty, rhs')) bod' + _ -> do + if v == "_" + then do + let env' = extendVEnv v ty env + rhs' <- removeReDefsExp env' rhs + bod' <- removeReDefsExp env' bod + pure $ (LetE (v, locs, ty, rhs')) bod' + else do + bod' <- removeReDefsExp env bod + pure bod' + MkProdE es -> do + MkProdE <$> mapM go es + + ProjE i e -> ProjE i <$> go e + VarE v -> do + return $ VarE v + LitE {} -> pure ex + CharE {} -> pure ex + FloatE {} -> pure ex + LitSymE {} -> pure ex + AppE f locs args -> AppE f locs <$> mapM go args + PrimAppE pr args -> PrimAppE pr <$> mapM go args + IfE a b c -> do + a' <- go a + b' <- go b + c' <- go c + pure $ IfE a' b' c' + CaseE scrt ls -> do + scrt' <- go scrt + ls' <- + mapM + ( \(dcon, vlocs, rhs) -> do + rhs' <- go rhs + pure $ (dcon, vlocs, rhs') + ) + ls + pure $ CaseE scrt' ls' + DataConE loc dcon args -> DataConE loc dcon <$> mapM go args + TimeIt e ty b -> do + e' <- go e + pure $ TimeIt e' ty b + WithArenaE v e -> do + e' <- go e + pure $ WithArenaE v e' + SpawnE v locs args -> SpawnE v locs <$> mapM go args + SyncE -> pure ex + Ext (RetE ls) -> do + ls' <- mapM go ls + pure $ Ext (RetE ls') + Ext (LetAvail vs bod) -> do + bod' <- go bod + pure $ Ext (LetAvail vs bod') + Ext (ReadScalar s v) -> do + pure $ Ext (ReadScalar s v) + Ext (WriteScalar s v e) -> do + e' <- go e + pure $ Ext (WriteScalar s v e') + Ext (ReadTag v) -> do + pure (Ext $ ReadTag v) + Ext (WriteTag dcon v) -> do + pure (Ext $ WriteTag dcon v) + Ext (TagCursor a b) -> do + pure (Ext $ TagCursor a b) + Ext (WriteTaggedCursor v e) -> do + e' <- go e + pure (Ext $ WriteTaggedCursor v e') + Ext (ReadTaggedCursor v) -> do + pure (Ext $ ReadTaggedCursor v) + Ext (ReadCursor v) -> do + pure (Ext $ ReadCursor v) + Ext (WriteCursor v e) -> do + e' <- go e + pure (Ext $ WriteCursor v e') + Ext (ReadList v ty) -> do + pure (Ext $ ReadList v ty) + Ext (WriteList v e ty) -> do + e' <- go e + pure (Ext $ WriteList v e' ty) + Ext (ReadVector v ty) -> do + pure (Ext $ ReadVector v ty) + Ext (WriteVector v e ty) -> do + e' <- go e + pure (Ext $ WriteVector v e' ty) + Ext (AddCursor v e) -> do + e' <- go e + pure (Ext $ AddCursor v e') + Ext (DerefMutCursor v) -> do + pure (Ext $ DerefMutCursor v) + Ext (SubPtr a b) -> do + pure (Ext $ SubPtr a b) + Ext (NewBuffer _) -> return ex + Ext (ScopedBuffer _) -> return ex + Ext (NewParBuffer _) -> return ex + Ext (ScopedParBuffer _) -> return ex + Ext (EndOfBuffer _) -> return ex + Ext (MMapFileSize v) -> do + pure $ Ext (MMapFileSize v) + Ext (SizeOfPacked a b) -> do + pure (Ext $ SizeOfPacked a b) + Ext (SizeOfScalar v) -> do + pure $ Ext (SizeOfScalar v) + Ext (BoundsCheck i a b) -> do + pure $ Ext (BoundsCheck i a b) + Ext (BoundsCheckVector{}) -> pure ex + Ext (IndirectionBarrier _ (_, _, _, _)) -> pure ex + Ext (BumpArenaRefCount _ _) -> pure ex + Ext NullCursor -> pure ex + Ext GetCilkWorkerNum -> pure ex + Ext (AllocateTagHere v tycon) -> do + pure $ (Ext $ AllocateTagHere v tycon) + Ext (AllocateScalarsHere v) -> do + pure $ (Ext $ AllocateScalarsHere v) + Ext (StartTagAllocation v) -> do + pure $ (Ext $ StartTagAllocation v) + Ext (EndTagAllocation v) -> do + pure $ (Ext $ EndTagAllocation v) + Ext (StartScalarsAllocation v) -> do + pure $ (Ext $ StartScalarsAllocation v) + Ext (EndScalarsAllocation v) -> do + pure $ (Ext $ EndScalarsAllocation v) + Ext (SSPush _ _ _ _) -> pure ex + Ext (SSPop _ _ _) -> pure ex + Ext (Assert e) -> do + e' <- go e + pure $ Ext $ Assert e' + Ext (CastPtr{}) -> pure ex + Ext (MakeCursorArray{}) -> pure ex + Ext (IndexCursorArray{}) -> pure ex + Ext (AddrOfCursor bod) -> do + bod' <- go bod + return $ Ext (AddrOfCursor bod') + Ext {} -> error $ "addCastsExp : Unexpected instruction " ++ show ex + MapE {} -> error "addCastsExp: MapE TODO" + FoldE {} -> error "addCastsExp: FoldE TODO" + where + go = removeReDefsExp env \ No newline at end of file From 260d04558f26ce7e141db6a4158ef8d7f4b1c54f Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Tue, 7 Oct 2025 13:08:47 -0400 Subject: [PATCH 28/60] edits --- .../examples/soa_examples/MonoTree.c.stack | 1562 +++++++++++++++++ .../examples/soa_examples/MonoTree.hs | 13 +- .../src/Gibbon/Passes/Cursorize.hs | 309 +++- 3 files changed, 1833 insertions(+), 51 deletions(-) create mode 100644 gibbon-compiler/examples/soa_examples/MonoTree.c.stack diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.c.stack b/gibbon-compiler/examples/soa_examples/MonoTree.c.stack new file mode 100644 index 000000000..2f460fb74 --- /dev/null +++ b/gibbon-compiler/examples/soa_examples/MonoTree.c.stack @@ -0,0 +1,1562 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorPtrProd_struct { + GibCursor *field0; + } GibCursorPtrProd; +typedef struct GibCursorPtrGibCursorPtrProd_struct { + GibCursor *field0; + GibCursor *field1; + } GibCursorPtrGibCursorPtrProd; +typedef struct GibCursorPtrGibCursorPtrGibIntProd_struct { + GibCursor *field0; + GibCursor *field1; + GibInt field2; + } GibCursorPtrGibCursorPtrGibIntProd; +typedef struct GibCursorPtrGibCursorPtrGibCursorPtrProd_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibCursor field2[3]; + } GibCursorPtrGibCursorPtrGibCursorPtrProd; +typedef struct GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibCursor field2[3]; + GibCursor field3[3]; + GibCursor field4[3]; + } GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd; +typedef struct GibMutCursorProd_struct { + GibCursor *field0; + } GibMutCursorProd; +GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd +add1Tree(GibCursor cursor_ptr_1299[3], GibCursor cursor_ptr_1298[3], + GibCursor cursor_ptr_1300[3], GibCursor t_22_116_186[3]); +GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd +_copy_Tree(GibCursor *cursor_ptr_1403, GibCursor *cursor_ptr_1402, + GibCursor *cursor_ptr_1404, GibCursor *arg_70_121_195); +GibCursorPtrGibCursorPtrGibIntProd sumTree(GibCursor *cursor_ptr_1506, + GibCursor *tr_27_130_204); +GibCursorPtrGibCursorPtrGibCursorPtrProd mkTree(GibCursor *cursor_ptr_1567, + GibCursor *cursor_ptr_1568, + GibInt d_32_135_212, + GibInt acc_33_136_213); +GibCursorPtrGibCursorPtrProd _traverse_Tree(GibCursor *cursor_ptr_1605, + GibCursor *arg_88_137_221); +GibCursorPtrGibCursorPtrProd _print_Tree(GibCursor *cursor_ptr_1667, + GibCursor *arg_97_144_228); +GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd +_copy_without_ptrs_Tree(GibCursor *cursor_ptr_1730, GibCursor *cursor_ptr_1729, + GibCursor *cursor_ptr_1731, GibCursor *arg_79_161_245); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + Tree_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[3]; + + error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 0); + exit(1); + } + field_tys[0] = Tree_T; + field_tys[1] = Tree_T; + error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(2007, ")"); + gib_add_symbol(2008, "(Node"); + gib_add_symbol(2009, "(Leaf"); + gib_add_symbol(2010, " ->r "); + gib_add_symbol(2011, " ->i "); + gib_add_symbol(2012, " "); +} +GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd add1Tree(GibCursor cursor_ptr_1299[3], + GibCursor cursor_ptr_1298[3], + GibCursor cursor_ptr_1300[3], + GibCursor t_22_116_186[3]) +{ + GibCursor end_r_598 = cursor_ptr_1298[2]; + GibCursor end_r_597 = cursor_ptr_1298[1]; + GibCursor end_r_596 = cursor_ptr_1298[0]; + GibCursor loc_IntTy_591 = cursor_ptr_1300[1]; + GibCursor loc_590 = cursor_ptr_1300[0]; + GibCursor loc_IntTy_592 = cursor_ptr_1300[2]; + + if (loc_IntTy_592 + 38 > end_r_598 || (loc_IntTy_591 + 38 > end_r_597 || + loc_590 + 12 > end_r_596)) { + gib_grow_region(&loc_IntTy_592, &end_r_598); + gib_grow_region(&loc_IntTy_591, &end_r_597); + gib_grow_region(&loc_590, &end_r_596); + } + + + GibCursor dcon_1307 = t_22_116_186[0]; + GibPackedTag tmpval_2050 = *(GibPackedTag *) dcon_1307; + GibCursor tmpcur_2051 = dcon_1307 + 1; + + + switch_2116: + ; + switch (tmpval_2050) { + + case 0: + { + GibCursor soa_field_0_1309 = t_22_116_186[1]; + GibCursor soa_field_1_1310 = t_22_116_186[2]; + GibInt tmpval_2052 = *(GibInt *) soa_field_0_1309; + GibCursor tmpcur_2053 = soa_field_0_1309 + sizeof(GibInt); + GibCursor loc_587 = t_22_116_186[0]; + GibCursor jumpf_dloc_916 = loc_587 + 1; + GibCursor loc_IntTy_588 = t_22_116_186[1]; + GibCursor loc_IntTy_589 = t_22_116_186[2]; + GibCursor jumpf_floc_loc_917 = soa_field_0_1309 + 8; + GibCursor jumpf_floc_loc_918 = loc_IntTy_589 + 0; + GibCursor cursor_ptr_1313_tmp[3] = {jumpf_dloc_916, + jumpf_floc_loc_917, + jumpf_floc_loc_918}; + //GibCursor *cursor_ptr_1313 = gib_array_alloc(cursor_ptr_1313_tmp, + // 3); + GibInt fltPkd_170_188 = tmpval_2052 + 1; + GibCursor loc_710 = loc_IntTy_592 + 0; + GibCursor new_floc_loc_713 = loc_710 + 8; + GibCursor new_dloc_711 = loc_590 + 1; + GibCursor new_floc_loc_712 = loc_IntTy_591 + 0; + + *(GibPackedTag *) loc_590 = 0; + + GibCursor writetag_1314 = loc_590 + 1; + GibCursor after_tag_1315 = loc_590 + 1; + + *(GibInt *) loc_IntTy_591 = fltPkd_170_188; + + GibCursor writecur_1319 = loc_IntTy_591 + sizeof(GibInt); + GibCursor aft_soa_loc_1321_tmp[3] = {after_tag_1315, writecur_1319, + loc_IntTy_592}; + //GibCursor *aft_soa_loc_1321 = gib_array_alloc(aft_soa_loc_1321_tmp, + // 3); + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{cursor_ptr_1299[0], cursor_ptr_1299[1], cursor_ptr_1299[2]}, + {end_r_596, end_r_597, end_r_598}, + {cursor_ptr_1313_tmp[0], cursor_ptr_1313_tmp[1], cursor_ptr_1313_tmp[2]}, + {cursor_ptr_1300[0], cursor_ptr_1300[1], cursor_ptr_1300[2]}, + {aft_soa_loc_1321_tmp[0], aft_soa_loc_1321_tmp[1], aft_soa_loc_1321_tmp[2]}}; + break; + } + + case 1: + { + GibCursor soa_field_0_1325 = t_22_116_186[1]; + GibCursor soa_field_1_1326 = t_22_116_186[2]; + GibInt tmpval_2058 = *(GibInt *) soa_field_1_1326; + GibCursor tmpcur_2059 = soa_field_1_1326 + sizeof(GibInt); + GibCursor cursor_ptr_1306_tmp[3] = {tmpcur_2051, soa_field_0_1325, + tmpcur_2059}; + + //GibCursor *cursor_ptr_1306 = gib_array_alloc(cursor_ptr_1306_tmp, + // 3); + + GibCursor loc_587 = t_22_116_186[0]; + GibCursor jumpf_dloc_920 = loc_587 + 1; + GibCursor loc_IntTy_588 = t_22_116_186[1]; + GibCursor loc_IntTy_589 = t_22_116_186[2]; + GibCursor jumpf_floc_loc_922 = soa_field_1_1326 + 8; + GibCursor jumpf_floc_loc_921 = loc_IntTy_588 + 0; + GibCursor loc_688 = jumpf_dloc_920 + 0; + GibCursor loc_687 = jumpf_floc_loc_922 + 0; + GibCursor loc_686 = jumpf_floc_loc_921 + 0; + GibCursor cursor_ptr_1330_tmp[3] = {jumpf_dloc_920, + jumpf_floc_loc_921, + jumpf_floc_loc_922}; + + //GibCursor *cursor_ptr_1330 = gib_array_alloc(cursor_ptr_1330_tmp, + // 3); + + GibInt fltPkd_171_192 = tmpval_2058 + 1; + GibCursor loc_710 = loc_IntTy_592 + 0; + GibCursor new_floc_loc_713 = loc_710 + 8; + GibCursor new_dloc_711 = loc_590 + 1; + GibCursor new_floc_loc_712 = loc_IntTy_591 + 0; + GibCursor cursor_ptr_1331_tmp[3] = {new_dloc_711, new_floc_loc_712, + new_floc_loc_713}; + + //GibCursor *cursor_ptr_1331 = gib_array_alloc(cursor_ptr_1331_tmp, + // 3); + + *(GibPackedTag *) loc_590 = 1; + + GibCursor writetag_1350 = loc_590 + 1; + GibCursor after_tag_1351 = loc_590 + 1; + + *(GibInt *) loc_IntTy_592 = fltPkd_171_192; + + GibCursor writecur_1355 = loc_IntTy_592 + sizeof(GibInt); + + GibCursor reg_tmp[3] = {end_r_596, end_r_597, end_r_598}; + + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_0 = + add1Tree(cursor_ptr_1299, reg_tmp, cursor_ptr_1331_tmp, cursor_ptr_1306_tmp); + + + GibCursor pvrtmp_2060[3] = {tmp_struct_0.field0[0], tmp_struct_0.field0[1], tmp_struct_0.field0[2]}; + GibCursor pvrtmp_2061[3] = {tmp_struct_0.field1[0], tmp_struct_0.field1[1], tmp_struct_0.field1[2]}; + GibCursor pvrtmp_2062[3] = {tmp_struct_0.field2[0], tmp_struct_0.field2[1], tmp_struct_0.field2[2]}; + GibCursor pvrtmp_2063[3] = {tmp_struct_0.field3[0], tmp_struct_0.field3[1], tmp_struct_0.field3[2]}; + GibCursor pvrtmp_2064[3] = {tmp_struct_0.field4[0], tmp_struct_0.field4[1], tmp_struct_0.field4[2]}; + + + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_1 = + add1Tree(pvrtmp_2060, pvrtmp_2061, pvrtmp_2064, pvrtmp_2062); + + + GibCursor pvrtmp_2069[3] = {tmp_struct_1.field0[0], tmp_struct_1.field0[1], tmp_struct_1.field0[2]}; + GibCursor pvrtmp_2070[3] = {tmp_struct_1.field1[0], tmp_struct_1.field1[1], tmp_struct_1.field1[2]}; + GibCursor pvrtmp_2071[3] = {tmp_struct_1.field2[0], tmp_struct_1.field2[1], tmp_struct_1.field2[2]}; + GibCursor pvrtmp_2072[3] = {tmp_struct_1.field3[0], tmp_struct_1.field3[1], tmp_struct_1.field3[2]}; + GibCursor pvrtmp_2073[3] = {tmp_struct_1.field4[0], tmp_struct_1.field4[1], tmp_struct_1.field4[2]}; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{pvrtmp_2069[0], pvrtmp_2069[1], pvrtmp_2069[2]}, + {pvrtmp_2070[0], pvrtmp_2070[1], pvrtmp_2070[2]}, + {pvrtmp_2071[0], pvrtmp_2071[1], pvrtmp_2071[2]}, + {cursor_ptr_1300[0], cursor_ptr_1300[1], cursor_ptr_1300[2]}, + {pvrtmp_2073[0], pvrtmp_2073[1], pvrtmp_2073[2]}}; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1363 = t_22_116_186[1]; + GibCursor soa_field_1_1364 = t_22_116_186[2]; + uintptr_t tagged_tmpcur_3 = *(uintptr_t *) tmpcur_2051; + GibCursor tmpcur_2082 = GIB_UNTAG(tagged_tmpcur_3); + GibCursor tmpaftercur_2083 = tmpcur_2051 + 8; + uint16_t tmptag_2084 = GIB_GET_TAG(tagged_tmpcur_3); + GibCursor *cursor_ptr_1304 = (GibCursor *) tmpcur_2082; + GibCursor loc_587 = t_22_116_186[0]; + GibCursor jump_dloc_1023 = loc_587 + 9; + GibCursor loc_IntTy_589 = t_22_116_186[2]; + GibCursor loc_IntTy_588 = t_22_116_186[1]; + GibCursor cursor_ptr_1368_tmp[3] = {jump_dloc_1023, loc_IntTy_588, + loc_IntTy_589}; + + //GibCursor *cursor_ptr_1368 = gib_array_alloc(cursor_ptr_1368_tmp, + // 3); + + GibCursor reg_tmp[3] = {end_r_596, end_r_597, end_r_598}; + + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_2 = + add1Tree(cursor_ptr_1304, reg_tmp, cursor_ptr_1300, cursor_ptr_1304); + GibCursor *pvrtmp_2085 = tmp_struct_2.field0; + GibCursor *pvrtmp_2086 = tmp_struct_2.field1; + GibCursor *pvrtmp_2087 = tmp_struct_2.field2; + GibCursor *pvrtmp_2088 = tmp_struct_2.field3; + GibCursor *pvrtmp_2089 = tmp_struct_2.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{cursor_ptr_1299[0], cursor_ptr_1299[1], cursor_ptr_1299[2]}, + {pvrtmp_2086[0], pvrtmp_2086[1], pvrtmp_2086[2]}, + {cursor_ptr_1368_tmp[0], cursor_ptr_1368_tmp[1], cursor_ptr_1368_tmp[2]}, + {pvrtmp_2088[0], pvrtmp_2088[1], pvrtmp_2088[2]}, + {pvrtmp_2089[0], pvrtmp_2089[1], pvrtmp_2089[2]}}; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1379 = t_22_116_186[1]; + GibCursor soa_field_1_1380 = t_22_116_186[2]; + uintptr_t tagged_tmpcur_7 = *(uintptr_t *) tmpcur_2051; + GibCursor tmpcur_2096 = GIB_UNTAG(tagged_tmpcur_7); + GibCursor tmpaftercur_2097 = tmpcur_2051 + 8; + uint16_t tmptag_2098 = GIB_GET_TAG(tagged_tmpcur_7); + GibCursor end_from_tagged_dcon_redir_1388 = tmpcur_2096 + + tmptag_2098; + GibCursor field_nxt_1386 = soa_field_0_1379 + 1; + uintptr_t tagged_tmpcur_6 = *(uintptr_t *) field_nxt_1386; + GibCursor tmpcur_2099 = GIB_UNTAG(tagged_tmpcur_6); + GibCursor tmpaftercur_2100 = field_nxt_1386 + 8; + uint16_t tmptag_2101 = GIB_GET_TAG(tagged_tmpcur_6); + GibCursor end_from_tagged_fld_redir_1389 = tmpcur_2099 + + tmptag_2101; + GibCursor field_nxt_1387 = soa_field_1_1380 + 1; + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) field_nxt_1387; + GibCursor tmpcur_2102 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_2103 = field_nxt_1387 + 8; + uint16_t tmptag_2104 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_fld_redir_1390 = tmpcur_2102 + + tmptag_2104; + GibCursor indr_1016_tmp[3] = {tmpcur_2096, tmpcur_2099, + tmpcur_2102}; + //GibCursor *indr_1016 = gib_array_alloc(indr_1016_tmp, 3); + GibCursor copy_dloc_1031 = loc_590 + 0; + GibCursor copy_floc_loc_1033 = loc_IntTy_592 + 0; + GibCursor copy_floc_loc_1032 = loc_IntTy_591 + 0; + GibCursor cursor_ptr_1391_tmp[3] = {copy_dloc_1031, + copy_floc_loc_1032, + copy_floc_loc_1033}; + //GibCursor *cursor_ptr_1391 = gib_array_alloc(cursor_ptr_1391_tmp, + // 3); + + GibCursor reg_tmp[3] = {end_r_596, end_r_597, end_r_598}; + + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_4 = + add1Tree(indr_1016_tmp, reg_tmp , cursor_ptr_1391_tmp, indr_1016_tmp); + GibCursor *pvrtmp_2105 = tmp_struct_4.field0; + GibCursor *pvrtmp_2106 = tmp_struct_4.field1; + GibCursor *pvrtmp_2107 = tmp_struct_4.field2; + GibCursor *pvrtmp_2108 = tmp_struct_4.field3; + GibCursor *pvrtmp_2109 = tmp_struct_4.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{pvrtmp_2105[0], pvrtmp_2105[1], pvrtmp_2105[2]}, + {pvrtmp_2106[0], pvrtmp_2106[1], pvrtmp_2106[2]}, + {pvrtmp_2107[0], pvrtmp_2107[1], pvrtmp_2107[2]}, + {pvrtmp_2108[0], pvrtmp_2108[1], pvrtmp_2108[2]}, + {pvrtmp_2109[0], pvrtmp_2109[1], pvrtmp_2109[2]}}; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2050"); + exit(1); + } + } +} +GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd _copy_Tree(GibCursor *cursor_ptr_1403, + GibCursor *cursor_ptr_1402, + GibCursor *cursor_ptr_1404, + GibCursor *arg_70_121_195) +{ + GibCursor *end_r_610 = &cursor_ptr_1402[2]; + GibCursor *end_r_609 = &cursor_ptr_1402[1]; + GibCursor *end_r_608 = &cursor_ptr_1402[0]; + GibCursor loc_IntTy_604 = cursor_ptr_1404[2]; + GibCursor loc_602 = cursor_ptr_1404[0]; + GibCursor loc_IntTy_603 = cursor_ptr_1404[1]; + GibCursor deref_1405 = *end_r_610; + GibCursor deref_1406 = *end_r_609; + GibCursor deref_1407 = *end_r_608; + + if (loc_IntTy_604 + 38 > deref_1405 || (loc_IntTy_603 + 38 > deref_1406 || + loc_602 + 12 > deref_1407)) { + gib_grow_region(&loc_IntTy_604, end_r_610); + gib_grow_region(&loc_IntTy_603, end_r_609); + gib_grow_region(&loc_602, end_r_608); + } + + GibCursor *end_r_605 = &cursor_ptr_1403[0]; + GibCursor *end_r_606 = &cursor_ptr_1403[1]; + GibCursor *end_r_607 = &cursor_ptr_1403[2]; + GibCursor dcon_1411 = arg_70_121_195[0]; + GibPackedTag tmpval_2117 = *(GibPackedTag *) dcon_1411; + GibCursor tmpcur_2118 = dcon_1411 + 1; + + + switch_2183: + ; + switch (tmpval_2117) { + + case 0: + { + GibCursor soa_field_0_1413 = arg_70_121_195[1]; + GibCursor soa_field_1_1414 = arg_70_121_195[2]; + GibInt tmpval_2119 = *(GibInt *) soa_field_0_1413; + GibCursor tmpcur_2120 = soa_field_0_1413 + sizeof(GibInt); + GibCursor loc_599 = arg_70_121_195[0]; + GibCursor jumpf_dloc_930 = loc_599 + 1; + GibCursor loc_IntTy_600 = arg_70_121_195[1]; + GibCursor loc_IntTy_601 = arg_70_121_195[2]; + GibCursor jumpf_floc_loc_931 = soa_field_0_1413 + 8; + GibCursor jumpf_floc_loc_932 = loc_IntTy_601 + 0; + GibCursor cursor_ptr_1417_tmp[3] = {jumpf_dloc_930, + jumpf_floc_loc_931, + jumpf_floc_loc_932}; + GibCursor *cursor_ptr_1417 = gib_array_alloc(cursor_ptr_1417_tmp, + 3); + GibCursor loc_756 = loc_IntTy_604 + 0; + GibCursor new_floc_loc_759 = loc_756 + 8; + GibCursor new_dloc_757 = loc_602 + 1; + GibCursor new_floc_loc_758 = loc_IntTy_603 + 0; + + *(GibPackedTag *) loc_602 = 0; + + GibCursor writetag_1418 = loc_602 + 1; + GibCursor after_tag_1419 = loc_602 + 1; + + *(GibInt *) loc_IntTy_603 = tmpval_2119; + + GibCursor writecur_1423 = loc_IntTy_603 + sizeof(GibInt); + GibCursor aft_soa_loc_1425_tmp[3] = {after_tag_1419, writecur_1423, + loc_IntTy_604}; + GibCursor *aft_soa_loc_1425 = gib_array_alloc(aft_soa_loc_1425_tmp, + 3); + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1403, + cursor_ptr_1402, + cursor_ptr_1417, + cursor_ptr_1404, + aft_soa_loc_1425}; + break; + } + + case 1: + { + GibCursor soa_field_0_1429 = arg_70_121_195[1]; + GibCursor soa_field_1_1430 = arg_70_121_195[2]; + GibInt tmpval_2125 = *(GibInt *) soa_field_1_1430; + GibCursor tmpcur_2126 = soa_field_1_1430 + sizeof(GibInt); + GibCursor cursor_ptr_1410_tmp[3] = {tmpcur_2118, soa_field_0_1429, + tmpcur_2126}; + GibCursor *cursor_ptr_1410 = gib_array_alloc(cursor_ptr_1410_tmp, + 3); + GibCursor loc_599 = arg_70_121_195[0]; + GibCursor jumpf_dloc_934 = loc_599 + 1; + GibCursor loc_IntTy_600 = arg_70_121_195[1]; + GibCursor loc_IntTy_601 = arg_70_121_195[2]; + GibCursor jumpf_floc_loc_936 = soa_field_1_1430 + 8; + GibCursor jumpf_floc_loc_935 = loc_IntTy_600 + 0; + GibCursor loc_734 = jumpf_dloc_934 + 0; + GibCursor loc_733 = jumpf_floc_loc_936 + 0; + GibCursor loc_732 = jumpf_floc_loc_935 + 0; + GibCursor cursor_ptr_1434_tmp[3] = {jumpf_dloc_934, + jumpf_floc_loc_935, + jumpf_floc_loc_936}; + GibCursor *cursor_ptr_1434 = gib_array_alloc(cursor_ptr_1434_tmp, + 3); + GibCursor loc_756 = loc_IntTy_604 + 0; + GibCursor new_floc_loc_759 = loc_756 + 8; + GibCursor new_dloc_757 = loc_602 + 1; + GibCursor new_floc_loc_758 = loc_IntTy_603 + 0; + GibCursor cursor_ptr_1435_tmp[3] = {new_dloc_757, new_floc_loc_758, + new_floc_loc_759}; + GibCursor *cursor_ptr_1435 = gib_array_alloc(cursor_ptr_1435_tmp, + 3); + + *(GibPackedTag *) loc_602 = 1; + + GibCursor writetag_1454 = loc_602 + 1; + GibCursor after_tag_1455 = loc_602 + 1; + + *(GibInt *) loc_IntTy_604 = tmpval_2125; + + GibCursor writecur_1459 = loc_IntTy_604 + sizeof(GibInt); + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_8 = + _copy_Tree(cursor_ptr_1403, cursor_ptr_1402, cursor_ptr_1435, cursor_ptr_1410); + GibCursor *pvrtmp_2127 = tmp_struct_8.field0; + GibCursor *pvrtmp_2128 = tmp_struct_8.field1; + GibCursor *pvrtmp_2129 = tmp_struct_8.field2; + GibCursor *pvrtmp_2130 = tmp_struct_8.field3; + GibCursor *pvrtmp_2131 = tmp_struct_8.field4; + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_9 = + _copy_Tree(pvrtmp_2127, pvrtmp_2128, pvrtmp_2131, pvrtmp_2129); + GibCursor *pvrtmp_2136 = tmp_struct_9.field0; + GibCursor *pvrtmp_2137 = tmp_struct_9.field1; + GibCursor *pvrtmp_2138 = tmp_struct_9.field2; + GibCursor *pvrtmp_2139 = tmp_struct_9.field3; + GibCursor *pvrtmp_2140 = tmp_struct_9.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2136, + pvrtmp_2137, + pvrtmp_2138, + cursor_ptr_1404, + pvrtmp_2140}; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1467 = arg_70_121_195[1]; + GibCursor soa_field_1_1468 = arg_70_121_195[2]; + uintptr_t tagged_tmpcur_11 = *(uintptr_t *) tmpcur_2118; + GibCursor tmpcur_2149 = GIB_UNTAG(tagged_tmpcur_11); + GibCursor tmpaftercur_2150 = tmpcur_2118 + 8; + uint16_t tmptag_2151 = GIB_GET_TAG(tagged_tmpcur_11); + GibCursor *cursor_ptr_1408 = (GibCursor *) tmpcur_2149; + GibCursor loc_599 = arg_70_121_195[0]; + GibCursor jump_dloc_1041 = loc_599 + 9; + GibCursor loc_IntTy_601 = arg_70_121_195[2]; + GibCursor loc_IntTy_600 = arg_70_121_195[1]; + GibCursor cursor_ptr_1472_tmp[3] = {jump_dloc_1041, loc_IntTy_600, + loc_IntTy_601}; + GibCursor *cursor_ptr_1472 = gib_array_alloc(cursor_ptr_1472_tmp, + 3); + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_10 = + _copy_Tree(cursor_ptr_1408, cursor_ptr_1402, cursor_ptr_1404, cursor_ptr_1408); + GibCursor *pvrtmp_2152 = tmp_struct_10.field0; + GibCursor *pvrtmp_2153 = tmp_struct_10.field1; + GibCursor *pvrtmp_2154 = tmp_struct_10.field2; + GibCursor *pvrtmp_2155 = tmp_struct_10.field3; + GibCursor *pvrtmp_2156 = tmp_struct_10.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1403, + pvrtmp_2153, + cursor_ptr_1472, + pvrtmp_2155, + pvrtmp_2156}; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1483 = arg_70_121_195[1]; + GibCursor soa_field_1_1484 = arg_70_121_195[2]; + uintptr_t tagged_tmpcur_15 = *(uintptr_t *) tmpcur_2118; + GibCursor tmpcur_2163 = GIB_UNTAG(tagged_tmpcur_15); + GibCursor tmpaftercur_2164 = tmpcur_2118 + 8; + uint16_t tmptag_2165 = GIB_GET_TAG(tagged_tmpcur_15); + GibCursor end_from_tagged_dcon_redir_1492 = tmpcur_2163 + + tmptag_2165; + GibCursor field_nxt_1490 = soa_field_0_1483 + 1; + uintptr_t tagged_tmpcur_14 = *(uintptr_t *) field_nxt_1490; + GibCursor tmpcur_2166 = GIB_UNTAG(tagged_tmpcur_14); + GibCursor tmpaftercur_2167 = field_nxt_1490 + 8; + uint16_t tmptag_2168 = GIB_GET_TAG(tagged_tmpcur_14); + GibCursor end_from_tagged_fld_redir_1493 = tmpcur_2166 + + tmptag_2168; + GibCursor field_nxt_1491 = soa_field_1_1484 + 1; + uintptr_t tagged_tmpcur_13 = *(uintptr_t *) field_nxt_1491; + GibCursor tmpcur_2169 = GIB_UNTAG(tagged_tmpcur_13); + GibCursor tmpaftercur_2170 = field_nxt_1491 + 8; + uint16_t tmptag_2171 = GIB_GET_TAG(tagged_tmpcur_13); + GibCursor end_from_tagged_fld_redir_1494 = tmpcur_2169 + + tmptag_2171; + GibCursor indr_1034_tmp[3] = {tmpcur_2163, tmpcur_2166, + tmpcur_2169}; + GibCursor *indr_1034 = gib_array_alloc(indr_1034_tmp, 3); + GibCursor copy_dloc_1049 = loc_602 + 0; + GibCursor copy_floc_loc_1051 = loc_IntTy_604 + 0; + GibCursor copy_floc_loc_1050 = loc_IntTy_603 + 0; + GibCursor cursor_ptr_1495_tmp[3] = {copy_dloc_1049, + copy_floc_loc_1050, + copy_floc_loc_1051}; + GibCursor *cursor_ptr_1495 = gib_array_alloc(cursor_ptr_1495_tmp, + 3); + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_12 = + _copy_Tree(indr_1034, cursor_ptr_1402, cursor_ptr_1495, indr_1034); + GibCursor *pvrtmp_2172 = tmp_struct_12.field0; + GibCursor *pvrtmp_2173 = tmp_struct_12.field1; + GibCursor *pvrtmp_2174 = tmp_struct_12.field2; + GibCursor *pvrtmp_2175 = tmp_struct_12.field3; + GibCursor *pvrtmp_2176 = tmp_struct_12.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2172, + pvrtmp_2173, + pvrtmp_2174, + pvrtmp_2175, + pvrtmp_2176}; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2117"); + exit(1); + } + } +} +GibCursorPtrGibCursorPtrGibIntProd sumTree(GibCursor *cursor_ptr_1506, + GibCursor *tr_27_130_204) +{ + GibCursor *end_r_614 = &cursor_ptr_1506[0]; + GibCursor *end_r_615 = &cursor_ptr_1506[1]; + GibCursor *end_r_616 = &cursor_ptr_1506[2]; + GibCursor dcon_1510 = tr_27_130_204[0]; + GibPackedTag tmpval_2184 = *(GibPackedTag *) dcon_1510; + GibCursor tmpcur_2185 = dcon_1510 + 1; + + + switch_2214: + ; + switch (tmpval_2184) { + + case 0: + { + GibCursor soa_field_0_1512 = tr_27_130_204[1]; + GibCursor soa_field_1_1513 = tr_27_130_204[2]; + GibInt tmpval_2186 = *(GibInt *) soa_field_0_1512; + GibCursor tmpcur_2187 = soa_field_0_1512 + sizeof(GibInt); + GibCursor loc_611 = tr_27_130_204[0]; + GibCursor jumpf_dloc_944 = loc_611 + 1; + GibCursor loc_IntTy_612 = tr_27_130_204[1]; + GibCursor loc_IntTy_613 = tr_27_130_204[2]; + GibCursor jumpf_floc_loc_945 = soa_field_0_1512 + 8; + GibCursor jumpf_floc_loc_946 = loc_IntTy_613 + 0; + GibCursor cursor_ptr_1516_tmp[3] = {jumpf_dloc_944, + jumpf_floc_loc_945, + jumpf_floc_loc_946}; + GibCursor *cursor_ptr_1516 = gib_array_alloc(cursor_ptr_1516_tmp, + 3); + + return (GibCursorPtrGibCursorPtrGibIntProd) {cursor_ptr_1506, + cursor_ptr_1516, + tmpval_2186}; + break; + } + + case 1: + { + GibCursor soa_field_0_1518 = tr_27_130_204[1]; + GibCursor soa_field_1_1519 = tr_27_130_204[2]; + GibInt tmpval_2188 = *(GibInt *) soa_field_1_1519; + GibCursor tmpcur_2189 = soa_field_1_1519 + sizeof(GibInt); + GibCursor cursor_ptr_1509_tmp[3] = {tmpcur_2185, soa_field_0_1518, + tmpcur_2189}; + GibCursor *cursor_ptr_1509 = gib_array_alloc(cursor_ptr_1509_tmp, + 3); + GibCursor loc_611 = tr_27_130_204[0]; + GibCursor jumpf_dloc_947 = loc_611 + 1; + GibCursor loc_IntTy_612 = tr_27_130_204[1]; + GibCursor loc_IntTy_613 = tr_27_130_204[2]; + GibCursor jumpf_floc_loc_949 = soa_field_1_1519 + 8; + GibCursor jumpf_floc_loc_948 = loc_IntTy_612 + 0; + GibCursor loc_777 = jumpf_dloc_947 + 0; + GibCursor loc_776 = jumpf_floc_loc_949 + 0; + GibCursor loc_775 = jumpf_floc_loc_948 + 0; + GibCursor cursor_ptr_1523_tmp[3] = {jumpf_dloc_947, + jumpf_floc_loc_948, + jumpf_floc_loc_949}; + GibCursor *cursor_ptr_1523 = gib_array_alloc(cursor_ptr_1523_tmp, + 3); + GibCursorPtrGibCursorPtrGibIntProd tmp_struct_16 = + sumTree(cursor_ptr_1506, cursor_ptr_1509); + GibCursor *pvrtmp_2190 = tmp_struct_16.field0; + GibCursor *pvrtmp_2191 = tmp_struct_16.field1; + GibInt pvrtmp_2192 = tmp_struct_16.field2; + GibInt fltPrm_174_210 = tmpval_2188 + pvrtmp_2192; + GibCursorPtrGibCursorPtrGibIntProd tmp_struct_17 = + sumTree(pvrtmp_2190, pvrtmp_2191); + GibCursor *pvrtmp_2193 = tmp_struct_17.field0; + GibCursor *pvrtmp_2194 = tmp_struct_17.field1; + GibInt pvrtmp_2195 = tmp_struct_17.field2; + GibInt tailprim_956 = fltPrm_174_210 + pvrtmp_2195; + + return (GibCursorPtrGibCursorPtrGibIntProd) {pvrtmp_2193, + pvrtmp_2194, + tailprim_956}; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1536 = tr_27_130_204[1]; + GibCursor soa_field_1_1537 = tr_27_130_204[2]; + uintptr_t tagged_tmpcur_19 = *(uintptr_t *) tmpcur_2185; + GibCursor tmpcur_2196 = GIB_UNTAG(tagged_tmpcur_19); + GibCursor tmpaftercur_2197 = tmpcur_2185 + 8; + uint16_t tmptag_2198 = GIB_GET_TAG(tagged_tmpcur_19); + GibCursor *cursor_ptr_1507 = (GibCursor *) tmpcur_2196; + GibCursor loc_611 = tr_27_130_204[0]; + GibCursor jump_dloc_1059 = loc_611 + 9; + GibCursor loc_IntTy_613 = tr_27_130_204[2]; + GibCursor loc_IntTy_612 = tr_27_130_204[1]; + GibCursor cursor_ptr_1541_tmp[3] = {jump_dloc_1059, loc_IntTy_612, + loc_IntTy_613}; + GibCursor *cursor_ptr_1541 = gib_array_alloc(cursor_ptr_1541_tmp, + 3); + GibCursorPtrGibCursorPtrGibIntProd tmp_struct_18 = + sumTree(cursor_ptr_1507, cursor_ptr_1507); + GibCursor *pvrtmp_2199 = tmp_struct_18.field0; + GibCursor *pvrtmp_2200 = tmp_struct_18.field1; + GibInt pvrtmp_2201 = tmp_struct_18.field2; + + return (GibCursorPtrGibCursorPtrGibIntProd) {cursor_ptr_1506, + cursor_ptr_1541, + pvrtmp_2201}; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1549 = tr_27_130_204[1]; + GibCursor soa_field_1_1550 = tr_27_130_204[2]; + uintptr_t tagged_tmpcur_23 = *(uintptr_t *) tmpcur_2185; + GibCursor tmpcur_2202 = GIB_UNTAG(tagged_tmpcur_23); + GibCursor tmpaftercur_2203 = tmpcur_2185 + 8; + uint16_t tmptag_2204 = GIB_GET_TAG(tagged_tmpcur_23); + GibCursor end_from_tagged_dcon_redir_1558 = tmpcur_2202 + + tmptag_2204; + GibCursor field_nxt_1556 = soa_field_0_1549 + 1; + uintptr_t tagged_tmpcur_22 = *(uintptr_t *) field_nxt_1556; + GibCursor tmpcur_2205 = GIB_UNTAG(tagged_tmpcur_22); + GibCursor tmpaftercur_2206 = field_nxt_1556 + 8; + uint16_t tmptag_2207 = GIB_GET_TAG(tagged_tmpcur_22); + GibCursor end_from_tagged_fld_redir_1559 = tmpcur_2205 + + tmptag_2207; + GibCursor field_nxt_1557 = soa_field_1_1550 + 1; + uintptr_t tagged_tmpcur_21 = *(uintptr_t *) field_nxt_1557; + GibCursor tmpcur_2208 = GIB_UNTAG(tagged_tmpcur_21); + GibCursor tmpaftercur_2209 = field_nxt_1557 + 8; + uint16_t tmptag_2210 = GIB_GET_TAG(tagged_tmpcur_21); + GibCursor end_from_tagged_fld_redir_1560 = tmpcur_2208 + + tmptag_2210; + GibCursor indr_1052_tmp[3] = {tmpcur_2202, tmpcur_2205, + tmpcur_2208}; + GibCursor *indr_1052 = gib_array_alloc(indr_1052_tmp, 3); + GibCursorPtrGibCursorPtrGibIntProd tmp_struct_20 = + sumTree(indr_1052, indr_1052); + GibCursor *pvrtmp_2211 = tmp_struct_20.field0; + GibCursor *pvrtmp_2212 = tmp_struct_20.field1; + GibInt pvrtmp_2213 = tmp_struct_20.field2; + + return (GibCursorPtrGibCursorPtrGibIntProd) {pvrtmp_2211, + pvrtmp_2212, + pvrtmp_2213}; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2184"); + exit(1); + } + } +} +GibCursorPtrGibCursorPtrGibCursorPtrProd mkTree(GibCursor cursor_ptr_1567[3], + GibCursor cursor_ptr_1568[3], + GibInt d_32_135_212, + GibInt acc_33_136_213) +{ + GibCursor end_r_622 = cursor_ptr_1567[2]; + GibCursor end_r_621 = cursor_ptr_1567[1]; + GibCursor end_r_620 = cursor_ptr_1567[0]; + GibCursor loc_617 = cursor_ptr_1568[0]; + GibCursor loc_IntTy_619 = cursor_ptr_1568[2]; + GibCursor loc_IntTy_618 = cursor_ptr_1568[1]; + GibCursor deref_1569 = end_r_622; + GibCursor deref_1570 = end_r_621; + GibCursor deref_1571 = end_r_620; + + if (loc_IntTy_619 + 38 > deref_1569 || (loc_IntTy_618 + 38 > deref_1570 || + loc_617 + 12 > deref_1571)) { + gib_grow_region(&loc_IntTy_619, &end_r_622); + gib_grow_region(&loc_IntTy_618, &end_r_621); + gib_grow_region(&loc_617, &end_r_620); + } + + GibBool fltIf_177_214 = d_32_135_212 == 0; + + if (fltIf_177_214) { + GibCursor new_floc_loc_804 = loc_IntTy_618 + 0; + GibCursor loc_802 = loc_IntTy_619 + 0; + GibCursor new_floc_loc_805 = loc_802 + 8; + GibCursor new_dloc_803 = loc_617 + 1; + + *(GibPackedTag *) loc_617 = 0; + + GibCursor writetag_1572 = loc_617 + 1; + GibCursor after_tag_1573 = loc_617 + 1; + + *(GibInt *) loc_IntTy_618 = acc_33_136_213; + + GibCursor writecur_1577 = loc_IntTy_618 + sizeof(GibInt); + GibCursor aft_soa_loc_1579_tmp[3] = {after_tag_1573, writecur_1577, + loc_IntTy_619}; + //GibCursor *aft_soa_loc_1579 = gib_array_alloc(aft_soa_loc_1579_tmp, 3); + + return (GibCursorPtrGibCursorPtrGibCursorPtrProd) {{end_r_620, end_r_621, end_r_622}, + {cursor_ptr_1568[0], cursor_ptr_1568[1], cursor_ptr_1568[2]}, + {aft_soa_loc_1579_tmp[0], aft_soa_loc_1579_tmp[1], aft_soa_loc_1579_tmp[2]}}; + } else { + GibInt fltAppE_179_215 = d_32_135_212 - 1; + GibInt fltAppE_180_216 = d_32_135_212 + acc_33_136_213; + GibCursor new_floc_loc_804 = loc_IntTy_618 + 0; + GibCursor loc_802 = loc_IntTy_619 + 0; + GibCursor new_floc_loc_805 = loc_802 + 8; + GibCursor new_dloc_803 = loc_617 + 1; + GibCursor cursor_ptr_1582_tmp[3] = {new_dloc_803, new_floc_loc_804, + new_floc_loc_805}; + //GibCursor *cursor_ptr_1582 = gib_array_alloc(cursor_ptr_1582_tmp, 3); + + *(GibPackedTag *) loc_617 = 1; + + GibCursor writetag_1592 = loc_617 + 1; + GibCursor after_tag_1593 = loc_617 + 1; + + *(GibInt *) loc_IntTy_619 = d_32_135_212; + + GibCursor writecur_1597 = loc_IntTy_619 + sizeof(GibInt); + GibCursor newEnds[3] = {end_r_620, end_r_621, end_r_622}; + GibCursorPtrGibCursorPtrGibCursorPtrProd tmp_struct_24 = + mkTree(newEnds, cursor_ptr_1582_tmp, fltAppE_179_215, fltAppE_180_216); + GibCursor pvrtmp_2219[3] = {tmp_struct_24.field0[0], tmp_struct_24.field0[1], tmp_struct_24.field0[2]}; + GibCursor pvrtmp_2220[3] = {tmp_struct_24.field1[0], tmp_struct_24.field1[1], tmp_struct_24.field1[2]}; + GibCursor pvrtmp_2221[3] = {tmp_struct_24.field2[0], tmp_struct_24.field2[1], tmp_struct_24.field2[2]}; + + GibInt fltAppE_182_218 = d_32_135_212 - 1; + GibInt fltAppE_183_219 = d_32_135_212 + acc_33_136_213; + GibCursorPtrGibCursorPtrGibCursorPtrProd tmp_struct_25 = + mkTree(pvrtmp_2219, pvrtmp_2221, fltAppE_182_218, fltAppE_183_219); + GibCursor pvrtmp_2226[3] = {tmp_struct_25.field0[0], tmp_struct_25.field0[1], tmp_struct_25.field0[2]}; + GibCursor pvrtmp_2227[3] = {tmp_struct_25.field1[0], tmp_struct_25.field1[1], tmp_struct_25.field1[2]}; + GibCursor pvrtmp_2228[3] = {tmp_struct_25.field2[0], tmp_struct_25.field2[1], tmp_struct_25.field2[2]}; + + return (GibCursorPtrGibCursorPtrGibCursorPtrProd) {{pvrtmp_2226[0], pvrtmp_2226[1], pvrtmp_2226[2]}, + {cursor_ptr_1568[0], cursor_ptr_1568[1], cursor_ptr_1568[2]}, + {pvrtmp_2228[0], pvrtmp_2228[1], pvrtmp_2228[2]}}; + } +} +GibCursorPtrGibCursorPtrProd _traverse_Tree(GibCursor *cursor_ptr_1605, + GibCursor *arg_88_137_221) +{ + GibCursor *end_r_626 = &cursor_ptr_1605[0]; + GibCursor *end_r_627 = &cursor_ptr_1605[1]; + GibCursor *end_r_628 = &cursor_ptr_1605[2]; + GibCursor dcon_1609 = arg_88_137_221[0]; + GibPackedTag tmpval_2237 = *(GibPackedTag *) dcon_1609; + GibCursor tmpcur_2238 = dcon_1609 + 1; + + + switch_2263: + ; + switch (tmpval_2237) { + + case 0: + { + GibCursor soa_field_0_1611 = arg_88_137_221[1]; + GibCursor soa_field_1_1612 = arg_88_137_221[2]; + GibInt tmpval_2239 = *(GibInt *) soa_field_0_1611; + GibCursor tmpcur_2240 = soa_field_0_1611 + sizeof(GibInt); + GibCursor loc_623 = arg_88_137_221[0]; + GibCursor jumpf_dloc_959 = loc_623 + 1; + GibCursor loc_IntTy_624 = arg_88_137_221[1]; + GibCursor loc_IntTy_625 = arg_88_137_221[2]; + GibCursor jumpf_floc_loc_960 = soa_field_0_1611 + 8; + GibCursor jumpf_floc_loc_961 = loc_IntTy_625 + 0; + GibCursor cursor_ptr_1615_tmp[3] = {jumpf_dloc_959, + jumpf_floc_loc_960, + jumpf_floc_loc_961}; + GibCursor *cursor_ptr_1615 = gib_array_alloc(cursor_ptr_1615_tmp, + 3); + + return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1605, + cursor_ptr_1615}; + break; + } + + case 1: + { + GibCursor soa_field_0_1617 = arg_88_137_221[1]; + GibCursor soa_field_1_1618 = arg_88_137_221[2]; + GibInt tmpval_2241 = *(GibInt *) soa_field_1_1618; + GibCursor tmpcur_2242 = soa_field_1_1618 + sizeof(GibInt); + GibCursor cursor_ptr_1608_tmp[3] = {tmpcur_2238, soa_field_0_1617, + tmpcur_2242}; + GibCursor *cursor_ptr_1608 = gib_array_alloc(cursor_ptr_1608_tmp, + 3); + GibCursor loc_623 = arg_88_137_221[0]; + GibCursor jumpf_dloc_963 = loc_623 + 1; + GibCursor loc_IntTy_624 = arg_88_137_221[1]; + GibCursor loc_IntTy_625 = arg_88_137_221[2]; + GibCursor jumpf_floc_loc_965 = soa_field_1_1618 + 8; + GibCursor jumpf_floc_loc_964 = loc_IntTy_624 + 0; + GibCursor loc_823 = jumpf_dloc_963 + 0; + GibCursor loc_822 = jumpf_floc_loc_965 + 0; + GibCursor loc_821 = jumpf_floc_loc_964 + 0; + GibCursor cursor_ptr_1622_tmp[3] = {jumpf_dloc_963, + jumpf_floc_loc_964, + jumpf_floc_loc_965}; + GibCursor *cursor_ptr_1622 = gib_array_alloc(cursor_ptr_1622_tmp, + 3); + GibCursorPtrGibCursorPtrProd tmp_struct_26 = + _traverse_Tree(cursor_ptr_1605, cursor_ptr_1608); + GibCursor *pvrtmp_2243 = tmp_struct_26.field0; + GibCursor *pvrtmp_2244 = tmp_struct_26.field1; + GibCursorPtrGibCursorPtrProd tmp_struct_27 = + _traverse_Tree(pvrtmp_2243, pvrtmp_2244); + GibCursor *pvrtmp_2245 = tmp_struct_27.field0; + GibCursor *pvrtmp_2246 = tmp_struct_27.field1; + + return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2245, pvrtmp_2246}; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1635 = arg_88_137_221[1]; + GibCursor soa_field_1_1636 = arg_88_137_221[2]; + uintptr_t tagged_tmpcur_29 = *(uintptr_t *) tmpcur_2238; + GibCursor tmpcur_2247 = GIB_UNTAG(tagged_tmpcur_29); + GibCursor tmpaftercur_2248 = tmpcur_2238 + 8; + uint16_t tmptag_2249 = GIB_GET_TAG(tagged_tmpcur_29); + GibCursor *cursor_ptr_1606 = (GibCursor *) tmpcur_2247; + GibCursor loc_623 = arg_88_137_221[0]; + GibCursor jump_dloc_1074 = loc_623 + 9; + GibCursor loc_IntTy_625 = arg_88_137_221[2]; + GibCursor loc_IntTy_624 = arg_88_137_221[1]; + GibCursor cursor_ptr_1640_tmp[3] = {jump_dloc_1074, loc_IntTy_624, + loc_IntTy_625}; + GibCursor *cursor_ptr_1640 = gib_array_alloc(cursor_ptr_1640_tmp, + 3); + GibCursorPtrGibCursorPtrProd tmp_struct_28 = + _traverse_Tree(cursor_ptr_1606, cursor_ptr_1606); + GibCursor *pvrtmp_2250 = tmp_struct_28.field0; + GibCursor *pvrtmp_2251 = tmp_struct_28.field1; + + return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1605, + cursor_ptr_1640}; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1648 = arg_88_137_221[1]; + GibCursor soa_field_1_1649 = arg_88_137_221[2]; + uintptr_t tagged_tmpcur_33 = *(uintptr_t *) tmpcur_2238; + GibCursor tmpcur_2252 = GIB_UNTAG(tagged_tmpcur_33); + GibCursor tmpaftercur_2253 = tmpcur_2238 + 8; + uint16_t tmptag_2254 = GIB_GET_TAG(tagged_tmpcur_33); + GibCursor end_from_tagged_dcon_redir_1657 = tmpcur_2252 + + tmptag_2254; + GibCursor field_nxt_1655 = soa_field_0_1648 + 1; + uintptr_t tagged_tmpcur_32 = *(uintptr_t *) field_nxt_1655; + GibCursor tmpcur_2255 = GIB_UNTAG(tagged_tmpcur_32); + GibCursor tmpaftercur_2256 = field_nxt_1655 + 8; + uint16_t tmptag_2257 = GIB_GET_TAG(tagged_tmpcur_32); + GibCursor end_from_tagged_fld_redir_1658 = tmpcur_2255 + + tmptag_2257; + GibCursor field_nxt_1656 = soa_field_1_1649 + 1; + uintptr_t tagged_tmpcur_31 = *(uintptr_t *) field_nxt_1656; + GibCursor tmpcur_2258 = GIB_UNTAG(tagged_tmpcur_31); + GibCursor tmpaftercur_2259 = field_nxt_1656 + 8; + uint16_t tmptag_2260 = GIB_GET_TAG(tagged_tmpcur_31); + GibCursor end_from_tagged_fld_redir_1659 = tmpcur_2258 + + tmptag_2260; + GibCursor indr_1067_tmp[3] = {tmpcur_2252, tmpcur_2255, + tmpcur_2258}; + GibCursor *indr_1067 = gib_array_alloc(indr_1067_tmp, 3); + GibCursorPtrGibCursorPtrProd tmp_struct_30 = + _traverse_Tree(indr_1067, indr_1067); + GibCursor *pvrtmp_2261 = tmp_struct_30.field0; + GibCursor *pvrtmp_2262 = tmp_struct_30.field1; + + return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2261, pvrtmp_2262}; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2237"); + exit(1); + } + } +} +GibCursorPtrGibCursorPtrProd _print_Tree(GibCursor *cursor_ptr_1667, + GibCursor *arg_97_144_228) +{ + GibCursor *end_r_632 = &cursor_ptr_1667[0]; + GibCursor *end_r_633 = &cursor_ptr_1667[1]; + GibCursor *end_r_634 = &cursor_ptr_1667[2]; + GibCursor dcon_1671 = arg_97_144_228[0]; + GibPackedTag tmpval_2264 = *(GibPackedTag *) dcon_1671; + GibCursor tmpcur_2265 = dcon_1671 + 1; + + + switch_2290: + ; + switch (tmpval_2264) { + + case 0: + { + GibCursor soa_field_0_1673 = arg_97_144_228[1]; + GibCursor soa_field_1_1674 = arg_97_144_228[2]; + GibInt tmpval_2266 = *(GibInt *) soa_field_0_1673; + GibCursor tmpcur_2267 = soa_field_0_1673 + sizeof(GibInt); + GibCursor loc_629 = arg_97_144_228[0]; + GibCursor jumpf_dloc_973 = loc_629 + 1; + GibCursor loc_IntTy_630 = arg_97_144_228[1]; + GibCursor loc_IntTy_631 = arg_97_144_228[2]; + GibCursor jumpf_floc_loc_974 = soa_field_0_1673 + 8; + GibCursor jumpf_floc_loc_975 = loc_IntTy_631 + 0; + GibCursor cursor_ptr_1677_tmp[3] = {jumpf_dloc_973, + jumpf_floc_loc_974, + jumpf_floc_loc_975}; + GibCursor *cursor_ptr_1677 = gib_array_alloc(cursor_ptr_1677_tmp, + 3); + unsigned char wildcard_100_146_230 = gib_print_symbol(2009); + unsigned char wildcard_102_147_231 = gib_print_symbol(2012); + unsigned char y_99_148_232 = printf("%ld", tmpval_2266); + unsigned char wildcard_101_149_233 = gib_print_symbol(2007); + + return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1667, + cursor_ptr_1677}; + break; + } + + case 1: + { + GibCursor soa_field_0_1679 = arg_97_144_228[1]; + GibCursor soa_field_1_1680 = arg_97_144_228[2]; + GibInt tmpval_2268 = *(GibInt *) soa_field_1_1680; + GibCursor tmpcur_2269 = soa_field_1_1680 + sizeof(GibInt); + GibCursor cursor_ptr_1670_tmp[3] = {tmpcur_2265, soa_field_0_1679, + tmpcur_2269}; + GibCursor *cursor_ptr_1670 = gib_array_alloc(cursor_ptr_1670_tmp, + 3); + GibCursor loc_629 = arg_97_144_228[0]; + GibCursor jumpf_dloc_977 = loc_629 + 1; + GibCursor loc_IntTy_630 = arg_97_144_228[1]; + GibCursor loc_IntTy_631 = arg_97_144_228[2]; + GibCursor jumpf_floc_loc_979 = soa_field_1_1680 + 8; + GibCursor jumpf_floc_loc_978 = loc_IntTy_630 + 0; + GibCursor loc_845 = jumpf_dloc_977 + 0; + GibCursor loc_844 = jumpf_floc_loc_979 + 0; + GibCursor loc_843 = jumpf_floc_loc_978 + 0; + GibCursor cursor_ptr_1684_tmp[3] = {jumpf_dloc_977, + jumpf_floc_loc_978, + jumpf_floc_loc_979}; + GibCursor *cursor_ptr_1684 = gib_array_alloc(cursor_ptr_1684_tmp, + 3); + unsigned char wildcard_109_153_237 = gib_print_symbol(2008); + unsigned char wildcard_113_154_238 = gib_print_symbol(2012); + unsigned char y_106_155_239 = printf("%ld", tmpval_2268); + unsigned char wildcard_112_156_240 = gib_print_symbol(2012); + GibCursorPtrGibCursorPtrProd tmp_struct_34 = + _print_Tree(cursor_ptr_1667, cursor_ptr_1670); + GibCursor *pvrtmp_2270 = tmp_struct_34.field0; + GibCursor *pvrtmp_2271 = tmp_struct_34.field1; + unsigned char wildcard_111_158_242 = gib_print_symbol(2012); + GibCursorPtrGibCursorPtrProd tmp_struct_35 = + _print_Tree(pvrtmp_2270, pvrtmp_2271); + GibCursor *pvrtmp_2272 = tmp_struct_35.field0; + GibCursor *pvrtmp_2273 = tmp_struct_35.field1; + unsigned char wildcard_110_160_244 = gib_print_symbol(2007); + + return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2272, pvrtmp_2273}; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1697 = arg_97_144_228[1]; + GibCursor soa_field_1_1698 = arg_97_144_228[2]; + uintptr_t tagged_tmpcur_37 = *(uintptr_t *) tmpcur_2265; + GibCursor tmpcur_2274 = GIB_UNTAG(tagged_tmpcur_37); + GibCursor tmpaftercur_2275 = tmpcur_2265 + 8; + uint16_t tmptag_2276 = GIB_GET_TAG(tagged_tmpcur_37); + GibCursor *cursor_ptr_1668 = (GibCursor *) tmpcur_2274; + GibCursor loc_629 = arg_97_144_228[0]; + GibCursor jump_dloc_1089 = loc_629 + 9; + GibCursor loc_IntTy_631 = arg_97_144_228[2]; + GibCursor loc_IntTy_630 = arg_97_144_228[1]; + GibCursor cursor_ptr_1702_tmp[3] = {jump_dloc_1089, loc_IntTy_630, + loc_IntTy_631}; + GibCursor *cursor_ptr_1702 = gib_array_alloc(cursor_ptr_1702_tmp, + 3); + unsigned char wildcard_1096 = gib_print_symbol(2011); + GibCursorPtrGibCursorPtrProd tmp_struct_36 = + _print_Tree(cursor_ptr_1668, cursor_ptr_1668); + GibCursor *pvrtmp_2277 = tmp_struct_36.field0; + GibCursor *pvrtmp_2278 = tmp_struct_36.field1; + + return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1667, + cursor_ptr_1702}; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1710 = arg_97_144_228[1]; + GibCursor soa_field_1_1711 = arg_97_144_228[2]; + uintptr_t tagged_tmpcur_41 = *(uintptr_t *) tmpcur_2265; + GibCursor tmpcur_2279 = GIB_UNTAG(tagged_tmpcur_41); + GibCursor tmpaftercur_2280 = tmpcur_2265 + 8; + uint16_t tmptag_2281 = GIB_GET_TAG(tagged_tmpcur_41); + GibCursor end_from_tagged_dcon_redir_1719 = tmpcur_2279 + + tmptag_2281; + GibCursor field_nxt_1717 = soa_field_0_1710 + 1; + uintptr_t tagged_tmpcur_40 = *(uintptr_t *) field_nxt_1717; + GibCursor tmpcur_2282 = GIB_UNTAG(tagged_tmpcur_40); + GibCursor tmpaftercur_2283 = field_nxt_1717 + 8; + uint16_t tmptag_2284 = GIB_GET_TAG(tagged_tmpcur_40); + GibCursor end_from_tagged_fld_redir_1720 = tmpcur_2282 + + tmptag_2284; + GibCursor field_nxt_1718 = soa_field_1_1711 + 1; + uintptr_t tagged_tmpcur_39 = *(uintptr_t *) field_nxt_1718; + GibCursor tmpcur_2285 = GIB_UNTAG(tagged_tmpcur_39); + GibCursor tmpaftercur_2286 = field_nxt_1718 + 8; + uint16_t tmptag_2287 = GIB_GET_TAG(tagged_tmpcur_39); + GibCursor end_from_tagged_fld_redir_1721 = tmpcur_2285 + + tmptag_2287; + GibCursor indr_1082_tmp[3] = {tmpcur_2279, tmpcur_2282, + tmpcur_2285}; + GibCursor *indr_1082 = gib_array_alloc(indr_1082_tmp, 3); + unsigned char wildcard_1096 = gib_print_symbol(2010); + GibCursorPtrGibCursorPtrProd tmp_struct_38 = + _print_Tree(indr_1082, indr_1082); + GibCursor *pvrtmp_2288 = tmp_struct_38.field0; + GibCursor *pvrtmp_2289 = tmp_struct_38.field1; + + return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2288, pvrtmp_2289}; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2264"); + exit(1); + } + } +} +GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd _copy_without_ptrs_Tree(GibCursor *cursor_ptr_1730, + GibCursor *cursor_ptr_1729, + GibCursor *cursor_ptr_1731, + GibCursor *arg_79_161_245) +{ + GibCursor *end_r_641 = &cursor_ptr_1730[0]; + GibCursor *end_r_642 = &cursor_ptr_1730[1]; + GibCursor *end_r_643 = &cursor_ptr_1730[2]; + GibCursor *end_r_644 = &cursor_ptr_1729[0]; + GibCursor *end_r_645 = &cursor_ptr_1729[1]; + GibCursor *end_r_646 = &cursor_ptr_1729[2]; + GibCursor dcon_1735 = arg_79_161_245[0]; + GibPackedTag tmpval_2291 = *(GibPackedTag *) dcon_1735; + GibCursor tmpcur_2292 = dcon_1735 + 1; + + + switch_2357: + ; + switch (tmpval_2291) { + + case 0: + { + GibCursor soa_field_0_1737 = arg_79_161_245[1]; + GibCursor soa_field_1_1738 = arg_79_161_245[2]; + GibInt tmpval_2293 = *(GibInt *) soa_field_0_1737; + GibCursor tmpcur_2294 = soa_field_0_1737 + sizeof(GibInt); + GibCursor loc_635 = arg_79_161_245[0]; + GibCursor jumpf_dloc_987 = loc_635 + 1; + GibCursor loc_IntTy_636 = arg_79_161_245[1]; + GibCursor loc_IntTy_637 = arg_79_161_245[2]; + GibCursor jumpf_floc_loc_988 = soa_field_0_1737 + 8; + GibCursor jumpf_floc_loc_989 = loc_IntTy_637 + 0; + GibCursor cursor_ptr_1741_tmp[3] = {jumpf_dloc_987, + jumpf_floc_loc_988, + jumpf_floc_loc_989}; + GibCursor *cursor_ptr_1741 = gib_array_alloc(cursor_ptr_1741_tmp, + 3); + GibCursor loc_IntTy_639 = cursor_ptr_1731[1]; + GibCursor new_floc_loc_894 = loc_IntTy_639 + 0; + GibCursor loc_638 = cursor_ptr_1731[0]; + GibCursor new_dloc_893 = loc_638 + 1; + GibCursor loc_IntTy_640 = cursor_ptr_1731[2]; + GibCursor loc_892 = loc_IntTy_640 + 0; + GibCursor new_floc_loc_895 = loc_892 + 8; + + *(GibPackedTag *) loc_638 = 0; + + GibCursor writetag_1742 = loc_638 + 1; + GibCursor after_tag_1743 = loc_638 + 1; + + *(GibInt *) loc_IntTy_639 = tmpval_2293; + + GibCursor writecur_1747 = loc_IntTy_639 + sizeof(GibInt); + GibCursor aft_soa_loc_1749_tmp[3] = {after_tag_1743, writecur_1747, + loc_IntTy_640}; + GibCursor *aft_soa_loc_1749 = gib_array_alloc(aft_soa_loc_1749_tmp, + 3); + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1730, + cursor_ptr_1729, + cursor_ptr_1741, + cursor_ptr_1731, + aft_soa_loc_1749}; + break; + } + + case 1: + { + GibCursor soa_field_0_1753 = arg_79_161_245[1]; + GibCursor soa_field_1_1754 = arg_79_161_245[2]; + GibInt tmpval_2299 = *(GibInt *) soa_field_1_1754; + GibCursor tmpcur_2300 = soa_field_1_1754 + sizeof(GibInt); + GibCursor cursor_ptr_1734_tmp[3] = {tmpcur_2292, soa_field_0_1753, + tmpcur_2300}; + GibCursor *cursor_ptr_1734 = gib_array_alloc(cursor_ptr_1734_tmp, + 3); + GibCursor loc_635 = arg_79_161_245[0]; + GibCursor jumpf_dloc_991 = loc_635 + 1; + GibCursor loc_IntTy_636 = arg_79_161_245[1]; + GibCursor loc_IntTy_637 = arg_79_161_245[2]; + GibCursor jumpf_floc_loc_993 = soa_field_1_1754 + 8; + GibCursor jumpf_floc_loc_992 = loc_IntTy_636 + 0; + GibCursor loc_870 = jumpf_dloc_991 + 0; + GibCursor loc_869 = jumpf_floc_loc_993 + 0; + GibCursor loc_868 = jumpf_floc_loc_992 + 0; + GibCursor cursor_ptr_1758_tmp[3] = {jumpf_dloc_991, + jumpf_floc_loc_992, + jumpf_floc_loc_993}; + GibCursor *cursor_ptr_1758 = gib_array_alloc(cursor_ptr_1758_tmp, + 3); + GibCursor loc_IntTy_639 = cursor_ptr_1731[1]; + GibCursor new_floc_loc_894 = loc_IntTy_639 + 0; + GibCursor loc_638 = cursor_ptr_1731[0]; + GibCursor new_dloc_893 = loc_638 + 1; + GibCursor loc_IntTy_640 = cursor_ptr_1731[2]; + GibCursor loc_892 = loc_IntTy_640 + 0; + GibCursor new_floc_loc_895 = loc_892 + 8; + GibCursor cursor_ptr_1759_tmp[3] = {new_dloc_893, new_floc_loc_894, + new_floc_loc_895}; + GibCursor *cursor_ptr_1759 = gib_array_alloc(cursor_ptr_1759_tmp, + 3); + + *(GibPackedTag *) loc_638 = 1; + + GibCursor writetag_1778 = loc_638 + 1; + GibCursor after_tag_1779 = loc_638 + 1; + + *(GibInt *) loc_IntTy_640 = tmpval_2299; + + GibCursor writecur_1783 = loc_IntTy_640 + sizeof(GibInt); + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_42 = + _copy_without_ptrs_Tree(cursor_ptr_1730, cursor_ptr_1729, cursor_ptr_1759, cursor_ptr_1734); + GibCursor *pvrtmp_2301 = tmp_struct_42.field0; + GibCursor *pvrtmp_2302 = tmp_struct_42.field1; + GibCursor *pvrtmp_2303 = tmp_struct_42.field2; + GibCursor *pvrtmp_2304 = tmp_struct_42.field3; + GibCursor *pvrtmp_2305 = tmp_struct_42.field4; + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_43 = + _copy_without_ptrs_Tree(pvrtmp_2301, pvrtmp_2302, pvrtmp_2305, pvrtmp_2303); + GibCursor *pvrtmp_2310 = tmp_struct_43.field0; + GibCursor *pvrtmp_2311 = tmp_struct_43.field1; + GibCursor *pvrtmp_2312 = tmp_struct_43.field2; + GibCursor *pvrtmp_2313 = tmp_struct_43.field3; + GibCursor *pvrtmp_2314 = tmp_struct_43.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2310, + pvrtmp_2311, + pvrtmp_2312, + cursor_ptr_1731, + pvrtmp_2314}; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1791 = arg_79_161_245[1]; + GibCursor soa_field_1_1792 = arg_79_161_245[2]; + uintptr_t tagged_tmpcur_45 = *(uintptr_t *) tmpcur_2292; + GibCursor tmpcur_2323 = GIB_UNTAG(tagged_tmpcur_45); + GibCursor tmpaftercur_2324 = tmpcur_2292 + 8; + uint16_t tmptag_2325 = GIB_GET_TAG(tagged_tmpcur_45); + GibCursor *cursor_ptr_1732 = (GibCursor *) tmpcur_2323; + GibCursor loc_635 = arg_79_161_245[0]; + GibCursor jump_dloc_1104 = loc_635 + 9; + GibCursor loc_IntTy_637 = arg_79_161_245[2]; + GibCursor loc_IntTy_636 = arg_79_161_245[1]; + GibCursor cursor_ptr_1796_tmp[3] = {jump_dloc_1104, loc_IntTy_636, + loc_IntTy_637}; + GibCursor *cursor_ptr_1796 = gib_array_alloc(cursor_ptr_1796_tmp, + 3); + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_44 = + _copy_without_ptrs_Tree(cursor_ptr_1732, cursor_ptr_1729, cursor_ptr_1731, cursor_ptr_1732); + GibCursor *pvrtmp_2326 = tmp_struct_44.field0; + GibCursor *pvrtmp_2327 = tmp_struct_44.field1; + GibCursor *pvrtmp_2328 = tmp_struct_44.field2; + GibCursor *pvrtmp_2329 = tmp_struct_44.field3; + GibCursor *pvrtmp_2330 = tmp_struct_44.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1730, + pvrtmp_2327, + cursor_ptr_1796, + pvrtmp_2329, + pvrtmp_2330}; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1807 = arg_79_161_245[1]; + GibCursor soa_field_1_1808 = arg_79_161_245[2]; + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_2292; + GibCursor tmpcur_2337 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_2338 = tmpcur_2292 + 8; + uint16_t tmptag_2339 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_dcon_redir_1816 = tmpcur_2337 + + tmptag_2339; + GibCursor field_nxt_1814 = soa_field_0_1807 + 1; + uintptr_t tagged_tmpcur_48 = *(uintptr_t *) field_nxt_1814; + GibCursor tmpcur_2340 = GIB_UNTAG(tagged_tmpcur_48); + GibCursor tmpaftercur_2341 = field_nxt_1814 + 8; + uint16_t tmptag_2342 = GIB_GET_TAG(tagged_tmpcur_48); + GibCursor end_from_tagged_fld_redir_1817 = tmpcur_2340 + + tmptag_2342; + GibCursor field_nxt_1815 = soa_field_1_1808 + 1; + uintptr_t tagged_tmpcur_47 = *(uintptr_t *) field_nxt_1815; + GibCursor tmpcur_2343 = GIB_UNTAG(tagged_tmpcur_47); + GibCursor tmpaftercur_2344 = field_nxt_1815 + 8; + uint16_t tmptag_2345 = GIB_GET_TAG(tagged_tmpcur_47); + GibCursor end_from_tagged_fld_redir_1818 = tmpcur_2343 + + tmptag_2345; + GibCursor indr_1097_tmp[3] = {tmpcur_2337, tmpcur_2340, + tmpcur_2343}; + GibCursor *indr_1097 = gib_array_alloc(indr_1097_tmp, 3); + GibCursor loc_638 = cursor_ptr_1731[0]; + GibCursor loc_IntTy_639 = cursor_ptr_1731[1]; + GibCursor loc_IntTy_640 = cursor_ptr_1731[2]; + GibCursor copy_dloc_1112 = loc_638 + 0; + GibCursor copy_floc_loc_1114 = loc_IntTy_640 + 0; + GibCursor copy_floc_loc_1113 = loc_IntTy_639 + 0; + GibCursor cursor_ptr_1819_tmp[3] = {copy_dloc_1112, + copy_floc_loc_1113, + copy_floc_loc_1114}; + GibCursor *cursor_ptr_1819 = gib_array_alloc(cursor_ptr_1819_tmp, + 3); + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_46 = + _copy_without_ptrs_Tree(indr_1097, cursor_ptr_1729, cursor_ptr_1819, indr_1097); + GibCursor *pvrtmp_2346 = tmp_struct_46.field0; + GibCursor *pvrtmp_2347 = tmp_struct_46.field1; + GibCursor *pvrtmp_2348 = tmp_struct_46.field2; + GibCursor *pvrtmp_2349 = tmp_struct_46.field3; + GibCursor *pvrtmp_2350 = tmp_struct_46.field4; + + return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2346, + pvrtmp_2347, + pvrtmp_2348, + pvrtmp_2349, + pvrtmp_2350}; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2291"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_58 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_2013 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_676 = region_2013.start; + GibCursor end_r_676 = region_2013.end; + GibChunk region_2014 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_677 = region_2014.start; + GibCursor end_r_677 = region_2014.end; + GibChunk region_2015 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_678 = region_2015.start; + GibCursor end_r_678 = region_2015.end; + GibCursor reg_ptr_1829_tmp[3] = {r_676, r_677, r_678}; + GibCursor *reg_ptr_1829 = gib_array_alloc(reg_ptr_1829_tmp, 3); + GibCursor reg_cursor_ptr_1830_tmp[3] = {end_r_676, end_r_677, end_r_678}; + GibCursor *reg_cursor_ptr_1830 = gib_array_alloc(reg_cursor_ptr_1830_tmp, + 3); + GibCursorPtrGibCursorPtrGibCursorPtrProd tmp_struct_50 = + mkTree(reg_cursor_ptr_1830, reg_ptr_1829, 20, 0); + + GibCursor pvrtmp_2016[3] = {tmp_struct_50.field0[0], tmp_struct_50.field0[1], tmp_struct_50.field0[2]}; + GibCursor pvrtmp_2017[3] = {tmp_struct_50.field1[0], tmp_struct_50.field1[1], tmp_struct_50.field1[2]}; + GibCursor pvrtmp_2018[3] = {tmp_struct_50.field2[0], tmp_struct_50.field2[1], tmp_struct_50.field2[2]}; + + GibChunk region_2023 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_673 = region_2023.start; + GibCursor end_r_673 = region_2023.end; + GibChunk region_2024 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_674 = region_2024.start; + GibCursor end_r_674 = region_2024.end; + GibChunk region_2025 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_675 = region_2025.start; + GibCursor end_r_675 = region_2025.end; + GibCursor reg_ptr_1836_tmp[3] = {r_673, r_674, r_675}; + GibCursor *reg_ptr_1836 = gib_array_alloc(reg_ptr_1836_tmp, 3); + GibCursor reg_cursor_ptr_1837_tmp[3] = {end_r_673, end_r_674, end_r_675}; + GibCursor *reg_cursor_ptr_1837 = gib_array_alloc(reg_cursor_ptr_1837_tmp, + 3); + + GibCursor *reg_cursor_ptr_1837_2 = gib_array_alloc(reg_cursor_ptr_1837_tmp, + 3); + + GibCursor pvrtmp_2037[3]; + GibCursor pvrtmp_2038[3]; + GibCursor pvrtmp_2039[3]; + + GibVector *times_55 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_2037; + struct timespec end_pvrtmp_2037; + + for (long long iters_pvrtmp_2037 = 0; iters_pvrtmp_2037 < + gib_get_iters_param(); iters_pvrtmp_2037++) { + if (iters_pvrtmp_2037 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_2037); + + GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd + tmp_struct_51 = + add1Tree(pvrtmp_2016, reg_cursor_ptr_1837, reg_ptr_1836, pvrtmp_2017); + + GibCursor pvrtmp_2026[3] = {tmp_struct_51.field0[0], tmp_struct_51.field0[1], tmp_struct_51.field0[2]}; + GibCursor pvrtmp_2027[3] = {tmp_struct_51.field1[0], tmp_struct_51.field1[1], tmp_struct_51.field1[2]}; + GibCursor pvrtmp_2028[3] = {tmp_struct_51.field2[0], tmp_struct_51.field2[1], tmp_struct_51.field2[2]}; + GibCursor pvrtmp_2029[3] = {tmp_struct_51.field3[0], tmp_struct_51.field3[1], tmp_struct_51.field3[2]}; + GibCursor pvrtmp_2030[3] = {tmp_struct_51.field4[0], tmp_struct_51.field4[1], tmp_struct_51.field4[2]}; + + //reg_cursor_ptr_1837 = gib_array_alloc(reg_cursor_ptr_1837_tmp, + // 3); + + pvrtmp_2037[0] = pvrtmp_2027[0]; + pvrtmp_2037[1] = pvrtmp_2027[1]; + pvrtmp_2037[2] = pvrtmp_2027[2]; + + + pvrtmp_2038[0] = pvrtmp_2029[0]; + pvrtmp_2038[1] = pvrtmp_2029[1]; + pvrtmp_2038[2] = pvrtmp_2029[2]; + + pvrtmp_2039[0] = pvrtmp_2030[0]; + pvrtmp_2039[1] = pvrtmp_2030[1]; + pvrtmp_2039[2] = pvrtmp_2030[2]; + + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_2037); + if (iters_pvrtmp_2037 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_52 = gib_difftimespecs(&begin_pvrtmp_2037, + &end_pvrtmp_2037); + + printf("itertime: %lf\n", itertime_52); + gib_vector_inplace_update(times_55, iters_pvrtmp_2037, &itertime_52); + } + gib_vector_inplace_sort(times_55, gib_compare_doubles); + + double *tmp_56 = (double *) gib_vector_nth(times_55, gib_get_iters_param() / + 2); + double selftimed_54 = *tmp_56; + double batchtime_53 = gib_sum_timing_array(times_55); + + gib_print_timing_array(times_55); + gib_vector_free(times_55); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_53); + printf("SELFTIMED: %e\n", selftimed_54); + + GibCursorPtrGibCursorPtrGibIntProd tmp_struct_57 = + sumTree(reg_cursor_ptr_1837, pvrtmp_2038); + GibCursor *pvrtmp_2047 = tmp_struct_57.field0; + GibCursor *pvrtmp_2048 = tmp_struct_57.field1; + GibInt pvrtmp_2049 = tmp_struct_57.field2; + + printf("%ld", pvrtmp_2049); + printf("\n"); + + int exit_59 = gib_exit(); + + return exit_59; +} diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 335f32fdb..5b9dc14db 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -18,10 +18,10 @@ add1Tree t = Leaf x -> Leaf (x + 1) Node d x1 x2 -> Node (d + 1) (add1Tree x1) (add1Tree x2) -rightMost :: Tree -> Int -rightMost t = case t of - Leaf x -> x - Node d x1 x2 -> rightMost x2 +--rightMost :: Tree -> Int +--rightMost t = case t of +-- Leaf x -> x +-- Node d x1 x2 -> rightMost x2 sumTree :: Tree -> Int sumTree tr = @@ -29,7 +29,10 @@ sumTree tr = Leaf n -> n Node d l r -> d + (sumTree l) + (sumTree r) -gibbon_main = rightMost (mkTree 18 0) --sumTree (add1Tree (mkTree 18)) +gibbon_main = let + tree = mkTree 20 0 + tree' = iterate (add1Tree tree) + in sumTree tree' main :: IO () main = print gibbon_main diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index a5aa37fc7..43d39b942 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -4,7 +4,7 @@ import Control.Monad (forM) import Data.Foldable (foldlM, foldrM) import qualified Data.List as L import qualified Data.Map as M -import Data.Maybe (fromJust, listToMaybe) +import Data.Maybe (fromJust, listToMaybe, fromMaybe) import Data.Set (Set) import GHC.RTS.Flags (MiscFlags (generateCrashDumpFile)) import Gibbon.Common @@ -1928,7 +1928,151 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = (MkProdE [VarE start, VarE end]) ), freeVarToVarEnv) - SoA _ flds -> error "Indirection when GC is enabled is not implemented for SoA! Please turn off the GC!" + SoA dcloc flds -> do + -- can this be refactored into a helper function? + let from_loc_var = case M.lookup (fromLocArgToFreeVarsTy from) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let from_locs = [Single dcloc] ++ map (\(_, floc) -> floc) flds + let to_locs = case (toLocVar to) of + Single{} -> error "Expected a SoA location!\n" + SoA dc_loc flocs -> [Single dc_loc] ++ map (\(_, floc) -> floc) flocs + let to_loc_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of + Nothing -> error "Did not find variable for location!" + Just var -> var + let reg_from_reg = fromLocVarToRegVar (toLocVar from_reg) + let from_reg_vars = case reg_from_reg of + SingleR{} -> error "expected an SoA region!\n" + SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs + + let from_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_from_reg) freeVarToVarEnv of + Nothing -> error "Did not find region!" + Just var -> var + + let reg_to_reg = fromLocVarToRegVar (toLocVar to_reg) + let to_reg_vars = case reg_to_reg of + SingleR{} -> error "expected an SoA region!\n" + SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs + + let to_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_to_reg) freeVarToVarEnv of + Nothing -> error "Did not find region!" + Just var -> var + + let barrier_args = L.zip4 from_locs to_locs from_reg_vars to_reg_vars + + let handle_indrs_rec = (\(lets, range, p@(flp, tp, rp, trp), b_args) r@(fl, to_loc, from_reg, to_reg) -> do + case fl of + Single{} -> do + start <- gensym "start" + end <- gensym "end" + (from_var, fvl) <- case M.lookup (fromLocVarToFreeVarsTy fl) freeVarToVarEnv of + Nothing -> case fl of + Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) + SoA{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + (to_var, tvl) <- do + case M.lookup (fromLocVarToFreeVarsTy to_loc) freeVarToVarEnv of + Nothing -> case to_loc of + Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray tp (fromJust (L.elemIndex r b_args)))]) + SoA{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray tp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + + (from_reg_var, frl) <- case M.lookup (fromRegVarToFreeVarsTy from_reg) freeVarToVarEnv of + Nothing -> case from_reg of + SingleR l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray rp (fromJust (L.elemIndex r b_args)))]) + SoARv{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray rp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + (to_reg_var, trl) <- case M.lookup (fromRegVarToFreeVarsTy to_reg) freeVarToVarEnv of + Nothing -> case to_reg of + SingleR l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray trp (fromJust (L.elemIndex r b_args)))]) + SoARv{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray trp (fromJust (L.elemIndex r b_args)))]) + + Just var -> return $ (var, []) + -- VS : [09/20/2025 -- For SoA case, indirection with gc need a bit more thinking] + -- One way could be to call indirection barrier seperately on every buffer/region + -- Then follow them seperately for every region in the case. + -- For now i'm erroring out but this needs more thought. + (need_deref, new_vars) <- foldlM (\(ls, nvs) v -> case M.lookup v tenv of + Just (MkTy2 MutCursorTy) -> do + new_deref <- gensym "new_deref" + return (ls ++ [(new_deref, [], CursorTy, Ext $ DerefMutCursor v)], nvs ++ [new_deref]) + _ -> return (ls, nvs ++ [v]) + ) ([], []) [from_var, to_var, from_reg_var, to_reg_var] + + let new_let = [ ("_", [], ProdTy [], Ext (IndirectionBarrier tycon ((new_vars !! 0), (new_vars !! 2), (new_vars !! 1), (new_vars !! 3)))), + (start, [], CursorTy, VarE (from_var)), + (end, [], CursorTy, Ext $ AddCursor (from_var) (L3.LitE 9)) + ] + return (lets ++ fvl ++ tvl ++ frl ++ trl ++ need_deref ++ new_let, range ++ [(start, end)], p, b_args) + SoA dcloc' flds' -> do + (fl_var, fvl) <- do case (M.lookup (fromLocVarToFreeVarsTy fl)) freeVarToVarEnv of + Nothing -> case to_loc of + Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) + SoA{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + let from_locs' = [Single dcloc'] ++ map (\(_, floc) -> floc) flds' + let to_locs' = case to_loc of + Single{} -> error "Expected a SoA location!\n" + SoA dc_loc flocs -> [Single dc_loc] ++ map (\(_, floc) -> floc) flocs + (to_loc_var', tvl) <- case M.lookup (fromLocVarToFreeVarsTy to_loc) freeVarToVarEnv of + Nothing -> case to_loc of + Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray tp (fromJust (L.elemIndex r b_args)))]) + SoA{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray tp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + let from_reg_vars' = case from_reg of + SingleR{} -> error "expected an SoA region!\n" + SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs + + (from_reg_var', frl) <- case (M.lookup (fromRegVarToFreeVarsTy from_reg)) freeVarToVarEnv of + Nothing -> case to_loc of + Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray rp (fromJust (L.elemIndex r b_args)))]) + SoA{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray rp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + + let to_reg_vars' = case to_reg of + SingleR{} -> error "expected an SoA region!\n" + SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs + + (to_reg_var', trl) <- case (M.lookup (fromRegVarToFreeVarsTy to_reg)) freeVarToVarEnv of + Nothing -> case to_loc of + Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray trp (fromJust (L.elemIndex r b_args)))]) + SoA{} -> do + field_name <- gensym "field_cursor" + return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray trp (fromJust (L.elemIndex r b_args)))]) + Just var -> return $ (var, []) + + let barrier_args' = L.zip4 from_locs' to_locs' from_reg_vars' to_reg_vars' + (let_exprs', range_s', parents, _) <- foldlM handle_indrs_rec ([], [], (fl_var, to_loc_var', from_reg_var', to_reg_var'), barrier_args') barrier_args' + error "SoA: Packed indirections with GC does not work! Please turn off GC for now!" + return (fvl ++ tvl ++ frl ++ trl ++ let_exprs', range_s', parents, barrier_args) + ) + + (let_exprs, range_s, _, _) <- foldlM handle_indrs_rec ([], [], (from_loc_var, to_loc_var, from_reg_var, to_reg_var), barrier_args) barrier_args + start_soa <- gensym "start_soa" + end_soa <- gensym "end_soa" + let start_vars = map fst range_s + let end_vars = map snd range_s + -- TODO change cursor array ty size + let let_start_soa = (start_soa, [], CursorArrayTy (L.length start_vars), Ext (MakeCursorArray (L.length start_vars) start_vars)) + let let_end_soa = (end_soa, [], CursorArrayTy (L.length end_vars), Ext (MakeCursorArray (L.length end_vars) end_vars)) + let end_prod = MkProdE [VarE start_soa, VarE end_soa] + let ret_let = mkLets (let_exprs ++ [let_start_soa, let_end_soa]) end_prod + return (Di ret_let, freeVarToVarEnv) + AddFixed {} -> error "cursorizePackedExp: AddFixed not handled." GetCilkWorkerNum -> pure (Di (Ext L3.GetCilkWorkerNum), freeVarToVarEnv) LetAvail vs bod -> do @@ -3389,52 +3533,125 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod else + -- This case is different for when the GC is on. + -- Vidush: TODO change this when the GC is on if isIndirectionTag dcon then do - tmp <- gensym "readcursor_indir" - loc_var <- lookupVariable loc fenv - let locs_ty = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) - _ -> error "Expected location!" - - let locs_ty3 :: Ty3 = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) - _ -> error "Expected location!" - - -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur - var_dcon_next <- gensym "dcon_next" - - let tenv' = - M.union - ( M.fromList - [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - ((loc_var), MkTy2 locs_ty), - (v, MkTy2 locs_ty) - -- (toEndV v, MkTy2 CursorTy), - -- (toTagV v, MkTy2 IntTy), - -- (toEndFromTaggedV v, MkTy2 CursorTy) - ] - ) - tenv - read_cursor = - if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor var_dcon_next) - else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - binds = - [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), - (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - (v, [], CursorTy, ProjE 0 (VarE tmp)), - -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), - -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), - -- End of region needs to be calculated differently - -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), - ((loc_var), [], locs_ty3, VarE v) - ] - bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) - return $ mkLets binds bod + dflags <- getDynFlags + if gopt Opt_DisableGC dflags + then do + tmp <- gensym "readcursor_indir" + loc_var <- lookupVariable loc fenv + let locs_ty = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + let locs_ty3 :: Ty3 = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + var_dcon_next <- gensym "dcon_next" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + ((loc_var), MkTy2 locs_ty), + (v, MkTy2 locs_ty) + -- (toEndV v, MkTy2 CursorTy), + -- (toTagV v, MkTy2 IntTy), + -- (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + binds = + [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (v, [], CursorTy, ProjE 0 (VarE tmp)), + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), + -- End of region needs to be calculated differently + -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), + ((loc_var), [], locs_ty3, VarE v) + ] + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) + return $ mkLets binds bod + else do + tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" + tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur + loc_var <- lookupVariable loc fenv + var_dcon_next <- gensym "dcon_next" + vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur + redirection_var_dcon <- gensym "dcon_redir" + redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + -- ((loc_var) , MkTy2 CursorTy), + (redirection_var_dcon, MkTy2 CursorTy), + (toEndV redirection_var_dcon, MkTy2 CursorTy), + (toTagV redirection_var_dcon, MkTy2 IntTy), + (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy) + ] + ) tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + -- v is the variable i want to send to the call. + -- In this case v is the soa variable where all redirections are unpacked. + binds = [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + ((loc_var), [], CursorTy, VarE dcur), + (redirection_var_dcon, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV redirection_var_dcon, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon))) + ] + -- generate binds for all fields. + binds_flields = + L.foldl + ( \(index, res) ((dcon', idx), var) -> + let read_cursor_f = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor (vars_next_fields !! index)) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + tmpf = tmp_flds !! index + ty_of_field = (lookupDataCon ddfs dcon') !! idx + in case ty_of_field of + (MkTy2 PackedTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + (MkTy2 CursorArrayTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + _ -> + let new_binds = + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] + in (index + 1, res ++ new_binds) + ) (0, []) _field_cur + soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] + tenv'' = M.union + ( M.fromList + [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) + ] + ) tenv + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod else error $ "unpackRegularDataCon: cursorty without indirection/redirection." VectorTy el_ty -> do tmp <- gensym "read_vec_tuple" From 55874ec1b4c679376e8b851a1de84c6cb4406b19 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Wed, 8 Oct 2025 00:05:37 -0400 Subject: [PATCH 29/60] use clang --- .../examples/soa_examples/MonoTree.c.stack | 1562 ----------------- gibbon-rts/Makefile | 6 +- 2 files changed, 3 insertions(+), 1565 deletions(-) delete mode 100644 gibbon-compiler/examples/soa_examples/MonoTree.c.stack diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.c.stack b/gibbon-compiler/examples/soa_examples/MonoTree.c.stack deleted file mode 100644 index 2f460fb74..000000000 --- a/gibbon-compiler/examples/soa_examples/MonoTree.c.stack +++ /dev/null @@ -1,1562 +0,0 @@ -/* Gibbon program. */ - -#include "gibbon_rts.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN64 -#include -#endif - -#ifdef _GIBBON_POINTER -#include -#endif - -#ifdef _GIBBON_PARALLEL -#include -#include -#endif - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Program starts here - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - -typedef struct GibIntProd_struct { - GibInt field0; - } GibIntProd; -typedef struct GibIntGibCursorProd_struct { - GibInt field0; - GibCursor field1; - } GibIntGibCursorProd; -typedef struct GibBoolProd_struct { - GibBool field0; - } GibBoolProd; -typedef struct GibPackedTagGibCursorProd_struct { - GibPackedTag field0; - GibCursor field1; - } GibPackedTagGibCursorProd; -typedef struct GibCursorProd_struct { - GibCursor field0; - } GibCursorProd; -typedef struct GibCursorGibCursorGibIntProd_struct { - GibCursor field0; - GibCursor field1; - GibInt field2; - } GibCursorGibCursorGibIntProd; -typedef struct GibCursorGibCursorGibCursorProd_struct { - GibCursor field0; - GibCursor field1; - GibCursor field2; - } GibCursorGibCursorGibCursorProd; -typedef struct GibCursorPtrProd_struct { - GibCursor *field0; - } GibCursorPtrProd; -typedef struct GibCursorPtrGibCursorPtrProd_struct { - GibCursor *field0; - GibCursor *field1; - } GibCursorPtrGibCursorPtrProd; -typedef struct GibCursorPtrGibCursorPtrGibIntProd_struct { - GibCursor *field0; - GibCursor *field1; - GibInt field2; - } GibCursorPtrGibCursorPtrGibIntProd; -typedef struct GibCursorPtrGibCursorPtrGibCursorPtrProd_struct { - GibCursor field0[3]; - GibCursor field1[3]; - GibCursor field2[3]; - } GibCursorPtrGibCursorPtrGibCursorPtrProd; -typedef struct GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd_struct { - GibCursor field0[3]; - GibCursor field1[3]; - GibCursor field2[3]; - GibCursor field3[3]; - GibCursor field4[3]; - } GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd; -typedef struct GibMutCursorProd_struct { - GibCursor *field0; - } GibMutCursorProd; -GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd -add1Tree(GibCursor cursor_ptr_1299[3], GibCursor cursor_ptr_1298[3], - GibCursor cursor_ptr_1300[3], GibCursor t_22_116_186[3]); -GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd -_copy_Tree(GibCursor *cursor_ptr_1403, GibCursor *cursor_ptr_1402, - GibCursor *cursor_ptr_1404, GibCursor *arg_70_121_195); -GibCursorPtrGibCursorPtrGibIntProd sumTree(GibCursor *cursor_ptr_1506, - GibCursor *tr_27_130_204); -GibCursorPtrGibCursorPtrGibCursorPtrProd mkTree(GibCursor *cursor_ptr_1567, - GibCursor *cursor_ptr_1568, - GibInt d_32_135_212, - GibInt acc_33_136_213); -GibCursorPtrGibCursorPtrProd _traverse_Tree(GibCursor *cursor_ptr_1605, - GibCursor *arg_88_137_221); -GibCursorPtrGibCursorPtrProd _print_Tree(GibCursor *cursor_ptr_1667, - GibCursor *arg_97_144_228); -GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd -_copy_without_ptrs_Tree(GibCursor *cursor_ptr_1730, GibCursor *cursor_ptr_1729, - GibCursor *cursor_ptr_1731, GibCursor *arg_79_161_245); -typedef enum { - GibInt_T, - GibFloat_T, - GibSym_T, - GibBool_T, - GibVector_T, - GibList_T, - GibCursor_T, - Tree_T, - } GibDatatype; -void info_table_initialize(void) -{ - int error = gib_info_table_initialize(8); - - if (error < 0) { - fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); - exit(1); - } - - GibDatatype field_tys[3]; - - error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, - 0); - if (error < 0) { - fprintf(stderr, - "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", - error, Tree_T, 0); - exit(1); - } - field_tys[0] = Tree_T; - field_tys[1] = Tree_T; - error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, - 2); - if (error < 0) { - fprintf(stderr, - "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", - error, Tree_T, 1); - exit(1); - } - gib_info_table_finalize(); -} -void symbol_table_initialize(void) -{ - gib_add_symbol(2007, ")"); - gib_add_symbol(2008, "(Node"); - gib_add_symbol(2009, "(Leaf"); - gib_add_symbol(2010, " ->r "); - gib_add_symbol(2011, " ->i "); - gib_add_symbol(2012, " "); -} -GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd add1Tree(GibCursor cursor_ptr_1299[3], - GibCursor cursor_ptr_1298[3], - GibCursor cursor_ptr_1300[3], - GibCursor t_22_116_186[3]) -{ - GibCursor end_r_598 = cursor_ptr_1298[2]; - GibCursor end_r_597 = cursor_ptr_1298[1]; - GibCursor end_r_596 = cursor_ptr_1298[0]; - GibCursor loc_IntTy_591 = cursor_ptr_1300[1]; - GibCursor loc_590 = cursor_ptr_1300[0]; - GibCursor loc_IntTy_592 = cursor_ptr_1300[2]; - - if (loc_IntTy_592 + 38 > end_r_598 || (loc_IntTy_591 + 38 > end_r_597 || - loc_590 + 12 > end_r_596)) { - gib_grow_region(&loc_IntTy_592, &end_r_598); - gib_grow_region(&loc_IntTy_591, &end_r_597); - gib_grow_region(&loc_590, &end_r_596); - } - - - GibCursor dcon_1307 = t_22_116_186[0]; - GibPackedTag tmpval_2050 = *(GibPackedTag *) dcon_1307; - GibCursor tmpcur_2051 = dcon_1307 + 1; - - - switch_2116: - ; - switch (tmpval_2050) { - - case 0: - { - GibCursor soa_field_0_1309 = t_22_116_186[1]; - GibCursor soa_field_1_1310 = t_22_116_186[2]; - GibInt tmpval_2052 = *(GibInt *) soa_field_0_1309; - GibCursor tmpcur_2053 = soa_field_0_1309 + sizeof(GibInt); - GibCursor loc_587 = t_22_116_186[0]; - GibCursor jumpf_dloc_916 = loc_587 + 1; - GibCursor loc_IntTy_588 = t_22_116_186[1]; - GibCursor loc_IntTy_589 = t_22_116_186[2]; - GibCursor jumpf_floc_loc_917 = soa_field_0_1309 + 8; - GibCursor jumpf_floc_loc_918 = loc_IntTy_589 + 0; - GibCursor cursor_ptr_1313_tmp[3] = {jumpf_dloc_916, - jumpf_floc_loc_917, - jumpf_floc_loc_918}; - //GibCursor *cursor_ptr_1313 = gib_array_alloc(cursor_ptr_1313_tmp, - // 3); - GibInt fltPkd_170_188 = tmpval_2052 + 1; - GibCursor loc_710 = loc_IntTy_592 + 0; - GibCursor new_floc_loc_713 = loc_710 + 8; - GibCursor new_dloc_711 = loc_590 + 1; - GibCursor new_floc_loc_712 = loc_IntTy_591 + 0; - - *(GibPackedTag *) loc_590 = 0; - - GibCursor writetag_1314 = loc_590 + 1; - GibCursor after_tag_1315 = loc_590 + 1; - - *(GibInt *) loc_IntTy_591 = fltPkd_170_188; - - GibCursor writecur_1319 = loc_IntTy_591 + sizeof(GibInt); - GibCursor aft_soa_loc_1321_tmp[3] = {after_tag_1315, writecur_1319, - loc_IntTy_592}; - //GibCursor *aft_soa_loc_1321 = gib_array_alloc(aft_soa_loc_1321_tmp, - // 3); - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{cursor_ptr_1299[0], cursor_ptr_1299[1], cursor_ptr_1299[2]}, - {end_r_596, end_r_597, end_r_598}, - {cursor_ptr_1313_tmp[0], cursor_ptr_1313_tmp[1], cursor_ptr_1313_tmp[2]}, - {cursor_ptr_1300[0], cursor_ptr_1300[1], cursor_ptr_1300[2]}, - {aft_soa_loc_1321_tmp[0], aft_soa_loc_1321_tmp[1], aft_soa_loc_1321_tmp[2]}}; - break; - } - - case 1: - { - GibCursor soa_field_0_1325 = t_22_116_186[1]; - GibCursor soa_field_1_1326 = t_22_116_186[2]; - GibInt tmpval_2058 = *(GibInt *) soa_field_1_1326; - GibCursor tmpcur_2059 = soa_field_1_1326 + sizeof(GibInt); - GibCursor cursor_ptr_1306_tmp[3] = {tmpcur_2051, soa_field_0_1325, - tmpcur_2059}; - - //GibCursor *cursor_ptr_1306 = gib_array_alloc(cursor_ptr_1306_tmp, - // 3); - - GibCursor loc_587 = t_22_116_186[0]; - GibCursor jumpf_dloc_920 = loc_587 + 1; - GibCursor loc_IntTy_588 = t_22_116_186[1]; - GibCursor loc_IntTy_589 = t_22_116_186[2]; - GibCursor jumpf_floc_loc_922 = soa_field_1_1326 + 8; - GibCursor jumpf_floc_loc_921 = loc_IntTy_588 + 0; - GibCursor loc_688 = jumpf_dloc_920 + 0; - GibCursor loc_687 = jumpf_floc_loc_922 + 0; - GibCursor loc_686 = jumpf_floc_loc_921 + 0; - GibCursor cursor_ptr_1330_tmp[3] = {jumpf_dloc_920, - jumpf_floc_loc_921, - jumpf_floc_loc_922}; - - //GibCursor *cursor_ptr_1330 = gib_array_alloc(cursor_ptr_1330_tmp, - // 3); - - GibInt fltPkd_171_192 = tmpval_2058 + 1; - GibCursor loc_710 = loc_IntTy_592 + 0; - GibCursor new_floc_loc_713 = loc_710 + 8; - GibCursor new_dloc_711 = loc_590 + 1; - GibCursor new_floc_loc_712 = loc_IntTy_591 + 0; - GibCursor cursor_ptr_1331_tmp[3] = {new_dloc_711, new_floc_loc_712, - new_floc_loc_713}; - - //GibCursor *cursor_ptr_1331 = gib_array_alloc(cursor_ptr_1331_tmp, - // 3); - - *(GibPackedTag *) loc_590 = 1; - - GibCursor writetag_1350 = loc_590 + 1; - GibCursor after_tag_1351 = loc_590 + 1; - - *(GibInt *) loc_IntTy_592 = fltPkd_171_192; - - GibCursor writecur_1355 = loc_IntTy_592 + sizeof(GibInt); - - GibCursor reg_tmp[3] = {end_r_596, end_r_597, end_r_598}; - - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_0 = - add1Tree(cursor_ptr_1299, reg_tmp, cursor_ptr_1331_tmp, cursor_ptr_1306_tmp); - - - GibCursor pvrtmp_2060[3] = {tmp_struct_0.field0[0], tmp_struct_0.field0[1], tmp_struct_0.field0[2]}; - GibCursor pvrtmp_2061[3] = {tmp_struct_0.field1[0], tmp_struct_0.field1[1], tmp_struct_0.field1[2]}; - GibCursor pvrtmp_2062[3] = {tmp_struct_0.field2[0], tmp_struct_0.field2[1], tmp_struct_0.field2[2]}; - GibCursor pvrtmp_2063[3] = {tmp_struct_0.field3[0], tmp_struct_0.field3[1], tmp_struct_0.field3[2]}; - GibCursor pvrtmp_2064[3] = {tmp_struct_0.field4[0], tmp_struct_0.field4[1], tmp_struct_0.field4[2]}; - - - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_1 = - add1Tree(pvrtmp_2060, pvrtmp_2061, pvrtmp_2064, pvrtmp_2062); - - - GibCursor pvrtmp_2069[3] = {tmp_struct_1.field0[0], tmp_struct_1.field0[1], tmp_struct_1.field0[2]}; - GibCursor pvrtmp_2070[3] = {tmp_struct_1.field1[0], tmp_struct_1.field1[1], tmp_struct_1.field1[2]}; - GibCursor pvrtmp_2071[3] = {tmp_struct_1.field2[0], tmp_struct_1.field2[1], tmp_struct_1.field2[2]}; - GibCursor pvrtmp_2072[3] = {tmp_struct_1.field3[0], tmp_struct_1.field3[1], tmp_struct_1.field3[2]}; - GibCursor pvrtmp_2073[3] = {tmp_struct_1.field4[0], tmp_struct_1.field4[1], tmp_struct_1.field4[2]}; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{pvrtmp_2069[0], pvrtmp_2069[1], pvrtmp_2069[2]}, - {pvrtmp_2070[0], pvrtmp_2070[1], pvrtmp_2070[2]}, - {pvrtmp_2071[0], pvrtmp_2071[1], pvrtmp_2071[2]}, - {cursor_ptr_1300[0], cursor_ptr_1300[1], cursor_ptr_1300[2]}, - {pvrtmp_2073[0], pvrtmp_2073[1], pvrtmp_2073[2]}}; - break; - } - - case GIB_INDIRECTION_TAG: - { - GibCursor soa_field_0_1363 = t_22_116_186[1]; - GibCursor soa_field_1_1364 = t_22_116_186[2]; - uintptr_t tagged_tmpcur_3 = *(uintptr_t *) tmpcur_2051; - GibCursor tmpcur_2082 = GIB_UNTAG(tagged_tmpcur_3); - GibCursor tmpaftercur_2083 = tmpcur_2051 + 8; - uint16_t tmptag_2084 = GIB_GET_TAG(tagged_tmpcur_3); - GibCursor *cursor_ptr_1304 = (GibCursor *) tmpcur_2082; - GibCursor loc_587 = t_22_116_186[0]; - GibCursor jump_dloc_1023 = loc_587 + 9; - GibCursor loc_IntTy_589 = t_22_116_186[2]; - GibCursor loc_IntTy_588 = t_22_116_186[1]; - GibCursor cursor_ptr_1368_tmp[3] = {jump_dloc_1023, loc_IntTy_588, - loc_IntTy_589}; - - //GibCursor *cursor_ptr_1368 = gib_array_alloc(cursor_ptr_1368_tmp, - // 3); - - GibCursor reg_tmp[3] = {end_r_596, end_r_597, end_r_598}; - - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_2 = - add1Tree(cursor_ptr_1304, reg_tmp, cursor_ptr_1300, cursor_ptr_1304); - GibCursor *pvrtmp_2085 = tmp_struct_2.field0; - GibCursor *pvrtmp_2086 = tmp_struct_2.field1; - GibCursor *pvrtmp_2087 = tmp_struct_2.field2; - GibCursor *pvrtmp_2088 = tmp_struct_2.field3; - GibCursor *pvrtmp_2089 = tmp_struct_2.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{cursor_ptr_1299[0], cursor_ptr_1299[1], cursor_ptr_1299[2]}, - {pvrtmp_2086[0], pvrtmp_2086[1], pvrtmp_2086[2]}, - {cursor_ptr_1368_tmp[0], cursor_ptr_1368_tmp[1], cursor_ptr_1368_tmp[2]}, - {pvrtmp_2088[0], pvrtmp_2088[1], pvrtmp_2088[2]}, - {pvrtmp_2089[0], pvrtmp_2089[1], pvrtmp_2089[2]}}; - break; - } - - case GIB_REDIRECTION_TAG: - { - GibCursor soa_field_0_1379 = t_22_116_186[1]; - GibCursor soa_field_1_1380 = t_22_116_186[2]; - uintptr_t tagged_tmpcur_7 = *(uintptr_t *) tmpcur_2051; - GibCursor tmpcur_2096 = GIB_UNTAG(tagged_tmpcur_7); - GibCursor tmpaftercur_2097 = tmpcur_2051 + 8; - uint16_t tmptag_2098 = GIB_GET_TAG(tagged_tmpcur_7); - GibCursor end_from_tagged_dcon_redir_1388 = tmpcur_2096 + - tmptag_2098; - GibCursor field_nxt_1386 = soa_field_0_1379 + 1; - uintptr_t tagged_tmpcur_6 = *(uintptr_t *) field_nxt_1386; - GibCursor tmpcur_2099 = GIB_UNTAG(tagged_tmpcur_6); - GibCursor tmpaftercur_2100 = field_nxt_1386 + 8; - uint16_t tmptag_2101 = GIB_GET_TAG(tagged_tmpcur_6); - GibCursor end_from_tagged_fld_redir_1389 = tmpcur_2099 + - tmptag_2101; - GibCursor field_nxt_1387 = soa_field_1_1380 + 1; - uintptr_t tagged_tmpcur_5 = *(uintptr_t *) field_nxt_1387; - GibCursor tmpcur_2102 = GIB_UNTAG(tagged_tmpcur_5); - GibCursor tmpaftercur_2103 = field_nxt_1387 + 8; - uint16_t tmptag_2104 = GIB_GET_TAG(tagged_tmpcur_5); - GibCursor end_from_tagged_fld_redir_1390 = tmpcur_2102 + - tmptag_2104; - GibCursor indr_1016_tmp[3] = {tmpcur_2096, tmpcur_2099, - tmpcur_2102}; - //GibCursor *indr_1016 = gib_array_alloc(indr_1016_tmp, 3); - GibCursor copy_dloc_1031 = loc_590 + 0; - GibCursor copy_floc_loc_1033 = loc_IntTy_592 + 0; - GibCursor copy_floc_loc_1032 = loc_IntTy_591 + 0; - GibCursor cursor_ptr_1391_tmp[3] = {copy_dloc_1031, - copy_floc_loc_1032, - copy_floc_loc_1033}; - //GibCursor *cursor_ptr_1391 = gib_array_alloc(cursor_ptr_1391_tmp, - // 3); - - GibCursor reg_tmp[3] = {end_r_596, end_r_597, end_r_598}; - - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_4 = - add1Tree(indr_1016_tmp, reg_tmp , cursor_ptr_1391_tmp, indr_1016_tmp); - GibCursor *pvrtmp_2105 = tmp_struct_4.field0; - GibCursor *pvrtmp_2106 = tmp_struct_4.field1; - GibCursor *pvrtmp_2107 = tmp_struct_4.field2; - GibCursor *pvrtmp_2108 = tmp_struct_4.field3; - GibCursor *pvrtmp_2109 = tmp_struct_4.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {{pvrtmp_2105[0], pvrtmp_2105[1], pvrtmp_2105[2]}, - {pvrtmp_2106[0], pvrtmp_2106[1], pvrtmp_2106[2]}, - {pvrtmp_2107[0], pvrtmp_2107[1], pvrtmp_2107[2]}, - {pvrtmp_2108[0], pvrtmp_2108[1], pvrtmp_2108[2]}, - {pvrtmp_2109[0], pvrtmp_2109[1], pvrtmp_2109[2]}}; - break; - } - - default: - { - printf("%s\n", "Unknown tag in: tmpval_2050"); - exit(1); - } - } -} -GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd _copy_Tree(GibCursor *cursor_ptr_1403, - GibCursor *cursor_ptr_1402, - GibCursor *cursor_ptr_1404, - GibCursor *arg_70_121_195) -{ - GibCursor *end_r_610 = &cursor_ptr_1402[2]; - GibCursor *end_r_609 = &cursor_ptr_1402[1]; - GibCursor *end_r_608 = &cursor_ptr_1402[0]; - GibCursor loc_IntTy_604 = cursor_ptr_1404[2]; - GibCursor loc_602 = cursor_ptr_1404[0]; - GibCursor loc_IntTy_603 = cursor_ptr_1404[1]; - GibCursor deref_1405 = *end_r_610; - GibCursor deref_1406 = *end_r_609; - GibCursor deref_1407 = *end_r_608; - - if (loc_IntTy_604 + 38 > deref_1405 || (loc_IntTy_603 + 38 > deref_1406 || - loc_602 + 12 > deref_1407)) { - gib_grow_region(&loc_IntTy_604, end_r_610); - gib_grow_region(&loc_IntTy_603, end_r_609); - gib_grow_region(&loc_602, end_r_608); - } - - GibCursor *end_r_605 = &cursor_ptr_1403[0]; - GibCursor *end_r_606 = &cursor_ptr_1403[1]; - GibCursor *end_r_607 = &cursor_ptr_1403[2]; - GibCursor dcon_1411 = arg_70_121_195[0]; - GibPackedTag tmpval_2117 = *(GibPackedTag *) dcon_1411; - GibCursor tmpcur_2118 = dcon_1411 + 1; - - - switch_2183: - ; - switch (tmpval_2117) { - - case 0: - { - GibCursor soa_field_0_1413 = arg_70_121_195[1]; - GibCursor soa_field_1_1414 = arg_70_121_195[2]; - GibInt tmpval_2119 = *(GibInt *) soa_field_0_1413; - GibCursor tmpcur_2120 = soa_field_0_1413 + sizeof(GibInt); - GibCursor loc_599 = arg_70_121_195[0]; - GibCursor jumpf_dloc_930 = loc_599 + 1; - GibCursor loc_IntTy_600 = arg_70_121_195[1]; - GibCursor loc_IntTy_601 = arg_70_121_195[2]; - GibCursor jumpf_floc_loc_931 = soa_field_0_1413 + 8; - GibCursor jumpf_floc_loc_932 = loc_IntTy_601 + 0; - GibCursor cursor_ptr_1417_tmp[3] = {jumpf_dloc_930, - jumpf_floc_loc_931, - jumpf_floc_loc_932}; - GibCursor *cursor_ptr_1417 = gib_array_alloc(cursor_ptr_1417_tmp, - 3); - GibCursor loc_756 = loc_IntTy_604 + 0; - GibCursor new_floc_loc_759 = loc_756 + 8; - GibCursor new_dloc_757 = loc_602 + 1; - GibCursor new_floc_loc_758 = loc_IntTy_603 + 0; - - *(GibPackedTag *) loc_602 = 0; - - GibCursor writetag_1418 = loc_602 + 1; - GibCursor after_tag_1419 = loc_602 + 1; - - *(GibInt *) loc_IntTy_603 = tmpval_2119; - - GibCursor writecur_1423 = loc_IntTy_603 + sizeof(GibInt); - GibCursor aft_soa_loc_1425_tmp[3] = {after_tag_1419, writecur_1423, - loc_IntTy_604}; - GibCursor *aft_soa_loc_1425 = gib_array_alloc(aft_soa_loc_1425_tmp, - 3); - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1403, - cursor_ptr_1402, - cursor_ptr_1417, - cursor_ptr_1404, - aft_soa_loc_1425}; - break; - } - - case 1: - { - GibCursor soa_field_0_1429 = arg_70_121_195[1]; - GibCursor soa_field_1_1430 = arg_70_121_195[2]; - GibInt tmpval_2125 = *(GibInt *) soa_field_1_1430; - GibCursor tmpcur_2126 = soa_field_1_1430 + sizeof(GibInt); - GibCursor cursor_ptr_1410_tmp[3] = {tmpcur_2118, soa_field_0_1429, - tmpcur_2126}; - GibCursor *cursor_ptr_1410 = gib_array_alloc(cursor_ptr_1410_tmp, - 3); - GibCursor loc_599 = arg_70_121_195[0]; - GibCursor jumpf_dloc_934 = loc_599 + 1; - GibCursor loc_IntTy_600 = arg_70_121_195[1]; - GibCursor loc_IntTy_601 = arg_70_121_195[2]; - GibCursor jumpf_floc_loc_936 = soa_field_1_1430 + 8; - GibCursor jumpf_floc_loc_935 = loc_IntTy_600 + 0; - GibCursor loc_734 = jumpf_dloc_934 + 0; - GibCursor loc_733 = jumpf_floc_loc_936 + 0; - GibCursor loc_732 = jumpf_floc_loc_935 + 0; - GibCursor cursor_ptr_1434_tmp[3] = {jumpf_dloc_934, - jumpf_floc_loc_935, - jumpf_floc_loc_936}; - GibCursor *cursor_ptr_1434 = gib_array_alloc(cursor_ptr_1434_tmp, - 3); - GibCursor loc_756 = loc_IntTy_604 + 0; - GibCursor new_floc_loc_759 = loc_756 + 8; - GibCursor new_dloc_757 = loc_602 + 1; - GibCursor new_floc_loc_758 = loc_IntTy_603 + 0; - GibCursor cursor_ptr_1435_tmp[3] = {new_dloc_757, new_floc_loc_758, - new_floc_loc_759}; - GibCursor *cursor_ptr_1435 = gib_array_alloc(cursor_ptr_1435_tmp, - 3); - - *(GibPackedTag *) loc_602 = 1; - - GibCursor writetag_1454 = loc_602 + 1; - GibCursor after_tag_1455 = loc_602 + 1; - - *(GibInt *) loc_IntTy_604 = tmpval_2125; - - GibCursor writecur_1459 = loc_IntTy_604 + sizeof(GibInt); - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_8 = - _copy_Tree(cursor_ptr_1403, cursor_ptr_1402, cursor_ptr_1435, cursor_ptr_1410); - GibCursor *pvrtmp_2127 = tmp_struct_8.field0; - GibCursor *pvrtmp_2128 = tmp_struct_8.field1; - GibCursor *pvrtmp_2129 = tmp_struct_8.field2; - GibCursor *pvrtmp_2130 = tmp_struct_8.field3; - GibCursor *pvrtmp_2131 = tmp_struct_8.field4; - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_9 = - _copy_Tree(pvrtmp_2127, pvrtmp_2128, pvrtmp_2131, pvrtmp_2129); - GibCursor *pvrtmp_2136 = tmp_struct_9.field0; - GibCursor *pvrtmp_2137 = tmp_struct_9.field1; - GibCursor *pvrtmp_2138 = tmp_struct_9.field2; - GibCursor *pvrtmp_2139 = tmp_struct_9.field3; - GibCursor *pvrtmp_2140 = tmp_struct_9.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2136, - pvrtmp_2137, - pvrtmp_2138, - cursor_ptr_1404, - pvrtmp_2140}; - break; - } - - case GIB_INDIRECTION_TAG: - { - GibCursor soa_field_0_1467 = arg_70_121_195[1]; - GibCursor soa_field_1_1468 = arg_70_121_195[2]; - uintptr_t tagged_tmpcur_11 = *(uintptr_t *) tmpcur_2118; - GibCursor tmpcur_2149 = GIB_UNTAG(tagged_tmpcur_11); - GibCursor tmpaftercur_2150 = tmpcur_2118 + 8; - uint16_t tmptag_2151 = GIB_GET_TAG(tagged_tmpcur_11); - GibCursor *cursor_ptr_1408 = (GibCursor *) tmpcur_2149; - GibCursor loc_599 = arg_70_121_195[0]; - GibCursor jump_dloc_1041 = loc_599 + 9; - GibCursor loc_IntTy_601 = arg_70_121_195[2]; - GibCursor loc_IntTy_600 = arg_70_121_195[1]; - GibCursor cursor_ptr_1472_tmp[3] = {jump_dloc_1041, loc_IntTy_600, - loc_IntTy_601}; - GibCursor *cursor_ptr_1472 = gib_array_alloc(cursor_ptr_1472_tmp, - 3); - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_10 = - _copy_Tree(cursor_ptr_1408, cursor_ptr_1402, cursor_ptr_1404, cursor_ptr_1408); - GibCursor *pvrtmp_2152 = tmp_struct_10.field0; - GibCursor *pvrtmp_2153 = tmp_struct_10.field1; - GibCursor *pvrtmp_2154 = tmp_struct_10.field2; - GibCursor *pvrtmp_2155 = tmp_struct_10.field3; - GibCursor *pvrtmp_2156 = tmp_struct_10.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1403, - pvrtmp_2153, - cursor_ptr_1472, - pvrtmp_2155, - pvrtmp_2156}; - break; - } - - case GIB_REDIRECTION_TAG: - { - GibCursor soa_field_0_1483 = arg_70_121_195[1]; - GibCursor soa_field_1_1484 = arg_70_121_195[2]; - uintptr_t tagged_tmpcur_15 = *(uintptr_t *) tmpcur_2118; - GibCursor tmpcur_2163 = GIB_UNTAG(tagged_tmpcur_15); - GibCursor tmpaftercur_2164 = tmpcur_2118 + 8; - uint16_t tmptag_2165 = GIB_GET_TAG(tagged_tmpcur_15); - GibCursor end_from_tagged_dcon_redir_1492 = tmpcur_2163 + - tmptag_2165; - GibCursor field_nxt_1490 = soa_field_0_1483 + 1; - uintptr_t tagged_tmpcur_14 = *(uintptr_t *) field_nxt_1490; - GibCursor tmpcur_2166 = GIB_UNTAG(tagged_tmpcur_14); - GibCursor tmpaftercur_2167 = field_nxt_1490 + 8; - uint16_t tmptag_2168 = GIB_GET_TAG(tagged_tmpcur_14); - GibCursor end_from_tagged_fld_redir_1493 = tmpcur_2166 + - tmptag_2168; - GibCursor field_nxt_1491 = soa_field_1_1484 + 1; - uintptr_t tagged_tmpcur_13 = *(uintptr_t *) field_nxt_1491; - GibCursor tmpcur_2169 = GIB_UNTAG(tagged_tmpcur_13); - GibCursor tmpaftercur_2170 = field_nxt_1491 + 8; - uint16_t tmptag_2171 = GIB_GET_TAG(tagged_tmpcur_13); - GibCursor end_from_tagged_fld_redir_1494 = tmpcur_2169 + - tmptag_2171; - GibCursor indr_1034_tmp[3] = {tmpcur_2163, tmpcur_2166, - tmpcur_2169}; - GibCursor *indr_1034 = gib_array_alloc(indr_1034_tmp, 3); - GibCursor copy_dloc_1049 = loc_602 + 0; - GibCursor copy_floc_loc_1051 = loc_IntTy_604 + 0; - GibCursor copy_floc_loc_1050 = loc_IntTy_603 + 0; - GibCursor cursor_ptr_1495_tmp[3] = {copy_dloc_1049, - copy_floc_loc_1050, - copy_floc_loc_1051}; - GibCursor *cursor_ptr_1495 = gib_array_alloc(cursor_ptr_1495_tmp, - 3); - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_12 = - _copy_Tree(indr_1034, cursor_ptr_1402, cursor_ptr_1495, indr_1034); - GibCursor *pvrtmp_2172 = tmp_struct_12.field0; - GibCursor *pvrtmp_2173 = tmp_struct_12.field1; - GibCursor *pvrtmp_2174 = tmp_struct_12.field2; - GibCursor *pvrtmp_2175 = tmp_struct_12.field3; - GibCursor *pvrtmp_2176 = tmp_struct_12.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2172, - pvrtmp_2173, - pvrtmp_2174, - pvrtmp_2175, - pvrtmp_2176}; - break; - } - - default: - { - printf("%s\n", "Unknown tag in: tmpval_2117"); - exit(1); - } - } -} -GibCursorPtrGibCursorPtrGibIntProd sumTree(GibCursor *cursor_ptr_1506, - GibCursor *tr_27_130_204) -{ - GibCursor *end_r_614 = &cursor_ptr_1506[0]; - GibCursor *end_r_615 = &cursor_ptr_1506[1]; - GibCursor *end_r_616 = &cursor_ptr_1506[2]; - GibCursor dcon_1510 = tr_27_130_204[0]; - GibPackedTag tmpval_2184 = *(GibPackedTag *) dcon_1510; - GibCursor tmpcur_2185 = dcon_1510 + 1; - - - switch_2214: - ; - switch (tmpval_2184) { - - case 0: - { - GibCursor soa_field_0_1512 = tr_27_130_204[1]; - GibCursor soa_field_1_1513 = tr_27_130_204[2]; - GibInt tmpval_2186 = *(GibInt *) soa_field_0_1512; - GibCursor tmpcur_2187 = soa_field_0_1512 + sizeof(GibInt); - GibCursor loc_611 = tr_27_130_204[0]; - GibCursor jumpf_dloc_944 = loc_611 + 1; - GibCursor loc_IntTy_612 = tr_27_130_204[1]; - GibCursor loc_IntTy_613 = tr_27_130_204[2]; - GibCursor jumpf_floc_loc_945 = soa_field_0_1512 + 8; - GibCursor jumpf_floc_loc_946 = loc_IntTy_613 + 0; - GibCursor cursor_ptr_1516_tmp[3] = {jumpf_dloc_944, - jumpf_floc_loc_945, - jumpf_floc_loc_946}; - GibCursor *cursor_ptr_1516 = gib_array_alloc(cursor_ptr_1516_tmp, - 3); - - return (GibCursorPtrGibCursorPtrGibIntProd) {cursor_ptr_1506, - cursor_ptr_1516, - tmpval_2186}; - break; - } - - case 1: - { - GibCursor soa_field_0_1518 = tr_27_130_204[1]; - GibCursor soa_field_1_1519 = tr_27_130_204[2]; - GibInt tmpval_2188 = *(GibInt *) soa_field_1_1519; - GibCursor tmpcur_2189 = soa_field_1_1519 + sizeof(GibInt); - GibCursor cursor_ptr_1509_tmp[3] = {tmpcur_2185, soa_field_0_1518, - tmpcur_2189}; - GibCursor *cursor_ptr_1509 = gib_array_alloc(cursor_ptr_1509_tmp, - 3); - GibCursor loc_611 = tr_27_130_204[0]; - GibCursor jumpf_dloc_947 = loc_611 + 1; - GibCursor loc_IntTy_612 = tr_27_130_204[1]; - GibCursor loc_IntTy_613 = tr_27_130_204[2]; - GibCursor jumpf_floc_loc_949 = soa_field_1_1519 + 8; - GibCursor jumpf_floc_loc_948 = loc_IntTy_612 + 0; - GibCursor loc_777 = jumpf_dloc_947 + 0; - GibCursor loc_776 = jumpf_floc_loc_949 + 0; - GibCursor loc_775 = jumpf_floc_loc_948 + 0; - GibCursor cursor_ptr_1523_tmp[3] = {jumpf_dloc_947, - jumpf_floc_loc_948, - jumpf_floc_loc_949}; - GibCursor *cursor_ptr_1523 = gib_array_alloc(cursor_ptr_1523_tmp, - 3); - GibCursorPtrGibCursorPtrGibIntProd tmp_struct_16 = - sumTree(cursor_ptr_1506, cursor_ptr_1509); - GibCursor *pvrtmp_2190 = tmp_struct_16.field0; - GibCursor *pvrtmp_2191 = tmp_struct_16.field1; - GibInt pvrtmp_2192 = tmp_struct_16.field2; - GibInt fltPrm_174_210 = tmpval_2188 + pvrtmp_2192; - GibCursorPtrGibCursorPtrGibIntProd tmp_struct_17 = - sumTree(pvrtmp_2190, pvrtmp_2191); - GibCursor *pvrtmp_2193 = tmp_struct_17.field0; - GibCursor *pvrtmp_2194 = tmp_struct_17.field1; - GibInt pvrtmp_2195 = tmp_struct_17.field2; - GibInt tailprim_956 = fltPrm_174_210 + pvrtmp_2195; - - return (GibCursorPtrGibCursorPtrGibIntProd) {pvrtmp_2193, - pvrtmp_2194, - tailprim_956}; - break; - } - - case GIB_INDIRECTION_TAG: - { - GibCursor soa_field_0_1536 = tr_27_130_204[1]; - GibCursor soa_field_1_1537 = tr_27_130_204[2]; - uintptr_t tagged_tmpcur_19 = *(uintptr_t *) tmpcur_2185; - GibCursor tmpcur_2196 = GIB_UNTAG(tagged_tmpcur_19); - GibCursor tmpaftercur_2197 = tmpcur_2185 + 8; - uint16_t tmptag_2198 = GIB_GET_TAG(tagged_tmpcur_19); - GibCursor *cursor_ptr_1507 = (GibCursor *) tmpcur_2196; - GibCursor loc_611 = tr_27_130_204[0]; - GibCursor jump_dloc_1059 = loc_611 + 9; - GibCursor loc_IntTy_613 = tr_27_130_204[2]; - GibCursor loc_IntTy_612 = tr_27_130_204[1]; - GibCursor cursor_ptr_1541_tmp[3] = {jump_dloc_1059, loc_IntTy_612, - loc_IntTy_613}; - GibCursor *cursor_ptr_1541 = gib_array_alloc(cursor_ptr_1541_tmp, - 3); - GibCursorPtrGibCursorPtrGibIntProd tmp_struct_18 = - sumTree(cursor_ptr_1507, cursor_ptr_1507); - GibCursor *pvrtmp_2199 = tmp_struct_18.field0; - GibCursor *pvrtmp_2200 = tmp_struct_18.field1; - GibInt pvrtmp_2201 = tmp_struct_18.field2; - - return (GibCursorPtrGibCursorPtrGibIntProd) {cursor_ptr_1506, - cursor_ptr_1541, - pvrtmp_2201}; - break; - } - - case GIB_REDIRECTION_TAG: - { - GibCursor soa_field_0_1549 = tr_27_130_204[1]; - GibCursor soa_field_1_1550 = tr_27_130_204[2]; - uintptr_t tagged_tmpcur_23 = *(uintptr_t *) tmpcur_2185; - GibCursor tmpcur_2202 = GIB_UNTAG(tagged_tmpcur_23); - GibCursor tmpaftercur_2203 = tmpcur_2185 + 8; - uint16_t tmptag_2204 = GIB_GET_TAG(tagged_tmpcur_23); - GibCursor end_from_tagged_dcon_redir_1558 = tmpcur_2202 + - tmptag_2204; - GibCursor field_nxt_1556 = soa_field_0_1549 + 1; - uintptr_t tagged_tmpcur_22 = *(uintptr_t *) field_nxt_1556; - GibCursor tmpcur_2205 = GIB_UNTAG(tagged_tmpcur_22); - GibCursor tmpaftercur_2206 = field_nxt_1556 + 8; - uint16_t tmptag_2207 = GIB_GET_TAG(tagged_tmpcur_22); - GibCursor end_from_tagged_fld_redir_1559 = tmpcur_2205 + - tmptag_2207; - GibCursor field_nxt_1557 = soa_field_1_1550 + 1; - uintptr_t tagged_tmpcur_21 = *(uintptr_t *) field_nxt_1557; - GibCursor tmpcur_2208 = GIB_UNTAG(tagged_tmpcur_21); - GibCursor tmpaftercur_2209 = field_nxt_1557 + 8; - uint16_t tmptag_2210 = GIB_GET_TAG(tagged_tmpcur_21); - GibCursor end_from_tagged_fld_redir_1560 = tmpcur_2208 + - tmptag_2210; - GibCursor indr_1052_tmp[3] = {tmpcur_2202, tmpcur_2205, - tmpcur_2208}; - GibCursor *indr_1052 = gib_array_alloc(indr_1052_tmp, 3); - GibCursorPtrGibCursorPtrGibIntProd tmp_struct_20 = - sumTree(indr_1052, indr_1052); - GibCursor *pvrtmp_2211 = tmp_struct_20.field0; - GibCursor *pvrtmp_2212 = tmp_struct_20.field1; - GibInt pvrtmp_2213 = tmp_struct_20.field2; - - return (GibCursorPtrGibCursorPtrGibIntProd) {pvrtmp_2211, - pvrtmp_2212, - pvrtmp_2213}; - break; - } - - default: - { - printf("%s\n", "Unknown tag in: tmpval_2184"); - exit(1); - } - } -} -GibCursorPtrGibCursorPtrGibCursorPtrProd mkTree(GibCursor cursor_ptr_1567[3], - GibCursor cursor_ptr_1568[3], - GibInt d_32_135_212, - GibInt acc_33_136_213) -{ - GibCursor end_r_622 = cursor_ptr_1567[2]; - GibCursor end_r_621 = cursor_ptr_1567[1]; - GibCursor end_r_620 = cursor_ptr_1567[0]; - GibCursor loc_617 = cursor_ptr_1568[0]; - GibCursor loc_IntTy_619 = cursor_ptr_1568[2]; - GibCursor loc_IntTy_618 = cursor_ptr_1568[1]; - GibCursor deref_1569 = end_r_622; - GibCursor deref_1570 = end_r_621; - GibCursor deref_1571 = end_r_620; - - if (loc_IntTy_619 + 38 > deref_1569 || (loc_IntTy_618 + 38 > deref_1570 || - loc_617 + 12 > deref_1571)) { - gib_grow_region(&loc_IntTy_619, &end_r_622); - gib_grow_region(&loc_IntTy_618, &end_r_621); - gib_grow_region(&loc_617, &end_r_620); - } - - GibBool fltIf_177_214 = d_32_135_212 == 0; - - if (fltIf_177_214) { - GibCursor new_floc_loc_804 = loc_IntTy_618 + 0; - GibCursor loc_802 = loc_IntTy_619 + 0; - GibCursor new_floc_loc_805 = loc_802 + 8; - GibCursor new_dloc_803 = loc_617 + 1; - - *(GibPackedTag *) loc_617 = 0; - - GibCursor writetag_1572 = loc_617 + 1; - GibCursor after_tag_1573 = loc_617 + 1; - - *(GibInt *) loc_IntTy_618 = acc_33_136_213; - - GibCursor writecur_1577 = loc_IntTy_618 + sizeof(GibInt); - GibCursor aft_soa_loc_1579_tmp[3] = {after_tag_1573, writecur_1577, - loc_IntTy_619}; - //GibCursor *aft_soa_loc_1579 = gib_array_alloc(aft_soa_loc_1579_tmp, 3); - - return (GibCursorPtrGibCursorPtrGibCursorPtrProd) {{end_r_620, end_r_621, end_r_622}, - {cursor_ptr_1568[0], cursor_ptr_1568[1], cursor_ptr_1568[2]}, - {aft_soa_loc_1579_tmp[0], aft_soa_loc_1579_tmp[1], aft_soa_loc_1579_tmp[2]}}; - } else { - GibInt fltAppE_179_215 = d_32_135_212 - 1; - GibInt fltAppE_180_216 = d_32_135_212 + acc_33_136_213; - GibCursor new_floc_loc_804 = loc_IntTy_618 + 0; - GibCursor loc_802 = loc_IntTy_619 + 0; - GibCursor new_floc_loc_805 = loc_802 + 8; - GibCursor new_dloc_803 = loc_617 + 1; - GibCursor cursor_ptr_1582_tmp[3] = {new_dloc_803, new_floc_loc_804, - new_floc_loc_805}; - //GibCursor *cursor_ptr_1582 = gib_array_alloc(cursor_ptr_1582_tmp, 3); - - *(GibPackedTag *) loc_617 = 1; - - GibCursor writetag_1592 = loc_617 + 1; - GibCursor after_tag_1593 = loc_617 + 1; - - *(GibInt *) loc_IntTy_619 = d_32_135_212; - - GibCursor writecur_1597 = loc_IntTy_619 + sizeof(GibInt); - GibCursor newEnds[3] = {end_r_620, end_r_621, end_r_622}; - GibCursorPtrGibCursorPtrGibCursorPtrProd tmp_struct_24 = - mkTree(newEnds, cursor_ptr_1582_tmp, fltAppE_179_215, fltAppE_180_216); - GibCursor pvrtmp_2219[3] = {tmp_struct_24.field0[0], tmp_struct_24.field0[1], tmp_struct_24.field0[2]}; - GibCursor pvrtmp_2220[3] = {tmp_struct_24.field1[0], tmp_struct_24.field1[1], tmp_struct_24.field1[2]}; - GibCursor pvrtmp_2221[3] = {tmp_struct_24.field2[0], tmp_struct_24.field2[1], tmp_struct_24.field2[2]}; - - GibInt fltAppE_182_218 = d_32_135_212 - 1; - GibInt fltAppE_183_219 = d_32_135_212 + acc_33_136_213; - GibCursorPtrGibCursorPtrGibCursorPtrProd tmp_struct_25 = - mkTree(pvrtmp_2219, pvrtmp_2221, fltAppE_182_218, fltAppE_183_219); - GibCursor pvrtmp_2226[3] = {tmp_struct_25.field0[0], tmp_struct_25.field0[1], tmp_struct_25.field0[2]}; - GibCursor pvrtmp_2227[3] = {tmp_struct_25.field1[0], tmp_struct_25.field1[1], tmp_struct_25.field1[2]}; - GibCursor pvrtmp_2228[3] = {tmp_struct_25.field2[0], tmp_struct_25.field2[1], tmp_struct_25.field2[2]}; - - return (GibCursorPtrGibCursorPtrGibCursorPtrProd) {{pvrtmp_2226[0], pvrtmp_2226[1], pvrtmp_2226[2]}, - {cursor_ptr_1568[0], cursor_ptr_1568[1], cursor_ptr_1568[2]}, - {pvrtmp_2228[0], pvrtmp_2228[1], pvrtmp_2228[2]}}; - } -} -GibCursorPtrGibCursorPtrProd _traverse_Tree(GibCursor *cursor_ptr_1605, - GibCursor *arg_88_137_221) -{ - GibCursor *end_r_626 = &cursor_ptr_1605[0]; - GibCursor *end_r_627 = &cursor_ptr_1605[1]; - GibCursor *end_r_628 = &cursor_ptr_1605[2]; - GibCursor dcon_1609 = arg_88_137_221[0]; - GibPackedTag tmpval_2237 = *(GibPackedTag *) dcon_1609; - GibCursor tmpcur_2238 = dcon_1609 + 1; - - - switch_2263: - ; - switch (tmpval_2237) { - - case 0: - { - GibCursor soa_field_0_1611 = arg_88_137_221[1]; - GibCursor soa_field_1_1612 = arg_88_137_221[2]; - GibInt tmpval_2239 = *(GibInt *) soa_field_0_1611; - GibCursor tmpcur_2240 = soa_field_0_1611 + sizeof(GibInt); - GibCursor loc_623 = arg_88_137_221[0]; - GibCursor jumpf_dloc_959 = loc_623 + 1; - GibCursor loc_IntTy_624 = arg_88_137_221[1]; - GibCursor loc_IntTy_625 = arg_88_137_221[2]; - GibCursor jumpf_floc_loc_960 = soa_field_0_1611 + 8; - GibCursor jumpf_floc_loc_961 = loc_IntTy_625 + 0; - GibCursor cursor_ptr_1615_tmp[3] = {jumpf_dloc_959, - jumpf_floc_loc_960, - jumpf_floc_loc_961}; - GibCursor *cursor_ptr_1615 = gib_array_alloc(cursor_ptr_1615_tmp, - 3); - - return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1605, - cursor_ptr_1615}; - break; - } - - case 1: - { - GibCursor soa_field_0_1617 = arg_88_137_221[1]; - GibCursor soa_field_1_1618 = arg_88_137_221[2]; - GibInt tmpval_2241 = *(GibInt *) soa_field_1_1618; - GibCursor tmpcur_2242 = soa_field_1_1618 + sizeof(GibInt); - GibCursor cursor_ptr_1608_tmp[3] = {tmpcur_2238, soa_field_0_1617, - tmpcur_2242}; - GibCursor *cursor_ptr_1608 = gib_array_alloc(cursor_ptr_1608_tmp, - 3); - GibCursor loc_623 = arg_88_137_221[0]; - GibCursor jumpf_dloc_963 = loc_623 + 1; - GibCursor loc_IntTy_624 = arg_88_137_221[1]; - GibCursor loc_IntTy_625 = arg_88_137_221[2]; - GibCursor jumpf_floc_loc_965 = soa_field_1_1618 + 8; - GibCursor jumpf_floc_loc_964 = loc_IntTy_624 + 0; - GibCursor loc_823 = jumpf_dloc_963 + 0; - GibCursor loc_822 = jumpf_floc_loc_965 + 0; - GibCursor loc_821 = jumpf_floc_loc_964 + 0; - GibCursor cursor_ptr_1622_tmp[3] = {jumpf_dloc_963, - jumpf_floc_loc_964, - jumpf_floc_loc_965}; - GibCursor *cursor_ptr_1622 = gib_array_alloc(cursor_ptr_1622_tmp, - 3); - GibCursorPtrGibCursorPtrProd tmp_struct_26 = - _traverse_Tree(cursor_ptr_1605, cursor_ptr_1608); - GibCursor *pvrtmp_2243 = tmp_struct_26.field0; - GibCursor *pvrtmp_2244 = tmp_struct_26.field1; - GibCursorPtrGibCursorPtrProd tmp_struct_27 = - _traverse_Tree(pvrtmp_2243, pvrtmp_2244); - GibCursor *pvrtmp_2245 = tmp_struct_27.field0; - GibCursor *pvrtmp_2246 = tmp_struct_27.field1; - - return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2245, pvrtmp_2246}; - break; - } - - case GIB_INDIRECTION_TAG: - { - GibCursor soa_field_0_1635 = arg_88_137_221[1]; - GibCursor soa_field_1_1636 = arg_88_137_221[2]; - uintptr_t tagged_tmpcur_29 = *(uintptr_t *) tmpcur_2238; - GibCursor tmpcur_2247 = GIB_UNTAG(tagged_tmpcur_29); - GibCursor tmpaftercur_2248 = tmpcur_2238 + 8; - uint16_t tmptag_2249 = GIB_GET_TAG(tagged_tmpcur_29); - GibCursor *cursor_ptr_1606 = (GibCursor *) tmpcur_2247; - GibCursor loc_623 = arg_88_137_221[0]; - GibCursor jump_dloc_1074 = loc_623 + 9; - GibCursor loc_IntTy_625 = arg_88_137_221[2]; - GibCursor loc_IntTy_624 = arg_88_137_221[1]; - GibCursor cursor_ptr_1640_tmp[3] = {jump_dloc_1074, loc_IntTy_624, - loc_IntTy_625}; - GibCursor *cursor_ptr_1640 = gib_array_alloc(cursor_ptr_1640_tmp, - 3); - GibCursorPtrGibCursorPtrProd tmp_struct_28 = - _traverse_Tree(cursor_ptr_1606, cursor_ptr_1606); - GibCursor *pvrtmp_2250 = tmp_struct_28.field0; - GibCursor *pvrtmp_2251 = tmp_struct_28.field1; - - return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1605, - cursor_ptr_1640}; - break; - } - - case GIB_REDIRECTION_TAG: - { - GibCursor soa_field_0_1648 = arg_88_137_221[1]; - GibCursor soa_field_1_1649 = arg_88_137_221[2]; - uintptr_t tagged_tmpcur_33 = *(uintptr_t *) tmpcur_2238; - GibCursor tmpcur_2252 = GIB_UNTAG(tagged_tmpcur_33); - GibCursor tmpaftercur_2253 = tmpcur_2238 + 8; - uint16_t tmptag_2254 = GIB_GET_TAG(tagged_tmpcur_33); - GibCursor end_from_tagged_dcon_redir_1657 = tmpcur_2252 + - tmptag_2254; - GibCursor field_nxt_1655 = soa_field_0_1648 + 1; - uintptr_t tagged_tmpcur_32 = *(uintptr_t *) field_nxt_1655; - GibCursor tmpcur_2255 = GIB_UNTAG(tagged_tmpcur_32); - GibCursor tmpaftercur_2256 = field_nxt_1655 + 8; - uint16_t tmptag_2257 = GIB_GET_TAG(tagged_tmpcur_32); - GibCursor end_from_tagged_fld_redir_1658 = tmpcur_2255 + - tmptag_2257; - GibCursor field_nxt_1656 = soa_field_1_1649 + 1; - uintptr_t tagged_tmpcur_31 = *(uintptr_t *) field_nxt_1656; - GibCursor tmpcur_2258 = GIB_UNTAG(tagged_tmpcur_31); - GibCursor tmpaftercur_2259 = field_nxt_1656 + 8; - uint16_t tmptag_2260 = GIB_GET_TAG(tagged_tmpcur_31); - GibCursor end_from_tagged_fld_redir_1659 = tmpcur_2258 + - tmptag_2260; - GibCursor indr_1067_tmp[3] = {tmpcur_2252, tmpcur_2255, - tmpcur_2258}; - GibCursor *indr_1067 = gib_array_alloc(indr_1067_tmp, 3); - GibCursorPtrGibCursorPtrProd tmp_struct_30 = - _traverse_Tree(indr_1067, indr_1067); - GibCursor *pvrtmp_2261 = tmp_struct_30.field0; - GibCursor *pvrtmp_2262 = tmp_struct_30.field1; - - return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2261, pvrtmp_2262}; - break; - } - - default: - { - printf("%s\n", "Unknown tag in: tmpval_2237"); - exit(1); - } - } -} -GibCursorPtrGibCursorPtrProd _print_Tree(GibCursor *cursor_ptr_1667, - GibCursor *arg_97_144_228) -{ - GibCursor *end_r_632 = &cursor_ptr_1667[0]; - GibCursor *end_r_633 = &cursor_ptr_1667[1]; - GibCursor *end_r_634 = &cursor_ptr_1667[2]; - GibCursor dcon_1671 = arg_97_144_228[0]; - GibPackedTag tmpval_2264 = *(GibPackedTag *) dcon_1671; - GibCursor tmpcur_2265 = dcon_1671 + 1; - - - switch_2290: - ; - switch (tmpval_2264) { - - case 0: - { - GibCursor soa_field_0_1673 = arg_97_144_228[1]; - GibCursor soa_field_1_1674 = arg_97_144_228[2]; - GibInt tmpval_2266 = *(GibInt *) soa_field_0_1673; - GibCursor tmpcur_2267 = soa_field_0_1673 + sizeof(GibInt); - GibCursor loc_629 = arg_97_144_228[0]; - GibCursor jumpf_dloc_973 = loc_629 + 1; - GibCursor loc_IntTy_630 = arg_97_144_228[1]; - GibCursor loc_IntTy_631 = arg_97_144_228[2]; - GibCursor jumpf_floc_loc_974 = soa_field_0_1673 + 8; - GibCursor jumpf_floc_loc_975 = loc_IntTy_631 + 0; - GibCursor cursor_ptr_1677_tmp[3] = {jumpf_dloc_973, - jumpf_floc_loc_974, - jumpf_floc_loc_975}; - GibCursor *cursor_ptr_1677 = gib_array_alloc(cursor_ptr_1677_tmp, - 3); - unsigned char wildcard_100_146_230 = gib_print_symbol(2009); - unsigned char wildcard_102_147_231 = gib_print_symbol(2012); - unsigned char y_99_148_232 = printf("%ld", tmpval_2266); - unsigned char wildcard_101_149_233 = gib_print_symbol(2007); - - return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1667, - cursor_ptr_1677}; - break; - } - - case 1: - { - GibCursor soa_field_0_1679 = arg_97_144_228[1]; - GibCursor soa_field_1_1680 = arg_97_144_228[2]; - GibInt tmpval_2268 = *(GibInt *) soa_field_1_1680; - GibCursor tmpcur_2269 = soa_field_1_1680 + sizeof(GibInt); - GibCursor cursor_ptr_1670_tmp[3] = {tmpcur_2265, soa_field_0_1679, - tmpcur_2269}; - GibCursor *cursor_ptr_1670 = gib_array_alloc(cursor_ptr_1670_tmp, - 3); - GibCursor loc_629 = arg_97_144_228[0]; - GibCursor jumpf_dloc_977 = loc_629 + 1; - GibCursor loc_IntTy_630 = arg_97_144_228[1]; - GibCursor loc_IntTy_631 = arg_97_144_228[2]; - GibCursor jumpf_floc_loc_979 = soa_field_1_1680 + 8; - GibCursor jumpf_floc_loc_978 = loc_IntTy_630 + 0; - GibCursor loc_845 = jumpf_dloc_977 + 0; - GibCursor loc_844 = jumpf_floc_loc_979 + 0; - GibCursor loc_843 = jumpf_floc_loc_978 + 0; - GibCursor cursor_ptr_1684_tmp[3] = {jumpf_dloc_977, - jumpf_floc_loc_978, - jumpf_floc_loc_979}; - GibCursor *cursor_ptr_1684 = gib_array_alloc(cursor_ptr_1684_tmp, - 3); - unsigned char wildcard_109_153_237 = gib_print_symbol(2008); - unsigned char wildcard_113_154_238 = gib_print_symbol(2012); - unsigned char y_106_155_239 = printf("%ld", tmpval_2268); - unsigned char wildcard_112_156_240 = gib_print_symbol(2012); - GibCursorPtrGibCursorPtrProd tmp_struct_34 = - _print_Tree(cursor_ptr_1667, cursor_ptr_1670); - GibCursor *pvrtmp_2270 = tmp_struct_34.field0; - GibCursor *pvrtmp_2271 = tmp_struct_34.field1; - unsigned char wildcard_111_158_242 = gib_print_symbol(2012); - GibCursorPtrGibCursorPtrProd tmp_struct_35 = - _print_Tree(pvrtmp_2270, pvrtmp_2271); - GibCursor *pvrtmp_2272 = tmp_struct_35.field0; - GibCursor *pvrtmp_2273 = tmp_struct_35.field1; - unsigned char wildcard_110_160_244 = gib_print_symbol(2007); - - return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2272, pvrtmp_2273}; - break; - } - - case GIB_INDIRECTION_TAG: - { - GibCursor soa_field_0_1697 = arg_97_144_228[1]; - GibCursor soa_field_1_1698 = arg_97_144_228[2]; - uintptr_t tagged_tmpcur_37 = *(uintptr_t *) tmpcur_2265; - GibCursor tmpcur_2274 = GIB_UNTAG(tagged_tmpcur_37); - GibCursor tmpaftercur_2275 = tmpcur_2265 + 8; - uint16_t tmptag_2276 = GIB_GET_TAG(tagged_tmpcur_37); - GibCursor *cursor_ptr_1668 = (GibCursor *) tmpcur_2274; - GibCursor loc_629 = arg_97_144_228[0]; - GibCursor jump_dloc_1089 = loc_629 + 9; - GibCursor loc_IntTy_631 = arg_97_144_228[2]; - GibCursor loc_IntTy_630 = arg_97_144_228[1]; - GibCursor cursor_ptr_1702_tmp[3] = {jump_dloc_1089, loc_IntTy_630, - loc_IntTy_631}; - GibCursor *cursor_ptr_1702 = gib_array_alloc(cursor_ptr_1702_tmp, - 3); - unsigned char wildcard_1096 = gib_print_symbol(2011); - GibCursorPtrGibCursorPtrProd tmp_struct_36 = - _print_Tree(cursor_ptr_1668, cursor_ptr_1668); - GibCursor *pvrtmp_2277 = tmp_struct_36.field0; - GibCursor *pvrtmp_2278 = tmp_struct_36.field1; - - return (GibCursorPtrGibCursorPtrProd) {cursor_ptr_1667, - cursor_ptr_1702}; - break; - } - - case GIB_REDIRECTION_TAG: - { - GibCursor soa_field_0_1710 = arg_97_144_228[1]; - GibCursor soa_field_1_1711 = arg_97_144_228[2]; - uintptr_t tagged_tmpcur_41 = *(uintptr_t *) tmpcur_2265; - GibCursor tmpcur_2279 = GIB_UNTAG(tagged_tmpcur_41); - GibCursor tmpaftercur_2280 = tmpcur_2265 + 8; - uint16_t tmptag_2281 = GIB_GET_TAG(tagged_tmpcur_41); - GibCursor end_from_tagged_dcon_redir_1719 = tmpcur_2279 + - tmptag_2281; - GibCursor field_nxt_1717 = soa_field_0_1710 + 1; - uintptr_t tagged_tmpcur_40 = *(uintptr_t *) field_nxt_1717; - GibCursor tmpcur_2282 = GIB_UNTAG(tagged_tmpcur_40); - GibCursor tmpaftercur_2283 = field_nxt_1717 + 8; - uint16_t tmptag_2284 = GIB_GET_TAG(tagged_tmpcur_40); - GibCursor end_from_tagged_fld_redir_1720 = tmpcur_2282 + - tmptag_2284; - GibCursor field_nxt_1718 = soa_field_1_1711 + 1; - uintptr_t tagged_tmpcur_39 = *(uintptr_t *) field_nxt_1718; - GibCursor tmpcur_2285 = GIB_UNTAG(tagged_tmpcur_39); - GibCursor tmpaftercur_2286 = field_nxt_1718 + 8; - uint16_t tmptag_2287 = GIB_GET_TAG(tagged_tmpcur_39); - GibCursor end_from_tagged_fld_redir_1721 = tmpcur_2285 + - tmptag_2287; - GibCursor indr_1082_tmp[3] = {tmpcur_2279, tmpcur_2282, - tmpcur_2285}; - GibCursor *indr_1082 = gib_array_alloc(indr_1082_tmp, 3); - unsigned char wildcard_1096 = gib_print_symbol(2010); - GibCursorPtrGibCursorPtrProd tmp_struct_38 = - _print_Tree(indr_1082, indr_1082); - GibCursor *pvrtmp_2288 = tmp_struct_38.field0; - GibCursor *pvrtmp_2289 = tmp_struct_38.field1; - - return (GibCursorPtrGibCursorPtrProd) {pvrtmp_2288, pvrtmp_2289}; - break; - } - - default: - { - printf("%s\n", "Unknown tag in: tmpval_2264"); - exit(1); - } - } -} -GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd _copy_without_ptrs_Tree(GibCursor *cursor_ptr_1730, - GibCursor *cursor_ptr_1729, - GibCursor *cursor_ptr_1731, - GibCursor *arg_79_161_245) -{ - GibCursor *end_r_641 = &cursor_ptr_1730[0]; - GibCursor *end_r_642 = &cursor_ptr_1730[1]; - GibCursor *end_r_643 = &cursor_ptr_1730[2]; - GibCursor *end_r_644 = &cursor_ptr_1729[0]; - GibCursor *end_r_645 = &cursor_ptr_1729[1]; - GibCursor *end_r_646 = &cursor_ptr_1729[2]; - GibCursor dcon_1735 = arg_79_161_245[0]; - GibPackedTag tmpval_2291 = *(GibPackedTag *) dcon_1735; - GibCursor tmpcur_2292 = dcon_1735 + 1; - - - switch_2357: - ; - switch (tmpval_2291) { - - case 0: - { - GibCursor soa_field_0_1737 = arg_79_161_245[1]; - GibCursor soa_field_1_1738 = arg_79_161_245[2]; - GibInt tmpval_2293 = *(GibInt *) soa_field_0_1737; - GibCursor tmpcur_2294 = soa_field_0_1737 + sizeof(GibInt); - GibCursor loc_635 = arg_79_161_245[0]; - GibCursor jumpf_dloc_987 = loc_635 + 1; - GibCursor loc_IntTy_636 = arg_79_161_245[1]; - GibCursor loc_IntTy_637 = arg_79_161_245[2]; - GibCursor jumpf_floc_loc_988 = soa_field_0_1737 + 8; - GibCursor jumpf_floc_loc_989 = loc_IntTy_637 + 0; - GibCursor cursor_ptr_1741_tmp[3] = {jumpf_dloc_987, - jumpf_floc_loc_988, - jumpf_floc_loc_989}; - GibCursor *cursor_ptr_1741 = gib_array_alloc(cursor_ptr_1741_tmp, - 3); - GibCursor loc_IntTy_639 = cursor_ptr_1731[1]; - GibCursor new_floc_loc_894 = loc_IntTy_639 + 0; - GibCursor loc_638 = cursor_ptr_1731[0]; - GibCursor new_dloc_893 = loc_638 + 1; - GibCursor loc_IntTy_640 = cursor_ptr_1731[2]; - GibCursor loc_892 = loc_IntTy_640 + 0; - GibCursor new_floc_loc_895 = loc_892 + 8; - - *(GibPackedTag *) loc_638 = 0; - - GibCursor writetag_1742 = loc_638 + 1; - GibCursor after_tag_1743 = loc_638 + 1; - - *(GibInt *) loc_IntTy_639 = tmpval_2293; - - GibCursor writecur_1747 = loc_IntTy_639 + sizeof(GibInt); - GibCursor aft_soa_loc_1749_tmp[3] = {after_tag_1743, writecur_1747, - loc_IntTy_640}; - GibCursor *aft_soa_loc_1749 = gib_array_alloc(aft_soa_loc_1749_tmp, - 3); - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1730, - cursor_ptr_1729, - cursor_ptr_1741, - cursor_ptr_1731, - aft_soa_loc_1749}; - break; - } - - case 1: - { - GibCursor soa_field_0_1753 = arg_79_161_245[1]; - GibCursor soa_field_1_1754 = arg_79_161_245[2]; - GibInt tmpval_2299 = *(GibInt *) soa_field_1_1754; - GibCursor tmpcur_2300 = soa_field_1_1754 + sizeof(GibInt); - GibCursor cursor_ptr_1734_tmp[3] = {tmpcur_2292, soa_field_0_1753, - tmpcur_2300}; - GibCursor *cursor_ptr_1734 = gib_array_alloc(cursor_ptr_1734_tmp, - 3); - GibCursor loc_635 = arg_79_161_245[0]; - GibCursor jumpf_dloc_991 = loc_635 + 1; - GibCursor loc_IntTy_636 = arg_79_161_245[1]; - GibCursor loc_IntTy_637 = arg_79_161_245[2]; - GibCursor jumpf_floc_loc_993 = soa_field_1_1754 + 8; - GibCursor jumpf_floc_loc_992 = loc_IntTy_636 + 0; - GibCursor loc_870 = jumpf_dloc_991 + 0; - GibCursor loc_869 = jumpf_floc_loc_993 + 0; - GibCursor loc_868 = jumpf_floc_loc_992 + 0; - GibCursor cursor_ptr_1758_tmp[3] = {jumpf_dloc_991, - jumpf_floc_loc_992, - jumpf_floc_loc_993}; - GibCursor *cursor_ptr_1758 = gib_array_alloc(cursor_ptr_1758_tmp, - 3); - GibCursor loc_IntTy_639 = cursor_ptr_1731[1]; - GibCursor new_floc_loc_894 = loc_IntTy_639 + 0; - GibCursor loc_638 = cursor_ptr_1731[0]; - GibCursor new_dloc_893 = loc_638 + 1; - GibCursor loc_IntTy_640 = cursor_ptr_1731[2]; - GibCursor loc_892 = loc_IntTy_640 + 0; - GibCursor new_floc_loc_895 = loc_892 + 8; - GibCursor cursor_ptr_1759_tmp[3] = {new_dloc_893, new_floc_loc_894, - new_floc_loc_895}; - GibCursor *cursor_ptr_1759 = gib_array_alloc(cursor_ptr_1759_tmp, - 3); - - *(GibPackedTag *) loc_638 = 1; - - GibCursor writetag_1778 = loc_638 + 1; - GibCursor after_tag_1779 = loc_638 + 1; - - *(GibInt *) loc_IntTy_640 = tmpval_2299; - - GibCursor writecur_1783 = loc_IntTy_640 + sizeof(GibInt); - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_42 = - _copy_without_ptrs_Tree(cursor_ptr_1730, cursor_ptr_1729, cursor_ptr_1759, cursor_ptr_1734); - GibCursor *pvrtmp_2301 = tmp_struct_42.field0; - GibCursor *pvrtmp_2302 = tmp_struct_42.field1; - GibCursor *pvrtmp_2303 = tmp_struct_42.field2; - GibCursor *pvrtmp_2304 = tmp_struct_42.field3; - GibCursor *pvrtmp_2305 = tmp_struct_42.field4; - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_43 = - _copy_without_ptrs_Tree(pvrtmp_2301, pvrtmp_2302, pvrtmp_2305, pvrtmp_2303); - GibCursor *pvrtmp_2310 = tmp_struct_43.field0; - GibCursor *pvrtmp_2311 = tmp_struct_43.field1; - GibCursor *pvrtmp_2312 = tmp_struct_43.field2; - GibCursor *pvrtmp_2313 = tmp_struct_43.field3; - GibCursor *pvrtmp_2314 = tmp_struct_43.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2310, - pvrtmp_2311, - pvrtmp_2312, - cursor_ptr_1731, - pvrtmp_2314}; - break; - } - - case GIB_INDIRECTION_TAG: - { - GibCursor soa_field_0_1791 = arg_79_161_245[1]; - GibCursor soa_field_1_1792 = arg_79_161_245[2]; - uintptr_t tagged_tmpcur_45 = *(uintptr_t *) tmpcur_2292; - GibCursor tmpcur_2323 = GIB_UNTAG(tagged_tmpcur_45); - GibCursor tmpaftercur_2324 = tmpcur_2292 + 8; - uint16_t tmptag_2325 = GIB_GET_TAG(tagged_tmpcur_45); - GibCursor *cursor_ptr_1732 = (GibCursor *) tmpcur_2323; - GibCursor loc_635 = arg_79_161_245[0]; - GibCursor jump_dloc_1104 = loc_635 + 9; - GibCursor loc_IntTy_637 = arg_79_161_245[2]; - GibCursor loc_IntTy_636 = arg_79_161_245[1]; - GibCursor cursor_ptr_1796_tmp[3] = {jump_dloc_1104, loc_IntTy_636, - loc_IntTy_637}; - GibCursor *cursor_ptr_1796 = gib_array_alloc(cursor_ptr_1796_tmp, - 3); - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_44 = - _copy_without_ptrs_Tree(cursor_ptr_1732, cursor_ptr_1729, cursor_ptr_1731, cursor_ptr_1732); - GibCursor *pvrtmp_2326 = tmp_struct_44.field0; - GibCursor *pvrtmp_2327 = tmp_struct_44.field1; - GibCursor *pvrtmp_2328 = tmp_struct_44.field2; - GibCursor *pvrtmp_2329 = tmp_struct_44.field3; - GibCursor *pvrtmp_2330 = tmp_struct_44.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {cursor_ptr_1730, - pvrtmp_2327, - cursor_ptr_1796, - pvrtmp_2329, - pvrtmp_2330}; - break; - } - - case GIB_REDIRECTION_TAG: - { - GibCursor soa_field_0_1807 = arg_79_161_245[1]; - GibCursor soa_field_1_1808 = arg_79_161_245[2]; - uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_2292; - GibCursor tmpcur_2337 = GIB_UNTAG(tagged_tmpcur_49); - GibCursor tmpaftercur_2338 = tmpcur_2292 + 8; - uint16_t tmptag_2339 = GIB_GET_TAG(tagged_tmpcur_49); - GibCursor end_from_tagged_dcon_redir_1816 = tmpcur_2337 + - tmptag_2339; - GibCursor field_nxt_1814 = soa_field_0_1807 + 1; - uintptr_t tagged_tmpcur_48 = *(uintptr_t *) field_nxt_1814; - GibCursor tmpcur_2340 = GIB_UNTAG(tagged_tmpcur_48); - GibCursor tmpaftercur_2341 = field_nxt_1814 + 8; - uint16_t tmptag_2342 = GIB_GET_TAG(tagged_tmpcur_48); - GibCursor end_from_tagged_fld_redir_1817 = tmpcur_2340 + - tmptag_2342; - GibCursor field_nxt_1815 = soa_field_1_1808 + 1; - uintptr_t tagged_tmpcur_47 = *(uintptr_t *) field_nxt_1815; - GibCursor tmpcur_2343 = GIB_UNTAG(tagged_tmpcur_47); - GibCursor tmpaftercur_2344 = field_nxt_1815 + 8; - uint16_t tmptag_2345 = GIB_GET_TAG(tagged_tmpcur_47); - GibCursor end_from_tagged_fld_redir_1818 = tmpcur_2343 + - tmptag_2345; - GibCursor indr_1097_tmp[3] = {tmpcur_2337, tmpcur_2340, - tmpcur_2343}; - GibCursor *indr_1097 = gib_array_alloc(indr_1097_tmp, 3); - GibCursor loc_638 = cursor_ptr_1731[0]; - GibCursor loc_IntTy_639 = cursor_ptr_1731[1]; - GibCursor loc_IntTy_640 = cursor_ptr_1731[2]; - GibCursor copy_dloc_1112 = loc_638 + 0; - GibCursor copy_floc_loc_1114 = loc_IntTy_640 + 0; - GibCursor copy_floc_loc_1113 = loc_IntTy_639 + 0; - GibCursor cursor_ptr_1819_tmp[3] = {copy_dloc_1112, - copy_floc_loc_1113, - copy_floc_loc_1114}; - GibCursor *cursor_ptr_1819 = gib_array_alloc(cursor_ptr_1819_tmp, - 3); - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_46 = - _copy_without_ptrs_Tree(indr_1097, cursor_ptr_1729, cursor_ptr_1819, indr_1097); - GibCursor *pvrtmp_2346 = tmp_struct_46.field0; - GibCursor *pvrtmp_2347 = tmp_struct_46.field1; - GibCursor *pvrtmp_2348 = tmp_struct_46.field2; - GibCursor *pvrtmp_2349 = tmp_struct_46.field3; - GibCursor *pvrtmp_2350 = tmp_struct_46.field4; - - return (GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd) {pvrtmp_2346, - pvrtmp_2347, - pvrtmp_2348, - pvrtmp_2349, - pvrtmp_2350}; - break; - } - - default: - { - printf("%s\n", "Unknown tag in: tmpval_2291"); - exit(1); - } - } -} -int main(int argc, char **argv) -{ - int init_58 = gib_init(argc, argv); - - info_table_initialize(); - symbol_table_initialize(); - - GibChunk region_2013 = - gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); - GibCursor r_676 = region_2013.start; - GibCursor end_r_676 = region_2013.end; - GibChunk region_2014 = - gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); - GibCursor r_677 = region_2014.start; - GibCursor end_r_677 = region_2014.end; - GibChunk region_2015 = - gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); - GibCursor r_678 = region_2015.start; - GibCursor end_r_678 = region_2015.end; - GibCursor reg_ptr_1829_tmp[3] = {r_676, r_677, r_678}; - GibCursor *reg_ptr_1829 = gib_array_alloc(reg_ptr_1829_tmp, 3); - GibCursor reg_cursor_ptr_1830_tmp[3] = {end_r_676, end_r_677, end_r_678}; - GibCursor *reg_cursor_ptr_1830 = gib_array_alloc(reg_cursor_ptr_1830_tmp, - 3); - GibCursorPtrGibCursorPtrGibCursorPtrProd tmp_struct_50 = - mkTree(reg_cursor_ptr_1830, reg_ptr_1829, 20, 0); - - GibCursor pvrtmp_2016[3] = {tmp_struct_50.field0[0], tmp_struct_50.field0[1], tmp_struct_50.field0[2]}; - GibCursor pvrtmp_2017[3] = {tmp_struct_50.field1[0], tmp_struct_50.field1[1], tmp_struct_50.field1[2]}; - GibCursor pvrtmp_2018[3] = {tmp_struct_50.field2[0], tmp_struct_50.field2[1], tmp_struct_50.field2[2]}; - - GibChunk region_2023 = - gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); - GibCursor r_673 = region_2023.start; - GibCursor end_r_673 = region_2023.end; - GibChunk region_2024 = - gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); - GibCursor r_674 = region_2024.start; - GibCursor end_r_674 = region_2024.end; - GibChunk region_2025 = - gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); - GibCursor r_675 = region_2025.start; - GibCursor end_r_675 = region_2025.end; - GibCursor reg_ptr_1836_tmp[3] = {r_673, r_674, r_675}; - GibCursor *reg_ptr_1836 = gib_array_alloc(reg_ptr_1836_tmp, 3); - GibCursor reg_cursor_ptr_1837_tmp[3] = {end_r_673, end_r_674, end_r_675}; - GibCursor *reg_cursor_ptr_1837 = gib_array_alloc(reg_cursor_ptr_1837_tmp, - 3); - - GibCursor *reg_cursor_ptr_1837_2 = gib_array_alloc(reg_cursor_ptr_1837_tmp, - 3); - - GibCursor pvrtmp_2037[3]; - GibCursor pvrtmp_2038[3]; - GibCursor pvrtmp_2039[3]; - - GibVector *times_55 = gib_vector_alloc(gib_get_iters_param(), - sizeof(double)); - struct timespec begin_pvrtmp_2037; - struct timespec end_pvrtmp_2037; - - for (long long iters_pvrtmp_2037 = 0; iters_pvrtmp_2037 < - gib_get_iters_param(); iters_pvrtmp_2037++) { - if (iters_pvrtmp_2037 != gib_get_iters_param() - 1) { - gib_list_bumpalloc_save_state(); - gib_ptr_bumpalloc_save_state(); - } - clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_2037); - - GibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrGibCursorPtrProd - tmp_struct_51 = - add1Tree(pvrtmp_2016, reg_cursor_ptr_1837, reg_ptr_1836, pvrtmp_2017); - - GibCursor pvrtmp_2026[3] = {tmp_struct_51.field0[0], tmp_struct_51.field0[1], tmp_struct_51.field0[2]}; - GibCursor pvrtmp_2027[3] = {tmp_struct_51.field1[0], tmp_struct_51.field1[1], tmp_struct_51.field1[2]}; - GibCursor pvrtmp_2028[3] = {tmp_struct_51.field2[0], tmp_struct_51.field2[1], tmp_struct_51.field2[2]}; - GibCursor pvrtmp_2029[3] = {tmp_struct_51.field3[0], tmp_struct_51.field3[1], tmp_struct_51.field3[2]}; - GibCursor pvrtmp_2030[3] = {tmp_struct_51.field4[0], tmp_struct_51.field4[1], tmp_struct_51.field4[2]}; - - //reg_cursor_ptr_1837 = gib_array_alloc(reg_cursor_ptr_1837_tmp, - // 3); - - pvrtmp_2037[0] = pvrtmp_2027[0]; - pvrtmp_2037[1] = pvrtmp_2027[1]; - pvrtmp_2037[2] = pvrtmp_2027[2]; - - - pvrtmp_2038[0] = pvrtmp_2029[0]; - pvrtmp_2038[1] = pvrtmp_2029[1]; - pvrtmp_2038[2] = pvrtmp_2029[2]; - - pvrtmp_2039[0] = pvrtmp_2030[0]; - pvrtmp_2039[1] = pvrtmp_2030[1]; - pvrtmp_2039[2] = pvrtmp_2030[2]; - - clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_2037); - if (iters_pvrtmp_2037 != gib_get_iters_param() - 1) { - gib_list_bumpalloc_restore_state(); - gib_ptr_bumpalloc_restore_state(); - } - - double itertime_52 = gib_difftimespecs(&begin_pvrtmp_2037, - &end_pvrtmp_2037); - - printf("itertime: %lf\n", itertime_52); - gib_vector_inplace_update(times_55, iters_pvrtmp_2037, &itertime_52); - } - gib_vector_inplace_sort(times_55, gib_compare_doubles); - - double *tmp_56 = (double *) gib_vector_nth(times_55, gib_get_iters_param() / - 2); - double selftimed_54 = *tmp_56; - double batchtime_53 = gib_sum_timing_array(times_55); - - gib_print_timing_array(times_55); - gib_vector_free(times_55); - printf("ITERS: %ld\n", gib_get_iters_param()); - printf("SIZE: %ld\n", gib_get_size_param()); - printf("BATCHTIME: %e\n", batchtime_53); - printf("SELFTIMED: %e\n", selftimed_54); - - GibCursorPtrGibCursorPtrGibIntProd tmp_struct_57 = - sumTree(reg_cursor_ptr_1837, pvrtmp_2038); - GibCursor *pvrtmp_2047 = tmp_struct_57.field0; - GibCursor *pvrtmp_2048 = tmp_struct_57.field1; - GibInt pvrtmp_2049 = tmp_struct_57.field2; - - printf("%ld", pvrtmp_2049); - printf("\n"); - - int exit_59 = gib_exit(); - - return exit_59; -} diff --git a/gibbon-rts/Makefile b/gibbon-rts/Makefile index 90a81921f..e487a6f7c 100644 --- a/gibbon-rts/Makefile +++ b/gibbon-rts/Makefile @@ -26,9 +26,9 @@ # ====================================================================== -CC := gcc -AR := gcc-ar -CFLAGS := -Wall -Wextra -Wpedantic -Wshadow -Werror -std=gnu11 -flto +CC := clang +AR := llvm-ar +CFLAGS := -Wall -Wextra -Wpedantic -Wshadow -std=gnu11 -flto RSC := cargo RSFLAGS := -v VERBOSITY := 1 From 9906197c25c9ff96c6996cf006de7f5b1030c9a7 Mon Sep 17 00:00:00 2001 From: vidush Date: Wed, 1 Oct 2025 08:48:51 -0400 Subject: [PATCH 30/60] edits --- gibbon-compiler/examples/soa_examples/test_copy.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/test_copy.hs b/gibbon-compiler/examples/soa_examples/test_copy.hs index a48a133b3..a1b6f57b0 100644 --- a/gibbon-compiler/examples/soa_examples/test_copy.hs +++ b/gibbon-compiler/examples/soa_examples/test_copy.hs @@ -13,13 +13,11 @@ foo' tree = tree gibbon_main = let t1 = foo 20 - --t4' = Node 12 (Leaf 1) (Leaf 1) t2 = foo 50 t3 = make_node t1 t2 - -- t4' = Node 12 (Leaf 1) (Leaf 1) t4 = foo' t3 t4' = Node 12 (Leaf 1) (Leaf 2) - t5 = Node 10 (Node 12 t4 t4') (Node 10 (Leaf 1) (Leaf 1)) + t5 = Node 10 (Node 12 t4 t4') t1 in printPacked t5 From bd09f485e2ecdb8aa26e63c084915b879fe45177 Mon Sep 17 00:00:00 2001 From: vidush Date: Wed, 8 Oct 2025 10:50:31 -0400 Subject: [PATCH 31/60] merge main --- gibbon-compiler/src/Gibbon/HaskellFrontend.hs | 1 - gibbon-compiler/src/Gibbon/L2/Syntax.hs | 9 +++++---- gibbon-compiler/src/Gibbon/L2/Typecheck.hs | 1 + gibbon-compiler/src/Gibbon/L3/Syntax.hs | 5 ++++- gibbon-compiler/src/Gibbon/L4/Interp.hs | 1 + gibbon-compiler/src/Gibbon/L4/Syntax.hs | 1 - gibbon-compiler/src/Gibbon/Language.hs | 4 ++++ gibbon-compiler/src/Gibbon/Language/Syntax.hs | 8 ++++---- gibbon-compiler/src/Gibbon/NewL2/Syntax.hs | 8 ++------ .../src/Gibbon/Passes/AddCastInstructions.hs | 4 ++-- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 3 +-- gibbon-compiler/src/Gibbon/Passes/Cursorize.hs | 10 ++-------- gibbon-compiler/src/Gibbon/Passes/DirectL3.hs | 1 + gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs | 2 -- gibbon-compiler/src/Gibbon/Passes/InferLocations.hs | 8 ++++---- gibbon-compiler/src/Gibbon/Passes/Lower.hs | 11 +++++------ gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs | 4 ---- 17 files changed, 36 insertions(+), 45 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/HaskellFrontend.hs b/gibbon-compiler/src/Gibbon/HaskellFrontend.hs index bf381067d..fa679d253 100644 --- a/gibbon-compiler/src/Gibbon/HaskellFrontend.hs +++ b/gibbon-compiler/src/Gibbon/HaskellFrontend.hs @@ -9,7 +9,6 @@ module Gibbon.HaskellFrontend import Control.Monad import Data.Foldable ( foldrM ) #if !MIN_VERSION_base(4,21,0) -import Data.Foldable ( foldl' ) #endif import Data.Maybe (catMaybes, isJust) import qualified Data.Map as M diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index 27bd2b383..03ad932a7 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -917,7 +917,7 @@ revertExp ex = LetParRegionE _ _ _ bod -> revertExp bod LetLocE _ _ bod -> revertExp bod StartOfPkdCursor cur -> Ext (L1.StartOfPkdCursor cur) - TagCursor a _b -> error "revertExp: Cannot revert TagCursor!" --Ext (L1.StartOfPkdCursor a) + TagCursor _a _b -> error "revertExp: Cannot revert TagCursor!" --Ext (L1.StartOfPkdCursor a) RetE _ v -> VarE v AddFixed{} -> error "revertExp: TODO AddFixed." FromEndE{} -> error "revertExp: TODO FromEndLE" @@ -987,7 +987,7 @@ occurs w ex = FromEndLE{} -> oc_bod _ -> oc_bod StartOfPkdCursor v -> v `S.member` w - TagCursor a b -> False --a `S.member` w || b `S.member` w + TagCursor _a _b -> False --a `S.member` w || b `S.member` w RetE _ v -> v `S.member` w FromEndE{} -> False BoundsCheck{} -> False @@ -995,7 +995,7 @@ occurs w ex = -- (unwrapLocVar v1) `S.member` w || (unwrapLocVar v2) `S.member` w || -- v1, v2 are not strictly variables, these are regions. - IndirectionE _ _ (_,v1) (_,v2) ib -> go ib + IndirectionE _ _ (_,_v1) (_,_v2) ib -> go ib GetCilkWorkerNum -> False LetAvail _ bod -> go bod AllocateTagHere{} -> False @@ -1149,7 +1149,8 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty FromEndLE loc -> [fromLocVarToFreeVarsTy loc] FreeLE -> [] GetDataConLocSoA loc -> [fromLocVarToFreeVarsTy loc] - GetFieldLocSoA key loc -> case loc of + GetFieldLocSoA key loc -> case loc of + Single{} -> error "Did not expect a single location!" SoA _ flocs -> let floc = lookup key flocs in case floc of Nothing -> [] diff --git a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs index e5ef52739..7f28b16e9 100644 --- a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs @@ -1317,6 +1317,7 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of return () -- TODO: implement for ran access pointers. CursorTy -> return () + _ -> error "Not implemented!" -- dbgTraceIt "Print in ensure data con" dbgTraceIt (sdoc (unselfTys, selfTys, unselfWriteAtLocs)) dbgTraceIt "End\n" return () diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index 247681bb9..0831bd747 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -154,6 +154,8 @@ instance FreeVars (E3Ext l d) where IndexCursorArray {} -> error "gFreeVars: IndexCursorArray not handled" CastPtr {} -> error "gFreeVars: CastPtr not handled" BoundsCheckVector {} -> error "gFreeVars: BoundsCheckVector not handled" + AddrOfCursor{} -> error "gFreeVars: AddrOfCursor not handled" + DerefMutCursor{} -> error "gFreeVars: DerefMutCursor not handled" instance (Out l, Out d, Show l, Show d) => Expression (E3Ext l d) where @@ -265,6 +267,8 @@ instance HasRenamable E3Ext l d => Renamable (E3Ext l d) where IndexCursorArray{} -> error "gRename: IndexCursorArray not handled" CastPtr{} -> error "gRename: CastPtr not handled" BoundsCheckVector{} -> error "gRename: BoundsCheckVector not handled" + AddrOfCursor{} -> error "gRename: AddrOfCursor not handled" + DerefMutCursor{} -> error "gRename: DerefMutCursor not handled" where go :: forall a. Renamable a => a -> a go = gRename env @@ -325,7 +329,6 @@ cursorizeTy ty = SymSetTy -> SymSetTy SymHashTy-> SymHashTy IntHashTy-> IntHashTy - CursorArrayTy {} -> error "cursorizeTy: CursorArrayTy not handled" -- | Map exprs with an initial type environment: -- Exactly the same function that was in L2 before diff --git a/gibbon-compiler/src/Gibbon/L4/Interp.hs b/gibbon-compiler/src/Gibbon/L4/Interp.hs index 9e34bff7c..e063b4d13 100644 --- a/gibbon-compiler/src/Gibbon/L4/Interp.hs +++ b/gibbon-compiler/src/Gibbon/L4/Interp.hs @@ -82,6 +82,7 @@ eval _ (SymTriv _) = error "eval: SymTriv not handled" eval _ (ProdTriv{}) = error "eval: ProdTriv not handled" eval _ (ProjTriv{}) = error "eval: ProjTriv not handled" eval _ (BoolTriv{}) = error "eval: BoolTriv not handled" +eval _ (IndexCursorArrayTriv{}) = error "eval: IndexCusorArrayTriv not handled" exec :: Env -> Tail -> IO [Val] diff --git a/gibbon-compiler/src/Gibbon/L4/Syntax.hs b/gibbon-compiler/src/Gibbon/L4/Syntax.hs index 3892d1e09..a5c2367e4 100644 --- a/gibbon-compiler/src/Gibbon/L4/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L4/Syntax.hs @@ -31,7 +31,6 @@ import Gibbon.Common import qualified Gibbon.Language as L import qualified Gibbon.L2.Syntax as L2 import qualified Gibbon.L3.Syntax as L3 -import Gibbon.L3.Syntax (E3Ext(DerefMutCursor)) -------------------------------------------------------------------------------- diff --git a/gibbon-compiler/src/Gibbon/Language.hs b/gibbon-compiler/src/Gibbon/Language.hs index 544d13c02..369446df4 100644 --- a/gibbon-compiler/src/Gibbon/Language.hs +++ b/gibbon-compiler/src/Gibbon/Language.hs @@ -533,6 +533,7 @@ hasPacked t = SymHashTy -> False IntHashTy -> False CursorArrayTy{} -> False + MutCursorTy -> False -- | Get all packed types in a type. @@ -557,6 +558,7 @@ getPackedTys t = SymHashTy -> [] IntHashTy -> [] CursorArrayTy{} -> [] + MutCursorTy -> [] -- | Provide a size in bytes, if it is statically known. sizeOfTy :: UrTy a -> Maybe Int @@ -580,6 +582,7 @@ sizeOfTy t = SymHashTy -> error "sizeOfTy: SymHashTy not handled." IntHashTy -> error "sizeOfTy: IntHashTy not handled." CursorArrayTy{} -> error "sizeOfTy: CursorArrayTy not handled." + MutCursorTy -> error "sizeOfTy: MutCursorTy not handled." -- | Type of the arguments for a primitive operation. primArgsTy :: Prim (UrTy a) -> [UrTy a] @@ -794,6 +797,7 @@ stripTyLocs ty = SymHashTy -> SymHashTy IntHashTy -> IntHashTy ArenaTy -> ArenaTy + MutCursorTy -> MutCursorTy -- | Get the data constructor type from a type, failing if it's not packed tyToDataCon :: Show a => UrTy a -> DataCon diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 88a7df0cf..28c968e53 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -164,10 +164,10 @@ lkp dds con = _ -> error$ "lookupDataCon: found multiple occurences of constructor "++show con ++", in datatypes:\n "++sdoc dds -getCursorTypeForDataCon :: Out a => DDefs (UrTy a) -> DDef (UrTy a) -> UrTy a -getCursorTypeForDataCon ddefs DDef{tyName, dataCons, memLayout} = +getCursorTypeForDataCon :: DDefs (UrTy a) -> DDef (UrTy a) -> UrTy a +getCursorTypeForDataCon _ddefs DDef{dataCons, memLayout} = -- remove data constructors introduced by RAN - let dataCons' = concatMap (\e@(dcon, _) -> if ('^' `elem` dcon) + let _dataCons' = concatMap (\e@(dcon, _) -> if ('^' `elem` dcon) then [] else [e] ) dataCons @@ -190,7 +190,7 @@ getCursorTypeForDataCon ddefs DDef{tyName, dataCons, memLayout} = -- in c' -- ) 0 dataCons' -- in CursorArrayTy (numFieldBuffers + 1) - _ -> error "Memory Layout is not implemented!" + -- _ -> error "Memory Layout is not implemented!" insertDD :: DDef a -> DDefs a -> DDefs a insertDD d = M.insertWith err' (tyName d) d diff --git a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs index 662d92055..ef6828666 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs @@ -464,7 +464,7 @@ revertExp ex = Old.LetRegionE _ _ _ bod -> revertExp bod Old.LetParRegionE _ _ _ bod -> revertExp bod Old.LetLocE _ _ bod -> revertExp bod - Old.TagCursor a _b -> error "revertExp cannot revert TagCursor" --Ext (L1.StartOfPkdCursor a) + Old.TagCursor _a _b -> error "revertExp cannot revert TagCursor" --Ext (L1.StartOfPkdCursor a) Old.StartOfPkdCursor v -> Ext (L1.StartOfPkdCursor v) Old.RetE _ v -> VarE v Old.AddFixed{} -> error "revertExp: TODO AddFixed." @@ -554,13 +554,9 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty Old.SSPush{} -> acc Old.SSPop{} -> acc Old.StartOfPkdCursor cur -> M.insertWith (++) (fromVarToFreeVarsTy cur) [(fromVarToFreeVarsTy cur)] acc -<<<<<<< HEAD - Old.TagCursor a b -> acc --M.insertWith (++) (fromVarToFreeVarsTy b) [(fromVarToFreeVarsTy b)] (M.insertWith (++) (fromVarToFreeVarsTy a) [(fromVarToFreeVarsTy a)] acc) -======= - Old.TagCursor a b -> M.insertWith (++) (fromVarToFreeVarsTy b) [(fromVarToFreeVarsTy b)] (M.insertWith (++) (fromVarToFreeVarsTy a) [(fromVarToFreeVarsTy a)] acc) + Old.TagCursor _a _b -> acc --M.insertWith (++) (fromVarToFreeVarsTy b) [(fromVarToFreeVarsTy b)] (M.insertWith (++) (fromVarToFreeVarsTy a) [(fromVarToFreeVarsTy a)] acc) Old.LetRegE {} -> error "depList: LetRegE not handled" Old.BoundsCheckVector {} -> error "depList: BoundsCheckVector not handled" ->>>>>>> main dep :: Old.PreLocExp LocArg -> [FreeVarsTy] dep ex = diff --git a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs index 7f127d125..43f62dd9a 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddCastInstructions.hs @@ -225,7 +225,7 @@ addCastsExp fundef cenv env ex = AppE f locs args -> do let funTy = lookupFEnv f env let args_zip_ty = zip args (fst funTy ++ [snd funTy]) - (lets, new_args) <- foldlM (\(l, args') zipped -> case zipped of + (_, new_args) <- foldlM (\(l, args') zipped -> case zipped of (VarE arg, ty) -> do let argTy = lookupVEnv arg env if argTy == ty @@ -456,7 +456,7 @@ addCastsExp fundef cenv env ex = Ext (Assert e) -> do e' <- go e pure $ Ext $ Assert e' - Ext (CastPtr v ty) -> pure ex + Ext (CastPtr _v _ty) -> pure ex Ext {} -> error $ "addCastsExp : Unexpected instruction " ++ show ex MapE {} -> error "addCastsExp: MapE TODO" FoldE {} -> error "addCastsExp: FoldE TODO" diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index bd60fdd19..be64a69fa 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -31,7 +31,6 @@ import qualified Gibbon.Language as GL import Gibbon.DynFlags import Gibbon.L2.Syntax ( Multiplicity(..) ) import Gibbon.L4.Syntax -import Language.Haskell.Exts (var) -------------------------------------------------------------------------------- @@ -1673,7 +1672,7 @@ codegenTy TagTyBoxed = [cty|typename GibBoxedTag|] codegenTy SymTy = [cty|typename GibSym|] codegenTy PtrTy = [cty|typename GibPtr|] -- char* - Hack, this could be void* if we have enough casts. [2016.11.06] codegenTy CursorTy = [cty|typename GibCursor|] -codegenTy (CursorArrayTy size) = [cty|typename GibCursor* |] +codegenTy (CursorArrayTy _size) = [cty|typename GibCursor* |] codegenTy MutCursorTy = [cty|typename GibCursor* |] codegenTy RegionTy = [cty|typename GibChunk|] codegenTy ChunkTy = [cty|typename GibChunk|] diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 4c7656cda..ddaf67935 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -9,9 +9,7 @@ import Control.Monad (forM) import Data.Foldable (foldlM, foldrM) import qualified Data.List as L import qualified Data.Map as M -import Data.Maybe (fromJust, listToMaybe, fromMaybe) -import Data.Set (Set) -import GHC.RTS.Flags (MiscFlags (generateCrashDumpFile)) +import Data.Maybe (fromJust) import Gibbon.Common import Gibbon.DynFlags import Gibbon.L3.Syntax hiding @@ -1083,7 +1081,6 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- SingleR v -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod -- SoARv dv _ -> cursorizePackedExp freeVarToVarEnv ddfs fundefs denv tenv senv bod - _ -> error $ "Unpexected Expression: " ++ show ext MapE {} -> error $ "TODO: cursorizeExp MapE" FoldE {} -> error $ "TODO: cursorizeExp FoldE" where @@ -1973,9 +1970,6 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = (from_var, fvl) <- case M.lookup (fromLocVarToFreeVarsTy fl) freeVarToVarEnv of Nothing -> case fl of Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) - SoA{} -> do - field_name <- gensym "field_cursor" - return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) Just var -> return $ (var, []) (to_var, tvl) <- do case M.lookup (fromLocVarToFreeVarsTy to_loc) freeVarToVarEnv of @@ -2062,7 +2056,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let barrier_args' = L.zip4 from_locs' to_locs' from_reg_vars' to_reg_vars' (let_exprs', range_s', parents, _) <- foldlM handle_indrs_rec ([], [], (fl_var, to_loc_var', from_reg_var', to_reg_var'), barrier_args') barrier_args' - error "SoA: Packed indirections with GC does not work! Please turn off GC for now!" + _ <- error "SoA: Packed indirections with GC does not work! Please turn off GC for now!" return (fvl ++ tvl ++ frl ++ trl ++ let_exprs', range_s', parents, barrier_args) ) diff --git a/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs b/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs index 0197a312e..a59fbccdd 100644 --- a/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs +++ b/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs @@ -96,3 +96,4 @@ directL3 prg@(Prog ddfs fndefs mnExp) = do SymHashTy -> SymHashTy IntHashTy -> IntHashTy CursorArrayTy {} -> error "directL3: CursorArrayTy not handled" + MutCursorTy {} -> error "directL3: MutCursorTy not handled" diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index 1dbc89c0c..772fd53cb 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -12,7 +12,6 @@ import Gibbon.Common import Gibbon.Language import Gibbon.L2.Syntax as L2 import Gibbon.DynFlags -import Gibbon.L3.Syntax (E3Ext(AddCursor)) -------------------------------------------------------------------------------- @@ -108,7 +107,6 @@ followPtrs (Prog ddefs fundefs mainExp) = do (pure (CaseE scrt (brs ++ [redir_br]))) else do indir_ptrv <- gensym "indr" - indir_ptrv_loc <- freshCommonLoc "indr" scrt_loc indir_ptrloc <- freshCommonLoc "case" scrt_loc jump <- freshCommonLoc "jump" scrt_loc callv <- gensym "call" diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index 5c0bd7ced..f5321e9fd 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -551,7 +551,7 @@ inferExp' ddefs env exp bound dest= ) (getFieldLocs slv2) exprs = P.map (\(key, l) -> LetLocE l (GetFieldLocSoA key slv2) ) get_loc_keys - (lv1, lv2, dconLoc) = case dconstr of + (lv1, _lv2, dconLoc) = case dconstr of AfterTagL lv1 lv2 -> (lv1, lv2, LetLocE lv1 (AfterConstantLE 1 lv2)) AfterConstantL lv1 i lv2 -> (lv1, lv2, LetLocE lv1 (AfterConstantLE i lv2)) _ -> error "Not implemented!" @@ -600,7 +600,7 @@ inferExp' ddefs env exp bound dest= returned = lambda exprs'' a' in dbgTrace minChatLvl " BindAllLocations: " dbgTrace minChatLvl (sdoc (get_loc_keys, returned)) dbgTrace minChatLvl "End bindAllLocations.\n" returned - _ -> error "bindAllLocations: AfterSoALE: unexpected tag constraint." + --_ -> error "bindAllLocations: AfterSoALE: unexpected tag constraint." AfterConstantL lv1 v lv2 -> Ext (LetLocE lv1 (AfterConstantLE v lv2) a) AssignL lv1 lv2 -> Ext (LetLocE lv1 (AssignLE lv2) a) AfterVariableL lv1 v lv2 -> Ext (LetLocE lv1 (AfterVariableLE v lv2 True) a) @@ -1222,7 +1222,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = Just $ AfterCopyL loc1 v v' loc2 f lvs afterVar _ = Nothing -- dbgTrace minChatLvl "Print DataConE SoA case argsLs: " dbgTrace minChatLvl (sdoc (d, argLs, newLocs)) dbgTrace minChatLvl "End DataConE SoA case argLs.\n" - let dataBufferLoc = Single dataBufferVar + let _dataBufferLoc = Single dataBufferVar -- VS: September 24th, 2025 -- Some locs need to be sequentialized with respect to the -- data contructor buffer. These are the recursive fields, @@ -1353,7 +1353,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = (sptrs, hloc:rstlocs) -> do -- make after tag constraint for the first let first_shortcut = Sf.headErr sptrs - let tail_shortcut = tail sptrs + let tail_shortcut = Sf.tailErr sptrs let last_shortcut = last sptrs let tagc_shortcut_first_c = AfterTagL (first_shortcut) d let fields_d = getFieldLocs d diff --git a/gibbon-compiler/src/Gibbon/Passes/Lower.hs b/gibbon-compiler/src/Gibbon/Passes/Lower.hs index 1a6497ae7..03ccd422c 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Lower.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Lower.hs @@ -29,7 +29,6 @@ import Gibbon.DynFlags import Gibbon.L3.Syntax import qualified Gibbon.L3.Syntax as L3 import qualified Gibbon.L4.Syntax as T -import Language.Haskell.Exts.Build (sym) -- Generating unpack functions from Packed->Pointer representation: ------------------------------------------------------------------------------- @@ -526,12 +525,11 @@ lower Prog{fundefs,ddefs,mainExp} = do SSPush{} -> syms SSPop{} -> syms Assert ex -> go ex - MakeCursorArray len vars -> syms - IndexCursorArray var idx -> syms - CastPtr var ty -> syms + MakeCursorArray _len _vars -> syms + IndexCursorArray _var _idx -> syms + CastPtr _var _ty -> syms AddrOfCursor rhs -> go rhs DerefMutCursor{} -> syms - _ -> error $ "Unexpected Ext: " ++ sdoc ex MapE{} -> syms FoldE{} -> syms @@ -767,7 +765,7 @@ lower Prog{fundefs,ddefs,mainExp} = do , triv sym_tbl "index_into_base_pointer" (LitE idx)] <$> tail free_reg sym_tbl bod - LetE (v, _, _, (Ext (AddrOfCursor i@(Ext (IndexCursorArray cur idx))))) bod -> do + LetE (v, _, _, (Ext (AddrOfCursor i@(Ext (IndexCursorArray _cur _idx))))) bod -> do --i' <- tail free_reg sym_tbl i T.LetPrimCallT [(v, T.MutCursorTy)] T.AddrOfCursor [triv sym_tbl "addofexpr" i ] <$> tail free_reg sym_tbl bod @@ -1139,6 +1137,7 @@ typ t = SymSetTy -> T.SymSetTy SymHashTy -> T.SymHashTy IntHashTy -> T.IntHashTy + MutCursorTy -> T.MutCursorTy typ' :: String -> Ty3 -> T.Ty typ' str t = dbgTraceIt str $ typ t diff --git a/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs b/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs index ac7c51f9f..db0b7273c 100644 --- a/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs +++ b/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs @@ -1,8 +1,5 @@ module Gibbon.Passes.OptimizeL3 (removeReDefs) where - -import Data.Foldable (foldrM, foldlM) -import qualified Data.List as L import qualified Data.Map as M import Gibbon.Common import Gibbon.L1.Syntax @@ -169,7 +166,6 @@ removeReDefsExp env ex = Ext (AddrOfCursor bod) -> do bod' <- go bod return $ Ext (AddrOfCursor bod') - Ext {} -> error $ "addCastsExp : Unexpected instruction " ++ show ex MapE {} -> error "addCastsExp: MapE TODO" FoldE {} -> error "addCastsExp: FoldE TODO" where From 0f93a9c04073d01d049a84dcd8a1e0cd0dbebe15 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Wed, 8 Oct 2025 19:05:52 -0400 Subject: [PATCH 32/60] edits --- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index be64a69fa..bea770a4e 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -559,6 +559,8 @@ codegenTail _ _ _ (ErrT s) _ty _ = return $ [ C.BlockStm [cstm| printf("%s\n", $ codegenTail venv fenv sort_fns (LetTrivT (vr,rty,rhs) body) ty sync_deps = do let venv' = M.insert vr rty venv tal <- codegenTail venv' fenv sort_fns body ty sync_deps + {-Bad assumption?-} + {-If it is a statically sized array -} return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] ++ tal @@ -1672,7 +1674,7 @@ codegenTy TagTyBoxed = [cty|typename GibBoxedTag|] codegenTy SymTy = [cty|typename GibSym|] codegenTy PtrTy = [cty|typename GibPtr|] -- char* - Hack, this could be void* if we have enough casts. [2016.11.06] codegenTy CursorTy = [cty|typename GibCursor|] -codegenTy (CursorArrayTy _size) = [cty|typename GibCursor* |] +codegenTy (CursorArrayTy size) = [cty| typename GibCursor[$int:size] |] codegenTy MutCursorTy = [cty|typename GibCursor* |] codegenTy RegionTy = [cty|typename GibChunk|] codegenTy ChunkTy = [cty|typename GibChunk|] From 7ed999dfd1c156fa94c7cc407b79280f29139aec Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 9 Oct 2025 12:19:51 -0400 Subject: [PATCH 33/60] change codegen to do copying of stack allocated arrays --- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 90 +++++++++++++++----- 1 file changed, 71 insertions(+), 19 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index bea770a4e..c0979e935 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -522,10 +522,24 @@ codegenTail venv _ _ (RetValsT [tr]) ty _ = return $ [ C.BlockStm [cstm| return $(C.CompoundLit ty' arg noLoc); |] ] _ -> return [ C.BlockStm [cstm| return $(codegenTriv venv tr); |] ] -- Multiple return: -codegenTail venv _ _ (RetValsT ts) ty _ = - return $ [ C.BlockStm [cstm| return $(C.CompoundLit ty' args noLoc); |] ] - where args = map (\a -> (Nothing,C.ExpInitializer (codegenTriv venv a) noLoc)) ts - ty' = codegenTy ty +codegenTail venv _ _ (RetValsT ts) ty _ = do + return_var <- gensym "return" + let ty' = codegenTy ty + let flds = foldl (\(vars, idx) _ -> + let n = toVar ((fromVar return_var) ++ ".field" ++ (show idx)) + in (vars ++ [n], idx + 1) + ) ([], 0) ts + let init_ret = [ C.BlockDecl [cdecl| $ty:ty' $id:return_var; |] ] + let mem_copies = map (\(a, fld) -> let ty = typeOfTriv venv a + a' = codegenTriv venv a + ty' = codegenTy ty + in case ty of + CursorArrayTy{} -> C.BlockStm [cstm| memcpy($id:fld, $exp:a', sizeof($ty:ty')); |] + --CursorTy -> C.BlockStm [cstm| memcpy($id:fld, $exp:a', sizeof($ty:ty')); |] + --_ -> C.BlockStm [cstm| memcpy(&$id:fld, &$exp:a', sizeof($ty:ty')); |] + _ -> C.BlockStm [cstm| $id:fld = $exp:a'; |] + ) (zip ts (fst flds)) + return $ init_ret ++ mem_copies ++ [ C.BlockStm [cstm| return $id:return_var; |] ] codegenTail venv fenv sort_fns (AssnValsT ls bod_maybe) ty sync_deps = do case bod_maybe of @@ -533,9 +547,15 @@ codegenTail venv fenv sort_fns (AssnValsT ls bod_maybe) ty sync_deps = do let venv' = (M.fromList $ map (\(a,b,_) -> (a,b)) ls) `M.union` venv bod' <- codegenTail venv' fenv sort_fns bod ty sync_deps - return $ [ mut (codegenTy ty) vr (codegenTriv venv triv) | (vr,ty,triv) <- ls ] ++ bod' + return $ [ case ty of + CursorArrayTy{} -> memcpy (codegenTy ty) vr (codegenTriv venv triv) + _ -> mut (codegenTy ty) vr (codegenTriv venv triv) + | (vr,ty,triv) <- ls ] ++ bod' Nothing -> - return $ [ mut (codegenTy ty) vr (codegenTriv venv triv) | (vr,ty,triv) <- ls ] + return $ [ case ty of + CursorArrayTy{} -> memcpy (codegenTy ty) vr (codegenTriv venv triv) + _ -> mut (codegenTy ty) vr (codegenTriv venv triv) + | (vr,ty,triv) <- ls ] codegenTail venv fenv sort_fns (Switch lbl tr alts def) ty sync_deps = case def of @@ -561,7 +581,12 @@ codegenTail venv fenv sort_fns (LetTrivT (vr,rty,rhs) body) ty sync_deps = tal <- codegenTail venv' fenv sort_fns body ty sync_deps {-Bad assumption?-} {-If it is a statically sized array -} - return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] + -- if we have an array type that's being assigned + -- we can do a memcpy instead + case rty of + CursorArrayTy _size -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr; |], + C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] ++ tal + _ -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] ++ tal -- TODO: extend rts with arena primitives, and invoke them here @@ -631,7 +656,7 @@ codegenTail venv fenv sort_fns (LetTimedT flg bnds rhs body) ty sync_deps = | (vr0,ty0) <- bnds ] let rhs' = rewriteReturns rhs bnds rhs'' <- codegenTail venv fenv sort_fns rhs' ty sync_deps - itertime <- gensym "itertime" + itertime <- dbgTrace (minChatLvl) "Print rhs''" dbgTrace (minChatLvl) (sdoc (show (rhs'', rhs', rhs))) dbgTrace (minChatLvl) "End printing rhs''\n" gensym "itertime" batchtime <- gensym "batchtime" selftimed <- gensym "selftimed" times <- gensym "times" @@ -656,7 +681,7 @@ codegenTail venv fenv sort_fns (LetTimedT flg bnds rhs body) ty sync_deps = } |] , C.BlockStm [cstm| clock_gettime(CLOCK_MONOTONIC_RAW, & $id:begn ); |] ] ++ - rhs''++ + rhs'' ++ [ C.BlockStm [cstm| clock_gettime(CLOCK_MONOTONIC_RAW, &$(cid (toVar end))); |] , C.BlockStm [cstm| if ( $id:iters != gib_get_iters_param()-1) { gib_list_bumpalloc_restore_state(); @@ -705,12 +730,14 @@ codegenTail venv fenv sort_fns (LetCallT False bnds ratr rnds body) ty sync_deps -- Copied from the otherwise case below. ProdTy [_one] -> do nam <- gensym $ toVar "tmp_struct" - let bind (v,t) f = assn (codegenTy t) v (C.Member (cid nam) (C.toIdent f noLoc) noLoc) + let bind (v,t) f = case t of + CursorArrayTy{} -> initVarItems (codegenTy t) v (C.Member (cid nam) (C.toIdent f noLoc) noLoc) + _ -> [assn (codegenTy t) v (C.Member (cid nam) (C.toIdent f noLoc) noLoc)] fields = map (\i -> "field" ++ show i) [0 :: Int .. length bnds - 1] ty0 = ProdTy $ map snd bnds init = [ C.BlockDecl [cdecl| $ty:(codegenTy ty0) $id:nam = $(fnexp); |] ] tal <- codegenTail venv' fenv sort_fns body ty sync_deps - return $ init ++ zipWith bind bnds fields ++ tal + return $ init ++ (concat $ zipWith bind bnds fields) ++ tal ProdTy [] -> do -- nam <- gensym "tmp" let init = [ C.BlockDecl [cdecl| $ty:(codegenTy fn_ret_ty) $id:(fst bnd) = $(fnexp); |] ] @@ -722,13 +749,15 @@ codegenTail venv fenv sort_fns (LetCallT False bnds ratr rnds body) ty sync_deps return $ [call] ++ tal | otherwise = do nam <- gensym $ toVar "tmp_struct" - let bind (v,t) f = assn (codegenTy t) v (C.Member (cid nam) (C.toIdent f noLoc) noLoc) + let bind (v,t) f = case t of + CursorArrayTy{} -> initVarItems (codegenTy t) v (C.Member (cid nam) (C.toIdent f noLoc) noLoc) + _ -> [assn (codegenTy t) v (C.Member (cid nam) (C.toIdent f noLoc) noLoc)] fields = map (\i -> "field" ++ show i) [0 :: Int .. length bnds - 1] ty0 = ProdTy $ map snd bnds init = [ C.BlockDecl [cdecl| $ty:(codegenTy ty0) $id:nam = $(fnexp); |] ] venv' = (M.fromList bnds) `M.union` venv tal <- codegenTail venv' fenv sort_fns body ty sync_deps - return $ init ++ zipWith bind bnds fields ++ tal + return $ init ++ (concat $ zipWith bind bnds fields) ++ tal where fncall = let rnds' = map (codegenTriv venv) rnds @@ -1555,14 +1584,16 @@ codegenTail venv fenv sort_fns (LetPrimCallT bnds prm rnds body) ty sync_deps = This way, we just allocate once, instead of allocating multiple times. -} MakeCursorArray -> do - let [(outV, outT)] = bnds - let outVtmp = toVar $ (fromVar outV) ++ "_tmp" + let [(outV, _outT)] = bnds + --let outVtmp = toVar $ (fromVar outV) ++ "_tmp" let args = rnds let size = length args let initList = map (\exp -> C.ExpInitializer exp (noLoc)) (map (codegenTriv venv) args) - let arrayInit = [cdecl| $ty:(codegenTy CursorTy) $id:outVtmp[$int:size] = { $inits:initList }; |] - let arrayMalloc = [cdecl| $ty:(codegenTy outT) $id:outV = gib_array_alloc($id:outVtmp, $int:size); |] - pure [C.BlockDecl arrayInit, C.BlockDecl arrayMalloc] + --let arrayInit = [cdecl| $ty:(codegenTy CursorTy) $id:outVtmp[$int:size] = { $inits:initList }; |] + let arrayInit = [cdecl| $ty:(codegenTy CursorTy) $id:outV[$int:size] = { $inits:initList }; |] + --let arrayMalloc = [cdecl| $ty:(codegenTy outT) $id:outV = gib_array_alloc($id:outVtmp, $int:size); |] + --pure [C.BlockDecl arrayInit, C.BlockDecl arrayMalloc] + pure [C.BlockDecl arrayInit] --let arrayInit = [cdecl| $ty:(codegenTy CursorTy) $id:outV[$int:size] = { $inits:initList }; |] -- let arrayMalloc = [cdecl| $ty:(codegenTy outT) $id:outV = gib_array_alloc($id:outVtmp, $int:size); |] --pure [C.BlockDecl arrayInit] @@ -1578,9 +1609,15 @@ codegenTail venv fenv sort_fns (LetPrimCallT bnds prm rnds body) ty sync_deps = CastPtr -> do let [(outV, outT)] = bnds + outT' = case outT of + CursorArrayTy{} -> MutCursorTy + _ -> outT [ptr] = rnds ptr' = codegenTriv venv ptr - return [ C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV = ($ty:(codegenTy outT)) $exp:ptr'; |] ] + -- In case it is a cusory array, we need to do an additional memcpy + init_array = C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV; |] + -- C.BlockStm [cstm| memcpy($id:x, $exp:y, sizeof($ty:t)); |] + return [ init_array, C.BlockStm [cstm| memcpy($id:outV, ($ty:(codegenTy outT')) $exp:ptr', sizeof($ty:(codegenTy outT'))) ;|] ] AddrOfCursor -> do let [(outV, outT)] = bnds @@ -1741,10 +1778,25 @@ cid v = C.Var (C.toIdent v noLoc) noLoc toStmt :: C.Exp -> C.BlockItem toStmt x = C.BlockStm [cstm| $exp:x; |] +-- toMemCpyStmt :: C.Exp -> C.BlockItem +-- toMemCpyStmt x = C.BlockStm [cstm| memcpy($id:x, $exp:y, sizeof($ty:t)); |] + -- | Create a NEW lexical binding. assn :: (C.ToIdent v, C.ToExp e) => C.Type -> v -> e -> C.BlockItem assn t x y = C.BlockDecl [cdecl| $ty:t $id:x = $exp:y; |] +-- initVar :: (C.ToIdent v) => C.Type -> v -> C.BlockItem +-- initVar t x = C.BlockDecl [cdecl| $ty:t $id:x; |] + +initVarItems :: (C.ToIdent v, C.ToExp e) => C.Type -> v -> e -> [C.BlockItem] +initVarItems t x y = + [ C.BlockDecl [cdecl| $ty:t $id:x; |] + , C.BlockStm [cstm| memcpy($id:x, $exp:y, sizeof($ty:t)); |] + ] + -- | Mutate an existing binding: mut :: (C.ToIdent v, C.ToExp e) => C.Type -> v -> e -> C.BlockItem mut _t x y = C.BlockStm [cstm| $id:x = $exp:y; |] + +memcpy :: (C.ToIdent v, C.ToExp e) => C.Type -> v -> e -> C.BlockItem +memcpy t x y = C.BlockStm [cstm| memcpy($id:x, $exp:y, sizeof($ty:t)); |] From 84a486743bdd7a8b459e39efcdaca6836623fcb5 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Fri, 10 Oct 2025 00:09:39 -0400 Subject: [PATCH 34/60] edits --- gibbon-compiler/examples/soa_examples/list.hs | 4 ++-- gibbon-compiler/examples/soa_examples/tree.hs | 6 +++--- gibbon-compiler/src/Gibbon/Passes/Cursorize.hs | 15 +++++++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 2c772960a..c477effcc 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -38,8 +38,8 @@ id lst = lst gibbon_main = let lst = mkList 100 - lst' = id (add1 lst) - in sumList lst' + lst' = iterate (add1 lst) + in printPacked lst'--sumList lst' diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index fe4abca31..208a41745 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -32,13 +32,13 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = id (mkTree 7) - tree' = id (add1Tree tree) + let tree = id (mkTree 13) + tree' = iterate (add1Tree tree) val = sumTree tree' _ = printsym (quote "(sum: ") _ = printint val _ = printsym (quote ", rightmost: ") - rmost = rightmost tree' + rmost = (rightmost tree') _ = printint rmost _ = printsym (quote ")\n\n") in () diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index ddaf67935..a73351b57 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -997,6 +997,13 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) ([], []) bounds + let end_regs = map (\(_, bound, _) _ -> let bound_loc = toLocVar bound + bound_reg = fromLocVarToRegVar bound_loc + in bound_reg + ) bounds + -- Now i need to find the parent region of these single regs. + -- Update these regions in the parent + -- and propgate the new region in the environment. exp' <- return $ mkLets lets <$> Ext $ L3.BoundsCheckVector bounds' return (exp', freeVarToVarEnv) FromEndE {} -> error $ "cursorizeExp: TODO FromEndE" ++ sdoc ext @@ -1033,10 +1040,10 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- In case we unpack single regions, we make them mutable since they may -- be updated by bounds check. let ty_of_loc = case loc of - SingleR _ -> MutCursorTy + SingleR _ -> CursorTy SoARv _ flds -> CursorArrayTy (1 + length flds) let ty2_of_loc :: Ty2 = case loc of - SingleR _ -> MkTy2 MutCursorTy + SingleR _ -> MkTy2 CursorTy SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) freeVarToVarEnv' <- do case loc of @@ -1739,10 +1746,10 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- SingleR _ -> CursorTy -- SoARv _ flds -> CursorArrayTy (1 + length flds) let ty_of_loc = case loc of - SingleR _ -> MutCursorTy + SingleR _ -> CursorTy SoARv _ flds -> CursorArrayTy (1 + length flds) let ty2_of_loc :: Ty2 = case loc of - SingleR _ -> MkTy2 MutCursorTy + SingleR _ -> MkTy2 CursorTy SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) freeVarToVarEnv' <- do case loc of From 56737b024ada44213219c44d9c55b7d5aa90bd55 Mon Sep 17 00:00:00 2001 From: vidush Date: Fri, 10 Oct 2025 14:22:24 -0400 Subject: [PATCH 35/60] Wip: use stack allocated arrays --- .../examples/soa_examples/MonoTree.hs | 2 +- gibbon-compiler/examples/soa_examples/list.hs | 4 +-- gibbon-compiler/src/Gibbon/L2/Syntax.hs | 1 + .../src/Gibbon/Passes/Cursorize.hs | 24 +++++++++++++++-- .../src/Gibbon/Passes/ThreadRegions2.hs | 26 ++++++++++++++----- gibbon-compiler/src/Gibbon/Pretty.hs | 1 + 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 5b9dc14db..79921815e 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -30,7 +30,7 @@ sumTree tr = Node d l r -> d + (sumTree l) + (sumTree r) gibbon_main = let - tree = mkTree 20 0 + tree = mkTree 23 0 tree' = iterate (add1Tree tree) in sumTree tree' diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index c477effcc..3f23adef8 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -37,9 +37,9 @@ id :: List -> List id lst = lst gibbon_main = let - lst = mkList 100 + lst = mkList 10000000 lst' = iterate (add1 lst) - in printPacked lst'--sumList lst' + in sumList lst' diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index 03ad932a7..081619535 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -232,6 +232,7 @@ data PreLocExp loc = StartOfRegionLE Region data PreRegExp loc = GetDataConRegSoA loc | GetFieldRegSoA (DataCon, FieldIndex) loc + | GenSoAReg loc [((DataCon, FieldIndex), loc)] deriving (Read, Show, Eq, Ord, Functor, Generic, NFData) type LocExp = PreLocExp LocVar diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index a73351b57..d54f224b7 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1053,7 +1053,10 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else return $ M.insert (fromRegVarToFreeVarsTy loc) l freeVarToVarEnv SoARv _ _ -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv - then return $ freeVarToVarEnv + -- overwrite this location with a new variable + then do + name <- gensym "overwrite_reg" + return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv else do name <- gensym "cursor_ptr" return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv @@ -1759,7 +1762,9 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else return $ M.insert (fromRegVarToFreeVarsTy loc) l freeVarToVarEnv SoARv _ _ -> if M.member (fromRegVarToFreeVarsTy loc) freeVarToVarEnv - then return $ freeVarToVarEnv + then do + name <- gensym "overwrite_reg" + return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv else do name <- gensym "cursor_ptr" return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv @@ -2338,6 +2343,21 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = in if isBound loc_var tenv then Right (rhs, [], tenv, senv) else Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], MutCursorTy, rhs)] denv + GenSoAReg dloc flocs -> + {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} + let dcloc_var = case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar dloc)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeRegExp: GenSoAReg: unexpected data constructor location variable" + field_vars = + map + ( \(_, loc) -> case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar loc)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeRegExp: GenSoAReg: unexpected field location variable" + ) + flocs + rhs = Ext $ MakeCursorArray (1 + length flocs) ([dcloc_var] ++ field_vars) + in dbgTrace (minChatLvl) "Print freeVarEnv GenSoAReg:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" Right (rhs, [], tenv, senv) + findSoAParent :: FreeVarsTy -> M.Map FreeVarsTy Var -> Maybe FreeVarsTy findSoAParent fvar freeVarEnv = case fvar of diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index 56c2f784c..c2bd34c78 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -242,6 +242,15 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod in [(2 * (size_of_ty + 11), (NewL2.EndOfReg freg mode (toEndVRegVar freg)), (NewL2.Loc (LREM floc freg (toEndVRegVar freg) mode)))] ) $ zip fieldLocs' fieldRegs' + -- end_of_regions = S.fromList $ map (\(_, reg, _) -> case reg of + -- NewL2.EndOfReg _ _ endr -> endr + -- _ -> error "Did not expect anything else than EndOfRegion!" + -- ) (boundsCheckDcon ++ boundsCheckFields) + + ends_fields = map (\(i, floc) -> (i, toEndVRegVar $ regionToVar floc)) fieldRegs + regen_region = SoARv dcEndReg ends_fields + ends_fields' = map (\(ind, floc) -> (ind, (NewL2.EndOfReg (regionToVar floc) mode (toEndVRegVar (regionToVar floc))))) fieldRegs + new_reg_Inst = [LetRegE regen_region (GenSoAReg (NewL2.EndOfReg dcreg mode (dcEndReg)) ends_fields')] boundsCheckVector = [("_", [], MkTy2 IntTy, Ext $ BoundsCheckVector (boundsCheckDcon ++ boundsCheckFields))] regInst = [LetRegE (fromLocVarToRegVar (NewL2.toLocVar dcRegArg)) (GetDataConRegSoA (NewL2.EndOfReg (regionToVar reg) Output (toEndVRegVar $ regionToVar reg)))] regInst' = @@ -260,7 +269,7 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod _ -> [LetLocE floc (GetFieldLocSoA d (NewL2.Loc (LREM loc (regionToVar reg) (toEndVRegVar (regionToVar reg)) mode)))] ) fieldLocs - in (boundsCheckVector, locInst ++ locInst' ++ regInst ++ regInst') + in ((boundsCheckVector, new_reg_Inst), locInst ++ locInst' ++ regInst ++ regInst') else let dcreg = regionToVar dcReg dcEndReg = toEndVRegVar dcreg @@ -273,7 +282,7 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod _ -> [LetRegE (toEndVRegVar $ regionToVar freg) (GetFieldRegSoA d (NewL2.EndOfReg (regionToVar reg) Output (toEndVRegVar $ regionToVar reg)))] ) fieldRegs - in ([], regInst ++ regInst') + in (([], []), regInst ++ regInst') _ -> if mode == Output then @@ -285,20 +294,23 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod regarg = NewL2.EndOfReg rv mode end_rv in -- dbgTrace (minChatLvl) ("boundscheck" ++ sdoc ((locs_tycons M.! loc), bc)) $ -- maintain shadowstack in no eager promotion mode - ([("_", [], MkTy2 IntTy, Ext $ BoundsCheck bc regarg locarg)], []) - else ([], []) + (([("_", [], MkTy2 IntTy, Ext $ BoundsCheck bc regarg locarg)], []), []) + else (([], []), []) ) (locVars funTy) - boundschecks = concatMap fst results + boundschecks = concatMap (fst . fst) results + instrs_after = concatMap (snd . fst) results regInsts = concatMap snd results in -- If eager promotion is disabled, growing a region can also trigger a GC. if no_eager_promote && funCanTriggerGC funMeta then - let lets = mkLets (rpush ++ wpush ++ boundschecks ++ wpop ++ rpop) bod' + let lets_aft = L.foldr (\i acc -> Ext $ i acc) bod' instrs_after + lets = mkLets (rpush ++ wpush ++ boundschecks ++ wpop ++ rpop) lets_aft bod'' = L.foldr (\i acc -> Ext $ i acc) lets regInsts in bod'' else - let lets = mkLets boundschecks bod' + let lets_aft = L.foldr (\i acc -> Ext $ i acc) bod' instrs_after + lets = mkLets boundschecks lets_aft bod'' = L.foldr (\i acc -> Ext $ i acc) lets regInsts in bod'' diff --git a/gibbon-compiler/src/Gibbon/Pretty.hs b/gibbon-compiler/src/Gibbon/Pretty.hs index 17d13524c..7c4177ef4 100644 --- a/gibbon-compiler/src/Gibbon/Pretty.hs +++ b/gibbon-compiler/src/Gibbon/Pretty.hs @@ -456,6 +456,7 @@ instance Pretty l => Pretty (L2.PreRegExp l) where case re of L2.GetDataConRegSoA loc -> lparen <> text "getDataConRegSoA" <+> pprint loc <> rparen L2.GetFieldRegSoA (dcon, idx) loc -> lparen <> text "getFieldRegSoA" <+> lparen <> text dcon <+> "," <+> int idx <> rparen <+> pprint loc <> rparen + L2.GenSoAReg loc flocs -> lparen <> text "genSoALoc" <+> pprint loc <+> (brackets $ hcat (punctuate "," (map (\((dc, x), l) -> lparen <> lparen <> text dc <+> "," <+> int x <> rparen <+> "," <+> pprint l <> rparen) flocs))) <> rparen instance Pretty RegionSize where pprintWithStyle _ (BoundedSize x) = parens $ text "Bounded" <+> int x From 0541f216f933562483f52ab042e99c4e026fcb13 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Fri, 10 Oct 2025 17:57:47 -0400 Subject: [PATCH 36/60] fix indirections with new stack allocation strategy --- gibbon-compiler/examples/soa_examples/list.hs | 2 +- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 3f23adef8..8c7ae9b87 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -37,7 +37,7 @@ id :: List -> List id lst = lst gibbon_main = let - lst = mkList 10000000 + lst = id (mkList 10000000) lst' = iterate (add1 lst) in sumList lst' diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index c0979e935..02371edbf 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -1609,15 +1609,20 @@ codegenTail venv fenv sort_fns (LetPrimCallT bnds prm rnds body) ty sync_deps = CastPtr -> do let [(outV, outT)] = bnds - outT' = case outT of - CursorArrayTy{} -> MutCursorTy - _ -> outT + --outT' = case outT of + -- CursorArrayTy{} -> MutCursorTy + -- _ -> outT [ptr] = rnds ptr' = codegenTriv venv ptr - -- In case it is a cusory array, we need to do an additional memcpy - init_array = C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV; |] - -- C.BlockStm [cstm| memcpy($id:x, $exp:y, sizeof($ty:t)); |] - return [ init_array, C.BlockStm [cstm| memcpy($id:outV, ($ty:(codegenTy outT')) $exp:ptr', sizeof($ty:(codegenTy outT'))) ;|] ] + case outT of + CursorArrayTy{} -> do + -- In case it is a cusory array, we need to do an additional memcpy + let init_array = C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV; |] + -- C.BlockStm [cstm| memcpy($id:x, $exp:y, sizeof($ty:t)); |] + -- return [ init_array, C.BlockStm [cstm| memcpy($id:outV, ($ty:(codegenTy outT)) $exp:ptr', sizeof($ty:(codegenTy outT))) ;|] ] + return [ init_array, C.BlockStm [cstm| memcpy($id:outV, $exp:ptr', sizeof($ty:(codegenTy outT))) ;|] ] + _ -> return [ C.BlockDecl [cdecl| $ty:(codegenTy outT) $id:outV = ($ty:(codegenTy outT)) $exp:ptr'; |] ] + AddrOfCursor -> do let [(outV, outT)] = bnds From 14ee91a4a171cedc5694df411c148947f18b040d Mon Sep 17 00:00:00 2001 From: vidush Date: Sat, 11 Oct 2025 18:15:32 -0400 Subject: [PATCH 37/60] indirections work with new stack allocated model --- cabal.project | 2 +- .../examples/soa_examples/MonoTree.hs | 5 +- gibbon-compiler/examples/soa_examples/list.hs | 2 +- .../examples/soa_examples/test_copy.hs | 4 +- gibbon-compiler/src/Gibbon/Compiler.hs | 3 +- gibbon-compiler/src/Gibbon/L3/Syntax.hs | 6 + gibbon-compiler/src/Gibbon/L3/Typecheck.hs | 5 + gibbon-compiler/src/Gibbon/L4/Interp.hs | 4 +- gibbon-compiler/src/Gibbon/L4/Syntax.hs | 8 + gibbon-compiler/src/Gibbon/Language/Syntax.hs | 34 +-- gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs | 1 + gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 22 +- .../src/Gibbon/Passes/Cursorize.hs | 269 +++++++++++++++++- .../src/Gibbon/Passes/FollowPtrs.hs | 6 +- gibbon-compiler/src/Gibbon/Passes/Lower.hs | 14 + .../src/Gibbon/Passes/OptimizeL3.hs | 2 + .../src/Gibbon/Passes/RemoveCopies.hs | 3 +- .../src/Gibbon/Passes/Simplifier.hs | 2 + 18 files changed, 354 insertions(+), 38 deletions(-) diff --git a/cabal.project b/cabal.project index 1ba410e0a..3bdff1ba3 100644 --- a/cabal.project +++ b/cabal.project @@ -1,4 +1,4 @@ packages: gibbon-compiler program-options - ghc-options: -Werror + ghc-options: -Werror diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 79921815e..1a30df5ab 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -29,8 +29,11 @@ sumTree tr = Leaf n -> n Node d l r -> d + (sumTree l) + (sumTree r) +id :: Tree -> Tree +id tree = tree + gibbon_main = let - tree = mkTree 23 0 + tree = id (mkTree 23 0) tree' = iterate (add1Tree tree) in sumTree tree' diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 8c7ae9b87..81371a76b 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -38,7 +38,7 @@ id lst = lst gibbon_main = let lst = id (mkList 10000000) - lst' = iterate (add1 lst) + lst' = iterate (id (add1 lst)) in sumList lst' diff --git a/gibbon-compiler/examples/soa_examples/test_copy.hs b/gibbon-compiler/examples/soa_examples/test_copy.hs index a1b6f57b0..0420e9e87 100644 --- a/gibbon-compiler/examples/soa_examples/test_copy.hs +++ b/gibbon-compiler/examples/soa_examples/test_copy.hs @@ -16,8 +16,8 @@ gibbon_main = t2 = foo 50 t3 = make_node t1 t2 t4 = foo' t3 - t4' = Node 12 (Leaf 1) (Leaf 2) - t5 = Node 10 (Node 12 t4 t4') t1 + --t4' = Node 12 (Leaf 1) (Leaf 2) + t5 = Node 12 (Leaf 1) t4 --Node 10 (Node 12 t4 t4') (Node 12 (Leaf 1) (Leaf 1)) in printPacked t5 diff --git a/gibbon-compiler/src/Gibbon/Compiler.hs b/gibbon-compiler/src/Gibbon/Compiler.hs index a0e64771d..ffe89af4c 100644 --- a/gibbon-compiler/src/Gibbon/Compiler.hs +++ b/gibbon-compiler/src/Gibbon/Compiler.hs @@ -91,7 +91,6 @@ import Gibbon.Passes.Unariser (unariser) import Gibbon.Passes.Lower (lower) import Gibbon.Passes.RearrangeFree (rearrangeFree) import Gibbon.Passes.Codegen (codegenProg) -import Gibbon.Passes.AddCastInstructions (addCasts) import Gibbon.Passes.Fusion2 (fusion2) import Gibbon.Passes.HoistBoundsCheck (hoistBoundsCheckProg) import Gibbon.Passes.ReorderLetExprs (reorderLetExprs) @@ -843,7 +842,7 @@ Also see Note [Adding dummy traversals] and Note [Adding random access nodes]. l3 <- go "reorderScalarWrites" reorderScalarWrites l3 -- _ <- lift $ putStrLn (pprender l3) l3 <- go "L3.flatten" flattenL3 l3 - l3 <- go "addCasts" addCasts l3 + -- l3 <- go "addCasts" addCasts l3 l3 <- go "L3.typecheck" tcProg3 l3 l3 <- go "hoistNewBuf" hoistNewBuf l3 l3 <- go "L3.typecheck" tcProg3 l3 diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index 0831bd747..157867b84 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -59,6 +59,7 @@ data E3Ext loc dec = | WriteTag DataCon Var -- ^ Write Tag at Cursor, and return a cursor | TagCursor Var Var -- ^ Create a tagged cursor | WriteTaggedCursor Var (PreExp E3Ext loc dec) -- ^ Write a tagged cursor + | MemCpy Var Var dec -- ^ Do a mem copy from right address into left address of type dec | ReadTaggedCursor Var -- ^ Reads and returns a tagged cursor at Var | ReadCursor Var -- ^ Reads and returns the cursor at Var | WriteCursor Var (PreExp E3Ext loc dec) -- ^ Write a cursor, and return a cursor @@ -93,6 +94,7 @@ data E3Ext loc dec = | NullCursor -- ^ Constant null cursor value (hack?). -- Used for dict lookup, which returns a packed value but -- no end witness. + | InitCursor dec -- ^ Initialize a cursor without a rhs value. | RetE [(PreExp E3Ext loc dec)] -- ^ Analogous to L2's RetE. | GetCilkWorkerNum -- ^ Translates to __cilkrts_get_worker_number(). | LetAvail [Var] (PreExp E3Ext loc dec) -- ^ These variables are available to use before the join point @@ -118,6 +120,7 @@ instance FreeVars (E3Ext l d) where TagCursor a b -> S.fromList [a,b] ReadTaggedCursor v -> S.singleton v WriteTaggedCursor v ex -> S.insert v (gFreeVars ex) + MemCpy a b _ -> S.fromList [a, b] ReadCursor v -> S.singleton v WriteCursor c ex -> S.insert c (gFreeVars ex) ReadList v _ -> S.singleton v @@ -135,6 +138,7 @@ instance FreeVars (E3Ext l d) where BoundsCheck{} -> S.empty IndirectionBarrier _tycon (l1,r1,l2,r2) -> S.fromList [l1,r1,l2,r2] NullCursor -> S.empty + InitCursor{} -> S.empty BumpArenaRefCount v w -> S.fromList [v, w] RetE ls -> S.unions (L.map gFreeVars ls) GetCilkWorkerNum -> S.empty @@ -228,6 +232,7 @@ instance HasRenamable E3Ext l d => Renamable (E3Ext l d) where TagCursor a b -> TagCursor (go a) (go b) ReadTaggedCursor v -> ReadTaggedCursor (go v) WriteTaggedCursor v bod -> WriteTaggedCursor (go v) (go bod) + MemCpy a b ty -> MemCpy (go a) (go b) ty ReadCursor v -> ReadCursor (go v) WriteCursor v bod -> WriteCursor (go v) (go bod) ReadList v el_ty -> ReadList (go v) el_ty @@ -251,6 +256,7 @@ instance HasRenamable E3Ext l d => Renamable (E3Ext l d) where IndirectionBarrier tycon (go a, go b, go c, go d) BumpArenaRefCount v w -> BumpArenaRefCount (go v) (go w) NullCursor -> ext + InitCursor{} -> ext RetE ls -> RetE (L.map go ls) GetCilkWorkerNum -> GetCilkWorkerNum LetAvail ls b -> LetAvail (L.map go ls) (go b) diff --git a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs index 2bd493bb5..9fca5386e 100644 --- a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs @@ -75,6 +75,10 @@ tcExp isSoA isPacked ddfs env exp = do valty <- go val ensureEqualTyModCursor isSoA exp valty CursorTy return CursorTy + + -- does this require typecheking + MemCpy{} -> do + return $ ProdTy [] ReadCursor v -> do vty <- lookupVar env v exp @@ -193,6 +197,7 @@ tcExp isSoA isPacked ddfs env exp = do pure (ProdTy tys) NullCursor -> return CursorTy + InitCursor ty -> return ty GetCilkWorkerNum -> return IntTy diff --git a/gibbon-compiler/src/Gibbon/L4/Interp.hs b/gibbon-compiler/src/Gibbon/L4/Interp.hs index e063b4d13..54341445f 100644 --- a/gibbon-compiler/src/Gibbon/L4/Interp.hs +++ b/gibbon-compiler/src/Gibbon/L4/Interp.hs @@ -82,7 +82,9 @@ eval _ (SymTriv _) = error "eval: SymTriv not handled" eval _ (ProdTriv{}) = error "eval: ProdTriv not handled" eval _ (ProjTriv{}) = error "eval: ProjTriv not handled" eval _ (BoolTriv{}) = error "eval: BoolTriv not handled" -eval _ (IndexCursorArrayTriv{}) = error "eval: IndexCusorArrayTriv not handled" +eval _ (IndexCursorArrayTriv{}) = error "eval: IndexCusorArrayTriv not handled" +eval _ (UninitTriv{}) = error "eval: NullTriv not handled" +eval _ (SizeOf{}) = error "eval: SizeOf not handled" exec :: Env -> Tail -> IO [Val] diff --git a/gibbon-compiler/src/Gibbon/L4/Syntax.hs b/gibbon-compiler/src/Gibbon/L4/Syntax.hs index a5c2367e4..034b38633 100644 --- a/gibbon-compiler/src/Gibbon/L4/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L4/Syntax.hs @@ -62,11 +62,15 @@ data Triv | ProdTriv [Triv] -- ^ Tuples | ProjTriv Int Triv -- ^ Projections | IndexCursorArrayTriv Int Triv -- ^ Indexing operation + | UninitTriv Var Ty Int -- ^ uninitialized values + | SizeOf Ty -- ^ Size of a type deriving (Show, Ord, Eq, Generic, NFData, Out) typeOfTriv :: M.Map Var Ty -> Triv -> Ty typeOfTriv env trv = case trv of + SizeOf{} -> IntTy + UninitTriv _ ty _ -> ty VarTriv v -> env M.! v IntTriv{} -> IntTy CharTriv{} -> CharTy @@ -205,6 +209,7 @@ data Ty | CursorArrayTy Int | MutCursorTy + -- TODO: Make Ptrs more type safe like this: -- | StructPtrTy { fields :: [Ty] } -- ^ A pointer to a struct containing the given fields. @@ -314,6 +319,8 @@ data Prim | WriteTaggedCursor + | MemCpy + | ReadCursor -- ^ Read and return a cursor @@ -486,6 +493,7 @@ inlineTrivL4 (Prog info_tbl sym_tbl fundefs mb_main) = VarTriv w -> case M.lookup w env of Nothing -> inline_tail (M.insert v trv env) bod Just pr -> inline_tail (M.insert v pr env) bod + UninitTriv{} -> inline_tail env bod _ -> inline_tail (M.insert v trv env) bod LetIfT{ife,bod} -> tl { ife = (\(a,b,c) -> (inline env a, go b, diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 28c968e53..6b3e3406a 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -164,8 +164,10 @@ lkp dds con = _ -> error$ "lookupDataCon: found multiple occurences of constructor "++show con ++", in datatypes:\n "++sdoc dds +--tyName, +--Out a => getCursorTypeForDataCon :: DDefs (UrTy a) -> DDef (UrTy a) -> UrTy a -getCursorTypeForDataCon _ddefs DDef{dataCons, memLayout} = +getCursorTypeForDataCon _ddefs DDef{ dataCons, memLayout} = -- remove data constructors introduced by RAN let _dataCons' = concatMap (\e@(dcon, _) -> if ('^' `elem` dcon) then [] @@ -175,21 +177,21 @@ getCursorTypeForDataCon _ddefs DDef{dataCons, memLayout} = -- VS: For now, in the design we just always ensure -- that a random access node is a CursorTy. _ -> CursorTy - -- Linear -> CursorTy - -- FullyFactored -> - -- let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon ddefs dcon - -- c' = foldr (\ty c'' -> case ty of - -- PackedTy tycon _ -> - -- if (toVar tycon) == tyName - -- then c'' - -- else c'' + 1 - -- CursorTy -> c'' - -- CursorArrayTy _ -> c'' - -- _ -> c'' + 1 - -- ) c fields - -- in c' - -- ) 0 dataCons' - -- in CursorArrayTy (numFieldBuffers + 1) + -- Linear -> CursorTy + -- FullyFactored -> + -- let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon _ddefs dcon + -- c' = foldr (\ty c'' -> case ty of + -- PackedTy tycon _ -> + -- if (toVar tycon) == tyName + -- then c'' + -- else c'' + 1 + -- CursorTy -> c'' + -- CursorArrayTy _ -> c'' + -- _ -> c'' + 1 + -- ) c fields + -- in c' + -- ) 0 _dataCons' + -- in CursorArrayTy (numFieldBuffers + 1) -- _ -> error "Memory Layout is not implemented!" insertDD :: DDef a -> DDefs a -> DDefs a diff --git a/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs b/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs index 0fbce83a7..fb21e4b69 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs @@ -87,6 +87,7 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = PackedTy _ loc -> (loc:acc) -- For indirection/redirection pointers. CursorTy -> ((Single w):acc) + CursorArrayTy{} -> ((Single w):acc) _ -> acc _ -> acc) [] diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index 02371edbf..0c46fa27c 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -460,6 +460,8 @@ rewriteReturns tl bnds = -- dummyLoc = (SrcLoc (Loc (Pos "" 0 0 0) (Pos "" 0 0 0))) codegenTriv :: VEnv -> Triv -> C.Exp +codegenTriv _ (SizeOf ty) = [cexp| sizeof($ty:(codegenTy ty)) |] +codegenTriv _ (UninitTriv{}) = [cexp| (void)0 |] -- noop codegenTriv _ (VarTriv v) = C.Var (C.toIdent v noLoc) noLoc codegenTriv _ (IntTriv i) = [cexp| $int:i |] codegenTriv _ (CharTriv i) = [cexp| $char:i |] @@ -583,11 +585,15 @@ codegenTail venv fenv sort_fns (LetTrivT (vr,rty,rhs) body) ty sync_deps = {-If it is a statically sized array -} -- if we have an array type that's being assigned -- we can do a memcpy instead - case rty of - CursorArrayTy _size -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr; |], - C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] ++ tal - _ -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] - ++ tal + case rty of + CursorArrayTy _size -> case rhs of + UninitTriv{} -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr; |] ] ++ tal + _ -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr; |], + C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] ++ tal + _ -> case rhs of + UninitTriv{} -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr; |] ] ++ tal + _ -> return $ [ C.BlockDecl [cdecl| $ty:(codegenTy rty) $id:vr = ($ty:(codegenTy rty)) $(codegenTriv venv rhs); |] ] + ++ tal -- TODO: extend rts with arena primitives, and invoke them here codegenTail venv fenv sort_fns (LetArenaT vr body) ty sync_deps = @@ -1040,6 +1046,12 @@ codegenTail venv fenv sort_fns (LetPrimCallT bnds prm rnds body) ty sync_deps = [ C.BlockStm [cstm| *( $ty:tagged_t *)($id:cur) = ($ty:tagged_t) $(codegenTriv venv val); |] , C.BlockDecl [cdecl| $ty:(codegenTy CursorTy) $id:outV = ($id:cur) + 8; |] ] + MemCpy -> let [(VarTriv copy_to), (VarTriv copy_from), size] = rnds in pure + [ C.BlockStm [cstm| memcpy($id:copy_to, $id:copy_from, $(codegenTriv venv size)); |] ] + + -- MemCpy -> let [(UninitTriv copy_to _ _), (VarTriv copy_from), size] = rnds in pure + -- [ C.BlockStm [cstm| memcpy($id:copy_to, $id:copy_from, $(codegenTriv venv size)); |] ] + ReadCursor -> let [(next,CursorTy),(afternext,CursorTy)] = bnds [(VarTriv cur)] = rnds in pure [ C.BlockDecl [cdecl| $ty:(codegenTy CursorTy) $id:next = *($ty:(codegenTy CursorTy) *) ($id:cur); |] diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index d54f224b7..3dfb36da4 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1585,6 +1585,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- shortcut pointer -- SoA case -- Fix case for indirection/shortcut pointers + -- TODO: Vidush, for SoA case, we should not use Cursor, but CursorArray to be precise + -- and type correct, change followPtrs to do this. CursorTy -> do (rnd', fvarenv') <- cursorizeExp fvarenv lenv ddfs fundefs denv tenv senv rnd after_indirection <- gensym "aft_indirection" @@ -1592,10 +1594,21 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let rnd_var = case rnd' of VarE v -> v _ -> error "Did not expected variable!" + let (rnd_ty, num_curs) = case M.lookup rnd_var tenv of + Nothing -> error "Expected type for variable!\n" + Just ty -> case unTy2 ty of + PackedTy _ l -> do + case l of + Single _ -> (CursorTy, 1) + SoA _ fields -> (CursorArrayTy (1 + length (fields)), ((1 + length (fields)))) + CursorArrayTy sz -> (CursorArrayTy sz, sz) + _ -> (CursorTy, 1) if isIndirectionTag dcon then do - LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> - LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) + --LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> + -- --LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE rnd_var)) + LetE ("_", [], ProdTy [], Ext (MemCpy aft_dloc rnd_var rnd_ty)) <$> + LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8 * num_curs))) <$> LetE (after_indirection, [], CursorTy, VarE d') <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) else do @@ -1603,7 +1616,41 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = <$> LetE (after_indirection, [], CursorTy, VarE d') <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) - + -- shortcut pointer + -- SoA case + -- Fix case for indirection/shortcut pointers + -- TODO: Vidush, for SoA case, we should not use Cursor, but CursorArray to be precise + -- and type correct, change followPtrs to do this. + CursorArrayTy _size -> do + (rnd', fvarenv') <- cursorizeExp fvarenv lenv ddfs fundefs denv tenv senv rnd + after_indirection <- gensym "aft_indirection" + casted_var <- gensym "cast" + let rnd_var = case rnd' of + VarE v -> v + _ -> error "Did not expected variable!" + let (rnd_ty, num_curs) = case M.lookup rnd_var tenv of + Nothing -> error "Expected type for variable!\n" + Just ty -> case unTy2 ty of + PackedTy _ l -> do + case l of + Single _ -> (CursorTy, 1) + SoA _ fields -> (CursorArrayTy (1 + length (fields)), ((1 + length (fields)))) + CursorArrayTy sz -> (CursorArrayTy sz, sz) + _ -> (CursorTy, 1) + if isIndirectionTag dcon + then do + --LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> + -- --LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE rnd_var)) + LetE ("_", [], ProdTy [], Ext (MemCpy aft_dloc rnd_var rnd_ty)) <$> + LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8 * _size))) + <$> LetE (after_indirection, [], CursorTy, VarE d') + <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + else do + LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') + <$> LetE (after_indirection, [], CursorTy, VarE d') + <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + + _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty writetag <- gensym "writetag" @@ -3597,13 +3644,222 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack else error $ "unpackRegularDataCon: cursorty without indirection/redirection." binds = [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), - (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), - (v, [], CursorTy, ProjE 0 (VarE tmp)), + --(tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (v, [], locs_ty3, Ext $ InitCursor locs_ty3), + ("_", [], ProdTy [], Ext (MemCpy v var_dcon_next locs_ty3)) + -- , + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), + -- End of region needs to be calculated differently + -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), + -- ((loc_var), [], locs_ty3, VarE v) + ] + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) + return $ mkLets binds bod + else do + tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" + tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur + loc_var <- lookupVariable loc fenv + var_dcon_next <- gensym "dcon_next" + vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur + redirection_var_dcon <- gensym "dcon_redir" + redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + -- ((loc_var) , MkTy2 CursorTy), + (redirection_var_dcon, MkTy2 CursorTy), + (toEndV redirection_var_dcon, MkTy2 CursorTy), + (toTagV redirection_var_dcon, MkTy2 IntTy), + (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy) + ] + ) tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + -- v is the variable i want to send to the call. + -- In this case v is the soa variable where all redirections are unpacked. + binds = [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + ((loc_var), [], CursorTy, VarE dcur), + (redirection_var_dcon, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV redirection_var_dcon, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon))) + ] + -- generate binds for all fields. + binds_flields = + L.foldl + ( \(index, res) ((dcon', idx), var) -> + let read_cursor_f = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor (vars_next_fields !! index)) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + tmpf = tmp_flds !! index + ty_of_field = (lookupDataCon ddfs dcon') !! idx + in case ty_of_field of + (MkTy2 PackedTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + (MkTy2 CursorArrayTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + _ -> + let new_binds = + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] + in (index + 1, res ++ new_binds) + ) (0, []) _field_cur + soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] + tenv'' = M.union + ( M.fromList + [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) + ] + ) tenv + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + + -- An indirection pointer for an SoA region. + -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag. + CursorArrayTy size -> do + if isRedirectionTag dcon + then do + tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" + tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur + loc_var <- lookupVariable loc fenv + var_dcon_next <- gensym "dcon_next" + vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur + redirection_var_dcon <- gensym "dcon_redir" + redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + -- ((loc_var) , MkTy2 CursorTy), + (redirection_var_dcon, MkTy2 CursorTy), + (toEndV redirection_var_dcon, MkTy2 CursorTy), + (toTagV redirection_var_dcon, MkTy2 IntTy), + (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + -- v is the variable i want to send to the call. + -- In this case v is the soa variable where all redirections are unpacked. + binds = + [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + ((loc_var), [], CursorTy, VarE dcur), + (redirection_var_dcon, [], CursorTy, ProjE 0 (VarE tmp)), + (toEndV redirection_var_dcon, [], CursorTy, ProjE 1 (VarE tmp)), + (toTagV redirection_var_dcon, [], IntTy, ProjE 2 (VarE tmp)), + (toEndFromTaggedV redirection_var_dcon, [], CursorTy, Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon))) + ] + + -- generate binds for all fields. + binds_flields = + L.foldl + ( \(index, res) ((dcon', idx), var) -> + let read_cursor_f = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor (vars_next_fields !! index)) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + tmpf = tmp_flds !! index + ty_of_field = (lookupDataCon ddfs dcon') !! idx + in case ty_of_field of + (MkTy2 PackedTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + (MkTy2 CursorArrayTy {}) -> + let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + in (index + 1, res ++ new_binds) + _ -> + let new_binds = + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] + in (index + 1, res ++ new_binds) + ) + (0, []) + _field_cur + soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] + tenv'' = + M.union + ( M.fromList + [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds))) + ] + ) + tenv + bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) + return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod + else + -- This case is different for when the GC is on. + -- Vidush: TODO change this when the GC is on + if isIndirectionTag dcon + then do + dflags <- getDynFlags + if gopt Opt_DisableGC dflags + then do + tmp <- gensym "readcursor_indir" + loc_var <- lookupVariable loc fenv + let locs_ty = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + let locs_ty3 :: Ty3 = case (loc) of + FL (Single _) -> CursorTy + FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + _ -> error "Expected location!" + -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 + -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur + var_dcon_next <- gensym "dcon_next" + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + ((loc_var), MkTy2 locs_ty), + (v, MkTy2 locs_ty) + -- (toEndV v, MkTy2 CursorTy), + -- (toTagV v, MkTy2 IntTy), + -- (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + read_cursor = + if isIndirectionTag dcon || isRedirectionTag dcon + then Ext (ReadTaggedCursor var_dcon_next) + else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + binds = + [ (var_dcon_next, [], CursorTy, Ext (AddCursor dcur (LitE 1))), + --(tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + (v, [], locs_ty3, Ext $ InitCursor locs_ty3), + ("_", [], ProdTy [], Ext (MemCpy v var_dcon_next locs_ty3)) + -- , -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)), -- End of region needs to be calculated differently -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))), - ((loc_var), [], locs_ty3, VarE v) + -- ((loc_var), [], locs_ty3, VarE v) ] bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) return $ mkLets binds bod @@ -3679,6 +3935,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v) return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod else error $ "unpackRegularDataCon: cursorty without indirection/redirection." + VectorTy el_ty -> do tmp <- gensym "read_vec_tuple" loc_var <- lookupVariable loc fenv diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index 772fd53cb..ddef67d9a 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -143,9 +143,11 @@ followPtrs (Prog ddefs fundefs mainExp) = do -- Make the new SoA location with the data con loc -- Field locs will all be the same indir_br <- case scrt_loc of - SoA{} -> do + SoA _d flocs -> do + let arr_elems = 1 + length flocs let data_con_let = LetLocE (getDconLoc scrt_loc) (GetDataConLocSoA scrt_loc) - let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE 9 ((getDconLoc scrt_loc))) + -- assuming 8 byte pointer size + let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE (1 + 8 * arr_elems) ((getDconLoc scrt_loc))) let unpack_fld_lets = foldr (\((dcon, idx), lc) acc -> acc ++ [LetLocE lc (GetFieldLocSoA (dcon, idx) scrt_loc)]) [] (getAllFieldLocsSoA scrt_loc) let indir_bod = Ext $ LetLocE (jump) (GenSoALoc (getDconLoc jump) (getAllFieldLocsSoA scrt_loc) ) $ diff --git a/gibbon-compiler/src/Gibbon/Passes/Lower.hs b/gibbon-compiler/src/Gibbon/Passes/Lower.hs index 03ccd422c..7edbe1a27 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Lower.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Lower.hs @@ -509,9 +509,11 @@ lower Prog{fundefs,ddefs,mainExp} = do BoundsCheckVector{} -> syms ReadCursor{} -> syms WriteTaggedCursor{}-> syms + MemCpy{} -> syms ReadTaggedCursor{} -> syms IndirectionBarrier{} -> syms NullCursor -> syms + InitCursor{} -> syms BumpArenaRefCount{}-> error "collect_syms: BumpArenaRefCount not handled." RetE ls -> gol ls GetCilkWorkerNum -> syms @@ -896,6 +898,12 @@ lower Prog{fundefs,ddefs,mainExp} = do T.LetPrimCallT [(v,T.CursorTy)] T.WriteTaggedCursor [triv sym_tbl "WriteTaggedCursor arg" e, T.VarTriv cur] <$> tail free_reg sym_tbl bod + LetE (_, _, _, (Ext (MemCpy a b (CursorArrayTy sz)))) bod -> + T.LetPrimCallT [] T.MemCpy [T.VarTriv a, T.VarTriv b, T.SizeOf (T.CursorArrayTy sz)] <$> tail free_reg sym_tbl bod + + LetE (_, _, _, (Ext (MemCpy a b (CursorTy)))) bod -> + T.LetPrimCallT [] T.MemCpy [T.VarTriv a, T.VarTriv b, T.SizeOf (T.CursorTy)] <$> tail free_reg sym_tbl bod + LetE(v,_,_, (Ext (ReadCursor c))) bod -> do vtmp <- gensym $ toVar "tmpcur" ctmp <- gensym $ toVar "tmpaftercur" @@ -950,6 +958,12 @@ lower Prog{fundefs,ddefs,mainExp} = do LetE (v, _, _, (Ext NullCursor)) bod -> T.LetTrivT (v,T.CursorTy,T.IntTriv 0) <$> tail free_reg sym_tbl bod + LetE (v, _, _, (Ext (InitCursor (CursorArrayTy sz)))) bod -> + T.LetTrivT (v, T.CursorArrayTy sz, T.UninitTriv v (T.CursorArrayTy sz) sz) <$> tail free_reg sym_tbl bod + + LetE (v, _, _, (Ext (InitCursor (CursorTy)))) bod -> + T.LetTrivT (v, T.CursorTy, T.UninitTriv v (T.CursorTy) 1) <$> tail free_reg sym_tbl bod + LetE (v, _, ty, (Ext GetCilkWorkerNum)) bod -> T.LetPrimCallT [(v,typ ty)] T.GetCilkWorkerNum [] <$> tail free_reg sym_tbl bod diff --git a/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs b/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs index db0b7273c..53cdf4d75 100644 --- a/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs +++ b/gibbon-compiler/src/Gibbon/Passes/OptimizeL3.hs @@ -101,6 +101,7 @@ removeReDefsExp env ex = Ext (WriteTaggedCursor v e) -> do e' <- go e pure (Ext $ WriteTaggedCursor v e') + Ext (MemCpy{}) -> return ex Ext (ReadTaggedCursor v) -> do pure (Ext $ ReadTaggedCursor v) Ext (ReadCursor v) -> do @@ -142,6 +143,7 @@ removeReDefsExp env ex = Ext (IndirectionBarrier _ (_, _, _, _)) -> pure ex Ext (BumpArenaRefCount _ _) -> pure ex Ext NullCursor -> pure ex + Ext InitCursor{} -> pure ex Ext GetCilkWorkerNum -> pure ex Ext (AllocateTagHere v tycon) -> do pure $ (Ext $ AllocateTagHere v tycon) diff --git a/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs b/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs index 77da32c46..62369f8f6 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RemoveCopies.hs @@ -19,7 +19,8 @@ removeCopies Prog{ddefs,fundefs,mainExp} = do -- RemoveCopies might run more than once (b/c repairProgram), so -- we ensure that we add the Indirection constructor only once. let datacons = filter (not . isIndirectionTag . fst) dataCons - return ddf {dataCons = datacons ++ [(dcon, [(False, CursorTy)])]} ) + let ty_of_indirection = getCursorTypeForDataCon ddefs ddf + return ddf {dataCons = datacons ++ [(dcon, [(False, ty_of_indirection)])]} ) ddefs -- Don't process copy* functions fds' <- mapM (\fn -> if isCopyFunName (funName fn) diff --git a/gibbon-compiler/src/Gibbon/Passes/Simplifier.hs b/gibbon-compiler/src/Gibbon/Passes/Simplifier.hs index d2fd854c4..3d744e68c 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Simplifier.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Simplifier.hs @@ -239,6 +239,7 @@ lateInlineTriv (L4.Prog info_tbl sym_tbl fundefs mainExp) = do Just t2 -> t2 L4.ProdTriv ls -> L4.ProdTriv (map (gotriv env) ls) L4.ProjTriv i t -> L4.ProjTriv i (gotriv env t) + L4.UninitTriv v _ _ -> L4.VarTriv v _ -> trv goalts env alts = @@ -261,6 +262,7 @@ lateInlineTriv (L4.Prog info_tbl sym_tbl fundefs mainExp) = do L4.VarTriv w -> case M.lookup w env of Nothing -> go (M.insert v trv env) bod Just trv' -> go (M.insert v trv' env) bod + L4.UninitTriv _ _ _ -> L4.LetTrivT (v, _ty, trv) (go env bod) _ -> go (M.insert v (gotriv env trv) env) bod L4.LetIfT binds (trv,tl1,tl2) bod -> L4.LetIfT binds (gotriv env trv, go env tl1, go env tl2) (go env bod) From 98d74f1f05019a4ebe460fe5ba87b942a51f8be5 Mon Sep 17 00:00:00 2001 From: vidush Date: Sun, 12 Oct 2025 18:10:28 -0400 Subject: [PATCH 38/60] edits --- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- gibbon-compiler/src/Gibbon/L2/Typecheck.hs | 9 +++- gibbon-compiler/src/Gibbon/Language/Syntax.hs | 40 ++++++++-------- .../src/Gibbon/Passes/Cursorize.hs | 48 +++++++++++++++++-- .../src/Gibbon/Passes/InferLocations.hs | 12 ++++- .../src/Gibbon/Passes/ThreadRegions2.hs | 1 + 6 files changed, 82 insertions(+), 30 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index 208a41745..316da03cd 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -3,7 +3,7 @@ module Tree where data Tree = Leaf Int Float | Node Int Int Int Float Tree Tree Tree Tree deriving Show ---{-# ANN type Tree "Factored" #-} +{-# ANN type Tree "Factored" #-} mkTree :: Int -> Tree mkTree d = diff --git a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs index 7f28b16e9..355428e73 100644 --- a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs @@ -31,6 +31,7 @@ import Text.PrettyPrint.GenericPretty import Gibbon.Common import Gibbon.L2.Syntax as L2 + -- import qualified Gibbon.L1.Syntax as L1 -- | Constraints on locations. Used during typechecking. Roughly analogous to LocExp. @@ -900,7 +901,10 @@ tcExp ddfs env funs constrs regs tstatein exp = Ext (StartOfPkdCursor cur) -> do case M.lookup (fromVarToFreeVarsTy cur) (vEnv env) of - Just (PackedTy{}) -> pure (CursorTy, tstatein) + Just (PackedTy ty _) -> do + let ddef = lookupDDef ddfs ty + let cursorType = getCursorTypeForDataCon ddfs ddef + pure (cursorType, tstatein) ty -> throwError $ GenericTC ("Expected PackedTy, got " ++ sdoc ty) exp Ext (TagCursor a _b) -> do @@ -1273,6 +1277,7 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of then [fromJust (L.elemIndex ty tys)] else [] CursorTy -> [fromJust (L.elemIndex ty tys)] + CursorArrayTy{} -> [fromJust (L.elemIndex ty tys)] _ -> [] ) tys @@ -1291,6 +1296,7 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of x:_ -> case x of PackedTy _ l -> ensureAfterConstant exp cs (Single dcloc) (getDconLoc l) CursorTy -> return () + CursorArrayTy{} -> return () _ -> error "Did not expected unpacked type!" -- TODO: ensure after constant for all scalar not self recursive fields, with offset 0 -- TODO: ensure after constant for all locs in dest with the next self recursive field. @@ -1317,6 +1323,7 @@ ensureDataCon exp dcty dc linit0 tys cs = case linit0 of return () -- TODO: implement for ran access pointers. CursorTy -> return () + CursorArrayTy{} -> return () _ -> error "Not implemented!" -- dbgTraceIt "Print in ensure data con" dbgTraceIt (sdoc (unselfTys, selfTys, unselfWriteAtLocs)) dbgTraceIt "End\n" return () diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 6b3e3406a..0b2c345f4 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -164,10 +164,8 @@ lkp dds con = _ -> error$ "lookupDataCon: found multiple occurences of constructor "++show con ++", in datatypes:\n "++sdoc dds ---tyName, ---Out a => -getCursorTypeForDataCon :: DDefs (UrTy a) -> DDef (UrTy a) -> UrTy a -getCursorTypeForDataCon _ddefs DDef{ dataCons, memLayout} = +getCursorTypeForDataCon :: Out a => DDefs (UrTy a) -> DDef (UrTy a) -> UrTy a +getCursorTypeForDataCon _ddefs DDef{tyName, dataCons, memLayout} = -- remove data constructors introduced by RAN let _dataCons' = concatMap (\e@(dcon, _) -> if ('^' `elem` dcon) then [] @@ -176,23 +174,23 @@ getCursorTypeForDataCon _ddefs DDef{ dataCons, memLayout} = in case memLayout of -- VS: For now, in the design we just always ensure -- that a random access node is a CursorTy. - _ -> CursorTy - -- Linear -> CursorTy - -- FullyFactored -> - -- let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon _ddefs dcon - -- c' = foldr (\ty c'' -> case ty of - -- PackedTy tycon _ -> - -- if (toVar tycon) == tyName - -- then c'' - -- else c'' + 1 - -- CursorTy -> c'' - -- CursorArrayTy _ -> c'' - -- _ -> c'' + 1 - -- ) c fields - -- in c' - -- ) 0 _dataCons' - -- in CursorArrayTy (numFieldBuffers + 1) - -- _ -> error "Memory Layout is not implemented!" + --_ -> CursorTy + Linear -> CursorTy + FullyFactored -> + let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon _ddefs dcon + c' = foldr (\ty c'' -> case ty of + PackedTy tycon _ -> + if (toVar tycon) == tyName + then c'' + else c'' + 1 + CursorTy -> c'' + CursorArrayTy _ -> c'' + _ -> c'' + 1 + ) c fields + in c' + ) 0 _dataCons' + in CursorArrayTy (numFieldBuffers + 1) + _ -> error "Memory Layout is not implemented!" insertDD :: DDef a -> DDefs a -> DDefs a insertDD d = M.insertWith err' (tyName d) d diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 3dfb36da4..104a65641 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -817,17 +817,18 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = SoA _ _ -> error $ "cursorizeExp: LetLocE: unexpected location variable " ++ show ((fromLocVarToRegVar . toLocVar) b) tag_cur_var <- gensym "tag_cur" - casted_var <- gensym "cast" + --casted_var <- gensym "cast" let ty3_of_field = case (toLocVar a) of Single _ -> CursorTy SoA _ fl -> CursorArrayTy (1 + length fl) let ty3_of_field2 :: Ty3 = case (toLocVar a) of Single _ -> CursorTy SoA _ fl -> CursorArrayTy (1 + length fl) - let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) - let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) - let let_bnd = mkLets $ [tag_inst] ++ [cast_inst] - return (let_bnd (VarE casted_var), freeVarToVarEnv) + let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) + -- should not need to case anymore + --let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) + let let_bnd = mkLets $ [tag_inst] -- ++ [cast_inst] + return (let_bnd (VarE tag_cur_var), freeVarToVarEnv) -- All locations are transformed into cursors here. Location arithmetic -- is expressed in terms of corresponding cursor operations. @@ -4316,6 +4317,43 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' return $ mkLets binds bod + CursorArrayTy sz -> do + tmp <- gensym "readcursor_shortcut" + locs_var <- lookupVariable loc fenv + let tenv' = + M.union + ( M.fromList + [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), + (locs_var, MkTy2 (CursorArrayTy sz)), + (v, MkTy2 (CursorArrayTy sz)), + (toEndV v, MkTy2 CursorTy), + (toTagV v, MkTy2 IntTy), + (toEndFromTaggedV v, MkTy2 CursorTy) + ] + ) + tenv + --dcur_end is where i want to read the shortcut pointer from + -- we'd just do a memcpy and copy the random access pointer out + --read_cursor = Ext (ReadTaggedCursor dcur_end) + --binds = + -- [ (tmp, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor), + -- (locs_var, [], CursorTy, VarE dcur_end), + -- (v, [], CursorTy, ProjE 0 (VarE tmp)), + -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)), + -- (toTagV v, [], IntTy, ProjE 2 (VarE tmp)), + -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))) + -- ] + binds = [ + (v, [], (CursorArrayTy sz), Ext $ InitCursor (CursorArrayTy sz)), + --(locs_var, [], (CursorArrayTy sz), VarE dcur_end), + ("_", [], ProdTy [], Ext (MemCpy v dcur_end (CursorArrayTy sz))), + (toEndV v, [], CursorTy, Ext $ AddCursor dcur_end (LitE (8 * sz))) + ] + let curw' = SoAWin (toEndV v) _field_cur + bod <- go curw' fenv rst_vlocs rst_tys indirections_env denv tenv' + return $ mkLets binds bod + + -- Int, Sym, or Bool _ | isScalarTy ty -> do locs_var <- lookupVariable loc fenv diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index f5321e9fd..7db9b2346 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -1898,7 +1898,11 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = Ext (L1.StartOfPkdCursor cur) -> do (bod',ty',cs') <- inferExp ddefs (extendVEnv vr CursorTy env) bod dest - return (L2.LetE (vr,[],L2.CursorTy,L2.Ext (L2.StartOfPkdCursor cur)) bod', ty', cs') + let bty' = case bty of + CursorTy -> L2.CursorTy + CursorArrayTy sz -> L2.CursorArrayTy sz + _ -> error "InferExp: Did not expect any other type!" + return (L2.LetE (vr,[],bty',L2.Ext (L2.StartOfPkdCursor cur)) bod', ty', cs') Ext(BenchE{}) -> error "inferExp: BenchE not handled." @@ -2780,7 +2784,11 @@ fixRANs prg@(Prog defs funs main) = do Nothing -> error $ show v ++ " not found in any datacon args, " ++ show bnd2 Just (dcon, ls) -> do let tys = lookupDataCon ddfs dcon - n = length [ ty | ty <- tys, ty == CursorTy ] + n = length [ ty | ty <- tys, case ty of + CursorTy -> True + CursorArrayTy{} -> True + _ -> False + ] rans = L.take n ls needRANsExp = L.reverse $ L.take n (reverse ls) ran_pairs = M.fromList $ fragileZip rans needRANsExp diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index c2bd34c78..e867e89d2 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -386,6 +386,7 @@ threadRegionsExp ddefs fundefs fnLocArgs renv env2 lfenv rlocs_env wlocs_env pkd case unTy2 argty of -- Indirection or redirection cursor. CursorTy -> [singleLocVar w] + CursorArrayTy{} -> [singleLocVar w] _ -> NewL2.locsInTy argty _ -> NewL2.locsInTy argty ) From 4d8499246a6b0f33c19850c7828bdfded880f817 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 12 Oct 2025 18:19:54 -0400 Subject: [PATCH 39/60] edit bench --- gibbon-compiler/examples/soa_examples/MonoTree.hs | 10 +++++----- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 1a30df5ab..872fcede2 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -18,10 +18,10 @@ add1Tree t = Leaf x -> Leaf (x + 1) Node d x1 x2 -> Node (d + 1) (add1Tree x1) (add1Tree x2) ---rightMost :: Tree -> Int ---rightMost t = case t of --- Leaf x -> x --- Node d x1 x2 -> rightMost x2 +rightMost :: Tree -> Int +rightMost t = case t of + Leaf x -> x + Node d x1 x2 -> rightMost x2 sumTree :: Tree -> Int sumTree tr = @@ -35,7 +35,7 @@ id tree = tree gibbon_main = let tree = id (mkTree 23 0) tree' = iterate (add1Tree tree) - in sumTree tree' + in rightMost tree' main :: IO () main = print gibbon_main diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index 316da03cd..d509e8ff4 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -32,7 +32,7 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = id (mkTree 13) + let tree = id (mkTree 5) tree' = iterate (add1Tree tree) val = sumTree tree' _ = printsym (quote "(sum: ") From 835de89e368da6fb293fc7a9410cbafa06ee0ff5 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Mon, 13 Oct 2025 15:42:52 -0400 Subject: [PATCH 40/60] fix RAN --- .../examples/soa_examples/MonoTree.hs | 6 +++-- gibbon-compiler/examples/soa_examples/list.hs | 6 ++--- gibbon-compiler/examples/soa_examples/tree.hs | 13 ++++----- gibbon-compiler/src/Gibbon/Language.hs | 2 +- .../src/Gibbon/Passes/Cursorize.hs | 20 ++++++++++---- .../src/Gibbon/Passes/InferLocations.hs | 13 ++++++--- .../src/Gibbon/Passes/ThreadRegions2.hs | 27 ++++++++++++++++--- gibbon-rts/Makefile | 4 +-- 8 files changed, 65 insertions(+), 26 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/MonoTree.hs b/gibbon-compiler/examples/soa_examples/MonoTree.hs index 872fcede2..2f27c871e 100644 --- a/gibbon-compiler/examples/soa_examples/MonoTree.hs +++ b/gibbon-compiler/examples/soa_examples/MonoTree.hs @@ -34,8 +34,10 @@ id tree = tree gibbon_main = let tree = id (mkTree 23 0) - tree' = iterate (add1Tree tree) - in rightMost tree' + tree' = (add1Tree tree) + tree'' = (add1Tree tree') + val = iterate (rightMost tree'') + in (sumTree tree'') + val main :: IO () main = print gibbon_main diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 81371a76b..5a5ccdfe4 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -1,6 +1,6 @@ data List = Cons Int List | Nil -{-# ANN type List "Factored" #-} +{-# ANN type List "Linear" #-} mkList :: Int -> List @@ -37,8 +37,8 @@ id :: List -> List id lst = lst gibbon_main = let - lst = id (mkList 10000000) - lst' = iterate (id (add1 lst)) + lst = (mkList 10000000) + lst' = iterate ((add1 lst)) in sumList lst' diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index d509e8ff4..7fd0b1fd9 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -20,7 +20,7 @@ add1Tree t = rightmost :: Tree -> Int rightmost tree = case tree of Leaf i _ -> i - Node _ _ _ _ l r ll rr -> rightmost rr + Node a b c d l r ll rr -> rightmost r sumTree :: Tree -> Int sumTree tr = @@ -32,13 +32,14 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = id (mkTree 5) - tree' = iterate (add1Tree tree) - val = sumTree tree' + let tree = id (mkTree 10) + tree' = (add1Tree tree) + tree'' = id (add1Tree tree') + val = iterate (sumTree tree'') _ = printsym (quote "(sum: ") _ = printint val _ = printsym (quote ", rightmost: ") - rmost = (rightmost tree') + rmost = (rightmost tree'') _ = printint rmost _ = printsym (quote ")\n\n") - in () + in val --printPacked tree'' --rmost --() diff --git a/gibbon-compiler/src/Gibbon/Language.hs b/gibbon-compiler/src/Gibbon/Language.hs index 369446df4..5d5fa2937 100644 --- a/gibbon-compiler/src/Gibbon/Language.hs +++ b/gibbon-compiler/src/Gibbon/Language.hs @@ -581,7 +581,7 @@ sizeOfTy t = SymSetTy -> error "sizeOfTy: SymSetTy not handled." SymHashTy -> error "sizeOfTy: SymHashTy not handled." IntHashTy -> error "sizeOfTy: IntHashTy not handled." - CursorArrayTy{} -> error "sizeOfTy: CursorArrayTy not handled." + CursorArrayTy sz -> Just (8 * sz) MutCursorTy -> error "sizeOfTy: MutCursorTy not handled." -- | Type of the arguments for a primitive operation. diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 104a65641..e26b55733 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -824,10 +824,14 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let ty3_of_field2 :: Ty3 = case (toLocVar a) of Single _ -> CursorTy SoA _ fl -> CursorArrayTy (1 + length fl) - let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) + let tag_inst = case (toLocVar a) of + Single _ -> [(tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var)] + -- in case its an SoA cursor, we mempcpy it. + SoA{} -> [ (tag_cur_var, [], ty3_of_field, Ext $ InitCursor ty3_of_field), + ("_", [], ProdTy [], Ext $ MemCpy tag_cur_var a_var ty3_of_field)] -- should not need to case anymore --let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) - let let_bnd = mkLets $ [tag_inst] -- ++ [cast_inst] + let let_bnd = mkLets $ tag_inst -- ++ [cast_inst] return (let_bnd (VarE tag_cur_var), freeVarToVarEnv) -- All locations are transformed into cursors here. Location arithmetic @@ -1612,6 +1616,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8 * num_curs))) <$> LetE (after_indirection, [], CursorTy, VarE d') <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + -- This is a shortcut pointer. else do LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') <$> LetE (after_indirection, [], CursorTy, VarE d') @@ -1644,12 +1649,17 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- --LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE rnd_var)) LetE ("_", [], ProdTy [], Ext (MemCpy aft_dloc rnd_var rnd_ty)) <$> LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8 * _size))) + -- Vidush : can get rid of after_indirection here. <$> LetE (after_indirection, [], CursorTy, VarE d') <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + -- shortcut pointer else do - LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') - <$> LetE (after_indirection, [], CursorTy, VarE d') - <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + -- LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc rnd') + -- <$> LetE (after_indirection, [], CursorTy, VarE d') + -- <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) + LetE ("_", [], ProdTy [], Ext (MemCpy aft_dloc rnd_var rnd_ty)) + <$> LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8 * _size))) + <$> go2 marker_added fvarenv' d' from_rec_end aft_flocs rst _ -> error $ "Unknown type encounterred while cursorizing DataConE. Type was " ++ show ty diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index 7db9b2346..7cc3ca32a 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -1179,7 +1179,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- both, cursor array and cursorArrty -- are reserved for shortcut pointers CursorTy -> return $ ArgFixed 8 - CursorArrayTy{} -> return $ ArgFixed 8 + CursorArrayTy sz -> return $ ArgFixed (8 * sz) --CursorTy -> return $ ArgFixed 8 IntTy -> return $ ArgFixed 0 --IntTy -> return $ ArgFixed (fromJust $ sizeOfTy IntTy) @@ -1297,6 +1297,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = case arg of (VarE v) -> case lookupVEnv v env of CursorTy -> return $ ArgFixed 8 + CursorArrayTy sz -> return $ ArgFixed (8 * sz) IntTy -> return $ ArgFixed (fromJust $ sizeOfTy IntTy) FloatTy -> return $ ArgFixed (fromJust $ sizeOfTy FloatTy) SymTy -> return $ ArgFixed (fromJust $ sizeOfTy SymTy) @@ -1368,7 +1369,12 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- let after_shorcut_constr = AfterSoAL after_shortcut_soa after_shortcut_all_dcon [] d -- The tag constraint will change to an after constant constraint - let tagc = AfterConstantL (getDconLoc hloc) (8) (last_shortcut) + -- TODO: For NESTED SoA, one approach is to linerize in Cursorize? + let last_shortcut_arg = last shortcut_ptr_dcargs + let last_shortcut_size = case last_shortcut_arg of + ArgFixed sz -> sz + _ -> error "Did not expected anything else than a fixed size argument!" + let tagc = AfterConstantL (getDconLoc hloc) (last_shortcut_size) (last_shortcut) let fieldLocVarsAfter = P.map (\(Just idx) -> let fldloc = lookup (k, idx) (getFieldLocs hloc) in case fldloc of Just location -> Just location @@ -1378,6 +1384,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = case arg of (VarE v) -> case lookupVEnv v env of CursorTy -> return $ ArgFixed 8 + CursorArrayTy sz -> return $ ArgFixed (8 * sz) IntTy -> return $ ArgFixed (fromJust $ sizeOfTy IntTy) FloatTy -> return $ ArgFixed (fromJust $ sizeOfTy FloatTy) SymTy -> return $ ArgFixed (fromJust $ sizeOfTy SymTy) @@ -1897,11 +1904,11 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = return (L2.LetE (vr,[],L2.CursorTy,L2.Ext (L2.AddFixed cur i)) bod', ty', cs') Ext (L1.StartOfPkdCursor cur) -> do - (bod',ty',cs') <- inferExp ddefs (extendVEnv vr CursorTy env) bod dest let bty' = case bty of CursorTy -> L2.CursorTy CursorArrayTy sz -> L2.CursorArrayTy sz _ -> error "InferExp: Did not expect any other type!" + (bod',ty',cs') <- inferExp ddefs (extendVEnv vr bty' env) bod dest return (L2.LetE (vr,[],bty',L2.Ext (L2.StartOfPkdCursor cur)) bod', ty', cs') Ext(BenchE{}) -> error "inferExp: BenchE not handled." diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index e867e89d2..990f38f2e 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -228,7 +228,8 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod -- -- ) $ zip fieldLocs' fieldRegs' -- VS: 1 byte for constructor, 1 byte for redirection, 8 bytes for pointer + 2 to be safe - boundsCheckDcon = [(12, dcRegArg, dcLocArg)] + spaceDcon = boundsCheckDconSoa ddefs (locs_tycons M.! loc) + boundsCheckDcon = [(spaceDcon, dcRegArg, dcLocArg)] boundsCheckFields = concatMap ( \(((dcon, idx), floc), freg) -> @@ -237,9 +238,8 @@ threadRegionsFn ddefs fundefs f@FunDef {funName, funArgs, funTy, funMeta, funBod PackedTy {} -> [] _ -> let size_of_ty = fromJust $ sizeOfTy (unTy2 ty) - -- VS: 1 byte for redirection, 8 for redirection pointer + 2 to be safe - -- Some large offset to be safe - in [(2 * (size_of_ty + 11), (NewL2.EndOfReg freg mode (toEndVRegVar freg)), (NewL2.Loc (LREM floc freg (toEndVRegVar freg) mode)))] + -- VS: 1 byte for redirection, 8 for redirection pointer + size of type + in [((size_of_ty + 9), (NewL2.EndOfReg freg mode (toEndVRegVar freg)), (NewL2.Loc (LREM floc freg (toEndVRegVar freg) mode)))] ) $ zip fieldLocs' fieldRegs' -- end_of_regions = S.fromList $ map (\(_, reg, _) -> case reg of @@ -1214,6 +1214,25 @@ boundsCheck ddefs tycon = in -- Reserve additional space for a redirection node or a forwarding pointer. dbgTrace (minChatLvl) "Print boundsCheck: " dbgTrace (minChatLvl) (sdoc (dcons, vals, tyss)) dbgTrace (minChatLvl) "End boundsCheck.\n" num_bytes + 9 + +boundsCheckDconSoa :: NewL2.DDefs2 -> TyCon -> Int +boundsCheckDconSoa ddefs tycon = + let dcons = getConOrdering ddefs tycon + spaceReqd tys = + foldl (\bytes ty -> + case (unTy2 ty) of + CursorTy -> (bytes + (fromJust $ sizeOfTy (unTy2 ty))) + CursorArrayTy _sz -> (bytes + (fromJust $ sizeOfTy (unTy2 ty))) + PackedTy ty _ -> if ty == tycon + then (bytes + 1) + else (bytes) + _ -> bytes + + ) 0 tys + tyss = map (lookupDataCon ddefs) dcons + num_bytes = 1 + (maximum $ map (spaceReqd) tyss) + in num_bytes + 9 + -- Not making a seperate function for bounds checking an SoA location at the moment. -- For a data constructor region -- it is 1 byte -- For a field region, it is size of field. diff --git a/gibbon-rts/Makefile b/gibbon-rts/Makefile index e487a6f7c..7c5e6c456 100644 --- a/gibbon-rts/Makefile +++ b/gibbon-rts/Makefile @@ -26,8 +26,8 @@ # ====================================================================== -CC := clang -AR := llvm-ar +CC := gcc +AR := gcc-ar CFLAGS := -Wall -Wextra -Wpedantic -Wshadow -std=gnu11 -flto RSC := cargo RSFLAGS := -v From 50d373042cea7f7b1f35607f69452f1c05afe059 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Tue, 14 Oct 2025 17:13:48 -0400 Subject: [PATCH 41/60] wip: Nested SoA regions --- gibbon-compiler/examples/soa_examples/list.hs | 2 +- gibbon-compiler/examples/soa_examples/tree.hs | 4 +- .../src/Gibbon/Passes/Cursorize.hs | 494 ++++++++++-------- 3 files changed, 273 insertions(+), 227 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 5a5ccdfe4..25696a7d6 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -17,7 +17,7 @@ add1 lst = case lst of Nil -> Nil Cons i rst -> let i1 = i + 1 - in Cons i1 (add1 rst) + in Cons i1 (add1 rst) --fieldDep :: List -> (Int, List) diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index 7fd0b1fd9..cd58c5d44 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -3,7 +3,7 @@ module Tree where data Tree = Leaf Int Float | Node Int Int Int Float Tree Tree Tree Tree deriving Show -{-# ANN type Tree "Factored" #-} +{-# ANN type Tree "Linear" #-} mkTree :: Int -> Tree mkTree d = @@ -34,7 +34,7 @@ id tree = tree gibbon_main = let tree = id (mkTree 10) tree' = (add1Tree tree) - tree'' = id (add1Tree tree') + tree'' = iterate (id (add1Tree tree')) val = iterate (sumTree tree'') _ = printsym (quote "(sum: ") _ = printint val diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index e26b55733..0e0285169 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -148,6 +148,108 @@ cursorize Prog {ddefs, fundefs, mainExp} = do mangle :: [Var] -> Var mangle vars = toVar $ "mangle" ++ (L.foldr (\v acc -> acc ++ "_" ++ (fromVar v)) "" vars) +getCursorizeTyFromLocVar :: LocVar -> Ty3 +getCursorizeTyFromLocVar lc = case lc of + Single{} -> CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar :: RegVar -> Ty3 +getCursorizeTyFromRegVar rv = case rv of + SingleR{} -> CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + + +getCursorizeTyFromLocVar' :: LocVar -> Ty2 +getCursorizeTyFromLocVar' lc = case lc of + Single{} -> MkTy2 CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in MkTy2 $ CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar' :: RegVar -> Ty2 +getCursorizeTyFromRegVar' rv = case rv of + SingleR{} -> MkTy2 CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in MkTy2 $ CursorArrayTy (1 + size_flds) + + +getCursorizeTyFromLocVar'' :: LocVar -> UrTy loc +getCursorizeTyFromLocVar'' lc = case lc of + Single{} -> CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar'' :: RegVar -> UrTy loc +getCursorizeTyFromRegVar'' rv = case rv of + SingleR{} -> CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + + +getCursorizeTyFromLocVar''' :: LocVar -> UrTy () +getCursorizeTyFromLocVar''' lc = case lc of + Single{} -> CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar''' :: RegVar -> UrTy () +getCursorizeTyFromRegVar''' rv = case rv of + SingleR{} -> CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + + + + cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do let inLocs = inLocVars funTy @@ -212,9 +314,7 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeFunDef: unexpected location variable" - packed_cursor_ty = case loc of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) + packed_cursor_ty = getCursorizeTyFromLocVar loc in (var_for_loc, [], packed_cursor_ty, proj) ) inLocs @@ -229,14 +329,12 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy l) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeFunDef: unexpected location variable" - packed_cursor_ty = case l of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) - loc_entry = (var_for_loc, MkTy2 packed_cursor_ty) + packed_cursor_ty = getCursorizeTyFromLocVar' l + loc_entry = (var_for_loc, packed_cursor_ty) var_for_reg = case (M.lookup (fromRegVarToFreeVarsTy (toEndVRegVar $ regionToVar r)) freeVarToVarEnv') of Just v -> v Nothing -> error "cursorizeFunDef: unexpected region variable" - reg_entry = (var_for_reg, MkTy2 packed_cursor_ty) + reg_entry = (var_for_reg, packed_cursor_ty) in [loc_entry, reg_entry] ) (locVars funTy) @@ -324,9 +422,7 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f ProdTy ls -> ProdTy $ L.map cursorizeInTy ls SymDictTy ar _ty -> SymDictTy ar CursorTy PDictTy k v -> PDictTy (cursorizeInTy k) (cursorizeInTy v) - PackedTy _ l -> case l of - Single _ -> CursorTy - SoA _ fieldLocs -> CursorArrayTy (1 + (length fieldLocs)) + PackedTy _ l -> getCursorizeTyFromLocVar'' l VectorTy el_ty -> VectorTy $ cursorizeInTy el_ty ListTy el_ty -> ListTy $ cursorizeInTy el_ty PtrTy -> PtrTy @@ -380,9 +476,7 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f outRegs = L.map - ( \r -> case r of - SingleR v -> CursorTy - SoARv dcr frs -> CursorArrayTy (1 + length frs) + ( \r -> getCursorizeTyFromRegVar'' r ) (outRegVars ty) @@ -393,9 +487,7 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f ret_curs = L.map ( \lret -> case lret of - EndOf (LRM l _ _) -> case l of - Single _ -> CursorTy - SoA dcl flocs -> CursorArrayTy (1 + length flocs) + EndOf (LRM l _ _) -> getCursorizeTyFromLocVar'' l ) locRets @@ -422,16 +514,12 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f outCurs = filter (\(LRM _ _ m) -> m == Output) locVars outCurTys = map - ( \(LRM l _ _) -> case l of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) + ( \(LRM l _ _) -> getCursorizeTyFromLocVar'' l ) outCurs inRegs = map - ( \r -> case r of - SingleR _ -> CursorTy - SoARv _ frs -> CursorArrayTy (1 + length frs) + ( \r -> getCursorizeTyFromRegVar'' r ) (inRegVars ty) in_tys = inRegs ++ outRegs ++ outCurTys ++ (map unTy2 arrIns) @@ -818,12 +906,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = tag_cur_var <- gensym "tag_cur" --casted_var <- gensym "cast" - let ty3_of_field = case (toLocVar a) of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case (toLocVar a) of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field = getCursorizeTyFromLocVar'' (toLocVar a) + let ty3_of_field2 = getCursorizeTyFromLocVar (toLocVar a) let tag_inst = case (toLocVar a) of Single _ -> [(tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var)] -- in case its an SoA cursor, we mempcpy it. @@ -838,12 +922,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- is expressed in terms of corresponding cursor operations. -- See `cursorizeLocExp` LetLocE loc rhs bod -> do - let ty2_of_loc = case loc of - Single l -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length fields) - let ty3_of_loc :: Ty3 = case loc of - Single l -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length fields) + let ty2_of_loc = getCursorizeTyFromLocVar'' loc + let ty3_of_loc = getCursorizeTyFromLocVar loc freeVarToVarEnv' <- do case loc of Single l -> @@ -861,7 +941,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Nothing -> case loc of Single lvarrr -> lvarrr SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - let rhs_either = cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs + rhs_either <- cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs let (bnds, tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of Nothing -> ([], tenv) Just vs -> @@ -907,9 +987,7 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetRegionE reg sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False reg sz let reg_var = regionToVar reg - let reg_ty = case reg_var of - SingleR {} -> MkTy2 CursorTy - SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) + let reg_ty = getCursorizeTyFromRegVar' reg_var reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of Just var -> return var @@ -1044,12 +1122,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) -- In case we unpack single regions, we make them mutable since they may -- be updated by bounds check. - let ty_of_loc = case loc of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - let ty2_of_loc :: Ty2 = case loc of - SingleR _ -> MkTy2 CursorTy - SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) + let ty_of_loc = getCursorizeTyFromRegVar'' loc + let ty2_of_loc :: Ty2 = getCursorizeTyFromRegVar' loc freeVarToVarEnv' <- do case loc of SingleR l -> @@ -1065,8 +1139,8 @@ cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else do name <- gensym "cursor_ptr" return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv - let rhs_either = cursorizeRegExp freeVarToVarEnv' denv tenv senv loc rhs - (bnds, tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of + rhs_either <- cursorizeRegExp freeVarToVarEnv' denv tenv senv loc rhs + let (bnds, tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of Nothing -> ([], tenv) Just vs -> let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] @@ -1492,7 +1566,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) aft_flocs let makeCurArr = Ext $ MakeCursorArray (1 + length (aft_flocs)) ([aft_dloc] ++ after_flocs_to_vars) - let let_mk_cur_arr = LetE (after_soa_loc, [], CursorArrayTy (1 + length (aft_flocs)), makeCurArr) + let let_mk_cur_arr = LetE (after_soa_loc, [], getCursorizeTyFromLocVar (SoA "" aft_flocs), makeCurArr) end_scalars_alloc <- gensym "end_scalars_alloc" return ( let_mk_cur_arr $ @@ -1509,9 +1583,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = d' <- gensym "writecur" case ty of PackedTy _ l -> do - let cur_ty = case l of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) + let cur_ty = getCursorizeTyFromLocVar l (rnd', fvarenv') <- go fvarenv tenv senv rnd end_scalars_alloc <- gensym "end_scalars_alloc" ( if not marker_added @@ -1599,21 +1671,19 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let rnd_var = case rnd' of VarE v -> v _ -> error "Did not expected variable!" - let (rnd_ty, num_curs) = case M.lookup rnd_var tenv of + let rnd_ty = case M.lookup rnd_var tenv of Nothing -> error "Expected type for variable!\n" Just ty -> case unTy2 ty of PackedTy _ l -> do - case l of - Single _ -> (CursorTy, 1) - SoA _ fields -> (CursorArrayTy (1 + length (fields)), ((1 + length (fields)))) - CursorArrayTy sz -> (CursorArrayTy sz, sz) - _ -> (CursorTy, 1) + getCursorizeTyFromLocVar'' l + CursorArrayTy sz -> CursorArrayTy sz + _ -> CursorTy if isIndirectionTag dcon then do --LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> -- --LetE (d', [], CursorTy, Ext $ WriteTaggedCursor aft_dloc (VarE rnd_var)) LetE ("_", [], ProdTy [], Ext (MemCpy aft_dloc rnd_var rnd_ty)) <$> - LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8 * num_curs))) + LetE (d', [], CursorTy, Ext $ AddCursor aft_dloc (LitE (8))) <$> LetE (after_indirection, [], CursorTy, VarE d') <$> go2 marker_added fvarenv' after_indirection from_rec_end aft_flocs rst -- Ext $ AddCursor aft_dloc (L3.LitE 8) -- This is a shortcut pointer. @@ -1634,15 +1704,15 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let rnd_var = case rnd' of VarE v -> v _ -> error "Did not expected variable!" - let (rnd_ty, num_curs) = case M.lookup rnd_var tenv of + let rnd_ty = case M.lookup rnd_var tenv of Nothing -> error "Expected type for variable!\n" Just ty -> case unTy2 ty of PackedTy _ l -> do case l of - Single _ -> (CursorTy, 1) - SoA _ fields -> (CursorArrayTy (1 + length (fields)), ((1 + length (fields)))) - CursorArrayTy sz -> (CursorArrayTy sz, sz) - _ -> (CursorTy, 1) + Single _ -> getCursorizeTyFromLocVar l + SoA _ fields -> getCursorizeTyFromLocVar l + CursorArrayTy sz -> CursorArrayTy sz + _ -> CursorTy if isIndirectionTag dcon then do --LetE (casted_var, [], CursorTy, Ext $ CastPtr rnd_var CursorTy) <$> @@ -1759,8 +1829,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else do name <- gensym "cursor_ptr" return $ M.insert (fromLocVarToFreeVarsTy loc) name freeVarToVarEnv - let rhs_either = dbgTrace (minChatLvl) "Print env" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv')) dbgTrace (minChatLvl) "End env cursorize\n" cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs - (bnds, tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of + rhs_either <- dbgTrace (minChatLvl) "Print env" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv')) dbgTrace (minChatLvl) "End env cursorize\n" cursorizeLocExp freeVarToVarEnv' denv tenv senv loc rhs + let (bnds, tenv') = case M.lookup (fromLocVarToFreeVarsTy loc) denv of Nothing -> ([], tenv) Just vs -> let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] @@ -1773,26 +1843,22 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Nothing -> case loc of Single lvarrr -> lvarrr SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" - let locs_ty3 :: Ty3 = case loc of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) - let locs_ty2 = case loc of - Single _ -> CursorTy - SoA _ fields -> CursorArrayTy (1 + length (fields)) + let locs_ty3 :: Ty3 = getCursorizeTyFromLocVar loc + let locs_ty2 = getCursorizeTyFromLocVar' loc case rhs of FromEndLE {} -> if isBound locs_var tenv - then go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod + then go freeVarToVarEnv' (M.insert locs_var locs_ty2 tenv''') senv' bod -- Discharge bindings that were waiting on 'loc'. else do - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv') senv' bod + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var locs_ty2 tenv') senv' bod return (onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) bod', freeVarToVarEnv'') -- Discharge bindings that were waiting on 'loc'. _ -> do - (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var (MkTy2 locs_ty2) tenv''') senv' bod + (bod', freeVarToVarEnv'') <- go freeVarToVarEnv' (M.insert locs_var locs_ty2 tenv''') senv' bod return (onDi (mkLets (bnds' ++ [(locs_var, [], locs_ty3, rhs')] ++ bnds)) bod', freeVarToVarEnv'') Left denv' -> do @@ -1806,12 +1872,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- let ty_of_loc = case loc of -- SingleR _ -> CursorTy -- SoARv _ flds -> CursorArrayTy (1 + length flds) - let ty_of_loc = case loc of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) - let ty2_of_loc :: Ty2 = case loc of - SingleR _ -> MkTy2 CursorTy - SoARv _ flds -> MkTy2 $ CursorArrayTy (1 + length flds) + let ty_of_loc = getCursorizeTyFromRegVar loc + let ty2_of_loc :: Ty2 = getCursorizeTyFromRegVar' loc freeVarToVarEnv' <- do case loc of SingleR l -> @@ -1826,8 +1888,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = else do name <- gensym "cursor_ptr" return $ M.insert (fromRegVarToFreeVarsTy loc) name freeVarToVarEnv - let rhs_either = cursorizeRegExp freeVarToVarEnv' denv tenv senv loc rhs - (bnds, tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of + rhs_either <- cursorizeRegExp freeVarToVarEnv' denv tenv senv loc rhs + let (bnds, tenv') = case M.lookup (fromRegVarToFreeVarsTy loc) denv of Nothing -> ([], tenv) Just vs -> let extended = M.fromList [(v, MkTy2 CursorTy) | (v, _, CursorTy, _) <- vs] @@ -1872,12 +1934,8 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = SoA _ _ -> error "cursorizeExp: LetLocE: unexpected location variable" tag_cur_var <- gensym "tag_cur" casted_var <- gensym "cast" - let ty3_of_field = case (toLocVar a) of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case (toLocVar a) of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field = getCursorizeTyFromLocVar (toLocVar a) + let ty3_of_field2 :: Ty3 = getCursorizeTyFromLocVar'' (toLocVar a) let tag_inst = (tag_cur_var, [], ty3_of_field, Ext $ L3.TagCursor a_var b_var) let cast_inst = (casted_var, [], CursorTy, Ext $ CastPtr tag_cur_var CursorTy) let let_bnd = mkLets $ [tag_inst] ++ [cast_inst] @@ -1919,9 +1977,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = LetRegionE r sz _ bod -> do (region_lets, freeVarToVarEnv') <- regionToBinds freeVarToVarEnv False r sz let reg_var = regionToVar r - let reg_ty = case reg_var of - SingleR {} -> MkTy2 CursorTy - SoARv _ flr -> MkTy2 $ CursorArrayTy (1 + length flr) + let reg_ty = getCursorizeTyFromRegVar' reg_var reg_var_name <- case (M.lookup (fromRegVarToFreeVarsTy reg_var) freeVarToVarEnv') of Just var -> return var @@ -2136,6 +2192,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let start_vars = map fst range_s let end_vars = map snd range_s -- TODO change cursor array ty size + -- TODO Fix , the size of CursorArrayTy needs to change here. let let_start_soa = (start_soa, [], CursorArrayTy (L.length start_vars), Ext (MakeCursorArray (L.length start_vars) start_vars)) let let_end_soa = (end_soa, [], CursorArrayTy (L.length end_vars), Ext (MakeCursorArray (L.length end_vars) end_vars)) let end_prod = MkProdE [VarE start_soa, VarE end_soa] @@ -2201,7 +2258,7 @@ cursorizeReadPackedFile freeVarToVarEnv lenv ddfs fundefs denv tenv senv isPacke -- -- i.e `loc_a` may not always be bound. If that's the case, don't process `loc_b` -- now. Instead, add it to the dependency environment. -cursorizeLocExp :: M.Map FreeVarsTy Var -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> LocVar -> LocExp -> Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv) +cursorizeLocExp :: M.Map FreeVarsTy Var -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> LocVar -> LocExp -> PassM (Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv)) cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = case locExp of AfterConstantLE i loc -> @@ -2213,8 +2270,8 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = Just v -> v Nothing -> error $ "cursorizeLocExp: AfterConstantLE: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show lvar) ++ ")" ++ show freeVarToVarEnv in if isBound locs_var tenv - then Right (rhs, [], tenv, senv) - else Left $ M.insertWith (++) ((fromLocVarToFreeVarsTy . toLocVar) loc) [(lvar_to_name, [], CursorTy, rhs)] denv + then pure $ Right (rhs, [], tenv, senv) + else pure $ Left $ M.insertWith (++) ((fromLocVarToFreeVarsTy . toLocVar) loc) [(lvar_to_name, [], CursorTy, rhs)] denv -- TODO: handle product types here {- [2018.03.07]: @@ -2274,17 +2331,17 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = if isBound locs_var tenv then if was_stolen - then Right (bod, [], tenv, senv) + then pure $ Right (bod, [], tenv, senv) -- The continuation was not stolen. It's safe to discharge all -- pending bindings of this particular variable. else do case M.lookup v senv of - Nothing -> Right (bod, [], tenv, senv) + Nothing -> pure $ Right (bod, [], tenv, senv) Just pending_bnds -> do let tenv' = foldr (\(v1, _, _, ty2, _) env -> M.insert v1 ty2 env) tenv pending_bnds bnds = map (\(a, b, c, _, e) -> (a, b, c, e)) pending_bnds - Right (bod, bnds, tenv', M.delete v senv) - else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name, [], CursorTy, bod)] denv + pure $ Right (bod, bnds, tenv', M.delete v senv) + else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name, [], CursorTy, bod)] denv FromEndLE locarg -> let loc = toLocVar locarg locs_var = case (M.lookup (fromLocVarToFreeVarsTy loc) freeVarToVarEnv) of @@ -2294,21 +2351,21 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = Just v -> v Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv in if isBound locs_var tenv - then Right (VarE locs_var, [], tenv, senv) - else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name, [], CursorTy, VarE locs_var)] denv + then pure $ Right (VarE locs_var, [], tenv, senv) + else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc) [(lvar_name, [], CursorTy, VarE locs_var)] denv StartOfRegionLE r -> case r of - GlobR v _ -> Right (VarE v, [], tenv, senv) - VarR v -> Right (VarE v, [], tenv, senv) - DynR v _ -> Right (VarE v, [], tenv, senv) + GlobR v _ -> pure $ Right (VarE v, [], tenv, senv) + VarR v -> pure $ Right (VarE v, [], tenv, senv) + DynR v _ -> pure $ Right (VarE v, [], tenv, senv) -- TODO: docs - MMapR _v -> Left denv + MMapR _v -> pure $ Left denv {- VS: TODO: This needs to be fixed. There should be an env. for tracking complex regions liks SoA regs-} SoAR dr fregs -> let regions_var = case (M.lookup (fromRegVarToFreeVarsTy (regionToVar r)) freeVarToVarEnv) of Just v -> v Nothing -> error "cursorizeLocExp: StartOfRegionLE: unexpected location variable" - in Right (VarE (regions_var), [], tenv, senv) - FreeLE -> Left denv -- AUDIT: should we just throw away this information? + in pure $ Right (VarE (regions_var), [], tenv, senv) + FreeLE -> pure $ Left denv -- AUDIT: should we just throw away this information? InRegionLE {} -> error $ "cursorizeExp: TODO InRegionLE" GetDataConLocSoA loc -> {- VS: TODO: instead of using unwrap loc var, we should keep an env mapping a SoA loc to a L3 variable -} @@ -2321,9 +2378,9 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv rhs = Ext $ IndexCursorArray loc_var 0 in if isBound loc_var tenv - then Right (rhs, [], tenv, senv) + then pure $ Right (rhs, [], tenv, senv) -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) - else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_logarg) [(lvar_name, [], CursorTy, rhs)] denv + else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_logarg) [(lvar_name, [], CursorTy, rhs)] denv GetFieldLocSoA i loc -> {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let loc_from_locarg = toLocVar loc @@ -2343,25 +2400,43 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -}) in if isBound loc_var tenv - then Right (rhs, [], tenv, senv) - else Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_locarg) [(lvar_name, [], CursorTy, rhs)] denv - GenSoALoc dloc flocs -> + then pure $ Right (rhs, [], tenv, senv) + else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_locarg) [(lvar_name, [], CursorTy, rhs)] denv + GenSoALoc dloc flocs -> do {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let dcloc_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar dloc)) freeVarToVarEnv) of Just v -> v Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected data constructor location variable" - field_vars = - map - ( \(_, loc) -> case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" - ) + res <- + mapM + (\(_, loc) -> case (toLocVar loc) of + Single{} -> case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of + Just v -> pure $ [(v, [])] + Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" + -- Here we need to generate indexing operations from the variable + -- There shouldn't be any recursion, since we fully linearized the data type + SoA{} -> let var_for_loc = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar loc)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" + loc_ty = getCursorizeTyFromLocVar (toLocVar loc) + in case loc_ty of + CursorTy -> pure $ [(var_for_loc, [])] + CursorArrayTy sz -> do + indexing_inst <- foldlM (\new_names i -> do + new_var <- gensym "unpack" + return $ new_names ++ [ (new_var, [(new_var, [], CursorTy, (Ext (IndexCursorArray var_for_loc i)))] ) ] + ) [] [0..(sz - 1)] + pure $ indexing_inst + ) flocs - rhs = Ext $ MakeCursorArray (1 + length flocs) ([dcloc_var] ++ field_vars) - in dbgTrace (minChatLvl) "Print freeVarEnv GenSoALoc:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" Right (rhs, [], tenv, senv) + let res' = concatMap (\r -> r) res + let field_vars = map fst res' + let new_insts = concatMap snd res' + let rhs = Ext $ MakeCursorArray (1 + length field_vars) ([dcloc_var] ++ field_vars) + dbgTrace (minChatLvl) "Print freeVarEnv GenSoALoc:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" return $ Right (rhs, new_insts, tenv, senv) _ -> error $ "cursorizeLocExp: Unexpected locExp: " ++ sdoc locExp -cursorizeRegExp :: M.Map FreeVarsTy Var -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> RegVar -> RegExp -> Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv) +cursorizeRegExp :: M.Map FreeVarsTy Var -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> RegVar -> RegExp -> PassM (Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv)) cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = case regExp of GetDataConRegSoA loc -> @@ -2375,10 +2450,10 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = Just v -> v Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv in if isBound reg_var tenv - then Right (rhs, [], tenv, senv) + then pure $ Right (rhs, [], tenv, senv) -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) -- VS: Hack: We always want to get a reference to the region. - else Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], MutCursorTy, rhs)] denv + else pure $ Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], CursorTy, rhs)] denv GetFieldRegSoA i loc -> {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let loc_from_locarg = toLocVar loc @@ -2399,22 +2474,40 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -}) in if isBound loc_var tenv - then Right (rhs, [], tenv, senv) - else Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], MutCursorTy, rhs)] denv - GenSoAReg dloc flocs -> + then pure $ Right (rhs, [], tenv, senv) + else pure $ Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], CursorTy, rhs)] denv + GenSoAReg dloc flocs -> do {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let dcloc_var = case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar dloc)) freeVarToVarEnv) of Just v -> v Nothing -> error "cursorizeRegExp: GenSoAReg: unexpected data constructor location variable" - field_vars = - map - ( \(_, loc) -> case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar loc)) freeVarToVarEnv) of - Just v -> v - Nothing -> error "cursorizeRegExp: GenSoAReg: unexpected field location variable" - ) + res <- + mapM + (\(_, loc) -> case (fromLocVarToRegVar $ toLocVar loc) of + SingleR{} -> case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar loc)) freeVarToVarEnv) of + Just v -> pure $ [(v, [])] + Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" + -- Here we need to generate indexing operations from the variable + -- There shouldn't be any recursion, since we fully linearized the data type + SoARv{} -> let var_for_loc = case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar loc)) freeVarToVarEnv) of + Just v -> v + Nothing -> error "cursorizeLocExp: GenSoALoc: unexpected field location variable" + loc_ty = getCursorizeTyFromRegVar (fromLocVarToRegVar $ toLocVar loc) + in case loc_ty of + CursorTy -> pure $ [(var_for_loc, [])] + CursorArrayTy sz -> do + indexing_inst <- foldlM (\new_names i -> do + new_var <- gensym "unpack" + return $ new_names ++ [ (new_var, [(new_var, [], CursorTy, (Ext (IndexCursorArray var_for_loc i)))] ) ] + ) [] [0..(sz - 1)] + pure $ indexing_inst + ) flocs - rhs = Ext $ MakeCursorArray (1 + length flocs) ([dcloc_var] ++ field_vars) - in dbgTrace (minChatLvl) "Print freeVarEnv GenSoAReg:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" Right (rhs, [], tenv, senv) + let res' = concatMap (\r -> r) res + let field_vars = map fst res' + let new_insts = concatMap snd res' + rhs = Ext $ MakeCursorArray (1 + length field_vars) ([dcloc_var] ++ field_vars) + in dbgTrace (minChatLvl) "Print freeVarEnv GenSoAReg:" dbgTrace (minChatLvl) (sdoc (freeVarToVarEnv)) dbgTrace (minChatLvl) "End freeVarEnv\n" pure $ Right (rhs, new_insts, tenv, senv) findSoAParent :: FreeVarsTy -> M.Map FreeVarsTy Var -> Maybe FreeVarsTy @@ -2489,6 +2582,7 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Just v -> return (acc, acc') Nothing -> case loc_var of R r -> case r of + {-Vidush: TODO, the type of this needs to change -} SingleR v -> return $ (M.insert loc_var v acc, acc') SoARv dconReg fieldRegions -> do -- let us try to find if the SoA region belongs to any other SoA region in the environment. @@ -2499,7 +2593,7 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Just v -> v Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding parent region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc name <- gensym "cursor_reg_ptr" - let instrs = [LetE (name, [], CursorArrayTy (1 + length fieldRegions), Ext $ IndexCursorArray (name_par_reg) 1)] + let instrs = [LetE (name, [], getCursorizeTyFromRegVar r, Ext $ IndexCursorArray (name_par_reg) 1)] return $ (M.insert loc_var name acc, acc' ++ instrs) Nothing -> do (dconReg_var, dcon_insts) <- case (M.lookup (fromRegVarToFreeVarsTy dconReg) acc) of @@ -2528,7 +2622,7 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = ) fieldRegions name <- gensym "cursor_reg_ptr" - let instrs = dcon_insts ++ [LetE (name, [], CursorArrayTy (1 + length fieldReg_vars), Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] + let instrs = dcon_insts ++ [LetE (name, [], getCursorizeTyFromRegVar r, Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] dbgTrace (minChatLvl) "Print Reg: " dbgTrace (minChatLvl) (sdoc (f, dconReg, fieldRegions)) dbgTrace (minChatLvl) "End soa Reg\n" return $ (M.insert loc_var name acc, acc' ++ instrs) pure ret @@ -2897,13 +2991,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \loc -> let free_var = fromLocArgToFreeVarsTy loc cursorType = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) + R r -> getCursorizeTyFromRegVar'' r V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) + FL l -> getCursorizeTyFromLocVar'' l in cursorType ) locs @@ -2912,13 +3002,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \loc -> let free_var = fromLocArgToFreeVarsTy loc cursorType :: Ty3 = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) + R r -> getCursorizeTyFromRegVar'' r V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) + FL l -> getCursorizeTyFromLocVar'' l in cursorType ) locs @@ -2980,13 +3066,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \loc -> let free_var = fromLocArgToFreeVarsTy loc cursorType = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) + R r -> getCursorizeTyFromRegVar'' r V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) + FL l -> getCursorizeTyFromLocVar'' l in cursorType ) locs @@ -2995,13 +3077,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \loc -> let free_var = fromLocArgToFreeVarsTy loc cursorType :: Ty3 = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) + R r -> getCursorizeTyFromRegVar'' r V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) + FL l -> getCursorizeTyFromLocVar'' l in cursorType ) locs @@ -3085,13 +3163,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \loc -> let free_var = fromLocArgToFreeVarsTy loc cursorType = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) + R r -> getCursorizeTyFromRegVar'' r V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) + FL l -> getCursorizeTyFromLocVar'' l in cursorType ) locs @@ -3100,13 +3174,9 @@ cursorizeLet freeVarToVarEnv lenv isPackedContext ddfs fundefs denv tenv senv (v ( \loc -> let free_var = fromLocArgToFreeVarsTy loc cursorType :: Ty3 = case free_var of - R r -> case r of - SingleR _ -> CursorTy - SoARv _ flds -> CursorArrayTy (1 + length flds) + R r -> getCursorizeTyFromRegVar'' r V _ -> error "cursorizeLet: did not expect a variable in locations in a LetE." - FL l -> case l of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + length flds) + FL l -> getCursorizeTyFromLocVar'' l in cursorType ) locs @@ -3235,9 +3305,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let idx_elem = fromJust $ L.elemIndex (key, loc) (getAllFieldLocsSoA scrut_loc) field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 - let field_cursor_ty = case loc of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + L.length (flds)) + let field_cursor_ty = getCursorizeTyFromLocVar loc let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1 + idx_elem))] let curr_window = [((dcon', idx), field_var)] return (acc1 ++ field_let, acc2 ++ curr_window, acc3') @@ -3289,9 +3357,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let idx_elem = fromJust $ L.elemIndex (key, loc) (getAllFieldLocsSoA scrut_loc) field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 - let field_cursor_ty = case loc of - Single _ -> CursorTy - SoA _ flds -> CursorArrayTy (1 + L.length (flds)) + let field_cursor_ty = getCursorizeTyFromLocVar loc let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1 + idx_elem))] let curr_window = [((dcon', idx), field_var)] return (acc1 ++ field_let, acc2 ++ curr_window, acc3') @@ -3606,6 +3672,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ) (0, []) _field_cur + -- Vidush : TODO this needs to change since type changed soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = M.union @@ -3627,12 +3694,10 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tmp <- gensym "readcursor_indir" loc_var <- lookupVariable loc fenv let locs_ty = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + FL l -> getCursorizeTyFromLocVar' l _ -> error "Expected location!" let locs_ty3 :: Ty3 = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) + FL l -> getCursorizeTyFromLocVar l _ -> error "Expected location!" -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur @@ -3641,8 +3706,8 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack M.union ( M.fromList [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - ((loc_var), MkTy2 locs_ty), - (v, MkTy2 locs_ty) + ((loc_var), locs_ty), + (v, locs_ty) -- (toEndV v, MkTy2 CursorTy), -- (toTagV v, MkTy2 IntTy), -- (toEndFromTaggedV v, MkTy2 CursorTy) @@ -3834,13 +3899,9 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tmp <- gensym "readcursor_indir" loc_var <- lookupVariable loc fenv let locs_ty = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) - _ -> error "Expected location!" + FL l -> getCursorizeTyFromLocVar' l let locs_ty3 :: Ty3 = case (loc) of - FL (Single _) -> CursorTy - FL (SoA _ flds) -> CursorArrayTy (1 + length (flds)) - _ -> error "Expected location!" + FL l -> getCursorizeTyFromLocVar l -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur var_dcon_next <- gensym "dcon_next" @@ -3848,8 +3909,8 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack M.union ( M.fromList [ (tmp, MkTy2 (ProdTy [CursorTy, CursorTy, IntTy])), - ((loc_var), MkTy2 locs_ty), - (v, MkTy2 locs_ty) + ((loc_var), locs_ty), + (v, locs_ty) -- (toEndV v, MkTy2 CursorTy), -- (toTagV v, MkTy2 IntTy), -- (toEndFromTaggedV v, MkTy2 CursorTy) @@ -4023,23 +4084,20 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let isSameTycon = if (elem dcon datacons) then True else False case isSameTycon of True -> do - let ty3_of_field = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let ty3_of_field = getCursorizeTyFromLocVar' ploc + let ty3_of_field2 :: Ty3 = getCursorizeTyFromLocVar ploc + let tenv' = M.insert v ( ty3_of_field) tenv let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) field_cur let cur = dcur loc_var <- lookupVariable loc fenv if canBind then do - let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' + let tenv'' = M.insert (loc_var) ( ty3_of_field) tenv' -- Flip canBind to indicate that the subsequent fields -- should be added to the dependency environment. dcon_next <- gensym $ toVar $ (fromVar dcur) ++ "_next" + -- Vidush: TODO: things need to change here since the type in Cursorize Ty needs to change let end_fields = map (\(key, varr) -> varr) _field_cur let makeCurArr = Ext $ MakeCursorArray (1 + length (end_fields)) ([dcon_next] ++ end_fields) let let_mk_cur_arr = (loc_var, [], CursorArrayTy (1 + length (end_fields)), makeCurArr) @@ -4054,20 +4112,16 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let denv' = M.insertWith (++) (loc) [(v, [], ty3_of_field2, VarE (loc_var))] denv go curw fenv rst_vlocs rst_tys False denv' tenv' -- (toEndV v) False -> do - let ty3_of_field = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let ty3_of_field = getCursorizeTyFromLocVar' ploc + let ty3_of_field2 :: Ty3 = getCursorizeTyFromLocVar ploc + let tenv' = M.insert v (ty3_of_field) tenv let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur -- let cur = dcur loc_var <- lookupVariable loc fenv if canBind then do - let tenv'' = M.insert (loc_var) (MkTy2 ty3_of_field) tenv' + let tenv'' = M.insert (loc_var) ( ty3_of_field) tenv' -- Flip canBind to indicate that the subsequent fields -- should be added to the dependency environment. bod <- go curw fenv rst_vlocs rst_tys False denv tenv'' -- (toEndV v) @@ -4476,21 +4530,17 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- availabe in data con buffer -- we could also take ran pointer to it True -> do - let ty3_of_field = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field = getCursorizeTyFromLocVar' ploc + let ty3_of_field2 :: Ty3 = getCursorizeTyFromLocVar ploc - let tenv' = M.insert v (MkTy2 ty3_of_field) tenv + let tenv' = M.insert v (ty3_of_field) tenv let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 let cur = dcur_end let tenv'' = M.union ( M.fromList - [ (locs_var, MkTy2 ty3_of_field), - (v, MkTy2 ty3_of_field) + [ (locs_var, ty3_of_field), + (v, ty3_of_field) ] ) tenv' @@ -4517,19 +4567,15 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack return $ mkLets dcon_nxt bod -- VS: TODO: needs to be fixed when packed type is not self recursive. False -> do - let ty3_of_field = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) - let ty3_of_field2 :: Ty3 = case ploc of - Single _ -> CursorTy - SoA _ fl -> CursorArrayTy (1 + length fl) + let ty3_of_field = getCursorizeTyFromLocVar' ploc + let ty3_of_field2 :: Ty3 = getCursorizeTyFromLocVar ploc let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur let tenv' = M.union ( M.fromList - [ (locs_var, MkTy2 ty3_of_field), - (v, MkTy2 ty3_of_field) + [ (locs_var, ty3_of_field), + (v, ty3_of_field) ] ) tenv From 62bf9fede82457dfaa40ccd4bca6f705655d959d Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Wed, 15 Oct 2025 00:01:29 -0400 Subject: [PATCH 42/60] wip fixing nested regions --- .../examples/soa_examples/packedTree.hs | 2 +- .../src/Gibbon/Passes/Cursorize.hs | 54 ++++++++++++++----- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index 1d467b2d7..bdbf1f840 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -1,7 +1,7 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf - +{-# ANN type Tree "Factored" #-} mkList :: Int -> List mkList len = if len <= 0 diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 0e0285169..3cc5be6de 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -27,6 +27,7 @@ import qualified Gibbon.L3.Syntax as L3 import Gibbon.NewL2.Syntax import Gibbon.Passes.AddRAN (numRANsDataCon) import Text.PrettyPrint.GenericPretty +import Safe (fromJustDef) {- @@ -1769,14 +1770,14 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = (additional_bnds', freeVarToVarEnv'', _) <- foldlM ( \(b, env, idx') ((_, _), loc) -> do - (var_for_loc, present', env') <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of - Just v -> return $ (v, True, env) + (var_for_loc, present', env', bnds) <- case (M.lookup (fromLocVarToFreeVarsTy loc) env) of + Just v -> return $ (v, True, env, []) Nothing -> case loc of - Single l -> return $ (l, False, env) + Single l -> return $ (l, False, env, []) SoA {} -> do new_name <- gensym "field_cursor" let env'' = M.insert (fromLocVarToFreeVarsTy loc) new_name env - return $ (new_name, False, env'') + return $ (new_name, False, env'', []) let b' = if present' then b @@ -2381,7 +2382,7 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = then pure $ Right (rhs, [], tenv, senv) -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_logarg) [(lvar_name, [], CursorTy, rhs)] denv - GetFieldLocSoA i loc -> + GetFieldLocSoA i loc -> do {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let loc_from_locarg = toLocVar loc field_locs = getAllFieldLocsSoA loc_from_locarg @@ -2398,10 +2399,22 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = lvar_name = case (M.lookup (fromLocVarToFreeVarsTy lvar) freeVarToVarEnv) of Just v -> v Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv - rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -}) - in if isBound loc_var tenv - then pure $ Right (rhs, [], tenv, senv) - else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_locarg) [(lvar_name, [], CursorTy, rhs)] denv + (rhs, additional_lets) <- case field_loc of + Single{} -> return $ (Ext $ IndexCursorArray loc_var (1 + elem_idx), []) + SoA _ fregs -> do + let CursorArrayTy sz = getCursorizeTyFromLocVar field_loc + let start = L.elemIndex (i, field_loc) field_locs + let start_val = fromJustDef (-1) start + res <- foldlM (\bnds i -> do + new_var <- gensym "unpack_loc" + return $ bnds ++ [ (new_var, (new_var, [], CursorTy, Ext $ IndexCursorArray loc_var i)) ] + ) [] [(start_val + 1)..(start_val + sz)] + let vars = map fst res + let bnds = map snd res + return $ (Ext $ MakeCursorArray (length vars) vars, bnds) + if isBound loc_var tenv + then pure $ Right (rhs, additional_lets, tenv, senv) + else pure $ Left $ M.insertWith (++) (fromLocVarToFreeVarsTy loc_from_locarg) (additional_lets ++ [(lvar_name, [], CursorTy, rhs)]) denv GenSoALoc dloc flocs -> do {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let dcloc_var = case (M.lookup (fromLocVarToFreeVarsTy (toLocVar dloc)) freeVarToVarEnv) of @@ -2454,7 +2467,7 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = -- CursorArrayTy (1 + length (getAllFieldLocsSoA loc_from_logarg)) -- VS: Hack: We always want to get a reference to the region. else pure $ Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], CursorTy, rhs)] denv - GetFieldRegSoA i loc -> + GetFieldRegSoA i loc -> do {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let loc_from_locarg = toLocVar loc field_locs = getAllFieldLocsSoA loc_from_locarg @@ -2472,10 +2485,23 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = lvar_name = case (M.lookup (fromRegVarToFreeVarsTy lvar) freeVarToVarEnv) of Just v -> v Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv - rhs = Ext $ IndexCursorArray loc_var (1 + elem_idx {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -}) - in if isBound loc_var tenv - then pure $ Right (rhs, [], tenv, senv) - else pure $ Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) [(lvar_name, [], CursorTy, rhs)] denv + -- {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -} + (rhs, additional_lets) <- case field_loc of + Single{} -> return $ (Ext $ IndexCursorArray loc_var (1 + elem_idx), []) + SoA _ fregs -> do + let CursorArrayTy sz = getCursorizeTyFromLocVar field_loc + let start = L.elemIndex (i, field_loc) field_locs + let start_val = fromJustDef (-1) start + res <- foldlM (\bnds i -> do + new_var <- gensym "unpack_loc" + return $ bnds ++ [ (new_var, (new_var, [], CursorTy, Ext $ IndexCursorArray loc_var i)) ] + ) [] [(start_val + 1)..(start_val + sz)] + let vars = map fst res + let bnds = map snd res + return $ (Ext $ MakeCursorArray (length vars) vars, bnds) + if isBound loc_var tenv + then pure $ Right (rhs, additional_lets, tenv, senv) + else pure $ Left $ M.insertWith (++) (fromRegVarToFreeVarsTy reg_from_loc) (additional_lets ++ [(lvar_name, [], CursorTy, rhs)]) denv GenSoAReg dloc flocs -> do {- VS: TODO: don't use unwrap loc var and keep an env mapping loc to its variable name in the program -} let dcloc_var = case (M.lookup (fromRegVarToFreeVarsTy (fromLocVarToRegVar $ toLocVar dloc)) freeVarToVarEnv) of From 98700ab4075338187a0449baa6aa6a16919d9e34 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Wed, 15 Oct 2025 00:07:09 -0400 Subject: [PATCH 43/60] wip --- gibbon-compiler/src/Gibbon/Passes/Cursorize.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 3cc5be6de..4d2444630 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -500,9 +500,7 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f -- Packed types in the output then become end-cursors for those same destinations. newOut = mapPacked - ( \var loc -> case loc of - Single _ -> ProdTy [CursorTy, CursorTy] - SoA _ fields -> ProdTy [CursorArrayTy (1 + length fields), CursorArrayTy (1 + length fields)] + ( \var loc -> ProdTy [getCursorizeTyFromLocVar'' loc, getCursorizeTyFromLocVar'' loc] ) out_ty From cceed08e04f488db2bd6b8c153d544900a79522e Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 16 Oct 2025 01:11:10 -0400 Subject: [PATCH 44/60] edits --- gibbon-compiler/src/Gibbon/L3/Syntax.hs | 127 +++++++++++++++- .../src/Gibbon/Passes/Cursorize.hs | 142 ++++-------------- 2 files changed, 153 insertions(+), 116 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index 157867b84..fb848e829 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -14,7 +14,15 @@ module Gibbon.L3.Syntax -- * Functions , eraseLocMarkers, mapMExprs, cursorizeTy, toL3Prim, updateAvailVars - + , getCursorizeTyFromLocVar + , getCursorizeTyFromLocVar' + , getCursorizeTyFromLocVar'' + , getCursorizeTyFromLocVar''' + , getCursorizeTyFromRegVar + , getCursorizeTyFromRegVar' + , getCursorizeTyFromRegVar'' + , getCursorizeTyFromRegVar''' + , getIndexPositionOfSoALocVar , module Gibbon.Language ) where @@ -298,6 +306,119 @@ scalarToTy SymS = SymTy scalarToTy BoolS = BoolTy +getIndexPositionOfSoALocVar :: [((DataCon, Int), LocVar)] -> LocVar -> (Int, Int, Bool) +getIndexPositionOfSoALocVar flds loc = foldl (\(s, e, b) (_, fl) -> if b + then + (s, e, True) + else + let seen = if fl == loc then True else False + in case fl of + Single{} -> (e, e + 1, seen) + SoA{} -> let (CursorArrayTy sz) = getCursorizeTyFromLocVar fl + in (e, e + sz, seen) + ) (1, 1, False) flds + + +getCursorizeTyFromLocVar :: LocVar -> Ty3 +getCursorizeTyFromLocVar lc = case lc of + Single{} -> CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar :: RegVar -> Ty3 +getCursorizeTyFromRegVar rv = case rv of + SingleR{} -> CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + + +getCursorizeTyFromLocVar' :: LocVar -> L2.Ty2 +getCursorizeTyFromLocVar' lc = case lc of + Single{} -> L2.MkTy2 CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in L2.MkTy2 $ CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar' :: RegVar -> L2.Ty2 +getCursorizeTyFromRegVar' rv = case rv of + SingleR{} -> L2.MkTy2 CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in L2.MkTy2 $ CursorArrayTy (1 + size_flds) + + +getCursorizeTyFromLocVar'' :: LocVar -> UrTy loc +getCursorizeTyFromLocVar'' lc = case lc of + Single{} -> CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar'' :: RegVar -> UrTy loc +getCursorizeTyFromRegVar'' rv = case rv of + SingleR{} -> CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + + +getCursorizeTyFromLocVar''' :: LocVar -> UrTy () +getCursorizeTyFromLocVar''' lc = case lc of + Single{} -> CursorTy + SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of + Single{} -> len + 1 + SoA{} -> let ty3 = getCursorizeTyFromLocVar flc + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + +getCursorizeTyFromRegVar''' :: RegVar -> UrTy () +getCursorizeTyFromRegVar''' rv = case rv of + SingleR{} -> CursorTy + SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of + SingleR{} -> len + 1 + SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr + in case ty3 of + CursorArrayTy sz -> len + sz + _ -> error "Did not expect type!" + ) 0 flds + in CursorArrayTy (1 + size_flds) + + ----------------------------------------------------------------------------------------- -- Do this manually to get prettier formatting: (Issue #90) @@ -322,9 +443,7 @@ cursorizeTy ty = ProdTy ls -> ProdTy $ L.map cursorizeTy ls SymDictTy v _ -> SymDictTy v CursorTy PDictTy k v -> PDictTy (cursorizeTy k) (cursorizeTy v) - PackedTy _ l -> case l of - Single _ -> ProdTy [CursorTy, CursorTy] - SoA _ flds -> ProdTy [CursorArrayTy (1 + length flds), CursorArrayTy (1 + length flds)] + PackedTy _ l -> ProdTy [getCursorizeTyFromLocVar'' l, getCursorizeTyFromLocVar'' l] VectorTy el_ty' -> VectorTy $ cursorizeTy el_ty' ListTy el_ty' -> ListTy $ cursorizeTy el_ty' PtrTy -> PtrTy diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 4d2444630..1c0dd4b3d 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -149,107 +149,6 @@ cursorize Prog {ddefs, fundefs, mainExp} = do mangle :: [Var] -> Var mangle vars = toVar $ "mangle" ++ (L.foldr (\v acc -> acc ++ "_" ++ (fromVar v)) "" vars) -getCursorizeTyFromLocVar :: LocVar -> Ty3 -getCursorizeTyFromLocVar lc = case lc of - Single{} -> CursorTy - SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of - Single{} -> len + 1 - SoA{} -> let ty3 = getCursorizeTyFromLocVar flc - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in CursorArrayTy (1 + size_flds) - -getCursorizeTyFromRegVar :: RegVar -> Ty3 -getCursorizeTyFromRegVar rv = case rv of - SingleR{} -> CursorTy - SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of - SingleR{} -> len + 1 - SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in CursorArrayTy (1 + size_flds) - - -getCursorizeTyFromLocVar' :: LocVar -> Ty2 -getCursorizeTyFromLocVar' lc = case lc of - Single{} -> MkTy2 CursorTy - SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of - Single{} -> len + 1 - SoA{} -> let ty3 = getCursorizeTyFromLocVar flc - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in MkTy2 $ CursorArrayTy (1 + size_flds) - -getCursorizeTyFromRegVar' :: RegVar -> Ty2 -getCursorizeTyFromRegVar' rv = case rv of - SingleR{} -> MkTy2 CursorTy - SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of - SingleR{} -> len + 1 - SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in MkTy2 $ CursorArrayTy (1 + size_flds) - - -getCursorizeTyFromLocVar'' :: LocVar -> UrTy loc -getCursorizeTyFromLocVar'' lc = case lc of - Single{} -> CursorTy - SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of - Single{} -> len + 1 - SoA{} -> let ty3 = getCursorizeTyFromLocVar flc - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in CursorArrayTy (1 + size_flds) - -getCursorizeTyFromRegVar'' :: RegVar -> UrTy loc -getCursorizeTyFromRegVar'' rv = case rv of - SingleR{} -> CursorTy - SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of - SingleR{} -> len + 1 - SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in CursorArrayTy (1 + size_flds) - - -getCursorizeTyFromLocVar''' :: LocVar -> UrTy () -getCursorizeTyFromLocVar''' lc = case lc of - Single{} -> CursorTy - SoA _ flds -> let size_flds = foldr (\(_, flc) len -> case flc of - Single{} -> len + 1 - SoA{} -> let ty3 = getCursorizeTyFromLocVar flc - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in CursorArrayTy (1 + size_flds) - -getCursorizeTyFromRegVar''' :: RegVar -> UrTy () -getCursorizeTyFromRegVar''' rv = case rv of - SingleR{} -> CursorTy - SoARv _ flds -> let size_flds = foldr (\(_, flr) len -> case flr of - SingleR{} -> len + 1 - SoARv{} -> let ty3 = getCursorizeTyFromRegVar flr - in case ty3 of - CursorArrayTy sz -> len + sz - _ -> error "Did not expect type!" - ) 0 flds - in CursorArrayTy (1 + size_flds) - - - cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do @@ -1555,20 +1454,39 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = if not (marker_added) then do after_soa_loc <- gensym "aft_soa_loc" - let after_flocs_to_vars = - map - ( \(_, floc) -> case (M.lookup (fromLocVarToFreeVarsTy $ floc) fvarenv) of - Just v -> v - Nothing -> case floc of - Single l -> l - _ -> error $ "cursorizeExp (1123): DataConE: unexpected location variable" ++ "(" ++ show (dcon, floc) ++ ")" ++ show fvarenv - ) - aft_flocs - let makeCurArr = Ext $ MakeCursorArray (1 + length (aft_flocs)) ([aft_dloc] ++ after_flocs_to_vars) + res <- + -- Here we need to unpack the individual variables from the cursor. + foldlM + ( \res e@(_, floc) -> case floc of + Single l -> do + let var_name = case (M.lookup (fromLocVarToFreeVarsTy $ floc) fvarenv) of + Just v -> v + Nothing -> l + return $ res ++ [([var_name], [])] + SoA _ flds -> do + let var_name = case (M.lookup (fromLocVarToFreeVarsTy $ floc) fvarenv) of + Just v -> v + Nothing -> error $ "cursorizeExp (1123): DataConE: unexpected location variable" ++ "(" ++ show (dcon, floc) ++ ")" ++ show fvarenv + let (CursorArrayTy sz) = getCursorizeTyFromLocVar floc + -- Vidush: This indexing is actually wrong. + -- I should make a function that given a position of a loc + -- get the exact index. + let (start, end, _) = getIndexPositionOfSoALocVar aft_flocs floc + (vars, bnds) <- foldlM (\(v, b) i -> do + new_var <- gensym "unpack_var" + let bnds = [(new_var, [], CursorTy, Ext $ IndexCursorArray var_name i)] + return $ (v ++ [new_var], b ++ bnds) + + ) ([], []) [start..(end - 1)] + return $ res ++ [(vars, bnds)] + ) [] aft_flocs + let after_flocs_to_vars = concatMap fst res + let lets_bef = concatMap snd res + let makeCurArr = Ext $ MakeCursorArray (1 + length (after_flocs_to_vars)) ([aft_dloc] ++ after_flocs_to_vars) let let_mk_cur_arr = LetE (after_soa_loc, [], getCursorizeTyFromLocVar (SoA "" aft_flocs), makeCurArr) end_scalars_alloc <- gensym "end_scalars_alloc" return - ( let_mk_cur_arr $ + ( mkLets lets_bef $ let_mk_cur_arr $ LetE (end_scalars_alloc, [], ProdTy [], Ext $ EndScalarsAllocation (curr_soa_loc)) (MkProdE [VarE (curr_soa_loc), VarE (after_soa_loc)]) From 36302e2a3e1dcafe779dc3df294403bb9465e9c2 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 16 Oct 2025 10:03:37 -0400 Subject: [PATCH 45/60] edits helper function --- gibbon-compiler/src/Gibbon/L3/Syntax.hs | 6 +++++ .../src/Gibbon/Passes/Cursorize.hs | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index fb848e829..c2a9938f9 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -23,6 +23,7 @@ module Gibbon.L3.Syntax , getCursorizeTyFromRegVar'' , getCursorizeTyFromRegVar''' , getIndexPositionOfSoALocVar + , linearizeLocVar , module Gibbon.Language ) where @@ -318,6 +319,11 @@ getIndexPositionOfSoALocVar flds loc = foldl (\(s, e, b) (_, fl) -> if b in (e, e + sz, seen) ) (1, 1, False) flds +linearizeLocVar :: LocVar -> [LocVar] +linearizeLocVar loc = case loc of + Single{} -> [loc] + SoA dcloc flocs -> let flinear = concatMap (\(_, fl) -> linearizeLocVar fl) flocs + in [singleLocVar dcloc] ++ flinear getCursorizeTyFromLocVar :: LocVar -> Ty3 getCursorizeTyFromLocVar lc = case lc of diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 1c0dd4b3d..6d4588370 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -150,6 +150,33 @@ mangle :: [Var] -> Var mangle vars = toVar $ "mangle" ++ (L.foldr (\v acc -> acc ++ "_" ++ (fromVar v)) "" vars) +-- The LocVar here is the field location, which we need to generate code for. +-- (Int, Int) is the start and end locations of that field. +handleIndexingSoACursors :: (Int, Int) -> LocVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var, [(Var, [()], Ty3, Exp3)]) +handleIndexingSoACursors (start, end) locvar var_env = do + let par_var = case (M.lookup (fromLocVarToFreeVarsTy locvar) var_env) of + Just v -> v + Nothing -> case locvar of + Single l -> l + SoA{} -> error "Expected variable name for parent array!" + case locvar of + Single{} -> do + return (var_env, [(par_var, [], CursorTy, Ext $ IndexCursorArray par_var start)]) + SoA{} -> do + (bnds, var_env') <- foldlM (\(b, env) (i, l) -> do + (lvar, fenv') <- case (M.lookup (fromLocVarToFreeVarsTy l) var_env) of + Just v -> return (v, env) + Nothing -> do + new_var <- gensym "unpack" + let env' = M.insert (fromLocVarToFreeVarsTy l) new_var env + return (new_var, env') + pure $ (b ++ [(lvar, [], CursorTy, Ext $ IndexCursorArray par_var i)], fenv') + + + ) ([], var_env) (zip [start..end] (linearizeLocVar locvar)) + return (var_env, bnds) + + cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do let inLocs = inLocVars funTy From 31a02c6ec7cbd3a8578e826534ccbc577386f38c Mon Sep 17 00:00:00 2001 From: vidush Date: Thu, 16 Oct 2025 17:20:09 -0400 Subject: [PATCH 46/60] wip nested soa --- gibbon-compiler/src/Gibbon/Common.hs | 9 +- gibbon-compiler/src/Gibbon/L3/Syntax.hs | 21 +++++ .../src/Gibbon/Passes/Cursorize.hs | 85 +++++++++++++++---- 3 files changed, 96 insertions(+), 19 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Common.hs b/gibbon-compiler/src/Gibbon/Common.hs index 5e20d08fb..782b41a75 100644 --- a/gibbon-compiler/src/Gibbon/Common.hs +++ b/gibbon-compiler/src/Gibbon/Common.hs @@ -33,7 +33,8 @@ module Gibbon.Common -- * Debugging/logging: , dbgLvl, dbgPrint, dbgPrintLn, dbgTrace, dbgTraceIt, minChatLvl - , internalError, dumpIfSet, unwrapLocVar, singleLocVar, getDconLoc, getFieldLoc, freshCommonLoc, getAllFieldLocsSoA, varsInLocVar, varsInRegVar + , internalError, dumpIfSet, unwrapLocVar, singleLocVar, getDconLoc, getFieldLoc, freshCommonLoc, getAllFieldLocsSoA + , varsInLocVar, varsInRegVar, getAllFieldRegsSoA , appendNameToLocVar -- * Establish conventions for the output of #lang gibbon: @@ -580,6 +581,12 @@ getAllFieldLocsSoA loc = case loc of SoA _dcon fieldLocs -> fieldLocs Single _lc -> error "getFieldLocs : Did not expect a non SoA location!" + +getAllFieldRegsSoA :: RegVar -> [((DataCon, Int), RegVar)] +getAllFieldRegsSoA loc = case loc of + SoARv _dcon fieldLocs -> fieldLocs + SingleR _lc -> error "getFieldLocs : Did not expect a non SoA location!" + freshSingleLocVar :: String -> PassM LocVar freshSingleLocVar m = do v <- gensym (toVar m) return $ Single v diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index c2a9938f9..7c0bd0116 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -23,7 +23,9 @@ module Gibbon.L3.Syntax , getCursorizeTyFromRegVar'' , getCursorizeTyFromRegVar''' , getIndexPositionOfSoALocVar + , getIndexPositionOfSoARegVar , linearizeLocVar + , linearizeRegVar , module Gibbon.Language ) where @@ -319,12 +321,31 @@ getIndexPositionOfSoALocVar flds loc = foldl (\(s, e, b) (_, fl) -> if b in (e, e + sz, seen) ) (1, 1, False) flds +getIndexPositionOfSoARegVar :: [((DataCon, Int), RegVar)] -> RegVar -> (Int, Int, Bool) +getIndexPositionOfSoARegVar flds loc = foldl (\(s, e, b) (_, fl) -> if b + then + (s, e, True) + else + let seen = if fl == loc then True else False + in case fl of + SingleR{} -> (e, e + 1, seen) + SoARv{} -> let (CursorArrayTy sz) = getCursorizeTyFromRegVar fl + in (e, e + sz, seen) + ) (1, 1, False) flds + linearizeLocVar :: LocVar -> [LocVar] linearizeLocVar loc = case loc of Single{} -> [loc] SoA dcloc flocs -> let flinear = concatMap (\(_, fl) -> linearizeLocVar fl) flocs in [singleLocVar dcloc] ++ flinear + +linearizeRegVar :: RegVar -> [RegVar] +linearizeRegVar loc = case loc of + SingleR{} -> [loc] + SoARv dcloc flocs -> let flinear = concatMap (\(_, fl) -> linearizeRegVar fl) flocs + in [dcloc] ++ flinear + getCursorizeTyFromLocVar :: LocVar -> Ty3 getCursorizeTyFromLocVar lc = case lc of Single{} -> CursorTy diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 6d4588370..bc06428fa 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -152,29 +152,57 @@ mangle vars = toVar $ "mangle" ++ (L.foldr (\v acc -> acc ++ "_" ++ (fromVar v)) -- The LocVar here is the field location, which we need to generate code for. -- (Int, Int) is the start and end locations of that field. -handleIndexingSoACursors :: (Int, Int) -> LocVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var, [(Var, [()], Ty3, Exp3)]) -handleIndexingSoACursors (start, end) locvar var_env = do +handleIndexingSoACursors :: (LocVar, Var) -> (Int, Int) -> LocVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var, [(Var, [()], Ty3, Exp3)]) +handleIndexingSoACursors (arrLoc, arrName) (start, end) locvar var_env = do let par_var = case (M.lookup (fromLocVarToFreeVarsTy locvar) var_env) of Just v -> v Nothing -> case locvar of Single l -> l SoA{} -> error "Expected variable name for parent array!" - case locvar of + case arrLoc of Single{} -> do - return (var_env, [(par_var, [], CursorTy, Ext $ IndexCursorArray par_var start)]) + return (var_env, [(arrName, [], CursorTy, Ext $ IndexCursorArray par_var start)]) SoA{} -> do - (bnds, var_env') <- foldlM (\(b, env) (i, l) -> do + let linearized_locs = (linearizeLocVar locvar) + (vars, bnds, var_env') <- foldlM (\(v, b, env) (i, l) -> do (lvar, fenv') <- case (M.lookup (fromLocVarToFreeVarsTy l) var_env) of Just v -> return (v, env) Nothing -> do new_var <- gensym "unpack" let env' = M.insert (fromLocVarToFreeVarsTy l) new_var env return (new_var, env') - pure $ (b ++ [(lvar, [], CursorTy, Ext $ IndexCursorArray par_var i)], fenv') + pure $ (v ++ [lvar], b ++ [(lvar, [], CursorTy, Ext $ IndexCursorArray par_var i)], fenv') - ) ([], var_env) (zip [start..end] (linearizeLocVar locvar)) - return (var_env, bnds) + ) ([], [], var_env) (zip [start..end] (take (end - start) (drop start linearized_locs)) ) + let make_cur_arr_let = [(arrName, [], getCursorizeTyFromLocVar arrLoc, Ext $ MakeCursorArray (length vars) vars)] + return (var_env, bnds ++ make_cur_arr_let) + +handleIndexingSoARegCursors :: (RegVar, Var) -> (Int, Int) -> RegVar -> M.Map FreeVarsTy Var -> PassM (M.Map FreeVarsTy Var, [(Var, [()], UrTy (), (PreExp E3Ext () (UrTy ())))]) +handleIndexingSoARegCursors (arrLoc, arrName) (start, end) locvar var_env = do + let par_var = case (M.lookup (fromRegVarToFreeVarsTy locvar) var_env) of + Just v -> v + Nothing -> case locvar of + SingleR l -> l + SoARv{} -> error "Expected variable name for parent array!" + case arrLoc of + SingleR{} -> do + return (var_env, [(arrName, [], CursorTy, Ext $ IndexCursorArray par_var start)]) + SoARv{} -> do + let linearized_locs = (linearizeRegVar locvar) + (vars, bnds, var_env') <- foldlM (\(v, b, env) (i, l) -> do + (lvar, fenv') <- case (M.lookup (fromRegVarToFreeVarsTy l) var_env) of + Just v -> return (v, env) + Nothing -> do + new_var <- gensym "unpack" + let env' = M.insert (fromRegVarToFreeVarsTy l) new_var env + return (new_var, env') + pure $ (v ++ [lvar], b ++ [(lvar, [], CursorTy, Ext $ IndexCursorArray par_var i)], fenv') + + + ) ([], [], var_env) (zip [start..end] (take (end - start) (drop start linearized_locs)) ) + let make_cur_arr_let = [(arrName, [], getCursorizeTyFromRegVar''' arrLoc, Ext $ MakeCursorArray (length vars) vars)] + return (var_env, bnds ++ make_cur_arr_let) cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 @@ -2562,8 +2590,13 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = Just v -> v Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding parent region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc name <- gensym "cursor_reg_ptr" - let instrs = [LetE (name, [], getCursorizeTyFromRegVar r, Ext $ IndexCursorArray (name_par_reg) 1)] - return $ (M.insert loc_var name acc, acc' ++ instrs) + let (R par_reg_inner) = par_reg + -- Vidush: TODO, is this right? + let (start, end, _) = getIndexPositionOfSoARegVar (getAllFieldRegsSoA par_reg_inner) r + (_acc, instrs) <- handleIndexingSoARegCursors (r, name) (start, end) par_reg_inner acc + --let instrs = [LetE (name, [], getCursorizeTyFromRegVar r, Ext $ IndexCursorArray (name_par_reg) 1)] + let instrs' = map (\i -> LetE i) instrs + return $ (M.insert loc_var name _acc, acc' ++ instrs') Nothing -> do (dconReg_var, dcon_insts) <- case (M.lookup (fromRegVarToFreeVarsTy dconReg) acc) of Just v -> return (v, []) @@ -2583,15 +2616,29 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = return (name_dcon, instrs) -- Nothing -> error $ "cursorizeAppE: Did not find an end of region variable for the corresponding datacon region.\n\n" ++ show f ++ "\n\n " ++ show r ++ "\n\n " ++ show acc - let fieldReg_vars = - map - ( \(key, field_reg) -> case (M.lookup (fromRegVarToFreeVarsTy field_reg) acc) of - Just v -> v - Nothing -> error "cursorizeAppE: Did not find an end of region variable for the corresponding field region.\n" + (fieldReg_vars, bnds) <- + foldlM + (\(vs, bds) (key, field_reg) -> do + v <- case (M.lookup (fromRegVarToFreeVarsTy field_reg) acc) of + Just vv -> return vv + Nothing -> error "cursorizeAppE: Did not find an end of region variable for the corresponding field region.\n" + case field_reg of + SingleR{} -> do + let (idx, _, _) = getIndexPositionOfSoARegVar fieldRegions field_reg + pure (vs ++ [v], bds ++ [(v, [], CursorTy, Ext $ IndexCursorArray v idx)]) + SoARv{} -> do + let (start, end, _) = getIndexPositionOfSoARegVar fieldRegions field_reg + (nvars, bnds) <- foldlM (\(nv, bnd) i -> do + var_n <- gensym "unpack" + return (nv ++ [var_n], bnd ++ [(var_n, [], CursorTy, Ext $ IndexCursorArray v i)]) + + ) ([], []) [start ..(end - 1)] + pure (vs ++ nvars, bds ++ bnds) ) + ([], []) fieldRegions name <- gensym "cursor_reg_ptr" - let instrs = dcon_insts ++ [LetE (name, [], getCursorizeTyFromRegVar r, Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] + let instrs = dcon_insts ++ (map (\i -> LetE i) bnds) ++ [LetE (name, [], getCursorizeTyFromRegVar r, Ext $ MakeCursorArray (1 + length fieldReg_vars) ([dconReg_var] ++ fieldReg_vars))] dbgTrace (minChatLvl) "Print Reg: " dbgTrace (minChatLvl) (sdoc (f, dconReg, fieldRegions)) dbgTrace (minChatLvl) "End soa Reg\n" return $ (M.insert loc_var name acc, acc' ++ instrs) pure ret @@ -3275,9 +3322,11 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack field_var <- gensym $ toVar $ (fromVar "soa_field_") ++ (show idx_elem) let acc3' = dbgTrace (minChatLvl) "print loc: " dbgTrace (minChatLvl) (sdoc (loc, scrut_loc)) dbgTrace (minChatLvl) "End cursorize print loc.\n" M.insert (fromLocVarToFreeVarsTy loc) field_var acc3 let field_cursor_ty = getCursorizeTyFromLocVar loc - let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1 + idx_elem))] + let (start, end, _) = getIndexPositionOfSoALocVar (getAllFieldLocsSoA scrut_loc) loc + (acc3'', field_let) <- handleIndexingSoACursors (loc, field_var) (start, end) scrut_loc acc3' + --let field_let = [(field_var, [], field_cursor_ty, Ext $ IndexCursorArray scrtCur (1 + idx_elem))] let curr_window = [((dcon', idx), field_var)] - return (acc1 ++ field_let, acc2 ++ curr_window, acc3') + return (acc1 ++ field_let, acc2 ++ curr_window, acc3'') ) ([], [], freeVarToVarEnv) (getAllFieldLocsSoA scrut_loc) From 488835e5ea5631c70c545e12fe7ebc45167efb97 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 19 Oct 2025 01:50:34 -0400 Subject: [PATCH 47/60] wip nested regions --- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 2 +- .../src/Gibbon/Passes/Cursorize.hs | 298 ++++++++++++++---- 2 files changed, 232 insertions(+), 68 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index 0c46fa27c..52c468058 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -1754,7 +1754,7 @@ makeName' FloatTy = "GibFloat" makeName' SymTy = "GibSym" makeName' BoolTy = "GibBool" makeName' CursorTy = "GibCursor" -makeName' (CursorArrayTy{}) = "GibCursorPtr" +makeName' (CursorArrayTy sz) = "GibCursorPtr" ++ show sz makeName' (MutCursorTy) = "GibMutCursor" makeName' TagTyPacked = "GibPackedTag" makeName' TagTyBoxed = "GibBoxedTag" diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index bc06428fa..746383cf1 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -2,6 +2,7 @@ {-# OPTIONS_GHC -Wno-unused-local-binds #-} {-# OPTIONS_GHC -Wno-name-shadowing #-} {-# OPTIONS_GHC -Wno-unused-matches #-} +{-# LANGUAGE BlockArguments #-} module Gibbon.Passes.Cursorize (cursorize) where @@ -3628,7 +3629,32 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack var_dcon_next <- gensym "dcon_next" vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur redirection_var_dcon <- gensym "dcon_redir" - redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + res <- mapM (\((dcon, idx), _loc) -> do + let locTy = (lookupDataCon ddfs dcon) !! idx + case locTy of + MkTy2 (PackedTy _ loc) -> do + let lty = getCursorizeTyFromLocVar loc + case lty of + CursorTy -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + CursorArrayTy _sz -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + MkTy2 (CursorArrayTy _sz) -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + _ -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + ) _field_cur + let redirection_var_flds = concatMap thd3 res -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur let tenv' = @@ -3662,7 +3688,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- generate binds for all fields. binds_flields = L.foldl - ( \(index, res) ((dcon', idx), var) -> + ( \(index, res) ((dcon', idx), var, redir_vars) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor (vars_next_fields !! index)) @@ -3671,25 +3697,31 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ty_of_field = (lookupDataCon ddfs dcon') !! idx in case ty_of_field of (MkTy2 PackedTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] - in (index + 1, res ++ new_binds) + let new_binds = case redir_vars of + [v] -> [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst + in (index + 1, res ++ new_binds) (MkTy2 CursorArrayTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) _ -> - let new_binds = - [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) - ] + let new_binds = case redir_vars of + [v] -> + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] + rst -> error $ "Did not expect multiple variables for type " ++ show ty_of_field in (index + 1, res ++ new_binds) ) (0, []) - _field_cur + res -- Vidush : TODO this needs to change since type changed soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = @@ -3757,7 +3789,32 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack var_dcon_next <- gensym "dcon_next" vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur redirection_var_dcon <- gensym "dcon_redir" - redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + res <- mapM (\((dcon, idx), _loc) -> do + let locTy = (lookupDataCon ddfs dcon) !! idx + case locTy of + MkTy2 (PackedTy _ loc) -> do + let lty = getCursorizeTyFromLocVar loc + case lty of + CursorTy -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + CursorArrayTy _sz -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + MkTy2 (CursorArrayTy _sz) -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + _ -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + ) _field_cur + let redirection_var_flds = concatMap thd3 res -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur let tenv' = M.union @@ -3787,7 +3844,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- generate binds for all fields. binds_flields = L.foldl - ( \(index, res) ((dcon', idx), var) -> + ( \(index, res) ((dcon', idx), var, redir_vars) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor (vars_next_fields !! index)) @@ -3796,23 +3853,29 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ty_of_field = (lookupDataCon ddfs dcon') !! idx in case ty_of_field of (MkTy2 PackedTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) (MkTy2 CursorArrayTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) _ -> - let new_binds = - [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) - ] + let new_binds = case redir_vars of + [v] -> + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((v), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (v), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (v), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (v), [], CursorTy, Ext $ AddCursor (v) (VarE (toTagV (v)))) + ] + _ -> error "Did not expect multiple variables!" in (index + 1, res ++ new_binds) - ) (0, []) _field_cur + ) (0, []) res soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = M.union ( M.fromList @@ -3834,7 +3897,32 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack var_dcon_next <- gensym "dcon_next" vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur redirection_var_dcon <- gensym "dcon_redir" - redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + res <- mapM (\((dcon, idx), _loc) -> do + let locTy = (lookupDataCon ddfs dcon) !! idx + case locTy of + MkTy2 (PackedTy _ loc) -> do + let lty = getCursorizeTyFromLocVar loc + case lty of + CursorTy -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + CursorArrayTy _sz -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + MkTy2 (CursorArrayTy _sz) -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + _ -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + ) _field_cur + let redirection_var_flds = concatMap thd3 res -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur let tenv' = @@ -3868,7 +3956,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- generate binds for all fields. binds_flields = L.foldl - ( \(index, res) ((dcon', idx), var) -> + ( \(index, res) ((dcon', idx), var, redir_vars) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor (vars_next_fields !! index)) @@ -3877,25 +3965,31 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ty_of_field = (lookupDataCon ddfs dcon') !! idx in case ty_of_field of (MkTy2 PackedTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) (MkTy2 CursorArrayTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) _ -> - let new_binds = - [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) - ] + let new_binds = case redir_vars of + [v] -> + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((v), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (v), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (v), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (v), [], CursorTy, Ext $ AddCursor (v) (VarE (toTagV (v)))) + ] + _ -> error $ "Did not expect multiple variables for type" ++ show ty_of_field in (index + 1, res ++ new_binds) ) (0, []) - _field_cur + res soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = M.union @@ -3960,7 +4054,32 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack var_dcon_next <- gensym "dcon_next" vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur redirection_var_dcon <- gensym "dcon_redir" - redirection_var_flds <- mapM (\((dcon, idx), _) -> gensym "fld_redir") _field_cur + res <- mapM (\((dcon, idx), _loc) -> do + let locTy = (lookupDataCon ddfs dcon) !! idx + case locTy of + MkTy2 (PackedTy _ loc) -> do + let lty = getCursorizeTyFromLocVar loc + case lty of + CursorTy -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + CursorArrayTy _sz -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + MkTy2 (CursorArrayTy _sz) -> do + num_vars <- mapM (\i -> do + var <- gensym "new" + return var + ) [1.._sz] + return $ ((dcon, idx), _loc, num_vars) + _ -> do + new_var <- gensym "fld_redir" + return $ ((dcon, idx), _loc, [new_var]) + ) _field_cur + let redirection_var_flds = concatMap thd3 res -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur let tenv' = M.union @@ -3990,7 +4109,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- generate binds for all fields. binds_flields = L.foldl - ( \(index, res) ((dcon', idx), var) -> + ( \(index, res) ((dcon', idx), var, redir_vars) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon then Ext (ReadTaggedCursor (vars_next_fields !! index)) @@ -3999,23 +4118,29 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ty_of_field = (lookupDataCon ddfs dcon') !! idx in case ty_of_field of (MkTy2 PackedTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) (MkTy2 CursorArrayTy {}) -> - let new_binds = [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] + let new_binds = case redir_vars of + [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + 1, res ++ new_binds) _ -> - let new_binds = - [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), - -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), - (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) - ] + let new_binds = case redir_vars of + [v] -> + [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] + _ -> error $ "Did not expect multiple variables for ty: " ++ show ty_of_field in (index + 1, res ++ new_binds) - ) (0, []) _field_cur + ) (0, []) res soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = M.union ( M.fromList @@ -4986,7 +5111,41 @@ regionToBinds freeVarToVarEnv for_parallel_allocs r sz = do -- TODO: SoA Region SoAR dcreg fieldRegs -> do (dcreg_binds, _freeVarToVarEnv) <- regionToBinds freeVarToVarEnv for_parallel_allocs dcreg sz - field_binds_pairs <- mapM (\(key, field_reg) -> regionToBinds _freeVarToVarEnv for_parallel_allocs field_reg sz) fieldRegs + field_binds_pairs <- mapM (\(key, field_reg) -> case regionToVar field_reg of + SingleR{} -> regionToBinds _freeVarToVarEnv for_parallel_allocs field_reg sz + -- We linearize these regions. + SoARv dc_reg fregs -> do + case field_reg of + SoAR dcr frs -> do + let dc_bnds = case dcr of + GlobR v mul -> let mul' = go mul + endv = toEndV v + bnds = [ (v, [], CursorTy, Ext (NewBuffer mul')), + (endv, [], CursorTy, Ext (EndOfBuffer mul')) + ] + in bnds + _ -> error "not implemented" + fld_bnds <- concat <$> mapM (\((dcon, idx), fr) -> do + case fr of + GlobR v mul -> do + let mul' = go mul + let endv = toEndV v + let ty :: Ty3 = CursorTy + let exp1 :: Exp3 = Ext (NewBuffer mul') + let exp2 :: Exp3 = Ext (EndOfBuffer mul') + let bnds = [ (v, [], ty, exp1), + (endv, [], ty, exp2) + ] + pure bnds + _ -> error "Not implemented!" + + ) frs + + pure (dc_bnds ++ fld_bnds, _freeVarToVarEnv) + + + + ) fieldRegs let field_binds = concatMap fst field_binds_pairs let field_new_maps = map snd field_binds_pairs let _freeVarToVarEnv' = foldr (\m acc -> M.union m acc) freeVarToVarEnv field_new_maps @@ -4998,18 +5157,23 @@ regionToBinds freeVarToVarEnv for_parallel_allocs r sz = do Nothing -> gensym "reg_ptr" let freeVarToVarEnv'' = M.insert (fromRegVarToFreeVarsTy reg_to_reg_var) regions_var freeVarToVarEnv' field_reg_keys_vars <- - mapM + concat <$> mapM ( \(key, field_reg) -> do case M.lookup (fromRegVarToFreeVarsTy (regionToVar field_reg)) freeVarToVarEnv'' of - Just v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) + Just v -> return [(fromRegVarToFreeVarsTy (regionToVar field_reg), v)] Nothing -> case field_reg of - VarR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - GlobR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - DynR v _ -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - MMapR v -> return (fromRegVarToFreeVarsTy (regionToVar field_reg), v) - SoAR _ _ -> do - new_name <- gensym "reg_ptr" - return (fromRegVarToFreeVarsTy (regionToVar field_reg), new_name) + VarR v -> return [(fromRegVarToFreeVarsTy (regionToVar field_reg), v)] + GlobR v _ -> return [(fromRegVarToFreeVarsTy (regionToVar field_reg), v)] + DynR v _ -> return [(fromRegVarToFreeVarsTy (regionToVar field_reg), v)] + MMapR v -> return [(fromRegVarToFreeVarsTy (regionToVar field_reg), v)] + SoAR dc fvar -> do + let dcv = case dc of + GlobR v _ -> (fromRegVarToFreeVarsTy (regionToVar dc), v) + let fvs = map (\(_, f) -> case f of + GlobR v _ -> (fromRegVarToFreeVarsTy (regionToVar f), v) + ) fvar + return $ [dcv] ++ fvs + ) fieldRegs let field_reg_keys = map fst field_reg_keys_vars From 87dae81b58f95123a9796008c8be62303f0b265f Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 19 Oct 2025 23:32:25 -0400 Subject: [PATCH 48/60] nested stack allocated array works, ran works --- .../examples/soa_examples/packedTree.hs | 9 ++++--- gibbon-compiler/src/Gibbon/L1/Typecheck.hs | 14 ++++++----- gibbon-compiler/src/Gibbon/Language/Syntax.hs | 8 ++++++- gibbon-compiler/src/Gibbon/Passes/AddRAN.hs | 10 ++++++-- .../src/Gibbon/Passes/Cursorize.hs | 24 ++++++++++--------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index bdbf1f840..a32ad924b 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -2,6 +2,8 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf {-# ANN type Tree "Factored" #-} +{-# ANN type List "Factored" #-} +{-# ANN type FloatList "Factored" #-} mkList :: Int -> List mkList len = if len <= 0 @@ -85,8 +87,9 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = mkTree 5 + let tree = mkTree 14 tree' = id (add1Tree tree) - val = sumTree tree' - in val + val = iterate (sumTree tree) + r = iterate (rightMostTree tree') + in val + r diff --git a/gibbon-compiler/src/Gibbon/L1/Typecheck.hs b/gibbon-compiler/src/Gibbon/L1/Typecheck.hs index 7ce7a0a22..c479c8d0c 100644 --- a/gibbon-compiler/src/Gibbon/L1/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L1/Typecheck.hs @@ -27,12 +27,14 @@ import Gibbon.Common import Gibbon.L1.Syntax as L1 import Gibbon.DynFlags import Prelude hiding (exp) +import Data.Vector.Internal.Check (HasCallStack) +import GHC.Stack (callStack, prettyCallStack) -------------------------------------------------------------------------------- -- | Typecheck a L1 expression -- -tcExp :: DDefs1 -> Env2 Var Ty1 -> Exp1 -> TcM Ty1 Exp1 +tcExp :: HasCallStack => DDefs1 -> Env2 Var Ty1 -> Exp1 -> TcM Ty1 Exp1 tcExp ddfs env exp = case exp of VarE v -> lookupVar env v exp @@ -648,7 +650,7 @@ tcExp ddfs env exp = then throwError $ GenericTC ("Invalid argument length: " ++ sdoc es) exp else do -- Check if arguments match with expected datacon types - sequence_ [ ensureEqualTy e ty1 ty2 + sequence_ [ ensureEqualTy e ty1 ty2 | (ty1,ty2,e) <- zip3 args tys es] return $ PackedTy dcTy loc @@ -688,7 +690,7 @@ tcExp ddfs env exp = case ty of PackedTy tycon _ -> let dd = lookupDDef ddfs tycon ranTy = getCursorTypeForDataCon ddfs dd - in pure ranTy + in dbgTrace (minChatLvl) "Print ty" dbgTrace (minChatLvl) (sdoc (ty, dd, ranTy)) dbgTrace (minChatLvl) "End printing ty" pure ranTy _ -> throwError $ GenericTC "Expected a packed argument" exp MapE{} -> error $ "L1.Typecheck: TODO: " ++ sdoc exp @@ -704,7 +706,7 @@ tcExp ddfs env exp = -- | Typecheck a L1 program -- -tcProg :: Prog1 -> PassM Prog1 +tcProg :: HasCallStack => Prog1 -> PassM Prog1 tcProg prg@Prog{ddefs,fundefs,mainExp} = do -- Get flags to check if we're in packed mode flags <- getDynFlags @@ -768,11 +770,11 @@ tcProg prg@Prog{ddefs,fundefs,mainExp} = do let (argTys,retty) = funTy venv = M.fromList (zip funArgs argTys) env' = Env2 venv (fEnv env) - res = runExcept $ tcExp ddefs env' funBody + res = runExcept $ tcExp ddefs env' funBody dynflags <- getDynFlags let isPacked = gopt Opt_Packed dynflags case res of - Left err -> error $ sdoc err + Left err -> error $ sdoc err ++ "\n" ++ prettyCallStack callStack Right ty -> if isPacked && (length $ getPackedTys retty) > 1 then error ("Gibbon-TODO: Functions cannot return multiple packed values; " ++ "check " ++ sdoc funName) diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 0b2c345f4..d3a3aab75 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -182,7 +182,13 @@ getCursorTypeForDataCon _ddefs DDef{tyName, dataCons, memLayout} = PackedTy tycon _ -> if (toVar tycon) == tyName then c'' - else c'' + 1 + else + let ddef_for_tycon = lookupDDef _ddefs tycon + ty_of_packed_field = getCursorTypeForDataCon _ddefs ddef_for_tycon + in case ty_of_packed_field of + CursorTy -> c'' + 1 + CursorArrayTy sz -> c'' + sz + _ -> error "Did not expect type" CursorTy -> c'' CursorArrayTy _ -> c'' _ -> c'' + 1 diff --git a/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs b/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs index 8e198def4..699a8d5bf 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs @@ -258,8 +258,14 @@ withRANDDefs needRANsTyCons ddfs = M.map go ddfs if not (getTyOfDataCon ddfs dcon `S.member` needRANsTyCons) then acc else - let ranTy = getCursorTypeForDataCon ddfs dd - tys' = [(False,ranTy) | _ <- [1..n]] ++ tys + let fields = lookupDataCon ddfs dcon + needsRanFields = L.drop (length fields - n) fields + ranTyFields = map (\ty -> case ty of + PackedTy tycon _ -> let dd = lookupDDef ddfs tycon + in getCursorTypeForDataCon ddfs dd + _ -> CursorTy + ) needsRanFields + tys' = [(False, r) | r <- ranTyFields] ++ tys dcon' = toAbsRANDataCon dcon _tys'' = (False,IntTy) : [(False,IntTy) | _ <- [1..n]] ++ tys diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 746383cf1..546217686 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -28,7 +28,6 @@ import qualified Gibbon.L3.Syntax as L3 import Gibbon.NewL2.Syntax import Gibbon.Passes.AddRAN (numRANsDataCon) import Text.PrettyPrint.GenericPretty -import Safe (fromJustDef) {- @@ -1527,13 +1526,13 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = -- Vidush: This indexing is actually wrong. -- I should make a function that given a position of a loc -- get the exact index. - let (start, end, _) = getIndexPositionOfSoALocVar aft_flocs floc + -- let (start, end, _) = getIndexPositionOfSoALocVar aft_flocs floc (vars, bnds) <- foldlM (\(v, b) i -> do new_var <- gensym "unpack_var" let bnds = [(new_var, [], CursorTy, Ext $ IndexCursorArray var_name i)] return $ (v ++ [new_var], b ++ bnds) - ) ([], []) [start..(end - 1)] + ) ([], []) [0..(sz - 1)] return $ res ++ [(vars, bnds)] ) [] aft_flocs let after_flocs_to_vars = concatMap fst res @@ -2375,12 +2374,13 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = Single{} -> return $ (Ext $ IndexCursorArray loc_var (1 + elem_idx), []) SoA _ fregs -> do let CursorArrayTy sz = getCursorizeTyFromLocVar field_loc - let start = L.elemIndex (i, field_loc) field_locs - let start_val = fromJustDef (-1) start + let (start, end, _) = getIndexPositionOfSoALocVar field_locs field_loc + --let start = L.elemIndex (i, field_loc) field_locs + --let start_val = fromJustDef (-1) start res <- foldlM (\bnds i -> do new_var <- gensym "unpack_loc" return $ bnds ++ [ (new_var, (new_var, [], CursorTy, Ext $ IndexCursorArray loc_var i)) ] - ) [] [(start_val + 1)..(start_val + sz)] + ) [] [(start)..(end - 1)] let vars = map fst res let bnds = map snd res return $ (Ext $ MakeCursorArray (length vars) vars, bnds) @@ -2462,12 +2462,13 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = Single{} -> return $ (Ext $ IndexCursorArray loc_var (1 + elem_idx), []) SoA _ fregs -> do let CursorArrayTy sz = getCursorizeTyFromLocVar field_loc - let start = L.elemIndex (i, field_loc) field_locs - let start_val = fromJustDef (-1) start + let (start, end, _) = getIndexPositionOfSoALocVar field_locs field_loc + --let start = L.elemIndex (i, field_loc) field_locs + --let start_val = fromJustDef (-1) start res <- foldlM (\bnds i -> do new_var <- gensym "unpack_loc" return $ bnds ++ [ (new_var, (new_var, [], CursorTy, Ext $ IndexCursorArray loc_var i)) ] - ) [] [(start_val + 1)..(start_val + sz)] + ) [] [(start)..(end-1)] let vars = map fst res let bnds = map snd res return $ (Ext $ MakeCursorArray (length vars) vars, bnds) @@ -2628,12 +2629,13 @@ cursorizeAppE freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let (idx, _, _) = getIndexPositionOfSoARegVar fieldRegions field_reg pure (vs ++ [v], bds ++ [(v, [], CursorTy, Ext $ IndexCursorArray v idx)]) SoARv{} -> do - let (start, end, _) = getIndexPositionOfSoARegVar fieldRegions field_reg + --let (start, end, _) = getIndexPositionOfSoARegVar fieldRegions field_reg + let CursorArrayTy _sz = getCursorizeTyFromRegVar field_reg (nvars, bnds) <- foldlM (\(nv, bnd) i -> do var_n <- gensym "unpack" return (nv ++ [var_n], bnd ++ [(var_n, [], CursorTy, Ext $ IndexCursorArray v i)]) - ) ([], []) [start ..(end - 1)] + ) ([], []) [0 ..(_sz - 1)] pure (vs ++ nvars, bds ++ bnds) ) ([], []) From 3545ab258c27a69054f08ce507f8b74e5c464dc3 Mon Sep 17 00:00:00 2001 From: vidush Date: Tue, 28 Oct 2025 09:47:33 -0400 Subject: [PATCH 49/60] edits --- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index cd58c5d44..f0ad4a9d1 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -35,7 +35,7 @@ gibbon_main = let tree = id (mkTree 10) tree' = (add1Tree tree) tree'' = iterate (id (add1Tree tree')) - val = iterate (sumTree tree'') + val = (sumTree tree'') _ = printsym (quote "(sum: ") _ = printint val _ = printsym (quote ", rightmost: ") From 5e7c4183086b45d7df5cdf7ab9dffcc8358d8a91 Mon Sep 17 00:00:00 2001 From: vidush Date: Tue, 28 Oct 2025 20:11:02 -0400 Subject: [PATCH 50/60] allowing data types to have different memory layouts --- gibbon-compiler/examples/soa_examples/list.hs | 4 +- .../examples/soa_examples/packedList.hs | 13 +- .../examples/soa_examples/packedTree.hs | 8 +- gibbon-compiler/src/Gibbon/L3/Typecheck.hs | 254 ++++++++++-------- gibbon-compiler/src/Gibbon/Language/Syntax.hs | 37 ++- .../src/Gibbon/Passes/Cursorize.hs | 21 +- .../src/Gibbon/Passes/InferLocations.hs | 236 ++++++++-------- .../src/Gibbon/Passes/ReorderScalarWrites.hs | 6 +- .../src/Gibbon/Passes/RouteEnds.hs | 50 ++-- .../src/Gibbon/Passes/ThreadRegions2.hs | 6 +- 10 files changed, 365 insertions(+), 270 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 25696a7d6..304b70c78 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -1,6 +1,6 @@ data List = Cons Int List | Nil -{-# ANN type List "Linear" #-} +{-# ANN type List "Factored" #-} mkList :: Int -> List @@ -37,7 +37,7 @@ id :: List -> List id lst = lst gibbon_main = let - lst = (mkList 10000000) + lst = (mkList 1000000) lst' = iterate ((add1 lst)) in sumList lst' diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index a2100ad14..4a32aeadf 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -1,5 +1,7 @@ data PackedInt = PacI Int data List = Cons Int PackedInt List | Nil +{-# ANN type PackedInt "Factored" #-} +{-# ANN type List "Linear" #-} addPackedInt' :: PackedInt -> Int -> PackedInt addPackedInt' a b = case a of @@ -46,11 +48,6 @@ id lst = lst gibbon_main = let pi = mkPackedInt 10 - lst = mkList 100 - lst' = id (add1 lst) - in (sumList lst') - - - - - + lst = mkList 1000000 + lst' = iterate (add1 lst) + in (sumList lst') diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index a32ad924b..f260e9065 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -2,8 +2,8 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf {-# ANN type Tree "Factored" #-} -{-# ANN type List "Factored" #-} -{-# ANN type FloatList "Factored" #-} +{-# ANN type List "Linear" #-} +{-# ANN type FloatList "Linear" #-} mkList :: Int -> List mkList len = if len <= 0 @@ -18,7 +18,7 @@ mkFloatList len = if len <= 0 mkTree :: Int -> Tree mkTree d = if (d <= 0) then Leaf - else Node d 1.0 (mkFloatList d) (mkList d) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) + else Node d 1.0 (mkFloatList 1000) (mkList 1000) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) rightMostTree :: Tree -> Int @@ -87,7 +87,7 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = mkTree 14 + let tree = mkTree 10 tree' = id (add1Tree tree) val = iterate (sumTree tree) r = iterate (rightMostTree tree') diff --git a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs index 9fca5386e..f07d8cdae 100644 --- a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs @@ -19,40 +19,40 @@ import Prelude hiding (exp) import Gibbon.Common import Gibbon.L1.Typecheck hiding (tcProg, tcExp, ensureEqual, ensureEqualTy) import Gibbon.L3.Syntax -import Gibbon.DynFlags + -- | Typecheck a L1 expression -- -tcExp :: Bool -> Bool -> DDefs3 -> Env2 Var Ty3 -> Exp3 -> TcM Ty3 Exp3 -tcExp isSoA isPacked ddfs env exp = do +tcExp :: Bool -> DDefs3 -> Env2 Var Ty3 -> Exp3 -> TcM Ty3 Exp3 +tcExp isPacked ddfs env exp = do case exp of Ext ext -> case ext of -- One cursor in, (int, cursor') out ReadScalar s v -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return $ ProdTy [scalarToTy s, CursorTy] -- Write int at cursor, and return a cursor WriteScalar s v rhs -> do vty <- lookupVar env v exp vrhs <- go rhs - ensureEqualTyModCursor isSoA exp vty CursorTy - ensureEqualTyModCursor isSoA exp vrhs (scalarToTy s) + ensureEqualTyModCursor ddfs exp vty CursorTy + ensureEqualTyModCursor ddfs exp vrhs (scalarToTy s) return CursorTy -- One cursor in, (tag,cursor) out -- QUESTION: what should be the type of the tag ? It's just an Int for now ReadTag v -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return $ ProdTy [IntTy, CursorTy] -- Write Tag at Cursor, and return a cursor WriteTag _dcon v -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return CursorTy -- VS: the semantics of Tag cursor have changed. @@ -61,19 +61,19 @@ tcExp isSoA isPacked ddfs env exp = do --ensureEqualTyModCursor isSoA exp aty CursorTy bty <- lookupVar env b exp --ensureEqualTyModCursor isSoA exp bty CursorTy - ensureEqualTyModCursor isSoA exp aty bty + ensureEqualTyModCursor ddfs exp aty bty return aty ReadTaggedCursor v -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return $ ProdTy [CursorTy, CursorTy, IntTy] WriteTaggedCursor v val -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy valty <- go val - ensureEqualTyModCursor isSoA exp valty CursorTy + ensureEqualTyModCursor ddfs exp valty CursorTy return CursorTy -- does this require typecheking @@ -82,54 +82,54 @@ tcExp isSoA isPacked ddfs env exp = do ReadCursor v -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return $ ProdTy [CursorTy, CursorTy] WriteCursor cur val -> do curty <- lookupVar env cur exp - ensureEqualTyModCursor isSoA exp curty CursorTy + ensureEqualTyModCursor ddfs exp curty CursorTy valty <- go val - ensureEqualTyModCursor isSoA exp valty CursorTy + ensureEqualTyModCursor ddfs exp valty CursorTy return CursorTy ReadList v ty -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return $ ProdTy [ListTy ty, CursorTy] WriteList cur val el_ty -> do curty <- lookupVar env cur exp - ensureEqualTyModCursor isSoA exp curty CursorTy + ensureEqualTyModCursor ddfs exp curty CursorTy valty <- go val - ensureEqualTyModCursor isSoA exp valty (ListTy el_ty) + ensureEqualTyModCursor ddfs exp valty (ListTy el_ty) return CursorTy ReadVector v ty -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy return $ ProdTy [VectorTy ty, CursorTy] WriteVector cur val el_ty -> do curty <- lookupVar env cur exp - ensureEqualTyModCursor isSoA exp curty CursorTy + ensureEqualTyModCursor ddfs exp curty CursorTy valty <- go val - ensureEqualTyModCursor isSoA exp valty (VectorTy el_ty) + ensureEqualTyModCursor ddfs exp valty (VectorTy el_ty) return CursorTy -- Add a constant offset to a cursor variable AddCursor v rhs -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy vrhs <- go rhs - ensureEqualTyModCursor isSoA exp vrhs IntTy + ensureEqualTyModCursor ddfs exp vrhs IntTy return CursorTy -- Subtract something from a cursor variable SubPtr v w -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty CursorTy + ensureEqualTyModCursor ddfs exp vty CursorTy wty <- lookupVar env w exp - ensureEqualTyModCursor isSoA exp wty CursorTy + ensureEqualTyModCursor ddfs exp wty CursorTy return IntTy -- Create a new buffer, and return a cursor @@ -147,9 +147,9 @@ tcExp isSoA isPacked ddfs env exp = do -- Takes in start and end cursors, and returns an Int SizeOfPacked start end -> do sty <- lookupVar env start exp - ensureEqualTyModCursor isSoA exp sty CursorTy + ensureEqualTyModCursor ddfs exp sty CursorTy ety <- lookupVar env end exp - ensureEqualTyModCursor isSoA exp ety CursorTy + ensureEqualTyModCursor ddfs exp ety CursorTy return IntTy -- Takes in a variable, and returns an Int @@ -162,9 +162,9 @@ tcExp isSoA isPacked ddfs env exp = do -- The IntTy is just a placeholder. BoundsCheck is a side-effect BoundsCheck _ bound cur -> do rty <- lookupVar env bound exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy cty <- lookupVar env cur exp - ensureEqualTyModCursor isSoA exp cty CursorTy + ensureEqualTyModCursor ddfs exp cty CursorTy return IntTy {- VS: Ignoring the types of the arguments to gib grow region -} @@ -172,21 +172,21 @@ tcExp isSoA isPacked ddfs env exp = do BoundsCheckVector bounds -> do _ <- mapM (\(_, bound, cur, _) -> do rty <- lookupVar env bound exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy cty <- lookupVar env cur exp - ensureEqualTyModCursor isSoA exp cty CursorTy + ensureEqualTyModCursor ddfs exp cty CursorTy ) bounds return IntTy IndirectionBarrier _tycon (l1, end_r1, l2, end_r2) -> do l1_ty <- lookupVar env l1 exp - ensureEqualTyModCursor isSoA exp l1_ty CursorTy + ensureEqualTyModCursor ddfs exp l1_ty CursorTy end_r1_ty <- lookupVar env end_r1 exp - ensureEqualTyModCursor isSoA exp end_r1_ty CursorTy + ensureEqualTyModCursor ddfs exp end_r1_ty CursorTy l2_ty <- lookupVar env l2 exp - ensureEqualTyModCursor isSoA exp l2_ty CursorTy + ensureEqualTyModCursor ddfs exp l2_ty CursorTy end_r2_ty <- lookupVar env end_r2 exp - ensureEqualTyModCursor isSoA exp end_r2_ty CursorTy + ensureEqualTyModCursor ddfs exp end_r2_ty CursorTy return (ProdTy []) BumpArenaRefCount{} -> @@ -205,51 +205,51 @@ tcExp isSoA isPacked ddfs env exp = do AllocateTagHere v _ -> do rty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy return (ProdTy []) AllocateScalarsHere v -> do rty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy return (ProdTy []) StartTagAllocation v -> do rty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy return (ProdTy []) EndTagAllocation v -> do rty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy return (ProdTy []) EndScalarsAllocation v -> do rty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy return (ProdTy []) StartScalarsAllocation v -> do rty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty CursorTy + ensureEqualTyModCursor ddfs exp rty CursorTy return (ProdTy []) SSPush _ v w _ -> do rty1 <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty1 CursorTy + ensureEqualTyModCursor ddfs exp rty1 CursorTy rty2 <- lookupVar env w exp - ensureEqualTyModCursor isSoA exp rty2 CursorTy + ensureEqualTyModCursor ddfs exp rty2 CursorTy return (ProdTy []) SSPop _ v w -> do rty1 <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp rty1 CursorTy + ensureEqualTyModCursor ddfs exp rty1 CursorTy rty2 <- lookupVar env w exp - ensureEqualTyModCursor isSoA exp rty2 CursorTy + ensureEqualTyModCursor ddfs exp rty2 CursorTy return (ProdTy []) Assert rhs -> do ety <- go rhs - ensureEqualTyModCursor isSoA rhs ety BoolTy + ensureEqualTyModCursor ddfs rhs ety BoolTy return (ProdTy []) CastPtr{} -> error "tcExp: CastPtr not handled" @@ -257,17 +257,17 @@ tcExp isSoA isPacked ddfs env exp = do {- VS: TODO: we should check the bounds of index cursory array -} IndexCursorArray v _ -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty vty + ensureEqualTyModCursor ddfs exp vty vty return CursorTy AddrOfCursor expr -> do ety <- go expr - ensureEqualTyModCursor isSoA expr ety CursorTy + ensureEqualTyModCursor ddfs expr ety CursorTy return MutCursorTy DerefMutCursor v -> do vty <- lookupVar env v exp - ensureEqualTyModCursor isSoA exp vty MutCursorTy + ensureEqualTyModCursor ddfs exp vty MutCursorTy return CursorTy @@ -321,7 +321,7 @@ tcExp isSoA isPacked ddfs env exp = do subFunInTys = L.map (subDictTy arMap) funInTys subFunOutTy = subDictTy arMap funRetTy - _ <- mapM (\(a,b) -> ensureEqualTyModCursor isSoA exp a b) (zip subFunInTys argTys) + _ <- mapM (\(a,b) -> ensureEqualTyModCursor ddfs exp a b) (zip subFunInTys argTys) return subFunOutTy PrimAppE pr es -> do @@ -343,14 +343,14 @@ tcExp isSoA isPacked ddfs env exp = do bool_ops = do len2 - _ <- ensureEqualTyModCursor isSoA (es !! 0) BoolTy (tys !! 0) - _ <- ensureEqualTyModCursor isSoA (es !! 1) BoolTy (tys !! 1) + _ <- ensureEqualTyModCursor ddfs (es !! 0) BoolTy (tys !! 0) + _ <- ensureEqualTyModCursor ddfs (es !! 1) BoolTy (tys !! 1) pure BoolTy int_ops = do len2 - _ <- ensureEqualTyModCursor isSoA (es !! 0) IntTy (tys !! 0) - _ <- ensureEqualTyModCursor isSoA (es !! 1) IntTy (tys !! 1) + _ <- ensureEqualTyModCursor ddfs (es !! 0) IntTy (tys !! 0) + _ <- ensureEqualTyModCursor ddfs (es !! 1) IntTy (tys !! 1) pure IntTy float_ops = do @@ -361,8 +361,8 @@ tcExp isSoA isPacked ddfs env exp = do int_cmps = do len2 - _ <- ensureEqualTyModCursor isSoA (es !! 0) IntTy (tys !! 0) - _ <- ensureEqualTyModCursor isSoA (es !! 1) IntTy (tys !! 1) + _ <- ensureEqualTyModCursor ddfs (es !! 0) IntTy (tys !! 0) + _ <- ensureEqualTyModCursor ddfs (es !! 1) IntTy (tys !! 1) pure BoolTy float_cmps = do @@ -409,8 +409,8 @@ tcExp isSoA isPacked ddfs env exp = do EqSymP -> do len2 - _ <- ensureEqualTyModCursor isSoA (es !! 0) SymTy (tys !! 0) - _ <- ensureEqualTyModCursor isSoA (es !! 1) SymTy (tys !! 1) + _ <- ensureEqualTyModCursor ddfs (es !! 0) SymTy (tys !! 0) + _ <- ensureEqualTyModCursor ddfs (es !! 1) SymTy (tys !! 1) return BoolTy EqBenchProgP _ -> do @@ -521,7 +521,7 @@ tcExp isSoA isPacked ddfs env exp = do DictEmptyP _ty -> do len1 let [a] = tys - _ <- ensureEqualTyModCursor isSoA exp ArenaTy a + _ <- ensureEqualTyModCursor ddfs exp ArenaTy a let (VarE var) = es !! 0 return $ SymDictTy (Just var) CursorTy @@ -529,22 +529,22 @@ tcExp isSoA isPacked ddfs env exp = do len4 let [a,_d,k,v] = tys let (VarE var) = es !! 0 - _ <- ensureEqualTyModCursor isSoA exp ArenaTy a - _ <- ensureEqualTyModCursor isSoA exp SymTy k - _ <- ensureEqualTyModCursor isSoA exp CursorTy v + _ <- ensureEqualTyModCursor ddfs exp ArenaTy a + _ <- ensureEqualTyModCursor ddfs exp SymTy k + _ <- ensureEqualTyModCursor ddfs exp CursorTy v return $ SymDictTy (Just var) CursorTy DictLookupP _ty -> do len2 let [_d,k] = tys - _ <- ensureEqualTyModCursor isSoA exp SymTy k + _ <- ensureEqualTyModCursor ddfs exp SymTy k return CursorTy DictHasKeyP _ty -> do len2 let [_d,k] = tys -- _ <- ensureEqualTyNoLoc exp (SymDictTy ty) d - _ <- ensureEqualTyModCursor isSoA exp SymTy k + _ <- ensureEqualTyModCursor ddfs exp SymTy k return BoolTy ErrorP _str ty -> do @@ -561,7 +561,7 @@ tcExp isSoA isPacked ddfs env exp = do | PackedTy{} <- ty -> do len1 let [packed_ty] = tys - _ <- ensureEqualTyModCursor isSoA exp packed_ty ty + _ <- ensureEqualTyModCursor ddfs exp packed_ty ty pure (ProdTy []) | otherwise -> error $ "writePackedFile expects a packed type. Given" ++ sdoc ty @@ -802,7 +802,7 @@ tcExp isSoA isPacked ddfs env exp = do SymDictTy ar _ -> do unless (isJust ar) $ throwError $ GenericTC "Expected arena variable annotation" rhs let env' = extendEnv env [(v,SymDictTy ar CursorTy)] - tcExp isSoA isPacked ddfs env' e + tcExp isPacked ddfs env' e _ -> throwError $ GenericTC ("Expected expression to be SymDict type:" ++ sdoc rhs) exp @@ -811,7 +811,7 @@ tcExp isSoA isPacked ddfs env exp = do then throwError $ GenericTC ("Expected expression to be SymDict type:" ++ sdoc rhs) exp else do let env' = extendEnv env [(v, ty)] - tcExp isSoA isPacked ddfs env' e + tcExp isPacked ddfs env' e LetE (v,locs,ty,rhs) e -> do @@ -823,15 +823,15 @@ tcExp isSoA isPacked ddfs env exp = do exp -- Check RHS tyRhs <- go rhs - _ <- ensureEqualTyModCursor isSoA exp tyRhs ty + _ <- ensureEqualTyModCursor ddfs exp tyRhs ty let env' = extendEnv env [(v,ty)] -- Check body - tcExp isSoA isPacked ddfs env' e + tcExp isPacked ddfs env' e IfE tst consq alt -> do -- Check if the test is a boolean tyTst <- go tst - _ <- ensureEqualTyModCursor isSoA exp tyTst BoolTy + _ <- ensureEqualTyModCursor ddfs exp tyTst BoolTy -- Check if both branches match tyConsq <- go consq @@ -842,7 +842,7 @@ tcExp isSoA isPacked ddfs env exp = do -- then return tyConsq -- else throwError $ GenericTC ("If branches have mismatched types:" -- ++ sdoc tyConsq ++ ", " ++ sdoc tyAlt) exp - ensureEqualTyModCursor isSoA exp tyConsq tyAlt + ensureEqualTyModCursor ddfs exp tyConsq tyAlt MkProdE [] -> return $ ProdTy [] @@ -864,12 +864,12 @@ tcExp isSoA isPacked ddfs env exp = do CursorTy -> do when (tye /= CursorTy && not (isPackedTy tye)) $ throwError $ GenericTC ("Case scrutinee should be packed, or have a cursor type. Got" ++ sdoc tye) e - tcCases isSoA isPacked ddfs env cs + tcCases isPacked ddfs env cs CursorArrayTy size -> do when (tye /= (CursorArrayTy size) && not (isPackedTy tye)) $ throwError $ GenericTC ("Case scrutinee should be packed, or have a cursor type. Got" ++ sdoc tye ++ sdoc e) e - tcCases isSoA isPacked ddfs env cs - _ -> tcCases isSoA isPacked ddfs env cs + tcCases isPacked ddfs env cs + _ -> tcCases isPacked ddfs env cs oth -> throwError $ GenericTC ("Case branches have mismatched types: " ++ sdoc oth ++" , in " ++ sdoc exp) exp @@ -881,7 +881,7 @@ tcExp isSoA isPacked ddfs env exp = do then throwError $ GenericTC ("Invalid argument length: " ++ sdoc es) exp else do -- Check if arguments match with expected datacon types - sequence_ [ ensureEqualTyModCursor isSoA e ty1 ty2 + sequence_ [ ensureEqualTyModCursor ddfs e ty1 ty2 | (ty1,ty2,e) <- zip3 args tys es] return $ PackedTy dcTy loc @@ -896,7 +896,7 @@ tcExp isSoA isPacked ddfs env exp = do WithArenaE v e -> do let env' = extendVEnv v ArenaTy env - tcExp isSoA isPacked ddfs env' e + tcExp isPacked ddfs env' e MapE{} -> throwError $ UnsupportedExpTC exp FoldE{} -> throwError $ UnsupportedExpTC exp @@ -904,7 +904,7 @@ tcExp isSoA isPacked ddfs env exp = do -- oth -> error $ "L1.tcExp : TODO " ++ sdoc oth where - go = tcExp isSoA isPacked ddfs env + go = tcExp isPacked ddfs env checkListElemTy el_ty = if isValidListElemTy el_ty then pure () @@ -924,10 +924,8 @@ tcProg isPacked prg@Prog{ddefs,fundefs,mainExp} = do Hence we should not reply on the use of the dynflags to determine the memory layout of the packed types. -} - dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags -- Handle functions - mapM_ (fd useSoA) $ M.elems fundefs + mapM_ fd $ M.elems fundefs -- Handle main expression -- We don't change the type of mainExp to have cursors. So if it's type was `Packed`, @@ -936,7 +934,7 @@ tcProg isPacked prg@Prog{ddefs,fundefs,mainExp} = do case mainExp of Nothing -> return () Just (e,ty) -> - let res = runExcept $ tcExp useSoA isPacked ddefs env e + let res = runExcept $ tcExp isPacked ddefs env e in case res of Left err -> error $ sdoc err Right ty' -> if tyEq ty ty' @@ -966,11 +964,11 @@ tcProg isPacked prg@Prog{ddefs,fundefs,mainExp} = do _ -> ty1 == ty2 -- fd :: forall e l . FunDef Ty1 Exp -> PassM () - fd useSoA FunDef{funArgs,funTy,funBody} = do + fd FunDef{funArgs,funTy,funBody} = do let (intys, outty) = funTy venv = M.fromList (zip funArgs intys) env' = Env2 venv (fEnv env) - res = runExcept $ tcExp useSoA isPacked ddefs env' funBody + res = runExcept $ tcExp isPacked ddefs env' funBody case res of Left err -> error $ sdoc err Right ty -> if ty `compareModCursor` outty @@ -981,14 +979,14 @@ tcProg isPacked prg@Prog{ddefs,fundefs,mainExp} = do return () -tcCases :: Bool -> Bool -> DDefs3 -> Env2 Var Ty3 -> [(DataCon, [(Var, ())], Exp3)] -> TcM Ty3 (Exp3) -tcCases isSoA isPacked ddfs env cs = do +tcCases :: Bool -> DDefs3 -> Env2 Var Ty3 -> [(DataCon, [(Var, ())], Exp3)] -> TcM Ty3 (Exp3) +tcCases isPacked ddfs env cs = do tys <- forM cs $ \(c,args',rhs) -> do let args = L.map fst args' - targs = map (packedToCursor isSoA) $ lookupDataCon ddfs c + targs = map (packedToCursor ddfs) $ lookupDataCon ddfs c env' = extendEnv env (zip args targs) - tcExp isSoA isPacked ddfs env' rhs - foldM_ (\acc (ex,ty) -> ensureEqualTyModCursor isSoA ex ty acc) + tcExp isPacked ddfs env' rhs + foldM_ (\acc (ex,ty) -> ensureEqualTyModCursor ddfs ex ty acc) -- if ty == acc -- then return acc -- else throwError $ GenericTC ("Case branches have mismatched types: " @@ -1014,30 +1012,62 @@ ensureEqualTy :: Exp3 -> Ty3 -> Ty3 -> TcM Ty3 (Exp3) ensureEqualTy exp a b = ensureEqual exp ("Expected these types to be the same: " ++ (sdoc a) ++ " <> " ++ (sdoc b)) a b -{- VS: First bool is wheather to use an SoA cursor or not to -} -ensureEqualTyModCursor :: Bool -> Exp3 -> Ty3 -> Ty3 -> TcM Ty3 (Exp3) -ensureEqualTyModCursor False _exp CursorTy (PackedTy _ _) = return CursorTy -ensureEqualTyModCursor False _exp (PackedTy _ _) CursorTy = return CursorTy -ensureEqualTyModCursor False _exp IntTy CursorTy = return CursorTy -ensureEqualTyModCursor False _exp CursorTy IntTy = return CursorTy -ensureEqualTyModCursor False exp (ProdTy ls1) (ProdTy ls2) = - sequence_ [ ensureEqualTyModCursor False exp ty1 ty2 | (ty1,ty2) <- zip ls1 ls2] >>= \_ -> return (packedToCursor False (ProdTy ls1)) - -ensureEqualTyModCursor True _exp (CursorArrayTy sz) (PackedTy _ _) = return (CursorArrayTy sz) -ensureEqualTyModCursor True _exp (PackedTy _ _) (CursorArrayTy sz) = return (CursorArrayTy sz) -ensureEqualTyModCursor True _exp IntTy (CursorArrayTy sz) = return (CursorArrayTy sz) -ensureEqualTyModCursor True _exp (CursorArrayTy sz) IntTy = return (CursorArrayTy sz) -ensureEqualTyModCursor True exp (ProdTy ls1) (ProdTy ls2) = - sequence_ [ ensureEqualTyModCursor True exp ty1 ty2 | (ty1,ty2) <- zip ls1 ls2] >>= \_ -> return (packedToCursor True (ProdTy ls1)) -ensureEqualTyModCursor _s exp a b = ensureEqualTy exp a b - -{- This assumes that The CursorArrayTy always has size 2 -} -{- VS: we should ideally update the PackedTy type to have more information on its layout -} -packedToCursor :: Bool -> Ty3 -> Ty3 -packedToCursor False (PackedTy _ _) = CursorTy -packedToCursor True (PackedTy _ _) = CursorArrayTy 2 -packedToCursor s (ProdTy tys) = ProdTy $ map (\ty -> packedToCursor s ty) tys -packedToCursor _s ty = ty + +ensureEqualTyModCursor :: DDefs3 -> Exp3 -> Ty3 -> Ty3 -> TcM Ty3 (Exp3) +ensureEqualTyModCursor ddefs exp ty1 ty2 = case ty2 of + PackedTy tycon _ -> + let cursorTy = getCursorTypeFromTy tycon ddefs + in case cursorTy of + CursorTy -> case ty1 of + CursorTy -> return CursorTy + _ -> ensureEqualTy exp ty1 ty2 + CursorArrayTy{} -> case ty1 of + CursorArrayTy{} -> return ty1 + _ -> ensureEqualTy exp ty1 ty2 + _ -> ensureEqualTy exp ty1 ty2 + CursorTy -> case ty1 of + PackedTy{} -> return CursorTy + IntTy -> return CursorTy + _ -> ensureEqualTy exp ty1 ty2 + CursorArrayTy sz -> case ty1 of + PackedTy{} -> return (CursorArrayTy sz) + IntTy -> return (CursorArrayTy sz) + _ -> ensureEqualTy exp ty1 ty2 + IntTy -> case ty1 of + CursorTy -> return CursorTy + CursorArrayTy sz -> return $ CursorArrayTy sz + _ -> ensureEqualTy exp ty1 ty2 + (ProdTy ls1) -> case ty1 of + (ProdTy ls2) -> sequence_ [ ensureEqualTyModCursor ddefs exp ty1' ty2' | (ty1',ty2') <- zip ls1 ls2] >>= \_ -> return (packedToCursor ddefs (ProdTy ls1)) + _ -> ensureEqualTy exp ty1 ty2 + _ -> ensureEqualTy exp ty1 ty2 + +-- ensureEqualTyModCursor False _exp CursorTy (PackedTy _ _) = return CursorTy +-- ensureEqualTyModCursor False _exp (PackedTy _ _) CursorTy = return CursorTy +-- ensureEqualTyModCursor False _exp IntTy CursorTy = return CursorTy +-- ensureEqualTyModCursor False _exp CursorTy IntTy = return CursorTy + +-- ensureEqualTyModCursor False exp (ProdTy ls1) (ProdTy ls2) = +-- sequence_ [ ensureEqualTyModCursor False exp ty1 ty2 | (ty1,ty2) <- zip ls1 ls2] >>= \_ -> return (packedToCursor False (ProdTy ls1)) + +-- ensureEqualTyModCursor True _exp (CursorArrayTy sz) (PackedTy _ _) = return (CursorArrayTy sz) +-- ensureEqualTyModCursor True _exp (PackedTy _ _) (CursorArrayTy sz) = return (CursorArrayTy sz) +-- ensureEqualTyModCursor True _exp IntTy (CursorArrayTy sz) = return (CursorArrayTy sz) +-- ensureEqualTyModCursor True _exp (CursorArrayTy sz) IntTy = return (CursorArrayTy sz) + +-- ensureEqualTyModCursor True exp (ProdTy ls1) (ProdTy ls2) = +-- sequence_ [ ensureEqualTyModCursor True exp ty1 ty2 | (ty1,ty2) <- zip ls1 ls2] >>= \_ -> return (packedToCursor True (ProdTy ls1)) +-- ensureEqualTyModCursor _s exp a b = ensureEqualTy exp a b + +packedToCursor :: DDefs3 -> Ty3 -> Ty3 +packedToCursor ddefs (PackedTy tycon _) = let + cursorTy = getCursorTypeFromTy tycon ddefs + in case cursorTy of + CursorTy -> CursorTy + CursorArrayTy sz -> CursorArrayTy sz + _ -> CursorTy +packedToCursor _dd (ProdTy tys) = ProdTy $ map (\ty -> packedToCursor _dd ty) tys +packedToCursor _dd ty = ty compareModCursor :: Ty3 -> Ty3 -> Bool compareModCursor CursorTy (PackedTy _ _) = True diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index d3a3aab75..cd6135c36 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -17,7 +17,7 @@ module Gibbon.Language.Syntax DDefs, TyCon, Tag, IsBoxed, MemoryLayout(..), DDef(..) , lookupDDef, getConOrdering, getTyOfDataCon, lookupDataCon, lkp , lookupDataCon', insertDD, emptyDD, fromListDD, isVoidDDef, - getCursorTypeForDataCon + getCursorTypeForDataCon, getCursorTypeFromTy -- * Function definitions , FunctionTy(..), FunDefs, FunDef(..), FunMeta(..), FunRec(..), FunInline(..) @@ -198,6 +198,41 @@ getCursorTypeForDataCon _ddefs DDef{tyName, dataCons, memLayout} = in CursorArrayTy (numFieldBuffers + 1) _ -> error "Memory Layout is not implemented!" +getCursorTypeFromTy :: Out a => TyCon -> DDefs (UrTy a) -> UrTy a +getCursorTypeFromTy tycon ddefs = + let _ddef@DDef{tyName, dataCons, memLayout} = lookupDDef ddefs tycon + -- remove data constructors introduced by RAN + _dataCons' = concatMap (\e@(dcon, _) -> if ('^' `elem` dcon) + then [] + else [e] + ) dataCons + in case memLayout of + -- VS: For now, in the design we just always ensure + -- that a random access node is a CursorTy. + --_ -> CursorTy + Linear -> CursorTy + FullyFactored -> + let numFieldBuffers = foldr (\(dcon, _) c -> let fields = lookupDataCon ddefs dcon + c' = foldr (\ty c'' -> case ty of + PackedTy tycon' _ -> + if (toVar tycon') == tyName + then c'' + else + let ddef_for_tycon = lookupDDef ddefs tycon' + ty_of_packed_field = getCursorTypeForDataCon ddefs ddef_for_tycon + in case ty_of_packed_field of + CursorTy -> c'' + 1 + CursorArrayTy sz -> c'' + sz + _ -> error "Did not expect type" + CursorTy -> c'' + CursorArrayTy _ -> c'' + _ -> c'' + 1 + ) c fields + in c' + ) 0 _dataCons' + in CursorArrayTy (numFieldBuffers + 1) + _ -> error "Memory Layout is not implemented!" + insertDD :: DDef a -> DDefs a -> DDefs a insertDD d = M.insertWith err' (tyName d) d where diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 546217686..7af5decd5 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -123,8 +123,7 @@ data WindowIntoCursor = AoSWin Var | SoAWin Var [((DataCon, Int), Var)] cursorize :: Prog2 -> PassM Prog3 cursorize Prog {ddefs, fundefs, mainExp} = do dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags - fns' <- mapM (cursorizeFunDef useSoA ddefs fundefs . snd) (M.toList fundefs) + fns' <- mapM (cursorizeFunDef ddefs fundefs . snd) (M.toList fundefs) let fundefs' = M.fromList $ L.map (\f -> (funName f, f)) fns' ddefs' = M.map eraseLocMarkers ddefs @@ -205,15 +204,15 @@ handleIndexingSoARegCursors (arrLoc, arrName) (start, end) locvar var_env = do return (var_env, bnds ++ make_cur_arr_let) -cursorizeFunDef :: Bool -> DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 -cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do +cursorizeFunDef :: DDefs Ty2 -> FunDefs2 -> FunDef2 -> PassM FunDef3 +cursorizeFunDef ddefs fundefs FunDef {funName, funTy, funArgs, funBody, funMeta} = do let inLocs = inLocVars funTy outLocs = outLocVars funTy outRegs = outRegVars funTy inRegs = inRegVars funTy in_tys = arrIns funTy out_ty = arrOut funTy - funTy' = cursorizeArrowTy useSoA funTy + funTy' = cursorizeArrowTy funTy -- [2019.03.04] CSK: the order of these new cursor/region arguments isn't -- intuitive and can be improved. @@ -423,8 +422,8 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f (zip (map MkTy2 tys) [0 ..]) _ -> acc - cursorizeArrowTy :: Bool -> ArrowTy2 Ty2 -> ([Ty3], Ty3) - cursorizeArrowTy useSoA ty@ArrowTy2 {arrIns, arrOut, locVars, locRets} = + cursorizeArrowTy :: ArrowTy2 Ty2 -> ([Ty3], Ty3) + cursorizeArrowTy ty@ArrowTy2 {arrIns, arrOut, locVars, locRets} = let -- Regions corresponding to ouput cursors. (See [Threading regions]) numOutRegs = length (outRegVars ty) -- outRegs = L.map (\_ -> CursorTy) [1..numOutRegs] @@ -479,10 +478,10 @@ cursorizeFunDef useSoA ddefs fundefs FunDef {funName, funTy, funArgs, funBody, f -- Packed types in the input now become (read-only) cursors. - newIns = - if useSoA - then map (cursorizeInTy) in_tys - else map (constPacked CursorTy) in_tys + newIns = map (cursorizeInTy) in_tys + --if useSoA + --then map (cursorizeInTy) in_tys + --else map (constPacked CursorTy) in_tys in dbgTrace (minChatLvl) "Print in_tys" dbgTrace (minChatLvl) (sdoc (out_ty, in_tys)) dbgTrace (minChatLvl) "End in_tys\n" (map stripTyLocs newIns, stripTyLocs newOut') -- | Cursorize expressions NOT producing `Packed` values diff --git a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs index 7cc3ca32a..f944ca899 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferLocations.hs @@ -11,7 +11,8 @@ module Gibbon.Passes.InferLocations fresh, freshUnifyLoc, finalUnifyLoc, fixLoc, freshLocVar, finalLocVar, assocLoc, finishExp, prim, emptyEnv, -- main functions - unify, inferLocs, inferExp, inferExp', convertFunTy, copyOutOfOrderPacked, fixRANs, removeAliasesForCopyCalls) + unify, inferLocs, inferExp, inferExp', convertFunTy, copyOutOfOrderPacked, fixRANs, removeAliasesForCopyCalls + , filterRanDatacons) where {- @@ -105,7 +106,6 @@ import qualified Gibbon.L1.Syntax as L1 import Gibbon.L2.Syntax as L2 hiding (extendVEnv, extendsVEnv, lookupVEnv, lookupFEnv) import Gibbon.Passes.InlineTriv (inlineTriv) import Gibbon.Passes.Flatten (flattenL1) -import Gibbon.DynFlags -------------------------------------------------------------------------------- -- Environments @@ -141,12 +141,11 @@ lookupFEnv v FullEnv{funEnv} = funEnv # v convertFunTy :: DDefs1 -> ([Ty1],Ty1,Bool) -> PassM (ArrowTy2 Ty2) convertFunTy ddefs (from,to,isPar) = do dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags - from' <- mapM (convertTy ddefs useSoA) from - to' <- convertTy ddefs useSoA to + from' <- mapM (convertTy ddefs) from + to' <- convertTy ddefs to -- For this simple version, we assume every location is in a separate region: - lrm1 <- concat <$> mapM (toLRM useSoA Input) from' - lrm2 <- toLRM useSoA Output to' + lrm1 <- concat <$> mapM (toLRM Input) from' + lrm2 <- toLRM Output to' -- dbgTrace minChatLvl "convertFunTy: " dbgTrace minChatLvl (sdoc (from', to', lrm1, lrm2, useSoA)) dbgTrace minChatLvl "\n" dbgTrace minChatLvl "Print The data type definitions: " dbgTrace minChatLvl (sdoc (from', to')) dbgTrace minChatLvl "End print data type definitions.\n" return $ ArrowTy2 { locVars = lrm1 ++ lrm2 , arrIns = from' @@ -155,21 +154,18 @@ convertFunTy ddefs (from,to,isPar) = do , locRets = [] , hasParallelism = isPar } where - toLRM soa md ls = do - case soa of - True -> mapM (\v -> do - dataBufRegion <- freshLocVar "r" - case v of - Single _ -> do - regionForLoc <- freshRegVar - return $ LRM v regionForLoc md - SoA _ fieldLocs -> do - fieldRegions <- getSoARegionsFromLocs fieldLocs - let region = SoAR (VarR (unwrapLocVar dataBufRegion)) fieldRegions - return $ LRM v region md + toLRM md ls = do + mapM (\v -> do + dataBufRegion <- freshLocVar "r" + case v of + Single _ -> do + regionForLoc <- freshRegVar + return $ LRM v regionForLoc md + SoA _ fieldLocs -> do + fieldRegions <- getSoARegionsFromLocs fieldLocs + let region = SoAR (VarR (unwrapLocVar dataBufRegion)) fieldRegions + return $ LRM v region md ) (F.toList ls) - False -> mapM (\v -> do r <- freshLocVar "r" - return $ LRM v (VarR (unwrapLocVar r)) md) (F.toList ls) getSoARegionsFromLocs :: [((DataCon, Int), LocVar)] -> PassM [((DataCon, Int), Region)] getSoARegionsFromLocs locs = case locs of @@ -214,18 +210,19 @@ filterRanDatacons dcons = let to_ignore = map (\(dcon, ty) -> if L.isSuffixOf "^ in catMaybes buffered_dcon -convertTy :: DDefs1 -> Bool -> Ty1 -> PassM Ty2 -convertTy ddefs useSoA ty = case useSoA of - False -> traverse (const (freshLocVar "loc")) ty - True -> case ty of - PackedTy tycon _ -> do - dconBuff <- freshLocVar "loc" - let dcons = getConOrdering ddefs tycon - let dcons' = filterRanDcons dcons - locsForFields <- convertTyHelperSoAParent tycon ddefs dcons' - let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields - dbgTrace minChatLvl "Print ty: " dbgTrace minChatLvl (sdoc (PackedTy tycon soaLocation)) dbgTrace minChatLvl "End ty.\n" return $ PackedTy tycon soaLocation - _ -> traverse (const (freshLocVar "loc")) ty +convertTy :: DDefs1 -> Ty1 -> PassM Ty2 +convertTy ddefs ty = case ty of + PackedTy tycon _ -> do + case (getCursorTypeFromTy tycon ddefs) of + CursorArrayTy{} -> do + dconBuff <- freshLocVar "loc" + let dcons = getConOrdering ddefs tycon + let dcons' = filterRanDcons dcons + locsForFields <- convertTyHelperSoAParent tycon ddefs dcons' + let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields + dbgTrace minChatLvl "Print ty: " dbgTrace minChatLvl (sdoc (PackedTy tycon soaLocation)) dbgTrace minChatLvl "End ty.\n" return $ PackedTy tycon soaLocation + _ -> traverse (const (freshLocVar "loc")) ty + _ -> traverse (const (freshLocVar "loc")) ty convertTyHelperSoAParent :: TyCon -> DDefs1 -> [DataCon] -> PassM [((DataCon, Int), LocVar)] convertTyHelperSoAParent tycon ddefs dcons = do @@ -263,11 +260,21 @@ convertTyHelperSoAChild tycon ddefs dcon = do if tycon == tycon' then return (flds, idx + 1) else do - dconBuff <- freshLocVar "loc" - let dcons = filterRanDcons $ getConOrdering ddefs tycon' - locsForFields <- convertTyHelperSoAParent tycon' ddefs dcons - let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields - return (flds ++ [((dcon, idx), soaLocation)], idx + 1) + -- we need to check the annotation attached with + -- the data type here and change the memory + -- representation accordingly. + let curTy = getCursorTypeFromTy tycon' ddefs + case curTy of + CursorArrayTy{} -> do + dconBuff <- freshLocVar "loc" + let dcons = filterRanDcons $ getConOrdering ddefs tycon' + locsForFields <- convertTyHelperSoAParent tycon' ddefs dcons + let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields + return (flds ++ [((dcon, idx), soaLocation)], idx + 1) + _ -> do + fldLoc <- freshLocVar "fldloc" + return (flds ++ [((dcon, idx), fldLoc)], idx + 1) + -- For ran pointers, we are skipping making buffers for them. CursorTy -> return (flds, idx + 1) CursorArrayTy _ -> return (flds, idx + 1) @@ -304,10 +311,9 @@ convertDDefs ddefs = traverse f ddefs -- in order to check the layout where f (DDef tyargs n dcs layout) = do dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags dcs' <- forM dcs $ \(dc,bnds) -> do bnds' <- forM bnds $ \(isb,ty) -> do - ty' <- convertTy ddefs useSoA ty + ty' <- convertTy ddefs ty return (isb, ty') return (dc,bnds') return $ DDef tyargs n dcs' layout @@ -439,11 +445,10 @@ destFromType' frt = freshTyLocs :: Ty2 -> DDefs1 -> TiM Ty2 freshTyLocs ty ddefs = do - dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags + dflags <- getDynFlags case ty of - PackedTy tc lv -> if useSoA - then do + PackedTy tc lv -> case (getCursorTypeFromTy tc ddefs) of + CursorArrayTy{} -> case lv of SoA dbuf rst -> do --dbuf' <- fresh @@ -458,7 +463,7 @@ freshTyLocs ty ddefs = do Single _ -> do freshLoc <- fresh return $ PackedTy tc freshLoc - else do fresh >>= return . PackedTy tc + _ -> fresh >>= return . PackedTy tc ProdTy tys -> mapM (\ty -> freshTyLocs ty ddefs) tys >>= return . ProdTy _ -> return ty @@ -862,14 +867,13 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = doCase ddfs env src dst (con,vars,rhs) = do let (_tyc, (_don, flds)) = lkp ddfs con dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags let zippedVars = zip vars flds vars' <- forM zippedVars $ \((v,_), (_, t)) -> do case t of PackedTy ty _ -> do - lv <- if useSoA - then freshSoALoc2 ddfs ty - else lift $ lift $ freshLocVar "case" + lv <- case (getCursorTypeFromTy ty ddfs) of + CursorArrayTy{} -> freshSoALoc2 ddfs ty + _ -> lift $ lift $ freshLocVar "case" _ <- fixLoc lv return (v,lv) @@ -1214,7 +1218,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = {- TODO: should we just using assign loc instead of afterconstant? -} {- Con: it might be tougher to typecheck constraints -} afterVar ((ArgFixed 0), (Just loc1), (Just loc2)) = case loc1 of - (Single _) -> Just $ AfterConstantL loc1 0 loc2 + --(Single _) -> Just $ AfterConstantL loc1 0 loc2 _ -> Just $ AssignL loc1 loc2 afterVar ((ArgFixed s), (Just loc1), (Just loc2)) = Just $ AfterConstantL loc1 s loc2 @@ -1337,7 +1341,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = else [] ) fields_hloc let fieldConstraints_unsed = map (\(k, loc_new, loc_old) -> case loc_new of - Single _ -> AfterConstantL loc_new 0 loc_old + --Single _ -> AfterConstantL loc_new 0 loc_old _ -> AssignL loc_new loc_old ) pair_new_old @@ -1423,7 +1427,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = else [] ) fields_hloc let fieldConstraints_unsed = map (\(k, loc_new, loc_old) -> case loc_new of - Single _ -> AfterConstantL loc_new 0 loc_old + --Single _ -> AfterConstantL loc_new 0 loc_old _ -> AssignL loc_new loc_old ) pair_new_old let afvarc = (mapMaybe afterVar $ zip3 @@ -1517,7 +1521,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = TupleDest _ -> err "Cannot unify DictInsert with destination" NoDest -> do (d',SymDictTy ar dty',_dcs) <- inferExp ddefs env d NoDest (k',_,_kcs) <- inferExp ddefs env k NoDest - dty'' <- lift $ lift $ convertTy ddefs False dty + dty'' <- lift $ lift $ convertTy ddefs dty r <- lift $ lift $ freshRegVar loc <- lift $ lift $ freshLocVar "ins" -- _ <- fixLoc loc @@ -1530,7 +1534,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = case dest of SingleDest loc -> do (d',SymDictTy _ _dty,_dcs) <- inferExp ddefs env d NoDest (k',_,_kcs) <- inferExp ddefs env k NoDest - dty' <- lift $ lift $ convertTy ddefs False dty + dty' <- lift $ lift $ convertTy ddefs dty let loc' = locOfTy dty' _ <- fixLoc loc' let e' = PrimAppE (DictLookupP dty') [d',k'] @@ -1545,7 +1549,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = case dest of SingleDest _ -> err "Cannot unify DictEmpty with destination" TupleDest _ -> err "Cannot unify DictEmpty with destination" - NoDest -> do dty' <- lift $ lift $ convertTy ddefs False dty + NoDest -> do dty' <- lift $ lift $ convertTy ddefs dty return (PrimAppE (DictEmptyP dty') [(VarE var)], SymDictTy (Just var) $ stripTyLocs dty', []) PrimAppE (DictHasKeyP dty) [d,k] -> @@ -1566,7 +1570,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = NoDest -> do results <- mapM (\e -> inferExp ddefs env e NoDest) [VarE ls] -- Assume arguments to PrimAppE are trivial -- so there's no need to deal with constraints or locations - ty <- lift $ lift $ convertTy ddefs False $ primRetTy pr + ty <- lift $ lift $ convertTy ddefs $ primRetTy pr pr' <- lift $ lift $ prim ddefs pr let args = [a | (a,_,_) <- results] ++ [VarE fp] return (PrimAppE pr' args, ty, []) @@ -1585,7 +1589,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = NoDest -> do results <- mapM (\e -> inferExp ddefs env e NoDest) es -- Assume arguments to PrimAppE are trivial -- so there's no need to deal with constraints or locations - ty <- lift $ lift $ convertTy ddefs False $ primRetTy pr + ty <- lift $ lift $ convertTy ddefs $ primRetTy pr pr' <- lift $ lift $ prim ddefs pr return (PrimAppE pr' [a | (a,_,_) <- results], ty, []) @@ -1698,7 +1702,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = PrimAppE (WritePackedFile fp _ty0) [VarE packd] -> do - bty' <- lift $ lift $ convertTy ddefs False bty + bty' <- lift $ lift $ convertTy ddefs bty (bod',ty',cs') <- inferExp ddefs (extendVEnv vr bty' env) bod dest (bod'',ty'',cs'') <- handleTrailingBindLoc vr (bod', ty', cs') fcs <- tryInRegion cs'' @@ -1712,8 +1716,8 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = PrimAppE (ReadArrayFile fp ty0) [] -> do - ty <- lift $ lift $ convertTy ddefs False bty - ty0' <- lift $ lift $ convertTy ddefs False ty0 + ty <- lift $ lift $ convertTy ddefs bty + ty0' <- lift $ lift $ convertTy ddefs ty0 (bod',ty',cs') <- inferExp ddefs (extendVEnv vr ty env) bod dest (bod'',ty'',cs''') <- handleTrailingBindLoc vr (bod', ty', cs') fcs <- tryInRegion cs''' @@ -1757,7 +1761,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- the type environment. PrimAppE p@(VSortP ty) [VarE ls, VarE fp] -> do lsrec <- mapM (\e -> inferExp ddefs env e NoDest) [VarE ls] - ty <- lift $ lift $ convertTy ddefs False bty + ty <- lift $ lift $ convertTy ddefs bty (bod',ty',cs') <- inferExp ddefs (extendVEnv vr ty env) bod dest let ls' = [a | (a,_,_) <- lsrec] ++ [VarE fp] cs'' = concat $ [c | (_,_,c) <- lsrec] @@ -1768,7 +1772,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = PrimAppE p ls -> do lsrec <- mapM (\e -> inferExp ddefs env e NoDest) ls - ty <- lift $ lift $ convertTy ddefs False bty + ty <- lift $ lift $ convertTy ddefs bty (bod',ty',cs') <- inferExp ddefs (extendVEnv vr ty env) bod dest let ls' = [a | (a,_,_) <- lsrec] cs'' = concat $ [c | (_,_,c) <- lsrec] @@ -1779,16 +1783,15 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = DataConE _loc k ls -> do dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags (_, locTy) <- case bty of - PackedTy tcon _ -> if useSoA - then do - lc1 <- freshSoALoc3 "datacon" (Just k) ddefs tcon - lc2 <- freshSoALoc3 "datacon" Nothing ddefs tcon - return (lc1, lc2) - else do - lcd <- lift $ lift $ freshLocVar "datacon" - return $ (lcd, lcd) + PackedTy tcon _ -> case (getCursorTypeFromTy tcon ddefs) of + CursorArrayTy{} -> do + lc1 <- freshSoALoc3 "datacon" (Just k) ddefs tcon + lc2 <- freshSoALoc3 "datacon" Nothing ddefs tcon + return (lc1, lc2) + _ -> do + lcd <- lift $ lift $ freshLocVar "datacon" + return $ (lcd, lcd) _ -> do lcd <- lift $ lift $ freshLocVar "datacon" return (lcd, lcd) @@ -1822,15 +1825,15 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = CaseE ex ls -> do dflags <- getDynFlags - let useSoA = gopt Opt_Packed_SoA dflags loc <- case bty of - PackedTy tcon _ -> if useSoA - then freshSoALoc3 "datacon" Nothing ddefs tcon - else lift $ lift $ freshLocVar "datacon" + PackedTy tcon _ -> case (getCursorTypeFromTy tcon ddefs) of + CursorArrayTy{} -> freshSoALoc3 "datacon" Nothing ddefs tcon + CursorTy -> lift $ lift $ freshLocVar "datacon" + _ -> error "did not expect cursor type for packed expression!" _ -> lift $ lift $ freshLocVar "datacon" (ex',ty2,cs) <- inferExp ddefs env ex (SingleDest loc) let src = locOfTy ty2 - rhsTy <- lift $ lift $ convertTy ddefs False bty + rhsTy <- lift $ lift $ convertTy ddefs bty caseDest <- destFromType' rhsTy pairs <- mapM (doCase dataDefs env src caseDest) ls (bod',ty',cs') <- inferExp ddefs (extendVEnv vr rhsTy env) bod dest @@ -1849,7 +1852,7 @@ inferExp ddefs env@FullEnv{dataDefs} ex0 dest = -- variable reference (because of ANF), and the AppE/DataConE cases -- above will do the right thing. lsrec <- mapM (\e -> inferExp ddefs env e NoDest) ls - ty@(ProdTy tys) <- lift $ lift $ convertTy ddefs False bty + ty@(ProdTy tys) <- lift $ lift $ convertTy ddefs bty let env' = extendVEnv vr ty env (bod',ty',cs') <- inferExp ddefs env' bod dest let als = [a | (a,_,_) <- lsrec] @@ -2155,6 +2158,7 @@ cleanExp e = AfterConstantLE _i lv -> [lv] AfterVariableLE _v lv _ -> [lv] GetFieldLocSoA _ lv -> [lv] + AssignLE lv -> [lv] oth -> [] in (Ext (LetLocE loc lex e'), S.delete loc (S.union s' $ S.fromList ls)) else (e',s') @@ -2492,10 +2496,18 @@ freshSoALocHelper ddefs tyvar lst = do if tyvar == tyc then return [] else do - {- TODO: we should return an SoA loc here instead -} - newLoc <- freshSoALoc2 ddefs tyc - let Just idx = L.elemIndex e flds - return $ [((a, idx), newLoc)] + -- determine the type of the location + -- from the meta-data + let cursorTy = getCursorTypeFromTy tyc ddefs + case cursorTy of + CursorArrayTy{} -> do + newLoc <- freshSoALoc2 ddefs tyc + let Just idx = L.elemIndex e flds + return $ [((a, idx), newLoc)] + _ -> do + newLoc <- fresh + let Just idx = L.elemIndex e flds + return $ [((a, idx), newLoc)] -- no new buffers for shortcut pointers CursorTy -> return [] CursorArrayTy{} -> return [] @@ -2698,40 +2710,40 @@ prim ddefs p = case p of PrintSym -> return PrintSym ReadInt -> return PrintInt RequestSizeOf -> return RequestSizeOf - ErrorP sty ty -> convertTy ddefs False ty >>= \ty -> return (ErrorP sty ty) - DictEmptyP dty -> convertTy ddefs False dty >>= return . DictEmptyP - DictInsertP dty -> convertTy ddefs False dty >>= return . DictInsertP - DictLookupP dty -> convertTy ddefs False dty >>= return . DictLookupP - DictHasKeyP dty -> convertTy ddefs False dty >>= return . DictHasKeyP - VAllocP elty -> convertTy ddefs False elty >>= return . VAllocP - VFreeP elty -> convertTy ddefs False elty >>= return . VFreeP - VFree2P elty -> convertTy ddefs False elty >>= return . VFree2P - VLengthP elty -> convertTy ddefs False elty >>= return . VLengthP - VNthP elty -> convertTy ddefs False elty >>= return . VNthP - VSliceP elty -> convertTy ddefs False elty >>= return . VSliceP - InplaceVUpdateP elty -> convertTy ddefs False elty >>= return . InplaceVUpdateP - VConcatP elty -> convertTy ddefs False elty >>= return . VConcatP - VSortP elty -> convertTy ddefs False elty >>= return . VSortP - VMergeP elty -> convertTy ddefs False elty >>= return . VMergeP - PDictAllocP k v -> convertTy ddefs False k >>= (\k' -> convertTy ddefs False v >>= \v' -> return $ PDictAllocP k' v') - PDictInsertP k v -> convertTy ddefs False k >>= (\k' -> convertTy ddefs False v >>= \v' -> return $ PDictInsertP k' v') - PDictLookupP k v -> convertTy ddefs False k >>= (\k' -> convertTy ddefs False v >>= \v' -> return $ PDictLookupP k' v') - PDictHasKeyP k v -> convertTy ddefs False k >>= (\k' -> convertTy ddefs False v >>= \v' -> return $ PDictHasKeyP k' v') - PDictForkP k v -> convertTy ddefs False k >>= (\k' -> convertTy ddefs False v >>= \v' -> return $ PDictForkP k' v') - PDictJoinP k v -> convertTy ddefs False k >>= (\k' -> convertTy ddefs False v >>= \v' -> return $ PDictJoinP k' v') - LLAllocP elty -> convertTy ddefs False elty >>= return . LLAllocP - LLIsEmptyP elty -> convertTy ddefs False elty >>= return . LLIsEmptyP - LLConsP elty -> convertTy ddefs False elty >>= return . LLConsP - LLHeadP elty -> convertTy ddefs False elty >>= return . LLHeadP - LLTailP elty -> convertTy ddefs False elty >>= return . LLTailP - LLFreeP elty -> convertTy ddefs False elty >>= return . LLFreeP - LLFree2P elty -> convertTy ddefs False elty >>= return . LLFree2P - LLCopyP elty -> convertTy ddefs False elty >>= return . LLCopyP - InplaceVSortP elty -> convertTy ddefs False elty >>= return . InplaceVSortP + ErrorP sty ty -> convertTy ddefs ty >>= \ty -> return (ErrorP sty ty) + DictEmptyP dty -> convertTy ddefs dty >>= return . DictEmptyP + DictInsertP dty -> convertTy ddefs dty >>= return . DictInsertP + DictLookupP dty -> convertTy ddefs dty >>= return . DictLookupP + DictHasKeyP dty -> convertTy ddefs dty >>= return . DictHasKeyP + VAllocP elty -> convertTy ddefs elty >>= return . VAllocP + VFreeP elty -> convertTy ddefs elty >>= return . VFreeP + VFree2P elty -> convertTy ddefs elty >>= return . VFree2P + VLengthP elty -> convertTy ddefs elty >>= return . VLengthP + VNthP elty -> convertTy ddefs elty >>= return . VNthP + VSliceP elty -> convertTy ddefs elty >>= return . VSliceP + InplaceVUpdateP elty -> convertTy ddefs elty >>= return . InplaceVUpdateP + VConcatP elty -> convertTy ddefs elty >>= return . VConcatP + VSortP elty -> convertTy ddefs elty >>= return . VSortP + VMergeP elty -> convertTy ddefs elty >>= return . VMergeP + PDictAllocP k v -> convertTy ddefs k >>= (\k' -> convertTy ddefs v >>= \v' -> return $ PDictAllocP k' v') + PDictInsertP k v -> convertTy ddefs k >>= (\k' -> convertTy ddefs v >>= \v' -> return $ PDictInsertP k' v') + PDictLookupP k v -> convertTy ddefs k >>= (\k' -> convertTy ddefs v >>= \v' -> return $ PDictLookupP k' v') + PDictHasKeyP k v -> convertTy ddefs k >>= (\k' -> convertTy ddefs v >>= \v' -> return $ PDictHasKeyP k' v') + PDictForkP k v -> convertTy ddefs k >>= (\k' -> convertTy ddefs v >>= \v' -> return $ PDictForkP k' v') + PDictJoinP k v -> convertTy ddefs k >>= (\k' -> convertTy ddefs v >>= \v' -> return $ PDictJoinP k' v') + LLAllocP elty -> convertTy ddefs elty >>= return . LLAllocP + LLIsEmptyP elty -> convertTy ddefs elty >>= return . LLIsEmptyP + LLConsP elty -> convertTy ddefs elty >>= return . LLConsP + LLHeadP elty -> convertTy ddefs elty >>= return . LLHeadP + LLTailP elty -> convertTy ddefs elty >>= return . LLTailP + LLFreeP elty -> convertTy ddefs elty >>= return . LLFreeP + LLFree2P elty -> convertTy ddefs elty >>= return . LLFree2P + LLCopyP elty -> convertTy ddefs elty >>= return . LLCopyP + InplaceVSortP elty -> convertTy ddefs elty >>= return . InplaceVSortP GetNumProcessors -> pure GetNumProcessors ReadPackedFile{} -> err $ "Can't handle this primop yet in InferLocations:\n"++show p ReadArrayFile{} -> err $ "Can't handle this primop yet in InferLocations:\n"++show p - WritePackedFile fp ty -> convertTy ddefs False ty >>= return . (WritePackedFile fp) + WritePackedFile fp ty -> convertTy ddefs ty >>= return . (WritePackedFile fp) SymSetEmpty{} -> return SymSetEmpty SymSetInsert{} -> return SymSetInsert SymSetContains{} -> return SymSetContains diff --git a/gibbon-compiler/src/Gibbon/Passes/ReorderScalarWrites.hs b/gibbon-compiler/src/Gibbon/Passes/ReorderScalarWrites.hs index 61a7d3864..3eaf02ea0 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ReorderScalarWrites.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ReorderScalarWrites.hs @@ -108,7 +108,7 @@ writeOrderMarkers (Prog ddefs fundefs mainExp) = do then (LetE (v,locs,ty,rhs)) <$> (go reg_env' alloc_env' store_env env2' bod) else do let tag_loc = Sf.headErr locs_before - let tag_tycon = findTyCon tag_loc bod + let tag_tycon = dbgTrace (minChatLvl) "Print Tag_Loc reorder scalars: " dbgTrace (minChatLvl) (sdoc (tag_loc, locs_before, one, ex)) dbgTrace (minChatLvl) "End printing tag_loc!!\n" findTyCon tag_loc bod let in_scope = M.keysSet (vEnv env2) `S.union` M.keysSet (fEnv env2) (move_set,move_scalars) = checkScalarDeps ddefs in_scope tag_loc ex move_scalars_easy = move_scalars && S.null move_set @@ -248,11 +248,11 @@ writeOrderMarkers (Prog ddefs fundefs mainExp) = do let locs_before = takeWhile (/= loc) locs in case locs_before of [] -> let ret = (True, locs_before, reg, rloc) - in ret + in dbgTrace (minChatLvl) "Print in isAllocationOK [] : " dbgTrace (minChatLvl) (sdoc (loc, locs, locs_before)) dbgTrace (minChatLvl) "End isAllocationOK\n" ret _ -> let freev = L2.allFreeVars rhs `S.union` L2.allFreeVars bod locs_before' = filter (\x -> S.member (fromLocVarToFreeVarsTy x) freev) locs_before - in (S.isProperSubsetOf (S.fromList locs_before') allocated_to, locs_before', reg, rloc) + in dbgTrace (minChatLvl) "Print in isAllocationOK _: " dbgTrace (minChatLvl) (sdoc (loc, locs, locs_before)) dbgTrace (minChatLvl) "End isAllocationOK\n" (S.isProperSubsetOf (S.fromList locs_before') allocated_to, locs_before', reg, rloc) -- dbgTraceIt "Print in isAllocationOk: " dbgTraceIt (sdoc (loc, rhs, locs_before, locs_before', allocated_to)) dbgTraceIt "End isAllocationOk.\n" findTyCon :: LocVar -> L2.Exp2 -> TyCon diff --git a/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs b/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs index 489cf39f5..5a1349f07 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs @@ -44,6 +44,7 @@ import Gibbon.L2.Syntax as L2 import Gibbon.L1.Syntax as L1 import GHC.Generics import Text.PrettyPrint.GenericPretty +import Gibbon.Passes.InferLocations (filterRanDatacons) -- | Data structure that accumulates what we know about the relationship @@ -312,7 +313,7 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do _ -> lenv (outlocs,newls,eor') <- doBoundApp f lsin - let (e2', inst_waiting_on_loc', rel) = wrapBody f e2 newls inst_waiting_on_loc + let (e2', inst_waiting_on_loc', rel) = wrapBody ddefs f e2 newls inst_waiting_on_loc e2'' <- exp inst_waiting_on_loc' fns retlocs eor' lenv' afterenv (extendVEnvLocVar (fromVarToFreeVarsTy v) ty env2) e2' let expr = dbgTrace (minChatLvl) "Print insts_waiting_on_loc: " dbgTrace (minChatLvl) (sdoc (newls, (v,_ls,ty,(AppE f lsin e1)), inst_waiting_on_loc', rel)) dbgTrace (minChatLvl) "End print insts waiting on loc.\n" LetE (v,outlocs,ty, AppE f lsin e1) e2'' @@ -327,7 +328,7 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do PackedTy _n l -> M.insert (fromVarToFreeVarsTy v) l lenv _ -> lenv (outlocs,newls,eor') <- doBoundApp f lsin - let (e2', inst_waiting_on_loc', rel) = wrapBody f e2 newls inst_waiting_on_loc + let (e2', inst_waiting_on_loc', rel) = wrapBody ddefs f e2 newls inst_waiting_on_loc e2'' <- exp inst_waiting_on_loc' fns retlocs eor' lenv' afterenv (extendVEnvLocVar (fromVarToFreeVarsTy v) ty env2) e2' return $ LetE (v,outlocs,ty, SpawnE f lsin e1) e2'' @@ -754,13 +755,13 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do -- We may need to emit some additional let bindings if we've reached -- an end witness that is equivalent to the after location of something. - wrapBody f e ((l1,l2):ls) inst_waiting_on_loc = + wrapBody ddefs f e ((l1,l2):ls) inst_waiting_on_loc = case M.lookup (fromLocVarToFreeVarsTy l1) afterenv of Nothing -> let let_to_release = case (M.lookup l1 inst_waiting_on_loc) of Just lets -> lets Nothing -> [] inst_waiting_on_loc' = M.delete l1 inst_waiting_on_loc - (e'', inst_waiting_on_loc'', let_to_release') = wrapBody f e ls inst_waiting_on_loc' + (e'', inst_waiting_on_loc'', let_to_release') = wrapBody ddefs f e ls inst_waiting_on_loc' in (e'', inst_waiting_on_loc'', let_to_release ++ let_to_release') Just la -> let go loc acc = @@ -802,9 +803,9 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do Nothing -> [] in (Ext (LetLocE la (FromEndLE l2) bod'), inst_waiting_on_loc, let_to_release) else - let same_ty_loc = findSubSetLoc la l2 + let same_ty_loc = findSubSetLoc ddefs tycon tycon' la l2 in case same_ty_loc of - Nothing -> error $ "RouteEnds: could not find same loc for: " ++ show (l2, la) + Nothing -> error $ "RouteEnds: could not find same loc for: " ++ show (l1, l2, la) Just l2loc -> let alias_same = [LetLocE l2loc (FromEndLE l2)] gen_soa = GenSoALoc (getDconLoc la) flocs @@ -831,13 +832,13 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do Nothing -> (Ext (LetLocE la (FromEndLE l2) bod'), inst_waiting_on_loc, []) _ -> (Ext (LetLocE la (FromEndLE l2) bod'), inst_waiting_on_loc, []) Nothing -> (Ext (LetLocE la (FromEndLE l2) bod'), inst_waiting_on_loc, []) - (bod''', inst_waiting_on_loc'', rel) = wrapBody f bod'' ls inst_waiting_on_loc' + (bod''', inst_waiting_on_loc'', rel) = wrapBody ddefs f bod'' ls inst_waiting_on_loc' in (bod''', M.unionWith (++) inst_waiting_on_loc' inst_waiting_on_loc'', rels ++ rel) else let bod'' = Ext (LetLocE la (FromEndLE l2) bod') - (bod''', inst_waiting_on_loc', rel) = wrapBody f bod'' ls inst_waiting_on_loc + (bod''', inst_waiting_on_loc', rel) = wrapBody ddefs f bod'' ls inst_waiting_on_loc in (bod''', M.unionWith (++) inst_waiting_on_loc' inst_waiting_on_loc, rel) - wrapBody f e [] inst_waiting_on_loc = (e, inst_waiting_on_loc, []) + wrapBody ddefs f e [] inst_waiting_on_loc = (e, inst_waiting_on_loc, []) -- Process a let bound fn app. doBoundApp :: Var -> [LocVar] -> PassM ([LocVar], [(LocVar, LocVar)], EndOfRel) @@ -868,13 +869,30 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do isSubset :: String -> String -> Bool isSubset subset str = all (`elem` str) (L.nub subset) -findSubSetLoc :: LocVar -> LocVar -> Maybe LocVar -findSubSetLoc l1@(SoA dloc1 flocs1) l2@(SoA dloc2 flocs2) = if l1 == l2 then Just l1 - else checkIfFieldLocInLoc flocs1 l2 -findSubSetLoc l1@(SoA dloc1 flocs1) l2@(Single dloc2) = Nothing -findSubSetLoc l1@(Single _) l2@(SoA _ _) = Nothing -findSubSetLoc l1@(Single dloc1) l2@(Single dloc2) = if l1 == l2 then Just l1 - else Nothing +findSubSetLoc :: DDefs2 -> TyCon -> TyCon -> LocVar -> LocVar -> Maybe LocVar +findSubSetLoc ddefs ptycon tycon l1@(SoA dloc1 flocs1) l2@(SoA dloc2 flocs2) = if l1 == l2 + then Just l1 + else checkIfFieldLocInLoc flocs1 l2 +findSubSetLoc ddefs ptycon tycon l1@(SoA dloc1 flocs1) l2@(Single dloc2) = let ddef_par@DDef{dataCons} = lookupDDef ddefs ptycon + dataCons' = filterRanDatacons dataCons + res = L.foldr (\(d, flds) acc -> let res = L.foldr (\s@(_, ty) acc -> case ty of + PackedTy t _ -> if t == tycon + then Just (d, fromJust $ L.elemIndex s flds) + else acc + _ -> acc + ) Nothing flds + in case res of + Nothing -> acc + Just s -> Just s + ) Nothing dataCons' + in case res of + Nothing -> error "Could not find location for end!" + Just x -> let l = dbgTrace (minChatLvl) "Tried looking: " dbgTrace (minChatLvl) (sdoc (x)) dbgTrace (minChatLvl) "End Tried looking!\n" L.lookup x flocs1 + in l +findSubSetLoc ddefs ptycon tycon l1@(Single _) l2@(SoA _ _) = Nothing +findSubSetLoc ddefs ptycon tycon l1@(Single dloc1) l2@(Single dloc2) = if l1 == l2 + then Just l1 + else Nothing diff --git a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs index 990f38f2e..ea80a9813 100644 --- a/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs +++ b/gibbon-compiler/src/Gibbon/Passes/ThreadRegions2.hs @@ -1028,7 +1028,11 @@ threadRegionsExp ddefs fundefs fnLocArgs renv env2 lfenv rlocs_env wlocs_env pkd region_locs1 (zip locs [0 .. length (locs)]) in acc' - num_cursor_tys = dbgTrace (minChatLvl) "print in doCase (renv0): " dbgTrace (minChatLvl) (sdoc (renv1'', renv0, region_locs1')) dbgTrace (minChatLvl) "End doCase (renv0).\n" length $ filter ((== CursorTy) . unTy2) dcon_tys + num_cursor_tys = dbgTrace (minChatLvl) "print in doCase (renv0): " dbgTrace (minChatLvl) (sdoc (renv1'', renv0, region_locs1')) dbgTrace (minChatLvl) "End doCase (renv0).\n" length $ filter (\t -> case (unTy2 t) of -- (== CursorTy) . unTy2 + CursorTy -> True + CursorArrayTy{} -> True + _ -> False + ) dcon_tys ran_env1' = ran_env1 `M.union` ( if isIndirectionTag dcon || isRedirectionTag dcon From 7c0a4abaac7c5b5b99cbd88e386020a94119f7eb Mon Sep 17 00:00:00 2001 From: vidush Date: Wed, 29 Oct 2025 17:38:46 -0400 Subject: [PATCH 51/60] fix bugs --- .../examples/soa_examples/packedList.hs | 4 +-- .../examples/soa_examples/packedTree.hs | 8 ++--- .../src/Gibbon/Passes/Cursorize.hs | 35 +++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index 4a32aeadf..0eb74d00d 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -1,7 +1,7 @@ data PackedInt = PacI Int data List = Cons Int PackedInt List | Nil -{-# ANN type PackedInt "Factored" #-} -{-# ANN type List "Linear" #-} +{-# ANN type PackedInt "Linear" #-} +{-# ANN type List "Factored" #-} addPackedInt' :: PackedInt -> Int -> PackedInt addPackedInt' a b = case a of diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index f260e9065..af5dfccb4 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -1,7 +1,7 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf -{-# ANN type Tree "Factored" #-} +{-# ANN type Tree "Linear" #-} {-# ANN type List "Linear" #-} {-# ANN type FloatList "Linear" #-} @@ -18,7 +18,7 @@ mkFloatList len = if len <= 0 mkTree :: Int -> Tree mkTree d = if (d <= 0) then Leaf - else Node d 1.0 (mkFloatList 1000) (mkList 1000) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) + else Node d 1.0 (mkFloatList 10000) (mkList 10000) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) rightMostTree :: Tree -> Int @@ -87,8 +87,8 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = mkTree 10 - tree' = id (add1Tree tree) + let tree = mkTree 8 + tree' = iterate (add1Tree tree) val = iterate (sumTree tree) r = iterate (rightMostTree tree') in val + r diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 7af5decd5..f94cd192c 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -1737,6 +1737,9 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = if present then [] else [(sloc_dcon, [], CursorTy, Ext $ IndexCursorArray sloc 0)] + + -- Vidush + -- Check the index logic might not be robust here. (additional_bnds', freeVarToVarEnv'', _) <- foldlM ( \(b, env, idx') ((_, _), loc) -> do @@ -2370,7 +2373,9 @@ cursorizeLocExp freeVarToVarEnv denv tenv senv lvar locExp = Just v -> v Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show locExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv (rhs, additional_lets) <- case field_loc of - Single{} -> return $ (Ext $ IndexCursorArray loc_var (1 + elem_idx), []) + Single{} -> do + let (start, end, _) = getIndexPositionOfSoALocVar field_locs field_loc + return $ (Ext $ IndexCursorArray loc_var start, []) SoA _ fregs -> do let CursorArrayTy sz = getCursorizeTyFromLocVar field_loc let (start, end, _) = getIndexPositionOfSoALocVar field_locs field_loc @@ -2458,7 +2463,9 @@ cursorizeRegExp freeVarToVarEnv denv tenv senv lvar regExp = Nothing -> error $ "cursorizeRegExp: GetDataConRegSoA: unexpected location variable: " ++ "(" ++ show regExp ++ "," ++ (show (lvar)) ++ ")" ++ show freeVarToVarEnv -- {- VS : We add one since the data constructor is reserved as the first element in the cursor Array -} (rhs, additional_lets) <- case field_loc of - Single{} -> return $ (Ext $ IndexCursorArray loc_var (1 + elem_idx), []) + Single{} -> do + let (start, end, _) = getIndexPositionOfSoALocVar field_locs field_loc + return $ (Ext $ IndexCursorArray loc_var start, []) SoA _ fregs -> do let CursorArrayTy sz = getCursorizeTyFromLocVar field_loc let (start, end, _) = getIndexPositionOfSoALocVar field_locs field_loc @@ -3701,12 +3708,12 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let new_binds = case redir_vars of [v] -> [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of [v] -> [(redirection_var_flds !! index, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) _ -> let new_binds = case redir_vars of [v] -> @@ -3719,7 +3726,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) ] rst -> error $ "Did not expect multiple variables for type " ++ show ty_of_field - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) ) (0, []) res @@ -3857,12 +3864,12 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let new_binds = case redir_vars of [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) _ -> let new_binds = case redir_vars of [v] -> @@ -3875,7 +3882,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (toEndFromTaggedV (v), [], CursorTy, Ext $ AddCursor (v) (VarE (toTagV (v)))) ] _ -> error "Did not expect multiple variables!" - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) ) (0, []) res soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = M.union @@ -3969,12 +3976,12 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let new_binds = case redir_vars of [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) _ -> let new_binds = case redir_vars of [v] -> @@ -3987,7 +3994,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (toEndFromTaggedV (v), [], CursorTy, Ext $ AddCursor (v) (VarE (toTagV (v)))) ] _ -> error $ "Did not expect multiple variables for type" ++ show ty_of_field - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) ) (0, []) res @@ -4122,12 +4129,12 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack let new_binds = case redir_vars of [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) _ -> let new_binds = case redir_vars of [v] -> @@ -4140,7 +4147,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) ] _ -> error $ "Did not expect multiple variables for ty: " ++ show ty_of_field - in (index + 1, res ++ new_binds) + in (index + L.length (redir_vars), res ++ new_binds) ) (0, []) res soa_redir_bind = [(v, [], CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))] tenv'' = M.union From 3704a6ec697ce861f2a6dd605bcd9d7e88953cd3 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 26 Oct 2025 12:02:45 -0400 Subject: [PATCH 52/60] edits --- gibbon-compiler/examples/soa_examples/packedList.hs | 11 ++++++++--- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index 0eb74d00d..aed9bbba2 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -48,6 +48,11 @@ id lst = lst gibbon_main = let pi = mkPackedInt 10 - lst = mkList 1000000 - lst' = iterate (add1 lst) - in (sumList lst') + lst = mkList 100000 + lst' = id (add1 lst) + in (sumList lst') + + + + + diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index f0ad4a9d1..3dab6120d 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -3,7 +3,7 @@ module Tree where data Tree = Leaf Int Float | Node Int Int Int Float Tree Tree Tree Tree deriving Show -{-# ANN type Tree "Linear" #-} +{-# ANN type Tree "Factored" #-} mkTree :: Int -> Tree mkTree d = From 65b69998d4a21310e8cfcda616453828b95645e6 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Wed, 29 Oct 2025 23:50:59 -0400 Subject: [PATCH 53/60] add example --- .../examples/soa_examples/packedBinaryTree.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs b/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs index f0080a5ff..e986c6d15 100644 --- a/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs @@ -1,6 +1,9 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int FloatList List Tree Tree | Leaf +{-# ANN type Tree "Linear" #-} +{-# ANN type List "Linear" #-} +{-# ANN type FloatList "Linear" #-} mkList :: Int -> List @@ -16,7 +19,7 @@ mkFloatList len = if len <= 0 mkTree :: Int -> Tree mkTree d = if (d <= 0) then Leaf - else Node d (mkFloatList d) (mkList d) (mkTree (d - 1)) (mkTree (d - 1)) + else Node d (mkFloatList 50000) (mkList 50000) (mkTree (d - 1)) (mkTree (d - 1)) add1List :: List -> List add1List lst = case lst of @@ -70,7 +73,7 @@ sumFloatList :: FloatList -> Int sumFloatList lst = 10 gibbon_main = - let tree = mkTree 12 - tree' = add1Tree tree - in sumTree tree' + let tree = mkTree 8 + tree' = iterate (add1Tree tree) + in iterate (sumTree tree') From 6571e9e95f58e27ef1f35bc2ce86b98446ca0b41 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 30 Oct 2025 23:21:06 -0400 Subject: [PATCH 54/60] edits --- gibbon-compiler/examples/soa_examples/list.hs | 5 +- .../examples/soa_examples/packedBinaryTree.hs | 4 +- .../examples/soa_examples/packedList.hs | 2 +- gibbon-compiler/examples/soa_examples/tree.hs | 2 +- .../src/Gibbon/Passes/RegionsInwards.hs | 11 ++- gibbon-compiler/tests/BenchRunner.hs | 2 +- gibbon-compiler/tests/TestRunner.hs | 26 +++---- .../tests/test-gibbon-examples.yaml | 74 +++++++++---------- 8 files changed, 60 insertions(+), 66 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 304b70c78..3770a2397 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -1,4 +1,3 @@ - data List = Cons Int List | Nil {-# ANN type List "Factored" #-} @@ -37,8 +36,8 @@ id :: List -> List id lst = lst gibbon_main = let - lst = (mkList 1000000) - lst' = iterate ((add1 lst)) + lst = mkList 100 + lst' = add1 lst in sumList lst' diff --git a/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs b/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs index e986c6d15..610fe9a16 100644 --- a/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedBinaryTree.hs @@ -1,7 +1,7 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int FloatList List Tree Tree | Leaf -{-# ANN type Tree "Linear" #-} +{-# ANN type Tree "Factored" #-} {-# ANN type List "Linear" #-} {-# ANN type FloatList "Linear" #-} @@ -73,7 +73,7 @@ sumFloatList :: FloatList -> Int sumFloatList lst = 10 gibbon_main = - let tree = mkTree 8 + let tree = mkTree 3 tree' = iterate (add1Tree tree) in iterate (sumTree tree') diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index aed9bbba2..501517fb3 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -48,7 +48,7 @@ id lst = lst gibbon_main = let pi = mkPackedInt 10 - lst = mkList 100000 + lst = mkList 100 lst' = id (add1 lst) in (sumList lst') diff --git a/gibbon-compiler/examples/soa_examples/tree.hs b/gibbon-compiler/examples/soa_examples/tree.hs index 3dab6120d..7cbc04dd9 100644 --- a/gibbon-compiler/examples/soa_examples/tree.hs +++ b/gibbon-compiler/examples/soa_examples/tree.hs @@ -42,4 +42,4 @@ gibbon_main = rmost = (rightmost tree'') _ = printint rmost _ = printsym (quote ")\n\n") - in val --printPacked tree'' --rmost --() + in val diff --git a/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs b/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs index 7cff3c774..f19afc5a8 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs @@ -36,7 +36,7 @@ regionsInwards Prog {ddefs, fundefs, mainExp} = do let env = M.empty mn' <- removeAliasedLocations M.empty S.empty mn -- Use M.empty for creating the empty env mn'' <- placeRegionInwards env scopeSetMain mn' -- Delay Regions for the main function - pure $ Just (mn'', ty) -- (mn'', ty) + pure $ Just (mn', ty) -- (mn'', ty) return $ Prog ddefs fundefs' mainExp' placeRegionsInwardsFunBody :: S.Set FreeVarsTy -> FunDef2 -> PassM FunDef2 @@ -668,9 +668,8 @@ removeAliasedLocations env definedLocs ex = AssignLE loc' -> do -- rhs' <- removeAliasedLocations env definedLocs' rhs let env' = makeAlias env loc' loc - removeAliasedLocations env' definedLocs rhs + removeAliasedLocations env' definedLocs' rhs GenSoALoc dconl fieldLocs -> do - rhs' <- removeAliasedLocations env definedLocs' rhs let nloc = case loc of Single _ -> getAliasLoc env loc SoA dcl fieldLocs' -> @@ -679,9 +678,13 @@ removeAliasedLocations env definedLocs ex = in SoA (unwrapLocVar dcl') fieldLocs'' ndconl = getAliasLoc env dconl nfieldLocs = map (\(k, l) -> (k, getAliasLoc env l)) fieldLocs + oldSoALoc = SoA (unwrapLocVar dconl) fieldLocs + newSoALoc = SoA (unwrapLocVar ndconl) nfieldLocs + env' = makeAlias env newSoALoc oldSoALoc + rhs' <- removeAliasedLocations env' definedLocs' rhs case existsLetForLoc of True -> return rhs' - False -> return $ Ext $ LetLocE nloc (GenSoALoc ndconl nfieldLocs) rhs' + False -> dbgTrace (minChatLvl) "New GenSoA: " dbgTrace (minChatLvl) (sdoc (GenSoALoc ndconl nfieldLocs)) dbgTrace (minChatLvl) "End GenSoA!\n" return $ Ext $ LetLocE nloc (GenSoALoc ndconl nfieldLocs) rhs' LetParRegionE r sz ty rhs -> do rhs' <- go rhs return $ Ext $ LetParRegionE r sz ty rhs' diff --git a/gibbon-compiler/tests/BenchRunner.hs b/gibbon-compiler/tests/BenchRunner.hs index 61f252935..d52450e96 100644 --- a/gibbon-compiler/tests/BenchRunner.hs +++ b/gibbon-compiler/tests/BenchRunner.hs @@ -76,7 +76,7 @@ bench_main :: TestConfig -> Tests -> IO () bench_main tc (Tests tests) = do putStrLn "Executing BenchRunner...\n" let benchmarks = filter (not . skip) $ filter isBenchmark tests - modesToBench = [Gibbon1, Gibbon2, Pointer,Colobus1, Colobus2, Colobus3, Colobus4] -- Omit MPL for now + modesToBench = [Gibbon1, Gibbon2, Pointer,GibbonNoCopies, GibbonNoRan] -- Omit MPL for now results <- mapM (go modesToBench) benchmarks mc <- getHostname let csvs = map (\arg -> intercalate "," (mc:arg)) (concat results) diff --git a/gibbon-compiler/tests/TestRunner.hs b/gibbon-compiler/tests/TestRunner.hs index ad8defe42..c44e34978 100644 --- a/gibbon-compiler/tests/TestRunner.hs +++ b/gibbon-compiler/tests/TestRunner.hs @@ -161,7 +161,7 @@ data Result = Pass | Fail -- Not used atm. -- | Gibbon mode to run programs in -data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | Colobus1 | Colobus2 | Colobus3 | Colobus4 +data Mode = Gibbon3 | Gibbon2 | Pointer | Interp1 | Gibbon1 | MPL | GibbonNoCopies | GibbonNoRan deriving (Show, Eq, Read, Ord, Bounded, Enum) instance FromJSON Mode where @@ -179,19 +179,15 @@ readMode s = "pointer" -> Pointer "interp1" -> Interp1 "gibbon1" -> Gibbon1 - "colobus1" -> Colobus1 - "colobus2" -> Colobus2 - "colobus3" -> Colobus3 - "colobus4" -> Colobus4 + "nocopies" -> GibbonNoCopies + "noran" -> GibbonNoRan "mpl" -> MPL _ -> error $ "readMode: " ++ show s -- Must match the flag expected by Gibbon. modeRunFlags :: Mode -> [String] -modeRunFlags Colobus1 = ["--run", "--packed", "--gibbon1", "--SoA"] -modeRunFlags Colobus2 = ["--run", "--packed", "--no-rcopies", "--no-ran", "--SoA"] -modeRunFlags Colobus3 = ["--run", "--packed", "--no-gc", "--no-ran", "--SoA"] -modeRunFlags Colobus4 = ["--run", "--packed", "--no-gc", "--SoA"] +modeRunFlags GibbonNoCopies = ["--run", "--packed", "--no-rcopies"] +modeRunFlags GibbonNoRan = ["--run", "--packed", "--no-ran"] modeRunFlags Gibbon3 = ["--run", "--packed", "--gen-gc"] modeRunFlags Gibbon2 = ["--run", "--packed"] modeRunFlags Pointer = ["--run", "--pointer"] @@ -201,10 +197,8 @@ modeRunFlags MPL = ["--mpl-run"] -- Must match the flag expected by Gibbon. modeExeFlags :: Mode -> [String] -modeExeFlags Colobus1 = ["--to-exe", "--packed", "--gibbon1", "--SoA"] -modeExeFlags Colobus2 = ["--to-exe", "--packed", "--no-rcopies", "--no-ran", "--SoA"] -modeExeFlags Colobus3 = ["--to-exe", "--packed", "--no-gc", "--no-ran", "--SoA"] -modeExeFlags Colobus4 = ["--to-exe", "--packed", "--no-gc", "--SoA"] +modeExeFlags GibbonNoCopies = ["--to-exe", "--packed", "--no-rcopies"] +modeExeFlags GibbonNoRan = ["--to-exe", "--packed", "--no-ran"] modeExeFlags Gibbon3 = ["--to-exe", "--packed", "--gen-gc"] modeExeFlags Gibbon2 = ["--to-exe", "--packed"] modeExeFlags Pointer = ["--to-exe", "--pointer"] @@ -213,10 +207,8 @@ modeExeFlags Gibbon1 = ["--to-exe", "--packed", "--gibbon1"] modeExeFlags MPL = ["--mpl-exe"] modeFileSuffix :: Mode -> String -modeFileSuffix Colobus1 = "_colobus1" -modeFileSuffix Colobus2 = "_colobus2" -modeFileSuffix Colobus3 = "_colobus3" -modeFileSuffix Colobus4 = "_colobus4" +modeFileSuffix GibbonNoCopies = "_gibbonNoCopies" +modeFileSuffix GibbonNoRan = "_gibbonNoRan" modeFileSuffix Gibbon3 = "_gibbon3" modeFileSuffix Gibbon2 = "_gibbon2" modeFileSuffix Pointer = "_ptr" diff --git a/gibbon-compiler/tests/test-gibbon-examples.yaml b/gibbon-compiler/tests/test-gibbon-examples.yaml index a702b69c0..7ed8b6601 100644 --- a/gibbon-compiler/tests/test-gibbon-examples.yaml +++ b/gibbon-compiler/tests/test-gibbon-examples.yaml @@ -71,15 +71,15 @@ tests: - name: test11f_funrec.gib - name: test11_fundata.gib - name: test12b_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, nocopies, noran] - name: test12c_traverse.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, nocopies, noran] - name: test13b_build.gib - name: test13_build.gib - name: Test185.hs answer-file: examples/Test185.ans # Scalar fields after packed not allowed - failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1,gibbon2,gibbon3, nocopies, noran] - name: SS.hs dir: examples/gc answer-file: examples/gc/SS.ans @@ -137,11 +137,11 @@ tests: - name: test29b_list.gib - name: test30_twitter.gib # ThreadRegions bug. - failing: [colobus1, colobus2, colobus3, colobus4] + failing: [] - name: test_buildstree.gib - name: test_buildtree.gib - name: test_buildtreesum.gib - failing: [colobus1, colobus2, colobus3, colobus4] + failing: [] - name: test_ddtree.gib - name: test_stree.gib - name: test_sumstree.gib @@ -258,7 +258,7 @@ tests: - name: Poly1.hs dir: examples/poly answer-file: examples/poly/Poly1.ans - failing: [gibbon1, gibbon2, gibbon3, interp1,colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, interp1, nocopies, noran] # - name: measure_mode.hs # answer-file: examples/measure_mode.ans @@ -288,7 +288,7 @@ tests: dir: examples/poly answer-file: examples/poly/CurriedFns.ans skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] - name: T127.hs dir: examples/poly @@ -308,19 +308,19 @@ tests: - name: unariser_bug1.hs answer-file: examples/unariser_bug1.ans - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] skip: true - name: ParseLinearTypes.hs test-flags: ["--ghc-tc"] dir: examples/lineartypes/ - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, nocopies, noran] - name: EqBench.hs answer-file: examples/EqBench.ans - name: test_parse.hs - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, nocopies, noran] - name: toplevel_value.hs answer-file: examples/toplevel_value.ans @@ -357,7 +357,7 @@ tests: dir: examples answer-file: examples/test_printpacked.ans # gibbon3 and gibbon2: Inferlocations bug. - failing: [interp1,gibbon1,pointer, colobus1, colobus2] + failing: [interp1,gibbon1,pointer, nocopies] ## FAILING: Multiple packed outputs. - name: TupleTest.hs @@ -371,7 +371,7 @@ tests: ## FAILING: Scalar field after a packed field. - name: test12_skip.gib - failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1] skip: true - name: test12b_traverse.gib skip: true @@ -401,7 +401,7 @@ tests: skip: true - name: test29d_list.gib skip: true - failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1] - name: test_unpacking.gib skip: true @@ -409,46 +409,46 @@ tests: ## Shouldn't typecheck - name: Fail1.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, nocopies, noran] - name: Fail2.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, nocopies, noran] - name: Fail3.hs dir: examples/should_fail - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, nocopies, noran] ## Fusion2 tests - name: test_sumup_seteven.gib skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] test-flags: ["--fusion"] - name: render_tree.hs dir: examples/fusion-benchmarks skip: true - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree.ans - name: render_tree_two_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_two_passes.ans - name: render_tree_four_passes.hs skip: true dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] test-flags: ["--fusion"] answer-file: examples/fusion-benchmarks/render_tree_four_passes.ans - name: render_tree_five_passes.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, pointer, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, pointer] ## [2020.05.27]: It never finishes on Travis... skip: true test-flags: ["--fusion"] @@ -456,7 +456,7 @@ tests: - name: LC.hs dir: examples/fusion-benchmarks - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3] test-flags: ["--fusion"] skip: true # gibbon2: segfaults in free_region @@ -494,29 +494,29 @@ tests: ## AST benchmarks - name: C1.hs dir: examples/ast - failing: [gibbon1, gibbon2, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2] answer-file: examples/ast/C1.ans skip: true ## Tests that only work with some backend: - name: test18f_flip.gib - failing: [gibbon1, gibbon2, gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1, gibbon2, gibbon3, nocopies, noran] - name: pp_projs.gib skip: true - name: test12_skip.gib - failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1] skip: true # Tests that actually work but we can't generate answers with Racket - name: test08_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3] - name: test08b_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, nocopies, noran] - name: test08c_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, nocopies, noran] - name: test08d_sharedict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, nocopies, noran] # - name: test08f_dict.gib # - name: test08f2_dict.gib @@ -524,13 +524,13 @@ tests: # This test depends on real symbols, which we don't support atm. - name: test27b_subst.gib - failing: [gibbon1,gibbon2,gibbon3, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1,gibbon2,gibbon3] skip: true # printing symbols is broken atm # No gensym, or real symbols. - name: test28_copyprop.gib - failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1,gibbon2,gibbon3,pointer,interp1, nocopies, noran] # sym-append not implemented in the RTS - name: test15b_symappend.gib @@ -555,15 +555,15 @@ tests: failing: [interp1] - name: test_153.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon3,gibbon2,gibbon1,interp1, nocopies, noran] answer-file: examples/test_153.ans - name: test_164.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon3,gibbon2,gibbon1,interp1, nocopies, noran] answer-file: examples/test_164.ans - name: test_166.hs - failing: [gibbon3,gibbon2,gibbon1,interp1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon3,gibbon2,gibbon1,interp1, nocopies, noran] answer-file: examples/test_166.ans - name: test_167.hs @@ -580,14 +580,14 @@ tests: - name: test_power.hs answer-file: examples/test_power.ans # gib_alloc_region_on_heap: gib_alloc failed - failing: [gibbon1, colobus1, colobus2, colobus3, colobus4] + failing: [gibbon1] # Vidush: unskip this, thing hangs because of all the debug print statements skip: true - name: test_191.hs answer-file: examples/test_191.ans # Gibbon2 and Gibbon3 modes don't pass the L2 typechecker. - failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, colobus1, colobus2, colobus3, colobus4] + failing: [pointer, gibbon1, interp1, gibbon3, gibbon2, nocopies, noran] run-modes: ["gibbon2"] #simple SoA benchmarks @@ -612,6 +612,6 @@ tests: answer-file: examples/soa_examples/test_packed_tree.ans - name: test_303.hs - failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, colobus] + failing: [gibbon1, gibbon2, gibbon3, pointer, interp1, nocopies, noran] From b6b9f0893681cfd52a1ad5ae492f668df2e67578 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Thu, 30 Oct 2025 23:26:01 -0400 Subject: [PATCH 55/60] edits --- gibbon-compiler/examples/soa_examples/packedTree.hs | 2 +- gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index af5dfccb4..e475e2f74 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -87,7 +87,7 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = mkTree 8 + let tree = mkTree 2 tree' = iterate (add1Tree tree) val = iterate (sumTree tree) r = iterate (rightMostTree tree') diff --git a/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs b/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs index f19afc5a8..afcc44ea3 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RegionsInwards.hs @@ -36,7 +36,7 @@ regionsInwards Prog {ddefs, fundefs, mainExp} = do let env = M.empty mn' <- removeAliasedLocations M.empty S.empty mn -- Use M.empty for creating the empty env mn'' <- placeRegionInwards env scopeSetMain mn' -- Delay Regions for the main function - pure $ Just (mn', ty) -- (mn'', ty) + pure $ Just (mn'', ty) -- (mn'', ty) return $ Prog ddefs fundefs' mainExp' placeRegionsInwardsFunBody :: S.Set FreeVarsTy -> FunDef2 -> PassM FunDef2 From 60fdad6eb37e6fc9e7b69a077311aaf7e866026f Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 2 Nov 2025 09:37:56 -0500 Subject: [PATCH 56/60] edits --- gibbon-compiler/examples/soa_examples/list.hs | 2 +- .../examples/soa_examples/packedList.hs | 4 +- .../examples/soa_examples/packedTree.hs | 12 +- gibbon-compiler/src/Gibbon/L3/Typecheck.hs | 76 +++++++------ .../src/Gibbon/Passes/Cursorize.hs | 107 ++++++++---------- .../src/Gibbon/Passes/FollowPtrs.hs | 25 +++- gibbon-compiler/src/Gibbon/Passes/Unariser.hs | 4 +- 7 files changed, 116 insertions(+), 114 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/list.hs b/gibbon-compiler/examples/soa_examples/list.hs index 3770a2397..b4ed7ddb6 100644 --- a/gibbon-compiler/examples/soa_examples/list.hs +++ b/gibbon-compiler/examples/soa_examples/list.hs @@ -37,7 +37,7 @@ id lst = lst gibbon_main = let lst = mkList 100 - lst' = add1 lst + lst' = id (add1 lst) in sumList lst' diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index 501517fb3..56c908f5b 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -1,6 +1,6 @@ data PackedInt = PacI Int data List = Cons Int PackedInt List | Nil -{-# ANN type PackedInt "Linear" #-} +{-# ANN type PackedInt "Factored" #-} {-# ANN type List "Factored" #-} addPackedInt' :: PackedInt -> Int -> PackedInt @@ -48,7 +48,7 @@ id lst = lst gibbon_main = let pi = mkPackedInt 10 - lst = mkList 100 + lst = iterate (mkList 100000) lst' = id (add1 lst) in (sumList lst') diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index e475e2f74..3379aa3d2 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -1,9 +1,9 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf -{-# ANN type Tree "Linear" #-} -{-# ANN type List "Linear" #-} -{-# ANN type FloatList "Linear" #-} +{-# ANN type Tree "Factored" #-} +{-# ANN type List "Factored" #-} +{-# ANN type FloatList "Factored" #-} mkList :: Int -> List mkList len = if len <= 0 @@ -87,9 +87,9 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = mkTree 2 - tree' = iterate (add1Tree tree) - val = iterate (sumTree tree) + let tree = id (mkTree 8) + tree' = iterate (id (add1Tree tree)) + val = iterate (sumTree tree') r = iterate (rightMostTree tree') in val + r diff --git a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs index f07d8cdae..2f477d55b 100644 --- a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs @@ -1013,42 +1013,44 @@ ensureEqualTy exp a b = ensureEqual exp ("Expected these types to be the same: " ++ (sdoc a) ++ " <> " ++ (sdoc b)) a b +-- ensureEqualTyModCursor :: DDefs3 -> Exp3 -> Ty3 -> Ty3 -> TcM Ty3 (Exp3) +-- ensureEqualTyModCursor ddefs exp ty1 ty2 = case ty2 of +-- PackedTy tycon _ -> +-- let cursorTy = getCursorTypeFromTy tycon ddefs +-- in case cursorTy of +-- CursorTy -> case ty1 of +-- CursorTy -> return CursorTy +-- _ -> ensureEqualTy exp ty1 ty2 +-- CursorArrayTy{} -> case ty1 of +-- CursorArrayTy{} -> return ty1 +-- _ -> ensureEqualTy exp ty1 ty2 +-- _ -> ensureEqualTy exp ty1 ty2 +-- CursorTy -> case ty1 of +-- PackedTy{} -> return CursorTy +-- IntTy -> return CursorTy +-- _ -> ensureEqualTy exp ty1 ty2 +-- CursorArrayTy sz -> case ty1 of +-- PackedTy{} -> return (CursorArrayTy sz) +-- IntTy -> return (CursorArrayTy sz) +-- _ -> ensureEqualTy exp ty1 ty2 +-- IntTy -> case ty1 of +-- CursorTy -> return CursorTy +-- CursorArrayTy sz -> return $ CursorArrayTy sz +-- _ -> ensureEqualTy exp ty1 ty2 +-- (ProdTy ls1) -> case ty1 of +-- (ProdTy ls2) -> sequence_ [ ensureEqualTyModCursor ddefs exp ty1' ty2' | (ty1',ty2') <- zip ls1 ls2] >>= \_ -> return (packedToCursor ddefs (ProdTy ls1)) +-- _ -> ensureEqualTy exp ty1 ty2 +-- _ -> ensureEqualTy exp ty1 ty2 + ensureEqualTyModCursor :: DDefs3 -> Exp3 -> Ty3 -> Ty3 -> TcM Ty3 (Exp3) -ensureEqualTyModCursor ddefs exp ty1 ty2 = case ty2 of - PackedTy tycon _ -> - let cursorTy = getCursorTypeFromTy tycon ddefs - in case cursorTy of - CursorTy -> case ty1 of - CursorTy -> return CursorTy - _ -> ensureEqualTy exp ty1 ty2 - CursorArrayTy{} -> case ty1 of - CursorArrayTy{} -> return ty1 - _ -> ensureEqualTy exp ty1 ty2 - _ -> ensureEqualTy exp ty1 ty2 - CursorTy -> case ty1 of - PackedTy{} -> return CursorTy - IntTy -> return CursorTy - _ -> ensureEqualTy exp ty1 ty2 - CursorArrayTy sz -> case ty1 of - PackedTy{} -> return (CursorArrayTy sz) - IntTy -> return (CursorArrayTy sz) - _ -> ensureEqualTy exp ty1 ty2 - IntTy -> case ty1 of - CursorTy -> return CursorTy - CursorArrayTy sz -> return $ CursorArrayTy sz - _ -> ensureEqualTy exp ty1 ty2 - (ProdTy ls1) -> case ty1 of - (ProdTy ls2) -> sequence_ [ ensureEqualTyModCursor ddefs exp ty1' ty2' | (ty1',ty2') <- zip ls1 ls2] >>= \_ -> return (packedToCursor ddefs (ProdTy ls1)) - _ -> ensureEqualTy exp ty1 ty2 - _ -> ensureEqualTy exp ty1 ty2 - --- ensureEqualTyModCursor False _exp CursorTy (PackedTy _ _) = return CursorTy --- ensureEqualTyModCursor False _exp (PackedTy _ _) CursorTy = return CursorTy --- ensureEqualTyModCursor False _exp IntTy CursorTy = return CursorTy --- ensureEqualTyModCursor False _exp CursorTy IntTy = return CursorTy - --- ensureEqualTyModCursor False exp (ProdTy ls1) (ProdTy ls2) = --- sequence_ [ ensureEqualTyModCursor False exp ty1 ty2 | (ty1,ty2) <- zip ls1 ls2] >>= \_ -> return (packedToCursor False (ProdTy ls1)) +ensureEqualTyModCursor _ddefs _exp CursorTy (PackedTy _ _) = return CursorTy +ensureEqualTyModCursor _ddefs _exp (PackedTy _ _) CursorTy = return CursorTy +ensureEqualTyModCursor _ddefs _exp IntTy CursorTy = return CursorTy +ensureEqualTyModCursor _ddefs _exp CursorTy IntTy = return CursorTy + +ensureEqualTyModCursor ddefs exp (ProdTy ls1) (ProdTy ls2) = + sequence_ [ ensureEqualTyModCursor ddefs exp ty1 ty2 | (ty1,ty2) <- zip ls1 ls2] >>= \_ -> return (packedToCursor ddefs (ProdTy ls1)) +ensureEqualTyModCursor _ddefs exp a b = ensureEqualTy exp a b -- ensureEqualTyModCursor True _exp (CursorArrayTy sz) (PackedTy _ _) = return (CursorArrayTy sz) -- ensureEqualTyModCursor True _exp (PackedTy _ _) (CursorArrayTy sz) = return (CursorArrayTy sz) @@ -1060,12 +1062,12 @@ ensureEqualTyModCursor ddefs exp ty1 ty2 = case ty2 of -- ensureEqualTyModCursor _s exp a b = ensureEqualTy exp a b packedToCursor :: DDefs3 -> Ty3 -> Ty3 -packedToCursor ddefs (PackedTy tycon _) = let +packedToCursor ddefs t@(PackedTy tycon _) = let cursorTy = getCursorTypeFromTy tycon ddefs in case cursorTy of CursorTy -> CursorTy CursorArrayTy sz -> CursorArrayTy sz - _ -> CursorTy + _ -> t packedToCursor _dd (ProdTy tys) = ProdTy $ map (\ty -> packedToCursor _dd ty) tys packedToCursor _dd ty = ty diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index f94cd192c..061360e94 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -2035,17 +2035,17 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let from_loc_var = case M.lookup (fromLocArgToFreeVarsTy from) freeVarToVarEnv of Nothing -> error "Did not find variable for location!" Just var -> var - let from_locs = [Single dcloc] ++ map (\(_, floc) -> floc) flds + let from_locs = linearizeLocVar (SoA dcloc flds) --[Single dcloc] ++ map (\(_, floc) -> floc) flds let to_locs = case (toLocVar to) of Single{} -> error "Expected a SoA location!\n" - SoA dc_loc flocs -> [Single dc_loc] ++ map (\(_, floc) -> floc) flocs + SoA dc_loc flocs -> linearizeLocVar (SoA dc_loc flocs) --[Single dc_loc] ++ map (\(_, floc) -> floc) flocs let to_loc_var = case M.lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of Nothing -> error "Did not find variable for location!" Just var -> var let reg_from_reg = fromLocVarToRegVar (toLocVar from_reg) let from_reg_vars = case reg_from_reg of SingleR{} -> error "expected an SoA region!\n" - SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs + SoARv dc_reg fieldRegs -> linearizeRegVar (SoARv dc_reg fieldRegs) --[dc_reg] ++ map (\(_, floc) -> floc) fieldRegs let from_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_from_reg) freeVarToVarEnv of Nothing -> error "Did not find region!" @@ -2054,7 +2054,7 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = let reg_to_reg = fromLocVarToRegVar (toLocVar to_reg) let to_reg_vars = case reg_to_reg of SingleR{} -> error "expected an SoA region!\n" - SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs + SoARv dc_reg fieldRegs -> linearizeRegVar (SoARv dc_reg fieldRegs) -- [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs let to_reg_var = case M.lookup (fromRegVarToFreeVarsTy reg_to_reg) freeVarToVarEnv of Nothing -> error "Did not find region!" @@ -2105,59 +2105,14 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex = return (ls ++ [(new_deref, [], CursorTy, Ext $ DerefMutCursor v)], nvs ++ [new_deref]) _ -> return (ls, nvs ++ [v]) ) ([], []) [from_var, to_var, from_reg_var, to_reg_var] - + -- We need to make sure to get the right tycon for the the nested SoA field + -- This may be important for the GC to work properly. + -- Vidush: TODO let new_let = [ ("_", [], ProdTy [], Ext (IndirectionBarrier tycon ((new_vars !! 0), (new_vars !! 2), (new_vars !! 1), (new_vars !! 3)))), (start, [], CursorTy, VarE (from_var)), (end, [], CursorTy, Ext $ AddCursor (from_var) (L3.LitE 9)) ] return (lets ++ fvl ++ tvl ++ frl ++ trl ++ need_deref ++ new_let, range ++ [(start, end)], p, b_args) - SoA dcloc' flds' -> do - (fl_var, fvl) <- do case (M.lookup (fromLocVarToFreeVarsTy fl)) freeVarToVarEnv of - Nothing -> case to_loc of - Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) - SoA{} -> do - field_name <- gensym "field_cursor" - return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray flp (fromJust (L.elemIndex r b_args)))]) - Just var -> return $ (var, []) - let from_locs' = [Single dcloc'] ++ map (\(_, floc) -> floc) flds' - let to_locs' = case to_loc of - Single{} -> error "Expected a SoA location!\n" - SoA dc_loc flocs -> [Single dc_loc] ++ map (\(_, floc) -> floc) flocs - (to_loc_var', tvl) <- case M.lookup (fromLocVarToFreeVarsTy to_loc) freeVarToVarEnv of - Nothing -> case to_loc of - Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray tp (fromJust (L.elemIndex r b_args)))]) - SoA{} -> do - field_name <- gensym "field_cursor" - return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray tp (fromJust (L.elemIndex r b_args)))]) - Just var -> return $ (var, []) - let from_reg_vars' = case from_reg of - SingleR{} -> error "expected an SoA region!\n" - SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs - - (from_reg_var', frl) <- case (M.lookup (fromRegVarToFreeVarsTy from_reg)) freeVarToVarEnv of - Nothing -> case to_loc of - Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray rp (fromJust (L.elemIndex r b_args)))]) - SoA{} -> do - field_name <- gensym "field_cursor" - return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray rp (fromJust (L.elemIndex r b_args)))]) - Just var -> return $ (var, []) - - let to_reg_vars' = case to_reg of - SingleR{} -> error "expected an SoA region!\n" - SoARv dc_reg fieldRegs -> [dc_reg] ++ map (\(_, floc) -> floc) fieldRegs - - (to_reg_var', trl) <- case (M.lookup (fromRegVarToFreeVarsTy to_reg)) freeVarToVarEnv of - Nothing -> case to_loc of - Single l -> return $ (l, [(l, [], CursorTy, Ext $ IndexCursorArray trp (fromJust (L.elemIndex r b_args)))]) - SoA{} -> do - field_name <- gensym "field_cursor" - return $ (field_name, [(field_name, [], CursorTy, Ext $ IndexCursorArray trp (fromJust (L.elemIndex r b_args)))]) - Just var -> return $ (var, []) - - let barrier_args' = L.zip4 from_locs' to_locs' from_reg_vars' to_reg_vars' - (let_exprs', range_s', parents, _) <- foldlM handle_indrs_rec ([], [], (fl_var, to_loc_var', from_reg_var', to_reg_var'), barrier_args') barrier_args' - _ <- error "SoA: Packed indirections with GC does not work! Please turn off GC for now!" - return (fvl ++ tvl ++ frl ++ trl ++ let_exprs', range_s', parents, barrier_args) ) (let_exprs, range_s, _, _) <- foldlM handle_indrs_rec ([], [], (from_loc_var, to_loc_var, from_reg_var, to_reg_var), barrier_args) barrier_args @@ -3790,6 +3745,8 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ] bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) return $ mkLets binds bod + -- TODO: + -- Vidush: The GC case for indirection will require us to take the indirection for nested SoA locations too! else do tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur @@ -3860,14 +3817,28 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack tmpf = tmp_flds !! index ty_of_field = (lookupDataCon ddfs dcon') !! idx in case ty_of_field of - (MkTy2 PackedTy {}) -> + (MkTy2 PackedTy {}) -> --[(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] let new_binds = case redir_vars of - [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((v), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (v), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (v), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (v), [], CursorTy, Ext $ AddCursor (v) (VarE (toTagV (v)))) + ] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of - [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((v), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (v), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (v), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (v), [], CursorTy, Ext $ AddCursor (v) (VarE (toTagV (v)))) + ] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + L.length (redir_vars), res ++ new_binds) _ -> @@ -4055,12 +4026,14 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack ] bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v) return $ mkLets binds bod - else do + else do + let linearizedLocs = case loc of + FL l -> linearizeLocVar l tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" - tmp_flds <- mapM (\((dcon, idx), _) -> gensym "readcursor_indir_flds") _field_cur + tmp_flds <- mapM (\_ -> gensym "readcursor_indir_flds") linearizedLocs loc_var <- lookupVariable loc fenv var_dcon_next <- gensym "dcon_next" - vars_next_fields <- mapM (\((dcon, idx), _) -> gensym "field_nxt") _field_cur + vars_next_fields <- mapM (\_ -> gensym "field_nxt") linearizedLocs redirection_var_dcon <- gensym "dcon_redir" res <- mapM (\((dcon, idx), _loc) -> do let locTy = (lookupDataCon ddfs dcon) !! idx @@ -4127,12 +4100,26 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack in case ty_of_field of (MkTy2 PackedTy {}) -> let new_binds = case redir_vars of - [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of - [v] -> [(v, [], CursorTy, Ext (AddCursor var (LitE 0)))] + [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), + (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) + ] rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst in (index + L.length (redir_vars), res ++ new_binds) _ -> diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index ddef67d9a..efdb769a4 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -5,7 +5,7 @@ module Gibbon.Passes.FollowPtrs import qualified Data.Map as M -- import qualified Data.Set as S import qualified Data.List as L -import Data.Foldable ( foldrM ) +import Data.Foldable ( foldrM, foldlM ) import Data.Maybe ( fromJust ) import Gibbon.Common @@ -106,6 +106,7 @@ followPtrs (Prog ddefs fundefs mainExp) = do ---------------------------------------- (pure (CaseE scrt (brs ++ [redir_br]))) else do + let gc_off = gopt Opt_DisableGC flags indir_ptrv <- gensym "indr" indir_ptrloc <- freshCommonLoc "case" scrt_loc jump <- freshCommonLoc "jump" scrt_loc @@ -144,17 +145,29 @@ followPtrs (Prog ddefs fundefs mainExp) = do -- Field locs will all be the same indir_br <- case scrt_loc of SoA _d flocs -> do - let arr_elems = 1 + length flocs + let arr_elems = 1 + length flocs + let aft_dcon_indir_size = if gc_off then (1 + 8 * arr_elems) else 9 let data_con_let = LetLocE (getDconLoc scrt_loc) (GetDataConLocSoA scrt_loc) -- assuming 8 byte pointer size - let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE (1 + 8 * arr_elems) ((getDconLoc scrt_loc))) + let new_jump_dloc = LetLocE (getDconLoc jump) (AfterConstantLE aft_dcon_indir_size ((getDconLoc scrt_loc))) let unpack_fld_lets = foldr (\((dcon, idx), lc) acc -> acc ++ [LetLocE lc (GetFieldLocSoA (dcon, idx) scrt_loc)]) [] (getAllFieldLocsSoA scrt_loc) - - let indir_bod = Ext $ LetLocE (jump) (GenSoALoc (getDconLoc jump) (getAllFieldLocsSoA scrt_loc) ) $ + (indir_bod_additional_lets, field_vars) <- case gc_off of + True -> return ([], getAllFieldLocsSoA scrt_loc) + False -> foldlM (\(lets, fvars_lst) ((dcon, idx), lc) -> case lc of + Single{} -> do + new_var <- gensym "aft_indir_loc" + return (lets ++ [LetLocE (singleLocVar new_var) (AfterConstantLE 9 (getFieldLoc (dcon, idx) scrt_loc))], fvars_lst ++ [((dcon, idx), singleLocVar new_var)]) + -- There is a slight bug here + -- Vidush: Since we linearize the SoA location + -- We do this in cursorize + -- There we need to make sure we add 9 to the end location! + SoA{} -> return (lets, fvars_lst ++ [((dcon, idx), lc)]) + ) ([], []) (getAllFieldLocsSoA scrt_loc) + let indir_bod = Ext $ LetLocE (jump) (GenSoALoc (getDconLoc jump) field_vars) $ (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) - let indir_bod' = foldr (\l b -> Ext $ l b) indir_bod ([data_con_let] ++ [new_jump_dloc] ++ unpack_fld_lets) + let indir_bod' = foldr (\l b -> Ext $ l b) indir_bod ([data_con_let] ++ [new_jump_dloc] ++ unpack_fld_lets ++ indir_bod_additional_lets) let indir_dcon = fst $ fromJust $ L.find (isIndirectionTag . fst) dataCons return $ (indir_dcon,[(indir_ptrv,(indir_ptrloc))],indir_bod') Single{} -> do diff --git a/gibbon-compiler/src/Gibbon/Passes/Unariser.hs b/gibbon-compiler/src/Gibbon/Passes/Unariser.hs index 343101a42..12bc4d56f 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Unariser.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Unariser.hs @@ -175,8 +175,8 @@ unariserExp isTerminal ddfs stk env2 ex = TimeIt e ty b -> do tmp <- gensym $ toVar "timed" - e' <- go isTerminal env2 e - return $ LetE (tmp,[],flattenTy ty, TimeIt e' ty b) (VarE tmp) + e' <- go isTerminal env2 e + dbgTrace (minChatLvl) "Print Ty unarizer: " dbgTrace (minChatLvl) (sdoc (ty, flattenTy ty)) dbgTrace (minChatLvl) "End Ty!\n" return $ LetE (tmp,[],flattenTy ty, TimeIt e' ty b) (VarE tmp) WithArenaE v e -> WithArenaE v <$> go isTerminal env2 e From cea646288c438c3528b5f8154bb45a711d6fff17 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 2 Nov 2025 14:09:25 -0500 Subject: [PATCH 57/60] fix test suite --- .../examples/soa_examples/packedList.hs | 4 +- .../examples/soa_examples/packedTree.hs | 15 +++-- .../src/Gibbon/Passes/Cursorize.hs | 56 +++++++++++++------ .../tests/test-gibbon-examples.yaml | 10 ++-- 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/gibbon-compiler/examples/soa_examples/packedList.hs b/gibbon-compiler/examples/soa_examples/packedList.hs index 56c908f5b..501517fb3 100644 --- a/gibbon-compiler/examples/soa_examples/packedList.hs +++ b/gibbon-compiler/examples/soa_examples/packedList.hs @@ -1,6 +1,6 @@ data PackedInt = PacI Int data List = Cons Int PackedInt List | Nil -{-# ANN type PackedInt "Factored" #-} +{-# ANN type PackedInt "Linear" #-} {-# ANN type List "Factored" #-} addPackedInt' :: PackedInt -> Int -> PackedInt @@ -48,7 +48,7 @@ id lst = lst gibbon_main = let pi = mkPackedInt 10 - lst = iterate (mkList 100000) + lst = mkList 100 lst' = id (add1 lst) in (sumList lst') diff --git a/gibbon-compiler/examples/soa_examples/packedTree.hs b/gibbon-compiler/examples/soa_examples/packedTree.hs index 3379aa3d2..17a2fe4a7 100644 --- a/gibbon-compiler/examples/soa_examples/packedTree.hs +++ b/gibbon-compiler/examples/soa_examples/packedTree.hs @@ -2,8 +2,8 @@ data List = Cons Int List | Nil data FloatList = FCons Float FloatList | FNil data Tree = Node Int Float FloatList List Tree Tree Tree | Leaf {-# ANN type Tree "Factored" #-} -{-# ANN type List "Factored" #-} -{-# ANN type FloatList "Factored" #-} +{-# ANN type List "Linear" #-} +{-# ANN type FloatList "Linear" #-} mkList :: Int -> List mkList len = if len <= 0 @@ -18,7 +18,7 @@ mkFloatList len = if len <= 0 mkTree :: Int -> Tree mkTree d = if (d <= 0) then Leaf - else Node d 1.0 (mkFloatList 10000) (mkList 10000) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) + else Node d 1.0 (mkFloatList d) (mkList d) (mkTree (d - 1)) (mkTree (d - 1)) (mkTree (d - 1)) rightMostTree :: Tree -> Int @@ -87,9 +87,8 @@ id :: Tree -> Tree id tree = tree gibbon_main = - let tree = id (mkTree 8) - tree' = iterate (id (add1Tree tree)) - val = iterate (sumTree tree') - r = iterate (rightMostTree tree') - in val + r + let tree = id (mkTree 5) + tree' = (id (add1Tree tree)) + val = (sumTree tree') + in val diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 061360e94..e5ed4989d 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -4031,6 +4031,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack FL l -> linearizeLocVar l tmp <- dbgTrace (minChatLvl) "Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) "End FieldCur\n" gensym "readcursor_indir" tmp_flds <- mapM (\_ -> gensym "readcursor_indir_flds") linearizedLocs + tmp_unpack <- mapM (\_ -> gensym "tmp_unpack") linearizedLocs loc_var <- lookupVariable loc fenv var_dcon_next <- gensym "dcon_next" vars_next_fields <- mapM (\_ -> gensym "field_nxt") linearizedLocs @@ -4091,46 +4092,67 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack binds_flields = L.foldl ( \(index, res) ((dcon', idx), var, redir_vars) -> - let read_cursor_f = + let read_cursor_f idx = if isIndirectionTag dcon || isRedirectionTag dcon - then Ext (ReadTaggedCursor (vars_next_fields !! index)) + then Ext (ReadTaggedCursor (vars_next_fields !! idx)) else error $ "unpackRegularDataCon: cursorty without indirection/redirection." - tmpf = tmp_flds !! index + tmpf idtmpf = tmp_flds !! idtmpf ty_of_field = (lookupDataCon ddfs dcon') !! idx in case ty_of_field of (MkTy2 PackedTy {}) -> let new_binds = case redir_vars of [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + (tmpf index, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f index), -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE $ tmpf index)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE $ tmpf index)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE $ tmpf index)), (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) ] - rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst + rst -> snd $ foldl (\(i, bnds) v -> (i + 1, bnds ++ [ (tmp_unpack !! i, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst))), + (vars_next_fields !! i, [], CursorTy, Ext (AddCursor (tmp_unpack !! i) (LitE 1))), + (tmpf i, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f i), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! i), [], CursorTy, ProjE 0 (VarE $ tmpf i)), + (toEndV (redirection_var_flds !! i), [], CursorTy, ProjE 1 (VarE $ tmpf i)), + (toTagV (redirection_var_flds !! i), [], IntTy, ProjE 2 (VarE $ tmpf i)), + (toEndFromTaggedV (redirection_var_flds !! i), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! i) (VarE (toTagV (redirection_var_flds !! i)))) + ] + ) + ) (index, []) rst in (index + L.length (redir_vars), res ++ new_binds) (MkTy2 CursorArrayTy {}) -> let new_binds = case redir_vars of [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + (tmpf index, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f index), -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE $ tmpf index)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE $ tmpf index)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE $ tmpf index)), (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) ] - rst -> map (\v -> (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst)))) rst + -- (v, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst))) + rst -> snd $ foldl (\(i, bnds) v -> (i + 1, bnds ++ [ (tmp_unpack !! i, [], CursorTy, Ext (IndexCursorArray var (fromJust $ L.elemIndex v rst))), + (vars_next_fields !! i, [], CursorTy, Ext (AddCursor (tmp_unpack !! i) (LitE 1))), + (tmpf i, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f i), + -- ((loc_var) , [], CursorTy, VarE dcur), + ((redirection_var_flds !! i), [], CursorTy, ProjE 0 (VarE $ tmpf i)), + (toEndV (redirection_var_flds !! i), [], CursorTy, ProjE 1 (VarE $ tmpf i)), + (toTagV (redirection_var_flds !! i), [], IntTy, ProjE 2 (VarE $ tmpf i)), + (toEndFromTaggedV (redirection_var_flds !! i), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! i) (VarE (toTagV (redirection_var_flds !! i)))) + ] + ) + ) (index, []) rst in (index + L.length (redir_vars), res ++ new_binds) _ -> let new_binds = case redir_vars of [v] -> [ (vars_next_fields !! index, [], CursorTy, Ext (AddCursor var (LitE 1))), - (tmpf, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f), + (tmpf index, [], ProdTy [CursorTy, CursorTy, IntTy], read_cursor_f index), -- ((loc_var) , [], CursorTy, VarE dcur), - ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE tmpf)), - (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE tmpf)), - (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE tmpf)), + ((redirection_var_flds !! index), [], CursorTy, ProjE 0 (VarE $ tmpf index)), + (toEndV (redirection_var_flds !! index), [], CursorTy, ProjE 1 (VarE $ tmpf index)), + (toTagV (redirection_var_flds !! index), [], IntTy, ProjE 2 (VarE $ tmpf index)), (toEndFromTaggedV (redirection_var_flds !! index), [], CursorTy, Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index)))) ] _ -> error $ "Did not expect multiple variables for ty: " ++ show ty_of_field diff --git a/gibbon-compiler/tests/test-gibbon-examples.yaml b/gibbon-compiler/tests/test-gibbon-examples.yaml index 7ed8b6601..2753be57c 100644 --- a/gibbon-compiler/tests/test-gibbon-examples.yaml +++ b/gibbon-compiler/tests/test-gibbon-examples.yaml @@ -510,7 +510,7 @@ tests: # Tests that actually work but we can't generate answers with Racket - name: test08_dict.gib - failing: [interp1,pointer,gibbon1,gibbon2,gibbon3] + failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, nocopies, noran] - name: test08b_dict.gib failing: [interp1,pointer,gibbon1,gibbon2,gibbon3, nocopies, noran] - name: test08c_dict.gib @@ -593,22 +593,22 @@ tests: #simple SoA benchmarks - name: list.hs dir: examples/soa_examples - failing: [] + failing: [gibbon3] answer-file: examples/soa_examples/test_list.ans - name: tree.hs dir: examples/soa_examples - failing: ["interp1"] + failing: ["interp1", gibbon3] answer-file: examples/soa_examples/test_tree.ans - name: packedList.hs dir: examples/soa_examples - failing: [] + failing: [gibbon3] answer-file: examples/soa_examples/test_packed_list.ans - name: packedTree.hs dir: examples/soa_examples - failing: [] + failing: [gibbon3] answer-file: examples/soa_examples/test_packed_tree.ans - name: test_303.hs From 0e3a663ef97aff19a9e9ff4e290de0906a36a690 Mon Sep 17 00:00:00 2001 From: Vidush Singhal Date: Sun, 2 Nov 2025 14:15:45 -0500 Subject: [PATCH 58/60] fix import of foldl' --- gibbon-compiler/src/Gibbon/HaskellFrontend.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gibbon-compiler/src/Gibbon/HaskellFrontend.hs b/gibbon-compiler/src/Gibbon/HaskellFrontend.hs index fa679d253..e6e3618dd 100644 --- a/gibbon-compiler/src/Gibbon/HaskellFrontend.hs +++ b/gibbon-compiler/src/Gibbon/HaskellFrontend.hs @@ -13,6 +13,7 @@ import Data.Foldable ( foldrM ) import Data.Maybe (catMaybes, isJust) import qualified Data.Map as M import qualified Data.Set as S +import qualified Data.List as L import qualified Safe as Sf import Data.IORef @@ -1410,7 +1411,7 @@ desugarLinearExts (Prog ddefs fundefs main) = do case fn' of Ext (LambdaE [(v,ProdTy tys)] bod) -> do let ty = Sf.headErr tys - bod'' = foldl' (\acc i -> gSubstE (ProjE i (VarE v)) (VarE v) acc) bod [0..(length tys)] + bod'' = L.foldl' (\acc i -> gSubstE (ProjE i (VarE v)) (VarE v) acc) bod [0..(length tys)] pure (LetE (v,[],ty,e) bod'') _ -> error $ "desugarLinearExts: couldn't desugar " ++ sdoc ex ReverseAppE fn arg -> do From dea90e3502914d0292a760bdfde68836bc8dce85 Mon Sep 17 00:00:00 2001 From: vidush Date: Wed, 5 Nov 2025 20:11:17 -0500 Subject: [PATCH 59/60] edits --- gibbon-compiler/src/Gibbon/NewL2/Syntax.hs | 2 +- gibbon-compiler/src/Gibbon/Passes/Cursorize.hs | 16 ++++++++++++++-- gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs index ef6828666..b78044042 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs @@ -595,7 +595,7 @@ allFreeVars ex = case ext of Old.LetRegionE r _ _ bod -> S.delete ((fromRegVarToFreeVarsTy . Old.regionToVar) r) (allFreeVars bod) Old.LetParRegionE r _ _ bod -> S.delete ((fromRegVarToFreeVarsTy . Old.regionToVar) r) (allFreeVars bod) - Old.LetLocE loc locexp bod -> S.difference ((S.singleton . fromLocVarToFreeVarsTy) loc) (allFreeVars bod `S.union` (S.map fromVarToFreeVarsTy $ gFreeVars locexp)) + Old.LetLocE loc locexp bod -> S.difference (allFreeVars bod `S.union` (S.map fromVarToFreeVarsTy $ gFreeVars locexp)) ((S.singleton . fromLocVarToFreeVarsTy) loc) Old.StartOfPkdCursor v -> S.singleton (fromVarToFreeVarsTy v) Old.TagCursor a b-> S.fromList [((fromLocVarToFreeVarsTy . toLocVar) a),((fromLocVarToFreeVarsTy . toLocVar) b)] Old.RetE locs v -> S.insert (fromVarToFreeVarsTy v) (S.fromList (map (fromLocVarToFreeVarsTy . toLocVar) locs)) diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index e5ed4989d..ed2f0cc76 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -10,6 +10,7 @@ import Control.Monad (forM) import Data.Foldable (foldlM, foldrM) import qualified Data.List as L import qualified Data.Map as M +--import qualified Data.Set as S import Data.Maybe (fromJust) import Gibbon.Common import Gibbon.DynFlags @@ -3378,7 +3379,7 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack fromDi <$> pure rhs' else do (rhs', _) <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv env senv rhs - pure rhs' + pure rhs' lookupVariable :: FreeVarsTy -> M.Map FreeVarsTy Var -> PassM Var lookupVariable loc fenv = case (M.lookup loc fenv) of @@ -3561,9 +3562,20 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack -- Int, Float, Sym, or Bool _ | isScalarTy ty -> do loc_var <- lookupVariable loc fenv + -- This won't work + -- VS: We need to take union of all branches + -- Traverse variables used there + -- Except for indirection or redirectin pointers + --let free_vars_rhs = allFreeVars rhs + --let var_used = dbgTrace (minChatLvl) "Print free vars: " dbgTrace (minChatLvl) (sdoc (free_vars_rhs, rhs)) dbgTrace (minChatLvl) "End free vars.\n" S.member (V v) free_vars_rhs + --(tenv', binds) <- if var_used + -- then scalarBinds ty v loc_var tenv + -- else return (tenv, []) (tenv', binds) <- scalarBinds ty v loc_var tenv let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1 - let field_cur' = map (\(k@(d, idx), var) -> if (d, idx) == (dcon, field_idx) then (k, (toEndV v)) else (k, var)) _field_cur + let field_cur' = map (\(k@(d, idx), var) -> if ((d, idx) == (dcon, field_idx)) {-&& var_used-} + then (k, (toEndV v)) + else (k, var)) _field_cur let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur if canBind then do diff --git a/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs b/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs index 5a1349f07..ab68edc71 100644 --- a/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs +++ b/gibbon-compiler/src/Gibbon/Passes/RouteEnds.hs @@ -504,7 +504,7 @@ routeEnds prg@Prog{ddefs,fundefs,mainExp} = do let eorr' = mkEnd l1 jump_loc eorr let (Just jump) = L1.sizeOfTy ty let fieldCon = LetLocE (jump_loc) (AfterConstantLE jump l1) - return (eorr', [fieldCon] ++ ee, seen, bnds) + return (eorr', ee ++ [fieldCon], seen, bnds) ) (eor, [], seenSamePackedTy, []) cases let in_dcon_lete = LetLocE (singleLocVar in_dbuf_loc) (GetDataConLocSoA scrutloc) let end_con_lete = LetLocE (getDconLoc final_soa_loc) (AfterConstantLE 1 (singleLocVar in_dbuf_loc)) From 4b590e7bf01aa055a6d71da808b17542fb99517b Mon Sep 17 00:00:00 2001 From: vidush Date: Fri, 7 Nov 2025 14:21:24 -0500 Subject: [PATCH 60/60] microbench --- microbench/manual_soa_examples/MonoTree.aos.c | 1106 ++++++ .../manual_soa_examples/MonoTree.aos.orig.c | 1049 ++++++ .../manual_soa_examples/MonoTree.aos.retarg.c | 1115 ++++++ microbench/manual_soa_examples/MonoTree.soa.c | 2050 ++++++++++ .../manual_soa_examples/MonoTree.soa.reurns.c | 1994 ++++++++++ microbench/manual_soa_examples/list.aos.c | 970 +++++ microbench/manual_soa_examples/list.soa.c | 1535 ++++++++ .../manual_soa_examples/reduceList.aos.c | 1984 ++++++++++ .../reduceList.aos.returns.c | 1982 ++++++++++ .../manual_soa_examples/reduceList.soa.c | 3332 +++++++++++++++++ .../reduceList.soa.returns.c | 3331 ++++++++++++++++ 11 files changed, 20448 insertions(+) create mode 100644 microbench/manual_soa_examples/MonoTree.aos.c create mode 100644 microbench/manual_soa_examples/MonoTree.aos.orig.c create mode 100644 microbench/manual_soa_examples/MonoTree.aos.retarg.c create mode 100644 microbench/manual_soa_examples/MonoTree.soa.c create mode 100644 microbench/manual_soa_examples/MonoTree.soa.reurns.c create mode 100644 microbench/manual_soa_examples/list.aos.c create mode 100644 microbench/manual_soa_examples/list.soa.c create mode 100644 microbench/manual_soa_examples/reduceList.aos.c create mode 100644 microbench/manual_soa_examples/reduceList.aos.returns.c create mode 100644 microbench/manual_soa_examples/reduceList.soa.c create mode 100644 microbench/manual_soa_examples/reduceList.soa.returns.c diff --git a/microbench/manual_soa_examples/MonoTree.aos.c b/microbench/manual_soa_examples/MonoTree.aos.c new file mode 100644 index 000000000..f8fe66e24 --- /dev/null +++ b/microbench/manual_soa_examples/MonoTree.aos.c @@ -0,0 +1,1106 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +void add1Tree(GibCursor *end_r_440, + GibCursor *end_r_442, + GibCursor *loc_438, + GibCursor *t_31_136_213); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_Tree(GibCursor end_r_446, GibCursor end_r_448, GibCursor loc_444, + GibCursor arg_89_141_222); +void sumTree(GibCursor *end_r_451, + GibCursor *tr_36_150_231, + GibInt *Res); +GibCursorGibCursorGibCursorProd mkTree(GibCursor end_r_454, GibCursor loc_452, + GibInt d_41_155_239, + GibInt acc_42_156_240); +GibCursorGibCursorProd _traverse_Tree(GibCursor end_r_457, + GibCursor arg_107_163_248); +GibCursorGibCursorProd _print_Tree(GibCursor end_r_460, + GibCursor arg_116_170_255); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_Tree(GibCursor end_r_464, GibCursor end_r_466, + GibCursor loc_462, GibCursor arg_98_187_272); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + Tree_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[3]; + + error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 0); + exit(1); + } + field_tys[0] = Tree_T; + field_tys[1] = Tree_T; + error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(1130, ")"); + gib_add_symbol(1131, "(Node"); + gib_add_symbol(1132, "(Leaf"); + gib_add_symbol(1133, " ->r "); + gib_add_symbol(1134, " ->i "); + gib_add_symbol(1135, " "); +} +//GibCursorGibCursorGibCursorGibCursorGibCursorProd +void add1Tree(GibCursor *end_r_440, + GibCursor *end_r_442, + GibCursor *loc_438, + GibCursor *t_31_136_213) +{ + if (*loc_438 + 18 > *end_r_442) { + gib_grow_region(loc_438, end_r_442); + } + + GibPackedTag tmpval_1169 = *(GibPackedTag *) (*t_31_136_213); + //GibCursor tmpcur_1170 = t_31_136_213 + 1; + *t_31_136_213 += 1; + + + switch_1229: + ; + switch (tmpval_1169) { + + case 0: + { + GibInt tmpval_1171 = *(GibInt *) (*t_31_136_213); + + //not used + //GibCursor tmpcur_1172 = tmpcur_1170 + sizeof(GibInt); + + //GibCursor jump_597 = tmpcur_1170 + 8; + *t_31_136_213 += 8; + + GibInt fltPkd_196_215 = tmpval_1171 + 1; + + *(GibPackedTag *) (*loc_438) = 0; + + //GibCursor writetag_782 = loc_438 + 1; + //GibCursor after_tag_783 = loc_438 + 1; + *loc_438 += 1; + + *(GibInt *) (*loc_438) = fltPkd_196_215; + + //GibCursor writecur_787 = after_tag_783 + sizeof(GibInt); + *(loc_438) += sizeof(GibInt); + + //GibCursorGibCursorGibCursorGibCursorGibCursorProd return_0; + + // return_0.field0 = end_r_440; + // return_0.field1 = end_r_442; + // return_0.field2 = jump_597; + // return_0.field3 = loc_438; + // return_0.field4 = writecur_787; + // return return_0; + break; + } + + case 1: + { + GibInt tmpval_1177 = *(GibInt *) (*t_31_136_213); + + //GibCursor tmpcur_1178 = tmpcur_1170 + sizeof(GibInt); + *t_31_136_213 += sizeof(GibInt); + + + //GibCursor jump_599 = tmpcur_1170 + 8; + GibInt fltPkd_197_219 = tmpval_1177 + 1; + + //GibCursor loc_495 = loc_438 + 1; + //GibCursor loc_496 = loc_495 + 8; + + + *(GibPackedTag *) (*loc_438) = 1; + *loc_438 += 1; + + //GibCursor writetag_798 = loc_438 + 1; + //GibCursor after_tag_799 = loc_438 + 1; + + *(GibInt *) (*loc_438) = fltPkd_197_219; + *loc_438 += 8; + + //GibCursor writecur_803 = after_tag_799 + sizeof(GibInt); + add1Tree(end_r_440, end_r_442, loc_438, t_31_136_213); + + + // GibCursor pvrtmp_1179 = tmp_struct_1.field0; + // GibCursor pvrtmp_1180 = tmp_struct_1.field1; + // GibCursor pvrtmp_1181 = tmp_struct_1.field2; + // GibCursor pvrtmp_1182 = tmp_struct_1.field3; + // GibCursor pvrtmp_1183 = tmp_struct_1.field4; + + add1Tree(end_r_440, end_r_442, loc_438, t_31_136_213); + + + // GibCursor pvrtmp_1188 = tmp_struct_2.field0; + // GibCursor pvrtmp_1189 = tmp_struct_2.field1; + // GibCursor pvrtmp_1190 = tmp_struct_2.field2; + // GibCursor pvrtmp_1191 = tmp_struct_2.field3; + // GibCursor pvrtmp_1192 = tmp_struct_2.field4; + /*GibCursorGibCursorGibCursorGibCursorGibCursorProd return_3; + + return_3.field0 = pvrtmp_1188; + return_3.field1 = pvrtmp_1189; + return_3.field2 = pvrtmp_1190; + return_3.field3 = loc_438; + return_3.field4 = pvrtmp_1192; + return return_3*/; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// uintptr_t tagged_tmpcur_6 = *(uintptr_t *) tmpcur_1170; +// GibCursor tmpcur_1201 = GIB_UNTAG(tagged_tmpcur_6); +// GibCursor tmpaftercur_1202 = tmpcur_1170 + 8; +// uint16_t tmptag_1203 = GIB_GET_TAG(tagged_tmpcur_6); +// GibCursor end_from_tagged_indr_645 = tmpcur_1201 + tmptag_1203; +// GibCursor jump_loc_647 = tmpcur_1170 + 8; +// GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_4 = +// add1Tree(tmpcur_1201, end_r_442, loc_438, tmpcur_1201); +// GibCursor pvrtmp_1204 = tmp_struct_4.field0; +// GibCursor pvrtmp_1205 = tmp_struct_4.field1; +// GibCursor pvrtmp_1206 = tmp_struct_4.field2; +// GibCursor pvrtmp_1207 = tmp_struct_4.field3; +// GibCursor pvrtmp_1208 = tmp_struct_4.field4; +// GibCursorGibCursorGibCursorGibCursorGibCursorProd return_5; +// +// return_5.field0 = end_r_440; +// return_5.field1 = pvrtmp_1205; +// return_5.field2 = jump_loc_647; +// return_5.field3 = pvrtmp_1207; +// return_5.field4 = pvrtmp_1208; +// return return_5; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_9 = *(uintptr_t *) (*t_31_136_213); + GibCursor tmpcur_1215 = GIB_UNTAG(tagged_tmpcur_9); + //GibCursor tmpaftercur_1216 = tmpcur_1170 + 8; + //uint16_t tmptag_1217 = GIB_GET_TAG(tagged_tmpcur_9); + //GibCursor end_from_tagged_indr_645 = tmpcur_1215 + tmptag_1217; + *t_31_136_213 = tmpcur_1215; + + add1Tree(t_31_136_213, end_r_442, loc_438, t_31_136_213); + +// GibCursor pvrtmp_1218 = tmp_struct_7.field0; +// GibCursor pvrtmp_1219 = tmp_struct_7.field1; +// GibCursor pvrtmp_1220 = tmp_struct_7.field2; +// GibCursor pvrtmp_1221 = tmp_struct_7.field3; +// GibCursor pvrtmp_1222 = tmp_struct_7.field4; +// GibCursorGibCursorGibCursorGibCursorGibCursorProd return_8; +// +// return_8.field0 = pvrtmp_1218; +// return_8.field1 = pvrtmp_1219; +// return_8.field2 = pvrtmp_1220; +// return_8.field3 = pvrtmp_1221; +// return_8.field4 = pvrtmp_1222; +// return return_8; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1169"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_Tree(GibCursor end_r_446, + GibCursor end_r_448, + GibCursor loc_444, + GibCursor arg_89_141_222) +{ + if (loc_444 + 18 > end_r_448) { + gib_grow_region(&loc_444, &end_r_448); + } + + GibPackedTag tmpval_1230 = *(GibPackedTag *) arg_89_141_222; + GibCursor tmpcur_1231 = arg_89_141_222 + 1; + + + switch_1290: + ; + switch (tmpval_1230) { + + case 0: + { + GibInt tmpval_1232 = *(GibInt *) tmpcur_1231; + GibCursor tmpcur_1233 = tmpcur_1231 + sizeof(GibInt); + GibCursor jump_603 = tmpcur_1231 + 8; + + *(GibPackedTag *) loc_444 = 0; + + GibCursor writetag_822 = loc_444 + 1; + GibCursor after_tag_823 = loc_444 + 1; + + *(GibInt *) after_tag_823 = tmpval_1232; + + GibCursor writecur_827 = after_tag_823 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_13; + + return_13.field0 = end_r_446; + return_13.field1 = end_r_448; + return_13.field2 = jump_603; + return_13.field3 = loc_444; + return_13.field4 = writecur_827; + return return_13; + break; + } + + case 1: + { + GibInt tmpval_1238 = *(GibInt *) tmpcur_1231; + GibCursor tmpcur_1239 = tmpcur_1231 + sizeof(GibInt); + GibCursor jump_605 = tmpcur_1231 + 8; + GibCursor loc_517 = loc_444 + 1; + GibCursor loc_518 = loc_517 + 8; + + *(GibPackedTag *) loc_444 = 1; + + GibCursor writetag_838 = loc_444 + 1; + GibCursor after_tag_839 = loc_444 + 1; + + *(GibInt *) after_tag_839 = tmpval_1238; + + GibCursor writecur_843 = after_tag_839 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_14 = + _copy_Tree(end_r_446, end_r_448, loc_518, tmpcur_1239); + GibCursor pvrtmp_1240 = tmp_struct_14.field0; + GibCursor pvrtmp_1241 = tmp_struct_14.field1; + GibCursor pvrtmp_1242 = tmp_struct_14.field2; + GibCursor pvrtmp_1243 = tmp_struct_14.field3; + GibCursor pvrtmp_1244 = tmp_struct_14.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_15 = + _copy_Tree(pvrtmp_1240, pvrtmp_1241, pvrtmp_1244, pvrtmp_1242); + GibCursor pvrtmp_1249 = tmp_struct_15.field0; + GibCursor pvrtmp_1250 = tmp_struct_15.field1; + GibCursor pvrtmp_1251 = tmp_struct_15.field2; + GibCursor pvrtmp_1252 = tmp_struct_15.field3; + GibCursor pvrtmp_1253 = tmp_struct_15.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_16; + + return_16.field0 = pvrtmp_1249; + return_16.field1 = pvrtmp_1250; + return_16.field2 = pvrtmp_1251; + return_16.field3 = loc_444; + return_16.field4 = pvrtmp_1253; + return return_16; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_19 = *(uintptr_t *) tmpcur_1231; + GibCursor tmpcur_1262 = GIB_UNTAG(tagged_tmpcur_19); + GibCursor tmpaftercur_1263 = tmpcur_1231 + 8; + uint16_t tmptag_1264 = GIB_GET_TAG(tagged_tmpcur_19); + GibCursor end_from_tagged_indr_651 = tmpcur_1262 + tmptag_1264; + GibCursor jump_loc_653 = tmpcur_1231 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_17 = + _copy_Tree(tmpcur_1262, end_r_448, loc_444, tmpcur_1262); + GibCursor pvrtmp_1265 = tmp_struct_17.field0; + GibCursor pvrtmp_1266 = tmp_struct_17.field1; + GibCursor pvrtmp_1267 = tmp_struct_17.field2; + GibCursor pvrtmp_1268 = tmp_struct_17.field3; + GibCursor pvrtmp_1269 = tmp_struct_17.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_18; + + return_18.field0 = end_r_446; + return_18.field1 = pvrtmp_1266; + return_18.field2 = jump_loc_653; + return_18.field3 = pvrtmp_1268; + return_18.field4 = pvrtmp_1269; + return return_18; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_22 = *(uintptr_t *) tmpcur_1231; + GibCursor tmpcur_1276 = GIB_UNTAG(tagged_tmpcur_22); + GibCursor tmpaftercur_1277 = tmpcur_1231 + 8; + uint16_t tmptag_1278 = GIB_GET_TAG(tagged_tmpcur_22); + GibCursor end_from_tagged_indr_651 = tmpcur_1276 + tmptag_1278; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_20 = + _copy_Tree(tmpcur_1276, end_r_448, loc_444, tmpcur_1276); + GibCursor pvrtmp_1279 = tmp_struct_20.field0; + GibCursor pvrtmp_1280 = tmp_struct_20.field1; + GibCursor pvrtmp_1281 = tmp_struct_20.field2; + GibCursor pvrtmp_1282 = tmp_struct_20.field3; + GibCursor pvrtmp_1283 = tmp_struct_20.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_21; + + return_21.field0 = pvrtmp_1279; + return_21.field1 = pvrtmp_1280; + return_21.field2 = pvrtmp_1281; + return_21.field3 = pvrtmp_1282; + return_21.field4 = pvrtmp_1283; + return return_21; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1230"); + exit(1); + } + } +} + +void sumTree(GibCursor *end_r_451, + GibCursor *tr_36_150_231, + GibInt *Res) +{ + GibPackedTag tmpval_1291 = *(GibPackedTag *) (*tr_36_150_231); + //GibCursor tmpcur_1292 = tr_36_150_231 + 1; + (*tr_36_150_231) += 1; + + + switch_1315: + ; + switch (tmpval_1291) { + + case 0: + { + GibInt tmpval_1293 = *(GibInt *) (*tr_36_150_231); + //GibCursor tmpcur_1294 = tmpcur_1292 + sizeof(GibInt); + //GibCursor jump_609 = tmpcur_1292 + 8; + + *(tr_36_150_231) += 8; + + // GibCursorGibCursorGibIntProd return_26; + // return_26.field0 = end_r_451; + // return_26.field1 = jump_609; + // return_26.field2 = tmpval_1293; + // return return_26; + *Res += tmpval_1293; + break; + } + + case 1: + { + GibInt tmpval_1295 = *(GibInt *) (*tr_36_150_231); + + //GibCursor tmpcur_1296 = tmpcur_1292 + sizeof(GibInt); + *tr_36_150_231 += sizeof(GibInt); + //GibCursor jump_610 = tmpcur_1292 + 8; + + *Res += tmpval_1295; + sumTree(end_r_451, tr_36_150_231, Res); + + // GibCursor pvrtmp_1297 = tmp_struct_27.field0; + // GibCursor pvrtmp_1298 = tmp_struct_27.field1; + // GibInt pvrtmp_1299 = tmp_struct_27.field2; + // GibInt fltPrm_200_237 = tmpval_1295 + pvrtmp_1299; + + + sumTree(end_r_451, tr_36_150_231, Res); + + + // GibCursor pvrtmp_1300 = tmp_struct_28.field0; + // GibCursor pvrtmp_1301 = tmp_struct_28.field1; + // GibInt pvrtmp_1302 = tmp_struct_28.field2; + // GibInt tailprim_613 = fltPrm_200_237 + pvrtmp_1302; + // GibCursorGibCursorGibIntProd return_29; + + // return_29.field0 = pvrtmp_1300; + // return_29.field1 = pvrtmp_1301; + // return_29.field2 = tailprim_613; + // return return_29; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// uintptr_t tagged_tmpcur_32 = *(uintptr_t *) tmpcur_1292; +// GibCursor tmpcur_1303 = GIB_UNTAG(tagged_tmpcur_32); +// GibCursor tmpaftercur_1304 = tmpcur_1292 + 8; +// uint16_t tmptag_1305 = GIB_GET_TAG(tagged_tmpcur_32); +// GibCursor end_from_tagged_indr_657 = tmpcur_1303 + tmptag_1305; +// GibCursor jump_loc_659 = tmpcur_1292 + 8; +// GibCursorGibCursorGibIntProd tmp_struct_30 = +// sumTree(tmpcur_1303, tmpcur_1303); +// GibCursor pvrtmp_1306 = tmp_struct_30.field0; +// GibCursor pvrtmp_1307 = tmp_struct_30.field1; +// GibInt pvrtmp_1308 = tmp_struct_30.field2; +// GibCursorGibCursorGibIntProd return_31; +// +// return_31.field0 = end_r_451; +// return_31.field1 = jump_loc_659; +// return_31.field2 = pvrtmp_1308; +// return return_31; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_35 = *(uintptr_t *) (*tr_36_150_231); + GibCursor tmpcur_1309 = GIB_UNTAG(tagged_tmpcur_35); + + //GibCursor tmpaftercur_1310 = tmpcur_1292 + 8; + //uint16_t tmptag_1311 = GIB_GET_TAG(tagged_tmpcur_35); + //GibCursor end_from_tagged_indr_657 = tmpcur_1309 + tmptag_1311; + *tr_36_150_231 = tmpcur_1309; + + sumTree(tr_36_150_231, tr_36_150_231, Res); + + // GibCursor pvrtmp_1312 = tmp_struct_33.field0; + // GibCursor pvrtmp_1313 = tmp_struct_33.field1; + // GibInt pvrtmp_1314 = tmp_struct_33.field2; + // GibCursorGibCursorGibIntProd return_34; + + // return_34.field0 = pvrtmp_1312; + // return_34.field1 = pvrtmp_1313; + // return_34.field2 = pvrtmp_1314; + // return return_34; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1291"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorProd mkTree(GibCursor end_r_454, GibCursor loc_452, + GibInt d_41_155_239, + GibInt acc_42_156_240) +{ + if (loc_452 + 18 > end_r_454) { + gib_grow_region(&loc_452, &end_r_454); + } + + GibBool fltIf_203_241 = d_41_155_239 == 0; + + if (fltIf_203_241) { + *(GibPackedTag *) loc_452 = 0; + + GibCursor writetag_876 = loc_452 + 1; + GibCursor after_tag_877 = loc_452 + 1; + + *(GibInt *) after_tag_877 = acc_42_156_240; + + GibCursor writecur_881 = after_tag_877 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd return_36; + + return_36.field0 = end_r_454; + return_36.field1 = loc_452; + return_36.field2 = writecur_881; + return return_36; + } else { + GibInt fltAppE_205_242 = d_41_155_239 - 1; + GibInt fltAppE_206_243 = d_41_155_239 + acc_42_156_240; + GibCursor loc_539 = loc_452 + 1; + GibCursor loc_540 = loc_539 + 8; + + *(GibPackedTag *) loc_452 = 1; + + GibCursor writetag_888 = loc_452 + 1; + GibCursor after_tag_889 = loc_452 + 1; + + *(GibInt *) after_tag_889 = d_41_155_239; + + GibCursor writecur_893 = after_tag_889 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd tmp_struct_37 = + mkTree(end_r_454, loc_540, fltAppE_205_242, fltAppE_206_243); + GibCursor pvrtmp_1320 = tmp_struct_37.field0; + GibCursor pvrtmp_1321 = tmp_struct_37.field1; + GibCursor pvrtmp_1322 = tmp_struct_37.field2; + GibInt fltAppE_208_245 = d_41_155_239 - 1; + GibInt fltAppE_209_246 = d_41_155_239 + acc_42_156_240; + GibCursorGibCursorGibCursorProd tmp_struct_38 = + mkTree(pvrtmp_1320, pvrtmp_1322, fltAppE_208_245, fltAppE_209_246); + GibCursor pvrtmp_1327 = tmp_struct_38.field0; + GibCursor pvrtmp_1328 = tmp_struct_38.field1; + GibCursor pvrtmp_1329 = tmp_struct_38.field2; + GibCursorGibCursorGibCursorProd return_39; + + return_39.field0 = pvrtmp_1327; + return_39.field1 = loc_452; + return_39.field2 = pvrtmp_1329; + return return_39; + } +} +GibCursorGibCursorProd _traverse_Tree(GibCursor end_r_457, + GibCursor arg_107_163_248) +{ + GibPackedTag tmpval_1338 = *(GibPackedTag *) arg_107_163_248; + GibCursor tmpcur_1339 = arg_107_163_248 + 1; + + + switch_1358: + ; + switch (tmpval_1338) { + + case 0: + { + GibInt tmpval_1340 = *(GibInt *) tmpcur_1339; + GibCursor tmpcur_1341 = tmpcur_1339 + sizeof(GibInt); + GibCursor jump_616 = tmpcur_1339 + 8; + GibCursorGibCursorProd return_43; + + return_43.field0 = end_r_457; + return_43.field1 = jump_616; + return return_43; + break; + } + + case 1: + { + GibInt tmpval_1342 = *(GibInt *) tmpcur_1339; + GibCursor tmpcur_1343 = tmpcur_1339 + sizeof(GibInt); + GibCursor jump_618 = tmpcur_1339 + 8; + GibCursorGibCursorProd tmp_struct_44 = + _traverse_Tree(end_r_457, tmpcur_1343); + GibCursor pvrtmp_1344 = tmp_struct_44.field0; + GibCursor pvrtmp_1345 = tmp_struct_44.field1; + GibCursorGibCursorProd tmp_struct_45 = + _traverse_Tree(pvrtmp_1344, pvrtmp_1345); + GibCursor pvrtmp_1346 = tmp_struct_45.field0; + GibCursor pvrtmp_1347 = tmp_struct_45.field1; + GibCursorGibCursorProd return_46; + + return_46.field0 = pvrtmp_1346; + return_46.field1 = pvrtmp_1347; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_1339; + GibCursor tmpcur_1348 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_1349 = tmpcur_1339 + 8; + uint16_t tmptag_1350 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_663 = tmpcur_1348 + tmptag_1350; + GibCursor jump_loc_665 = tmpcur_1339 + 8; + GibCursorGibCursorProd tmp_struct_47 = + _traverse_Tree(tmpcur_1348, tmpcur_1348); + GibCursor pvrtmp_1351 = tmp_struct_47.field0; + GibCursor pvrtmp_1352 = tmp_struct_47.field1; + GibCursorGibCursorProd return_48; + + return_48.field0 = end_r_457; + return_48.field1 = jump_loc_665; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_1339; + GibCursor tmpcur_1353 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_1354 = tmpcur_1339 + 8; + uint16_t tmptag_1355 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_663 = tmpcur_1353 + tmptag_1355; + GibCursorGibCursorProd tmp_struct_50 = + _traverse_Tree(tmpcur_1353, tmpcur_1353); + GibCursor pvrtmp_1356 = tmp_struct_50.field0; + GibCursor pvrtmp_1357 = tmp_struct_50.field1; + GibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_1356; + return_51.field1 = pvrtmp_1357; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1338"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_Tree(GibCursor end_r_460, + GibCursor arg_116_170_255) +{ + GibPackedTag tmpval_1359 = *(GibPackedTag *) arg_116_170_255; + GibCursor tmpcur_1360 = arg_116_170_255 + 1; + + + switch_1379: + ; + switch (tmpval_1359) { + + case 0: + { + GibInt tmpval_1361 = *(GibInt *) tmpcur_1360; + GibCursor tmpcur_1362 = tmpcur_1360 + sizeof(GibInt); + GibCursor jump_622 = tmpcur_1360 + 8; + unsigned char wildcard_119_172_257 = gib_print_symbol(1132); + unsigned char wildcard_121_173_258 = gib_print_symbol(1135); + unsigned char y_118_174_259 = printf("%ld", tmpval_1361); + unsigned char wildcard_120_175_260 = gib_print_symbol(1130); + GibCursorGibCursorProd return_53; + + return_53.field0 = end_r_460; + return_53.field1 = jump_622; + return return_53; + break; + } + + case 1: + { + GibInt tmpval_1363 = *(GibInt *) tmpcur_1360; + GibCursor tmpcur_1364 = tmpcur_1360 + sizeof(GibInt); + GibCursor jump_624 = tmpcur_1360 + 8; + unsigned char wildcard_128_179_264 = gib_print_symbol(1131); + unsigned char wildcard_132_180_265 = gib_print_symbol(1135); + unsigned char y_125_181_266 = printf("%ld", tmpval_1363); + unsigned char wildcard_131_182_267 = gib_print_symbol(1135); + GibCursorGibCursorProd tmp_struct_54 = + _print_Tree(end_r_460, tmpcur_1364); + GibCursor pvrtmp_1365 = tmp_struct_54.field0; + GibCursor pvrtmp_1366 = tmp_struct_54.field1; + unsigned char wildcard_130_184_269 = gib_print_symbol(1135); + GibCursorGibCursorProd tmp_struct_55 = + _print_Tree(pvrtmp_1365, pvrtmp_1366); + GibCursor pvrtmp_1367 = tmp_struct_55.field0; + GibCursor pvrtmp_1368 = tmp_struct_55.field1; + unsigned char wildcard_129_186_271 = gib_print_symbol(1130); + GibCursorGibCursorProd return_56; + + return_56.field0 = pvrtmp_1367; + return_56.field1 = pvrtmp_1368; + return return_56; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_59 = *(uintptr_t *) tmpcur_1360; + GibCursor tmpcur_1369 = GIB_UNTAG(tagged_tmpcur_59); + GibCursor tmpaftercur_1370 = tmpcur_1360 + 8; + uint16_t tmptag_1371 = GIB_GET_TAG(tagged_tmpcur_59); + GibCursor end_from_tagged_indr_669 = tmpcur_1369 + tmptag_1371; + GibCursor jump_loc_671 = tmpcur_1360 + 8; + unsigned char wildcard_674 = gib_print_symbol(1134); + GibCursorGibCursorProd tmp_struct_57 = + _print_Tree(tmpcur_1369, tmpcur_1369); + GibCursor pvrtmp_1372 = tmp_struct_57.field0; + GibCursor pvrtmp_1373 = tmp_struct_57.field1; + GibCursorGibCursorProd return_58; + + return_58.field0 = end_r_460; + return_58.field1 = jump_loc_671; + return return_58; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_62 = *(uintptr_t *) tmpcur_1360; + GibCursor tmpcur_1374 = GIB_UNTAG(tagged_tmpcur_62); + GibCursor tmpaftercur_1375 = tmpcur_1360 + 8; + uint16_t tmptag_1376 = GIB_GET_TAG(tagged_tmpcur_62); + GibCursor end_from_tagged_indr_669 = tmpcur_1374 + tmptag_1376; + unsigned char wildcard_674 = gib_print_symbol(1133); + GibCursorGibCursorProd tmp_struct_60 = + _print_Tree(tmpcur_1374, tmpcur_1374); + GibCursor pvrtmp_1377 = tmp_struct_60.field0; + GibCursor pvrtmp_1378 = tmp_struct_60.field1; + GibCursorGibCursorProd return_61; + + return_61.field0 = pvrtmp_1377; + return_61.field1 = pvrtmp_1378; + return return_61; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1359"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_Tree(GibCursor end_r_464, + GibCursor end_r_466, + GibCursor loc_462, + GibCursor arg_98_187_272) +{ + GibPackedTag tmpval_1380 = *(GibPackedTag *) arg_98_187_272; + GibCursor tmpcur_1381 = arg_98_187_272 + 1; + + + switch_1440: + ; + switch (tmpval_1380) { + + case 0: + { + GibInt tmpval_1382 = *(GibInt *) tmpcur_1381; + GibCursor tmpcur_1383 = tmpcur_1381 + sizeof(GibInt); + GibCursor jump_628 = tmpcur_1381 + 8; + + *(GibPackedTag *) loc_462 = 0; + + GibCursor writetag_936 = loc_462 + 1; + GibCursor after_tag_937 = loc_462 + 1; + + *(GibInt *) after_tag_937 = tmpval_1382; + + GibCursor writecur_941 = after_tag_937 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_63; + + return_63.field0 = end_r_464; + return_63.field1 = end_r_466; + return_63.field2 = jump_628; + return_63.field3 = loc_462; + return_63.field4 = writecur_941; + return return_63; + break; + } + + case 1: + { + GibInt tmpval_1388 = *(GibInt *) tmpcur_1381; + GibCursor tmpcur_1389 = tmpcur_1381 + sizeof(GibInt); + GibCursor jump_630 = tmpcur_1381 + 8; + GibCursor loc_581 = loc_462 + 1; + GibCursor loc_582 = loc_581 + 8; + + *(GibPackedTag *) loc_462 = 1; + + GibCursor writetag_952 = loc_462 + 1; + GibCursor after_tag_953 = loc_462 + 1; + + *(GibInt *) after_tag_953 = tmpval_1388; + + GibCursor writecur_957 = after_tag_953 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_64 = + _copy_without_ptrs_Tree(end_r_464, end_r_466, loc_582, tmpcur_1389); + GibCursor pvrtmp_1390 = tmp_struct_64.field0; + GibCursor pvrtmp_1391 = tmp_struct_64.field1; + GibCursor pvrtmp_1392 = tmp_struct_64.field2; + GibCursor pvrtmp_1393 = tmp_struct_64.field3; + GibCursor pvrtmp_1394 = tmp_struct_64.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_65 = + _copy_without_ptrs_Tree(pvrtmp_1390, pvrtmp_1391, pvrtmp_1394, pvrtmp_1392); + GibCursor pvrtmp_1399 = tmp_struct_65.field0; + GibCursor pvrtmp_1400 = tmp_struct_65.field1; + GibCursor pvrtmp_1401 = tmp_struct_65.field2; + GibCursor pvrtmp_1402 = tmp_struct_65.field3; + GibCursor pvrtmp_1403 = tmp_struct_65.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_66; + + return_66.field0 = pvrtmp_1399; + return_66.field1 = pvrtmp_1400; + return_66.field2 = pvrtmp_1401; + return_66.field3 = loc_462; + return_66.field4 = pvrtmp_1403; + return return_66; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_69 = *(uintptr_t *) tmpcur_1381; + GibCursor tmpcur_1412 = GIB_UNTAG(tagged_tmpcur_69); + GibCursor tmpaftercur_1413 = tmpcur_1381 + 8; + uint16_t tmptag_1414 = GIB_GET_TAG(tagged_tmpcur_69); + GibCursor end_from_tagged_indr_675 = tmpcur_1412 + tmptag_1414; + GibCursor jump_loc_677 = tmpcur_1381 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_67 = + _copy_without_ptrs_Tree(tmpcur_1412, end_r_466, loc_462, tmpcur_1412); + GibCursor pvrtmp_1415 = tmp_struct_67.field0; + GibCursor pvrtmp_1416 = tmp_struct_67.field1; + GibCursor pvrtmp_1417 = tmp_struct_67.field2; + GibCursor pvrtmp_1418 = tmp_struct_67.field3; + GibCursor pvrtmp_1419 = tmp_struct_67.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_68; + + return_68.field0 = end_r_464; + return_68.field1 = pvrtmp_1416; + return_68.field2 = jump_loc_677; + return_68.field3 = pvrtmp_1418; + return_68.field4 = pvrtmp_1419; + return return_68; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_72 = *(uintptr_t *) tmpcur_1381; + GibCursor tmpcur_1426 = GIB_UNTAG(tagged_tmpcur_72); + GibCursor tmpaftercur_1427 = tmpcur_1381 + 8; + uint16_t tmptag_1428 = GIB_GET_TAG(tagged_tmpcur_72); + GibCursor end_from_tagged_indr_675 = tmpcur_1426 + tmptag_1428; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_70 = + _copy_without_ptrs_Tree(tmpcur_1426, end_r_466, loc_462, tmpcur_1426); + GibCursor pvrtmp_1429 = tmp_struct_70.field0; + GibCursor pvrtmp_1430 = tmp_struct_70.field1; + GibCursor pvrtmp_1431 = tmp_struct_70.field2; + GibCursor pvrtmp_1432 = tmp_struct_70.field3; + GibCursor pvrtmp_1433 = tmp_struct_70.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_71; + + return_71.field0 = pvrtmp_1429; + return_71.field1 = pvrtmp_1430; + return_71.field2 = pvrtmp_1431; + return_71.field3 = pvrtmp_1432; + return_71.field4 = pvrtmp_1433; + return return_71; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1380"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_86 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_1136 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_479 = region_1136.start; + GibCursor end_r_479 = region_1136.end; + GibCursorGibCursorGibCursorProd tmp_struct_73 = + mkTree(end_r_479, r_479, 23, 0); + GibCursor pvrtmp_1137 = tmp_struct_73.field0; + GibCursor pvrtmp_1138 = tmp_struct_73.field1; + GibCursor pvrtmp_1139 = tmp_struct_73.field2; + GibChunk region_1144 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_478 = region_1144.start; + GibCursor end_r_478 = region_1144.end; + GibCursor pvrtmp_1156; + GibCursor pvrtmp_1157; + GibCursor pvrtmp_1158; + GibVector *times_78 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_1156; + struct timespec end_pvrtmp_1156; + + for (long long iters_pvrtmp_1156 = 0; iters_pvrtmp_1156 < + gib_get_iters_param(); iters_pvrtmp_1156++) { + if (iters_pvrtmp_1156 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_1156); + + add1Tree(&pvrtmp_1137, &end_r_478, &r_478, &pvrtmp_1138); + + // GibCursor pvrtmp_1145 = tmp_struct_74.field0; + // GibCursor pvrtmp_1146 = tmp_struct_74.field1; + // GibCursor pvrtmp_1147 = tmp_struct_74.field2; + // GibCursor pvrtmp_1148 = tmp_struct_74.field3; + // GibCursor pvrtmp_1149 = tmp_struct_74.field4; + + // pvrtmp_1156 = pvrtmp_1146; + //pvrtmp_1157 = pvrtmp_1148; + // pvrtmp_1158 = pvrtmp_1149; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_1156); + if (iters_pvrtmp_1156 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + pvrtmp_1137 = tmp_struct_73.field0; + end_r_478 = region_1144.end; + r_478 = region_1144.start; + pvrtmp_1138 = tmp_struct_73.field1; + pvrtmp_1157 = region_1144.start; + + double itertime_75 = gib_difftimespecs(&begin_pvrtmp_1156, + &end_pvrtmp_1156); + + printf("itertime: %lf\n", itertime_75); + gib_vector_inplace_update(times_78, iters_pvrtmp_1156, &itertime_75); + } + gib_vector_inplace_sort(times_78, gib_compare_doubles); + + double *tmp_79 = (double *) gib_vector_nth(times_78, gib_get_iters_param() / + 2); + double selftimed_77 = *tmp_79; + double batchtime_76 = gib_sum_timing_array(times_78); + + gib_print_timing_array(times_78); + gib_vector_free(times_78); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_76); + printf("SELFTIMED: %e\n", selftimed_77); + + GibInt timed_1031; + GibVector *times_84 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_1031; + struct timespec end_timed_1031; + + for (long long iters_timed_1031 = 0; iters_timed_1031 < + gib_get_iters_param(); iters_timed_1031++) { + if (iters_timed_1031 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_1031); + + GibInt Res = 0; + sumTree(&end_r_478, &pvrtmp_1157, &Res); + + // GibCursor pvrtmp_1166 = tmp_struct_80.field0; + // GibCursor pvrtmp_1167 = tmp_struct_80.field1; + // GibInt pvrtmp_1168 = tmp_struct_80.field2; + + timed_1031 = Res; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_1031); + if (iters_timed_1031 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + //Save the state of mutable cursors. + end_r_478 = region_1144.end; + pvrtmp_1157 = region_1144.start; + Res = 0; + + double itertime_81 = gib_difftimespecs(&begin_timed_1031, + &end_timed_1031); + + printf("itertime: %lf\n", itertime_81); + gib_vector_inplace_update(times_84, iters_timed_1031, &itertime_81); + } + gib_vector_inplace_sort(times_84, gib_compare_doubles); + + double *tmp_85 = (double *) gib_vector_nth(times_84, gib_get_iters_param() / + 2); + double selftimed_83 = *tmp_85; + double batchtime_82 = gib_sum_timing_array(times_84); + + gib_print_timing_array(times_84); + gib_vector_free(times_84); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_82); + printf("SELFTIMED: %e\n", selftimed_83); + printf("%ld", timed_1031); + printf("\n"); + + int exit_87 = gib_exit(); + + return exit_87; +} + +// gcc -std=gnu11 -O3 -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + +// gcc -std=gnu11 -g -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + diff --git a/microbench/manual_soa_examples/MonoTree.aos.orig.c b/microbench/manual_soa_examples/MonoTree.aos.orig.c new file mode 100644 index 000000000..4b0fc85e3 --- /dev/null +++ b/microbench/manual_soa_examples/MonoTree.aos.orig.c @@ -0,0 +1,1049 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +GibCursorGibCursorGibCursorGibCursorGibCursorProd add1Tree(GibCursor end_r_440, + GibCursor end_r_442, + GibCursor loc_438, + GibCursor t_31_136_213); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_Tree(GibCursor end_r_446, GibCursor end_r_448, GibCursor loc_444, + GibCursor arg_89_141_222); +GibCursorGibCursorGibIntProd sumTree(GibCursor end_r_451, + GibCursor tr_36_150_231); +GibCursorGibCursorGibCursorProd mkTree(GibCursor end_r_454, GibCursor loc_452, + GibInt d_41_155_239, + GibInt acc_42_156_240); +GibCursorGibCursorProd _traverse_Tree(GibCursor end_r_457, + GibCursor arg_107_163_248); +GibCursorGibCursorProd _print_Tree(GibCursor end_r_460, + GibCursor arg_116_170_255); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_Tree(GibCursor end_r_464, GibCursor end_r_466, + GibCursor loc_462, GibCursor arg_98_187_272); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + Tree_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[3]; + + error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 0); + exit(1); + } + field_tys[0] = Tree_T; + field_tys[1] = Tree_T; + error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(1130, ")"); + gib_add_symbol(1131, "(Node"); + gib_add_symbol(1132, "(Leaf"); + gib_add_symbol(1133, " ->r "); + gib_add_symbol(1134, " ->i "); + gib_add_symbol(1135, " "); +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd add1Tree(GibCursor end_r_440, + GibCursor end_r_442, + GibCursor loc_438, + GibCursor t_31_136_213) +{ + if (loc_438 + 18 > end_r_442) { + gib_grow_region(&loc_438, &end_r_442); + } + + GibPackedTag tmpval_1169 = *(GibPackedTag *) t_31_136_213; + GibCursor tmpcur_1170 = t_31_136_213 + 1; + + + switch_1229: + ; + switch (tmpval_1169) { + + case 0: + { + GibInt tmpval_1171 = *(GibInt *) tmpcur_1170; + GibCursor tmpcur_1172 = tmpcur_1170 + sizeof(GibInt); + GibCursor jump_597 = tmpcur_1170 + 8; + GibInt fltPkd_196_215 = tmpval_1171 + 1; + + *(GibPackedTag *) loc_438 = 0; + + GibCursor writetag_782 = loc_438 + 1; + GibCursor after_tag_783 = loc_438 + 1; + + *(GibInt *) after_tag_783 = fltPkd_196_215; + + GibCursor writecur_787 = after_tag_783 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_0; + + return_0.field0 = end_r_440; + return_0.field1 = end_r_442; + return_0.field2 = jump_597; + return_0.field3 = loc_438; + return_0.field4 = writecur_787; + return return_0; + break; + } + + case 1: + { + GibInt tmpval_1177 = *(GibInt *) tmpcur_1170; + GibCursor tmpcur_1178 = tmpcur_1170 + sizeof(GibInt); + GibCursor jump_599 = tmpcur_1170 + 8; + GibInt fltPkd_197_219 = tmpval_1177 + 1; + GibCursor loc_495 = loc_438 + 1; + GibCursor loc_496 = loc_495 + 8; + + *(GibPackedTag *) loc_438 = 1; + + GibCursor writetag_798 = loc_438 + 1; + GibCursor after_tag_799 = loc_438 + 1; + + *(GibInt *) after_tag_799 = fltPkd_197_219; + + GibCursor writecur_803 = after_tag_799 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_1 = + add1Tree(end_r_440, end_r_442, loc_496, tmpcur_1178); + GibCursor pvrtmp_1179 = tmp_struct_1.field0; + GibCursor pvrtmp_1180 = tmp_struct_1.field1; + GibCursor pvrtmp_1181 = tmp_struct_1.field2; + GibCursor pvrtmp_1182 = tmp_struct_1.field3; + GibCursor pvrtmp_1183 = tmp_struct_1.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_2 = + add1Tree(pvrtmp_1179, pvrtmp_1180, pvrtmp_1183, pvrtmp_1181); + GibCursor pvrtmp_1188 = tmp_struct_2.field0; + GibCursor pvrtmp_1189 = tmp_struct_2.field1; + GibCursor pvrtmp_1190 = tmp_struct_2.field2; + GibCursor pvrtmp_1191 = tmp_struct_2.field3; + GibCursor pvrtmp_1192 = tmp_struct_2.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_3; + + return_3.field0 = pvrtmp_1188; + return_3.field1 = pvrtmp_1189; + return_3.field2 = pvrtmp_1190; + return_3.field3 = loc_438; + return_3.field4 = pvrtmp_1192; + return return_3; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_6 = *(uintptr_t *) tmpcur_1170; + GibCursor tmpcur_1201 = GIB_UNTAG(tagged_tmpcur_6); + GibCursor tmpaftercur_1202 = tmpcur_1170 + 8; + uint16_t tmptag_1203 = GIB_GET_TAG(tagged_tmpcur_6); + GibCursor end_from_tagged_indr_645 = tmpcur_1201 + tmptag_1203; + GibCursor jump_loc_647 = tmpcur_1170 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_4 = + add1Tree(tmpcur_1201, end_r_442, loc_438, tmpcur_1201); + GibCursor pvrtmp_1204 = tmp_struct_4.field0; + GibCursor pvrtmp_1205 = tmp_struct_4.field1; + GibCursor pvrtmp_1206 = tmp_struct_4.field2; + GibCursor pvrtmp_1207 = tmp_struct_4.field3; + GibCursor pvrtmp_1208 = tmp_struct_4.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_5; + + return_5.field0 = end_r_440; + return_5.field1 = pvrtmp_1205; + return_5.field2 = jump_loc_647; + return_5.field3 = pvrtmp_1207; + return_5.field4 = pvrtmp_1208; + return return_5; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_9 = *(uintptr_t *) tmpcur_1170; + GibCursor tmpcur_1215 = GIB_UNTAG(tagged_tmpcur_9); + GibCursor tmpaftercur_1216 = tmpcur_1170 + 8; + uint16_t tmptag_1217 = GIB_GET_TAG(tagged_tmpcur_9); + GibCursor end_from_tagged_indr_645 = tmpcur_1215 + tmptag_1217; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_7 = + add1Tree(tmpcur_1215, end_r_442, loc_438, tmpcur_1215); + GibCursor pvrtmp_1218 = tmp_struct_7.field0; + GibCursor pvrtmp_1219 = tmp_struct_7.field1; + GibCursor pvrtmp_1220 = tmp_struct_7.field2; + GibCursor pvrtmp_1221 = tmp_struct_7.field3; + GibCursor pvrtmp_1222 = tmp_struct_7.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_8; + + return_8.field0 = pvrtmp_1218; + return_8.field1 = pvrtmp_1219; + return_8.field2 = pvrtmp_1220; + return_8.field3 = pvrtmp_1221; + return_8.field4 = pvrtmp_1222; + return return_8; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1169"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_Tree(GibCursor end_r_446, + GibCursor end_r_448, + GibCursor loc_444, + GibCursor arg_89_141_222) +{ + if (loc_444 + 18 > end_r_448) { + gib_grow_region(&loc_444, &end_r_448); + } + + GibPackedTag tmpval_1230 = *(GibPackedTag *) arg_89_141_222; + GibCursor tmpcur_1231 = arg_89_141_222 + 1; + + + switch_1290: + ; + switch (tmpval_1230) { + + case 0: + { + GibInt tmpval_1232 = *(GibInt *) tmpcur_1231; + GibCursor tmpcur_1233 = tmpcur_1231 + sizeof(GibInt); + GibCursor jump_603 = tmpcur_1231 + 8; + + *(GibPackedTag *) loc_444 = 0; + + GibCursor writetag_822 = loc_444 + 1; + GibCursor after_tag_823 = loc_444 + 1; + + *(GibInt *) after_tag_823 = tmpval_1232; + + GibCursor writecur_827 = after_tag_823 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_13; + + return_13.field0 = end_r_446; + return_13.field1 = end_r_448; + return_13.field2 = jump_603; + return_13.field3 = loc_444; + return_13.field4 = writecur_827; + return return_13; + break; + } + + case 1: + { + GibInt tmpval_1238 = *(GibInt *) tmpcur_1231; + GibCursor tmpcur_1239 = tmpcur_1231 + sizeof(GibInt); + GibCursor jump_605 = tmpcur_1231 + 8; + GibCursor loc_517 = loc_444 + 1; + GibCursor loc_518 = loc_517 + 8; + + *(GibPackedTag *) loc_444 = 1; + + GibCursor writetag_838 = loc_444 + 1; + GibCursor after_tag_839 = loc_444 + 1; + + *(GibInt *) after_tag_839 = tmpval_1238; + + GibCursor writecur_843 = after_tag_839 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_14 = + _copy_Tree(end_r_446, end_r_448, loc_518, tmpcur_1239); + GibCursor pvrtmp_1240 = tmp_struct_14.field0; + GibCursor pvrtmp_1241 = tmp_struct_14.field1; + GibCursor pvrtmp_1242 = tmp_struct_14.field2; + GibCursor pvrtmp_1243 = tmp_struct_14.field3; + GibCursor pvrtmp_1244 = tmp_struct_14.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_15 = + _copy_Tree(pvrtmp_1240, pvrtmp_1241, pvrtmp_1244, pvrtmp_1242); + GibCursor pvrtmp_1249 = tmp_struct_15.field0; + GibCursor pvrtmp_1250 = tmp_struct_15.field1; + GibCursor pvrtmp_1251 = tmp_struct_15.field2; + GibCursor pvrtmp_1252 = tmp_struct_15.field3; + GibCursor pvrtmp_1253 = tmp_struct_15.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_16; + + return_16.field0 = pvrtmp_1249; + return_16.field1 = pvrtmp_1250; + return_16.field2 = pvrtmp_1251; + return_16.field3 = loc_444; + return_16.field4 = pvrtmp_1253; + return return_16; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_19 = *(uintptr_t *) tmpcur_1231; + GibCursor tmpcur_1262 = GIB_UNTAG(tagged_tmpcur_19); + GibCursor tmpaftercur_1263 = tmpcur_1231 + 8; + uint16_t tmptag_1264 = GIB_GET_TAG(tagged_tmpcur_19); + GibCursor end_from_tagged_indr_651 = tmpcur_1262 + tmptag_1264; + GibCursor jump_loc_653 = tmpcur_1231 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_17 = + _copy_Tree(tmpcur_1262, end_r_448, loc_444, tmpcur_1262); + GibCursor pvrtmp_1265 = tmp_struct_17.field0; + GibCursor pvrtmp_1266 = tmp_struct_17.field1; + GibCursor pvrtmp_1267 = tmp_struct_17.field2; + GibCursor pvrtmp_1268 = tmp_struct_17.field3; + GibCursor pvrtmp_1269 = tmp_struct_17.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_18; + + return_18.field0 = end_r_446; + return_18.field1 = pvrtmp_1266; + return_18.field2 = jump_loc_653; + return_18.field3 = pvrtmp_1268; + return_18.field4 = pvrtmp_1269; + return return_18; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_22 = *(uintptr_t *) tmpcur_1231; + GibCursor tmpcur_1276 = GIB_UNTAG(tagged_tmpcur_22); + GibCursor tmpaftercur_1277 = tmpcur_1231 + 8; + uint16_t tmptag_1278 = GIB_GET_TAG(tagged_tmpcur_22); + GibCursor end_from_tagged_indr_651 = tmpcur_1276 + tmptag_1278; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_20 = + _copy_Tree(tmpcur_1276, end_r_448, loc_444, tmpcur_1276); + GibCursor pvrtmp_1279 = tmp_struct_20.field0; + GibCursor pvrtmp_1280 = tmp_struct_20.field1; + GibCursor pvrtmp_1281 = tmp_struct_20.field2; + GibCursor pvrtmp_1282 = tmp_struct_20.field3; + GibCursor pvrtmp_1283 = tmp_struct_20.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_21; + + return_21.field0 = pvrtmp_1279; + return_21.field1 = pvrtmp_1280; + return_21.field2 = pvrtmp_1281; + return_21.field3 = pvrtmp_1282; + return_21.field4 = pvrtmp_1283; + return return_21; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1230"); + exit(1); + } + } +} +GibCursorGibCursorGibIntProd sumTree(GibCursor end_r_451, + GibCursor tr_36_150_231) +{ + GibPackedTag tmpval_1291 = *(GibPackedTag *) tr_36_150_231; + GibCursor tmpcur_1292 = tr_36_150_231 + 1; + + + switch_1315: + ; + switch (tmpval_1291) { + + case 0: + { + GibInt tmpval_1293 = *(GibInt *) tmpcur_1292; + GibCursor tmpcur_1294 = tmpcur_1292 + sizeof(GibInt); + GibCursor jump_609 = tmpcur_1292 + 8; + GibCursorGibCursorGibIntProd return_26; + + return_26.field0 = end_r_451; + return_26.field1 = jump_609; + return_26.field2 = tmpval_1293; + return return_26; + break; + } + + case 1: + { + GibInt tmpval_1295 = *(GibInt *) tmpcur_1292; + GibCursor tmpcur_1296 = tmpcur_1292 + sizeof(GibInt); + GibCursor jump_610 = tmpcur_1292 + 8; + GibCursorGibCursorGibIntProd tmp_struct_27 = + sumTree(end_r_451, tmpcur_1296); + GibCursor pvrtmp_1297 = tmp_struct_27.field0; + GibCursor pvrtmp_1298 = tmp_struct_27.field1; + GibInt pvrtmp_1299 = tmp_struct_27.field2; + GibInt fltPrm_200_237 = tmpval_1295 + pvrtmp_1299; + GibCursorGibCursorGibIntProd tmp_struct_28 = + sumTree(pvrtmp_1297, pvrtmp_1298); + GibCursor pvrtmp_1300 = tmp_struct_28.field0; + GibCursor pvrtmp_1301 = tmp_struct_28.field1; + GibInt pvrtmp_1302 = tmp_struct_28.field2; + GibInt tailprim_613 = fltPrm_200_237 + pvrtmp_1302; + GibCursorGibCursorGibIntProd return_29; + + return_29.field0 = pvrtmp_1300; + return_29.field1 = pvrtmp_1301; + return_29.field2 = tailprim_613; + return return_29; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_32 = *(uintptr_t *) tmpcur_1292; + GibCursor tmpcur_1303 = GIB_UNTAG(tagged_tmpcur_32); + GibCursor tmpaftercur_1304 = tmpcur_1292 + 8; + uint16_t tmptag_1305 = GIB_GET_TAG(tagged_tmpcur_32); + GibCursor end_from_tagged_indr_657 = tmpcur_1303 + tmptag_1305; + GibCursor jump_loc_659 = tmpcur_1292 + 8; + GibCursorGibCursorGibIntProd tmp_struct_30 = + sumTree(tmpcur_1303, tmpcur_1303); + GibCursor pvrtmp_1306 = tmp_struct_30.field0; + GibCursor pvrtmp_1307 = tmp_struct_30.field1; + GibInt pvrtmp_1308 = tmp_struct_30.field2; + GibCursorGibCursorGibIntProd return_31; + + return_31.field0 = end_r_451; + return_31.field1 = jump_loc_659; + return_31.field2 = pvrtmp_1308; + return return_31; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_35 = *(uintptr_t *) tmpcur_1292; + GibCursor tmpcur_1309 = GIB_UNTAG(tagged_tmpcur_35); + GibCursor tmpaftercur_1310 = tmpcur_1292 + 8; + uint16_t tmptag_1311 = GIB_GET_TAG(tagged_tmpcur_35); + GibCursor end_from_tagged_indr_657 = tmpcur_1309 + tmptag_1311; + GibCursorGibCursorGibIntProd tmp_struct_33 = + sumTree(tmpcur_1309, tmpcur_1309); + GibCursor pvrtmp_1312 = tmp_struct_33.field0; + GibCursor pvrtmp_1313 = tmp_struct_33.field1; + GibInt pvrtmp_1314 = tmp_struct_33.field2; + GibCursorGibCursorGibIntProd return_34; + + return_34.field0 = pvrtmp_1312; + return_34.field1 = pvrtmp_1313; + return_34.field2 = pvrtmp_1314; + return return_34; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1291"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorProd mkTree(GibCursor end_r_454, GibCursor loc_452, + GibInt d_41_155_239, + GibInt acc_42_156_240) +{ + if (loc_452 + 18 > end_r_454) { + gib_grow_region(&loc_452, &end_r_454); + } + + GibBool fltIf_203_241 = d_41_155_239 == 0; + + if (fltIf_203_241) { + *(GibPackedTag *) loc_452 = 0; + + GibCursor writetag_876 = loc_452 + 1; + GibCursor after_tag_877 = loc_452 + 1; + + *(GibInt *) after_tag_877 = acc_42_156_240; + + GibCursor writecur_881 = after_tag_877 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd return_36; + + return_36.field0 = end_r_454; + return_36.field1 = loc_452; + return_36.field2 = writecur_881; + return return_36; + } else { + GibInt fltAppE_205_242 = d_41_155_239 - 1; + GibInt fltAppE_206_243 = d_41_155_239 + acc_42_156_240; + GibCursor loc_539 = loc_452 + 1; + GibCursor loc_540 = loc_539 + 8; + + *(GibPackedTag *) loc_452 = 1; + + GibCursor writetag_888 = loc_452 + 1; + GibCursor after_tag_889 = loc_452 + 1; + + *(GibInt *) after_tag_889 = d_41_155_239; + + GibCursor writecur_893 = after_tag_889 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd tmp_struct_37 = + mkTree(end_r_454, loc_540, fltAppE_205_242, fltAppE_206_243); + GibCursor pvrtmp_1320 = tmp_struct_37.field0; + GibCursor pvrtmp_1321 = tmp_struct_37.field1; + GibCursor pvrtmp_1322 = tmp_struct_37.field2; + GibInt fltAppE_208_245 = d_41_155_239 - 1; + GibInt fltAppE_209_246 = d_41_155_239 + acc_42_156_240; + GibCursorGibCursorGibCursorProd tmp_struct_38 = + mkTree(pvrtmp_1320, pvrtmp_1322, fltAppE_208_245, fltAppE_209_246); + GibCursor pvrtmp_1327 = tmp_struct_38.field0; + GibCursor pvrtmp_1328 = tmp_struct_38.field1; + GibCursor pvrtmp_1329 = tmp_struct_38.field2; + GibCursorGibCursorGibCursorProd return_39; + + return_39.field0 = pvrtmp_1327; + return_39.field1 = loc_452; + return_39.field2 = pvrtmp_1329; + return return_39; + } +} +GibCursorGibCursorProd _traverse_Tree(GibCursor end_r_457, + GibCursor arg_107_163_248) +{ + GibPackedTag tmpval_1338 = *(GibPackedTag *) arg_107_163_248; + GibCursor tmpcur_1339 = arg_107_163_248 + 1; + + + switch_1358: + ; + switch (tmpval_1338) { + + case 0: + { + GibInt tmpval_1340 = *(GibInt *) tmpcur_1339; + GibCursor tmpcur_1341 = tmpcur_1339 + sizeof(GibInt); + GibCursor jump_616 = tmpcur_1339 + 8; + GibCursorGibCursorProd return_43; + + return_43.field0 = end_r_457; + return_43.field1 = jump_616; + return return_43; + break; + } + + case 1: + { + GibInt tmpval_1342 = *(GibInt *) tmpcur_1339; + GibCursor tmpcur_1343 = tmpcur_1339 + sizeof(GibInt); + GibCursor jump_618 = tmpcur_1339 + 8; + GibCursorGibCursorProd tmp_struct_44 = + _traverse_Tree(end_r_457, tmpcur_1343); + GibCursor pvrtmp_1344 = tmp_struct_44.field0; + GibCursor pvrtmp_1345 = tmp_struct_44.field1; + GibCursorGibCursorProd tmp_struct_45 = + _traverse_Tree(pvrtmp_1344, pvrtmp_1345); + GibCursor pvrtmp_1346 = tmp_struct_45.field0; + GibCursor pvrtmp_1347 = tmp_struct_45.field1; + GibCursorGibCursorProd return_46; + + return_46.field0 = pvrtmp_1346; + return_46.field1 = pvrtmp_1347; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_1339; + GibCursor tmpcur_1348 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_1349 = tmpcur_1339 + 8; + uint16_t tmptag_1350 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_663 = tmpcur_1348 + tmptag_1350; + GibCursor jump_loc_665 = tmpcur_1339 + 8; + GibCursorGibCursorProd tmp_struct_47 = + _traverse_Tree(tmpcur_1348, tmpcur_1348); + GibCursor pvrtmp_1351 = tmp_struct_47.field0; + GibCursor pvrtmp_1352 = tmp_struct_47.field1; + GibCursorGibCursorProd return_48; + + return_48.field0 = end_r_457; + return_48.field1 = jump_loc_665; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_1339; + GibCursor tmpcur_1353 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_1354 = tmpcur_1339 + 8; + uint16_t tmptag_1355 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_663 = tmpcur_1353 + tmptag_1355; + GibCursorGibCursorProd tmp_struct_50 = + _traverse_Tree(tmpcur_1353, tmpcur_1353); + GibCursor pvrtmp_1356 = tmp_struct_50.field0; + GibCursor pvrtmp_1357 = tmp_struct_50.field1; + GibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_1356; + return_51.field1 = pvrtmp_1357; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1338"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_Tree(GibCursor end_r_460, + GibCursor arg_116_170_255) +{ + GibPackedTag tmpval_1359 = *(GibPackedTag *) arg_116_170_255; + GibCursor tmpcur_1360 = arg_116_170_255 + 1; + + + switch_1379: + ; + switch (tmpval_1359) { + + case 0: + { + GibInt tmpval_1361 = *(GibInt *) tmpcur_1360; + GibCursor tmpcur_1362 = tmpcur_1360 + sizeof(GibInt); + GibCursor jump_622 = tmpcur_1360 + 8; + unsigned char wildcard_119_172_257 = gib_print_symbol(1132); + unsigned char wildcard_121_173_258 = gib_print_symbol(1135); + unsigned char y_118_174_259 = printf("%ld", tmpval_1361); + unsigned char wildcard_120_175_260 = gib_print_symbol(1130); + GibCursorGibCursorProd return_53; + + return_53.field0 = end_r_460; + return_53.field1 = jump_622; + return return_53; + break; + } + + case 1: + { + GibInt tmpval_1363 = *(GibInt *) tmpcur_1360; + GibCursor tmpcur_1364 = tmpcur_1360 + sizeof(GibInt); + GibCursor jump_624 = tmpcur_1360 + 8; + unsigned char wildcard_128_179_264 = gib_print_symbol(1131); + unsigned char wildcard_132_180_265 = gib_print_symbol(1135); + unsigned char y_125_181_266 = printf("%ld", tmpval_1363); + unsigned char wildcard_131_182_267 = gib_print_symbol(1135); + GibCursorGibCursorProd tmp_struct_54 = + _print_Tree(end_r_460, tmpcur_1364); + GibCursor pvrtmp_1365 = tmp_struct_54.field0; + GibCursor pvrtmp_1366 = tmp_struct_54.field1; + unsigned char wildcard_130_184_269 = gib_print_symbol(1135); + GibCursorGibCursorProd tmp_struct_55 = + _print_Tree(pvrtmp_1365, pvrtmp_1366); + GibCursor pvrtmp_1367 = tmp_struct_55.field0; + GibCursor pvrtmp_1368 = tmp_struct_55.field1; + unsigned char wildcard_129_186_271 = gib_print_symbol(1130); + GibCursorGibCursorProd return_56; + + return_56.field0 = pvrtmp_1367; + return_56.field1 = pvrtmp_1368; + return return_56; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_59 = *(uintptr_t *) tmpcur_1360; + GibCursor tmpcur_1369 = GIB_UNTAG(tagged_tmpcur_59); + GibCursor tmpaftercur_1370 = tmpcur_1360 + 8; + uint16_t tmptag_1371 = GIB_GET_TAG(tagged_tmpcur_59); + GibCursor end_from_tagged_indr_669 = tmpcur_1369 + tmptag_1371; + GibCursor jump_loc_671 = tmpcur_1360 + 8; + unsigned char wildcard_674 = gib_print_symbol(1134); + GibCursorGibCursorProd tmp_struct_57 = + _print_Tree(tmpcur_1369, tmpcur_1369); + GibCursor pvrtmp_1372 = tmp_struct_57.field0; + GibCursor pvrtmp_1373 = tmp_struct_57.field1; + GibCursorGibCursorProd return_58; + + return_58.field0 = end_r_460; + return_58.field1 = jump_loc_671; + return return_58; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_62 = *(uintptr_t *) tmpcur_1360; + GibCursor tmpcur_1374 = GIB_UNTAG(tagged_tmpcur_62); + GibCursor tmpaftercur_1375 = tmpcur_1360 + 8; + uint16_t tmptag_1376 = GIB_GET_TAG(tagged_tmpcur_62); + GibCursor end_from_tagged_indr_669 = tmpcur_1374 + tmptag_1376; + unsigned char wildcard_674 = gib_print_symbol(1133); + GibCursorGibCursorProd tmp_struct_60 = + _print_Tree(tmpcur_1374, tmpcur_1374); + GibCursor pvrtmp_1377 = tmp_struct_60.field0; + GibCursor pvrtmp_1378 = tmp_struct_60.field1; + GibCursorGibCursorProd return_61; + + return_61.field0 = pvrtmp_1377; + return_61.field1 = pvrtmp_1378; + return return_61; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1359"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_Tree(GibCursor end_r_464, + GibCursor end_r_466, + GibCursor loc_462, + GibCursor arg_98_187_272) +{ + GibPackedTag tmpval_1380 = *(GibPackedTag *) arg_98_187_272; + GibCursor tmpcur_1381 = arg_98_187_272 + 1; + + + switch_1440: + ; + switch (tmpval_1380) { + + case 0: + { + GibInt tmpval_1382 = *(GibInt *) tmpcur_1381; + GibCursor tmpcur_1383 = tmpcur_1381 + sizeof(GibInt); + GibCursor jump_628 = tmpcur_1381 + 8; + + *(GibPackedTag *) loc_462 = 0; + + GibCursor writetag_936 = loc_462 + 1; + GibCursor after_tag_937 = loc_462 + 1; + + *(GibInt *) after_tag_937 = tmpval_1382; + + GibCursor writecur_941 = after_tag_937 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_63; + + return_63.field0 = end_r_464; + return_63.field1 = end_r_466; + return_63.field2 = jump_628; + return_63.field3 = loc_462; + return_63.field4 = writecur_941; + return return_63; + break; + } + + case 1: + { + GibInt tmpval_1388 = *(GibInt *) tmpcur_1381; + GibCursor tmpcur_1389 = tmpcur_1381 + sizeof(GibInt); + GibCursor jump_630 = tmpcur_1381 + 8; + GibCursor loc_581 = loc_462 + 1; + GibCursor loc_582 = loc_581 + 8; + + *(GibPackedTag *) loc_462 = 1; + + GibCursor writetag_952 = loc_462 + 1; + GibCursor after_tag_953 = loc_462 + 1; + + *(GibInt *) after_tag_953 = tmpval_1388; + + GibCursor writecur_957 = after_tag_953 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_64 = + _copy_without_ptrs_Tree(end_r_464, end_r_466, loc_582, tmpcur_1389); + GibCursor pvrtmp_1390 = tmp_struct_64.field0; + GibCursor pvrtmp_1391 = tmp_struct_64.field1; + GibCursor pvrtmp_1392 = tmp_struct_64.field2; + GibCursor pvrtmp_1393 = tmp_struct_64.field3; + GibCursor pvrtmp_1394 = tmp_struct_64.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_65 = + _copy_without_ptrs_Tree(pvrtmp_1390, pvrtmp_1391, pvrtmp_1394, pvrtmp_1392); + GibCursor pvrtmp_1399 = tmp_struct_65.field0; + GibCursor pvrtmp_1400 = tmp_struct_65.field1; + GibCursor pvrtmp_1401 = tmp_struct_65.field2; + GibCursor pvrtmp_1402 = tmp_struct_65.field3; + GibCursor pvrtmp_1403 = tmp_struct_65.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_66; + + return_66.field0 = pvrtmp_1399; + return_66.field1 = pvrtmp_1400; + return_66.field2 = pvrtmp_1401; + return_66.field3 = loc_462; + return_66.field4 = pvrtmp_1403; + return return_66; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_69 = *(uintptr_t *) tmpcur_1381; + GibCursor tmpcur_1412 = GIB_UNTAG(tagged_tmpcur_69); + GibCursor tmpaftercur_1413 = tmpcur_1381 + 8; + uint16_t tmptag_1414 = GIB_GET_TAG(tagged_tmpcur_69); + GibCursor end_from_tagged_indr_675 = tmpcur_1412 + tmptag_1414; + GibCursor jump_loc_677 = tmpcur_1381 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_67 = + _copy_without_ptrs_Tree(tmpcur_1412, end_r_466, loc_462, tmpcur_1412); + GibCursor pvrtmp_1415 = tmp_struct_67.field0; + GibCursor pvrtmp_1416 = tmp_struct_67.field1; + GibCursor pvrtmp_1417 = tmp_struct_67.field2; + GibCursor pvrtmp_1418 = tmp_struct_67.field3; + GibCursor pvrtmp_1419 = tmp_struct_67.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_68; + + return_68.field0 = end_r_464; + return_68.field1 = pvrtmp_1416; + return_68.field2 = jump_loc_677; + return_68.field3 = pvrtmp_1418; + return_68.field4 = pvrtmp_1419; + return return_68; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_72 = *(uintptr_t *) tmpcur_1381; + GibCursor tmpcur_1426 = GIB_UNTAG(tagged_tmpcur_72); + GibCursor tmpaftercur_1427 = tmpcur_1381 + 8; + uint16_t tmptag_1428 = GIB_GET_TAG(tagged_tmpcur_72); + GibCursor end_from_tagged_indr_675 = tmpcur_1426 + tmptag_1428; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_70 = + _copy_without_ptrs_Tree(tmpcur_1426, end_r_466, loc_462, tmpcur_1426); + GibCursor pvrtmp_1429 = tmp_struct_70.field0; + GibCursor pvrtmp_1430 = tmp_struct_70.field1; + GibCursor pvrtmp_1431 = tmp_struct_70.field2; + GibCursor pvrtmp_1432 = tmp_struct_70.field3; + GibCursor pvrtmp_1433 = tmp_struct_70.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_71; + + return_71.field0 = pvrtmp_1429; + return_71.field1 = pvrtmp_1430; + return_71.field2 = pvrtmp_1431; + return_71.field3 = pvrtmp_1432; + return_71.field4 = pvrtmp_1433; + return return_71; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1380"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_86 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_1136 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_479 = region_1136.start; + GibCursor end_r_479 = region_1136.end; + GibCursorGibCursorGibCursorProd tmp_struct_73 = + mkTree(end_r_479, r_479, 23, 0); + GibCursor pvrtmp_1137 = tmp_struct_73.field0; + GibCursor pvrtmp_1138 = tmp_struct_73.field1; + GibCursor pvrtmp_1139 = tmp_struct_73.field2; + GibChunk region_1144 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_478 = region_1144.start; + GibCursor end_r_478 = region_1144.end; + GibCursor pvrtmp_1156; + GibCursor pvrtmp_1157; + GibCursor pvrtmp_1158; + GibVector *times_78 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_1156; + struct timespec end_pvrtmp_1156; + + for (long long iters_pvrtmp_1156 = 0; iters_pvrtmp_1156 < + gib_get_iters_param(); iters_pvrtmp_1156++) { + if (iters_pvrtmp_1156 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_1156); + + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_74 = + add1Tree(pvrtmp_1137, end_r_478, r_478, pvrtmp_1138); + GibCursor pvrtmp_1145 = tmp_struct_74.field0; + GibCursor pvrtmp_1146 = tmp_struct_74.field1; + GibCursor pvrtmp_1147 = tmp_struct_74.field2; + GibCursor pvrtmp_1148 = tmp_struct_74.field3; + GibCursor pvrtmp_1149 = tmp_struct_74.field4; + + pvrtmp_1156 = pvrtmp_1146; + pvrtmp_1157 = pvrtmp_1148; + pvrtmp_1158 = pvrtmp_1149; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_1156); + if (iters_pvrtmp_1156 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_75 = gib_difftimespecs(&begin_pvrtmp_1156, + &end_pvrtmp_1156); + + printf("itertime: %lf\n", itertime_75); + gib_vector_inplace_update(times_78, iters_pvrtmp_1156, &itertime_75); + } + gib_vector_inplace_sort(times_78, gib_compare_doubles); + + double *tmp_79 = (double *) gib_vector_nth(times_78, gib_get_iters_param() / + 2); + double selftimed_77 = *tmp_79; + double batchtime_76 = gib_sum_timing_array(times_78); + + gib_print_timing_array(times_78); + gib_vector_free(times_78); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_76); + printf("SELFTIMED: %e\n", selftimed_77); + + GibInt timed_1031; + GibVector *times_84 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_1031; + struct timespec end_timed_1031; + + for (long long iters_timed_1031 = 0; iters_timed_1031 < + gib_get_iters_param(); iters_timed_1031++) { + if (iters_timed_1031 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_1031); + + GibCursorGibCursorGibIntProd tmp_struct_80 = + sumTree(end_r_478, pvrtmp_1157); + GibCursor pvrtmp_1166 = tmp_struct_80.field0; + GibCursor pvrtmp_1167 = tmp_struct_80.field1; + GibInt pvrtmp_1168 = tmp_struct_80.field2; + + timed_1031 = pvrtmp_1168; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_1031); + if (iters_timed_1031 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_81 = gib_difftimespecs(&begin_timed_1031, + &end_timed_1031); + + printf("itertime: %lf\n", itertime_81); + gib_vector_inplace_update(times_84, iters_timed_1031, &itertime_81); + } + gib_vector_inplace_sort(times_84, gib_compare_doubles); + + double *tmp_85 = (double *) gib_vector_nth(times_84, gib_get_iters_param() / + 2); + double selftimed_83 = *tmp_85; + double batchtime_82 = gib_sum_timing_array(times_84); + + gib_print_timing_array(times_84); + gib_vector_free(times_84); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_82); + printf("SELFTIMED: %e\n", selftimed_83); + printf("%ld", timed_1031); + printf("\n"); + + int exit_87 = gib_exit(); + + return exit_87; +} \ No newline at end of file diff --git a/microbench/manual_soa_examples/MonoTree.aos.retarg.c b/microbench/manual_soa_examples/MonoTree.aos.retarg.c new file mode 100644 index 000000000..012deee3a --- /dev/null +++ b/microbench/manual_soa_examples/MonoTree.aos.retarg.c @@ -0,0 +1,1115 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; + +void add1Tree(GibCursor *end_r_440, + GibCursor *end_r_442, + GibCursor *loc_438, + GibCursor *t_31_136_213, + GibCursorGibCursorGibCursorGibCursorGibCursorProd *Ret + ); + + +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_Tree(GibCursor end_r_446, GibCursor end_r_448, GibCursor loc_444, + GibCursor arg_89_141_222); +void sumTree(GibCursor *end_r_451, + GibCursor *tr_36_150_231, + GibCursorGibCursorGibIntProd *Ret); +GibCursorGibCursorGibCursorProd mkTree(GibCursor end_r_454, GibCursor loc_452, + GibInt d_41_155_239, + GibInt acc_42_156_240); +GibCursorGibCursorProd _traverse_Tree(GibCursor end_r_457, + GibCursor arg_107_163_248); +GibCursorGibCursorProd _print_Tree(GibCursor end_r_460, + GibCursor arg_116_170_255); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_Tree(GibCursor end_r_464, GibCursor end_r_466, + GibCursor loc_462, GibCursor arg_98_187_272); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + Tree_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[3]; + + error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 0); + exit(1); + } + field_tys[0] = Tree_T; + field_tys[1] = Tree_T; + error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(1130, ")"); + gib_add_symbol(1131, "(Node"); + gib_add_symbol(1132, "(Leaf"); + gib_add_symbol(1133, " ->r "); + gib_add_symbol(1134, " ->i "); + gib_add_symbol(1135, " "); +} +//GibCursorGibCursorGibCursorGibCursorGibCursorProd +void add1Tree(GibCursor *end_r_440, + GibCursor *end_r_442, + GibCursor *loc_438, + GibCursor *t_31_136_213, + GibCursorGibCursorGibCursorGibCursorGibCursorProd *Ret + ) +{ + if (*loc_438 + 18 > *end_r_442) { + gib_grow_region(loc_438, end_r_442); + } + + GibPackedTag tmpval_1169 = *(GibPackedTag *) (*t_31_136_213); + //GibCursor tmpcur_1170 = t_31_136_213 + 1; + *t_31_136_213 += 1; + + + switch_1229: + ; + switch (tmpval_1169) { + + case 0: + { + GibInt tmpval_1171 = *(GibInt *) (*t_31_136_213); + + //not used + //GibCursor tmpcur_1172 = tmpcur_1170 + sizeof(GibInt); + + //GibCursor jump_597 = tmpcur_1170 + 8; + *t_31_136_213 += 8; + + GibInt fltPkd_196_215 = tmpval_1171 + 1; + + *(GibPackedTag *) (*loc_438) = 0; + + //GibCursor writetag_782 = loc_438 + 1; + //GibCursor after_tag_783 = loc_438 + 1; + *loc_438 += 1; + + *(GibInt *) (*loc_438) = fltPkd_196_215; + + //GibCursor writecur_787 = after_tag_783 + sizeof(GibInt); + *(loc_438) += sizeof(GibInt); + + //GibCursorGibCursorGibCursorGibCursorGibCursorProd return_0; + + Ret->field0 = *end_r_440; + Ret->field1 = *end_r_442; + Ret->field2 = *t_31_136_213; + Ret->field4 = *loc_438; + // return return_0; + break; + } + + case 1: + { + GibInt tmpval_1177 = *(GibInt *) (*t_31_136_213); + + //GibCursor tmpcur_1178 = tmpcur_1170 + sizeof(GibInt); + *t_31_136_213 += sizeof(GibInt); + + + //GibCursor jump_599 = tmpcur_1170 + 8; + GibInt fltPkd_197_219 = tmpval_1177 + 1; + + //GibCursor loc_495 = loc_438 + 1; + //GibCursor loc_496 = loc_495 + 8; + + + *(GibPackedTag *) (*loc_438) = 1; + *loc_438 += 1; + + //GibCursor writetag_798 = loc_438 + 1; + //GibCursor after_tag_799 = loc_438 + 1; + + *(GibInt *) (*loc_438) = fltPkd_197_219; + *loc_438 += 8; + + //GibCursor writecur_803 = after_tag_799 + sizeof(GibInt); + add1Tree(end_r_440, end_r_442, loc_438, t_31_136_213, Ret); + + + // GibCursor pvrtmp_1179 = tmp_struct_1.field0; + // GibCursor pvrtmp_1180 = tmp_struct_1.field1; + // GibCursor pvrtmp_1181 = tmp_struct_1.field2; + // GibCursor pvrtmp_1182 = tmp_struct_1.field3; + // GibCursor pvrtmp_1183 = tmp_struct_1.field4; + + add1Tree(end_r_440, end_r_442, loc_438, t_31_136_213, Ret); + + + // GibCursor pvrtmp_1188 = tmp_struct_2.field0; + // GibCursor pvrtmp_1189 = tmp_struct_2.field1; + // GibCursor pvrtmp_1190 = tmp_struct_2.field2; + // GibCursor pvrtmp_1191 = tmp_struct_2.field3; + // GibCursor pvrtmp_1192 = tmp_struct_2.field4; + /*GibCursorGibCursorGibCursorGibCursorGibCursorProd return_3; + + return_3.field0 = pvrtmp_1188; + return_3.field1 = pvrtmp_1189; + return_3.field2 = pvrtmp_1190; + return_3.field3 = loc_438; + return_3.field4 = pvrtmp_1192; + return return_3*/; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// uintptr_t tagged_tmpcur_6 = *(uintptr_t *) tmpcur_1170; +// GibCursor tmpcur_1201 = GIB_UNTAG(tagged_tmpcur_6); +// GibCursor tmpaftercur_1202 = tmpcur_1170 + 8; +// uint16_t tmptag_1203 = GIB_GET_TAG(tagged_tmpcur_6); +// GibCursor end_from_tagged_indr_645 = tmpcur_1201 + tmptag_1203; +// GibCursor jump_loc_647 = tmpcur_1170 + 8; +// GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_4 = +// add1Tree(tmpcur_1201, end_r_442, loc_438, tmpcur_1201); +// GibCursor pvrtmp_1204 = tmp_struct_4.field0; +// GibCursor pvrtmp_1205 = tmp_struct_4.field1; +// GibCursor pvrtmp_1206 = tmp_struct_4.field2; +// GibCursor pvrtmp_1207 = tmp_struct_4.field3; +// GibCursor pvrtmp_1208 = tmp_struct_4.field4; +// GibCursorGibCursorGibCursorGibCursorGibCursorProd return_5; +// +// return_5.field0 = end_r_440; +// return_5.field1 = pvrtmp_1205; +// return_5.field2 = jump_loc_647; +// return_5.field3 = pvrtmp_1207; +// return_5.field4 = pvrtmp_1208; +// return return_5; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_9 = *(uintptr_t *) (*t_31_136_213); + GibCursor tmpcur_1215 = GIB_UNTAG(tagged_tmpcur_9); + //GibCursor tmpaftercur_1216 = tmpcur_1170 + 8; + //uint16_t tmptag_1217 = GIB_GET_TAG(tagged_tmpcur_9); + //GibCursor end_from_tagged_indr_645 = tmpcur_1215 + tmptag_1217; + *t_31_136_213 = tmpcur_1215; + + add1Tree(t_31_136_213, end_r_442, loc_438, t_31_136_213, Ret); + +// GibCursor pvrtmp_1218 = tmp_struct_7.field0; +// GibCursor pvrtmp_1219 = tmp_struct_7.field1; +// GibCursor pvrtmp_1220 = tmp_struct_7.field2; +// GibCursor pvrtmp_1221 = tmp_struct_7.field3; +// GibCursor pvrtmp_1222 = tmp_struct_7.field4; +// GibCursorGibCursorGibCursorGibCursorGibCursorProd return_8; +// +// return_8.field0 = pvrtmp_1218; +// return_8.field1 = pvrtmp_1219; +// return_8.field2 = pvrtmp_1220; +// return_8.field3 = pvrtmp_1221; +// return_8.field4 = pvrtmp_1222; +// return return_8; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1169"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_Tree(GibCursor end_r_446, + GibCursor end_r_448, + GibCursor loc_444, + GibCursor arg_89_141_222) +{ + if (loc_444 + 18 > end_r_448) { + gib_grow_region(&loc_444, &end_r_448); + } + + GibPackedTag tmpval_1230 = *(GibPackedTag *) arg_89_141_222; + GibCursor tmpcur_1231 = arg_89_141_222 + 1; + + + switch_1290: + ; + switch (tmpval_1230) { + + case 0: + { + GibInt tmpval_1232 = *(GibInt *) tmpcur_1231; + GibCursor tmpcur_1233 = tmpcur_1231 + sizeof(GibInt); + GibCursor jump_603 = tmpcur_1231 + 8; + + *(GibPackedTag *) loc_444 = 0; + + GibCursor writetag_822 = loc_444 + 1; + GibCursor after_tag_823 = loc_444 + 1; + + *(GibInt *) after_tag_823 = tmpval_1232; + + GibCursor writecur_827 = after_tag_823 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_13; + + return_13.field0 = end_r_446; + return_13.field1 = end_r_448; + return_13.field2 = jump_603; + return_13.field3 = loc_444; + return_13.field4 = writecur_827; + return return_13; + break; + } + + case 1: + { + GibInt tmpval_1238 = *(GibInt *) tmpcur_1231; + GibCursor tmpcur_1239 = tmpcur_1231 + sizeof(GibInt); + GibCursor jump_605 = tmpcur_1231 + 8; + GibCursor loc_517 = loc_444 + 1; + GibCursor loc_518 = loc_517 + 8; + + *(GibPackedTag *) loc_444 = 1; + + GibCursor writetag_838 = loc_444 + 1; + GibCursor after_tag_839 = loc_444 + 1; + + *(GibInt *) after_tag_839 = tmpval_1238; + + GibCursor writecur_843 = after_tag_839 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_14 = + _copy_Tree(end_r_446, end_r_448, loc_518, tmpcur_1239); + GibCursor pvrtmp_1240 = tmp_struct_14.field0; + GibCursor pvrtmp_1241 = tmp_struct_14.field1; + GibCursor pvrtmp_1242 = tmp_struct_14.field2; + GibCursor pvrtmp_1243 = tmp_struct_14.field3; + GibCursor pvrtmp_1244 = tmp_struct_14.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_15 = + _copy_Tree(pvrtmp_1240, pvrtmp_1241, pvrtmp_1244, pvrtmp_1242); + GibCursor pvrtmp_1249 = tmp_struct_15.field0; + GibCursor pvrtmp_1250 = tmp_struct_15.field1; + GibCursor pvrtmp_1251 = tmp_struct_15.field2; + GibCursor pvrtmp_1252 = tmp_struct_15.field3; + GibCursor pvrtmp_1253 = tmp_struct_15.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_16; + + return_16.field0 = pvrtmp_1249; + return_16.field1 = pvrtmp_1250; + return_16.field2 = pvrtmp_1251; + return_16.field3 = loc_444; + return_16.field4 = pvrtmp_1253; + return return_16; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_19 = *(uintptr_t *) tmpcur_1231; + GibCursor tmpcur_1262 = GIB_UNTAG(tagged_tmpcur_19); + GibCursor tmpaftercur_1263 = tmpcur_1231 + 8; + uint16_t tmptag_1264 = GIB_GET_TAG(tagged_tmpcur_19); + GibCursor end_from_tagged_indr_651 = tmpcur_1262 + tmptag_1264; + GibCursor jump_loc_653 = tmpcur_1231 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_17 = + _copy_Tree(tmpcur_1262, end_r_448, loc_444, tmpcur_1262); + GibCursor pvrtmp_1265 = tmp_struct_17.field0; + GibCursor pvrtmp_1266 = tmp_struct_17.field1; + GibCursor pvrtmp_1267 = tmp_struct_17.field2; + GibCursor pvrtmp_1268 = tmp_struct_17.field3; + GibCursor pvrtmp_1269 = tmp_struct_17.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_18; + + return_18.field0 = end_r_446; + return_18.field1 = pvrtmp_1266; + return_18.field2 = jump_loc_653; + return_18.field3 = pvrtmp_1268; + return_18.field4 = pvrtmp_1269; + return return_18; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_22 = *(uintptr_t *) tmpcur_1231; + GibCursor tmpcur_1276 = GIB_UNTAG(tagged_tmpcur_22); + GibCursor tmpaftercur_1277 = tmpcur_1231 + 8; + uint16_t tmptag_1278 = GIB_GET_TAG(tagged_tmpcur_22); + GibCursor end_from_tagged_indr_651 = tmpcur_1276 + tmptag_1278; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_20 = + _copy_Tree(tmpcur_1276, end_r_448, loc_444, tmpcur_1276); + GibCursor pvrtmp_1279 = tmp_struct_20.field0; + GibCursor pvrtmp_1280 = tmp_struct_20.field1; + GibCursor pvrtmp_1281 = tmp_struct_20.field2; + GibCursor pvrtmp_1282 = tmp_struct_20.field3; + GibCursor pvrtmp_1283 = tmp_struct_20.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_21; + + return_21.field0 = pvrtmp_1279; + return_21.field1 = pvrtmp_1280; + return_21.field2 = pvrtmp_1281; + return_21.field3 = pvrtmp_1282; + return_21.field4 = pvrtmp_1283; + return return_21; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1230"); + exit(1); + } + } +} + +void sumTree(GibCursor *end_r_451, + GibCursor *tr_36_150_231, + GibCursorGibCursorGibIntProd *Res) +{ + GibPackedTag tmpval_1291 = *(GibPackedTag *) (*tr_36_150_231); + //GibCursor tmpcur_1292 = tr_36_150_231 + 1; + (*tr_36_150_231) += 1; + + + switch_1315: + ; + switch (tmpval_1291) { + + case 0: + { + GibInt tmpval_1293 = *(GibInt *) (*tr_36_150_231); + //GibCursor tmpcur_1294 = tmpcur_1292 + sizeof(GibInt); + //GibCursor jump_609 = tmpcur_1292 + 8; + + *(tr_36_150_231) += 8; + + // GibCursorGibCursorGibIntProd return_26; + // return_26.field0 = end_r_451; + // return_26.field1 = jump_609; + // return_26.field2 = tmpval_1293; + // return return_26; + Res->field0 = *end_r_451; + Res->field1 = *tr_36_150_231; + Res->field2 += tmpval_1293; + break; + } + + case 1: + { + GibInt tmpval_1295 = *(GibInt *) (*tr_36_150_231); + + //GibCursor tmpcur_1296 = tmpcur_1292 + sizeof(GibInt); + *tr_36_150_231 += sizeof(GibInt); + //GibCursor jump_610 = tmpcur_1292 + 8; + + sumTree(end_r_451, tr_36_150_231, Res); + + // GibCursor pvrtmp_1297 = tmp_struct_27.field0; + // GibCursor pvrtmp_1298 = tmp_struct_27.field1; + // GibInt pvrtmp_1299 = tmp_struct_27.field2; + // GibInt fltPrm_200_237 = tmpval_1295 + pvrtmp_1299; + + + sumTree(end_r_451, tr_36_150_231, Res); + + + // GibCursor pvrtmp_1300 = tmp_struct_28.field0; + // GibCursor pvrtmp_1301 = tmp_struct_28.field1; + // GibInt pvrtmp_1302 = tmp_struct_28.field2; + // GibInt tailprim_613 = fltPrm_200_237 + pvrtmp_1302; + // GibCursorGibCursorGibIntProd return_29; + + // return_29.field0 = pvrtmp_1300; + // return_29.field1 = pvrtmp_1301; + // return_29.field2 = tailprim_613; + // return return_29; + + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// uintptr_t tagged_tmpcur_32 = *(uintptr_t *) tmpcur_1292; +// GibCursor tmpcur_1303 = GIB_UNTAG(tagged_tmpcur_32); +// GibCursor tmpaftercur_1304 = tmpcur_1292 + 8; +// uint16_t tmptag_1305 = GIB_GET_TAG(tagged_tmpcur_32); +// GibCursor end_from_tagged_indr_657 = tmpcur_1303 + tmptag_1305; +// GibCursor jump_loc_659 = tmpcur_1292 + 8; +// GibCursorGibCursorGibIntProd tmp_struct_30 = +// sumTree(tmpcur_1303, tmpcur_1303); +// GibCursor pvrtmp_1306 = tmp_struct_30.field0; +// GibCursor pvrtmp_1307 = tmp_struct_30.field1; +// GibInt pvrtmp_1308 = tmp_struct_30.field2; +// GibCursorGibCursorGibIntProd return_31; +// +// return_31.field0 = end_r_451; +// return_31.field1 = jump_loc_659; +// return_31.field2 = pvrtmp_1308; +// return return_31; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_35 = *(uintptr_t *) (*tr_36_150_231); + GibCursor tmpcur_1309 = GIB_UNTAG(tagged_tmpcur_35); + + //GibCursor tmpaftercur_1310 = tmpcur_1292 + 8; + //uint16_t tmptag_1311 = GIB_GET_TAG(tagged_tmpcur_35); + //GibCursor end_from_tagged_indr_657 = tmpcur_1309 + tmptag_1311; + *tr_36_150_231 = tmpcur_1309; + + sumTree(tr_36_150_231, tr_36_150_231, Res); + + // GibCursor pvrtmp_1312 = tmp_struct_33.field0; + // GibCursor pvrtmp_1313 = tmp_struct_33.field1; + // GibInt pvrtmp_1314 = tmp_struct_33.field2; + // GibCursorGibCursorGibIntProd return_34; + + // return_34.field0 = pvrtmp_1312; + // return_34.field1 = pvrtmp_1313; + // return_34.field2 = pvrtmp_1314; + // return return_34; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1291"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorProd mkTree(GibCursor end_r_454, GibCursor loc_452, + GibInt d_41_155_239, + GibInt acc_42_156_240) +{ + if (loc_452 + 18 > end_r_454) { + gib_grow_region(&loc_452, &end_r_454); + } + + GibBool fltIf_203_241 = d_41_155_239 == 0; + + if (fltIf_203_241) { + *(GibPackedTag *) loc_452 = 0; + + GibCursor writetag_876 = loc_452 + 1; + GibCursor after_tag_877 = loc_452 + 1; + + *(GibInt *) after_tag_877 = acc_42_156_240; + + GibCursor writecur_881 = after_tag_877 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd return_36; + + return_36.field0 = end_r_454; + return_36.field1 = loc_452; + return_36.field2 = writecur_881; + return return_36; + } else { + GibInt fltAppE_205_242 = d_41_155_239 - 1; + GibInt fltAppE_206_243 = d_41_155_239 + acc_42_156_240; + GibCursor loc_539 = loc_452 + 1; + GibCursor loc_540 = loc_539 + 8; + + *(GibPackedTag *) loc_452 = 1; + + GibCursor writetag_888 = loc_452 + 1; + GibCursor after_tag_889 = loc_452 + 1; + + *(GibInt *) after_tag_889 = d_41_155_239; + + GibCursor writecur_893 = after_tag_889 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd tmp_struct_37 = + mkTree(end_r_454, loc_540, fltAppE_205_242, fltAppE_206_243); + GibCursor pvrtmp_1320 = tmp_struct_37.field0; + GibCursor pvrtmp_1321 = tmp_struct_37.field1; + GibCursor pvrtmp_1322 = tmp_struct_37.field2; + GibInt fltAppE_208_245 = d_41_155_239 - 1; + GibInt fltAppE_209_246 = d_41_155_239 + acc_42_156_240; + GibCursorGibCursorGibCursorProd tmp_struct_38 = + mkTree(pvrtmp_1320, pvrtmp_1322, fltAppE_208_245, fltAppE_209_246); + GibCursor pvrtmp_1327 = tmp_struct_38.field0; + GibCursor pvrtmp_1328 = tmp_struct_38.field1; + GibCursor pvrtmp_1329 = tmp_struct_38.field2; + GibCursorGibCursorGibCursorProd return_39; + + return_39.field0 = pvrtmp_1327; + return_39.field1 = loc_452; + return_39.field2 = pvrtmp_1329; + return return_39; + } +} +GibCursorGibCursorProd _traverse_Tree(GibCursor end_r_457, + GibCursor arg_107_163_248) +{ + GibPackedTag tmpval_1338 = *(GibPackedTag *) arg_107_163_248; + GibCursor tmpcur_1339 = arg_107_163_248 + 1; + + + switch_1358: + ; + switch (tmpval_1338) { + + case 0: + { + GibInt tmpval_1340 = *(GibInt *) tmpcur_1339; + GibCursor tmpcur_1341 = tmpcur_1339 + sizeof(GibInt); + GibCursor jump_616 = tmpcur_1339 + 8; + GibCursorGibCursorProd return_43; + + return_43.field0 = end_r_457; + return_43.field1 = jump_616; + return return_43; + break; + } + + case 1: + { + GibInt tmpval_1342 = *(GibInt *) tmpcur_1339; + GibCursor tmpcur_1343 = tmpcur_1339 + sizeof(GibInt); + GibCursor jump_618 = tmpcur_1339 + 8; + GibCursorGibCursorProd tmp_struct_44 = + _traverse_Tree(end_r_457, tmpcur_1343); + GibCursor pvrtmp_1344 = tmp_struct_44.field0; + GibCursor pvrtmp_1345 = tmp_struct_44.field1; + GibCursorGibCursorProd tmp_struct_45 = + _traverse_Tree(pvrtmp_1344, pvrtmp_1345); + GibCursor pvrtmp_1346 = tmp_struct_45.field0; + GibCursor pvrtmp_1347 = tmp_struct_45.field1; + GibCursorGibCursorProd return_46; + + return_46.field0 = pvrtmp_1346; + return_46.field1 = pvrtmp_1347; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_1339; + GibCursor tmpcur_1348 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_1349 = tmpcur_1339 + 8; + uint16_t tmptag_1350 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_663 = tmpcur_1348 + tmptag_1350; + GibCursor jump_loc_665 = tmpcur_1339 + 8; + GibCursorGibCursorProd tmp_struct_47 = + _traverse_Tree(tmpcur_1348, tmpcur_1348); + GibCursor pvrtmp_1351 = tmp_struct_47.field0; + GibCursor pvrtmp_1352 = tmp_struct_47.field1; + GibCursorGibCursorProd return_48; + + return_48.field0 = end_r_457; + return_48.field1 = jump_loc_665; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_1339; + GibCursor tmpcur_1353 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_1354 = tmpcur_1339 + 8; + uint16_t tmptag_1355 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_663 = tmpcur_1353 + tmptag_1355; + GibCursorGibCursorProd tmp_struct_50 = + _traverse_Tree(tmpcur_1353, tmpcur_1353); + GibCursor pvrtmp_1356 = tmp_struct_50.field0; + GibCursor pvrtmp_1357 = tmp_struct_50.field1; + GibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_1356; + return_51.field1 = pvrtmp_1357; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1338"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_Tree(GibCursor end_r_460, + GibCursor arg_116_170_255) +{ + GibPackedTag tmpval_1359 = *(GibPackedTag *) arg_116_170_255; + GibCursor tmpcur_1360 = arg_116_170_255 + 1; + + + switch_1379: + ; + switch (tmpval_1359) { + + case 0: + { + GibInt tmpval_1361 = *(GibInt *) tmpcur_1360; + GibCursor tmpcur_1362 = tmpcur_1360 + sizeof(GibInt); + GibCursor jump_622 = tmpcur_1360 + 8; + unsigned char wildcard_119_172_257 = gib_print_symbol(1132); + unsigned char wildcard_121_173_258 = gib_print_symbol(1135); + unsigned char y_118_174_259 = printf("%ld", tmpval_1361); + unsigned char wildcard_120_175_260 = gib_print_symbol(1130); + GibCursorGibCursorProd return_53; + + return_53.field0 = end_r_460; + return_53.field1 = jump_622; + return return_53; + break; + } + + case 1: + { + GibInt tmpval_1363 = *(GibInt *) tmpcur_1360; + GibCursor tmpcur_1364 = tmpcur_1360 + sizeof(GibInt); + GibCursor jump_624 = tmpcur_1360 + 8; + unsigned char wildcard_128_179_264 = gib_print_symbol(1131); + unsigned char wildcard_132_180_265 = gib_print_symbol(1135); + unsigned char y_125_181_266 = printf("%ld", tmpval_1363); + unsigned char wildcard_131_182_267 = gib_print_symbol(1135); + GibCursorGibCursorProd tmp_struct_54 = + _print_Tree(end_r_460, tmpcur_1364); + GibCursor pvrtmp_1365 = tmp_struct_54.field0; + GibCursor pvrtmp_1366 = tmp_struct_54.field1; + unsigned char wildcard_130_184_269 = gib_print_symbol(1135); + GibCursorGibCursorProd tmp_struct_55 = + _print_Tree(pvrtmp_1365, pvrtmp_1366); + GibCursor pvrtmp_1367 = tmp_struct_55.field0; + GibCursor pvrtmp_1368 = tmp_struct_55.field1; + unsigned char wildcard_129_186_271 = gib_print_symbol(1130); + GibCursorGibCursorProd return_56; + + return_56.field0 = pvrtmp_1367; + return_56.field1 = pvrtmp_1368; + return return_56; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_59 = *(uintptr_t *) tmpcur_1360; + GibCursor tmpcur_1369 = GIB_UNTAG(tagged_tmpcur_59); + GibCursor tmpaftercur_1370 = tmpcur_1360 + 8; + uint16_t tmptag_1371 = GIB_GET_TAG(tagged_tmpcur_59); + GibCursor end_from_tagged_indr_669 = tmpcur_1369 + tmptag_1371; + GibCursor jump_loc_671 = tmpcur_1360 + 8; + unsigned char wildcard_674 = gib_print_symbol(1134); + GibCursorGibCursorProd tmp_struct_57 = + _print_Tree(tmpcur_1369, tmpcur_1369); + GibCursor pvrtmp_1372 = tmp_struct_57.field0; + GibCursor pvrtmp_1373 = tmp_struct_57.field1; + GibCursorGibCursorProd return_58; + + return_58.field0 = end_r_460; + return_58.field1 = jump_loc_671; + return return_58; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_62 = *(uintptr_t *) tmpcur_1360; + GibCursor tmpcur_1374 = GIB_UNTAG(tagged_tmpcur_62); + GibCursor tmpaftercur_1375 = tmpcur_1360 + 8; + uint16_t tmptag_1376 = GIB_GET_TAG(tagged_tmpcur_62); + GibCursor end_from_tagged_indr_669 = tmpcur_1374 + tmptag_1376; + unsigned char wildcard_674 = gib_print_symbol(1133); + GibCursorGibCursorProd tmp_struct_60 = + _print_Tree(tmpcur_1374, tmpcur_1374); + GibCursor pvrtmp_1377 = tmp_struct_60.field0; + GibCursor pvrtmp_1378 = tmp_struct_60.field1; + GibCursorGibCursorProd return_61; + + return_61.field0 = pvrtmp_1377; + return_61.field1 = pvrtmp_1378; + return return_61; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1359"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_Tree(GibCursor end_r_464, + GibCursor end_r_466, + GibCursor loc_462, + GibCursor arg_98_187_272) +{ + GibPackedTag tmpval_1380 = *(GibPackedTag *) arg_98_187_272; + GibCursor tmpcur_1381 = arg_98_187_272 + 1; + + + switch_1440: + ; + switch (tmpval_1380) { + + case 0: + { + GibInt tmpval_1382 = *(GibInt *) tmpcur_1381; + GibCursor tmpcur_1383 = tmpcur_1381 + sizeof(GibInt); + GibCursor jump_628 = tmpcur_1381 + 8; + + *(GibPackedTag *) loc_462 = 0; + + GibCursor writetag_936 = loc_462 + 1; + GibCursor after_tag_937 = loc_462 + 1; + + *(GibInt *) after_tag_937 = tmpval_1382; + + GibCursor writecur_941 = after_tag_937 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_63; + + return_63.field0 = end_r_464; + return_63.field1 = end_r_466; + return_63.field2 = jump_628; + return_63.field3 = loc_462; + return_63.field4 = writecur_941; + return return_63; + break; + } + + case 1: + { + GibInt tmpval_1388 = *(GibInt *) tmpcur_1381; + GibCursor tmpcur_1389 = tmpcur_1381 + sizeof(GibInt); + GibCursor jump_630 = tmpcur_1381 + 8; + GibCursor loc_581 = loc_462 + 1; + GibCursor loc_582 = loc_581 + 8; + + *(GibPackedTag *) loc_462 = 1; + + GibCursor writetag_952 = loc_462 + 1; + GibCursor after_tag_953 = loc_462 + 1; + + *(GibInt *) after_tag_953 = tmpval_1388; + + GibCursor writecur_957 = after_tag_953 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_64 = + _copy_without_ptrs_Tree(end_r_464, end_r_466, loc_582, tmpcur_1389); + GibCursor pvrtmp_1390 = tmp_struct_64.field0; + GibCursor pvrtmp_1391 = tmp_struct_64.field1; + GibCursor pvrtmp_1392 = tmp_struct_64.field2; + GibCursor pvrtmp_1393 = tmp_struct_64.field3; + GibCursor pvrtmp_1394 = tmp_struct_64.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_65 = + _copy_without_ptrs_Tree(pvrtmp_1390, pvrtmp_1391, pvrtmp_1394, pvrtmp_1392); + GibCursor pvrtmp_1399 = tmp_struct_65.field0; + GibCursor pvrtmp_1400 = tmp_struct_65.field1; + GibCursor pvrtmp_1401 = tmp_struct_65.field2; + GibCursor pvrtmp_1402 = tmp_struct_65.field3; + GibCursor pvrtmp_1403 = tmp_struct_65.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_66; + + return_66.field0 = pvrtmp_1399; + return_66.field1 = pvrtmp_1400; + return_66.field2 = pvrtmp_1401; + return_66.field3 = loc_462; + return_66.field4 = pvrtmp_1403; + return return_66; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_69 = *(uintptr_t *) tmpcur_1381; + GibCursor tmpcur_1412 = GIB_UNTAG(tagged_tmpcur_69); + GibCursor tmpaftercur_1413 = tmpcur_1381 + 8; + uint16_t tmptag_1414 = GIB_GET_TAG(tagged_tmpcur_69); + GibCursor end_from_tagged_indr_675 = tmpcur_1412 + tmptag_1414; + GibCursor jump_loc_677 = tmpcur_1381 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_67 = + _copy_without_ptrs_Tree(tmpcur_1412, end_r_466, loc_462, tmpcur_1412); + GibCursor pvrtmp_1415 = tmp_struct_67.field0; + GibCursor pvrtmp_1416 = tmp_struct_67.field1; + GibCursor pvrtmp_1417 = tmp_struct_67.field2; + GibCursor pvrtmp_1418 = tmp_struct_67.field3; + GibCursor pvrtmp_1419 = tmp_struct_67.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_68; + + return_68.field0 = end_r_464; + return_68.field1 = pvrtmp_1416; + return_68.field2 = jump_loc_677; + return_68.field3 = pvrtmp_1418; + return_68.field4 = pvrtmp_1419; + return return_68; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_72 = *(uintptr_t *) tmpcur_1381; + GibCursor tmpcur_1426 = GIB_UNTAG(tagged_tmpcur_72); + GibCursor tmpaftercur_1427 = tmpcur_1381 + 8; + uint16_t tmptag_1428 = GIB_GET_TAG(tagged_tmpcur_72); + GibCursor end_from_tagged_indr_675 = tmpcur_1426 + tmptag_1428; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_70 = + _copy_without_ptrs_Tree(tmpcur_1426, end_r_466, loc_462, tmpcur_1426); + GibCursor pvrtmp_1429 = tmp_struct_70.field0; + GibCursor pvrtmp_1430 = tmp_struct_70.field1; + GibCursor pvrtmp_1431 = tmp_struct_70.field2; + GibCursor pvrtmp_1432 = tmp_struct_70.field3; + GibCursor pvrtmp_1433 = tmp_struct_70.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_71; + + return_71.field0 = pvrtmp_1429; + return_71.field1 = pvrtmp_1430; + return_71.field2 = pvrtmp_1431; + return_71.field3 = pvrtmp_1432; + return_71.field4 = pvrtmp_1433; + return return_71; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1380"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_86 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_1136 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_479 = region_1136.start; + GibCursor end_r_479 = region_1136.end; + GibCursorGibCursorGibCursorProd tmp_struct_73 = + mkTree(end_r_479, r_479, 23, 0); + GibCursor pvrtmp_1137 = tmp_struct_73.field0; + GibCursor pvrtmp_1138 = tmp_struct_73.field1; + GibCursor pvrtmp_1139 = tmp_struct_73.field2; + GibChunk region_1144 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_478 = region_1144.start; + GibCursor end_r_478 = region_1144.end; + GibCursor pvrtmp_1156; + GibCursor pvrtmp_1157; + GibCursor pvrtmp_1158; + GibVector *times_78 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_1156; + struct timespec end_pvrtmp_1156; + + for (long long iters_pvrtmp_1156 = 0; iters_pvrtmp_1156 < + gib_get_iters_param(); iters_pvrtmp_1156++) { + if (iters_pvrtmp_1156 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_1156); + + GibCursorGibCursorGibCursorGibCursorGibCursorProd Res; + Res.field3 = r_478; + add1Tree(&pvrtmp_1137, &end_r_478, &r_478, &pvrtmp_1138, &Res); + + GibCursor pvrtmp_1145 = Res.field0; + GibCursor pvrtmp_1146 = Res.field1; + GibCursor pvrtmp_1147 = Res.field2; + GibCursor pvrtmp_1148 = Res.field3; + GibCursor pvrtmp_1149 = Res.field4; + + pvrtmp_1156 = pvrtmp_1146; + pvrtmp_1157 = pvrtmp_1148; + pvrtmp_1158 = pvrtmp_1149; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_1156); + if (iters_pvrtmp_1156 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + pvrtmp_1137 = tmp_struct_73.field0; + end_r_478 = region_1144.end; + r_478 = region_1144.start; + pvrtmp_1138 = tmp_struct_73.field1; + + double itertime_75 = gib_difftimespecs(&begin_pvrtmp_1156, + &end_pvrtmp_1156); + + printf("itertime: %lf\n", itertime_75); + gib_vector_inplace_update(times_78, iters_pvrtmp_1156, &itertime_75); + } + gib_vector_inplace_sort(times_78, gib_compare_doubles); + + double *tmp_79 = (double *) gib_vector_nth(times_78, gib_get_iters_param() / + 2); + double selftimed_77 = *tmp_79; + double batchtime_76 = gib_sum_timing_array(times_78); + + gib_print_timing_array(times_78); + gib_vector_free(times_78); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_76); + printf("SELFTIMED: %e\n", selftimed_77); + + GibInt timed_1031; + GibVector *times_84 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_1031; + struct timespec end_timed_1031; + + for (long long iters_timed_1031 = 0; iters_timed_1031 < + gib_get_iters_param(); iters_timed_1031++) { + if (iters_timed_1031 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_1031); + + GibCursorGibCursorGibIntProd Res; + sumTree(&end_r_478, &pvrtmp_1157, &Res); + + GibCursor pvrtmp_1166 = Res.field0; + GibCursor pvrtmp_1167 = Res.field1; + GibInt pvrtmp_1168 = Res.field2; + + timed_1031 = pvrtmp_1168; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_1031); + if (iters_timed_1031 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + //Save the state of mutable cursors. + end_r_478 = region_1144.end; + pvrtmp_1157 = region_1144.start; + Res.field2 = 0; + + double itertime_81 = gib_difftimespecs(&begin_timed_1031, + &end_timed_1031); + + printf("itertime: %lf\n", itertime_81); + gib_vector_inplace_update(times_84, iters_timed_1031, &itertime_81); + } + gib_vector_inplace_sort(times_84, gib_compare_doubles); + + double *tmp_85 = (double *) gib_vector_nth(times_84, gib_get_iters_param() / + 2); + double selftimed_83 = *tmp_85; + double batchtime_82 = gib_sum_timing_array(times_84); + + gib_print_timing_array(times_84); + gib_vector_free(times_84); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_82); + printf("SELFTIMED: %e\n", selftimed_83); + printf("%ld", timed_1031); + printf("\n"); + + int exit_87 = gib_exit(); + + return exit_87; +} + +// gcc -std=gnu11 -O3 -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + +// gcc -std=gnu11 -g -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.aos.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + diff --git a/microbench/manual_soa_examples/MonoTree.soa.c b/microbench/manual_soa_examples/MonoTree.soa.c new file mode 100644 index 000000000..91462f8a0 --- /dev/null +++ b/microbench/manual_soa_examples/MonoTree.soa.c @@ -0,0 +1,2050 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorPtr3Prod_struct { + GibCursor field0[3]; + } GibCursorPtr3Prod; +typedef struct GibCursorPtr3GibCursorPtr3Prod_struct { + GibCursor field0[3]; + GibCursor field1[3]; + } GibCursorPtr3GibCursorPtr3Prod; +typedef struct GibCursorPtr3GibCursorPtr3GibIntProd_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibInt field2; + } GibCursorPtr3GibCursorPtr3GibIntProd; +typedef struct GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibCursor field2[3]; + } GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod; +typedef struct GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibCursor field2[3]; + GibCursor field3[3]; + GibCursor field4[3]; + } GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod; + + +void add1Tree(GibCursor cursor_ptr_1322[3], GibCursor cursor_ptr_1321[3], + GibCursor cursor_ptr_1323[3], GibCursor t_31_136_213[3] + ); + +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +_copy_Tree(GibCursor cursor_ptr_1436[3], GibCursor cursor_ptr_1435[3], + GibCursor cursor_ptr_1437[3], GibCursor arg_89_141_222[3]); +void sumTree(GibCursor cursor_ptr_1549[3], + GibCursor tr_36_150_231[3], + GibInt *Res); +GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod mkTree(GibCursor cursor_ptr_1622[3], + GibCursor cursor_ptr_1623[3], + GibInt d_41_155_239, + GibInt acc_42_156_240); +GibCursorPtr3GibCursorPtr3Prod _traverse_Tree(GibCursor cursor_ptr_1658[3], + GibCursor arg_107_163_248[3]); +GibCursorPtr3GibCursorPtr3Prod _print_Tree(GibCursor cursor_ptr_1732[3], + GibCursor arg_116_170_255[3]); +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +_copy_without_ptrs_Tree(GibCursor cursor_ptr_1807[3], + GibCursor cursor_ptr_1806[3], + GibCursor cursor_ptr_1808[3], + GibCursor arg_98_187_272[3]); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + Tree_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[3]; + + error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 0); + exit(1); + } + field_tys[0] = Tree_T; + field_tys[1] = Tree_T; + error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(2091, ")"); + gib_add_symbol(2092, "(Node"); + gib_add_symbol(2093, "(Leaf"); + gib_add_symbol(2094, " ->r "); + gib_add_symbol(2095, " ->i "); + gib_add_symbol(2096, " "); +} +void add1Tree(GibCursor cursor_ptr_1322[3], + GibCursor cursor_ptr_1321[3], + GibCursor cursor_ptr_1323[3], + GibCursor t_31_136_213[3] + ) +{ + GibCursor *end_r_625 = &cursor_ptr_1321[1]; + GibCursor *end_r_626 = &cursor_ptr_1321[2]; + GibCursor *end_r_624 = &cursor_ptr_1321[0]; + + GibCursor *loc_IntTy_619 = &cursor_ptr_1323[1]; + GibCursor *loc_IntTy_620 = &cursor_ptr_1323[2]; + GibCursor *loc_618 = &cursor_ptr_1323[0]; + + if (*loc_IntTy_620 + 17 > *end_r_626 || + (*loc_IntTy_619 + 17 > *end_r_625 || + *loc_618 + 34 > *end_r_624)) { + gib_grow_region(loc_IntTy_620, end_r_626); + gib_grow_region(loc_IntTy_619, end_r_625); + gib_grow_region(loc_618, end_r_624); + } + + // GibCursor end_r_621 = cursor_ptr_1322[0]; + // GibCursor end_r_622 = cursor_ptr_1322[1]; + // GibCursor end_r_623 = cursor_ptr_1322[2]; + + //GibCursor overwrite_reg_1324[3] = {end_r_624, end_r_625, end_r_626}; + GibCursor *dcon_1328 = &t_31_136_213[0]; + GibPackedTag tmpval_2134 = *(GibPackedTag *) (*dcon_1328); + //GibCursor tmpcur_2135 = dcon_1328 + 1; + *dcon_1328 += 1; + + + switch_2206: + ; + switch (tmpval_2134) { + + case 0: + { + GibCursor *soa_field_0_1330 = &t_31_136_213[1]; + //GibCursor *soa_field_1_1331 = &t_31_136_213[2]; + + GibInt tmpval_2136 = *(GibInt *) *soa_field_0_1330; + + //GibCursor tmpcur_2137 = soa_field_0_1330 + sizeof(GibInt); + + //GibCursor *loc_615 = &t_31_136_213[0]; + + //GibCursor jumpf_dloc_945 = loc_615 + 1; + //*loc_615 += 1; + + // GibCursor *loc_IntTy_616 = &t_31_136_213[1]; + GibCursor *loc_IntTy_617 = &t_31_136_213[2]; + + //GibCursor jumpf_floc_loc_946 = soa_field_0_1330 + 8; + *soa_field_0_1330 += 8; + + //GibCursor jumpf_floc_loc_947 = loc_IntTy_617 + 0; + + // GibCursor cursor_ptr_1334[3] = {jumpf_dloc_945, jumpf_floc_loc_946, + // jumpf_floc_loc_947}; + + GibInt fltPkd_196_215 = tmpval_2136 + 1; + //GibCursor new_dloc_740 = loc_618 + 1; + //GibCursor new_floc_loc_742 = loc_IntTy_620 + 8; + + *(GibPackedTag *) *loc_618 = 0; + + //GibCursor writetag_1335 = loc_618 + 1; + //GibCursor after_tag_1336 = loc_618 + 1; + *loc_618 += 1; + + *(GibInt *) *loc_IntTy_619 = fltPkd_196_215; + + //GibCursor writecur_1340 = loc_IntTy_619 + sizeof(GibInt); + *loc_IntTy_619 += sizeof(GibInt); + + // GibCursor aft_soa_loc_1342[3] = {after_tag_1336, writecur_1340, + // loc_IntTy_620}; + + // GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + // return_0; + + // memcpy(Ret->field0, cursor_ptr_1322, sizeof(GibCursor [3])); + // memcpy(Ret->field1, cursor_ptr_1321, sizeof(GibCursor [3])); + // memcpy(Ret->field2, t_31_136_213, sizeof(GibCursor [3])); + // //memcpy(Ret->field3, cursor_ptr_1323, sizeof(GibCursor [3])); + // memcpy(Ret->field4, cursor_ptr_1323, sizeof(GibCursor [3])); + // //return return_0; + break; + } + + case 1: + { + //GibCursor *soa_field_0_1346 = &t_31_136_213[1]; + GibCursor *soa_field_1_1347 = &t_31_136_213[2]; + + GibInt tmpval_2142 = *(GibInt *) *soa_field_1_1347; + + //GibCursor tmpcur_2143 = soa_field_1_1347 + sizeof(GibInt); + *soa_field_1_1347 += sizeof(GibInt); + + + // GibCursor cursor_ptr_1327[3] = {tmpcur_2135, soa_field_0_1346, + // tmpcur_2143}; + + //GibCursor *loc_615 = &t_31_136_213[0]; + + //GibCursor jumpf_dloc_949 = loc_615 + 1; + //*loc_615 += 1; + + // GibCursor *loc_IntTy_616 = &t_31_136_213[1]; + // GibCursor *loc_IntTy_617 = &t_31_136_213[2]; + + //GibCursor jumpf_floc_loc_951 = soa_field_1_1347 + 8; + //*soa_field_1_1347 += 8; + + //GibCursor jumpf_floc_loc_950 = loc_IntTy_616 + 0; + + // GibCursor loc_717 = jumpf_dloc_949 + 0; + // GibCursor loc_716 = jumpf_floc_loc_951 + 0; + // GibCursor loc_715 = jumpf_floc_loc_950 + 0; + // GibCursor cursor_ptr_1351[3] = {jumpf_dloc_949, jumpf_floc_loc_950, + // jumpf_floc_loc_951}; + GibInt fltPkd_197_219 = tmpval_2142 + 1; + + //GibCursor new_dloc_740 = loc_618 + 1; + + //GibCursor new_floc_loc_742 = loc_IntTy_620 + 8; + // GibCursor cursor_ptr_1352[3] = {new_dloc_740, loc_IntTy_619, + // new_floc_loc_742}; + + *(GibPackedTag *) *loc_618 = 1; + *loc_618 += 1; + + // GibCursor writetag_1371 = loc_618 + 1; + // GibCursor after_tag_1372 = loc_618 + 1; + + *(GibInt *) *loc_IntTy_620 = fltPkd_197_219; + + *loc_IntTy_620 += 8; + + add1Tree(cursor_ptr_1322, cursor_ptr_1321, cursor_ptr_1323, t_31_136_213); + + // GibCursor pvrtmp_2144[3]; + +// memcpy(pvrtmp_2144, tmp_struct_1.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2145[3]; +// +// memcpy(pvrtmp_2145, tmp_struct_1.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2146[3]; +// +// memcpy(pvrtmp_2146, tmp_struct_1.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2147[3]; +// +// memcpy(pvrtmp_2147, tmp_struct_1.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2148[3]; +// +// memcpy(pvrtmp_2148, tmp_struct_1.field4, sizeof(GibCursor [3])); + + add1Tree(cursor_ptr_1322, cursor_ptr_1321, cursor_ptr_1323, t_31_136_213); + +// GibCursor pvrtmp_2153[3]; +// +// memcpy(pvrtmp_2153, tmp_struct_2.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2154[3]; +// +// memcpy(pvrtmp_2154, tmp_struct_2.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2155[3]; +// +// memcpy(pvrtmp_2155, tmp_struct_2.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2156[3]; +// +// memcpy(pvrtmp_2156, tmp_struct_2.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2157[3]; +// +// memcpy(pvrtmp_2157, tmp_struct_2.field4, sizeof(GibCursor [3])); +// +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// return_3; + + // memcpy(return_3.field0, pvrtmp_2153, sizeof(GibCursor [3])); + // memcpy(return_3.field1, pvrtmp_2154, sizeof(GibCursor [3])); + // memcpy(return_3.field2, pvrtmp_2155, sizeof(GibCursor [3])); + // memcpy(return_3.field3, cursor_ptr_1323, sizeof(GibCursor [3])); + // memcpy(return_3.field4, pvrtmp_2157, sizeof(GibCursor [3])); + // return return_3; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// GibCursor soa_field_0_1384 = t_31_136_213[1]; +// GibCursor soa_field_1_1385 = t_31_136_213[2]; +// uintptr_t tagged_tmpcur_8 = *(uintptr_t *) tmpcur_2135; +// GibCursor tmpcur_2166 = GIB_UNTAG(tagged_tmpcur_8); +// GibCursor tmpaftercur_2167 = tmpcur_2135 + 8; +// uint16_t tmptag_2168 = GIB_GET_TAG(tagged_tmpcur_8); +// GibCursor end_from_tagged_dcon_redir_1398 = tmpcur_2166 + +// tmptag_2168; +// GibCursor field_nxt_1395 = soa_field_0_1384 + 1; +// uintptr_t tagged_tmpcur_7 = *(uintptr_t *) field_nxt_1395; +// GibCursor tmpcur_2169 = GIB_UNTAG(tagged_tmpcur_7); +// GibCursor tmpaftercur_2170 = field_nxt_1395 + 8; +// uint16_t tmptag_2171 = GIB_GET_TAG(tagged_tmpcur_7); +// GibCursor end_from_tagged_fld_redir_1399 = tmpcur_2169 + +// tmptag_2171; +// GibCursor field_nxt_1396 = soa_field_1_1385 + 1; +// uintptr_t tagged_tmpcur_6 = *(uintptr_t *) field_nxt_1396; +// GibCursor tmpcur_2172 = GIB_UNTAG(tagged_tmpcur_6); +// GibCursor tmpaftercur_2173 = field_nxt_1396 + 8; +// uint16_t tmptag_2174 = GIB_GET_TAG(tagged_tmpcur_6); +// GibCursor end_from_tagged_fld_redir_1400 = tmpcur_2172 + +// tmptag_2174; +// GibCursor indr_1045[3] = {tmpcur_2166, tmpcur_2169, tmpcur_2172}; +// GibCursor loc_615 = t_31_136_213[0]; +// GibCursor jump_dloc_1049 = loc_615 + 9; +// GibCursor loc_IntTy_617 = t_31_136_213[2]; +// GibCursor loc_IntTy_616 = t_31_136_213[1]; +// GibCursor aft_indir_loc_1057 = loc_IntTy_616 + 9; +// GibCursor aft_indir_loc_1058 = loc_IntTy_617 + 9; +// GibCursor cursor_ptr_1401[3] = {jump_dloc_1049, aft_indir_loc_1057, +// aft_indir_loc_1058}; +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// tmp_struct_4 = +// add1Tree(indr_1045, overwrite_reg_1324, cursor_ptr_1323, indr_1045); +// GibCursor pvrtmp_2175[3]; +// +// memcpy(pvrtmp_2175, tmp_struct_4.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2176[3]; +// +// memcpy(pvrtmp_2176, tmp_struct_4.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2177[3]; +// +// memcpy(pvrtmp_2177, tmp_struct_4.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2178[3]; +// +// memcpy(pvrtmp_2178, tmp_struct_4.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2179[3]; +// +// memcpy(pvrtmp_2179, tmp_struct_4.field4, sizeof(GibCursor [3])); +// +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// return_5; +// +// memcpy(return_5.field0, cursor_ptr_1322, sizeof(GibCursor [3])); +// memcpy(return_5.field1, pvrtmp_2176, sizeof(GibCursor [3])); +// memcpy(return_5.field2, cursor_ptr_1401, sizeof(GibCursor [3])); +// memcpy(return_5.field3, pvrtmp_2178, sizeof(GibCursor [3])); +// memcpy(return_5.field4, pvrtmp_2179, sizeof(GibCursor [3])); +// return return_5; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + GibCursor *soa_field_0_1412 = &t_31_136_213[1]; + GibCursor *soa_field_1_1413 = &t_31_136_213[2]; + + uintptr_t tagged_tmpcur_13 = *(uintptr_t *) (*dcon_1328); + GibCursor tmpcur_2186 = GIB_UNTAG(tagged_tmpcur_13); + *dcon_1328 = tmpcur_2186; + + // GibCursor tmpaftercur_2187 = tmpcur_2135 + 8; + // uint16_t tmptag_2188 = GIB_GET_TAG(tagged_tmpcur_13); + // GibCursor end_from_tagged_dcon_redir_1421 = tmpcur_2186 + + // tmptag_2188; + + GibCursor field_nxt_1419 = *soa_field_0_1412 + 1; + uintptr_t tagged_tmpcur_12 = *(uintptr_t *) field_nxt_1419; + GibCursor tmpcur_2189 = GIB_UNTAG(tagged_tmpcur_12); + *soa_field_0_1412 = tmpcur_2189; + + // GibCursor tmpaftercur_2190 = field_nxt_1419 + 8; + // uint16_t tmptag_2191 = GIB_GET_TAG(tagged_tmpcur_12); + // GibCursor end_from_tagged_fld_redir_1422 = tmpcur_2189 + + // tmptag_2191; + + GibCursor field_nxt_1420 = *soa_field_1_1413 + 1; + uintptr_t tagged_tmpcur_11 = *(uintptr_t *) field_nxt_1420; + GibCursor tmpcur_2192 = GIB_UNTAG(tagged_tmpcur_11); + *soa_field_1_1413 = tmpcur_2192; + + + // GibCursor tmpaftercur_2193 = field_nxt_1420 + 8; + // uint16_t tmptag_2194 = GIB_GET_TAG(tagged_tmpcur_11); + // GibCursor end_from_tagged_fld_redir_1423 = tmpcur_2192 + + // tmptag_2194; + + // GibCursor indr_1045[3] = {tmpcur_2186, tmpcur_2189, tmpcur_2192}; + + // GibCursor copy_dloc_1059 = loc_618 + 0; + // GibCursor copy_floc_loc_1061 = loc_IntTy_620 + 0; + // GibCursor copy_floc_loc_1060 = loc_IntTy_619 + 0; + // GibCursor cursor_ptr_1424[3] = {copy_dloc_1059, copy_floc_loc_1060, + // copy_floc_loc_1061}; + + add1Tree(t_31_136_213, cursor_ptr_1321, cursor_ptr_1323, t_31_136_213); + + +// GibCursor pvrtmp_2195[3]; +// +// memcpy(pvrtmp_2195, tmp_struct_9.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2196[3]; +// +// memcpy(pvrtmp_2196, tmp_struct_9.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2197[3]; +// +// memcpy(pvrtmp_2197, tmp_struct_9.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2198[3]; +// +// memcpy(pvrtmp_2198, tmp_struct_9.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2199[3]; +// +// memcpy(pvrtmp_2199, tmp_struct_9.field4, sizeof(GibCursor [3])); +// +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// return_10; +// +// memcpy(return_10.field0, pvrtmp_2195, sizeof(GibCursor [3])); +// memcpy(return_10.field1, pvrtmp_2196, sizeof(GibCursor [3])); +// memcpy(return_10.field2, pvrtmp_2197, sizeof(GibCursor [3])); +// memcpy(return_10.field3, pvrtmp_2198, sizeof(GibCursor [3])); +// memcpy(return_10.field4, pvrtmp_2199, sizeof(GibCursor [3])); +// return return_10; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2134"); + exit(1); + } + } +} + +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod _copy_Tree(GibCursor cursor_ptr_1436[3], + GibCursor cursor_ptr_1435[3], + GibCursor cursor_ptr_1437[3], + GibCursor arg_89_141_222[3]) +{ + GibCursor end_r_636 = cursor_ptr_1435[0]; + GibCursor end_r_637 = cursor_ptr_1435[1]; + GibCursor end_r_638 = cursor_ptr_1435[2]; + GibCursor loc_IntTy_631 = cursor_ptr_1437[1]; + GibCursor loc_IntTy_632 = cursor_ptr_1437[2]; + GibCursor loc_630 = cursor_ptr_1437[0]; + + if (loc_IntTy_632 + 17 > end_r_638 || (loc_IntTy_631 + 17 > end_r_637 || + loc_630 + 34 > end_r_636)) { + gib_grow_region(&loc_IntTy_632, &end_r_638); + gib_grow_region(&loc_IntTy_631, &end_r_637); + gib_grow_region(&loc_630, &end_r_636); + } + + GibCursor end_r_633 = cursor_ptr_1436[0]; + GibCursor end_r_634 = cursor_ptr_1436[1]; + GibCursor end_r_635 = cursor_ptr_1436[2]; + GibCursor overwrite_reg_1438[3] = {end_r_636, end_r_637, end_r_638}; + GibCursor dcon_1442 = arg_89_141_222[0]; + GibPackedTag tmpval_2207 = *(GibPackedTag *) dcon_1442; + GibCursor tmpcur_2208 = dcon_1442 + 1; + + + switch_2279: + ; + switch (tmpval_2207) { + + case 0: + { + GibCursor soa_field_0_1444 = arg_89_141_222[1]; + GibCursor soa_field_1_1445 = arg_89_141_222[2]; + GibInt tmpval_2209 = *(GibInt *) soa_field_0_1444; + GibCursor tmpcur_2210 = soa_field_0_1444 + sizeof(GibInt); + GibCursor loc_627 = arg_89_141_222[0]; + GibCursor jumpf_dloc_959 = loc_627 + 1; + GibCursor loc_IntTy_628 = arg_89_141_222[1]; + GibCursor loc_IntTy_629 = arg_89_141_222[2]; + GibCursor jumpf_floc_loc_960 = soa_field_0_1444 + 8; + GibCursor jumpf_floc_loc_961 = loc_IntTy_629 + 0; + GibCursor cursor_ptr_1448[3] = {jumpf_dloc_959, jumpf_floc_loc_960, + jumpf_floc_loc_961}; + GibCursor new_floc_loc_788 = loc_IntTy_632 + 8; + GibCursor new_dloc_786 = loc_630 + 1; + + *(GibPackedTag *) loc_630 = 0; + + GibCursor writetag_1449 = loc_630 + 1; + GibCursor after_tag_1450 = loc_630 + 1; + + *(GibInt *) loc_IntTy_631 = tmpval_2209; + + GibCursor writecur_1454 = loc_IntTy_631 + sizeof(GibInt); + GibCursor aft_soa_loc_1456[3] = {after_tag_1450, writecur_1454, + loc_IntTy_632}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_14; + + memcpy(return_14.field0, cursor_ptr_1436, sizeof(GibCursor [3])); + memcpy(return_14.field1, overwrite_reg_1438, sizeof(GibCursor [3])); + memcpy(return_14.field2, cursor_ptr_1448, sizeof(GibCursor [3])); + memcpy(return_14.field3, cursor_ptr_1437, sizeof(GibCursor [3])); + memcpy(return_14.field4, aft_soa_loc_1456, sizeof(GibCursor [3])); + return return_14; + break; + } + + case 1: + { + GibCursor soa_field_0_1460 = arg_89_141_222[1]; + GibCursor soa_field_1_1461 = arg_89_141_222[2]; + GibInt tmpval_2215 = *(GibInt *) soa_field_1_1461; + GibCursor tmpcur_2216 = soa_field_1_1461 + sizeof(GibInt); + GibCursor cursor_ptr_1441[3] = {tmpcur_2208, soa_field_0_1460, + tmpcur_2216}; + GibCursor loc_627 = arg_89_141_222[0]; + GibCursor jumpf_dloc_963 = loc_627 + 1; + GibCursor loc_IntTy_628 = arg_89_141_222[1]; + GibCursor loc_IntTy_629 = arg_89_141_222[2]; + GibCursor jumpf_floc_loc_965 = soa_field_1_1461 + 8; + GibCursor jumpf_floc_loc_964 = loc_IntTy_628 + 0; + GibCursor loc_763 = jumpf_dloc_963 + 0; + GibCursor loc_762 = jumpf_floc_loc_965 + 0; + GibCursor loc_761 = jumpf_floc_loc_964 + 0; + GibCursor cursor_ptr_1465[3] = {jumpf_dloc_963, jumpf_floc_loc_964, + jumpf_floc_loc_965}; + GibCursor new_floc_loc_788 = loc_IntTy_632 + 8; + GibCursor new_dloc_786 = loc_630 + 1; + GibCursor cursor_ptr_1466[3] = {new_dloc_786, loc_IntTy_631, + new_floc_loc_788}; + + *(GibPackedTag *) loc_630 = 1; + + GibCursor writetag_1485 = loc_630 + 1; + GibCursor after_tag_1486 = loc_630 + 1; + + *(GibInt *) loc_IntTy_632 = tmpval_2215; + + GibCursor writecur_1490 = loc_IntTy_632 + sizeof(GibInt); + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_15 = + _copy_Tree(cursor_ptr_1436, overwrite_reg_1438, cursor_ptr_1466, cursor_ptr_1441); + GibCursor pvrtmp_2217[3]; + + memcpy(pvrtmp_2217, tmp_struct_15.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2218[3]; + + memcpy(pvrtmp_2218, tmp_struct_15.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2219[3]; + + memcpy(pvrtmp_2219, tmp_struct_15.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2220[3]; + + memcpy(pvrtmp_2220, tmp_struct_15.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2221[3]; + + memcpy(pvrtmp_2221, tmp_struct_15.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_16 = + _copy_Tree(pvrtmp_2217, pvrtmp_2218, pvrtmp_2221, pvrtmp_2219); + GibCursor pvrtmp_2226[3]; + + memcpy(pvrtmp_2226, tmp_struct_16.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2227[3]; + + memcpy(pvrtmp_2227, tmp_struct_16.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2228[3]; + + memcpy(pvrtmp_2228, tmp_struct_16.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2229[3]; + + memcpy(pvrtmp_2229, tmp_struct_16.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2230[3]; + + memcpy(pvrtmp_2230, tmp_struct_16.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_17; + + memcpy(return_17.field0, pvrtmp_2226, sizeof(GibCursor [3])); + memcpy(return_17.field1, pvrtmp_2227, sizeof(GibCursor [3])); + memcpy(return_17.field2, pvrtmp_2228, sizeof(GibCursor [3])); + memcpy(return_17.field3, cursor_ptr_1437, sizeof(GibCursor [3])); + memcpy(return_17.field4, pvrtmp_2230, sizeof(GibCursor [3])); + return return_17; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1498 = arg_89_141_222[1]; + GibCursor soa_field_1_1499 = arg_89_141_222[2]; + uintptr_t tagged_tmpcur_22 = *(uintptr_t *) tmpcur_2208; + GibCursor tmpcur_2239 = GIB_UNTAG(tagged_tmpcur_22); + GibCursor tmpaftercur_2240 = tmpcur_2208 + 8; + uint16_t tmptag_2241 = GIB_GET_TAG(tagged_tmpcur_22); + GibCursor end_from_tagged_dcon_redir_1512 = tmpcur_2239 + + tmptag_2241; + GibCursor field_nxt_1509 = soa_field_0_1498 + 1; + uintptr_t tagged_tmpcur_21 = *(uintptr_t *) field_nxt_1509; + GibCursor tmpcur_2242 = GIB_UNTAG(tagged_tmpcur_21); + GibCursor tmpaftercur_2243 = field_nxt_1509 + 8; + uint16_t tmptag_2244 = GIB_GET_TAG(tagged_tmpcur_21); + GibCursor end_from_tagged_fld_redir_1513 = tmpcur_2242 + + tmptag_2244; + GibCursor field_nxt_1510 = soa_field_1_1499 + 1; + uintptr_t tagged_tmpcur_20 = *(uintptr_t *) field_nxt_1510; + GibCursor tmpcur_2245 = GIB_UNTAG(tagged_tmpcur_20); + GibCursor tmpaftercur_2246 = field_nxt_1510 + 8; + uint16_t tmptag_2247 = GIB_GET_TAG(tagged_tmpcur_20); + GibCursor end_from_tagged_fld_redir_1514 = tmpcur_2245 + + tmptag_2247; + GibCursor indr_1062[3] = {tmpcur_2239, tmpcur_2242, tmpcur_2245}; + GibCursor loc_627 = arg_89_141_222[0]; + GibCursor jump_dloc_1066 = loc_627 + 9; + GibCursor loc_IntTy_629 = arg_89_141_222[2]; + GibCursor loc_IntTy_628 = arg_89_141_222[1]; + GibCursor aft_indir_loc_1074 = loc_IntTy_628 + 9; + GibCursor aft_indir_loc_1075 = loc_IntTy_629 + 9; + GibCursor cursor_ptr_1515[3] = {jump_dloc_1066, aft_indir_loc_1074, + aft_indir_loc_1075}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_18 = + _copy_Tree(indr_1062, overwrite_reg_1438, cursor_ptr_1437, indr_1062); + GibCursor pvrtmp_2248[3]; + + memcpy(pvrtmp_2248, tmp_struct_18.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2249[3]; + + memcpy(pvrtmp_2249, tmp_struct_18.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2250[3]; + + memcpy(pvrtmp_2250, tmp_struct_18.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2251[3]; + + memcpy(pvrtmp_2251, tmp_struct_18.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2252[3]; + + memcpy(pvrtmp_2252, tmp_struct_18.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_19; + + memcpy(return_19.field0, cursor_ptr_1436, sizeof(GibCursor [3])); + memcpy(return_19.field1, pvrtmp_2249, sizeof(GibCursor [3])); + memcpy(return_19.field2, cursor_ptr_1515, sizeof(GibCursor [3])); + memcpy(return_19.field3, pvrtmp_2251, sizeof(GibCursor [3])); + memcpy(return_19.field4, pvrtmp_2252, sizeof(GibCursor [3])); + return return_19; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1526 = arg_89_141_222[1]; + GibCursor soa_field_1_1527 = arg_89_141_222[2]; + uintptr_t tagged_tmpcur_27 = *(uintptr_t *) tmpcur_2208; + GibCursor tmpcur_2259 = GIB_UNTAG(tagged_tmpcur_27); + GibCursor tmpaftercur_2260 = tmpcur_2208 + 8; + uint16_t tmptag_2261 = GIB_GET_TAG(tagged_tmpcur_27); + GibCursor end_from_tagged_dcon_redir_1535 = tmpcur_2259 + + tmptag_2261; + GibCursor field_nxt_1533 = soa_field_0_1526 + 1; + uintptr_t tagged_tmpcur_26 = *(uintptr_t *) field_nxt_1533; + GibCursor tmpcur_2262 = GIB_UNTAG(tagged_tmpcur_26); + GibCursor tmpaftercur_2263 = field_nxt_1533 + 8; + uint16_t tmptag_2264 = GIB_GET_TAG(tagged_tmpcur_26); + GibCursor end_from_tagged_fld_redir_1536 = tmpcur_2262 + + tmptag_2264; + GibCursor field_nxt_1534 = soa_field_1_1527 + 1; + uintptr_t tagged_tmpcur_25 = *(uintptr_t *) field_nxt_1534; + GibCursor tmpcur_2265 = GIB_UNTAG(tagged_tmpcur_25); + GibCursor tmpaftercur_2266 = field_nxt_1534 + 8; + uint16_t tmptag_2267 = GIB_GET_TAG(tagged_tmpcur_25); + GibCursor end_from_tagged_fld_redir_1537 = tmpcur_2265 + + tmptag_2267; + GibCursor indr_1062[3] = {tmpcur_2259, tmpcur_2262, tmpcur_2265}; + GibCursor copy_dloc_1076 = loc_630 + 0; + GibCursor copy_floc_loc_1078 = loc_IntTy_632 + 0; + GibCursor copy_floc_loc_1077 = loc_IntTy_631 + 0; + GibCursor cursor_ptr_1538[3] = {copy_dloc_1076, copy_floc_loc_1077, + copy_floc_loc_1078}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_23 = + _copy_Tree(indr_1062, overwrite_reg_1438, cursor_ptr_1538, indr_1062); + GibCursor pvrtmp_2268[3]; + + memcpy(pvrtmp_2268, tmp_struct_23.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2269[3]; + + memcpy(pvrtmp_2269, tmp_struct_23.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2270[3]; + + memcpy(pvrtmp_2270, tmp_struct_23.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2271[3]; + + memcpy(pvrtmp_2271, tmp_struct_23.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2272[3]; + + memcpy(pvrtmp_2272, tmp_struct_23.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_24; + + memcpy(return_24.field0, pvrtmp_2268, sizeof(GibCursor [3])); + memcpy(return_24.field1, pvrtmp_2269, sizeof(GibCursor [3])); + memcpy(return_24.field2, pvrtmp_2270, sizeof(GibCursor [3])); + memcpy(return_24.field3, pvrtmp_2271, sizeof(GibCursor [3])); + memcpy(return_24.field4, pvrtmp_2272, sizeof(GibCursor [3])); + return return_24; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2207"); + exit(1); + } + } +} + +void sumTree(GibCursor cursor_ptr_1549[3], + GibCursor tr_36_150_231[3], + GibInt *Res) +{ + GibCursor *end_r_642 = &cursor_ptr_1549[0]; + GibCursor *end_r_643 = &cursor_ptr_1549[1]; + GibCursor *end_r_644 = &cursor_ptr_1549[2]; + GibCursor *dcon_1553 = &tr_36_150_231[0]; + GibPackedTag tmpval_2280 = *(GibPackedTag *) *dcon_1553; + //GibCursor tmpcur_2281 = dcon_1553 + 1; + *dcon_1553 += 1; + + switch_2316: + ; + switch (tmpval_2280) { + + case 0: + { + GibCursor *soa_field_0_1555 = &tr_36_150_231[1]; + GibCursor *soa_field_1_1556 = &tr_36_150_231[2]; + + GibInt tmpval_2282 = *(GibInt *) *soa_field_0_1555; + //GibCursor tmpcur_2283 = soa_field_0_1555 + sizeof(GibInt); + + *soa_field_0_1555 += sizeof(GibInt); + + + //GibCursor *loc_639 = &tr_36_150_231[0]; + ///GibCursor jumpf_dloc_973 = loc_639 + 1; + + + // GibCursor loc_IntTy_640 = &tr_36_150_231[1]; + // GibCursor loc_IntTy_641 = &tr_36_150_231[2]; + + + + //GibCursor jumpf_floc_loc_974 = soa_field_0_1555 + 8; + //GibCursor jumpf_floc_loc_975 = loc_IntTy_641 + 0; + //GibCursor cursor_ptr_1559[3] = {jumpf_dloc_973, jumpf_floc_loc_974, + // jumpf_floc_loc_975}; + // GibCursorPtr3GibCursorPtr3GibIntProd return_28; + + // memcpy(return_28.field0, cursor_ptr_1549, sizeof(GibCursor [3])); + // memcpy(return_28.field1, cursor_ptr_1559, sizeof(GibCursor [3])); + // return_28.field2 = tmpval_2282; + *Res += tmpval_2282; + // return return_28; + break; + } + + case 1: + { + GibCursor *soa_field_0_1561 = &tr_36_150_231[1]; + GibCursor *soa_field_1_1562 = &tr_36_150_231[2]; + + + GibInt tmpval_2284 = *(GibInt *) *soa_field_1_1562; + //GibCursor tmpcur_2285 = soa_field_1_1562 + sizeof(GibInt); + *soa_field_1_1562 += sizeof(GibInt); + + + //GibCursor cursor_ptr_1552[3] = {tmpcur_2281, soa_field_0_1561, + // tmpcur_2285}; + + + //GibCursor loc_639 = tr_36_150_231[0]; + //GibCursor jumpf_dloc_976 = loc_639 + 1; + + + //GibCursor loc_IntTy_640 = tr_36_150_231[1]; + //GibCursor loc_IntTy_641 = tr_36_150_231[2]; + + //GibCursor jumpf_floc_loc_978 = soa_field_1_1562 + 8; + //GibCursor jumpf_floc_loc_977 = loc_IntTy_640 + 0; + //GibCursor loc_806 = jumpf_dloc_976 + 0; + //GibCursor loc_805 = jumpf_floc_loc_978 + 0; + //GibCursor loc_804 = jumpf_floc_loc_977 + 0; + // GibCursor cursor_ptr_1566[3] = {jumpf_dloc_976, jumpf_floc_loc_977, + // jumpf_floc_loc_978}; + + *Res += tmpval_2284; + sumTree(cursor_ptr_1549, tr_36_150_231, Res); + + + + // GibCursor pvrtmp_2286[3]; + + // memcpy(pvrtmp_2286, tmp_struct_29.field0, sizeof(GibCursor [3])); + + // GibCursor pvrtmp_2287[3]; + + // memcpy(pvrtmp_2287, tmp_struct_29.field1, sizeof(GibCursor [3])); + + // GibInt pvrtmp_2288 = tmp_struct_29.field2; + + //GibInt fltPrm_200_237 = tmpval_2284 + pvrtmp_2288; + + sumTree(cursor_ptr_1549, tr_36_150_231, Res); + + // GibCursor pvrtmp_2289[3]; + + // memcpy(pvrtmp_2289, tmp_struct_30.field0, sizeof(GibCursor [3])); + + // GibCursor pvrtmp_2290[3]; + + // memcpy(pvrtmp_2290, tmp_struct_30.field1, sizeof(GibCursor [3])); + + // GibInt pvrtmp_2291 = tmp_struct_30.field2; + + //GibInt tailprim_985 = fltPrm_200_237 + pvrtmp_2291; + //GibCursorPtr3GibCursorPtr3GibIntProd return_31; + + //memcpy(return_31.field0, pvrtmp_2289, sizeof(GibCursor [3])); + //memcpy(return_31.field1, pvrtmp_2290, sizeof(GibCursor [3])); + //return_31.field2 = tailprim_985; + //return return_31; + break; + } + // case GIB_INDIRECTION_TAG: + // { + // GibCursor soa_field_0_1579 = tr_36_150_231[1]; + // GibCursor soa_field_1_1580 = tr_36_150_231[2]; + // uintptr_t tagged_tmpcur_36 = *(uintptr_t *) tmpcur_2281; + // GibCursor tmpcur_2292 = GIB_UNTAG(tagged_tmpcur_36); + // GibCursor tmpaftercur_2293 = tmpcur_2281 + 8; + // uint16_t tmptag_2294 = GIB_GET_TAG(tagged_tmpcur_36); + // GibCursor end_from_tagged_dcon_redir_1593 = tmpcur_2292 + + // tmptag_2294; + // GibCursor field_nxt_1590 = soa_field_0_1579 + 1; + // uintptr_t tagged_tmpcur_35 = *(uintptr_t *) field_nxt_1590; + // GibCursor tmpcur_2295 = GIB_UNTAG(tagged_tmpcur_35); + // GibCursor tmpaftercur_2296 = field_nxt_1590 + 8; + // uint16_t tmptag_2297 = GIB_GET_TAG(tagged_tmpcur_35); + // GibCursor end_from_tagged_fld_redir_1594 = tmpcur_2295 + + // tmptag_2297; + // GibCursor field_nxt_1591 = soa_field_1_1580 + 1; + // uintptr_t tagged_tmpcur_34 = *(uintptr_t *) field_nxt_1591; + // GibCursor tmpcur_2298 = GIB_UNTAG(tagged_tmpcur_34); + // GibCursor tmpaftercur_2299 = field_nxt_1591 + 8; + // uint16_t tmptag_2300 = GIB_GET_TAG(tagged_tmpcur_34); + // GibCursor end_from_tagged_fld_redir_1595 = tmpcur_2298 + + // tmptag_2300; + // GibCursor indr_1079[3] = {tmpcur_2292, tmpcur_2295, tmpcur_2298}; + // GibCursor loc_639 = tr_36_150_231[0]; + // GibCursor jump_dloc_1083 = loc_639 + 9; + // GibCursor loc_IntTy_641 = tr_36_150_231[2]; + // GibCursor loc_IntTy_640 = tr_36_150_231[1]; + // GibCursor aft_indir_loc_1091 = loc_IntTy_640 + 9; + // GibCursor aft_indir_loc_1092 = loc_IntTy_641 + 9; + // GibCursor cursor_ptr_1596[3] = {jump_dloc_1083, aft_indir_loc_1091, + // aft_indir_loc_1092}; + // GibCursorPtr3GibCursorPtr3GibIntProd tmp_struct_32 = + // sumTree(indr_1079, indr_1079); + // GibCursor pvrtmp_2301[3]; + + // memcpy(pvrtmp_2301, tmp_struct_32.field0, sizeof(GibCursor [3])); + + // GibCursor pvrtmp_2302[3]; + + // memcpy(pvrtmp_2302, tmp_struct_32.field1, sizeof(GibCursor [3])); + + // GibInt pvrtmp_2303 = tmp_struct_32.field2; + // GibCursorPtr3GibCursorPtr3GibIntProd return_33; + + // memcpy(return_33.field0, cursor_ptr_1549, sizeof(GibCursor [3])); + // memcpy(return_33.field1, cursor_ptr_1596, sizeof(GibCursor [3])); + // return_33.field2 = pvrtmp_2303; + // return return_33; + // break; + // } + + case GIB_REDIRECTION_TAG: + { + GibCursor *soa_field_0_1604 = &tr_36_150_231[1]; + GibCursor *soa_field_1_1605 = &tr_36_150_231[2]; + + uintptr_t tagged_tmpcur_41 = *(uintptr_t *) (*dcon_1553); + GibCursor tmpcur_2304 = GIB_UNTAG(tagged_tmpcur_41); + *dcon_1553 = tmpcur_2304; + + //GibCursor tmpaftercur_2305 = tmpcur_2281 + 8; + // uint16_t tmptag_2306 = GIB_GET_TAG(tagged_tmpcur_41); + // GibCursor end_from_tagged_dcon_redir_1613 = tmpcur_2304 + + // tmptag_2306; + + + + GibCursor field_nxt_1611 = *soa_field_0_1604 + 1; + uintptr_t tagged_tmpcur_40 = *(uintptr_t *) field_nxt_1611; + GibCursor tmpcur_2307 = GIB_UNTAG(tagged_tmpcur_40); + *soa_field_0_1604 = tmpcur_2307; + + + //GibCursor tmpaftercur_2308 = field_nxt_1611 + 8; + //uint16_t tmptag_2309 = GIB_GET_TAG(tagged_tmpcur_40); + //GibCursor end_from_tagged_fld_redir_1614 = tmpcur_2307 + + // tmptag_2309; + + + GibCursor field_nxt_1612 = *soa_field_1_1605 + 1; + uintptr_t tagged_tmpcur_39 = *(uintptr_t *) field_nxt_1612; + GibCursor tmpcur_2310 = GIB_UNTAG(tagged_tmpcur_39); + *soa_field_1_1605 = tmpcur_2310; + + //GibCursor tmpaftercur_2311 = field_nxt_1612 + 8; + //uint16_t tmptag_2312 = GIB_GET_TAG(tagged_tmpcur_39); + //GibCursor end_from_tagged_fld_redir_1615 = tmpcur_2310 + + // tmptag_2312; + + + //GibCursor indr_1079[3] = {tmpcur_2304, tmpcur_2307, tmpcur_2310}; + sumTree(tr_36_150_231, tr_36_150_231, Res); + + // GibCursor pvrtmp_2313[3]; + + // memcpy(pvrtmp_2313, tmp_struct_37.field0, sizeof(GibCursor [3])); + + // GibCursor pvrtmp_2314[3]; + + // memcpy(pvrtmp_2314, tmp_struct_37.field1, sizeof(GibCursor [3])); + + // GibInt pvrtmp_2315 = tmp_struct_37.field2; + // GibCursorPtr3GibCursorPtr3GibIntProd return_38; + + // memcpy(return_38.field0, pvrtmp_2313, sizeof(GibCursor [3])); + // memcpy(return_38.field1, pvrtmp_2314, sizeof(GibCursor [3])); + // return_38.field2 = pvrtmp_2315; + // return return_38; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2280"); + exit(1); + } + } +} + + +GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod mkTree(GibCursor cursor_ptr_1622[3], + GibCursor cursor_ptr_1623[3], + GibInt d_41_155_239, + GibInt acc_42_156_240) +{ + GibCursor end_r_649 = cursor_ptr_1622[1]; + GibCursor end_r_648 = cursor_ptr_1622[0]; + GibCursor end_r_650 = cursor_ptr_1622[2]; + GibCursor loc_645 = cursor_ptr_1623[0]; + GibCursor loc_IntTy_646 = cursor_ptr_1623[1]; + GibCursor loc_IntTy_647 = cursor_ptr_1623[2]; + + if (loc_IntTy_647 + 17 > end_r_650 || (loc_IntTy_646 + 17 > end_r_649 || + loc_645 + 34 > end_r_648)) { + gib_grow_region(&loc_IntTy_647, &end_r_650); + gib_grow_region(&loc_IntTy_646, &end_r_649); + gib_grow_region(&loc_645, &end_r_648); + } + + GibCursor overwrite_reg_1624[3] = {end_r_648, end_r_649, end_r_650}; + GibBool fltIf_203_241 = d_41_155_239 == 0; + + if (fltIf_203_241) { + GibCursor new_floc_loc_834 = loc_IntTy_647 + 8; + GibCursor new_dloc_832 = loc_645 + 1; + + *(GibPackedTag *) loc_645 = 0; + + GibCursor writetag_1625 = loc_645 + 1; + GibCursor after_tag_1626 = loc_645 + 1; + + *(GibInt *) loc_IntTy_646 = acc_42_156_240; + + GibCursor writecur_1630 = loc_IntTy_646 + sizeof(GibInt); + GibCursor aft_soa_loc_1632[3] = {after_tag_1626, writecur_1630, + loc_IntTy_647}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod return_42; + + memcpy(return_42.field0, overwrite_reg_1624, sizeof(GibCursor [3])); + memcpy(return_42.field1, cursor_ptr_1623, sizeof(GibCursor [3])); + memcpy(return_42.field2, aft_soa_loc_1632, sizeof(GibCursor [3])); + return return_42; + } else { + GibInt fltAppE_205_242 = d_41_155_239 - 1; + GibInt fltAppE_206_243 = d_41_155_239 + acc_42_156_240; + GibCursor new_floc_loc_834 = loc_IntTy_647 + 8; + GibCursor new_dloc_832 = loc_645 + 1; + GibCursor cursor_ptr_1635[3] = {new_dloc_832, loc_IntTy_646, + new_floc_loc_834}; + + *(GibPackedTag *) loc_645 = 1; + + GibCursor writetag_1645 = loc_645 + 1; + GibCursor after_tag_1646 = loc_645 + 1; + + *(GibInt *) loc_IntTy_647 = d_41_155_239; + + GibCursor writecur_1650 = loc_IntTy_647 + sizeof(GibInt); + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod tmp_struct_43 = + mkTree(overwrite_reg_1624, cursor_ptr_1635, fltAppE_205_242, fltAppE_206_243); + GibCursor pvrtmp_2321[3]; + + memcpy(pvrtmp_2321, tmp_struct_43.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2322[3]; + + memcpy(pvrtmp_2322, tmp_struct_43.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2323[3]; + + memcpy(pvrtmp_2323, tmp_struct_43.field2, sizeof(GibCursor [3])); + + GibInt fltAppE_208_245 = d_41_155_239 - 1; + GibInt fltAppE_209_246 = d_41_155_239 + acc_42_156_240; + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod tmp_struct_44 = + mkTree(pvrtmp_2321, pvrtmp_2323, fltAppE_208_245, fltAppE_209_246); + GibCursor pvrtmp_2328[3]; + + memcpy(pvrtmp_2328, tmp_struct_44.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2329[3]; + + memcpy(pvrtmp_2329, tmp_struct_44.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2330[3]; + + memcpy(pvrtmp_2330, tmp_struct_44.field2, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod return_45; + + memcpy(return_45.field0, pvrtmp_2328, sizeof(GibCursor [3])); + memcpy(return_45.field1, cursor_ptr_1623, sizeof(GibCursor [3])); + memcpy(return_45.field2, pvrtmp_2330, sizeof(GibCursor [3])); + return return_45; + } +} +GibCursorPtr3GibCursorPtr3Prod _traverse_Tree(GibCursor cursor_ptr_1658[3], + GibCursor arg_107_163_248[3]) +{ + GibCursor end_r_654 = cursor_ptr_1658[0]; + GibCursor end_r_655 = cursor_ptr_1658[1]; + GibCursor end_r_656 = cursor_ptr_1658[2]; + GibCursor dcon_1662 = arg_107_163_248[0]; + GibPackedTag tmpval_2339 = *(GibPackedTag *) dcon_1662; + GibCursor tmpcur_2340 = dcon_1662 + 1; + + + switch_2371: + ; + switch (tmpval_2339) { + + case 0: + { + GibCursor soa_field_0_1664 = arg_107_163_248[1]; + GibCursor soa_field_1_1665 = arg_107_163_248[2]; + GibInt tmpval_2341 = *(GibInt *) soa_field_0_1664; + GibCursor tmpcur_2342 = soa_field_0_1664 + sizeof(GibInt); + GibCursor loc_651 = arg_107_163_248[0]; + GibCursor jumpf_dloc_988 = loc_651 + 1; + GibCursor loc_IntTy_652 = arg_107_163_248[1]; + GibCursor loc_IntTy_653 = arg_107_163_248[2]; + GibCursor jumpf_floc_loc_989 = soa_field_0_1664 + 8; + GibCursor jumpf_floc_loc_990 = loc_IntTy_653 + 0; + GibCursor cursor_ptr_1668[3] = {jumpf_dloc_988, jumpf_floc_loc_989, + jumpf_floc_loc_990}; + GibCursorPtr3GibCursorPtr3Prod return_46; + + memcpy(return_46.field0, cursor_ptr_1658, sizeof(GibCursor [3])); + memcpy(return_46.field1, cursor_ptr_1668, sizeof(GibCursor [3])); + return return_46; + break; + } + + case 1: + { + GibCursor soa_field_0_1670 = arg_107_163_248[1]; + GibCursor soa_field_1_1671 = arg_107_163_248[2]; + GibInt tmpval_2343 = *(GibInt *) soa_field_1_1671; + GibCursor tmpcur_2344 = soa_field_1_1671 + sizeof(GibInt); + GibCursor cursor_ptr_1661[3] = {tmpcur_2340, soa_field_0_1670, + tmpcur_2344}; + GibCursor loc_651 = arg_107_163_248[0]; + GibCursor jumpf_dloc_992 = loc_651 + 1; + GibCursor loc_IntTy_652 = arg_107_163_248[1]; + GibCursor loc_IntTy_653 = arg_107_163_248[2]; + GibCursor jumpf_floc_loc_994 = soa_field_1_1671 + 8; + GibCursor jumpf_floc_loc_993 = loc_IntTy_652 + 0; + GibCursor loc_852 = jumpf_dloc_992 + 0; + GibCursor loc_851 = jumpf_floc_loc_994 + 0; + GibCursor loc_850 = jumpf_floc_loc_993 + 0; + GibCursor cursor_ptr_1675[3] = {jumpf_dloc_992, jumpf_floc_loc_993, + jumpf_floc_loc_994}; + GibCursorPtr3GibCursorPtr3Prod tmp_struct_47 = + _traverse_Tree(cursor_ptr_1658, cursor_ptr_1661); + GibCursor pvrtmp_2345[3]; + + memcpy(pvrtmp_2345, tmp_struct_47.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2346[3]; + + memcpy(pvrtmp_2346, tmp_struct_47.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod tmp_struct_48 = + _traverse_Tree(pvrtmp_2345, pvrtmp_2346); + GibCursor pvrtmp_2347[3]; + + memcpy(pvrtmp_2347, tmp_struct_48.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2348[3]; + + memcpy(pvrtmp_2348, tmp_struct_48.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_49; + + memcpy(return_49.field0, pvrtmp_2347, sizeof(GibCursor [3])); + memcpy(return_49.field1, pvrtmp_2348, sizeof(GibCursor [3])); + return return_49; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1688 = arg_107_163_248[1]; + GibCursor soa_field_1_1689 = arg_107_163_248[2]; + uintptr_t tagged_tmpcur_54 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2349 = GIB_UNTAG(tagged_tmpcur_54); + GibCursor tmpaftercur_2350 = tmpcur_2340 + 8; + uint16_t tmptag_2351 = GIB_GET_TAG(tagged_tmpcur_54); + GibCursor end_from_tagged_dcon_redir_1702 = tmpcur_2349 + + tmptag_2351; + GibCursor field_nxt_1699 = soa_field_0_1688 + 1; + uintptr_t tagged_tmpcur_53 = *(uintptr_t *) field_nxt_1699; + GibCursor tmpcur_2352 = GIB_UNTAG(tagged_tmpcur_53); + GibCursor tmpaftercur_2353 = field_nxt_1699 + 8; + uint16_t tmptag_2354 = GIB_GET_TAG(tagged_tmpcur_53); + GibCursor end_from_tagged_fld_redir_1703 = tmpcur_2352 + + tmptag_2354; + GibCursor field_nxt_1700 = soa_field_1_1689 + 1; + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) field_nxt_1700; + GibCursor tmpcur_2355 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_2356 = field_nxt_1700 + 8; + uint16_t tmptag_2357 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_fld_redir_1704 = tmpcur_2355 + + tmptag_2357; + GibCursor indr_1093[3] = {tmpcur_2349, tmpcur_2352, tmpcur_2355}; + GibCursor loc_651 = arg_107_163_248[0]; + GibCursor jump_dloc_1097 = loc_651 + 9; + GibCursor loc_IntTy_653 = arg_107_163_248[2]; + GibCursor loc_IntTy_652 = arg_107_163_248[1]; + GibCursor aft_indir_loc_1105 = loc_IntTy_652 + 9; + GibCursor aft_indir_loc_1106 = loc_IntTy_653 + 9; + GibCursor cursor_ptr_1705[3] = {jump_dloc_1097, aft_indir_loc_1105, + aft_indir_loc_1106}; + GibCursorPtr3GibCursorPtr3Prod tmp_struct_50 = + _traverse_Tree(indr_1093, indr_1093); + GibCursor pvrtmp_2358[3]; + + memcpy(pvrtmp_2358, tmp_struct_50.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2359[3]; + + memcpy(pvrtmp_2359, tmp_struct_50.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_51; + + memcpy(return_51.field0, cursor_ptr_1658, sizeof(GibCursor [3])); + memcpy(return_51.field1, cursor_ptr_1705, sizeof(GibCursor [3])); + return return_51; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1713 = arg_107_163_248[1]; + GibCursor soa_field_1_1714 = arg_107_163_248[2]; + uintptr_t tagged_tmpcur_59 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2360 = GIB_UNTAG(tagged_tmpcur_59); + GibCursor tmpaftercur_2361 = tmpcur_2340 + 8; + uint16_t tmptag_2362 = GIB_GET_TAG(tagged_tmpcur_59); + GibCursor end_from_tagged_dcon_redir_1722 = tmpcur_2360 + + tmptag_2362; + GibCursor field_nxt_1720 = soa_field_0_1713 + 1; + uintptr_t tagged_tmpcur_58 = *(uintptr_t *) field_nxt_1720; + GibCursor tmpcur_2363 = GIB_UNTAG(tagged_tmpcur_58); + GibCursor tmpaftercur_2364 = field_nxt_1720 + 8; + uint16_t tmptag_2365 = GIB_GET_TAG(tagged_tmpcur_58); + GibCursor end_from_tagged_fld_redir_1723 = tmpcur_2363 + + tmptag_2365; + GibCursor field_nxt_1721 = soa_field_1_1714 + 1; + uintptr_t tagged_tmpcur_57 = *(uintptr_t *) field_nxt_1721; + GibCursor tmpcur_2366 = GIB_UNTAG(tagged_tmpcur_57); + GibCursor tmpaftercur_2367 = field_nxt_1721 + 8; + uint16_t tmptag_2368 = GIB_GET_TAG(tagged_tmpcur_57); + GibCursor end_from_tagged_fld_redir_1724 = tmpcur_2366 + + tmptag_2368; + GibCursor indr_1093[3] = {tmpcur_2360, tmpcur_2363, tmpcur_2366}; + GibCursorPtr3GibCursorPtr3Prod tmp_struct_55 = + _traverse_Tree(indr_1093, indr_1093); + GibCursor pvrtmp_2369[3]; + + memcpy(pvrtmp_2369, tmp_struct_55.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2370[3]; + + memcpy(pvrtmp_2370, tmp_struct_55.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_56; + + memcpy(return_56.field0, pvrtmp_2369, sizeof(GibCursor [3])); + memcpy(return_56.field1, pvrtmp_2370, sizeof(GibCursor [3])); + return return_56; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2339"); + exit(1); + } + } +} +GibCursorPtr3GibCursorPtr3Prod _print_Tree(GibCursor cursor_ptr_1732[3], + GibCursor arg_116_170_255[3]) +{ + GibCursor end_r_660 = cursor_ptr_1732[0]; + GibCursor end_r_661 = cursor_ptr_1732[1]; + GibCursor end_r_662 = cursor_ptr_1732[2]; + GibCursor dcon_1736 = arg_116_170_255[0]; + GibPackedTag tmpval_2372 = *(GibPackedTag *) dcon_1736; + GibCursor tmpcur_2373 = dcon_1736 + 1; + + + switch_2404: + ; + switch (tmpval_2372) { + + case 0: + { + GibCursor soa_field_0_1738 = arg_116_170_255[1]; + GibCursor soa_field_1_1739 = arg_116_170_255[2]; + GibInt tmpval_2374 = *(GibInt *) soa_field_0_1738; + GibCursor tmpcur_2375 = soa_field_0_1738 + sizeof(GibInt); + GibCursor loc_657 = arg_116_170_255[0]; + GibCursor jumpf_dloc_1002 = loc_657 + 1; + GibCursor loc_IntTy_658 = arg_116_170_255[1]; + GibCursor loc_IntTy_659 = arg_116_170_255[2]; + GibCursor jumpf_floc_loc_1003 = soa_field_0_1738 + 8; + GibCursor jumpf_floc_loc_1004 = loc_IntTy_659 + 0; + GibCursor cursor_ptr_1742[3] = {jumpf_dloc_1002, + jumpf_floc_loc_1003, + jumpf_floc_loc_1004}; + unsigned char wildcard_119_172_257 = gib_print_symbol(2093); + unsigned char wildcard_121_173_258 = gib_print_symbol(2096); + unsigned char y_118_174_259 = printf("%ld", tmpval_2374); + unsigned char wildcard_120_175_260 = gib_print_symbol(2091); + GibCursorPtr3GibCursorPtr3Prod return_60; + + memcpy(return_60.field0, cursor_ptr_1732, sizeof(GibCursor [3])); + memcpy(return_60.field1, cursor_ptr_1742, sizeof(GibCursor [3])); + return return_60; + break; + } + + case 1: + { + GibCursor soa_field_0_1744 = arg_116_170_255[1]; + GibCursor soa_field_1_1745 = arg_116_170_255[2]; + GibInt tmpval_2376 = *(GibInt *) soa_field_1_1745; + GibCursor tmpcur_2377 = soa_field_1_1745 + sizeof(GibInt); + GibCursor cursor_ptr_1735[3] = {tmpcur_2373, soa_field_0_1744, + tmpcur_2377}; + GibCursor loc_657 = arg_116_170_255[0]; + GibCursor jumpf_dloc_1006 = loc_657 + 1; + GibCursor loc_IntTy_658 = arg_116_170_255[1]; + GibCursor loc_IntTy_659 = arg_116_170_255[2]; + GibCursor jumpf_floc_loc_1008 = soa_field_1_1745 + 8; + GibCursor jumpf_floc_loc_1007 = loc_IntTy_658 + 0; + GibCursor loc_874 = jumpf_dloc_1006 + 0; + GibCursor loc_873 = jumpf_floc_loc_1008 + 0; + GibCursor loc_872 = jumpf_floc_loc_1007 + 0; + GibCursor cursor_ptr_1749[3] = {jumpf_dloc_1006, + jumpf_floc_loc_1007, + jumpf_floc_loc_1008}; + unsigned char wildcard_128_179_264 = gib_print_symbol(2092); + unsigned char wildcard_132_180_265 = gib_print_symbol(2096); + unsigned char y_125_181_266 = printf("%ld", tmpval_2376); + unsigned char wildcard_131_182_267 = gib_print_symbol(2096); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_61 = + _print_Tree(cursor_ptr_1732, cursor_ptr_1735); + GibCursor pvrtmp_2378[3]; + + memcpy(pvrtmp_2378, tmp_struct_61.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2379[3]; + + memcpy(pvrtmp_2379, tmp_struct_61.field1, sizeof(GibCursor [3])); + + unsigned char wildcard_130_184_269 = gib_print_symbol(2096); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_62 = + _print_Tree(pvrtmp_2378, pvrtmp_2379); + GibCursor pvrtmp_2380[3]; + + memcpy(pvrtmp_2380, tmp_struct_62.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2381[3]; + + memcpy(pvrtmp_2381, tmp_struct_62.field1, sizeof(GibCursor [3])); + + unsigned char wildcard_129_186_271 = gib_print_symbol(2091); + GibCursorPtr3GibCursorPtr3Prod return_63; + + memcpy(return_63.field0, pvrtmp_2380, sizeof(GibCursor [3])); + memcpy(return_63.field1, pvrtmp_2381, sizeof(GibCursor [3])); + return return_63; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1762 = arg_116_170_255[1]; + GibCursor soa_field_1_1763 = arg_116_170_255[2]; + uintptr_t tagged_tmpcur_68 = *(uintptr_t *) tmpcur_2373; + GibCursor tmpcur_2382 = GIB_UNTAG(tagged_tmpcur_68); + GibCursor tmpaftercur_2383 = tmpcur_2373 + 8; + uint16_t tmptag_2384 = GIB_GET_TAG(tagged_tmpcur_68); + GibCursor end_from_tagged_dcon_redir_1776 = tmpcur_2382 + + tmptag_2384; + GibCursor field_nxt_1773 = soa_field_0_1762 + 1; + uintptr_t tagged_tmpcur_67 = *(uintptr_t *) field_nxt_1773; + GibCursor tmpcur_2385 = GIB_UNTAG(tagged_tmpcur_67); + GibCursor tmpaftercur_2386 = field_nxt_1773 + 8; + uint16_t tmptag_2387 = GIB_GET_TAG(tagged_tmpcur_67); + GibCursor end_from_tagged_fld_redir_1777 = tmpcur_2385 + + tmptag_2387; + GibCursor field_nxt_1774 = soa_field_1_1763 + 1; + uintptr_t tagged_tmpcur_66 = *(uintptr_t *) field_nxt_1774; + GibCursor tmpcur_2388 = GIB_UNTAG(tagged_tmpcur_66); + GibCursor tmpaftercur_2389 = field_nxt_1774 + 8; + uint16_t tmptag_2390 = GIB_GET_TAG(tagged_tmpcur_66); + GibCursor end_from_tagged_fld_redir_1778 = tmpcur_2388 + + tmptag_2390; + GibCursor indr_1107[3] = {tmpcur_2382, tmpcur_2385, tmpcur_2388}; + GibCursor loc_657 = arg_116_170_255[0]; + GibCursor jump_dloc_1111 = loc_657 + 9; + GibCursor loc_IntTy_659 = arg_116_170_255[2]; + GibCursor loc_IntTy_658 = arg_116_170_255[1]; + GibCursor aft_indir_loc_1119 = loc_IntTy_658 + 9; + GibCursor aft_indir_loc_1120 = loc_IntTy_659 + 9; + GibCursor cursor_ptr_1779[3] = {jump_dloc_1111, aft_indir_loc_1119, + aft_indir_loc_1120}; + unsigned char wildcard_1118 = gib_print_symbol(2095); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_64 = + _print_Tree(indr_1107, indr_1107); + GibCursor pvrtmp_2391[3]; + + memcpy(pvrtmp_2391, tmp_struct_64.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2392[3]; + + memcpy(pvrtmp_2392, tmp_struct_64.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_65; + + memcpy(return_65.field0, cursor_ptr_1732, sizeof(GibCursor [3])); + memcpy(return_65.field1, cursor_ptr_1779, sizeof(GibCursor [3])); + return return_65; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1787 = arg_116_170_255[1]; + GibCursor soa_field_1_1788 = arg_116_170_255[2]; + uintptr_t tagged_tmpcur_73 = *(uintptr_t *) tmpcur_2373; + GibCursor tmpcur_2393 = GIB_UNTAG(tagged_tmpcur_73); + GibCursor tmpaftercur_2394 = tmpcur_2373 + 8; + uint16_t tmptag_2395 = GIB_GET_TAG(tagged_tmpcur_73); + GibCursor end_from_tagged_dcon_redir_1796 = tmpcur_2393 + + tmptag_2395; + GibCursor field_nxt_1794 = soa_field_0_1787 + 1; + uintptr_t tagged_tmpcur_72 = *(uintptr_t *) field_nxt_1794; + GibCursor tmpcur_2396 = GIB_UNTAG(tagged_tmpcur_72); + GibCursor tmpaftercur_2397 = field_nxt_1794 + 8; + uint16_t tmptag_2398 = GIB_GET_TAG(tagged_tmpcur_72); + GibCursor end_from_tagged_fld_redir_1797 = tmpcur_2396 + + tmptag_2398; + GibCursor field_nxt_1795 = soa_field_1_1788 + 1; + uintptr_t tagged_tmpcur_71 = *(uintptr_t *) field_nxt_1795; + GibCursor tmpcur_2399 = GIB_UNTAG(tagged_tmpcur_71); + GibCursor tmpaftercur_2400 = field_nxt_1795 + 8; + uint16_t tmptag_2401 = GIB_GET_TAG(tagged_tmpcur_71); + GibCursor end_from_tagged_fld_redir_1798 = tmpcur_2399 + + tmptag_2401; + GibCursor indr_1107[3] = {tmpcur_2393, tmpcur_2396, tmpcur_2399}; + unsigned char wildcard_1118 = gib_print_symbol(2094); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_69 = + _print_Tree(indr_1107, indr_1107); + GibCursor pvrtmp_2402[3]; + + memcpy(pvrtmp_2402, tmp_struct_69.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2403[3]; + + memcpy(pvrtmp_2403, tmp_struct_69.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_70; + + memcpy(return_70.field0, pvrtmp_2402, sizeof(GibCursor [3])); + memcpy(return_70.field1, pvrtmp_2403, sizeof(GibCursor [3])); + return return_70; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2372"); + exit(1); + } + } +} +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod _copy_without_ptrs_Tree(GibCursor cursor_ptr_1807[3], + GibCursor cursor_ptr_1806[3], + GibCursor cursor_ptr_1808[3], + GibCursor arg_98_187_272[3]) +{ + GibCursor end_r_669 = cursor_ptr_1807[0]; + GibCursor end_r_670 = cursor_ptr_1807[1]; + GibCursor end_r_671 = cursor_ptr_1807[2]; + GibCursor end_r_672 = cursor_ptr_1806[0]; + GibCursor end_r_673 = cursor_ptr_1806[1]; + GibCursor end_r_674 = cursor_ptr_1806[2]; + GibCursor dcon_1812 = arg_98_187_272[0]; + GibPackedTag tmpval_2405 = *(GibPackedTag *) dcon_1812; + GibCursor tmpcur_2406 = dcon_1812 + 1; + + + switch_2477: + ; + switch (tmpval_2405) { + + case 0: + { + GibCursor soa_field_0_1814 = arg_98_187_272[1]; + GibCursor soa_field_1_1815 = arg_98_187_272[2]; + GibInt tmpval_2407 = *(GibInt *) soa_field_0_1814; + GibCursor tmpcur_2408 = soa_field_0_1814 + sizeof(GibInt); + GibCursor loc_663 = arg_98_187_272[0]; + GibCursor jumpf_dloc_1016 = loc_663 + 1; + GibCursor loc_IntTy_664 = arg_98_187_272[1]; + GibCursor loc_IntTy_665 = arg_98_187_272[2]; + GibCursor jumpf_floc_loc_1017 = soa_field_0_1814 + 8; + GibCursor jumpf_floc_loc_1018 = loc_IntTy_665 + 0; + GibCursor cursor_ptr_1818[3] = {jumpf_dloc_1016, + jumpf_floc_loc_1017, + jumpf_floc_loc_1018}; + GibCursor loc_IntTy_668 = cursor_ptr_1808[2]; + GibCursor new_floc_loc_924 = loc_IntTy_668 + 8; + GibCursor loc_666 = cursor_ptr_1808[0]; + GibCursor new_dloc_922 = loc_666 + 1; + GibCursor loc_IntTy_667 = cursor_ptr_1808[1]; + + *(GibPackedTag *) loc_666 = 0; + + GibCursor writetag_1819 = loc_666 + 1; + GibCursor after_tag_1820 = loc_666 + 1; + + *(GibInt *) loc_IntTy_667 = tmpval_2407; + + GibCursor writecur_1824 = loc_IntTy_667 + sizeof(GibInt); + GibCursor aft_soa_loc_1826[3] = {after_tag_1820, writecur_1824, + loc_IntTy_668}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_74; + + memcpy(return_74.field0, cursor_ptr_1807, sizeof(GibCursor [3])); + memcpy(return_74.field1, cursor_ptr_1806, sizeof(GibCursor [3])); + memcpy(return_74.field2, cursor_ptr_1818, sizeof(GibCursor [3])); + memcpy(return_74.field3, cursor_ptr_1808, sizeof(GibCursor [3])); + memcpy(return_74.field4, aft_soa_loc_1826, sizeof(GibCursor [3])); + return return_74; + break; + } + + case 1: + { + GibCursor soa_field_0_1830 = arg_98_187_272[1]; + GibCursor soa_field_1_1831 = arg_98_187_272[2]; + GibInt tmpval_2413 = *(GibInt *) soa_field_1_1831; + GibCursor tmpcur_2414 = soa_field_1_1831 + sizeof(GibInt); + GibCursor cursor_ptr_1811[3] = {tmpcur_2406, soa_field_0_1830, + tmpcur_2414}; + GibCursor loc_663 = arg_98_187_272[0]; + GibCursor jumpf_dloc_1020 = loc_663 + 1; + GibCursor loc_IntTy_664 = arg_98_187_272[1]; + GibCursor loc_IntTy_665 = arg_98_187_272[2]; + GibCursor jumpf_floc_loc_1022 = soa_field_1_1831 + 8; + GibCursor jumpf_floc_loc_1021 = loc_IntTy_664 + 0; + GibCursor loc_899 = jumpf_dloc_1020 + 0; + GibCursor loc_898 = jumpf_floc_loc_1022 + 0; + GibCursor loc_897 = jumpf_floc_loc_1021 + 0; + GibCursor cursor_ptr_1835[3] = {jumpf_dloc_1020, + jumpf_floc_loc_1021, + jumpf_floc_loc_1022}; + GibCursor loc_IntTy_668 = cursor_ptr_1808[2]; + GibCursor new_floc_loc_924 = loc_IntTy_668 + 8; + GibCursor loc_666 = cursor_ptr_1808[0]; + GibCursor new_dloc_922 = loc_666 + 1; + GibCursor loc_IntTy_667 = cursor_ptr_1808[1]; + GibCursor cursor_ptr_1836[3] = {new_dloc_922, loc_IntTy_667, + new_floc_loc_924}; + + *(GibPackedTag *) loc_666 = 1; + + GibCursor writetag_1855 = loc_666 + 1; + GibCursor after_tag_1856 = loc_666 + 1; + + *(GibInt *) loc_IntTy_668 = tmpval_2413; + + GibCursor writecur_1860 = loc_IntTy_668 + sizeof(GibInt); + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_75 = + _copy_without_ptrs_Tree(cursor_ptr_1807, cursor_ptr_1806, cursor_ptr_1836, cursor_ptr_1811); + GibCursor pvrtmp_2415[3]; + + memcpy(pvrtmp_2415, tmp_struct_75.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2416[3]; + + memcpy(pvrtmp_2416, tmp_struct_75.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2417[3]; + + memcpy(pvrtmp_2417, tmp_struct_75.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2418[3]; + + memcpy(pvrtmp_2418, tmp_struct_75.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2419[3]; + + memcpy(pvrtmp_2419, tmp_struct_75.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_76 = + _copy_without_ptrs_Tree(pvrtmp_2415, pvrtmp_2416, pvrtmp_2419, pvrtmp_2417); + GibCursor pvrtmp_2424[3]; + + memcpy(pvrtmp_2424, tmp_struct_76.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2425[3]; + + memcpy(pvrtmp_2425, tmp_struct_76.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2426[3]; + + memcpy(pvrtmp_2426, tmp_struct_76.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2427[3]; + + memcpy(pvrtmp_2427, tmp_struct_76.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2428[3]; + + memcpy(pvrtmp_2428, tmp_struct_76.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_77; + + memcpy(return_77.field0, pvrtmp_2424, sizeof(GibCursor [3])); + memcpy(return_77.field1, pvrtmp_2425, sizeof(GibCursor [3])); + memcpy(return_77.field2, pvrtmp_2426, sizeof(GibCursor [3])); + memcpy(return_77.field3, cursor_ptr_1808, sizeof(GibCursor [3])); + memcpy(return_77.field4, pvrtmp_2428, sizeof(GibCursor [3])); + return return_77; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1868 = arg_98_187_272[1]; + GibCursor soa_field_1_1869 = arg_98_187_272[2]; + uintptr_t tagged_tmpcur_82 = *(uintptr_t *) tmpcur_2406; + GibCursor tmpcur_2437 = GIB_UNTAG(tagged_tmpcur_82); + GibCursor tmpaftercur_2438 = tmpcur_2406 + 8; + uint16_t tmptag_2439 = GIB_GET_TAG(tagged_tmpcur_82); + GibCursor end_from_tagged_dcon_redir_1882 = tmpcur_2437 + + tmptag_2439; + GibCursor field_nxt_1879 = soa_field_0_1868 + 1; + uintptr_t tagged_tmpcur_81 = *(uintptr_t *) field_nxt_1879; + GibCursor tmpcur_2440 = GIB_UNTAG(tagged_tmpcur_81); + GibCursor tmpaftercur_2441 = field_nxt_1879 + 8; + uint16_t tmptag_2442 = GIB_GET_TAG(tagged_tmpcur_81); + GibCursor end_from_tagged_fld_redir_1883 = tmpcur_2440 + + tmptag_2442; + GibCursor field_nxt_1880 = soa_field_1_1869 + 1; + uintptr_t tagged_tmpcur_80 = *(uintptr_t *) field_nxt_1880; + GibCursor tmpcur_2443 = GIB_UNTAG(tagged_tmpcur_80); + GibCursor tmpaftercur_2444 = field_nxt_1880 + 8; + uint16_t tmptag_2445 = GIB_GET_TAG(tagged_tmpcur_80); + GibCursor end_from_tagged_fld_redir_1884 = tmpcur_2443 + + tmptag_2445; + GibCursor indr_1121[3] = {tmpcur_2437, tmpcur_2440, tmpcur_2443}; + GibCursor loc_663 = arg_98_187_272[0]; + GibCursor jump_dloc_1125 = loc_663 + 9; + GibCursor loc_IntTy_665 = arg_98_187_272[2]; + GibCursor loc_IntTy_664 = arg_98_187_272[1]; + GibCursor aft_indir_loc_1133 = loc_IntTy_664 + 9; + GibCursor aft_indir_loc_1134 = loc_IntTy_665 + 9; + GibCursor cursor_ptr_1885[3] = {jump_dloc_1125, aft_indir_loc_1133, + aft_indir_loc_1134}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_78 = + _copy_without_ptrs_Tree(indr_1121, cursor_ptr_1806, cursor_ptr_1808, indr_1121); + GibCursor pvrtmp_2446[3]; + + memcpy(pvrtmp_2446, tmp_struct_78.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2447[3]; + + memcpy(pvrtmp_2447, tmp_struct_78.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2448[3]; + + memcpy(pvrtmp_2448, tmp_struct_78.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2449[3]; + + memcpy(pvrtmp_2449, tmp_struct_78.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2450[3]; + + memcpy(pvrtmp_2450, tmp_struct_78.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_79; + + memcpy(return_79.field0, cursor_ptr_1807, sizeof(GibCursor [3])); + memcpy(return_79.field1, pvrtmp_2447, sizeof(GibCursor [3])); + memcpy(return_79.field2, cursor_ptr_1885, sizeof(GibCursor [3])); + memcpy(return_79.field3, pvrtmp_2449, sizeof(GibCursor [3])); + memcpy(return_79.field4, pvrtmp_2450, sizeof(GibCursor [3])); + return return_79; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1896 = arg_98_187_272[1]; + GibCursor soa_field_1_1897 = arg_98_187_272[2]; + uintptr_t tagged_tmpcur_87 = *(uintptr_t *) tmpcur_2406; + GibCursor tmpcur_2457 = GIB_UNTAG(tagged_tmpcur_87); + GibCursor tmpaftercur_2458 = tmpcur_2406 + 8; + uint16_t tmptag_2459 = GIB_GET_TAG(tagged_tmpcur_87); + GibCursor end_from_tagged_dcon_redir_1905 = tmpcur_2457 + + tmptag_2459; + GibCursor field_nxt_1903 = soa_field_0_1896 + 1; + uintptr_t tagged_tmpcur_86 = *(uintptr_t *) field_nxt_1903; + GibCursor tmpcur_2460 = GIB_UNTAG(tagged_tmpcur_86); + GibCursor tmpaftercur_2461 = field_nxt_1903 + 8; + uint16_t tmptag_2462 = GIB_GET_TAG(tagged_tmpcur_86); + GibCursor end_from_tagged_fld_redir_1906 = tmpcur_2460 + + tmptag_2462; + GibCursor field_nxt_1904 = soa_field_1_1897 + 1; + uintptr_t tagged_tmpcur_85 = *(uintptr_t *) field_nxt_1904; + GibCursor tmpcur_2463 = GIB_UNTAG(tagged_tmpcur_85); + GibCursor tmpaftercur_2464 = field_nxt_1904 + 8; + uint16_t tmptag_2465 = GIB_GET_TAG(tagged_tmpcur_85); + GibCursor end_from_tagged_fld_redir_1907 = tmpcur_2463 + + tmptag_2465; + GibCursor indr_1121[3] = {tmpcur_2457, tmpcur_2460, tmpcur_2463}; + GibCursor loc_666 = cursor_ptr_1808[0]; + GibCursor loc_IntTy_667 = cursor_ptr_1808[1]; + GibCursor loc_IntTy_668 = cursor_ptr_1808[2]; + GibCursor copy_dloc_1135 = loc_666 + 0; + GibCursor copy_floc_loc_1137 = loc_IntTy_668 + 0; + GibCursor copy_floc_loc_1136 = loc_IntTy_667 + 0; + GibCursor cursor_ptr_1908[3] = {copy_dloc_1135, copy_floc_loc_1136, + copy_floc_loc_1137}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_83 = + _copy_without_ptrs_Tree(indr_1121, cursor_ptr_1806, cursor_ptr_1908, indr_1121); + GibCursor pvrtmp_2466[3]; + + memcpy(pvrtmp_2466, tmp_struct_83.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2467[3]; + + memcpy(pvrtmp_2467, tmp_struct_83.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2468[3]; + + memcpy(pvrtmp_2468, tmp_struct_83.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2469[3]; + + memcpy(pvrtmp_2469, tmp_struct_83.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2470[3]; + + memcpy(pvrtmp_2470, tmp_struct_83.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_84; + + memcpy(return_84.field0, pvrtmp_2466, sizeof(GibCursor [3])); + memcpy(return_84.field1, pvrtmp_2467, sizeof(GibCursor [3])); + memcpy(return_84.field2, pvrtmp_2468, sizeof(GibCursor [3])); + memcpy(return_84.field3, pvrtmp_2469, sizeof(GibCursor [3])); + memcpy(return_84.field4, pvrtmp_2470, sizeof(GibCursor [3])); + return return_84; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2405"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_101 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_2097 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_705 = region_2097.start; + GibCursor end_r_705 = region_2097.end; + GibChunk region_2098 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_706 = region_2098.start; + GibCursor end_r_706 = region_2098.end; + GibChunk region_2099 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_707 = region_2099.start; + GibCursor end_r_707 = region_2099.end; + GibCursor reg_ptr_1918[3] = {r_705, r_706, r_707}; + GibCursor reg_cursor_ptr_1919[3] = {end_r_705, end_r_706, end_r_707}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod tmp_struct_88 = + mkTree(reg_cursor_ptr_1919, reg_ptr_1918, 23, 0); + GibCursor pvrtmp_2100[3]; + + memcpy(pvrtmp_2100, tmp_struct_88.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2101[3]; + + memcpy(pvrtmp_2101, tmp_struct_88.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2102[3]; + + memcpy(pvrtmp_2102, tmp_struct_88.field2, sizeof(GibCursor [3])); + + GibChunk region_2107 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_702 = region_2107.start; + GibCursor end_r_702 = region_2107.end; + GibChunk region_2108 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_703 = region_2108.start; + GibCursor end_r_703 = region_2108.end; + GibChunk region_2109 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_704 = region_2109.start; + GibCursor end_r_704 = region_2109.end; + GibCursor reg_ptr_1925[3] = {r_702, r_703, r_704}; + GibCursor reg_cursor_ptr_1926[3] = {end_r_702, end_r_703, end_r_704}; + GibCursor pvrtmp_2121[3]; + GibCursor pvrtmp_2122[3]; + GibCursor pvrtmp_2123[3]; + GibVector *times_93 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_2121; + struct timespec end_pvrtmp_2121; + + for (long long iters_pvrtmp_2121 = 0; iters_pvrtmp_2121 < + gib_get_iters_param(); iters_pvrtmp_2121++) { + if (iters_pvrtmp_2121 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_2121); + + // GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + // tmp_struct_89; + + add1Tree(pvrtmp_2100, reg_cursor_ptr_1926, reg_ptr_1925, pvrtmp_2101); + +// GibCursor pvrtmp_2110[3]; +// +// memcpy(pvrtmp_2110, tmp_struct_89.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2111[3]; +// +// memcpy(pvrtmp_2111, tmp_struct_89.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2112[3]; +// +// memcpy(pvrtmp_2112, tmp_struct_89.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2113[3]; +// +// memcpy(pvrtmp_2113, tmp_struct_89.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2114[3]; +// +// memcpy(pvrtmp_2114, tmp_struct_89.field4, sizeof(GibCursor [3])); +// memcpy(pvrtmp_2121, pvrtmp_2111, sizeof(GibCursor [3])); +// memcpy(pvrtmp_2122, pvrtmp_2113, sizeof(GibCursor [3])); +// memcpy(pvrtmp_2123, pvrtmp_2114, sizeof(GibCursor [3])); + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_2121); + if (iters_pvrtmp_2121 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + + memcpy(pvrtmp_2100, tmp_struct_88.field0, sizeof(GibCursor [3])); + + memcpy(pvrtmp_2101, tmp_struct_88.field1, sizeof(GibCursor [3])); + + + reg_cursor_ptr_1926[0] = end_r_702; + reg_cursor_ptr_1926[1] = end_r_703; + reg_cursor_ptr_1926[2] = end_r_704; + + reg_ptr_1925[0] = r_702; + reg_ptr_1925[1] = r_703; + reg_ptr_1925[2] = r_704; + + memcpy(pvrtmp_2122, reg_ptr_1925, sizeof(GibCursor [3])); + + + double itertime_90 = gib_difftimespecs(&begin_pvrtmp_2121, + &end_pvrtmp_2121); + + printf("itertime: %lf\n", itertime_90); + gib_vector_inplace_update(times_93, iters_pvrtmp_2121, &itertime_90); + } + gib_vector_inplace_sort(times_93, gib_compare_doubles); + + double *tmp_94 = (double *) gib_vector_nth(times_93, gib_get_iters_param() / + 2); + double selftimed_92 = *tmp_94; + double batchtime_91 = gib_sum_timing_array(times_93); + + gib_print_timing_array(times_93); + gib_vector_free(times_93); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_91); + printf("SELFTIMED: %e\n", selftimed_92); + + GibInt timed_1992; + GibVector *times_99 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_1992; + struct timespec end_timed_1992; + + for (long long iters_timed_1992 = 0; iters_timed_1992 < + gib_get_iters_param(); iters_timed_1992++) { + if (iters_timed_1992 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_1992); + + GibInt Res = 0; + sumTree(reg_cursor_ptr_1926, pvrtmp_2122, &Res); + + // GibCursor pvrtmp_2131[3]; + + // memcpy(pvrtmp_2131, tmp_struct_95.field0, sizeof(GibCursor [3])); + + // GibCursor pvrtmp_2132[3]; + + // memcpy(pvrtmp_2132, tmp_struct_95.field1, sizeof(GibCursor [3])); + + // GibInt pvrtmp_2133 = tmp_struct_95.field2; + + timed_1992 = Res; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_1992); + if (iters_timed_1992 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + reg_cursor_ptr_1926[0] = end_r_702; + reg_cursor_ptr_1926[1] = end_r_703; + reg_cursor_ptr_1926[2] = end_r_704; + + memcpy(pvrtmp_2122, reg_ptr_1925, sizeof(GibCursor [3])); + + Res = 0; + + double itertime_96 = gib_difftimespecs(&begin_timed_1992, + &end_timed_1992); + + printf("itertime: %lf\n", itertime_96); + gib_vector_inplace_update(times_99, iters_timed_1992, &itertime_96); + } + gib_vector_inplace_sort(times_99, gib_compare_doubles); + + double *tmp_100 = (double *) gib_vector_nth(times_99, + gib_get_iters_param() / 2); + double selftimed_98 = *tmp_100; + double batchtime_97 = gib_sum_timing_array(times_99); + + gib_print_timing_array(times_99); + gib_vector_free(times_99); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_97); + printf("SELFTIMED: %e\n", selftimed_98); + printf("%ld", timed_1992); + printf("\n"); + + int exit_102 = gib_exit(); + + return exit_102; +} + + +// gcc -std=gnu11 -O3 -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + +// gcc -std=gnu11 -g -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + diff --git a/microbench/manual_soa_examples/MonoTree.soa.reurns.c b/microbench/manual_soa_examples/MonoTree.soa.reurns.c new file mode 100644 index 000000000..69e275f02 --- /dev/null +++ b/microbench/manual_soa_examples/MonoTree.soa.reurns.c @@ -0,0 +1,1994 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorPtr3Prod_struct { + GibCursor field0[3]; + } GibCursorPtr3Prod; +typedef struct GibCursorPtr3GibCursorPtr3Prod_struct { + GibCursor field0[3]; + GibCursor field1[3]; + } GibCursorPtr3GibCursorPtr3Prod; +typedef struct GibCursorPtr3GibCursorPtr3GibIntProd_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibInt field2; + } GibCursorPtr3GibCursorPtr3GibIntProd; +typedef struct GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibCursor field2[3]; + } GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod; +typedef struct GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod_struct { + GibCursor field0[3]; + GibCursor field1[3]; + GibCursor field2[3]; + GibCursor field3[3]; + GibCursor field4[3]; + } GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod; + + +void add1Tree(GibCursor cursor_ptr_1322[3], GibCursor cursor_ptr_1321[3], + GibCursor cursor_ptr_1323[3], GibCursor t_31_136_213[3], + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod *Ret + ); + +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +_copy_Tree(GibCursor cursor_ptr_1436[3], GibCursor cursor_ptr_1435[3], + GibCursor cursor_ptr_1437[3], GibCursor arg_89_141_222[3]); +GibCursorPtr3GibCursorPtr3GibIntProd sumTree(GibCursor cursor_ptr_1549[3], + GibCursor tr_36_150_231[3]); +GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod mkTree(GibCursor cursor_ptr_1622[3], + GibCursor cursor_ptr_1623[3], + GibInt d_41_155_239, + GibInt acc_42_156_240); +GibCursorPtr3GibCursorPtr3Prod _traverse_Tree(GibCursor cursor_ptr_1658[3], + GibCursor arg_107_163_248[3]); +GibCursorPtr3GibCursorPtr3Prod _print_Tree(GibCursor cursor_ptr_1732[3], + GibCursor arg_116_170_255[3]); +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +_copy_without_ptrs_Tree(GibCursor cursor_ptr_1807[3], + GibCursor cursor_ptr_1806[3], + GibCursor cursor_ptr_1808[3], + GibCursor arg_98_187_272[3]); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + Tree_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[3]; + + error = gib_info_table_insert_packed_dcon(Tree_T, 0, 8, 0, 1, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 0); + exit(1); + } + field_tys[0] = Tree_T; + field_tys[1] = Tree_T; + error = gib_info_table_insert_packed_dcon(Tree_T, 1, 8, 0, 1, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, Tree_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(2091, ")"); + gib_add_symbol(2092, "(Node"); + gib_add_symbol(2093, "(Leaf"); + gib_add_symbol(2094, " ->r "); + gib_add_symbol(2095, " ->i "); + gib_add_symbol(2096, " "); +} +void add1Tree(GibCursor cursor_ptr_1322[3], + GibCursor cursor_ptr_1321[3], + GibCursor cursor_ptr_1323[3], + GibCursor t_31_136_213[3], + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod *Ret + ) +{ + GibCursor *end_r_625 = &cursor_ptr_1321[1]; + GibCursor *end_r_626 = &cursor_ptr_1321[2]; + GibCursor *end_r_624 = &cursor_ptr_1321[0]; + + GibCursor *loc_IntTy_619 = &cursor_ptr_1323[1]; + GibCursor *loc_IntTy_620 = &cursor_ptr_1323[2]; + GibCursor *loc_618 = &cursor_ptr_1323[0]; + + if (*loc_IntTy_620 + 17 > *end_r_626 || + (*loc_IntTy_619 + 17 > *end_r_625 || + *loc_618 + 34 > *end_r_624)) { + gib_grow_region(loc_IntTy_620, end_r_626); + gib_grow_region(loc_IntTy_619, end_r_625); + gib_grow_region(loc_618, end_r_624); + } + + // GibCursor end_r_621 = cursor_ptr_1322[0]; + // GibCursor end_r_622 = cursor_ptr_1322[1]; + // GibCursor end_r_623 = cursor_ptr_1322[2]; + + //GibCursor overwrite_reg_1324[3] = {end_r_624, end_r_625, end_r_626}; + GibCursor *dcon_1328 = &t_31_136_213[0]; + GibPackedTag tmpval_2134 = *(GibPackedTag *) (*dcon_1328); + //GibCursor tmpcur_2135 = dcon_1328 + 1; + *dcon_1328 += 1; + + + switch_2206: + ; + switch (tmpval_2134) { + + case 0: + { + GibCursor *soa_field_0_1330 = &t_31_136_213[1]; + //GibCursor *soa_field_1_1331 = &t_31_136_213[2]; + + GibInt tmpval_2136 = *(GibInt *) *soa_field_0_1330; + + //GibCursor tmpcur_2137 = soa_field_0_1330 + sizeof(GibInt); + + //GibCursor *loc_615 = &t_31_136_213[0]; + + //GibCursor jumpf_dloc_945 = loc_615 + 1; + //*loc_615 += 1; + + // GibCursor *loc_IntTy_616 = &t_31_136_213[1]; + GibCursor *loc_IntTy_617 = &t_31_136_213[2]; + + //GibCursor jumpf_floc_loc_946 = soa_field_0_1330 + 8; + *soa_field_0_1330 += 8; + + //GibCursor jumpf_floc_loc_947 = loc_IntTy_617 + 0; + + // GibCursor cursor_ptr_1334[3] = {jumpf_dloc_945, jumpf_floc_loc_946, + // jumpf_floc_loc_947}; + + GibInt fltPkd_196_215 = tmpval_2136 + 1; + //GibCursor new_dloc_740 = loc_618 + 1; + //GibCursor new_floc_loc_742 = loc_IntTy_620 + 8; + + *(GibPackedTag *) *loc_618 = 0; + + //GibCursor writetag_1335 = loc_618 + 1; + //GibCursor after_tag_1336 = loc_618 + 1; + *loc_618 += 1; + + *(GibInt *) *loc_IntTy_619 = fltPkd_196_215; + + //GibCursor writecur_1340 = loc_IntTy_619 + sizeof(GibInt); + *loc_IntTy_619 += sizeof(GibInt); + + // GibCursor aft_soa_loc_1342[3] = {after_tag_1336, writecur_1340, + // loc_IntTy_620}; + + // GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + // return_0; + + memcpy(Ret->field0, cursor_ptr_1322, sizeof(GibCursor [3])); + memcpy(Ret->field1, cursor_ptr_1321, sizeof(GibCursor [3])); + memcpy(Ret->field2, t_31_136_213, sizeof(GibCursor [3])); + //memcpy(Ret->field3, cursor_ptr_1323, sizeof(GibCursor [3])); + memcpy(Ret->field4, cursor_ptr_1323, sizeof(GibCursor [3])); + //return return_0; + break; + } + + case 1: + { + //GibCursor *soa_field_0_1346 = &t_31_136_213[1]; + GibCursor *soa_field_1_1347 = &t_31_136_213[2]; + + GibInt tmpval_2142 = *(GibInt *) *soa_field_1_1347; + + //GibCursor tmpcur_2143 = soa_field_1_1347 + sizeof(GibInt); + *soa_field_1_1347 += sizeof(GibInt); + + + // GibCursor cursor_ptr_1327[3] = {tmpcur_2135, soa_field_0_1346, + // tmpcur_2143}; + + //GibCursor *loc_615 = &t_31_136_213[0]; + + //GibCursor jumpf_dloc_949 = loc_615 + 1; + //*loc_615 += 1; + + // GibCursor *loc_IntTy_616 = &t_31_136_213[1]; + // GibCursor *loc_IntTy_617 = &t_31_136_213[2]; + + //GibCursor jumpf_floc_loc_951 = soa_field_1_1347 + 8; + //*soa_field_1_1347 += 8; + + //GibCursor jumpf_floc_loc_950 = loc_IntTy_616 + 0; + + // GibCursor loc_717 = jumpf_dloc_949 + 0; + // GibCursor loc_716 = jumpf_floc_loc_951 + 0; + // GibCursor loc_715 = jumpf_floc_loc_950 + 0; + // GibCursor cursor_ptr_1351[3] = {jumpf_dloc_949, jumpf_floc_loc_950, + // jumpf_floc_loc_951}; + GibInt fltPkd_197_219 = tmpval_2142 + 1; + + //GibCursor new_dloc_740 = loc_618 + 1; + + //GibCursor new_floc_loc_742 = loc_IntTy_620 + 8; + // GibCursor cursor_ptr_1352[3] = {new_dloc_740, loc_IntTy_619, + // new_floc_loc_742}; + + *(GibPackedTag *) *loc_618 = 1; + *loc_618 += 1; + + // GibCursor writetag_1371 = loc_618 + 1; + // GibCursor after_tag_1372 = loc_618 + 1; + + *(GibInt *) *loc_IntTy_620 = fltPkd_197_219; + + *loc_IntTy_620 += 8; + + add1Tree(cursor_ptr_1322, cursor_ptr_1321, cursor_ptr_1323, t_31_136_213, Ret); + + // GibCursor pvrtmp_2144[3]; + +// memcpy(pvrtmp_2144, tmp_struct_1.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2145[3]; +// +// memcpy(pvrtmp_2145, tmp_struct_1.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2146[3]; +// +// memcpy(pvrtmp_2146, tmp_struct_1.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2147[3]; +// +// memcpy(pvrtmp_2147, tmp_struct_1.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2148[3]; +// +// memcpy(pvrtmp_2148, tmp_struct_1.field4, sizeof(GibCursor [3])); + + add1Tree(cursor_ptr_1322, cursor_ptr_1321, cursor_ptr_1323, t_31_136_213, Ret); + +// GibCursor pvrtmp_2153[3]; +// +// memcpy(pvrtmp_2153, tmp_struct_2.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2154[3]; +// +// memcpy(pvrtmp_2154, tmp_struct_2.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2155[3]; +// +// memcpy(pvrtmp_2155, tmp_struct_2.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2156[3]; +// +// memcpy(pvrtmp_2156, tmp_struct_2.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2157[3]; +// +// memcpy(pvrtmp_2157, tmp_struct_2.field4, sizeof(GibCursor [3])); +// +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// return_3; + + // memcpy(return_3.field0, pvrtmp_2153, sizeof(GibCursor [3])); + // memcpy(return_3.field1, pvrtmp_2154, sizeof(GibCursor [3])); + // memcpy(return_3.field2, pvrtmp_2155, sizeof(GibCursor [3])); + // memcpy(return_3.field3, cursor_ptr_1323, sizeof(GibCursor [3])); + // memcpy(return_3.field4, pvrtmp_2157, sizeof(GibCursor [3])); + // return return_3; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// GibCursor soa_field_0_1384 = t_31_136_213[1]; +// GibCursor soa_field_1_1385 = t_31_136_213[2]; +// uintptr_t tagged_tmpcur_8 = *(uintptr_t *) tmpcur_2135; +// GibCursor tmpcur_2166 = GIB_UNTAG(tagged_tmpcur_8); +// GibCursor tmpaftercur_2167 = tmpcur_2135 + 8; +// uint16_t tmptag_2168 = GIB_GET_TAG(tagged_tmpcur_8); +// GibCursor end_from_tagged_dcon_redir_1398 = tmpcur_2166 + +// tmptag_2168; +// GibCursor field_nxt_1395 = soa_field_0_1384 + 1; +// uintptr_t tagged_tmpcur_7 = *(uintptr_t *) field_nxt_1395; +// GibCursor tmpcur_2169 = GIB_UNTAG(tagged_tmpcur_7); +// GibCursor tmpaftercur_2170 = field_nxt_1395 + 8; +// uint16_t tmptag_2171 = GIB_GET_TAG(tagged_tmpcur_7); +// GibCursor end_from_tagged_fld_redir_1399 = tmpcur_2169 + +// tmptag_2171; +// GibCursor field_nxt_1396 = soa_field_1_1385 + 1; +// uintptr_t tagged_tmpcur_6 = *(uintptr_t *) field_nxt_1396; +// GibCursor tmpcur_2172 = GIB_UNTAG(tagged_tmpcur_6); +// GibCursor tmpaftercur_2173 = field_nxt_1396 + 8; +// uint16_t tmptag_2174 = GIB_GET_TAG(tagged_tmpcur_6); +// GibCursor end_from_tagged_fld_redir_1400 = tmpcur_2172 + +// tmptag_2174; +// GibCursor indr_1045[3] = {tmpcur_2166, tmpcur_2169, tmpcur_2172}; +// GibCursor loc_615 = t_31_136_213[0]; +// GibCursor jump_dloc_1049 = loc_615 + 9; +// GibCursor loc_IntTy_617 = t_31_136_213[2]; +// GibCursor loc_IntTy_616 = t_31_136_213[1]; +// GibCursor aft_indir_loc_1057 = loc_IntTy_616 + 9; +// GibCursor aft_indir_loc_1058 = loc_IntTy_617 + 9; +// GibCursor cursor_ptr_1401[3] = {jump_dloc_1049, aft_indir_loc_1057, +// aft_indir_loc_1058}; +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// tmp_struct_4 = +// add1Tree(indr_1045, overwrite_reg_1324, cursor_ptr_1323, indr_1045); +// GibCursor pvrtmp_2175[3]; +// +// memcpy(pvrtmp_2175, tmp_struct_4.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2176[3]; +// +// memcpy(pvrtmp_2176, tmp_struct_4.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2177[3]; +// +// memcpy(pvrtmp_2177, tmp_struct_4.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2178[3]; +// +// memcpy(pvrtmp_2178, tmp_struct_4.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2179[3]; +// +// memcpy(pvrtmp_2179, tmp_struct_4.field4, sizeof(GibCursor [3])); +// +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// return_5; +// +// memcpy(return_5.field0, cursor_ptr_1322, sizeof(GibCursor [3])); +// memcpy(return_5.field1, pvrtmp_2176, sizeof(GibCursor [3])); +// memcpy(return_5.field2, cursor_ptr_1401, sizeof(GibCursor [3])); +// memcpy(return_5.field3, pvrtmp_2178, sizeof(GibCursor [3])); +// memcpy(return_5.field4, pvrtmp_2179, sizeof(GibCursor [3])); +// return return_5; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + GibCursor *soa_field_0_1412 = &t_31_136_213[1]; + GibCursor *soa_field_1_1413 = &t_31_136_213[2]; + + uintptr_t tagged_tmpcur_13 = *(uintptr_t *) (*dcon_1328); + GibCursor tmpcur_2186 = GIB_UNTAG(tagged_tmpcur_13); + *dcon_1328 = tmpcur_2186; + + // GibCursor tmpaftercur_2187 = tmpcur_2135 + 8; + // uint16_t tmptag_2188 = GIB_GET_TAG(tagged_tmpcur_13); + // GibCursor end_from_tagged_dcon_redir_1421 = tmpcur_2186 + + // tmptag_2188; + + GibCursor field_nxt_1419 = *soa_field_0_1412 + 1; + uintptr_t tagged_tmpcur_12 = *(uintptr_t *) field_nxt_1419; + GibCursor tmpcur_2189 = GIB_UNTAG(tagged_tmpcur_12); + *soa_field_0_1412 = tmpcur_2189; + + // GibCursor tmpaftercur_2190 = field_nxt_1419 + 8; + // uint16_t tmptag_2191 = GIB_GET_TAG(tagged_tmpcur_12); + // GibCursor end_from_tagged_fld_redir_1422 = tmpcur_2189 + + // tmptag_2191; + + GibCursor field_nxt_1420 = *soa_field_1_1413 + 1; + uintptr_t tagged_tmpcur_11 = *(uintptr_t *) field_nxt_1420; + GibCursor tmpcur_2192 = GIB_UNTAG(tagged_tmpcur_11); + *soa_field_1_1413 = tmpcur_2192; + + + // GibCursor tmpaftercur_2193 = field_nxt_1420 + 8; + // uint16_t tmptag_2194 = GIB_GET_TAG(tagged_tmpcur_11); + // GibCursor end_from_tagged_fld_redir_1423 = tmpcur_2192 + + // tmptag_2194; + + // GibCursor indr_1045[3] = {tmpcur_2186, tmpcur_2189, tmpcur_2192}; + + // GibCursor copy_dloc_1059 = loc_618 + 0; + // GibCursor copy_floc_loc_1061 = loc_IntTy_620 + 0; + // GibCursor copy_floc_loc_1060 = loc_IntTy_619 + 0; + // GibCursor cursor_ptr_1424[3] = {copy_dloc_1059, copy_floc_loc_1060, + // copy_floc_loc_1061}; + + add1Tree(t_31_136_213, cursor_ptr_1321, cursor_ptr_1323, t_31_136_213, Ret); + + +// GibCursor pvrtmp_2195[3]; +// +// memcpy(pvrtmp_2195, tmp_struct_9.field0, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2196[3]; +// +// memcpy(pvrtmp_2196, tmp_struct_9.field1, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2197[3]; +// +// memcpy(pvrtmp_2197, tmp_struct_9.field2, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2198[3]; +// +// memcpy(pvrtmp_2198, tmp_struct_9.field3, sizeof(GibCursor [3])); +// +// GibCursor pvrtmp_2199[3]; +// +// memcpy(pvrtmp_2199, tmp_struct_9.field4, sizeof(GibCursor [3])); +// +// GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod +// return_10; +// +// memcpy(return_10.field0, pvrtmp_2195, sizeof(GibCursor [3])); +// memcpy(return_10.field1, pvrtmp_2196, sizeof(GibCursor [3])); +// memcpy(return_10.field2, pvrtmp_2197, sizeof(GibCursor [3])); +// memcpy(return_10.field3, pvrtmp_2198, sizeof(GibCursor [3])); +// memcpy(return_10.field4, pvrtmp_2199, sizeof(GibCursor [3])); +// return return_10; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2134"); + exit(1); + } + } +} + +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod _copy_Tree(GibCursor cursor_ptr_1436[3], + GibCursor cursor_ptr_1435[3], + GibCursor cursor_ptr_1437[3], + GibCursor arg_89_141_222[3]) +{ + GibCursor end_r_636 = cursor_ptr_1435[0]; + GibCursor end_r_637 = cursor_ptr_1435[1]; + GibCursor end_r_638 = cursor_ptr_1435[2]; + GibCursor loc_IntTy_631 = cursor_ptr_1437[1]; + GibCursor loc_IntTy_632 = cursor_ptr_1437[2]; + GibCursor loc_630 = cursor_ptr_1437[0]; + + if (loc_IntTy_632 + 17 > end_r_638 || (loc_IntTy_631 + 17 > end_r_637 || + loc_630 + 34 > end_r_636)) { + gib_grow_region(&loc_IntTy_632, &end_r_638); + gib_grow_region(&loc_IntTy_631, &end_r_637); + gib_grow_region(&loc_630, &end_r_636); + } + + GibCursor end_r_633 = cursor_ptr_1436[0]; + GibCursor end_r_634 = cursor_ptr_1436[1]; + GibCursor end_r_635 = cursor_ptr_1436[2]; + GibCursor overwrite_reg_1438[3] = {end_r_636, end_r_637, end_r_638}; + GibCursor dcon_1442 = arg_89_141_222[0]; + GibPackedTag tmpval_2207 = *(GibPackedTag *) dcon_1442; + GibCursor tmpcur_2208 = dcon_1442 + 1; + + + switch_2279: + ; + switch (tmpval_2207) { + + case 0: + { + GibCursor soa_field_0_1444 = arg_89_141_222[1]; + GibCursor soa_field_1_1445 = arg_89_141_222[2]; + GibInt tmpval_2209 = *(GibInt *) soa_field_0_1444; + GibCursor tmpcur_2210 = soa_field_0_1444 + sizeof(GibInt); + GibCursor loc_627 = arg_89_141_222[0]; + GibCursor jumpf_dloc_959 = loc_627 + 1; + GibCursor loc_IntTy_628 = arg_89_141_222[1]; + GibCursor loc_IntTy_629 = arg_89_141_222[2]; + GibCursor jumpf_floc_loc_960 = soa_field_0_1444 + 8; + GibCursor jumpf_floc_loc_961 = loc_IntTy_629 + 0; + GibCursor cursor_ptr_1448[3] = {jumpf_dloc_959, jumpf_floc_loc_960, + jumpf_floc_loc_961}; + GibCursor new_floc_loc_788 = loc_IntTy_632 + 8; + GibCursor new_dloc_786 = loc_630 + 1; + + *(GibPackedTag *) loc_630 = 0; + + GibCursor writetag_1449 = loc_630 + 1; + GibCursor after_tag_1450 = loc_630 + 1; + + *(GibInt *) loc_IntTy_631 = tmpval_2209; + + GibCursor writecur_1454 = loc_IntTy_631 + sizeof(GibInt); + GibCursor aft_soa_loc_1456[3] = {after_tag_1450, writecur_1454, + loc_IntTy_632}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_14; + + memcpy(return_14.field0, cursor_ptr_1436, sizeof(GibCursor [3])); + memcpy(return_14.field1, overwrite_reg_1438, sizeof(GibCursor [3])); + memcpy(return_14.field2, cursor_ptr_1448, sizeof(GibCursor [3])); + memcpy(return_14.field3, cursor_ptr_1437, sizeof(GibCursor [3])); + memcpy(return_14.field4, aft_soa_loc_1456, sizeof(GibCursor [3])); + return return_14; + break; + } + + case 1: + { + GibCursor soa_field_0_1460 = arg_89_141_222[1]; + GibCursor soa_field_1_1461 = arg_89_141_222[2]; + GibInt tmpval_2215 = *(GibInt *) soa_field_1_1461; + GibCursor tmpcur_2216 = soa_field_1_1461 + sizeof(GibInt); + GibCursor cursor_ptr_1441[3] = {tmpcur_2208, soa_field_0_1460, + tmpcur_2216}; + GibCursor loc_627 = arg_89_141_222[0]; + GibCursor jumpf_dloc_963 = loc_627 + 1; + GibCursor loc_IntTy_628 = arg_89_141_222[1]; + GibCursor loc_IntTy_629 = arg_89_141_222[2]; + GibCursor jumpf_floc_loc_965 = soa_field_1_1461 + 8; + GibCursor jumpf_floc_loc_964 = loc_IntTy_628 + 0; + GibCursor loc_763 = jumpf_dloc_963 + 0; + GibCursor loc_762 = jumpf_floc_loc_965 + 0; + GibCursor loc_761 = jumpf_floc_loc_964 + 0; + GibCursor cursor_ptr_1465[3] = {jumpf_dloc_963, jumpf_floc_loc_964, + jumpf_floc_loc_965}; + GibCursor new_floc_loc_788 = loc_IntTy_632 + 8; + GibCursor new_dloc_786 = loc_630 + 1; + GibCursor cursor_ptr_1466[3] = {new_dloc_786, loc_IntTy_631, + new_floc_loc_788}; + + *(GibPackedTag *) loc_630 = 1; + + GibCursor writetag_1485 = loc_630 + 1; + GibCursor after_tag_1486 = loc_630 + 1; + + *(GibInt *) loc_IntTy_632 = tmpval_2215; + + GibCursor writecur_1490 = loc_IntTy_632 + sizeof(GibInt); + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_15 = + _copy_Tree(cursor_ptr_1436, overwrite_reg_1438, cursor_ptr_1466, cursor_ptr_1441); + GibCursor pvrtmp_2217[3]; + + memcpy(pvrtmp_2217, tmp_struct_15.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2218[3]; + + memcpy(pvrtmp_2218, tmp_struct_15.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2219[3]; + + memcpy(pvrtmp_2219, tmp_struct_15.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2220[3]; + + memcpy(pvrtmp_2220, tmp_struct_15.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2221[3]; + + memcpy(pvrtmp_2221, tmp_struct_15.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_16 = + _copy_Tree(pvrtmp_2217, pvrtmp_2218, pvrtmp_2221, pvrtmp_2219); + GibCursor pvrtmp_2226[3]; + + memcpy(pvrtmp_2226, tmp_struct_16.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2227[3]; + + memcpy(pvrtmp_2227, tmp_struct_16.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2228[3]; + + memcpy(pvrtmp_2228, tmp_struct_16.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2229[3]; + + memcpy(pvrtmp_2229, tmp_struct_16.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2230[3]; + + memcpy(pvrtmp_2230, tmp_struct_16.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_17; + + memcpy(return_17.field0, pvrtmp_2226, sizeof(GibCursor [3])); + memcpy(return_17.field1, pvrtmp_2227, sizeof(GibCursor [3])); + memcpy(return_17.field2, pvrtmp_2228, sizeof(GibCursor [3])); + memcpy(return_17.field3, cursor_ptr_1437, sizeof(GibCursor [3])); + memcpy(return_17.field4, pvrtmp_2230, sizeof(GibCursor [3])); + return return_17; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1498 = arg_89_141_222[1]; + GibCursor soa_field_1_1499 = arg_89_141_222[2]; + uintptr_t tagged_tmpcur_22 = *(uintptr_t *) tmpcur_2208; + GibCursor tmpcur_2239 = GIB_UNTAG(tagged_tmpcur_22); + GibCursor tmpaftercur_2240 = tmpcur_2208 + 8; + uint16_t tmptag_2241 = GIB_GET_TAG(tagged_tmpcur_22); + GibCursor end_from_tagged_dcon_redir_1512 = tmpcur_2239 + + tmptag_2241; + GibCursor field_nxt_1509 = soa_field_0_1498 + 1; + uintptr_t tagged_tmpcur_21 = *(uintptr_t *) field_nxt_1509; + GibCursor tmpcur_2242 = GIB_UNTAG(tagged_tmpcur_21); + GibCursor tmpaftercur_2243 = field_nxt_1509 + 8; + uint16_t tmptag_2244 = GIB_GET_TAG(tagged_tmpcur_21); + GibCursor end_from_tagged_fld_redir_1513 = tmpcur_2242 + + tmptag_2244; + GibCursor field_nxt_1510 = soa_field_1_1499 + 1; + uintptr_t tagged_tmpcur_20 = *(uintptr_t *) field_nxt_1510; + GibCursor tmpcur_2245 = GIB_UNTAG(tagged_tmpcur_20); + GibCursor tmpaftercur_2246 = field_nxt_1510 + 8; + uint16_t tmptag_2247 = GIB_GET_TAG(tagged_tmpcur_20); + GibCursor end_from_tagged_fld_redir_1514 = tmpcur_2245 + + tmptag_2247; + GibCursor indr_1062[3] = {tmpcur_2239, tmpcur_2242, tmpcur_2245}; + GibCursor loc_627 = arg_89_141_222[0]; + GibCursor jump_dloc_1066 = loc_627 + 9; + GibCursor loc_IntTy_629 = arg_89_141_222[2]; + GibCursor loc_IntTy_628 = arg_89_141_222[1]; + GibCursor aft_indir_loc_1074 = loc_IntTy_628 + 9; + GibCursor aft_indir_loc_1075 = loc_IntTy_629 + 9; + GibCursor cursor_ptr_1515[3] = {jump_dloc_1066, aft_indir_loc_1074, + aft_indir_loc_1075}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_18 = + _copy_Tree(indr_1062, overwrite_reg_1438, cursor_ptr_1437, indr_1062); + GibCursor pvrtmp_2248[3]; + + memcpy(pvrtmp_2248, tmp_struct_18.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2249[3]; + + memcpy(pvrtmp_2249, tmp_struct_18.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2250[3]; + + memcpy(pvrtmp_2250, tmp_struct_18.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2251[3]; + + memcpy(pvrtmp_2251, tmp_struct_18.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2252[3]; + + memcpy(pvrtmp_2252, tmp_struct_18.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_19; + + memcpy(return_19.field0, cursor_ptr_1436, sizeof(GibCursor [3])); + memcpy(return_19.field1, pvrtmp_2249, sizeof(GibCursor [3])); + memcpy(return_19.field2, cursor_ptr_1515, sizeof(GibCursor [3])); + memcpy(return_19.field3, pvrtmp_2251, sizeof(GibCursor [3])); + memcpy(return_19.field4, pvrtmp_2252, sizeof(GibCursor [3])); + return return_19; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1526 = arg_89_141_222[1]; + GibCursor soa_field_1_1527 = arg_89_141_222[2]; + uintptr_t tagged_tmpcur_27 = *(uintptr_t *) tmpcur_2208; + GibCursor tmpcur_2259 = GIB_UNTAG(tagged_tmpcur_27); + GibCursor tmpaftercur_2260 = tmpcur_2208 + 8; + uint16_t tmptag_2261 = GIB_GET_TAG(tagged_tmpcur_27); + GibCursor end_from_tagged_dcon_redir_1535 = tmpcur_2259 + + tmptag_2261; + GibCursor field_nxt_1533 = soa_field_0_1526 + 1; + uintptr_t tagged_tmpcur_26 = *(uintptr_t *) field_nxt_1533; + GibCursor tmpcur_2262 = GIB_UNTAG(tagged_tmpcur_26); + GibCursor tmpaftercur_2263 = field_nxt_1533 + 8; + uint16_t tmptag_2264 = GIB_GET_TAG(tagged_tmpcur_26); + GibCursor end_from_tagged_fld_redir_1536 = tmpcur_2262 + + tmptag_2264; + GibCursor field_nxt_1534 = soa_field_1_1527 + 1; + uintptr_t tagged_tmpcur_25 = *(uintptr_t *) field_nxt_1534; + GibCursor tmpcur_2265 = GIB_UNTAG(tagged_tmpcur_25); + GibCursor tmpaftercur_2266 = field_nxt_1534 + 8; + uint16_t tmptag_2267 = GIB_GET_TAG(tagged_tmpcur_25); + GibCursor end_from_tagged_fld_redir_1537 = tmpcur_2265 + + tmptag_2267; + GibCursor indr_1062[3] = {tmpcur_2259, tmpcur_2262, tmpcur_2265}; + GibCursor copy_dloc_1076 = loc_630 + 0; + GibCursor copy_floc_loc_1078 = loc_IntTy_632 + 0; + GibCursor copy_floc_loc_1077 = loc_IntTy_631 + 0; + GibCursor cursor_ptr_1538[3] = {copy_dloc_1076, copy_floc_loc_1077, + copy_floc_loc_1078}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_23 = + _copy_Tree(indr_1062, overwrite_reg_1438, cursor_ptr_1538, indr_1062); + GibCursor pvrtmp_2268[3]; + + memcpy(pvrtmp_2268, tmp_struct_23.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2269[3]; + + memcpy(pvrtmp_2269, tmp_struct_23.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2270[3]; + + memcpy(pvrtmp_2270, tmp_struct_23.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2271[3]; + + memcpy(pvrtmp_2271, tmp_struct_23.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2272[3]; + + memcpy(pvrtmp_2272, tmp_struct_23.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_24; + + memcpy(return_24.field0, pvrtmp_2268, sizeof(GibCursor [3])); + memcpy(return_24.field1, pvrtmp_2269, sizeof(GibCursor [3])); + memcpy(return_24.field2, pvrtmp_2270, sizeof(GibCursor [3])); + memcpy(return_24.field3, pvrtmp_2271, sizeof(GibCursor [3])); + memcpy(return_24.field4, pvrtmp_2272, sizeof(GibCursor [3])); + return return_24; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2207"); + exit(1); + } + } +} +GibCursorPtr3GibCursorPtr3GibIntProd sumTree(GibCursor cursor_ptr_1549[3], + GibCursor tr_36_150_231[3]) +{ + GibCursor end_r_642 = cursor_ptr_1549[0]; + GibCursor end_r_643 = cursor_ptr_1549[1]; + GibCursor end_r_644 = cursor_ptr_1549[2]; + GibCursor dcon_1553 = tr_36_150_231[0]; + GibPackedTag tmpval_2280 = *(GibPackedTag *) dcon_1553; + GibCursor tmpcur_2281 = dcon_1553 + 1; + + + switch_2316: + ; + switch (tmpval_2280) { + + case 0: + { + GibCursor soa_field_0_1555 = tr_36_150_231[1]; + GibCursor soa_field_1_1556 = tr_36_150_231[2]; + GibInt tmpval_2282 = *(GibInt *) soa_field_0_1555; + GibCursor tmpcur_2283 = soa_field_0_1555 + sizeof(GibInt); + GibCursor loc_639 = tr_36_150_231[0]; + GibCursor jumpf_dloc_973 = loc_639 + 1; + GibCursor loc_IntTy_640 = tr_36_150_231[1]; + GibCursor loc_IntTy_641 = tr_36_150_231[2]; + GibCursor jumpf_floc_loc_974 = soa_field_0_1555 + 8; + GibCursor jumpf_floc_loc_975 = loc_IntTy_641 + 0; + GibCursor cursor_ptr_1559[3] = {jumpf_dloc_973, jumpf_floc_loc_974, + jumpf_floc_loc_975}; + GibCursorPtr3GibCursorPtr3GibIntProd return_28; + + memcpy(return_28.field0, cursor_ptr_1549, sizeof(GibCursor [3])); + memcpy(return_28.field1, cursor_ptr_1559, sizeof(GibCursor [3])); + return_28.field2 = tmpval_2282; + return return_28; + break; + } + + case 1: + { + GibCursor soa_field_0_1561 = tr_36_150_231[1]; + GibCursor soa_field_1_1562 = tr_36_150_231[2]; + GibInt tmpval_2284 = *(GibInt *) soa_field_1_1562; + GibCursor tmpcur_2285 = soa_field_1_1562 + sizeof(GibInt); + GibCursor cursor_ptr_1552[3] = {tmpcur_2281, soa_field_0_1561, + tmpcur_2285}; + GibCursor loc_639 = tr_36_150_231[0]; + GibCursor jumpf_dloc_976 = loc_639 + 1; + GibCursor loc_IntTy_640 = tr_36_150_231[1]; + GibCursor loc_IntTy_641 = tr_36_150_231[2]; + GibCursor jumpf_floc_loc_978 = soa_field_1_1562 + 8; + GibCursor jumpf_floc_loc_977 = loc_IntTy_640 + 0; + GibCursor loc_806 = jumpf_dloc_976 + 0; + GibCursor loc_805 = jumpf_floc_loc_978 + 0; + GibCursor loc_804 = jumpf_floc_loc_977 + 0; + GibCursor cursor_ptr_1566[3] = {jumpf_dloc_976, jumpf_floc_loc_977, + jumpf_floc_loc_978}; + GibCursorPtr3GibCursorPtr3GibIntProd tmp_struct_29 = + sumTree(cursor_ptr_1549, cursor_ptr_1552); + GibCursor pvrtmp_2286[3]; + + memcpy(pvrtmp_2286, tmp_struct_29.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2287[3]; + + memcpy(pvrtmp_2287, tmp_struct_29.field1, sizeof(GibCursor [3])); + + GibInt pvrtmp_2288 = tmp_struct_29.field2; + GibInt fltPrm_200_237 = tmpval_2284 + pvrtmp_2288; + GibCursorPtr3GibCursorPtr3GibIntProd tmp_struct_30 = + sumTree(pvrtmp_2286, pvrtmp_2287); + GibCursor pvrtmp_2289[3]; + + memcpy(pvrtmp_2289, tmp_struct_30.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2290[3]; + + memcpy(pvrtmp_2290, tmp_struct_30.field1, sizeof(GibCursor [3])); + + GibInt pvrtmp_2291 = tmp_struct_30.field2; + GibInt tailprim_985 = fltPrm_200_237 + pvrtmp_2291; + GibCursorPtr3GibCursorPtr3GibIntProd return_31; + + memcpy(return_31.field0, pvrtmp_2289, sizeof(GibCursor [3])); + memcpy(return_31.field1, pvrtmp_2290, sizeof(GibCursor [3])); + return_31.field2 = tailprim_985; + return return_31; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1579 = tr_36_150_231[1]; + GibCursor soa_field_1_1580 = tr_36_150_231[2]; + uintptr_t tagged_tmpcur_36 = *(uintptr_t *) tmpcur_2281; + GibCursor tmpcur_2292 = GIB_UNTAG(tagged_tmpcur_36); + GibCursor tmpaftercur_2293 = tmpcur_2281 + 8; + uint16_t tmptag_2294 = GIB_GET_TAG(tagged_tmpcur_36); + GibCursor end_from_tagged_dcon_redir_1593 = tmpcur_2292 + + tmptag_2294; + GibCursor field_nxt_1590 = soa_field_0_1579 + 1; + uintptr_t tagged_tmpcur_35 = *(uintptr_t *) field_nxt_1590; + GibCursor tmpcur_2295 = GIB_UNTAG(tagged_tmpcur_35); + GibCursor tmpaftercur_2296 = field_nxt_1590 + 8; + uint16_t tmptag_2297 = GIB_GET_TAG(tagged_tmpcur_35); + GibCursor end_from_tagged_fld_redir_1594 = tmpcur_2295 + + tmptag_2297; + GibCursor field_nxt_1591 = soa_field_1_1580 + 1; + uintptr_t tagged_tmpcur_34 = *(uintptr_t *) field_nxt_1591; + GibCursor tmpcur_2298 = GIB_UNTAG(tagged_tmpcur_34); + GibCursor tmpaftercur_2299 = field_nxt_1591 + 8; + uint16_t tmptag_2300 = GIB_GET_TAG(tagged_tmpcur_34); + GibCursor end_from_tagged_fld_redir_1595 = tmpcur_2298 + + tmptag_2300; + GibCursor indr_1079[3] = {tmpcur_2292, tmpcur_2295, tmpcur_2298}; + GibCursor loc_639 = tr_36_150_231[0]; + GibCursor jump_dloc_1083 = loc_639 + 9; + GibCursor loc_IntTy_641 = tr_36_150_231[2]; + GibCursor loc_IntTy_640 = tr_36_150_231[1]; + GibCursor aft_indir_loc_1091 = loc_IntTy_640 + 9; + GibCursor aft_indir_loc_1092 = loc_IntTy_641 + 9; + GibCursor cursor_ptr_1596[3] = {jump_dloc_1083, aft_indir_loc_1091, + aft_indir_loc_1092}; + GibCursorPtr3GibCursorPtr3GibIntProd tmp_struct_32 = + sumTree(indr_1079, indr_1079); + GibCursor pvrtmp_2301[3]; + + memcpy(pvrtmp_2301, tmp_struct_32.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2302[3]; + + memcpy(pvrtmp_2302, tmp_struct_32.field1, sizeof(GibCursor [3])); + + GibInt pvrtmp_2303 = tmp_struct_32.field2; + GibCursorPtr3GibCursorPtr3GibIntProd return_33; + + memcpy(return_33.field0, cursor_ptr_1549, sizeof(GibCursor [3])); + memcpy(return_33.field1, cursor_ptr_1596, sizeof(GibCursor [3])); + return_33.field2 = pvrtmp_2303; + return return_33; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1604 = tr_36_150_231[1]; + GibCursor soa_field_1_1605 = tr_36_150_231[2]; + uintptr_t tagged_tmpcur_41 = *(uintptr_t *) tmpcur_2281; + GibCursor tmpcur_2304 = GIB_UNTAG(tagged_tmpcur_41); + GibCursor tmpaftercur_2305 = tmpcur_2281 + 8; + uint16_t tmptag_2306 = GIB_GET_TAG(tagged_tmpcur_41); + GibCursor end_from_tagged_dcon_redir_1613 = tmpcur_2304 + + tmptag_2306; + GibCursor field_nxt_1611 = soa_field_0_1604 + 1; + uintptr_t tagged_tmpcur_40 = *(uintptr_t *) field_nxt_1611; + GibCursor tmpcur_2307 = GIB_UNTAG(tagged_tmpcur_40); + GibCursor tmpaftercur_2308 = field_nxt_1611 + 8; + uint16_t tmptag_2309 = GIB_GET_TAG(tagged_tmpcur_40); + GibCursor end_from_tagged_fld_redir_1614 = tmpcur_2307 + + tmptag_2309; + GibCursor field_nxt_1612 = soa_field_1_1605 + 1; + uintptr_t tagged_tmpcur_39 = *(uintptr_t *) field_nxt_1612; + GibCursor tmpcur_2310 = GIB_UNTAG(tagged_tmpcur_39); + GibCursor tmpaftercur_2311 = field_nxt_1612 + 8; + uint16_t tmptag_2312 = GIB_GET_TAG(tagged_tmpcur_39); + GibCursor end_from_tagged_fld_redir_1615 = tmpcur_2310 + + tmptag_2312; + GibCursor indr_1079[3] = {tmpcur_2304, tmpcur_2307, tmpcur_2310}; + GibCursorPtr3GibCursorPtr3GibIntProd tmp_struct_37 = + sumTree(indr_1079, indr_1079); + GibCursor pvrtmp_2313[3]; + + memcpy(pvrtmp_2313, tmp_struct_37.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2314[3]; + + memcpy(pvrtmp_2314, tmp_struct_37.field1, sizeof(GibCursor [3])); + + GibInt pvrtmp_2315 = tmp_struct_37.field2; + GibCursorPtr3GibCursorPtr3GibIntProd return_38; + + memcpy(return_38.field0, pvrtmp_2313, sizeof(GibCursor [3])); + memcpy(return_38.field1, pvrtmp_2314, sizeof(GibCursor [3])); + return_38.field2 = pvrtmp_2315; + return return_38; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2280"); + exit(1); + } + } +} +GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod mkTree(GibCursor cursor_ptr_1622[3], + GibCursor cursor_ptr_1623[3], + GibInt d_41_155_239, + GibInt acc_42_156_240) +{ + GibCursor end_r_649 = cursor_ptr_1622[1]; + GibCursor end_r_648 = cursor_ptr_1622[0]; + GibCursor end_r_650 = cursor_ptr_1622[2]; + GibCursor loc_645 = cursor_ptr_1623[0]; + GibCursor loc_IntTy_646 = cursor_ptr_1623[1]; + GibCursor loc_IntTy_647 = cursor_ptr_1623[2]; + + if (loc_IntTy_647 + 17 > end_r_650 || (loc_IntTy_646 + 17 > end_r_649 || + loc_645 + 34 > end_r_648)) { + gib_grow_region(&loc_IntTy_647, &end_r_650); + gib_grow_region(&loc_IntTy_646, &end_r_649); + gib_grow_region(&loc_645, &end_r_648); + } + + GibCursor overwrite_reg_1624[3] = {end_r_648, end_r_649, end_r_650}; + GibBool fltIf_203_241 = d_41_155_239 == 0; + + if (fltIf_203_241) { + GibCursor new_floc_loc_834 = loc_IntTy_647 + 8; + GibCursor new_dloc_832 = loc_645 + 1; + + *(GibPackedTag *) loc_645 = 0; + + GibCursor writetag_1625 = loc_645 + 1; + GibCursor after_tag_1626 = loc_645 + 1; + + *(GibInt *) loc_IntTy_646 = acc_42_156_240; + + GibCursor writecur_1630 = loc_IntTy_646 + sizeof(GibInt); + GibCursor aft_soa_loc_1632[3] = {after_tag_1626, writecur_1630, + loc_IntTy_647}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod return_42; + + memcpy(return_42.field0, overwrite_reg_1624, sizeof(GibCursor [3])); + memcpy(return_42.field1, cursor_ptr_1623, sizeof(GibCursor [3])); + memcpy(return_42.field2, aft_soa_loc_1632, sizeof(GibCursor [3])); + return return_42; + } else { + GibInt fltAppE_205_242 = d_41_155_239 - 1; + GibInt fltAppE_206_243 = d_41_155_239 + acc_42_156_240; + GibCursor new_floc_loc_834 = loc_IntTy_647 + 8; + GibCursor new_dloc_832 = loc_645 + 1; + GibCursor cursor_ptr_1635[3] = {new_dloc_832, loc_IntTy_646, + new_floc_loc_834}; + + *(GibPackedTag *) loc_645 = 1; + + GibCursor writetag_1645 = loc_645 + 1; + GibCursor after_tag_1646 = loc_645 + 1; + + *(GibInt *) loc_IntTy_647 = d_41_155_239; + + GibCursor writecur_1650 = loc_IntTy_647 + sizeof(GibInt); + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod tmp_struct_43 = + mkTree(overwrite_reg_1624, cursor_ptr_1635, fltAppE_205_242, fltAppE_206_243); + GibCursor pvrtmp_2321[3]; + + memcpy(pvrtmp_2321, tmp_struct_43.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2322[3]; + + memcpy(pvrtmp_2322, tmp_struct_43.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2323[3]; + + memcpy(pvrtmp_2323, tmp_struct_43.field2, sizeof(GibCursor [3])); + + GibInt fltAppE_208_245 = d_41_155_239 - 1; + GibInt fltAppE_209_246 = d_41_155_239 + acc_42_156_240; + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod tmp_struct_44 = + mkTree(pvrtmp_2321, pvrtmp_2323, fltAppE_208_245, fltAppE_209_246); + GibCursor pvrtmp_2328[3]; + + memcpy(pvrtmp_2328, tmp_struct_44.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2329[3]; + + memcpy(pvrtmp_2329, tmp_struct_44.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2330[3]; + + memcpy(pvrtmp_2330, tmp_struct_44.field2, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod return_45; + + memcpy(return_45.field0, pvrtmp_2328, sizeof(GibCursor [3])); + memcpy(return_45.field1, cursor_ptr_1623, sizeof(GibCursor [3])); + memcpy(return_45.field2, pvrtmp_2330, sizeof(GibCursor [3])); + return return_45; + } +} +GibCursorPtr3GibCursorPtr3Prod _traverse_Tree(GibCursor cursor_ptr_1658[3], + GibCursor arg_107_163_248[3]) +{ + GibCursor end_r_654 = cursor_ptr_1658[0]; + GibCursor end_r_655 = cursor_ptr_1658[1]; + GibCursor end_r_656 = cursor_ptr_1658[2]; + GibCursor dcon_1662 = arg_107_163_248[0]; + GibPackedTag tmpval_2339 = *(GibPackedTag *) dcon_1662; + GibCursor tmpcur_2340 = dcon_1662 + 1; + + + switch_2371: + ; + switch (tmpval_2339) { + + case 0: + { + GibCursor soa_field_0_1664 = arg_107_163_248[1]; + GibCursor soa_field_1_1665 = arg_107_163_248[2]; + GibInt tmpval_2341 = *(GibInt *) soa_field_0_1664; + GibCursor tmpcur_2342 = soa_field_0_1664 + sizeof(GibInt); + GibCursor loc_651 = arg_107_163_248[0]; + GibCursor jumpf_dloc_988 = loc_651 + 1; + GibCursor loc_IntTy_652 = arg_107_163_248[1]; + GibCursor loc_IntTy_653 = arg_107_163_248[2]; + GibCursor jumpf_floc_loc_989 = soa_field_0_1664 + 8; + GibCursor jumpf_floc_loc_990 = loc_IntTy_653 + 0; + GibCursor cursor_ptr_1668[3] = {jumpf_dloc_988, jumpf_floc_loc_989, + jumpf_floc_loc_990}; + GibCursorPtr3GibCursorPtr3Prod return_46; + + memcpy(return_46.field0, cursor_ptr_1658, sizeof(GibCursor [3])); + memcpy(return_46.field1, cursor_ptr_1668, sizeof(GibCursor [3])); + return return_46; + break; + } + + case 1: + { + GibCursor soa_field_0_1670 = arg_107_163_248[1]; + GibCursor soa_field_1_1671 = arg_107_163_248[2]; + GibInt tmpval_2343 = *(GibInt *) soa_field_1_1671; + GibCursor tmpcur_2344 = soa_field_1_1671 + sizeof(GibInt); + GibCursor cursor_ptr_1661[3] = {tmpcur_2340, soa_field_0_1670, + tmpcur_2344}; + GibCursor loc_651 = arg_107_163_248[0]; + GibCursor jumpf_dloc_992 = loc_651 + 1; + GibCursor loc_IntTy_652 = arg_107_163_248[1]; + GibCursor loc_IntTy_653 = arg_107_163_248[2]; + GibCursor jumpf_floc_loc_994 = soa_field_1_1671 + 8; + GibCursor jumpf_floc_loc_993 = loc_IntTy_652 + 0; + GibCursor loc_852 = jumpf_dloc_992 + 0; + GibCursor loc_851 = jumpf_floc_loc_994 + 0; + GibCursor loc_850 = jumpf_floc_loc_993 + 0; + GibCursor cursor_ptr_1675[3] = {jumpf_dloc_992, jumpf_floc_loc_993, + jumpf_floc_loc_994}; + GibCursorPtr3GibCursorPtr3Prod tmp_struct_47 = + _traverse_Tree(cursor_ptr_1658, cursor_ptr_1661); + GibCursor pvrtmp_2345[3]; + + memcpy(pvrtmp_2345, tmp_struct_47.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2346[3]; + + memcpy(pvrtmp_2346, tmp_struct_47.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod tmp_struct_48 = + _traverse_Tree(pvrtmp_2345, pvrtmp_2346); + GibCursor pvrtmp_2347[3]; + + memcpy(pvrtmp_2347, tmp_struct_48.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2348[3]; + + memcpy(pvrtmp_2348, tmp_struct_48.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_49; + + memcpy(return_49.field0, pvrtmp_2347, sizeof(GibCursor [3])); + memcpy(return_49.field1, pvrtmp_2348, sizeof(GibCursor [3])); + return return_49; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1688 = arg_107_163_248[1]; + GibCursor soa_field_1_1689 = arg_107_163_248[2]; + uintptr_t tagged_tmpcur_54 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2349 = GIB_UNTAG(tagged_tmpcur_54); + GibCursor tmpaftercur_2350 = tmpcur_2340 + 8; + uint16_t tmptag_2351 = GIB_GET_TAG(tagged_tmpcur_54); + GibCursor end_from_tagged_dcon_redir_1702 = tmpcur_2349 + + tmptag_2351; + GibCursor field_nxt_1699 = soa_field_0_1688 + 1; + uintptr_t tagged_tmpcur_53 = *(uintptr_t *) field_nxt_1699; + GibCursor tmpcur_2352 = GIB_UNTAG(tagged_tmpcur_53); + GibCursor tmpaftercur_2353 = field_nxt_1699 + 8; + uint16_t tmptag_2354 = GIB_GET_TAG(tagged_tmpcur_53); + GibCursor end_from_tagged_fld_redir_1703 = tmpcur_2352 + + tmptag_2354; + GibCursor field_nxt_1700 = soa_field_1_1689 + 1; + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) field_nxt_1700; + GibCursor tmpcur_2355 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_2356 = field_nxt_1700 + 8; + uint16_t tmptag_2357 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_fld_redir_1704 = tmpcur_2355 + + tmptag_2357; + GibCursor indr_1093[3] = {tmpcur_2349, tmpcur_2352, tmpcur_2355}; + GibCursor loc_651 = arg_107_163_248[0]; + GibCursor jump_dloc_1097 = loc_651 + 9; + GibCursor loc_IntTy_653 = arg_107_163_248[2]; + GibCursor loc_IntTy_652 = arg_107_163_248[1]; + GibCursor aft_indir_loc_1105 = loc_IntTy_652 + 9; + GibCursor aft_indir_loc_1106 = loc_IntTy_653 + 9; + GibCursor cursor_ptr_1705[3] = {jump_dloc_1097, aft_indir_loc_1105, + aft_indir_loc_1106}; + GibCursorPtr3GibCursorPtr3Prod tmp_struct_50 = + _traverse_Tree(indr_1093, indr_1093); + GibCursor pvrtmp_2358[3]; + + memcpy(pvrtmp_2358, tmp_struct_50.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2359[3]; + + memcpy(pvrtmp_2359, tmp_struct_50.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_51; + + memcpy(return_51.field0, cursor_ptr_1658, sizeof(GibCursor [3])); + memcpy(return_51.field1, cursor_ptr_1705, sizeof(GibCursor [3])); + return return_51; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1713 = arg_107_163_248[1]; + GibCursor soa_field_1_1714 = arg_107_163_248[2]; + uintptr_t tagged_tmpcur_59 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2360 = GIB_UNTAG(tagged_tmpcur_59); + GibCursor tmpaftercur_2361 = tmpcur_2340 + 8; + uint16_t tmptag_2362 = GIB_GET_TAG(tagged_tmpcur_59); + GibCursor end_from_tagged_dcon_redir_1722 = tmpcur_2360 + + tmptag_2362; + GibCursor field_nxt_1720 = soa_field_0_1713 + 1; + uintptr_t tagged_tmpcur_58 = *(uintptr_t *) field_nxt_1720; + GibCursor tmpcur_2363 = GIB_UNTAG(tagged_tmpcur_58); + GibCursor tmpaftercur_2364 = field_nxt_1720 + 8; + uint16_t tmptag_2365 = GIB_GET_TAG(tagged_tmpcur_58); + GibCursor end_from_tagged_fld_redir_1723 = tmpcur_2363 + + tmptag_2365; + GibCursor field_nxt_1721 = soa_field_1_1714 + 1; + uintptr_t tagged_tmpcur_57 = *(uintptr_t *) field_nxt_1721; + GibCursor tmpcur_2366 = GIB_UNTAG(tagged_tmpcur_57); + GibCursor tmpaftercur_2367 = field_nxt_1721 + 8; + uint16_t tmptag_2368 = GIB_GET_TAG(tagged_tmpcur_57); + GibCursor end_from_tagged_fld_redir_1724 = tmpcur_2366 + + tmptag_2368; + GibCursor indr_1093[3] = {tmpcur_2360, tmpcur_2363, tmpcur_2366}; + GibCursorPtr3GibCursorPtr3Prod tmp_struct_55 = + _traverse_Tree(indr_1093, indr_1093); + GibCursor pvrtmp_2369[3]; + + memcpy(pvrtmp_2369, tmp_struct_55.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2370[3]; + + memcpy(pvrtmp_2370, tmp_struct_55.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_56; + + memcpy(return_56.field0, pvrtmp_2369, sizeof(GibCursor [3])); + memcpy(return_56.field1, pvrtmp_2370, sizeof(GibCursor [3])); + return return_56; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2339"); + exit(1); + } + } +} +GibCursorPtr3GibCursorPtr3Prod _print_Tree(GibCursor cursor_ptr_1732[3], + GibCursor arg_116_170_255[3]) +{ + GibCursor end_r_660 = cursor_ptr_1732[0]; + GibCursor end_r_661 = cursor_ptr_1732[1]; + GibCursor end_r_662 = cursor_ptr_1732[2]; + GibCursor dcon_1736 = arg_116_170_255[0]; + GibPackedTag tmpval_2372 = *(GibPackedTag *) dcon_1736; + GibCursor tmpcur_2373 = dcon_1736 + 1; + + + switch_2404: + ; + switch (tmpval_2372) { + + case 0: + { + GibCursor soa_field_0_1738 = arg_116_170_255[1]; + GibCursor soa_field_1_1739 = arg_116_170_255[2]; + GibInt tmpval_2374 = *(GibInt *) soa_field_0_1738; + GibCursor tmpcur_2375 = soa_field_0_1738 + sizeof(GibInt); + GibCursor loc_657 = arg_116_170_255[0]; + GibCursor jumpf_dloc_1002 = loc_657 + 1; + GibCursor loc_IntTy_658 = arg_116_170_255[1]; + GibCursor loc_IntTy_659 = arg_116_170_255[2]; + GibCursor jumpf_floc_loc_1003 = soa_field_0_1738 + 8; + GibCursor jumpf_floc_loc_1004 = loc_IntTy_659 + 0; + GibCursor cursor_ptr_1742[3] = {jumpf_dloc_1002, + jumpf_floc_loc_1003, + jumpf_floc_loc_1004}; + unsigned char wildcard_119_172_257 = gib_print_symbol(2093); + unsigned char wildcard_121_173_258 = gib_print_symbol(2096); + unsigned char y_118_174_259 = printf("%ld", tmpval_2374); + unsigned char wildcard_120_175_260 = gib_print_symbol(2091); + GibCursorPtr3GibCursorPtr3Prod return_60; + + memcpy(return_60.field0, cursor_ptr_1732, sizeof(GibCursor [3])); + memcpy(return_60.field1, cursor_ptr_1742, sizeof(GibCursor [3])); + return return_60; + break; + } + + case 1: + { + GibCursor soa_field_0_1744 = arg_116_170_255[1]; + GibCursor soa_field_1_1745 = arg_116_170_255[2]; + GibInt tmpval_2376 = *(GibInt *) soa_field_1_1745; + GibCursor tmpcur_2377 = soa_field_1_1745 + sizeof(GibInt); + GibCursor cursor_ptr_1735[3] = {tmpcur_2373, soa_field_0_1744, + tmpcur_2377}; + GibCursor loc_657 = arg_116_170_255[0]; + GibCursor jumpf_dloc_1006 = loc_657 + 1; + GibCursor loc_IntTy_658 = arg_116_170_255[1]; + GibCursor loc_IntTy_659 = arg_116_170_255[2]; + GibCursor jumpf_floc_loc_1008 = soa_field_1_1745 + 8; + GibCursor jumpf_floc_loc_1007 = loc_IntTy_658 + 0; + GibCursor loc_874 = jumpf_dloc_1006 + 0; + GibCursor loc_873 = jumpf_floc_loc_1008 + 0; + GibCursor loc_872 = jumpf_floc_loc_1007 + 0; + GibCursor cursor_ptr_1749[3] = {jumpf_dloc_1006, + jumpf_floc_loc_1007, + jumpf_floc_loc_1008}; + unsigned char wildcard_128_179_264 = gib_print_symbol(2092); + unsigned char wildcard_132_180_265 = gib_print_symbol(2096); + unsigned char y_125_181_266 = printf("%ld", tmpval_2376); + unsigned char wildcard_131_182_267 = gib_print_symbol(2096); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_61 = + _print_Tree(cursor_ptr_1732, cursor_ptr_1735); + GibCursor pvrtmp_2378[3]; + + memcpy(pvrtmp_2378, tmp_struct_61.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2379[3]; + + memcpy(pvrtmp_2379, tmp_struct_61.field1, sizeof(GibCursor [3])); + + unsigned char wildcard_130_184_269 = gib_print_symbol(2096); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_62 = + _print_Tree(pvrtmp_2378, pvrtmp_2379); + GibCursor pvrtmp_2380[3]; + + memcpy(pvrtmp_2380, tmp_struct_62.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2381[3]; + + memcpy(pvrtmp_2381, tmp_struct_62.field1, sizeof(GibCursor [3])); + + unsigned char wildcard_129_186_271 = gib_print_symbol(2091); + GibCursorPtr3GibCursorPtr3Prod return_63; + + memcpy(return_63.field0, pvrtmp_2380, sizeof(GibCursor [3])); + memcpy(return_63.field1, pvrtmp_2381, sizeof(GibCursor [3])); + return return_63; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1762 = arg_116_170_255[1]; + GibCursor soa_field_1_1763 = arg_116_170_255[2]; + uintptr_t tagged_tmpcur_68 = *(uintptr_t *) tmpcur_2373; + GibCursor tmpcur_2382 = GIB_UNTAG(tagged_tmpcur_68); + GibCursor tmpaftercur_2383 = tmpcur_2373 + 8; + uint16_t tmptag_2384 = GIB_GET_TAG(tagged_tmpcur_68); + GibCursor end_from_tagged_dcon_redir_1776 = tmpcur_2382 + + tmptag_2384; + GibCursor field_nxt_1773 = soa_field_0_1762 + 1; + uintptr_t tagged_tmpcur_67 = *(uintptr_t *) field_nxt_1773; + GibCursor tmpcur_2385 = GIB_UNTAG(tagged_tmpcur_67); + GibCursor tmpaftercur_2386 = field_nxt_1773 + 8; + uint16_t tmptag_2387 = GIB_GET_TAG(tagged_tmpcur_67); + GibCursor end_from_tagged_fld_redir_1777 = tmpcur_2385 + + tmptag_2387; + GibCursor field_nxt_1774 = soa_field_1_1763 + 1; + uintptr_t tagged_tmpcur_66 = *(uintptr_t *) field_nxt_1774; + GibCursor tmpcur_2388 = GIB_UNTAG(tagged_tmpcur_66); + GibCursor tmpaftercur_2389 = field_nxt_1774 + 8; + uint16_t tmptag_2390 = GIB_GET_TAG(tagged_tmpcur_66); + GibCursor end_from_tagged_fld_redir_1778 = tmpcur_2388 + + tmptag_2390; + GibCursor indr_1107[3] = {tmpcur_2382, tmpcur_2385, tmpcur_2388}; + GibCursor loc_657 = arg_116_170_255[0]; + GibCursor jump_dloc_1111 = loc_657 + 9; + GibCursor loc_IntTy_659 = arg_116_170_255[2]; + GibCursor loc_IntTy_658 = arg_116_170_255[1]; + GibCursor aft_indir_loc_1119 = loc_IntTy_658 + 9; + GibCursor aft_indir_loc_1120 = loc_IntTy_659 + 9; + GibCursor cursor_ptr_1779[3] = {jump_dloc_1111, aft_indir_loc_1119, + aft_indir_loc_1120}; + unsigned char wildcard_1118 = gib_print_symbol(2095); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_64 = + _print_Tree(indr_1107, indr_1107); + GibCursor pvrtmp_2391[3]; + + memcpy(pvrtmp_2391, tmp_struct_64.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2392[3]; + + memcpy(pvrtmp_2392, tmp_struct_64.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_65; + + memcpy(return_65.field0, cursor_ptr_1732, sizeof(GibCursor [3])); + memcpy(return_65.field1, cursor_ptr_1779, sizeof(GibCursor [3])); + return return_65; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1787 = arg_116_170_255[1]; + GibCursor soa_field_1_1788 = arg_116_170_255[2]; + uintptr_t tagged_tmpcur_73 = *(uintptr_t *) tmpcur_2373; + GibCursor tmpcur_2393 = GIB_UNTAG(tagged_tmpcur_73); + GibCursor tmpaftercur_2394 = tmpcur_2373 + 8; + uint16_t tmptag_2395 = GIB_GET_TAG(tagged_tmpcur_73); + GibCursor end_from_tagged_dcon_redir_1796 = tmpcur_2393 + + tmptag_2395; + GibCursor field_nxt_1794 = soa_field_0_1787 + 1; + uintptr_t tagged_tmpcur_72 = *(uintptr_t *) field_nxt_1794; + GibCursor tmpcur_2396 = GIB_UNTAG(tagged_tmpcur_72); + GibCursor tmpaftercur_2397 = field_nxt_1794 + 8; + uint16_t tmptag_2398 = GIB_GET_TAG(tagged_tmpcur_72); + GibCursor end_from_tagged_fld_redir_1797 = tmpcur_2396 + + tmptag_2398; + GibCursor field_nxt_1795 = soa_field_1_1788 + 1; + uintptr_t tagged_tmpcur_71 = *(uintptr_t *) field_nxt_1795; + GibCursor tmpcur_2399 = GIB_UNTAG(tagged_tmpcur_71); + GibCursor tmpaftercur_2400 = field_nxt_1795 + 8; + uint16_t tmptag_2401 = GIB_GET_TAG(tagged_tmpcur_71); + GibCursor end_from_tagged_fld_redir_1798 = tmpcur_2399 + + tmptag_2401; + GibCursor indr_1107[3] = {tmpcur_2393, tmpcur_2396, tmpcur_2399}; + unsigned char wildcard_1118 = gib_print_symbol(2094); + GibCursorPtr3GibCursorPtr3Prod tmp_struct_69 = + _print_Tree(indr_1107, indr_1107); + GibCursor pvrtmp_2402[3]; + + memcpy(pvrtmp_2402, tmp_struct_69.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2403[3]; + + memcpy(pvrtmp_2403, tmp_struct_69.field1, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3Prod return_70; + + memcpy(return_70.field0, pvrtmp_2402, sizeof(GibCursor [3])); + memcpy(return_70.field1, pvrtmp_2403, sizeof(GibCursor [3])); + return return_70; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2372"); + exit(1); + } + } +} +GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod _copy_without_ptrs_Tree(GibCursor cursor_ptr_1807[3], + GibCursor cursor_ptr_1806[3], + GibCursor cursor_ptr_1808[3], + GibCursor arg_98_187_272[3]) +{ + GibCursor end_r_669 = cursor_ptr_1807[0]; + GibCursor end_r_670 = cursor_ptr_1807[1]; + GibCursor end_r_671 = cursor_ptr_1807[2]; + GibCursor end_r_672 = cursor_ptr_1806[0]; + GibCursor end_r_673 = cursor_ptr_1806[1]; + GibCursor end_r_674 = cursor_ptr_1806[2]; + GibCursor dcon_1812 = arg_98_187_272[0]; + GibPackedTag tmpval_2405 = *(GibPackedTag *) dcon_1812; + GibCursor tmpcur_2406 = dcon_1812 + 1; + + + switch_2477: + ; + switch (tmpval_2405) { + + case 0: + { + GibCursor soa_field_0_1814 = arg_98_187_272[1]; + GibCursor soa_field_1_1815 = arg_98_187_272[2]; + GibInt tmpval_2407 = *(GibInt *) soa_field_0_1814; + GibCursor tmpcur_2408 = soa_field_0_1814 + sizeof(GibInt); + GibCursor loc_663 = arg_98_187_272[0]; + GibCursor jumpf_dloc_1016 = loc_663 + 1; + GibCursor loc_IntTy_664 = arg_98_187_272[1]; + GibCursor loc_IntTy_665 = arg_98_187_272[2]; + GibCursor jumpf_floc_loc_1017 = soa_field_0_1814 + 8; + GibCursor jumpf_floc_loc_1018 = loc_IntTy_665 + 0; + GibCursor cursor_ptr_1818[3] = {jumpf_dloc_1016, + jumpf_floc_loc_1017, + jumpf_floc_loc_1018}; + GibCursor loc_IntTy_668 = cursor_ptr_1808[2]; + GibCursor new_floc_loc_924 = loc_IntTy_668 + 8; + GibCursor loc_666 = cursor_ptr_1808[0]; + GibCursor new_dloc_922 = loc_666 + 1; + GibCursor loc_IntTy_667 = cursor_ptr_1808[1]; + + *(GibPackedTag *) loc_666 = 0; + + GibCursor writetag_1819 = loc_666 + 1; + GibCursor after_tag_1820 = loc_666 + 1; + + *(GibInt *) loc_IntTy_667 = tmpval_2407; + + GibCursor writecur_1824 = loc_IntTy_667 + sizeof(GibInt); + GibCursor aft_soa_loc_1826[3] = {after_tag_1820, writecur_1824, + loc_IntTy_668}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_74; + + memcpy(return_74.field0, cursor_ptr_1807, sizeof(GibCursor [3])); + memcpy(return_74.field1, cursor_ptr_1806, sizeof(GibCursor [3])); + memcpy(return_74.field2, cursor_ptr_1818, sizeof(GibCursor [3])); + memcpy(return_74.field3, cursor_ptr_1808, sizeof(GibCursor [3])); + memcpy(return_74.field4, aft_soa_loc_1826, sizeof(GibCursor [3])); + return return_74; + break; + } + + case 1: + { + GibCursor soa_field_0_1830 = arg_98_187_272[1]; + GibCursor soa_field_1_1831 = arg_98_187_272[2]; + GibInt tmpval_2413 = *(GibInt *) soa_field_1_1831; + GibCursor tmpcur_2414 = soa_field_1_1831 + sizeof(GibInt); + GibCursor cursor_ptr_1811[3] = {tmpcur_2406, soa_field_0_1830, + tmpcur_2414}; + GibCursor loc_663 = arg_98_187_272[0]; + GibCursor jumpf_dloc_1020 = loc_663 + 1; + GibCursor loc_IntTy_664 = arg_98_187_272[1]; + GibCursor loc_IntTy_665 = arg_98_187_272[2]; + GibCursor jumpf_floc_loc_1022 = soa_field_1_1831 + 8; + GibCursor jumpf_floc_loc_1021 = loc_IntTy_664 + 0; + GibCursor loc_899 = jumpf_dloc_1020 + 0; + GibCursor loc_898 = jumpf_floc_loc_1022 + 0; + GibCursor loc_897 = jumpf_floc_loc_1021 + 0; + GibCursor cursor_ptr_1835[3] = {jumpf_dloc_1020, + jumpf_floc_loc_1021, + jumpf_floc_loc_1022}; + GibCursor loc_IntTy_668 = cursor_ptr_1808[2]; + GibCursor new_floc_loc_924 = loc_IntTy_668 + 8; + GibCursor loc_666 = cursor_ptr_1808[0]; + GibCursor new_dloc_922 = loc_666 + 1; + GibCursor loc_IntTy_667 = cursor_ptr_1808[1]; + GibCursor cursor_ptr_1836[3] = {new_dloc_922, loc_IntTy_667, + new_floc_loc_924}; + + *(GibPackedTag *) loc_666 = 1; + + GibCursor writetag_1855 = loc_666 + 1; + GibCursor after_tag_1856 = loc_666 + 1; + + *(GibInt *) loc_IntTy_668 = tmpval_2413; + + GibCursor writecur_1860 = loc_IntTy_668 + sizeof(GibInt); + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_75 = + _copy_without_ptrs_Tree(cursor_ptr_1807, cursor_ptr_1806, cursor_ptr_1836, cursor_ptr_1811); + GibCursor pvrtmp_2415[3]; + + memcpy(pvrtmp_2415, tmp_struct_75.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2416[3]; + + memcpy(pvrtmp_2416, tmp_struct_75.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2417[3]; + + memcpy(pvrtmp_2417, tmp_struct_75.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2418[3]; + + memcpy(pvrtmp_2418, tmp_struct_75.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2419[3]; + + memcpy(pvrtmp_2419, tmp_struct_75.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_76 = + _copy_without_ptrs_Tree(pvrtmp_2415, pvrtmp_2416, pvrtmp_2419, pvrtmp_2417); + GibCursor pvrtmp_2424[3]; + + memcpy(pvrtmp_2424, tmp_struct_76.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2425[3]; + + memcpy(pvrtmp_2425, tmp_struct_76.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2426[3]; + + memcpy(pvrtmp_2426, tmp_struct_76.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2427[3]; + + memcpy(pvrtmp_2427, tmp_struct_76.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2428[3]; + + memcpy(pvrtmp_2428, tmp_struct_76.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_77; + + memcpy(return_77.field0, pvrtmp_2424, sizeof(GibCursor [3])); + memcpy(return_77.field1, pvrtmp_2425, sizeof(GibCursor [3])); + memcpy(return_77.field2, pvrtmp_2426, sizeof(GibCursor [3])); + memcpy(return_77.field3, cursor_ptr_1808, sizeof(GibCursor [3])); + memcpy(return_77.field4, pvrtmp_2428, sizeof(GibCursor [3])); + return return_77; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1868 = arg_98_187_272[1]; + GibCursor soa_field_1_1869 = arg_98_187_272[2]; + uintptr_t tagged_tmpcur_82 = *(uintptr_t *) tmpcur_2406; + GibCursor tmpcur_2437 = GIB_UNTAG(tagged_tmpcur_82); + GibCursor tmpaftercur_2438 = tmpcur_2406 + 8; + uint16_t tmptag_2439 = GIB_GET_TAG(tagged_tmpcur_82); + GibCursor end_from_tagged_dcon_redir_1882 = tmpcur_2437 + + tmptag_2439; + GibCursor field_nxt_1879 = soa_field_0_1868 + 1; + uintptr_t tagged_tmpcur_81 = *(uintptr_t *) field_nxt_1879; + GibCursor tmpcur_2440 = GIB_UNTAG(tagged_tmpcur_81); + GibCursor tmpaftercur_2441 = field_nxt_1879 + 8; + uint16_t tmptag_2442 = GIB_GET_TAG(tagged_tmpcur_81); + GibCursor end_from_tagged_fld_redir_1883 = tmpcur_2440 + + tmptag_2442; + GibCursor field_nxt_1880 = soa_field_1_1869 + 1; + uintptr_t tagged_tmpcur_80 = *(uintptr_t *) field_nxt_1880; + GibCursor tmpcur_2443 = GIB_UNTAG(tagged_tmpcur_80); + GibCursor tmpaftercur_2444 = field_nxt_1880 + 8; + uint16_t tmptag_2445 = GIB_GET_TAG(tagged_tmpcur_80); + GibCursor end_from_tagged_fld_redir_1884 = tmpcur_2443 + + tmptag_2445; + GibCursor indr_1121[3] = {tmpcur_2437, tmpcur_2440, tmpcur_2443}; + GibCursor loc_663 = arg_98_187_272[0]; + GibCursor jump_dloc_1125 = loc_663 + 9; + GibCursor loc_IntTy_665 = arg_98_187_272[2]; + GibCursor loc_IntTy_664 = arg_98_187_272[1]; + GibCursor aft_indir_loc_1133 = loc_IntTy_664 + 9; + GibCursor aft_indir_loc_1134 = loc_IntTy_665 + 9; + GibCursor cursor_ptr_1885[3] = {jump_dloc_1125, aft_indir_loc_1133, + aft_indir_loc_1134}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_78 = + _copy_without_ptrs_Tree(indr_1121, cursor_ptr_1806, cursor_ptr_1808, indr_1121); + GibCursor pvrtmp_2446[3]; + + memcpy(pvrtmp_2446, tmp_struct_78.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2447[3]; + + memcpy(pvrtmp_2447, tmp_struct_78.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2448[3]; + + memcpy(pvrtmp_2448, tmp_struct_78.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2449[3]; + + memcpy(pvrtmp_2449, tmp_struct_78.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2450[3]; + + memcpy(pvrtmp_2450, tmp_struct_78.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_79; + + memcpy(return_79.field0, cursor_ptr_1807, sizeof(GibCursor [3])); + memcpy(return_79.field1, pvrtmp_2447, sizeof(GibCursor [3])); + memcpy(return_79.field2, cursor_ptr_1885, sizeof(GibCursor [3])); + memcpy(return_79.field3, pvrtmp_2449, sizeof(GibCursor [3])); + memcpy(return_79.field4, pvrtmp_2450, sizeof(GibCursor [3])); + return return_79; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1896 = arg_98_187_272[1]; + GibCursor soa_field_1_1897 = arg_98_187_272[2]; + uintptr_t tagged_tmpcur_87 = *(uintptr_t *) tmpcur_2406; + GibCursor tmpcur_2457 = GIB_UNTAG(tagged_tmpcur_87); + GibCursor tmpaftercur_2458 = tmpcur_2406 + 8; + uint16_t tmptag_2459 = GIB_GET_TAG(tagged_tmpcur_87); + GibCursor end_from_tagged_dcon_redir_1905 = tmpcur_2457 + + tmptag_2459; + GibCursor field_nxt_1903 = soa_field_0_1896 + 1; + uintptr_t tagged_tmpcur_86 = *(uintptr_t *) field_nxt_1903; + GibCursor tmpcur_2460 = GIB_UNTAG(tagged_tmpcur_86); + GibCursor tmpaftercur_2461 = field_nxt_1903 + 8; + uint16_t tmptag_2462 = GIB_GET_TAG(tagged_tmpcur_86); + GibCursor end_from_tagged_fld_redir_1906 = tmpcur_2460 + + tmptag_2462; + GibCursor field_nxt_1904 = soa_field_1_1897 + 1; + uintptr_t tagged_tmpcur_85 = *(uintptr_t *) field_nxt_1904; + GibCursor tmpcur_2463 = GIB_UNTAG(tagged_tmpcur_85); + GibCursor tmpaftercur_2464 = field_nxt_1904 + 8; + uint16_t tmptag_2465 = GIB_GET_TAG(tagged_tmpcur_85); + GibCursor end_from_tagged_fld_redir_1907 = tmpcur_2463 + + tmptag_2465; + GibCursor indr_1121[3] = {tmpcur_2457, tmpcur_2460, tmpcur_2463}; + GibCursor loc_666 = cursor_ptr_1808[0]; + GibCursor loc_IntTy_667 = cursor_ptr_1808[1]; + GibCursor loc_IntTy_668 = cursor_ptr_1808[2]; + GibCursor copy_dloc_1135 = loc_666 + 0; + GibCursor copy_floc_loc_1137 = loc_IntTy_668 + 0; + GibCursor copy_floc_loc_1136 = loc_IntTy_667 + 0; + GibCursor cursor_ptr_1908[3] = {copy_dloc_1135, copy_floc_loc_1136, + copy_floc_loc_1137}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_83 = + _copy_without_ptrs_Tree(indr_1121, cursor_ptr_1806, cursor_ptr_1908, indr_1121); + GibCursor pvrtmp_2466[3]; + + memcpy(pvrtmp_2466, tmp_struct_83.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2467[3]; + + memcpy(pvrtmp_2467, tmp_struct_83.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2468[3]; + + memcpy(pvrtmp_2468, tmp_struct_83.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2469[3]; + + memcpy(pvrtmp_2469, tmp_struct_83.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2470[3]; + + memcpy(pvrtmp_2470, tmp_struct_83.field4, sizeof(GibCursor [3])); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + return_84; + + memcpy(return_84.field0, pvrtmp_2466, sizeof(GibCursor [3])); + memcpy(return_84.field1, pvrtmp_2467, sizeof(GibCursor [3])); + memcpy(return_84.field2, pvrtmp_2468, sizeof(GibCursor [3])); + memcpy(return_84.field3, pvrtmp_2469, sizeof(GibCursor [3])); + memcpy(return_84.field4, pvrtmp_2470, sizeof(GibCursor [3])); + return return_84; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2405"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_101 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_2097 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_705 = region_2097.start; + GibCursor end_r_705 = region_2097.end; + GibChunk region_2098 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_706 = region_2098.start; + GibCursor end_r_706 = region_2098.end; + GibChunk region_2099 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_707 = region_2099.start; + GibCursor end_r_707 = region_2099.end; + GibCursor reg_ptr_1918[3] = {r_705, r_706, r_707}; + GibCursor reg_cursor_ptr_1919[3] = {end_r_705, end_r_706, end_r_707}; + GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod tmp_struct_88 = + mkTree(reg_cursor_ptr_1919, reg_ptr_1918, 23, 0); + GibCursor pvrtmp_2100[3]; + + memcpy(pvrtmp_2100, tmp_struct_88.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2101[3]; + + memcpy(pvrtmp_2101, tmp_struct_88.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2102[3]; + + memcpy(pvrtmp_2102, tmp_struct_88.field2, sizeof(GibCursor [3])); + + GibChunk region_2107 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_702 = region_2107.start; + GibCursor end_r_702 = region_2107.end; + GibChunk region_2108 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_703 = region_2108.start; + GibCursor end_r_703 = region_2108.end; + GibChunk region_2109 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_704 = region_2109.start; + GibCursor end_r_704 = region_2109.end; + GibCursor reg_ptr_1925[3] = {r_702, r_703, r_704}; + GibCursor reg_cursor_ptr_1926[3] = {end_r_702, end_r_703, end_r_704}; + GibCursor pvrtmp_2121[3]; + GibCursor pvrtmp_2122[3]; + GibCursor pvrtmp_2123[3]; + GibVector *times_93 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_2121; + struct timespec end_pvrtmp_2121; + + for (long long iters_pvrtmp_2121 = 0; iters_pvrtmp_2121 < + gib_get_iters_param(); iters_pvrtmp_2121++) { + if (iters_pvrtmp_2121 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_2121); + + GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3GibCursorPtr3Prod + tmp_struct_89; + + add1Tree(pvrtmp_2100, reg_cursor_ptr_1926, reg_ptr_1925, pvrtmp_2101, &tmp_struct_89); + + GibCursor pvrtmp_2110[3]; + + memcpy(pvrtmp_2110, tmp_struct_89.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2111[3]; + + memcpy(pvrtmp_2111, tmp_struct_89.field1, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2112[3]; + + memcpy(pvrtmp_2112, tmp_struct_89.field2, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2113[3]; + + memcpy(pvrtmp_2113, tmp_struct_89.field3, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2114[3]; + + memcpy(pvrtmp_2114, tmp_struct_89.field4, sizeof(GibCursor [3])); + memcpy(pvrtmp_2121, pvrtmp_2111, sizeof(GibCursor [3])); + memcpy(pvrtmp_2122, pvrtmp_2113, sizeof(GibCursor [3])); + memcpy(pvrtmp_2123, pvrtmp_2114, sizeof(GibCursor [3])); + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_2121); + if (iters_pvrtmp_2121 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + + memcpy(pvrtmp_2100, tmp_struct_88.field0, sizeof(GibCursor [3])); + + memcpy(pvrtmp_2101, tmp_struct_88.field1, sizeof(GibCursor [3])); + + + reg_cursor_ptr_1926[0] = end_r_702; + reg_cursor_ptr_1926[1] = end_r_703; + reg_cursor_ptr_1926[2] = end_r_704; + + reg_ptr_1925[0] = r_702; + reg_ptr_1925[1] = r_703; + reg_ptr_1925[2] = r_704; + + + double itertime_90 = gib_difftimespecs(&begin_pvrtmp_2121, + &end_pvrtmp_2121); + + printf("itertime: %lf\n", itertime_90); + gib_vector_inplace_update(times_93, iters_pvrtmp_2121, &itertime_90); + } + gib_vector_inplace_sort(times_93, gib_compare_doubles); + + double *tmp_94 = (double *) gib_vector_nth(times_93, gib_get_iters_param() / + 2); + double selftimed_92 = *tmp_94; + double batchtime_91 = gib_sum_timing_array(times_93); + + gib_print_timing_array(times_93); + gib_vector_free(times_93); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_91); + printf("SELFTIMED: %e\n", selftimed_92); + + GibInt timed_1992; + GibVector *times_99 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_1992; + struct timespec end_timed_1992; + + for (long long iters_timed_1992 = 0; iters_timed_1992 < + gib_get_iters_param(); iters_timed_1992++) { + if (iters_timed_1992 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_1992); + + GibCursorPtr3GibCursorPtr3GibIntProd tmp_struct_95 = + sumTree(reg_cursor_ptr_1926, pvrtmp_2122); + GibCursor pvrtmp_2131[3]; + + memcpy(pvrtmp_2131, tmp_struct_95.field0, sizeof(GibCursor [3])); + + GibCursor pvrtmp_2132[3]; + + memcpy(pvrtmp_2132, tmp_struct_95.field1, sizeof(GibCursor [3])); + + GibInt pvrtmp_2133 = tmp_struct_95.field2; + + timed_1992 = pvrtmp_2133; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_1992); + if (iters_timed_1992 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_96 = gib_difftimespecs(&begin_timed_1992, + &end_timed_1992); + + printf("itertime: %lf\n", itertime_96); + gib_vector_inplace_update(times_99, iters_timed_1992, &itertime_96); + } + gib_vector_inplace_sort(times_99, gib_compare_doubles); + + double *tmp_100 = (double *) gib_vector_nth(times_99, + gib_get_iters_param() / 2); + double selftimed_98 = *tmp_100; + double batchtime_97 = gib_sum_timing_array(times_99); + + gib_print_timing_array(times_99); + gib_vector_free(times_99); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_97); + printf("SELFTIMED: %e\n", selftimed_98); + printf("%ld", timed_1992); + printf("\n"); + + int exit_102 = gib_exit(); + + return exit_102; +} + + +// gcc -std=gnu11 -O3 -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + +// gcc -std=gnu11 -g -flto -D_GIBBON_GENGC=0 -D_GIBBON_SIMPLE_WRITE_BARRIER=0 -D_GIBBON_EAGER_PROMOTION=1 -o /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.exe -I/home/vidushs/Applications/src/gibbon/gibbon-rts/build -L/home/vidushs/Applications/src/gibbon/gibbon-rts/build -Wl,-rpath=/home/vidushs/Applications/src/gibbon/gibbon-rts/build /home/vidushs/Applications/src/gibbon/microbench/manual_soa_examples/MonoTree.soa.c /home/vidushs/Applications/src/gibbon/gibbon-rts/build/gibbon_rts.o -lm -lgibbon_rts_ng + diff --git a/microbench/manual_soa_examples/list.aos.c b/microbench/manual_soa_examples/list.aos.c new file mode 100644 index 000000000..49c9e0dbb --- /dev/null +++ b/microbench/manual_soa_examples/list.aos.c @@ -0,0 +1,970 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +GibCursorGibCursorProd _print_List(GibCursor end_r_280, + GibCursor arg_74_88_130); +GibCursorGibCursorProd _traverse_List(GibCursor end_r_283, + GibCursor arg_69_99_141); +GibCursorGibCursorGibCursorProd mkList(GibCursor end_r_286, GibCursor loc_284, + GibInt length_24_103_145); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_List(GibCursor end_r_290, GibCursor end_r_292, GibCursor loc_288, + GibCursor arg_59_105_149); +GibCursorGibCursorGibIntProd sumList(GibCursor end_r_295, + GibCursor lst_26_110_154); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_List(GibCursor end_r_299, GibCursor end_r_301, + GibCursor loc_297, GibCursor arg_64_115_158); +GibCursorGibCursorGibCursorGibCursorGibCursorProd add1(GibCursor end_r_305, + GibCursor end_r_307, + GibCursor loc_303, + GibCursor lst_31_120_163); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + List_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[2]; + + field_tys[0] = List_T; + error = gib_info_table_insert_packed_dcon(List_T, 0, 8, 0, 1, 1, field_tys, + 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(List_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(827, ")"); + gib_add_symbol(828, "(Nil"); + gib_add_symbol(829, "(Cons"); + gib_add_symbol(830, " ->r "); + gib_add_symbol(831, " ->i "); + gib_add_symbol(832, " "); +} +GibCursorGibCursorProd _print_List(GibCursor end_r_280, GibCursor arg_74_88_130) +{ + GibPackedTag tmpval_866 = *(GibPackedTag *) arg_74_88_130; + GibCursor tmpcur_867 = arg_74_88_130 + 1; + + + switch_882: + ; + switch (tmpval_866) { + + case 0: + { + GibInt tmpval_868 = *(GibInt *) tmpcur_867; + GibCursor tmpcur_869 = tmpcur_867 + sizeof(GibInt); + GibCursor jump_394 = tmpcur_867 + 8; + unsigned char wildcard_79_91_133 = gib_print_symbol(829); + unsigned char wildcard_82_92_134 = gib_print_symbol(832); + unsigned char y_77_93_135 = printf("%ld", tmpval_868); + unsigned char wildcard_81_94_136 = gib_print_symbol(832); + GibCursorGibCursorProd tmp_struct_0 = + _print_List(end_r_280, tmpcur_869); + GibCursor pvrtmp_870 = tmp_struct_0.field0; + GibCursor pvrtmp_871 = tmp_struct_0.field1; + unsigned char wildcard_80_96_138 = gib_print_symbol(827); + GibCursorGibCursorProd return_1; + + return_1.field0 = pvrtmp_870; + return_1.field1 = pvrtmp_871; + return return_1; + break; + } + + case 1: + { + GibCursor jump_loc_397 = arg_74_88_130 + 1; + unsigned char wildcard_83_97_139 = gib_print_symbol(828); + unsigned char wildcard_84_98_140 = gib_print_symbol(827); + GibCursorGibCursorProd return_2; + + return_2.field0 = end_r_280; + return_2.field1 = jump_loc_397; + return return_2; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) tmpcur_867; + GibCursor tmpcur_872 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_873 = tmpcur_867 + 8; + uint16_t tmptag_874 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_indr_431 = tmpcur_872 + tmptag_874; + GibCursor jump_loc_433 = tmpcur_867 + 8; + unsigned char wildcard_436 = gib_print_symbol(831); + GibCursorGibCursorProd tmp_struct_3 = + _print_List(tmpcur_872, tmpcur_872); + GibCursor pvrtmp_875 = tmp_struct_3.field0; + GibCursor pvrtmp_876 = tmp_struct_3.field1; + GibCursorGibCursorProd return_4; + + return_4.field0 = end_r_280; + return_4.field1 = jump_loc_433; + return return_4; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_8 = *(uintptr_t *) tmpcur_867; + GibCursor tmpcur_877 = GIB_UNTAG(tagged_tmpcur_8); + GibCursor tmpaftercur_878 = tmpcur_867 + 8; + uint16_t tmptag_879 = GIB_GET_TAG(tagged_tmpcur_8); + GibCursor end_from_tagged_indr_431 = tmpcur_877 + tmptag_879; + unsigned char wildcard_436 = gib_print_symbol(830); + GibCursorGibCursorProd tmp_struct_6 = + _print_List(tmpcur_877, tmpcur_877); + GibCursor pvrtmp_880 = tmp_struct_6.field0; + GibCursor pvrtmp_881 = tmp_struct_6.field1; + GibCursorGibCursorProd return_7; + + return_7.field0 = pvrtmp_880; + return_7.field1 = pvrtmp_881; + return return_7; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_866"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_List(GibCursor end_r_283, + GibCursor arg_69_99_141) +{ + GibPackedTag tmpval_883 = *(GibPackedTag *) arg_69_99_141; + GibCursor tmpcur_884 = arg_69_99_141 + 1; + + + switch_899: + ; + switch (tmpval_883) { + + case 0: + { + GibInt tmpval_885 = *(GibInt *) tmpcur_884; + GibCursor tmpcur_886 = tmpcur_884 + sizeof(GibInt); + GibCursor jump_399 = tmpcur_884 + 8; + GibCursorGibCursorProd tmp_struct_9 = + _traverse_List(end_r_283, tmpcur_886); + GibCursor pvrtmp_887 = tmp_struct_9.field0; + GibCursor pvrtmp_888 = tmp_struct_9.field1; + GibCursorGibCursorProd return_10; + + return_10.field0 = pvrtmp_887; + return_10.field1 = pvrtmp_888; + return return_10; + break; + } + + case 1: + { + GibCursor jump_loc_402 = arg_69_99_141 + 1; + GibCursorGibCursorProd return_11; + + return_11.field0 = end_r_283; + return_11.field1 = jump_loc_402; + return return_11; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_14 = *(uintptr_t *) tmpcur_884; + GibCursor tmpcur_889 = GIB_UNTAG(tagged_tmpcur_14); + GibCursor tmpaftercur_890 = tmpcur_884 + 8; + uint16_t tmptag_891 = GIB_GET_TAG(tagged_tmpcur_14); + GibCursor end_from_tagged_indr_437 = tmpcur_889 + tmptag_891; + GibCursor jump_loc_439 = tmpcur_884 + 8; + GibCursorGibCursorProd tmp_struct_12 = + _traverse_List(tmpcur_889, tmpcur_889); + GibCursor pvrtmp_892 = tmp_struct_12.field0; + GibCursor pvrtmp_893 = tmp_struct_12.field1; + GibCursorGibCursorProd return_13; + + return_13.field0 = end_r_283; + return_13.field1 = jump_loc_439; + return return_13; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_17 = *(uintptr_t *) tmpcur_884; + GibCursor tmpcur_894 = GIB_UNTAG(tagged_tmpcur_17); + GibCursor tmpaftercur_895 = tmpcur_884 + 8; + uint16_t tmptag_896 = GIB_GET_TAG(tagged_tmpcur_17); + GibCursor end_from_tagged_indr_437 = tmpcur_894 + tmptag_896; + GibCursorGibCursorProd tmp_struct_15 = + _traverse_List(tmpcur_894, tmpcur_894); + GibCursor pvrtmp_897 = tmp_struct_15.field0; + GibCursor pvrtmp_898 = tmp_struct_15.field1; + GibCursorGibCursorProd return_16; + + return_16.field0 = pvrtmp_897; + return_16.field1 = pvrtmp_898; + return return_16; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_883"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorProd mkList(GibCursor end_r_286, GibCursor loc_284, + GibInt length_24_103_145) +{ + if (loc_284 + 18 > end_r_286) { + gib_grow_region(&loc_284, &end_r_286); + } + + GibBool fltIf_124_146 = length_24_103_145 <= 0; + + if (fltIf_124_146) { + *(GibPackedTag *) loc_284 = 1; + + GibCursor writetag_563 = loc_284 + 1; + GibCursor after_tag_564 = loc_284 + 1; + GibCursorGibCursorGibCursorProd return_18; + + return_18.field0 = end_r_286; + return_18.field1 = loc_284; + return_18.field2 = after_tag_564; + return return_18; + } else { + GibInt fltAppE_125_147 = length_24_103_145 - 1; + GibCursor loc_335 = loc_284 + 1; + GibCursor loc_336 = loc_335 + 8; + + *(GibPackedTag *) loc_284 = 0; + + GibCursor writetag_572 = loc_284 + 1; + GibCursor after_tag_573 = loc_284 + 1; + + *(GibInt *) after_tag_573 = length_24_103_145; + + GibCursor writecur_577 = after_tag_573 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd tmp_struct_19 = + mkList(end_r_286, loc_336, fltAppE_125_147); + GibCursor pvrtmp_904 = tmp_struct_19.field0; + GibCursor pvrtmp_905 = tmp_struct_19.field1; + GibCursor pvrtmp_906 = tmp_struct_19.field2; + GibCursorGibCursorGibCursorProd return_20; + + return_20.field0 = pvrtmp_904; + return_20.field1 = loc_284; + return_20.field2 = pvrtmp_906; + return return_20; + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_List(GibCursor end_r_290, + GibCursor end_r_292, + GibCursor loc_288, + GibCursor arg_59_105_149) +{ + if (loc_288 + 18 > end_r_292) { + gib_grow_region(&loc_288, &end_r_292); + } + + GibPackedTag tmpval_915 = *(GibPackedTag *) arg_59_105_149; + GibCursor tmpcur_916 = arg_59_105_149 + 1; + + + switch_964: + ; + switch (tmpval_915) { + + case 0: + { + GibInt tmpval_917 = *(GibInt *) tmpcur_916; + GibCursor tmpcur_918 = tmpcur_916 + sizeof(GibInt); + GibCursor jump_406 = tmpcur_916 + 8; + GibCursor loc_347 = loc_288 + 1; + GibCursor loc_348 = loc_347 + 8; + + *(GibPackedTag *) loc_288 = 0; + + GibCursor writetag_587 = loc_288 + 1; + GibCursor after_tag_588 = loc_288 + 1; + + *(GibInt *) after_tag_588 = tmpval_917; + + GibCursor writecur_592 = after_tag_588 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_24 = + _copy_List(end_r_290, end_r_292, loc_348, tmpcur_918); + GibCursor pvrtmp_919 = tmp_struct_24.field0; + GibCursor pvrtmp_920 = tmp_struct_24.field1; + GibCursor pvrtmp_921 = tmp_struct_24.field2; + GibCursor pvrtmp_922 = tmp_struct_24.field3; + GibCursor pvrtmp_923 = tmp_struct_24.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_25; + + return_25.field0 = pvrtmp_919; + return_25.field1 = pvrtmp_920; + return_25.field2 = pvrtmp_921; + return_25.field3 = loc_288; + return_25.field4 = pvrtmp_923; + return return_25; + break; + } + + case 1: + { + GibCursor jump_loc_409 = arg_59_105_149 + 1; + + *(GibPackedTag *) loc_288 = 1; + + GibCursor writetag_597 = loc_288 + 1; + GibCursor after_tag_598 = loc_288 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_26; + + return_26.field0 = end_r_290; + return_26.field1 = end_r_292; + return_26.field2 = jump_loc_409; + return_26.field3 = loc_288; + return_26.field4 = after_tag_598; + return return_26; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_29 = *(uintptr_t *) tmpcur_916; + GibCursor tmpcur_936 = GIB_UNTAG(tagged_tmpcur_29); + GibCursor tmpaftercur_937 = tmpcur_916 + 8; + uint16_t tmptag_938 = GIB_GET_TAG(tagged_tmpcur_29); + GibCursor end_from_tagged_indr_443 = tmpcur_936 + tmptag_938; + GibCursor jump_loc_445 = tmpcur_916 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_27 = + _copy_List(tmpcur_936, end_r_292, loc_288, tmpcur_936); + GibCursor pvrtmp_939 = tmp_struct_27.field0; + GibCursor pvrtmp_940 = tmp_struct_27.field1; + GibCursor pvrtmp_941 = tmp_struct_27.field2; + GibCursor pvrtmp_942 = tmp_struct_27.field3; + GibCursor pvrtmp_943 = tmp_struct_27.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_28; + + return_28.field0 = end_r_290; + return_28.field1 = pvrtmp_940; + return_28.field2 = jump_loc_445; + return_28.field3 = pvrtmp_942; + return_28.field4 = pvrtmp_943; + return return_28; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_32 = *(uintptr_t *) tmpcur_916; + GibCursor tmpcur_950 = GIB_UNTAG(tagged_tmpcur_32); + GibCursor tmpaftercur_951 = tmpcur_916 + 8; + uint16_t tmptag_952 = GIB_GET_TAG(tagged_tmpcur_32); + GibCursor end_from_tagged_indr_443 = tmpcur_950 + tmptag_952; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_30 = + _copy_List(tmpcur_950, end_r_292, loc_288, tmpcur_950); + GibCursor pvrtmp_953 = tmp_struct_30.field0; + GibCursor pvrtmp_954 = tmp_struct_30.field1; + GibCursor pvrtmp_955 = tmp_struct_30.field2; + GibCursor pvrtmp_956 = tmp_struct_30.field3; + GibCursor pvrtmp_957 = tmp_struct_30.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_31; + + return_31.field0 = pvrtmp_953; + return_31.field1 = pvrtmp_954; + return_31.field2 = pvrtmp_955; + return_31.field3 = pvrtmp_956; + return_31.field4 = pvrtmp_957; + return return_31; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_915"); + exit(1); + } + } +} +GibCursorGibCursorGibIntProd sumList(GibCursor end_r_295, + GibCursor lst_26_110_154) +{ + GibPackedTag tmpval_965 = *(GibPackedTag *) lst_26_110_154; + GibCursor tmpcur_966 = lst_26_110_154 + 1; + + + switch_984: + ; + switch (tmpval_965) { + + case 1: + { + GibCursor jump_loc_412 = lst_26_110_154 + 1; + GibCursorGibCursorGibIntProd return_36; + + return_36.field0 = end_r_295; + return_36.field1 = jump_loc_412; + return_36.field2 = 0; + return return_36; + break; + } + + case 0: + { + GibInt tmpval_967 = *(GibInt *) tmpcur_966; + GibCursor tmpcur_968 = tmpcur_966 + sizeof(GibInt); + GibCursor jump_413 = tmpcur_966 + 8; + GibCursorGibCursorGibIntProd tmp_struct_37 = + sumList(end_r_295, tmpcur_968); + GibCursor pvrtmp_969 = tmp_struct_37.field0; + GibCursor pvrtmp_970 = tmp_struct_37.field1; + GibInt pvrtmp_971 = tmp_struct_37.field2; + GibInt tailprim_415 = tmpval_967 + pvrtmp_971; + GibCursorGibCursorGibIntProd return_38; + + return_38.field0 = pvrtmp_969; + return_38.field1 = pvrtmp_970; + return_38.field2 = tailprim_415; + return return_38; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_41 = *(uintptr_t *) tmpcur_966; + GibCursor tmpcur_972 = GIB_UNTAG(tagged_tmpcur_41); + GibCursor tmpaftercur_973 = tmpcur_966 + 8; + uint16_t tmptag_974 = GIB_GET_TAG(tagged_tmpcur_41); + GibCursor end_from_tagged_indr_449 = tmpcur_972 + tmptag_974; + GibCursor jump_loc_451 = tmpcur_966 + 8; + GibCursorGibCursorGibIntProd tmp_struct_39 = + sumList(tmpcur_972, tmpcur_972); + GibCursor pvrtmp_975 = tmp_struct_39.field0; + GibCursor pvrtmp_976 = tmp_struct_39.field1; + GibInt pvrtmp_977 = tmp_struct_39.field2; + GibCursorGibCursorGibIntProd return_40; + + return_40.field0 = end_r_295; + return_40.field1 = jump_loc_451; + return_40.field2 = pvrtmp_977; + return return_40; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_44 = *(uintptr_t *) tmpcur_966; + GibCursor tmpcur_978 = GIB_UNTAG(tagged_tmpcur_44); + GibCursor tmpaftercur_979 = tmpcur_966 + 8; + uint16_t tmptag_980 = GIB_GET_TAG(tagged_tmpcur_44); + GibCursor end_from_tagged_indr_449 = tmpcur_978 + tmptag_980; + GibCursorGibCursorGibIntProd tmp_struct_42 = + sumList(tmpcur_978, tmpcur_978); + GibCursor pvrtmp_981 = tmp_struct_42.field0; + GibCursor pvrtmp_982 = tmp_struct_42.field1; + GibInt pvrtmp_983 = tmp_struct_42.field2; + GibCursorGibCursorGibIntProd return_43; + + return_43.field0 = pvrtmp_981; + return_43.field1 = pvrtmp_982; + return_43.field2 = pvrtmp_983; + return return_43; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_965"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_List(GibCursor end_r_299, + GibCursor end_r_301, + GibCursor loc_297, + GibCursor arg_64_115_158) +{ + GibPackedTag tmpval_985 = *(GibPackedTag *) arg_64_115_158; + GibCursor tmpcur_986 = arg_64_115_158 + 1; + + + switch_1034: + ; + switch (tmpval_985) { + + case 0: + { + GibInt tmpval_987 = *(GibInt *) tmpcur_986; + GibCursor tmpcur_988 = tmpcur_986 + sizeof(GibInt); + GibCursor jump_416 = tmpcur_986 + 8; + GibCursor loc_366 = loc_297 + 1; + GibCursor loc_367 = loc_366 + 8; + + *(GibPackedTag *) loc_297 = 0; + + GibCursor writetag_634 = loc_297 + 1; + GibCursor after_tag_635 = loc_297 + 1; + + *(GibInt *) after_tag_635 = tmpval_987; + + GibCursor writecur_639 = after_tag_635 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_45 = + _copy_without_ptrs_List(end_r_299, end_r_301, loc_367, tmpcur_988); + GibCursor pvrtmp_989 = tmp_struct_45.field0; + GibCursor pvrtmp_990 = tmp_struct_45.field1; + GibCursor pvrtmp_991 = tmp_struct_45.field2; + GibCursor pvrtmp_992 = tmp_struct_45.field3; + GibCursor pvrtmp_993 = tmp_struct_45.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_46; + + return_46.field0 = pvrtmp_989; + return_46.field1 = pvrtmp_990; + return_46.field2 = pvrtmp_991; + return_46.field3 = loc_297; + return_46.field4 = pvrtmp_993; + return return_46; + break; + } + + case 1: + { + GibCursor jump_loc_419 = arg_64_115_158 + 1; + + *(GibPackedTag *) loc_297 = 1; + + GibCursor writetag_644 = loc_297 + 1; + GibCursor after_tag_645 = loc_297 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_47; + + return_47.field0 = end_r_299; + return_47.field1 = end_r_301; + return_47.field2 = jump_loc_419; + return_47.field3 = loc_297; + return_47.field4 = after_tag_645; + return return_47; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_50 = *(uintptr_t *) tmpcur_986; + GibCursor tmpcur_1006 = GIB_UNTAG(tagged_tmpcur_50); + GibCursor tmpaftercur_1007 = tmpcur_986 + 8; + uint16_t tmptag_1008 = GIB_GET_TAG(tagged_tmpcur_50); + GibCursor end_from_tagged_indr_455 = tmpcur_1006 + tmptag_1008; + GibCursor jump_loc_457 = tmpcur_986 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_48 = + _copy_without_ptrs_List(tmpcur_1006, end_r_301, loc_297, tmpcur_1006); + GibCursor pvrtmp_1009 = tmp_struct_48.field0; + GibCursor pvrtmp_1010 = tmp_struct_48.field1; + GibCursor pvrtmp_1011 = tmp_struct_48.field2; + GibCursor pvrtmp_1012 = tmp_struct_48.field3; + GibCursor pvrtmp_1013 = tmp_struct_48.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_49; + + return_49.field0 = end_r_299; + return_49.field1 = pvrtmp_1010; + return_49.field2 = jump_loc_457; + return_49.field3 = pvrtmp_1012; + return_49.field4 = pvrtmp_1013; + return return_49; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_53 = *(uintptr_t *) tmpcur_986; + GibCursor tmpcur_1020 = GIB_UNTAG(tagged_tmpcur_53); + GibCursor tmpaftercur_1021 = tmpcur_986 + 8; + uint16_t tmptag_1022 = GIB_GET_TAG(tagged_tmpcur_53); + GibCursor end_from_tagged_indr_455 = tmpcur_1020 + tmptag_1022; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_51 = + _copy_without_ptrs_List(tmpcur_1020, end_r_301, loc_297, tmpcur_1020); + GibCursor pvrtmp_1023 = tmp_struct_51.field0; + GibCursor pvrtmp_1024 = tmp_struct_51.field1; + GibCursor pvrtmp_1025 = tmp_struct_51.field2; + GibCursor pvrtmp_1026 = tmp_struct_51.field3; + GibCursor pvrtmp_1027 = tmp_struct_51.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_52; + + return_52.field0 = pvrtmp_1023; + return_52.field1 = pvrtmp_1024; + return_52.field2 = pvrtmp_1025; + return_52.field3 = pvrtmp_1026; + return_52.field4 = pvrtmp_1027; + return return_52; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_985"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd add1(GibCursor end_r_305, + GibCursor end_r_307, + GibCursor loc_303, + GibCursor lst_31_120_163) +{ + if (loc_303 + 18 > end_r_307) { + gib_grow_region(&loc_303, &end_r_307); + } + + GibPackedTag tmpval_1035 = *(GibPackedTag *) lst_31_120_163; + GibCursor tmpcur_1036 = lst_31_120_163 + 1; + + + switch_1084: + ; + switch (tmpval_1035) { + + case 1: + { + GibCursor jump_loc_421 = lst_31_120_163 + 1; + + *(GibPackedTag *) loc_303 = 1; + + GibCursor writetag_663 = loc_303 + 1; + GibCursor after_tag_664 = loc_303 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_54; + + return_54.field0 = end_r_305; + return_54.field1 = end_r_307; + return_54.field2 = jump_loc_421; + return_54.field3 = loc_303; + return_54.field4 = after_tag_664; + return return_54; + break; + } + + case 0: + { + GibInt tmpval_1041 = *(GibInt *) tmpcur_1036; + GibCursor tmpcur_1042 = tmpcur_1036 + sizeof(GibInt); + GibCursor jump_423 = tmpcur_1036 + 8; + GibInt i1_34_123_166 = tmpval_1041 + 1; + GibCursor loc_380 = loc_303 + 1; + GibCursor loc_381 = loc_380 + 8; + + *(GibPackedTag *) loc_303 = 0; + + GibCursor writetag_675 = loc_303 + 1; + GibCursor after_tag_676 = loc_303 + 1; + + *(GibInt *) after_tag_676 = i1_34_123_166; + + GibCursor writecur_680 = after_tag_676 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_55 = + add1(end_r_305, end_r_307, loc_381, tmpcur_1042); + GibCursor pvrtmp_1043 = tmp_struct_55.field0; + GibCursor pvrtmp_1044 = tmp_struct_55.field1; + GibCursor pvrtmp_1045 = tmp_struct_55.field2; + GibCursor pvrtmp_1046 = tmp_struct_55.field3; + GibCursor pvrtmp_1047 = tmp_struct_55.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_56; + + return_56.field0 = pvrtmp_1043; + return_56.field1 = pvrtmp_1044; + return_56.field2 = pvrtmp_1045; + return_56.field3 = loc_303; + return_56.field4 = pvrtmp_1047; + return return_56; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_59 = *(uintptr_t *) tmpcur_1036; + GibCursor tmpcur_1056 = GIB_UNTAG(tagged_tmpcur_59); + GibCursor tmpaftercur_1057 = tmpcur_1036 + 8; + uint16_t tmptag_1058 = GIB_GET_TAG(tagged_tmpcur_59); + GibCursor end_from_tagged_indr_461 = tmpcur_1056 + tmptag_1058; + GibCursor jump_loc_463 = tmpcur_1036 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_57 = + add1(tmpcur_1056, end_r_307, loc_303, tmpcur_1056); + GibCursor pvrtmp_1059 = tmp_struct_57.field0; + GibCursor pvrtmp_1060 = tmp_struct_57.field1; + GibCursor pvrtmp_1061 = tmp_struct_57.field2; + GibCursor pvrtmp_1062 = tmp_struct_57.field3; + GibCursor pvrtmp_1063 = tmp_struct_57.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_58; + + return_58.field0 = end_r_305; + return_58.field1 = pvrtmp_1060; + return_58.field2 = jump_loc_463; + return_58.field3 = pvrtmp_1062; + return_58.field4 = pvrtmp_1063; + return return_58; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_62 = *(uintptr_t *) tmpcur_1036; + GibCursor tmpcur_1070 = GIB_UNTAG(tagged_tmpcur_62); + GibCursor tmpaftercur_1071 = tmpcur_1036 + 8; + uint16_t tmptag_1072 = GIB_GET_TAG(tagged_tmpcur_62); + GibCursor end_from_tagged_indr_461 = tmpcur_1070 + tmptag_1072; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_60 = + add1(tmpcur_1070, end_r_307, loc_303, tmpcur_1070); + GibCursor pvrtmp_1073 = tmp_struct_60.field0; + GibCursor pvrtmp_1074 = tmp_struct_60.field1; + GibCursor pvrtmp_1075 = tmp_struct_60.field2; + GibCursor pvrtmp_1076 = tmp_struct_60.field3; + GibCursor pvrtmp_1077 = tmp_struct_60.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_61; + + return_61.field0 = pvrtmp_1073; + return_61.field1 = pvrtmp_1074; + return_61.field2 = pvrtmp_1075; + return_61.field3 = pvrtmp_1076; + return_61.field4 = pvrtmp_1077; + return return_61; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1035"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_79 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_833 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_320 = region_833.start; + GibCursor end_r_320 = region_833.end; + GibCursorGibCursorGibCursorProd tmp_struct_66 = + mkList(end_r_320, r_320, 10000000); + GibCursor pvrtmp_834 = tmp_struct_66.field0; + GibCursor pvrtmp_835 = tmp_struct_66.field1; + GibCursor pvrtmp_836 = tmp_struct_66.field2; + GibChunk region_841 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_319 = region_841.start; + GibCursor end_r_319 = region_841.end; + GibCursor pvrtmp_853; + GibCursor pvrtmp_854; + GibCursor pvrtmp_855; + GibVector *times_71 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_853; + struct timespec end_pvrtmp_853; + + for (long long iters_pvrtmp_853 = 0; iters_pvrtmp_853 < + gib_get_iters_param(); iters_pvrtmp_853++) { + if (iters_pvrtmp_853 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_853); + + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_67 = + add1(pvrtmp_834, end_r_319, r_319, pvrtmp_835); + GibCursor pvrtmp_842 = tmp_struct_67.field0; + GibCursor pvrtmp_843 = tmp_struct_67.field1; + GibCursor pvrtmp_844 = tmp_struct_67.field2; + GibCursor pvrtmp_845 = tmp_struct_67.field3; + GibCursor pvrtmp_846 = tmp_struct_67.field4; + + pvrtmp_853 = pvrtmp_843; + pvrtmp_854 = pvrtmp_845; + pvrtmp_855 = pvrtmp_846; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_853); + if (iters_pvrtmp_853 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_68 = gib_difftimespecs(&begin_pvrtmp_853, + &end_pvrtmp_853); + + printf("itertime: %lf\n", itertime_68); + gib_vector_inplace_update(times_71, iters_pvrtmp_853, &itertime_68); + } + gib_vector_inplace_sort(times_71, gib_compare_doubles); + + double *tmp_72 = (double *) gib_vector_nth(times_71, gib_get_iters_param() / + 2); + double selftimed_70 = *tmp_72; + double batchtime_69 = gib_sum_timing_array(times_71); + + gib_print_timing_array(times_71); + gib_vector_free(times_71); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_69); + printf("SELFTIMED: %e\n", selftimed_70); + + GibInt timed_744; + GibVector *times_77 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_744; + struct timespec end_timed_744; + + for (long long iters_timed_744 = 0; iters_timed_744 < gib_get_iters_param(); + iters_timed_744++) { + if (iters_timed_744 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_744); + + GibCursorGibCursorGibIntProd tmp_struct_73 = + sumList(end_r_319, pvrtmp_854); + GibCursor pvrtmp_863 = tmp_struct_73.field0; + GibCursor pvrtmp_864 = tmp_struct_73.field1; + GibInt pvrtmp_865 = tmp_struct_73.field2; + + timed_744 = pvrtmp_865; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_744); + if (iters_timed_744 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_74 = gib_difftimespecs(&begin_timed_744, + &end_timed_744); + + printf("itertime: %lf\n", itertime_74); + gib_vector_inplace_update(times_77, iters_timed_744, &itertime_74); + } + gib_vector_inplace_sort(times_77, gib_compare_doubles); + + double *tmp_78 = (double *) gib_vector_nth(times_77, gib_get_iters_param() / + 2); + double selftimed_76 = *tmp_78; + double batchtime_75 = gib_sum_timing_array(times_77); + + gib_print_timing_array(times_77); + gib_vector_free(times_77); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_75); + printf("SELFTIMED: %e\n", selftimed_76); + printf("%ld", timed_744); + printf("\n"); + + int exit_80 = gib_exit(); + + return exit_80; +} \ No newline at end of file diff --git a/microbench/manual_soa_examples/list.soa.c b/microbench/manual_soa_examples/list.soa.c new file mode 100644 index 000000000..e87a87673 --- /dev/null +++ b/microbench/manual_soa_examples/list.soa.c @@ -0,0 +1,1535 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorPtr2Prod_struct { + GibCursor field0[2]; + } GibCursorPtr2Prod; +typedef struct GibCursorPtr2GibCursorPtr2Prod_struct { + GibCursor field0[2]; + GibCursor field1[2]; + } GibCursorPtr2GibCursorPtr2Prod; +typedef struct GibCursorPtr2GibCursorPtr2GibIntProd_struct { + GibCursor field0[2]; + GibCursor field1[2]; + GibInt field2; + } GibCursorPtr2GibCursorPtr2GibIntProd; +typedef struct GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod_struct { + GibCursor field0[2]; + GibCursor field1[2]; + GibCursor field2[2]; + } GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod; +typedef struct GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod_struct { + GibCursor field0[2]; + GibCursor field1[2]; + GibCursor field2[2]; + GibCursor field3[2]; + GibCursor field4[2]; + } GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod; +GibCursorPtr2GibCursorPtr2Prod _print_List(GibCursor cursor_ptr_728[2], + GibCursor arg_74_88_130[2]); +GibCursorPtr2GibCursorPtr2Prod _traverse_List(GibCursor cursor_ptr_784[2], + GibCursor arg_69_99_141[2]); +GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod mkList(GibCursor cursor_ptr_839[2], + GibCursor cursor_ptr_840[2], + GibInt length_24_103_145); +GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod +_copy_List(GibCursor cursor_ptr_867[2], GibCursor cursor_ptr_866[2], + GibCursor cursor_ptr_868[2], GibCursor arg_59_105_149[2]); +GibCursorPtr2GibCursorPtr2GibIntProd sumList(GibCursor cursor_ptr_954[2], + GibCursor lst_26_110_154[2]); +GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod +_copy_without_ptrs_List(GibCursor cursor_ptr_1011[2], + GibCursor cursor_ptr_1010[2], + GibCursor cursor_ptr_1012[2], + GibCursor arg_64_115_158[2]); +GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod +add1(GibCursor cursor_ptr_1098[2], GibCursor cursor_ptr_1097[2], + GibCursor cursor_ptr_1099[2], GibCursor lst_31_120_163[2]); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + List_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(8); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[2]; + + field_tys[0] = List_T; + error = gib_info_table_insert_packed_dcon(List_T, 0, 8, 0, 1, 1, field_tys, + 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(List_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(1333, ")"); + gib_add_symbol(1334, "(Nil"); + gib_add_symbol(1335, "(Cons"); + gib_add_symbol(1336, " ->r "); + gib_add_symbol(1337, " ->i "); + gib_add_symbol(1338, " "); +} +GibCursorPtr2GibCursorPtr2Prod _print_List(GibCursor cursor_ptr_728[2], + GibCursor arg_74_88_130[2]) +{ + GibCursor end_r_336 = cursor_ptr_728[0]; + GibCursor end_r_337 = cursor_ptr_728[1]; + GibCursor dcon_731 = arg_74_88_130[0]; + GibPackedTag tmpval_1374 = *(GibPackedTag *) dcon_731; + GibCursor tmpcur_1375 = dcon_731 + 1; + + + switch_1396: + ; + switch (tmpval_1374) { + + case 0: + { + GibCursor soa_field_0_733 = arg_74_88_130[1]; + GibInt tmpval_1376 = *(GibInt *) soa_field_0_733; + GibCursor tmpcur_1377 = soa_field_0_733 + sizeof(GibInt); + GibCursor cursor_ptr_730[2] = {tmpcur_1375, tmpcur_1377}; + GibCursor loc_334 = arg_74_88_130[0]; + GibCursor jumpf_dloc_504 = loc_334 + 1; + GibCursor loc_IntTy_335 = arg_74_88_130[1]; + GibCursor jumpf_floc_loc_505 = soa_field_0_733 + 8; + GibCursor loc_401 = jumpf_dloc_504 + 0; + GibCursor loc_400 = jumpf_floc_loc_505 + 0; + GibCursor cursor_ptr_737[2] = {jumpf_dloc_504, jumpf_floc_loc_505}; + unsigned char wildcard_79_91_133 = gib_print_symbol(1335); + unsigned char wildcard_82_92_134 = gib_print_symbol(1338); + unsigned char y_77_93_135 = printf("%ld", tmpval_1376); + unsigned char wildcard_81_94_136 = gib_print_symbol(1338); + GibCursorPtr2GibCursorPtr2Prod tmp_struct_0 = + _print_List(cursor_ptr_728, cursor_ptr_730); + GibCursor pvrtmp_1378[2]; + + memcpy(pvrtmp_1378, tmp_struct_0.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1379[2]; + + memcpy(pvrtmp_1379, tmp_struct_0.field1, sizeof(GibCursor [2])); + + unsigned char wildcard_80_96_138 = gib_print_symbol(1333); + GibCursorPtr2GibCursorPtr2Prod return_1; + + memcpy(return_1.field0, pvrtmp_1378, sizeof(GibCursor [2])); + memcpy(return_1.field1, pvrtmp_1379, sizeof(GibCursor [2])); + return return_1; + break; + } + + case 1: + { + GibCursor soa_field_0_745 = arg_74_88_130[1]; + GibCursor loc_334 = arg_74_88_130[0]; + GibCursor jump_dloc_509 = loc_334 + 1; + GibCursor loc_IntTy_335 = arg_74_88_130[1]; + GibCursor jump_floc_loc_510 = loc_IntTy_335 + 0; + GibCursor cursor_ptr_747[2] = {jump_dloc_509, jump_floc_loc_510}; + unsigned char wildcard_83_97_139 = gib_print_symbol(1334); + unsigned char wildcard_84_98_140 = gib_print_symbol(1333); + GibCursorPtr2GibCursorPtr2Prod return_2; + + memcpy(return_2.field0, cursor_ptr_728, sizeof(GibCursor [2])); + memcpy(return_2.field1, cursor_ptr_747, sizeof(GibCursor [2])); + return return_2; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_749 = arg_74_88_130[1]; + uintptr_t tagged_tmpcur_6 = *(uintptr_t *) tmpcur_1375; + GibCursor tmpcur_1380 = GIB_UNTAG(tagged_tmpcur_6); + GibCursor tmpaftercur_1381 = tmpcur_1375 + 8; + uint16_t tmptag_1382 = GIB_GET_TAG(tagged_tmpcur_6); + GibCursor end_from_tagged_dcon_redir_759 = tmpcur_1380 + + tmptag_1382; + GibCursor field_nxt_757 = soa_field_0_749 + 1; + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) field_nxt_757; + GibCursor tmpcur_1383 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_1384 = field_nxt_757 + 8; + uint16_t tmptag_1385 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_fld_redir_760 = tmpcur_1383 + tmptag_1385; + GibCursor indr_561[2] = {tmpcur_1380, tmpcur_1383}; + GibCursor loc_334 = arg_74_88_130[0]; + GibCursor jump_dloc_564 = loc_334 + 9; + GibCursor loc_IntTy_335 = arg_74_88_130[1]; + GibCursor aft_indir_loc_570 = loc_IntTy_335 + 9; + GibCursor cursor_ptr_761[2] = {jump_dloc_564, aft_indir_loc_570}; + unsigned char wildcard_569 = gib_print_symbol(1337); + GibCursorPtr2GibCursorPtr2Prod tmp_struct_3 = + _print_List(indr_561, indr_561); + GibCursor pvrtmp_1386[2]; + + memcpy(pvrtmp_1386, tmp_struct_3.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1387[2]; + + memcpy(pvrtmp_1387, tmp_struct_3.field1, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2Prod return_4; + + memcpy(return_4.field0, cursor_ptr_728, sizeof(GibCursor [2])); + memcpy(return_4.field1, cursor_ptr_761, sizeof(GibCursor [2])); + return return_4; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_769 = arg_74_88_130[1]; + uintptr_t tagged_tmpcur_10 = *(uintptr_t *) tmpcur_1375; + GibCursor tmpcur_1388 = GIB_UNTAG(tagged_tmpcur_10); + GibCursor tmpaftercur_1389 = tmpcur_1375 + 8; + uint16_t tmptag_1390 = GIB_GET_TAG(tagged_tmpcur_10); + GibCursor end_from_tagged_dcon_redir_775 = tmpcur_1388 + + tmptag_1390; + GibCursor field_nxt_774 = soa_field_0_769 + 1; + uintptr_t tagged_tmpcur_9 = *(uintptr_t *) field_nxt_774; + GibCursor tmpcur_1391 = GIB_UNTAG(tagged_tmpcur_9); + GibCursor tmpaftercur_1392 = field_nxt_774 + 8; + uint16_t tmptag_1393 = GIB_GET_TAG(tagged_tmpcur_9); + GibCursor end_from_tagged_fld_redir_776 = tmpcur_1391 + tmptag_1393; + GibCursor indr_561[2] = {tmpcur_1388, tmpcur_1391}; + unsigned char wildcard_569 = gib_print_symbol(1336); + GibCursorPtr2GibCursorPtr2Prod tmp_struct_7 = + _print_List(indr_561, indr_561); + GibCursor pvrtmp_1394[2]; + + memcpy(pvrtmp_1394, tmp_struct_7.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1395[2]; + + memcpy(pvrtmp_1395, tmp_struct_7.field1, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2Prod return_8; + + memcpy(return_8.field0, pvrtmp_1394, sizeof(GibCursor [2])); + memcpy(return_8.field1, pvrtmp_1395, sizeof(GibCursor [2])); + return return_8; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1374"); + exit(1); + } + } +} +GibCursorPtr2GibCursorPtr2Prod _traverse_List(GibCursor cursor_ptr_784[2], + GibCursor arg_69_99_141[2]) +{ + GibCursor end_r_340 = cursor_ptr_784[0]; + GibCursor end_r_341 = cursor_ptr_784[1]; + GibCursor dcon_787 = arg_69_99_141[0]; + GibPackedTag tmpval_1397 = *(GibPackedTag *) dcon_787; + GibCursor tmpcur_1398 = dcon_787 + 1; + + + switch_1419: + ; + switch (tmpval_1397) { + + case 0: + { + GibCursor soa_field_0_789 = arg_69_99_141[1]; + GibInt tmpval_1399 = *(GibInt *) soa_field_0_789; + GibCursor tmpcur_1400 = soa_field_0_789 + sizeof(GibInt); + GibCursor cursor_ptr_786[2] = {tmpcur_1398, tmpcur_1400}; + GibCursor loc_338 = arg_69_99_141[0]; + GibCursor jumpf_dloc_512 = loc_338 + 1; + GibCursor loc_IntTy_339 = arg_69_99_141[1]; + GibCursor jumpf_floc_loc_513 = soa_field_0_789 + 8; + GibCursor loc_410 = jumpf_dloc_512 + 0; + GibCursor loc_409 = jumpf_floc_loc_513 + 0; + GibCursor cursor_ptr_793[2] = {jumpf_dloc_512, jumpf_floc_loc_513}; + GibCursorPtr2GibCursorPtr2Prod tmp_struct_11 = + _traverse_List(cursor_ptr_784, cursor_ptr_786); + GibCursor pvrtmp_1401[2]; + + memcpy(pvrtmp_1401, tmp_struct_11.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1402[2]; + + memcpy(pvrtmp_1402, tmp_struct_11.field1, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2Prod return_12; + + memcpy(return_12.field0, pvrtmp_1401, sizeof(GibCursor [2])); + memcpy(return_12.field1, pvrtmp_1402, sizeof(GibCursor [2])); + return return_12; + break; + } + + case 1: + { + GibCursor soa_field_0_801 = arg_69_99_141[1]; + GibCursor loc_338 = arg_69_99_141[0]; + GibCursor jump_dloc_517 = loc_338 + 1; + GibCursor loc_IntTy_339 = arg_69_99_141[1]; + GibCursor jump_floc_loc_518 = loc_IntTy_339 + 0; + GibCursor cursor_ptr_803[2] = {jump_dloc_517, jump_floc_loc_518}; + GibCursorPtr2GibCursorPtr2Prod return_13; + + memcpy(return_13.field0, cursor_ptr_784, sizeof(GibCursor [2])); + memcpy(return_13.field1, cursor_ptr_803, sizeof(GibCursor [2])); + return return_13; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_805 = arg_69_99_141[1]; + uintptr_t tagged_tmpcur_17 = *(uintptr_t *) tmpcur_1398; + GibCursor tmpcur_1403 = GIB_UNTAG(tagged_tmpcur_17); + GibCursor tmpaftercur_1404 = tmpcur_1398 + 8; + uint16_t tmptag_1405 = GIB_GET_TAG(tagged_tmpcur_17); + GibCursor end_from_tagged_dcon_redir_815 = tmpcur_1403 + + tmptag_1405; + GibCursor field_nxt_813 = soa_field_0_805 + 1; + uintptr_t tagged_tmpcur_16 = *(uintptr_t *) field_nxt_813; + GibCursor tmpcur_1406 = GIB_UNTAG(tagged_tmpcur_16); + GibCursor tmpaftercur_1407 = field_nxt_813 + 8; + uint16_t tmptag_1408 = GIB_GET_TAG(tagged_tmpcur_16); + GibCursor end_from_tagged_fld_redir_816 = tmpcur_1406 + tmptag_1408; + GibCursor indr_571[2] = {tmpcur_1403, tmpcur_1406}; + GibCursor loc_338 = arg_69_99_141[0]; + GibCursor jump_dloc_574 = loc_338 + 9; + GibCursor loc_IntTy_339 = arg_69_99_141[1]; + GibCursor aft_indir_loc_580 = loc_IntTy_339 + 9; + GibCursor cursor_ptr_817[2] = {jump_dloc_574, aft_indir_loc_580}; + GibCursorPtr2GibCursorPtr2Prod tmp_struct_14 = + _traverse_List(indr_571, indr_571); + GibCursor pvrtmp_1409[2]; + + memcpy(pvrtmp_1409, tmp_struct_14.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1410[2]; + + memcpy(pvrtmp_1410, tmp_struct_14.field1, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2Prod return_15; + + memcpy(return_15.field0, cursor_ptr_784, sizeof(GibCursor [2])); + memcpy(return_15.field1, cursor_ptr_817, sizeof(GibCursor [2])); + return return_15; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_825 = arg_69_99_141[1]; + uintptr_t tagged_tmpcur_21 = *(uintptr_t *) tmpcur_1398; + GibCursor tmpcur_1411 = GIB_UNTAG(tagged_tmpcur_21); + GibCursor tmpaftercur_1412 = tmpcur_1398 + 8; + uint16_t tmptag_1413 = GIB_GET_TAG(tagged_tmpcur_21); + GibCursor end_from_tagged_dcon_redir_831 = tmpcur_1411 + + tmptag_1413; + GibCursor field_nxt_830 = soa_field_0_825 + 1; + uintptr_t tagged_tmpcur_20 = *(uintptr_t *) field_nxt_830; + GibCursor tmpcur_1414 = GIB_UNTAG(tagged_tmpcur_20); + GibCursor tmpaftercur_1415 = field_nxt_830 + 8; + uint16_t tmptag_1416 = GIB_GET_TAG(tagged_tmpcur_20); + GibCursor end_from_tagged_fld_redir_832 = tmpcur_1414 + tmptag_1416; + GibCursor indr_571[2] = {tmpcur_1411, tmpcur_1414}; + GibCursorPtr2GibCursorPtr2Prod tmp_struct_18 = + _traverse_List(indr_571, indr_571); + GibCursor pvrtmp_1417[2]; + + memcpy(pvrtmp_1417, tmp_struct_18.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1418[2]; + + memcpy(pvrtmp_1418, tmp_struct_18.field1, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2Prod return_19; + + memcpy(return_19.field0, pvrtmp_1417, sizeof(GibCursor [2])); + memcpy(return_19.field1, pvrtmp_1418, sizeof(GibCursor [2])); + return return_19; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1397"); + exit(1); + } + } +} +GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod mkList(GibCursor cursor_ptr_839[2], + GibCursor cursor_ptr_840[2], + GibInt length_24_103_145) +{ + GibCursor end_r_345 = cursor_ptr_839[1]; + GibCursor end_r_344 = cursor_ptr_839[0]; + GibCursor loc_342 = cursor_ptr_840[0]; + GibCursor loc_IntTy_343 = cursor_ptr_840[1]; + + if (loc_IntTy_343 + 17 > end_r_345 || loc_342 + 26 > end_r_344) { + gib_grow_region(&loc_IntTy_343, &end_r_345); + gib_grow_region(&loc_342, &end_r_344); + } + + GibCursor overwrite_reg_841[2] = {end_r_344, end_r_345}; + GibBool fltIf_124_146 = length_24_103_145 <= 0; + + if (fltIf_124_146) { + GibCursor new_dloc_420 = loc_342 + 1; + GibCursor new_floc_loc_421 = loc_IntTy_343 + 8; + + *(GibPackedTag *) loc_342 = 1; + + GibCursor writetag_842 = loc_342 + 1; + GibCursor after_tag_843 = loc_342 + 1; + GibCursor aft_soa_loc_847[2] = {after_tag_843, loc_IntTy_343}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod return_22; + + memcpy(return_22.field0, overwrite_reg_841, sizeof(GibCursor [2])); + memcpy(return_22.field1, cursor_ptr_840, sizeof(GibCursor [2])); + memcpy(return_22.field2, aft_soa_loc_847, sizeof(GibCursor [2])); + return return_22; + } else { + GibInt fltAppE_125_147 = length_24_103_145 - 1; + GibCursor new_dloc_420 = loc_342 + 1; + GibCursor new_floc_loc_421 = loc_IntTy_343 + 8; + GibCursor cursor_ptr_850[2] = {new_dloc_420, new_floc_loc_421}; + + *(GibPackedTag *) loc_342 = 0; + + GibCursor writetag_855 = loc_342 + 1; + GibCursor after_tag_856 = loc_342 + 1; + + *(GibInt *) loc_IntTy_343 = length_24_103_145; + + GibCursor writecur_860 = loc_IntTy_343 + sizeof(GibInt); + GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod tmp_struct_23 = + mkList(overwrite_reg_841, cursor_ptr_850, fltAppE_125_147); + GibCursor pvrtmp_1424[2]; + + memcpy(pvrtmp_1424, tmp_struct_23.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1425[2]; + + memcpy(pvrtmp_1425, tmp_struct_23.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1426[2]; + + memcpy(pvrtmp_1426, tmp_struct_23.field2, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod return_24; + + memcpy(return_24.field0, pvrtmp_1424, sizeof(GibCursor [2])); + memcpy(return_24.field1, cursor_ptr_840, sizeof(GibCursor [2])); + memcpy(return_24.field2, pvrtmp_1426, sizeof(GibCursor [2])); + return return_24; + } +} +GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod _copy_List(GibCursor cursor_ptr_867[2], + GibCursor cursor_ptr_866[2], + GibCursor cursor_ptr_868[2], + GibCursor arg_59_105_149[2]) +{ + GibCursor end_r_352 = cursor_ptr_866[0]; + GibCursor end_r_353 = cursor_ptr_866[1]; + GibCursor loc_IntTy_349 = cursor_ptr_868[1]; + GibCursor loc_348 = cursor_ptr_868[0]; + + if (loc_IntTy_349 + 17 > end_r_353 || loc_348 + 26 > end_r_352) { + gib_grow_region(&loc_IntTy_349, &end_r_353); + gib_grow_region(&loc_348, &end_r_352); + } + + GibCursor end_r_350 = cursor_ptr_867[0]; + GibCursor end_r_351 = cursor_ptr_867[1]; + GibCursor overwrite_reg_869[2] = {end_r_352, end_r_353}; + GibCursor dcon_872 = arg_59_105_149[0]; + GibPackedTag tmpval_1435 = *(GibPackedTag *) dcon_872; + GibCursor tmpcur_1436 = dcon_872 + 1; + + + switch_1490: + ; + switch (tmpval_1435) { + + case 0: + { + GibCursor soa_field_0_874 = arg_59_105_149[1]; + GibInt tmpval_1437 = *(GibInt *) soa_field_0_874; + GibCursor tmpcur_1438 = soa_field_0_874 + sizeof(GibInt); + GibCursor cursor_ptr_871[2] = {tmpcur_1436, tmpcur_1438}; + GibCursor loc_346 = arg_59_105_149[0]; + GibCursor jumpf_dloc_522 = loc_346 + 1; + GibCursor loc_IntTy_347 = arg_59_105_149[1]; + GibCursor jumpf_floc_loc_523 = soa_field_0_874 + 8; + GibCursor loc_430 = jumpf_dloc_522 + 0; + GibCursor loc_429 = jumpf_floc_loc_523 + 0; + GibCursor cursor_ptr_878[2] = {jumpf_dloc_522, jumpf_floc_loc_523}; + GibCursor new_dloc_438 = loc_348 + 1; + GibCursor new_floc_loc_439 = loc_IntTy_349 + 8; + GibCursor cursor_ptr_879[2] = {new_dloc_438, new_floc_loc_439}; + + *(GibPackedTag *) loc_348 = 0; + + GibCursor writetag_889 = loc_348 + 1; + GibCursor after_tag_890 = loc_348 + 1; + + *(GibInt *) loc_IntTy_349 = tmpval_1437; + + GibCursor writecur_894 = loc_IntTy_349 + sizeof(GibInt); + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_25 = + _copy_List(cursor_ptr_867, overwrite_reg_869, cursor_ptr_879, cursor_ptr_871); + GibCursor pvrtmp_1439[2]; + + memcpy(pvrtmp_1439, tmp_struct_25.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1440[2]; + + memcpy(pvrtmp_1440, tmp_struct_25.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1441[2]; + + memcpy(pvrtmp_1441, tmp_struct_25.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1442[2]; + + memcpy(pvrtmp_1442, tmp_struct_25.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1443[2]; + + memcpy(pvrtmp_1443, tmp_struct_25.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_26; + + memcpy(return_26.field0, pvrtmp_1439, sizeof(GibCursor [2])); + memcpy(return_26.field1, pvrtmp_1440, sizeof(GibCursor [2])); + memcpy(return_26.field2, pvrtmp_1441, sizeof(GibCursor [2])); + memcpy(return_26.field3, cursor_ptr_868, sizeof(GibCursor [2])); + memcpy(return_26.field4, pvrtmp_1443, sizeof(GibCursor [2])); + return return_26; + break; + } + + case 1: + { + GibCursor soa_field_0_900 = arg_59_105_149[1]; + GibCursor loc_346 = arg_59_105_149[0]; + GibCursor jump_dloc_527 = loc_346 + 1; + GibCursor loc_IntTy_347 = arg_59_105_149[1]; + GibCursor jump_floc_loc_528 = loc_IntTy_347 + 0; + GibCursor cursor_ptr_902[2] = {jump_dloc_527, jump_floc_loc_528}; + GibCursor new_dloc_438 = loc_348 + 1; + GibCursor new_floc_loc_439 = loc_IntTy_349 + 8; + + *(GibPackedTag *) loc_348 = 1; + + GibCursor writetag_903 = loc_348 + 1; + GibCursor after_tag_904 = loc_348 + 1; + GibCursor aft_soa_loc_908[2] = {after_tag_904, loc_IntTy_349}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_27; + + memcpy(return_27.field0, cursor_ptr_867, sizeof(GibCursor [2])); + memcpy(return_27.field1, overwrite_reg_869, sizeof(GibCursor [2])); + memcpy(return_27.field2, cursor_ptr_902, sizeof(GibCursor [2])); + memcpy(return_27.field3, cursor_ptr_868, sizeof(GibCursor [2])); + memcpy(return_27.field4, aft_soa_loc_908, sizeof(GibCursor [2])); + return return_27; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_912 = arg_59_105_149[1]; + uintptr_t tagged_tmpcur_31 = *(uintptr_t *) tmpcur_1436; + GibCursor tmpcur_1456 = GIB_UNTAG(tagged_tmpcur_31); + GibCursor tmpaftercur_1457 = tmpcur_1436 + 8; + uint16_t tmptag_1458 = GIB_GET_TAG(tagged_tmpcur_31); + GibCursor end_from_tagged_dcon_redir_922 = tmpcur_1456 + + tmptag_1458; + GibCursor field_nxt_920 = soa_field_0_912 + 1; + uintptr_t tagged_tmpcur_30 = *(uintptr_t *) field_nxt_920; + GibCursor tmpcur_1459 = GIB_UNTAG(tagged_tmpcur_30); + GibCursor tmpaftercur_1460 = field_nxt_920 + 8; + uint16_t tmptag_1461 = GIB_GET_TAG(tagged_tmpcur_30); + GibCursor end_from_tagged_fld_redir_923 = tmpcur_1459 + tmptag_1461; + GibCursor indr_581[2] = {tmpcur_1456, tmpcur_1459}; + GibCursor loc_346 = arg_59_105_149[0]; + GibCursor jump_dloc_584 = loc_346 + 9; + GibCursor loc_IntTy_347 = arg_59_105_149[1]; + GibCursor aft_indir_loc_590 = loc_IntTy_347 + 9; + GibCursor cursor_ptr_924[2] = {jump_dloc_584, aft_indir_loc_590}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_28 = + _copy_List(indr_581, overwrite_reg_869, cursor_ptr_868, indr_581); + GibCursor pvrtmp_1462[2]; + + memcpy(pvrtmp_1462, tmp_struct_28.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1463[2]; + + memcpy(pvrtmp_1463, tmp_struct_28.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1464[2]; + + memcpy(pvrtmp_1464, tmp_struct_28.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1465[2]; + + memcpy(pvrtmp_1465, tmp_struct_28.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1466[2]; + + memcpy(pvrtmp_1466, tmp_struct_28.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_29; + + memcpy(return_29.field0, cursor_ptr_867, sizeof(GibCursor [2])); + memcpy(return_29.field1, pvrtmp_1463, sizeof(GibCursor [2])); + memcpy(return_29.field2, cursor_ptr_924, sizeof(GibCursor [2])); + memcpy(return_29.field3, pvrtmp_1465, sizeof(GibCursor [2])); + memcpy(return_29.field4, pvrtmp_1466, sizeof(GibCursor [2])); + return return_29; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_935 = arg_59_105_149[1]; + uintptr_t tagged_tmpcur_35 = *(uintptr_t *) tmpcur_1436; + GibCursor tmpcur_1473 = GIB_UNTAG(tagged_tmpcur_35); + GibCursor tmpaftercur_1474 = tmpcur_1436 + 8; + uint16_t tmptag_1475 = GIB_GET_TAG(tagged_tmpcur_35); + GibCursor end_from_tagged_dcon_redir_941 = tmpcur_1473 + + tmptag_1475; + GibCursor field_nxt_940 = soa_field_0_935 + 1; + uintptr_t tagged_tmpcur_34 = *(uintptr_t *) field_nxt_940; + GibCursor tmpcur_1476 = GIB_UNTAG(tagged_tmpcur_34); + GibCursor tmpaftercur_1477 = field_nxt_940 + 8; + uint16_t tmptag_1478 = GIB_GET_TAG(tagged_tmpcur_34); + GibCursor end_from_tagged_fld_redir_942 = tmpcur_1476 + tmptag_1478; + GibCursor indr_581[2] = {tmpcur_1473, tmpcur_1476}; + GibCursor copy_dloc_591 = loc_348 + 0; + GibCursor copy_floc_loc_592 = loc_IntTy_349 + 0; + GibCursor cursor_ptr_943[2] = {copy_dloc_591, copy_floc_loc_592}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_32 = + _copy_List(indr_581, overwrite_reg_869, cursor_ptr_943, indr_581); + GibCursor pvrtmp_1479[2]; + + memcpy(pvrtmp_1479, tmp_struct_32.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1480[2]; + + memcpy(pvrtmp_1480, tmp_struct_32.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1481[2]; + + memcpy(pvrtmp_1481, tmp_struct_32.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1482[2]; + + memcpy(pvrtmp_1482, tmp_struct_32.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1483[2]; + + memcpy(pvrtmp_1483, tmp_struct_32.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_33; + + memcpy(return_33.field0, pvrtmp_1479, sizeof(GibCursor [2])); + memcpy(return_33.field1, pvrtmp_1480, sizeof(GibCursor [2])); + memcpy(return_33.field2, pvrtmp_1481, sizeof(GibCursor [2])); + memcpy(return_33.field3, pvrtmp_1482, sizeof(GibCursor [2])); + memcpy(return_33.field4, pvrtmp_1483, sizeof(GibCursor [2])); + return return_33; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1435"); + exit(1); + } + } +} +GibCursorPtr2GibCursorPtr2GibIntProd sumList(GibCursor cursor_ptr_954[2], + GibCursor lst_26_110_154[2]) +{ + GibCursor end_r_356 = cursor_ptr_954[0]; + GibCursor end_r_357 = cursor_ptr_954[1]; + GibCursor dcon_957 = lst_26_110_154[0]; + GibPackedTag tmpval_1491 = *(GibPackedTag *) dcon_957; + GibCursor tmpcur_1492 = dcon_957 + 1; + + + switch_1516: + ; + switch (tmpval_1491) { + + case 1: + { + GibCursor soa_field_0_959 = lst_26_110_154[1]; + GibCursor loc_354 = lst_26_110_154[0]; + GibCursor jump_dloc_531 = loc_354 + 1; + GibCursor loc_IntTy_355 = lst_26_110_154[1]; + GibCursor jump_floc_loc_532 = loc_IntTy_355 + 0; + GibCursor cursor_ptr_961[2] = {jump_dloc_531, jump_floc_loc_532}; + GibCursorPtr2GibCursorPtr2GibIntProd return_36; + + memcpy(return_36.field0, cursor_ptr_954, sizeof(GibCursor [2])); + memcpy(return_36.field1, cursor_ptr_961, sizeof(GibCursor [2])); + return_36.field2 = 0; + return return_36; + break; + } + + case 0: + { + GibCursor soa_field_0_963 = lst_26_110_154[1]; + GibInt tmpval_1493 = *(GibInt *) soa_field_0_963; + GibCursor tmpcur_1494 = soa_field_0_963 + sizeof(GibInt); + GibCursor cursor_ptr_956[2] = {tmpcur_1492, tmpcur_1494}; + GibCursor loc_354 = lst_26_110_154[0]; + GibCursor jumpf_dloc_533 = loc_354 + 1; + GibCursor loc_IntTy_355 = lst_26_110_154[1]; + GibCursor jumpf_floc_loc_534 = soa_field_0_963 + 8; + GibCursor loc_450 = jumpf_dloc_533 + 0; + GibCursor loc_449 = jumpf_floc_loc_534 + 0; + GibCursor cursor_ptr_967[2] = {jumpf_dloc_533, jumpf_floc_loc_534}; + GibCursorPtr2GibCursorPtr2GibIntProd tmp_struct_37 = + sumList(cursor_ptr_954, cursor_ptr_956); + GibCursor pvrtmp_1495[2]; + + memcpy(pvrtmp_1495, tmp_struct_37.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1496[2]; + + memcpy(pvrtmp_1496, tmp_struct_37.field1, sizeof(GibCursor [2])); + + GibInt pvrtmp_1497 = tmp_struct_37.field2; + GibInt tailprim_537 = tmpval_1493 + pvrtmp_1497; + GibCursorPtr2GibCursorPtr2GibIntProd return_38; + + memcpy(return_38.field0, pvrtmp_1495, sizeof(GibCursor [2])); + memcpy(return_38.field1, pvrtmp_1496, sizeof(GibCursor [2])); + return_38.field2 = tailprim_537; + return return_38; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_975 = lst_26_110_154[1]; + uintptr_t tagged_tmpcur_42 = *(uintptr_t *) tmpcur_1492; + GibCursor tmpcur_1498 = GIB_UNTAG(tagged_tmpcur_42); + GibCursor tmpaftercur_1499 = tmpcur_1492 + 8; + uint16_t tmptag_1500 = GIB_GET_TAG(tagged_tmpcur_42); + GibCursor end_from_tagged_dcon_redir_985 = tmpcur_1498 + + tmptag_1500; + GibCursor field_nxt_983 = soa_field_0_975 + 1; + uintptr_t tagged_tmpcur_41 = *(uintptr_t *) field_nxt_983; + GibCursor tmpcur_1501 = GIB_UNTAG(tagged_tmpcur_41); + GibCursor tmpaftercur_1502 = field_nxt_983 + 8; + uint16_t tmptag_1503 = GIB_GET_TAG(tagged_tmpcur_41); + GibCursor end_from_tagged_fld_redir_986 = tmpcur_1501 + tmptag_1503; + GibCursor indr_593[2] = {tmpcur_1498, tmpcur_1501}; + GibCursor loc_354 = lst_26_110_154[0]; + GibCursor jump_dloc_596 = loc_354 + 9; + GibCursor loc_IntTy_355 = lst_26_110_154[1]; + GibCursor aft_indir_loc_602 = loc_IntTy_355 + 9; + GibCursor cursor_ptr_987[2] = {jump_dloc_596, aft_indir_loc_602}; + GibCursorPtr2GibCursorPtr2GibIntProd tmp_struct_39 = + sumList(indr_593, indr_593); + GibCursor pvrtmp_1504[2]; + + memcpy(pvrtmp_1504, tmp_struct_39.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1505[2]; + + memcpy(pvrtmp_1505, tmp_struct_39.field1, sizeof(GibCursor [2])); + + GibInt pvrtmp_1506 = tmp_struct_39.field2; + GibCursorPtr2GibCursorPtr2GibIntProd return_40; + + memcpy(return_40.field0, cursor_ptr_954, sizeof(GibCursor [2])); + memcpy(return_40.field1, cursor_ptr_987, sizeof(GibCursor [2])); + return_40.field2 = pvrtmp_1506; + return return_40; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_995 = lst_26_110_154[1]; + uintptr_t tagged_tmpcur_46 = *(uintptr_t *) tmpcur_1492; + GibCursor tmpcur_1507 = GIB_UNTAG(tagged_tmpcur_46); + GibCursor tmpaftercur_1508 = tmpcur_1492 + 8; + uint16_t tmptag_1509 = GIB_GET_TAG(tagged_tmpcur_46); + GibCursor end_from_tagged_dcon_redir_1001 = tmpcur_1507 + + tmptag_1509; + GibCursor field_nxt_1000 = soa_field_0_995 + 1; + uintptr_t tagged_tmpcur_45 = *(uintptr_t *) field_nxt_1000; + GibCursor tmpcur_1510 = GIB_UNTAG(tagged_tmpcur_45); + GibCursor tmpaftercur_1511 = field_nxt_1000 + 8; + uint16_t tmptag_1512 = GIB_GET_TAG(tagged_tmpcur_45); + GibCursor end_from_tagged_fld_redir_1002 = tmpcur_1510 + + tmptag_1512; + GibCursor indr_593[2] = {tmpcur_1507, tmpcur_1510}; + GibCursorPtr2GibCursorPtr2GibIntProd tmp_struct_43 = + sumList(indr_593, indr_593); + GibCursor pvrtmp_1513[2]; + + memcpy(pvrtmp_1513, tmp_struct_43.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1514[2]; + + memcpy(pvrtmp_1514, tmp_struct_43.field1, sizeof(GibCursor [2])); + + GibInt pvrtmp_1515 = tmp_struct_43.field2; + GibCursorPtr2GibCursorPtr2GibIntProd return_44; + + memcpy(return_44.field0, pvrtmp_1513, sizeof(GibCursor [2])); + memcpy(return_44.field1, pvrtmp_1514, sizeof(GibCursor [2])); + return_44.field2 = pvrtmp_1515; + return return_44; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1491"); + exit(1); + } + } +} +GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod _copy_without_ptrs_List(GibCursor cursor_ptr_1011[2], + GibCursor cursor_ptr_1010[2], + GibCursor cursor_ptr_1012[2], + GibCursor arg_64_115_158[2]) +{ + GibCursor end_r_362 = cursor_ptr_1011[0]; + GibCursor end_r_363 = cursor_ptr_1011[1]; + GibCursor end_r_364 = cursor_ptr_1010[0]; + GibCursor end_r_365 = cursor_ptr_1010[1]; + GibCursor dcon_1015 = arg_64_115_158[0]; + GibPackedTag tmpval_1517 = *(GibPackedTag *) dcon_1015; + GibCursor tmpcur_1518 = dcon_1015 + 1; + + + switch_1572: + ; + switch (tmpval_1517) { + + case 0: + { + GibCursor soa_field_0_1017 = arg_64_115_158[1]; + GibInt tmpval_1519 = *(GibInt *) soa_field_0_1017; + GibCursor tmpcur_1520 = soa_field_0_1017 + sizeof(GibInt); + GibCursor cursor_ptr_1014[2] = {tmpcur_1518, tmpcur_1520}; + GibCursor loc_358 = arg_64_115_158[0]; + GibCursor jumpf_dloc_538 = loc_358 + 1; + GibCursor loc_IntTy_359 = arg_64_115_158[1]; + GibCursor jumpf_floc_loc_539 = soa_field_0_1017 + 8; + GibCursor loc_459 = jumpf_dloc_538 + 0; + GibCursor loc_458 = jumpf_floc_loc_539 + 0; + GibCursor cursor_ptr_1021[2] = {jumpf_dloc_538, jumpf_floc_loc_539}; + GibCursor loc_IntTy_361 = cursor_ptr_1012[1]; + GibCursor new_floc_loc_468 = loc_IntTy_361 + 8; + GibCursor loc_360 = cursor_ptr_1012[0]; + GibCursor new_dloc_467 = loc_360 + 1; + GibCursor cursor_ptr_1022[2] = {new_dloc_467, new_floc_loc_468}; + + *(GibPackedTag *) loc_360 = 0; + + GibCursor writetag_1032 = loc_360 + 1; + GibCursor after_tag_1033 = loc_360 + 1; + + *(GibInt *) loc_IntTy_361 = tmpval_1519; + + GibCursor writecur_1037 = loc_IntTy_361 + sizeof(GibInt); + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_47 = + _copy_without_ptrs_List(cursor_ptr_1011, cursor_ptr_1010, cursor_ptr_1022, cursor_ptr_1014); + GibCursor pvrtmp_1521[2]; + + memcpy(pvrtmp_1521, tmp_struct_47.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1522[2]; + + memcpy(pvrtmp_1522, tmp_struct_47.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1523[2]; + + memcpy(pvrtmp_1523, tmp_struct_47.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1524[2]; + + memcpy(pvrtmp_1524, tmp_struct_47.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1525[2]; + + memcpy(pvrtmp_1525, tmp_struct_47.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_48; + + memcpy(return_48.field0, pvrtmp_1521, sizeof(GibCursor [2])); + memcpy(return_48.field1, pvrtmp_1522, sizeof(GibCursor [2])); + memcpy(return_48.field2, pvrtmp_1523, sizeof(GibCursor [2])); + memcpy(return_48.field3, cursor_ptr_1012, sizeof(GibCursor [2])); + memcpy(return_48.field4, pvrtmp_1525, sizeof(GibCursor [2])); + return return_48; + break; + } + + case 1: + { + GibCursor soa_field_0_1043 = arg_64_115_158[1]; + GibCursor loc_358 = arg_64_115_158[0]; + GibCursor jump_dloc_543 = loc_358 + 1; + GibCursor loc_IntTy_359 = arg_64_115_158[1]; + GibCursor jump_floc_loc_544 = loc_IntTy_359 + 0; + GibCursor cursor_ptr_1045[2] = {jump_dloc_543, jump_floc_loc_544}; + GibCursor loc_IntTy_361 = cursor_ptr_1012[1]; + GibCursor new_floc_loc_468 = loc_IntTy_361 + 8; + GibCursor loc_360 = cursor_ptr_1012[0]; + GibCursor new_dloc_467 = loc_360 + 1; + + *(GibPackedTag *) loc_360 = 1; + + GibCursor writetag_1046 = loc_360 + 1; + GibCursor after_tag_1047 = loc_360 + 1; + GibCursor aft_soa_loc_1051[2] = {after_tag_1047, loc_IntTy_361}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_49; + + memcpy(return_49.field0, cursor_ptr_1011, sizeof(GibCursor [2])); + memcpy(return_49.field1, cursor_ptr_1010, sizeof(GibCursor [2])); + memcpy(return_49.field2, cursor_ptr_1045, sizeof(GibCursor [2])); + memcpy(return_49.field3, cursor_ptr_1012, sizeof(GibCursor [2])); + memcpy(return_49.field4, aft_soa_loc_1051, sizeof(GibCursor [2])); + return return_49; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1055 = arg_64_115_158[1]; + uintptr_t tagged_tmpcur_53 = *(uintptr_t *) tmpcur_1518; + GibCursor tmpcur_1538 = GIB_UNTAG(tagged_tmpcur_53); + GibCursor tmpaftercur_1539 = tmpcur_1518 + 8; + uint16_t tmptag_1540 = GIB_GET_TAG(tagged_tmpcur_53); + GibCursor end_from_tagged_dcon_redir_1065 = tmpcur_1538 + + tmptag_1540; + GibCursor field_nxt_1063 = soa_field_0_1055 + 1; + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) field_nxt_1063; + GibCursor tmpcur_1541 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_1542 = field_nxt_1063 + 8; + uint16_t tmptag_1543 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_fld_redir_1066 = tmpcur_1541 + + tmptag_1543; + GibCursor indr_603[2] = {tmpcur_1538, tmpcur_1541}; + GibCursor loc_358 = arg_64_115_158[0]; + GibCursor jump_dloc_606 = loc_358 + 9; + GibCursor loc_IntTy_359 = arg_64_115_158[1]; + GibCursor aft_indir_loc_612 = loc_IntTy_359 + 9; + GibCursor cursor_ptr_1067[2] = {jump_dloc_606, aft_indir_loc_612}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_50 = + _copy_without_ptrs_List(indr_603, cursor_ptr_1010, cursor_ptr_1012, indr_603); + GibCursor pvrtmp_1544[2]; + + memcpy(pvrtmp_1544, tmp_struct_50.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1545[2]; + + memcpy(pvrtmp_1545, tmp_struct_50.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1546[2]; + + memcpy(pvrtmp_1546, tmp_struct_50.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1547[2]; + + memcpy(pvrtmp_1547, tmp_struct_50.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1548[2]; + + memcpy(pvrtmp_1548, tmp_struct_50.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_51; + + memcpy(return_51.field0, cursor_ptr_1011, sizeof(GibCursor [2])); + memcpy(return_51.field1, pvrtmp_1545, sizeof(GibCursor [2])); + memcpy(return_51.field2, cursor_ptr_1067, sizeof(GibCursor [2])); + memcpy(return_51.field3, pvrtmp_1547, sizeof(GibCursor [2])); + memcpy(return_51.field4, pvrtmp_1548, sizeof(GibCursor [2])); + return return_51; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1078 = arg_64_115_158[1]; + uintptr_t tagged_tmpcur_57 = *(uintptr_t *) tmpcur_1518; + GibCursor tmpcur_1555 = GIB_UNTAG(tagged_tmpcur_57); + GibCursor tmpaftercur_1556 = tmpcur_1518 + 8; + uint16_t tmptag_1557 = GIB_GET_TAG(tagged_tmpcur_57); + GibCursor end_from_tagged_dcon_redir_1084 = tmpcur_1555 + + tmptag_1557; + GibCursor field_nxt_1083 = soa_field_0_1078 + 1; + uintptr_t tagged_tmpcur_56 = *(uintptr_t *) field_nxt_1083; + GibCursor tmpcur_1558 = GIB_UNTAG(tagged_tmpcur_56); + GibCursor tmpaftercur_1559 = field_nxt_1083 + 8; + uint16_t tmptag_1560 = GIB_GET_TAG(tagged_tmpcur_56); + GibCursor end_from_tagged_fld_redir_1085 = tmpcur_1558 + + tmptag_1560; + GibCursor indr_603[2] = {tmpcur_1555, tmpcur_1558}; + GibCursor loc_360 = cursor_ptr_1012[0]; + GibCursor loc_IntTy_361 = cursor_ptr_1012[1]; + GibCursor copy_dloc_613 = loc_360 + 0; + GibCursor copy_floc_loc_614 = loc_IntTy_361 + 0; + GibCursor cursor_ptr_1086[2] = {copy_dloc_613, copy_floc_loc_614}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_54 = + _copy_without_ptrs_List(indr_603, cursor_ptr_1010, cursor_ptr_1086, indr_603); + GibCursor pvrtmp_1561[2]; + + memcpy(pvrtmp_1561, tmp_struct_54.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1562[2]; + + memcpy(pvrtmp_1562, tmp_struct_54.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1563[2]; + + memcpy(pvrtmp_1563, tmp_struct_54.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1564[2]; + + memcpy(pvrtmp_1564, tmp_struct_54.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1565[2]; + + memcpy(pvrtmp_1565, tmp_struct_54.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_55; + + memcpy(return_55.field0, pvrtmp_1561, sizeof(GibCursor [2])); + memcpy(return_55.field1, pvrtmp_1562, sizeof(GibCursor [2])); + memcpy(return_55.field2, pvrtmp_1563, sizeof(GibCursor [2])); + memcpy(return_55.field3, pvrtmp_1564, sizeof(GibCursor [2])); + memcpy(return_55.field4, pvrtmp_1565, sizeof(GibCursor [2])); + return return_55; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1517"); + exit(1); + } + } +} +GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod add1(GibCursor cursor_ptr_1098[2], + GibCursor cursor_ptr_1097[2], + GibCursor cursor_ptr_1099[2], + GibCursor lst_31_120_163[2]) +{ + GibCursor end_r_373 = cursor_ptr_1097[1]; + GibCursor end_r_372 = cursor_ptr_1097[0]; + GibCursor loc_IntTy_369 = cursor_ptr_1099[1]; + GibCursor loc_368 = cursor_ptr_1099[0]; + + if (loc_IntTy_369 + 17 > end_r_373 || loc_368 + 26 > end_r_372) { + gib_grow_region(&loc_IntTy_369, &end_r_373); + gib_grow_region(&loc_368, &end_r_372); + } + + GibCursor end_r_370 = cursor_ptr_1098[0]; + GibCursor end_r_371 = cursor_ptr_1098[1]; + GibCursor overwrite_reg_1100[2] = {end_r_372, end_r_373}; + GibCursor dcon_1103 = lst_31_120_163[0]; + GibPackedTag tmpval_1573 = *(GibPackedTag *) dcon_1103; + GibCursor tmpcur_1574 = dcon_1103 + 1; + + + switch_1628: + ; + switch (tmpval_1573) { + + case 1: + { + GibCursor soa_field_0_1105 = lst_31_120_163[1]; + GibCursor loc_366 = lst_31_120_163[0]; + GibCursor jump_dloc_546 = loc_366 + 1; + GibCursor loc_IntTy_367 = lst_31_120_163[1]; + GibCursor jump_floc_loc_547 = loc_IntTy_367 + 0; + GibCursor cursor_ptr_1107[2] = {jump_dloc_546, jump_floc_loc_547}; + GibCursor new_dloc_489 = loc_368 + 1; + GibCursor new_floc_loc_490 = loc_IntTy_369 + 8; + + *(GibPackedTag *) loc_368 = 1; + + GibCursor writetag_1108 = loc_368 + 1; + GibCursor after_tag_1109 = loc_368 + 1; + GibCursor aft_soa_loc_1113[2] = {after_tag_1109, loc_IntTy_369}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_58; + + memcpy(return_58.field0, cursor_ptr_1098, sizeof(GibCursor [2])); + memcpy(return_58.field1, overwrite_reg_1100, sizeof(GibCursor [2])); + memcpy(return_58.field2, cursor_ptr_1107, sizeof(GibCursor [2])); + memcpy(return_58.field3, cursor_ptr_1099, sizeof(GibCursor [2])); + memcpy(return_58.field4, aft_soa_loc_1113, sizeof(GibCursor [2])); + return return_58; + break; + } + + case 0: + { + GibCursor soa_field_0_1117 = lst_31_120_163[1]; + GibInt tmpval_1579 = *(GibInt *) soa_field_0_1117; + GibCursor tmpcur_1580 = soa_field_0_1117 + sizeof(GibInt); + GibCursor cursor_ptr_1102[2] = {tmpcur_1574, tmpcur_1580}; + GibCursor loc_366 = lst_31_120_163[0]; + GibCursor jumpf_dloc_549 = loc_366 + 1; + GibCursor loc_IntTy_367 = lst_31_120_163[1]; + GibCursor jumpf_floc_loc_550 = soa_field_0_1117 + 8; + GibCursor loc_481 = jumpf_dloc_549 + 0; + GibCursor loc_480 = jumpf_floc_loc_550 + 0; + GibCursor cursor_ptr_1121[2] = {jumpf_dloc_549, jumpf_floc_loc_550}; + GibInt i1_34_123_166 = tmpval_1579 + 1; + GibCursor new_dloc_489 = loc_368 + 1; + GibCursor new_floc_loc_490 = loc_IntTy_369 + 8; + GibCursor cursor_ptr_1122[2] = {new_dloc_489, new_floc_loc_490}; + + *(GibPackedTag *) loc_368 = 0; + + GibCursor writetag_1132 = loc_368 + 1; + GibCursor after_tag_1133 = loc_368 + 1; + + *(GibInt *) loc_IntTy_369 = i1_34_123_166; + + GibCursor writecur_1137 = loc_IntTy_369 + sizeof(GibInt); + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_59 = + add1(cursor_ptr_1098, overwrite_reg_1100, cursor_ptr_1122, cursor_ptr_1102); + GibCursor pvrtmp_1581[2]; + + memcpy(pvrtmp_1581, tmp_struct_59.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1582[2]; + + memcpy(pvrtmp_1582, tmp_struct_59.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1583[2]; + + memcpy(pvrtmp_1583, tmp_struct_59.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1584[2]; + + memcpy(pvrtmp_1584, tmp_struct_59.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1585[2]; + + memcpy(pvrtmp_1585, tmp_struct_59.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_60; + + memcpy(return_60.field0, pvrtmp_1581, sizeof(GibCursor [2])); + memcpy(return_60.field1, pvrtmp_1582, sizeof(GibCursor [2])); + memcpy(return_60.field2, pvrtmp_1583, sizeof(GibCursor [2])); + memcpy(return_60.field3, cursor_ptr_1099, sizeof(GibCursor [2])); + memcpy(return_60.field4, pvrtmp_1585, sizeof(GibCursor [2])); + return return_60; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_1143 = lst_31_120_163[1]; + uintptr_t tagged_tmpcur_64 = *(uintptr_t *) tmpcur_1574; + GibCursor tmpcur_1594 = GIB_UNTAG(tagged_tmpcur_64); + GibCursor tmpaftercur_1595 = tmpcur_1574 + 8; + uint16_t tmptag_1596 = GIB_GET_TAG(tagged_tmpcur_64); + GibCursor end_from_tagged_dcon_redir_1153 = tmpcur_1594 + + tmptag_1596; + GibCursor field_nxt_1151 = soa_field_0_1143 + 1; + uintptr_t tagged_tmpcur_63 = *(uintptr_t *) field_nxt_1151; + GibCursor tmpcur_1597 = GIB_UNTAG(tagged_tmpcur_63); + GibCursor tmpaftercur_1598 = field_nxt_1151 + 8; + uint16_t tmptag_1599 = GIB_GET_TAG(tagged_tmpcur_63); + GibCursor end_from_tagged_fld_redir_1154 = tmpcur_1597 + + tmptag_1599; + GibCursor indr_615[2] = {tmpcur_1594, tmpcur_1597}; + GibCursor loc_366 = lst_31_120_163[0]; + GibCursor jump_dloc_618 = loc_366 + 9; + GibCursor loc_IntTy_367 = lst_31_120_163[1]; + GibCursor aft_indir_loc_624 = loc_IntTy_367 + 9; + GibCursor cursor_ptr_1155[2] = {jump_dloc_618, aft_indir_loc_624}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_61 = + add1(indr_615, overwrite_reg_1100, cursor_ptr_1099, indr_615); + GibCursor pvrtmp_1600[2]; + + memcpy(pvrtmp_1600, tmp_struct_61.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1601[2]; + + memcpy(pvrtmp_1601, tmp_struct_61.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1602[2]; + + memcpy(pvrtmp_1602, tmp_struct_61.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1603[2]; + + memcpy(pvrtmp_1603, tmp_struct_61.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1604[2]; + + memcpy(pvrtmp_1604, tmp_struct_61.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_62; + + memcpy(return_62.field0, cursor_ptr_1098, sizeof(GibCursor [2])); + memcpy(return_62.field1, pvrtmp_1601, sizeof(GibCursor [2])); + memcpy(return_62.field2, cursor_ptr_1155, sizeof(GibCursor [2])); + memcpy(return_62.field3, pvrtmp_1603, sizeof(GibCursor [2])); + memcpy(return_62.field4, pvrtmp_1604, sizeof(GibCursor [2])); + return return_62; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_1166 = lst_31_120_163[1]; + uintptr_t tagged_tmpcur_68 = *(uintptr_t *) tmpcur_1574; + GibCursor tmpcur_1611 = GIB_UNTAG(tagged_tmpcur_68); + GibCursor tmpaftercur_1612 = tmpcur_1574 + 8; + uint16_t tmptag_1613 = GIB_GET_TAG(tagged_tmpcur_68); + GibCursor end_from_tagged_dcon_redir_1172 = tmpcur_1611 + + tmptag_1613; + GibCursor field_nxt_1171 = soa_field_0_1166 + 1; + uintptr_t tagged_tmpcur_67 = *(uintptr_t *) field_nxt_1171; + GibCursor tmpcur_1614 = GIB_UNTAG(tagged_tmpcur_67); + GibCursor tmpaftercur_1615 = field_nxt_1171 + 8; + uint16_t tmptag_1616 = GIB_GET_TAG(tagged_tmpcur_67); + GibCursor end_from_tagged_fld_redir_1173 = tmpcur_1614 + + tmptag_1616; + GibCursor indr_615[2] = {tmpcur_1611, tmpcur_1614}; + GibCursor copy_dloc_625 = loc_368 + 0; + GibCursor copy_floc_loc_626 = loc_IntTy_369 + 0; + GibCursor cursor_ptr_1174[2] = {copy_dloc_625, copy_floc_loc_626}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_65 = + add1(indr_615, overwrite_reg_1100, cursor_ptr_1174, indr_615); + GibCursor pvrtmp_1617[2]; + + memcpy(pvrtmp_1617, tmp_struct_65.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1618[2]; + + memcpy(pvrtmp_1618, tmp_struct_65.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1619[2]; + + memcpy(pvrtmp_1619, tmp_struct_65.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1620[2]; + + memcpy(pvrtmp_1620, tmp_struct_65.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1621[2]; + + memcpy(pvrtmp_1621, tmp_struct_65.field4, sizeof(GibCursor [2])); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + return_66; + + memcpy(return_66.field0, pvrtmp_1617, sizeof(GibCursor [2])); + memcpy(return_66.field1, pvrtmp_1618, sizeof(GibCursor [2])); + memcpy(return_66.field2, pvrtmp_1619, sizeof(GibCursor [2])); + memcpy(return_66.field3, pvrtmp_1620, sizeof(GibCursor [2])); + memcpy(return_66.field4, pvrtmp_1621, sizeof(GibCursor [2])); + return return_66; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_1573"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_82 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_1339 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_395 = region_1339.start; + GibCursor end_r_395 = region_1339.end; + GibChunk region_1340 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_396 = region_1340.start; + GibCursor end_r_396 = region_1340.end; + GibCursor reg_ptr_1184[2] = {r_395, r_396}; + GibCursor reg_cursor_ptr_1185[2] = {end_r_395, end_r_396}; + GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod tmp_struct_69 = + mkList(reg_cursor_ptr_1185, reg_ptr_1184, 10000000); + GibCursor pvrtmp_1341[2]; + + memcpy(pvrtmp_1341, tmp_struct_69.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1342[2]; + + memcpy(pvrtmp_1342, tmp_struct_69.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1343[2]; + + memcpy(pvrtmp_1343, tmp_struct_69.field2, sizeof(GibCursor [2])); + + GibChunk region_1348 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_393 = region_1348.start; + GibCursor end_r_393 = region_1348.end; + GibChunk region_1349 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_394 = region_1349.start; + GibCursor end_r_394 = region_1349.end; + GibCursor reg_ptr_1191[2] = {r_393, r_394}; + GibCursor reg_cursor_ptr_1192[2] = {end_r_393, end_r_394}; + GibCursor pvrtmp_1361[2]; + GibCursor pvrtmp_1362[2]; + GibCursor pvrtmp_1363[2]; + GibVector *times_74 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_pvrtmp_1361; + struct timespec end_pvrtmp_1361; + + for (long long iters_pvrtmp_1361 = 0; iters_pvrtmp_1361 < + gib_get_iters_param(); iters_pvrtmp_1361++) { + if (iters_pvrtmp_1361 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_pvrtmp_1361); + + GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2GibCursorPtr2Prod + tmp_struct_70 = + add1(pvrtmp_1341, reg_cursor_ptr_1192, reg_ptr_1191, pvrtmp_1342); + GibCursor pvrtmp_1350[2]; + + memcpy(pvrtmp_1350, tmp_struct_70.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1351[2]; + + memcpy(pvrtmp_1351, tmp_struct_70.field1, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1352[2]; + + memcpy(pvrtmp_1352, tmp_struct_70.field2, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1353[2]; + + memcpy(pvrtmp_1353, tmp_struct_70.field3, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1354[2]; + + memcpy(pvrtmp_1354, tmp_struct_70.field4, sizeof(GibCursor [2])); + memcpy(pvrtmp_1361, pvrtmp_1351, sizeof(GibCursor [2])); + memcpy(pvrtmp_1362, pvrtmp_1353, sizeof(GibCursor [2])); + memcpy(pvrtmp_1363, pvrtmp_1354, sizeof(GibCursor [2])); + clock_gettime(CLOCK_MONOTONIC_RAW, &end_pvrtmp_1361); + if (iters_pvrtmp_1361 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_71 = gib_difftimespecs(&begin_pvrtmp_1361, + &end_pvrtmp_1361); + + printf("itertime: %lf\n", itertime_71); + gib_vector_inplace_update(times_74, iters_pvrtmp_1361, &itertime_71); + } + gib_vector_inplace_sort(times_74, gib_compare_doubles); + + double *tmp_75 = (double *) gib_vector_nth(times_74, gib_get_iters_param() / + 2); + double selftimed_73 = *tmp_75; + double batchtime_72 = gib_sum_timing_array(times_74); + + gib_print_timing_array(times_74); + gib_vector_free(times_74); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_72); + printf("SELFTIMED: %e\n", selftimed_73); + + GibInt timed_1250; + GibVector *times_80 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_1250; + struct timespec end_timed_1250; + + for (long long iters_timed_1250 = 0; iters_timed_1250 < + gib_get_iters_param(); iters_timed_1250++) { + if (iters_timed_1250 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_1250); + + GibCursorPtr2GibCursorPtr2GibIntProd tmp_struct_76 = + sumList(reg_cursor_ptr_1192, pvrtmp_1362); + GibCursor pvrtmp_1371[2]; + + memcpy(pvrtmp_1371, tmp_struct_76.field0, sizeof(GibCursor [2])); + + GibCursor pvrtmp_1372[2]; + + memcpy(pvrtmp_1372, tmp_struct_76.field1, sizeof(GibCursor [2])); + + GibInt pvrtmp_1373 = tmp_struct_76.field2; + + timed_1250 = pvrtmp_1373; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_1250); + if (iters_timed_1250 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_77 = gib_difftimespecs(&begin_timed_1250, + &end_timed_1250); + + printf("itertime: %lf\n", itertime_77); + gib_vector_inplace_update(times_80, iters_timed_1250, &itertime_77); + } + gib_vector_inplace_sort(times_80, gib_compare_doubles); + + double *tmp_81 = (double *) gib_vector_nth(times_80, gib_get_iters_param() / + 2); + double selftimed_79 = *tmp_81; + double batchtime_78 = gib_sum_timing_array(times_80); + + gib_print_timing_array(times_80); + gib_vector_free(times_80); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_78); + printf("SELFTIMED: %e\n", selftimed_79); + printf("%ld", timed_1250); + printf("\n"); + + int exit_83 = gib_exit(); + + return exit_83; +} \ No newline at end of file diff --git a/microbench/manual_soa_examples/reduceList.aos.c b/microbench/manual_soa_examples/reduceList.aos.c new file mode 100644 index 000000000..13a6b054c --- /dev/null +++ b/microbench/manual_soa_examples/reduceList.aos.c @@ -0,0 +1,1984 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_ListB(GibCursor end_r_910, GibCursor end_r_912, + GibCursor loc_908, GibCursor arg_191_249_424); +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_915, + GibCursor arg_98_264_439); +GibCursorGibCursorProd _print_List(GibCursor end_r_918, + GibCursor arg_153_268_443); +GibCursorGibCursorGibCursorProd mkListB(GibCursor end_r_921, GibCursor loc_919, + GibInt len_34_291_466); +GibCursorGibCursorProd _traverse_List(GibCursor end_r_924, + GibCursor arg_140_293_470); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_ListA(GibCursor end_r_928, GibCursor end_r_930, + GibCursor loc_926, GibCursor arg_93_302_479); +void reduceB(GibCursor *end_r_933, + GibCursor *lst_36_307_484, GibInt *Res); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_ListA(GibCursor end_r_937, GibCursor end_r_939, GibCursor loc_935, + GibCursor arg_88_315_493); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_ListB(GibCursor end_r_943, GibCursor end_r_945, GibCursor loc_941, + GibCursor arg_176_330_498); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_List(GibCursor end_r_949, GibCursor end_r_951, GibCursor loc_947, + GibCursor arg_114_345_513); +GibCursorGibCursorProd _traverse_ListB(GibCursor end_r_954, + GibCursor arg_206_358_526); +GibCursorGibCursorProd _print_ListA(GibCursor end_r_957, + GibCursor arg_103_369_535); +GibCursorGibCursorProd _print_ListB(GibCursor end_r_960, + GibCursor arg_221_380_546); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_List(GibCursor end_r_964, GibCursor end_r_966, + GibCursor loc_962, GibCursor arg_127_406_572); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + List_T, + ListA_T, + ListB_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(10); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[7]; + + field_tys[0] = ListA_T; + field_tys[1] = List_T; + error = gib_info_table_insert_packed_dcon(List_T, 0, 32, 0, 4, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(List_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 1); + exit(1); + } + field_tys[0] = ListA_T; + error = gib_info_table_insert_packed_dcon(ListA_T, 0, 8, 0, 1, 1, field_tys, + 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListA_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 1); + exit(1); + } + field_tys[0] = ListB_T; + error = gib_info_table_insert_packed_dcon(ListB_T, 0, 48, 0, 6, 1, + field_tys, 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListB_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(2176, ")"); + gib_add_symbol(2177, "(NilB"); + gib_add_symbol(2178, "(NilA"); + gib_add_symbol(2179, "(Nil"); + gib_add_symbol(2180, "(ConsB"); + gib_add_symbol(2181, "(ConsA"); + gib_add_symbol(2182, "(Cons"); + gib_add_symbol(2183, " ->r "); + gib_add_symbol(2184, " ->i "); + gib_add_symbol(2185, " "); +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_ListB(GibCursor end_r_910, + GibCursor end_r_912, + GibCursor loc_908, + GibCursor arg_191_249_424) +{ + GibPackedTag tmpval_2197 = *(GibPackedTag *) arg_191_249_424; + GibCursor tmpcur_2198 = arg_191_249_424 + 1; + + + switch_2256: + ; + switch (tmpval_2197) { + + case 0: + { + GibInt tmpval_2199 = *(GibInt *) tmpcur_2198; + GibCursor tmpcur_2200 = tmpcur_2198 + sizeof(GibInt); + GibInt tmpval_2201 = *(GibInt *) tmpcur_2200; + GibCursor tmpcur_2202 = tmpcur_2200 + sizeof(GibInt); + GibInt tmpval_2203 = *(GibInt *) tmpcur_2202; + GibCursor tmpcur_2204 = tmpcur_2202 + sizeof(GibInt); + GibInt tmpval_2205 = *(GibInt *) tmpcur_2204; + GibCursor tmpcur_2206 = tmpcur_2204 + sizeof(GibInt); + GibInt tmpval_2207 = *(GibInt *) tmpcur_2206; + GibCursor tmpcur_2208 = tmpcur_2206 + sizeof(GibInt); + GibInt tmpval_2209 = *(GibInt *) tmpcur_2208; + GibCursor tmpcur_2210 = tmpcur_2208 + sizeof(GibInt); + GibCursor jump_1240 = tmpcur_2208 + 8; + GibCursor jump_1239 = tmpcur_2206 + 8; + GibCursor jump_1238 = tmpcur_2204 + 8; + GibCursor jump_1237 = tmpcur_2202 + 8; + GibCursor jump_1236 = tmpcur_2200 + 8; + GibCursor jump_1235 = tmpcur_2198 + 8; + GibCursor loc_985 = loc_908 + 1; + GibCursor loc_986 = loc_985 + 8; + GibCursor loc_987 = loc_986 + 8; + GibCursor loc_988 = loc_987 + 8; + GibCursor loc_989 = loc_988 + 8; + GibCursor loc_990 = loc_989 + 8; + GibCursor loc_991 = loc_990 + 8; + + *(GibPackedTag *) loc_908 = 0; + + GibCursor writetag_1586 = loc_908 + 1; + GibCursor after_tag_1587 = loc_908 + 1; + + *(GibInt *) after_tag_1587 = tmpval_2199; + + GibCursor writecur_1591 = after_tag_1587 + sizeof(GibInt); + + *(GibInt *) writecur_1591 = tmpval_2201; + + GibCursor writecur_1592 = writecur_1591 + sizeof(GibInt); + + *(GibInt *) writecur_1592 = tmpval_2203; + + GibCursor writecur_1593 = writecur_1592 + sizeof(GibInt); + + *(GibInt *) writecur_1593 = tmpval_2205; + + GibCursor writecur_1594 = writecur_1593 + sizeof(GibInt); + + *(GibInt *) writecur_1594 = tmpval_2207; + + GibCursor writecur_1595 = writecur_1594 + sizeof(GibInt); + + *(GibInt *) writecur_1595 = tmpval_2209; + + GibCursor writecur_1596 = writecur_1595 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_0 = + _copy_without_ptrs_ListB(end_r_910, end_r_912, loc_991, tmpcur_2210); + GibCursor pvrtmp_2211 = tmp_struct_0.field0; + GibCursor pvrtmp_2212 = tmp_struct_0.field1; + GibCursor pvrtmp_2213 = tmp_struct_0.field2; + GibCursor pvrtmp_2214 = tmp_struct_0.field3; + GibCursor pvrtmp_2215 = tmp_struct_0.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_1; + + return_1.field0 = pvrtmp_2211; + return_1.field1 = pvrtmp_2212; + return_1.field2 = pvrtmp_2213; + return_1.field3 = loc_908; + return_1.field4 = pvrtmp_2215; + return return_1; + break; + } + + case 1: + { + GibCursor jump_loc_1243 = arg_191_249_424 + 1; + + *(GibPackedTag *) loc_908 = 1; + + GibCursor writetag_1601 = loc_908 + 1; + GibCursor after_tag_1602 = loc_908 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_2; + + return_2.field0 = end_r_910; + return_2.field1 = end_r_912; + return_2.field2 = jump_loc_1243; + return_2.field3 = loc_908; + return_2.field4 = after_tag_1602; + return return_2; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) tmpcur_2198; + GibCursor tmpcur_2228 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_2229 = tmpcur_2198 + 8; + uint16_t tmptag_2230 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_indr_1352 = tmpcur_2228 + tmptag_2230; + GibCursor jump_loc_1354 = tmpcur_2198 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_3 = + _copy_without_ptrs_ListB(tmpcur_2228, end_r_912, loc_908, tmpcur_2228); + GibCursor pvrtmp_2231 = tmp_struct_3.field0; + GibCursor pvrtmp_2232 = tmp_struct_3.field1; + GibCursor pvrtmp_2233 = tmp_struct_3.field2; + GibCursor pvrtmp_2234 = tmp_struct_3.field3; + GibCursor pvrtmp_2235 = tmp_struct_3.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_4; + + return_4.field0 = end_r_910; + return_4.field1 = pvrtmp_2232; + return_4.field2 = jump_loc_1354; + return_4.field3 = pvrtmp_2234; + return_4.field4 = pvrtmp_2235; + return return_4; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_8 = *(uintptr_t *) tmpcur_2198; + GibCursor tmpcur_2242 = GIB_UNTAG(tagged_tmpcur_8); + GibCursor tmpaftercur_2243 = tmpcur_2198 + 8; + uint16_t tmptag_2244 = GIB_GET_TAG(tagged_tmpcur_8); + GibCursor end_from_tagged_indr_1352 = tmpcur_2242 + tmptag_2244; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_6 = + _copy_without_ptrs_ListB(tmpcur_2242, end_r_912, loc_908, tmpcur_2242); + GibCursor pvrtmp_2245 = tmp_struct_6.field0; + GibCursor pvrtmp_2246 = tmp_struct_6.field1; + GibCursor pvrtmp_2247 = tmp_struct_6.field2; + GibCursor pvrtmp_2248 = tmp_struct_6.field3; + GibCursor pvrtmp_2249 = tmp_struct_6.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_7; + + return_7.field0 = pvrtmp_2245; + return_7.field1 = pvrtmp_2246; + return_7.field2 = pvrtmp_2247; + return_7.field3 = pvrtmp_2248; + return_7.field4 = pvrtmp_2249; + return return_7; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2197"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_915, + GibCursor arg_98_264_439) +{ + GibPackedTag tmpval_2257 = *(GibPackedTag *) arg_98_264_439; + GibCursor tmpcur_2258 = arg_98_264_439 + 1; + + + switch_2273: + ; + switch (tmpval_2257) { + + case 0: + { + GibInt tmpval_2259 = *(GibInt *) tmpcur_2258; + GibCursor tmpcur_2260 = tmpcur_2258 + sizeof(GibInt); + GibCursor jump_1245 = tmpcur_2258 + 8; + GibCursorGibCursorProd tmp_struct_9 = + _traverse_ListA(end_r_915, tmpcur_2260); + GibCursor pvrtmp_2261 = tmp_struct_9.field0; + GibCursor pvrtmp_2262 = tmp_struct_9.field1; + GibCursorGibCursorProd return_10; + + return_10.field0 = pvrtmp_2261; + return_10.field1 = pvrtmp_2262; + return return_10; + break; + } + + case 1: + { + GibCursor jump_loc_1248 = arg_98_264_439 + 1; + GibCursorGibCursorProd return_11; + + return_11.field0 = end_r_915; + return_11.field1 = jump_loc_1248; + return return_11; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_14 = *(uintptr_t *) tmpcur_2258; + GibCursor tmpcur_2263 = GIB_UNTAG(tagged_tmpcur_14); + GibCursor tmpaftercur_2264 = tmpcur_2258 + 8; + uint16_t tmptag_2265 = GIB_GET_TAG(tagged_tmpcur_14); + GibCursor end_from_tagged_indr_1358 = tmpcur_2263 + tmptag_2265; + GibCursor jump_loc_1360 = tmpcur_2258 + 8; + GibCursorGibCursorProd tmp_struct_12 = + _traverse_ListA(tmpcur_2263, tmpcur_2263); + GibCursor pvrtmp_2266 = tmp_struct_12.field0; + GibCursor pvrtmp_2267 = tmp_struct_12.field1; + GibCursorGibCursorProd return_13; + + return_13.field0 = end_r_915; + return_13.field1 = jump_loc_1360; + return return_13; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_17 = *(uintptr_t *) tmpcur_2258; + GibCursor tmpcur_2268 = GIB_UNTAG(tagged_tmpcur_17); + GibCursor tmpaftercur_2269 = tmpcur_2258 + 8; + uint16_t tmptag_2270 = GIB_GET_TAG(tagged_tmpcur_17); + GibCursor end_from_tagged_indr_1358 = tmpcur_2268 + tmptag_2270; + GibCursorGibCursorProd tmp_struct_15 = + _traverse_ListA(tmpcur_2268, tmpcur_2268); + GibCursor pvrtmp_2271 = tmp_struct_15.field0; + GibCursor pvrtmp_2272 = tmp_struct_15.field1; + GibCursorGibCursorProd return_16; + + return_16.field0 = pvrtmp_2271; + return_16.field1 = pvrtmp_2272; + return return_16; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2257"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_List(GibCursor end_r_918, + GibCursor arg_153_268_443) +{ + GibPackedTag tmpval_2274 = *(GibPackedTag *) arg_153_268_443; + GibCursor tmpcur_2275 = arg_153_268_443 + 1; + + + switch_2298: + ; + switch (tmpval_2274) { + + case 0: + { + GibInt tmpval_2276 = *(GibInt *) tmpcur_2275; + GibCursor tmpcur_2277 = tmpcur_2275 + sizeof(GibInt); + GibInt tmpval_2278 = *(GibInt *) tmpcur_2277; + GibCursor tmpcur_2279 = tmpcur_2277 + sizeof(GibInt); + GibInt tmpval_2280 = *(GibInt *) tmpcur_2279; + GibCursor tmpcur_2281 = tmpcur_2279 + sizeof(GibInt); + GibInt tmpval_2282 = *(GibInt *) tmpcur_2281; + GibCursor tmpcur_2283 = tmpcur_2281 + sizeof(GibInt); + GibCursor jump_1253 = tmpcur_2281 + 8; + GibCursor jump_1252 = tmpcur_2279 + 8; + GibCursor jump_1251 = tmpcur_2277 + 8; + GibCursor jump_1250 = tmpcur_2275 + 8; + unsigned char wildcard_166_275_450 = gib_print_symbol(2182); + unsigned char wildcard_173_276_451 = gib_print_symbol(2185); + unsigned char y_160_277_452 = printf("%ld", tmpval_2276); + unsigned char wildcard_172_278_453 = gib_print_symbol(2185); + unsigned char y_161_279_454 = printf("%ld", tmpval_2278); + unsigned char wildcard_171_280_455 = gib_print_symbol(2185); + unsigned char y_162_281_456 = printf("%ld", tmpval_2280); + unsigned char wildcard_170_282_457 = gib_print_symbol(2185); + unsigned char y_163_283_458 = printf("%ld", tmpval_2282); + unsigned char wildcard_169_284_459 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_18 = + _print_ListA(end_r_918, tmpcur_2283); + GibCursor pvrtmp_2284 = tmp_struct_18.field0; + GibCursor pvrtmp_2285 = tmp_struct_18.field1; + unsigned char wildcard_168_286_461 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_19 = + _print_List(pvrtmp_2284, pvrtmp_2285); + GibCursor pvrtmp_2286 = tmp_struct_19.field0; + GibCursor pvrtmp_2287 = tmp_struct_19.field1; + unsigned char wildcard_167_288_463 = gib_print_symbol(2176); + GibCursorGibCursorProd return_20; + + return_20.field0 = pvrtmp_2286; + return_20.field1 = pvrtmp_2287; + return return_20; + break; + } + + case 1: + { + GibCursor jump_loc_1257 = arg_153_268_443 + 1; + unsigned char wildcard_174_289_464 = gib_print_symbol(2179); + unsigned char wildcard_175_290_465 = gib_print_symbol(2176); + GibCursorGibCursorProd return_21; + + return_21.field0 = end_r_918; + return_21.field1 = jump_loc_1257; + return return_21; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_24 = *(uintptr_t *) tmpcur_2275; + GibCursor tmpcur_2288 = GIB_UNTAG(tagged_tmpcur_24); + GibCursor tmpaftercur_2289 = tmpcur_2275 + 8; + uint16_t tmptag_2290 = GIB_GET_TAG(tagged_tmpcur_24); + GibCursor end_from_tagged_indr_1364 = tmpcur_2288 + tmptag_2290; + GibCursor jump_loc_1366 = tmpcur_2275 + 8; + unsigned char wildcard_1369 = gib_print_symbol(2184); + GibCursorGibCursorProd tmp_struct_22 = + _print_List(tmpcur_2288, tmpcur_2288); + GibCursor pvrtmp_2291 = tmp_struct_22.field0; + GibCursor pvrtmp_2292 = tmp_struct_22.field1; + GibCursorGibCursorProd return_23; + + return_23.field0 = end_r_918; + return_23.field1 = jump_loc_1366; + return return_23; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_27 = *(uintptr_t *) tmpcur_2275; + GibCursor tmpcur_2293 = GIB_UNTAG(tagged_tmpcur_27); + GibCursor tmpaftercur_2294 = tmpcur_2275 + 8; + uint16_t tmptag_2295 = GIB_GET_TAG(tagged_tmpcur_27); + GibCursor end_from_tagged_indr_1364 = tmpcur_2293 + tmptag_2295; + unsigned char wildcard_1369 = gib_print_symbol(2183); + GibCursorGibCursorProd tmp_struct_25 = + _print_List(tmpcur_2293, tmpcur_2293); + GibCursor pvrtmp_2296 = tmp_struct_25.field0; + GibCursor pvrtmp_2297 = tmp_struct_25.field1; + GibCursorGibCursorProd return_26; + + return_26.field0 = pvrtmp_2296; + return_26.field1 = pvrtmp_2297; + return return_26; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2274"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorProd mkListB(GibCursor end_r_921, GibCursor loc_919, + GibInt len_34_291_466) +{ + if (loc_919 + 58 > end_r_921) { + gib_grow_region(&loc_919, &end_r_921); + } + + GibBool fltIf_419_467 = len_34_291_466 <= 0; + + if (fltIf_419_467) { + *(GibPackedTag *) loc_919 = 1; + + GibCursor writetag_1651 = loc_919 + 1; + GibCursor after_tag_1652 = loc_919 + 1; + GibCursorGibCursorGibCursorProd return_28; + + return_28.field0 = end_r_921; + return_28.field1 = loc_919; + return_28.field2 = after_tag_1652; + return return_28; + } else { + GibInt fltAppE_420_468 = len_34_291_466 - 1; + GibCursor loc_1026 = loc_919 + 1; + GibCursor loc_1027 = loc_1026 + 8; + GibCursor loc_1028 = loc_1027 + 8; + GibCursor loc_1029 = loc_1028 + 8; + GibCursor loc_1030 = loc_1029 + 8; + GibCursor loc_1031 = loc_1030 + 8; + GibCursor loc_1032 = loc_1031 + 8; + + *(GibPackedTag *) loc_919 = 0; + + GibCursor writetag_1660 = loc_919 + 1; + GibCursor after_tag_1661 = loc_919 + 1; + + *(GibInt *) after_tag_1661 = len_34_291_466; + + GibCursor writecur_1665 = after_tag_1661 + sizeof(GibInt); + + *(GibInt *) writecur_1665 = len_34_291_466; + + GibCursor writecur_1666 = writecur_1665 + sizeof(GibInt); + + *(GibInt *) writecur_1666 = len_34_291_466; + + GibCursor writecur_1667 = writecur_1666 + sizeof(GibInt); + + *(GibInt *) writecur_1667 = len_34_291_466; + + GibCursor writecur_1668 = writecur_1667 + sizeof(GibInt); + + *(GibInt *) writecur_1668 = len_34_291_466; + + GibCursor writecur_1669 = writecur_1668 + sizeof(GibInt); + + *(GibInt *) writecur_1669 = len_34_291_466; + + GibCursor writecur_1670 = writecur_1669 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd tmp_struct_29 = + mkListB(end_r_921, loc_1032, fltAppE_420_468); + GibCursor pvrtmp_2303 = tmp_struct_29.field0; + GibCursor pvrtmp_2304 = tmp_struct_29.field1; + GibCursor pvrtmp_2305 = tmp_struct_29.field2; + GibCursorGibCursorGibCursorProd return_30; + + return_30.field0 = pvrtmp_2303; + return_30.field1 = loc_919; + return_30.field2 = pvrtmp_2305; + return return_30; + } +} +GibCursorGibCursorProd _traverse_List(GibCursor end_r_924, + GibCursor arg_140_293_470) +{ + GibPackedTag tmpval_2314 = *(GibPackedTag *) arg_140_293_470; + GibCursor tmpcur_2315 = arg_140_293_470 + 1; + + + switch_2338: + ; + switch (tmpval_2314) { + + case 0: + { + GibInt tmpval_2316 = *(GibInt *) tmpcur_2315; + GibCursor tmpcur_2317 = tmpcur_2315 + sizeof(GibInt); + GibInt tmpval_2318 = *(GibInt *) tmpcur_2317; + GibCursor tmpcur_2319 = tmpcur_2317 + sizeof(GibInt); + GibInt tmpval_2320 = *(GibInt *) tmpcur_2319; + GibCursor tmpcur_2321 = tmpcur_2319 + sizeof(GibInt); + GibInt tmpval_2322 = *(GibInt *) tmpcur_2321; + GibCursor tmpcur_2323 = tmpcur_2321 + sizeof(GibInt); + GibCursor jump_1264 = tmpcur_2321 + 8; + GibCursor jump_1263 = tmpcur_2319 + 8; + GibCursor jump_1262 = tmpcur_2317 + 8; + GibCursor jump_1261 = tmpcur_2315 + 8; + GibCursorGibCursorProd tmp_struct_34 = + _traverse_ListA(end_r_924, tmpcur_2323); + GibCursor pvrtmp_2324 = tmp_struct_34.field0; + GibCursor pvrtmp_2325 = tmp_struct_34.field1; + GibCursorGibCursorProd tmp_struct_35 = + _traverse_List(pvrtmp_2324, pvrtmp_2325); + GibCursor pvrtmp_2326 = tmp_struct_35.field0; + GibCursor pvrtmp_2327 = tmp_struct_35.field1; + GibCursorGibCursorProd return_36; + + return_36.field0 = pvrtmp_2326; + return_36.field1 = pvrtmp_2327; + return return_36; + break; + } + + case 1: + { + GibCursor jump_loc_1268 = arg_140_293_470 + 1; + GibCursorGibCursorProd return_37; + + return_37.field0 = end_r_924; + return_37.field1 = jump_loc_1268; + return return_37; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_40 = *(uintptr_t *) tmpcur_2315; + GibCursor tmpcur_2328 = GIB_UNTAG(tagged_tmpcur_40); + GibCursor tmpaftercur_2329 = tmpcur_2315 + 8; + uint16_t tmptag_2330 = GIB_GET_TAG(tagged_tmpcur_40); + GibCursor end_from_tagged_indr_1370 = tmpcur_2328 + tmptag_2330; + GibCursor jump_loc_1372 = tmpcur_2315 + 8; + GibCursorGibCursorProd tmp_struct_38 = + _traverse_List(tmpcur_2328, tmpcur_2328); + GibCursor pvrtmp_2331 = tmp_struct_38.field0; + GibCursor pvrtmp_2332 = tmp_struct_38.field1; + GibCursorGibCursorProd return_39; + + return_39.field0 = end_r_924; + return_39.field1 = jump_loc_1372; + return return_39; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_43 = *(uintptr_t *) tmpcur_2315; + GibCursor tmpcur_2333 = GIB_UNTAG(tagged_tmpcur_43); + GibCursor tmpaftercur_2334 = tmpcur_2315 + 8; + uint16_t tmptag_2335 = GIB_GET_TAG(tagged_tmpcur_43); + GibCursor end_from_tagged_indr_1370 = tmpcur_2333 + tmptag_2335; + GibCursorGibCursorProd tmp_struct_41 = + _traverse_List(tmpcur_2333, tmpcur_2333); + GibCursor pvrtmp_2336 = tmp_struct_41.field0; + GibCursor pvrtmp_2337 = tmp_struct_41.field1; + GibCursorGibCursorProd return_42; + + return_42.field0 = pvrtmp_2336; + return_42.field1 = pvrtmp_2337; + return return_42; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2314"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_ListA(GibCursor end_r_928, + GibCursor end_r_930, + GibCursor loc_926, + GibCursor arg_93_302_479) +{ + GibPackedTag tmpval_2339 = *(GibPackedTag *) arg_93_302_479; + GibCursor tmpcur_2340 = arg_93_302_479 + 1; + + + switch_2388: + ; + switch (tmpval_2339) { + + case 0: + { + GibInt tmpval_2341 = *(GibInt *) tmpcur_2340; + GibCursor tmpcur_2342 = tmpcur_2340 + sizeof(GibInt); + GibCursor jump_1270 = tmpcur_2340 + 8; + GibCursor loc_1065 = loc_926 + 1; + GibCursor loc_1066 = loc_1065 + 8; + + *(GibPackedTag *) loc_926 = 0; + + GibCursor writetag_1699 = loc_926 + 1; + GibCursor after_tag_1700 = loc_926 + 1; + + *(GibInt *) after_tag_1700 = tmpval_2341; + + GibCursor writecur_1704 = after_tag_1700 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_44 = + _copy_without_ptrs_ListA(end_r_928, end_r_930, loc_1066, tmpcur_2342); + GibCursor pvrtmp_2343 = tmp_struct_44.field0; + GibCursor pvrtmp_2344 = tmp_struct_44.field1; + GibCursor pvrtmp_2345 = tmp_struct_44.field2; + GibCursor pvrtmp_2346 = tmp_struct_44.field3; + GibCursor pvrtmp_2347 = tmp_struct_44.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_45; + + return_45.field0 = pvrtmp_2343; + return_45.field1 = pvrtmp_2344; + return_45.field2 = pvrtmp_2345; + return_45.field3 = loc_926; + return_45.field4 = pvrtmp_2347; + return return_45; + break; + } + + case 1: + { + GibCursor jump_loc_1273 = arg_93_302_479 + 1; + + *(GibPackedTag *) loc_926 = 1; + + GibCursor writetag_1709 = loc_926 + 1; + GibCursor after_tag_1710 = loc_926 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_46; + + return_46.field0 = end_r_928; + return_46.field1 = end_r_930; + return_46.field2 = jump_loc_1273; + return_46.field3 = loc_926; + return_46.field4 = after_tag_1710; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2360 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_2361 = tmpcur_2340 + 8; + uint16_t tmptag_2362 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_1376 = tmpcur_2360 + tmptag_2362; + GibCursor jump_loc_1378 = tmpcur_2340 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_47 = + _copy_without_ptrs_ListA(tmpcur_2360, end_r_930, loc_926, tmpcur_2360); + GibCursor pvrtmp_2363 = tmp_struct_47.field0; + GibCursor pvrtmp_2364 = tmp_struct_47.field1; + GibCursor pvrtmp_2365 = tmp_struct_47.field2; + GibCursor pvrtmp_2366 = tmp_struct_47.field3; + GibCursor pvrtmp_2367 = tmp_struct_47.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_48; + + return_48.field0 = end_r_928; + return_48.field1 = pvrtmp_2364; + return_48.field2 = jump_loc_1378; + return_48.field3 = pvrtmp_2366; + return_48.field4 = pvrtmp_2367; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2374 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_2375 = tmpcur_2340 + 8; + uint16_t tmptag_2376 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_1376 = tmpcur_2374 + tmptag_2376; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_50 = + _copy_without_ptrs_ListA(tmpcur_2374, end_r_930, loc_926, tmpcur_2374); + GibCursor pvrtmp_2377 = tmp_struct_50.field0; + GibCursor pvrtmp_2378 = tmp_struct_50.field1; + GibCursor pvrtmp_2379 = tmp_struct_50.field2; + GibCursor pvrtmp_2380 = tmp_struct_50.field3; + GibCursor pvrtmp_2381 = tmp_struct_50.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_2377; + return_51.field1 = pvrtmp_2378; + return_51.field2 = pvrtmp_2379; + return_51.field3 = pvrtmp_2380; + return_51.field4 = pvrtmp_2381; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2339"); + exit(1); + } + } +} + +void reduceB(GibCursor *end_r_933, + GibCursor *lst_36_307_484, + GibInt *res) +{ + GibPackedTag tmpval_2389 = *(GibPackedTag *) (*lst_36_307_484); + //GibCursor tmpcur_2390 = lst_36_307_484 + 1; + *lst_36_307_484 += 1; + + + switch_2418: + ; + switch (tmpval_2389) { + + case 1: + { + //GibCursor jump_loc_1276 = lst_36_307_484 + 1; + GibCursorGibCursorGibIntProd return_53; + + //return_53.field0 = end_r_933; + //return_53.field1 = jump_loc_1276; + //return_53.field2 = 0; + *res += 0; + //return return_53; + break; + } + + case 0: + { + GibInt tmpval_2391 = *(GibInt *) (*lst_36_307_484); + + // GibCursor tmpcur_2392 = tmpcur_2390 + sizeof(GibInt); + // + // GibInt tmpval_2393 = *(GibInt *) tmpcur_2392; + // GibCursor tmpcur_2394 = tmpcur_2392 + sizeof(GibInt); + // GibInt tmpval_2395 = *(GibInt *) tmpcur_2394; + // GibCursor tmpcur_2396 = tmpcur_2394 + sizeof(GibInt); + // GibInt tmpval_2397 = *(GibInt *) tmpcur_2396; + // GibCursor tmpcur_2398 = tmpcur_2396 + sizeof(GibInt); + // GibInt tmpval_2399 = *(GibInt *) tmpcur_2398; + // GibCursor tmpcur_2400 = tmpcur_2398 + sizeof(GibInt); + // GibInt tmpval_2401 = *(GibInt *) tmpcur_2400; + // GibCursor tmpcur_2402 = tmpcur_2400 + sizeof(GibInt); + + //*lst_36_307_484 += ((sizeof(GibInt)) * 6); + + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + + // GibCursor jump_1282 = tmpcur_2400 + 8; + // GibCursor jump_1281 = tmpcur_2398 + 8; + // GibCursor jump_1280 = tmpcur_2396 + 8; + // GibCursor jump_1279 = tmpcur_2394 + 8; + // GibCursor jump_1278 = tmpcur_2392 + 8; + // GibCursor jump_1277 = tmpcur_2390 + 8; + + *res = *res + tmpval_2391; + reduceB(end_r_933, lst_36_307_484, res); + + //GibCursor pvrtmp_2403 = tmp_struct_54.field0; + //GibCursor pvrtmp_2404 = tmp_struct_54.field1; + // GibInt pvrtmp_2405 = tmp_struct_54.field2; + // GibInt tailprim_1284 = tmpval_2391 + pvrtmp_2405; + // GibCursorGibCursorGibIntProd return_55; + + //return_55.field0 = pvrtmp_2403; + //return_55.field1 = pvrtmp_2404; + // return_55.field2 = tailprim_1284; + // return return_55; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// uintptr_t tagged_tmpcur_58 = *(uintptr_t *) tmpcur_2390; +// GibCursor tmpcur_2406 = GIB_UNTAG(tagged_tmpcur_58); +// GibCursor tmpaftercur_2407 = tmpcur_2390 + 8; +// uint16_t tmptag_2408 = GIB_GET_TAG(tagged_tmpcur_58); +// GibCursor end_from_tagged_indr_1382 = tmpcur_2406 + tmptag_2408; +// GibCursor jump_loc_1384 = tmpcur_2390 + 8; +// GibCursorGibCursorGibIntProd tmp_struct_56 = +// reduceB(tmpcur_2406, tmpcur_2406); +// GibCursor pvrtmp_2409 = tmp_struct_56.field0; +// GibCursor pvrtmp_2410 = tmp_struct_56.field1; +// GibInt pvrtmp_2411 = tmp_struct_56.field2; +// GibCursorGibCursorGibIntProd return_57; +// +// return_57.field0 = end_r_933; +// return_57.field1 = jump_loc_1384; +// return_57.field2 = pvrtmp_2411; +// return return_57; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_61 = *(uintptr_t *) (*lst_36_307_484); + GibCursor tmpcur_2412 = GIB_UNTAG(tagged_tmpcur_61); + //GibCursor tmpaftercur_2413 = tmpcur_2390 + 8; + *lst_36_307_484 = tmpcur_2412; + + // uint16_t tmptag_2414 = GIB_GET_TAG(tagged_tmpcur_61); + // GibCursor end_from_tagged_indr_1382 = tmpcur_2412 + tmptag_2414; + + reduceB(lst_36_307_484, lst_36_307_484, res); + +// GibCursor pvrtmp_2415 = tmp_struct_59.field0; +// GibCursor pvrtmp_2416 = tmp_struct_59.field1; +// GibInt pvrtmp_2417 = tmp_struct_59.field2; +// GibCursorGibCursorGibIntProd return_60; +// +// return_60.field0 = pvrtmp_2415; +// return_60.field1 = pvrtmp_2416; +// return_60.field2 = pvrtmp_2417; +// return return_60; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2389"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_ListA(GibCursor end_r_937, + GibCursor end_r_939, + GibCursor loc_935, + GibCursor arg_88_315_493) +{ + if (loc_935 + 18 > end_r_939) { + gib_grow_region(&loc_935, &end_r_939); + } + + GibPackedTag tmpval_2419 = *(GibPackedTag *) arg_88_315_493; + GibCursor tmpcur_2420 = arg_88_315_493 + 1; + + + switch_2468: + ; + switch (tmpval_2419) { + + case 0: + { + GibInt tmpval_2421 = *(GibInt *) tmpcur_2420; + GibCursor tmpcur_2422 = tmpcur_2420 + sizeof(GibInt); + GibCursor jump_1285 = tmpcur_2420 + 8; + GibCursor loc_1089 = loc_935 + 1; + GibCursor loc_1090 = loc_1089 + 8; + + *(GibPackedTag *) loc_935 = 0; + + GibCursor writetag_1751 = loc_935 + 1; + GibCursor after_tag_1752 = loc_935 + 1; + + *(GibInt *) after_tag_1752 = tmpval_2421; + + GibCursor writecur_1756 = after_tag_1752 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_62 = + _copy_ListA(end_r_937, end_r_939, loc_1090, tmpcur_2422); + GibCursor pvrtmp_2423 = tmp_struct_62.field0; + GibCursor pvrtmp_2424 = tmp_struct_62.field1; + GibCursor pvrtmp_2425 = tmp_struct_62.field2; + GibCursor pvrtmp_2426 = tmp_struct_62.field3; + GibCursor pvrtmp_2427 = tmp_struct_62.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_63; + + return_63.field0 = pvrtmp_2423; + return_63.field1 = pvrtmp_2424; + return_63.field2 = pvrtmp_2425; + return_63.field3 = loc_935; + return_63.field4 = pvrtmp_2427; + return return_63; + break; + } + + case 1: + { + GibCursor jump_loc_1288 = arg_88_315_493 + 1; + + *(GibPackedTag *) loc_935 = 1; + + GibCursor writetag_1761 = loc_935 + 1; + GibCursor after_tag_1762 = loc_935 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_64; + + return_64.field0 = end_r_937; + return_64.field1 = end_r_939; + return_64.field2 = jump_loc_1288; + return_64.field3 = loc_935; + return_64.field4 = after_tag_1762; + return return_64; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_67 = *(uintptr_t *) tmpcur_2420; + GibCursor tmpcur_2440 = GIB_UNTAG(tagged_tmpcur_67); + GibCursor tmpaftercur_2441 = tmpcur_2420 + 8; + uint16_t tmptag_2442 = GIB_GET_TAG(tagged_tmpcur_67); + GibCursor end_from_tagged_indr_1388 = tmpcur_2440 + tmptag_2442; + GibCursor jump_loc_1390 = tmpcur_2420 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_65 = + _copy_ListA(tmpcur_2440, end_r_939, loc_935, tmpcur_2440); + GibCursor pvrtmp_2443 = tmp_struct_65.field0; + GibCursor pvrtmp_2444 = tmp_struct_65.field1; + GibCursor pvrtmp_2445 = tmp_struct_65.field2; + GibCursor pvrtmp_2446 = tmp_struct_65.field3; + GibCursor pvrtmp_2447 = tmp_struct_65.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_66; + + return_66.field0 = end_r_937; + return_66.field1 = pvrtmp_2444; + return_66.field2 = jump_loc_1390; + return_66.field3 = pvrtmp_2446; + return_66.field4 = pvrtmp_2447; + return return_66; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_70 = *(uintptr_t *) tmpcur_2420; + GibCursor tmpcur_2454 = GIB_UNTAG(tagged_tmpcur_70); + GibCursor tmpaftercur_2455 = tmpcur_2420 + 8; + uint16_t tmptag_2456 = GIB_GET_TAG(tagged_tmpcur_70); + GibCursor end_from_tagged_indr_1388 = tmpcur_2454 + tmptag_2456; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_68 = + _copy_ListA(tmpcur_2454, end_r_939, loc_935, tmpcur_2454); + GibCursor pvrtmp_2457 = tmp_struct_68.field0; + GibCursor pvrtmp_2458 = tmp_struct_68.field1; + GibCursor pvrtmp_2459 = tmp_struct_68.field2; + GibCursor pvrtmp_2460 = tmp_struct_68.field3; + GibCursor pvrtmp_2461 = tmp_struct_68.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_69; + + return_69.field0 = pvrtmp_2457; + return_69.field1 = pvrtmp_2458; + return_69.field2 = pvrtmp_2459; + return_69.field3 = pvrtmp_2460; + return_69.field4 = pvrtmp_2461; + return return_69; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2419"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_ListB(GibCursor end_r_943, + GibCursor end_r_945, + GibCursor loc_941, + GibCursor arg_176_330_498) +{ + if (loc_941 + 58 > end_r_945) { + gib_grow_region(&loc_941, &end_r_945); + } + + GibPackedTag tmpval_2469 = *(GibPackedTag *) arg_176_330_498; + GibCursor tmpcur_2470 = arg_176_330_498 + 1; + + + switch_2528: + ; + switch (tmpval_2469) { + + case 0: + { + GibInt tmpval_2471 = *(GibInt *) tmpcur_2470; + GibCursor tmpcur_2472 = tmpcur_2470 + sizeof(GibInt); + GibInt tmpval_2473 = *(GibInt *) tmpcur_2472; + GibCursor tmpcur_2474 = tmpcur_2472 + sizeof(GibInt); + GibInt tmpval_2475 = *(GibInt *) tmpcur_2474; + GibCursor tmpcur_2476 = tmpcur_2474 + sizeof(GibInt); + GibInt tmpval_2477 = *(GibInt *) tmpcur_2476; + GibCursor tmpcur_2478 = tmpcur_2476 + sizeof(GibInt); + GibInt tmpval_2479 = *(GibInt *) tmpcur_2478; + GibCursor tmpcur_2480 = tmpcur_2478 + sizeof(GibInt); + GibInt tmpval_2481 = *(GibInt *) tmpcur_2480; + GibCursor tmpcur_2482 = tmpcur_2480 + sizeof(GibInt); + GibCursor jump_1295 = tmpcur_2480 + 8; + GibCursor jump_1294 = tmpcur_2478 + 8; + GibCursor jump_1293 = tmpcur_2476 + 8; + GibCursor jump_1292 = tmpcur_2474 + 8; + GibCursor jump_1291 = tmpcur_2472 + 8; + GibCursor jump_1290 = tmpcur_2470 + 8; + GibCursor loc_1107 = loc_941 + 1; + GibCursor loc_1108 = loc_1107 + 8; + GibCursor loc_1109 = loc_1108 + 8; + GibCursor loc_1110 = loc_1109 + 8; + GibCursor loc_1111 = loc_1110 + 8; + GibCursor loc_1112 = loc_1111 + 8; + GibCursor loc_1113 = loc_1112 + 8; + + *(GibPackedTag *) loc_941 = 0; + + GibCursor writetag_1789 = loc_941 + 1; + GibCursor after_tag_1790 = loc_941 + 1; + + *(GibInt *) after_tag_1790 = tmpval_2471; + + GibCursor writecur_1794 = after_tag_1790 + sizeof(GibInt); + + *(GibInt *) writecur_1794 = tmpval_2473; + + GibCursor writecur_1795 = writecur_1794 + sizeof(GibInt); + + *(GibInt *) writecur_1795 = tmpval_2475; + + GibCursor writecur_1796 = writecur_1795 + sizeof(GibInt); + + *(GibInt *) writecur_1796 = tmpval_2477; + + GibCursor writecur_1797 = writecur_1796 + sizeof(GibInt); + + *(GibInt *) writecur_1797 = tmpval_2479; + + GibCursor writecur_1798 = writecur_1797 + sizeof(GibInt); + + *(GibInt *) writecur_1798 = tmpval_2481; + + GibCursor writecur_1799 = writecur_1798 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_74 = + _copy_ListB(end_r_943, end_r_945, loc_1113, tmpcur_2482); + GibCursor pvrtmp_2483 = tmp_struct_74.field0; + GibCursor pvrtmp_2484 = tmp_struct_74.field1; + GibCursor pvrtmp_2485 = tmp_struct_74.field2; + GibCursor pvrtmp_2486 = tmp_struct_74.field3; + GibCursor pvrtmp_2487 = tmp_struct_74.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_75; + + return_75.field0 = pvrtmp_2483; + return_75.field1 = pvrtmp_2484; + return_75.field2 = pvrtmp_2485; + return_75.field3 = loc_941; + return_75.field4 = pvrtmp_2487; + return return_75; + break; + } + + case 1: + { + GibCursor jump_loc_1298 = arg_176_330_498 + 1; + + *(GibPackedTag *) loc_941 = 1; + + GibCursor writetag_1804 = loc_941 + 1; + GibCursor after_tag_1805 = loc_941 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_76; + + return_76.field0 = end_r_943; + return_76.field1 = end_r_945; + return_76.field2 = jump_loc_1298; + return_76.field3 = loc_941; + return_76.field4 = after_tag_1805; + return return_76; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_79 = *(uintptr_t *) tmpcur_2470; + GibCursor tmpcur_2500 = GIB_UNTAG(tagged_tmpcur_79); + GibCursor tmpaftercur_2501 = tmpcur_2470 + 8; + uint16_t tmptag_2502 = GIB_GET_TAG(tagged_tmpcur_79); + GibCursor end_from_tagged_indr_1394 = tmpcur_2500 + tmptag_2502; + GibCursor jump_loc_1396 = tmpcur_2470 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_77 = + _copy_ListB(tmpcur_2500, end_r_945, loc_941, tmpcur_2500); + GibCursor pvrtmp_2503 = tmp_struct_77.field0; + GibCursor pvrtmp_2504 = tmp_struct_77.field1; + GibCursor pvrtmp_2505 = tmp_struct_77.field2; + GibCursor pvrtmp_2506 = tmp_struct_77.field3; + GibCursor pvrtmp_2507 = tmp_struct_77.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_78; + + return_78.field0 = end_r_943; + return_78.field1 = pvrtmp_2504; + return_78.field2 = jump_loc_1396; + return_78.field3 = pvrtmp_2506; + return_78.field4 = pvrtmp_2507; + return return_78; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_82 = *(uintptr_t *) tmpcur_2470; + GibCursor tmpcur_2514 = GIB_UNTAG(tagged_tmpcur_82); + GibCursor tmpaftercur_2515 = tmpcur_2470 + 8; + uint16_t tmptag_2516 = GIB_GET_TAG(tagged_tmpcur_82); + GibCursor end_from_tagged_indr_1394 = tmpcur_2514 + tmptag_2516; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_80 = + _copy_ListB(tmpcur_2514, end_r_945, loc_941, tmpcur_2514); + GibCursor pvrtmp_2517 = tmp_struct_80.field0; + GibCursor pvrtmp_2518 = tmp_struct_80.field1; + GibCursor pvrtmp_2519 = tmp_struct_80.field2; + GibCursor pvrtmp_2520 = tmp_struct_80.field3; + GibCursor pvrtmp_2521 = tmp_struct_80.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_81; + + return_81.field0 = pvrtmp_2517; + return_81.field1 = pvrtmp_2518; + return_81.field2 = pvrtmp_2519; + return_81.field3 = pvrtmp_2520; + return_81.field4 = pvrtmp_2521; + return return_81; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2469"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_List(GibCursor end_r_949, + GibCursor end_r_951, + GibCursor loc_947, + GibCursor arg_114_345_513) +{ + if (loc_947 + 42 > end_r_951) { + gib_grow_region(&loc_947, &end_r_951); + } + + GibPackedTag tmpval_2529 = *(GibPackedTag *) arg_114_345_513; + GibCursor tmpcur_2530 = arg_114_345_513 + 1; + + + switch_2593: + ; + switch (tmpval_2529) { + + case 0: + { + GibInt tmpval_2531 = *(GibInt *) tmpcur_2530; + GibCursor tmpcur_2532 = tmpcur_2530 + sizeof(GibInt); + GibInt tmpval_2533 = *(GibInt *) tmpcur_2532; + GibCursor tmpcur_2534 = tmpcur_2532 + sizeof(GibInt); + GibInt tmpval_2535 = *(GibInt *) tmpcur_2534; + GibCursor tmpcur_2536 = tmpcur_2534 + sizeof(GibInt); + GibInt tmpval_2537 = *(GibInt *) tmpcur_2536; + GibCursor tmpcur_2538 = tmpcur_2536 + sizeof(GibInt); + GibCursor jump_1303 = tmpcur_2536 + 8; + GibCursor jump_1302 = tmpcur_2534 + 8; + GibCursor jump_1301 = tmpcur_2532 + 8; + GibCursor jump_1300 = tmpcur_2530 + 8; + GibCursor loc_1142 = loc_947 + 1; + GibCursor loc_1143 = loc_1142 + 8; + GibCursor loc_1144 = loc_1143 + 8; + GibCursor loc_1145 = loc_1144 + 8; + GibCursor loc_1146 = loc_1145 + 8; + + *(GibPackedTag *) loc_947 = 0; + + GibCursor writetag_1833 = loc_947 + 1; + GibCursor after_tag_1834 = loc_947 + 1; + + *(GibInt *) after_tag_1834 = tmpval_2531; + + GibCursor writecur_1838 = after_tag_1834 + sizeof(GibInt); + + *(GibInt *) writecur_1838 = tmpval_2533; + + GibCursor writecur_1839 = writecur_1838 + sizeof(GibInt); + + *(GibInt *) writecur_1839 = tmpval_2535; + + GibCursor writecur_1840 = writecur_1839 + sizeof(GibInt); + + *(GibInt *) writecur_1840 = tmpval_2537; + + GibCursor writecur_1841 = writecur_1840 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_86 = + _copy_ListA(end_r_949, end_r_951, loc_1146, tmpcur_2538); + GibCursor pvrtmp_2539 = tmp_struct_86.field0; + GibCursor pvrtmp_2540 = tmp_struct_86.field1; + GibCursor pvrtmp_2541 = tmp_struct_86.field2; + GibCursor pvrtmp_2542 = tmp_struct_86.field3; + GibCursor pvrtmp_2543 = tmp_struct_86.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_87 = + _copy_List(pvrtmp_2539, pvrtmp_2540, pvrtmp_2543, pvrtmp_2541); + GibCursor pvrtmp_2548 = tmp_struct_87.field0; + GibCursor pvrtmp_2549 = tmp_struct_87.field1; + GibCursor pvrtmp_2550 = tmp_struct_87.field2; + GibCursor pvrtmp_2551 = tmp_struct_87.field3; + GibCursor pvrtmp_2552 = tmp_struct_87.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_88; + + return_88.field0 = pvrtmp_2548; + return_88.field1 = pvrtmp_2549; + return_88.field2 = pvrtmp_2550; + return_88.field3 = loc_947; + return_88.field4 = pvrtmp_2552; + return return_88; + break; + } + + case 1: + { + GibCursor jump_loc_1307 = arg_114_345_513 + 1; + + *(GibPackedTag *) loc_947 = 1; + + GibCursor writetag_1848 = loc_947 + 1; + GibCursor after_tag_1849 = loc_947 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_89; + + return_89.field0 = end_r_949; + return_89.field1 = end_r_951; + return_89.field2 = jump_loc_1307; + return_89.field3 = loc_947; + return_89.field4 = after_tag_1849; + return return_89; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_92 = *(uintptr_t *) tmpcur_2530; + GibCursor tmpcur_2565 = GIB_UNTAG(tagged_tmpcur_92); + GibCursor tmpaftercur_2566 = tmpcur_2530 + 8; + uint16_t tmptag_2567 = GIB_GET_TAG(tagged_tmpcur_92); + GibCursor end_from_tagged_indr_1400 = tmpcur_2565 + tmptag_2567; + GibCursor jump_loc_1402 = tmpcur_2530 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_90 = + _copy_List(tmpcur_2565, end_r_951, loc_947, tmpcur_2565); + GibCursor pvrtmp_2568 = tmp_struct_90.field0; + GibCursor pvrtmp_2569 = tmp_struct_90.field1; + GibCursor pvrtmp_2570 = tmp_struct_90.field2; + GibCursor pvrtmp_2571 = tmp_struct_90.field3; + GibCursor pvrtmp_2572 = tmp_struct_90.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_91; + + return_91.field0 = end_r_949; + return_91.field1 = pvrtmp_2569; + return_91.field2 = jump_loc_1402; + return_91.field3 = pvrtmp_2571; + return_91.field4 = pvrtmp_2572; + return return_91; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_95 = *(uintptr_t *) tmpcur_2530; + GibCursor tmpcur_2579 = GIB_UNTAG(tagged_tmpcur_95); + GibCursor tmpaftercur_2580 = tmpcur_2530 + 8; + uint16_t tmptag_2581 = GIB_GET_TAG(tagged_tmpcur_95); + GibCursor end_from_tagged_indr_1400 = tmpcur_2579 + tmptag_2581; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_93 = + _copy_List(tmpcur_2579, end_r_951, loc_947, tmpcur_2579); + GibCursor pvrtmp_2582 = tmp_struct_93.field0; + GibCursor pvrtmp_2583 = tmp_struct_93.field1; + GibCursor pvrtmp_2584 = tmp_struct_93.field2; + GibCursor pvrtmp_2585 = tmp_struct_93.field3; + GibCursor pvrtmp_2586 = tmp_struct_93.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_94; + + return_94.field0 = pvrtmp_2582; + return_94.field1 = pvrtmp_2583; + return_94.field2 = pvrtmp_2584; + return_94.field3 = pvrtmp_2585; + return_94.field4 = pvrtmp_2586; + return return_94; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2529"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_ListB(GibCursor end_r_954, + GibCursor arg_206_358_526) +{ + GibPackedTag tmpval_2594 = *(GibPackedTag *) arg_206_358_526; + GibCursor tmpcur_2595 = arg_206_358_526 + 1; + + + switch_2620: + ; + switch (tmpval_2594) { + + case 0: + { + GibInt tmpval_2596 = *(GibInt *) tmpcur_2595; + GibCursor tmpcur_2597 = tmpcur_2595 + sizeof(GibInt); + GibInt tmpval_2598 = *(GibInt *) tmpcur_2597; + GibCursor tmpcur_2599 = tmpcur_2597 + sizeof(GibInt); + GibInt tmpval_2600 = *(GibInt *) tmpcur_2599; + GibCursor tmpcur_2601 = tmpcur_2599 + sizeof(GibInt); + GibInt tmpval_2602 = *(GibInt *) tmpcur_2601; + GibCursor tmpcur_2603 = tmpcur_2601 + sizeof(GibInt); + GibInt tmpval_2604 = *(GibInt *) tmpcur_2603; + GibCursor tmpcur_2605 = tmpcur_2603 + sizeof(GibInt); + GibInt tmpval_2606 = *(GibInt *) tmpcur_2605; + GibCursor tmpcur_2607 = tmpcur_2605 + sizeof(GibInt); + GibCursor jump_1314 = tmpcur_2605 + 8; + GibCursor jump_1313 = tmpcur_2603 + 8; + GibCursor jump_1312 = tmpcur_2601 + 8; + GibCursor jump_1311 = tmpcur_2599 + 8; + GibCursor jump_1310 = tmpcur_2597 + 8; + GibCursor jump_1309 = tmpcur_2595 + 8; + GibCursorGibCursorProd tmp_struct_99 = + _traverse_ListB(end_r_954, tmpcur_2607); + GibCursor pvrtmp_2608 = tmp_struct_99.field0; + GibCursor pvrtmp_2609 = tmp_struct_99.field1; + GibCursorGibCursorProd return_100; + + return_100.field0 = pvrtmp_2608; + return_100.field1 = pvrtmp_2609; + return return_100; + break; + } + + case 1: + { + GibCursor jump_loc_1317 = arg_206_358_526 + 1; + GibCursorGibCursorProd return_101; + + return_101.field0 = end_r_954; + return_101.field1 = jump_loc_1317; + return return_101; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_104 = *(uintptr_t *) tmpcur_2595; + GibCursor tmpcur_2610 = GIB_UNTAG(tagged_tmpcur_104); + GibCursor tmpaftercur_2611 = tmpcur_2595 + 8; + uint16_t tmptag_2612 = GIB_GET_TAG(tagged_tmpcur_104); + GibCursor end_from_tagged_indr_1406 = tmpcur_2610 + tmptag_2612; + GibCursor jump_loc_1408 = tmpcur_2595 + 8; + GibCursorGibCursorProd tmp_struct_102 = + _traverse_ListB(tmpcur_2610, tmpcur_2610); + GibCursor pvrtmp_2613 = tmp_struct_102.field0; + GibCursor pvrtmp_2614 = tmp_struct_102.field1; + GibCursorGibCursorProd return_103; + + return_103.field0 = end_r_954; + return_103.field1 = jump_loc_1408; + return return_103; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_107 = *(uintptr_t *) tmpcur_2595; + GibCursor tmpcur_2615 = GIB_UNTAG(tagged_tmpcur_107); + GibCursor tmpaftercur_2616 = tmpcur_2595 + 8; + uint16_t tmptag_2617 = GIB_GET_TAG(tagged_tmpcur_107); + GibCursor end_from_tagged_indr_1406 = tmpcur_2615 + tmptag_2617; + GibCursorGibCursorProd tmp_struct_105 = + _traverse_ListB(tmpcur_2615, tmpcur_2615); + GibCursor pvrtmp_2618 = tmp_struct_105.field0; + GibCursor pvrtmp_2619 = tmp_struct_105.field1; + GibCursorGibCursorProd return_106; + + return_106.field0 = pvrtmp_2618; + return_106.field1 = pvrtmp_2619; + return return_106; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2594"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_ListA(GibCursor end_r_957, + GibCursor arg_103_369_535) +{ + GibPackedTag tmpval_2621 = *(GibPackedTag *) arg_103_369_535; + GibCursor tmpcur_2622 = arg_103_369_535 + 1; + + + switch_2637: + ; + switch (tmpval_2621) { + + case 0: + { + GibInt tmpval_2623 = *(GibInt *) tmpcur_2622; + GibCursor tmpcur_2624 = tmpcur_2622 + sizeof(GibInt); + GibCursor jump_1319 = tmpcur_2622 + 8; + unsigned char wildcard_108_372_538 = gib_print_symbol(2181); + unsigned char wildcard_111_373_539 = gib_print_symbol(2185); + unsigned char y_106_374_540 = printf("%ld", tmpval_2623); + unsigned char wildcard_110_375_541 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_108 = + _print_ListA(end_r_957, tmpcur_2624); + GibCursor pvrtmp_2625 = tmp_struct_108.field0; + GibCursor pvrtmp_2626 = tmp_struct_108.field1; + unsigned char wildcard_109_377_543 = gib_print_symbol(2176); + GibCursorGibCursorProd return_109; + + return_109.field0 = pvrtmp_2625; + return_109.field1 = pvrtmp_2626; + return return_109; + break; + } + + case 1: + { + GibCursor jump_loc_1322 = arg_103_369_535 + 1; + unsigned char wildcard_112_378_544 = gib_print_symbol(2178); + unsigned char wildcard_113_379_545 = gib_print_symbol(2176); + GibCursorGibCursorProd return_110; + + return_110.field0 = end_r_957; + return_110.field1 = jump_loc_1322; + return return_110; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_113 = *(uintptr_t *) tmpcur_2622; + GibCursor tmpcur_2627 = GIB_UNTAG(tagged_tmpcur_113); + GibCursor tmpaftercur_2628 = tmpcur_2622 + 8; + uint16_t tmptag_2629 = GIB_GET_TAG(tagged_tmpcur_113); + GibCursor end_from_tagged_indr_1412 = tmpcur_2627 + tmptag_2629; + GibCursor jump_loc_1414 = tmpcur_2622 + 8; + unsigned char wildcard_1417 = gib_print_symbol(2184); + GibCursorGibCursorProd tmp_struct_111 = + _print_ListA(tmpcur_2627, tmpcur_2627); + GibCursor pvrtmp_2630 = tmp_struct_111.field0; + GibCursor pvrtmp_2631 = tmp_struct_111.field1; + GibCursorGibCursorProd return_112; + + return_112.field0 = end_r_957; + return_112.field1 = jump_loc_1414; + return return_112; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_116 = *(uintptr_t *) tmpcur_2622; + GibCursor tmpcur_2632 = GIB_UNTAG(tagged_tmpcur_116); + GibCursor tmpaftercur_2633 = tmpcur_2622 + 8; + uint16_t tmptag_2634 = GIB_GET_TAG(tagged_tmpcur_116); + GibCursor end_from_tagged_indr_1412 = tmpcur_2632 + tmptag_2634; + unsigned char wildcard_1417 = gib_print_symbol(2183); + GibCursorGibCursorProd tmp_struct_114 = + _print_ListA(tmpcur_2632, tmpcur_2632); + GibCursor pvrtmp_2635 = tmp_struct_114.field0; + GibCursor pvrtmp_2636 = tmp_struct_114.field1; + GibCursorGibCursorProd return_115; + + return_115.field0 = pvrtmp_2635; + return_115.field1 = pvrtmp_2636; + return return_115; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2621"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_ListB(GibCursor end_r_960, + GibCursor arg_221_380_546) +{ + GibPackedTag tmpval_2638 = *(GibPackedTag *) arg_221_380_546; + GibCursor tmpcur_2639 = arg_221_380_546 + 1; + + + switch_2664: + ; + switch (tmpval_2638) { + + case 0: + { + GibInt tmpval_2640 = *(GibInt *) tmpcur_2639; + GibCursor tmpcur_2641 = tmpcur_2639 + sizeof(GibInt); + GibInt tmpval_2642 = *(GibInt *) tmpcur_2641; + GibCursor tmpcur_2643 = tmpcur_2641 + sizeof(GibInt); + GibInt tmpval_2644 = *(GibInt *) tmpcur_2643; + GibCursor tmpcur_2645 = tmpcur_2643 + sizeof(GibInt); + GibInt tmpval_2646 = *(GibInt *) tmpcur_2645; + GibCursor tmpcur_2647 = tmpcur_2645 + sizeof(GibInt); + GibInt tmpval_2648 = *(GibInt *) tmpcur_2647; + GibCursor tmpcur_2649 = tmpcur_2647 + sizeof(GibInt); + GibInt tmpval_2650 = *(GibInt *) tmpcur_2649; + GibCursor tmpcur_2651 = tmpcur_2649 + sizeof(GibInt); + GibCursor jump_1329 = tmpcur_2649 + 8; + GibCursor jump_1328 = tmpcur_2647 + 8; + GibCursor jump_1327 = tmpcur_2645 + 8; + GibCursor jump_1326 = tmpcur_2643 + 8; + GibCursor jump_1325 = tmpcur_2641 + 8; + GibCursor jump_1324 = tmpcur_2639 + 8; + unsigned char wildcard_236_388_554 = gib_print_symbol(2180); + unsigned char wildcard_244_389_555 = gib_print_symbol(2185); + unsigned char y_229_390_556 = printf("%ld", tmpval_2640); + unsigned char wildcard_243_391_557 = gib_print_symbol(2185); + unsigned char y_230_392_558 = printf("%ld", tmpval_2642); + unsigned char wildcard_242_393_559 = gib_print_symbol(2185); + unsigned char y_231_394_560 = printf("%ld", tmpval_2644); + unsigned char wildcard_241_395_561 = gib_print_symbol(2185); + unsigned char y_232_396_562 = printf("%ld", tmpval_2646); + unsigned char wildcard_240_397_563 = gib_print_symbol(2185); + unsigned char y_233_398_564 = printf("%ld", tmpval_2648); + unsigned char wildcard_239_399_565 = gib_print_symbol(2185); + unsigned char y_234_400_566 = printf("%ld", tmpval_2650); + unsigned char wildcard_238_401_567 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_117 = + _print_ListB(end_r_960, tmpcur_2651); + GibCursor pvrtmp_2652 = tmp_struct_117.field0; + GibCursor pvrtmp_2653 = tmp_struct_117.field1; + unsigned char wildcard_237_403_569 = gib_print_symbol(2176); + GibCursorGibCursorProd return_118; + + return_118.field0 = pvrtmp_2652; + return_118.field1 = pvrtmp_2653; + return return_118; + break; + } + + case 1: + { + GibCursor jump_loc_1332 = arg_221_380_546 + 1; + unsigned char wildcard_245_404_570 = gib_print_symbol(2177); + unsigned char wildcard_246_405_571 = gib_print_symbol(2176); + GibCursorGibCursorProd return_119; + + return_119.field0 = end_r_960; + return_119.field1 = jump_loc_1332; + return return_119; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_122 = *(uintptr_t *) tmpcur_2639; + GibCursor tmpcur_2654 = GIB_UNTAG(tagged_tmpcur_122); + GibCursor tmpaftercur_2655 = tmpcur_2639 + 8; + uint16_t tmptag_2656 = GIB_GET_TAG(tagged_tmpcur_122); + GibCursor end_from_tagged_indr_1418 = tmpcur_2654 + tmptag_2656; + GibCursor jump_loc_1420 = tmpcur_2639 + 8; + unsigned char wildcard_1423 = gib_print_symbol(2184); + GibCursorGibCursorProd tmp_struct_120 = + _print_ListB(tmpcur_2654, tmpcur_2654); + GibCursor pvrtmp_2657 = tmp_struct_120.field0; + GibCursor pvrtmp_2658 = tmp_struct_120.field1; + GibCursorGibCursorProd return_121; + + return_121.field0 = end_r_960; + return_121.field1 = jump_loc_1420; + return return_121; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_125 = *(uintptr_t *) tmpcur_2639; + GibCursor tmpcur_2659 = GIB_UNTAG(tagged_tmpcur_125); + GibCursor tmpaftercur_2660 = tmpcur_2639 + 8; + uint16_t tmptag_2661 = GIB_GET_TAG(tagged_tmpcur_125); + GibCursor end_from_tagged_indr_1418 = tmpcur_2659 + tmptag_2661; + unsigned char wildcard_1423 = gib_print_symbol(2183); + GibCursorGibCursorProd tmp_struct_123 = + _print_ListB(tmpcur_2659, tmpcur_2659); + GibCursor pvrtmp_2662 = tmp_struct_123.field0; + GibCursor pvrtmp_2663 = tmp_struct_123.field1; + GibCursorGibCursorProd return_124; + + return_124.field0 = pvrtmp_2662; + return_124.field1 = pvrtmp_2663; + return return_124; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2638"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_List(GibCursor end_r_964, + GibCursor end_r_966, + GibCursor loc_962, + GibCursor arg_127_406_572) +{ + GibPackedTag tmpval_2665 = *(GibPackedTag *) arg_127_406_572; + GibCursor tmpcur_2666 = arg_127_406_572 + 1; + + + switch_2729: + ; + switch (tmpval_2665) { + + case 0: + { + GibInt tmpval_2667 = *(GibInt *) tmpcur_2666; + GibCursor tmpcur_2668 = tmpcur_2666 + sizeof(GibInt); + GibInt tmpval_2669 = *(GibInt *) tmpcur_2668; + GibCursor tmpcur_2670 = tmpcur_2668 + sizeof(GibInt); + GibInt tmpval_2671 = *(GibInt *) tmpcur_2670; + GibCursor tmpcur_2672 = tmpcur_2670 + sizeof(GibInt); + GibInt tmpval_2673 = *(GibInt *) tmpcur_2672; + GibCursor tmpcur_2674 = tmpcur_2672 + sizeof(GibInt); + GibCursor jump_1337 = tmpcur_2672 + 8; + GibCursor jump_1336 = tmpcur_2670 + 8; + GibCursor jump_1335 = tmpcur_2668 + 8; + GibCursor jump_1334 = tmpcur_2666 + 8; + GibCursor loc_1201 = loc_962 + 1; + GibCursor loc_1202 = loc_1201 + 8; + GibCursor loc_1203 = loc_1202 + 8; + GibCursor loc_1204 = loc_1203 + 8; + GibCursor loc_1205 = loc_1204 + 8; + + *(GibPackedTag *) loc_962 = 0; + + GibCursor writetag_1929 = loc_962 + 1; + GibCursor after_tag_1930 = loc_962 + 1; + + *(GibInt *) after_tag_1930 = tmpval_2667; + + GibCursor writecur_1934 = after_tag_1930 + sizeof(GibInt); + + *(GibInt *) writecur_1934 = tmpval_2669; + + GibCursor writecur_1935 = writecur_1934 + sizeof(GibInt); + + *(GibInt *) writecur_1935 = tmpval_2671; + + GibCursor writecur_1936 = writecur_1935 + sizeof(GibInt); + + *(GibInt *) writecur_1936 = tmpval_2673; + + GibCursor writecur_1937 = writecur_1936 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_126 = + _copy_without_ptrs_ListA(end_r_964, end_r_966, loc_1205, tmpcur_2674); + GibCursor pvrtmp_2675 = tmp_struct_126.field0; + GibCursor pvrtmp_2676 = tmp_struct_126.field1; + GibCursor pvrtmp_2677 = tmp_struct_126.field2; + GibCursor pvrtmp_2678 = tmp_struct_126.field3; + GibCursor pvrtmp_2679 = tmp_struct_126.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_127 = + _copy_without_ptrs_List(pvrtmp_2675, pvrtmp_2676, pvrtmp_2679, pvrtmp_2677); + GibCursor pvrtmp_2684 = tmp_struct_127.field0; + GibCursor pvrtmp_2685 = tmp_struct_127.field1; + GibCursor pvrtmp_2686 = tmp_struct_127.field2; + GibCursor pvrtmp_2687 = tmp_struct_127.field3; + GibCursor pvrtmp_2688 = tmp_struct_127.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_128; + + return_128.field0 = pvrtmp_2684; + return_128.field1 = pvrtmp_2685; + return_128.field2 = pvrtmp_2686; + return_128.field3 = loc_962; + return_128.field4 = pvrtmp_2688; + return return_128; + break; + } + + case 1: + { + GibCursor jump_loc_1341 = arg_127_406_572 + 1; + + *(GibPackedTag *) loc_962 = 1; + + GibCursor writetag_1944 = loc_962 + 1; + GibCursor after_tag_1945 = loc_962 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_129; + + return_129.field0 = end_r_964; + return_129.field1 = end_r_966; + return_129.field2 = jump_loc_1341; + return_129.field3 = loc_962; + return_129.field4 = after_tag_1945; + return return_129; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_132 = *(uintptr_t *) tmpcur_2666; + GibCursor tmpcur_2701 = GIB_UNTAG(tagged_tmpcur_132); + GibCursor tmpaftercur_2702 = tmpcur_2666 + 8; + uint16_t tmptag_2703 = GIB_GET_TAG(tagged_tmpcur_132); + GibCursor end_from_tagged_indr_1424 = tmpcur_2701 + tmptag_2703; + GibCursor jump_loc_1426 = tmpcur_2666 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_130 = + _copy_without_ptrs_List(tmpcur_2701, end_r_966, loc_962, tmpcur_2701); + GibCursor pvrtmp_2704 = tmp_struct_130.field0; + GibCursor pvrtmp_2705 = tmp_struct_130.field1; + GibCursor pvrtmp_2706 = tmp_struct_130.field2; + GibCursor pvrtmp_2707 = tmp_struct_130.field3; + GibCursor pvrtmp_2708 = tmp_struct_130.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_131; + + return_131.field0 = end_r_964; + return_131.field1 = pvrtmp_2705; + return_131.field2 = jump_loc_1426; + return_131.field3 = pvrtmp_2707; + return_131.field4 = pvrtmp_2708; + return return_131; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_135 = *(uintptr_t *) tmpcur_2666; + GibCursor tmpcur_2715 = GIB_UNTAG(tagged_tmpcur_135); + GibCursor tmpaftercur_2716 = tmpcur_2666 + 8; + uint16_t tmptag_2717 = GIB_GET_TAG(tagged_tmpcur_135); + GibCursor end_from_tagged_indr_1424 = tmpcur_2715 + tmptag_2717; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_133 = + _copy_without_ptrs_List(tmpcur_2715, end_r_966, loc_962, tmpcur_2715); + GibCursor pvrtmp_2718 = tmp_struct_133.field0; + GibCursor pvrtmp_2719 = tmp_struct_133.field1; + GibCursor pvrtmp_2720 = tmp_struct_133.field2; + GibCursor pvrtmp_2721 = tmp_struct_133.field3; + GibCursor pvrtmp_2722 = tmp_struct_133.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_134; + + return_134.field0 = pvrtmp_2718; + return_134.field1 = pvrtmp_2719; + return_134.field2 = pvrtmp_2720; + return_134.field3 = pvrtmp_2721; + return_134.field4 = pvrtmp_2722; + return return_134; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2665"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_143 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_2186 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_972 = region_2186.start; + GibCursor end_r_972 = region_2186.end; + GibCursorGibCursorGibCursorProd tmp_struct_136 = + mkListB(end_r_972, r_972, 2500000); + GibCursor pvrtmp_2187 = tmp_struct_136.field0; + GibCursor pvrtmp_2188 = tmp_struct_136.field1; + GibCursor pvrtmp_2189 = tmp_struct_136.field2; + GibInt timed_2035; + GibVector *times_141 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_2035; + struct timespec end_timed_2035; + + for (long long iters_timed_2035 = 0; iters_timed_2035 < + gib_get_iters_param(); iters_timed_2035++) { + if (iters_timed_2035 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_2035); + + GibInt Res = 0; + reduceB(&pvrtmp_2187, &pvrtmp_2188, &Res); + // GibCursor pvrtmp_2194 = tmp_struct_137.field0; + // GibCursor pvrtmp_2195 = tmp_struct_137.field1; + // GibInt pvrtmp_2196 = tmp_struct_137.field2; + + timed_2035 = Res; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_2035); + if (iters_timed_2035 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + pvrtmp_2187 = tmp_struct_136.field0; + pvrtmp_2188 = tmp_struct_136.field1; + Res = 0; + + double itertime_138 = gib_difftimespecs(&begin_timed_2035, + &end_timed_2035); + + printf("itertime: %lf\n", itertime_138); + gib_vector_inplace_update(times_141, iters_timed_2035, &itertime_138); + } + gib_vector_inplace_sort(times_141, gib_compare_doubles); + + double *tmp_142 = (double *) gib_vector_nth(times_141, + gib_get_iters_param() / 2); + double selftimed_140 = *tmp_142; + double batchtime_139 = gib_sum_timing_array(times_141); + + gib_print_timing_array(times_141); + gib_vector_free(times_141); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_139); + printf("SELFTIMED: %e\n", selftimed_140); + printf("%ld", timed_2035); + printf("\n"); + + int exit_144 = gib_exit(); + + return exit_144; +} diff --git a/microbench/manual_soa_examples/reduceList.aos.returns.c b/microbench/manual_soa_examples/reduceList.aos.returns.c new file mode 100644 index 000000000..4879c46d7 --- /dev/null +++ b/microbench/manual_soa_examples/reduceList.aos.returns.c @@ -0,0 +1,1982 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_ListB(GibCursor end_r_910, GibCursor end_r_912, + GibCursor loc_908, GibCursor arg_191_249_424); +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_915, + GibCursor arg_98_264_439); +GibCursorGibCursorProd _print_List(GibCursor end_r_918, + GibCursor arg_153_268_443); +GibCursorGibCursorGibCursorProd mkListB(GibCursor end_r_921, GibCursor loc_919, + GibInt len_34_291_466); +GibCursorGibCursorProd _traverse_List(GibCursor end_r_924, + GibCursor arg_140_293_470); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_ListA(GibCursor end_r_928, GibCursor end_r_930, + GibCursor loc_926, GibCursor arg_93_302_479); +GibCursorGibCursorGibIntProd reduceB(GibCursor *end_r_933, + GibCursor *lst_36_307_484); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_ListA(GibCursor end_r_937, GibCursor end_r_939, GibCursor loc_935, + GibCursor arg_88_315_493); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_ListB(GibCursor end_r_943, GibCursor end_r_945, GibCursor loc_941, + GibCursor arg_176_330_498); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_List(GibCursor end_r_949, GibCursor end_r_951, GibCursor loc_947, + GibCursor arg_114_345_513); +GibCursorGibCursorProd _traverse_ListB(GibCursor end_r_954, + GibCursor arg_206_358_526); +GibCursorGibCursorProd _print_ListA(GibCursor end_r_957, + GibCursor arg_103_369_535); +GibCursorGibCursorProd _print_ListB(GibCursor end_r_960, + GibCursor arg_221_380_546); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_List(GibCursor end_r_964, GibCursor end_r_966, + GibCursor loc_962, GibCursor arg_127_406_572); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + List_T, + ListA_T, + ListB_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(10); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[7]; + + field_tys[0] = ListA_T; + field_tys[1] = List_T; + error = gib_info_table_insert_packed_dcon(List_T, 0, 32, 0, 4, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(List_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 1); + exit(1); + } + field_tys[0] = ListA_T; + error = gib_info_table_insert_packed_dcon(ListA_T, 0, 8, 0, 1, 1, field_tys, + 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListA_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 1); + exit(1); + } + field_tys[0] = ListB_T; + error = gib_info_table_insert_packed_dcon(ListB_T, 0, 48, 0, 6, 1, + field_tys, 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListB_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(2176, ")"); + gib_add_symbol(2177, "(NilB"); + gib_add_symbol(2178, "(NilA"); + gib_add_symbol(2179, "(Nil"); + gib_add_symbol(2180, "(ConsB"); + gib_add_symbol(2181, "(ConsA"); + gib_add_symbol(2182, "(Cons"); + gib_add_symbol(2183, " ->r "); + gib_add_symbol(2184, " ->i "); + gib_add_symbol(2185, " "); +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_ListB(GibCursor end_r_910, + GibCursor end_r_912, + GibCursor loc_908, + GibCursor arg_191_249_424) +{ + GibPackedTag tmpval_2197 = *(GibPackedTag *) arg_191_249_424; + GibCursor tmpcur_2198 = arg_191_249_424 + 1; + + + switch_2256: + ; + switch (tmpval_2197) { + + case 0: + { + GibInt tmpval_2199 = *(GibInt *) tmpcur_2198; + GibCursor tmpcur_2200 = tmpcur_2198 + sizeof(GibInt); + GibInt tmpval_2201 = *(GibInt *) tmpcur_2200; + GibCursor tmpcur_2202 = tmpcur_2200 + sizeof(GibInt); + GibInt tmpval_2203 = *(GibInt *) tmpcur_2202; + GibCursor tmpcur_2204 = tmpcur_2202 + sizeof(GibInt); + GibInt tmpval_2205 = *(GibInt *) tmpcur_2204; + GibCursor tmpcur_2206 = tmpcur_2204 + sizeof(GibInt); + GibInt tmpval_2207 = *(GibInt *) tmpcur_2206; + GibCursor tmpcur_2208 = tmpcur_2206 + sizeof(GibInt); + GibInt tmpval_2209 = *(GibInt *) tmpcur_2208; + GibCursor tmpcur_2210 = tmpcur_2208 + sizeof(GibInt); + GibCursor jump_1240 = tmpcur_2208 + 8; + GibCursor jump_1239 = tmpcur_2206 + 8; + GibCursor jump_1238 = tmpcur_2204 + 8; + GibCursor jump_1237 = tmpcur_2202 + 8; + GibCursor jump_1236 = tmpcur_2200 + 8; + GibCursor jump_1235 = tmpcur_2198 + 8; + GibCursor loc_985 = loc_908 + 1; + GibCursor loc_986 = loc_985 + 8; + GibCursor loc_987 = loc_986 + 8; + GibCursor loc_988 = loc_987 + 8; + GibCursor loc_989 = loc_988 + 8; + GibCursor loc_990 = loc_989 + 8; + GibCursor loc_991 = loc_990 + 8; + + *(GibPackedTag *) loc_908 = 0; + + GibCursor writetag_1586 = loc_908 + 1; + GibCursor after_tag_1587 = loc_908 + 1; + + *(GibInt *) after_tag_1587 = tmpval_2199; + + GibCursor writecur_1591 = after_tag_1587 + sizeof(GibInt); + + *(GibInt *) writecur_1591 = tmpval_2201; + + GibCursor writecur_1592 = writecur_1591 + sizeof(GibInt); + + *(GibInt *) writecur_1592 = tmpval_2203; + + GibCursor writecur_1593 = writecur_1592 + sizeof(GibInt); + + *(GibInt *) writecur_1593 = tmpval_2205; + + GibCursor writecur_1594 = writecur_1593 + sizeof(GibInt); + + *(GibInt *) writecur_1594 = tmpval_2207; + + GibCursor writecur_1595 = writecur_1594 + sizeof(GibInt); + + *(GibInt *) writecur_1595 = tmpval_2209; + + GibCursor writecur_1596 = writecur_1595 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_0 = + _copy_without_ptrs_ListB(end_r_910, end_r_912, loc_991, tmpcur_2210); + GibCursor pvrtmp_2211 = tmp_struct_0.field0; + GibCursor pvrtmp_2212 = tmp_struct_0.field1; + GibCursor pvrtmp_2213 = tmp_struct_0.field2; + GibCursor pvrtmp_2214 = tmp_struct_0.field3; + GibCursor pvrtmp_2215 = tmp_struct_0.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_1; + + return_1.field0 = pvrtmp_2211; + return_1.field1 = pvrtmp_2212; + return_1.field2 = pvrtmp_2213; + return_1.field3 = loc_908; + return_1.field4 = pvrtmp_2215; + return return_1; + break; + } + + case 1: + { + GibCursor jump_loc_1243 = arg_191_249_424 + 1; + + *(GibPackedTag *) loc_908 = 1; + + GibCursor writetag_1601 = loc_908 + 1; + GibCursor after_tag_1602 = loc_908 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_2; + + return_2.field0 = end_r_910; + return_2.field1 = end_r_912; + return_2.field2 = jump_loc_1243; + return_2.field3 = loc_908; + return_2.field4 = after_tag_1602; + return return_2; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) tmpcur_2198; + GibCursor tmpcur_2228 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_2229 = tmpcur_2198 + 8; + uint16_t tmptag_2230 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_indr_1352 = tmpcur_2228 + tmptag_2230; + GibCursor jump_loc_1354 = tmpcur_2198 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_3 = + _copy_without_ptrs_ListB(tmpcur_2228, end_r_912, loc_908, tmpcur_2228); + GibCursor pvrtmp_2231 = tmp_struct_3.field0; + GibCursor pvrtmp_2232 = tmp_struct_3.field1; + GibCursor pvrtmp_2233 = tmp_struct_3.field2; + GibCursor pvrtmp_2234 = tmp_struct_3.field3; + GibCursor pvrtmp_2235 = tmp_struct_3.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_4; + + return_4.field0 = end_r_910; + return_4.field1 = pvrtmp_2232; + return_4.field2 = jump_loc_1354; + return_4.field3 = pvrtmp_2234; + return_4.field4 = pvrtmp_2235; + return return_4; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_8 = *(uintptr_t *) tmpcur_2198; + GibCursor tmpcur_2242 = GIB_UNTAG(tagged_tmpcur_8); + GibCursor tmpaftercur_2243 = tmpcur_2198 + 8; + uint16_t tmptag_2244 = GIB_GET_TAG(tagged_tmpcur_8); + GibCursor end_from_tagged_indr_1352 = tmpcur_2242 + tmptag_2244; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_6 = + _copy_without_ptrs_ListB(tmpcur_2242, end_r_912, loc_908, tmpcur_2242); + GibCursor pvrtmp_2245 = tmp_struct_6.field0; + GibCursor pvrtmp_2246 = tmp_struct_6.field1; + GibCursor pvrtmp_2247 = tmp_struct_6.field2; + GibCursor pvrtmp_2248 = tmp_struct_6.field3; + GibCursor pvrtmp_2249 = tmp_struct_6.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_7; + + return_7.field0 = pvrtmp_2245; + return_7.field1 = pvrtmp_2246; + return_7.field2 = pvrtmp_2247; + return_7.field3 = pvrtmp_2248; + return_7.field4 = pvrtmp_2249; + return return_7; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2197"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_915, + GibCursor arg_98_264_439) +{ + GibPackedTag tmpval_2257 = *(GibPackedTag *) arg_98_264_439; + GibCursor tmpcur_2258 = arg_98_264_439 + 1; + + + switch_2273: + ; + switch (tmpval_2257) { + + case 0: + { + GibInt tmpval_2259 = *(GibInt *) tmpcur_2258; + GibCursor tmpcur_2260 = tmpcur_2258 + sizeof(GibInt); + GibCursor jump_1245 = tmpcur_2258 + 8; + GibCursorGibCursorProd tmp_struct_9 = + _traverse_ListA(end_r_915, tmpcur_2260); + GibCursor pvrtmp_2261 = tmp_struct_9.field0; + GibCursor pvrtmp_2262 = tmp_struct_9.field1; + GibCursorGibCursorProd return_10; + + return_10.field0 = pvrtmp_2261; + return_10.field1 = pvrtmp_2262; + return return_10; + break; + } + + case 1: + { + GibCursor jump_loc_1248 = arg_98_264_439 + 1; + GibCursorGibCursorProd return_11; + + return_11.field0 = end_r_915; + return_11.field1 = jump_loc_1248; + return return_11; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_14 = *(uintptr_t *) tmpcur_2258; + GibCursor tmpcur_2263 = GIB_UNTAG(tagged_tmpcur_14); + GibCursor tmpaftercur_2264 = tmpcur_2258 + 8; + uint16_t tmptag_2265 = GIB_GET_TAG(tagged_tmpcur_14); + GibCursor end_from_tagged_indr_1358 = tmpcur_2263 + tmptag_2265; + GibCursor jump_loc_1360 = tmpcur_2258 + 8; + GibCursorGibCursorProd tmp_struct_12 = + _traverse_ListA(tmpcur_2263, tmpcur_2263); + GibCursor pvrtmp_2266 = tmp_struct_12.field0; + GibCursor pvrtmp_2267 = tmp_struct_12.field1; + GibCursorGibCursorProd return_13; + + return_13.field0 = end_r_915; + return_13.field1 = jump_loc_1360; + return return_13; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_17 = *(uintptr_t *) tmpcur_2258; + GibCursor tmpcur_2268 = GIB_UNTAG(tagged_tmpcur_17); + GibCursor tmpaftercur_2269 = tmpcur_2258 + 8; + uint16_t tmptag_2270 = GIB_GET_TAG(tagged_tmpcur_17); + GibCursor end_from_tagged_indr_1358 = tmpcur_2268 + tmptag_2270; + GibCursorGibCursorProd tmp_struct_15 = + _traverse_ListA(tmpcur_2268, tmpcur_2268); + GibCursor pvrtmp_2271 = tmp_struct_15.field0; + GibCursor pvrtmp_2272 = tmp_struct_15.field1; + GibCursorGibCursorProd return_16; + + return_16.field0 = pvrtmp_2271; + return_16.field1 = pvrtmp_2272; + return return_16; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2257"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_List(GibCursor end_r_918, + GibCursor arg_153_268_443) +{ + GibPackedTag tmpval_2274 = *(GibPackedTag *) arg_153_268_443; + GibCursor tmpcur_2275 = arg_153_268_443 + 1; + + + switch_2298: + ; + switch (tmpval_2274) { + + case 0: + { + GibInt tmpval_2276 = *(GibInt *) tmpcur_2275; + GibCursor tmpcur_2277 = tmpcur_2275 + sizeof(GibInt); + GibInt tmpval_2278 = *(GibInt *) tmpcur_2277; + GibCursor tmpcur_2279 = tmpcur_2277 + sizeof(GibInt); + GibInt tmpval_2280 = *(GibInt *) tmpcur_2279; + GibCursor tmpcur_2281 = tmpcur_2279 + sizeof(GibInt); + GibInt tmpval_2282 = *(GibInt *) tmpcur_2281; + GibCursor tmpcur_2283 = tmpcur_2281 + sizeof(GibInt); + GibCursor jump_1253 = tmpcur_2281 + 8; + GibCursor jump_1252 = tmpcur_2279 + 8; + GibCursor jump_1251 = tmpcur_2277 + 8; + GibCursor jump_1250 = tmpcur_2275 + 8; + unsigned char wildcard_166_275_450 = gib_print_symbol(2182); + unsigned char wildcard_173_276_451 = gib_print_symbol(2185); + unsigned char y_160_277_452 = printf("%ld", tmpval_2276); + unsigned char wildcard_172_278_453 = gib_print_symbol(2185); + unsigned char y_161_279_454 = printf("%ld", tmpval_2278); + unsigned char wildcard_171_280_455 = gib_print_symbol(2185); + unsigned char y_162_281_456 = printf("%ld", tmpval_2280); + unsigned char wildcard_170_282_457 = gib_print_symbol(2185); + unsigned char y_163_283_458 = printf("%ld", tmpval_2282); + unsigned char wildcard_169_284_459 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_18 = + _print_ListA(end_r_918, tmpcur_2283); + GibCursor pvrtmp_2284 = tmp_struct_18.field0; + GibCursor pvrtmp_2285 = tmp_struct_18.field1; + unsigned char wildcard_168_286_461 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_19 = + _print_List(pvrtmp_2284, pvrtmp_2285); + GibCursor pvrtmp_2286 = tmp_struct_19.field0; + GibCursor pvrtmp_2287 = tmp_struct_19.field1; + unsigned char wildcard_167_288_463 = gib_print_symbol(2176); + GibCursorGibCursorProd return_20; + + return_20.field0 = pvrtmp_2286; + return_20.field1 = pvrtmp_2287; + return return_20; + break; + } + + case 1: + { + GibCursor jump_loc_1257 = arg_153_268_443 + 1; + unsigned char wildcard_174_289_464 = gib_print_symbol(2179); + unsigned char wildcard_175_290_465 = gib_print_symbol(2176); + GibCursorGibCursorProd return_21; + + return_21.field0 = end_r_918; + return_21.field1 = jump_loc_1257; + return return_21; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_24 = *(uintptr_t *) tmpcur_2275; + GibCursor tmpcur_2288 = GIB_UNTAG(tagged_tmpcur_24); + GibCursor tmpaftercur_2289 = tmpcur_2275 + 8; + uint16_t tmptag_2290 = GIB_GET_TAG(tagged_tmpcur_24); + GibCursor end_from_tagged_indr_1364 = tmpcur_2288 + tmptag_2290; + GibCursor jump_loc_1366 = tmpcur_2275 + 8; + unsigned char wildcard_1369 = gib_print_symbol(2184); + GibCursorGibCursorProd tmp_struct_22 = + _print_List(tmpcur_2288, tmpcur_2288); + GibCursor pvrtmp_2291 = tmp_struct_22.field0; + GibCursor pvrtmp_2292 = tmp_struct_22.field1; + GibCursorGibCursorProd return_23; + + return_23.field0 = end_r_918; + return_23.field1 = jump_loc_1366; + return return_23; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_27 = *(uintptr_t *) tmpcur_2275; + GibCursor tmpcur_2293 = GIB_UNTAG(tagged_tmpcur_27); + GibCursor tmpaftercur_2294 = tmpcur_2275 + 8; + uint16_t tmptag_2295 = GIB_GET_TAG(tagged_tmpcur_27); + GibCursor end_from_tagged_indr_1364 = tmpcur_2293 + tmptag_2295; + unsigned char wildcard_1369 = gib_print_symbol(2183); + GibCursorGibCursorProd tmp_struct_25 = + _print_List(tmpcur_2293, tmpcur_2293); + GibCursor pvrtmp_2296 = tmp_struct_25.field0; + GibCursor pvrtmp_2297 = tmp_struct_25.field1; + GibCursorGibCursorProd return_26; + + return_26.field0 = pvrtmp_2296; + return_26.field1 = pvrtmp_2297; + return return_26; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2274"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorProd mkListB(GibCursor end_r_921, GibCursor loc_919, + GibInt len_34_291_466) +{ + if (loc_919 + 58 > end_r_921) { + gib_grow_region(&loc_919, &end_r_921); + } + + GibBool fltIf_419_467 = len_34_291_466 <= 0; + + if (fltIf_419_467) { + *(GibPackedTag *) loc_919 = 1; + + GibCursor writetag_1651 = loc_919 + 1; + GibCursor after_tag_1652 = loc_919 + 1; + GibCursorGibCursorGibCursorProd return_28; + + return_28.field0 = end_r_921; + return_28.field1 = loc_919; + return_28.field2 = after_tag_1652; + return return_28; + } else { + GibInt fltAppE_420_468 = len_34_291_466 - 1; + GibCursor loc_1026 = loc_919 + 1; + GibCursor loc_1027 = loc_1026 + 8; + GibCursor loc_1028 = loc_1027 + 8; + GibCursor loc_1029 = loc_1028 + 8; + GibCursor loc_1030 = loc_1029 + 8; + GibCursor loc_1031 = loc_1030 + 8; + GibCursor loc_1032 = loc_1031 + 8; + + *(GibPackedTag *) loc_919 = 0; + + GibCursor writetag_1660 = loc_919 + 1; + GibCursor after_tag_1661 = loc_919 + 1; + + *(GibInt *) after_tag_1661 = len_34_291_466; + + GibCursor writecur_1665 = after_tag_1661 + sizeof(GibInt); + + *(GibInt *) writecur_1665 = len_34_291_466; + + GibCursor writecur_1666 = writecur_1665 + sizeof(GibInt); + + *(GibInt *) writecur_1666 = len_34_291_466; + + GibCursor writecur_1667 = writecur_1666 + sizeof(GibInt); + + *(GibInt *) writecur_1667 = len_34_291_466; + + GibCursor writecur_1668 = writecur_1667 + sizeof(GibInt); + + *(GibInt *) writecur_1668 = len_34_291_466; + + GibCursor writecur_1669 = writecur_1668 + sizeof(GibInt); + + *(GibInt *) writecur_1669 = len_34_291_466; + + GibCursor writecur_1670 = writecur_1669 + sizeof(GibInt); + GibCursorGibCursorGibCursorProd tmp_struct_29 = + mkListB(end_r_921, loc_1032, fltAppE_420_468); + GibCursor pvrtmp_2303 = tmp_struct_29.field0; + GibCursor pvrtmp_2304 = tmp_struct_29.field1; + GibCursor pvrtmp_2305 = tmp_struct_29.field2; + GibCursorGibCursorGibCursorProd return_30; + + return_30.field0 = pvrtmp_2303; + return_30.field1 = loc_919; + return_30.field2 = pvrtmp_2305; + return return_30; + } +} +GibCursorGibCursorProd _traverse_List(GibCursor end_r_924, + GibCursor arg_140_293_470) +{ + GibPackedTag tmpval_2314 = *(GibPackedTag *) arg_140_293_470; + GibCursor tmpcur_2315 = arg_140_293_470 + 1; + + + switch_2338: + ; + switch (tmpval_2314) { + + case 0: + { + GibInt tmpval_2316 = *(GibInt *) tmpcur_2315; + GibCursor tmpcur_2317 = tmpcur_2315 + sizeof(GibInt); + GibInt tmpval_2318 = *(GibInt *) tmpcur_2317; + GibCursor tmpcur_2319 = tmpcur_2317 + sizeof(GibInt); + GibInt tmpval_2320 = *(GibInt *) tmpcur_2319; + GibCursor tmpcur_2321 = tmpcur_2319 + sizeof(GibInt); + GibInt tmpval_2322 = *(GibInt *) tmpcur_2321; + GibCursor tmpcur_2323 = tmpcur_2321 + sizeof(GibInt); + GibCursor jump_1264 = tmpcur_2321 + 8; + GibCursor jump_1263 = tmpcur_2319 + 8; + GibCursor jump_1262 = tmpcur_2317 + 8; + GibCursor jump_1261 = tmpcur_2315 + 8; + GibCursorGibCursorProd tmp_struct_34 = + _traverse_ListA(end_r_924, tmpcur_2323); + GibCursor pvrtmp_2324 = tmp_struct_34.field0; + GibCursor pvrtmp_2325 = tmp_struct_34.field1; + GibCursorGibCursorProd tmp_struct_35 = + _traverse_List(pvrtmp_2324, pvrtmp_2325); + GibCursor pvrtmp_2326 = tmp_struct_35.field0; + GibCursor pvrtmp_2327 = tmp_struct_35.field1; + GibCursorGibCursorProd return_36; + + return_36.field0 = pvrtmp_2326; + return_36.field1 = pvrtmp_2327; + return return_36; + break; + } + + case 1: + { + GibCursor jump_loc_1268 = arg_140_293_470 + 1; + GibCursorGibCursorProd return_37; + + return_37.field0 = end_r_924; + return_37.field1 = jump_loc_1268; + return return_37; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_40 = *(uintptr_t *) tmpcur_2315; + GibCursor tmpcur_2328 = GIB_UNTAG(tagged_tmpcur_40); + GibCursor tmpaftercur_2329 = tmpcur_2315 + 8; + uint16_t tmptag_2330 = GIB_GET_TAG(tagged_tmpcur_40); + GibCursor end_from_tagged_indr_1370 = tmpcur_2328 + tmptag_2330; + GibCursor jump_loc_1372 = tmpcur_2315 + 8; + GibCursorGibCursorProd tmp_struct_38 = + _traverse_List(tmpcur_2328, tmpcur_2328); + GibCursor pvrtmp_2331 = tmp_struct_38.field0; + GibCursor pvrtmp_2332 = tmp_struct_38.field1; + GibCursorGibCursorProd return_39; + + return_39.field0 = end_r_924; + return_39.field1 = jump_loc_1372; + return return_39; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_43 = *(uintptr_t *) tmpcur_2315; + GibCursor tmpcur_2333 = GIB_UNTAG(tagged_tmpcur_43); + GibCursor tmpaftercur_2334 = tmpcur_2315 + 8; + uint16_t tmptag_2335 = GIB_GET_TAG(tagged_tmpcur_43); + GibCursor end_from_tagged_indr_1370 = tmpcur_2333 + tmptag_2335; + GibCursorGibCursorProd tmp_struct_41 = + _traverse_List(tmpcur_2333, tmpcur_2333); + GibCursor pvrtmp_2336 = tmp_struct_41.field0; + GibCursor pvrtmp_2337 = tmp_struct_41.field1; + GibCursorGibCursorProd return_42; + + return_42.field0 = pvrtmp_2336; + return_42.field1 = pvrtmp_2337; + return return_42; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2314"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_ListA(GibCursor end_r_928, + GibCursor end_r_930, + GibCursor loc_926, + GibCursor arg_93_302_479) +{ + GibPackedTag tmpval_2339 = *(GibPackedTag *) arg_93_302_479; + GibCursor tmpcur_2340 = arg_93_302_479 + 1; + + + switch_2388: + ; + switch (tmpval_2339) { + + case 0: + { + GibInt tmpval_2341 = *(GibInt *) tmpcur_2340; + GibCursor tmpcur_2342 = tmpcur_2340 + sizeof(GibInt); + GibCursor jump_1270 = tmpcur_2340 + 8; + GibCursor loc_1065 = loc_926 + 1; + GibCursor loc_1066 = loc_1065 + 8; + + *(GibPackedTag *) loc_926 = 0; + + GibCursor writetag_1699 = loc_926 + 1; + GibCursor after_tag_1700 = loc_926 + 1; + + *(GibInt *) after_tag_1700 = tmpval_2341; + + GibCursor writecur_1704 = after_tag_1700 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_44 = + _copy_without_ptrs_ListA(end_r_928, end_r_930, loc_1066, tmpcur_2342); + GibCursor pvrtmp_2343 = tmp_struct_44.field0; + GibCursor pvrtmp_2344 = tmp_struct_44.field1; + GibCursor pvrtmp_2345 = tmp_struct_44.field2; + GibCursor pvrtmp_2346 = tmp_struct_44.field3; + GibCursor pvrtmp_2347 = tmp_struct_44.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_45; + + return_45.field0 = pvrtmp_2343; + return_45.field1 = pvrtmp_2344; + return_45.field2 = pvrtmp_2345; + return_45.field3 = loc_926; + return_45.field4 = pvrtmp_2347; + return return_45; + break; + } + + case 1: + { + GibCursor jump_loc_1273 = arg_93_302_479 + 1; + + *(GibPackedTag *) loc_926 = 1; + + GibCursor writetag_1709 = loc_926 + 1; + GibCursor after_tag_1710 = loc_926 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_46; + + return_46.field0 = end_r_928; + return_46.field1 = end_r_930; + return_46.field2 = jump_loc_1273; + return_46.field3 = loc_926; + return_46.field4 = after_tag_1710; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2360 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_2361 = tmpcur_2340 + 8; + uint16_t tmptag_2362 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_1376 = tmpcur_2360 + tmptag_2362; + GibCursor jump_loc_1378 = tmpcur_2340 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_47 = + _copy_without_ptrs_ListA(tmpcur_2360, end_r_930, loc_926, tmpcur_2360); + GibCursor pvrtmp_2363 = tmp_struct_47.field0; + GibCursor pvrtmp_2364 = tmp_struct_47.field1; + GibCursor pvrtmp_2365 = tmp_struct_47.field2; + GibCursor pvrtmp_2366 = tmp_struct_47.field3; + GibCursor pvrtmp_2367 = tmp_struct_47.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_48; + + return_48.field0 = end_r_928; + return_48.field1 = pvrtmp_2364; + return_48.field2 = jump_loc_1378; + return_48.field3 = pvrtmp_2366; + return_48.field4 = pvrtmp_2367; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_2340; + GibCursor tmpcur_2374 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_2375 = tmpcur_2340 + 8; + uint16_t tmptag_2376 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_1376 = tmpcur_2374 + tmptag_2376; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_50 = + _copy_without_ptrs_ListA(tmpcur_2374, end_r_930, loc_926, tmpcur_2374); + GibCursor pvrtmp_2377 = tmp_struct_50.field0; + GibCursor pvrtmp_2378 = tmp_struct_50.field1; + GibCursor pvrtmp_2379 = tmp_struct_50.field2; + GibCursor pvrtmp_2380 = tmp_struct_50.field3; + GibCursor pvrtmp_2381 = tmp_struct_50.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_2377; + return_51.field1 = pvrtmp_2378; + return_51.field2 = pvrtmp_2379; + return_51.field3 = pvrtmp_2380; + return_51.field4 = pvrtmp_2381; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2339"); + exit(1); + } + } +} + +GibCursorGibCursorGibIntProd reduceB(GibCursor *end_r_933, + GibCursor *lst_36_307_484) +{ + GibPackedTag tmpval_2389 = *(GibPackedTag *) (*lst_36_307_484); + //GibCursor tmpcur_2390 = lst_36_307_484 + 1; + *lst_36_307_484 += 1; + + + switch_2418: + ; + switch (tmpval_2389) { + + case 1: + { + //GibCursor jump_loc_1276 = lst_36_307_484 + 1; + GibCursorGibCursorGibIntProd return_53; + + //return_53.field0 = end_r_933; + //return_53.field1 = jump_loc_1276; + return_53.field2 = 0; + //*res += 0; + return return_53; + break; + } + + case 0: + { + GibInt tmpval_2391 = *(GibInt *) (*lst_36_307_484); + + // GibCursor tmpcur_2392 = tmpcur_2390 + sizeof(GibInt); + // + // GibInt tmpval_2393 = *(GibInt *) tmpcur_2392; + // GibCursor tmpcur_2394 = tmpcur_2392 + sizeof(GibInt); + // GibInt tmpval_2395 = *(GibInt *) tmpcur_2394; + // GibCursor tmpcur_2396 = tmpcur_2394 + sizeof(GibInt); + // GibInt tmpval_2397 = *(GibInt *) tmpcur_2396; + // GibCursor tmpcur_2398 = tmpcur_2396 + sizeof(GibInt); + // GibInt tmpval_2399 = *(GibInt *) tmpcur_2398; + // GibCursor tmpcur_2400 = tmpcur_2398 + sizeof(GibInt); + // GibInt tmpval_2401 = *(GibInt *) tmpcur_2400; + // GibCursor tmpcur_2402 = tmpcur_2400 + sizeof(GibInt); + + //*lst_36_307_484 += ((sizeof(GibInt)) * 6); + + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + *lst_36_307_484 += sizeof(GibInt); + + // GibCursor jump_1282 = tmpcur_2400 + 8; + // GibCursor jump_1281 = tmpcur_2398 + 8; + // GibCursor jump_1280 = tmpcur_2396 + 8; + // GibCursor jump_1279 = tmpcur_2394 + 8; + // GibCursor jump_1278 = tmpcur_2392 + 8; + // GibCursor jump_1277 = tmpcur_2390 + 8; + + //*res = *res + tmpval_2391; + GibCursorGibCursorGibIntProd tmp_struct_54 = reduceB(end_r_933, lst_36_307_484); + + //GibCursor pvrtmp_2403 = tmp_struct_54.field0; + //GibCursor pvrtmp_2404 = tmp_struct_54.field1; + GibInt pvrtmp_2405 = tmp_struct_54.field2; + GibInt tailprim_1284 = tmpval_2391 + pvrtmp_2405; + GibCursorGibCursorGibIntProd return_55; + + //return_55.field0 = pvrtmp_2403; + //return_55.field1 = pvrtmp_2404; + return_55.field2 = tailprim_1284; + return return_55; + break; + } + +// case GIB_INDIRECTION_TAG: +// { +// uintptr_t tagged_tmpcur_58 = *(uintptr_t *) tmpcur_2390; +// GibCursor tmpcur_2406 = GIB_UNTAG(tagged_tmpcur_58); +// GibCursor tmpaftercur_2407 = tmpcur_2390 + 8; +// uint16_t tmptag_2408 = GIB_GET_TAG(tagged_tmpcur_58); +// GibCursor end_from_tagged_indr_1382 = tmpcur_2406 + tmptag_2408; +// GibCursor jump_loc_1384 = tmpcur_2390 + 8; +// GibCursorGibCursorGibIntProd tmp_struct_56 = +// reduceB(tmpcur_2406, tmpcur_2406); +// GibCursor pvrtmp_2409 = tmp_struct_56.field0; +// GibCursor pvrtmp_2410 = tmp_struct_56.field1; +// GibInt pvrtmp_2411 = tmp_struct_56.field2; +// GibCursorGibCursorGibIntProd return_57; +// +// return_57.field0 = end_r_933; +// return_57.field1 = jump_loc_1384; +// return_57.field2 = pvrtmp_2411; +// return return_57; +// break; +// } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_61 = *(uintptr_t *) (*lst_36_307_484); + GibCursor tmpcur_2412 = GIB_UNTAG(tagged_tmpcur_61); + //GibCursor tmpaftercur_2413 = tmpcur_2390 + 8; + *lst_36_307_484 = tmpcur_2412; + + // uint16_t tmptag_2414 = GIB_GET_TAG(tagged_tmpcur_61); + // GibCursor end_from_tagged_indr_1382 = tmpcur_2412 + tmptag_2414; + + GibCursorGibCursorGibIntProd tmp_struct_59 = reduceB(lst_36_307_484, lst_36_307_484); + return tmp_struct_59; + +// GibCursor pvrtmp_2415 = tmp_struct_59.field0; +// GibCursor pvrtmp_2416 = tmp_struct_59.field1; +// GibInt pvrtmp_2417 = tmp_struct_59.field2; +// GibCursorGibCursorGibIntProd return_60; +// +// return_60.field0 = pvrtmp_2415; +// return_60.field1 = pvrtmp_2416; +// return_60.field2 = pvrtmp_2417; +// return return_60; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2389"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_ListA(GibCursor end_r_937, + GibCursor end_r_939, + GibCursor loc_935, + GibCursor arg_88_315_493) +{ + if (loc_935 + 18 > end_r_939) { + gib_grow_region(&loc_935, &end_r_939); + } + + GibPackedTag tmpval_2419 = *(GibPackedTag *) arg_88_315_493; + GibCursor tmpcur_2420 = arg_88_315_493 + 1; + + + switch_2468: + ; + switch (tmpval_2419) { + + case 0: + { + GibInt tmpval_2421 = *(GibInt *) tmpcur_2420; + GibCursor tmpcur_2422 = tmpcur_2420 + sizeof(GibInt); + GibCursor jump_1285 = tmpcur_2420 + 8; + GibCursor loc_1089 = loc_935 + 1; + GibCursor loc_1090 = loc_1089 + 8; + + *(GibPackedTag *) loc_935 = 0; + + GibCursor writetag_1751 = loc_935 + 1; + GibCursor after_tag_1752 = loc_935 + 1; + + *(GibInt *) after_tag_1752 = tmpval_2421; + + GibCursor writecur_1756 = after_tag_1752 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_62 = + _copy_ListA(end_r_937, end_r_939, loc_1090, tmpcur_2422); + GibCursor pvrtmp_2423 = tmp_struct_62.field0; + GibCursor pvrtmp_2424 = tmp_struct_62.field1; + GibCursor pvrtmp_2425 = tmp_struct_62.field2; + GibCursor pvrtmp_2426 = tmp_struct_62.field3; + GibCursor pvrtmp_2427 = tmp_struct_62.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_63; + + return_63.field0 = pvrtmp_2423; + return_63.field1 = pvrtmp_2424; + return_63.field2 = pvrtmp_2425; + return_63.field3 = loc_935; + return_63.field4 = pvrtmp_2427; + return return_63; + break; + } + + case 1: + { + GibCursor jump_loc_1288 = arg_88_315_493 + 1; + + *(GibPackedTag *) loc_935 = 1; + + GibCursor writetag_1761 = loc_935 + 1; + GibCursor after_tag_1762 = loc_935 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_64; + + return_64.field0 = end_r_937; + return_64.field1 = end_r_939; + return_64.field2 = jump_loc_1288; + return_64.field3 = loc_935; + return_64.field4 = after_tag_1762; + return return_64; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_67 = *(uintptr_t *) tmpcur_2420; + GibCursor tmpcur_2440 = GIB_UNTAG(tagged_tmpcur_67); + GibCursor tmpaftercur_2441 = tmpcur_2420 + 8; + uint16_t tmptag_2442 = GIB_GET_TAG(tagged_tmpcur_67); + GibCursor end_from_tagged_indr_1388 = tmpcur_2440 + tmptag_2442; + GibCursor jump_loc_1390 = tmpcur_2420 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_65 = + _copy_ListA(tmpcur_2440, end_r_939, loc_935, tmpcur_2440); + GibCursor pvrtmp_2443 = tmp_struct_65.field0; + GibCursor pvrtmp_2444 = tmp_struct_65.field1; + GibCursor pvrtmp_2445 = tmp_struct_65.field2; + GibCursor pvrtmp_2446 = tmp_struct_65.field3; + GibCursor pvrtmp_2447 = tmp_struct_65.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_66; + + return_66.field0 = end_r_937; + return_66.field1 = pvrtmp_2444; + return_66.field2 = jump_loc_1390; + return_66.field3 = pvrtmp_2446; + return_66.field4 = pvrtmp_2447; + return return_66; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_70 = *(uintptr_t *) tmpcur_2420; + GibCursor tmpcur_2454 = GIB_UNTAG(tagged_tmpcur_70); + GibCursor tmpaftercur_2455 = tmpcur_2420 + 8; + uint16_t tmptag_2456 = GIB_GET_TAG(tagged_tmpcur_70); + GibCursor end_from_tagged_indr_1388 = tmpcur_2454 + tmptag_2456; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_68 = + _copy_ListA(tmpcur_2454, end_r_939, loc_935, tmpcur_2454); + GibCursor pvrtmp_2457 = tmp_struct_68.field0; + GibCursor pvrtmp_2458 = tmp_struct_68.field1; + GibCursor pvrtmp_2459 = tmp_struct_68.field2; + GibCursor pvrtmp_2460 = tmp_struct_68.field3; + GibCursor pvrtmp_2461 = tmp_struct_68.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_69; + + return_69.field0 = pvrtmp_2457; + return_69.field1 = pvrtmp_2458; + return_69.field2 = pvrtmp_2459; + return_69.field3 = pvrtmp_2460; + return_69.field4 = pvrtmp_2461; + return return_69; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2419"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_ListB(GibCursor end_r_943, + GibCursor end_r_945, + GibCursor loc_941, + GibCursor arg_176_330_498) +{ + if (loc_941 + 58 > end_r_945) { + gib_grow_region(&loc_941, &end_r_945); + } + + GibPackedTag tmpval_2469 = *(GibPackedTag *) arg_176_330_498; + GibCursor tmpcur_2470 = arg_176_330_498 + 1; + + + switch_2528: + ; + switch (tmpval_2469) { + + case 0: + { + GibInt tmpval_2471 = *(GibInt *) tmpcur_2470; + GibCursor tmpcur_2472 = tmpcur_2470 + sizeof(GibInt); + GibInt tmpval_2473 = *(GibInt *) tmpcur_2472; + GibCursor tmpcur_2474 = tmpcur_2472 + sizeof(GibInt); + GibInt tmpval_2475 = *(GibInt *) tmpcur_2474; + GibCursor tmpcur_2476 = tmpcur_2474 + sizeof(GibInt); + GibInt tmpval_2477 = *(GibInt *) tmpcur_2476; + GibCursor tmpcur_2478 = tmpcur_2476 + sizeof(GibInt); + GibInt tmpval_2479 = *(GibInt *) tmpcur_2478; + GibCursor tmpcur_2480 = tmpcur_2478 + sizeof(GibInt); + GibInt tmpval_2481 = *(GibInt *) tmpcur_2480; + GibCursor tmpcur_2482 = tmpcur_2480 + sizeof(GibInt); + GibCursor jump_1295 = tmpcur_2480 + 8; + GibCursor jump_1294 = tmpcur_2478 + 8; + GibCursor jump_1293 = tmpcur_2476 + 8; + GibCursor jump_1292 = tmpcur_2474 + 8; + GibCursor jump_1291 = tmpcur_2472 + 8; + GibCursor jump_1290 = tmpcur_2470 + 8; + GibCursor loc_1107 = loc_941 + 1; + GibCursor loc_1108 = loc_1107 + 8; + GibCursor loc_1109 = loc_1108 + 8; + GibCursor loc_1110 = loc_1109 + 8; + GibCursor loc_1111 = loc_1110 + 8; + GibCursor loc_1112 = loc_1111 + 8; + GibCursor loc_1113 = loc_1112 + 8; + + *(GibPackedTag *) loc_941 = 0; + + GibCursor writetag_1789 = loc_941 + 1; + GibCursor after_tag_1790 = loc_941 + 1; + + *(GibInt *) after_tag_1790 = tmpval_2471; + + GibCursor writecur_1794 = after_tag_1790 + sizeof(GibInt); + + *(GibInt *) writecur_1794 = tmpval_2473; + + GibCursor writecur_1795 = writecur_1794 + sizeof(GibInt); + + *(GibInt *) writecur_1795 = tmpval_2475; + + GibCursor writecur_1796 = writecur_1795 + sizeof(GibInt); + + *(GibInt *) writecur_1796 = tmpval_2477; + + GibCursor writecur_1797 = writecur_1796 + sizeof(GibInt); + + *(GibInt *) writecur_1797 = tmpval_2479; + + GibCursor writecur_1798 = writecur_1797 + sizeof(GibInt); + + *(GibInt *) writecur_1798 = tmpval_2481; + + GibCursor writecur_1799 = writecur_1798 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_74 = + _copy_ListB(end_r_943, end_r_945, loc_1113, tmpcur_2482); + GibCursor pvrtmp_2483 = tmp_struct_74.field0; + GibCursor pvrtmp_2484 = tmp_struct_74.field1; + GibCursor pvrtmp_2485 = tmp_struct_74.field2; + GibCursor pvrtmp_2486 = tmp_struct_74.field3; + GibCursor pvrtmp_2487 = tmp_struct_74.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_75; + + return_75.field0 = pvrtmp_2483; + return_75.field1 = pvrtmp_2484; + return_75.field2 = pvrtmp_2485; + return_75.field3 = loc_941; + return_75.field4 = pvrtmp_2487; + return return_75; + break; + } + + case 1: + { + GibCursor jump_loc_1298 = arg_176_330_498 + 1; + + *(GibPackedTag *) loc_941 = 1; + + GibCursor writetag_1804 = loc_941 + 1; + GibCursor after_tag_1805 = loc_941 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_76; + + return_76.field0 = end_r_943; + return_76.field1 = end_r_945; + return_76.field2 = jump_loc_1298; + return_76.field3 = loc_941; + return_76.field4 = after_tag_1805; + return return_76; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_79 = *(uintptr_t *) tmpcur_2470; + GibCursor tmpcur_2500 = GIB_UNTAG(tagged_tmpcur_79); + GibCursor tmpaftercur_2501 = tmpcur_2470 + 8; + uint16_t tmptag_2502 = GIB_GET_TAG(tagged_tmpcur_79); + GibCursor end_from_tagged_indr_1394 = tmpcur_2500 + tmptag_2502; + GibCursor jump_loc_1396 = tmpcur_2470 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_77 = + _copy_ListB(tmpcur_2500, end_r_945, loc_941, tmpcur_2500); + GibCursor pvrtmp_2503 = tmp_struct_77.field0; + GibCursor pvrtmp_2504 = tmp_struct_77.field1; + GibCursor pvrtmp_2505 = tmp_struct_77.field2; + GibCursor pvrtmp_2506 = tmp_struct_77.field3; + GibCursor pvrtmp_2507 = tmp_struct_77.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_78; + + return_78.field0 = end_r_943; + return_78.field1 = pvrtmp_2504; + return_78.field2 = jump_loc_1396; + return_78.field3 = pvrtmp_2506; + return_78.field4 = pvrtmp_2507; + return return_78; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_82 = *(uintptr_t *) tmpcur_2470; + GibCursor tmpcur_2514 = GIB_UNTAG(tagged_tmpcur_82); + GibCursor tmpaftercur_2515 = tmpcur_2470 + 8; + uint16_t tmptag_2516 = GIB_GET_TAG(tagged_tmpcur_82); + GibCursor end_from_tagged_indr_1394 = tmpcur_2514 + tmptag_2516; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_80 = + _copy_ListB(tmpcur_2514, end_r_945, loc_941, tmpcur_2514); + GibCursor pvrtmp_2517 = tmp_struct_80.field0; + GibCursor pvrtmp_2518 = tmp_struct_80.field1; + GibCursor pvrtmp_2519 = tmp_struct_80.field2; + GibCursor pvrtmp_2520 = tmp_struct_80.field3; + GibCursor pvrtmp_2521 = tmp_struct_80.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_81; + + return_81.field0 = pvrtmp_2517; + return_81.field1 = pvrtmp_2518; + return_81.field2 = pvrtmp_2519; + return_81.field3 = pvrtmp_2520; + return_81.field4 = pvrtmp_2521; + return return_81; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2469"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_List(GibCursor end_r_949, + GibCursor end_r_951, + GibCursor loc_947, + GibCursor arg_114_345_513) +{ + if (loc_947 + 42 > end_r_951) { + gib_grow_region(&loc_947, &end_r_951); + } + + GibPackedTag tmpval_2529 = *(GibPackedTag *) arg_114_345_513; + GibCursor tmpcur_2530 = arg_114_345_513 + 1; + + + switch_2593: + ; + switch (tmpval_2529) { + + case 0: + { + GibInt tmpval_2531 = *(GibInt *) tmpcur_2530; + GibCursor tmpcur_2532 = tmpcur_2530 + sizeof(GibInt); + GibInt tmpval_2533 = *(GibInt *) tmpcur_2532; + GibCursor tmpcur_2534 = tmpcur_2532 + sizeof(GibInt); + GibInt tmpval_2535 = *(GibInt *) tmpcur_2534; + GibCursor tmpcur_2536 = tmpcur_2534 + sizeof(GibInt); + GibInt tmpval_2537 = *(GibInt *) tmpcur_2536; + GibCursor tmpcur_2538 = tmpcur_2536 + sizeof(GibInt); + GibCursor jump_1303 = tmpcur_2536 + 8; + GibCursor jump_1302 = tmpcur_2534 + 8; + GibCursor jump_1301 = tmpcur_2532 + 8; + GibCursor jump_1300 = tmpcur_2530 + 8; + GibCursor loc_1142 = loc_947 + 1; + GibCursor loc_1143 = loc_1142 + 8; + GibCursor loc_1144 = loc_1143 + 8; + GibCursor loc_1145 = loc_1144 + 8; + GibCursor loc_1146 = loc_1145 + 8; + + *(GibPackedTag *) loc_947 = 0; + + GibCursor writetag_1833 = loc_947 + 1; + GibCursor after_tag_1834 = loc_947 + 1; + + *(GibInt *) after_tag_1834 = tmpval_2531; + + GibCursor writecur_1838 = after_tag_1834 + sizeof(GibInt); + + *(GibInt *) writecur_1838 = tmpval_2533; + + GibCursor writecur_1839 = writecur_1838 + sizeof(GibInt); + + *(GibInt *) writecur_1839 = tmpval_2535; + + GibCursor writecur_1840 = writecur_1839 + sizeof(GibInt); + + *(GibInt *) writecur_1840 = tmpval_2537; + + GibCursor writecur_1841 = writecur_1840 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_86 = + _copy_ListA(end_r_949, end_r_951, loc_1146, tmpcur_2538); + GibCursor pvrtmp_2539 = tmp_struct_86.field0; + GibCursor pvrtmp_2540 = tmp_struct_86.field1; + GibCursor pvrtmp_2541 = tmp_struct_86.field2; + GibCursor pvrtmp_2542 = tmp_struct_86.field3; + GibCursor pvrtmp_2543 = tmp_struct_86.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_87 = + _copy_List(pvrtmp_2539, pvrtmp_2540, pvrtmp_2543, pvrtmp_2541); + GibCursor pvrtmp_2548 = tmp_struct_87.field0; + GibCursor pvrtmp_2549 = tmp_struct_87.field1; + GibCursor pvrtmp_2550 = tmp_struct_87.field2; + GibCursor pvrtmp_2551 = tmp_struct_87.field3; + GibCursor pvrtmp_2552 = tmp_struct_87.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_88; + + return_88.field0 = pvrtmp_2548; + return_88.field1 = pvrtmp_2549; + return_88.field2 = pvrtmp_2550; + return_88.field3 = loc_947; + return_88.field4 = pvrtmp_2552; + return return_88; + break; + } + + case 1: + { + GibCursor jump_loc_1307 = arg_114_345_513 + 1; + + *(GibPackedTag *) loc_947 = 1; + + GibCursor writetag_1848 = loc_947 + 1; + GibCursor after_tag_1849 = loc_947 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_89; + + return_89.field0 = end_r_949; + return_89.field1 = end_r_951; + return_89.field2 = jump_loc_1307; + return_89.field3 = loc_947; + return_89.field4 = after_tag_1849; + return return_89; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_92 = *(uintptr_t *) tmpcur_2530; + GibCursor tmpcur_2565 = GIB_UNTAG(tagged_tmpcur_92); + GibCursor tmpaftercur_2566 = tmpcur_2530 + 8; + uint16_t tmptag_2567 = GIB_GET_TAG(tagged_tmpcur_92); + GibCursor end_from_tagged_indr_1400 = tmpcur_2565 + tmptag_2567; + GibCursor jump_loc_1402 = tmpcur_2530 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_90 = + _copy_List(tmpcur_2565, end_r_951, loc_947, tmpcur_2565); + GibCursor pvrtmp_2568 = tmp_struct_90.field0; + GibCursor pvrtmp_2569 = tmp_struct_90.field1; + GibCursor pvrtmp_2570 = tmp_struct_90.field2; + GibCursor pvrtmp_2571 = tmp_struct_90.field3; + GibCursor pvrtmp_2572 = tmp_struct_90.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_91; + + return_91.field0 = end_r_949; + return_91.field1 = pvrtmp_2569; + return_91.field2 = jump_loc_1402; + return_91.field3 = pvrtmp_2571; + return_91.field4 = pvrtmp_2572; + return return_91; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_95 = *(uintptr_t *) tmpcur_2530; + GibCursor tmpcur_2579 = GIB_UNTAG(tagged_tmpcur_95); + GibCursor tmpaftercur_2580 = tmpcur_2530 + 8; + uint16_t tmptag_2581 = GIB_GET_TAG(tagged_tmpcur_95); + GibCursor end_from_tagged_indr_1400 = tmpcur_2579 + tmptag_2581; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_93 = + _copy_List(tmpcur_2579, end_r_951, loc_947, tmpcur_2579); + GibCursor pvrtmp_2582 = tmp_struct_93.field0; + GibCursor pvrtmp_2583 = tmp_struct_93.field1; + GibCursor pvrtmp_2584 = tmp_struct_93.field2; + GibCursor pvrtmp_2585 = tmp_struct_93.field3; + GibCursor pvrtmp_2586 = tmp_struct_93.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_94; + + return_94.field0 = pvrtmp_2582; + return_94.field1 = pvrtmp_2583; + return_94.field2 = pvrtmp_2584; + return_94.field3 = pvrtmp_2585; + return_94.field4 = pvrtmp_2586; + return return_94; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2529"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_ListB(GibCursor end_r_954, + GibCursor arg_206_358_526) +{ + GibPackedTag tmpval_2594 = *(GibPackedTag *) arg_206_358_526; + GibCursor tmpcur_2595 = arg_206_358_526 + 1; + + + switch_2620: + ; + switch (tmpval_2594) { + + case 0: + { + GibInt tmpval_2596 = *(GibInt *) tmpcur_2595; + GibCursor tmpcur_2597 = tmpcur_2595 + sizeof(GibInt); + GibInt tmpval_2598 = *(GibInt *) tmpcur_2597; + GibCursor tmpcur_2599 = tmpcur_2597 + sizeof(GibInt); + GibInt tmpval_2600 = *(GibInt *) tmpcur_2599; + GibCursor tmpcur_2601 = tmpcur_2599 + sizeof(GibInt); + GibInt tmpval_2602 = *(GibInt *) tmpcur_2601; + GibCursor tmpcur_2603 = tmpcur_2601 + sizeof(GibInt); + GibInt tmpval_2604 = *(GibInt *) tmpcur_2603; + GibCursor tmpcur_2605 = tmpcur_2603 + sizeof(GibInt); + GibInt tmpval_2606 = *(GibInt *) tmpcur_2605; + GibCursor tmpcur_2607 = tmpcur_2605 + sizeof(GibInt); + GibCursor jump_1314 = tmpcur_2605 + 8; + GibCursor jump_1313 = tmpcur_2603 + 8; + GibCursor jump_1312 = tmpcur_2601 + 8; + GibCursor jump_1311 = tmpcur_2599 + 8; + GibCursor jump_1310 = tmpcur_2597 + 8; + GibCursor jump_1309 = tmpcur_2595 + 8; + GibCursorGibCursorProd tmp_struct_99 = + _traverse_ListB(end_r_954, tmpcur_2607); + GibCursor pvrtmp_2608 = tmp_struct_99.field0; + GibCursor pvrtmp_2609 = tmp_struct_99.field1; + GibCursorGibCursorProd return_100; + + return_100.field0 = pvrtmp_2608; + return_100.field1 = pvrtmp_2609; + return return_100; + break; + } + + case 1: + { + GibCursor jump_loc_1317 = arg_206_358_526 + 1; + GibCursorGibCursorProd return_101; + + return_101.field0 = end_r_954; + return_101.field1 = jump_loc_1317; + return return_101; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_104 = *(uintptr_t *) tmpcur_2595; + GibCursor tmpcur_2610 = GIB_UNTAG(tagged_tmpcur_104); + GibCursor tmpaftercur_2611 = tmpcur_2595 + 8; + uint16_t tmptag_2612 = GIB_GET_TAG(tagged_tmpcur_104); + GibCursor end_from_tagged_indr_1406 = tmpcur_2610 + tmptag_2612; + GibCursor jump_loc_1408 = tmpcur_2595 + 8; + GibCursorGibCursorProd tmp_struct_102 = + _traverse_ListB(tmpcur_2610, tmpcur_2610); + GibCursor pvrtmp_2613 = tmp_struct_102.field0; + GibCursor pvrtmp_2614 = tmp_struct_102.field1; + GibCursorGibCursorProd return_103; + + return_103.field0 = end_r_954; + return_103.field1 = jump_loc_1408; + return return_103; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_107 = *(uintptr_t *) tmpcur_2595; + GibCursor tmpcur_2615 = GIB_UNTAG(tagged_tmpcur_107); + GibCursor tmpaftercur_2616 = tmpcur_2595 + 8; + uint16_t tmptag_2617 = GIB_GET_TAG(tagged_tmpcur_107); + GibCursor end_from_tagged_indr_1406 = tmpcur_2615 + tmptag_2617; + GibCursorGibCursorProd tmp_struct_105 = + _traverse_ListB(tmpcur_2615, tmpcur_2615); + GibCursor pvrtmp_2618 = tmp_struct_105.field0; + GibCursor pvrtmp_2619 = tmp_struct_105.field1; + GibCursorGibCursorProd return_106; + + return_106.field0 = pvrtmp_2618; + return_106.field1 = pvrtmp_2619; + return return_106; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2594"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_ListA(GibCursor end_r_957, + GibCursor arg_103_369_535) +{ + GibPackedTag tmpval_2621 = *(GibPackedTag *) arg_103_369_535; + GibCursor tmpcur_2622 = arg_103_369_535 + 1; + + + switch_2637: + ; + switch (tmpval_2621) { + + case 0: + { + GibInt tmpval_2623 = *(GibInt *) tmpcur_2622; + GibCursor tmpcur_2624 = tmpcur_2622 + sizeof(GibInt); + GibCursor jump_1319 = tmpcur_2622 + 8; + unsigned char wildcard_108_372_538 = gib_print_symbol(2181); + unsigned char wildcard_111_373_539 = gib_print_symbol(2185); + unsigned char y_106_374_540 = printf("%ld", tmpval_2623); + unsigned char wildcard_110_375_541 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_108 = + _print_ListA(end_r_957, tmpcur_2624); + GibCursor pvrtmp_2625 = tmp_struct_108.field0; + GibCursor pvrtmp_2626 = tmp_struct_108.field1; + unsigned char wildcard_109_377_543 = gib_print_symbol(2176); + GibCursorGibCursorProd return_109; + + return_109.field0 = pvrtmp_2625; + return_109.field1 = pvrtmp_2626; + return return_109; + break; + } + + case 1: + { + GibCursor jump_loc_1322 = arg_103_369_535 + 1; + unsigned char wildcard_112_378_544 = gib_print_symbol(2178); + unsigned char wildcard_113_379_545 = gib_print_symbol(2176); + GibCursorGibCursorProd return_110; + + return_110.field0 = end_r_957; + return_110.field1 = jump_loc_1322; + return return_110; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_113 = *(uintptr_t *) tmpcur_2622; + GibCursor tmpcur_2627 = GIB_UNTAG(tagged_tmpcur_113); + GibCursor tmpaftercur_2628 = tmpcur_2622 + 8; + uint16_t tmptag_2629 = GIB_GET_TAG(tagged_tmpcur_113); + GibCursor end_from_tagged_indr_1412 = tmpcur_2627 + tmptag_2629; + GibCursor jump_loc_1414 = tmpcur_2622 + 8; + unsigned char wildcard_1417 = gib_print_symbol(2184); + GibCursorGibCursorProd tmp_struct_111 = + _print_ListA(tmpcur_2627, tmpcur_2627); + GibCursor pvrtmp_2630 = tmp_struct_111.field0; + GibCursor pvrtmp_2631 = tmp_struct_111.field1; + GibCursorGibCursorProd return_112; + + return_112.field0 = end_r_957; + return_112.field1 = jump_loc_1414; + return return_112; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_116 = *(uintptr_t *) tmpcur_2622; + GibCursor tmpcur_2632 = GIB_UNTAG(tagged_tmpcur_116); + GibCursor tmpaftercur_2633 = tmpcur_2622 + 8; + uint16_t tmptag_2634 = GIB_GET_TAG(tagged_tmpcur_116); + GibCursor end_from_tagged_indr_1412 = tmpcur_2632 + tmptag_2634; + unsigned char wildcard_1417 = gib_print_symbol(2183); + GibCursorGibCursorProd tmp_struct_114 = + _print_ListA(tmpcur_2632, tmpcur_2632); + GibCursor pvrtmp_2635 = tmp_struct_114.field0; + GibCursor pvrtmp_2636 = tmp_struct_114.field1; + GibCursorGibCursorProd return_115; + + return_115.field0 = pvrtmp_2635; + return_115.field1 = pvrtmp_2636; + return return_115; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2621"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_ListB(GibCursor end_r_960, + GibCursor arg_221_380_546) +{ + GibPackedTag tmpval_2638 = *(GibPackedTag *) arg_221_380_546; + GibCursor tmpcur_2639 = arg_221_380_546 + 1; + + + switch_2664: + ; + switch (tmpval_2638) { + + case 0: + { + GibInt tmpval_2640 = *(GibInt *) tmpcur_2639; + GibCursor tmpcur_2641 = tmpcur_2639 + sizeof(GibInt); + GibInt tmpval_2642 = *(GibInt *) tmpcur_2641; + GibCursor tmpcur_2643 = tmpcur_2641 + sizeof(GibInt); + GibInt tmpval_2644 = *(GibInt *) tmpcur_2643; + GibCursor tmpcur_2645 = tmpcur_2643 + sizeof(GibInt); + GibInt tmpval_2646 = *(GibInt *) tmpcur_2645; + GibCursor tmpcur_2647 = tmpcur_2645 + sizeof(GibInt); + GibInt tmpval_2648 = *(GibInt *) tmpcur_2647; + GibCursor tmpcur_2649 = tmpcur_2647 + sizeof(GibInt); + GibInt tmpval_2650 = *(GibInt *) tmpcur_2649; + GibCursor tmpcur_2651 = tmpcur_2649 + sizeof(GibInt); + GibCursor jump_1329 = tmpcur_2649 + 8; + GibCursor jump_1328 = tmpcur_2647 + 8; + GibCursor jump_1327 = tmpcur_2645 + 8; + GibCursor jump_1326 = tmpcur_2643 + 8; + GibCursor jump_1325 = tmpcur_2641 + 8; + GibCursor jump_1324 = tmpcur_2639 + 8; + unsigned char wildcard_236_388_554 = gib_print_symbol(2180); + unsigned char wildcard_244_389_555 = gib_print_symbol(2185); + unsigned char y_229_390_556 = printf("%ld", tmpval_2640); + unsigned char wildcard_243_391_557 = gib_print_symbol(2185); + unsigned char y_230_392_558 = printf("%ld", tmpval_2642); + unsigned char wildcard_242_393_559 = gib_print_symbol(2185); + unsigned char y_231_394_560 = printf("%ld", tmpval_2644); + unsigned char wildcard_241_395_561 = gib_print_symbol(2185); + unsigned char y_232_396_562 = printf("%ld", tmpval_2646); + unsigned char wildcard_240_397_563 = gib_print_symbol(2185); + unsigned char y_233_398_564 = printf("%ld", tmpval_2648); + unsigned char wildcard_239_399_565 = gib_print_symbol(2185); + unsigned char y_234_400_566 = printf("%ld", tmpval_2650); + unsigned char wildcard_238_401_567 = gib_print_symbol(2185); + GibCursorGibCursorProd tmp_struct_117 = + _print_ListB(end_r_960, tmpcur_2651); + GibCursor pvrtmp_2652 = tmp_struct_117.field0; + GibCursor pvrtmp_2653 = tmp_struct_117.field1; + unsigned char wildcard_237_403_569 = gib_print_symbol(2176); + GibCursorGibCursorProd return_118; + + return_118.field0 = pvrtmp_2652; + return_118.field1 = pvrtmp_2653; + return return_118; + break; + } + + case 1: + { + GibCursor jump_loc_1332 = arg_221_380_546 + 1; + unsigned char wildcard_245_404_570 = gib_print_symbol(2177); + unsigned char wildcard_246_405_571 = gib_print_symbol(2176); + GibCursorGibCursorProd return_119; + + return_119.field0 = end_r_960; + return_119.field1 = jump_loc_1332; + return return_119; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_122 = *(uintptr_t *) tmpcur_2639; + GibCursor tmpcur_2654 = GIB_UNTAG(tagged_tmpcur_122); + GibCursor tmpaftercur_2655 = tmpcur_2639 + 8; + uint16_t tmptag_2656 = GIB_GET_TAG(tagged_tmpcur_122); + GibCursor end_from_tagged_indr_1418 = tmpcur_2654 + tmptag_2656; + GibCursor jump_loc_1420 = tmpcur_2639 + 8; + unsigned char wildcard_1423 = gib_print_symbol(2184); + GibCursorGibCursorProd tmp_struct_120 = + _print_ListB(tmpcur_2654, tmpcur_2654); + GibCursor pvrtmp_2657 = tmp_struct_120.field0; + GibCursor pvrtmp_2658 = tmp_struct_120.field1; + GibCursorGibCursorProd return_121; + + return_121.field0 = end_r_960; + return_121.field1 = jump_loc_1420; + return return_121; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_125 = *(uintptr_t *) tmpcur_2639; + GibCursor tmpcur_2659 = GIB_UNTAG(tagged_tmpcur_125); + GibCursor tmpaftercur_2660 = tmpcur_2639 + 8; + uint16_t tmptag_2661 = GIB_GET_TAG(tagged_tmpcur_125); + GibCursor end_from_tagged_indr_1418 = tmpcur_2659 + tmptag_2661; + unsigned char wildcard_1423 = gib_print_symbol(2183); + GibCursorGibCursorProd tmp_struct_123 = + _print_ListB(tmpcur_2659, tmpcur_2659); + GibCursor pvrtmp_2662 = tmp_struct_123.field0; + GibCursor pvrtmp_2663 = tmp_struct_123.field1; + GibCursorGibCursorProd return_124; + + return_124.field0 = pvrtmp_2662; + return_124.field1 = pvrtmp_2663; + return return_124; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2638"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_List(GibCursor end_r_964, + GibCursor end_r_966, + GibCursor loc_962, + GibCursor arg_127_406_572) +{ + GibPackedTag tmpval_2665 = *(GibPackedTag *) arg_127_406_572; + GibCursor tmpcur_2666 = arg_127_406_572 + 1; + + + switch_2729: + ; + switch (tmpval_2665) { + + case 0: + { + GibInt tmpval_2667 = *(GibInt *) tmpcur_2666; + GibCursor tmpcur_2668 = tmpcur_2666 + sizeof(GibInt); + GibInt tmpval_2669 = *(GibInt *) tmpcur_2668; + GibCursor tmpcur_2670 = tmpcur_2668 + sizeof(GibInt); + GibInt tmpval_2671 = *(GibInt *) tmpcur_2670; + GibCursor tmpcur_2672 = tmpcur_2670 + sizeof(GibInt); + GibInt tmpval_2673 = *(GibInt *) tmpcur_2672; + GibCursor tmpcur_2674 = tmpcur_2672 + sizeof(GibInt); + GibCursor jump_1337 = tmpcur_2672 + 8; + GibCursor jump_1336 = tmpcur_2670 + 8; + GibCursor jump_1335 = tmpcur_2668 + 8; + GibCursor jump_1334 = tmpcur_2666 + 8; + GibCursor loc_1201 = loc_962 + 1; + GibCursor loc_1202 = loc_1201 + 8; + GibCursor loc_1203 = loc_1202 + 8; + GibCursor loc_1204 = loc_1203 + 8; + GibCursor loc_1205 = loc_1204 + 8; + + *(GibPackedTag *) loc_962 = 0; + + GibCursor writetag_1929 = loc_962 + 1; + GibCursor after_tag_1930 = loc_962 + 1; + + *(GibInt *) after_tag_1930 = tmpval_2667; + + GibCursor writecur_1934 = after_tag_1930 + sizeof(GibInt); + + *(GibInt *) writecur_1934 = tmpval_2669; + + GibCursor writecur_1935 = writecur_1934 + sizeof(GibInt); + + *(GibInt *) writecur_1935 = tmpval_2671; + + GibCursor writecur_1936 = writecur_1935 + sizeof(GibInt); + + *(GibInt *) writecur_1936 = tmpval_2673; + + GibCursor writecur_1937 = writecur_1936 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_126 = + _copy_without_ptrs_ListA(end_r_964, end_r_966, loc_1205, tmpcur_2674); + GibCursor pvrtmp_2675 = tmp_struct_126.field0; + GibCursor pvrtmp_2676 = tmp_struct_126.field1; + GibCursor pvrtmp_2677 = tmp_struct_126.field2; + GibCursor pvrtmp_2678 = tmp_struct_126.field3; + GibCursor pvrtmp_2679 = tmp_struct_126.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_127 = + _copy_without_ptrs_List(pvrtmp_2675, pvrtmp_2676, pvrtmp_2679, pvrtmp_2677); + GibCursor pvrtmp_2684 = tmp_struct_127.field0; + GibCursor pvrtmp_2685 = tmp_struct_127.field1; + GibCursor pvrtmp_2686 = tmp_struct_127.field2; + GibCursor pvrtmp_2687 = tmp_struct_127.field3; + GibCursor pvrtmp_2688 = tmp_struct_127.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_128; + + return_128.field0 = pvrtmp_2684; + return_128.field1 = pvrtmp_2685; + return_128.field2 = pvrtmp_2686; + return_128.field3 = loc_962; + return_128.field4 = pvrtmp_2688; + return return_128; + break; + } + + case 1: + { + GibCursor jump_loc_1341 = arg_127_406_572 + 1; + + *(GibPackedTag *) loc_962 = 1; + + GibCursor writetag_1944 = loc_962 + 1; + GibCursor after_tag_1945 = loc_962 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_129; + + return_129.field0 = end_r_964; + return_129.field1 = end_r_966; + return_129.field2 = jump_loc_1341; + return_129.field3 = loc_962; + return_129.field4 = after_tag_1945; + return return_129; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_132 = *(uintptr_t *) tmpcur_2666; + GibCursor tmpcur_2701 = GIB_UNTAG(tagged_tmpcur_132); + GibCursor tmpaftercur_2702 = tmpcur_2666 + 8; + uint16_t tmptag_2703 = GIB_GET_TAG(tagged_tmpcur_132); + GibCursor end_from_tagged_indr_1424 = tmpcur_2701 + tmptag_2703; + GibCursor jump_loc_1426 = tmpcur_2666 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_130 = + _copy_without_ptrs_List(tmpcur_2701, end_r_966, loc_962, tmpcur_2701); + GibCursor pvrtmp_2704 = tmp_struct_130.field0; + GibCursor pvrtmp_2705 = tmp_struct_130.field1; + GibCursor pvrtmp_2706 = tmp_struct_130.field2; + GibCursor pvrtmp_2707 = tmp_struct_130.field3; + GibCursor pvrtmp_2708 = tmp_struct_130.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_131; + + return_131.field0 = end_r_964; + return_131.field1 = pvrtmp_2705; + return_131.field2 = jump_loc_1426; + return_131.field3 = pvrtmp_2707; + return_131.field4 = pvrtmp_2708; + return return_131; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_135 = *(uintptr_t *) tmpcur_2666; + GibCursor tmpcur_2715 = GIB_UNTAG(tagged_tmpcur_135); + GibCursor tmpaftercur_2716 = tmpcur_2666 + 8; + uint16_t tmptag_2717 = GIB_GET_TAG(tagged_tmpcur_135); + GibCursor end_from_tagged_indr_1424 = tmpcur_2715 + tmptag_2717; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_133 = + _copy_without_ptrs_List(tmpcur_2715, end_r_966, loc_962, tmpcur_2715); + GibCursor pvrtmp_2718 = tmp_struct_133.field0; + GibCursor pvrtmp_2719 = tmp_struct_133.field1; + GibCursor pvrtmp_2720 = tmp_struct_133.field2; + GibCursor pvrtmp_2721 = tmp_struct_133.field3; + GibCursor pvrtmp_2722 = tmp_struct_133.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_134; + + return_134.field0 = pvrtmp_2718; + return_134.field1 = pvrtmp_2719; + return_134.field2 = pvrtmp_2720; + return_134.field3 = pvrtmp_2721; + return_134.field4 = pvrtmp_2722; + return return_134; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_2665"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_143 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_2186 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_972 = region_2186.start; + GibCursor end_r_972 = region_2186.end; + GibCursorGibCursorGibCursorProd tmp_struct_136 = + mkListB(end_r_972, r_972, 2500000); + GibCursor pvrtmp_2187 = tmp_struct_136.field0; + GibCursor pvrtmp_2188 = tmp_struct_136.field1; + GibCursor pvrtmp_2189 = tmp_struct_136.field2; + GibInt timed_2035; + GibVector *times_141 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_2035; + struct timespec end_timed_2035; + + for (long long iters_timed_2035 = 0; iters_timed_2035 < + gib_get_iters_param(); iters_timed_2035++) { + if (iters_timed_2035 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_2035); + + GibCursorGibCursorGibIntProd tmp_struct_137 = reduceB(&pvrtmp_2187, &pvrtmp_2188); + // GibCursor pvrtmp_2194 = tmp_struct_137.field0; + // GibCursor pvrtmp_2195 = tmp_struct_137.field1; + GibInt pvrtmp_2196 = tmp_struct_137.field2; + + timed_2035 = pvrtmp_2196; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_2035); + if (iters_timed_2035 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + pvrtmp_2187 = tmp_struct_136.field0; + pvrtmp_2188 = tmp_struct_136.field1; + + double itertime_138 = gib_difftimespecs(&begin_timed_2035, + &end_timed_2035); + + printf("itertime: %lf\n", itertime_138); + gib_vector_inplace_update(times_141, iters_timed_2035, &itertime_138); + } + gib_vector_inplace_sort(times_141, gib_compare_doubles); + + double *tmp_142 = (double *) gib_vector_nth(times_141, + gib_get_iters_param() / 2); + double selftimed_140 = *tmp_142; + double batchtime_139 = gib_sum_timing_array(times_141); + + gib_print_timing_array(times_141); + gib_vector_free(times_141); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_139); + printf("SELFTIMED: %e\n", selftimed_140); + printf("%ld", timed_2035); + printf("\n"); + + int exit_144 = gib_exit(); + + return exit_144; +} diff --git a/microbench/manual_soa_examples/reduceList.soa.c b/microbench/manual_soa_examples/reduceList.soa.c new file mode 100644 index 000000000..161634d64 --- /dev/null +++ b/microbench/manual_soa_examples/reduceList.soa.c @@ -0,0 +1,3332 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +typedef struct GibCursorPtr7Prod_struct { + GibCursor field0[7]; + } GibCursorPtr7Prod; +typedef struct GibCursorPtr7GibCursorPtr7Prod_struct { + GibCursor field0[7]; + GibCursor field1[7]; + } GibCursorPtr7GibCursorPtr7Prod; +typedef struct GibCursorPtr7GibCursorPtr7GibIntProd_struct { + GibCursor field0[7]; + GibCursor field1[7]; + GibInt field2; + } GibCursorPtr7GibCursorPtr7GibIntProd; +typedef struct GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod_struct { + GibCursor field0[7]; + GibCursor field1[7]; + GibCursor field2[7]; + } GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod; +typedef struct GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod_struct { + GibCursor field0[7]; + GibCursor field1[7]; + GibCursor field2[7]; + GibCursor field3[7]; + GibCursor field4[7]; + } GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod; +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod +_copy_without_ptrs_ListB(GibCursor cursor_ptr_2498[7], + GibCursor cursor_ptr_2497[7], + GibCursor cursor_ptr_2499[7], + GibCursor arg_191_249_424[7]); +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_1229, + GibCursor arg_98_264_439); +GibCursorGibCursorProd _print_List(GibCursor end_r_1232, + GibCursor arg_153_268_443); +GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod +mkListB(GibCursor cursor_ptr_2686[7], GibCursor cursor_ptr_2687[7], + GibInt len_34_291_466); +GibCursorGibCursorProd _traverse_List(GibCursor end_r_1249, + GibCursor arg_140_293_470); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_ListA(GibCursor end_r_1253, GibCursor end_r_1255, + GibCursor loc_1251, GibCursor arg_93_302_479); +void reduceB(GibCursor cursor_ptr_2775[7], + GibCursor lst_36_307_484[7], + GibInt *Res); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_ListA(GibCursor end_r_1273, GibCursor end_r_1275, GibCursor loc_1271, + GibCursor arg_88_315_493); +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod +_copy_ListB(GibCursor cursor_ptr_2925[7], GibCursor cursor_ptr_2924[7], + GibCursor cursor_ptr_2926[7], GibCursor arg_176_330_498[7]); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_List(GibCursor end_r_1307, GibCursor end_r_1309, GibCursor loc_1305, + GibCursor arg_114_345_513); +GibCursorPtr7GibCursorPtr7Prod _traverse_ListB(GibCursor cursor_ptr_3126[7], + GibCursor arg_206_358_526[7]); +GibCursorGibCursorProd _print_ListA(GibCursor end_r_1326, + GibCursor arg_103_369_535); +GibCursorPtr7GibCursorPtr7Prod _print_ListB(GibCursor cursor_ptr_3256[7], + GibCursor arg_221_380_546[7]); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_List(GibCursor end_r_1344, GibCursor end_r_1346, + GibCursor loc_1342, GibCursor arg_127_406_572); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + List_T, + ListA_T, + ListB_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(10); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[7]; + + field_tys[0] = ListA_T; + field_tys[1] = List_T; + error = gib_info_table_insert_packed_dcon(List_T, 0, 32, 0, 4, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(List_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 1); + exit(1); + } + field_tys[0] = ListA_T; + error = gib_info_table_insert_packed_dcon(ListA_T, 0, 8, 0, 1, 1, field_tys, + 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListA_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 1); + exit(1); + } + field_tys[0] = ListB_T; + error = gib_info_table_insert_packed_dcon(ListB_T, 0, 48, 0, 6, 1, + field_tys, 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListB_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(3638, ")"); + gib_add_symbol(3639, "(NilB"); + gib_add_symbol(3640, "(NilA"); + gib_add_symbol(3641, "(Nil"); + gib_add_symbol(3642, "(ConsB"); + gib_add_symbol(3643, "(ConsA"); + gib_add_symbol(3644, "(Cons"); + gib_add_symbol(3645, " ->r "); + gib_add_symbol(3646, " ->i "); + gib_add_symbol(3647, " "); +} +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod _copy_without_ptrs_ListB(GibCursor cursor_ptr_2498[7], + GibCursor cursor_ptr_2497[7], + GibCursor cursor_ptr_2499[7], + GibCursor arg_191_249_424[7]) +{ + GibCursor end_r_1213 = cursor_ptr_2498[0]; + GibCursor end_r_1214 = cursor_ptr_2498[1]; + GibCursor end_r_1215 = cursor_ptr_2498[2]; + GibCursor end_r_1216 = cursor_ptr_2498[3]; + GibCursor end_r_1217 = cursor_ptr_2498[4]; + GibCursor end_r_1218 = cursor_ptr_2498[5]; + GibCursor end_r_1219 = cursor_ptr_2498[6]; + GibCursor end_r_1220 = cursor_ptr_2497[0]; + GibCursor end_r_1221 = cursor_ptr_2497[1]; + GibCursor end_r_1222 = cursor_ptr_2497[2]; + GibCursor end_r_1223 = cursor_ptr_2497[3]; + GibCursor end_r_1224 = cursor_ptr_2497[4]; + GibCursor end_r_1225 = cursor_ptr_2497[5]; + GibCursor end_r_1226 = cursor_ptr_2497[6]; + GibCursor dcon_2502 = arg_191_249_424[0]; + GibPackedTag tmpval_3665 = *(GibPackedTag *) dcon_2502; + GibCursor tmpcur_3666 = dcon_2502 + 1; + + + switch_3760: + ; + switch (tmpval_3665) { + + case 0: + { + GibCursor soa_field_0_2504 = arg_191_249_424[1]; + GibCursor soa_field_1_2505 = arg_191_249_424[2]; + GibCursor soa_field_2_2506 = arg_191_249_424[3]; + GibCursor soa_field_3_2507 = arg_191_249_424[4]; + GibCursor soa_field_4_2508 = arg_191_249_424[5]; + GibCursor soa_field_5_2509 = arg_191_249_424[6]; + GibInt tmpval_3667 = *(GibInt *) soa_field_0_2504; + GibCursor tmpcur_3668 = soa_field_0_2504 + sizeof(GibInt); + GibInt tmpval_3669 = *(GibInt *) soa_field_1_2505; + GibCursor tmpcur_3670 = soa_field_1_2505 + sizeof(GibInt); + GibInt tmpval_3671 = *(GibInt *) soa_field_2_2506; + GibCursor tmpcur_3672 = soa_field_2_2506 + sizeof(GibInt); + GibInt tmpval_3673 = *(GibInt *) soa_field_3_2507; + GibCursor tmpcur_3674 = soa_field_3_2507 + sizeof(GibInt); + GibInt tmpval_3675 = *(GibInt *) soa_field_4_2508; + GibCursor tmpcur_3676 = soa_field_4_2508 + sizeof(GibInt); + GibInt tmpval_3677 = *(GibInt *) soa_field_5_2509; + GibCursor tmpcur_3678 = soa_field_5_2509 + sizeof(GibInt); + GibCursor cursor_ptr_2501[7] = {tmpcur_3666, tmpcur_3668, + tmpcur_3670, tmpcur_3672, + tmpcur_3674, tmpcur_3676, + tmpcur_3678}; + GibCursor loc_1199 = arg_191_249_424[0]; + GibCursor jumpf_dloc_1807 = loc_1199 + 1; + GibCursor loc_IntTy_1200 = arg_191_249_424[1]; + GibCursor loc_IntTy_1201 = arg_191_249_424[2]; + GibCursor loc_IntTy_1202 = arg_191_249_424[3]; + GibCursor loc_IntTy_1203 = arg_191_249_424[4]; + GibCursor loc_IntTy_1204 = arg_191_249_424[5]; + GibCursor loc_IntTy_1205 = arg_191_249_424[6]; + GibCursor jumpf_floc_loc_1808 = soa_field_0_2504 + 8; + GibCursor jumpf_floc_loc_1809 = soa_field_1_2505 + 8; + GibCursor jumpf_floc_loc_1810 = soa_field_2_2506 + 8; + GibCursor jumpf_floc_loc_1811 = soa_field_3_2507 + 8; + GibCursor jumpf_floc_loc_1812 = soa_field_4_2508 + 8; + GibCursor jumpf_floc_loc_1813 = soa_field_5_2509 + 8; + GibCursor loc_1397 = jumpf_dloc_1807 + 0; + GibCursor loc_1396 = jumpf_floc_loc_1808 + 0; + GibCursor cursor_ptr_2518[7] = {jumpf_dloc_1807, + jumpf_floc_loc_1808, + jumpf_floc_loc_1809, + jumpf_floc_loc_1810, + jumpf_floc_loc_1811, + jumpf_floc_loc_1812, + jumpf_floc_loc_1813}; + GibCursor loc_IntTy_1208 = cursor_ptr_2499[2]; + GibCursor new_floc_loc_1427 = loc_IntTy_1208 + 8; + GibCursor loc_1206 = cursor_ptr_2499[0]; + GibCursor new_dloc_1425 = loc_1206 + 1; + GibCursor loc_IntTy_1210 = cursor_ptr_2499[4]; + GibCursor new_floc_loc_1429 = loc_IntTy_1210 + 8; + GibCursor loc_IntTy_1212 = cursor_ptr_2499[6]; + GibCursor new_floc_loc_1431 = loc_IntTy_1212 + 8; + GibCursor loc_IntTy_1209 = cursor_ptr_2499[3]; + GibCursor new_floc_loc_1428 = loc_IntTy_1209 + 8; + GibCursor loc_IntTy_1207 = cursor_ptr_2499[1]; + GibCursor new_floc_loc_1426 = loc_IntTy_1207 + 8; + GibCursor loc_IntTy_1211 = cursor_ptr_2499[5]; + GibCursor new_floc_loc_1430 = loc_IntTy_1211 + 8; + GibCursor cursor_ptr_2519[7] = {new_dloc_1425, new_floc_loc_1426, + new_floc_loc_1427, + new_floc_loc_1428, + new_floc_loc_1429, + new_floc_loc_1430, + new_floc_loc_1431}; + + *(GibPackedTag *) loc_1206 = 0; + + GibCursor writetag_2529 = loc_1206 + 1; + GibCursor after_tag_2530 = loc_1206 + 1; + + *(GibInt *) loc_IntTy_1207 = tmpval_3667; + + GibCursor writecur_2534 = loc_IntTy_1207 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1208 = tmpval_3669; + + GibCursor writecur_2536 = loc_IntTy_1208 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1209 = tmpval_3671; + + GibCursor writecur_2538 = loc_IntTy_1209 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1210 = tmpval_3673; + + GibCursor writecur_2540 = loc_IntTy_1210 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1211 = tmpval_3675; + + GibCursor writecur_2542 = loc_IntTy_1211 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1212 = tmpval_3677; + + GibCursor writecur_2544 = loc_IntTy_1212 + sizeof(GibInt); + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_0 = + _copy_without_ptrs_ListB(cursor_ptr_2498, cursor_ptr_2497, cursor_ptr_2519, cursor_ptr_2501); + GibCursor pvrtmp_3679[7]; + + memcpy(pvrtmp_3679, tmp_struct_0.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3680[7]; + + memcpy(pvrtmp_3680, tmp_struct_0.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3681[7]; + + memcpy(pvrtmp_3681, tmp_struct_0.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3682[7]; + + memcpy(pvrtmp_3682, tmp_struct_0.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3683[7]; + + memcpy(pvrtmp_3683, tmp_struct_0.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_1; + + memcpy(return_1.field0, pvrtmp_3679, sizeof(GibCursor [7])); + memcpy(return_1.field1, pvrtmp_3680, sizeof(GibCursor [7])); + memcpy(return_1.field2, pvrtmp_3681, sizeof(GibCursor [7])); + memcpy(return_1.field3, cursor_ptr_2499, sizeof(GibCursor [7])); + memcpy(return_1.field4, pvrtmp_3683, sizeof(GibCursor [7])); + return return_1; + break; + } + + case 1: + { + GibCursor soa_field_0_2550 = arg_191_249_424[1]; + GibCursor soa_field_1_2551 = arg_191_249_424[2]; + GibCursor soa_field_2_2552 = arg_191_249_424[3]; + GibCursor soa_field_3_2553 = arg_191_249_424[4]; + GibCursor soa_field_4_2554 = arg_191_249_424[5]; + GibCursor soa_field_5_2555 = arg_191_249_424[6]; + GibCursor loc_1199 = arg_191_249_424[0]; + GibCursor jump_dloc_1822 = loc_1199 + 1; + GibCursor loc_IntTy_1200 = arg_191_249_424[1]; + GibCursor jump_floc_loc_1823 = loc_IntTy_1200 + 0; + GibCursor loc_IntTy_1201 = arg_191_249_424[2]; + GibCursor jump_floc_loc_1824 = loc_IntTy_1201 + 0; + GibCursor loc_IntTy_1202 = arg_191_249_424[3]; + GibCursor jump_floc_loc_1825 = loc_IntTy_1202 + 0; + GibCursor loc_IntTy_1203 = arg_191_249_424[4]; + GibCursor jump_floc_loc_1826 = loc_IntTy_1203 + 0; + GibCursor loc_IntTy_1204 = arg_191_249_424[5]; + GibCursor jump_floc_loc_1827 = loc_IntTy_1204 + 0; + GibCursor loc_IntTy_1205 = arg_191_249_424[6]; + GibCursor jump_floc_loc_1828 = loc_IntTy_1205 + 0; + GibCursor cursor_ptr_2557[7] = {jump_dloc_1822, jump_floc_loc_1823, + jump_floc_loc_1824, + jump_floc_loc_1825, + jump_floc_loc_1826, + jump_floc_loc_1827, + jump_floc_loc_1828}; + GibCursor loc_IntTy_1208 = cursor_ptr_2499[2]; + GibCursor new_floc_loc_1427 = loc_IntTy_1208 + 8; + GibCursor loc_1206 = cursor_ptr_2499[0]; + GibCursor new_dloc_1425 = loc_1206 + 1; + GibCursor loc_IntTy_1210 = cursor_ptr_2499[4]; + GibCursor new_floc_loc_1429 = loc_IntTy_1210 + 8; + GibCursor loc_IntTy_1212 = cursor_ptr_2499[6]; + GibCursor new_floc_loc_1431 = loc_IntTy_1212 + 8; + GibCursor loc_IntTy_1209 = cursor_ptr_2499[3]; + GibCursor new_floc_loc_1428 = loc_IntTy_1209 + 8; + GibCursor loc_IntTy_1207 = cursor_ptr_2499[1]; + GibCursor new_floc_loc_1426 = loc_IntTy_1207 + 8; + GibCursor loc_IntTy_1211 = cursor_ptr_2499[5]; + GibCursor new_floc_loc_1430 = loc_IntTy_1211 + 8; + + *(GibPackedTag *) loc_1206 = 1; + + GibCursor writetag_2558 = loc_1206 + 1; + GibCursor after_tag_2559 = loc_1206 + 1; + GibCursor aft_soa_loc_2563[7] = {after_tag_2559, loc_IntTy_1207, + loc_IntTy_1208, loc_IntTy_1209, + loc_IntTy_1210, loc_IntTy_1211, + loc_IntTy_1212}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_2; + + memcpy(return_2.field0, cursor_ptr_2498, sizeof(GibCursor [7])); + memcpy(return_2.field1, cursor_ptr_2497, sizeof(GibCursor [7])); + memcpy(return_2.field2, cursor_ptr_2557, sizeof(GibCursor [7])); + memcpy(return_2.field3, cursor_ptr_2499, sizeof(GibCursor [7])); + memcpy(return_2.field4, aft_soa_loc_2563, sizeof(GibCursor [7])); + return return_2; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_2567 = arg_191_249_424[1]; + GibCursor soa_field_1_2568 = arg_191_249_424[2]; + GibCursor soa_field_2_2569 = arg_191_249_424[3]; + GibCursor soa_field_3_2570 = arg_191_249_424[4]; + GibCursor soa_field_4_2571 = arg_191_249_424[5]; + GibCursor soa_field_5_2572 = arg_191_249_424[6]; + uintptr_t tagged_tmpcur_11 = *(uintptr_t *) tmpcur_3666; + GibCursor tmpcur_3696 = GIB_UNTAG(tagged_tmpcur_11); + GibCursor tmpaftercur_3697 = tmpcur_3666 + 8; + uint16_t tmptag_3698 = GIB_GET_TAG(tagged_tmpcur_11); + GibCursor end_from_tagged_dcon_redir_2597 = tmpcur_3696 + + tmptag_3698; + GibCursor field_nxt_2590 = soa_field_0_2567 + 1; + uintptr_t tagged_tmpcur_10 = *(uintptr_t *) field_nxt_2590; + GibCursor tmpcur_3699 = GIB_UNTAG(tagged_tmpcur_10); + GibCursor tmpaftercur_3700 = field_nxt_2590 + 8; + uint16_t tmptag_3701 = GIB_GET_TAG(tagged_tmpcur_10); + GibCursor end_from_tagged_fld_redir_2598 = tmpcur_3699 + + tmptag_3701; + GibCursor field_nxt_2591 = soa_field_1_2568 + 1; + uintptr_t tagged_tmpcur_9 = *(uintptr_t *) field_nxt_2591; + GibCursor tmpcur_3702 = GIB_UNTAG(tagged_tmpcur_9); + GibCursor tmpaftercur_3703 = field_nxt_2591 + 8; + uint16_t tmptag_3704 = GIB_GET_TAG(tagged_tmpcur_9); + GibCursor end_from_tagged_fld_redir_2599 = tmpcur_3702 + + tmptag_3704; + GibCursor field_nxt_2592 = soa_field_2_2569 + 1; + uintptr_t tagged_tmpcur_8 = *(uintptr_t *) field_nxt_2592; + GibCursor tmpcur_3705 = GIB_UNTAG(tagged_tmpcur_8); + GibCursor tmpaftercur_3706 = field_nxt_2592 + 8; + uint16_t tmptag_3707 = GIB_GET_TAG(tagged_tmpcur_8); + GibCursor end_from_tagged_fld_redir_2600 = tmpcur_3705 + + tmptag_3707; + GibCursor field_nxt_2593 = soa_field_3_2570 + 1; + uintptr_t tagged_tmpcur_7 = *(uintptr_t *) field_nxt_2593; + GibCursor tmpcur_3708 = GIB_UNTAG(tagged_tmpcur_7); + GibCursor tmpaftercur_3709 = field_nxt_2593 + 8; + uint16_t tmptag_3710 = GIB_GET_TAG(tagged_tmpcur_7); + GibCursor end_from_tagged_fld_redir_2601 = tmpcur_3708 + + tmptag_3710; + GibCursor field_nxt_2594 = soa_field_4_2571 + 1; + uintptr_t tagged_tmpcur_6 = *(uintptr_t *) field_nxt_2594; + GibCursor tmpcur_3711 = GIB_UNTAG(tagged_tmpcur_6); + GibCursor tmpaftercur_3712 = field_nxt_2594 + 8; + uint16_t tmptag_3713 = GIB_GET_TAG(tagged_tmpcur_6); + GibCursor end_from_tagged_fld_redir_2602 = tmpcur_3711 + + tmptag_3713; + GibCursor field_nxt_2595 = soa_field_5_2572 + 1; + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) field_nxt_2595; + GibCursor tmpcur_3714 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_3715 = field_nxt_2595 + 8; + uint16_t tmptag_3716 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_fld_redir_2603 = tmpcur_3714 + + tmptag_3716; + GibCursor indr_1995[7] = {tmpcur_3696, tmpcur_3699, tmpcur_3702, + tmpcur_3705, tmpcur_3708, tmpcur_3711, + tmpcur_3714}; + GibCursor loc_1199 = arg_191_249_424[0]; + GibCursor jump_dloc_2003 = loc_1199 + 9; + GibCursor loc_IntTy_1205 = arg_191_249_424[6]; + GibCursor loc_IntTy_1204 = arg_191_249_424[5]; + GibCursor loc_IntTy_1203 = arg_191_249_424[4]; + GibCursor loc_IntTy_1202 = arg_191_249_424[3]; + GibCursor loc_IntTy_1201 = arg_191_249_424[2]; + GibCursor loc_IntTy_1200 = arg_191_249_424[1]; + GibCursor aft_indir_loc_2019 = loc_IntTy_1200 + 9; + GibCursor aft_indir_loc_2020 = loc_IntTy_1201 + 9; + GibCursor aft_indir_loc_2021 = loc_IntTy_1202 + 9; + GibCursor aft_indir_loc_2022 = loc_IntTy_1203 + 9; + GibCursor aft_indir_loc_2023 = loc_IntTy_1204 + 9; + GibCursor aft_indir_loc_2024 = loc_IntTy_1205 + 9; + GibCursor cursor_ptr_2604[7] = {jump_dloc_2003, aft_indir_loc_2019, + aft_indir_loc_2020, + aft_indir_loc_2021, + aft_indir_loc_2022, + aft_indir_loc_2023, + aft_indir_loc_2024}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_3 = + _copy_without_ptrs_ListB(indr_1995, cursor_ptr_2497, cursor_ptr_2499, indr_1995); + GibCursor pvrtmp_3717[7]; + + memcpy(pvrtmp_3717, tmp_struct_3.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3718[7]; + + memcpy(pvrtmp_3718, tmp_struct_3.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3719[7]; + + memcpy(pvrtmp_3719, tmp_struct_3.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3720[7]; + + memcpy(pvrtmp_3720, tmp_struct_3.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3721[7]; + + memcpy(pvrtmp_3721, tmp_struct_3.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_4; + + memcpy(return_4.field0, cursor_ptr_2498, sizeof(GibCursor [7])); + memcpy(return_4.field1, pvrtmp_3718, sizeof(GibCursor [7])); + memcpy(return_4.field2, cursor_ptr_2604, sizeof(GibCursor [7])); + memcpy(return_4.field3, pvrtmp_3720, sizeof(GibCursor [7])); + memcpy(return_4.field4, pvrtmp_3721, sizeof(GibCursor [7])); + return return_4; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_2615 = arg_191_249_424[1]; + GibCursor soa_field_1_2616 = arg_191_249_424[2]; + GibCursor soa_field_2_2617 = arg_191_249_424[3]; + GibCursor soa_field_3_2618 = arg_191_249_424[4]; + GibCursor soa_field_4_2619 = arg_191_249_424[5]; + GibCursor soa_field_5_2620 = arg_191_249_424[6]; + uintptr_t tagged_tmpcur_20 = *(uintptr_t *) tmpcur_3666; + GibCursor tmpcur_3728 = GIB_UNTAG(tagged_tmpcur_20); + GibCursor tmpaftercur_3729 = tmpcur_3666 + 8; + uint16_t tmptag_3730 = GIB_GET_TAG(tagged_tmpcur_20); + GibCursor end_from_tagged_dcon_redir_2636 = tmpcur_3728 + + tmptag_3730; + GibCursor field_nxt_2630 = soa_field_0_2615 + 1; + uintptr_t tagged_tmpcur_19 = *(uintptr_t *) field_nxt_2630; + GibCursor tmpcur_3731 = GIB_UNTAG(tagged_tmpcur_19); + GibCursor tmpaftercur_3732 = field_nxt_2630 + 8; + uint16_t tmptag_3733 = GIB_GET_TAG(tagged_tmpcur_19); + GibCursor end_from_tagged_fld_redir_2637 = tmpcur_3731 + + tmptag_3733; + GibCursor field_nxt_2631 = soa_field_1_2616 + 1; + uintptr_t tagged_tmpcur_18 = *(uintptr_t *) field_nxt_2631; + GibCursor tmpcur_3734 = GIB_UNTAG(tagged_tmpcur_18); + GibCursor tmpaftercur_3735 = field_nxt_2631 + 8; + uint16_t tmptag_3736 = GIB_GET_TAG(tagged_tmpcur_18); + GibCursor end_from_tagged_fld_redir_2638 = tmpcur_3734 + + tmptag_3736; + GibCursor field_nxt_2632 = soa_field_2_2617 + 1; + uintptr_t tagged_tmpcur_17 = *(uintptr_t *) field_nxt_2632; + GibCursor tmpcur_3737 = GIB_UNTAG(tagged_tmpcur_17); + GibCursor tmpaftercur_3738 = field_nxt_2632 + 8; + uint16_t tmptag_3739 = GIB_GET_TAG(tagged_tmpcur_17); + GibCursor end_from_tagged_fld_redir_2639 = tmpcur_3737 + + tmptag_3739; + GibCursor field_nxt_2633 = soa_field_3_2618 + 1; + uintptr_t tagged_tmpcur_16 = *(uintptr_t *) field_nxt_2633; + GibCursor tmpcur_3740 = GIB_UNTAG(tagged_tmpcur_16); + GibCursor tmpaftercur_3741 = field_nxt_2633 + 8; + uint16_t tmptag_3742 = GIB_GET_TAG(tagged_tmpcur_16); + GibCursor end_from_tagged_fld_redir_2640 = tmpcur_3740 + + tmptag_3742; + GibCursor field_nxt_2634 = soa_field_4_2619 + 1; + uintptr_t tagged_tmpcur_15 = *(uintptr_t *) field_nxt_2634; + GibCursor tmpcur_3743 = GIB_UNTAG(tagged_tmpcur_15); + GibCursor tmpaftercur_3744 = field_nxt_2634 + 8; + uint16_t tmptag_3745 = GIB_GET_TAG(tagged_tmpcur_15); + GibCursor end_from_tagged_fld_redir_2641 = tmpcur_3743 + + tmptag_3745; + GibCursor field_nxt_2635 = soa_field_5_2620 + 1; + uintptr_t tagged_tmpcur_14 = *(uintptr_t *) field_nxt_2635; + GibCursor tmpcur_3746 = GIB_UNTAG(tagged_tmpcur_14); + GibCursor tmpaftercur_3747 = field_nxt_2635 + 8; + uint16_t tmptag_3748 = GIB_GET_TAG(tagged_tmpcur_14); + GibCursor end_from_tagged_fld_redir_2642 = tmpcur_3746 + + tmptag_3748; + GibCursor indr_1995[7] = {tmpcur_3728, tmpcur_3731, tmpcur_3734, + tmpcur_3737, tmpcur_3740, tmpcur_3743, + tmpcur_3746}; + GibCursor loc_1206 = cursor_ptr_2499[0]; + GibCursor loc_IntTy_1207 = cursor_ptr_2499[1]; + GibCursor loc_IntTy_1208 = cursor_ptr_2499[2]; + GibCursor loc_IntTy_1209 = cursor_ptr_2499[3]; + GibCursor loc_IntTy_1210 = cursor_ptr_2499[4]; + GibCursor loc_IntTy_1211 = cursor_ptr_2499[5]; + GibCursor loc_IntTy_1212 = cursor_ptr_2499[6]; + GibCursor copy_dloc_2025 = loc_1206 + 0; + GibCursor copy_floc_loc_2031 = loc_IntTy_1212 + 0; + GibCursor copy_floc_loc_2030 = loc_IntTy_1211 + 0; + GibCursor copy_floc_loc_2029 = loc_IntTy_1210 + 0; + GibCursor copy_floc_loc_2028 = loc_IntTy_1209 + 0; + GibCursor copy_floc_loc_2027 = loc_IntTy_1208 + 0; + GibCursor copy_floc_loc_2026 = loc_IntTy_1207 + 0; + GibCursor cursor_ptr_2643[7] = {copy_dloc_2025, copy_floc_loc_2026, + copy_floc_loc_2027, + copy_floc_loc_2028, + copy_floc_loc_2029, + copy_floc_loc_2030, + copy_floc_loc_2031}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_12 = + _copy_without_ptrs_ListB(indr_1995, cursor_ptr_2497, cursor_ptr_2643, indr_1995); + GibCursor pvrtmp_3749[7]; + + memcpy(pvrtmp_3749, tmp_struct_12.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3750[7]; + + memcpy(pvrtmp_3750, tmp_struct_12.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3751[7]; + + memcpy(pvrtmp_3751, tmp_struct_12.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3752[7]; + + memcpy(pvrtmp_3752, tmp_struct_12.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3753[7]; + + memcpy(pvrtmp_3753, tmp_struct_12.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_13; + + memcpy(return_13.field0, pvrtmp_3749, sizeof(GibCursor [7])); + memcpy(return_13.field1, pvrtmp_3750, sizeof(GibCursor [7])); + memcpy(return_13.field2, pvrtmp_3751, sizeof(GibCursor [7])); + memcpy(return_13.field3, pvrtmp_3752, sizeof(GibCursor [7])); + memcpy(return_13.field4, pvrtmp_3753, sizeof(GibCursor [7])); + return return_13; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3665"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_1229, + GibCursor arg_98_264_439) +{ + GibPackedTag tmpval_3761 = *(GibPackedTag *) arg_98_264_439; + GibCursor tmpcur_3762 = arg_98_264_439 + 1; + + + switch_3777: + ; + switch (tmpval_3761) { + + case 0: + { + GibInt tmpval_3763 = *(GibInt *) tmpcur_3762; + GibCursor tmpcur_3764 = tmpcur_3762 + sizeof(GibInt); + GibCursor jump_1830 = tmpcur_3762 + 8; + GibCursorGibCursorProd tmp_struct_21 = + _traverse_ListA(end_r_1229, tmpcur_3764); + GibCursor pvrtmp_3765 = tmp_struct_21.field0; + GibCursor pvrtmp_3766 = tmp_struct_21.field1; + GibCursorGibCursorProd return_22; + + return_22.field0 = pvrtmp_3765; + return_22.field1 = pvrtmp_3766; + return return_22; + break; + } + + case 1: + { + GibCursor jump_loc_1833 = arg_98_264_439 + 1; + GibCursorGibCursorProd return_23; + + return_23.field0 = end_r_1229; + return_23.field1 = jump_loc_1833; + return return_23; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_26 = *(uintptr_t *) tmpcur_3762; + GibCursor tmpcur_3767 = GIB_UNTAG(tagged_tmpcur_26); + GibCursor tmpaftercur_3768 = tmpcur_3762 + 8; + uint16_t tmptag_3769 = GIB_GET_TAG(tagged_tmpcur_26); + GibCursor end_from_tagged_indr_2032 = tmpcur_3767 + tmptag_3769; + GibCursor jump_loc_2034 = tmpcur_3762 + 8; + GibCursorGibCursorProd tmp_struct_24 = + _traverse_ListA(tmpcur_3767, tmpcur_3767); + GibCursor pvrtmp_3770 = tmp_struct_24.field0; + GibCursor pvrtmp_3771 = tmp_struct_24.field1; + GibCursorGibCursorProd return_25; + + return_25.field0 = end_r_1229; + return_25.field1 = jump_loc_2034; + return return_25; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_29 = *(uintptr_t *) tmpcur_3762; + GibCursor tmpcur_3772 = GIB_UNTAG(tagged_tmpcur_29); + GibCursor tmpaftercur_3773 = tmpcur_3762 + 8; + uint16_t tmptag_3774 = GIB_GET_TAG(tagged_tmpcur_29); + GibCursor end_from_tagged_indr_2032 = tmpcur_3772 + tmptag_3774; + GibCursorGibCursorProd tmp_struct_27 = + _traverse_ListA(tmpcur_3772, tmpcur_3772); + GibCursor pvrtmp_3775 = tmp_struct_27.field0; + GibCursor pvrtmp_3776 = tmp_struct_27.field1; + GibCursorGibCursorProd return_28; + + return_28.field0 = pvrtmp_3775; + return_28.field1 = pvrtmp_3776; + return return_28; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3761"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_List(GibCursor end_r_1232, + GibCursor arg_153_268_443) +{ + GibPackedTag tmpval_3778 = *(GibPackedTag *) arg_153_268_443; + GibCursor tmpcur_3779 = arg_153_268_443 + 1; + + + switch_3802: + ; + switch (tmpval_3778) { + + case 0: + { + GibInt tmpval_3780 = *(GibInt *) tmpcur_3779; + GibCursor tmpcur_3781 = tmpcur_3779 + sizeof(GibInt); + GibInt tmpval_3782 = *(GibInt *) tmpcur_3781; + GibCursor tmpcur_3783 = tmpcur_3781 + sizeof(GibInt); + GibInt tmpval_3784 = *(GibInt *) tmpcur_3783; + GibCursor tmpcur_3785 = tmpcur_3783 + sizeof(GibInt); + GibInt tmpval_3786 = *(GibInt *) tmpcur_3785; + GibCursor tmpcur_3787 = tmpcur_3785 + sizeof(GibInt); + GibCursor jump_1838 = tmpcur_3785 + 8; + GibCursor jump_1837 = tmpcur_3783 + 8; + GibCursor jump_1836 = tmpcur_3781 + 8; + GibCursor jump_1835 = tmpcur_3779 + 8; + unsigned char wildcard_166_275_450 = gib_print_symbol(3644); + unsigned char wildcard_173_276_451 = gib_print_symbol(3647); + unsigned char y_160_277_452 = printf("%ld", tmpval_3780); + unsigned char wildcard_172_278_453 = gib_print_symbol(3647); + unsigned char y_161_279_454 = printf("%ld", tmpval_3782); + unsigned char wildcard_171_280_455 = gib_print_symbol(3647); + unsigned char y_162_281_456 = printf("%ld", tmpval_3784); + unsigned char wildcard_170_282_457 = gib_print_symbol(3647); + unsigned char y_163_283_458 = printf("%ld", tmpval_3786); + unsigned char wildcard_169_284_459 = gib_print_symbol(3647); + GibCursorGibCursorProd tmp_struct_30 = + _print_ListA(end_r_1232, tmpcur_3787); + GibCursor pvrtmp_3788 = tmp_struct_30.field0; + GibCursor pvrtmp_3789 = tmp_struct_30.field1; + unsigned char wildcard_168_286_461 = gib_print_symbol(3647); + GibCursorGibCursorProd tmp_struct_31 = + _print_List(pvrtmp_3788, pvrtmp_3789); + GibCursor pvrtmp_3790 = tmp_struct_31.field0; + GibCursor pvrtmp_3791 = tmp_struct_31.field1; + unsigned char wildcard_167_288_463 = gib_print_symbol(3638); + GibCursorGibCursorProd return_32; + + return_32.field0 = pvrtmp_3790; + return_32.field1 = pvrtmp_3791; + return return_32; + break; + } + + case 1: + { + GibCursor jump_loc_1842 = arg_153_268_443 + 1; + unsigned char wildcard_174_289_464 = gib_print_symbol(3641); + unsigned char wildcard_175_290_465 = gib_print_symbol(3638); + GibCursorGibCursorProd return_33; + + return_33.field0 = end_r_1232; + return_33.field1 = jump_loc_1842; + return return_33; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_36 = *(uintptr_t *) tmpcur_3779; + GibCursor tmpcur_3792 = GIB_UNTAG(tagged_tmpcur_36); + GibCursor tmpaftercur_3793 = tmpcur_3779 + 8; + uint16_t tmptag_3794 = GIB_GET_TAG(tagged_tmpcur_36); + GibCursor end_from_tagged_indr_2038 = tmpcur_3792 + tmptag_3794; + GibCursor jump_loc_2040 = tmpcur_3779 + 8; + unsigned char wildcard_2043 = gib_print_symbol(3646); + GibCursorGibCursorProd tmp_struct_34 = + _print_List(tmpcur_3792, tmpcur_3792); + GibCursor pvrtmp_3795 = tmp_struct_34.field0; + GibCursor pvrtmp_3796 = tmp_struct_34.field1; + GibCursorGibCursorProd return_35; + + return_35.field0 = end_r_1232; + return_35.field1 = jump_loc_2040; + return return_35; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_39 = *(uintptr_t *) tmpcur_3779; + GibCursor tmpcur_3797 = GIB_UNTAG(tagged_tmpcur_39); + GibCursor tmpaftercur_3798 = tmpcur_3779 + 8; + uint16_t tmptag_3799 = GIB_GET_TAG(tagged_tmpcur_39); + GibCursor end_from_tagged_indr_2038 = tmpcur_3797 + tmptag_3799; + unsigned char wildcard_2043 = gib_print_symbol(3645); + GibCursorGibCursorProd tmp_struct_37 = + _print_List(tmpcur_3797, tmpcur_3797); + GibCursor pvrtmp_3800 = tmp_struct_37.field0; + GibCursor pvrtmp_3801 = tmp_struct_37.field1; + GibCursorGibCursorProd return_38; + + return_38.field0 = pvrtmp_3800; + return_38.field1 = pvrtmp_3801; + return return_38; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3778"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod mkListB(GibCursor cursor_ptr_2686[7], + GibCursor cursor_ptr_2687[7], + GibInt len_34_291_466) +{ + GibCursor end_r_1245 = cursor_ptr_2686[5]; + GibCursor end_r_1242 = cursor_ptr_2686[2]; + GibCursor end_r_1246 = cursor_ptr_2686[6]; + GibCursor end_r_1243 = cursor_ptr_2686[3]; + GibCursor end_r_1241 = cursor_ptr_2686[1]; + GibCursor end_r_1240 = cursor_ptr_2686[0]; + GibCursor end_r_1244 = cursor_ptr_2686[4]; + GibCursor loc_IntTy_1235 = cursor_ptr_2687[2]; + GibCursor loc_IntTy_1238 = cursor_ptr_2687[5]; + GibCursor loc_IntTy_1236 = cursor_ptr_2687[3]; + GibCursor loc_IntTy_1234 = cursor_ptr_2687[1]; + GibCursor loc_IntTy_1239 = cursor_ptr_2687[6]; + GibCursor loc_1233 = cursor_ptr_2687[0]; + GibCursor loc_IntTy_1237 = cursor_ptr_2687[4]; + + if (loc_IntTy_1239 + 17 > end_r_1246 || (loc_IntTy_1238 + 17 > end_r_1245 || + (loc_IntTy_1237 + 17 > + end_r_1244 || (loc_IntTy_1236 + + 17 > end_r_1243 || + (loc_IntTy_1235 + + 17 > end_r_1242 || + (loc_IntTy_1234 + + 17 > + end_r_1241 || + loc_1233 + 66 > + end_r_1240)))))) { + gib_grow_region(&loc_IntTy_1239, &end_r_1246); + gib_grow_region(&loc_IntTy_1238, &end_r_1245); + gib_grow_region(&loc_IntTy_1237, &end_r_1244); + gib_grow_region(&loc_IntTy_1236, &end_r_1243); + gib_grow_region(&loc_IntTy_1235, &end_r_1242); + gib_grow_region(&loc_IntTy_1234, &end_r_1241); + gib_grow_region(&loc_1233, &end_r_1240); + } + + GibCursor overwrite_reg_2688[7] = {end_r_1240, end_r_1241, end_r_1242, + end_r_1243, end_r_1244, end_r_1245, + end_r_1246}; + GibBool fltIf_419_467 = len_34_291_466 <= 0; + + if (fltIf_419_467) { + GibCursor new_floc_loc_1499 = loc_IntTy_1236 + 8; + GibCursor new_floc_loc_1500 = loc_IntTy_1237 + 8; + GibCursor new_dloc_1496 = loc_1233 + 1; + GibCursor new_floc_loc_1502 = loc_IntTy_1239 + 8; + GibCursor new_floc_loc_1497 = loc_IntTy_1234 + 8; + GibCursor new_floc_loc_1498 = loc_IntTy_1235 + 8; + GibCursor new_floc_loc_1501 = loc_IntTy_1238 + 8; + + *(GibPackedTag *) loc_1233 = 1; + + GibCursor writetag_2689 = loc_1233 + 1; + GibCursor after_tag_2690 = loc_1233 + 1; + GibCursor aft_soa_loc_2694[7] = {after_tag_2690, loc_IntTy_1234, + loc_IntTy_1235, loc_IntTy_1236, + loc_IntTy_1237, loc_IntTy_1238, + loc_IntTy_1239}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod return_40; + + memcpy(return_40.field0, overwrite_reg_2688, sizeof(GibCursor [7])); + memcpy(return_40.field1, cursor_ptr_2687, sizeof(GibCursor [7])); + memcpy(return_40.field2, aft_soa_loc_2694, sizeof(GibCursor [7])); + return return_40; + } else { + GibInt fltAppE_420_468 = len_34_291_466 - 1; + GibCursor new_floc_loc_1499 = loc_IntTy_1236 + 8; + GibCursor new_floc_loc_1500 = loc_IntTy_1237 + 8; + GibCursor new_dloc_1496 = loc_1233 + 1; + GibCursor new_floc_loc_1502 = loc_IntTy_1239 + 8; + GibCursor new_floc_loc_1497 = loc_IntTy_1234 + 8; + GibCursor new_floc_loc_1498 = loc_IntTy_1235 + 8; + GibCursor new_floc_loc_1501 = loc_IntTy_1238 + 8; + GibCursor cursor_ptr_2697[7] = {new_dloc_1496, new_floc_loc_1497, + new_floc_loc_1498, new_floc_loc_1499, + new_floc_loc_1500, new_floc_loc_1501, + new_floc_loc_1502}; + + *(GibPackedTag *) loc_1233 = 0; + + GibCursor writetag_2702 = loc_1233 + 1; + GibCursor after_tag_2703 = loc_1233 + 1; + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2707 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2709 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2711 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2713 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2715 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2717 = loc_IntTy_1234 + sizeof(GibInt); + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod tmp_struct_41 = + mkListB(overwrite_reg_2688, cursor_ptr_2697, fltAppE_420_468); + GibCursor pvrtmp_3807[7]; + + memcpy(pvrtmp_3807, tmp_struct_41.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3808[7]; + + memcpy(pvrtmp_3808, tmp_struct_41.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3809[7]; + + memcpy(pvrtmp_3809, tmp_struct_41.field2, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod return_42; + + memcpy(return_42.field0, pvrtmp_3807, sizeof(GibCursor [7])); + memcpy(return_42.field1, cursor_ptr_2687, sizeof(GibCursor [7])); + memcpy(return_42.field2, pvrtmp_3809, sizeof(GibCursor [7])); + return return_42; + } +} +GibCursorGibCursorProd _traverse_List(GibCursor end_r_1249, + GibCursor arg_140_293_470) +{ + GibPackedTag tmpval_3818 = *(GibPackedTag *) arg_140_293_470; + GibCursor tmpcur_3819 = arg_140_293_470 + 1; + + + switch_3842: + ; + switch (tmpval_3818) { + + case 0: + { + GibInt tmpval_3820 = *(GibInt *) tmpcur_3819; + GibCursor tmpcur_3821 = tmpcur_3819 + sizeof(GibInt); + GibInt tmpval_3822 = *(GibInt *) tmpcur_3821; + GibCursor tmpcur_3823 = tmpcur_3821 + sizeof(GibInt); + GibInt tmpval_3824 = *(GibInt *) tmpcur_3823; + GibCursor tmpcur_3825 = tmpcur_3823 + sizeof(GibInt); + GibInt tmpval_3826 = *(GibInt *) tmpcur_3825; + GibCursor tmpcur_3827 = tmpcur_3825 + sizeof(GibInt); + GibCursor jump_1849 = tmpcur_3825 + 8; + GibCursor jump_1848 = tmpcur_3823 + 8; + GibCursor jump_1847 = tmpcur_3821 + 8; + GibCursor jump_1846 = tmpcur_3819 + 8; + GibCursorGibCursorProd tmp_struct_43 = + _traverse_ListA(end_r_1249, tmpcur_3827); + GibCursor pvrtmp_3828 = tmp_struct_43.field0; + GibCursor pvrtmp_3829 = tmp_struct_43.field1; + GibCursorGibCursorProd tmp_struct_44 = + _traverse_List(pvrtmp_3828, pvrtmp_3829); + GibCursor pvrtmp_3830 = tmp_struct_44.field0; + GibCursor pvrtmp_3831 = tmp_struct_44.field1; + GibCursorGibCursorProd return_45; + + return_45.field0 = pvrtmp_3830; + return_45.field1 = pvrtmp_3831; + return return_45; + break; + } + + case 1: + { + GibCursor jump_loc_1853 = arg_140_293_470 + 1; + GibCursorGibCursorProd return_46; + + return_46.field0 = end_r_1249; + return_46.field1 = jump_loc_1853; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_3819; + GibCursor tmpcur_3832 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_3833 = tmpcur_3819 + 8; + uint16_t tmptag_3834 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_2044 = tmpcur_3832 + tmptag_3834; + GibCursor jump_loc_2046 = tmpcur_3819 + 8; + GibCursorGibCursorProd tmp_struct_47 = + _traverse_List(tmpcur_3832, tmpcur_3832); + GibCursor pvrtmp_3835 = tmp_struct_47.field0; + GibCursor pvrtmp_3836 = tmp_struct_47.field1; + GibCursorGibCursorProd return_48; + + return_48.field0 = end_r_1249; + return_48.field1 = jump_loc_2046; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_3819; + GibCursor tmpcur_3837 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_3838 = tmpcur_3819 + 8; + uint16_t tmptag_3839 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_2044 = tmpcur_3837 + tmptag_3839; + GibCursorGibCursorProd tmp_struct_50 = + _traverse_List(tmpcur_3837, tmpcur_3837); + GibCursor pvrtmp_3840 = tmp_struct_50.field0; + GibCursor pvrtmp_3841 = tmp_struct_50.field1; + GibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_3840; + return_51.field1 = pvrtmp_3841; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3818"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_ListA(GibCursor end_r_1253, + GibCursor end_r_1255, + GibCursor loc_1251, + GibCursor arg_93_302_479) +{ + GibPackedTag tmpval_3843 = *(GibPackedTag *) arg_93_302_479; + GibCursor tmpcur_3844 = arg_93_302_479 + 1; + + + switch_3892: + ; + switch (tmpval_3843) { + + case 0: + { + GibInt tmpval_3845 = *(GibInt *) tmpcur_3844; + GibCursor tmpcur_3846 = tmpcur_3844 + sizeof(GibInt); + GibCursor jump_1855 = tmpcur_3844 + 8; + GibCursor loc_1541 = loc_1251 + 1; + GibCursor loc_1542 = loc_1541 + 8; + + *(GibPackedTag *) loc_1251 = 0; + + GibCursor writetag_2747 = loc_1251 + 1; + GibCursor after_tag_2748 = loc_1251 + 1; + + *(GibInt *) after_tag_2748 = tmpval_3845; + + GibCursor writecur_2752 = after_tag_2748 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_53 = + _copy_without_ptrs_ListA(end_r_1253, end_r_1255, loc_1542, tmpcur_3846); + GibCursor pvrtmp_3847 = tmp_struct_53.field0; + GibCursor pvrtmp_3848 = tmp_struct_53.field1; + GibCursor pvrtmp_3849 = tmp_struct_53.field2; + GibCursor pvrtmp_3850 = tmp_struct_53.field3; + GibCursor pvrtmp_3851 = tmp_struct_53.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_54; + + return_54.field0 = pvrtmp_3847; + return_54.field1 = pvrtmp_3848; + return_54.field2 = pvrtmp_3849; + return_54.field3 = loc_1251; + return_54.field4 = pvrtmp_3851; + return return_54; + break; + } + + case 1: + { + GibCursor jump_loc_1858 = arg_93_302_479 + 1; + + *(GibPackedTag *) loc_1251 = 1; + + GibCursor writetag_2757 = loc_1251 + 1; + GibCursor after_tag_2758 = loc_1251 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_55; + + return_55.field0 = end_r_1253; + return_55.field1 = end_r_1255; + return_55.field2 = jump_loc_1858; + return_55.field3 = loc_1251; + return_55.field4 = after_tag_2758; + return return_55; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_58 = *(uintptr_t *) tmpcur_3844; + GibCursor tmpcur_3864 = GIB_UNTAG(tagged_tmpcur_58); + GibCursor tmpaftercur_3865 = tmpcur_3844 + 8; + uint16_t tmptag_3866 = GIB_GET_TAG(tagged_tmpcur_58); + GibCursor end_from_tagged_indr_2050 = tmpcur_3864 + tmptag_3866; + GibCursor jump_loc_2052 = tmpcur_3844 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_56 = + _copy_without_ptrs_ListA(tmpcur_3864, end_r_1255, loc_1251, tmpcur_3864); + GibCursor pvrtmp_3867 = tmp_struct_56.field0; + GibCursor pvrtmp_3868 = tmp_struct_56.field1; + GibCursor pvrtmp_3869 = tmp_struct_56.field2; + GibCursor pvrtmp_3870 = tmp_struct_56.field3; + GibCursor pvrtmp_3871 = tmp_struct_56.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_57; + + return_57.field0 = end_r_1253; + return_57.field1 = pvrtmp_3868; + return_57.field2 = jump_loc_2052; + return_57.field3 = pvrtmp_3870; + return_57.field4 = pvrtmp_3871; + return return_57; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_61 = *(uintptr_t *) tmpcur_3844; + GibCursor tmpcur_3878 = GIB_UNTAG(tagged_tmpcur_61); + GibCursor tmpaftercur_3879 = tmpcur_3844 + 8; + uint16_t tmptag_3880 = GIB_GET_TAG(tagged_tmpcur_61); + GibCursor end_from_tagged_indr_2050 = tmpcur_3878 + tmptag_3880; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_59 = + _copy_without_ptrs_ListA(tmpcur_3878, end_r_1255, loc_1251, tmpcur_3878); + GibCursor pvrtmp_3881 = tmp_struct_59.field0; + GibCursor pvrtmp_3882 = tmp_struct_59.field1; + GibCursor pvrtmp_3883 = tmp_struct_59.field2; + GibCursor pvrtmp_3884 = tmp_struct_59.field3; + GibCursor pvrtmp_3885 = tmp_struct_59.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_60; + + return_60.field0 = pvrtmp_3881; + return_60.field1 = pvrtmp_3882; + return_60.field2 = pvrtmp_3883; + return_60.field3 = pvrtmp_3884; + return_60.field4 = pvrtmp_3885; + return return_60; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3843"); + exit(1); + } + } +} +void reduceB(GibCursor cursor_ptr_2775[7], + GibCursor lst_36_307_484[7], + GibInt *Res) +{ + // GibCursor *end_r_1263 = &cursor_ptr_2775[0]; + // GibCursor *end_r_1264 = &cursor_ptr_2775[1]; + // GibCursor *end_r_1265 = &cursor_ptr_2775[2]; + // GibCursor *end_r_1266 = &cursor_ptr_2775[3]; + // GibCursor *end_r_1267 = &cursor_ptr_2775[4]; + // GibCursor *end_r_1268 = &cursor_ptr_2775[5]; + // GibCursor *end_r_1269 = &cursor_ptr_2775[6]; + + GibCursor *dcon_2778 = &lst_36_307_484[0]; + GibPackedTag tmpval_3893 = *(GibPackedTag *) (*dcon_2778); + + //GibCursor tmpcur_3894 = *dcon_2778 + 1; + *dcon_2778 += 1; + + switch_3958: + ; + switch (tmpval_3893) { + + case 1: + { + // GibCursor *soa_field_0_2780 = &lst_36_307_484[1]; + // GibCursor *soa_field_1_2781 = &lst_36_307_484[2]; + // GibCursor *soa_field_2_2782 = &lst_36_307_484[3]; + // GibCursor *soa_field_3_2783 = &lst_36_307_484[4]; + // GibCursor *soa_field_4_2784 = &lst_36_307_484[5]; + // GibCursor *soa_field_5_2785 = &lst_36_307_484[6]; + GibCursor *loc_1256 = &lst_36_307_484[0]; + + + //GibCursor jump_dloc_1861 = loc_1256 + 1; + *loc_1256 += 1; + + // GibCursor *loc_IntTy_1257 = &lst_36_307_484[1]; + // + // GibCursor *jump_floc_loc_1862 = loc_IntTy_1257; + // GibCursor *loc_IntTy_1258 = &lst_36_307_484[2]; + // GibCursor *jump_floc_loc_1863 = loc_IntTy_1258; + // GibCursor *loc_IntTy_1259 = &lst_36_307_484[3]; + // GibCursor *jump_floc_loc_1864 = loc_IntTy_1259; + // GibCursor *loc_IntTy_1260 = &lst_36_307_484[4]; + // GibCursor *jump_floc_loc_1865 = &loc_IntTy_1260; + // GibCursor *loc_IntTy_1261 = &lst_36_307_484[5]; + // GibCursor *jump_floc_loc_1866 = &loc_IntTy_1261; + // GibCursor *loc_IntTy_1262 = &lst_36_307_484[6]; + // GibCursor *jump_floc_loc_1867 = &loc_IntTy_1262; + + // GibCursor cursor_ptr_2787[7] = {jump_dloc_1861, jump_floc_loc_1862, + // jump_floc_loc_1863, + // jump_floc_loc_1864, + // jump_floc_loc_1865, + // jump_floc_loc_1866, + // jump_floc_loc_1867}; + //GibCursorPtr7GibCursorPtr7GibIntProd return_62; + + //memcpy(return_62.field0, cursor_ptr_2775, sizeof(GibCursor [7])); + //memcpy(return_62.field1, lst_36_307_484, sizeof(GibCursor [7])); + //return_62.field2 = 0; + //return return_62; + *Res += 0; + break; + } + + case 0: + { + GibCursor *soa_field_0_2789 = &lst_36_307_484[1]; + + // GibCursor *soa_field_1_2790 = &lst_36_307_484[2]; + // GibCursor *soa_field_2_2791 = &lst_36_307_484[3]; + // GibCursor *soa_field_3_2792 = &lst_36_307_484[4]; + // GibCursor *soa_field_4_2793 = &lst_36_307_484[5]; + // GibCursor *soa_field_5_2794 = &lst_36_307_484[6]; + + GibInt tmpval_3895 = *(GibInt *) (*soa_field_0_2789); + //GibCursor tmpcur_3896 = soa_field_0_2789 + sizeof(GibInt); + *soa_field_0_2789 += sizeof(GibInt); + + // *soa_field_1_2790 += sizeof(GibInt); + // *soa_field_2_2791 += sizeof(GibInt); + // *soa_field_3_2792 += sizeof(GibInt); + // *soa_field_4_2793 += sizeof(GibInt); + // *soa_field_5_2794 += sizeof(GibInt); + + // GibInt tmpval_3897 = *(GibInt *) soa_field_1_2790; + // //GibCursor tmpcur_3898 = soa_field_1_2790 + sizeof(GibInt); + // *soa_field_1_2790 += sizeof(GibInt); + // + // GibInt tmpval_3899 = *(GibInt *) soa_field_2_2791; + // //GibCursor tmpcur_3900 = soa_field_2_2791 + sizeof(GibInt); + // *soa_field_2_2791 += sizeof(GibInt); + // + // GibInt tmpval_3901 = *(GibInt *) soa_field_3_2792; + // //GibCursor tmpcur_3902 = soa_field_3_2792 + sizeof(GibInt); + // *soa_field_3_2792 += sizeof(GibInt); + // + // GibInt tmpval_3903 = *(GibInt *) soa_field_4_2793; + // //GibCursor tmpcur_3904 = soa_field_4_2793 + sizeof(GibInt); + // *soa_field_4_2793 += sizeof(GibInt); + // + // GibInt tmpval_3905 = *(GibInt *) soa_field_5_2794; + // //GibCursor tmpcur_3906 = soa_field_5_2794 + sizeof(GibInt); + // *soa_field_5_2794 += sizeof(GibInt); + + + // GibCursor cursor_ptr_2777[7] = {tmpcur_3894, tmpcur_3896, + // tmpcur_3898, tmpcur_3900, + // tmpcur_3902, tmpcur_3904, + // tmpcur_3906}; + // GibCursor loc_1256 = lst_36_307_484[0]; + // GibCursor jumpf_dloc_1868 = loc_1256 + 1; + // GibCursor loc_IntTy_1257 = lst_36_307_484[1]; + // GibCursor loc_IntTy_1258 = lst_36_307_484[2]; + // GibCursor loc_IntTy_1259 = lst_36_307_484[3]; + // GibCursor loc_IntTy_1260 = lst_36_307_484[4]; + // GibCursor loc_IntTy_1261 = lst_36_307_484[5]; + // GibCursor loc_IntTy_1262 = lst_36_307_484[6]; + // GibCursor jumpf_floc_loc_1869 = soa_field_0_2789 + 8; + // GibCursor jumpf_floc_loc_1870 = soa_field_1_2790 + 8; + // GibCursor jumpf_floc_loc_1871 = soa_field_2_2791 + 8; + // GibCursor jumpf_floc_loc_1872 = soa_field_3_2792 + 8; + // GibCursor jumpf_floc_loc_1873 = soa_field_4_2793 + 8; + // GibCursor jumpf_floc_loc_1874 = soa_field_5_2794 + 8; + // GibCursor loc_1561 = jumpf_dloc_1868 + 0; + // GibCursor loc_1560 = jumpf_floc_loc_1869 + 0; + // GibCursor cursor_ptr_2803[7] = {jumpf_dloc_1868, + // jumpf_floc_loc_1869, + // jumpf_floc_loc_1870, + // jumpf_floc_loc_1871, + // jumpf_floc_loc_1872, + // jumpf_floc_loc_1873, + // jumpf_floc_loc_1874}; + *Res += tmpval_3895; + reduceB(cursor_ptr_2775, lst_36_307_484, Res); + //GibCursor pvrtmp_3907[7]; + + //memcpy(pvrtmp_3907, tmp_struct_63.field0, sizeof(GibCursor [7])); + + //GibCursor pvrtmp_3908[7]; + + //memcpy(pvrtmp_3908, tmp_struct_63.field1, sizeof(GibCursor [7])); + +// GibInt pvrtmp_3909 = tmp_struct_63.field2; +// GibInt tailprim_1882 = tmpval_3895 + pvrtmp_3909; +// GibCursorPtr7GibCursorPtr7GibIntProd return_64; +// +// //memcpy(return_64.field0, pvrtmp_3907, sizeof(GibCursor [7])); +// //memcpy(return_64.field1, pvrtmp_3908, sizeof(GibCursor [7])); +// return_64.field2 = tailprim_1882; +// return return_64; + break; + } + + // case GIB_INDIRECTION_TAG: + // { + // GibCursor soa_field_0_2811 = lst_36_307_484[1]; + // GibCursor soa_field_1_2812 = lst_36_307_484[2]; + // GibCursor soa_field_2_2813 = lst_36_307_484[3]; + // GibCursor soa_field_3_2814 = lst_36_307_484[4]; + // GibCursor soa_field_4_2815 = lst_36_307_484[5]; + // GibCursor soa_field_5_2816 = lst_36_307_484[6]; + // uintptr_t tagged_tmpcur_73 = *(uintptr_t *) *dcon_2778; + // GibCursor tmpcur_3910 = GIB_UNTAG(tagged_tmpcur_73); + // GibCursor tmpaftercur_3911 = *dcon_2778 + 8; + // uint16_t tmptag_3912 = GIB_GET_TAG(tagged_tmpcur_73); + // GibCursor end_from_tagged_dcon_redir_2841 = tmpcur_3910 + + // tmptag_3912; + // GibCursor field_nxt_2834 = soa_field_0_2811 + 1; + // uintptr_t tagged_tmpcur_72 = *(uintptr_t *) field_nxt_2834; + // GibCursor tmpcur_3913 = GIB_UNTAG(tagged_tmpcur_72); + // GibCursor tmpaftercur_3914 = field_nxt_2834 + 8; + // uint16_t tmptag_3915 = GIB_GET_TAG(tagged_tmpcur_72); + // GibCursor end_from_tagged_fld_redir_2842 = tmpcur_3913 + + // tmptag_3915; + // GibCursor field_nxt_2835 = soa_field_1_2812 + 1; + // uintptr_t tagged_tmpcur_71 = *(uintptr_t *) field_nxt_2835; + // GibCursor tmpcur_3916 = GIB_UNTAG(tagged_tmpcur_71); + // GibCursor tmpaftercur_3917 = field_nxt_2835 + 8; + // uint16_t tmptag_3918 = GIB_GET_TAG(tagged_tmpcur_71); + // GibCursor end_from_tagged_fld_redir_2843 = tmpcur_3916 + + // tmptag_3918; + // GibCursor field_nxt_2836 = soa_field_2_2813 + 1; + // uintptr_t tagged_tmpcur_70 = *(uintptr_t *) field_nxt_2836; + // GibCursor tmpcur_3919 = GIB_UNTAG(tagged_tmpcur_70); + // GibCursor tmpaftercur_3920 = field_nxt_2836 + 8; + // uint16_t tmptag_3921 = GIB_GET_TAG(tagged_tmpcur_70); + // GibCursor end_from_tagged_fld_redir_2844 = tmpcur_3919 + + // tmptag_3921; + // GibCursor field_nxt_2837 = soa_field_3_2814 + 1; + // uintptr_t tagged_tmpcur_69 = *(uintptr_t *) field_nxt_2837; + // GibCursor tmpcur_3922 = GIB_UNTAG(tagged_tmpcur_69); + // GibCursor tmpaftercur_3923 = field_nxt_2837 + 8; + // uint16_t tmptag_3924 = GIB_GET_TAG(tagged_tmpcur_69); + // GibCursor end_from_tagged_fld_redir_2845 = tmpcur_3922 + + // tmptag_3924; + // GibCursor field_nxt_2838 = soa_field_4_2815 + 1; + // uintptr_t tagged_tmpcur_68 = *(uintptr_t *) field_nxt_2838; + // GibCursor tmpcur_3925 = GIB_UNTAG(tagged_tmpcur_68); + // GibCursor tmpaftercur_3926 = field_nxt_2838 + 8; + // uint16_t tmptag_3927 = GIB_GET_TAG(tagged_tmpcur_68); + // GibCursor end_from_tagged_fld_redir_2846 = tmpcur_3925 + + // tmptag_3927; + // GibCursor field_nxt_2839 = soa_field_5_2816 + 1; + // uintptr_t tagged_tmpcur_67 = *(uintptr_t *) field_nxt_2839; + // GibCursor tmpcur_3928 = GIB_UNTAG(tagged_tmpcur_67); + // GibCursor tmpaftercur_3929 = field_nxt_2839 + 8; + // uint16_t tmptag_3930 = GIB_GET_TAG(tagged_tmpcur_67); + // GibCursor end_from_tagged_fld_redir_2847 = tmpcur_3928 + + // tmptag_3930; + // GibCursor indr_2056[7] = {tmpcur_3910, tmpcur_3913, tmpcur_3916, + // tmpcur_3919, tmpcur_3922, tmpcur_3925, + // tmpcur_3928}; + // GibCursor loc_1256 = lst_36_307_484[0]; + // GibCursor jump_dloc_2064 = loc_1256 + 9; + // GibCursor loc_IntTy_1262 = lst_36_307_484[6]; + // GibCursor loc_IntTy_1261 = lst_36_307_484[5]; + // GibCursor loc_IntTy_1260 = lst_36_307_484[4]; + // GibCursor loc_IntTy_1259 = lst_36_307_484[3]; + // GibCursor loc_IntTy_1258 = lst_36_307_484[2]; + // GibCursor loc_IntTy_1257 = lst_36_307_484[1]; + // GibCursor aft_indir_loc_2080 = loc_IntTy_1257 + 9; + // GibCursor aft_indir_loc_2081 = loc_IntTy_1258 + 9; + // GibCursor aft_indir_loc_2082 = loc_IntTy_1259 + 9; + // GibCursor aft_indir_loc_2083 = loc_IntTy_1260 + 9; + // GibCursor aft_indir_loc_2084 = loc_IntTy_1261 + 9; + // GibCursor aft_indir_loc_2085 = loc_IntTy_1262 + 9; + // GibCursor cursor_ptr_2848[7] = {jump_dloc_2064, aft_indir_loc_2080, + // aft_indir_loc_2081, + // aft_indir_loc_2082, + // aft_indir_loc_2083, + // aft_indir_loc_2084, + // aft_indir_loc_2085}; + // GibCursorPtr7GibCursorPtr7GibIntProd tmp_struct_65 = + // reduceB(indr_2056, indr_2056); + // GibCursor pvrtmp_3931[7]; + // + // memcpy(pvrtmp_3931, tmp_struct_65.field0, sizeof(GibCursor [7])); + // + // GibCursor pvrtmp_3932[7]; + // + // memcpy(pvrtmp_3932, tmp_struct_65.field1, sizeof(GibCursor [7])); + // + // GibInt pvrtmp_3933 = tmp_struct_65.field2; + // GibCursorPtr7GibCursorPtr7GibIntProd return_66; + // + // memcpy(return_66.field0, cursor_ptr_2775, sizeof(GibCursor [7])); + // memcpy(return_66.field1, cursor_ptr_2848, sizeof(GibCursor [7])); + // return_66.field2 = pvrtmp_3933; + // return return_66; + // break; + // } + + case GIB_REDIRECTION_TAG: + { + GibCursor *soa_field_0_2856 = &lst_36_307_484[1]; + + + uintptr_t tagged_tmpcur_82 = *(uintptr_t *) (*dcon_2778); + GibCursor tmpcur_3934 = GIB_UNTAG(tagged_tmpcur_82); + *dcon_2778 = tmpcur_3934; + + // GibCursor tmpaftercur_3935 = *dcon_2778 + 8; + // uint16_t tmptag_3936 = GIB_GET_TAG(tagged_tmpcur_82); + // GibCursor end_from_tagged_dcon_redir_2877 = tmpcur_3934 + + // tmptag_3936; + + + //GibCursor field_nxt_2871 = soa_field_0_2856 + 1; + *soa_field_0_2856 += 1; + uintptr_t tagged_tmpcur_81 = *(uintptr_t *) (*soa_field_0_2856); + GibCursor tmpcur_3937 = GIB_UNTAG(tagged_tmpcur_81); + *soa_field_0_2856 = tmpcur_3937; + + + // GibCursor tmpaftercur_3938 = field_nxt_2871 + 8; + // uint16_t tmptag_3939 = GIB_GET_TAG(tagged_tmpcur_81); + // GibCursor end_from_tagged_fld_redir_2878 = tmpcur_3937 + + // tmptag_3939; + + + // GibCursor field_nxt_2872 = soa_field_1_2857 + 1; + // uintptr_t tagged_tmpcur_80 = *(uintptr_t *) field_nxt_2872; + // GibCursor tmpcur_3940 = GIB_UNTAG(tagged_tmpcur_80); + // GibCursor tmpaftercur_3941 = field_nxt_2872 + 8; + // uint16_t tmptag_3942 = GIB_GET_TAG(tagged_tmpcur_80); + // GibCursor end_from_tagged_fld_redir_2879 = tmpcur_3940 + + // tmptag_3942; + // GibCursor field_nxt_2873 = soa_field_2_2858 + 1; + // uintptr_t tagged_tmpcur_79 = *(uintptr_t *) field_nxt_2873; + // GibCursor tmpcur_3943 = GIB_UNTAG(tagged_tmpcur_79); + // GibCursor tmpaftercur_3944 = field_nxt_2873 + 8; + // uint16_t tmptag_3945 = GIB_GET_TAG(tagged_tmpcur_79); + // GibCursor end_from_tagged_fld_redir_2880 = tmpcur_3943 + + // tmptag_3945; + // GibCursor field_nxt_2874 = soa_field_3_2859 + 1; + // uintptr_t tagged_tmpcur_78 = *(uintptr_t *) field_nxt_2874; + // GibCursor tmpcur_3946 = GIB_UNTAG(tagged_tmpcur_78); + // GibCursor tmpaftercur_3947 = field_nxt_2874 + 8; + // uint16_t tmptag_3948 = GIB_GET_TAG(tagged_tmpcur_78); + // GibCursor end_from_tagged_fld_redir_2881 = tmpcur_3946 + + // tmptag_3948; + // GibCursor field_nxt_2875 = soa_field_4_2860 + 1; + // uintptr_t tagged_tmpcur_77 = *(uintptr_t *) field_nxt_2875; + // GibCursor tmpcur_3949 = GIB_UNTAG(tagged_tmpcur_77); + // GibCursor tmpaftercur_3950 = field_nxt_2875 + 8; + // uint16_t tmptag_3951 = GIB_GET_TAG(tagged_tmpcur_77); + // GibCursor end_from_tagged_fld_redir_2882 = tmpcur_3949 + + // tmptag_3951; + // GibCursor field_nxt_2876 = soa_field_5_2861 + 1; + // uintptr_t tagged_tmpcur_76 = *(uintptr_t *) field_nxt_2876; + // GibCursor tmpcur_3952 = GIB_UNTAG(tagged_tmpcur_76); + // GibCursor tmpaftercur_3953 = field_nxt_2876 + 8; + // uint16_t tmptag_3954 = GIB_GET_TAG(tagged_tmpcur_76); + // GibCursor end_from_tagged_fld_redir_2883 = tmpcur_3952 + + // tmptag_3954; + + + // GibCursor indr_2056[7] = {tmpcur_3934, tmpcur_3937, soa_field_1_2857, + // soa_field_2_2858, soa_field_3_2859, soa_field_4_2860, + // soa_field_5_2861}; + + reduceB(lst_36_307_484, lst_36_307_484, Res); + //GibCursor pvrtmp_3955[7]; + + //memcpy(pvrtmp_3955, tmp_struct_74.field0, sizeof(GibCursor [7])); + + //GibCursor pvrtmp_3956[7]; + + //memcpy(pvrtmp_3956, tmp_struct_74.field1, sizeof(GibCursor [7])); + + // GibInt pvrtmp_3957 = tmp_struct_74.field2; + // GibCursorPtr7GibCursorPtr7GibIntProd return_75; + + //memcpy(return_75.field0, pvrtmp_3955, sizeof(GibCursor [7])); + //memcpy(return_75.field1, pvrtmp_3956, sizeof(GibCursor [7])); + // return_75.field2 = pvrtmp_3957; + // return return_75; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3893"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_ListA(GibCursor end_r_1273, + GibCursor end_r_1275, + GibCursor loc_1271, + GibCursor arg_88_315_493) +{ + if (loc_1271 + 18 > end_r_1275) { + gib_grow_region(&loc_1271, &end_r_1275); + } + + GibPackedTag tmpval_3959 = *(GibPackedTag *) arg_88_315_493; + GibCursor tmpcur_3960 = arg_88_315_493 + 1; + + + switch_4008: + ; + switch (tmpval_3959) { + + case 0: + { + GibInt tmpval_3961 = *(GibInt *) tmpcur_3960; + GibCursor tmpcur_3962 = tmpcur_3960 + sizeof(GibInt); + GibCursor jump_1883 = tmpcur_3960 + 8; + GibCursor loc_1583 = loc_1271 + 1; + GibCursor loc_1584 = loc_1583 + 8; + + *(GibPackedTag *) loc_1271 = 0; + + GibCursor writetag_2896 = loc_1271 + 1; + GibCursor after_tag_2897 = loc_1271 + 1; + + *(GibInt *) after_tag_2897 = tmpval_3961; + + GibCursor writecur_2901 = after_tag_2897 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_83 = + _copy_ListA(end_r_1273, end_r_1275, loc_1584, tmpcur_3962); + GibCursor pvrtmp_3963 = tmp_struct_83.field0; + GibCursor pvrtmp_3964 = tmp_struct_83.field1; + GibCursor pvrtmp_3965 = tmp_struct_83.field2; + GibCursor pvrtmp_3966 = tmp_struct_83.field3; + GibCursor pvrtmp_3967 = tmp_struct_83.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_84; + + return_84.field0 = pvrtmp_3963; + return_84.field1 = pvrtmp_3964; + return_84.field2 = pvrtmp_3965; + return_84.field3 = loc_1271; + return_84.field4 = pvrtmp_3967; + return return_84; + break; + } + + case 1: + { + GibCursor jump_loc_1886 = arg_88_315_493 + 1; + + *(GibPackedTag *) loc_1271 = 1; + + GibCursor writetag_2906 = loc_1271 + 1; + GibCursor after_tag_2907 = loc_1271 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_85; + + return_85.field0 = end_r_1273; + return_85.field1 = end_r_1275; + return_85.field2 = jump_loc_1886; + return_85.field3 = loc_1271; + return_85.field4 = after_tag_2907; + return return_85; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_88 = *(uintptr_t *) tmpcur_3960; + GibCursor tmpcur_3980 = GIB_UNTAG(tagged_tmpcur_88); + GibCursor tmpaftercur_3981 = tmpcur_3960 + 8; + uint16_t tmptag_3982 = GIB_GET_TAG(tagged_tmpcur_88); + GibCursor end_from_tagged_indr_2086 = tmpcur_3980 + tmptag_3982; + GibCursor jump_loc_2088 = tmpcur_3960 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_86 = + _copy_ListA(tmpcur_3980, end_r_1275, loc_1271, tmpcur_3980); + GibCursor pvrtmp_3983 = tmp_struct_86.field0; + GibCursor pvrtmp_3984 = tmp_struct_86.field1; + GibCursor pvrtmp_3985 = tmp_struct_86.field2; + GibCursor pvrtmp_3986 = tmp_struct_86.field3; + GibCursor pvrtmp_3987 = tmp_struct_86.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_87; + + return_87.field0 = end_r_1273; + return_87.field1 = pvrtmp_3984; + return_87.field2 = jump_loc_2088; + return_87.field3 = pvrtmp_3986; + return_87.field4 = pvrtmp_3987; + return return_87; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_91 = *(uintptr_t *) tmpcur_3960; + GibCursor tmpcur_3994 = GIB_UNTAG(tagged_tmpcur_91); + GibCursor tmpaftercur_3995 = tmpcur_3960 + 8; + uint16_t tmptag_3996 = GIB_GET_TAG(tagged_tmpcur_91); + GibCursor end_from_tagged_indr_2086 = tmpcur_3994 + tmptag_3996; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_89 = + _copy_ListA(tmpcur_3994, end_r_1275, loc_1271, tmpcur_3994); + GibCursor pvrtmp_3997 = tmp_struct_89.field0; + GibCursor pvrtmp_3998 = tmp_struct_89.field1; + GibCursor pvrtmp_3999 = tmp_struct_89.field2; + GibCursor pvrtmp_4000 = tmp_struct_89.field3; + GibCursor pvrtmp_4001 = tmp_struct_89.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_90; + + return_90.field0 = pvrtmp_3997; + return_90.field1 = pvrtmp_3998; + return_90.field2 = pvrtmp_3999; + return_90.field3 = pvrtmp_4000; + return_90.field4 = pvrtmp_4001; + return return_90; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3959"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod _copy_ListB(GibCursor cursor_ptr_2925[7], + GibCursor cursor_ptr_2924[7], + GibCursor cursor_ptr_2926[7], + GibCursor arg_176_330_498[7]) +{ + GibCursor end_r_1298 = cursor_ptr_2924[1]; + GibCursor end_r_1302 = cursor_ptr_2924[5]; + GibCursor end_r_1297 = cursor_ptr_2924[0]; + GibCursor end_r_1301 = cursor_ptr_2924[4]; + GibCursor end_r_1303 = cursor_ptr_2924[6]; + GibCursor end_r_1300 = cursor_ptr_2924[3]; + GibCursor end_r_1299 = cursor_ptr_2924[2]; + GibCursor loc_IntTy_1288 = cursor_ptr_2926[5]; + GibCursor loc_IntTy_1285 = cursor_ptr_2926[2]; + GibCursor loc_IntTy_1289 = cursor_ptr_2926[6]; + GibCursor loc_1283 = cursor_ptr_2926[0]; + GibCursor loc_IntTy_1286 = cursor_ptr_2926[3]; + GibCursor loc_IntTy_1284 = cursor_ptr_2926[1]; + GibCursor loc_IntTy_1287 = cursor_ptr_2926[4]; + + if (loc_IntTy_1289 + 17 > end_r_1303 || (loc_IntTy_1288 + 17 > end_r_1302 || + (loc_IntTy_1287 + 17 > + end_r_1301 || (loc_IntTy_1286 + + 17 > end_r_1300 || + (loc_IntTy_1285 + + 17 > end_r_1299 || + (loc_IntTy_1284 + + 17 > + end_r_1298 || + loc_1283 + 66 > + end_r_1297)))))) { + gib_grow_region(&loc_IntTy_1289, &end_r_1303); + gib_grow_region(&loc_IntTy_1288, &end_r_1302); + gib_grow_region(&loc_IntTy_1287, &end_r_1301); + gib_grow_region(&loc_IntTy_1286, &end_r_1300); + gib_grow_region(&loc_IntTy_1285, &end_r_1299); + gib_grow_region(&loc_IntTy_1284, &end_r_1298); + gib_grow_region(&loc_1283, &end_r_1297); + } + + GibCursor end_r_1290 = cursor_ptr_2925[0]; + GibCursor end_r_1291 = cursor_ptr_2925[1]; + GibCursor end_r_1292 = cursor_ptr_2925[2]; + GibCursor end_r_1293 = cursor_ptr_2925[3]; + GibCursor end_r_1294 = cursor_ptr_2925[4]; + GibCursor end_r_1295 = cursor_ptr_2925[5]; + GibCursor end_r_1296 = cursor_ptr_2925[6]; + GibCursor overwrite_reg_2927[7] = {end_r_1297, end_r_1298, end_r_1299, + end_r_1300, end_r_1301, end_r_1302, + end_r_1303}; + GibCursor dcon_2930 = arg_176_330_498[0]; + GibPackedTag tmpval_4009 = *(GibPackedTag *) dcon_2930; + GibCursor tmpcur_4010 = dcon_2930 + 1; + + + switch_4104: + ; + switch (tmpval_4009) { + + case 0: + { + GibCursor soa_field_0_2932 = arg_176_330_498[1]; + GibCursor soa_field_1_2933 = arg_176_330_498[2]; + GibCursor soa_field_2_2934 = arg_176_330_498[3]; + GibCursor soa_field_3_2935 = arg_176_330_498[4]; + GibCursor soa_field_4_2936 = arg_176_330_498[5]; + GibCursor soa_field_5_2937 = arg_176_330_498[6]; + GibInt tmpval_4011 = *(GibInt *) soa_field_0_2932; + GibCursor tmpcur_4012 = soa_field_0_2932 + sizeof(GibInt); + GibInt tmpval_4013 = *(GibInt *) soa_field_1_2933; + GibCursor tmpcur_4014 = soa_field_1_2933 + sizeof(GibInt); + GibInt tmpval_4015 = *(GibInt *) soa_field_2_2934; + GibCursor tmpcur_4016 = soa_field_2_2934 + sizeof(GibInt); + GibInt tmpval_4017 = *(GibInt *) soa_field_3_2935; + GibCursor tmpcur_4018 = soa_field_3_2935 + sizeof(GibInt); + GibInt tmpval_4019 = *(GibInt *) soa_field_4_2936; + GibCursor tmpcur_4020 = soa_field_4_2936 + sizeof(GibInt); + GibInt tmpval_4021 = *(GibInt *) soa_field_5_2937; + GibCursor tmpcur_4022 = soa_field_5_2937 + sizeof(GibInt); + GibCursor cursor_ptr_2929[7] = {tmpcur_4010, tmpcur_4012, + tmpcur_4014, tmpcur_4016, + tmpcur_4018, tmpcur_4020, + tmpcur_4022}; + GibCursor loc_1276 = arg_176_330_498[0]; + GibCursor jumpf_dloc_1888 = loc_1276 + 1; + GibCursor loc_IntTy_1277 = arg_176_330_498[1]; + GibCursor loc_IntTy_1278 = arg_176_330_498[2]; + GibCursor loc_IntTy_1279 = arg_176_330_498[3]; + GibCursor loc_IntTy_1280 = arg_176_330_498[4]; + GibCursor loc_IntTy_1281 = arg_176_330_498[5]; + GibCursor loc_IntTy_1282 = arg_176_330_498[6]; + GibCursor jumpf_floc_loc_1889 = soa_field_0_2932 + 8; + GibCursor jumpf_floc_loc_1890 = soa_field_1_2933 + 8; + GibCursor jumpf_floc_loc_1891 = soa_field_2_2934 + 8; + GibCursor jumpf_floc_loc_1892 = soa_field_3_2935 + 8; + GibCursor jumpf_floc_loc_1893 = soa_field_4_2936 + 8; + GibCursor jumpf_floc_loc_1894 = soa_field_5_2937 + 8; + GibCursor loc_1603 = jumpf_dloc_1888 + 0; + GibCursor loc_1602 = jumpf_floc_loc_1889 + 0; + GibCursor cursor_ptr_2946[7] = {jumpf_dloc_1888, + jumpf_floc_loc_1889, + jumpf_floc_loc_1890, + jumpf_floc_loc_1891, + jumpf_floc_loc_1892, + jumpf_floc_loc_1893, + jumpf_floc_loc_1894}; + GibCursor new_floc_loc_1632 = loc_IntTy_1284 + 8; + GibCursor new_floc_loc_1635 = loc_IntTy_1287 + 8; + GibCursor new_floc_loc_1634 = loc_IntTy_1286 + 8; + GibCursor new_dloc_1631 = loc_1283 + 1; + GibCursor new_floc_loc_1637 = loc_IntTy_1289 + 8; + GibCursor new_floc_loc_1633 = loc_IntTy_1285 + 8; + GibCursor new_floc_loc_1636 = loc_IntTy_1288 + 8; + GibCursor cursor_ptr_2947[7] = {new_dloc_1631, new_floc_loc_1632, + new_floc_loc_1633, + new_floc_loc_1634, + new_floc_loc_1635, + new_floc_loc_1636, + new_floc_loc_1637}; + + *(GibPackedTag *) loc_1283 = 0; + + GibCursor writetag_2957 = loc_1283 + 1; + GibCursor after_tag_2958 = loc_1283 + 1; + + *(GibInt *) loc_IntTy_1284 = tmpval_4011; + + GibCursor writecur_2962 = loc_IntTy_1284 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1285 = tmpval_4013; + + GibCursor writecur_2964 = loc_IntTy_1285 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1286 = tmpval_4015; + + GibCursor writecur_2966 = loc_IntTy_1286 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1287 = tmpval_4017; + + GibCursor writecur_2968 = loc_IntTy_1287 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1288 = tmpval_4019; + + GibCursor writecur_2970 = loc_IntTy_1288 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1289 = tmpval_4021; + + GibCursor writecur_2972 = loc_IntTy_1289 + sizeof(GibInt); + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_95 = + _copy_ListB(cursor_ptr_2925, overwrite_reg_2927, cursor_ptr_2947, cursor_ptr_2929); + GibCursor pvrtmp_4023[7]; + + memcpy(pvrtmp_4023, tmp_struct_95.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4024[7]; + + memcpy(pvrtmp_4024, tmp_struct_95.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4025[7]; + + memcpy(pvrtmp_4025, tmp_struct_95.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4026[7]; + + memcpy(pvrtmp_4026, tmp_struct_95.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4027[7]; + + memcpy(pvrtmp_4027, tmp_struct_95.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_96; + + memcpy(return_96.field0, pvrtmp_4023, sizeof(GibCursor [7])); + memcpy(return_96.field1, pvrtmp_4024, sizeof(GibCursor [7])); + memcpy(return_96.field2, pvrtmp_4025, sizeof(GibCursor [7])); + memcpy(return_96.field3, cursor_ptr_2926, sizeof(GibCursor [7])); + memcpy(return_96.field4, pvrtmp_4027, sizeof(GibCursor [7])); + return return_96; + break; + } + + case 1: + { + GibCursor soa_field_0_2978 = arg_176_330_498[1]; + GibCursor soa_field_1_2979 = arg_176_330_498[2]; + GibCursor soa_field_2_2980 = arg_176_330_498[3]; + GibCursor soa_field_3_2981 = arg_176_330_498[4]; + GibCursor soa_field_4_2982 = arg_176_330_498[5]; + GibCursor soa_field_5_2983 = arg_176_330_498[6]; + GibCursor loc_1276 = arg_176_330_498[0]; + GibCursor jump_dloc_1903 = loc_1276 + 1; + GibCursor loc_IntTy_1277 = arg_176_330_498[1]; + GibCursor jump_floc_loc_1904 = loc_IntTy_1277 + 0; + GibCursor loc_IntTy_1278 = arg_176_330_498[2]; + GibCursor jump_floc_loc_1905 = loc_IntTy_1278 + 0; + GibCursor loc_IntTy_1279 = arg_176_330_498[3]; + GibCursor jump_floc_loc_1906 = loc_IntTy_1279 + 0; + GibCursor loc_IntTy_1280 = arg_176_330_498[4]; + GibCursor jump_floc_loc_1907 = loc_IntTy_1280 + 0; + GibCursor loc_IntTy_1281 = arg_176_330_498[5]; + GibCursor jump_floc_loc_1908 = loc_IntTy_1281 + 0; + GibCursor loc_IntTy_1282 = arg_176_330_498[6]; + GibCursor jump_floc_loc_1909 = loc_IntTy_1282 + 0; + GibCursor cursor_ptr_2985[7] = {jump_dloc_1903, jump_floc_loc_1904, + jump_floc_loc_1905, + jump_floc_loc_1906, + jump_floc_loc_1907, + jump_floc_loc_1908, + jump_floc_loc_1909}; + GibCursor new_floc_loc_1632 = loc_IntTy_1284 + 8; + GibCursor new_floc_loc_1635 = loc_IntTy_1287 + 8; + GibCursor new_floc_loc_1634 = loc_IntTy_1286 + 8; + GibCursor new_dloc_1631 = loc_1283 + 1; + GibCursor new_floc_loc_1637 = loc_IntTy_1289 + 8; + GibCursor new_floc_loc_1633 = loc_IntTy_1285 + 8; + GibCursor new_floc_loc_1636 = loc_IntTy_1288 + 8; + + *(GibPackedTag *) loc_1283 = 1; + + GibCursor writetag_2986 = loc_1283 + 1; + GibCursor after_tag_2987 = loc_1283 + 1; + GibCursor aft_soa_loc_2991[7] = {after_tag_2987, loc_IntTy_1284, + loc_IntTy_1285, loc_IntTy_1286, + loc_IntTy_1287, loc_IntTy_1288, + loc_IntTy_1289}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_97; + + memcpy(return_97.field0, cursor_ptr_2925, sizeof(GibCursor [7])); + memcpy(return_97.field1, overwrite_reg_2927, sizeof(GibCursor [7])); + memcpy(return_97.field2, cursor_ptr_2985, sizeof(GibCursor [7])); + memcpy(return_97.field3, cursor_ptr_2926, sizeof(GibCursor [7])); + memcpy(return_97.field4, aft_soa_loc_2991, sizeof(GibCursor [7])); + return return_97; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_2995 = arg_176_330_498[1]; + GibCursor soa_field_1_2996 = arg_176_330_498[2]; + GibCursor soa_field_2_2997 = arg_176_330_498[3]; + GibCursor soa_field_3_2998 = arg_176_330_498[4]; + GibCursor soa_field_4_2999 = arg_176_330_498[5]; + GibCursor soa_field_5_3000 = arg_176_330_498[6]; + uintptr_t tagged_tmpcur_106 = *(uintptr_t *) tmpcur_4010; + GibCursor tmpcur_4040 = GIB_UNTAG(tagged_tmpcur_106); + GibCursor tmpaftercur_4041 = tmpcur_4010 + 8; + uint16_t tmptag_4042 = GIB_GET_TAG(tagged_tmpcur_106); + GibCursor end_from_tagged_dcon_redir_3025 = tmpcur_4040 + + tmptag_4042; + GibCursor field_nxt_3018 = soa_field_0_2995 + 1; + uintptr_t tagged_tmpcur_105 = *(uintptr_t *) field_nxt_3018; + GibCursor tmpcur_4043 = GIB_UNTAG(tagged_tmpcur_105); + GibCursor tmpaftercur_4044 = field_nxt_3018 + 8; + uint16_t tmptag_4045 = GIB_GET_TAG(tagged_tmpcur_105); + GibCursor end_from_tagged_fld_redir_3026 = tmpcur_4043 + + tmptag_4045; + GibCursor field_nxt_3019 = soa_field_1_2996 + 1; + uintptr_t tagged_tmpcur_104 = *(uintptr_t *) field_nxt_3019; + GibCursor tmpcur_4046 = GIB_UNTAG(tagged_tmpcur_104); + GibCursor tmpaftercur_4047 = field_nxt_3019 + 8; + uint16_t tmptag_4048 = GIB_GET_TAG(tagged_tmpcur_104); + GibCursor end_from_tagged_fld_redir_3027 = tmpcur_4046 + + tmptag_4048; + GibCursor field_nxt_3020 = soa_field_2_2997 + 1; + uintptr_t tagged_tmpcur_103 = *(uintptr_t *) field_nxt_3020; + GibCursor tmpcur_4049 = GIB_UNTAG(tagged_tmpcur_103); + GibCursor tmpaftercur_4050 = field_nxt_3020 + 8; + uint16_t tmptag_4051 = GIB_GET_TAG(tagged_tmpcur_103); + GibCursor end_from_tagged_fld_redir_3028 = tmpcur_4049 + + tmptag_4051; + GibCursor field_nxt_3021 = soa_field_3_2998 + 1; + uintptr_t tagged_tmpcur_102 = *(uintptr_t *) field_nxt_3021; + GibCursor tmpcur_4052 = GIB_UNTAG(tagged_tmpcur_102); + GibCursor tmpaftercur_4053 = field_nxt_3021 + 8; + uint16_t tmptag_4054 = GIB_GET_TAG(tagged_tmpcur_102); + GibCursor end_from_tagged_fld_redir_3029 = tmpcur_4052 + + tmptag_4054; + GibCursor field_nxt_3022 = soa_field_4_2999 + 1; + uintptr_t tagged_tmpcur_101 = *(uintptr_t *) field_nxt_3022; + GibCursor tmpcur_4055 = GIB_UNTAG(tagged_tmpcur_101); + GibCursor tmpaftercur_4056 = field_nxt_3022 + 8; + uint16_t tmptag_4057 = GIB_GET_TAG(tagged_tmpcur_101); + GibCursor end_from_tagged_fld_redir_3030 = tmpcur_4055 + + tmptag_4057; + GibCursor field_nxt_3023 = soa_field_5_3000 + 1; + uintptr_t tagged_tmpcur_100 = *(uintptr_t *) field_nxt_3023; + GibCursor tmpcur_4058 = GIB_UNTAG(tagged_tmpcur_100); + GibCursor tmpaftercur_4059 = field_nxt_3023 + 8; + uint16_t tmptag_4060 = GIB_GET_TAG(tagged_tmpcur_100); + GibCursor end_from_tagged_fld_redir_3031 = tmpcur_4058 + + tmptag_4060; + GibCursor indr_2092[7] = {tmpcur_4040, tmpcur_4043, tmpcur_4046, + tmpcur_4049, tmpcur_4052, tmpcur_4055, + tmpcur_4058}; + GibCursor loc_1276 = arg_176_330_498[0]; + GibCursor jump_dloc_2100 = loc_1276 + 9; + GibCursor loc_IntTy_1282 = arg_176_330_498[6]; + GibCursor loc_IntTy_1281 = arg_176_330_498[5]; + GibCursor loc_IntTy_1280 = arg_176_330_498[4]; + GibCursor loc_IntTy_1279 = arg_176_330_498[3]; + GibCursor loc_IntTy_1278 = arg_176_330_498[2]; + GibCursor loc_IntTy_1277 = arg_176_330_498[1]; + GibCursor aft_indir_loc_2116 = loc_IntTy_1277 + 9; + GibCursor aft_indir_loc_2117 = loc_IntTy_1278 + 9; + GibCursor aft_indir_loc_2118 = loc_IntTy_1279 + 9; + GibCursor aft_indir_loc_2119 = loc_IntTy_1280 + 9; + GibCursor aft_indir_loc_2120 = loc_IntTy_1281 + 9; + GibCursor aft_indir_loc_2121 = loc_IntTy_1282 + 9; + GibCursor cursor_ptr_3032[7] = {jump_dloc_2100, aft_indir_loc_2116, + aft_indir_loc_2117, + aft_indir_loc_2118, + aft_indir_loc_2119, + aft_indir_loc_2120, + aft_indir_loc_2121}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_98 = + _copy_ListB(indr_2092, overwrite_reg_2927, cursor_ptr_2926, indr_2092); + GibCursor pvrtmp_4061[7]; + + memcpy(pvrtmp_4061, tmp_struct_98.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4062[7]; + + memcpy(pvrtmp_4062, tmp_struct_98.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4063[7]; + + memcpy(pvrtmp_4063, tmp_struct_98.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4064[7]; + + memcpy(pvrtmp_4064, tmp_struct_98.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4065[7]; + + memcpy(pvrtmp_4065, tmp_struct_98.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_99; + + memcpy(return_99.field0, cursor_ptr_2925, sizeof(GibCursor [7])); + memcpy(return_99.field1, pvrtmp_4062, sizeof(GibCursor [7])); + memcpy(return_99.field2, cursor_ptr_3032, sizeof(GibCursor [7])); + memcpy(return_99.field3, pvrtmp_4064, sizeof(GibCursor [7])); + memcpy(return_99.field4, pvrtmp_4065, sizeof(GibCursor [7])); + return return_99; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_3043 = arg_176_330_498[1]; + GibCursor soa_field_1_3044 = arg_176_330_498[2]; + GibCursor soa_field_2_3045 = arg_176_330_498[3]; + GibCursor soa_field_3_3046 = arg_176_330_498[4]; + GibCursor soa_field_4_3047 = arg_176_330_498[5]; + GibCursor soa_field_5_3048 = arg_176_330_498[6]; + uintptr_t tagged_tmpcur_115 = *(uintptr_t *) tmpcur_4010; + GibCursor tmpcur_4072 = GIB_UNTAG(tagged_tmpcur_115); + GibCursor tmpaftercur_4073 = tmpcur_4010 + 8; + uint16_t tmptag_4074 = GIB_GET_TAG(tagged_tmpcur_115); + GibCursor end_from_tagged_dcon_redir_3064 = tmpcur_4072 + + tmptag_4074; + GibCursor field_nxt_3058 = soa_field_0_3043 + 1; + uintptr_t tagged_tmpcur_114 = *(uintptr_t *) field_nxt_3058; + GibCursor tmpcur_4075 = GIB_UNTAG(tagged_tmpcur_114); + GibCursor tmpaftercur_4076 = field_nxt_3058 + 8; + uint16_t tmptag_4077 = GIB_GET_TAG(tagged_tmpcur_114); + GibCursor end_from_tagged_fld_redir_3065 = tmpcur_4075 + + tmptag_4077; + GibCursor field_nxt_3059 = soa_field_1_3044 + 1; + uintptr_t tagged_tmpcur_113 = *(uintptr_t *) field_nxt_3059; + GibCursor tmpcur_4078 = GIB_UNTAG(tagged_tmpcur_113); + GibCursor tmpaftercur_4079 = field_nxt_3059 + 8; + uint16_t tmptag_4080 = GIB_GET_TAG(tagged_tmpcur_113); + GibCursor end_from_tagged_fld_redir_3066 = tmpcur_4078 + + tmptag_4080; + GibCursor field_nxt_3060 = soa_field_2_3045 + 1; + uintptr_t tagged_tmpcur_112 = *(uintptr_t *) field_nxt_3060; + GibCursor tmpcur_4081 = GIB_UNTAG(tagged_tmpcur_112); + GibCursor tmpaftercur_4082 = field_nxt_3060 + 8; + uint16_t tmptag_4083 = GIB_GET_TAG(tagged_tmpcur_112); + GibCursor end_from_tagged_fld_redir_3067 = tmpcur_4081 + + tmptag_4083; + GibCursor field_nxt_3061 = soa_field_3_3046 + 1; + uintptr_t tagged_tmpcur_111 = *(uintptr_t *) field_nxt_3061; + GibCursor tmpcur_4084 = GIB_UNTAG(tagged_tmpcur_111); + GibCursor tmpaftercur_4085 = field_nxt_3061 + 8; + uint16_t tmptag_4086 = GIB_GET_TAG(tagged_tmpcur_111); + GibCursor end_from_tagged_fld_redir_3068 = tmpcur_4084 + + tmptag_4086; + GibCursor field_nxt_3062 = soa_field_4_3047 + 1; + uintptr_t tagged_tmpcur_110 = *(uintptr_t *) field_nxt_3062; + GibCursor tmpcur_4087 = GIB_UNTAG(tagged_tmpcur_110); + GibCursor tmpaftercur_4088 = field_nxt_3062 + 8; + uint16_t tmptag_4089 = GIB_GET_TAG(tagged_tmpcur_110); + GibCursor end_from_tagged_fld_redir_3069 = tmpcur_4087 + + tmptag_4089; + GibCursor field_nxt_3063 = soa_field_5_3048 + 1; + uintptr_t tagged_tmpcur_109 = *(uintptr_t *) field_nxt_3063; + GibCursor tmpcur_4090 = GIB_UNTAG(tagged_tmpcur_109); + GibCursor tmpaftercur_4091 = field_nxt_3063 + 8; + uint16_t tmptag_4092 = GIB_GET_TAG(tagged_tmpcur_109); + GibCursor end_from_tagged_fld_redir_3070 = tmpcur_4090 + + tmptag_4092; + GibCursor indr_2092[7] = {tmpcur_4072, tmpcur_4075, tmpcur_4078, + tmpcur_4081, tmpcur_4084, tmpcur_4087, + tmpcur_4090}; + GibCursor copy_dloc_2122 = loc_1283 + 0; + GibCursor copy_floc_loc_2128 = loc_IntTy_1289 + 0; + GibCursor copy_floc_loc_2127 = loc_IntTy_1288 + 0; + GibCursor copy_floc_loc_2126 = loc_IntTy_1287 + 0; + GibCursor copy_floc_loc_2125 = loc_IntTy_1286 + 0; + GibCursor copy_floc_loc_2124 = loc_IntTy_1285 + 0; + GibCursor copy_floc_loc_2123 = loc_IntTy_1284 + 0; + GibCursor cursor_ptr_3071[7] = {copy_dloc_2122, copy_floc_loc_2123, + copy_floc_loc_2124, + copy_floc_loc_2125, + copy_floc_loc_2126, + copy_floc_loc_2127, + copy_floc_loc_2128}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_107 = + _copy_ListB(indr_2092, overwrite_reg_2927, cursor_ptr_3071, indr_2092); + GibCursor pvrtmp_4093[7]; + + memcpy(pvrtmp_4093, tmp_struct_107.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4094[7]; + + memcpy(pvrtmp_4094, tmp_struct_107.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4095[7]; + + memcpy(pvrtmp_4095, tmp_struct_107.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4096[7]; + + memcpy(pvrtmp_4096, tmp_struct_107.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4097[7]; + + memcpy(pvrtmp_4097, tmp_struct_107.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_108; + + memcpy(return_108.field0, pvrtmp_4093, sizeof(GibCursor [7])); + memcpy(return_108.field1, pvrtmp_4094, sizeof(GibCursor [7])); + memcpy(return_108.field2, pvrtmp_4095, sizeof(GibCursor [7])); + memcpy(return_108.field3, pvrtmp_4096, sizeof(GibCursor [7])); + memcpy(return_108.field4, pvrtmp_4097, sizeof(GibCursor [7])); + return return_108; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4009"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_List(GibCursor end_r_1307, + GibCursor end_r_1309, + GibCursor loc_1305, + GibCursor arg_114_345_513) +{ + if (loc_1305 + 42 > end_r_1309) { + gib_grow_region(&loc_1305, &end_r_1309); + } + + GibPackedTag tmpval_4105 = *(GibPackedTag *) arg_114_345_513; + GibCursor tmpcur_4106 = arg_114_345_513 + 1; + + + switch_4169: + ; + switch (tmpval_4105) { + + case 0: + { + GibInt tmpval_4107 = *(GibInt *) tmpcur_4106; + GibCursor tmpcur_4108 = tmpcur_4106 + sizeof(GibInt); + GibInt tmpval_4109 = *(GibInt *) tmpcur_4108; + GibCursor tmpcur_4110 = tmpcur_4108 + sizeof(GibInt); + GibInt tmpval_4111 = *(GibInt *) tmpcur_4110; + GibCursor tmpcur_4112 = tmpcur_4110 + sizeof(GibInt); + GibInt tmpval_4113 = *(GibInt *) tmpcur_4112; + GibCursor tmpcur_4114 = tmpcur_4112 + sizeof(GibInt); + GibCursor jump_1914 = tmpcur_4112 + 8; + GibCursor jump_1913 = tmpcur_4110 + 8; + GibCursor jump_1912 = tmpcur_4108 + 8; + GibCursor jump_1911 = tmpcur_4106 + 8; + GibCursor loc_1678 = loc_1305 + 1; + GibCursor loc_1679 = loc_1678 + 8; + GibCursor loc_1680 = loc_1679 + 8; + GibCursor loc_1681 = loc_1680 + 8; + GibCursor loc_1682 = loc_1681 + 8; + + *(GibPackedTag *) loc_1305 = 0; + + GibCursor writetag_3093 = loc_1305 + 1; + GibCursor after_tag_3094 = loc_1305 + 1; + + *(GibInt *) after_tag_3094 = tmpval_4107; + + GibCursor writecur_3098 = after_tag_3094 + sizeof(GibInt); + + *(GibInt *) writecur_3098 = tmpval_4109; + + GibCursor writecur_3099 = writecur_3098 + sizeof(GibInt); + + *(GibInt *) writecur_3099 = tmpval_4111; + + GibCursor writecur_3100 = writecur_3099 + sizeof(GibInt); + + *(GibInt *) writecur_3100 = tmpval_4113; + + GibCursor writecur_3101 = writecur_3100 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_116 = + _copy_ListA(end_r_1307, end_r_1309, loc_1682, tmpcur_4114); + GibCursor pvrtmp_4115 = tmp_struct_116.field0; + GibCursor pvrtmp_4116 = tmp_struct_116.field1; + GibCursor pvrtmp_4117 = tmp_struct_116.field2; + GibCursor pvrtmp_4118 = tmp_struct_116.field3; + GibCursor pvrtmp_4119 = tmp_struct_116.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_117 = + _copy_List(pvrtmp_4115, pvrtmp_4116, pvrtmp_4119, pvrtmp_4117); + GibCursor pvrtmp_4124 = tmp_struct_117.field0; + GibCursor pvrtmp_4125 = tmp_struct_117.field1; + GibCursor pvrtmp_4126 = tmp_struct_117.field2; + GibCursor pvrtmp_4127 = tmp_struct_117.field3; + GibCursor pvrtmp_4128 = tmp_struct_117.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_118; + + return_118.field0 = pvrtmp_4124; + return_118.field1 = pvrtmp_4125; + return_118.field2 = pvrtmp_4126; + return_118.field3 = loc_1305; + return_118.field4 = pvrtmp_4128; + return return_118; + break; + } + + case 1: + { + GibCursor jump_loc_1918 = arg_114_345_513 + 1; + + *(GibPackedTag *) loc_1305 = 1; + + GibCursor writetag_3108 = loc_1305 + 1; + GibCursor after_tag_3109 = loc_1305 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_119; + + return_119.field0 = end_r_1307; + return_119.field1 = end_r_1309; + return_119.field2 = jump_loc_1918; + return_119.field3 = loc_1305; + return_119.field4 = after_tag_3109; + return return_119; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_122 = *(uintptr_t *) tmpcur_4106; + GibCursor tmpcur_4141 = GIB_UNTAG(tagged_tmpcur_122); + GibCursor tmpaftercur_4142 = tmpcur_4106 + 8; + uint16_t tmptag_4143 = GIB_GET_TAG(tagged_tmpcur_122); + GibCursor end_from_tagged_indr_2129 = tmpcur_4141 + tmptag_4143; + GibCursor jump_loc_2131 = tmpcur_4106 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_120 = + _copy_List(tmpcur_4141, end_r_1309, loc_1305, tmpcur_4141); + GibCursor pvrtmp_4144 = tmp_struct_120.field0; + GibCursor pvrtmp_4145 = tmp_struct_120.field1; + GibCursor pvrtmp_4146 = tmp_struct_120.field2; + GibCursor pvrtmp_4147 = tmp_struct_120.field3; + GibCursor pvrtmp_4148 = tmp_struct_120.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_121; + + return_121.field0 = end_r_1307; + return_121.field1 = pvrtmp_4145; + return_121.field2 = jump_loc_2131; + return_121.field3 = pvrtmp_4147; + return_121.field4 = pvrtmp_4148; + return return_121; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_125 = *(uintptr_t *) tmpcur_4106; + GibCursor tmpcur_4155 = GIB_UNTAG(tagged_tmpcur_125); + GibCursor tmpaftercur_4156 = tmpcur_4106 + 8; + uint16_t tmptag_4157 = GIB_GET_TAG(tagged_tmpcur_125); + GibCursor end_from_tagged_indr_2129 = tmpcur_4155 + tmptag_4157; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_123 = + _copy_List(tmpcur_4155, end_r_1309, loc_1305, tmpcur_4155); + GibCursor pvrtmp_4158 = tmp_struct_123.field0; + GibCursor pvrtmp_4159 = tmp_struct_123.field1; + GibCursor pvrtmp_4160 = tmp_struct_123.field2; + GibCursor pvrtmp_4161 = tmp_struct_123.field3; + GibCursor pvrtmp_4162 = tmp_struct_123.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_124; + + return_124.field0 = pvrtmp_4158; + return_124.field1 = pvrtmp_4159; + return_124.field2 = pvrtmp_4160; + return_124.field3 = pvrtmp_4161; + return_124.field4 = pvrtmp_4162; + return return_124; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4105"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7Prod _traverse_ListB(GibCursor cursor_ptr_3126[7], + GibCursor arg_206_358_526[7]) +{ + GibCursor end_r_1317 = cursor_ptr_3126[0]; + GibCursor end_r_1318 = cursor_ptr_3126[1]; + GibCursor end_r_1319 = cursor_ptr_3126[2]; + GibCursor end_r_1320 = cursor_ptr_3126[3]; + GibCursor end_r_1321 = cursor_ptr_3126[4]; + GibCursor end_r_1322 = cursor_ptr_3126[5]; + GibCursor end_r_1323 = cursor_ptr_3126[6]; + GibCursor dcon_3129 = arg_206_358_526[0]; + GibPackedTag tmpval_4170 = *(GibPackedTag *) dcon_3129; + GibCursor tmpcur_4171 = dcon_3129 + 1; + + + switch_4232: + ; + switch (tmpval_4170) { + + case 0: + { + GibCursor soa_field_0_3131 = arg_206_358_526[1]; + GibCursor soa_field_1_3132 = arg_206_358_526[2]; + GibCursor soa_field_2_3133 = arg_206_358_526[3]; + GibCursor soa_field_3_3134 = arg_206_358_526[4]; + GibCursor soa_field_4_3135 = arg_206_358_526[5]; + GibCursor soa_field_5_3136 = arg_206_358_526[6]; + GibInt tmpval_4172 = *(GibInt *) soa_field_0_3131; + GibCursor tmpcur_4173 = soa_field_0_3131 + sizeof(GibInt); + GibInt tmpval_4174 = *(GibInt *) soa_field_1_3132; + GibCursor tmpcur_4175 = soa_field_1_3132 + sizeof(GibInt); + GibInt tmpval_4176 = *(GibInt *) soa_field_2_3133; + GibCursor tmpcur_4177 = soa_field_2_3133 + sizeof(GibInt); + GibInt tmpval_4178 = *(GibInt *) soa_field_3_3134; + GibCursor tmpcur_4179 = soa_field_3_3134 + sizeof(GibInt); + GibInt tmpval_4180 = *(GibInt *) soa_field_4_3135; + GibCursor tmpcur_4181 = soa_field_4_3135 + sizeof(GibInt); + GibInt tmpval_4182 = *(GibInt *) soa_field_5_3136; + GibCursor tmpcur_4183 = soa_field_5_3136 + sizeof(GibInt); + GibCursor cursor_ptr_3128[7] = {tmpcur_4171, tmpcur_4173, + tmpcur_4175, tmpcur_4177, + tmpcur_4179, tmpcur_4181, + tmpcur_4183}; + GibCursor loc_1310 = arg_206_358_526[0]; + GibCursor jumpf_dloc_1920 = loc_1310 + 1; + GibCursor loc_IntTy_1311 = arg_206_358_526[1]; + GibCursor loc_IntTy_1312 = arg_206_358_526[2]; + GibCursor loc_IntTy_1313 = arg_206_358_526[3]; + GibCursor loc_IntTy_1314 = arg_206_358_526[4]; + GibCursor loc_IntTy_1315 = arg_206_358_526[5]; + GibCursor loc_IntTy_1316 = arg_206_358_526[6]; + GibCursor jumpf_floc_loc_1921 = soa_field_0_3131 + 8; + GibCursor jumpf_floc_loc_1922 = soa_field_1_3132 + 8; + GibCursor jumpf_floc_loc_1923 = soa_field_2_3133 + 8; + GibCursor jumpf_floc_loc_1924 = soa_field_3_3134 + 8; + GibCursor jumpf_floc_loc_1925 = soa_field_4_3135 + 8; + GibCursor jumpf_floc_loc_1926 = soa_field_5_3136 + 8; + GibCursor loc_1709 = jumpf_dloc_1920 + 0; + GibCursor loc_1708 = jumpf_floc_loc_1921 + 0; + GibCursor cursor_ptr_3145[7] = {jumpf_dloc_1920, + jumpf_floc_loc_1921, + jumpf_floc_loc_1922, + jumpf_floc_loc_1923, + jumpf_floc_loc_1924, + jumpf_floc_loc_1925, + jumpf_floc_loc_1926}; + GibCursorPtr7GibCursorPtr7Prod tmp_struct_129 = + _traverse_ListB(cursor_ptr_3126, cursor_ptr_3128); + GibCursor pvrtmp_4184[7]; + + memcpy(pvrtmp_4184, tmp_struct_129.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4185[7]; + + memcpy(pvrtmp_4185, tmp_struct_129.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_130; + + memcpy(return_130.field0, pvrtmp_4184, sizeof(GibCursor [7])); + memcpy(return_130.field1, pvrtmp_4185, sizeof(GibCursor [7])); + return return_130; + break; + } + + case 1: + { + GibCursor soa_field_0_3153 = arg_206_358_526[1]; + GibCursor soa_field_1_3154 = arg_206_358_526[2]; + GibCursor soa_field_2_3155 = arg_206_358_526[3]; + GibCursor soa_field_3_3156 = arg_206_358_526[4]; + GibCursor soa_field_4_3157 = arg_206_358_526[5]; + GibCursor soa_field_5_3158 = arg_206_358_526[6]; + GibCursor loc_1310 = arg_206_358_526[0]; + GibCursor jump_dloc_1935 = loc_1310 + 1; + GibCursor loc_IntTy_1311 = arg_206_358_526[1]; + GibCursor jump_floc_loc_1936 = loc_IntTy_1311 + 0; + GibCursor loc_IntTy_1312 = arg_206_358_526[2]; + GibCursor jump_floc_loc_1937 = loc_IntTy_1312 + 0; + GibCursor loc_IntTy_1313 = arg_206_358_526[3]; + GibCursor jump_floc_loc_1938 = loc_IntTy_1313 + 0; + GibCursor loc_IntTy_1314 = arg_206_358_526[4]; + GibCursor jump_floc_loc_1939 = loc_IntTy_1314 + 0; + GibCursor loc_IntTy_1315 = arg_206_358_526[5]; + GibCursor jump_floc_loc_1940 = loc_IntTy_1315 + 0; + GibCursor loc_IntTy_1316 = arg_206_358_526[6]; + GibCursor jump_floc_loc_1941 = loc_IntTy_1316 + 0; + GibCursor cursor_ptr_3160[7] = {jump_dloc_1935, jump_floc_loc_1936, + jump_floc_loc_1937, + jump_floc_loc_1938, + jump_floc_loc_1939, + jump_floc_loc_1940, + jump_floc_loc_1941}; + GibCursorPtr7GibCursorPtr7Prod return_131; + + memcpy(return_131.field0, cursor_ptr_3126, sizeof(GibCursor [7])); + memcpy(return_131.field1, cursor_ptr_3160, sizeof(GibCursor [7])); + return return_131; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_3162 = arg_206_358_526[1]; + GibCursor soa_field_1_3163 = arg_206_358_526[2]; + GibCursor soa_field_2_3164 = arg_206_358_526[3]; + GibCursor soa_field_3_3165 = arg_206_358_526[4]; + GibCursor soa_field_4_3166 = arg_206_358_526[5]; + GibCursor soa_field_5_3167 = arg_206_358_526[6]; + uintptr_t tagged_tmpcur_140 = *(uintptr_t *) tmpcur_4171; + GibCursor tmpcur_4186 = GIB_UNTAG(tagged_tmpcur_140); + GibCursor tmpaftercur_4187 = tmpcur_4171 + 8; + uint16_t tmptag_4188 = GIB_GET_TAG(tagged_tmpcur_140); + GibCursor end_from_tagged_dcon_redir_3192 = tmpcur_4186 + + tmptag_4188; + GibCursor field_nxt_3185 = soa_field_0_3162 + 1; + uintptr_t tagged_tmpcur_139 = *(uintptr_t *) field_nxt_3185; + GibCursor tmpcur_4189 = GIB_UNTAG(tagged_tmpcur_139); + GibCursor tmpaftercur_4190 = field_nxt_3185 + 8; + uint16_t tmptag_4191 = GIB_GET_TAG(tagged_tmpcur_139); + GibCursor end_from_tagged_fld_redir_3193 = tmpcur_4189 + + tmptag_4191; + GibCursor field_nxt_3186 = soa_field_1_3163 + 1; + uintptr_t tagged_tmpcur_138 = *(uintptr_t *) field_nxt_3186; + GibCursor tmpcur_4192 = GIB_UNTAG(tagged_tmpcur_138); + GibCursor tmpaftercur_4193 = field_nxt_3186 + 8; + uint16_t tmptag_4194 = GIB_GET_TAG(tagged_tmpcur_138); + GibCursor end_from_tagged_fld_redir_3194 = tmpcur_4192 + + tmptag_4194; + GibCursor field_nxt_3187 = soa_field_2_3164 + 1; + uintptr_t tagged_tmpcur_137 = *(uintptr_t *) field_nxt_3187; + GibCursor tmpcur_4195 = GIB_UNTAG(tagged_tmpcur_137); + GibCursor tmpaftercur_4196 = field_nxt_3187 + 8; + uint16_t tmptag_4197 = GIB_GET_TAG(tagged_tmpcur_137); + GibCursor end_from_tagged_fld_redir_3195 = tmpcur_4195 + + tmptag_4197; + GibCursor field_nxt_3188 = soa_field_3_3165 + 1; + uintptr_t tagged_tmpcur_136 = *(uintptr_t *) field_nxt_3188; + GibCursor tmpcur_4198 = GIB_UNTAG(tagged_tmpcur_136); + GibCursor tmpaftercur_4199 = field_nxt_3188 + 8; + uint16_t tmptag_4200 = GIB_GET_TAG(tagged_tmpcur_136); + GibCursor end_from_tagged_fld_redir_3196 = tmpcur_4198 + + tmptag_4200; + GibCursor field_nxt_3189 = soa_field_4_3166 + 1; + uintptr_t tagged_tmpcur_135 = *(uintptr_t *) field_nxt_3189; + GibCursor tmpcur_4201 = GIB_UNTAG(tagged_tmpcur_135); + GibCursor tmpaftercur_4202 = field_nxt_3189 + 8; + uint16_t tmptag_4203 = GIB_GET_TAG(tagged_tmpcur_135); + GibCursor end_from_tagged_fld_redir_3197 = tmpcur_4201 + + tmptag_4203; + GibCursor field_nxt_3190 = soa_field_5_3167 + 1; + uintptr_t tagged_tmpcur_134 = *(uintptr_t *) field_nxt_3190; + GibCursor tmpcur_4204 = GIB_UNTAG(tagged_tmpcur_134); + GibCursor tmpaftercur_4205 = field_nxt_3190 + 8; + uint16_t tmptag_4206 = GIB_GET_TAG(tagged_tmpcur_134); + GibCursor end_from_tagged_fld_redir_3198 = tmpcur_4204 + + tmptag_4206; + GibCursor indr_2135[7] = {tmpcur_4186, tmpcur_4189, tmpcur_4192, + tmpcur_4195, tmpcur_4198, tmpcur_4201, + tmpcur_4204}; + GibCursor loc_1310 = arg_206_358_526[0]; + GibCursor jump_dloc_2143 = loc_1310 + 9; + GibCursor loc_IntTy_1316 = arg_206_358_526[6]; + GibCursor loc_IntTy_1315 = arg_206_358_526[5]; + GibCursor loc_IntTy_1314 = arg_206_358_526[4]; + GibCursor loc_IntTy_1313 = arg_206_358_526[3]; + GibCursor loc_IntTy_1312 = arg_206_358_526[2]; + GibCursor loc_IntTy_1311 = arg_206_358_526[1]; + GibCursor aft_indir_loc_2159 = loc_IntTy_1311 + 9; + GibCursor aft_indir_loc_2160 = loc_IntTy_1312 + 9; + GibCursor aft_indir_loc_2161 = loc_IntTy_1313 + 9; + GibCursor aft_indir_loc_2162 = loc_IntTy_1314 + 9; + GibCursor aft_indir_loc_2163 = loc_IntTy_1315 + 9; + GibCursor aft_indir_loc_2164 = loc_IntTy_1316 + 9; + GibCursor cursor_ptr_3199[7] = {jump_dloc_2143, aft_indir_loc_2159, + aft_indir_loc_2160, + aft_indir_loc_2161, + aft_indir_loc_2162, + aft_indir_loc_2163, + aft_indir_loc_2164}; + GibCursorPtr7GibCursorPtr7Prod tmp_struct_132 = + _traverse_ListB(indr_2135, indr_2135); + GibCursor pvrtmp_4207[7]; + + memcpy(pvrtmp_4207, tmp_struct_132.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4208[7]; + + memcpy(pvrtmp_4208, tmp_struct_132.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_133; + + memcpy(return_133.field0, cursor_ptr_3126, sizeof(GibCursor [7])); + memcpy(return_133.field1, cursor_ptr_3199, sizeof(GibCursor [7])); + return return_133; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_3207 = arg_206_358_526[1]; + GibCursor soa_field_1_3208 = arg_206_358_526[2]; + GibCursor soa_field_2_3209 = arg_206_358_526[3]; + GibCursor soa_field_3_3210 = arg_206_358_526[4]; + GibCursor soa_field_4_3211 = arg_206_358_526[5]; + GibCursor soa_field_5_3212 = arg_206_358_526[6]; + uintptr_t tagged_tmpcur_149 = *(uintptr_t *) tmpcur_4171; + GibCursor tmpcur_4209 = GIB_UNTAG(tagged_tmpcur_149); + GibCursor tmpaftercur_4210 = tmpcur_4171 + 8; + uint16_t tmptag_4211 = GIB_GET_TAG(tagged_tmpcur_149); + GibCursor end_from_tagged_dcon_redir_3228 = tmpcur_4209 + + tmptag_4211; + GibCursor field_nxt_3222 = soa_field_0_3207 + 1; + uintptr_t tagged_tmpcur_148 = *(uintptr_t *) field_nxt_3222; + GibCursor tmpcur_4212 = GIB_UNTAG(tagged_tmpcur_148); + GibCursor tmpaftercur_4213 = field_nxt_3222 + 8; + uint16_t tmptag_4214 = GIB_GET_TAG(tagged_tmpcur_148); + GibCursor end_from_tagged_fld_redir_3229 = tmpcur_4212 + + tmptag_4214; + GibCursor field_nxt_3223 = soa_field_1_3208 + 1; + uintptr_t tagged_tmpcur_147 = *(uintptr_t *) field_nxt_3223; + GibCursor tmpcur_4215 = GIB_UNTAG(tagged_tmpcur_147); + GibCursor tmpaftercur_4216 = field_nxt_3223 + 8; + uint16_t tmptag_4217 = GIB_GET_TAG(tagged_tmpcur_147); + GibCursor end_from_tagged_fld_redir_3230 = tmpcur_4215 + + tmptag_4217; + GibCursor field_nxt_3224 = soa_field_2_3209 + 1; + uintptr_t tagged_tmpcur_146 = *(uintptr_t *) field_nxt_3224; + GibCursor tmpcur_4218 = GIB_UNTAG(tagged_tmpcur_146); + GibCursor tmpaftercur_4219 = field_nxt_3224 + 8; + uint16_t tmptag_4220 = GIB_GET_TAG(tagged_tmpcur_146); + GibCursor end_from_tagged_fld_redir_3231 = tmpcur_4218 + + tmptag_4220; + GibCursor field_nxt_3225 = soa_field_3_3210 + 1; + uintptr_t tagged_tmpcur_145 = *(uintptr_t *) field_nxt_3225; + GibCursor tmpcur_4221 = GIB_UNTAG(tagged_tmpcur_145); + GibCursor tmpaftercur_4222 = field_nxt_3225 + 8; + uint16_t tmptag_4223 = GIB_GET_TAG(tagged_tmpcur_145); + GibCursor end_from_tagged_fld_redir_3232 = tmpcur_4221 + + tmptag_4223; + GibCursor field_nxt_3226 = soa_field_4_3211 + 1; + uintptr_t tagged_tmpcur_144 = *(uintptr_t *) field_nxt_3226; + GibCursor tmpcur_4224 = GIB_UNTAG(tagged_tmpcur_144); + GibCursor tmpaftercur_4225 = field_nxt_3226 + 8; + uint16_t tmptag_4226 = GIB_GET_TAG(tagged_tmpcur_144); + GibCursor end_from_tagged_fld_redir_3233 = tmpcur_4224 + + tmptag_4226; + GibCursor field_nxt_3227 = soa_field_5_3212 + 1; + uintptr_t tagged_tmpcur_143 = *(uintptr_t *) field_nxt_3227; + GibCursor tmpcur_4227 = GIB_UNTAG(tagged_tmpcur_143); + GibCursor tmpaftercur_4228 = field_nxt_3227 + 8; + uint16_t tmptag_4229 = GIB_GET_TAG(tagged_tmpcur_143); + GibCursor end_from_tagged_fld_redir_3234 = tmpcur_4227 + + tmptag_4229; + GibCursor indr_2135[7] = {tmpcur_4209, tmpcur_4212, tmpcur_4215, + tmpcur_4218, tmpcur_4221, tmpcur_4224, + tmpcur_4227}; + GibCursorPtr7GibCursorPtr7Prod tmp_struct_141 = + _traverse_ListB(indr_2135, indr_2135); + GibCursor pvrtmp_4230[7]; + + memcpy(pvrtmp_4230, tmp_struct_141.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4231[7]; + + memcpy(pvrtmp_4231, tmp_struct_141.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_142; + + memcpy(return_142.field0, pvrtmp_4230, sizeof(GibCursor [7])); + memcpy(return_142.field1, pvrtmp_4231, sizeof(GibCursor [7])); + return return_142; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4170"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_ListA(GibCursor end_r_1326, + GibCursor arg_103_369_535) +{ + GibPackedTag tmpval_4233 = *(GibPackedTag *) arg_103_369_535; + GibCursor tmpcur_4234 = arg_103_369_535 + 1; + + + switch_4249: + ; + switch (tmpval_4233) { + + case 0: + { + GibInt tmpval_4235 = *(GibInt *) tmpcur_4234; + GibCursor tmpcur_4236 = tmpcur_4234 + sizeof(GibInt); + GibCursor jump_1943 = tmpcur_4234 + 8; + unsigned char wildcard_108_372_538 = gib_print_symbol(3643); + unsigned char wildcard_111_373_539 = gib_print_symbol(3647); + unsigned char y_106_374_540 = printf("%ld", tmpval_4235); + unsigned char wildcard_110_375_541 = gib_print_symbol(3647); + GibCursorGibCursorProd tmp_struct_150 = + _print_ListA(end_r_1326, tmpcur_4236); + GibCursor pvrtmp_4237 = tmp_struct_150.field0; + GibCursor pvrtmp_4238 = tmp_struct_150.field1; + unsigned char wildcard_109_377_543 = gib_print_symbol(3638); + GibCursorGibCursorProd return_151; + + return_151.field0 = pvrtmp_4237; + return_151.field1 = pvrtmp_4238; + return return_151; + break; + } + + case 1: + { + GibCursor jump_loc_1946 = arg_103_369_535 + 1; + unsigned char wildcard_112_378_544 = gib_print_symbol(3640); + unsigned char wildcard_113_379_545 = gib_print_symbol(3638); + GibCursorGibCursorProd return_152; + + return_152.field0 = end_r_1326; + return_152.field1 = jump_loc_1946; + return return_152; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_155 = *(uintptr_t *) tmpcur_4234; + GibCursor tmpcur_4239 = GIB_UNTAG(tagged_tmpcur_155); + GibCursor tmpaftercur_4240 = tmpcur_4234 + 8; + uint16_t tmptag_4241 = GIB_GET_TAG(tagged_tmpcur_155); + GibCursor end_from_tagged_indr_2165 = tmpcur_4239 + tmptag_4241; + GibCursor jump_loc_2167 = tmpcur_4234 + 8; + unsigned char wildcard_2170 = gib_print_symbol(3646); + GibCursorGibCursorProd tmp_struct_153 = + _print_ListA(tmpcur_4239, tmpcur_4239); + GibCursor pvrtmp_4242 = tmp_struct_153.field0; + GibCursor pvrtmp_4243 = tmp_struct_153.field1; + GibCursorGibCursorProd return_154; + + return_154.field0 = end_r_1326; + return_154.field1 = jump_loc_2167; + return return_154; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_158 = *(uintptr_t *) tmpcur_4234; + GibCursor tmpcur_4244 = GIB_UNTAG(tagged_tmpcur_158); + GibCursor tmpaftercur_4245 = tmpcur_4234 + 8; + uint16_t tmptag_4246 = GIB_GET_TAG(tagged_tmpcur_158); + GibCursor end_from_tagged_indr_2165 = tmpcur_4244 + tmptag_4246; + unsigned char wildcard_2170 = gib_print_symbol(3645); + GibCursorGibCursorProd tmp_struct_156 = + _print_ListA(tmpcur_4244, tmpcur_4244); + GibCursor pvrtmp_4247 = tmp_struct_156.field0; + GibCursor pvrtmp_4248 = tmp_struct_156.field1; + GibCursorGibCursorProd return_157; + + return_157.field0 = pvrtmp_4247; + return_157.field1 = pvrtmp_4248; + return return_157; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4233"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7Prod _print_ListB(GibCursor cursor_ptr_3256[7], + GibCursor arg_221_380_546[7]) +{ + GibCursor end_r_1334 = cursor_ptr_3256[0]; + GibCursor end_r_1335 = cursor_ptr_3256[1]; + GibCursor end_r_1336 = cursor_ptr_3256[2]; + GibCursor end_r_1337 = cursor_ptr_3256[3]; + GibCursor end_r_1338 = cursor_ptr_3256[4]; + GibCursor end_r_1339 = cursor_ptr_3256[5]; + GibCursor end_r_1340 = cursor_ptr_3256[6]; + GibCursor dcon_3259 = arg_221_380_546[0]; + GibPackedTag tmpval_4250 = *(GibPackedTag *) dcon_3259; + GibCursor tmpcur_4251 = dcon_3259 + 1; + + + switch_4312: + ; + switch (tmpval_4250) { + + case 0: + { + GibCursor soa_field_0_3261 = arg_221_380_546[1]; + GibCursor soa_field_1_3262 = arg_221_380_546[2]; + GibCursor soa_field_2_3263 = arg_221_380_546[3]; + GibCursor soa_field_3_3264 = arg_221_380_546[4]; + GibCursor soa_field_4_3265 = arg_221_380_546[5]; + GibCursor soa_field_5_3266 = arg_221_380_546[6]; + GibInt tmpval_4252 = *(GibInt *) soa_field_0_3261; + GibCursor tmpcur_4253 = soa_field_0_3261 + sizeof(GibInt); + GibInt tmpval_4254 = *(GibInt *) soa_field_1_3262; + GibCursor tmpcur_4255 = soa_field_1_3262 + sizeof(GibInt); + GibInt tmpval_4256 = *(GibInt *) soa_field_2_3263; + GibCursor tmpcur_4257 = soa_field_2_3263 + sizeof(GibInt); + GibInt tmpval_4258 = *(GibInt *) soa_field_3_3264; + GibCursor tmpcur_4259 = soa_field_3_3264 + sizeof(GibInt); + GibInt tmpval_4260 = *(GibInt *) soa_field_4_3265; + GibCursor tmpcur_4261 = soa_field_4_3265 + sizeof(GibInt); + GibInt tmpval_4262 = *(GibInt *) soa_field_5_3266; + GibCursor tmpcur_4263 = soa_field_5_3266 + sizeof(GibInt); + GibCursor cursor_ptr_3258[7] = {tmpcur_4251, tmpcur_4253, + tmpcur_4255, tmpcur_4257, + tmpcur_4259, tmpcur_4261, + tmpcur_4263}; + GibCursor loc_1327 = arg_221_380_546[0]; + GibCursor jumpf_dloc_1948 = loc_1327 + 1; + GibCursor loc_IntTy_1328 = arg_221_380_546[1]; + GibCursor loc_IntTy_1329 = arg_221_380_546[2]; + GibCursor loc_IntTy_1330 = arg_221_380_546[3]; + GibCursor loc_IntTy_1331 = arg_221_380_546[4]; + GibCursor loc_IntTy_1332 = arg_221_380_546[5]; + GibCursor loc_IntTy_1333 = arg_221_380_546[6]; + GibCursor jumpf_floc_loc_1949 = soa_field_0_3261 + 8; + GibCursor jumpf_floc_loc_1950 = soa_field_1_3262 + 8; + GibCursor jumpf_floc_loc_1951 = soa_field_2_3263 + 8; + GibCursor jumpf_floc_loc_1952 = soa_field_3_3264 + 8; + GibCursor jumpf_floc_loc_1953 = soa_field_4_3265 + 8; + GibCursor jumpf_floc_loc_1954 = soa_field_5_3266 + 8; + GibCursor loc_1744 = jumpf_dloc_1948 + 0; + GibCursor loc_1743 = jumpf_floc_loc_1949 + 0; + GibCursor cursor_ptr_3275[7] = {jumpf_dloc_1948, + jumpf_floc_loc_1949, + jumpf_floc_loc_1950, + jumpf_floc_loc_1951, + jumpf_floc_loc_1952, + jumpf_floc_loc_1953, + jumpf_floc_loc_1954}; + unsigned char wildcard_236_388_554 = gib_print_symbol(3642); + unsigned char wildcard_244_389_555 = gib_print_symbol(3647); + unsigned char y_229_390_556 = printf("%ld", tmpval_4252); + unsigned char wildcard_243_391_557 = gib_print_symbol(3647); + unsigned char y_230_392_558 = printf("%ld", tmpval_4254); + unsigned char wildcard_242_393_559 = gib_print_symbol(3647); + unsigned char y_231_394_560 = printf("%ld", tmpval_4256); + unsigned char wildcard_241_395_561 = gib_print_symbol(3647); + unsigned char y_232_396_562 = printf("%ld", tmpval_4258); + unsigned char wildcard_240_397_563 = gib_print_symbol(3647); + unsigned char y_233_398_564 = printf("%ld", tmpval_4260); + unsigned char wildcard_239_399_565 = gib_print_symbol(3647); + unsigned char y_234_400_566 = printf("%ld", tmpval_4262); + unsigned char wildcard_238_401_567 = gib_print_symbol(3647); + GibCursorPtr7GibCursorPtr7Prod tmp_struct_159 = + _print_ListB(cursor_ptr_3256, cursor_ptr_3258); + GibCursor pvrtmp_4264[7]; + + memcpy(pvrtmp_4264, tmp_struct_159.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4265[7]; + + memcpy(pvrtmp_4265, tmp_struct_159.field1, sizeof(GibCursor [7])); + + unsigned char wildcard_237_403_569 = gib_print_symbol(3638); + GibCursorPtr7GibCursorPtr7Prod return_160; + + memcpy(return_160.field0, pvrtmp_4264, sizeof(GibCursor [7])); + memcpy(return_160.field1, pvrtmp_4265, sizeof(GibCursor [7])); + return return_160; + break; + } + + case 1: + { + GibCursor soa_field_0_3283 = arg_221_380_546[1]; + GibCursor soa_field_1_3284 = arg_221_380_546[2]; + GibCursor soa_field_2_3285 = arg_221_380_546[3]; + GibCursor soa_field_3_3286 = arg_221_380_546[4]; + GibCursor soa_field_4_3287 = arg_221_380_546[5]; + GibCursor soa_field_5_3288 = arg_221_380_546[6]; + GibCursor loc_1327 = arg_221_380_546[0]; + GibCursor jump_dloc_1963 = loc_1327 + 1; + GibCursor loc_IntTy_1328 = arg_221_380_546[1]; + GibCursor jump_floc_loc_1964 = loc_IntTy_1328 + 0; + GibCursor loc_IntTy_1329 = arg_221_380_546[2]; + GibCursor jump_floc_loc_1965 = loc_IntTy_1329 + 0; + GibCursor loc_IntTy_1330 = arg_221_380_546[3]; + GibCursor jump_floc_loc_1966 = loc_IntTy_1330 + 0; + GibCursor loc_IntTy_1331 = arg_221_380_546[4]; + GibCursor jump_floc_loc_1967 = loc_IntTy_1331 + 0; + GibCursor loc_IntTy_1332 = arg_221_380_546[5]; + GibCursor jump_floc_loc_1968 = loc_IntTy_1332 + 0; + GibCursor loc_IntTy_1333 = arg_221_380_546[6]; + GibCursor jump_floc_loc_1969 = loc_IntTy_1333 + 0; + GibCursor cursor_ptr_3290[7] = {jump_dloc_1963, jump_floc_loc_1964, + jump_floc_loc_1965, + jump_floc_loc_1966, + jump_floc_loc_1967, + jump_floc_loc_1968, + jump_floc_loc_1969}; + unsigned char wildcard_245_404_570 = gib_print_symbol(3639); + unsigned char wildcard_246_405_571 = gib_print_symbol(3638); + GibCursorPtr7GibCursorPtr7Prod return_161; + + memcpy(return_161.field0, cursor_ptr_3256, sizeof(GibCursor [7])); + memcpy(return_161.field1, cursor_ptr_3290, sizeof(GibCursor [7])); + return return_161; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_3292 = arg_221_380_546[1]; + GibCursor soa_field_1_3293 = arg_221_380_546[2]; + GibCursor soa_field_2_3294 = arg_221_380_546[3]; + GibCursor soa_field_3_3295 = arg_221_380_546[4]; + GibCursor soa_field_4_3296 = arg_221_380_546[5]; + GibCursor soa_field_5_3297 = arg_221_380_546[6]; + uintptr_t tagged_tmpcur_170 = *(uintptr_t *) tmpcur_4251; + GibCursor tmpcur_4266 = GIB_UNTAG(tagged_tmpcur_170); + GibCursor tmpaftercur_4267 = tmpcur_4251 + 8; + uint16_t tmptag_4268 = GIB_GET_TAG(tagged_tmpcur_170); + GibCursor end_from_tagged_dcon_redir_3322 = tmpcur_4266 + + tmptag_4268; + GibCursor field_nxt_3315 = soa_field_0_3292 + 1; + uintptr_t tagged_tmpcur_169 = *(uintptr_t *) field_nxt_3315; + GibCursor tmpcur_4269 = GIB_UNTAG(tagged_tmpcur_169); + GibCursor tmpaftercur_4270 = field_nxt_3315 + 8; + uint16_t tmptag_4271 = GIB_GET_TAG(tagged_tmpcur_169); + GibCursor end_from_tagged_fld_redir_3323 = tmpcur_4269 + + tmptag_4271; + GibCursor field_nxt_3316 = soa_field_1_3293 + 1; + uintptr_t tagged_tmpcur_168 = *(uintptr_t *) field_nxt_3316; + GibCursor tmpcur_4272 = GIB_UNTAG(tagged_tmpcur_168); + GibCursor tmpaftercur_4273 = field_nxt_3316 + 8; + uint16_t tmptag_4274 = GIB_GET_TAG(tagged_tmpcur_168); + GibCursor end_from_tagged_fld_redir_3324 = tmpcur_4272 + + tmptag_4274; + GibCursor field_nxt_3317 = soa_field_2_3294 + 1; + uintptr_t tagged_tmpcur_167 = *(uintptr_t *) field_nxt_3317; + GibCursor tmpcur_4275 = GIB_UNTAG(tagged_tmpcur_167); + GibCursor tmpaftercur_4276 = field_nxt_3317 + 8; + uint16_t tmptag_4277 = GIB_GET_TAG(tagged_tmpcur_167); + GibCursor end_from_tagged_fld_redir_3325 = tmpcur_4275 + + tmptag_4277; + GibCursor field_nxt_3318 = soa_field_3_3295 + 1; + uintptr_t tagged_tmpcur_166 = *(uintptr_t *) field_nxt_3318; + GibCursor tmpcur_4278 = GIB_UNTAG(tagged_tmpcur_166); + GibCursor tmpaftercur_4279 = field_nxt_3318 + 8; + uint16_t tmptag_4280 = GIB_GET_TAG(tagged_tmpcur_166); + GibCursor end_from_tagged_fld_redir_3326 = tmpcur_4278 + + tmptag_4280; + GibCursor field_nxt_3319 = soa_field_4_3296 + 1; + uintptr_t tagged_tmpcur_165 = *(uintptr_t *) field_nxt_3319; + GibCursor tmpcur_4281 = GIB_UNTAG(tagged_tmpcur_165); + GibCursor tmpaftercur_4282 = field_nxt_3319 + 8; + uint16_t tmptag_4283 = GIB_GET_TAG(tagged_tmpcur_165); + GibCursor end_from_tagged_fld_redir_3327 = tmpcur_4281 + + tmptag_4283; + GibCursor field_nxt_3320 = soa_field_5_3297 + 1; + uintptr_t tagged_tmpcur_164 = *(uintptr_t *) field_nxt_3320; + GibCursor tmpcur_4284 = GIB_UNTAG(tagged_tmpcur_164); + GibCursor tmpaftercur_4285 = field_nxt_3320 + 8; + uint16_t tmptag_4286 = GIB_GET_TAG(tagged_tmpcur_164); + GibCursor end_from_tagged_fld_redir_3328 = tmpcur_4284 + + tmptag_4286; + GibCursor indr_2171[7] = {tmpcur_4266, tmpcur_4269, tmpcur_4272, + tmpcur_4275, tmpcur_4278, tmpcur_4281, + tmpcur_4284}; + GibCursor loc_1327 = arg_221_380_546[0]; + GibCursor jump_dloc_2179 = loc_1327 + 9; + GibCursor loc_IntTy_1333 = arg_221_380_546[6]; + GibCursor loc_IntTy_1332 = arg_221_380_546[5]; + GibCursor loc_IntTy_1331 = arg_221_380_546[4]; + GibCursor loc_IntTy_1330 = arg_221_380_546[3]; + GibCursor loc_IntTy_1329 = arg_221_380_546[2]; + GibCursor loc_IntTy_1328 = arg_221_380_546[1]; + GibCursor aft_indir_loc_2195 = loc_IntTy_1328 + 9; + GibCursor aft_indir_loc_2196 = loc_IntTy_1329 + 9; + GibCursor aft_indir_loc_2197 = loc_IntTy_1330 + 9; + GibCursor aft_indir_loc_2198 = loc_IntTy_1331 + 9; + GibCursor aft_indir_loc_2199 = loc_IntTy_1332 + 9; + GibCursor aft_indir_loc_2200 = loc_IntTy_1333 + 9; + GibCursor cursor_ptr_3329[7] = {jump_dloc_2179, aft_indir_loc_2195, + aft_indir_loc_2196, + aft_indir_loc_2197, + aft_indir_loc_2198, + aft_indir_loc_2199, + aft_indir_loc_2200}; + unsigned char wildcard_2194 = gib_print_symbol(3646); + GibCursorPtr7GibCursorPtr7Prod tmp_struct_162 = + _print_ListB(indr_2171, indr_2171); + GibCursor pvrtmp_4287[7]; + + memcpy(pvrtmp_4287, tmp_struct_162.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4288[7]; + + memcpy(pvrtmp_4288, tmp_struct_162.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_163; + + memcpy(return_163.field0, cursor_ptr_3256, sizeof(GibCursor [7])); + memcpy(return_163.field1, cursor_ptr_3329, sizeof(GibCursor [7])); + return return_163; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_3337 = arg_221_380_546[1]; + GibCursor soa_field_1_3338 = arg_221_380_546[2]; + GibCursor soa_field_2_3339 = arg_221_380_546[3]; + GibCursor soa_field_3_3340 = arg_221_380_546[4]; + GibCursor soa_field_4_3341 = arg_221_380_546[5]; + GibCursor soa_field_5_3342 = arg_221_380_546[6]; + uintptr_t tagged_tmpcur_179 = *(uintptr_t *) tmpcur_4251; + GibCursor tmpcur_4289 = GIB_UNTAG(tagged_tmpcur_179); + GibCursor tmpaftercur_4290 = tmpcur_4251 + 8; + uint16_t tmptag_4291 = GIB_GET_TAG(tagged_tmpcur_179); + GibCursor end_from_tagged_dcon_redir_3358 = tmpcur_4289 + + tmptag_4291; + GibCursor field_nxt_3352 = soa_field_0_3337 + 1; + uintptr_t tagged_tmpcur_178 = *(uintptr_t *) field_nxt_3352; + GibCursor tmpcur_4292 = GIB_UNTAG(tagged_tmpcur_178); + GibCursor tmpaftercur_4293 = field_nxt_3352 + 8; + uint16_t tmptag_4294 = GIB_GET_TAG(tagged_tmpcur_178); + GibCursor end_from_tagged_fld_redir_3359 = tmpcur_4292 + + tmptag_4294; + GibCursor field_nxt_3353 = soa_field_1_3338 + 1; + uintptr_t tagged_tmpcur_177 = *(uintptr_t *) field_nxt_3353; + GibCursor tmpcur_4295 = GIB_UNTAG(tagged_tmpcur_177); + GibCursor tmpaftercur_4296 = field_nxt_3353 + 8; + uint16_t tmptag_4297 = GIB_GET_TAG(tagged_tmpcur_177); + GibCursor end_from_tagged_fld_redir_3360 = tmpcur_4295 + + tmptag_4297; + GibCursor field_nxt_3354 = soa_field_2_3339 + 1; + uintptr_t tagged_tmpcur_176 = *(uintptr_t *) field_nxt_3354; + GibCursor tmpcur_4298 = GIB_UNTAG(tagged_tmpcur_176); + GibCursor tmpaftercur_4299 = field_nxt_3354 + 8; + uint16_t tmptag_4300 = GIB_GET_TAG(tagged_tmpcur_176); + GibCursor end_from_tagged_fld_redir_3361 = tmpcur_4298 + + tmptag_4300; + GibCursor field_nxt_3355 = soa_field_3_3340 + 1; + uintptr_t tagged_tmpcur_175 = *(uintptr_t *) field_nxt_3355; + GibCursor tmpcur_4301 = GIB_UNTAG(tagged_tmpcur_175); + GibCursor tmpaftercur_4302 = field_nxt_3355 + 8; + uint16_t tmptag_4303 = GIB_GET_TAG(tagged_tmpcur_175); + GibCursor end_from_tagged_fld_redir_3362 = tmpcur_4301 + + tmptag_4303; + GibCursor field_nxt_3356 = soa_field_4_3341 + 1; + uintptr_t tagged_tmpcur_174 = *(uintptr_t *) field_nxt_3356; + GibCursor tmpcur_4304 = GIB_UNTAG(tagged_tmpcur_174); + GibCursor tmpaftercur_4305 = field_nxt_3356 + 8; + uint16_t tmptag_4306 = GIB_GET_TAG(tagged_tmpcur_174); + GibCursor end_from_tagged_fld_redir_3363 = tmpcur_4304 + + tmptag_4306; + GibCursor field_nxt_3357 = soa_field_5_3342 + 1; + uintptr_t tagged_tmpcur_173 = *(uintptr_t *) field_nxt_3357; + GibCursor tmpcur_4307 = GIB_UNTAG(tagged_tmpcur_173); + GibCursor tmpaftercur_4308 = field_nxt_3357 + 8; + uint16_t tmptag_4309 = GIB_GET_TAG(tagged_tmpcur_173); + GibCursor end_from_tagged_fld_redir_3364 = tmpcur_4307 + + tmptag_4309; + GibCursor indr_2171[7] = {tmpcur_4289, tmpcur_4292, tmpcur_4295, + tmpcur_4298, tmpcur_4301, tmpcur_4304, + tmpcur_4307}; + unsigned char wildcard_2194 = gib_print_symbol(3645); + GibCursorPtr7GibCursorPtr7Prod tmp_struct_171 = + _print_ListB(indr_2171, indr_2171); + GibCursor pvrtmp_4310[7]; + + memcpy(pvrtmp_4310, tmp_struct_171.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4311[7]; + + memcpy(pvrtmp_4311, tmp_struct_171.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_172; + + memcpy(return_172.field0, pvrtmp_4310, sizeof(GibCursor [7])); + memcpy(return_172.field1, pvrtmp_4311, sizeof(GibCursor [7])); + return return_172; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4250"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_List(GibCursor end_r_1344, + GibCursor end_r_1346, + GibCursor loc_1342, + GibCursor arg_127_406_572) +{ + GibPackedTag tmpval_4313 = *(GibPackedTag *) arg_127_406_572; + GibCursor tmpcur_4314 = arg_127_406_572 + 1; + + + switch_4377: + ; + switch (tmpval_4313) { + + case 0: + { + GibInt tmpval_4315 = *(GibInt *) tmpcur_4314; + GibCursor tmpcur_4316 = tmpcur_4314 + sizeof(GibInt); + GibInt tmpval_4317 = *(GibInt *) tmpcur_4316; + GibCursor tmpcur_4318 = tmpcur_4316 + sizeof(GibInt); + GibInt tmpval_4319 = *(GibInt *) tmpcur_4318; + GibCursor tmpcur_4320 = tmpcur_4318 + sizeof(GibInt); + GibInt tmpval_4321 = *(GibInt *) tmpcur_4320; + GibCursor tmpcur_4322 = tmpcur_4320 + sizeof(GibInt); + GibCursor jump_1974 = tmpcur_4320 + 8; + GibCursor jump_1973 = tmpcur_4318 + 8; + GibCursor jump_1972 = tmpcur_4316 + 8; + GibCursor jump_1971 = tmpcur_4314 + 8; + GibCursor loc_1773 = loc_1342 + 1; + GibCursor loc_1774 = loc_1773 + 8; + GibCursor loc_1775 = loc_1774 + 8; + GibCursor loc_1776 = loc_1775 + 8; + GibCursor loc_1777 = loc_1776 + 8; + + *(GibPackedTag *) loc_1342 = 0; + + GibCursor writetag_3383 = loc_1342 + 1; + GibCursor after_tag_3384 = loc_1342 + 1; + + *(GibInt *) after_tag_3384 = tmpval_4315; + + GibCursor writecur_3388 = after_tag_3384 + sizeof(GibInt); + + *(GibInt *) writecur_3388 = tmpval_4317; + + GibCursor writecur_3389 = writecur_3388 + sizeof(GibInt); + + *(GibInt *) writecur_3389 = tmpval_4319; + + GibCursor writecur_3390 = writecur_3389 + sizeof(GibInt); + + *(GibInt *) writecur_3390 = tmpval_4321; + + GibCursor writecur_3391 = writecur_3390 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_180 = + _copy_without_ptrs_ListA(end_r_1344, end_r_1346, loc_1777, tmpcur_4322); + GibCursor pvrtmp_4323 = tmp_struct_180.field0; + GibCursor pvrtmp_4324 = tmp_struct_180.field1; + GibCursor pvrtmp_4325 = tmp_struct_180.field2; + GibCursor pvrtmp_4326 = tmp_struct_180.field3; + GibCursor pvrtmp_4327 = tmp_struct_180.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_181 = + _copy_without_ptrs_List(pvrtmp_4323, pvrtmp_4324, pvrtmp_4327, pvrtmp_4325); + GibCursor pvrtmp_4332 = tmp_struct_181.field0; + GibCursor pvrtmp_4333 = tmp_struct_181.field1; + GibCursor pvrtmp_4334 = tmp_struct_181.field2; + GibCursor pvrtmp_4335 = tmp_struct_181.field3; + GibCursor pvrtmp_4336 = tmp_struct_181.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_182; + + return_182.field0 = pvrtmp_4332; + return_182.field1 = pvrtmp_4333; + return_182.field2 = pvrtmp_4334; + return_182.field3 = loc_1342; + return_182.field4 = pvrtmp_4336; + return return_182; + break; + } + + case 1: + { + GibCursor jump_loc_1978 = arg_127_406_572 + 1; + + *(GibPackedTag *) loc_1342 = 1; + + GibCursor writetag_3398 = loc_1342 + 1; + GibCursor after_tag_3399 = loc_1342 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_183; + + return_183.field0 = end_r_1344; + return_183.field1 = end_r_1346; + return_183.field2 = jump_loc_1978; + return_183.field3 = loc_1342; + return_183.field4 = after_tag_3399; + return return_183; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_186 = *(uintptr_t *) tmpcur_4314; + GibCursor tmpcur_4349 = GIB_UNTAG(tagged_tmpcur_186); + GibCursor tmpaftercur_4350 = tmpcur_4314 + 8; + uint16_t tmptag_4351 = GIB_GET_TAG(tagged_tmpcur_186); + GibCursor end_from_tagged_indr_2201 = tmpcur_4349 + tmptag_4351; + GibCursor jump_loc_2203 = tmpcur_4314 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_184 = + _copy_without_ptrs_List(tmpcur_4349, end_r_1346, loc_1342, tmpcur_4349); + GibCursor pvrtmp_4352 = tmp_struct_184.field0; + GibCursor pvrtmp_4353 = tmp_struct_184.field1; + GibCursor pvrtmp_4354 = tmp_struct_184.field2; + GibCursor pvrtmp_4355 = tmp_struct_184.field3; + GibCursor pvrtmp_4356 = tmp_struct_184.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_185; + + return_185.field0 = end_r_1344; + return_185.field1 = pvrtmp_4353; + return_185.field2 = jump_loc_2203; + return_185.field3 = pvrtmp_4355; + return_185.field4 = pvrtmp_4356; + return return_185; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_189 = *(uintptr_t *) tmpcur_4314; + GibCursor tmpcur_4363 = GIB_UNTAG(tagged_tmpcur_189); + GibCursor tmpaftercur_4364 = tmpcur_4314 + 8; + uint16_t tmptag_4365 = GIB_GET_TAG(tagged_tmpcur_189); + GibCursor end_from_tagged_indr_2201 = tmpcur_4363 + tmptag_4365; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_187 = + _copy_without_ptrs_List(tmpcur_4363, end_r_1346, loc_1342, tmpcur_4363); + GibCursor pvrtmp_4366 = tmp_struct_187.field0; + GibCursor pvrtmp_4367 = tmp_struct_187.field1; + GibCursor pvrtmp_4368 = tmp_struct_187.field2; + GibCursor pvrtmp_4369 = tmp_struct_187.field3; + GibCursor pvrtmp_4370 = tmp_struct_187.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_188; + + return_188.field0 = pvrtmp_4366; + return_188.field1 = pvrtmp_4367; + return_188.field2 = pvrtmp_4368; + return_188.field3 = pvrtmp_4369; + return_188.field4 = pvrtmp_4370; + return return_188; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4313"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_197 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_3648 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1376 = region_3648.start; + GibCursor end_r_1376 = region_3648.end; + GibChunk region_3649 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1377 = region_3649.start; + GibCursor end_r_1377 = region_3649.end; + GibChunk region_3650 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1378 = region_3650.start; + GibCursor end_r_1378 = region_3650.end; + GibChunk region_3651 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1379 = region_3651.start; + GibCursor end_r_1379 = region_3651.end; + GibChunk region_3652 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1380 = region_3652.start; + GibCursor end_r_1380 = region_3652.end; + GibChunk region_3653 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1381 = region_3653.start; + GibCursor end_r_1381 = region_3653.end; + GibChunk region_3654 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1382 = region_3654.start; + GibCursor end_r_1382 = region_3654.end; + GibCursor reg_ptr_3415[7] = {r_1376, r_1377, r_1378, r_1379, r_1380, r_1381, + r_1382}; + GibCursor reg_cursor_ptr_3416[7] = {end_r_1376, end_r_1377, end_r_1378, + end_r_1379, end_r_1380, end_r_1381, + end_r_1382}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod tmp_struct_190 = + mkListB(reg_cursor_ptr_3416, reg_ptr_3415, 2500000); + GibCursor pvrtmp_3655[7]; + + memcpy(pvrtmp_3655, tmp_struct_190.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3656[7]; + + memcpy(pvrtmp_3656, tmp_struct_190.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3657[7]; + + memcpy(pvrtmp_3657, tmp_struct_190.field2, sizeof(GibCursor [7])); + + GibInt timed_3497; + GibVector *times_195 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_3497; + struct timespec end_timed_3497; + + for (long long iters_timed_3497 = 0; iters_timed_3497 < + gib_get_iters_param(); iters_timed_3497++) { + if (iters_timed_3497 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_3497); + + GibInt pvrtmp_3664 = 0; + + reduceB(pvrtmp_3655, pvrtmp_3656, &pvrtmp_3664); +// GibCursor pvrtmp_3662[7]; +// +// memcpy(pvrtmp_3662, tmp_struct_191.field0, sizeof(GibCursor [7])); +// +// GibCursor pvrtmp_3663[7]; +// +// memcpy(pvrtmp_3663, tmp_struct_191.field1, sizeof(GibCursor [7])); +// +// GibInt pvrtmp_3664 = tmp_struct_191.field2; + + timed_3497 = pvrtmp_3664; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_3497); + if (iters_timed_3497 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_192 = gib_difftimespecs(&begin_timed_3497, + &end_timed_3497); + + printf("itertime: %lf\n", itertime_192); + gib_vector_inplace_update(times_195, iters_timed_3497, &itertime_192); + + memcpy(pvrtmp_3655, tmp_struct_190.field0, sizeof(GibCursor [7])); + memcpy(pvrtmp_3656, tmp_struct_190.field1, sizeof(GibCursor [7])); + pvrtmp_3664 = 0; + + } + gib_vector_inplace_sort(times_195, gib_compare_doubles); + + double *tmp_196 = (double *) gib_vector_nth(times_195, + gib_get_iters_param() / 2); + double selftimed_194 = *tmp_196; + double batchtime_193 = gib_sum_timing_array(times_195); + + gib_print_timing_array(times_195); + gib_vector_free(times_195); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_193); + printf("SELFTIMED: %e\n", selftimed_194); + printf("%ld", timed_3497); + printf("\n"); + + int exit_198 = gib_exit(); + + return exit_198; +} diff --git a/microbench/manual_soa_examples/reduceList.soa.returns.c b/microbench/manual_soa_examples/reduceList.soa.returns.c new file mode 100644 index 000000000..306e1cc35 --- /dev/null +++ b/microbench/manual_soa_examples/reduceList.soa.returns.c @@ -0,0 +1,3331 @@ +/* Gibbon program. */ + +#include "gibbon_rts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#endif + +#ifdef _GIBBON_POINTER +#include +#endif + +#ifdef _GIBBON_PARALLEL +#include +#include +#endif + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Program starts here + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +typedef struct GibIntProd_struct { + GibInt field0; + } GibIntProd; +typedef struct GibIntGibCursorProd_struct { + GibInt field0; + GibCursor field1; + } GibIntGibCursorProd; +typedef struct GibBoolProd_struct { + GibBool field0; + } GibBoolProd; +typedef struct GibPackedTagGibCursorProd_struct { + GibPackedTag field0; + GibCursor field1; + } GibPackedTagGibCursorProd; +typedef struct GibCursorProd_struct { + GibCursor field0; + } GibCursorProd; +typedef struct GibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + } GibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibIntProd_struct { + GibCursor field0; + GibCursor field1; + GibInt field2; + } GibCursorGibCursorGibIntProd; +typedef struct GibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + } GibCursorGibCursorGibCursorProd; +typedef struct GibCursorGibCursorGibCursorGibCursorGibCursorProd_struct { + GibCursor field0; + GibCursor field1; + GibCursor field2; + GibCursor field3; + GibCursor field4; + } GibCursorGibCursorGibCursorGibCursorGibCursorProd; +typedef struct GibCursorPtr7Prod_struct { + GibCursor field0[7]; + } GibCursorPtr7Prod; +typedef struct GibCursorPtr7GibCursorPtr7Prod_struct { + GibCursor field0[7]; + GibCursor field1[7]; + } GibCursorPtr7GibCursorPtr7Prod; +typedef struct GibCursorPtr7GibCursorPtr7GibIntProd_struct { + GibCursor field0[7]; + GibCursor field1[7]; + GibInt field2; + } GibCursorPtr7GibCursorPtr7GibIntProd; +typedef struct GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod_struct { + GibCursor field0[7]; + GibCursor field1[7]; + GibCursor field2[7]; + } GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod; +typedef struct GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod_struct { + GibCursor field0[7]; + GibCursor field1[7]; + GibCursor field2[7]; + GibCursor field3[7]; + GibCursor field4[7]; + } GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod; +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod +_copy_without_ptrs_ListB(GibCursor cursor_ptr_2498[7], + GibCursor cursor_ptr_2497[7], + GibCursor cursor_ptr_2499[7], + GibCursor arg_191_249_424[7]); +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_1229, + GibCursor arg_98_264_439); +GibCursorGibCursorProd _print_List(GibCursor end_r_1232, + GibCursor arg_153_268_443); +GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod +mkListB(GibCursor cursor_ptr_2686[7], GibCursor cursor_ptr_2687[7], + GibInt len_34_291_466); +GibCursorGibCursorProd _traverse_List(GibCursor end_r_1249, + GibCursor arg_140_293_470); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_ListA(GibCursor end_r_1253, GibCursor end_r_1255, + GibCursor loc_1251, GibCursor arg_93_302_479); +GibCursorPtr7GibCursorPtr7GibIntProd reduceB(GibCursor cursor_ptr_2775[7], + GibCursor lst_36_307_484[7]); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_ListA(GibCursor end_r_1273, GibCursor end_r_1275, GibCursor loc_1271, + GibCursor arg_88_315_493); +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod +_copy_ListB(GibCursor cursor_ptr_2925[7], GibCursor cursor_ptr_2924[7], + GibCursor cursor_ptr_2926[7], GibCursor arg_176_330_498[7]); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_List(GibCursor end_r_1307, GibCursor end_r_1309, GibCursor loc_1305, + GibCursor arg_114_345_513); +GibCursorPtr7GibCursorPtr7Prod _traverse_ListB(GibCursor cursor_ptr_3126[7], + GibCursor arg_206_358_526[7]); +GibCursorGibCursorProd _print_ListA(GibCursor end_r_1326, + GibCursor arg_103_369_535); +GibCursorPtr7GibCursorPtr7Prod _print_ListB(GibCursor cursor_ptr_3256[7], + GibCursor arg_221_380_546[7]); +GibCursorGibCursorGibCursorGibCursorGibCursorProd +_copy_without_ptrs_List(GibCursor end_r_1344, GibCursor end_r_1346, + GibCursor loc_1342, GibCursor arg_127_406_572); +typedef enum { + GibInt_T, + GibFloat_T, + GibSym_T, + GibBool_T, + GibVector_T, + GibList_T, + GibCursor_T, + List_T, + ListA_T, + ListB_T, + } GibDatatype; +void info_table_initialize(void) +{ + int error = gib_info_table_initialize(10); + + if (error < 0) { + fprintf(stderr, "Couldn't initialize info table, errorno=%d", error); + exit(1); + } + + GibDatatype field_tys[7]; + + field_tys[0] = ListA_T; + field_tys[1] = List_T; + error = gib_info_table_insert_packed_dcon(List_T, 0, 32, 0, 4, 2, field_tys, + 2); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(List_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, List_T, 1); + exit(1); + } + field_tys[0] = ListA_T; + error = gib_info_table_insert_packed_dcon(ListA_T, 0, 8, 0, 1, 1, field_tys, + 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListA_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListA_T, 1); + exit(1); + } + field_tys[0] = ListB_T; + error = gib_info_table_insert_packed_dcon(ListB_T, 0, 48, 0, 6, 1, + field_tys, 1); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 0); + exit(1); + } + error = gib_info_table_insert_packed_dcon(ListB_T, 1, 0, 0, 0, 0, field_tys, + 0); + if (error < 0) { + fprintf(stderr, + "Couldn't insert into info table, errorno=%d, tycon=%d, dcon=%d", + error, ListB_T, 1); + exit(1); + } + gib_info_table_finalize(); +} +void symbol_table_initialize(void) +{ + gib_add_symbol(3638, ")"); + gib_add_symbol(3639, "(NilB"); + gib_add_symbol(3640, "(NilA"); + gib_add_symbol(3641, "(Nil"); + gib_add_symbol(3642, "(ConsB"); + gib_add_symbol(3643, "(ConsA"); + gib_add_symbol(3644, "(Cons"); + gib_add_symbol(3645, " ->r "); + gib_add_symbol(3646, " ->i "); + gib_add_symbol(3647, " "); +} +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod _copy_without_ptrs_ListB(GibCursor cursor_ptr_2498[7], + GibCursor cursor_ptr_2497[7], + GibCursor cursor_ptr_2499[7], + GibCursor arg_191_249_424[7]) +{ + GibCursor end_r_1213 = cursor_ptr_2498[0]; + GibCursor end_r_1214 = cursor_ptr_2498[1]; + GibCursor end_r_1215 = cursor_ptr_2498[2]; + GibCursor end_r_1216 = cursor_ptr_2498[3]; + GibCursor end_r_1217 = cursor_ptr_2498[4]; + GibCursor end_r_1218 = cursor_ptr_2498[5]; + GibCursor end_r_1219 = cursor_ptr_2498[6]; + GibCursor end_r_1220 = cursor_ptr_2497[0]; + GibCursor end_r_1221 = cursor_ptr_2497[1]; + GibCursor end_r_1222 = cursor_ptr_2497[2]; + GibCursor end_r_1223 = cursor_ptr_2497[3]; + GibCursor end_r_1224 = cursor_ptr_2497[4]; + GibCursor end_r_1225 = cursor_ptr_2497[5]; + GibCursor end_r_1226 = cursor_ptr_2497[6]; + GibCursor dcon_2502 = arg_191_249_424[0]; + GibPackedTag tmpval_3665 = *(GibPackedTag *) dcon_2502; + GibCursor tmpcur_3666 = dcon_2502 + 1; + + + switch_3760: + ; + switch (tmpval_3665) { + + case 0: + { + GibCursor soa_field_0_2504 = arg_191_249_424[1]; + GibCursor soa_field_1_2505 = arg_191_249_424[2]; + GibCursor soa_field_2_2506 = arg_191_249_424[3]; + GibCursor soa_field_3_2507 = arg_191_249_424[4]; + GibCursor soa_field_4_2508 = arg_191_249_424[5]; + GibCursor soa_field_5_2509 = arg_191_249_424[6]; + GibInt tmpval_3667 = *(GibInt *) soa_field_0_2504; + GibCursor tmpcur_3668 = soa_field_0_2504 + sizeof(GibInt); + GibInt tmpval_3669 = *(GibInt *) soa_field_1_2505; + GibCursor tmpcur_3670 = soa_field_1_2505 + sizeof(GibInt); + GibInt tmpval_3671 = *(GibInt *) soa_field_2_2506; + GibCursor tmpcur_3672 = soa_field_2_2506 + sizeof(GibInt); + GibInt tmpval_3673 = *(GibInt *) soa_field_3_2507; + GibCursor tmpcur_3674 = soa_field_3_2507 + sizeof(GibInt); + GibInt tmpval_3675 = *(GibInt *) soa_field_4_2508; + GibCursor tmpcur_3676 = soa_field_4_2508 + sizeof(GibInt); + GibInt tmpval_3677 = *(GibInt *) soa_field_5_2509; + GibCursor tmpcur_3678 = soa_field_5_2509 + sizeof(GibInt); + GibCursor cursor_ptr_2501[7] = {tmpcur_3666, tmpcur_3668, + tmpcur_3670, tmpcur_3672, + tmpcur_3674, tmpcur_3676, + tmpcur_3678}; + GibCursor loc_1199 = arg_191_249_424[0]; + GibCursor jumpf_dloc_1807 = loc_1199 + 1; + GibCursor loc_IntTy_1200 = arg_191_249_424[1]; + GibCursor loc_IntTy_1201 = arg_191_249_424[2]; + GibCursor loc_IntTy_1202 = arg_191_249_424[3]; + GibCursor loc_IntTy_1203 = arg_191_249_424[4]; + GibCursor loc_IntTy_1204 = arg_191_249_424[5]; + GibCursor loc_IntTy_1205 = arg_191_249_424[6]; + GibCursor jumpf_floc_loc_1808 = soa_field_0_2504 + 8; + GibCursor jumpf_floc_loc_1809 = soa_field_1_2505 + 8; + GibCursor jumpf_floc_loc_1810 = soa_field_2_2506 + 8; + GibCursor jumpf_floc_loc_1811 = soa_field_3_2507 + 8; + GibCursor jumpf_floc_loc_1812 = soa_field_4_2508 + 8; + GibCursor jumpf_floc_loc_1813 = soa_field_5_2509 + 8; + GibCursor loc_1397 = jumpf_dloc_1807 + 0; + GibCursor loc_1396 = jumpf_floc_loc_1808 + 0; + GibCursor cursor_ptr_2518[7] = {jumpf_dloc_1807, + jumpf_floc_loc_1808, + jumpf_floc_loc_1809, + jumpf_floc_loc_1810, + jumpf_floc_loc_1811, + jumpf_floc_loc_1812, + jumpf_floc_loc_1813}; + GibCursor loc_IntTy_1208 = cursor_ptr_2499[2]; + GibCursor new_floc_loc_1427 = loc_IntTy_1208 + 8; + GibCursor loc_1206 = cursor_ptr_2499[0]; + GibCursor new_dloc_1425 = loc_1206 + 1; + GibCursor loc_IntTy_1210 = cursor_ptr_2499[4]; + GibCursor new_floc_loc_1429 = loc_IntTy_1210 + 8; + GibCursor loc_IntTy_1212 = cursor_ptr_2499[6]; + GibCursor new_floc_loc_1431 = loc_IntTy_1212 + 8; + GibCursor loc_IntTy_1209 = cursor_ptr_2499[3]; + GibCursor new_floc_loc_1428 = loc_IntTy_1209 + 8; + GibCursor loc_IntTy_1207 = cursor_ptr_2499[1]; + GibCursor new_floc_loc_1426 = loc_IntTy_1207 + 8; + GibCursor loc_IntTy_1211 = cursor_ptr_2499[5]; + GibCursor new_floc_loc_1430 = loc_IntTy_1211 + 8; + GibCursor cursor_ptr_2519[7] = {new_dloc_1425, new_floc_loc_1426, + new_floc_loc_1427, + new_floc_loc_1428, + new_floc_loc_1429, + new_floc_loc_1430, + new_floc_loc_1431}; + + *(GibPackedTag *) loc_1206 = 0; + + GibCursor writetag_2529 = loc_1206 + 1; + GibCursor after_tag_2530 = loc_1206 + 1; + + *(GibInt *) loc_IntTy_1207 = tmpval_3667; + + GibCursor writecur_2534 = loc_IntTy_1207 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1208 = tmpval_3669; + + GibCursor writecur_2536 = loc_IntTy_1208 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1209 = tmpval_3671; + + GibCursor writecur_2538 = loc_IntTy_1209 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1210 = tmpval_3673; + + GibCursor writecur_2540 = loc_IntTy_1210 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1211 = tmpval_3675; + + GibCursor writecur_2542 = loc_IntTy_1211 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1212 = tmpval_3677; + + GibCursor writecur_2544 = loc_IntTy_1212 + sizeof(GibInt); + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_0 = + _copy_without_ptrs_ListB(cursor_ptr_2498, cursor_ptr_2497, cursor_ptr_2519, cursor_ptr_2501); + GibCursor pvrtmp_3679[7]; + + memcpy(pvrtmp_3679, tmp_struct_0.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3680[7]; + + memcpy(pvrtmp_3680, tmp_struct_0.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3681[7]; + + memcpy(pvrtmp_3681, tmp_struct_0.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3682[7]; + + memcpy(pvrtmp_3682, tmp_struct_0.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3683[7]; + + memcpy(pvrtmp_3683, tmp_struct_0.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_1; + + memcpy(return_1.field0, pvrtmp_3679, sizeof(GibCursor [7])); + memcpy(return_1.field1, pvrtmp_3680, sizeof(GibCursor [7])); + memcpy(return_1.field2, pvrtmp_3681, sizeof(GibCursor [7])); + memcpy(return_1.field3, cursor_ptr_2499, sizeof(GibCursor [7])); + memcpy(return_1.field4, pvrtmp_3683, sizeof(GibCursor [7])); + return return_1; + break; + } + + case 1: + { + GibCursor soa_field_0_2550 = arg_191_249_424[1]; + GibCursor soa_field_1_2551 = arg_191_249_424[2]; + GibCursor soa_field_2_2552 = arg_191_249_424[3]; + GibCursor soa_field_3_2553 = arg_191_249_424[4]; + GibCursor soa_field_4_2554 = arg_191_249_424[5]; + GibCursor soa_field_5_2555 = arg_191_249_424[6]; + GibCursor loc_1199 = arg_191_249_424[0]; + GibCursor jump_dloc_1822 = loc_1199 + 1; + GibCursor loc_IntTy_1200 = arg_191_249_424[1]; + GibCursor jump_floc_loc_1823 = loc_IntTy_1200 + 0; + GibCursor loc_IntTy_1201 = arg_191_249_424[2]; + GibCursor jump_floc_loc_1824 = loc_IntTy_1201 + 0; + GibCursor loc_IntTy_1202 = arg_191_249_424[3]; + GibCursor jump_floc_loc_1825 = loc_IntTy_1202 + 0; + GibCursor loc_IntTy_1203 = arg_191_249_424[4]; + GibCursor jump_floc_loc_1826 = loc_IntTy_1203 + 0; + GibCursor loc_IntTy_1204 = arg_191_249_424[5]; + GibCursor jump_floc_loc_1827 = loc_IntTy_1204 + 0; + GibCursor loc_IntTy_1205 = arg_191_249_424[6]; + GibCursor jump_floc_loc_1828 = loc_IntTy_1205 + 0; + GibCursor cursor_ptr_2557[7] = {jump_dloc_1822, jump_floc_loc_1823, + jump_floc_loc_1824, + jump_floc_loc_1825, + jump_floc_loc_1826, + jump_floc_loc_1827, + jump_floc_loc_1828}; + GibCursor loc_IntTy_1208 = cursor_ptr_2499[2]; + GibCursor new_floc_loc_1427 = loc_IntTy_1208 + 8; + GibCursor loc_1206 = cursor_ptr_2499[0]; + GibCursor new_dloc_1425 = loc_1206 + 1; + GibCursor loc_IntTy_1210 = cursor_ptr_2499[4]; + GibCursor new_floc_loc_1429 = loc_IntTy_1210 + 8; + GibCursor loc_IntTy_1212 = cursor_ptr_2499[6]; + GibCursor new_floc_loc_1431 = loc_IntTy_1212 + 8; + GibCursor loc_IntTy_1209 = cursor_ptr_2499[3]; + GibCursor new_floc_loc_1428 = loc_IntTy_1209 + 8; + GibCursor loc_IntTy_1207 = cursor_ptr_2499[1]; + GibCursor new_floc_loc_1426 = loc_IntTy_1207 + 8; + GibCursor loc_IntTy_1211 = cursor_ptr_2499[5]; + GibCursor new_floc_loc_1430 = loc_IntTy_1211 + 8; + + *(GibPackedTag *) loc_1206 = 1; + + GibCursor writetag_2558 = loc_1206 + 1; + GibCursor after_tag_2559 = loc_1206 + 1; + GibCursor aft_soa_loc_2563[7] = {after_tag_2559, loc_IntTy_1207, + loc_IntTy_1208, loc_IntTy_1209, + loc_IntTy_1210, loc_IntTy_1211, + loc_IntTy_1212}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_2; + + memcpy(return_2.field0, cursor_ptr_2498, sizeof(GibCursor [7])); + memcpy(return_2.field1, cursor_ptr_2497, sizeof(GibCursor [7])); + memcpy(return_2.field2, cursor_ptr_2557, sizeof(GibCursor [7])); + memcpy(return_2.field3, cursor_ptr_2499, sizeof(GibCursor [7])); + memcpy(return_2.field4, aft_soa_loc_2563, sizeof(GibCursor [7])); + return return_2; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_2567 = arg_191_249_424[1]; + GibCursor soa_field_1_2568 = arg_191_249_424[2]; + GibCursor soa_field_2_2569 = arg_191_249_424[3]; + GibCursor soa_field_3_2570 = arg_191_249_424[4]; + GibCursor soa_field_4_2571 = arg_191_249_424[5]; + GibCursor soa_field_5_2572 = arg_191_249_424[6]; + uintptr_t tagged_tmpcur_11 = *(uintptr_t *) tmpcur_3666; + GibCursor tmpcur_3696 = GIB_UNTAG(tagged_tmpcur_11); + GibCursor tmpaftercur_3697 = tmpcur_3666 + 8; + uint16_t tmptag_3698 = GIB_GET_TAG(tagged_tmpcur_11); + GibCursor end_from_tagged_dcon_redir_2597 = tmpcur_3696 + + tmptag_3698; + GibCursor field_nxt_2590 = soa_field_0_2567 + 1; + uintptr_t tagged_tmpcur_10 = *(uintptr_t *) field_nxt_2590; + GibCursor tmpcur_3699 = GIB_UNTAG(tagged_tmpcur_10); + GibCursor tmpaftercur_3700 = field_nxt_2590 + 8; + uint16_t tmptag_3701 = GIB_GET_TAG(tagged_tmpcur_10); + GibCursor end_from_tagged_fld_redir_2598 = tmpcur_3699 + + tmptag_3701; + GibCursor field_nxt_2591 = soa_field_1_2568 + 1; + uintptr_t tagged_tmpcur_9 = *(uintptr_t *) field_nxt_2591; + GibCursor tmpcur_3702 = GIB_UNTAG(tagged_tmpcur_9); + GibCursor tmpaftercur_3703 = field_nxt_2591 + 8; + uint16_t tmptag_3704 = GIB_GET_TAG(tagged_tmpcur_9); + GibCursor end_from_tagged_fld_redir_2599 = tmpcur_3702 + + tmptag_3704; + GibCursor field_nxt_2592 = soa_field_2_2569 + 1; + uintptr_t tagged_tmpcur_8 = *(uintptr_t *) field_nxt_2592; + GibCursor tmpcur_3705 = GIB_UNTAG(tagged_tmpcur_8); + GibCursor tmpaftercur_3706 = field_nxt_2592 + 8; + uint16_t tmptag_3707 = GIB_GET_TAG(tagged_tmpcur_8); + GibCursor end_from_tagged_fld_redir_2600 = tmpcur_3705 + + tmptag_3707; + GibCursor field_nxt_2593 = soa_field_3_2570 + 1; + uintptr_t tagged_tmpcur_7 = *(uintptr_t *) field_nxt_2593; + GibCursor tmpcur_3708 = GIB_UNTAG(tagged_tmpcur_7); + GibCursor tmpaftercur_3709 = field_nxt_2593 + 8; + uint16_t tmptag_3710 = GIB_GET_TAG(tagged_tmpcur_7); + GibCursor end_from_tagged_fld_redir_2601 = tmpcur_3708 + + tmptag_3710; + GibCursor field_nxt_2594 = soa_field_4_2571 + 1; + uintptr_t tagged_tmpcur_6 = *(uintptr_t *) field_nxt_2594; + GibCursor tmpcur_3711 = GIB_UNTAG(tagged_tmpcur_6); + GibCursor tmpaftercur_3712 = field_nxt_2594 + 8; + uint16_t tmptag_3713 = GIB_GET_TAG(tagged_tmpcur_6); + GibCursor end_from_tagged_fld_redir_2602 = tmpcur_3711 + + tmptag_3713; + GibCursor field_nxt_2595 = soa_field_5_2572 + 1; + uintptr_t tagged_tmpcur_5 = *(uintptr_t *) field_nxt_2595; + GibCursor tmpcur_3714 = GIB_UNTAG(tagged_tmpcur_5); + GibCursor tmpaftercur_3715 = field_nxt_2595 + 8; + uint16_t tmptag_3716 = GIB_GET_TAG(tagged_tmpcur_5); + GibCursor end_from_tagged_fld_redir_2603 = tmpcur_3714 + + tmptag_3716; + GibCursor indr_1995[7] = {tmpcur_3696, tmpcur_3699, tmpcur_3702, + tmpcur_3705, tmpcur_3708, tmpcur_3711, + tmpcur_3714}; + GibCursor loc_1199 = arg_191_249_424[0]; + GibCursor jump_dloc_2003 = loc_1199 + 9; + GibCursor loc_IntTy_1205 = arg_191_249_424[6]; + GibCursor loc_IntTy_1204 = arg_191_249_424[5]; + GibCursor loc_IntTy_1203 = arg_191_249_424[4]; + GibCursor loc_IntTy_1202 = arg_191_249_424[3]; + GibCursor loc_IntTy_1201 = arg_191_249_424[2]; + GibCursor loc_IntTy_1200 = arg_191_249_424[1]; + GibCursor aft_indir_loc_2019 = loc_IntTy_1200 + 9; + GibCursor aft_indir_loc_2020 = loc_IntTy_1201 + 9; + GibCursor aft_indir_loc_2021 = loc_IntTy_1202 + 9; + GibCursor aft_indir_loc_2022 = loc_IntTy_1203 + 9; + GibCursor aft_indir_loc_2023 = loc_IntTy_1204 + 9; + GibCursor aft_indir_loc_2024 = loc_IntTy_1205 + 9; + GibCursor cursor_ptr_2604[7] = {jump_dloc_2003, aft_indir_loc_2019, + aft_indir_loc_2020, + aft_indir_loc_2021, + aft_indir_loc_2022, + aft_indir_loc_2023, + aft_indir_loc_2024}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_3 = + _copy_without_ptrs_ListB(indr_1995, cursor_ptr_2497, cursor_ptr_2499, indr_1995); + GibCursor pvrtmp_3717[7]; + + memcpy(pvrtmp_3717, tmp_struct_3.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3718[7]; + + memcpy(pvrtmp_3718, tmp_struct_3.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3719[7]; + + memcpy(pvrtmp_3719, tmp_struct_3.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3720[7]; + + memcpy(pvrtmp_3720, tmp_struct_3.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3721[7]; + + memcpy(pvrtmp_3721, tmp_struct_3.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_4; + + memcpy(return_4.field0, cursor_ptr_2498, sizeof(GibCursor [7])); + memcpy(return_4.field1, pvrtmp_3718, sizeof(GibCursor [7])); + memcpy(return_4.field2, cursor_ptr_2604, sizeof(GibCursor [7])); + memcpy(return_4.field3, pvrtmp_3720, sizeof(GibCursor [7])); + memcpy(return_4.field4, pvrtmp_3721, sizeof(GibCursor [7])); + return return_4; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_2615 = arg_191_249_424[1]; + GibCursor soa_field_1_2616 = arg_191_249_424[2]; + GibCursor soa_field_2_2617 = arg_191_249_424[3]; + GibCursor soa_field_3_2618 = arg_191_249_424[4]; + GibCursor soa_field_4_2619 = arg_191_249_424[5]; + GibCursor soa_field_5_2620 = arg_191_249_424[6]; + uintptr_t tagged_tmpcur_20 = *(uintptr_t *) tmpcur_3666; + GibCursor tmpcur_3728 = GIB_UNTAG(tagged_tmpcur_20); + GibCursor tmpaftercur_3729 = tmpcur_3666 + 8; + uint16_t tmptag_3730 = GIB_GET_TAG(tagged_tmpcur_20); + GibCursor end_from_tagged_dcon_redir_2636 = tmpcur_3728 + + tmptag_3730; + GibCursor field_nxt_2630 = soa_field_0_2615 + 1; + uintptr_t tagged_tmpcur_19 = *(uintptr_t *) field_nxt_2630; + GibCursor tmpcur_3731 = GIB_UNTAG(tagged_tmpcur_19); + GibCursor tmpaftercur_3732 = field_nxt_2630 + 8; + uint16_t tmptag_3733 = GIB_GET_TAG(tagged_tmpcur_19); + GibCursor end_from_tagged_fld_redir_2637 = tmpcur_3731 + + tmptag_3733; + GibCursor field_nxt_2631 = soa_field_1_2616 + 1; + uintptr_t tagged_tmpcur_18 = *(uintptr_t *) field_nxt_2631; + GibCursor tmpcur_3734 = GIB_UNTAG(tagged_tmpcur_18); + GibCursor tmpaftercur_3735 = field_nxt_2631 + 8; + uint16_t tmptag_3736 = GIB_GET_TAG(tagged_tmpcur_18); + GibCursor end_from_tagged_fld_redir_2638 = tmpcur_3734 + + tmptag_3736; + GibCursor field_nxt_2632 = soa_field_2_2617 + 1; + uintptr_t tagged_tmpcur_17 = *(uintptr_t *) field_nxt_2632; + GibCursor tmpcur_3737 = GIB_UNTAG(tagged_tmpcur_17); + GibCursor tmpaftercur_3738 = field_nxt_2632 + 8; + uint16_t tmptag_3739 = GIB_GET_TAG(tagged_tmpcur_17); + GibCursor end_from_tagged_fld_redir_2639 = tmpcur_3737 + + tmptag_3739; + GibCursor field_nxt_2633 = soa_field_3_2618 + 1; + uintptr_t tagged_tmpcur_16 = *(uintptr_t *) field_nxt_2633; + GibCursor tmpcur_3740 = GIB_UNTAG(tagged_tmpcur_16); + GibCursor tmpaftercur_3741 = field_nxt_2633 + 8; + uint16_t tmptag_3742 = GIB_GET_TAG(tagged_tmpcur_16); + GibCursor end_from_tagged_fld_redir_2640 = tmpcur_3740 + + tmptag_3742; + GibCursor field_nxt_2634 = soa_field_4_2619 + 1; + uintptr_t tagged_tmpcur_15 = *(uintptr_t *) field_nxt_2634; + GibCursor tmpcur_3743 = GIB_UNTAG(tagged_tmpcur_15); + GibCursor tmpaftercur_3744 = field_nxt_2634 + 8; + uint16_t tmptag_3745 = GIB_GET_TAG(tagged_tmpcur_15); + GibCursor end_from_tagged_fld_redir_2641 = tmpcur_3743 + + tmptag_3745; + GibCursor field_nxt_2635 = soa_field_5_2620 + 1; + uintptr_t tagged_tmpcur_14 = *(uintptr_t *) field_nxt_2635; + GibCursor tmpcur_3746 = GIB_UNTAG(tagged_tmpcur_14); + GibCursor tmpaftercur_3747 = field_nxt_2635 + 8; + uint16_t tmptag_3748 = GIB_GET_TAG(tagged_tmpcur_14); + GibCursor end_from_tagged_fld_redir_2642 = tmpcur_3746 + + tmptag_3748; + GibCursor indr_1995[7] = {tmpcur_3728, tmpcur_3731, tmpcur_3734, + tmpcur_3737, tmpcur_3740, tmpcur_3743, + tmpcur_3746}; + GibCursor loc_1206 = cursor_ptr_2499[0]; + GibCursor loc_IntTy_1207 = cursor_ptr_2499[1]; + GibCursor loc_IntTy_1208 = cursor_ptr_2499[2]; + GibCursor loc_IntTy_1209 = cursor_ptr_2499[3]; + GibCursor loc_IntTy_1210 = cursor_ptr_2499[4]; + GibCursor loc_IntTy_1211 = cursor_ptr_2499[5]; + GibCursor loc_IntTy_1212 = cursor_ptr_2499[6]; + GibCursor copy_dloc_2025 = loc_1206 + 0; + GibCursor copy_floc_loc_2031 = loc_IntTy_1212 + 0; + GibCursor copy_floc_loc_2030 = loc_IntTy_1211 + 0; + GibCursor copy_floc_loc_2029 = loc_IntTy_1210 + 0; + GibCursor copy_floc_loc_2028 = loc_IntTy_1209 + 0; + GibCursor copy_floc_loc_2027 = loc_IntTy_1208 + 0; + GibCursor copy_floc_loc_2026 = loc_IntTy_1207 + 0; + GibCursor cursor_ptr_2643[7] = {copy_dloc_2025, copy_floc_loc_2026, + copy_floc_loc_2027, + copy_floc_loc_2028, + copy_floc_loc_2029, + copy_floc_loc_2030, + copy_floc_loc_2031}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_12 = + _copy_without_ptrs_ListB(indr_1995, cursor_ptr_2497, cursor_ptr_2643, indr_1995); + GibCursor pvrtmp_3749[7]; + + memcpy(pvrtmp_3749, tmp_struct_12.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3750[7]; + + memcpy(pvrtmp_3750, tmp_struct_12.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3751[7]; + + memcpy(pvrtmp_3751, tmp_struct_12.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3752[7]; + + memcpy(pvrtmp_3752, tmp_struct_12.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3753[7]; + + memcpy(pvrtmp_3753, tmp_struct_12.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_13; + + memcpy(return_13.field0, pvrtmp_3749, sizeof(GibCursor [7])); + memcpy(return_13.field1, pvrtmp_3750, sizeof(GibCursor [7])); + memcpy(return_13.field2, pvrtmp_3751, sizeof(GibCursor [7])); + memcpy(return_13.field3, pvrtmp_3752, sizeof(GibCursor [7])); + memcpy(return_13.field4, pvrtmp_3753, sizeof(GibCursor [7])); + return return_13; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3665"); + exit(1); + } + } +} +GibCursorGibCursorProd _traverse_ListA(GibCursor end_r_1229, + GibCursor arg_98_264_439) +{ + GibPackedTag tmpval_3761 = *(GibPackedTag *) arg_98_264_439; + GibCursor tmpcur_3762 = arg_98_264_439 + 1; + + + switch_3777: + ; + switch (tmpval_3761) { + + case 0: + { + GibInt tmpval_3763 = *(GibInt *) tmpcur_3762; + GibCursor tmpcur_3764 = tmpcur_3762 + sizeof(GibInt); + GibCursor jump_1830 = tmpcur_3762 + 8; + GibCursorGibCursorProd tmp_struct_21 = + _traverse_ListA(end_r_1229, tmpcur_3764); + GibCursor pvrtmp_3765 = tmp_struct_21.field0; + GibCursor pvrtmp_3766 = tmp_struct_21.field1; + GibCursorGibCursorProd return_22; + + return_22.field0 = pvrtmp_3765; + return_22.field1 = pvrtmp_3766; + return return_22; + break; + } + + case 1: + { + GibCursor jump_loc_1833 = arg_98_264_439 + 1; + GibCursorGibCursorProd return_23; + + return_23.field0 = end_r_1229; + return_23.field1 = jump_loc_1833; + return return_23; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_26 = *(uintptr_t *) tmpcur_3762; + GibCursor tmpcur_3767 = GIB_UNTAG(tagged_tmpcur_26); + GibCursor tmpaftercur_3768 = tmpcur_3762 + 8; + uint16_t tmptag_3769 = GIB_GET_TAG(tagged_tmpcur_26); + GibCursor end_from_tagged_indr_2032 = tmpcur_3767 + tmptag_3769; + GibCursor jump_loc_2034 = tmpcur_3762 + 8; + GibCursorGibCursorProd tmp_struct_24 = + _traverse_ListA(tmpcur_3767, tmpcur_3767); + GibCursor pvrtmp_3770 = tmp_struct_24.field0; + GibCursor pvrtmp_3771 = tmp_struct_24.field1; + GibCursorGibCursorProd return_25; + + return_25.field0 = end_r_1229; + return_25.field1 = jump_loc_2034; + return return_25; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_29 = *(uintptr_t *) tmpcur_3762; + GibCursor tmpcur_3772 = GIB_UNTAG(tagged_tmpcur_29); + GibCursor tmpaftercur_3773 = tmpcur_3762 + 8; + uint16_t tmptag_3774 = GIB_GET_TAG(tagged_tmpcur_29); + GibCursor end_from_tagged_indr_2032 = tmpcur_3772 + tmptag_3774; + GibCursorGibCursorProd tmp_struct_27 = + _traverse_ListA(tmpcur_3772, tmpcur_3772); + GibCursor pvrtmp_3775 = tmp_struct_27.field0; + GibCursor pvrtmp_3776 = tmp_struct_27.field1; + GibCursorGibCursorProd return_28; + + return_28.field0 = pvrtmp_3775; + return_28.field1 = pvrtmp_3776; + return return_28; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3761"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_List(GibCursor end_r_1232, + GibCursor arg_153_268_443) +{ + GibPackedTag tmpval_3778 = *(GibPackedTag *) arg_153_268_443; + GibCursor tmpcur_3779 = arg_153_268_443 + 1; + + + switch_3802: + ; + switch (tmpval_3778) { + + case 0: + { + GibInt tmpval_3780 = *(GibInt *) tmpcur_3779; + GibCursor tmpcur_3781 = tmpcur_3779 + sizeof(GibInt); + GibInt tmpval_3782 = *(GibInt *) tmpcur_3781; + GibCursor tmpcur_3783 = tmpcur_3781 + sizeof(GibInt); + GibInt tmpval_3784 = *(GibInt *) tmpcur_3783; + GibCursor tmpcur_3785 = tmpcur_3783 + sizeof(GibInt); + GibInt tmpval_3786 = *(GibInt *) tmpcur_3785; + GibCursor tmpcur_3787 = tmpcur_3785 + sizeof(GibInt); + GibCursor jump_1838 = tmpcur_3785 + 8; + GibCursor jump_1837 = tmpcur_3783 + 8; + GibCursor jump_1836 = tmpcur_3781 + 8; + GibCursor jump_1835 = tmpcur_3779 + 8; + unsigned char wildcard_166_275_450 = gib_print_symbol(3644); + unsigned char wildcard_173_276_451 = gib_print_symbol(3647); + unsigned char y_160_277_452 = printf("%ld", tmpval_3780); + unsigned char wildcard_172_278_453 = gib_print_symbol(3647); + unsigned char y_161_279_454 = printf("%ld", tmpval_3782); + unsigned char wildcard_171_280_455 = gib_print_symbol(3647); + unsigned char y_162_281_456 = printf("%ld", tmpval_3784); + unsigned char wildcard_170_282_457 = gib_print_symbol(3647); + unsigned char y_163_283_458 = printf("%ld", tmpval_3786); + unsigned char wildcard_169_284_459 = gib_print_symbol(3647); + GibCursorGibCursorProd tmp_struct_30 = + _print_ListA(end_r_1232, tmpcur_3787); + GibCursor pvrtmp_3788 = tmp_struct_30.field0; + GibCursor pvrtmp_3789 = tmp_struct_30.field1; + unsigned char wildcard_168_286_461 = gib_print_symbol(3647); + GibCursorGibCursorProd tmp_struct_31 = + _print_List(pvrtmp_3788, pvrtmp_3789); + GibCursor pvrtmp_3790 = tmp_struct_31.field0; + GibCursor pvrtmp_3791 = tmp_struct_31.field1; + unsigned char wildcard_167_288_463 = gib_print_symbol(3638); + GibCursorGibCursorProd return_32; + + return_32.field0 = pvrtmp_3790; + return_32.field1 = pvrtmp_3791; + return return_32; + break; + } + + case 1: + { + GibCursor jump_loc_1842 = arg_153_268_443 + 1; + unsigned char wildcard_174_289_464 = gib_print_symbol(3641); + unsigned char wildcard_175_290_465 = gib_print_symbol(3638); + GibCursorGibCursorProd return_33; + + return_33.field0 = end_r_1232; + return_33.field1 = jump_loc_1842; + return return_33; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_36 = *(uintptr_t *) tmpcur_3779; + GibCursor tmpcur_3792 = GIB_UNTAG(tagged_tmpcur_36); + GibCursor tmpaftercur_3793 = tmpcur_3779 + 8; + uint16_t tmptag_3794 = GIB_GET_TAG(tagged_tmpcur_36); + GibCursor end_from_tagged_indr_2038 = tmpcur_3792 + tmptag_3794; + GibCursor jump_loc_2040 = tmpcur_3779 + 8; + unsigned char wildcard_2043 = gib_print_symbol(3646); + GibCursorGibCursorProd tmp_struct_34 = + _print_List(tmpcur_3792, tmpcur_3792); + GibCursor pvrtmp_3795 = tmp_struct_34.field0; + GibCursor pvrtmp_3796 = tmp_struct_34.field1; + GibCursorGibCursorProd return_35; + + return_35.field0 = end_r_1232; + return_35.field1 = jump_loc_2040; + return return_35; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_39 = *(uintptr_t *) tmpcur_3779; + GibCursor tmpcur_3797 = GIB_UNTAG(tagged_tmpcur_39); + GibCursor tmpaftercur_3798 = tmpcur_3779 + 8; + uint16_t tmptag_3799 = GIB_GET_TAG(tagged_tmpcur_39); + GibCursor end_from_tagged_indr_2038 = tmpcur_3797 + tmptag_3799; + unsigned char wildcard_2043 = gib_print_symbol(3645); + GibCursorGibCursorProd tmp_struct_37 = + _print_List(tmpcur_3797, tmpcur_3797); + GibCursor pvrtmp_3800 = tmp_struct_37.field0; + GibCursor pvrtmp_3801 = tmp_struct_37.field1; + GibCursorGibCursorProd return_38; + + return_38.field0 = pvrtmp_3800; + return_38.field1 = pvrtmp_3801; + return return_38; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3778"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod mkListB(GibCursor cursor_ptr_2686[7], + GibCursor cursor_ptr_2687[7], + GibInt len_34_291_466) +{ + GibCursor end_r_1245 = cursor_ptr_2686[5]; + GibCursor end_r_1242 = cursor_ptr_2686[2]; + GibCursor end_r_1246 = cursor_ptr_2686[6]; + GibCursor end_r_1243 = cursor_ptr_2686[3]; + GibCursor end_r_1241 = cursor_ptr_2686[1]; + GibCursor end_r_1240 = cursor_ptr_2686[0]; + GibCursor end_r_1244 = cursor_ptr_2686[4]; + GibCursor loc_IntTy_1235 = cursor_ptr_2687[2]; + GibCursor loc_IntTy_1238 = cursor_ptr_2687[5]; + GibCursor loc_IntTy_1236 = cursor_ptr_2687[3]; + GibCursor loc_IntTy_1234 = cursor_ptr_2687[1]; + GibCursor loc_IntTy_1239 = cursor_ptr_2687[6]; + GibCursor loc_1233 = cursor_ptr_2687[0]; + GibCursor loc_IntTy_1237 = cursor_ptr_2687[4]; + + if (loc_IntTy_1239 + 17 > end_r_1246 || (loc_IntTy_1238 + 17 > end_r_1245 || + (loc_IntTy_1237 + 17 > + end_r_1244 || (loc_IntTy_1236 + + 17 > end_r_1243 || + (loc_IntTy_1235 + + 17 > end_r_1242 || + (loc_IntTy_1234 + + 17 > + end_r_1241 || + loc_1233 + 66 > + end_r_1240)))))) { + gib_grow_region(&loc_IntTy_1239, &end_r_1246); + gib_grow_region(&loc_IntTy_1238, &end_r_1245); + gib_grow_region(&loc_IntTy_1237, &end_r_1244); + gib_grow_region(&loc_IntTy_1236, &end_r_1243); + gib_grow_region(&loc_IntTy_1235, &end_r_1242); + gib_grow_region(&loc_IntTy_1234, &end_r_1241); + gib_grow_region(&loc_1233, &end_r_1240); + } + + GibCursor overwrite_reg_2688[7] = {end_r_1240, end_r_1241, end_r_1242, + end_r_1243, end_r_1244, end_r_1245, + end_r_1246}; + GibBool fltIf_419_467 = len_34_291_466 <= 0; + + if (fltIf_419_467) { + GibCursor new_floc_loc_1499 = loc_IntTy_1236 + 8; + GibCursor new_floc_loc_1500 = loc_IntTy_1237 + 8; + GibCursor new_dloc_1496 = loc_1233 + 1; + GibCursor new_floc_loc_1502 = loc_IntTy_1239 + 8; + GibCursor new_floc_loc_1497 = loc_IntTy_1234 + 8; + GibCursor new_floc_loc_1498 = loc_IntTy_1235 + 8; + GibCursor new_floc_loc_1501 = loc_IntTy_1238 + 8; + + *(GibPackedTag *) loc_1233 = 1; + + GibCursor writetag_2689 = loc_1233 + 1; + GibCursor after_tag_2690 = loc_1233 + 1; + GibCursor aft_soa_loc_2694[7] = {after_tag_2690, loc_IntTy_1234, + loc_IntTy_1235, loc_IntTy_1236, + loc_IntTy_1237, loc_IntTy_1238, + loc_IntTy_1239}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod return_40; + + memcpy(return_40.field0, overwrite_reg_2688, sizeof(GibCursor [7])); + memcpy(return_40.field1, cursor_ptr_2687, sizeof(GibCursor [7])); + memcpy(return_40.field2, aft_soa_loc_2694, sizeof(GibCursor [7])); + return return_40; + } else { + GibInt fltAppE_420_468 = len_34_291_466 - 1; + GibCursor new_floc_loc_1499 = loc_IntTy_1236 + 8; + GibCursor new_floc_loc_1500 = loc_IntTy_1237 + 8; + GibCursor new_dloc_1496 = loc_1233 + 1; + GibCursor new_floc_loc_1502 = loc_IntTy_1239 + 8; + GibCursor new_floc_loc_1497 = loc_IntTy_1234 + 8; + GibCursor new_floc_loc_1498 = loc_IntTy_1235 + 8; + GibCursor new_floc_loc_1501 = loc_IntTy_1238 + 8; + GibCursor cursor_ptr_2697[7] = {new_dloc_1496, new_floc_loc_1497, + new_floc_loc_1498, new_floc_loc_1499, + new_floc_loc_1500, new_floc_loc_1501, + new_floc_loc_1502}; + + *(GibPackedTag *) loc_1233 = 0; + + GibCursor writetag_2702 = loc_1233 + 1; + GibCursor after_tag_2703 = loc_1233 + 1; + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2707 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2709 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2711 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2713 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2715 = loc_IntTy_1234 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1234 = len_34_291_466; + + GibCursor writecur_2717 = loc_IntTy_1234 + sizeof(GibInt); + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod tmp_struct_41 = + mkListB(overwrite_reg_2688, cursor_ptr_2697, fltAppE_420_468); + GibCursor pvrtmp_3807[7]; + + memcpy(pvrtmp_3807, tmp_struct_41.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3808[7]; + + memcpy(pvrtmp_3808, tmp_struct_41.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3809[7]; + + memcpy(pvrtmp_3809, tmp_struct_41.field2, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod return_42; + + memcpy(return_42.field0, pvrtmp_3807, sizeof(GibCursor [7])); + memcpy(return_42.field1, cursor_ptr_2687, sizeof(GibCursor [7])); + memcpy(return_42.field2, pvrtmp_3809, sizeof(GibCursor [7])); + return return_42; + } +} +GibCursorGibCursorProd _traverse_List(GibCursor end_r_1249, + GibCursor arg_140_293_470) +{ + GibPackedTag tmpval_3818 = *(GibPackedTag *) arg_140_293_470; + GibCursor tmpcur_3819 = arg_140_293_470 + 1; + + + switch_3842: + ; + switch (tmpval_3818) { + + case 0: + { + GibInt tmpval_3820 = *(GibInt *) tmpcur_3819; + GibCursor tmpcur_3821 = tmpcur_3819 + sizeof(GibInt); + GibInt tmpval_3822 = *(GibInt *) tmpcur_3821; + GibCursor tmpcur_3823 = tmpcur_3821 + sizeof(GibInt); + GibInt tmpval_3824 = *(GibInt *) tmpcur_3823; + GibCursor tmpcur_3825 = tmpcur_3823 + sizeof(GibInt); + GibInt tmpval_3826 = *(GibInt *) tmpcur_3825; + GibCursor tmpcur_3827 = tmpcur_3825 + sizeof(GibInt); + GibCursor jump_1849 = tmpcur_3825 + 8; + GibCursor jump_1848 = tmpcur_3823 + 8; + GibCursor jump_1847 = tmpcur_3821 + 8; + GibCursor jump_1846 = tmpcur_3819 + 8; + GibCursorGibCursorProd tmp_struct_43 = + _traverse_ListA(end_r_1249, tmpcur_3827); + GibCursor pvrtmp_3828 = tmp_struct_43.field0; + GibCursor pvrtmp_3829 = tmp_struct_43.field1; + GibCursorGibCursorProd tmp_struct_44 = + _traverse_List(pvrtmp_3828, pvrtmp_3829); + GibCursor pvrtmp_3830 = tmp_struct_44.field0; + GibCursor pvrtmp_3831 = tmp_struct_44.field1; + GibCursorGibCursorProd return_45; + + return_45.field0 = pvrtmp_3830; + return_45.field1 = pvrtmp_3831; + return return_45; + break; + } + + case 1: + { + GibCursor jump_loc_1853 = arg_140_293_470 + 1; + GibCursorGibCursorProd return_46; + + return_46.field0 = end_r_1249; + return_46.field1 = jump_loc_1853; + return return_46; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_49 = *(uintptr_t *) tmpcur_3819; + GibCursor tmpcur_3832 = GIB_UNTAG(tagged_tmpcur_49); + GibCursor tmpaftercur_3833 = tmpcur_3819 + 8; + uint16_t tmptag_3834 = GIB_GET_TAG(tagged_tmpcur_49); + GibCursor end_from_tagged_indr_2044 = tmpcur_3832 + tmptag_3834; + GibCursor jump_loc_2046 = tmpcur_3819 + 8; + GibCursorGibCursorProd tmp_struct_47 = + _traverse_List(tmpcur_3832, tmpcur_3832); + GibCursor pvrtmp_3835 = tmp_struct_47.field0; + GibCursor pvrtmp_3836 = tmp_struct_47.field1; + GibCursorGibCursorProd return_48; + + return_48.field0 = end_r_1249; + return_48.field1 = jump_loc_2046; + return return_48; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_52 = *(uintptr_t *) tmpcur_3819; + GibCursor tmpcur_3837 = GIB_UNTAG(tagged_tmpcur_52); + GibCursor tmpaftercur_3838 = tmpcur_3819 + 8; + uint16_t tmptag_3839 = GIB_GET_TAG(tagged_tmpcur_52); + GibCursor end_from_tagged_indr_2044 = tmpcur_3837 + tmptag_3839; + GibCursorGibCursorProd tmp_struct_50 = + _traverse_List(tmpcur_3837, tmpcur_3837); + GibCursor pvrtmp_3840 = tmp_struct_50.field0; + GibCursor pvrtmp_3841 = tmp_struct_50.field1; + GibCursorGibCursorProd return_51; + + return_51.field0 = pvrtmp_3840; + return_51.field1 = pvrtmp_3841; + return return_51; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3818"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_ListA(GibCursor end_r_1253, + GibCursor end_r_1255, + GibCursor loc_1251, + GibCursor arg_93_302_479) +{ + GibPackedTag tmpval_3843 = *(GibPackedTag *) arg_93_302_479; + GibCursor tmpcur_3844 = arg_93_302_479 + 1; + + + switch_3892: + ; + switch (tmpval_3843) { + + case 0: + { + GibInt tmpval_3845 = *(GibInt *) tmpcur_3844; + GibCursor tmpcur_3846 = tmpcur_3844 + sizeof(GibInt); + GibCursor jump_1855 = tmpcur_3844 + 8; + GibCursor loc_1541 = loc_1251 + 1; + GibCursor loc_1542 = loc_1541 + 8; + + *(GibPackedTag *) loc_1251 = 0; + + GibCursor writetag_2747 = loc_1251 + 1; + GibCursor after_tag_2748 = loc_1251 + 1; + + *(GibInt *) after_tag_2748 = tmpval_3845; + + GibCursor writecur_2752 = after_tag_2748 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_53 = + _copy_without_ptrs_ListA(end_r_1253, end_r_1255, loc_1542, tmpcur_3846); + GibCursor pvrtmp_3847 = tmp_struct_53.field0; + GibCursor pvrtmp_3848 = tmp_struct_53.field1; + GibCursor pvrtmp_3849 = tmp_struct_53.field2; + GibCursor pvrtmp_3850 = tmp_struct_53.field3; + GibCursor pvrtmp_3851 = tmp_struct_53.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_54; + + return_54.field0 = pvrtmp_3847; + return_54.field1 = pvrtmp_3848; + return_54.field2 = pvrtmp_3849; + return_54.field3 = loc_1251; + return_54.field4 = pvrtmp_3851; + return return_54; + break; + } + + case 1: + { + GibCursor jump_loc_1858 = arg_93_302_479 + 1; + + *(GibPackedTag *) loc_1251 = 1; + + GibCursor writetag_2757 = loc_1251 + 1; + GibCursor after_tag_2758 = loc_1251 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_55; + + return_55.field0 = end_r_1253; + return_55.field1 = end_r_1255; + return_55.field2 = jump_loc_1858; + return_55.field3 = loc_1251; + return_55.field4 = after_tag_2758; + return return_55; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_58 = *(uintptr_t *) tmpcur_3844; + GibCursor tmpcur_3864 = GIB_UNTAG(tagged_tmpcur_58); + GibCursor tmpaftercur_3865 = tmpcur_3844 + 8; + uint16_t tmptag_3866 = GIB_GET_TAG(tagged_tmpcur_58); + GibCursor end_from_tagged_indr_2050 = tmpcur_3864 + tmptag_3866; + GibCursor jump_loc_2052 = tmpcur_3844 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_56 = + _copy_without_ptrs_ListA(tmpcur_3864, end_r_1255, loc_1251, tmpcur_3864); + GibCursor pvrtmp_3867 = tmp_struct_56.field0; + GibCursor pvrtmp_3868 = tmp_struct_56.field1; + GibCursor pvrtmp_3869 = tmp_struct_56.field2; + GibCursor pvrtmp_3870 = tmp_struct_56.field3; + GibCursor pvrtmp_3871 = tmp_struct_56.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_57; + + return_57.field0 = end_r_1253; + return_57.field1 = pvrtmp_3868; + return_57.field2 = jump_loc_2052; + return_57.field3 = pvrtmp_3870; + return_57.field4 = pvrtmp_3871; + return return_57; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_61 = *(uintptr_t *) tmpcur_3844; + GibCursor tmpcur_3878 = GIB_UNTAG(tagged_tmpcur_61); + GibCursor tmpaftercur_3879 = tmpcur_3844 + 8; + uint16_t tmptag_3880 = GIB_GET_TAG(tagged_tmpcur_61); + GibCursor end_from_tagged_indr_2050 = tmpcur_3878 + tmptag_3880; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_59 = + _copy_without_ptrs_ListA(tmpcur_3878, end_r_1255, loc_1251, tmpcur_3878); + GibCursor pvrtmp_3881 = tmp_struct_59.field0; + GibCursor pvrtmp_3882 = tmp_struct_59.field1; + GibCursor pvrtmp_3883 = tmp_struct_59.field2; + GibCursor pvrtmp_3884 = tmp_struct_59.field3; + GibCursor pvrtmp_3885 = tmp_struct_59.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_60; + + return_60.field0 = pvrtmp_3881; + return_60.field1 = pvrtmp_3882; + return_60.field2 = pvrtmp_3883; + return_60.field3 = pvrtmp_3884; + return_60.field4 = pvrtmp_3885; + return return_60; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3843"); + exit(1); + } + } +} + +GibCursorPtr7GibCursorPtr7GibIntProd reduceB(GibCursor cursor_ptr_2775[7], + GibCursor lst_36_307_484[7]) +{ + // GibCursor *end_r_1263 = &cursor_ptr_2775[0]; + // GibCursor *end_r_1264 = &cursor_ptr_2775[1]; + // GibCursor *end_r_1265 = &cursor_ptr_2775[2]; + // GibCursor *end_r_1266 = &cursor_ptr_2775[3]; + // GibCursor *end_r_1267 = &cursor_ptr_2775[4]; + // GibCursor *end_r_1268 = &cursor_ptr_2775[5]; + // GibCursor *end_r_1269 = &cursor_ptr_2775[6]; + + GibCursor *dcon_2778 = &lst_36_307_484[0]; + GibPackedTag tmpval_3893 = *(GibPackedTag *) (*dcon_2778); + + //GibCursor tmpcur_3894 = *dcon_2778 + 1; + *dcon_2778 += 1; + + switch_3958: + ; + switch (tmpval_3893) { + + case 1: + { + // GibCursor *soa_field_0_2780 = &lst_36_307_484[1]; + // GibCursor *soa_field_1_2781 = &lst_36_307_484[2]; + // GibCursor *soa_field_2_2782 = &lst_36_307_484[3]; + // GibCursor *soa_field_3_2783 = &lst_36_307_484[4]; + // GibCursor *soa_field_4_2784 = &lst_36_307_484[5]; + // GibCursor *soa_field_5_2785 = &lst_36_307_484[6]; + GibCursor *loc_1256 = &lst_36_307_484[0]; + + + //GibCursor jump_dloc_1861 = loc_1256 + 1; + *loc_1256 += 1; + + // GibCursor *loc_IntTy_1257 = &lst_36_307_484[1]; + // + // GibCursor *jump_floc_loc_1862 = loc_IntTy_1257; + // GibCursor *loc_IntTy_1258 = &lst_36_307_484[2]; + // GibCursor *jump_floc_loc_1863 = loc_IntTy_1258; + // GibCursor *loc_IntTy_1259 = &lst_36_307_484[3]; + // GibCursor *jump_floc_loc_1864 = loc_IntTy_1259; + // GibCursor *loc_IntTy_1260 = &lst_36_307_484[4]; + // GibCursor *jump_floc_loc_1865 = &loc_IntTy_1260; + // GibCursor *loc_IntTy_1261 = &lst_36_307_484[5]; + // GibCursor *jump_floc_loc_1866 = &loc_IntTy_1261; + // GibCursor *loc_IntTy_1262 = &lst_36_307_484[6]; + // GibCursor *jump_floc_loc_1867 = &loc_IntTy_1262; + + // GibCursor cursor_ptr_2787[7] = {jump_dloc_1861, jump_floc_loc_1862, + // jump_floc_loc_1863, + // jump_floc_loc_1864, + // jump_floc_loc_1865, + // jump_floc_loc_1866, + // jump_floc_loc_1867}; + GibCursorPtr7GibCursorPtr7GibIntProd return_62; + + //memcpy(return_62.field0, cursor_ptr_2775, sizeof(GibCursor [7])); + //memcpy(return_62.field1, lst_36_307_484, sizeof(GibCursor [7])); + return_62.field2 = 0; + return return_62; + //*Res += 0; + break; + } + + case 0: + { + GibCursor *soa_field_0_2789 = &lst_36_307_484[1]; + + // GibCursor *soa_field_1_2790 = &lst_36_307_484[2]; + // GibCursor *soa_field_2_2791 = &lst_36_307_484[3]; + // GibCursor *soa_field_3_2792 = &lst_36_307_484[4]; + // GibCursor *soa_field_4_2793 = &lst_36_307_484[5]; + // GibCursor *soa_field_5_2794 = &lst_36_307_484[6]; + + GibInt tmpval_3895 = *(GibInt *) (*soa_field_0_2789); + //GibCursor tmpcur_3896 = soa_field_0_2789 + sizeof(GibInt); + *soa_field_0_2789 += sizeof(GibInt); + + // *soa_field_1_2790 += sizeof(GibInt); + // *soa_field_2_2791 += sizeof(GibInt); + // *soa_field_3_2792 += sizeof(GibInt); + // *soa_field_4_2793 += sizeof(GibInt); + // *soa_field_5_2794 += sizeof(GibInt); + + // GibInt tmpval_3897 = *(GibInt *) soa_field_1_2790; + // //GibCursor tmpcur_3898 = soa_field_1_2790 + sizeof(GibInt); + // *soa_field_1_2790 += sizeof(GibInt); + // + // GibInt tmpval_3899 = *(GibInt *) soa_field_2_2791; + // //GibCursor tmpcur_3900 = soa_field_2_2791 + sizeof(GibInt); + // *soa_field_2_2791 += sizeof(GibInt); + // + // GibInt tmpval_3901 = *(GibInt *) soa_field_3_2792; + // //GibCursor tmpcur_3902 = soa_field_3_2792 + sizeof(GibInt); + // *soa_field_3_2792 += sizeof(GibInt); + // + // GibInt tmpval_3903 = *(GibInt *) soa_field_4_2793; + // //GibCursor tmpcur_3904 = soa_field_4_2793 + sizeof(GibInt); + // *soa_field_4_2793 += sizeof(GibInt); + // + // GibInt tmpval_3905 = *(GibInt *) soa_field_5_2794; + // //GibCursor tmpcur_3906 = soa_field_5_2794 + sizeof(GibInt); + // *soa_field_5_2794 += sizeof(GibInt); + + + // GibCursor cursor_ptr_2777[7] = {tmpcur_3894, tmpcur_3896, + // tmpcur_3898, tmpcur_3900, + // tmpcur_3902, tmpcur_3904, + // tmpcur_3906}; + // GibCursor loc_1256 = lst_36_307_484[0]; + // GibCursor jumpf_dloc_1868 = loc_1256 + 1; + // GibCursor loc_IntTy_1257 = lst_36_307_484[1]; + // GibCursor loc_IntTy_1258 = lst_36_307_484[2]; + // GibCursor loc_IntTy_1259 = lst_36_307_484[3]; + // GibCursor loc_IntTy_1260 = lst_36_307_484[4]; + // GibCursor loc_IntTy_1261 = lst_36_307_484[5]; + // GibCursor loc_IntTy_1262 = lst_36_307_484[6]; + // GibCursor jumpf_floc_loc_1869 = soa_field_0_2789 + 8; + // GibCursor jumpf_floc_loc_1870 = soa_field_1_2790 + 8; + // GibCursor jumpf_floc_loc_1871 = soa_field_2_2791 + 8; + // GibCursor jumpf_floc_loc_1872 = soa_field_3_2792 + 8; + // GibCursor jumpf_floc_loc_1873 = soa_field_4_2793 + 8; + // GibCursor jumpf_floc_loc_1874 = soa_field_5_2794 + 8; + // GibCursor loc_1561 = jumpf_dloc_1868 + 0; + // GibCursor loc_1560 = jumpf_floc_loc_1869 + 0; + // GibCursor cursor_ptr_2803[7] = {jumpf_dloc_1868, + // jumpf_floc_loc_1869, + // jumpf_floc_loc_1870, + // jumpf_floc_loc_1871, + // jumpf_floc_loc_1872, + // jumpf_floc_loc_1873, + // jumpf_floc_loc_1874}; + //*Res += tmpval_3895; + GibCursorPtr7GibCursorPtr7GibIntProd tmp_struct_63 = reduceB(cursor_ptr_2775, lst_36_307_484); + //GibCursor pvrtmp_3907[7]; + + //memcpy(pvrtmp_3907, tmp_struct_63.field0, sizeof(GibCursor [7])); + + //GibCursor pvrtmp_3908[7]; + + //memcpy(pvrtmp_3908, tmp_struct_63.field1, sizeof(GibCursor [7])); + + GibInt pvrtmp_3909 = tmp_struct_63.field2; + GibInt tailprim_1882 = tmpval_3895 + pvrtmp_3909; + GibCursorPtr7GibCursorPtr7GibIntProd return_64; + + //memcpy(return_64.field0, pvrtmp_3907, sizeof(GibCursor [7])); + //memcpy(return_64.field1, pvrtmp_3908, sizeof(GibCursor [7])); + return_64.field2 = tailprim_1882; + return return_64; + break; + } + + // case GIB_INDIRECTION_TAG: + // { + // GibCursor soa_field_0_2811 = lst_36_307_484[1]; + // GibCursor soa_field_1_2812 = lst_36_307_484[2]; + // GibCursor soa_field_2_2813 = lst_36_307_484[3]; + // GibCursor soa_field_3_2814 = lst_36_307_484[4]; + // GibCursor soa_field_4_2815 = lst_36_307_484[5]; + // GibCursor soa_field_5_2816 = lst_36_307_484[6]; + // uintptr_t tagged_tmpcur_73 = *(uintptr_t *) *dcon_2778; + // GibCursor tmpcur_3910 = GIB_UNTAG(tagged_tmpcur_73); + // GibCursor tmpaftercur_3911 = *dcon_2778 + 8; + // uint16_t tmptag_3912 = GIB_GET_TAG(tagged_tmpcur_73); + // GibCursor end_from_tagged_dcon_redir_2841 = tmpcur_3910 + + // tmptag_3912; + // GibCursor field_nxt_2834 = soa_field_0_2811 + 1; + // uintptr_t tagged_tmpcur_72 = *(uintptr_t *) field_nxt_2834; + // GibCursor tmpcur_3913 = GIB_UNTAG(tagged_tmpcur_72); + // GibCursor tmpaftercur_3914 = field_nxt_2834 + 8; + // uint16_t tmptag_3915 = GIB_GET_TAG(tagged_tmpcur_72); + // GibCursor end_from_tagged_fld_redir_2842 = tmpcur_3913 + + // tmptag_3915; + // GibCursor field_nxt_2835 = soa_field_1_2812 + 1; + // uintptr_t tagged_tmpcur_71 = *(uintptr_t *) field_nxt_2835; + // GibCursor tmpcur_3916 = GIB_UNTAG(tagged_tmpcur_71); + // GibCursor tmpaftercur_3917 = field_nxt_2835 + 8; + // uint16_t tmptag_3918 = GIB_GET_TAG(tagged_tmpcur_71); + // GibCursor end_from_tagged_fld_redir_2843 = tmpcur_3916 + + // tmptag_3918; + // GibCursor field_nxt_2836 = soa_field_2_2813 + 1; + // uintptr_t tagged_tmpcur_70 = *(uintptr_t *) field_nxt_2836; + // GibCursor tmpcur_3919 = GIB_UNTAG(tagged_tmpcur_70); + // GibCursor tmpaftercur_3920 = field_nxt_2836 + 8; + // uint16_t tmptag_3921 = GIB_GET_TAG(tagged_tmpcur_70); + // GibCursor end_from_tagged_fld_redir_2844 = tmpcur_3919 + + // tmptag_3921; + // GibCursor field_nxt_2837 = soa_field_3_2814 + 1; + // uintptr_t tagged_tmpcur_69 = *(uintptr_t *) field_nxt_2837; + // GibCursor tmpcur_3922 = GIB_UNTAG(tagged_tmpcur_69); + // GibCursor tmpaftercur_3923 = field_nxt_2837 + 8; + // uint16_t tmptag_3924 = GIB_GET_TAG(tagged_tmpcur_69); + // GibCursor end_from_tagged_fld_redir_2845 = tmpcur_3922 + + // tmptag_3924; + // GibCursor field_nxt_2838 = soa_field_4_2815 + 1; + // uintptr_t tagged_tmpcur_68 = *(uintptr_t *) field_nxt_2838; + // GibCursor tmpcur_3925 = GIB_UNTAG(tagged_tmpcur_68); + // GibCursor tmpaftercur_3926 = field_nxt_2838 + 8; + // uint16_t tmptag_3927 = GIB_GET_TAG(tagged_tmpcur_68); + // GibCursor end_from_tagged_fld_redir_2846 = tmpcur_3925 + + // tmptag_3927; + // GibCursor field_nxt_2839 = soa_field_5_2816 + 1; + // uintptr_t tagged_tmpcur_67 = *(uintptr_t *) field_nxt_2839; + // GibCursor tmpcur_3928 = GIB_UNTAG(tagged_tmpcur_67); + // GibCursor tmpaftercur_3929 = field_nxt_2839 + 8; + // uint16_t tmptag_3930 = GIB_GET_TAG(tagged_tmpcur_67); + // GibCursor end_from_tagged_fld_redir_2847 = tmpcur_3928 + + // tmptag_3930; + // GibCursor indr_2056[7] = {tmpcur_3910, tmpcur_3913, tmpcur_3916, + // tmpcur_3919, tmpcur_3922, tmpcur_3925, + // tmpcur_3928}; + // GibCursor loc_1256 = lst_36_307_484[0]; + // GibCursor jump_dloc_2064 = loc_1256 + 9; + // GibCursor loc_IntTy_1262 = lst_36_307_484[6]; + // GibCursor loc_IntTy_1261 = lst_36_307_484[5]; + // GibCursor loc_IntTy_1260 = lst_36_307_484[4]; + // GibCursor loc_IntTy_1259 = lst_36_307_484[3]; + // GibCursor loc_IntTy_1258 = lst_36_307_484[2]; + // GibCursor loc_IntTy_1257 = lst_36_307_484[1]; + // GibCursor aft_indir_loc_2080 = loc_IntTy_1257 + 9; + // GibCursor aft_indir_loc_2081 = loc_IntTy_1258 + 9; + // GibCursor aft_indir_loc_2082 = loc_IntTy_1259 + 9; + // GibCursor aft_indir_loc_2083 = loc_IntTy_1260 + 9; + // GibCursor aft_indir_loc_2084 = loc_IntTy_1261 + 9; + // GibCursor aft_indir_loc_2085 = loc_IntTy_1262 + 9; + // GibCursor cursor_ptr_2848[7] = {jump_dloc_2064, aft_indir_loc_2080, + // aft_indir_loc_2081, + // aft_indir_loc_2082, + // aft_indir_loc_2083, + // aft_indir_loc_2084, + // aft_indir_loc_2085}; + // GibCursorPtr7GibCursorPtr7GibIntProd tmp_struct_65 = + // reduceB(indr_2056, indr_2056); + // GibCursor pvrtmp_3931[7]; + // + // memcpy(pvrtmp_3931, tmp_struct_65.field0, sizeof(GibCursor [7])); + // + // GibCursor pvrtmp_3932[7]; + // + // memcpy(pvrtmp_3932, tmp_struct_65.field1, sizeof(GibCursor [7])); + // + // GibInt pvrtmp_3933 = tmp_struct_65.field2; + // GibCursorPtr7GibCursorPtr7GibIntProd return_66; + // + // memcpy(return_66.field0, cursor_ptr_2775, sizeof(GibCursor [7])); + // memcpy(return_66.field1, cursor_ptr_2848, sizeof(GibCursor [7])); + // return_66.field2 = pvrtmp_3933; + // return return_66; + // break; + // } + + case GIB_REDIRECTION_TAG: + { + GibCursor *soa_field_0_2856 = &lst_36_307_484[1]; + + + uintptr_t tagged_tmpcur_82 = *(uintptr_t *) (*dcon_2778); + GibCursor tmpcur_3934 = GIB_UNTAG(tagged_tmpcur_82); + *dcon_2778 = tmpcur_3934; + + // GibCursor tmpaftercur_3935 = *dcon_2778 + 8; + // uint16_t tmptag_3936 = GIB_GET_TAG(tagged_tmpcur_82); + // GibCursor end_from_tagged_dcon_redir_2877 = tmpcur_3934 + + // tmptag_3936; + + + //GibCursor field_nxt_2871 = soa_field_0_2856 + 1; + *soa_field_0_2856 += 1; + uintptr_t tagged_tmpcur_81 = *(uintptr_t *) (*soa_field_0_2856); + GibCursor tmpcur_3937 = GIB_UNTAG(tagged_tmpcur_81); + *soa_field_0_2856 = tmpcur_3937; + + + // GibCursor tmpaftercur_3938 = field_nxt_2871 + 8; + // uint16_t tmptag_3939 = GIB_GET_TAG(tagged_tmpcur_81); + // GibCursor end_from_tagged_fld_redir_2878 = tmpcur_3937 + + // tmptag_3939; + + + // GibCursor field_nxt_2872 = soa_field_1_2857 + 1; + // uintptr_t tagged_tmpcur_80 = *(uintptr_t *) field_nxt_2872; + // GibCursor tmpcur_3940 = GIB_UNTAG(tagged_tmpcur_80); + // GibCursor tmpaftercur_3941 = field_nxt_2872 + 8; + // uint16_t tmptag_3942 = GIB_GET_TAG(tagged_tmpcur_80); + // GibCursor end_from_tagged_fld_redir_2879 = tmpcur_3940 + + // tmptag_3942; + // GibCursor field_nxt_2873 = soa_field_2_2858 + 1; + // uintptr_t tagged_tmpcur_79 = *(uintptr_t *) field_nxt_2873; + // GibCursor tmpcur_3943 = GIB_UNTAG(tagged_tmpcur_79); + // GibCursor tmpaftercur_3944 = field_nxt_2873 + 8; + // uint16_t tmptag_3945 = GIB_GET_TAG(tagged_tmpcur_79); + // GibCursor end_from_tagged_fld_redir_2880 = tmpcur_3943 + + // tmptag_3945; + // GibCursor field_nxt_2874 = soa_field_3_2859 + 1; + // uintptr_t tagged_tmpcur_78 = *(uintptr_t *) field_nxt_2874; + // GibCursor tmpcur_3946 = GIB_UNTAG(tagged_tmpcur_78); + // GibCursor tmpaftercur_3947 = field_nxt_2874 + 8; + // uint16_t tmptag_3948 = GIB_GET_TAG(tagged_tmpcur_78); + // GibCursor end_from_tagged_fld_redir_2881 = tmpcur_3946 + + // tmptag_3948; + // GibCursor field_nxt_2875 = soa_field_4_2860 + 1; + // uintptr_t tagged_tmpcur_77 = *(uintptr_t *) field_nxt_2875; + // GibCursor tmpcur_3949 = GIB_UNTAG(tagged_tmpcur_77); + // GibCursor tmpaftercur_3950 = field_nxt_2875 + 8; + // uint16_t tmptag_3951 = GIB_GET_TAG(tagged_tmpcur_77); + // GibCursor end_from_tagged_fld_redir_2882 = tmpcur_3949 + + // tmptag_3951; + // GibCursor field_nxt_2876 = soa_field_5_2861 + 1; + // uintptr_t tagged_tmpcur_76 = *(uintptr_t *) field_nxt_2876; + // GibCursor tmpcur_3952 = GIB_UNTAG(tagged_tmpcur_76); + // GibCursor tmpaftercur_3953 = field_nxt_2876 + 8; + // uint16_t tmptag_3954 = GIB_GET_TAG(tagged_tmpcur_76); + // GibCursor end_from_tagged_fld_redir_2883 = tmpcur_3952 + + // tmptag_3954; + + + // GibCursor indr_2056[7] = {tmpcur_3934, tmpcur_3937, soa_field_1_2857, + // soa_field_2_2858, soa_field_3_2859, soa_field_4_2860, + // soa_field_5_2861}; + + return reduceB(lst_36_307_484, lst_36_307_484); + //GibCursor pvrtmp_3955[7]; + + //memcpy(pvrtmp_3955, tmp_struct_74.field0, sizeof(GibCursor [7])); + + //GibCursor pvrtmp_3956[7]; + + //memcpy(pvrtmp_3956, tmp_struct_74.field1, sizeof(GibCursor [7])); + + // GibInt pvrtmp_3957 = tmp_struct_74.field2; + // GibCursorPtr7GibCursorPtr7GibIntProd return_75; + + //memcpy(return_75.field0, pvrtmp_3955, sizeof(GibCursor [7])); + //memcpy(return_75.field1, pvrtmp_3956, sizeof(GibCursor [7])); + // return_75.field2 = pvrtmp_3957; + // return return_75; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3893"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_ListA(GibCursor end_r_1273, + GibCursor end_r_1275, + GibCursor loc_1271, + GibCursor arg_88_315_493) +{ + if (loc_1271 + 18 > end_r_1275) { + gib_grow_region(&loc_1271, &end_r_1275); + } + + GibPackedTag tmpval_3959 = *(GibPackedTag *) arg_88_315_493; + GibCursor tmpcur_3960 = arg_88_315_493 + 1; + + + switch_4008: + ; + switch (tmpval_3959) { + + case 0: + { + GibInt tmpval_3961 = *(GibInt *) tmpcur_3960; + GibCursor tmpcur_3962 = tmpcur_3960 + sizeof(GibInt); + GibCursor jump_1883 = tmpcur_3960 + 8; + GibCursor loc_1583 = loc_1271 + 1; + GibCursor loc_1584 = loc_1583 + 8; + + *(GibPackedTag *) loc_1271 = 0; + + GibCursor writetag_2896 = loc_1271 + 1; + GibCursor after_tag_2897 = loc_1271 + 1; + + *(GibInt *) after_tag_2897 = tmpval_3961; + + GibCursor writecur_2901 = after_tag_2897 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_83 = + _copy_ListA(end_r_1273, end_r_1275, loc_1584, tmpcur_3962); + GibCursor pvrtmp_3963 = tmp_struct_83.field0; + GibCursor pvrtmp_3964 = tmp_struct_83.field1; + GibCursor pvrtmp_3965 = tmp_struct_83.field2; + GibCursor pvrtmp_3966 = tmp_struct_83.field3; + GibCursor pvrtmp_3967 = tmp_struct_83.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_84; + + return_84.field0 = pvrtmp_3963; + return_84.field1 = pvrtmp_3964; + return_84.field2 = pvrtmp_3965; + return_84.field3 = loc_1271; + return_84.field4 = pvrtmp_3967; + return return_84; + break; + } + + case 1: + { + GibCursor jump_loc_1886 = arg_88_315_493 + 1; + + *(GibPackedTag *) loc_1271 = 1; + + GibCursor writetag_2906 = loc_1271 + 1; + GibCursor after_tag_2907 = loc_1271 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_85; + + return_85.field0 = end_r_1273; + return_85.field1 = end_r_1275; + return_85.field2 = jump_loc_1886; + return_85.field3 = loc_1271; + return_85.field4 = after_tag_2907; + return return_85; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_88 = *(uintptr_t *) tmpcur_3960; + GibCursor tmpcur_3980 = GIB_UNTAG(tagged_tmpcur_88); + GibCursor tmpaftercur_3981 = tmpcur_3960 + 8; + uint16_t tmptag_3982 = GIB_GET_TAG(tagged_tmpcur_88); + GibCursor end_from_tagged_indr_2086 = tmpcur_3980 + tmptag_3982; + GibCursor jump_loc_2088 = tmpcur_3960 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_86 = + _copy_ListA(tmpcur_3980, end_r_1275, loc_1271, tmpcur_3980); + GibCursor pvrtmp_3983 = tmp_struct_86.field0; + GibCursor pvrtmp_3984 = tmp_struct_86.field1; + GibCursor pvrtmp_3985 = tmp_struct_86.field2; + GibCursor pvrtmp_3986 = tmp_struct_86.field3; + GibCursor pvrtmp_3987 = tmp_struct_86.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_87; + + return_87.field0 = end_r_1273; + return_87.field1 = pvrtmp_3984; + return_87.field2 = jump_loc_2088; + return_87.field3 = pvrtmp_3986; + return_87.field4 = pvrtmp_3987; + return return_87; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_91 = *(uintptr_t *) tmpcur_3960; + GibCursor tmpcur_3994 = GIB_UNTAG(tagged_tmpcur_91); + GibCursor tmpaftercur_3995 = tmpcur_3960 + 8; + uint16_t tmptag_3996 = GIB_GET_TAG(tagged_tmpcur_91); + GibCursor end_from_tagged_indr_2086 = tmpcur_3994 + tmptag_3996; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_89 = + _copy_ListA(tmpcur_3994, end_r_1275, loc_1271, tmpcur_3994); + GibCursor pvrtmp_3997 = tmp_struct_89.field0; + GibCursor pvrtmp_3998 = tmp_struct_89.field1; + GibCursor pvrtmp_3999 = tmp_struct_89.field2; + GibCursor pvrtmp_4000 = tmp_struct_89.field3; + GibCursor pvrtmp_4001 = tmp_struct_89.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_90; + + return_90.field0 = pvrtmp_3997; + return_90.field1 = pvrtmp_3998; + return_90.field2 = pvrtmp_3999; + return_90.field3 = pvrtmp_4000; + return_90.field4 = pvrtmp_4001; + return return_90; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_3959"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod _copy_ListB(GibCursor cursor_ptr_2925[7], + GibCursor cursor_ptr_2924[7], + GibCursor cursor_ptr_2926[7], + GibCursor arg_176_330_498[7]) +{ + GibCursor end_r_1298 = cursor_ptr_2924[1]; + GibCursor end_r_1302 = cursor_ptr_2924[5]; + GibCursor end_r_1297 = cursor_ptr_2924[0]; + GibCursor end_r_1301 = cursor_ptr_2924[4]; + GibCursor end_r_1303 = cursor_ptr_2924[6]; + GibCursor end_r_1300 = cursor_ptr_2924[3]; + GibCursor end_r_1299 = cursor_ptr_2924[2]; + GibCursor loc_IntTy_1288 = cursor_ptr_2926[5]; + GibCursor loc_IntTy_1285 = cursor_ptr_2926[2]; + GibCursor loc_IntTy_1289 = cursor_ptr_2926[6]; + GibCursor loc_1283 = cursor_ptr_2926[0]; + GibCursor loc_IntTy_1286 = cursor_ptr_2926[3]; + GibCursor loc_IntTy_1284 = cursor_ptr_2926[1]; + GibCursor loc_IntTy_1287 = cursor_ptr_2926[4]; + + if (loc_IntTy_1289 + 17 > end_r_1303 || (loc_IntTy_1288 + 17 > end_r_1302 || + (loc_IntTy_1287 + 17 > + end_r_1301 || (loc_IntTy_1286 + + 17 > end_r_1300 || + (loc_IntTy_1285 + + 17 > end_r_1299 || + (loc_IntTy_1284 + + 17 > + end_r_1298 || + loc_1283 + 66 > + end_r_1297)))))) { + gib_grow_region(&loc_IntTy_1289, &end_r_1303); + gib_grow_region(&loc_IntTy_1288, &end_r_1302); + gib_grow_region(&loc_IntTy_1287, &end_r_1301); + gib_grow_region(&loc_IntTy_1286, &end_r_1300); + gib_grow_region(&loc_IntTy_1285, &end_r_1299); + gib_grow_region(&loc_IntTy_1284, &end_r_1298); + gib_grow_region(&loc_1283, &end_r_1297); + } + + GibCursor end_r_1290 = cursor_ptr_2925[0]; + GibCursor end_r_1291 = cursor_ptr_2925[1]; + GibCursor end_r_1292 = cursor_ptr_2925[2]; + GibCursor end_r_1293 = cursor_ptr_2925[3]; + GibCursor end_r_1294 = cursor_ptr_2925[4]; + GibCursor end_r_1295 = cursor_ptr_2925[5]; + GibCursor end_r_1296 = cursor_ptr_2925[6]; + GibCursor overwrite_reg_2927[7] = {end_r_1297, end_r_1298, end_r_1299, + end_r_1300, end_r_1301, end_r_1302, + end_r_1303}; + GibCursor dcon_2930 = arg_176_330_498[0]; + GibPackedTag tmpval_4009 = *(GibPackedTag *) dcon_2930; + GibCursor tmpcur_4010 = dcon_2930 + 1; + + + switch_4104: + ; + switch (tmpval_4009) { + + case 0: + { + GibCursor soa_field_0_2932 = arg_176_330_498[1]; + GibCursor soa_field_1_2933 = arg_176_330_498[2]; + GibCursor soa_field_2_2934 = arg_176_330_498[3]; + GibCursor soa_field_3_2935 = arg_176_330_498[4]; + GibCursor soa_field_4_2936 = arg_176_330_498[5]; + GibCursor soa_field_5_2937 = arg_176_330_498[6]; + GibInt tmpval_4011 = *(GibInt *) soa_field_0_2932; + GibCursor tmpcur_4012 = soa_field_0_2932 + sizeof(GibInt); + GibInt tmpval_4013 = *(GibInt *) soa_field_1_2933; + GibCursor tmpcur_4014 = soa_field_1_2933 + sizeof(GibInt); + GibInt tmpval_4015 = *(GibInt *) soa_field_2_2934; + GibCursor tmpcur_4016 = soa_field_2_2934 + sizeof(GibInt); + GibInt tmpval_4017 = *(GibInt *) soa_field_3_2935; + GibCursor tmpcur_4018 = soa_field_3_2935 + sizeof(GibInt); + GibInt tmpval_4019 = *(GibInt *) soa_field_4_2936; + GibCursor tmpcur_4020 = soa_field_4_2936 + sizeof(GibInt); + GibInt tmpval_4021 = *(GibInt *) soa_field_5_2937; + GibCursor tmpcur_4022 = soa_field_5_2937 + sizeof(GibInt); + GibCursor cursor_ptr_2929[7] = {tmpcur_4010, tmpcur_4012, + tmpcur_4014, tmpcur_4016, + tmpcur_4018, tmpcur_4020, + tmpcur_4022}; + GibCursor loc_1276 = arg_176_330_498[0]; + GibCursor jumpf_dloc_1888 = loc_1276 + 1; + GibCursor loc_IntTy_1277 = arg_176_330_498[1]; + GibCursor loc_IntTy_1278 = arg_176_330_498[2]; + GibCursor loc_IntTy_1279 = arg_176_330_498[3]; + GibCursor loc_IntTy_1280 = arg_176_330_498[4]; + GibCursor loc_IntTy_1281 = arg_176_330_498[5]; + GibCursor loc_IntTy_1282 = arg_176_330_498[6]; + GibCursor jumpf_floc_loc_1889 = soa_field_0_2932 + 8; + GibCursor jumpf_floc_loc_1890 = soa_field_1_2933 + 8; + GibCursor jumpf_floc_loc_1891 = soa_field_2_2934 + 8; + GibCursor jumpf_floc_loc_1892 = soa_field_3_2935 + 8; + GibCursor jumpf_floc_loc_1893 = soa_field_4_2936 + 8; + GibCursor jumpf_floc_loc_1894 = soa_field_5_2937 + 8; + GibCursor loc_1603 = jumpf_dloc_1888 + 0; + GibCursor loc_1602 = jumpf_floc_loc_1889 + 0; + GibCursor cursor_ptr_2946[7] = {jumpf_dloc_1888, + jumpf_floc_loc_1889, + jumpf_floc_loc_1890, + jumpf_floc_loc_1891, + jumpf_floc_loc_1892, + jumpf_floc_loc_1893, + jumpf_floc_loc_1894}; + GibCursor new_floc_loc_1632 = loc_IntTy_1284 + 8; + GibCursor new_floc_loc_1635 = loc_IntTy_1287 + 8; + GibCursor new_floc_loc_1634 = loc_IntTy_1286 + 8; + GibCursor new_dloc_1631 = loc_1283 + 1; + GibCursor new_floc_loc_1637 = loc_IntTy_1289 + 8; + GibCursor new_floc_loc_1633 = loc_IntTy_1285 + 8; + GibCursor new_floc_loc_1636 = loc_IntTy_1288 + 8; + GibCursor cursor_ptr_2947[7] = {new_dloc_1631, new_floc_loc_1632, + new_floc_loc_1633, + new_floc_loc_1634, + new_floc_loc_1635, + new_floc_loc_1636, + new_floc_loc_1637}; + + *(GibPackedTag *) loc_1283 = 0; + + GibCursor writetag_2957 = loc_1283 + 1; + GibCursor after_tag_2958 = loc_1283 + 1; + + *(GibInt *) loc_IntTy_1284 = tmpval_4011; + + GibCursor writecur_2962 = loc_IntTy_1284 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1285 = tmpval_4013; + + GibCursor writecur_2964 = loc_IntTy_1285 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1286 = tmpval_4015; + + GibCursor writecur_2966 = loc_IntTy_1286 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1287 = tmpval_4017; + + GibCursor writecur_2968 = loc_IntTy_1287 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1288 = tmpval_4019; + + GibCursor writecur_2970 = loc_IntTy_1288 + sizeof(GibInt); + + *(GibInt *) loc_IntTy_1289 = tmpval_4021; + + GibCursor writecur_2972 = loc_IntTy_1289 + sizeof(GibInt); + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_95 = + _copy_ListB(cursor_ptr_2925, overwrite_reg_2927, cursor_ptr_2947, cursor_ptr_2929); + GibCursor pvrtmp_4023[7]; + + memcpy(pvrtmp_4023, tmp_struct_95.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4024[7]; + + memcpy(pvrtmp_4024, tmp_struct_95.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4025[7]; + + memcpy(pvrtmp_4025, tmp_struct_95.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4026[7]; + + memcpy(pvrtmp_4026, tmp_struct_95.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4027[7]; + + memcpy(pvrtmp_4027, tmp_struct_95.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_96; + + memcpy(return_96.field0, pvrtmp_4023, sizeof(GibCursor [7])); + memcpy(return_96.field1, pvrtmp_4024, sizeof(GibCursor [7])); + memcpy(return_96.field2, pvrtmp_4025, sizeof(GibCursor [7])); + memcpy(return_96.field3, cursor_ptr_2926, sizeof(GibCursor [7])); + memcpy(return_96.field4, pvrtmp_4027, sizeof(GibCursor [7])); + return return_96; + break; + } + + case 1: + { + GibCursor soa_field_0_2978 = arg_176_330_498[1]; + GibCursor soa_field_1_2979 = arg_176_330_498[2]; + GibCursor soa_field_2_2980 = arg_176_330_498[3]; + GibCursor soa_field_3_2981 = arg_176_330_498[4]; + GibCursor soa_field_4_2982 = arg_176_330_498[5]; + GibCursor soa_field_5_2983 = arg_176_330_498[6]; + GibCursor loc_1276 = arg_176_330_498[0]; + GibCursor jump_dloc_1903 = loc_1276 + 1; + GibCursor loc_IntTy_1277 = arg_176_330_498[1]; + GibCursor jump_floc_loc_1904 = loc_IntTy_1277 + 0; + GibCursor loc_IntTy_1278 = arg_176_330_498[2]; + GibCursor jump_floc_loc_1905 = loc_IntTy_1278 + 0; + GibCursor loc_IntTy_1279 = arg_176_330_498[3]; + GibCursor jump_floc_loc_1906 = loc_IntTy_1279 + 0; + GibCursor loc_IntTy_1280 = arg_176_330_498[4]; + GibCursor jump_floc_loc_1907 = loc_IntTy_1280 + 0; + GibCursor loc_IntTy_1281 = arg_176_330_498[5]; + GibCursor jump_floc_loc_1908 = loc_IntTy_1281 + 0; + GibCursor loc_IntTy_1282 = arg_176_330_498[6]; + GibCursor jump_floc_loc_1909 = loc_IntTy_1282 + 0; + GibCursor cursor_ptr_2985[7] = {jump_dloc_1903, jump_floc_loc_1904, + jump_floc_loc_1905, + jump_floc_loc_1906, + jump_floc_loc_1907, + jump_floc_loc_1908, + jump_floc_loc_1909}; + GibCursor new_floc_loc_1632 = loc_IntTy_1284 + 8; + GibCursor new_floc_loc_1635 = loc_IntTy_1287 + 8; + GibCursor new_floc_loc_1634 = loc_IntTy_1286 + 8; + GibCursor new_dloc_1631 = loc_1283 + 1; + GibCursor new_floc_loc_1637 = loc_IntTy_1289 + 8; + GibCursor new_floc_loc_1633 = loc_IntTy_1285 + 8; + GibCursor new_floc_loc_1636 = loc_IntTy_1288 + 8; + + *(GibPackedTag *) loc_1283 = 1; + + GibCursor writetag_2986 = loc_1283 + 1; + GibCursor after_tag_2987 = loc_1283 + 1; + GibCursor aft_soa_loc_2991[7] = {after_tag_2987, loc_IntTy_1284, + loc_IntTy_1285, loc_IntTy_1286, + loc_IntTy_1287, loc_IntTy_1288, + loc_IntTy_1289}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_97; + + memcpy(return_97.field0, cursor_ptr_2925, sizeof(GibCursor [7])); + memcpy(return_97.field1, overwrite_reg_2927, sizeof(GibCursor [7])); + memcpy(return_97.field2, cursor_ptr_2985, sizeof(GibCursor [7])); + memcpy(return_97.field3, cursor_ptr_2926, sizeof(GibCursor [7])); + memcpy(return_97.field4, aft_soa_loc_2991, sizeof(GibCursor [7])); + return return_97; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_2995 = arg_176_330_498[1]; + GibCursor soa_field_1_2996 = arg_176_330_498[2]; + GibCursor soa_field_2_2997 = arg_176_330_498[3]; + GibCursor soa_field_3_2998 = arg_176_330_498[4]; + GibCursor soa_field_4_2999 = arg_176_330_498[5]; + GibCursor soa_field_5_3000 = arg_176_330_498[6]; + uintptr_t tagged_tmpcur_106 = *(uintptr_t *) tmpcur_4010; + GibCursor tmpcur_4040 = GIB_UNTAG(tagged_tmpcur_106); + GibCursor tmpaftercur_4041 = tmpcur_4010 + 8; + uint16_t tmptag_4042 = GIB_GET_TAG(tagged_tmpcur_106); + GibCursor end_from_tagged_dcon_redir_3025 = tmpcur_4040 + + tmptag_4042; + GibCursor field_nxt_3018 = soa_field_0_2995 + 1; + uintptr_t tagged_tmpcur_105 = *(uintptr_t *) field_nxt_3018; + GibCursor tmpcur_4043 = GIB_UNTAG(tagged_tmpcur_105); + GibCursor tmpaftercur_4044 = field_nxt_3018 + 8; + uint16_t tmptag_4045 = GIB_GET_TAG(tagged_tmpcur_105); + GibCursor end_from_tagged_fld_redir_3026 = tmpcur_4043 + + tmptag_4045; + GibCursor field_nxt_3019 = soa_field_1_2996 + 1; + uintptr_t tagged_tmpcur_104 = *(uintptr_t *) field_nxt_3019; + GibCursor tmpcur_4046 = GIB_UNTAG(tagged_tmpcur_104); + GibCursor tmpaftercur_4047 = field_nxt_3019 + 8; + uint16_t tmptag_4048 = GIB_GET_TAG(tagged_tmpcur_104); + GibCursor end_from_tagged_fld_redir_3027 = tmpcur_4046 + + tmptag_4048; + GibCursor field_nxt_3020 = soa_field_2_2997 + 1; + uintptr_t tagged_tmpcur_103 = *(uintptr_t *) field_nxt_3020; + GibCursor tmpcur_4049 = GIB_UNTAG(tagged_tmpcur_103); + GibCursor tmpaftercur_4050 = field_nxt_3020 + 8; + uint16_t tmptag_4051 = GIB_GET_TAG(tagged_tmpcur_103); + GibCursor end_from_tagged_fld_redir_3028 = tmpcur_4049 + + tmptag_4051; + GibCursor field_nxt_3021 = soa_field_3_2998 + 1; + uintptr_t tagged_tmpcur_102 = *(uintptr_t *) field_nxt_3021; + GibCursor tmpcur_4052 = GIB_UNTAG(tagged_tmpcur_102); + GibCursor tmpaftercur_4053 = field_nxt_3021 + 8; + uint16_t tmptag_4054 = GIB_GET_TAG(tagged_tmpcur_102); + GibCursor end_from_tagged_fld_redir_3029 = tmpcur_4052 + + tmptag_4054; + GibCursor field_nxt_3022 = soa_field_4_2999 + 1; + uintptr_t tagged_tmpcur_101 = *(uintptr_t *) field_nxt_3022; + GibCursor tmpcur_4055 = GIB_UNTAG(tagged_tmpcur_101); + GibCursor tmpaftercur_4056 = field_nxt_3022 + 8; + uint16_t tmptag_4057 = GIB_GET_TAG(tagged_tmpcur_101); + GibCursor end_from_tagged_fld_redir_3030 = tmpcur_4055 + + tmptag_4057; + GibCursor field_nxt_3023 = soa_field_5_3000 + 1; + uintptr_t tagged_tmpcur_100 = *(uintptr_t *) field_nxt_3023; + GibCursor tmpcur_4058 = GIB_UNTAG(tagged_tmpcur_100); + GibCursor tmpaftercur_4059 = field_nxt_3023 + 8; + uint16_t tmptag_4060 = GIB_GET_TAG(tagged_tmpcur_100); + GibCursor end_from_tagged_fld_redir_3031 = tmpcur_4058 + + tmptag_4060; + GibCursor indr_2092[7] = {tmpcur_4040, tmpcur_4043, tmpcur_4046, + tmpcur_4049, tmpcur_4052, tmpcur_4055, + tmpcur_4058}; + GibCursor loc_1276 = arg_176_330_498[0]; + GibCursor jump_dloc_2100 = loc_1276 + 9; + GibCursor loc_IntTy_1282 = arg_176_330_498[6]; + GibCursor loc_IntTy_1281 = arg_176_330_498[5]; + GibCursor loc_IntTy_1280 = arg_176_330_498[4]; + GibCursor loc_IntTy_1279 = arg_176_330_498[3]; + GibCursor loc_IntTy_1278 = arg_176_330_498[2]; + GibCursor loc_IntTy_1277 = arg_176_330_498[1]; + GibCursor aft_indir_loc_2116 = loc_IntTy_1277 + 9; + GibCursor aft_indir_loc_2117 = loc_IntTy_1278 + 9; + GibCursor aft_indir_loc_2118 = loc_IntTy_1279 + 9; + GibCursor aft_indir_loc_2119 = loc_IntTy_1280 + 9; + GibCursor aft_indir_loc_2120 = loc_IntTy_1281 + 9; + GibCursor aft_indir_loc_2121 = loc_IntTy_1282 + 9; + GibCursor cursor_ptr_3032[7] = {jump_dloc_2100, aft_indir_loc_2116, + aft_indir_loc_2117, + aft_indir_loc_2118, + aft_indir_loc_2119, + aft_indir_loc_2120, + aft_indir_loc_2121}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_98 = + _copy_ListB(indr_2092, overwrite_reg_2927, cursor_ptr_2926, indr_2092); + GibCursor pvrtmp_4061[7]; + + memcpy(pvrtmp_4061, tmp_struct_98.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4062[7]; + + memcpy(pvrtmp_4062, tmp_struct_98.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4063[7]; + + memcpy(pvrtmp_4063, tmp_struct_98.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4064[7]; + + memcpy(pvrtmp_4064, tmp_struct_98.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4065[7]; + + memcpy(pvrtmp_4065, tmp_struct_98.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_99; + + memcpy(return_99.field0, cursor_ptr_2925, sizeof(GibCursor [7])); + memcpy(return_99.field1, pvrtmp_4062, sizeof(GibCursor [7])); + memcpy(return_99.field2, cursor_ptr_3032, sizeof(GibCursor [7])); + memcpy(return_99.field3, pvrtmp_4064, sizeof(GibCursor [7])); + memcpy(return_99.field4, pvrtmp_4065, sizeof(GibCursor [7])); + return return_99; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_3043 = arg_176_330_498[1]; + GibCursor soa_field_1_3044 = arg_176_330_498[2]; + GibCursor soa_field_2_3045 = arg_176_330_498[3]; + GibCursor soa_field_3_3046 = arg_176_330_498[4]; + GibCursor soa_field_4_3047 = arg_176_330_498[5]; + GibCursor soa_field_5_3048 = arg_176_330_498[6]; + uintptr_t tagged_tmpcur_115 = *(uintptr_t *) tmpcur_4010; + GibCursor tmpcur_4072 = GIB_UNTAG(tagged_tmpcur_115); + GibCursor tmpaftercur_4073 = tmpcur_4010 + 8; + uint16_t tmptag_4074 = GIB_GET_TAG(tagged_tmpcur_115); + GibCursor end_from_tagged_dcon_redir_3064 = tmpcur_4072 + + tmptag_4074; + GibCursor field_nxt_3058 = soa_field_0_3043 + 1; + uintptr_t tagged_tmpcur_114 = *(uintptr_t *) field_nxt_3058; + GibCursor tmpcur_4075 = GIB_UNTAG(tagged_tmpcur_114); + GibCursor tmpaftercur_4076 = field_nxt_3058 + 8; + uint16_t tmptag_4077 = GIB_GET_TAG(tagged_tmpcur_114); + GibCursor end_from_tagged_fld_redir_3065 = tmpcur_4075 + + tmptag_4077; + GibCursor field_nxt_3059 = soa_field_1_3044 + 1; + uintptr_t tagged_tmpcur_113 = *(uintptr_t *) field_nxt_3059; + GibCursor tmpcur_4078 = GIB_UNTAG(tagged_tmpcur_113); + GibCursor tmpaftercur_4079 = field_nxt_3059 + 8; + uint16_t tmptag_4080 = GIB_GET_TAG(tagged_tmpcur_113); + GibCursor end_from_tagged_fld_redir_3066 = tmpcur_4078 + + tmptag_4080; + GibCursor field_nxt_3060 = soa_field_2_3045 + 1; + uintptr_t tagged_tmpcur_112 = *(uintptr_t *) field_nxt_3060; + GibCursor tmpcur_4081 = GIB_UNTAG(tagged_tmpcur_112); + GibCursor tmpaftercur_4082 = field_nxt_3060 + 8; + uint16_t tmptag_4083 = GIB_GET_TAG(tagged_tmpcur_112); + GibCursor end_from_tagged_fld_redir_3067 = tmpcur_4081 + + tmptag_4083; + GibCursor field_nxt_3061 = soa_field_3_3046 + 1; + uintptr_t tagged_tmpcur_111 = *(uintptr_t *) field_nxt_3061; + GibCursor tmpcur_4084 = GIB_UNTAG(tagged_tmpcur_111); + GibCursor tmpaftercur_4085 = field_nxt_3061 + 8; + uint16_t tmptag_4086 = GIB_GET_TAG(tagged_tmpcur_111); + GibCursor end_from_tagged_fld_redir_3068 = tmpcur_4084 + + tmptag_4086; + GibCursor field_nxt_3062 = soa_field_4_3047 + 1; + uintptr_t tagged_tmpcur_110 = *(uintptr_t *) field_nxt_3062; + GibCursor tmpcur_4087 = GIB_UNTAG(tagged_tmpcur_110); + GibCursor tmpaftercur_4088 = field_nxt_3062 + 8; + uint16_t tmptag_4089 = GIB_GET_TAG(tagged_tmpcur_110); + GibCursor end_from_tagged_fld_redir_3069 = tmpcur_4087 + + tmptag_4089; + GibCursor field_nxt_3063 = soa_field_5_3048 + 1; + uintptr_t tagged_tmpcur_109 = *(uintptr_t *) field_nxt_3063; + GibCursor tmpcur_4090 = GIB_UNTAG(tagged_tmpcur_109); + GibCursor tmpaftercur_4091 = field_nxt_3063 + 8; + uint16_t tmptag_4092 = GIB_GET_TAG(tagged_tmpcur_109); + GibCursor end_from_tagged_fld_redir_3070 = tmpcur_4090 + + tmptag_4092; + GibCursor indr_2092[7] = {tmpcur_4072, tmpcur_4075, tmpcur_4078, + tmpcur_4081, tmpcur_4084, tmpcur_4087, + tmpcur_4090}; + GibCursor copy_dloc_2122 = loc_1283 + 0; + GibCursor copy_floc_loc_2128 = loc_IntTy_1289 + 0; + GibCursor copy_floc_loc_2127 = loc_IntTy_1288 + 0; + GibCursor copy_floc_loc_2126 = loc_IntTy_1287 + 0; + GibCursor copy_floc_loc_2125 = loc_IntTy_1286 + 0; + GibCursor copy_floc_loc_2124 = loc_IntTy_1285 + 0; + GibCursor copy_floc_loc_2123 = loc_IntTy_1284 + 0; + GibCursor cursor_ptr_3071[7] = {copy_dloc_2122, copy_floc_loc_2123, + copy_floc_loc_2124, + copy_floc_loc_2125, + copy_floc_loc_2126, + copy_floc_loc_2127, + copy_floc_loc_2128}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + tmp_struct_107 = + _copy_ListB(indr_2092, overwrite_reg_2927, cursor_ptr_3071, indr_2092); + GibCursor pvrtmp_4093[7]; + + memcpy(pvrtmp_4093, tmp_struct_107.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4094[7]; + + memcpy(pvrtmp_4094, tmp_struct_107.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4095[7]; + + memcpy(pvrtmp_4095, tmp_struct_107.field2, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4096[7]; + + memcpy(pvrtmp_4096, tmp_struct_107.field3, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4097[7]; + + memcpy(pvrtmp_4097, tmp_struct_107.field4, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod + return_108; + + memcpy(return_108.field0, pvrtmp_4093, sizeof(GibCursor [7])); + memcpy(return_108.field1, pvrtmp_4094, sizeof(GibCursor [7])); + memcpy(return_108.field2, pvrtmp_4095, sizeof(GibCursor [7])); + memcpy(return_108.field3, pvrtmp_4096, sizeof(GibCursor [7])); + memcpy(return_108.field4, pvrtmp_4097, sizeof(GibCursor [7])); + return return_108; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4009"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_List(GibCursor end_r_1307, + GibCursor end_r_1309, + GibCursor loc_1305, + GibCursor arg_114_345_513) +{ + if (loc_1305 + 42 > end_r_1309) { + gib_grow_region(&loc_1305, &end_r_1309); + } + + GibPackedTag tmpval_4105 = *(GibPackedTag *) arg_114_345_513; + GibCursor tmpcur_4106 = arg_114_345_513 + 1; + + + switch_4169: + ; + switch (tmpval_4105) { + + case 0: + { + GibInt tmpval_4107 = *(GibInt *) tmpcur_4106; + GibCursor tmpcur_4108 = tmpcur_4106 + sizeof(GibInt); + GibInt tmpval_4109 = *(GibInt *) tmpcur_4108; + GibCursor tmpcur_4110 = tmpcur_4108 + sizeof(GibInt); + GibInt tmpval_4111 = *(GibInt *) tmpcur_4110; + GibCursor tmpcur_4112 = tmpcur_4110 + sizeof(GibInt); + GibInt tmpval_4113 = *(GibInt *) tmpcur_4112; + GibCursor tmpcur_4114 = tmpcur_4112 + sizeof(GibInt); + GibCursor jump_1914 = tmpcur_4112 + 8; + GibCursor jump_1913 = tmpcur_4110 + 8; + GibCursor jump_1912 = tmpcur_4108 + 8; + GibCursor jump_1911 = tmpcur_4106 + 8; + GibCursor loc_1678 = loc_1305 + 1; + GibCursor loc_1679 = loc_1678 + 8; + GibCursor loc_1680 = loc_1679 + 8; + GibCursor loc_1681 = loc_1680 + 8; + GibCursor loc_1682 = loc_1681 + 8; + + *(GibPackedTag *) loc_1305 = 0; + + GibCursor writetag_3093 = loc_1305 + 1; + GibCursor after_tag_3094 = loc_1305 + 1; + + *(GibInt *) after_tag_3094 = tmpval_4107; + + GibCursor writecur_3098 = after_tag_3094 + sizeof(GibInt); + + *(GibInt *) writecur_3098 = tmpval_4109; + + GibCursor writecur_3099 = writecur_3098 + sizeof(GibInt); + + *(GibInt *) writecur_3099 = tmpval_4111; + + GibCursor writecur_3100 = writecur_3099 + sizeof(GibInt); + + *(GibInt *) writecur_3100 = tmpval_4113; + + GibCursor writecur_3101 = writecur_3100 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_116 = + _copy_ListA(end_r_1307, end_r_1309, loc_1682, tmpcur_4114); + GibCursor pvrtmp_4115 = tmp_struct_116.field0; + GibCursor pvrtmp_4116 = tmp_struct_116.field1; + GibCursor pvrtmp_4117 = tmp_struct_116.field2; + GibCursor pvrtmp_4118 = tmp_struct_116.field3; + GibCursor pvrtmp_4119 = tmp_struct_116.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_117 = + _copy_List(pvrtmp_4115, pvrtmp_4116, pvrtmp_4119, pvrtmp_4117); + GibCursor pvrtmp_4124 = tmp_struct_117.field0; + GibCursor pvrtmp_4125 = tmp_struct_117.field1; + GibCursor pvrtmp_4126 = tmp_struct_117.field2; + GibCursor pvrtmp_4127 = tmp_struct_117.field3; + GibCursor pvrtmp_4128 = tmp_struct_117.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_118; + + return_118.field0 = pvrtmp_4124; + return_118.field1 = pvrtmp_4125; + return_118.field2 = pvrtmp_4126; + return_118.field3 = loc_1305; + return_118.field4 = pvrtmp_4128; + return return_118; + break; + } + + case 1: + { + GibCursor jump_loc_1918 = arg_114_345_513 + 1; + + *(GibPackedTag *) loc_1305 = 1; + + GibCursor writetag_3108 = loc_1305 + 1; + GibCursor after_tag_3109 = loc_1305 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_119; + + return_119.field0 = end_r_1307; + return_119.field1 = end_r_1309; + return_119.field2 = jump_loc_1918; + return_119.field3 = loc_1305; + return_119.field4 = after_tag_3109; + return return_119; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_122 = *(uintptr_t *) tmpcur_4106; + GibCursor tmpcur_4141 = GIB_UNTAG(tagged_tmpcur_122); + GibCursor tmpaftercur_4142 = tmpcur_4106 + 8; + uint16_t tmptag_4143 = GIB_GET_TAG(tagged_tmpcur_122); + GibCursor end_from_tagged_indr_2129 = tmpcur_4141 + tmptag_4143; + GibCursor jump_loc_2131 = tmpcur_4106 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_120 = + _copy_List(tmpcur_4141, end_r_1309, loc_1305, tmpcur_4141); + GibCursor pvrtmp_4144 = tmp_struct_120.field0; + GibCursor pvrtmp_4145 = tmp_struct_120.field1; + GibCursor pvrtmp_4146 = tmp_struct_120.field2; + GibCursor pvrtmp_4147 = tmp_struct_120.field3; + GibCursor pvrtmp_4148 = tmp_struct_120.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_121; + + return_121.field0 = end_r_1307; + return_121.field1 = pvrtmp_4145; + return_121.field2 = jump_loc_2131; + return_121.field3 = pvrtmp_4147; + return_121.field4 = pvrtmp_4148; + return return_121; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_125 = *(uintptr_t *) tmpcur_4106; + GibCursor tmpcur_4155 = GIB_UNTAG(tagged_tmpcur_125); + GibCursor tmpaftercur_4156 = tmpcur_4106 + 8; + uint16_t tmptag_4157 = GIB_GET_TAG(tagged_tmpcur_125); + GibCursor end_from_tagged_indr_2129 = tmpcur_4155 + tmptag_4157; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_123 = + _copy_List(tmpcur_4155, end_r_1309, loc_1305, tmpcur_4155); + GibCursor pvrtmp_4158 = tmp_struct_123.field0; + GibCursor pvrtmp_4159 = tmp_struct_123.field1; + GibCursor pvrtmp_4160 = tmp_struct_123.field2; + GibCursor pvrtmp_4161 = tmp_struct_123.field3; + GibCursor pvrtmp_4162 = tmp_struct_123.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_124; + + return_124.field0 = pvrtmp_4158; + return_124.field1 = pvrtmp_4159; + return_124.field2 = pvrtmp_4160; + return_124.field3 = pvrtmp_4161; + return_124.field4 = pvrtmp_4162; + return return_124; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4105"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7Prod _traverse_ListB(GibCursor cursor_ptr_3126[7], + GibCursor arg_206_358_526[7]) +{ + GibCursor end_r_1317 = cursor_ptr_3126[0]; + GibCursor end_r_1318 = cursor_ptr_3126[1]; + GibCursor end_r_1319 = cursor_ptr_3126[2]; + GibCursor end_r_1320 = cursor_ptr_3126[3]; + GibCursor end_r_1321 = cursor_ptr_3126[4]; + GibCursor end_r_1322 = cursor_ptr_3126[5]; + GibCursor end_r_1323 = cursor_ptr_3126[6]; + GibCursor dcon_3129 = arg_206_358_526[0]; + GibPackedTag tmpval_4170 = *(GibPackedTag *) dcon_3129; + GibCursor tmpcur_4171 = dcon_3129 + 1; + + + switch_4232: + ; + switch (tmpval_4170) { + + case 0: + { + GibCursor soa_field_0_3131 = arg_206_358_526[1]; + GibCursor soa_field_1_3132 = arg_206_358_526[2]; + GibCursor soa_field_2_3133 = arg_206_358_526[3]; + GibCursor soa_field_3_3134 = arg_206_358_526[4]; + GibCursor soa_field_4_3135 = arg_206_358_526[5]; + GibCursor soa_field_5_3136 = arg_206_358_526[6]; + GibInt tmpval_4172 = *(GibInt *) soa_field_0_3131; + GibCursor tmpcur_4173 = soa_field_0_3131 + sizeof(GibInt); + GibInt tmpval_4174 = *(GibInt *) soa_field_1_3132; + GibCursor tmpcur_4175 = soa_field_1_3132 + sizeof(GibInt); + GibInt tmpval_4176 = *(GibInt *) soa_field_2_3133; + GibCursor tmpcur_4177 = soa_field_2_3133 + sizeof(GibInt); + GibInt tmpval_4178 = *(GibInt *) soa_field_3_3134; + GibCursor tmpcur_4179 = soa_field_3_3134 + sizeof(GibInt); + GibInt tmpval_4180 = *(GibInt *) soa_field_4_3135; + GibCursor tmpcur_4181 = soa_field_4_3135 + sizeof(GibInt); + GibInt tmpval_4182 = *(GibInt *) soa_field_5_3136; + GibCursor tmpcur_4183 = soa_field_5_3136 + sizeof(GibInt); + GibCursor cursor_ptr_3128[7] = {tmpcur_4171, tmpcur_4173, + tmpcur_4175, tmpcur_4177, + tmpcur_4179, tmpcur_4181, + tmpcur_4183}; + GibCursor loc_1310 = arg_206_358_526[0]; + GibCursor jumpf_dloc_1920 = loc_1310 + 1; + GibCursor loc_IntTy_1311 = arg_206_358_526[1]; + GibCursor loc_IntTy_1312 = arg_206_358_526[2]; + GibCursor loc_IntTy_1313 = arg_206_358_526[3]; + GibCursor loc_IntTy_1314 = arg_206_358_526[4]; + GibCursor loc_IntTy_1315 = arg_206_358_526[5]; + GibCursor loc_IntTy_1316 = arg_206_358_526[6]; + GibCursor jumpf_floc_loc_1921 = soa_field_0_3131 + 8; + GibCursor jumpf_floc_loc_1922 = soa_field_1_3132 + 8; + GibCursor jumpf_floc_loc_1923 = soa_field_2_3133 + 8; + GibCursor jumpf_floc_loc_1924 = soa_field_3_3134 + 8; + GibCursor jumpf_floc_loc_1925 = soa_field_4_3135 + 8; + GibCursor jumpf_floc_loc_1926 = soa_field_5_3136 + 8; + GibCursor loc_1709 = jumpf_dloc_1920 + 0; + GibCursor loc_1708 = jumpf_floc_loc_1921 + 0; + GibCursor cursor_ptr_3145[7] = {jumpf_dloc_1920, + jumpf_floc_loc_1921, + jumpf_floc_loc_1922, + jumpf_floc_loc_1923, + jumpf_floc_loc_1924, + jumpf_floc_loc_1925, + jumpf_floc_loc_1926}; + GibCursorPtr7GibCursorPtr7Prod tmp_struct_129 = + _traverse_ListB(cursor_ptr_3126, cursor_ptr_3128); + GibCursor pvrtmp_4184[7]; + + memcpy(pvrtmp_4184, tmp_struct_129.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4185[7]; + + memcpy(pvrtmp_4185, tmp_struct_129.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_130; + + memcpy(return_130.field0, pvrtmp_4184, sizeof(GibCursor [7])); + memcpy(return_130.field1, pvrtmp_4185, sizeof(GibCursor [7])); + return return_130; + break; + } + + case 1: + { + GibCursor soa_field_0_3153 = arg_206_358_526[1]; + GibCursor soa_field_1_3154 = arg_206_358_526[2]; + GibCursor soa_field_2_3155 = arg_206_358_526[3]; + GibCursor soa_field_3_3156 = arg_206_358_526[4]; + GibCursor soa_field_4_3157 = arg_206_358_526[5]; + GibCursor soa_field_5_3158 = arg_206_358_526[6]; + GibCursor loc_1310 = arg_206_358_526[0]; + GibCursor jump_dloc_1935 = loc_1310 + 1; + GibCursor loc_IntTy_1311 = arg_206_358_526[1]; + GibCursor jump_floc_loc_1936 = loc_IntTy_1311 + 0; + GibCursor loc_IntTy_1312 = arg_206_358_526[2]; + GibCursor jump_floc_loc_1937 = loc_IntTy_1312 + 0; + GibCursor loc_IntTy_1313 = arg_206_358_526[3]; + GibCursor jump_floc_loc_1938 = loc_IntTy_1313 + 0; + GibCursor loc_IntTy_1314 = arg_206_358_526[4]; + GibCursor jump_floc_loc_1939 = loc_IntTy_1314 + 0; + GibCursor loc_IntTy_1315 = arg_206_358_526[5]; + GibCursor jump_floc_loc_1940 = loc_IntTy_1315 + 0; + GibCursor loc_IntTy_1316 = arg_206_358_526[6]; + GibCursor jump_floc_loc_1941 = loc_IntTy_1316 + 0; + GibCursor cursor_ptr_3160[7] = {jump_dloc_1935, jump_floc_loc_1936, + jump_floc_loc_1937, + jump_floc_loc_1938, + jump_floc_loc_1939, + jump_floc_loc_1940, + jump_floc_loc_1941}; + GibCursorPtr7GibCursorPtr7Prod return_131; + + memcpy(return_131.field0, cursor_ptr_3126, sizeof(GibCursor [7])); + memcpy(return_131.field1, cursor_ptr_3160, sizeof(GibCursor [7])); + return return_131; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_3162 = arg_206_358_526[1]; + GibCursor soa_field_1_3163 = arg_206_358_526[2]; + GibCursor soa_field_2_3164 = arg_206_358_526[3]; + GibCursor soa_field_3_3165 = arg_206_358_526[4]; + GibCursor soa_field_4_3166 = arg_206_358_526[5]; + GibCursor soa_field_5_3167 = arg_206_358_526[6]; + uintptr_t tagged_tmpcur_140 = *(uintptr_t *) tmpcur_4171; + GibCursor tmpcur_4186 = GIB_UNTAG(tagged_tmpcur_140); + GibCursor tmpaftercur_4187 = tmpcur_4171 + 8; + uint16_t tmptag_4188 = GIB_GET_TAG(tagged_tmpcur_140); + GibCursor end_from_tagged_dcon_redir_3192 = tmpcur_4186 + + tmptag_4188; + GibCursor field_nxt_3185 = soa_field_0_3162 + 1; + uintptr_t tagged_tmpcur_139 = *(uintptr_t *) field_nxt_3185; + GibCursor tmpcur_4189 = GIB_UNTAG(tagged_tmpcur_139); + GibCursor tmpaftercur_4190 = field_nxt_3185 + 8; + uint16_t tmptag_4191 = GIB_GET_TAG(tagged_tmpcur_139); + GibCursor end_from_tagged_fld_redir_3193 = tmpcur_4189 + + tmptag_4191; + GibCursor field_nxt_3186 = soa_field_1_3163 + 1; + uintptr_t tagged_tmpcur_138 = *(uintptr_t *) field_nxt_3186; + GibCursor tmpcur_4192 = GIB_UNTAG(tagged_tmpcur_138); + GibCursor tmpaftercur_4193 = field_nxt_3186 + 8; + uint16_t tmptag_4194 = GIB_GET_TAG(tagged_tmpcur_138); + GibCursor end_from_tagged_fld_redir_3194 = tmpcur_4192 + + tmptag_4194; + GibCursor field_nxt_3187 = soa_field_2_3164 + 1; + uintptr_t tagged_tmpcur_137 = *(uintptr_t *) field_nxt_3187; + GibCursor tmpcur_4195 = GIB_UNTAG(tagged_tmpcur_137); + GibCursor tmpaftercur_4196 = field_nxt_3187 + 8; + uint16_t tmptag_4197 = GIB_GET_TAG(tagged_tmpcur_137); + GibCursor end_from_tagged_fld_redir_3195 = tmpcur_4195 + + tmptag_4197; + GibCursor field_nxt_3188 = soa_field_3_3165 + 1; + uintptr_t tagged_tmpcur_136 = *(uintptr_t *) field_nxt_3188; + GibCursor tmpcur_4198 = GIB_UNTAG(tagged_tmpcur_136); + GibCursor tmpaftercur_4199 = field_nxt_3188 + 8; + uint16_t tmptag_4200 = GIB_GET_TAG(tagged_tmpcur_136); + GibCursor end_from_tagged_fld_redir_3196 = tmpcur_4198 + + tmptag_4200; + GibCursor field_nxt_3189 = soa_field_4_3166 + 1; + uintptr_t tagged_tmpcur_135 = *(uintptr_t *) field_nxt_3189; + GibCursor tmpcur_4201 = GIB_UNTAG(tagged_tmpcur_135); + GibCursor tmpaftercur_4202 = field_nxt_3189 + 8; + uint16_t tmptag_4203 = GIB_GET_TAG(tagged_tmpcur_135); + GibCursor end_from_tagged_fld_redir_3197 = tmpcur_4201 + + tmptag_4203; + GibCursor field_nxt_3190 = soa_field_5_3167 + 1; + uintptr_t tagged_tmpcur_134 = *(uintptr_t *) field_nxt_3190; + GibCursor tmpcur_4204 = GIB_UNTAG(tagged_tmpcur_134); + GibCursor tmpaftercur_4205 = field_nxt_3190 + 8; + uint16_t tmptag_4206 = GIB_GET_TAG(tagged_tmpcur_134); + GibCursor end_from_tagged_fld_redir_3198 = tmpcur_4204 + + tmptag_4206; + GibCursor indr_2135[7] = {tmpcur_4186, tmpcur_4189, tmpcur_4192, + tmpcur_4195, tmpcur_4198, tmpcur_4201, + tmpcur_4204}; + GibCursor loc_1310 = arg_206_358_526[0]; + GibCursor jump_dloc_2143 = loc_1310 + 9; + GibCursor loc_IntTy_1316 = arg_206_358_526[6]; + GibCursor loc_IntTy_1315 = arg_206_358_526[5]; + GibCursor loc_IntTy_1314 = arg_206_358_526[4]; + GibCursor loc_IntTy_1313 = arg_206_358_526[3]; + GibCursor loc_IntTy_1312 = arg_206_358_526[2]; + GibCursor loc_IntTy_1311 = arg_206_358_526[1]; + GibCursor aft_indir_loc_2159 = loc_IntTy_1311 + 9; + GibCursor aft_indir_loc_2160 = loc_IntTy_1312 + 9; + GibCursor aft_indir_loc_2161 = loc_IntTy_1313 + 9; + GibCursor aft_indir_loc_2162 = loc_IntTy_1314 + 9; + GibCursor aft_indir_loc_2163 = loc_IntTy_1315 + 9; + GibCursor aft_indir_loc_2164 = loc_IntTy_1316 + 9; + GibCursor cursor_ptr_3199[7] = {jump_dloc_2143, aft_indir_loc_2159, + aft_indir_loc_2160, + aft_indir_loc_2161, + aft_indir_loc_2162, + aft_indir_loc_2163, + aft_indir_loc_2164}; + GibCursorPtr7GibCursorPtr7Prod tmp_struct_132 = + _traverse_ListB(indr_2135, indr_2135); + GibCursor pvrtmp_4207[7]; + + memcpy(pvrtmp_4207, tmp_struct_132.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4208[7]; + + memcpy(pvrtmp_4208, tmp_struct_132.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_133; + + memcpy(return_133.field0, cursor_ptr_3126, sizeof(GibCursor [7])); + memcpy(return_133.field1, cursor_ptr_3199, sizeof(GibCursor [7])); + return return_133; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_3207 = arg_206_358_526[1]; + GibCursor soa_field_1_3208 = arg_206_358_526[2]; + GibCursor soa_field_2_3209 = arg_206_358_526[3]; + GibCursor soa_field_3_3210 = arg_206_358_526[4]; + GibCursor soa_field_4_3211 = arg_206_358_526[5]; + GibCursor soa_field_5_3212 = arg_206_358_526[6]; + uintptr_t tagged_tmpcur_149 = *(uintptr_t *) tmpcur_4171; + GibCursor tmpcur_4209 = GIB_UNTAG(tagged_tmpcur_149); + GibCursor tmpaftercur_4210 = tmpcur_4171 + 8; + uint16_t tmptag_4211 = GIB_GET_TAG(tagged_tmpcur_149); + GibCursor end_from_tagged_dcon_redir_3228 = tmpcur_4209 + + tmptag_4211; + GibCursor field_nxt_3222 = soa_field_0_3207 + 1; + uintptr_t tagged_tmpcur_148 = *(uintptr_t *) field_nxt_3222; + GibCursor tmpcur_4212 = GIB_UNTAG(tagged_tmpcur_148); + GibCursor tmpaftercur_4213 = field_nxt_3222 + 8; + uint16_t tmptag_4214 = GIB_GET_TAG(tagged_tmpcur_148); + GibCursor end_from_tagged_fld_redir_3229 = tmpcur_4212 + + tmptag_4214; + GibCursor field_nxt_3223 = soa_field_1_3208 + 1; + uintptr_t tagged_tmpcur_147 = *(uintptr_t *) field_nxt_3223; + GibCursor tmpcur_4215 = GIB_UNTAG(tagged_tmpcur_147); + GibCursor tmpaftercur_4216 = field_nxt_3223 + 8; + uint16_t tmptag_4217 = GIB_GET_TAG(tagged_tmpcur_147); + GibCursor end_from_tagged_fld_redir_3230 = tmpcur_4215 + + tmptag_4217; + GibCursor field_nxt_3224 = soa_field_2_3209 + 1; + uintptr_t tagged_tmpcur_146 = *(uintptr_t *) field_nxt_3224; + GibCursor tmpcur_4218 = GIB_UNTAG(tagged_tmpcur_146); + GibCursor tmpaftercur_4219 = field_nxt_3224 + 8; + uint16_t tmptag_4220 = GIB_GET_TAG(tagged_tmpcur_146); + GibCursor end_from_tagged_fld_redir_3231 = tmpcur_4218 + + tmptag_4220; + GibCursor field_nxt_3225 = soa_field_3_3210 + 1; + uintptr_t tagged_tmpcur_145 = *(uintptr_t *) field_nxt_3225; + GibCursor tmpcur_4221 = GIB_UNTAG(tagged_tmpcur_145); + GibCursor tmpaftercur_4222 = field_nxt_3225 + 8; + uint16_t tmptag_4223 = GIB_GET_TAG(tagged_tmpcur_145); + GibCursor end_from_tagged_fld_redir_3232 = tmpcur_4221 + + tmptag_4223; + GibCursor field_nxt_3226 = soa_field_4_3211 + 1; + uintptr_t tagged_tmpcur_144 = *(uintptr_t *) field_nxt_3226; + GibCursor tmpcur_4224 = GIB_UNTAG(tagged_tmpcur_144); + GibCursor tmpaftercur_4225 = field_nxt_3226 + 8; + uint16_t tmptag_4226 = GIB_GET_TAG(tagged_tmpcur_144); + GibCursor end_from_tagged_fld_redir_3233 = tmpcur_4224 + + tmptag_4226; + GibCursor field_nxt_3227 = soa_field_5_3212 + 1; + uintptr_t tagged_tmpcur_143 = *(uintptr_t *) field_nxt_3227; + GibCursor tmpcur_4227 = GIB_UNTAG(tagged_tmpcur_143); + GibCursor tmpaftercur_4228 = field_nxt_3227 + 8; + uint16_t tmptag_4229 = GIB_GET_TAG(tagged_tmpcur_143); + GibCursor end_from_tagged_fld_redir_3234 = tmpcur_4227 + + tmptag_4229; + GibCursor indr_2135[7] = {tmpcur_4209, tmpcur_4212, tmpcur_4215, + tmpcur_4218, tmpcur_4221, tmpcur_4224, + tmpcur_4227}; + GibCursorPtr7GibCursorPtr7Prod tmp_struct_141 = + _traverse_ListB(indr_2135, indr_2135); + GibCursor pvrtmp_4230[7]; + + memcpy(pvrtmp_4230, tmp_struct_141.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4231[7]; + + memcpy(pvrtmp_4231, tmp_struct_141.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_142; + + memcpy(return_142.field0, pvrtmp_4230, sizeof(GibCursor [7])); + memcpy(return_142.field1, pvrtmp_4231, sizeof(GibCursor [7])); + return return_142; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4170"); + exit(1); + } + } +} +GibCursorGibCursorProd _print_ListA(GibCursor end_r_1326, + GibCursor arg_103_369_535) +{ + GibPackedTag tmpval_4233 = *(GibPackedTag *) arg_103_369_535; + GibCursor tmpcur_4234 = arg_103_369_535 + 1; + + + switch_4249: + ; + switch (tmpval_4233) { + + case 0: + { + GibInt tmpval_4235 = *(GibInt *) tmpcur_4234; + GibCursor tmpcur_4236 = tmpcur_4234 + sizeof(GibInt); + GibCursor jump_1943 = tmpcur_4234 + 8; + unsigned char wildcard_108_372_538 = gib_print_symbol(3643); + unsigned char wildcard_111_373_539 = gib_print_symbol(3647); + unsigned char y_106_374_540 = printf("%ld", tmpval_4235); + unsigned char wildcard_110_375_541 = gib_print_symbol(3647); + GibCursorGibCursorProd tmp_struct_150 = + _print_ListA(end_r_1326, tmpcur_4236); + GibCursor pvrtmp_4237 = tmp_struct_150.field0; + GibCursor pvrtmp_4238 = tmp_struct_150.field1; + unsigned char wildcard_109_377_543 = gib_print_symbol(3638); + GibCursorGibCursorProd return_151; + + return_151.field0 = pvrtmp_4237; + return_151.field1 = pvrtmp_4238; + return return_151; + break; + } + + case 1: + { + GibCursor jump_loc_1946 = arg_103_369_535 + 1; + unsigned char wildcard_112_378_544 = gib_print_symbol(3640); + unsigned char wildcard_113_379_545 = gib_print_symbol(3638); + GibCursorGibCursorProd return_152; + + return_152.field0 = end_r_1326; + return_152.field1 = jump_loc_1946; + return return_152; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_155 = *(uintptr_t *) tmpcur_4234; + GibCursor tmpcur_4239 = GIB_UNTAG(tagged_tmpcur_155); + GibCursor tmpaftercur_4240 = tmpcur_4234 + 8; + uint16_t tmptag_4241 = GIB_GET_TAG(tagged_tmpcur_155); + GibCursor end_from_tagged_indr_2165 = tmpcur_4239 + tmptag_4241; + GibCursor jump_loc_2167 = tmpcur_4234 + 8; + unsigned char wildcard_2170 = gib_print_symbol(3646); + GibCursorGibCursorProd tmp_struct_153 = + _print_ListA(tmpcur_4239, tmpcur_4239); + GibCursor pvrtmp_4242 = tmp_struct_153.field0; + GibCursor pvrtmp_4243 = tmp_struct_153.field1; + GibCursorGibCursorProd return_154; + + return_154.field0 = end_r_1326; + return_154.field1 = jump_loc_2167; + return return_154; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_158 = *(uintptr_t *) tmpcur_4234; + GibCursor tmpcur_4244 = GIB_UNTAG(tagged_tmpcur_158); + GibCursor tmpaftercur_4245 = tmpcur_4234 + 8; + uint16_t tmptag_4246 = GIB_GET_TAG(tagged_tmpcur_158); + GibCursor end_from_tagged_indr_2165 = tmpcur_4244 + tmptag_4246; + unsigned char wildcard_2170 = gib_print_symbol(3645); + GibCursorGibCursorProd tmp_struct_156 = + _print_ListA(tmpcur_4244, tmpcur_4244); + GibCursor pvrtmp_4247 = tmp_struct_156.field0; + GibCursor pvrtmp_4248 = tmp_struct_156.field1; + GibCursorGibCursorProd return_157; + + return_157.field0 = pvrtmp_4247; + return_157.field1 = pvrtmp_4248; + return return_157; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4233"); + exit(1); + } + } +} +GibCursorPtr7GibCursorPtr7Prod _print_ListB(GibCursor cursor_ptr_3256[7], + GibCursor arg_221_380_546[7]) +{ + GibCursor end_r_1334 = cursor_ptr_3256[0]; + GibCursor end_r_1335 = cursor_ptr_3256[1]; + GibCursor end_r_1336 = cursor_ptr_3256[2]; + GibCursor end_r_1337 = cursor_ptr_3256[3]; + GibCursor end_r_1338 = cursor_ptr_3256[4]; + GibCursor end_r_1339 = cursor_ptr_3256[5]; + GibCursor end_r_1340 = cursor_ptr_3256[6]; + GibCursor dcon_3259 = arg_221_380_546[0]; + GibPackedTag tmpval_4250 = *(GibPackedTag *) dcon_3259; + GibCursor tmpcur_4251 = dcon_3259 + 1; + + + switch_4312: + ; + switch (tmpval_4250) { + + case 0: + { + GibCursor soa_field_0_3261 = arg_221_380_546[1]; + GibCursor soa_field_1_3262 = arg_221_380_546[2]; + GibCursor soa_field_2_3263 = arg_221_380_546[3]; + GibCursor soa_field_3_3264 = arg_221_380_546[4]; + GibCursor soa_field_4_3265 = arg_221_380_546[5]; + GibCursor soa_field_5_3266 = arg_221_380_546[6]; + GibInt tmpval_4252 = *(GibInt *) soa_field_0_3261; + GibCursor tmpcur_4253 = soa_field_0_3261 + sizeof(GibInt); + GibInt tmpval_4254 = *(GibInt *) soa_field_1_3262; + GibCursor tmpcur_4255 = soa_field_1_3262 + sizeof(GibInt); + GibInt tmpval_4256 = *(GibInt *) soa_field_2_3263; + GibCursor tmpcur_4257 = soa_field_2_3263 + sizeof(GibInt); + GibInt tmpval_4258 = *(GibInt *) soa_field_3_3264; + GibCursor tmpcur_4259 = soa_field_3_3264 + sizeof(GibInt); + GibInt tmpval_4260 = *(GibInt *) soa_field_4_3265; + GibCursor tmpcur_4261 = soa_field_4_3265 + sizeof(GibInt); + GibInt tmpval_4262 = *(GibInt *) soa_field_5_3266; + GibCursor tmpcur_4263 = soa_field_5_3266 + sizeof(GibInt); + GibCursor cursor_ptr_3258[7] = {tmpcur_4251, tmpcur_4253, + tmpcur_4255, tmpcur_4257, + tmpcur_4259, tmpcur_4261, + tmpcur_4263}; + GibCursor loc_1327 = arg_221_380_546[0]; + GibCursor jumpf_dloc_1948 = loc_1327 + 1; + GibCursor loc_IntTy_1328 = arg_221_380_546[1]; + GibCursor loc_IntTy_1329 = arg_221_380_546[2]; + GibCursor loc_IntTy_1330 = arg_221_380_546[3]; + GibCursor loc_IntTy_1331 = arg_221_380_546[4]; + GibCursor loc_IntTy_1332 = arg_221_380_546[5]; + GibCursor loc_IntTy_1333 = arg_221_380_546[6]; + GibCursor jumpf_floc_loc_1949 = soa_field_0_3261 + 8; + GibCursor jumpf_floc_loc_1950 = soa_field_1_3262 + 8; + GibCursor jumpf_floc_loc_1951 = soa_field_2_3263 + 8; + GibCursor jumpf_floc_loc_1952 = soa_field_3_3264 + 8; + GibCursor jumpf_floc_loc_1953 = soa_field_4_3265 + 8; + GibCursor jumpf_floc_loc_1954 = soa_field_5_3266 + 8; + GibCursor loc_1744 = jumpf_dloc_1948 + 0; + GibCursor loc_1743 = jumpf_floc_loc_1949 + 0; + GibCursor cursor_ptr_3275[7] = {jumpf_dloc_1948, + jumpf_floc_loc_1949, + jumpf_floc_loc_1950, + jumpf_floc_loc_1951, + jumpf_floc_loc_1952, + jumpf_floc_loc_1953, + jumpf_floc_loc_1954}; + unsigned char wildcard_236_388_554 = gib_print_symbol(3642); + unsigned char wildcard_244_389_555 = gib_print_symbol(3647); + unsigned char y_229_390_556 = printf("%ld", tmpval_4252); + unsigned char wildcard_243_391_557 = gib_print_symbol(3647); + unsigned char y_230_392_558 = printf("%ld", tmpval_4254); + unsigned char wildcard_242_393_559 = gib_print_symbol(3647); + unsigned char y_231_394_560 = printf("%ld", tmpval_4256); + unsigned char wildcard_241_395_561 = gib_print_symbol(3647); + unsigned char y_232_396_562 = printf("%ld", tmpval_4258); + unsigned char wildcard_240_397_563 = gib_print_symbol(3647); + unsigned char y_233_398_564 = printf("%ld", tmpval_4260); + unsigned char wildcard_239_399_565 = gib_print_symbol(3647); + unsigned char y_234_400_566 = printf("%ld", tmpval_4262); + unsigned char wildcard_238_401_567 = gib_print_symbol(3647); + GibCursorPtr7GibCursorPtr7Prod tmp_struct_159 = + _print_ListB(cursor_ptr_3256, cursor_ptr_3258); + GibCursor pvrtmp_4264[7]; + + memcpy(pvrtmp_4264, tmp_struct_159.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4265[7]; + + memcpy(pvrtmp_4265, tmp_struct_159.field1, sizeof(GibCursor [7])); + + unsigned char wildcard_237_403_569 = gib_print_symbol(3638); + GibCursorPtr7GibCursorPtr7Prod return_160; + + memcpy(return_160.field0, pvrtmp_4264, sizeof(GibCursor [7])); + memcpy(return_160.field1, pvrtmp_4265, sizeof(GibCursor [7])); + return return_160; + break; + } + + case 1: + { + GibCursor soa_field_0_3283 = arg_221_380_546[1]; + GibCursor soa_field_1_3284 = arg_221_380_546[2]; + GibCursor soa_field_2_3285 = arg_221_380_546[3]; + GibCursor soa_field_3_3286 = arg_221_380_546[4]; + GibCursor soa_field_4_3287 = arg_221_380_546[5]; + GibCursor soa_field_5_3288 = arg_221_380_546[6]; + GibCursor loc_1327 = arg_221_380_546[0]; + GibCursor jump_dloc_1963 = loc_1327 + 1; + GibCursor loc_IntTy_1328 = arg_221_380_546[1]; + GibCursor jump_floc_loc_1964 = loc_IntTy_1328 + 0; + GibCursor loc_IntTy_1329 = arg_221_380_546[2]; + GibCursor jump_floc_loc_1965 = loc_IntTy_1329 + 0; + GibCursor loc_IntTy_1330 = arg_221_380_546[3]; + GibCursor jump_floc_loc_1966 = loc_IntTy_1330 + 0; + GibCursor loc_IntTy_1331 = arg_221_380_546[4]; + GibCursor jump_floc_loc_1967 = loc_IntTy_1331 + 0; + GibCursor loc_IntTy_1332 = arg_221_380_546[5]; + GibCursor jump_floc_loc_1968 = loc_IntTy_1332 + 0; + GibCursor loc_IntTy_1333 = arg_221_380_546[6]; + GibCursor jump_floc_loc_1969 = loc_IntTy_1333 + 0; + GibCursor cursor_ptr_3290[7] = {jump_dloc_1963, jump_floc_loc_1964, + jump_floc_loc_1965, + jump_floc_loc_1966, + jump_floc_loc_1967, + jump_floc_loc_1968, + jump_floc_loc_1969}; + unsigned char wildcard_245_404_570 = gib_print_symbol(3639); + unsigned char wildcard_246_405_571 = gib_print_symbol(3638); + GibCursorPtr7GibCursorPtr7Prod return_161; + + memcpy(return_161.field0, cursor_ptr_3256, sizeof(GibCursor [7])); + memcpy(return_161.field1, cursor_ptr_3290, sizeof(GibCursor [7])); + return return_161; + break; + } + + case GIB_INDIRECTION_TAG: + { + GibCursor soa_field_0_3292 = arg_221_380_546[1]; + GibCursor soa_field_1_3293 = arg_221_380_546[2]; + GibCursor soa_field_2_3294 = arg_221_380_546[3]; + GibCursor soa_field_3_3295 = arg_221_380_546[4]; + GibCursor soa_field_4_3296 = arg_221_380_546[5]; + GibCursor soa_field_5_3297 = arg_221_380_546[6]; + uintptr_t tagged_tmpcur_170 = *(uintptr_t *) tmpcur_4251; + GibCursor tmpcur_4266 = GIB_UNTAG(tagged_tmpcur_170); + GibCursor tmpaftercur_4267 = tmpcur_4251 + 8; + uint16_t tmptag_4268 = GIB_GET_TAG(tagged_tmpcur_170); + GibCursor end_from_tagged_dcon_redir_3322 = tmpcur_4266 + + tmptag_4268; + GibCursor field_nxt_3315 = soa_field_0_3292 + 1; + uintptr_t tagged_tmpcur_169 = *(uintptr_t *) field_nxt_3315; + GibCursor tmpcur_4269 = GIB_UNTAG(tagged_tmpcur_169); + GibCursor tmpaftercur_4270 = field_nxt_3315 + 8; + uint16_t tmptag_4271 = GIB_GET_TAG(tagged_tmpcur_169); + GibCursor end_from_tagged_fld_redir_3323 = tmpcur_4269 + + tmptag_4271; + GibCursor field_nxt_3316 = soa_field_1_3293 + 1; + uintptr_t tagged_tmpcur_168 = *(uintptr_t *) field_nxt_3316; + GibCursor tmpcur_4272 = GIB_UNTAG(tagged_tmpcur_168); + GibCursor tmpaftercur_4273 = field_nxt_3316 + 8; + uint16_t tmptag_4274 = GIB_GET_TAG(tagged_tmpcur_168); + GibCursor end_from_tagged_fld_redir_3324 = tmpcur_4272 + + tmptag_4274; + GibCursor field_nxt_3317 = soa_field_2_3294 + 1; + uintptr_t tagged_tmpcur_167 = *(uintptr_t *) field_nxt_3317; + GibCursor tmpcur_4275 = GIB_UNTAG(tagged_tmpcur_167); + GibCursor tmpaftercur_4276 = field_nxt_3317 + 8; + uint16_t tmptag_4277 = GIB_GET_TAG(tagged_tmpcur_167); + GibCursor end_from_tagged_fld_redir_3325 = tmpcur_4275 + + tmptag_4277; + GibCursor field_nxt_3318 = soa_field_3_3295 + 1; + uintptr_t tagged_tmpcur_166 = *(uintptr_t *) field_nxt_3318; + GibCursor tmpcur_4278 = GIB_UNTAG(tagged_tmpcur_166); + GibCursor tmpaftercur_4279 = field_nxt_3318 + 8; + uint16_t tmptag_4280 = GIB_GET_TAG(tagged_tmpcur_166); + GibCursor end_from_tagged_fld_redir_3326 = tmpcur_4278 + + tmptag_4280; + GibCursor field_nxt_3319 = soa_field_4_3296 + 1; + uintptr_t tagged_tmpcur_165 = *(uintptr_t *) field_nxt_3319; + GibCursor tmpcur_4281 = GIB_UNTAG(tagged_tmpcur_165); + GibCursor tmpaftercur_4282 = field_nxt_3319 + 8; + uint16_t tmptag_4283 = GIB_GET_TAG(tagged_tmpcur_165); + GibCursor end_from_tagged_fld_redir_3327 = tmpcur_4281 + + tmptag_4283; + GibCursor field_nxt_3320 = soa_field_5_3297 + 1; + uintptr_t tagged_tmpcur_164 = *(uintptr_t *) field_nxt_3320; + GibCursor tmpcur_4284 = GIB_UNTAG(tagged_tmpcur_164); + GibCursor tmpaftercur_4285 = field_nxt_3320 + 8; + uint16_t tmptag_4286 = GIB_GET_TAG(tagged_tmpcur_164); + GibCursor end_from_tagged_fld_redir_3328 = tmpcur_4284 + + tmptag_4286; + GibCursor indr_2171[7] = {tmpcur_4266, tmpcur_4269, tmpcur_4272, + tmpcur_4275, tmpcur_4278, tmpcur_4281, + tmpcur_4284}; + GibCursor loc_1327 = arg_221_380_546[0]; + GibCursor jump_dloc_2179 = loc_1327 + 9; + GibCursor loc_IntTy_1333 = arg_221_380_546[6]; + GibCursor loc_IntTy_1332 = arg_221_380_546[5]; + GibCursor loc_IntTy_1331 = arg_221_380_546[4]; + GibCursor loc_IntTy_1330 = arg_221_380_546[3]; + GibCursor loc_IntTy_1329 = arg_221_380_546[2]; + GibCursor loc_IntTy_1328 = arg_221_380_546[1]; + GibCursor aft_indir_loc_2195 = loc_IntTy_1328 + 9; + GibCursor aft_indir_loc_2196 = loc_IntTy_1329 + 9; + GibCursor aft_indir_loc_2197 = loc_IntTy_1330 + 9; + GibCursor aft_indir_loc_2198 = loc_IntTy_1331 + 9; + GibCursor aft_indir_loc_2199 = loc_IntTy_1332 + 9; + GibCursor aft_indir_loc_2200 = loc_IntTy_1333 + 9; + GibCursor cursor_ptr_3329[7] = {jump_dloc_2179, aft_indir_loc_2195, + aft_indir_loc_2196, + aft_indir_loc_2197, + aft_indir_loc_2198, + aft_indir_loc_2199, + aft_indir_loc_2200}; + unsigned char wildcard_2194 = gib_print_symbol(3646); + GibCursorPtr7GibCursorPtr7Prod tmp_struct_162 = + _print_ListB(indr_2171, indr_2171); + GibCursor pvrtmp_4287[7]; + + memcpy(pvrtmp_4287, tmp_struct_162.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4288[7]; + + memcpy(pvrtmp_4288, tmp_struct_162.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_163; + + memcpy(return_163.field0, cursor_ptr_3256, sizeof(GibCursor [7])); + memcpy(return_163.field1, cursor_ptr_3329, sizeof(GibCursor [7])); + return return_163; + break; + } + + case GIB_REDIRECTION_TAG: + { + GibCursor soa_field_0_3337 = arg_221_380_546[1]; + GibCursor soa_field_1_3338 = arg_221_380_546[2]; + GibCursor soa_field_2_3339 = arg_221_380_546[3]; + GibCursor soa_field_3_3340 = arg_221_380_546[4]; + GibCursor soa_field_4_3341 = arg_221_380_546[5]; + GibCursor soa_field_5_3342 = arg_221_380_546[6]; + uintptr_t tagged_tmpcur_179 = *(uintptr_t *) tmpcur_4251; + GibCursor tmpcur_4289 = GIB_UNTAG(tagged_tmpcur_179); + GibCursor tmpaftercur_4290 = tmpcur_4251 + 8; + uint16_t tmptag_4291 = GIB_GET_TAG(tagged_tmpcur_179); + GibCursor end_from_tagged_dcon_redir_3358 = tmpcur_4289 + + tmptag_4291; + GibCursor field_nxt_3352 = soa_field_0_3337 + 1; + uintptr_t tagged_tmpcur_178 = *(uintptr_t *) field_nxt_3352; + GibCursor tmpcur_4292 = GIB_UNTAG(tagged_tmpcur_178); + GibCursor tmpaftercur_4293 = field_nxt_3352 + 8; + uint16_t tmptag_4294 = GIB_GET_TAG(tagged_tmpcur_178); + GibCursor end_from_tagged_fld_redir_3359 = tmpcur_4292 + + tmptag_4294; + GibCursor field_nxt_3353 = soa_field_1_3338 + 1; + uintptr_t tagged_tmpcur_177 = *(uintptr_t *) field_nxt_3353; + GibCursor tmpcur_4295 = GIB_UNTAG(tagged_tmpcur_177); + GibCursor tmpaftercur_4296 = field_nxt_3353 + 8; + uint16_t tmptag_4297 = GIB_GET_TAG(tagged_tmpcur_177); + GibCursor end_from_tagged_fld_redir_3360 = tmpcur_4295 + + tmptag_4297; + GibCursor field_nxt_3354 = soa_field_2_3339 + 1; + uintptr_t tagged_tmpcur_176 = *(uintptr_t *) field_nxt_3354; + GibCursor tmpcur_4298 = GIB_UNTAG(tagged_tmpcur_176); + GibCursor tmpaftercur_4299 = field_nxt_3354 + 8; + uint16_t tmptag_4300 = GIB_GET_TAG(tagged_tmpcur_176); + GibCursor end_from_tagged_fld_redir_3361 = tmpcur_4298 + + tmptag_4300; + GibCursor field_nxt_3355 = soa_field_3_3340 + 1; + uintptr_t tagged_tmpcur_175 = *(uintptr_t *) field_nxt_3355; + GibCursor tmpcur_4301 = GIB_UNTAG(tagged_tmpcur_175); + GibCursor tmpaftercur_4302 = field_nxt_3355 + 8; + uint16_t tmptag_4303 = GIB_GET_TAG(tagged_tmpcur_175); + GibCursor end_from_tagged_fld_redir_3362 = tmpcur_4301 + + tmptag_4303; + GibCursor field_nxt_3356 = soa_field_4_3341 + 1; + uintptr_t tagged_tmpcur_174 = *(uintptr_t *) field_nxt_3356; + GibCursor tmpcur_4304 = GIB_UNTAG(tagged_tmpcur_174); + GibCursor tmpaftercur_4305 = field_nxt_3356 + 8; + uint16_t tmptag_4306 = GIB_GET_TAG(tagged_tmpcur_174); + GibCursor end_from_tagged_fld_redir_3363 = tmpcur_4304 + + tmptag_4306; + GibCursor field_nxt_3357 = soa_field_5_3342 + 1; + uintptr_t tagged_tmpcur_173 = *(uintptr_t *) field_nxt_3357; + GibCursor tmpcur_4307 = GIB_UNTAG(tagged_tmpcur_173); + GibCursor tmpaftercur_4308 = field_nxt_3357 + 8; + uint16_t tmptag_4309 = GIB_GET_TAG(tagged_tmpcur_173); + GibCursor end_from_tagged_fld_redir_3364 = tmpcur_4307 + + tmptag_4309; + GibCursor indr_2171[7] = {tmpcur_4289, tmpcur_4292, tmpcur_4295, + tmpcur_4298, tmpcur_4301, tmpcur_4304, + tmpcur_4307}; + unsigned char wildcard_2194 = gib_print_symbol(3645); + GibCursorPtr7GibCursorPtr7Prod tmp_struct_171 = + _print_ListB(indr_2171, indr_2171); + GibCursor pvrtmp_4310[7]; + + memcpy(pvrtmp_4310, tmp_struct_171.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_4311[7]; + + memcpy(pvrtmp_4311, tmp_struct_171.field1, sizeof(GibCursor [7])); + + GibCursorPtr7GibCursorPtr7Prod return_172; + + memcpy(return_172.field0, pvrtmp_4310, sizeof(GibCursor [7])); + memcpy(return_172.field1, pvrtmp_4311, sizeof(GibCursor [7])); + return return_172; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4250"); + exit(1); + } + } +} +GibCursorGibCursorGibCursorGibCursorGibCursorProd _copy_without_ptrs_List(GibCursor end_r_1344, + GibCursor end_r_1346, + GibCursor loc_1342, + GibCursor arg_127_406_572) +{ + GibPackedTag tmpval_4313 = *(GibPackedTag *) arg_127_406_572; + GibCursor tmpcur_4314 = arg_127_406_572 + 1; + + + switch_4377: + ; + switch (tmpval_4313) { + + case 0: + { + GibInt tmpval_4315 = *(GibInt *) tmpcur_4314; + GibCursor tmpcur_4316 = tmpcur_4314 + sizeof(GibInt); + GibInt tmpval_4317 = *(GibInt *) tmpcur_4316; + GibCursor tmpcur_4318 = tmpcur_4316 + sizeof(GibInt); + GibInt tmpval_4319 = *(GibInt *) tmpcur_4318; + GibCursor tmpcur_4320 = tmpcur_4318 + sizeof(GibInt); + GibInt tmpval_4321 = *(GibInt *) tmpcur_4320; + GibCursor tmpcur_4322 = tmpcur_4320 + sizeof(GibInt); + GibCursor jump_1974 = tmpcur_4320 + 8; + GibCursor jump_1973 = tmpcur_4318 + 8; + GibCursor jump_1972 = tmpcur_4316 + 8; + GibCursor jump_1971 = tmpcur_4314 + 8; + GibCursor loc_1773 = loc_1342 + 1; + GibCursor loc_1774 = loc_1773 + 8; + GibCursor loc_1775 = loc_1774 + 8; + GibCursor loc_1776 = loc_1775 + 8; + GibCursor loc_1777 = loc_1776 + 8; + + *(GibPackedTag *) loc_1342 = 0; + + GibCursor writetag_3383 = loc_1342 + 1; + GibCursor after_tag_3384 = loc_1342 + 1; + + *(GibInt *) after_tag_3384 = tmpval_4315; + + GibCursor writecur_3388 = after_tag_3384 + sizeof(GibInt); + + *(GibInt *) writecur_3388 = tmpval_4317; + + GibCursor writecur_3389 = writecur_3388 + sizeof(GibInt); + + *(GibInt *) writecur_3389 = tmpval_4319; + + GibCursor writecur_3390 = writecur_3389 + sizeof(GibInt); + + *(GibInt *) writecur_3390 = tmpval_4321; + + GibCursor writecur_3391 = writecur_3390 + sizeof(GibInt); + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_180 = + _copy_without_ptrs_ListA(end_r_1344, end_r_1346, loc_1777, tmpcur_4322); + GibCursor pvrtmp_4323 = tmp_struct_180.field0; + GibCursor pvrtmp_4324 = tmp_struct_180.field1; + GibCursor pvrtmp_4325 = tmp_struct_180.field2; + GibCursor pvrtmp_4326 = tmp_struct_180.field3; + GibCursor pvrtmp_4327 = tmp_struct_180.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_181 = + _copy_without_ptrs_List(pvrtmp_4323, pvrtmp_4324, pvrtmp_4327, pvrtmp_4325); + GibCursor pvrtmp_4332 = tmp_struct_181.field0; + GibCursor pvrtmp_4333 = tmp_struct_181.field1; + GibCursor pvrtmp_4334 = tmp_struct_181.field2; + GibCursor pvrtmp_4335 = tmp_struct_181.field3; + GibCursor pvrtmp_4336 = tmp_struct_181.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_182; + + return_182.field0 = pvrtmp_4332; + return_182.field1 = pvrtmp_4333; + return_182.field2 = pvrtmp_4334; + return_182.field3 = loc_1342; + return_182.field4 = pvrtmp_4336; + return return_182; + break; + } + + case 1: + { + GibCursor jump_loc_1978 = arg_127_406_572 + 1; + + *(GibPackedTag *) loc_1342 = 1; + + GibCursor writetag_3398 = loc_1342 + 1; + GibCursor after_tag_3399 = loc_1342 + 1; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_183; + + return_183.field0 = end_r_1344; + return_183.field1 = end_r_1346; + return_183.field2 = jump_loc_1978; + return_183.field3 = loc_1342; + return_183.field4 = after_tag_3399; + return return_183; + break; + } + + case GIB_INDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_186 = *(uintptr_t *) tmpcur_4314; + GibCursor tmpcur_4349 = GIB_UNTAG(tagged_tmpcur_186); + GibCursor tmpaftercur_4350 = tmpcur_4314 + 8; + uint16_t tmptag_4351 = GIB_GET_TAG(tagged_tmpcur_186); + GibCursor end_from_tagged_indr_2201 = tmpcur_4349 + tmptag_4351; + GibCursor jump_loc_2203 = tmpcur_4314 + 8; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_184 = + _copy_without_ptrs_List(tmpcur_4349, end_r_1346, loc_1342, tmpcur_4349); + GibCursor pvrtmp_4352 = tmp_struct_184.field0; + GibCursor pvrtmp_4353 = tmp_struct_184.field1; + GibCursor pvrtmp_4354 = tmp_struct_184.field2; + GibCursor pvrtmp_4355 = tmp_struct_184.field3; + GibCursor pvrtmp_4356 = tmp_struct_184.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_185; + + return_185.field0 = end_r_1344; + return_185.field1 = pvrtmp_4353; + return_185.field2 = jump_loc_2203; + return_185.field3 = pvrtmp_4355; + return_185.field4 = pvrtmp_4356; + return return_185; + break; + } + + case GIB_REDIRECTION_TAG: + { + uintptr_t tagged_tmpcur_189 = *(uintptr_t *) tmpcur_4314; + GibCursor tmpcur_4363 = GIB_UNTAG(tagged_tmpcur_189); + GibCursor tmpaftercur_4364 = tmpcur_4314 + 8; + uint16_t tmptag_4365 = GIB_GET_TAG(tagged_tmpcur_189); + GibCursor end_from_tagged_indr_2201 = tmpcur_4363 + tmptag_4365; + GibCursorGibCursorGibCursorGibCursorGibCursorProd tmp_struct_187 = + _copy_without_ptrs_List(tmpcur_4363, end_r_1346, loc_1342, tmpcur_4363); + GibCursor pvrtmp_4366 = tmp_struct_187.field0; + GibCursor pvrtmp_4367 = tmp_struct_187.field1; + GibCursor pvrtmp_4368 = tmp_struct_187.field2; + GibCursor pvrtmp_4369 = tmp_struct_187.field3; + GibCursor pvrtmp_4370 = tmp_struct_187.field4; + GibCursorGibCursorGibCursorGibCursorGibCursorProd return_188; + + return_188.field0 = pvrtmp_4366; + return_188.field1 = pvrtmp_4367; + return_188.field2 = pvrtmp_4368; + return_188.field3 = pvrtmp_4369; + return_188.field4 = pvrtmp_4370; + return return_188; + break; + } + + default: + { + printf("%s\n", "Unknown tag in: tmpval_4313"); + exit(1); + } + } +} +int main(int argc, char **argv) +{ + int init_197 = gib_init(argc, argv); + + info_table_initialize(); + symbol_table_initialize(); + + GibChunk region_3648 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1376 = region_3648.start; + GibCursor end_r_1376 = region_3648.end; + GibChunk region_3649 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1377 = region_3649.start; + GibCursor end_r_1377 = region_3649.end; + GibChunk region_3650 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1378 = region_3650.start; + GibCursor end_r_1378 = region_3650.end; + GibChunk region_3651 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1379 = region_3651.start; + GibCursor end_r_1379 = region_3651.end; + GibChunk region_3652 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1380 = region_3652.start; + GibCursor end_r_1380 = region_3652.end; + GibChunk region_3653 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1381 = region_3653.start; + GibCursor end_r_1381 = region_3653.end; + GibChunk region_3654 = + gib_alloc_region_on_heap(gib_get_inf_init_chunk_size()); + GibCursor r_1382 = region_3654.start; + GibCursor end_r_1382 = region_3654.end; + GibCursor reg_ptr_3415[7] = {r_1376, r_1377, r_1378, r_1379, r_1380, r_1381, + r_1382}; + GibCursor reg_cursor_ptr_3416[7] = {end_r_1376, end_r_1377, end_r_1378, + end_r_1379, end_r_1380, end_r_1381, + end_r_1382}; + GibCursorPtr7GibCursorPtr7GibCursorPtr7Prod tmp_struct_190 = + mkListB(reg_cursor_ptr_3416, reg_ptr_3415, 2500000); + GibCursor pvrtmp_3655[7]; + + memcpy(pvrtmp_3655, tmp_struct_190.field0, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3656[7]; + + memcpy(pvrtmp_3656, tmp_struct_190.field1, sizeof(GibCursor [7])); + + GibCursor pvrtmp_3657[7]; + + memcpy(pvrtmp_3657, tmp_struct_190.field2, sizeof(GibCursor [7])); + + GibInt timed_3497; + GibVector *times_195 = gib_vector_alloc(gib_get_iters_param(), + sizeof(double)); + struct timespec begin_timed_3497; + struct timespec end_timed_3497; + + for (long long iters_timed_3497 = 0; iters_timed_3497 < + gib_get_iters_param(); iters_timed_3497++) { + if (iters_timed_3497 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_save_state(); + gib_ptr_bumpalloc_save_state(); + } + clock_gettime(CLOCK_MONOTONIC_RAW, &begin_timed_3497); + + //GibInt pvrtmp_3664 = 0; + + GibCursorPtr7GibCursorPtr7GibIntProd tmp_struct_191 = reduceB(pvrtmp_3655, pvrtmp_3656); +// GibCursor pvrtmp_3662[7]; +// +// memcpy(pvrtmp_3662, tmp_struct_191.field0, sizeof(GibCursor [7])); +// +// GibCursor pvrtmp_3663[7]; +// +// memcpy(pvrtmp_3663, tmp_struct_191.field1, sizeof(GibCursor [7])); +// + GibInt pvrtmp_3664 = tmp_struct_191.field2; + + timed_3497 = pvrtmp_3664; + clock_gettime(CLOCK_MONOTONIC_RAW, &end_timed_3497); + if (iters_timed_3497 != gib_get_iters_param() - 1) { + gib_list_bumpalloc_restore_state(); + gib_ptr_bumpalloc_restore_state(); + } + + double itertime_192 = gib_difftimespecs(&begin_timed_3497, + &end_timed_3497); + + printf("itertime: %lf\n", itertime_192); + gib_vector_inplace_update(times_195, iters_timed_3497, &itertime_192); + + memcpy(pvrtmp_3655, tmp_struct_190.field0, sizeof(GibCursor [7])); + memcpy(pvrtmp_3656, tmp_struct_190.field1, sizeof(GibCursor [7])); + //pvrtmp_3664 = 0; + + } + gib_vector_inplace_sort(times_195, gib_compare_doubles); + + double *tmp_196 = (double *) gib_vector_nth(times_195, + gib_get_iters_param() / 2); + double selftimed_194 = *tmp_196; + double batchtime_193 = gib_sum_timing_array(times_195); + + gib_print_timing_array(times_195); + gib_vector_free(times_195); + printf("ITERS: %ld\n", gib_get_iters_param()); + printf("SIZE: %ld\n", gib_get_size_param()); + printf("BATCHTIME: %e\n", batchtime_193); + printf("SELFTIMED: %e\n", selftimed_194); + printf("%ld", timed_3497); + printf("\n"); + + int exit_198 = gib_exit(); + + return exit_198; +}