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

Safe HaskellNone

Feldspar.Core.Interpretation

Description

Defines different interpretations of Feldspar programs

Synopsis

Documentation

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

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

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

Convenient default implementation of sizeProp

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

Compute a type representation of a symbol's result type

type SourceInfo = StringSource

Information about the source code of an expression

data Info a whereSource

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 aSource

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

class LatticeSize1 m whereSource

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)Source

Instances

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

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

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

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)) aSource

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

data SomeInfo whereSource

Info with hidden result type

Constructors

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

data SomeType whereSource

Constructors

SomeType :: TypeRep a -> SomeType 

data Env Source

Constructors

Env 

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

Insert a variable into the environment

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

Change the SourceInfo environment

type Opt = Reader EnvSource

Environment for optimization

class Optimize feature dom whereSource

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))Source

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))Source

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))Source

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 Source

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))Source

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)Source

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)) aSource

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))Source

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))Source

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))Source

Convenient default implementation of optimizeFeat

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

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