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

Safe HaskellNone
LanguageHaskell2010

Futhark.Optimise.Simplify.Engine

Contents

Description

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

Monadic interface

data SimpleM lore a Source #

Instances
MonadWriter Certificates (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

writer :: (a, Certificates) -> SimpleM lore a #

tell :: Certificates -> SimpleM lore () #

listen :: SimpleM lore a -> SimpleM lore (a, Certificates) #

pass :: SimpleM lore (a, Certificates -> Certificates) -> SimpleM lore a #

Monad (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

(>>=) :: SimpleM lore a -> (a -> SimpleM lore b) -> SimpleM lore b #

(>>) :: SimpleM lore a -> SimpleM lore b -> SimpleM lore b #

return :: a -> SimpleM lore a #

fail :: String -> SimpleM lore a #

Functor (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

fmap :: (a -> b) -> SimpleM lore a -> SimpleM lore b #

(<$) :: a -> SimpleM lore b -> SimpleM lore a #

Applicative (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

pure :: a -> SimpleM lore a #

(<*>) :: SimpleM lore (a -> b) -> SimpleM lore a -> SimpleM lore b #

liftA2 :: (a -> b -> c) -> SimpleM lore a -> SimpleM lore b -> SimpleM lore c #

(*>) :: SimpleM lore a -> SimpleM lore b -> SimpleM lore b #

(<*) :: SimpleM lore a -> SimpleM lore b -> SimpleM lore a #

MonadFreshNames (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

SimplifiableLore lore => LocalScope (Wise lore) (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

localScope :: Scope (Wise lore) -> SimpleM lore a -> SimpleM lore a Source #

SimplifiableLore lore => HasScope (Wise lore) (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

lookupType :: VName -> SimpleM lore Type Source #

lookupInfo :: VName -> SimpleM lore (NameInfo (Wise lore)) Source #

askScope :: SimpleM lore (Scope (Wise lore)) Source #

asksScope :: (Scope (Wise lore) -> a) -> SimpleM lore a Source #

MonadState (VNameSource, Bool) (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

get :: SimpleM lore (VNameSource, Bool) #

put :: (VNameSource, Bool) -> SimpleM lore () #

state :: ((VNameSource, Bool) -> (a, (VNameSource, Bool))) -> SimpleM lore a #

MonadReader (SimpleOps lore, Env lore) (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

ask :: SimpleM lore (SimpleOps lore, Env lore) #

local :: ((SimpleOps lore, Env lore) -> (SimpleOps lore, Env lore)) -> SimpleM lore a -> SimpleM lore a #

reader :: ((SimpleOps lore, Env lore) -> a) -> SimpleM lore a #

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 #

data SimpleOps lore Source #

Constructors

SimpleOps 

Fields

Instances
MonadReader (SimpleOps lore, Env lore) (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

ask :: SimpleM lore (SimpleOps lore, Env lore) #

local :: ((SimpleOps lore, Env lore) -> (SimpleOps lore, Env lore)) -> SimpleM lore a -> SimpleM lore a #

reader :: ((SimpleOps lore, Env lore) -> a) -> SimpleM lore a #

type SimplifyOp lore = Op lore -> SimpleM lore (OpWithWisdom (Op lore), Stms (Wise lore)) Source #

data Env lore Source #

Instances
MonadReader (SimpleOps lore, Env lore) (SimpleM lore) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

ask :: SimpleM lore (SimpleOps lore, Env lore) #

local :: ((SimpleOps lore, Env lore) -> (SimpleOps lore, Env lore)) -> SimpleM lore a -> SimpleM lore a #

reader :: ((SimpleOps lore, Env lore) -> a) -> SimpleM lore a #

emptyEnv :: RuleBook (Wise lore) -> HoistBlockers lore -> Env lore Source #

data HoistBlockers lore Source #

Constructors

HoistBlockers 

Fields

type BlockPred lore = UsageTable -> Stm lore -> Bool Source #

orIf :: BlockPred lore -> BlockPred 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

class Simplifiable e where Source #

Methods

simplify :: SimplifiableLore lore => e -> SimpleM lore e Source #

Instances
Simplifiable Int Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => Int -> SimpleM lore Int Source #

Simplifiable VName Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => VName -> SimpleM lore VName Source #

Simplifiable SubExp Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable Certificates Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable ExtSize Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable CombineSpace Source # 
Instance details

Defined in Futhark.Representation.Kernels.Simplify

Simplifiable SplitOrdering Source # 
Instance details

Defined in Futhark.Representation.Kernels.Simplify

Simplifiable WhichThreads Source # 
Instance details

Defined in Futhark.Representation.Kernels.Simplify

Simplifiable KernelResult Source # 
Instance details

Defined in Futhark.Representation.Kernels.Simplify

Simplifiable SpaceStructure Source # 
Instance details

Defined in Futhark.Representation.Kernels.Simplify

Simplifiable KernelSpace Source # 
Instance details

Defined in Futhark.Representation.Kernels.Simplify

Simplifiable MemReturn Source # 
Instance details

Defined in Futhark.Representation.ExplicitMemory

Simplifiable MemBind Source # 
Instance details

Defined in Futhark.Representation.ExplicitMemory

Simplifiable a => Simplifiable [a] Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => [a] -> SimpleM lore [a] Source #

Simplifiable [FunReturns] Source # 
Instance details

Defined in Futhark.Representation.ExplicitMemory

Simplifiable a => Simplifiable (Maybe a) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => Maybe a -> SimpleM lore (Maybe a) Source #

Simplifiable d => Simplifiable (DimIndex d) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => DimIndex d -> SimpleM lore (DimIndex d) Source #

Simplifiable d => Simplifiable (ShapeBase d) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => ShapeBase d -> SimpleM lore (ShapeBase d) Source #

(Simplifiable a, Simplifiable b) => Simplifiable (a, b) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => (a, b) -> SimpleM lore (a, b) Source #

Simplifiable shape => Simplifiable (TypeBase shape u) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => TypeBase shape u -> SimpleM lore (TypeBase shape u) Source #

(Simplifiable a, Simplifiable b, Simplifiable c) => Simplifiable (a, b, c) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableLore lore => (a, b, c) -> SimpleM lore (a, b, c) Source #

(Simplifiable d, Simplifiable ret) => Simplifiable (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.Representation.ExplicitMemory

Methods

simplify :: SimplifiableLore lore => MemInfo d u ret -> SimpleM lore (MemInfo d u ret) Source #

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 #

simplifyParam :: (attr -> SimpleM lore attr) -> ParamT attr -> SimpleM lore (ParamT attr) 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 #

enterLoop :: 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 #

protectIf :: MonadBinder m => (Exp (Lore m) -> Bool) -> SubExp -> Stm (Lore m) -> m () Source #