futhark-0.25.27: An optimising compiler for a functional, array-oriented language.

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.Builder.Class

Description

This module defines a convenience typeclass for creating normalised programs.

See Futhark.Construct for a high-level description.

Synopsis

- class (ASTRep rep, FParamInfo rep ~ DeclType, LParamInfo rep ~ Type, RetType rep ~ DeclExtType, BranchType rep ~ ExtType) => Buildable rep where
  - mkExpPat :: [Ident] -> Exp rep -> Pat (LetDec rep)
  - mkExpDec :: Pat (LetDec rep) -> Exp rep -> ExpDec rep
  - mkBody :: Stms rep -> Result -> Body rep
  - mkLetNames :: (MonadFreshNames m, HasScope rep m) => [VName] -> Exp rep -> m (Stm rep)
- mkLet :: Buildable rep => [Ident] -> Exp rep -> Stm rep
- mkLet' :: Buildable rep => [Ident] -> StmAux a -> Exp rep -> Stm rep
- class (ASTRep (Rep m), MonadFreshNames m, Applicative m, Monad m, LocalScope (Rep m) m) => MonadBuilder m where
  - type Rep m :: Type
  - mkExpDecM :: Pat (LetDec (Rep m)) -> Exp (Rep m) -> m (ExpDec (Rep m))
  - mkBodyM :: Stms (Rep m) -> Result -> m (Body (Rep m))
  - mkLetNamesM :: [VName] -> Exp (Rep m) -> m (Stm (Rep m))
  - addStm :: Stm (Rep m) -> m ()
  - addStms :: Stms (Rep m) -> m ()
  - collectStms :: m a -> m (a, Stms (Rep m))
  - certifying :: Certs -> m a -> m a
- insertStms :: Buildable rep => Stms rep -> Body rep -> Body rep
- insertStm :: Buildable rep => Stm rep -> Body rep -> Body rep
- letBind :: MonadBuilder m => Pat (LetDec (Rep m)) -> Exp (Rep m) -> m ()
- letBindNames :: MonadBuilder m => [VName] -> Exp (Rep m) -> m ()
- collectStms_ :: MonadBuilder m => m a -> m (Stms (Rep m))
- bodyBind :: MonadBuilder m => Body (Rep m) -> m Result
- attributing :: MonadBuilder m => Attrs -> m a -> m a
- auxing :: MonadBuilder m => StmAux anyrep -> m a -> m a
- module Futhark.MonadFreshNames

# Documentation

class (ASTRep rep, FParamInfo rep ~ DeclType, LParamInfo rep ~ Type, RetType rep ~ DeclExtType, BranchType rep ~ ExtType) => Buildable rep where Source #

The class of representations that can be constructed solely from an expression, within some monad. Very important: the methods should not have any significant side effects! They may be called more often than you think, and the results thrown away. If used exclusively within a `MonadBuilder` instance, it is acceptable for them to create new bindings, however.

Methods

mkExpPat :: [Ident] -> Exp rep -> Pat (LetDec rep) Source #

mkExpDec :: Pat (LetDec rep) -> Exp rep -> ExpDec rep Source #

mkBody :: Stms rep -> Result -> Body rep Source #

mkLetNames :: (MonadFreshNames m, HasScope rep m) => [VName] -> Exp rep -> m (Stm rep) Source #

#### Instances

Instances details

Buildable GPU Source # |
Instance details Defined in Futhark.IR.GPU Methods mkExpPat :: [Ident] -> Exp GPU -> Pat (LetDec GPU) Source # mkExpDec :: Pat (LetDec GPU) -> Exp GPU -> ExpDec GPU Source # mkBody :: Stms GPU -> Result -> Body GPU Source # mkLetNames :: (MonadFreshNames m, HasScope GPU m) => [VName] -> Exp GPU -> m (Stm GPU) Source #
Buildable MC Source # |
Instance details Defined in Futhark.IR.MC Methods mkExpPat :: [Ident] -> Exp MC -> Pat (LetDec MC) Source # mkExpDec :: Pat (LetDec MC) -> Exp MC -> ExpDec MC Source # mkBody :: Stms MC -> Result -> Body MC Source # mkLetNames :: (MonadFreshNames m, HasScope MC m) => [VName] -> Exp MC -> m (Stm MC) Source #
Buildable SOACS Source # |
Instance details Defined in Futhark.IR.SOACS Methods mkExpPat :: [Ident] -> Exp SOACS -> Pat (LetDec SOACS) Source # mkExpDec :: Pat (LetDec SOACS) -> Exp SOACS -> ExpDec SOACS Source # mkBody :: Stms SOACS -> Result -> Body SOACS Source # mkLetNames :: (MonadFreshNames m, HasScope SOACS m) => [VName] -> Exp SOACS -> m (Stm SOACS) Source #
Buildable Seq Source # |
Instance details Defined in Futhark.IR.Seq Methods mkExpPat :: [Ident] -> Exp Seq -> Pat (LetDec Seq) Source # mkExpDec :: Pat (LetDec Seq) -> Exp Seq -> ExpDec Seq Source # mkBody :: Stms Seq -> Result -> Body Seq Source # mkLetNames :: (MonadFreshNames m, HasScope Seq m) => [VName] -> Exp Seq -> m (Stm Seq) Source #
(Buildable rep, AliasedOp (OpC rep), ASTConstraints (OpC rep (Aliases rep))) => Buildable (Aliases rep) Source # |

