feldspar-language-0.6.0.2: A functional embedded language for DSP and parallelism

Safe Haskell | None

Feldspar.Core.Interpretation

Description

Defines different interpretations of Feldspar programs

Synopsis

- module Language.Syntactic.Constructs.Decoration
- module Feldspar.Core.Interpretation.Typed
- targetSpecialization :: BitWidth n -> ASTF dom a -> ASTF dom a
- class Sharable dom where
  - sharable :: dom a -> Bool
- class SizeProp feature where
  - sizeProp :: feature a -> Args (WrapFull Info) a -> Size (DenResult a)
- sizePropDefault :: Type (DenResult a) => feature a -> Args (WrapFull Info) a -> Size (DenResult a)
- resultType :: Type (DenResult a) => c a -> TypeRep (DenResult a)
- type SourceInfo = String
- data Info a where
  - Info :: Show (Size a) => {
    - infoType :: TypeRep a
    - infoSize :: Size a
    - infoVars :: VarInfo
    - infoSource :: SourceInfo
    } -> Info a
- mkInfo :: Type a => Size a -> Info a
- mkInfoTy :: (Show (Size a), Lattice (Size a)) => TypeRep a -> Info a
- infoRange :: Type a => Info a -> RangeSet a
- class LatticeSize1 m where
  - mergeSize :: Lattice (Size a) => Info (m a) -> Size (m a) -> Size (m a) -> Size (m a)
- viewLiteral :: forall info dom a. (Literal :|| Type) :<: dom => ASTF (Decor info (dom :|| Typeable)) a -> Maybe a
- literalDecor :: (Type a, (Literal :|| Type) :<: dom) => a -> ASTF (Decor Info (dom :|| Typeable)) a
- constFold :: (Typed dom, (Literal :|| Type) :<: dom) => SourceInfo -> ASTF (Decor Info (dom :|| Typeable)) a -> a -> ASTF (Decor Info (dom :|| Typeable)) a
- data SomeInfo where
  - SomeInfo :: Typeable a => Info a -> SomeInfo
- data SomeType where
  - SomeType :: TypeRep a -> SomeType
- data Env = Env {
  - varEnv :: [(VarId, SomeInfo)]
  - sourceEnv :: SourceInfo
  }
- localVar :: Typeable b => VarId -> Info b -> Opt a -> Opt a
- localSource :: SourceInfo -> Opt a -> Opt a
- type Opt = Reader Env
- class Optimize feature dom where
  - optimizeFeat :: (Typeable (DenResult a), OptimizeSuper dom) => feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
  - constructFeatOpt :: Typeable (DenResult a) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
  - constructFeatUnOpt :: Typeable (DenResult a) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- class (AlphaEq dom dom (dom :|| Typeable) [(VarId, VarId)], AlphaEq dom dom (Decor Info (dom :|| Typeable)) [(VarId, VarId)], EvalBind dom, (Literal :|| Type) :<: dom, Typed dom, Constrained dom, Optimize dom dom) => OptimizeSuper dom
- constructFeat :: (Typeable (DenResult a), Optimize feature dom) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- optimizeM :: OptimizeSuper dom => ASTF (dom :|| Typeable) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) a)
- optimize :: (Typeable a, OptimizeSuper dom) => ASTF (dom :|| Typeable) a -> ASTF (Decor Info (dom :|| Typeable)) a
- constructFeatUnOptDefaultTyp :: (feature :<: dom, SizeProp feature, Typeable (DenResult a), Show (Size (DenResult a))) => TypeRep (DenResult a) -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- constructFeatUnOptDefault :: (feature :<: dom, SizeProp feature, Type (DenResult a)) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- optimizeFeatDefault :: (Optimize feature dom, Typeable (DenResult a), OptimizeSuper dom) => feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- prjF :: Project (sub :|| Type) sup => sup sig -> Maybe ((sub :|| Type) sig)
- c' :: Type (DenResult sig) => feature sig -> (feature :|| Type) sig

# Documentation

module Language.Syntactic.Constructs.Decoration

module Feldspar.Core.Interpretation.Typed

targetSpecialization :: BitWidth n -> ASTF dom a -> ASTF dom a

Specialize the program for a target platform with the given native bit width

class Sharable dom where

Indication whether a symbol is sharable or not

Methods

sharable :: dom a -> Bool

Instances

