Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
C code generator framework.
Synopsis
- data Operations op s = Operations {
- opsWriteScalar :: WriteScalar op s
- opsReadScalar :: ReadScalar op s
- opsAllocate :: Allocate op s
- opsDeallocate :: Deallocate op s
- opsCopy :: Copy op s
- opsMemoryType :: MemoryType op s
- opsCompiler :: OpCompiler op s
- opsError :: ErrorCompiler op s
- opsCall :: CallCompiler op s
- opsCopies :: Map (Space, Space) (DoCopy op s)
- opsFatMemory :: Bool
- opsCritical :: ([BlockItem], [BlockItem])
- data Publicness
- type OpCompiler op s = op -> CompilerM op s ()
- type ErrorCompiler op s = ErrorMsg Exp -> String -> CompilerM op s ()
- type CallCompiler op s = [VName] -> Name -> [Exp] -> CompilerM op s ()
- type PointerQuals = String -> [TypeQual]
- type MemoryType op s = SpaceId -> CompilerM op s Type
- type WriteScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> Exp -> CompilerM op s ()
- writeScalarPointerWithQuals :: PointerQuals -> WriteScalar op s
- type ReadScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> CompilerM op s Exp
- readScalarPointerWithQuals :: PointerQuals -> ReadScalar op s
- type Allocate op s = Exp -> Exp -> Exp -> SpaceId -> CompilerM op s ()
- type Deallocate op s = Exp -> Exp -> Exp -> SpaceId -> CompilerM op s ()
- data CopyBarrier
- type Copy op s = CopyBarrier -> Exp -> Exp -> Space -> Exp -> Exp -> Space -> Exp -> CompilerM op s ()
- type DoCopy op s = CopyBarrier -> PrimType -> [Count Elements Exp] -> Exp -> (Count Elements Exp, [Count Elements Exp]) -> Exp -> (Count Elements Exp, [Count Elements Exp]) -> CompilerM op s ()
- data CompilerM op s a
- data CompilerState s = CompilerState {
- compArrayTypes :: Map ArrayType Publicness
- compEarlyDecls :: DList Definition
- compNameSrc :: VNameSource
- compUserState :: s
- compHeaderDecls :: Map HeaderSection (DList Definition)
- compLibDecls :: DList Definition
- compCtxFields :: DList (Id, Type, Maybe Exp, Maybe (Stm, Stm))
- compClearItems :: DList BlockItem
- compDeclaredMem :: [(VName, Space)]
- compItems :: DList BlockItem
- data CompilerEnv op s = CompilerEnv {
- envOperations :: Operations op s
- envCachedMem :: Map Exp VName
- getUserState :: CompilerM op s s
- modifyUserState :: (s -> s) -> CompilerM op s ()
- generateProgramStruct :: CompilerM op s ()
- runCompilerM :: Operations op s -> VNameSource -> s -> CompilerM op s a -> (a, CompilerState s)
- inNewFunction :: CompilerM op s a -> CompilerM op s a
- cachingMemory :: Map VName Space -> ([BlockItem] -> [Stm] -> CompilerM op s a) -> CompilerM op s a
- volQuals :: Volatility -> [TypeQual]
- rawMem :: VName -> CompilerM op s Exp
- item :: BlockItem -> CompilerM op s ()
- items :: [BlockItem] -> CompilerM op s ()
- stm :: Stm -> CompilerM op s ()
- stms :: [Stm] -> CompilerM op s ()
- decl :: InitGroup -> CompilerM op s ()
- headerDecl :: HeaderSection -> Definition -> CompilerM op s ()
- publicDef :: Text -> HeaderSection -> (Text -> (Definition, Definition)) -> CompilerM op s Text
- publicDef_ :: Text -> HeaderSection -> (Text -> (Definition, Definition)) -> CompilerM op s ()
- onClear :: BlockItem -> CompilerM op s ()
- data HeaderSection
- libDecl :: Definition -> CompilerM op s ()
- earlyDecl :: Definition -> CompilerM op s ()
- publicName :: Text -> CompilerM op s Text
- contextField :: Id -> Type -> Maybe Exp -> CompilerM op s ()
- contextFieldDyn :: Id -> Type -> Stm -> Stm -> CompilerM op s ()
- memToCType :: VName -> Space -> CompilerM op s Type
- cacheMem :: ToExp a => a -> CompilerM op s (Maybe VName)
- fatMemory :: Space -> CompilerM op s Bool
- rawMemCType :: Space -> CompilerM op s Type
- freeRawMem :: (ToExp a, ToExp b, ToExp c) => a -> b -> Space -> c -> CompilerM op s ()
- allocRawMem :: (ToExp a, ToExp b, ToExp c) => a -> b -> Space -> c -> CompilerM op s ()
- fatMemType :: Space -> Type
- declAllocatedMem :: CompilerM op s [BlockItem]
- freeAllocatedMem :: CompilerM op s [BlockItem]
- collect :: CompilerM op s () -> CompilerM op s [BlockItem]
- collect' :: CompilerM op s a -> CompilerM op s (a, [BlockItem])
- contextType :: CompilerM op s Type
- configType :: CompilerM op s Type
- copyMemoryDefaultSpace :: Exp -> Exp -> Exp -> Exp -> Exp -> CompilerM op s ()
- derefPointer :: Exp -> Exp -> Type -> Exp
- setMem :: (ToExp a, ToExp b) => a -> b -> Space -> CompilerM op s ()
- allocMem :: (ToExp a, ToExp b) => a -> b -> Space -> Stm -> CompilerM op s ()
- unRefMem :: ToExp a => a -> Space -> CompilerM op s ()
- declMem :: VName -> Space -> CompilerM op s ()
- resetMem :: ToExp a => a -> Space -> CompilerM op s ()
- fatMemAlloc :: Space -> String
- fatMemSet :: Space -> String
- fatMemUnRef :: Space -> String
- criticalSection :: Operations op s -> [BlockItem] -> [BlockItem]
- module Futhark.CodeGen.Backends.SimpleRep
Pluggable compiler
data Operations op s Source #
Operations | |
|
data Publicness Source #
Instances
Show Publicness Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad showsPrec :: Int -> Publicness -> ShowS # show :: Publicness -> String # showList :: [Publicness] -> ShowS # | |
Eq Publicness Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad (==) :: Publicness -> Publicness -> Bool # (/=) :: Publicness -> Publicness -> Bool # | |
Ord Publicness Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad compare :: Publicness -> Publicness -> Ordering # (<) :: Publicness -> Publicness -> Bool # (<=) :: Publicness -> Publicness -> Bool # (>) :: Publicness -> Publicness -> Bool # (>=) :: Publicness -> Publicness -> Bool # max :: Publicness -> Publicness -> Publicness # min :: Publicness -> Publicness -> Publicness # |
type OpCompiler op s = op -> CompilerM op s () Source #
A substitute expression compiler, tried before the main compilation function.
type PointerQuals = String -> [TypeQual] Source #
The address space qualifiers for a pointer of the given type with the given annotation.
type MemoryType op s = SpaceId -> CompilerM op s Type Source #
The type of a memory block in the given memory space.
type WriteScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> Exp -> CompilerM op s () Source #
Write a scalar to the given memory block with the given element index and in the given memory space.
writeScalarPointerWithQuals :: PointerQuals -> WriteScalar op s Source #
type ReadScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> CompilerM op s Exp Source #
Read a scalar from the given memory block with the given element index and in the given memory space.
readScalarPointerWithQuals :: PointerQuals -> ReadScalar op s Source #
type Allocate op s = Exp -> Exp -> Exp -> SpaceId -> CompilerM op s () Source #
Allocate a memory block of the given size and with the given tag in the given memory space, saving a reference in the given variable name.
type Deallocate op s = Exp -> Exp -> Exp -> SpaceId -> CompilerM op s () Source #
De-allocate the given memory block, with the given tag, with the given size,, which is in the given memory space.
data CopyBarrier Source #
Whether a copying operation should implicitly function as a barrier regarding further operations on the source. This is a rather subtle detail and is mostly useful for letting some device/GPU copies be asynchronous (#1664).
CopyBarrier | |
CopyNoBarrier | Explicit context synchronisation should be done before the source or target is used. |
Instances
Show CopyBarrier Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad showsPrec :: Int -> CopyBarrier -> ShowS # show :: CopyBarrier -> String # showList :: [CopyBarrier] -> ShowS # | |
Eq CopyBarrier Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad (==) :: CopyBarrier -> CopyBarrier -> Bool # (/=) :: CopyBarrier -> CopyBarrier -> Bool # |
type Copy op s = CopyBarrier -> Exp -> Exp -> Space -> Exp -> Exp -> Space -> Exp -> CompilerM op s () Source #
Copy from one memory block to another.
type DoCopy op s = CopyBarrier -> PrimType -> [Count Elements Exp] -> Exp -> (Count Elements Exp, [Count Elements Exp]) -> Exp -> (Count Elements Exp, [Count Elements Exp]) -> CompilerM op s () Source #
Perform an Copy
. It is expected that these functions are
each specialised on which spaces they operate on, so that is not part of their arguments.
Monadic compiler interface
data CompilerM op s a Source #
Instances
data CompilerState s Source #
CompilerState | |
|
Instances
MonadState (CompilerState s) (CompilerM op s) Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad get :: CompilerM op s (CompilerState s) # put :: CompilerState s -> CompilerM op s () # state :: (CompilerState s -> (a, CompilerState s)) -> CompilerM op s a # |
data CompilerEnv op s Source #
CompilerEnv | |
|
Instances
MonadReader (CompilerEnv op s) (CompilerM op s) Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad ask :: CompilerM op s (CompilerEnv op s) # local :: (CompilerEnv op s -> CompilerEnv op s) -> CompilerM op s a -> CompilerM op s a # reader :: (CompilerEnv op s -> a) -> CompilerM op s a # |
getUserState :: CompilerM op s s Source #
modifyUserState :: (s -> s) -> CompilerM op s () Source #
generateProgramStruct :: CompilerM op s () Source #
runCompilerM :: Operations op s -> VNameSource -> s -> CompilerM op s a -> (a, CompilerState s) Source #
inNewFunction :: CompilerM op s a -> CompilerM op s a Source #
Used when we, inside an existing CompilerM
action, want to
generate code for a new function. Use this so that the compiler
understands that previously declared memory doesn't need to be
freed inside this action.
cachingMemory :: Map VName Space -> ([BlockItem] -> [Stm] -> CompilerM op s a) -> CompilerM op s a Source #
volQuals :: Volatility -> [TypeQual] Source #
headerDecl :: HeaderSection -> Definition -> CompilerM op s () Source #
publicDef :: Text -> HeaderSection -> (Text -> (Definition, Definition)) -> CompilerM op s Text Source #
Construct a publicly visible definition using the specified name as the template. The first returned definition is put in the header file, and the second is the implementation. Returns the public name.
publicDef_ :: Text -> HeaderSection -> (Text -> (Definition, Definition)) -> CompilerM op s () Source #
As publicDef
, but ignores the public name.
data HeaderSection Source #
In which part of the header file we put the declaration. This is to ensure that the header file remains structured and readable.
Instances
Eq HeaderSection Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad (==) :: HeaderSection -> HeaderSection -> Bool # (/=) :: HeaderSection -> HeaderSection -> Bool # | |
Ord HeaderSection Source # | |
Defined in Futhark.CodeGen.Backends.GenericC.Monad compare :: HeaderSection -> HeaderSection -> Ordering # (<) :: HeaderSection -> HeaderSection -> Bool # (<=) :: HeaderSection -> HeaderSection -> Bool # (>) :: HeaderSection -> HeaderSection -> Bool # (>=) :: HeaderSection -> HeaderSection -> Bool # max :: HeaderSection -> HeaderSection -> HeaderSection # min :: HeaderSection -> HeaderSection -> HeaderSection # |
libDecl :: Definition -> CompilerM op s () Source #
earlyDecl :: Definition -> CompilerM op s () Source #
fatMemType :: Space -> Type Source #
declAllocatedMem :: CompilerM op s [BlockItem] Source #
freeAllocatedMem :: CompilerM op s [BlockItem] Source #
contextType :: CompilerM op s Type Source #
The generated code must define a context struct with this name.
configType :: CompilerM op s Type Source #
The generated code must define a configuration struct with this name.
Building Blocks
fatMemAlloc :: Space -> String Source #
fatMemUnRef :: Space -> String Source #
criticalSection :: Operations op s -> [BlockItem] -> [BlockItem] Source #