clash-lib-0.6.4: CAES Language for Synchronous Hardware - As a Library

Safe HaskellNone
LanguageHaskell2010

CLaSH.Rewrite.Util

Description

Utilities for rewriting: e.g. inlining, specialisation, etc.

Synopsis

Documentation

zoomExtra :: State extra a -> RewriteMonad extra a Source

Lift an action working in the _extra state to the RewriteMonad

apply Source

Arguments

:: String

Name of the transformation

-> Rewrite extra

Transformation to be applied

-> Rewrite extra 

Record if a transformation is succesfully applied

runRewrite Source

Arguments

:: String

Name of the transformation

-> Rewrite extra

Transformation to perform

-> Term

Term to transform

-> RewriteMonad extra Term 

Perform a transformation on a Term

runRewriteSession :: RewriteEnv -> RewriteState extra -> RewriteMonad extra a -> a Source

Evaluate a RewriteSession to its inner monad

setChanged :: RewriteMonad extra () Source

Notify that a transformation has changed the expression

changed :: a -> RewriteMonad extra a Source

Identity function that additionally notifies that a transformation has changed the expression

contextEnv :: [CoreContext] -> (Gamma, Delta) Source

Create a type and kind context out of a transformation context

mkEnv :: [CoreContext] -> RewriteMonad extra (Gamma, Delta) Source

Create a complete type and kind context out of the global binders and the transformation context

mkTmBinderFor Source

Arguments

:: (Functor m, Fresh m, MonadUnique m) 
=> HashMap TyConName TyCon

TyCon cache

-> String

Name of the new binder

-> Term

Term to bind

-> m (Id, Term) 

Make a new binder and variable reference for a term

mkBinderFor Source

Arguments

:: (Functor m, Monad m, MonadUnique m, Fresh m) 
=> HashMap TyConName TyCon

TyCon cache

-> String

Name of the new binder

-> Either Term Type

Type or Term to bind

-> m (Either (Id, Term) (TyVar, Type)) 

Make a new binder and variable reference for either a term or a type

mkInternalVar Source

Arguments

:: (Functor m, Monad m, MonadUnique m) 
=> String

Name of the identifier

-> KindOrType 
-> m (Id, Term) 

Make a new, unique, identifier and corresponding variable reference

inlineBinders Source

Arguments

:: (Term -> LetBinding -> RewriteMonad extra Bool)

Property test

-> Rewrite extra 

Inline the binders in a let-binding that have a certain property

isJoinPointIn Source

Arguments

:: Id

Id of the local binder

-> Term

Expression in which the binder is bound

-> Bool 

Determine whether a binder is a join-point created for a complex case expression.

A join-point is when a local function only occurs in tail-call positions, and when it does, more than once.

tailCalls Source

Arguments

:: Id

Function to check

-> Term

Expression to check it in

-> Maybe Int 

Count the number of (only) tail calls of a function in an expression. Nothing indicates that the function was used in a non-tail call position.

substituteBinders Source

Arguments

:: [LetBinding]

Let-binders to substitute

-> [LetBinding]

Let-binders where substitution takes place

-> Term

Expression where substitution takes place

-> ([LetBinding], Term) 

Substitute the RHS of the first set of Let-binders for references to the first set of Let-binders in: the second set of Let-binders and the additional term

localFreeIds :: (Applicative f, Contravariant f) => RewriteMonad extra ((TmName -> f TmName) -> Term -> f Term) Source

Calculate the local free variable of an expression: the free variables that are not bound in the global environment.

liftBinders Source

Arguments

:: (Term -> LetBinding -> RewriteMonad extra Bool)

Property test

-> Rewrite extra 

Lift the binders in a let-binding to a global function that have a certain property

liftBinding :: Gamma -> Delta -> LetBinding -> RewriteMonad extra LetBinding Source

Create a global function for a Let-binding and return a Let-binding where the RHS is a reference to the new global function applied to the free variables of the original RHS

mkFunction Source

Arguments

:: TmName

Name of the function

-> Term

Term bound to the function

-> RewriteMonad extra (TmName, Type)

Name with a proper unique and the type of the function

Make a global function for a name-term tuple

addGlobalBind :: TmName -> Type -> Term -> RewriteMonad extra () Source

Add a function to the set of global binders

cloneVar :: TmName -> RewriteMonad extra TmName Source

Create a new name out of the given name, but with another unique

isLocalVar :: Term -> RewriteMonad extra Bool Source

Test whether a term is a variable reference to a local binder

isUntranslatable :: Term -> RewriteMonad extra Bool Source

Determine if a term cannot be represented in hardware

isUntranslatableType :: Type -> RewriteMonad extra Bool Source

Determine if a type cannot be represented in hardware

isLambdaBodyCtx :: CoreContext -> Bool Source

Is the Context a Lambda/Term-abstraction context?

mkWildValBinder :: (Functor m, Monad m, MonadUnique m) => Type -> m Id Source

Make a binder that should not be referenced

mkSelectorCase Source

Arguments

:: (Functor m, Monad m, MonadUnique m, Fresh m) 
=> String

Name of the caller of this function

-> HashMap TyConName TyCon

TyCon cache

-> Term

Subject of the case-composition

-> Int 
-> Int 
-> m Term 

Make a case-decomposition that extracts a field out of a (Sum-of-)Product type

specialise Source

Arguments

:: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type))

Lens into previous specialisations

-> Lens' extra (HashMap TmName Int)

Lens into the specialisation history

-> Lens' extra Int

Lens into the specialisation limit

-> Rewrite extra 

Specialise an application on its argument

specialise' Source

Arguments

:: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type))

Lens into previous specialisations

-> Lens' extra (HashMap TmName Int)

Lens into specialisation history

-> Lens' extra Int

Lens into the specialisation limit

-> [CoreContext] 
-> Term

Original term

-> (Term, [Either Term Type])

Function part of the term, split into root and applied arguments

-> Either Term Type

Argument to specialize on

-> RewriteMonad extra Term 

Specialise an application on its argument

specArgBndrsAndVars :: [CoreContext] -> Either Term Type -> RewriteMonad extra ([Either Id TyVar], [Either Term Type]) Source

Create binders and variable references for free variables in specArg