Instance details

Defined in Futhark.IR.Aliases

Methods

mkExpPat :: [Ident] -> Exp (Aliases rep) -> Pat (LetDec (Aliases rep)) Source #

mkExpDec :: Pat (LetDec (Aliases rep)) -> Exp (Aliases rep) -> ExpDec (Aliases rep) Source #

mkBody :: Stms (Aliases rep) -> Result -> Body (Aliases rep) Source #

mkLetNames :: (MonadFreshNames m, HasScope (Aliases rep) m) => [VName] -> Exp (Aliases rep) -> m (Stm (Aliases rep)) Source #

(Buildable rep, Informing rep) => Buildable (Wise rep) Source # |

Instance details

Defined in Futhark.Optimise.Simplify.Rep

Methods

mkExpPat :: [Ident] -> Exp (Wise rep) -> Pat (LetDec (Wise rep)) Source #

mkExpDec :: Pat (LetDec (Wise rep)) -> Exp (Wise rep) -> ExpDec (Wise rep) Source #

mkBody :: Stms (Wise rep) -> Result -> Body (Wise rep) Source #

mkLetNames :: (MonadFreshNames m, HasScope (Wise rep) m) => [VName] -> Exp (Wise rep) -> m (Stm (Wise rep)) Source #

mkLet :: Buildable rep => [Ident] -> Exp rep -> Stm rep Source #

Construct a `Stm` from identifiers for the context- and value part of the pattern, as well as the expression.

mkLet' :: Buildable rep => [Ident] -> StmAux a -> Exp rep -> Stm rep Source #

Like mkLet, but also take attributes and certificates from the given `StmAux`.

class (ASTRep (Rep m), MonadFreshNames m, Applicative m, Monad m, LocalScope (Rep m) m) => MonadBuilder m where Source #

A monad that supports the creation of bindings from expressions and bodies from bindings, with a specific rep. This is the main typeclass that a monad must implement in order for it to be useful for generating or modifying Futhark code. Most importantly maintains a current state of `Stms` (as well as a `Scope`) that have been added with `addStm`.

Very important: the methods should not have any significant side effects! They may be called more often than you think, and the results thrown away. It is acceptable for them to create new bindings, however.

Minimal complete definition

mkExpDecM, mkBodyM, mkLetNamesM, addStms, collectStms

Associated Types

type Rep m :: Type Source #

Methods

mkExpDecM :: Pat (LetDec (Rep m)) -> Exp (Rep m) -> m (ExpDec (Rep m)) Source #

mkBodyM :: Stms (Rep m) -> Result -> m (Body (Rep m)) Source #

mkLetNamesM :: [VName] -> Exp (Rep m) -> m (Stm (Rep m)) Source #

addStm :: Stm (Rep m) -> m () Source #

Add a statement to the `Stms` under construction.

addStms :: Stms (Rep m) -> m () Source #

Add multiple statements to the `Stms` under construction.

collectStms :: m a -> m (a, Stms (Rep m)) Source #

Obtain the statements constructed during a monadic action, instead of adding them to the state.

certifying :: Certs -> m a -> m a Source #

Add the provided certificates to any statements added during execution of the action.

#### Instances

Instances details

MonadBuilder ADM Source # |

Instance details

Defined in Futhark.AD.Rev.Monad

Associated Types

type Rep ADM Source #

Methods

mkExpDecM :: Pat (LetDec (Rep ADM)) -> Exp (Rep ADM) -> ADM (ExpDec (Rep ADM)) Source #

mkBodyM :: Stms (Rep ADM) -> Result -> ADM (Body (Rep ADM)) Source #

mkLetNamesM :: [VName] -> Exp (Rep ADM) -> ADM (Stm (Rep ADM)) Source #

addStm :: Stm (Rep ADM) -> ADM () Source #

addStms :: Stms (Rep ADM) -> ADM () Source #

collectStms :: ADM a -> ADM (a, Stms (Rep ADM)) Source #

certifying :: Certs -> ADM a -> ADM a Source #

MonadBuilder InternaliseM Source # |

Instance details

Defined in Futhark.Internalise.Monad

Associated Types

type Rep InternaliseM Source #

Methods

mkExpDecM :: Pat (LetDec (Rep InternaliseM)) -> Exp (Rep InternaliseM) -> InternaliseM (ExpDec (Rep InternaliseM)) Source #

mkBodyM :: Stms (Rep InternaliseM) -> Result -> InternaliseM (Body (Rep InternaliseM)) Source #

mkLetNamesM :: [VName] -> Exp (Rep InternaliseM) -> InternaliseM (Stm (Rep InternaliseM)) Source #