Sharable Variable |
Sharable Lambda |
Sharable Let |
Sharable Tuple |
Sharable Select |
Sharable Literal |
Sharable Condition |
Sharable Empty |
Sharable ORD |
Sharable EQ |
Sharable Logic |
Sharable BITS |
Sharable COMPLEX |
Sharable Error |
Sharable FLOATING |
Sharable NUM |
Sharable FRACTIONAL |
Sharable INTEGRAL |
Sharable NoInline |
Sharable Trace |
Sharable FFI |
Sharable Save |
Sharable Array |
Sharable FUTURE |
Sharable Loop |
Sharable Mutable |
Sharable Conversion |
Sharable MutableArray |
Sharable MutableReference |
Sharable MutableToPure |
Sharable ParFeature |
Sharable PropSize |
Sharable (MONAD Par) |
Sharable (MONAD Mut) |
Sharable (ConditionM m) |
Sharable (LoopM m) |
Sharable dom => Sharable (Decor Info dom) |
Sharable (Decor SourceInfo1 Identity) |
Sharable sym => Sharable (:|| sym pred) |
(Sharable sub1, Sharable sub2) => Sharable (:+: sub1 sub2) |
Sharable sym => Sharable (SubConstr2 c sym p1 p2) |

class SizeProp feature where

Forwards size propagation

Methods

sizeProp :: feature a -> Args (WrapFull Info) a -> Size (DenResult a)

Size propagation for a symbol given a list of argument sizes

Instances

SizeProp Identity |
SizeProp Mutable |
SizeProp MutableArray |
SizeProp MutableReference |
SizeProp MutableToPure |
SizeProp ParFeature |
SizeProp (MONAD Par) |
SizeProp (MONAD Mut) |
LatticeSize1 m => SizeProp (ConditionM m) |
SizeProp (LoopM m) |
SizeProp (:|| Let Type) |
SizeProp (:|| Tuple Type) |
SizeProp (:|| Select Type) |
SizeProp (:|| Literal Type) |
SizeProp (:|| (Decor SourceInfo1 Identity) Type) |
SizeProp (:|| Condition Type) |
SizeProp (:|| ORD Type) |
SizeProp (:|| EQ Type) |
SizeProp (:|| Logic Type) |
SizeProp (:|| BITS Type) |
SizeProp (:|| COMPLEX Type) |
SizeProp (:|| Error Type) |
SizeProp (:|| FLOATING Type) |
SizeProp (:|| NUM Type) |
SizeProp (:|| FRACTIONAL Type) |
SizeProp (:|| INTEGRAL Type) |
SizeProp (:|| NoInline Type) |
SizeProp (:|| Trace Type) |
SizeProp (:|| FFI Type) |
SizeProp (:|| Save Type) |
SizeProp (:|| Array Type) |
SizeProp (:|| FUTURE Type) |
SizeProp (:|| Loop Type) |
SizeProp (:|| Conversion Type) |
SizeProp (:|| PropSize Type) |

sizePropDefault :: Type (DenResult a) => feature a -> Args (WrapFull Info) a -> Size (DenResult a)

Convenient default implementation of `sizeProp`

resultType :: Type (DenResult a) => c a -> TypeRep (DenResult a)

Compute a type representation of a symbol's result type

type SourceInfo = String

Information about the source code of an expression

data Info a where

Type and size information of a Feldspar program

Constructors

Info :: Show (Size a) => TypeRep a -> Size a -> VarInfo -> SourceInfo -> Info a |

Fields

infoType :: TypeRep a
infoSize :: Size a
infoVars :: VarInfo
infoSource :: SourceInfo

Instances

Render Info |
Eq (Size a) => Eq (Info a) |
Sharable dom => Sharable (Decor Info dom) |

mkInfo :: Type a => Size a -> Info a

mkInfoTy :: (Show (Size a), Lattice (Size a)) => TypeRep a -> Info a

infoRange :: Type a => Info a -> RangeSet a

class LatticeSize1 m where

This class is used to allow constructs to be abstract in the monad. Its purpose is similar to that of `MonadType`.

Methods

mergeSize :: Lattice (Size a) => Info (m a) -> Size (m a) -> Size (m a) -> Size (m a)

Instances

LatticeSize1 Mut |

viewLiteral :: forall info dom a. (Literal :|| Type) :<: dom => ASTF (Decor info (dom :|| Typeable)) a -> Maybe a

