Safe Haskell | None |
---|---|
Language | Haskell2010 |
Perform general rule-based simplification based on data dependency information. This module will:
- Perform common-subexpression elimination (CSE).
- Hoist expressions out of loops (including lambdas) and branches. This is done as aggressively as possible.
- Apply simplification rules (see Futhark.Optimise.Simplification.Rules).
If you just want to run the simplifier as simply as possible, you may prefer to use the Futhark.Optimise.Simplify module.
Synopsis
- data SimpleM lore a
- runSimpleM :: SimpleM lore a -> SimpleOps lore -> Env lore -> VNameSource -> ((a, Bool), VNameSource)
- data SimpleOps lore = SimpleOps {
- mkExpDecS :: SymbolTable (Wise lore) -> Pattern (Wise lore) -> Exp (Wise lore) -> SimpleM lore (ExpDec (Wise lore))
- mkBodyS :: SymbolTable (Wise lore) -> Stms (Wise lore) -> Result -> SimpleM lore (Body (Wise lore))
- protectHoistedOpS :: Protect (Binder (Wise lore))
- opUsageS :: Op (Wise lore) -> UsageTable
- simplifyOpS :: SimplifyOp lore (Op lore)
- type SimplifyOp lore op = op -> SimpleM lore (OpWithWisdom op, Stms (Wise lore))
- bindableSimpleOps :: (SimplifiableLore lore, Bindable lore) => SimplifyOp lore (Op lore) -> SimpleOps lore
- data Env lore
- emptyEnv :: RuleBook (Wise lore) -> HoistBlockers lore -> Env lore
- data HoistBlockers lore = HoistBlockers {
- blockHoistPar :: BlockPred (Wise lore)
- blockHoistSeq :: BlockPred (Wise lore)
- blockHoistBranch :: BlockPred (Wise lore)
- isAllocation :: Stm (Wise lore) -> Bool
- neverBlocks :: BlockPred lore
- noExtraHoistBlockers :: HoistBlockers lore
- neverHoist :: HoistBlockers lore
- type BlockPred lore = SymbolTable lore -> UsageTable -> Stm lore -> Bool
- orIf :: BlockPred lore -> BlockPred lore -> BlockPred lore
- hasFree :: ASTLore lore => Names -> BlockPred lore
- isConsumed :: BlockPred lore
- isFalse :: Bool -> BlockPred lore
- isOp :: BlockPred lore
- isNotSafe :: ASTLore lore => BlockPred lore
- asksEngineEnv :: (Env lore -> a) -> SimpleM lore a
- askVtable :: SimpleM lore (SymbolTable (Wise lore))
- localVtable :: (SymbolTable (Wise lore) -> SymbolTable (Wise lore)) -> SimpleM lore a -> SimpleM lore a
- type SimplifiableLore lore = (ASTLore lore, Simplifiable (LetDec lore), Simplifiable (FParamInfo lore), Simplifiable (LParamInfo lore), Simplifiable (RetType lore), Simplifiable (BranchType lore), CanBeWise (Op lore), IndexOp (OpWithWisdom (Op lore)), BinderOps (Wise lore), IsOp (Op lore))
- class Simplifiable e where
- simplify :: SimplifiableLore lore => e -> SimpleM lore e
- simplifyStms :: SimplifiableLore lore => Stms lore -> SimpleM lore (a, Stms (Wise lore)) -> SimpleM lore (a, Stms (Wise lore))
- simplifyFun :: SimplifiableLore lore => FunDef lore -> SimpleM lore (FunDef (Wise lore))
- simplifyLambda :: SimplifiableLore lore => Lambda lore -> SimpleM lore (Lambda (Wise lore), Stms (Wise lore))
- simplifyLambdaNoHoisting :: SimplifiableLore lore => Lambda lore -> SimpleM lore (Lambda (Wise lore))
- bindLParams :: SimplifiableLore lore => [LParam (Wise lore)] -> SimpleM lore a -> SimpleM lore a
- simplifyBody :: SimplifiableLore lore => [Diet] -> Body lore -> SimpleM lore (SimplifiedBody lore Result)
- type SimplifiedBody lore a = ((a, UsageTable), Stms (Wise lore))
- data SymbolTable lore
- hoistStms :: SimplifiableLore lore => RuleBook (Wise lore) -> BlockPred (Wise lore) -> SymbolTable (Wise lore) -> UsageTable -> Stms (Wise lore) -> SimpleM lore (Stms (Wise lore), Stms (Wise lore))
- blockIf :: SimplifiableLore lore => BlockPred (Wise lore) -> SimpleM lore (SimplifiedBody lore a) -> SimpleM lore ((Stms (Wise lore), a), Stms (Wise lore))
- enterLoop :: SimpleM lore a -> SimpleM lore a
- module Futhark.Optimise.Simplify.Lore
Monadic interface
Instances
Monad (SimpleM lore) Source # | |
Functor (SimpleM lore) Source # | |
Applicative (SimpleM lore) Source # | |
Defined in Futhark.Optimise.Simplify.Engine | |
MonadFreshNames (SimpleM lore) Source # | |
Defined in Futhark.Optimise.Simplify.Engine getNameSource :: SimpleM lore VNameSource Source # putNameSource :: VNameSource -> SimpleM lore () Source # | |
SimplifiableLore lore => LocalScope (Wise lore) (SimpleM lore) Source # | |
Defined in Futhark.Optimise.Simplify.Engine | |
SimplifiableLore lore => HasScope (Wise lore) (SimpleM lore) Source # | |
MonadReader (SimpleOps lore, Env lore) (SimpleM lore) Source # | |
MonadState (VNameSource, Bool, Certificates) (SimpleM lore) Source # | |
Defined in Futhark.Optimise.Simplify.Engine get :: SimpleM lore (VNameSource, Bool, Certificates) # put :: (VNameSource, Bool, Certificates) -> SimpleM lore () # state :: ((VNameSource, Bool, Certificates) -> (a, (VNameSource, Bool, Certificates))) -> SimpleM lore a # |
runSimpleM :: SimpleM lore a -> SimpleOps lore -> Env lore -> VNameSource -> ((a, Bool), VNameSource) Source #
SimpleOps | |
|
type SimplifyOp lore op = op -> SimpleM lore (OpWithWisdom op, Stms (Wise lore)) Source #
bindableSimpleOps :: (SimplifiableLore lore, Bindable lore) => SimplifyOp lore (Op lore) -> SimpleOps lore Source #
data HoistBlockers lore Source #
HoistBlockers | |
|
neverBlocks :: BlockPred lore Source #
noExtraHoistBlockers :: HoistBlockers lore Source #
neverHoist :: HoistBlockers lore Source #
type BlockPred lore = SymbolTable lore -> UsageTable -> Stm lore -> Bool Source #
isConsumed :: BlockPred lore Source #
asksEngineEnv :: (Env lore -> a) -> SimpleM lore a Source #
localVtable :: (SymbolTable (Wise lore) -> SymbolTable (Wise lore)) -> SimpleM lore a -> SimpleM lore a Source #
Building blocks
type SimplifiableLore lore = (ASTLore lore, Simplifiable (LetDec lore), Simplifiable (FParamInfo lore), Simplifiable (LParamInfo lore), Simplifiable (RetType lore), Simplifiable (BranchType lore), CanBeWise (Op lore), IndexOp (OpWithWisdom (Op lore)), BinderOps (Wise lore), IsOp (Op lore)) Source #
class Simplifiable e where Source #
simplify :: SimplifiableLore lore => e -> SimpleM lore e Source #
Instances
simplifyStms :: SimplifiableLore lore => Stms lore -> SimpleM lore (a, Stms (Wise lore)) -> SimpleM lore (a, Stms (Wise lore)) Source #
simplifyFun :: SimplifiableLore lore => FunDef lore -> SimpleM lore (FunDef (Wise lore)) Source #
simplifyLambda :: SimplifiableLore lore => Lambda lore -> SimpleM lore (Lambda (Wise lore), Stms (Wise lore)) Source #
simplifyLambdaNoHoisting :: SimplifiableLore lore => Lambda lore -> SimpleM lore (Lambda (Wise lore)) Source #
bindLParams :: SimplifiableLore lore => [LParam (Wise lore)] -> SimpleM lore a -> SimpleM lore a Source #
simplifyBody :: SimplifiableLore lore => [Diet] -> Body lore -> SimpleM lore (SimplifiedBody lore Result) Source #
Simplify a single body. The [Diet]
only covers the value
elements, because the context cannot be consumed.
type SimplifiedBody lore a = ((a, UsageTable), Stms (Wise lore)) Source #
data SymbolTable lore Source #
Instances
Semigroup (SymbolTable lore) Source # | |
Defined in Futhark.Analysis.SymbolTable (<>) :: SymbolTable lore -> SymbolTable lore -> SymbolTable lore # sconcat :: NonEmpty (SymbolTable lore) -> SymbolTable lore # stimes :: Integral b => b -> SymbolTable lore -> SymbolTable lore # | |
Monoid (SymbolTable lore) Source # | |
Defined in Futhark.Analysis.SymbolTable mempty :: SymbolTable lore # mappend :: SymbolTable lore -> SymbolTable lore -> SymbolTable lore # mconcat :: [SymbolTable lore] -> SymbolTable lore # |
hoistStms :: SimplifiableLore lore => RuleBook (Wise lore) -> BlockPred (Wise lore) -> SymbolTable (Wise lore) -> UsageTable -> Stms (Wise lore) -> SimpleM lore (Stms (Wise lore), Stms (Wise lore)) Source #
blockIf :: SimplifiableLore lore => BlockPred (Wise lore) -> SimpleM lore (SimplifiedBody lore a) -> SimpleM lore ((Stms (Wise lore), a), Stms (Wise lore)) Source #