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

Futhark.CodeGen.Backends.SimpleRep

Description

Simple C runtime representation.

Most types use the same memory and scalar variable representation. For those that do not (as of this writing, only Float16), we use primStorageType for the array element representation, and primTypeToCType for their scalar representation. Use toStorage and fromStorage to convert back and forth.

Synopsis

Documentation

tupleField :: Int -> String Source #

tupleField i is the name of field number i in a tuple.

funName :: Name -> Text Source #

funName f is the name of the C function corresponding to the Futhark function f.

defaultMemBlockType :: Type Source #

The type of memory blocks in the default memory space.

intTypeToCType :: IntType -> Type Source #

The C type corresponding to a signed integer type.

primTypeToCType :: PrimType -> Type Source #

The C type corresponding to a primitive type. Integers are assumed to be unsigned.

primStorageType :: PrimType -> Type Source #

The C storage type for arrays of this primitive type.

primAPIType :: Signedness -> PrimType -> Type Source #

The C API corresponding to a primitive type. Integers are assumed to have the specified sign.

arrayName :: PrimType -> Signedness -> Int -> Text Source #

The name of exposed array type structs.

opaqueName :: Name -> Text Source #

The name of exposed opaque types.

isValidCName :: Text -> Bool Source #

Is this name a valid C identifier? If not, it should be escaped before being emitted into C.

escapeName :: Text -> Text Source #

If the provided text is a valid C identifier, then return it verbatim. Otherwise, escape it such that it becomes valid.

toStorage :: PrimType -> Exp -> Exp Source #

Convert from scalar to storage representation for the given type.

fromStorage :: PrimType -> Exp -> Exp Source #

Convert from storage to scalar representation for the given type.

cproduct :: [Exp] -> Exp Source #

Return an expression multiplying together the given expressions. If an empty list is given, the expression 1 is returned.

csum :: [Exp] -> Exp Source #

Return an expression summing the given expressions. If an empty list is given, the expression 0 is returned.

scalarToPrim :: Text -> (Signedness, PrimType) Source #

The PrimType (and sign) correspond to a human-readable scalar type name (e.g. f64). Beware: partial!

Primitive value operations

cScalarDefs :: Text Source #

Implementations of scalar operations.

Storing/restoring values in byte sequences

storageSize :: PrimType -> Int -> Exp -> Exp Source #

storageSize pt rank shape produces an expression giving size taken when storing this value in the binary value format. It is assumed that the shape is an array with rank dimensions.

storeValueHeader :: Signedness -> PrimType -> Int -> Exp -> Exp -> [Stm] Source #

Produce code for storing the header (everything besides the actual payload) for a value of this type.

loadValueHeader :: Signedness -> PrimType -> Int -> Exp -> Exp -> [Stm] Source #

Produce code for loading the header (everything besides the actual payload) for a value of this type.

Orphan instances

ToExp SubExp Source # 
Instance details

Methods

toExp :: SubExp -> SrcLoc -> Exp #

ToExp VName Source # 
Instance details

Methods

toExp :: VName -> SrcLoc -> Exp #

ToExp FloatValue Source # 
Instance details

Methods

toExp :: FloatValue -> SrcLoc -> Exp #

ToExp IntValue Source # 
Instance details

Methods

toExp :: IntValue -> SrcLoc -> Exp #

ToExp PrimValue Source # 
Instance details

Methods

toExp :: PrimValue -> SrcLoc -> Exp #

ToIdent Name Source # 
Instance details

Methods

toIdent :: Name -> SrcLoc -> Id #

ToIdent VName Source # 
Instance details

Methods

toIdent :: VName -> SrcLoc -> Id #

ToIdent Text Source # 
Instance details

Methods

toIdent :: Text -> SrcLoc -> Id #