macaw-base
Safe HaskellNone
LanguageHaskell2010

Data.Macaw.CFG.DemandSet

Description

Provides a monad that allows one to record a list of values and statements, and then resolve all their dependencies to see what additional computations must be run to provide inputs to the statements and compute the final value.

Synopsis

Documentation

data DemandComp arch ids a Source #

This is a monad that one can use for recording which values and statements we need to compute.

Use runDemandComp to get the assignments that need to be computed.

Instances

Instances details
Applicative (DemandComp arch ids) Source # 
Instance details

Defined in Data.Macaw.CFG.DemandSet

Methods

pure :: a -> DemandComp arch ids a #

(<*>) :: DemandComp arch ids (a -> b) -> DemandComp arch ids a -> DemandComp arch ids b #

liftA2 :: (a -> b -> c) -> DemandComp arch ids a -> DemandComp arch ids b -> DemandComp arch ids c #

(*>) :: DemandComp arch ids a -> DemandComp arch ids b -> DemandComp arch ids b #

(<*) :: DemandComp arch ids a -> DemandComp arch ids b -> DemandComp arch ids a #

Functor (DemandComp arch ids) Source # 
Instance details

Defined in Data.Macaw.CFG.DemandSet

Methods

fmap :: (a -> b) -> DemandComp arch ids a -> DemandComp arch ids b #

(<$) :: a -> DemandComp arch ids b -> DemandComp arch ids a #

Monad (DemandComp arch ids) Source # 
Instance details

Defined in Data.Macaw.CFG.DemandSet

Methods

(>>=) :: DemandComp arch ids a -> (a -> DemandComp arch ids b) -> DemandComp arch ids b #

(>>) :: DemandComp arch ids a -> DemandComp arch ids b -> DemandComp arch ids b #

return :: a -> DemandComp arch ids a #

type AssignIdSet ids = Set (Some (AssignId ids)) Source #

A set of assignments

runDemandComp :: DemandContext arch -> DemandComp arch ids () -> AssignIdSet ids Source #

Run demand computation and return the set of assignments that are needed to compute all the values we needed.

addValueDemands :: forall arch ids (tp :: Type). Value arch ids tp -> DemandComp arch ids () Source #

Add any subassignments needed to compute values to demand set.

addStmtDemands :: Stmt arch ids -> DemandComp arch ids () Source #

Parse statement, and if it has side effects, add assignments needed to compute statement to demand set.

DemandContext

data DemandContext arch Source #

This provides the architecture specific functions needed to resolve demand sets.

Constructors

DemandContext 

Fields

  • archFnHasSideEffects :: !(forall (v :: Type -> Type) (tp :: Type). ArchFn arch v tp -> Bool)

    This returns true if the architecture function has implicit side effects (and thus can not be removed even its its result is not needed).

  • demandConstraints :: !(forall a. ((FoldableFC (ArchFn arch), FoldableF (ArchStmt arch)) => a) -> a)

    Typeclass constraints that are captured so we do not need to explicitly pass them around to functions also taking a DemandContext.

hasSideEffects :: forall arch (f :: Type -> Type) (tp :: Type). DemandContext arch -> AssignRhs arch f tp -> Bool Source #

Return true if assign rhs has side effects (and thus should always be demanded)

Filtering after demand set is computed.

stmtNeeded :: AssignIdSet ids -> Stmt arch ids -> Bool Source #

This returns true if the statement should be kept given the demand set.