ghc-9.2.1: The GHC API
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHC.CmmToLlvm.Base

Description

Base LLVM Code Generation module

Contains functions useful through out the code generator.

Synopsis

Documentation

type LiveGlobalRegs = [GlobalReg] Source #

Global registers live on proc entry

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

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

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

Top level LLVM Data (globals and type aliases)

type UnresLabel = CmmLit Source #

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.

supportedLlvmVersionLowerBound :: LlvmVersion Source #

The (inclusive) lower bound on the LLVM Version that is currently supported.

supportedLlvmVersionUpperBound :: LlvmVersion Source #

The (not-inclusive) upper bound bound on the LLVM Version that is currently supported.

data LlvmM a Source #

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

Instances

Instances details
Applicative LlvmM Source # 
Instance details

Defined in GHC.CmmToLlvm.Base

Methods

pure :: a -> LlvmM a Source #

(<*>) :: LlvmM (a -> b) -> LlvmM a -> LlvmM b Source #

liftA2 :: (a -> b -> c) -> LlvmM a -> LlvmM b -> LlvmM c Source #

(*>) :: LlvmM a -> LlvmM b -> LlvmM b Source #

(<*) :: LlvmM a -> LlvmM b -> LlvmM a Source #

Functor LlvmM Source # 
Instance details

Defined in GHC.CmmToLlvm.Base

Methods

fmap :: (a -> b) -> LlvmM a -> LlvmM b Source #

(<$) :: a -> LlvmM b -> LlvmM a Source #

Monad LlvmM Source # 
Instance details

Defined in GHC.CmmToLlvm.Base

Methods

(>>=) :: LlvmM a -> (a -> LlvmM b) -> LlvmM b Source #

(>>) :: LlvmM a -> LlvmM b -> LlvmM b Source #

return :: a -> LlvmM a Source #

HasDynFlags LlvmM Source # 
Instance details

Defined in GHC.CmmToLlvm.Base

MonadUnique LlvmM Source # 
Instance details

Defined in GHC.CmmToLlvm.Base

HasLogger LlvmM Source # 
Instance details

Defined in GHC.CmmToLlvm.Base

runLlvm :: Logger -> DynFlags -> LlvmVersion -> BufHandle -> LlvmM a -> IO a Source #

Get initial Llvm environment.

withClearVars :: LlvmM a -> LlvmM a Source #

Clear variables from the environment for a subcomputation

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

Lookup variables or functions in the environment.

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

Insert variables or functions into the environment.

markStackReg :: GlobalReg -> LlvmM () Source #

Set a register as allocated on the stack

checkStackReg :: GlobalReg -> LlvmM Bool Source #

Check whether a register is allocated on the stack

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

Lookup variables or functions in the environment.

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

Insert variables or functions into the environment.

getLlvmVer :: LlvmM LlvmVersion Source #

Get the LLVM version we are generating code for

dumpIfSetLlvm :: DumpFlag -> String -> DumpFormat -> SDoc -> LlvmM () Source #

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

renderLlvm :: SDoc -> LlvmM () Source #

Prints the given contents to the output handle

markUsedVar :: LlvmVar -> LlvmM () Source #

Marks a variable as "used"

getUsedVars :: LlvmM [LlvmVar] Source #

Return all variables marked as "used" so far

ghcInternalFunctions :: LlvmM () Source #

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.

getPlatform :: LlvmM Platform Source #

Get target platform

getLlvmOpts :: LlvmM LlvmOpts Source #

Get LLVM options

getMetaUniqueId :: LlvmM MetaId Source #

Allocate a new global unnamed metadata identifier

setUniqMeta :: Unique -> MetaId -> LlvmM () Source #

Sets metadata node for a given unique

getUniqMeta :: Unique -> LlvmM (Maybe MetaId) Source #

Gets metadata node for given unique

liftIO :: IO a -> LlvmM a Source #

Lifting of IO actions. Not exported, as we want to encapsulate IO.

cmmToLlvmType :: CmmType -> LlvmType Source #

Translate a basic CmmType to an LlvmType.

widthToLlvmFloat :: Width -> LlvmType Source #

Translate a Cmm Float Width to a LlvmType.

widthToLlvmInt :: Width -> LlvmType Source #

Translate a Cmm Bit Width to a LlvmType.

llvmFunTy :: LiveGlobalRegs -> LlvmM LlvmType Source #

Llvm Function type for Cmm function

llvmFunArgs :: Platform -> LiveGlobalRegs -> [LlvmVar] Source #

A Function's arguments

llvmStdFunAttrs :: [LlvmFuncAttr] Source #

Llvm standard fun attributes

llvmFunAlign :: Platform -> LMAlign Source #

Alignment to use for functions

llvmInfAlign :: Platform -> LMAlign Source #

Alignment to use for into tables

llvmPtrBits :: Platform -> Int Source #

Pointer width

tysToParams :: [LlvmType] -> [LlvmParameter] Source #

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

llvmFunSection :: LlvmOpts -> LMString -> LMSection Source #

Section to use for a function

padLiveArgs :: Platform -> LiveGlobalRegs -> LiveGlobalRegs Source #

Return a list of "padding" registers for LLVM function calls.

When we generate LLVM function signatures, we can't just make any register alive on function entry. Instead, we need to insert fake arguments of the same register class until we are sure that one of them is mapped to the register we want alive. E.g. to ensure that F5 is alive, we may need to insert fake arguments mapped to F1, F2, F3 and F4.

Invariant: Cmm FPR regs with number "n" maps to real registers with number "n" If the calling convention uses registers in a different order or if the invariant doesn't hold, this code probably won't be correct.

getGlobalPtr :: LMString -> LlvmM LlvmVar Source #

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]) Source #

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] Source #

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

llvmDefLabel :: LMString -> LMString Source #

Derive the definition label. It has an identified structure type.