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 rep a
- runSimpleM :: SimpleM rep a -> SimpleOps rep -> Env rep -> VNameSource -> ((a, Bool), VNameSource)
- data SimpleOps rep = SimpleOps {
- mkExpDecS :: SymbolTable (Wise rep) -> Pat (Wise rep) -> Exp (Wise rep) -> SimpleM rep (ExpDec (Wise rep))
- mkBodyS :: SymbolTable (Wise rep) -> Stms (Wise rep) -> Result -> SimpleM rep (Body (Wise rep))
- protectHoistedOpS :: Protect (Builder (Wise rep))
- opUsageS :: Op (Wise rep) -> UsageTable
- simplifyOpS :: SimplifyOp rep (Op rep)
- type SimplifyOp rep op = op -> SimpleM rep (OpWithWisdom op, Stms (Wise rep))
- bindableSimpleOps :: (SimplifiableRep rep, Buildable rep) => SimplifyOp rep (Op rep) -> SimpleOps rep
- data Env rep
- emptyEnv :: RuleBook (Wise rep) -> HoistBlockers rep -> Env rep
- data HoistBlockers rep = HoistBlockers {
- blockHoistPar :: BlockPred (Wise rep)
- blockHoistSeq :: BlockPred (Wise rep)
- blockHoistBranch :: BlockPred (Wise rep)
- isAllocation :: Stm (Wise rep) -> Bool
- neverBlocks :: BlockPred rep
- noExtraHoistBlockers :: HoistBlockers rep
- neverHoist :: HoistBlockers rep
- type BlockPred rep = SymbolTable rep -> UsageTable -> Stm rep -> Bool
- orIf :: BlockPred rep -> BlockPred rep -> BlockPred rep
- hasFree :: ASTRep rep => Names -> BlockPred rep
- isConsumed :: BlockPred rep
- isFalse :: Bool -> BlockPred rep
- isOp :: BlockPred rep
- isNotSafe :: ASTRep rep => BlockPred rep
- asksEngineEnv :: (Env rep -> a) -> SimpleM rep a
- askVtable :: SimpleM rep (SymbolTable (Wise rep))
- localVtable :: (SymbolTable (Wise rep) -> SymbolTable (Wise rep)) -> SimpleM rep a -> SimpleM rep a
- type SimplifiableRep rep = (ASTRep rep, Simplifiable (LetDec rep), Simplifiable (FParamInfo rep), Simplifiable (LParamInfo rep), Simplifiable (RetType rep), Simplifiable (BranchType rep), CanBeWise (Op rep), IndexOp (OpWithWisdom (Op rep)), BuilderOps (Wise rep), IsOp (Op rep))
- class Simplifiable e where
- simplify :: SimplifiableRep rep => e -> SimpleM rep e
- simplifyStms :: SimplifiableRep rep => Stms rep -> SimpleM rep (a, Stms (Wise rep)) -> SimpleM rep (a, Stms (Wise rep))
- simplifyFun :: SimplifiableRep rep => FunDef rep -> SimpleM rep (FunDef (Wise rep))
- simplifyLambda :: SimplifiableRep rep => Lambda rep -> SimpleM rep (Lambda (Wise rep), Stms (Wise rep))
- simplifyLambdaNoHoisting :: SimplifiableRep rep => Lambda rep -> SimpleM rep (Lambda (Wise rep))
- bindLParams :: SimplifiableRep rep => [LParam (Wise rep)] -> SimpleM rep a -> SimpleM rep a
- simplifyBody :: SimplifiableRep rep => [Diet] -> Body rep -> SimpleM rep (SimplifiedBody rep Result)
- type SimplifiedBody rep a = ((a, UsageTable), Stms (Wise rep))
- data SymbolTable rep
- hoistStms :: SimplifiableRep rep => RuleBook (Wise rep) -> BlockPred (Wise rep) -> SymbolTable (Wise rep) -> UsageTable -> Stms (Wise rep) -> SimpleM rep (Stms (Wise rep), Stms (Wise rep))
- blockIf :: SimplifiableRep rep => BlockPred (Wise rep) -> SimpleM rep (SimplifiedBody rep a) -> SimpleM rep ((Stms (Wise rep), a), Stms (Wise rep))
- enterLoop :: SimpleM rep a -> SimpleM rep a
- module Futhark.Optimise.Simplify.Rep
Monadic interface
Instances
Monad (SimpleM rep) Source # | |
Functor (SimpleM rep) Source # | |
Applicative (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine | |
MonadFreshNames (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine getNameSource :: SimpleM rep VNameSource Source # putNameSource :: VNameSource -> SimpleM rep () Source # | |
SimplifiableRep rep => LocalScope (Wise rep) (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine | |
SimplifiableRep rep => HasScope (Wise rep) (SimpleM rep) Source # | |
MonadReader (SimpleOps rep, Env rep) (SimpleM rep) Source # | |
MonadState (VNameSource, Bool, Certs) (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine |
runSimpleM :: SimpleM rep a -> SimpleOps rep -> Env rep -> VNameSource -> ((a, Bool), VNameSource) Source #
SimpleOps | |
|
type SimplifyOp rep op = op -> SimpleM rep (OpWithWisdom op, Stms (Wise rep)) Source #
bindableSimpleOps :: (SimplifiableRep rep, Buildable rep) => SimplifyOp rep (Op rep) -> SimpleOps rep Source #
data HoistBlockers rep Source #
HoistBlockers | |
|
neverBlocks :: BlockPred rep Source #
noExtraHoistBlockers :: HoistBlockers rep Source #
neverHoist :: HoistBlockers rep Source #
type BlockPred rep = SymbolTable rep -> UsageTable -> Stm rep -> Bool Source #
isConsumed :: BlockPred rep Source #
asksEngineEnv :: (Env rep -> a) -> SimpleM rep a Source #
localVtable :: (SymbolTable (Wise rep) -> SymbolTable (Wise rep)) -> SimpleM rep a -> SimpleM rep a Source #
Building blocks
type SimplifiableRep rep = (ASTRep rep, Simplifiable (LetDec rep), Simplifiable (FParamInfo rep), Simplifiable (LParamInfo rep), Simplifiable (RetType rep), Simplifiable (BranchType rep), CanBeWise (Op rep), IndexOp (OpWithWisdom (Op rep)), BuilderOps (Wise rep), IsOp (Op rep)) Source #
class Simplifiable e where Source #
simplify :: SimplifiableRep rep => e -> SimpleM rep e Source #
Instances
simplifyStms :: SimplifiableRep rep => Stms rep -> SimpleM rep (a, Stms (Wise rep)) -> SimpleM rep (a, Stms (Wise rep)) Source #
simplifyFun :: SimplifiableRep rep => FunDef rep -> SimpleM rep (FunDef (Wise rep)) Source #
simplifyLambda :: SimplifiableRep rep => Lambda rep -> SimpleM rep (Lambda (Wise rep), Stms (Wise rep)) Source #
simplifyLambdaNoHoisting :: SimplifiableRep rep => Lambda rep -> SimpleM rep (Lambda (Wise rep)) Source #
bindLParams :: SimplifiableRep rep => [LParam (Wise rep)] -> SimpleM rep a -> SimpleM rep a Source #
simplifyBody :: SimplifiableRep rep => [Diet] -> Body rep -> SimpleM rep (SimplifiedBody rep Result) Source #
Simplify a single body. The [Diet]
only covers the value
elements, because the context cannot be consumed.
type SimplifiedBody rep a = ((a, UsageTable), Stms (Wise rep)) Source #
data SymbolTable rep Source #
Instances
Semigroup (SymbolTable rep) Source # | |
Defined in Futhark.Analysis.SymbolTable (<>) :: SymbolTable rep -> SymbolTable rep -> SymbolTable rep # sconcat :: NonEmpty (SymbolTable rep) -> SymbolTable rep # stimes :: Integral b => b -> SymbolTable rep -> SymbolTable rep # | |
Monoid (SymbolTable rep) Source # | |
Defined in Futhark.Analysis.SymbolTable mempty :: SymbolTable rep # mappend :: SymbolTable rep -> SymbolTable rep -> SymbolTable rep # mconcat :: [SymbolTable rep] -> SymbolTable rep # |
hoistStms :: SimplifiableRep rep => RuleBook (Wise rep) -> BlockPred (Wise rep) -> SymbolTable (Wise rep) -> UsageTable -> Stms (Wise rep) -> SimpleM rep (Stms (Wise rep), Stms (Wise rep)) Source #
blockIf :: SimplifiableRep rep => BlockPred (Wise rep) -> SimpleM rep (SimplifiedBody rep a) -> SimpleM rep ((Stms (Wise rep), a), Stms (Wise rep)) Source #