Copyright | (C) 2020 QBayLogic B.V. |
---|---|

License | BSD2 (see the file LICENSE) |

Maintainer | QBayLogic B.V. <devops@qaylogic.com> |

Safe Haskell | None |

Language | Haskell2010 |

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

- isWorkFree :: forall s m. (HasCallStack, MonadState s m) => Lens' s (VarEnv Bool) -> BindingMap -> Term -> m Bool
- isWorkFreeClockOrResetOrEnable :: TyConMap -> Term -> Maybe Bool
- isWorkFreeIsh :: TyConMap -> Term -> Bool
- isConstant :: Term -> Bool
- isConstantNotClockReset :: TyConMap -> Term -> Bool

# 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