clash-lib-1.0.1: CAES Language for Synchronous Hardware - As a Library
Copyright(C) 2012-2016 University of Twente
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Clash.Normalize.Util

Description

Utility functions used by the normalisation transformations

Synopsis

Documentation

data ConstantSpecInfo Source #

Constructors

ConstantSpecInfo 

Fields

  • csrNewBindings :: [(Id, Term)]

    New let-bindings to be created for all the non-constants found

  • csrNewTerm :: !Term

    A term where all the non-constant constructs are replaced by variable references (found in csrNewBindings)

  • csrFoundConstant :: !Bool

    Whether the algorithm found a constant at all. (If it didn't, it's no use creating any new let-bindings!)

Instances

Instances details
Show ConstantSpecInfo Source # 
Instance details

Defined in Clash.Normalize.Util

isConstantArg Source #

Arguments

:: Text

Primitive name

-> Int

Argument number

-> RewriteMonad NormalizeState Bool

Yields DontCare for if given primitive name is not found, if the argument does not exist, or if the argument was not mentioned by the blackbox.

Determine if argument should reduce to a constant given a primitive and an argument number. Caches results.

shouldReduce Source #

Arguments

:: Context

..in the current transformcontext

-> RewriteMonad NormalizeState Bool 

Given a list of transformation contexts, determine if any of the contexts indicates that the current arg is to be reduced to a constant / literal.

alreadyInlined Source #

Arguments

:: Id

Function we want to inline

-> Id

Function in which we want to perform the inlining

-> NormalizeMonad (Maybe Int) 

Determine if a function is already inlined in the context of the NetlistMonad

addNewInline Source #

Arguments

:: Id

Function we want to inline

-> Id

Function in which we want to perform the inlining

-> NormalizeMonad () 

specializeNorm :: NormRewrite Source #

Specialize under the Normalization Monad

isRecursiveBndr :: Id -> NormalizeSession Bool Source #

Assert whether a name is a reference to a recursive binder.

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

Determine if a term is closed

callGraph :: BindingMap -> Id -> CallGraph Source #

Create a call graph for a set of global binders, given a root

classifyFunction :: Term -> TermClassification Source #

Give a "performance/size" classification of a function in normal form.

isCheapFunction :: Term -> Bool Source #

Determine whether a function adds a lot of hardware or not.

It is considered expensive when it has 2 or more of the following components:

  • functions
  • primitives
  • selections (multiplexers)

isNonRecursiveGlobalVar :: Term -> NormalizeSession Bool Source #

Test whether a given term represents a non-recursive global variable

constantSpecInfo :: TransformContext -> Term -> RewriteMonad NormalizeState ConstantSpecInfo Source #

Calculate constant spec info. The goal of this function is to analyze a given term and yield a new term that:

  • Leaves all the constant parts as they were.
  • Has all _variable_ parts replaced by a newly generated identifier.

The result structure will additionally contain:

  • Whether the function found any constant parts at all
  • A list of let-bindings binding the aforementioned identifiers with the term they replaced.

This can be used in functions wanting to constant specialize over partially constant data structures.

rewriteExpr Source #

Arguments

:: (String, NormRewrite)

Transformation to apply

-> (String, Term)

Term to transform

-> (Id, SrcSpan)

Renew current function being rewritten

-> NormalizeSession Term 

Rewrite a term according to the provided transformation