addStm :: Stm (Rep InternaliseM) -> InternaliseM () Source #

addStms :: Stms (Rep InternaliseM) -> InternaliseM () Source #

collectStms :: InternaliseM a -> InternaliseM (a, Stms (Rep InternaliseM)) Source #

certifying :: Certs -> InternaliseM a -> InternaliseM a Source #

BuilderOps rep => MonadBuilder (RuleM rep) Source # |

Instance details

Defined in Futhark.Optimise.Simplify.Rule

Associated Types

type Rep (RuleM rep) Source #

Methods

mkExpDecM :: Pat (LetDec (Rep (RuleM rep))) -> Exp (Rep (RuleM rep)) -> RuleM rep (ExpDec (Rep (RuleM rep))) Source #

mkBodyM :: Stms (Rep (RuleM rep)) -> Result -> RuleM rep (Body (Rep (RuleM rep))) Source #

mkLetNamesM :: [VName] -> Exp (Rep (RuleM rep)) -> RuleM rep (Stm (Rep (RuleM rep))) Source #

addStm :: Stm (Rep (RuleM rep)) -> RuleM rep () Source #

addStms :: Stms (Rep (RuleM rep)) -> RuleM rep () Source #

collectStms :: RuleM rep a -> RuleM rep (a, Stms (Rep (RuleM rep))) Source #

certifying :: Certs -> RuleM rep a -> RuleM rep a Source #

(MonadFreshNames m, BuilderOps rep) => MonadBuilder (BuilderT rep m) Source # |

Instance details

Defined in Futhark.Builder

Associated Types

type Rep (BuilderT rep m) Source #

Methods

mkExpDecM :: Pat (LetDec (Rep (BuilderT rep m))) -> Exp (Rep (BuilderT rep m)) -> BuilderT rep m (ExpDec (Rep (BuilderT rep m))) Source #

mkBodyM :: Stms (Rep (BuilderT rep m)) -> Result -> BuilderT rep m (Body (Rep (BuilderT rep m))) Source #

mkLetNamesM :: [VName] -> Exp (Rep (BuilderT rep m)) -> BuilderT rep m (Stm (Rep (BuilderT rep m))) Source #

addStm :: Stm (Rep (BuilderT rep m)) -> BuilderT rep m () Source #

addStms :: Stms (Rep (BuilderT rep m)) -> BuilderT rep m () Source #

collectStms :: BuilderT rep m a -> BuilderT rep m (a, Stms (Rep (BuilderT rep m))) Source #

certifying :: Certs -> BuilderT rep m a -> BuilderT rep m a Source #

Allocable fromrep torep inner => MonadBuilder (AllocM fromrep torep) Source # |

Instance details

Defined in Futhark.Pass.ExplicitAllocations

Associated Types

type Rep (AllocM fromrep torep) Source #

Methods

mkExpDecM :: Pat (LetDec (Rep (AllocM fromrep torep))) -> Exp (Rep (AllocM fromrep torep)) -> AllocM fromrep torep (ExpDec (Rep (AllocM fromrep torep))) Source #

mkBodyM :: Stms (Rep (AllocM fromrep torep)) -> Result -> AllocM fromrep torep (Body (Rep (AllocM fromrep torep))) Source #

mkLetNamesM :: [VName] -> Exp (Rep (AllocM fromrep torep)) -> AllocM fromrep torep (Stm (Rep (AllocM fromrep torep))) Source #

addStm :: Stm (Rep (AllocM fromrep torep)) -> AllocM fromrep torep () Source #

addStms :: Stms (Rep (AllocM fromrep torep)) -> AllocM fromrep torep () Source #

collectStms :: AllocM fromrep torep a -> AllocM fromrep torep (a, Stms (Rep (AllocM fromrep torep))) Source #

certifying :: Certs -> AllocM fromrep torep a -> AllocM fromrep torep a Source #

insertStms :: Buildable rep => Stms rep -> Body rep -> Body rep Source #

Add several bindings at the outermost level of a `Body`.

insertStm :: Buildable rep => Stm rep -> Body rep -> Body rep Source #

Add a single binding at the outermost level of a `Body`.

letBind :: MonadBuilder m => Pat (LetDec (Rep m)) -> Exp (Rep m) -> m () Source #

Add a statement with the given pattern and expression.

letBindNames :: MonadBuilder m => [VName] -> Exp (Rep m) -> m () Source #

Add a statement with the given pattern element names and expression.

collectStms_ :: MonadBuilder m => m a -> m (Stms (Rep m)) Source #

As `collectStms`, but throw away the ordinary result.

bodyBind :: MonadBuilder m => Body (Rep m) -> m Result Source #

Add the statements of the body, then return the body result.

attributing :: MonadBuilder m => Attrs -> m a -> m a Source #

Add the given attributes to any statements added by this action.

auxing :: MonadBuilder m => StmAux anyrep -> m a -> m a Source #

Add the certificates and attributes to any statements added by this action.

module Futhark.MonadFreshNames