LlvmCodeGen.Base

ghc-7.10.3: The GHC API

Safe Haskell | None
Language | Haskell2010

LlvmCodeGen.Base

Description

Base LLVM Code Generation module

Contains functions useful through out the code generator.

Synopsis

- type LlvmCmmDecl = GenCmmDecl [LlvmData] (Maybe CmmStatics) (ListGraph LlvmStatement)
- type LlvmBasicBlock = GenBasicBlock LlvmStatement
- type LiveGlobalRegs = [GlobalReg]
- type LlvmUnresData = (CLabel, Section, LlvmType, [UnresStatic])
- type LlvmData = ([LMGlobal], [LlvmType])
- type UnresLabel = CmmLit
- type UnresStatic = Either UnresLabel LlvmStatic
- type LlvmVersion = Int
- defaultLlvmVersion :: LlvmVersion
- minSupportLlvmVersion :: LlvmVersion
- maxSupportLlvmVersion :: LlvmVersion
- data LlvmM a
- runLlvm :: DynFlags -> LlvmVersion -> BufHandle -> UniqSupply -> LlvmM () -> IO ()
- liftStream :: Stream IO a x -> Stream LlvmM a x
- withClearVars :: LlvmM a -> LlvmM a
- varLookup :: Uniquable key => key -> LlvmM (Maybe LlvmType)
- varInsert :: Uniquable key => key -> LlvmType -> LlvmM ()
- markStackReg :: GlobalReg -> LlvmM ()
- checkStackReg :: GlobalReg -> LlvmM Bool
- funLookup :: Uniquable key => key -> LlvmM (Maybe LlvmType)
- funInsert :: Uniquable key => key -> LlvmType -> LlvmM ()
- getLlvmVer :: LlvmM LlvmVersion
- getDynFlags :: HasDynFlags m => m DynFlags
- getDynFlag :: (DynFlags -> a) -> LlvmM a
- getLlvmPlatform :: LlvmM Platform
- dumpIfSetLlvm :: DumpFlag -> String -> SDoc -> LlvmM ()
- renderLlvm :: SDoc -> LlvmM ()
- runUs :: UniqSM a -> LlvmM a
- markUsedVar :: LlvmVar -> LlvmM ()
- getUsedVars :: LlvmM [LlvmVar]
- ghcInternalFunctions :: LlvmM ()
- getMetaUniqueId :: LlvmM Int
- setUniqMeta :: Unique -> Int -> LlvmM ()
- getUniqMeta :: Unique -> LlvmM (Maybe Int)
- freshSectionId :: LlvmM Int
- cmmToLlvmType :: CmmType -> LlvmType
- widthToLlvmFloat :: Width -> LlvmType
- widthToLlvmInt :: Width -> LlvmType
- llvmFunTy :: LiveGlobalRegs -> LlvmM LlvmType
- llvmFunSig :: LiveGlobalRegs -> CLabel -> LlvmLinkageType -> LlvmM LlvmFunctionDecl
- llvmStdFunAttrs :: [LlvmFuncAttr]
- llvmFunAlign :: DynFlags -> LMAlign
- llvmInfAlign :: DynFlags -> LMAlign
- llvmPtrBits :: DynFlags -> Int
- mkLlvmFunc :: LiveGlobalRegs -> CLabel -> LlvmLinkageType -> LMSection -> LlvmBlocks -> LlvmM LlvmFunction
- tysToParams :: [LlvmType] -> [LlvmParameter]
- strCLabel_llvm :: CLabel -> LlvmM LMString
- strDisplayName_llvm :: CLabel -> LlvmM LMString
- strProcedureName_llvm :: CLabel -> LlvmM LMString
- getGlobalPtr :: LMString -> LlvmM LlvmVar
- generateExternDecls :: LlvmM ([LMGlobal], [LlvmType])
- aliasify :: LMGlobal -> LlvmM [LMGlobal]

# Documentation

type LlvmCmmDecl = GenCmmDecl [LlvmData] (Maybe CmmStatics) (ListGraph LlvmStatement)

type LlvmBasicBlock = GenBasicBlock LlvmStatement

type LiveGlobalRegs = [GlobalReg]

Global registers live on proc entry

type LlvmUnresData = (CLabel, Section, LlvmType, [UnresStatic])

Unresolved code. Of the form: (data label, data type, unresolved data)

type LlvmData = ([LMGlobal], [LlvmType])

Top level LLVM Data (globals and type aliases)

type UnresLabel = CmmLit

An unresolved Label.

Labels are unresolved when we haven't yet determined if they are defined in the module we are currently compiling, or an external one.

type UnresStatic = Either UnresLabel LlvmStatic

type LlvmVersion = Int

LLVM Version Number

defaultLlvmVersion :: LlvmVersion

The LLVM Version we assume if we don't know

minSupportLlvmVersion :: LlvmVersion

