Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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 (LetDec (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 (Wise rep))
- type SimplifyOp rep op = op -> SimpleM rep (op, Stms (Wise rep))
- bindableSimpleOps :: (SimplifiableRep rep, Buildable rep) => SimplifyOp rep (Op (Wise 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
- isConsuming :: Aliased rep => BlockPred rep
- isFalse :: Bool -> BlockPred rep
- isOp :: BlockPred rep
- isNotSafe :: ASTRep rep => BlockPred rep
- isDeviceMigrated :: SimplifiableRep rep => BlockPred (Wise 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), TraverseOpStms (Wise rep), CanBeWise (OpC rep), IndexOp (Op (Wise rep)), AliasedOp (Op (Wise rep)), RephraseOp (OpC rep), BuilderOps (Wise rep), IsOp (Op rep))
- class Simplifiable e where
- simplify :: SimplifiableRep rep => e -> SimpleM rep e
- simplifyFun :: SimplifiableRep rep => FunDef (Wise rep) -> SimpleM rep (FunDef (Wise rep))
- simplifyStms :: SimplifiableRep rep => Stms (Wise rep) -> SimpleM rep (Stms (Wise rep))
- simplifyStmsWithUsage :: SimplifiableRep rep => UsageTable -> Stms (Wise rep) -> SimpleM rep (Stms (Wise rep))
- simplifyLambda :: SimplifiableRep rep => Names -> Lambda (Wise rep) -> SimpleM rep (Lambda (Wise rep), Stms (Wise rep))
- simplifyLambdaNoHoisting :: SimplifiableRep rep => Lambda (Wise rep) -> SimpleM rep (Lambda (Wise rep))
- bindLParams :: SimplifiableRep rep => [LParam (Wise rep)] -> SimpleM rep a -> SimpleM rep a
- simplifyBody :: SimplifiableRep rep => BlockPred (Wise rep) -> UsageTable -> [Usages] -> Body (Wise rep) -> SimpleM rep (Stms (Wise rep), Body (Wise rep))
- data SymbolTable rep
- hoistStms :: SimplifiableRep rep => RuleBook (Wise rep) -> BlockPred (Wise rep) -> Stms (Wise rep) -> SimpleM rep (a, UsageTable) -> SimpleM rep (a, Stms (Wise rep), Stms (Wise rep))
- blockIf :: SimplifiableRep rep => BlockPred (Wise rep) -> Stms (Wise rep) -> SimpleM rep (a, UsageTable) -> SimpleM rep (a, Stms (Wise rep), Stms (Wise rep))
- blockMigrated :: SimplifiableRep rep => SimpleM rep (Lambda (Wise rep), Stms (Wise rep)) -> SimpleM rep (Lambda (Wise rep), Stms (Wise rep))
- enterLoop :: SimpleM rep a -> SimpleM rep a
- constructBody :: SimplifiableRep rep => Stms (Wise rep) -> Result -> SimpleM rep (Body (Wise rep))
- module Futhark.Optimise.Simplify.Rep
Monadic interface
Instances
Applicative (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine | |
Functor (SimpleM rep) Source # | |
Monad (SimpleM rep) Source # | |
MonadFreshNames (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine getNameSource :: SimpleM rep VNameSource Source # putNameSource :: VNameSource -> SimpleM rep () Source # | |
SimplifiableRep rep => HasScope (Wise rep) (SimpleM rep) Source # | |
SimplifiableRep rep => LocalScope (Wise rep) (SimpleM rep) Source # | |
Defined in Futhark.Optimise.Simplify.Engine | |
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 | |
|
bindableSimpleOps :: (SimplifiableRep rep, Buildable rep) => SimplifyOp rep (Op (Wise 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 #
isConsuming :: Aliased rep => BlockPred rep Source #
isDeviceMigrated :: SimplifiableRep rep => BlockPred (Wise rep) Source #
Statement is a scalar read from a single element array of rank one.
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), TraverseOpStms (Wise rep), CanBeWise (OpC rep), IndexOp (Op (Wise rep)), AliasedOp (Op (Wise rep)), RephraseOp (OpC rep), BuilderOps (Wise rep), IsOp (Op rep)) Source #
class Simplifiable e where Source #
simplify :: SimplifiableRep rep => e -> SimpleM rep e Source #
Instances
simplifyFun :: SimplifiableRep rep => FunDef (Wise rep) -> SimpleM rep (FunDef (Wise rep)) Source #
simplifyStms :: SimplifiableRep rep => Stms (Wise rep) -> SimpleM rep (Stms (Wise rep)) Source #
simplifyStmsWithUsage :: SimplifiableRep rep => UsageTable -> Stms (Wise rep) -> SimpleM rep (Stms (Wise rep)) Source #
simplifyLambda :: SimplifiableRep rep => Names -> Lambda (Wise rep) -> SimpleM rep (Lambda (Wise rep), Stms (Wise rep)) Source #
simplifyLambdaNoHoisting :: SimplifiableRep rep => Lambda (Wise rep) -> SimpleM rep (Lambda (Wise rep)) Source #
bindLParams :: SimplifiableRep rep => [LParam (Wise rep)] -> SimpleM rep a -> SimpleM rep a Source #
simplifyBody :: SimplifiableRep rep => BlockPred (Wise rep) -> UsageTable -> [Usages] -> Body (Wise rep) -> SimpleM rep (Stms (Wise rep), Body (Wise rep)) Source #
Simplify a single body.
data SymbolTable rep Source #
Instances
Monoid (SymbolTable rep) Source # | |
Defined in Futhark.Analysis.SymbolTable mempty :: SymbolTable rep # mappend :: SymbolTable rep -> SymbolTable rep -> SymbolTable rep # mconcat :: [SymbolTable rep] -> SymbolTable rep # | |
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 # |
hoistStms :: SimplifiableRep rep => RuleBook (Wise rep) -> BlockPred (Wise rep) -> Stms (Wise rep) -> SimpleM rep (a, UsageTable) -> SimpleM rep (a, Stms (Wise rep), Stms (Wise rep)) Source #
blockIf :: SimplifiableRep rep => BlockPred (Wise rep) -> Stms (Wise rep) -> SimpleM rep (a, UsageTable) -> SimpleM rep (a, Stms (Wise rep), Stms (Wise rep)) Source #
blockMigrated :: SimplifiableRep rep => SimpleM rep (Lambda (Wise rep), Stms (Wise rep)) -> SimpleM rep (Lambda (Wise rep), Stms (Wise rep)) Source #
Block hoisting of Index
statements introduced by migration.
enterLoop :: SimpleM rep a -> SimpleM rep a Source #
Indicate in the symbol table that we have descended into a loop.
constructBody :: SimplifiableRep rep => Stms (Wise rep) -> Result -> SimpleM rep (Body (Wise rep)) Source #