Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Imperative intermediate language used as a stepping stone in code generation.
This is a generic representation parametrised on an extensible arbitrary operation.
Originally inspired by the paper "Defunctionalizing Push Arrays" (FHPC '14).
Synopsis
- data Definitions a = Definitions {}
- newtype Functions a = Functions [(Name, Function a)]
- type Function = FunctionT
- data FunctionT a = Function {
- functionEntry :: Bool
- functionOutput :: [Param]
- functionInput :: [Param]
- functionBody :: Code a
- functionResult :: [ExternalValue]
- functionArgs :: [ExternalValue]
- data Constants a = Constants {
- constsDecl :: [Param]
- constsInit :: Code a
- data ValueDesc
- data Signedness
- data ExternalValue
- data Param
- paramName :: Param -> VName
- data SubExp
- type MemSize = SubExp
- type DimSize = SubExp
- data Space
- type SpaceId = String
- data Code a
- = Skip
- | (Code a) :>>: (Code a)
- | For VName Exp (Code a)
- | While (TExp Bool) (Code a)
- | DeclareMem VName Space
- | DeclareScalar VName Volatility PrimType
- | DeclareArray VName Space PrimType ArrayContents
- | Allocate VName (Count Bytes (TExp Int64)) Space
- | Free VName Space
- | Copy VName (Count Bytes (TExp Int64)) Space VName (Count Bytes (TExp Int64)) Space (Count Bytes (TExp Int64))
- | Write VName (Count Elements (TExp Int64)) PrimType Space Volatility Exp
- | SetScalar VName Exp
- | SetMem VName VName Space
- | Call [VName] Name [Arg]
- | If (TExp Bool) (Code a) (Code a)
- | Assert Exp (ErrorMsg Exp) (SrcLoc, [SrcLoc])
- | Comment String (Code a)
- | DebugPrint String (Maybe Exp)
- | Op a
- data PrimValue
- = IntValue !IntValue
- | FloatValue !FloatValue
- | BoolValue !Bool
- | Checked
- data ExpLeaf
- type Exp = PrimExp ExpLeaf
- type TExp t = TPrimExp t ExpLeaf
- data Volatility
- data Arg
- var :: VName -> PrimType -> Exp
- vi32 :: VName -> TExp Int32
- vi64 :: VName -> TExp Int64
- index :: VName -> Count Elements (TExp Int64) -> PrimType -> Space -> Volatility -> Exp
- newtype ErrorMsg a = ErrorMsg [ErrorMsgPart a]
- data ErrorMsgPart a
- = ErrorString String
- | ErrorInt32 a
- | ErrorInt64 a
- errorMsgArgTypes :: ErrorMsg a -> [PrimType]
- data ArrayContents
- declaredIn :: Code a -> Names
- lexicalMemoryUsage :: Function a -> Map VName Space
- calledFuncs :: Code a -> Set Name
- data Bytes
- data Elements
- elements :: a -> Count Elements a
- bytes :: a -> Count Bytes a
- withElemType :: Count Elements (TExp Int64) -> PrimType -> Count Bytes (TExp Int64)
- module Language.Futhark.Core
- module Futhark.IR.Primitive
- module Futhark.Analysis.PrimExp
- newtype Count u e = Count {
- unCount :: e
- module Futhark.IR.Prop.Names
Documentation
data Definitions a Source #
A collection of imperative functions and constants.
Instances
Pretty op => Pretty (Definitions op) Source # | |
Defined in Futhark.CodeGen.ImpCode ppr :: Definitions op -> Doc # pprPrec :: Int -> Definitions op -> Doc # pprList :: [Definitions op] -> Doc # |
A collection of imperative functions.
Instances
Functor Functions Source # | |
Foldable Functions Source # | |
Defined in Futhark.CodeGen.ImpCode fold :: Monoid m => Functions m -> m # foldMap :: Monoid m => (a -> m) -> Functions a -> m # foldMap' :: Monoid m => (a -> m) -> Functions a -> m # foldr :: (a -> b -> b) -> b -> Functions a -> b # foldr' :: (a -> b -> b) -> b -> Functions a -> b # foldl :: (b -> a -> b) -> b -> Functions a -> b # foldl' :: (b -> a -> b) -> b -> Functions a -> b # foldr1 :: (a -> a -> a) -> Functions a -> a # foldl1 :: (a -> a -> a) -> Functions a -> a # toList :: Functions a -> [a] # length :: Functions a -> Int # elem :: Eq a => a -> Functions a -> Bool # maximum :: Ord a => Functions a -> a # minimum :: Ord a => Functions a -> a # | |
Traversable Functions Source # | |
Defined in Futhark.CodeGen.ImpCode | |
Semigroup (Functions a) Source # | |
Monoid (Functions a) Source # | |
Pretty op => Pretty (Functions op) Source # | |
FreeIn a => FreeIn (Functions a) Source # | |
A imperative function, containing the body as well as its low-level inputs and outputs, as well as its high-level arguments and results. The latter are only used if the function is an entry point.
Function | |
|
Instances
Functor FunctionT Source # | |
Foldable FunctionT Source # | |
Defined in Futhark.CodeGen.ImpCode fold :: Monoid m => FunctionT m -> m # foldMap :: Monoid m => (a -> m) -> FunctionT a -> m # foldMap' :: Monoid m => (a -> m) -> FunctionT a -> m # foldr :: (a -> b -> b) -> b -> FunctionT a -> b # foldr' :: (a -> b -> b) -> b -> FunctionT a -> b # foldl :: (b -> a -> b) -> b -> FunctionT a -> b # foldl' :: (b -> a -> b) -> b -> FunctionT a -> b # foldr1 :: (a -> a -> a) -> FunctionT a -> a # foldl1 :: (a -> a -> a) -> FunctionT a -> a # toList :: FunctionT a -> [a] # length :: FunctionT a -> Int # elem :: Eq a => a -> FunctionT a -> Bool # maximum :: Ord a => FunctionT a -> a # minimum :: Ord a => FunctionT a -> a # | |
Traversable FunctionT Source # | |
Defined in Futhark.CodeGen.ImpCode | |
Show a => Show (FunctionT a) Source # | |
Pretty op => Pretty (FunctionT op) Source # | |
A collection of imperative constants.
Constants | |
|
A description of an externally meaningful value.
ArrayValue VName Space PrimType Signedness [DimSize] | An array with memory block memory space, element type, signedness of element type (if applicable), and shape. |
ScalarValue PrimType Signedness VName | A scalar value with signedness if applicable. |
data Signedness Source #
Since the core language does not care for signedness, but the source language does, entry point input/output information has metadata for integer types (and arrays containing these) that indicate whether they are really unsigned integers.
Instances
Eq Signedness Source # | |
Defined in Futhark.CodeGen.ImpCode (==) :: Signedness -> Signedness -> Bool # (/=) :: Signedness -> Signedness -> Bool # | |
Show Signedness Source # | |
Defined in Futhark.CodeGen.ImpCode showsPrec :: Int -> Signedness -> ShowS # show :: Signedness -> String # showList :: [Signedness] -> ShowS # |
data ExternalValue Source #
^ An externally visible value. This can be an opaque value (covering several physical internal values), or a single value that can be used externally.
OpaqueValue String [ValueDesc] | The string is a human-readable description with no other semantics. |
TransparentValue ValueDesc |
Instances
Show ExternalValue Source # | |
Defined in Futhark.CodeGen.ImpCode showsPrec :: Int -> ExternalValue -> ShowS # show :: ExternalValue -> String # showList :: [ExternalValue] -> ShowS # | |
Pretty ExternalValue Source # | |
Defined in Futhark.CodeGen.ImpCode ppr :: ExternalValue -> Doc # pprPrec :: Int -> ExternalValue -> Doc # pprList :: [ExternalValue] -> Doc # | |
FreeIn ExternalValue Source # | |
Defined in Futhark.CodeGen.ImpCode freeIn' :: ExternalValue -> FV Source # |
An ImpCode function parameter.
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
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.
DefaultSpace | |
Space SpaceId | |
ScalarSpace [SubExp] PrimType | A special kind of memory that is a statically sized array of some primitive type. Used for private memory on GPUs. |
A block of imperative code. Parameterised by an Op
, which
allows extensibility. Concrete uses of this type will instantiate
the type parameter with e.g. a construct for launching GPU kernels.
Skip | No-op. Crucial for the |
(Code a) :>>: (Code a) | Statement composition. Crucial for the |
For VName Exp (Code a) | A for-loop iterating the given number of times. The loop parameter starts counting from zero and will have the same (integer) type as the bound. The bound is evaluated just once, before the loop is entered. |
While (TExp Bool) (Code a) | While loop. The conditional is (of course) re-evaluated before every iteration of the loop. |
DeclareMem VName Space | Declare a memory block variable that will point to
memory in the given memory space. Note that this is
distinct from allocation. The memory block must be the
target of either an |
DeclareScalar VName Volatility PrimType | Declare a scalar variable with an initially undefined value. |
DeclareArray VName Space PrimType ArrayContents | Create an array containing the given values. The lifetime of the array will be the entire application. This is mostly used for constant arrays, but also for some bookkeeping data, like the synchronisation counts used to implement reduction. |
Allocate VName (Count Bytes (TExp Int64)) Space | Memory space must match the corresponding
|
Free VName Space | Indicate that some memory block will never again be referenced via the indicated variable. However, it may still be accessed through aliases. It is only safe to actually deallocate the memory block if this is the last reference. There is no guarantee that all memory blocks will be freed with this statement. Backends are free to ignore it entirely. |
Copy VName (Count Bytes (TExp Int64)) Space VName (Count Bytes (TExp Int64)) Space (Count Bytes (TExp Int64)) | Destination, offset in destination, destination space, source, offset in source, offset space, number of bytes. |
Write VName (Count Elements (TExp Int64)) PrimType Space Volatility Exp |
|
SetScalar VName Exp | Set a scalar variable. |
SetMem VName VName Space | Must be in same space. |
Call [VName] Name [Arg] | Function call. The results are written to the
provided |
If (TExp Bool) (Code a) (Code a) | Conditional execution. |
Assert Exp (ErrorMsg Exp) (SrcLoc, [SrcLoc]) | Assert that something must be true. Should it turn out not to be true, then report a failure along with the given error message. |
Comment String (Code a) | Has the same semantics as the contained code, but the comment should show up in generated code for ease of inspection. |
DebugPrint String (Maybe Exp) | Print the given value to the screen, somehow annotated with the given string as a description. If no type/value pair, just print the string. This has no semantic meaning, but is used entirely for debugging. Code generators are free to ignore this statement. |
Op a | Perform an extensible operation. |
Instances
Functor Code Source # | |
Foldable Code Source # | |
Defined in Futhark.CodeGen.ImpCode fold :: Monoid m => Code m -> m # foldMap :: Monoid m => (a -> m) -> Code a -> m # foldMap' :: Monoid m => (a -> m) -> Code a -> m # foldr :: (a -> b -> b) -> b -> Code a -> b # foldr' :: (a -> b -> b) -> b -> Code a -> b # foldl :: (b -> a -> b) -> b -> Code a -> b # foldl' :: (b -> a -> b) -> b -> Code a -> b # foldr1 :: (a -> a -> a) -> Code a -> a # foldl1 :: (a -> a -> a) -> Code a -> a # elem :: Eq a => a -> Code a -> Bool # maximum :: Ord a => Code a -> a # | |
Traversable Code Source # | |
Show a => Show (Code a) Source # | |
Semigroup (Code a) Source # | |
Monoid (Code a) Source # | |
Pretty op => Pretty (Code op) Source # | |
FreeIn a => FreeIn (Code a) Source # | |
Non-array values.
IntValue !IntValue | |
FloatValue !FloatValue | |
BoolValue !Bool | |
Checked | The only value of type |
The leaves of an Exp
.
ScalarVar VName | A scalar variable. The type is stored in the
|
SizeOf PrimType | The size of a primitive type. |
Index VName (Count Elements (TExp Int64)) PrimType Space Volatility | Reading a value from memory. The arguments have
the same meaning as with |
type Exp = PrimExp ExpLeaf Source #
A side-effect free expression whose execution will produce a single primitive value.
data Volatility Source #
The volatility of a memory access or variable. Feel free to ignore this for backends where it makes no sense (anything but C and similar low-level things)
Instances
Eq Volatility Source # | |
Defined in Futhark.CodeGen.ImpCode (==) :: Volatility -> Volatility -> Bool # (/=) :: Volatility -> Volatility -> Bool # | |
Ord Volatility Source # | |
Defined in Futhark.CodeGen.ImpCode compare :: Volatility -> Volatility -> Ordering # (<) :: Volatility -> Volatility -> Bool # (<=) :: Volatility -> Volatility -> Bool # (>) :: Volatility -> Volatility -> Bool # (>=) :: Volatility -> Volatility -> Bool # max :: Volatility -> Volatility -> Volatility # min :: Volatility -> Volatility -> Volatility # | |
Show Volatility Source # | |
Defined in Futhark.CodeGen.ImpCode showsPrec :: Int -> Volatility -> ShowS # show :: Volatility -> String # showList :: [Volatility] -> ShowS # |
index :: VName -> Count Elements (TExp Int64) -> PrimType -> Space -> Volatility -> Exp Source #
Concise wrapper for using Index
.
An error message is a list of error parts, which are concatenated to form the final message.
ErrorMsg [ErrorMsgPart a] |
Instances
Functor ErrorMsg Source # | |
Foldable ErrorMsg Source # | |
Defined in Futhark.IR.Syntax.Core fold :: Monoid m => ErrorMsg m -> m # foldMap :: Monoid m => (a -> m) -> ErrorMsg a -> m # foldMap' :: Monoid m => (a -> m) -> ErrorMsg a -> m # foldr :: (a -> b -> b) -> b -> ErrorMsg a -> b # foldr' :: (a -> b -> b) -> b -> ErrorMsg a -> b # foldl :: (b -> a -> b) -> b -> ErrorMsg a -> b # foldl' :: (b -> a -> b) -> b -> ErrorMsg a -> b # foldr1 :: (a -> a -> a) -> ErrorMsg a -> a # foldl1 :: (a -> a -> a) -> ErrorMsg a -> a # elem :: Eq a => a -> ErrorMsg a -> Bool # maximum :: Ord a => ErrorMsg a -> a # minimum :: Ord a => ErrorMsg a -> a # | |
Traversable ErrorMsg Source # | |
Eq a => Eq (ErrorMsg a) Source # | |
Ord a => Ord (ErrorMsg a) Source # | |
Show a => Show (ErrorMsg a) Source # | |
IsString (ErrorMsg a) Source # | |
Defined in Futhark.IR.Syntax.Core fromString :: String -> ErrorMsg a # | |
Pretty a => Pretty (ErrorMsg a) Source # | |
data ErrorMsgPart a Source #
A part of an error message.
ErrorString String | A literal string. |
ErrorInt32 a | A run-time integer value. |
ErrorInt64 a | A bigger run-time integer value. |
Instances
errorMsgArgTypes :: ErrorMsg a -> [PrimType] Source #
How many non-constant parts does the error message have, and what is their type?
data ArrayContents Source #
The contents of a statically declared constant array. Such arrays are always unidimensional, and reshaped if necessary in the code that uses them.
ArrayValues [PrimValue] | Precisely these values. |
ArrayZeros Int | This many zeroes. |
Instances
Show ArrayContents Source # | |
Defined in Futhark.CodeGen.ImpCode showsPrec :: Int -> ArrayContents -> ShowS # show :: ArrayContents -> String # showList :: [ArrayContents] -> ShowS # | |
Pretty ArrayContents Source # | |
Defined in Futhark.CodeGen.ImpCode ppr :: ArrayContents -> Doc # pprPrec :: Int -> ArrayContents -> Doc # pprList :: [ArrayContents] -> Doc # |
declaredIn :: Code a -> Names Source #
The names declared with DeclareMem
, DeclareScalar
, and
DeclareArray
in the given code.
lexicalMemoryUsage :: Function a -> Map VName Space Source #
Find those memory blocks that are used only lexically. That is,
are not used as the source or target of a SetMem
, or are the
result of the function, nor passed as arguments to other functions.
This is interesting because such memory blocks do not need
reference counting, but can be managed in a purely stack-like
fashion.
We do not look inside any Op
s. We assume that no Op
is going
to SetMem
a memory block declared outside it.
calledFuncs :: Code a -> Set Name Source #
The set of functions that are called by this code. Assumes there
are no function calls in Op
s.
Typed enumerations
withElemType :: Count Elements (TExp Int64) -> PrimType -> Count Bytes (TExp Int64) Source #
Convert a count of elements into a count of bytes, given the per-element size.
Re-exports from other modules.
module Language.Futhark.Core
module Futhark.IR.Primitive
module Futhark.Analysis.PrimExp
A wrapper supporting a phantom type for indicating what we are counting.
Instances
Functor (Count u) Source # | |
Foldable (Count u) Source # | |
Defined in Futhark.IR.Kernels.Sizes fold :: Monoid m => Count u m -> m # foldMap :: Monoid m => (a -> m) -> Count u a -> m # foldMap' :: Monoid m => (a -> m) -> Count u a -> m # foldr :: (a -> b -> b) -> b -> Count u a -> b # foldr' :: (a -> b -> b) -> b -> Count u a -> b # foldl :: (b -> a -> b) -> b -> Count u a -> b # foldl' :: (b -> a -> b) -> b -> Count u a -> b # foldr1 :: (a -> a -> a) -> Count u a -> a # foldl1 :: (a -> a -> a) -> Count u a -> a # elem :: Eq a => a -> Count u a -> Bool # maximum :: Ord a => Count u a -> a # minimum :: Ord a => Count u a -> a # | |
Traversable (Count u) Source # | |
Eq e => Eq (Count u e) Source # | |
Num e => Num (Count u e) Source # | |
Defined in Futhark.IR.Kernels.Sizes | |
Ord e => Ord (Count u e) Source # | |
Defined in Futhark.IR.Kernels.Sizes | |
Show e => Show (Count u e) Source # | |
Pretty e => Pretty (Count u e) Source # | |
IntegralExp e => IntegralExp (Count u e) Source # | |
Defined in Futhark.IR.Kernels.Sizes | |
FreeIn e => FreeIn (Count u e) Source # | |
Substitute e => Substitute (Count u e) Source # | |
Defined in Futhark.IR.Kernels.Sizes |
module Futhark.IR.Prop.Names