It the expression is a literal, its value is returned, otherwise `Nothing`

literalDecor :: (Type a, (Literal :|| Type) :<: dom) => a -> ASTF (Decor Info (dom :|| Typeable)) a

Construct a `Literal` decorated with `Info`

constFold :: (Typed dom, (Literal :|| Type) :<: dom) => SourceInfo -> ASTF (Decor Info (dom :|| Typeable)) a -> a -> ASTF (Decor Info (dom :|| Typeable)) a

Replaces an expression with a literal if the type permits, otherwise returns the expression unchanged.

data SomeInfo where

`Info` with hidden result type

Constructors

SomeInfo :: Typeable a => Info a -> SomeInfo |

data SomeType where

Constructors

SomeType :: TypeRep a -> SomeType |

data Env

Constructors

Env |

Fields

varEnv :: [(VarId, SomeInfo)]
sourceEnv :: SourceInfo

localVar :: Typeable b => VarId -> Info b -> Opt a -> Opt a

Insert a variable into the environment

localSource :: SourceInfo -> Opt a -> Opt a

Change the `SourceInfo` environment

type Opt = Reader Env

Environment for optimization

class Optimize feature dom where

Basic optimization of a feature

This optimization is similar to `Optimize`, but it also performs size inference. Size inference has to be done simultaneously with other optimizations in order to avoid iterating the phases. (Size information may help optimization and optimization may help size inference.)

Methods

optimizeFeat :: (Typeable (DenResult a), OptimizeSuper dom) => feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Top-down and bottom-up optimization of a feature

constructFeatOpt :: Typeable (DenResult a) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Optimized construction of an expression from a symbol and its optimized arguments

Note: This function should normally not be called directly. Instead, use `constructFeat` which has more accurate propagation of `Info`.

constructFeatUnOpt :: Typeable (DenResult a) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Unoptimized construction of an expression from a symbol and its optimized arguments

Instances

