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)
- subSimpleM :: (SameScope outerlore lore, ExpAttr outerlore ~ ExpAttr lore, BodyAttr outerlore ~ BodyAttr lore, RetType outerlore ~ RetType lore, BranchType outerlore ~ BranchType lore) => SimpleOps lore -> Env lore -> SymbolTable (Wise outerlore) -> SimpleM lore a -> SimpleM outerlore a
- data SimpleOps lore = SimpleOps {
- mkExpAttrS :: SymbolTable (Wise lore) -> Pattern (Wise lore) -> Exp (Wise lore) -> SimpleM lore (ExpAttr (Wise lore))
- mkBodyS :: SymbolTable (Wise lore) -> Stms (Wise lore) -> Result -> SimpleM lore (Body (Wise lore))
- mkLetNamesS :: SymbolTable (Wise lore) -> [VName] -> Exp (Wise lore) -> SimpleM lore (Stm (Wise lore), Stms (Wise lore))
- simplifyOpS :: SimplifyOp lore
- type SimplifyOp lore = Op lore -> SimpleM lore (OpWithWisdom (Op lore), Stms (Wise lore))
- bindableSimpleOps :: (SimplifiableLore lore, Bindable lore) => SimplifyOp 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)
- getArraySizes :: Stm (Wise lore) -> Names
- isAllocation :: Stm (Wise lore) -> Bool
- neverBlocks :: BlockPred lore
- noExtraHoistBlockers :: HoistBlockers lore
- type BlockPred lore = UsageTable -> Stm lore -> Bool
- orIf :: BlockPred lore -> BlockPred lore -> BlockPred lore
- hasFree :: Attributes lore => Names -> BlockPred lore
- isConsumed :: BlockPred lore
- isFalse :: Bool -> BlockPred lore
- isOp :: BlockPred lore
- isNotSafe :: Attributes 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 = (Attributes lore, Simplifiable (LetAttr lore), Simplifiable (FParamAttr lore), Simplifiable (LParamAttr 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 -> [Maybe VName] -> SimpleM lore (Lambda (Wise lore), Stms (Wise lore))
- simplifyLambdaSeq :: SimplifiableLore lore => Lambda lore -> [Maybe VName] -> SimpleM lore (Lambda (Wise lore), Stms (Wise lore))
- simplifyLambdaNoHoisting :: SimplifiableLore lore => Lambda lore -> [Maybe VName] -> SimpleM lore (Lambda (Wise lore))
- simplifyParam :: (attr -> SimpleM lore attr) -> ParamT attr -> SimpleM lore (ParamT attr)
- bindLParams :: SimplifiableLore lore => [LParam (Wise lore)] -> SimpleM lore a -> SimpleM lore a
- bindChunkLParams :: SimplifiableLore lore => VName -> [(LParam (Wise lore), VName)] -> SimpleM lore a -> SimpleM lore a
- bindLoopVar :: SimplifiableLore lore => VName -> IntType -> SubExp -> SimpleM lore a -> SimpleM lore a
- enterLoop :: 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))
- blockIf :: SimplifiableLore lore => BlockPred (Wise lore) -> SimpleM lore (SimplifiedBody lore a) -> SimpleM lore ((Stms (Wise lore), a), Stms (Wise lore))
- constructBody :: SimplifiableLore lore => Stms (Wise lore) -> Result -> SimpleM lore (Body (Wise lore))
- protectIf :: MonadBinder m => (Exp (Lore m) -> Bool) -> SubExp -> Stm (Lore m) -> m ()
- module Futhark.Optimise.Simplify.Lore
Monadic interface
Instances
runSimpleM :: SimpleM lore a -> SimpleOps lore -> Env lore -> VNameSource -> ((a, Bool), VNameSource) Source #
subSimpleM :: (SameScope outerlore lore, ExpAttr outerlore ~ ExpAttr lore, BodyAttr outerlore ~ BodyAttr lore, RetType outerlore ~ RetType lore, BranchType outerlore ~ BranchType lore) => SimpleOps lore -> Env lore -> SymbolTable (Wise outerlore) -> SimpleM lore a -> SimpleM outerlore a Source #
SimpleOps | |
|
type SimplifyOp lore = Op lore -> SimpleM lore (OpWithWisdom (Op lore), Stms (Wise lore)) Source #
bindableSimpleOps :: (SimplifiableLore lore, Bindable lore) => SimplifyOp lore -> SimpleOps lore Source #
data HoistBlockers lore Source #
HoistBlockers | |
|
neverBlocks :: BlockPred lore Source #
noExtraHoistBlockers :: HoistBlockers lore Source #
isConsumed :: BlockPred lore Source #
isNotSafe :: Attributes lore => 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 = (Attributes lore, Simplifiable (LetAttr lore), Simplifiable (FParamAttr lore), Simplifiable (LParamAttr 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 -> [Maybe VName] -> SimpleM lore (Lambda (Wise lore), Stms (Wise lore)) Source #
simplifyLambdaSeq :: SimplifiableLore lore => Lambda lore -> [Maybe VName] -> SimpleM lore (Lambda (Wise lore), Stms (Wise lore)) Source #
simplifyLambdaNoHoisting :: SimplifiableLore lore => Lambda lore -> [Maybe VName] -> SimpleM lore (Lambda (Wise lore)) Source #
bindLParams :: SimplifiableLore lore => [LParam (Wise lore)] -> SimpleM lore a -> SimpleM lore a Source #
bindChunkLParams :: SimplifiableLore lore => VName -> [(LParam (Wise lore), VName)] -> SimpleM lore a -> SimpleM lore a Source #
bindLoopVar :: SimplifiableLore lore => VName -> IntType -> SubExp -> SimpleM lore a -> SimpleM lore a Source #
simplifyBody :: SimplifiableLore lore => [Diet] -> Body lore -> SimpleM lore (SimplifiedBody lore Result) Source #
Simplify a single BodyT
. The [Diet]
only covers the value
elements, because the context cannot be consumed.
type SimplifiedBody lore a = ((a, UsageTable), 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 #
constructBody :: SimplifiableLore lore => Stms (Wise lore) -> Result -> SimpleM lore (Body (Wise lore)) Source #