Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Soa: Modify Infer Locations #274

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ RUN echo "export PATH=${PATH}" >> /home/${USERNAME}/.profile
# install ghcup
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

ARG GHC=9.4.6
ARG CABAL=3.8.1.0
ARG GHC=9.10.1
ARG CABAL=3.12.1.0
ARG STACK=2.9.3
ARG HLS=recommended

Expand Down
22 changes: 14 additions & 8 deletions gibbon-compiler/src/Gibbon/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module Gibbon.Common
(
-- * Variables
Var(..), LocVar(..), Location, FieldIndex
Var(..), LocVar(..), Location, FieldIndex, DataCon
, RegVar, fromVar, toVar, varAppend, toEndV, toEndVLoc, toSeqV, cleanFunName
, TyVar(..), isUserTv
, Symbol, intern, unintern
Expand Down Expand Up @@ -66,7 +66,6 @@ import System.IO.Unsafe ( unsafePerformIO )
import System.Random ( randomIO )
import Debug.Trace
import Language.C.Quote.CUDA (ToIdent, toIdent)

import Gibbon.DynFlags

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -138,12 +137,19 @@ toSeqV v = varAppend v (toVar "_seq")

-- | A location variable stores the abstract location.
type Location = Var

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

data LocVar = Single Location
deriving (Show, Ord, Eq, Read, Generic, NFData, Out)
-- | The position or index of a field in a data constructor value.
type FieldIndex = Int
-- | A data constructor is a String type in the compiler
type DataCon = String

-- | Single: For storing a single location, useful for adding a cursor in a region.
-- | SoA: A location signature for a structure of arrays representation.
-- The first location points to a location in the data constructor buffer.
-- The list includes locations for each field and a tuple storing
-- information about which data constructor and corresponding index the field
-- comes from.
data LocVar = Single Location | SoA Location [((DataCon, FieldIndex), Location)]
deriving (Show, Ord, Eq, Read, Generic, NFData, Out)

-- | Abstract region variables.
type RegVar = Var
Expand Down
34 changes: 26 additions & 8 deletions gibbon-compiler/src/Gibbon/L2/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,23 @@ data E2Ext loc dec

-- | Define a location in terms of a different location.
data PreLocExp loc = StartOfRegionLE Region
| AfterConstantLE Int -- Number of bytes after.
loc -- Location which this location is offset from.
| AfterVariableLE Var -- Name of variable v. This loc is size(v) bytes after.
loc -- Location which this location is offset from.
Bool -- Whether it's running in a stolen continuation i.e
-- whether this should return an index in a fresh region or not.
-- It's True by default and flipped by ParAlloc if required.
| AfterConstantLE Int -- Number of bytes after. (In case of an SoA loc, this is the offset into the data constructor buffer)
loc -- Location which this location is offset from.

| AfterVariableLE Var -- Name of variable v. This loc is size(v) bytes after.
loc -- Location which this location is offset from.
Bool -- Whether it's running in a stolen continuation i.e
-- whether this should return an index in a fresh region or not.
-- It's True by default and flipped by ParAlloc if required.
| InRegionLE Region
| FreeLE
| FromEndLE loc

| AfterSoALE (PreLocExp loc) [PreLocExp loc] loc -- Compute new SoA location from an old SoA location
-- (PreLocExp loc) -> expression for arithmetic on data constructor buffer
-- [PreLocExp loc] -> expressions for arithmetic on each field location
-- loc, store the old loc, why? -- capture more metadata, also style

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

type LocExp = PreLocExp LocVar
Expand Down Expand Up @@ -231,7 +238,7 @@ instance FreeVars LocExp where
gFreeVars e =
case e of
AfterConstantLE _ loc -> S.singleton $ unwrapLocVar loc
AfterVariableLE v loc _ -> S.fromList $ [v, unwrapLocVar loc]
AfterVariableLE v loc _ -> S.fromList [v, unwrapLocVar loc]
_ -> S.empty

instance (Out l, Out d, Show l, Show d) => Expression (E2Ext l d) where
Expand Down Expand Up @@ -479,6 +486,17 @@ data Region = GlobR Var Multiplicity -- ^ A global region with lifetime equal to
-- are no free locations in the program.
deriving (Read,Show,Eq,Ord, Generic)

{-
Why a new datatype? -- Well, For a location, we changed the exisiting datatype, i.e. LocVar.
That's acceptable, because locations are just cursors into regions, they are an indices into
regions which don't necessarily signify an entity/allocated object.

A region encapsulates an allocated space and i'd like a region to represent a unit of space.
We can create more "complex" regions using that unit, for instance a SoA region.
In additon, it preserves statements like "is region A within region B?"
It would be tough to formalize what is means by saying an SoA region exists within another region
(VarR x). Since an SoA region contains multiple regions.
-}
data ExtendedRegion = AoSR Region -- ^ A simple "flat" region where the datatype
-- will reside in an array of structure representation.
| SoAR Region [((DataCon, FieldIndex), Region)] -- ^ A complex region representation for a datatype
Expand Down
1 change: 1 addition & 0 deletions gibbon-compiler/src/Gibbon/L2/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ tcExp ddfs env funs constrs regs tstatein exp =
(ty,tstate2) <- tcExp ddfs env' funs constrs1 regs tstate1 e
tstate3 <- removeLoc exp tstate2 (Single loc)
return (ty,tstate3)
{-TODO handle what needs to happen with the wildcard argument, list of offsets in case of soa -}
AfterConstantLE i l1 ->
do r <- getRegion exp constrs l1
let tstate1 = extendTS (Single loc) (Output,True) $ setAfter l1 tstatein
Expand Down
2 changes: 1 addition & 1 deletion gibbon-compiler/src/Gibbon/L4/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Label = Var
type SymTable = M.Map Word16 String

type InfoTable = (M.Map L.TyCon TyConInfo)
type TyConInfo = M.Map L.DataCon DataConInfo
type TyConInfo = M.Map DataCon DataConInfo

data DataConInfo = DataConInfo
{ dcon_tag :: Tag
Expand Down
3 changes: 1 addition & 2 deletions gibbon-compiler/src/Gibbon/Language/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
module Gibbon.Language.Syntax
(
-- * Datatype definitions
DDefs, DataCon, TyCon, Tag, IsBoxed, DDef(..)
DDefs, TyCon, Tag, IsBoxed, DDef(..)
, lookupDDef, getConOrdering, getTyOfDataCon, lookupDataCon, lkp
, lookupDataCon', insertDD, emptyDD, fromListDD, isVoidDDef

Expand Down Expand Up @@ -78,7 +78,6 @@ import Gibbon.Common

type DDefs a = M.Map Var (DDef a)

type DataCon = String
type TyCon = String
type Tag = Word8

Expand Down
2 changes: 1 addition & 1 deletion gibbon-compiler/src/Gibbon/NewL2/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ instance FreeVars LocExp where
gFreeVars e =
case e of
Old.AfterConstantLE _ loc -> S.singleton $ unwrapLocVar (toLocVar loc)
Old.AfterVariableLE v loc _ -> S.fromList $ [v, unwrapLocVar (toLocVar loc)]
Old.AfterVariableLE v loc _ -> S.fromList [v, unwrapLocVar (toLocVar loc)]
_ -> S.empty


Expand Down
2 changes: 2 additions & 0 deletions gibbon-compiler/src/Gibbon/Passes/CalculateBounds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ calculateBoundsExp ddefs env2 varSzEnv varLocEnv locRegEnv locOffEnv regSzEnv re
else do
let (re, off) = case locExp of
(StartOfRegionLE r ) -> (regionToVar r, BoundedSize 0)
-- [2024.12.04] VS: currently discarding offsets for SoA representation
(AfterConstantLE n l ) -> (locRegEnv # l, locOffEnv # l <> BoundedSize n)
-- [2022.12.26] CSK: the lookup in varSzEnv always fails since the
-- pass never inserts anything into it. Disabling it for now.
-- [2024.12.04] VS: currently discarding offsets for SoA representation
(AfterVariableLE v l _) -> (locRegEnv # l, locOffEnv # (varLocEnv # v)) -- <> varSzEnv # v
(InRegionLE r ) -> (regionToVar r, Undefined)
(FromEndLE l ) -> (locRegEnv # l, Undefined)
Expand Down
1 change: 1 addition & 0 deletions gibbon-compiler/src/Gibbon/Passes/Cursorize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ cursorizeLocExp denv tenv senv lvar locExp =
in if isBound ((toLocVar) loc) tenv
then Right (rhs, [], tenv, senv)
else Left$ M.insertWith (++) ((toLocVar) loc) [((unwrapLocVar lvar),[],CursorTy,rhs)] denv

-- TODO: handle product types here

{- [2018.03.07]:
Expand Down
Loading
Loading