clash-lib-1.9.0: Clash: a functional hardware description language - As a library
Copyright(C) 2020-2021 QBayLogic B.V.
LicenseBSD2 (see the file LICENSE)
MaintainerQBayLogic B.V. <devops@qaylogic.com>
Safe HaskellNone
LanguageHaskell2010

Clash.Rewrite.WorkFree

Description

Check whether a term is work free or not. This is used by transformations / evaluation to check whether it is possible to perform changes without duplicating work in the result, e.g. inlining.

Synopsis

Documentation

isWorkFree :: forall s m. (HasCallStack, MonadState s m) => Lens' s (VarEnv Bool) -> BindingMap -> Term -> m Bool Source #

Determine whether a term does any work, i.e. adds to the size of the circuit. This function requires a cache (specified as a lens) to store the result for querying work info of global binders.

isWorkFreeIsh :: TyConMap -> Term -> Bool Source #

A conservative version of isWorkFree. Is used to determine in bindConstantVar to determine whether an expression can be "bound" (locally inlined). While binding workfree expressions won't result in extra work for the circuit, it might very well cause extra work for Clash. In fact, using isWorkFree in bindConstantVar makes Clash two orders of magnitude slower for some of our test cases.

In effect, this function is a version of isConstant that also considers references to clocks and resets constant. This allows us to bind HiddenClock(ResetEnable) constructs, allowing Clash to constant spec subconstants - most notably KnownDomain. Doing that enables Clash to eliminate any case-constructs on it.

isConstant :: Term -> Bool Source #

Determine if a term represents a constant