futhark-0.22.2: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
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
SimplifiableRep rep => HasScope (Wise rep :: Type) (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

lookupType :: VName -> SimpleM rep Type0 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 :: Type) (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

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

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 #

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 #

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 #

MonadFreshNames (SimpleM rep) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

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

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

class Simplifiable e where Source #

Methods

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

Instances

Instances details
Simplifiable SegLevel Source # 
Instance details

Defined in Futhark.IR.GPU.Op

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => SegLevel -> SimpleM rep SegLevel Source #

Simplifiable MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => MemBind -> SimpleM rep MemBind Source #

Simplifiable MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => MemReturn -> SimpleM rep MemReturn Source #

Simplifiable KernelResult Source # 
Instance details

Defined in Futhark.IR.SegOp

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => KernelResult -> SimpleM rep KernelResult Source #

Simplifiable SegSpace Source # 
Instance details

Defined in Futhark.IR.SegOp

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => SegSpace -> SimpleM rep SegSpace Source #

Simplifiable SubExpRes Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => SubExpRes -> SimpleM rep SubExpRes Source #

Simplifiable Certs Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => Certs -> SimpleM rep Certs Source #

Simplifiable ExtSize Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => ExtSize -> SimpleM rep ExtSize Source #

Simplifiable Space Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => Space -> SimpleM rep Space Source #

Simplifiable SubExp Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => SubExp -> SimpleM rep SubExp Source #

Simplifiable VName Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => VName -> SimpleM rep VName Source #

Simplifiable PrimType Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => PrimType -> SimpleM rep PrimType Source #

Simplifiable () Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => () -> SimpleM rep () Source #

Simplifiable Int Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => Int -> SimpleM rep Int Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => DimIndex d -> SimpleM rep (DimIndex d) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => ShapeBase d -> SimpleM rep (ShapeBase d) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => Slice d -> SimpleM rep (Slice d) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => Maybe a -> SimpleM rep (Maybe a) Source #

Simplifiable [FunReturns] Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => [FunReturns] -> SimpleM rep [FunReturns] Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => [a] -> SimpleM rep [a] Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => TypeBase shape u -> SimpleM rep (TypeBase shape u) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => (a, b) -> SimpleM rep (a, b) Source #

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

Defined in Futhark.IR.Mem

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => MemInfo d u ret -> SimpleM rep (MemInfo d u ret) Source #

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: forall {k} (rep :: k). SimplifiableRep rep => (a, b, c) -> SimpleM rep (a, b, c) Source #

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

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

Instances details
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 #

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 #

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 #