futhark-0.20.2: An optimising compiler for a functional, array-oriented language.
Safe HaskellNone
LanguageHaskell2010

Futhark.Optimise.Simplify.Engine

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 rep a Source #

Instances

Instances details
Monad (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

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

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

return :: a -> SimpleM rep a #

Functor (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

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

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

Applicative (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

pure :: a -> SimpleM rep a #

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

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

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

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

MonadFreshNames (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

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 #

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 #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

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

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

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

MonadState (VNameSource, Bool, Certs) (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

get :: SimpleM rep (VNameSource, Bool, Certs) #

put :: (VNameSource, Bool, Certs) -> SimpleM rep () #

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

runSimpleM :: SimpleM rep a -> SimpleOps rep -> Env rep -> VNameSource -> ((a, Bool), VNameSource) Source #

data SimpleOps rep Source #

Constructors

SimpleOps 

Fields

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

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

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

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

data Env rep Source #

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

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

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

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

data HoistBlockers rep Source #

Constructors

HoistBlockers 

Fields

type BlockPred rep = SymbolTable rep -> UsageTable -> Stm rep -> Bool Source #

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

class Simplifiable e where Source #

Methods

simplify :: SimplifiableRep rep => e -> SimpleM rep e Source #

Instances

Instances details
Simplifiable Int Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => Int -> SimpleM rep Int Source #

Simplifiable () Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => () -> SimpleM rep () Source #

Simplifiable PrimType Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable VName Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable SubExp Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable Certs Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable Space Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable ExtSize Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable SubExpRes Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable SegSpace Source # 
Instance details

Defined in Futhark.IR.SegOp

Simplifiable KernelResult Source # 
Instance details

Defined in Futhark.IR.SegOp

Simplifiable SplitOrdering Source # 
Instance details

Defined in Futhark.IR.SegOp

Simplifiable SegLevel Source # 
Instance details

Defined in Futhark.IR.GPU.Op

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => [a] -> SimpleM rep [a] Source #

Simplifiable [FunReturns] Source # 
Instance details

Defined in Futhark.IR.Mem

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => Maybe a -> SimpleM rep (Maybe a) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => Slice d -> SimpleM rep (Slice d) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => DimIndex d -> SimpleM rep (DimIndex d) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => (a, b) -> SimpleM rep (a, b) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => TypeBase shape u -> SimpleM rep (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 :: SimplifiableRep rep => (a, b, c) -> SimpleM rep (a, b, c) Source #

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

Defined in Futhark.IR.Mem

Methods

simplify :: SimplifiableRep rep => MemInfo d u ret -> SimpleM rep (MemInfo d u ret) Source #

simplifyStms :: SimplifiableRep rep => Stms rep -> SimpleM rep (a, Stms (Wise rep)) -> SimpleM rep (a, Stms (Wise rep)) Source #

simplifyLambda :: SimplifiableRep rep => Lambda rep -> SimpleM rep (Lambda (Wise rep), Stms (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

Instances details
Semigroup (SymbolTable rep) Source # 
Instance details

Defined in Futhark.Analysis.SymbolTable

Methods

(<>) :: SymbolTable rep -> SymbolTable rep -> SymbolTable rep #

sconcat :: NonEmpty (SymbolTable rep) -> SymbolTable rep #

stimes :: Integral b => b -> SymbolTable rep -> SymbolTable rep #

Monoid (SymbolTable rep) Source # 
Instance details

Defined in Futhark.Analysis.SymbolTable

Methods

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 #

enterLoop :: SimpleM rep a -> SimpleM rep a Source #

Indicate in the symbol table that we have descended into a loop.