clash-lib
Copyright(C) 2012-2016 University of Twente
2016 Myrtle Software Ltd
2017 Google Inc.
2021-2026 QBayLogic B.V.
LicenseBSD2 (see the file LICENSE)
MaintainerQBayLogic B.V. <devops@qbaylogic.com>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Clash.Normalize

Description

Turn CoreHW terms into normalized CoreHW Terms

Synopsis

Documentation

runNormalization Source #

Arguments

:: ClashEnv 
-> Supply

UniqueSupply

-> BindingMap

Global Binders

-> (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType)))

Hardcoded Type -> HWType translator

-> Evaluator

Hardcoded evaluator for partial evaluation

-> Evaluator

Hardcoded evaluator for WHNF (old evaluator)

-> VarEnv Bool

Map telling whether a components is part of a recursive group

-> [Id]

topEntities

-> NormalizeSession a

NormalizeSession to run

-> IO a 

Run a NormalizeSession in a given environment

checkNonRecursive Source #

Arguments

:: BindingMap

List of normalized binders

-> BindingMap 

Check whether the normalized bindings are non-recursive. Errors when one of the components is recursive.

cleanupGraph :: Id -> BindingMap -> NormalizeSession BindingMap Source #

Perform general "clean up" of the normalized (non-recursive) function hierarchy. This includes:

  • Inlining functions that simply "wrap" another function

nameArgsAfterParams Source #

Arguments

:: BindingMap

All bindings, used to find out which functions are defined by the user

-> [(Id, Term)]

Functions that are about to be inlined, and their definitions

-> Term

Term the functions are inlined in

-> Term 

Before inlining functions defined by the user, name variables made up by GHC after the parameter of the function they are passed to. For example, given:

topEntity = \eta -> ... txStep s eta ...
txStep = \s input -> ...

where GHC made up eta when it eta-expanded topEntity, we rename eta to input. Once txStep is inlined, input would otherwise be gone from the HDL. For top entities without a Synthesize annotation this also names the ports.

Functions count as defined by the user when their binding has a source location, i.e., when they were defined in a module compiled from source. We don't take names from library functions: their parameters are often named x or f, which isn't an improvement over a name made up by GHC.

If a variable is passed to multiple user-defined functions, the first application found determines its name.

data CallTree Source #

A tree of identifiers and their bindings, with branches containing additional bindings which are used. See Clash.Driver.Types.Binding.

Constructors

CLeaf (Id, Binding Term) 
CBranch (Id, Binding Term) [CallTree] 

mkCallTree Source #

Arguments

:: [Id]

Visited

-> BindingMap

Global binders

-> Id

Root of the call graph

-> Maybe CallTree 

flattenCallTree Source #

Arguments

:: IORef (UniqMap CallTree)

Memo cache, keyed by binder Id. Local to one cleanupGraph call.

-> CallTree 
-> NormalizeSession CallTree 

Flatten a CallTree, memoizing results by binder Id within one cleanup pass. Without the cache, every binder reachable from the root is flattened as many times as it appears in the (un-deduplicated) call tree.