maxSupportLlvmVersion :: LlvmVersion

data LlvmM a

The Llvm monad. Wraps `LlvmEnv` state as well as the `IO` monad

Instances

Monad LlvmM |
Functor LlvmM |
Applicative LlvmM |
HasDynFlags LlvmM |

runLlvm :: DynFlags -> LlvmVersion -> BufHandle -> UniqSupply -> LlvmM () -> IO ()

Get initial Llvm environment.

liftStream :: Stream IO a x -> Stream LlvmM a x

Lift a stream into the LlvmM monad

withClearVars :: LlvmM a -> LlvmM a

Clear variables from the environment for a subcomputation

varLookup :: Uniquable key => key -> LlvmM (Maybe LlvmType)

Lookup variables or functions in the environment.

varInsert :: Uniquable key => key -> LlvmType -> LlvmM ()

Insert variables or functions into the environment.

markStackReg :: GlobalReg -> LlvmM ()

Set a register as allocated on the stack

checkStackReg :: GlobalReg -> LlvmM Bool

Check whether a register is allocated on the stack

funLookup :: Uniquable key => key -> LlvmM (Maybe LlvmType)

Lookup variables or functions in the environment.

funInsert :: Uniquable key => key -> LlvmType -> LlvmM ()

Insert variables or functions into the environment.

getLlvmVer :: LlvmM LlvmVersion

Get the LLVM version we are generating code for

getDynFlags :: HasDynFlags m => m DynFlags

getDynFlag :: (DynFlags -> a) -> LlvmM a

Get the platform we are generating code for

getLlvmPlatform :: LlvmM Platform

Get the platform we are generating code for

dumpIfSetLlvm :: DumpFlag -> String -> SDoc -> LlvmM ()

Dumps the document if the corresponding flag has been set by the user

renderLlvm :: SDoc -> LlvmM ()

Prints the given contents to the output handle

runUs :: UniqSM a -> LlvmM a

Run a `UniqSM` action with our unique supply

markUsedVar :: LlvmVar -> LlvmM ()

Marks a variable as "used"

getUsedVars :: LlvmM [LlvmVar]

Return all variables marked as "used" so far

ghcInternalFunctions :: LlvmM ()

Here we pre-initialise some functions that are used internally by GHC so as to make sure they have the most general type in the case that user code also uses these functions but with a different type than GHC internally. (Main offender is treating return type as `void` instead of 'void *'). Fixes trac #5486.

getMetaUniqueId :: LlvmM Int

Allocate a new global unnamed metadata identifier

setUniqMeta :: Unique -> Int -> LlvmM ()

Sets metadata node for a given unique

getUniqMeta :: Unique -> LlvmM (Maybe Int)

Gets metadata node for given unique

freshSectionId :: LlvmM Int

Returns a fresh section ID

cmmToLlvmType :: CmmType -> LlvmType

Translate a basic CmmType to an LlvmType.

widthToLlvmFloat :: Width -> LlvmType

Translate a Cmm Float Width to a LlvmType.

widthToLlvmInt :: Width -> LlvmType

Translate a Cmm Bit Width to a LlvmType.

llvmFunTy :: LiveGlobalRegs -> LlvmM LlvmType

Llvm Function type for Cmm function

llvmFunSig :: LiveGlobalRegs -> CLabel -> LlvmLinkageType -> LlvmM LlvmFunctionDecl

Llvm Function signature

llvmStdFunAttrs :: [LlvmFuncAttr]

Llvm standard fun attributes

llvmFunAlign :: DynFlags -> LMAlign

Alignment to use for functions

llvmInfAlign :: DynFlags -> LMAlign

Alignment to use for into tables

llvmPtrBits :: DynFlags -> Int

Pointer width

mkLlvmFunc :: LiveGlobalRegs -> CLabel -> LlvmLinkageType -> LMSection -> LlvmBlocks -> LlvmM LlvmFunction

Create a Haskell function in LLVM.

tysToParams :: [LlvmType] -> [LlvmParameter]

Convert a list of types to a list of function parameters (each with no parameter attributes)

strCLabel_llvm :: CLabel -> LlvmM LMString

Pretty print a `CLabel`.

strDisplayName_llvm :: CLabel -> LlvmM LMString

strProcedureName_llvm :: CLabel -> LlvmM LMString

getGlobalPtr :: LMString -> LlvmM LlvmVar

Create/get a pointer to a global value. Might return an alias if the value in question hasn't been defined yet. We especially make no guarantees on the type of the returned pointer.

generateExternDecls :: LlvmM ([LMGlobal], [LlvmType])

Generate definitions for aliases forward-referenced by `getGlobalPtr`.

Must be called at a point where we are sure that no new global definitions will be generated anymore!

aliasify :: LMGlobal -> LlvmM [LMGlobal]

Here we take a global variable definition, rename it with a `$def` suffix, and generate the appropriate alias.