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

Copyright(C) 2012-2016 University of Twente
2016 Myrtle Software Ltd
2017 Google Inc.
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
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

:: (Fresh m, MonadUnique m) 
=> HashMap TyConOccName TyCon

TyCon cache

-> Name a

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

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

TyCon cache

-> Name a

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

:: (Monad m, MonadUnique m) 
=> TmName

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.

isVoidWrapper :: Term -> Bool Source #

Determines whether a function has the following shape:

\(w :: Void) -> f a b c

i.e. is a wrapper around a (partially) applied function f, where the introduced argument w is not used by f

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 ((TmOccName -> f TmOccName) -> Term -> f Term) Source #

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

inlineOrLiftBinders Source #

Arguments

:: (LetBinding -> RewriteMonad extra Bool)

Property test

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

Test whether to lift or inline

  • True: inline
  • False: lift
-> Rewrite extra 

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

-> SrcSpan 
-> InlineSpec 
-> 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 -> SrcSpan -> InlineSpec -> Term -> RewriteMonad extra () Source #

Add a function to the set of global binders

cloneVar :: (Monad m, MonadUnique m) => Name a -> m (Name a) 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 Source #

Arguments

:: Bool

String representable

-> Term 
-> RewriteMonad extra Bool 

Determine if a term cannot be represented in hardware

isUntranslatableType Source #

Arguments

:: Bool

String representable

-> Type 
-> RewriteMonad extra Bool 

Determine if a type cannot be represented in hardware

isLambdaBodyCtx :: CoreContext -> Bool Source #

Is the Context a Lambda/Term-abstraction context?

mkWildValBinder :: (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 TyConOccName 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 (TmOccName, Int, Either Term Type) (TmName, Type))

Lens into previous specialisations

-> Lens' extra (HashMap TmOccName 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 (TmOccName, Int, Either Term Type) (TmName, Type))

Lens into previous specialisations

-> Lens' extra (HashMap TmOccName 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