Skip to content

Commit

Permalink
generate soa regions in inferlocations
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Dec 3, 2024
1 parent a8ec386 commit f370f05
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions gibbon-compiler/src/Gibbon/Passes/InferLocations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,47 @@ convertFunTy ddefs (from,to,isPar) = do
from' <- mapM (convertTy ddefs useSoA) from
to' <- convertTy ddefs useSoA to
-- For this simple version, we assume every location is in a separate region:
lrm1 <- concat <$> mapM (toLRM Input) from'
lrm2 <- toLRM Output to'
lrm1 <- concat <$> mapM (toLRM useSoA Input) from'
lrm2 <- toLRM useSoA Output to'
dbgTraceIt "convertFunTy: " dbgTraceIt (sdoc (from', to', lrm1, lrm2, useSoA)) dbgTraceIt "\n" return $ ArrowTy2 { locVars = lrm1 ++ lrm2
, arrIns = from'
, arrEffs = S.empty
, arrOut = to'
, locRets = []
, hasParallelism = isPar }
where
toLRM md ls =
mapM (\v -> do r <- freshLocVar "r"
return $ LRM v (AoSR $ VarR (unwrapLocVar r)) md)
(F.toList ls)
toLRM soa md ls = do
case soa of
True -> mapM (\v -> do
dataBufRegion <- freshLocVar "r"
case v of
Single _ -> error "InferLocations : toLRM : Expected an SoA location!\n"
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 (AoSR $ VarR (unwrapLocVar r)) md) (F.toList ls)

getSoARegionsFromLocs :: [((DataCon, Int), Var)] -> PassM [((DataCon, Int), Region)]
getSoARegionsFromLocs locs = case locs of
[] -> return []
(a, b):rst -> do
regionVariable <- freshLocVar "r"
let region = VarR (unwrapLocVar regionVariable)
rst' <- getSoARegionsFromLocs rst
let elem = (a, region)
return $ [elem] ++ rst'



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 ddef = lookupDDef ddefs tycon
let dcons = getConOrdering ddefs tycon
locsForFields <- convertTyHelperSoAParent tycon ddefs dcons
let soaLocation = SoA (unwrapLocVar dconBuff) locsForFields
Expand Down

0 comments on commit f370f05

Please sign in to comment.