Copyright  (C) 20122016 University of Twente 2016 Myrtle Software Ltd 2017 Google Inc. 20212022 QBayLogic B.V. 

License  BSD2 (see the file LICENSE) 
Maintainer  QBayLogic B.V. <devops@qbaylogic.com> 
Safe Haskell  None 
Language  Haskell2010 
Utilities for rewriting: e.g. inlining, specialisation, etc.
Synopsis
 zoomExtra :: State extra a > RewriteMonad extra a
 findAccidentialShadows :: Term > [[Id]]
 apply :: String > Rewrite extra > Rewrite extra
 applyDebug :: String > Term > Bool > Term > RewriteMonad extra Term
 runRewrite :: String > InScopeSet > Rewrite extra > Term > RewriteMonad extra Term
 runRewriteSession :: RewriteEnv > RewriteState extra > RewriteMonad extra a > IO a
 setChanged :: RewriteMonad extra ()
 changed :: a > RewriteMonad extra a
 closestLetBinder :: Context > Maybe Id
 mkDerivedName :: TransformContext > OccName > TmName
 mkTmBinderFor :: MonadUnique m => InScopeSet > TyConMap > Name a > Term > m Id
 mkBinderFor :: MonadUnique m => InScopeSet > TyConMap > Name a > Either Term Type > m (Either Id TyVar)
 inlineBinders :: (Term > LetBinding > RewriteMonad extra Bool) > Rewrite extra
 isJoinPointIn :: Id > Term > Bool
 tailCalls :: Id > Term > Maybe Int
 isVoidWrapper :: Term > Bool
 substituteBinders :: InScopeSet > [LetBinding] > [LetBinding] > Term > ([LetBinding], ([LetBinding], Term))
 liftAndSubsituteBinders :: InScopeSet > [LetBinding] > [LetBinding] > Term > RewriteMonad extra ([LetBinding], Term)
 isFromInt :: Text > Bool
 inlineOrLiftBinders :: (LetBinding > RewriteMonad extra Bool) > (Term > LetBinding > Bool) > Rewrite extra
 liftBinding :: LetBinding > RewriteMonad extra LetBinding
 mkFunction :: TmName > SrcSpan > InlineSpec > Term > RewriteMonad extra Id
 addGlobalBind :: TmName > Type > SrcSpan > InlineSpec > Term > RewriteMonad extra ()
 cloneNameWithInScopeSet :: MonadUnique m => InScopeSet > Name a > m (Name a)
 cloneNameWithBindingMap :: MonadUnique m => BindingMap > Name a > m (Name a)
 isUntranslatable :: Bool > Term > RewriteMonad extra Bool
 isUntranslatableType :: Bool > Type > RewriteMonad extra Bool
 normalizeTermTypes :: TyConMap > Term > Term
 normalizeId :: TyConMap > Id > Id
 whnfRW :: Bool > TransformContext > Term > Rewrite extra > RewriteMonad extra Term
 bindPureHeap :: TyConMap > PureHeap > Rewrite extra > Rewrite extra
 removeUnusedBinders :: Bind Term > Term > Maybe Term
 module Clash.Rewrite.WorkFree
Documentation
zoomExtra :: State extra a > RewriteMonad extra a Source #
Lift an action working in the _extra
state to the RewriteMonad
findAccidentialShadows :: Term > [[Id]] Source #
Some transformations might erroneously introduce shadowing. For example, a transformation might result in:
let a = ... b = ... a = ...
where the last a
, shadows the first, while Clash assumes that this can't
happen. This function finds those constructs and a list of found duplicates.
Record if a transformation is successfully applied
:: String  Name of the transformation 
> InScopeSet  
> 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 > IO 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
mkDerivedName :: TransformContext > OccName > TmName Source #
:: MonadUnique m  
=> InScopeSet  
> TyConMap  TyCon cache 
> Name a  Name of the new binder 
> Term  Term to bind 
> m Id 
Make a new binder and variable reference for a term
:: MonadUnique m  
=> InScopeSet  
> TyConMap  TyCon cache 
> Name a  Name of the new binder 
> Either Term Type  Type or Term to bind 
> m (Either Id TyVar) 
Make a new binder and variable reference for either a term or a type
:: (Term > LetBinding > RewriteMonad extra Bool)  Property test 
> Rewrite extra 
Inline the binders in a letbinding that have a certain property
Determine whether a binder is a joinpoint created for a complex case expression.
A joinpoint is when a local function only occurs in tailcall positions, and when it does, more than once.
Count the number of (only) tail calls of a function in an expression.
Nothing
indicates that the function was used in a nontail 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
:: InScopeSet  
> [LetBinding]  Letbinders to substitute 
> [LetBinding]  Letbinders where substitution takes place 
> Term  Body where substitution takes place 
> ([LetBinding], ([LetBinding], Term)) 

Inline the first set of binder into the second set of binders and into the body of the original let expression.
liftAndSubsituteBinders Source #
:: InScopeSet  
> [LetBinding]  Letbinders to lift, and substitute the lifted result 
> [LetBinding]  Lefbinders where substitution takes place 
> Term  Body where substitution takes place 
> RewriteMonad extra ([LetBinding], Term) 
Lift the first set of binders to the level of global bindings, and substitute these lifted bindings into the second set of binders and the body of the original let expression.
:: (LetBinding > RewriteMonad extra Bool)  Property test 
> (Term > LetBinding > Bool)  Test whether to lift or inline

> Rewrite extra 
liftBinding :: LetBinding > RewriteMonad extra LetBinding Source #
Create a global function for a Letbinding and return a Letbinding where the RHS is a reference to the new global function applied to the free variables of the original RHS
:: TmName  Name of the function 
> SrcSpan  
> InlineSpec  
> Term  Term bound to the function 
> RewriteMonad extra Id  Name with a proper unique and the type of the function 
Make a global function for a nameterm tuple
addGlobalBind :: TmName > Type > SrcSpan > InlineSpec > Term > RewriteMonad extra () Source #
Add a function to the set of global binders
cloneNameWithInScopeSet :: MonadUnique m => InScopeSet > Name a > m (Name a) Source #
Create a new name out of the given name, but with another unique. Resulting unique is guaranteed to not be in the given InScopeSet.
cloneNameWithBindingMap :: MonadUnique m => BindingMap > Name a > m (Name a) Source #
Create a new name out of the given name, but with another unique. Resulting unique is guaranteed to not be in the given BindingMap.
:: Bool  String representable 
> Term  
> RewriteMonad extra Bool 
Determine if a term cannot be represented in hardware
:: Bool  String representable 
> Type  
> RewriteMonad extra Bool 
Determine if a type cannot be represented in hardware
:: Bool  Whether the expression we're reducing to WHNF is the subject of a case expression. 
> TransformContext  
> Term  
> Rewrite extra  
> RewriteMonad extra Term 
Evaluate an expression to weakhead normal form (WHNF), and apply a transformation on the expression in WHNF.
bindPureHeap :: TyConMap > PureHeap > Rewrite extra > Rewrite extra Source #
Binds variables on the PureHeap over the result of the rewrite
To prevent unnecessary rewrites only do this when rewrite changed something.
removeUnusedBinders :: Bind Term > Term > Maybe Term Source #
Remove unused binders in given letbinding. Returns Nothing if no unused binders were found.
module Clash.Rewrite.WorkFree