futhark-0.25.12: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
LanguageGHC2021

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

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

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 KernelGrid Source # 
Instance details

Defined in Futhark.IR.GPU.Op

Simplifiable SegLevel Source # 
Instance details

Defined in Futhark.IR.GPU.Op

Simplifiable MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable KernelResult Source # 
Instance details

Defined in Futhark.IR.SegOp

Simplifiable SegSpace Source # 
Instance details

Defined in Futhark.IR.SegOp

Simplifiable SubExpRes Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable Certs Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable ExtSize Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable Space Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable SubExp Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable VName Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable PrimType Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Simplifiable () Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

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

Simplifiable Int Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => Int -> SimpleM rep Int 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 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 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 [FunReturns] Source # 
Instance details

Defined in Futhark.IR.Mem

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

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: SimplifiableRep rep => [a] -> SimpleM rep [a] 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 (a, b) Source # 
Instance details

Defined in Futhark.Optimise.Simplify.Engine

Methods

simplify :: 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 :: 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 :: 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 => Names -> 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 #