Safe Haskell | None |
---|---|
Language | Haskell2010 |
Futhark core language skeleton. Concrete representations further extend this skeleton by defining a "lore", which specifies concrete annotations (Futhark.Representation.AST.Annotations) and semantics.
Synopsis
- module Language.Futhark.Core
- module Futhark.Representation.AST.Annotations
- module Futhark.Representation.AST.Syntax.Core
- data Uniqueness
- data NoUniqueness = NoUniqueness
- newtype Rank = Rank Int
- class (Monoid a, Eq a, Ord a) => ArrayShape a where
- data Space
- data TypeBase shape u
- data Diet
- data Ident = Ident {}
- data SubExp
- type PatElem lore = PatElemT (LetAttr lore)
- data PatElemT attr = PatElem {
- patElemName :: VName
- patElemAttr :: attr
- data PatternT attr = Pattern {
- patternContextElements :: [PatElemT attr]
- patternValueElements :: [PatElemT attr]
- type Pattern lore = PatternT (LetAttr lore)
- data StmAux attr = StmAux {
- stmAuxCerts :: !Certificates
- stmAuxAttr :: attr
- data Stm lore = Let {}
- type Stms lore = Seq (Stm lore)
- type Result = [SubExp]
- data BodyT lore = Body {}
- type Body = BodyT
- data BasicOp lore
- = SubExp SubExp
- | Opaque SubExp
- | ArrayLit [SubExp] Type
- | UnOp UnOp SubExp
- | BinOp BinOp SubExp SubExp
- | CmpOp CmpOp SubExp SubExp
- | ConvOp ConvOp SubExp
- | Assert SubExp (ErrorMsg SubExp) (SrcLoc, [SrcLoc])
- | Index VName (Slice SubExp)
- | Update VName (Slice SubExp) SubExp
- | Concat Int VName [VName] SubExp
- | Copy VName
- | Manifest [Int] VName
- | Iota SubExp SubExp SubExp IntType
- | Replicate Shape SubExp
- | Repeat [Shape] Shape VName
- | Scratch PrimType [SubExp]
- | Reshape (ShapeChange SubExp) VName
- | Rearrange [Int] VName
- | Rotate [SubExp] VName
- data UnOp
- data BinOp
- = Add IntType
- | FAdd FloatType
- | Sub IntType
- | FSub FloatType
- | Mul IntType
- | FMul FloatType
- | UDiv IntType
- | SDiv IntType
- | FDiv FloatType
- | UMod IntType
- | SMod IntType
- | SQuot IntType
- | SRem IntType
- | SMin IntType
- | UMin IntType
- | FMin FloatType
- | SMax IntType
- | UMax IntType
- | FMax FloatType
- | Shl IntType
- | LShr IntType
- | AShr IntType
- | And IntType
- | Or IntType
- | Xor IntType
- | Pow IntType
- | FPow FloatType
- | LogAnd
- | LogOr
- data CmpOp
- data ConvOp
- data DimChange d
- = DimCoercion d
- | DimNew d
- type ShapeChange d = [DimChange d]
- data ExpT lore
- type Exp = ExpT
- data LoopForm lore
- data IfAttr rt = IfAttr {}
- data IfSort
- data Safety
- data LambdaT lore = Lambda {
- lambdaParams :: [LParam lore]
- lambdaBody :: BodyT lore
- lambdaReturnType :: [Type]
- type Lambda = LambdaT
- data ParamT attr = Param {}
- type FParam lore = ParamT (FParamAttr lore)
- type LParam lore = ParamT (LParamAttr lore)
- data FunDefT lore = FunDef {
- funDefEntryPoint :: Maybe EntryPoint
- funDefName :: Name
- funDefRetType :: [RetType lore]
- funDefParams :: [FParam lore]
- funDefBody :: BodyT lore
- type FunDef = FunDefT
- type EntryPoint = ([EntryPointType], [EntryPointType])
- data EntryPointType
- newtype ProgT lore = Prog {
- progFunctions :: [FunDef lore]
- type Prog = ProgT
- oneStm :: Stm lore -> Stms lore
- stmsFromList :: [Stm lore] -> Stms lore
- stmsToList :: Stms lore -> [Stm lore]
- stmsHead :: Stms lore -> Maybe (Stm lore, Stms lore)
Documentation
module Language.Futhark.Core
Types
data Uniqueness Source #
The uniqueness attribute of a type. This essentially indicates
whether or not in-place modifications are acceptable. With respect
to ordering, Unique
is greater than Nonunique
.
Instances
data NoUniqueness Source #
A fancier name for '()' - encodes no uniqueness information.
Instances
The size of an array type as merely the number of dimensions, with no further information.
class (Monoid a, Eq a, Ord a) => ArrayShape a where Source #
A class encompassing types containing array shape information.
shapeRank :: a -> Int Source #
Return the rank of an array with the given size.
stripDims :: Int -> a -> a Source #
stripDims n shape
strips the outer n
dimensions from
shape
.
subShapeOf :: a -> a -> Bool Source #
Check whether one shape if a subset of another shape.
Instances
ArrayShape Rank Source # | |
ArrayShape (ShapeBase SubExp) Source # | |
ArrayShape (ShapeBase ExtSize) Source # | |
The memory space of a block. If DefaultSpace
, this is the "default"
space, whatever that is. The exact meaning of the SpaceID
depends on the backend used. In GPU kernels, for example, this is
used to distinguish between constant, global and shared memory
spaces. In GPU-enabled host code, it is used to distinguish
between host memory (DefaultSpace
) and GPU space.
data TypeBase shape u Source #
An Futhark type is either an array or an element type. When
comparing types for equality with ==
, shapes must match.
Instances
Information about which parts of a value/type are consumed. For
example, we might say that a function taking three arguments of
types ([int], *[int], [int])
has diet [Observe, Consume,
Observe]
.
Abstract syntax tree
An identifier consists of its name and the type of the value bound to the identifier.
A subexpression is either a scalar constant or a variable. One important property is that evaluation of a subexpression is guaranteed to complete in constant time.
Instances
An element of a pattern - consisting of a name (essentially a pair of the name and type) and an addditional parametric attribute. This attribute is what is expected to contain the type of the resulting variable.
PatElem | |
|
Instances
A pattern is conceptually just a list of names and their types.
Pattern | |
|
Instances
Functor PatternT Source # | |
Eq attr => Eq (PatternT attr) Source # | |
Ord attr => Ord (PatternT attr) Source # | |
Defined in Futhark.Representation.AST.Syntax compare :: PatternT attr -> PatternT attr -> Ordering # (<) :: PatternT attr -> PatternT attr -> Bool # (<=) :: PatternT attr -> PatternT attr -> Bool # (>) :: PatternT attr -> PatternT attr -> Bool # (>=) :: PatternT attr -> PatternT attr -> Bool # | |
Show attr => Show (PatternT attr) Source # | |
Semigroup (PatternT attr) Source # | |
Monoid (PatternT attr) Source # | |
Pretty (PatElemT attr) => Pretty (PatternT attr) Source # | |
FreeIn attr => FreeIn (PatternT attr) Source # | |
Substitute attr => Substitute (PatternT attr) Source # | |
Defined in Futhark.Transform.Substitute | |
Rename attr => Rename (PatternT attr) Source # | |
RangeOf attr => RangesOf (PatternT attr) Source # | |
Auxilliary Information associated with a statement.
StmAux | |
|
Instances
Eq attr => Eq (StmAux attr) Source # | |
Ord attr => Ord (StmAux attr) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Show attr => Show (StmAux attr) Source # | |
FreeIn attr => FreeIn (StmAux attr) Source # | |
Substitute attr => Substitute (StmAux attr) Source # | |
Defined in Futhark.Transform.Substitute | |
Rename attr => Rename (StmAux attr) Source # | |
A local variable binding.
Instances
Scoped lore (Stm lore) Source # | |
Scoped lore (Stms lore) Source # | |
Annotations lore => Eq (Stm lore) Source # | |
Annotations lore => Ord (Stm lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Annotations lore => Show (Stm lore) Source # | |
PrettyLore lore => Pretty (Stms lore) Source # | |
PrettyLore lore => Pretty (Stm lore) Source # | |
FreeIn (Stm lore) => FreeIn (Stms lore) Source # | |
Substitute (Stm lore) => Substitute (Stms lore) Source # | |
Defined in Futhark.Transform.Substitute | |
Substitutable lore => Substitute (Stm lore) Source # | |
Defined in Futhark.Transform.Substitute | |
Renameable lore => Rename (Stm lore) Source # | |
A body consists of a number of bindings, terminating in a result (essentially a tuple literal).
Instances
Annotations lore => Eq (BodyT lore) Source # | |
Annotations lore => Ord (BodyT lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Annotations lore => Show (BodyT lore) Source # | |
PrettyLore lore => Pretty (Body lore) Source # | |
Substitutable lore => Substitute (Body lore) Source # | |
Defined in Futhark.Transform.Substitute | |
Renameable lore => Rename (Body lore) Source # | |
Ranged lore => RangesOf (Body lore) Source # | |
A primitive operation that returns something of known size and does not itself contain any bindings.
SubExp SubExp | A variable or constant. |
Opaque SubExp | Semantically and operationally just identity, but is invisible/impenetrable to optimisations (hopefully). This is just a hack to avoid optimisation (so, to work around compiler limitations). |
ArrayLit [SubExp] Type | Array literals, e.g., |
UnOp UnOp SubExp | Unary operation. |
BinOp BinOp SubExp SubExp | Binary operation. |
CmpOp CmpOp SubExp SubExp | Comparison - result type is always boolean. |
ConvOp ConvOp SubExp | Conversion "casting". |
Assert SubExp (ErrorMsg SubExp) (SrcLoc, [SrcLoc]) | Turn a boolean into a certificate, halting the program with the given error message if the boolean is false. |
Index VName (Slice SubExp) | The certificates for bounds-checking are part of the |
Update VName (Slice SubExp) SubExp | An in-place update of the given array at the given position. Consumes the array. |
Concat Int VName [VName] SubExp |
|
Copy VName | Copy the given array. The result will not alias anything. |
Manifest [Int] VName | Manifest an array with dimensions represented in the given order. The result will not alias anything. |
Iota SubExp SubExp SubExp IntType |
The |
Replicate Shape SubExp | replicate([3][2],1) = [[1,1], [1,1], [1,1]] |
Repeat [Shape] Shape VName | Repeat each dimension of the input array some number of times,
given by the corresponding shape. For an array of rank |
Scratch PrimType [SubExp] | Create array of given type and shape, with undefined elements. |
Reshape (ShapeChange SubExp) VName | 1st arg is the new shape, 2nd arg is the input array *) |
Rearrange [Int] VName | Permute the dimensions of the input array. The list
of integers is a list of dimensions (0-indexed), which
must be a permutation of |
Rotate [SubExp] VName | Rotate the dimensions of the input array. The list of subexpressions specify how much each dimension is rotated. The length of this list must be equal to the rank of the array. |
Instances
Eq (BasicOp lore) Source # | |
Ord (BasicOp lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Show (BasicOp lore) Source # | |
Pretty (BasicOp lore) Source # | |
Various unary operators. It is a bit ad-hoc what is a unary operator and what is a built-in function. Perhaps these should all go away eventually.
Not | E.g., |
Complement IntType | E.g., |
Abs IntType |
|
FAbs FloatType |
|
SSignum IntType | Signed sign function: |
USignum IntType | Unsigned sign function: |
Binary operators. These correspond closely to the binary operators in LLVM. Most are parametrised by their expected input and output types.
Add IntType | Integer addition. |
FAdd FloatType | Floating-point addition. |
Sub IntType | Integer subtraction. |
FSub FloatType | Floating-point subtraction. |
Mul IntType | Integer multiplication. |
FMul FloatType | Floating-point multiplication. |
UDiv IntType | Unsigned integer division. Rounds towards negativity infinity. Note: this is different from LLVM. |
SDiv IntType | Signed integer division. Rounds towards negativity infinity. Note: this is different from LLVM. |
FDiv FloatType | Floating-point division. |
UMod IntType | Unsigned integer modulus; the countepart to |
SMod IntType | Signed integer modulus; the countepart to |
SQuot IntType | Signed integer division. Rounds towards zero.
This corresponds to the |
SRem IntType | Signed integer division. Rounds towards zero.
This corresponds to the |
SMin IntType | Returns the smallest of two signed integers. |
UMin IntType | Returns the smallest of two unsigned integers. |
FMin FloatType | Returns the smallest of two floating-point numbers. |
SMax IntType | Returns the greatest of two signed integers. |
UMax IntType | Returns the greatest of two unsigned integers. |
FMax FloatType | Returns the greatest of two floating-point numbers. |
Shl IntType | Left-shift. |
LShr IntType | Logical right-shift, zero-extended. |
AShr IntType | Arithmetic right-shift, sign-extended. |
And IntType | Bitwise and. |
Or IntType | Bitwise or. |
Xor IntType | Bitwise exclusive-or. |
Pow IntType | Integer exponentiation. |
FPow FloatType | Floating-point exponentiation. |
LogAnd | Boolean and - not short-circuiting. |
LogOr | Boolean or - not short-circuiting. |
Comparison operators are like BinOp
s, but they return PrimType
s.
The somewhat ugly constructor names are straight out of LLVM.
CmpEq PrimType | All types equality. |
CmpUlt IntType | Unsigned less than. |
CmpUle IntType | Unsigned less than or equal. |
CmpSlt IntType | Signed less than. |
CmpSle IntType | Signed less than or equal. |
FCmpLt FloatType | Floating-point less than. |
FCmpLe FloatType | Floating-point less than or equal. |
CmpLlt | Boolean less than. |
CmpLle | Boolean less than or equal. |
Conversion operators try to generalise the from t0 x to t1
instructions from LLVM.
ZExt IntType IntType | Zero-extend the former integer type to the latter. If the new type is smaller, the result is a truncation. |
SExt IntType IntType | Sign-extend the former integer type to the latter. If the new type is smaller, the result is a truncation. |
FPConv FloatType FloatType | Convert value of the former floating-point type to the latter. If the new type is smaller, the result is a truncation. |
FPToUI FloatType IntType | Convert a floating-point value to the nearest unsigned integer (rounding towards zero). |
FPToSI FloatType IntType | Convert a floating-point value to the nearest signed integer (rounding towards zero). |
UIToFP IntType FloatType | Convert an unsigned integer to a floating-point value. |
SIToFP IntType FloatType | Convert a signed integer to a floating-point value. |
IToB IntType | Convert an integer to a boolean value. Zero becomes false; anything else is true. |
BToI IntType | Convert a boolean to an integer. True is converted to 1 and False to 0. |
The new dimension in a Reshape
-like operation. This allows us to
disambiguate "real" reshapes, that change the actual shape of the
array, from type coercions that are just present to make the types
work out. The two constructors are considered equal for purposes of Eq
.
DimCoercion d | The new dimension is guaranteed to be numerically equal to the old one. |
DimNew d | The new dimension is not necessarily numerically equal to the old one. |
Instances
type ShapeChange d = [DimChange d] Source #
A list of DimChange
s, indicating the new dimensions of an array.
The root Futhark expression type. The ExpT
constructor contains
a lore-specific operation. Do-loops, branches and function calls
are special. Everything else is a simple BasicOp
.
BasicOp (BasicOp lore) | A simple (non-recursive) operation. |
Apply Name [(SubExp, Diet)] [RetType lore] (Safety, SrcLoc, [SrcLoc]) | |
If SubExp (BodyT lore) (BodyT lore) (IfAttr (BranchType lore)) | |
DoLoop [(FParam lore, SubExp)] [(FParam lore, SubExp)] (LoopForm lore) (BodyT lore) |
|
Op (Op lore) |
Instances
Annotations lore => Eq (ExpT lore) Source # | |
Annotations lore => Ord (ExpT lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Annotations lore => Show (ExpT lore) Source # | |
PrettyLore lore => Pretty (Exp lore) Source # | |
Substitutable lore => Substitute (Exp lore) Source # | |
Defined in Futhark.Transform.Substitute | |
Renameable lore => Rename (Exp lore) Source # | |
For-loop or while-loop?
Instances
Scoped lore (LoopForm lore) Source # | |
Annotations lore => Eq (LoopForm lore) Source # | |
Annotations lore => Ord (LoopForm lore) Source # | |
Defined in Futhark.Representation.AST.Syntax compare :: LoopForm lore -> LoopForm lore -> Ordering # (<) :: LoopForm lore -> LoopForm lore -> Bool # (<=) :: LoopForm lore -> LoopForm lore -> Bool # (>) :: LoopForm lore -> LoopForm lore -> Bool # (>=) :: LoopForm lore -> LoopForm lore -> Bool # | |
Annotations lore => Show (LoopForm lore) Source # | |
FreeIn (LParamAttr lore) => FreeIn (LoopForm lore) Source # | |
Data associated with a branch.
IfNormal | An ordinary branch. |
IfFallback | A branch where the "true" case is what we are actually interested in, and the "false" case is only present as a fallback for when the true case cannot be safely evaluated. the compiler is permitted to optimise away the branch if the true case contains only safe statements. |
Whether something is safe or unsafe (mostly function calls, and
in the context of whether operations are dynamically checked).
When we inline an Unsafe
function, we remove all safety checks in
its body. The Ord
instance picks Unsafe
as being less than
Safe
.
Anonymous function for use in a SOAC.
Lambda | |
|
Instances
Scoped lore (Lambda lore) Source # | |
Annotations lore => Eq (LambdaT lore) Source # | |
Annotations lore => Ord (LambdaT lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Annotations lore => Show (LambdaT lore) Source # | |
PrettyLore lore => Pretty (Lambda lore) Source # | |
Substitutable lore => Substitute (Lambda lore) Source # | |
Defined in Futhark.Transform.Substitute | |
Renameable lore => Rename (Lambda lore) Source # | |
Definitions
A function parameter.
Instances
type FParam lore = ParamT (FParamAttr lore) Source #
type LParam lore = ParamT (LParamAttr lore) Source #
Function Declarations
FunDef | |
|
Instances
Scoped lore (FunDef lore) Source # | |
Annotations lore => Eq (FunDefT lore) Source # | |
Annotations lore => Ord (FunDefT lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Annotations lore => Show (FunDefT lore) Source # | |
PrettyLore lore => Pretty (FunDef lore) Source # | |
Renameable lore => Rename (FunDef lore) Source # | |
type EntryPoint = ([EntryPointType], [EntryPointType]) Source #
Information about the parameters and return value of an entry point. The first element is for parameters, the second for return value.
data EntryPointType Source #
Every entry point argument and return value has an annotation indicating how it maps to the original source program type.
TypeUnsigned | Is an unsigned integer or array of unsigned integers. |
TypeOpaque String Int | A black box type comprising this many core values. The string is a human-readable description with no other semantics. |
TypeDirect | Maps directly. |
Instances
Eq EntryPointType Source # | |
Defined in Futhark.Representation.AST.Syntax (==) :: EntryPointType -> EntryPointType -> Bool # (/=) :: EntryPointType -> EntryPointType -> Bool # | |
Ord EntryPointType Source # | |
Defined in Futhark.Representation.AST.Syntax compare :: EntryPointType -> EntryPointType -> Ordering # (<) :: EntryPointType -> EntryPointType -> Bool # (<=) :: EntryPointType -> EntryPointType -> Bool # (>) :: EntryPointType -> EntryPointType -> Bool # (>=) :: EntryPointType -> EntryPointType -> Bool # max :: EntryPointType -> EntryPointType -> EntryPointType # min :: EntryPointType -> EntryPointType -> EntryPointType # | |
Show EntryPointType Source # | |
Defined in Futhark.Representation.AST.Syntax showsPrec :: Int -> EntryPointType -> ShowS # show :: EntryPointType -> String # showList :: [EntryPointType] -> ShowS # |
An entire Futhark program.
Prog | |
|
Instances
Annotations lore => Eq (ProgT lore) Source # | |
Annotations lore => Ord (ProgT lore) Source # | |
Defined in Futhark.Representation.AST.Syntax | |
Annotations lore => Show (ProgT lore) Source # | |
PrettyLore lore => Pretty (Prog lore) Source # | |
Utils
stmsFromList :: [Stm lore] -> Stms lore Source #
stmsToList :: Stms lore -> [Stm lore] Source #