futhark
Safe HaskellNone
LanguageGHC2021

Futhark.Transform.FirstOrderTransform

Description

The code generator cannot handle the array combinators (map and friends), so this module was written to transform them into the equivalent do-loops. The transformation is currently rather naive, and - it's certainly worth considering when we can express such transformations in-place.

Synopsis

Documentation

transformFunDef :: (MonadFreshNames m, FirstOrderRep torep) => Scope torep -> FunDef SOACS -> m (FunDef torep) Source #

First-order-transform a single function, with the given scope provided by top-level constants.

transformConsts :: (MonadFreshNames m, FirstOrderRep torep) => Stms SOACS -> m (Stms torep) Source #

First-order-transform these top-level constants.

type FirstOrderRep rep = (Buildable rep, BuilderOps rep, LetDec SOACS ~ LetDec rep, LParamInfo SOACS ~ LParamInfo rep, AliasableRep rep) Source #

The constraints that must hold for a rep in order to be the target of first-order transformation.

type Transformer (m :: Type -> Type) = (MonadBuilder m, LocalScope (Rep m) m, Buildable (Rep m), BuilderOps (Rep m), LParamInfo SOACS ~ LParamInfo (Rep m), AliasableRep (Rep m)) Source #

The constraints that a monad must uphold in order to be used for first-order transformation.

transformStmRecursively :: (Transformer m, LetDec (Rep m) ~ LetDec SOACS) => Stm SOACS -> m () Source #

First transform any nested Body or Lambda elements, then apply transformSOAC if the expression is a SOAC.

transformLambda :: (MonadFreshNames m, Buildable rep, BuilderOps rep, LocalScope somerep m, SameScope somerep rep, LetDec rep ~ LetDec SOACS, AliasableRep rep) => GLambda SOACS t -> m (GLambda rep t) Source #

Recursively first-order-transform a lambda.

transformSOAC :: Transformer m => Pat (LetDec (Rep m)) -> SOAC (Rep m) -> m () Source #

Transform a single SOAC into a do-loop. The body of the lambda is untouched, and may or may not contain further SOACs depending on the given rep.

transformScrema :: Transformer m => Pat dec -> SubExp -> [VName] -> ScremaForm (Rep m) -> m () Source #

Sequentialise a single Screma.

transformFlatMap :: Transformer m => Pat (LetDec (Rep m)) -> SubExp -> [VName] -> ExtLambda (Rep m) -> m () Source #

Sequentialise a single FlatMap. The size of the nonuniform results produced by the lambda is not known until it has been run, so each of them is accumulated in a scratch buffer that is doubled whenever it runs out of space, and finally truncated to the actual size. The value results need no such treatment, as there is exactly one per iteration. The shape and offset arrays are filled in as we go, and the flag array is then a scatter of the segment starts.