Optimize Empty dom |
(:<: Mutable dom, OptimizeSuper dom) => Optimize Mutable dom |
(:<: MutableArray dom, Optimize dom dom) => Optimize MutableArray dom |
(:<: MutableReference dom, Optimize dom dom) => Optimize MutableReference dom |
(:<: MutableToPure dom, Optimize dom dom) => Optimize MutableToPure dom |
(:<: (MONAD Par) dom, :<: ParFeature dom, Optimize dom dom) => Optimize ParFeature dom |
(:<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (CLambda Type) dom |
(:<: (MONAD Par) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (MONAD Par) dom |
(:<: (MONAD Mut) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (MONAD Mut) dom |
(:<: (ConditionM m) dom, :<: (:|| Logic Type) dom, OptimizeSuper dom, LatticeSize1 m) => Optimize (ConditionM m) dom |
(MonadType m, :<: (LoopM m) dom, :<: (CLambda Type) dom, Optimize dom dom) => Optimize (LoopM m) dom |
(:<: (:|| Variable Type) dom, OptimizeSuper dom) => Optimize (:|| Variable Type) dom |
(:<: (:|| Let Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (:|| Let Type) dom |
(:<: (:|| Tuple Type) dom, :<: (:|| Select Type) dom, OptimizeSuper dom) => Optimize (:|| Tuple Type) dom |
(:<: (:|| Select Type) dom, :<: (:|| Tuple Type) dom, Optimize dom dom) => Optimize (:|| Select Type) dom |
(:<: (:|| Literal Type) dom, OptimizeSuper dom) => Optimize (:|| Literal Type) dom |
(:<: (:|| (Decor SourceInfo1 Identity) Type) dom, Optimize dom dom) => Optimize (:|| (Decor SourceInfo1 Identity) Type) dom |
(:<: (:|| Condition Type) dom, :<: (:|| Logic Type) dom, OptimizeSuper dom) => Optimize (:|| Condition Type) dom |
(:<: (:|| ORD Type) dom, OptimizeSuper dom) => Optimize (:|| ORD Type) dom |
(:<: (:|| EQ Type) dom, OptimizeSuper dom) => Optimize (:|| EQ Type) dom |
(:<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, OptimizeSuper dom) => Optimize (:|| Logic Type) dom |
(:<: (:|| BITS Type) dom, :<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, OptimizeSuper dom) => Optimize (:|| BITS Type) dom |
(:<: (:|| COMPLEX Type) dom, OptimizeSuper dom) => Optimize (:|| COMPLEX Type) dom |
(:<: (:|| Error Type) dom, Optimize dom dom) => Optimize (:|| Error Type) dom |
(:<: (:|| FLOATING Type) dom, OptimizeSuper dom) => Optimize (:|| FLOATING Type) dom |
(:<: (:|| NUM Type) dom, :<: (:|| Literal Type) dom, OptimizeSuper dom) => Optimize (:|| NUM Type) dom |
(:<: (:|| FRACTIONAL Type) dom, :<: (:|| NUM Type) dom, OptimizeSuper dom) => Optimize (:|| FRACTIONAL Type) dom |
(:<: (:|| INTEGRAL Type) dom, :<: (:|| BITS Type) dom, :<: (:|| NUM Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, :<: (:|| Condition Type) dom, :<: (:|| Logic Type) dom, OptimizeSuper dom, Optimize (:|| Condition Type) dom) => Optimize (:|| INTEGRAL Type) dom |
(:<: (:|| NoInline Type) dom, OptimizeSuper dom) => Optimize (:|| NoInline Type) dom |
(:<: (:|| Trace Type) dom, OptimizeSuper dom) => Optimize (:|| Trace Type) dom |
(:<: (:|| FFI Type) dom, OptimizeSuper dom) => Optimize (:|| FFI Type) dom |
(:<: (:|| Save Type) dom, OptimizeSuper dom) => Optimize (:|| Save Type) dom |
(:<: (:|| Array Type) dom, :<: (:|| NUM Type) dom, :<: (:|| ORD Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (:|| Array Type) dom |
(:<: (:|| FUTURE Type) dom, OptimizeSuper dom) => Optimize (:|| FUTURE Type) dom |
(:<: (:|| Literal Type) dom, :<: (:|| Loop Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (:|| Loop Type) dom |
(:<: (:|| Conversion Type) dom, OptimizeSuper dom) => Optimize (:|| Conversion Type) dom |
(:<: (:|| PropSize Type) dom, OptimizeSuper dom) => Optimize (:|| PropSize Type) dom |
(Optimize sub1 dom, Optimize sub2 dom) => Optimize (:+: sub1 sub2) dom |

class (AlphaEq dom dom (dom :|| Typeable) [(VarId, VarId)], AlphaEq dom dom (Decor Info (dom :|| Typeable)) [(VarId, VarId)], EvalBind dom, (Literal :|| Type) :<: dom, Typed dom, Constrained dom, Optimize dom dom) => OptimizeSuper dom

Instances

(AlphaEq dom dom (:|| dom Typeable) [(VarId, VarId)], AlphaEq dom dom (Decor Info (:|| dom Typeable)) [(VarId, VarId)], EvalBind dom, :<: (:|| Literal Type) dom, Typed dom, Constrained dom, Optimize dom dom) => OptimizeSuper dom |

constructFeat :: (Typeable (DenResult a), Optimize feature dom) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Optimized construction of an expression from a symbol and its optimized arguments

optimizeM :: OptimizeSuper dom => ASTF (dom :|| Typeable) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) a)

Optimization of an expression

In addition to running `optimizeFeat`, this function performs constant folding on all closed expressions, provided that the type permits making a literal.

optimize :: (Typeable a, OptimizeSuper dom) => ASTF (dom :|| Typeable) a -> ASTF (Decor Info (dom :|| Typeable)) a

Optimization of an expression. This function runs `optimizeM` and extracts the result.

constructFeatUnOptDefaultTyp :: (feature :<: dom, SizeProp feature, Typeable (DenResult a), Show (Size (DenResult a))) => TypeRep (DenResult a) -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Convenient default implementation of `constructFeatUnOpt`. Uses `sizeProp` to propagate size.

constructFeatUnOptDefault :: (feature :<: dom, SizeProp feature, Type (DenResult a)) => feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Like `constructFeatUnOptDefaultTyp` but without an explicit `TypeRep`

optimizeFeatDefault :: (Optimize feature dom, Typeable (DenResult a), OptimizeSuper dom) => feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))

Convenient default implementation of `optimizeFeat`

prjF :: Project (sub :|| Type) sup => sup sig -> Maybe ((sub :|| Type) sig)

c' :: Type (DenResult sig) => feature sig -> (feature :|| Type) sig