feldspar-language-0.7: 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

class SizeProp feature whereSource

Forwards size propagation

Methods

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

Size propagation for a symbol given a list of argument sizes

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), Lattice (Size a)) => TypeRep a -> Size a -> VarInfo -> SourceInfo -> Info a 

Fields

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

Instances

Show (Info a) 
Monotonic dom => Monotonic (Decor Info dom) 
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

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

Construct a Literal

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 

Fields

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

data FeldOpts Source

A record with options for explicit passing in rewrite rules.

Constructors

FeldOpts 

Fields

targets :: [Target]
 

data Target Source

Possible compilation targets.

Constructors

RegionInf 
SICS 

Instances

inTarget :: Target -> FeldOpts -> BoolSource

Decide whether a Target is enabled in FeldOpts.

defaultFeldOpts :: FeldOptsSource

Default options.

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) => FeldOpts -> 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) => FeldOpts -> 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) => FeldOpts -> 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 
(:<: Let dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize Let dom 
(:<: Mutable dom, :<: (MONAD Mut) dom, OptimizeSuper dom) => Optimize Mutable dom 
(:<: MutableReference dom, :<: (MONAD Mut) dom, Project (CLambda Type) dom, Project (:|| Variable Type) dom, OptimizeSuper dom) => Optimize MutableReference dom 
(:<: MutableArray dom, Optimize dom dom) => Optimize MutableArray dom 
(:<: MutableToPure dom, Optimize dom dom) => Optimize MutableToPure dom 
(:<: (MONAD Par) dom, :<: ParFeature dom, Optimize dom dom) => Optimize ParFeature dom 
(:<: (MONAD Par) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: Let dom, OptimizeSuper dom) => Optimize (MONAD Par) dom 
(:<: (MONAD Mut) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: Let dom, OptimizeSuper dom) => Optimize (MONAD Mut) dom 
(:<: (ConditionM m) dom, :<: (:|| Logic Type) dom, OptimizeSuper dom, LatticeSize1 m) => Optimize (ConditionM m) dom 
(:<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (CLambda Type) dom 
(:<: (LoopM Mut) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: (MONAD Mut) dom, :<: MutableReference dom, :<: Let dom, Optimize (CLambda Type) dom, Optimize (MONAD Mut) dom, Optimize dom dom) => Optimize (LoopM Mut) dom 
(Optimize sub1 dom, Optimize sub2 dom) => Optimize (:+: sub1 sub2) dom 
(:<: (:|| (Decor SourceInfo1 Identity) Type) dom, Optimize dom dom) => Optimize (:|| (Decor SourceInfo1 Identity) Type) dom 
(:<: (:|| Literal Type) dom, OptimizeSuper dom) => Optimize (:|| Literal Type) dom 
(:<: (:|| Tuple Type) dom, :<: (:|| Select Type) dom, OptimizeSuper dom) => Optimize (:|| Tuple Type) dom 
(:<: (:|| Select Type) dom, :<: (CLambda Type) dom, :<: (:|| Tuple Type) dom, :<: Let dom, :<: (:|| Variable Type) dom, OptimizeSuper dom) => Optimize (:|| Select Type) dom 
(:<: (:|| Condition Type) dom, :<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, Monotonic dom, OptimizeSuper dom) => Optimize (:|| Condition Type) dom 
(:<: (:|| Variable Type) dom, OptimizeSuper dom) => Optimize (:|| Variable Type) dom 
(:<: (:|| COMPLEX Type) dom, OptimizeSuper dom) => Optimize (:|| COMPLEX Type) dom 
(:<: (:|| ORD Type) dom, Monotonic 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, Monotonic dom, OptimizeSuper dom) => Optimize (:|| Logic Type) dom 
(:<: (:|| BITS Type) dom, :<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, Monotonic dom, OptimizeSuper dom) => Optimize (:|| BITS Type) dom 
(:<: (:|| INTEGRAL Type) dom, :<: (:|| BITS Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, :<: (:|| COMPLEX Type) dom, :<: (:|| Condition Type) dom, :<: (:|| Logic Type) dom, Monotonic dom, OptimizeSuper dom, Optimize (:|| Condition Type) dom) => Optimize (:|| INTEGRAL 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, :<: (:|| INTEGRAL Type) dom, :<: (:|| COMPLEX Type) dom, OptimizeSuper dom) => Optimize (:|| NUM Type) dom 
(:<: (:|| FRACTIONAL Type) dom, :<: (:|| NUM Type) dom, OptimizeSuper dom) => Optimize (:|| FRACTIONAL Type) dom 
(:<: (:|| NoInline Type) dom, OptimizeSuper dom) => Optimize (:|| NoInline Type) dom 
(:<: (:|| REALFLOAT Type) dom, OptimizeSuper dom) => Optimize (:|| REALFLOAT 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, :<: Let dom, :<: (:|| ORD Type) dom, :<: (:|| INTEGRAL Type) dom, :<: (:|| COMPLEX Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (:|| Array Type) dom 
(:<: (:|| FUTURE Type) dom, OptimizeSuper dom) => Optimize (:|| FUTURE Type) dom 
(:<: (:|| Switch Type) dom, :<: (:|| EQ Type) dom, :<: (:|| Condition Type) dom, OptimizeSuper dom) => Optimize (:|| Switch Type) dom 
(:<: (:|| Conversion Type) dom, OptimizeSuper dom) => Optimize (:|| Conversion Type) dom 
(:<: (:|| Literal Type) dom, :<: (:|| Loop Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: Let dom, OptimizeSuper dom) => Optimize (:|| Loop Type) dom 
(:<: (:|| PropSize Type) dom, OptimizeSuper dom) => Optimize (:|| PropSize Type) 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, Render 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, Render dom, Constrained dom, Optimize dom dom) => OptimizeSuper dom 

constructFeat :: (Typeable (DenResult a), Optimize feature dom) => FeldOpts -> 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 => FeldOpts -> 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) => FeldOpts -> 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)), Lattice (Size (DenResult a))) => FeldOpts -> 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)) => FeldOpts -> 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) => FeldOpts -> 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

class Monotonic feature whereSource

The Monotonic class represents (weak) monotonicity

Methods

monotonicInc :: feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> [ASTF (Decor Info (dom :|| Typeable)) (DenResult a)]Source

Return the arguments for which the symbol is monotonic increasing

forAll a. [a] = monotonicInc (f a) ==> f a >= a

monotonicDec :: feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> [ASTF (Decor Info (dom :|| Typeable)) (DenResult a)]Source

Return the arguments for which the symbol is monotonic decreasing

forAll a. [a] = monotonicDec (f a) ==> f a <= a

viewMonotonicInc :: Monotonic dom => ASTF (Decor Info (dom :|| Typeable)) a -> [ASTF (Decor Info (dom :|| Typeable)) a]Source

Extract sub-expressions for which the expression is (weak) monotonic increasing

viewMonotonicDec :: Monotonic dom => ASTF (Decor Info (dom :|| Typeable)) a -> [ASTF (Decor Info (dom :|| Typeable)) a]Source

Extract sub-expressions for which the expression is (weak) monotonic decreasing