| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Futhark.IR.Prop
Contents
Description
This module provides various simple ways to query and manipulate fundamental Futhark terms, such as types and values. The intent is to keep Futhark.IR.Syntax simple, and put whatever embellishments we need here. This is an internal, desugared representation.
Synopsis
- module Futhark.IR.Prop.Reshape
- module Futhark.IR.Prop.Rearrange
- module Futhark.IR.Prop.Types
- module Futhark.IR.Prop.Constants
- module Futhark.IR.Prop.TypeOf
- module Futhark.IR.Prop.Pat
- module Futhark.IR.Prop.Names
- module Futhark.IR.RetType
- module Futhark.IR.Rephrase
- isBuiltInFunction :: Name -> Bool
- builtInFunctions :: Map Name (PrimType, [PrimType])
- asBasicOp :: Exp rep -> Maybe BasicOp
- safeExp :: ASTRep rep => Exp rep -> Bool
- subExpVars :: [SubExp] -> [VName]
- subExpVar :: SubExp -> Maybe VName
- commutativeLambda :: Lambda rep -> Bool
- defAux :: dec -> StmAux dec
- stmCerts :: Stm rep -> Certs
- certify :: Certs -> Stm rep -> Stm rep
- attribute :: Attrs -> Stm rep -> Stm rep
- expExtTypesFromPat :: Typed dec => Pat dec -> [ExtType]
- attrsForAssert :: Attrs -> Attrs
- lamIsBinOp :: ASTRep rep => Lambda rep -> Maybe [(BinOp, PrimType, VName, VName)]
- isIdentityLambda :: Lambda rep -> Bool
- isNilLambda :: Lambda rep -> Bool
- builtinName :: Text -> Name
- isBuiltinName :: Name -> Maybe Text
- type ASTConstraints a = (Eq a, Ord a, Show a, Rename a, Substitute a, FreeIn a, Pretty a)
- class TypedOp op => IsOp (op :: Type -> Type) where
- class (RepTypes rep, PrettyRep rep, Renameable rep, Substitutable rep, FreeDec (ExpDec rep), FreeIn (LetDec rep), FreeDec (BodyDec rep), FreeIn (FParamInfo rep), FreeIn (LParamInfo rep), FreeIn (RetType rep), FreeIn (BranchType rep), ASTConstraints (OpC rep rep), IsOp (OpC rep), RephraseOp (OpC rep)) => ASTRep rep where
- expTypesFromPat :: (HasScope rep m, Monad m) => Pat (LetDec rep) -> m [BranchType rep]
- class FreeIn res => IsResult res where
- resAliases :: res -> Names
Documentation
module Futhark.IR.Prop.Reshape
module Futhark.IR.Prop.Rearrange
module Futhark.IR.Prop.Types
module Futhark.IR.Prop.Constants
module Futhark.IR.Prop.TypeOf
module Futhark.IR.Prop.Pat
module Futhark.IR.Prop.Names
module Futhark.IR.RetType
module Futhark.IR.Rephrase
Built-in functions
isBuiltInFunction :: Name -> Bool Source #
isBuiltInFunction k is True if k is an element of builtInFunctions.
builtInFunctions :: Map Name (PrimType, [PrimType]) Source #
A map of all built-in functions and their types.
Extra tools
safeExp :: ASTRep rep => Exp rep -> Bool Source #
An expression is safe if it is always well-defined in any context, assuming data dependencies are satisfied - and note that certificates are just a special case of data dependencies. For example, array indexing is not safe, as the index may be out of bounds. Array slicing is also considered unsafe, as semantically we consider this to be a copy (even if operationally it is usually a view). On the other hand, adding two numbers cannot fail.
The certificate requirement is subtle but important: Iota is safe only when the argument given is non-negative, which is assumed checked by a certificate.
Essentially the rule is this: if an expression is safe, then it means we can hoist it out of control flow without a soundness issue.
Some of these operations are less safe than you might intuitively expect, e.g. Reshape is considered unsafe despite usually not resulting in any code generation. Reshape can *semantically* fail if the original array does not have the same number of elements as the new shape.
Being very generous with unsafety-status is to ease program transformation, such that we do not have to worry too much about turning unsafe operations into "safe" operations.
subExpVars :: [SubExp] -> [VName] Source #
Return the variable names used in Var subexpressions. May contain
duplicates.
commutativeLambda :: Lambda rep -> Bool Source #
Does the given lambda represent a known commutative function? Based on pattern matching and checking whether the lambda represents a known arithmetic operator; don't expect anything clever here.
expExtTypesFromPat :: Typed dec => Pat dec -> [ExtType] Source #
Construct the type of an expression that would match the pattern.
attrsForAssert :: Attrs -> Attrs Source #
Keep only those attributes that are relevant for Assert
expressions.
lamIsBinOp :: ASTRep rep => Lambda rep -> Maybe [(BinOp, PrimType, VName, VName)] Source #
Horizontally fission a lambda that models a binary operator.
isIdentityLambda :: Lambda rep -> Bool Source #
Is the given lambda an identity lambda?
isNilLambda :: Lambda rep -> Bool Source #
Is the given lambda a nil lambda?
builtinName :: Text -> Name Source #
Construct a name for a builtin function. This name will be recognised by
isBuiltinName.
isBuiltinName :: Name -> Maybe Text Source #
Is this a builtin name, and if so, what is the underlying name?
type ASTConstraints a = (Eq a, Ord a, Show a, Rename a, Substitute a, FreeIn a, Pretty a) Source #
A handy shorthand for properties that we usually want for things we stuff into ASTs.
class TypedOp op => IsOp (op :: Type -> Type) where Source #
A type class for operations.
Methods
safeOp :: ASTRep rep => op rep -> Bool Source #
Like safeExp, but for arbitrary ops.
cheapOp :: ASTRep rep => op rep -> Bool Source #
Should we try to hoist this out of branches?
opDependencies :: ASTRep rep => op rep -> [Names] Source #
Compute the data dependencies of an operation.
class (RepTypes rep, PrettyRep rep, Renameable rep, Substitutable rep, FreeDec (ExpDec rep), FreeIn (LetDec rep), FreeDec (BodyDec rep), FreeIn (FParamInfo rep), FreeIn (LParamInfo rep), FreeIn (RetType rep), FreeIn (BranchType rep), ASTConstraints (OpC rep rep), IsOp (OpC rep), RephraseOp (OpC rep)) => ASTRep rep where Source #
Representation-specific attributes; also means the rep supports some basic facilities.
Methods
expTypesFromPat :: (HasScope rep m, Monad m) => Pat (LetDec rep) -> m [BranchType rep] Source #
Given a pattern, construct the type of a body that would match
it. An implementation for many representations would be
expExtTypesFromPat.
Instances
| ASTRep GPU Source # | |
Defined in Futhark.IR.GPU | |
| ASTRep GPUMem Source # | |
Defined in Futhark.IR.GPUMem | |
| ASTRep MC Source # | |
Defined in Futhark.IR.MC | |
| ASTRep MCMem Source # | |
Defined in Futhark.IR.MCMem | |
| ASTRep SOACS Source # | |
Defined in Futhark.IR.SOACS | |
| ASTRep Seq Source # | |
Defined in Futhark.IR.Seq | |
| ASTRep SeqMem Source # | |
Defined in Futhark.IR.SeqMem | |
| (ASTRep rep, AliasedOp (OpC rep), ASTConstraints (OpC rep (Aliases rep))) => ASTRep (Aliases rep) Source # | |
Defined in Futhark.IR.Aliases | |
| (Informing rep, IsOp (OpC rep)) => ASTRep (Wise rep) Source # | |
Defined in Futhark.Optimise.Simplify.Rep | |
class FreeIn res => IsResult res where Source #
Something that can be returned from a GBody.
Methods
resAliases :: res -> Names Source #
The names that may or may not contribute to the aliases of this result.
Instances
| IsResult KernelResult Source # | |
Defined in Futhark.IR.SegOp Methods resAliases :: KernelResult -> Names Source # | |
| IsResult SubExpRes Source # | |
Defined in Futhark.IR.Prop Methods resAliases :: SubExpRes -> Names Source # | |
| IsResult () Source # | |
Defined in Futhark.IR.Prop Methods resAliases :: () -> Names Source # | |