futhark-0.25.32: An optimising compiler for a functional, array-oriented language.

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.Optimise.Simplify

Synopsis

- simplifyProg :: SimplifiableRep rep => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> Prog rep -> PassM (Prog rep)
- simplifySomething :: (MonadFreshNames m, SimplifiableRep rep) => (a -> SimpleM rep b) -> (b -> a) -> SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> SymbolTable (Wise rep) -> a -> m a
- simplifyFun :: (MonadFreshNames m, SimplifiableRep rep) => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> SymbolTable (Wise rep) -> FunDef rep -> m (FunDef rep)
- simplifyLambda :: (MonadFreshNames m, HasScope rep m, SimplifiableRep rep) => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> Lambda rep -> m (Lambda rep)
- simplifyStms :: (MonadFreshNames m, SimplifiableRep rep) => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> Scope rep -> Stms rep -> m (Stms rep)
- 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))
  }
- data SimpleM rep a
- type SimplifyOp rep op = op -> SimpleM rep (op, Stms (Wise rep))
- bindableSimpleOps :: (SimplifiableRep rep, Buildable rep) => SimplifyOp rep (Op (Wise rep)) -> SimpleOps rep
- noExtraHoistBlockers :: HoistBlockers rep
- neverHoist :: HoistBlockers rep
- 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)), IsOp (OpC rep), ASTConstraints (OpC rep (Wise rep)), AliasedOp (OpC (Wise rep)), RephraseOp (OpC rep), BuilderOps (Wise rep), IsOp (OpC rep))
- data HoistBlockers rep
- data RuleBook rep

# Documentation

simplifyProg :: SimplifiableRep rep => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> Prog rep -> PassM (Prog rep) Source #

Simplify the given program. Even if the output differs from the output, meaningful simplification may not have taken place - the order of bindings may simply have been rearranged.

simplifySomething :: (MonadFreshNames m, SimplifiableRep rep) => (a -> SimpleM rep b) -> (b -> a) -> SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> SymbolTable (Wise rep) -> a -> m a Source #

Run a simplification operation to convergence.

simplifyFun :: (MonadFreshNames m, SimplifiableRep rep) => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> SymbolTable (Wise rep) -> FunDef rep -> m (FunDef rep) Source #

Simplify the given function. Even if the output differs from the output, meaningful simplification may not have taken place - the order of bindings may simply have been rearranged. Runs in a loop until convergence.

simplifyLambda :: (MonadFreshNames m, HasScope rep m, SimplifiableRep rep) => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> Lambda rep -> m (Lambda rep) Source #

Simplify just a single `Lambda`.

simplifyStms :: (MonadFreshNames m, SimplifiableRep rep) => SimpleOps rep -> RuleBook (Wise rep) -> HoistBlockers rep -> Scope rep -> Stms rep -> m (Stms rep) Source #

Simplify a sequence of `Stm`s.

data SimpleOps rep Source #

Constructors

SimpleOps |

Fields

- 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))

  Make a hoisted Op safe. The SubExp is a boolean that is true when the value of the statement will actually be used.

- opUsageS :: Op (Wise rep) -> UsageTable
- simplifyOpS :: SimplifyOp rep (Op (Wise rep))

#### Instances

Instances details

MonadReader (SimpleOps rep, Env rep) (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods ask :: SimpleM rep (SimpleOps rep, Env rep) Source # local :: ((SimpleOps rep, Env rep) -> (SimpleOps rep, Env rep)) -> SimpleM rep a -> SimpleM rep a Source # reader :: ((SimpleOps rep, Env rep) -> a) -> SimpleM rep a Source #

data SimpleM rep a Source #

#### Instances

Instances details

Applicative (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods pure :: a -> SimpleM rep a Source # (<*>) :: SimpleM rep (a -> b) -> SimpleM rep a -> SimpleM rep b Source # liftA2 :: (a -> b -> c) -> SimpleM rep a -> SimpleM rep b -> SimpleM rep c Source # (*>) :: SimpleM rep a -> SimpleM rep b -> SimpleM rep b Source # (<*) :: SimpleM rep a -> SimpleM rep b -> SimpleM rep a Source #
Functor (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods fmap :: (a -> b) -> SimpleM rep a -> SimpleM rep b Source # (<$) :: a -> SimpleM rep b -> SimpleM rep a Source #
Monad (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods (>>=) :: SimpleM rep a -> (a -> SimpleM rep b) -> SimpleM rep b Source # (>>) :: SimpleM rep a -> SimpleM rep b -> SimpleM rep b Source # return :: a -> SimpleM rep a Source #
MonadFreshNames (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods getNameSource :: SimpleM rep VNameSource Source # putNameSource :: VNameSource -> SimpleM rep () Source #
SimplifiableRep rep => HasScope (Wise rep) (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods lookupType :: VName -> SimpleM rep Type Source # lookupInfo :: VName -> SimpleM rep (NameInfo (Wise rep)) Source # askScope :: SimpleM rep (Scope (Wise rep)) Source # asksScope :: (Scope (Wise rep) -> a) -> SimpleM rep a Source #
SimplifiableRep rep => LocalScope (Wise rep) (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods localScope :: Scope (Wise rep) -> SimpleM rep a -> SimpleM rep a Source #
MonadReader (SimpleOps rep, Env rep) (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods ask :: SimpleM rep (SimpleOps rep, Env rep) Source # local :: ((SimpleOps rep, Env rep) -> (SimpleOps rep, Env rep)) -> SimpleM rep a -> SimpleM rep a Source # reader :: ((SimpleOps rep, Env rep) -> a) -> SimpleM rep a Source #
MonadState (VNameSource, Bool, Certs) (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods get :: SimpleM rep (VNameSource, Bool, Certs) Source # put :: (VNameSource, Bool, Certs) -> SimpleM rep () Source # state :: ((VNameSource, Bool, Certs) -> (a, (VNameSource, Bool, Certs))) -> SimpleM rep a Source #

type SimplifyOp rep op = op -> SimpleM rep (op, Stms (Wise rep)) Source #

bindableSimpleOps :: (SimplifiableRep rep, Buildable rep) => SimplifyOp rep (Op (Wise rep)) -> SimpleOps rep Source #

noExtraHoistBlockers :: HoistBlockers rep Source #

neverHoist :: HoistBlockers rep Source #

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)), IsOp (OpC rep), ASTConstraints (OpC rep (Wise rep)), AliasedOp (OpC (Wise rep)), RephraseOp (OpC rep), BuilderOps (Wise rep), IsOp (OpC rep)) Source #

data HoistBlockers rep Source #

data RuleBook rep Source #

A collection of both top-down and bottom-up rules.

#### Instances

Instances details

Monoid (RuleBook rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Rule Methods mempty :: RuleBook rep Source # mappend :: RuleBook rep -> RuleBook rep -> RuleBook rep Source # mconcat :: [RuleBook rep] -> RuleBook rep Source #
Semigroup (RuleBook rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Rule Methods (<>) :: RuleBook rep -> RuleBook rep -> RuleBook rep Source # sconcat :: NonEmpty (RuleBook rep) -> RuleBook rep Source # stimes :: Integral b => b -> RuleBook rep -> RuleBook rep Source #