HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Llvm

This module supplies bindings to generate Llvm IR from Haskell (http://www.llvm.org/docs/LangRef.html).

Note: this module is developed in a demand driven way. It is no complete LLVM binding library in Haskell, but enough to generate code for GHC.

This code is derived from code taken from the Essential Haskell Compiler (EHC) project.

  • 38 types
  • 41 values
  • Packageghc-9.10.3
  • Exports79
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceLlvm.hs

Modules, Functions and Blocks

12 declarations
datadata LlvmFunctionDecl
#

An LLVM Function

Constructors

Instances1Eq
datadata LlvmStatement
#

Llvm Statements

Constructors

  • Assignment LlvmVar LlvmExpression

    Assign an expression to a variable: * dest: Variable to assign to * source: Source expression

  • Fence Bool LlvmSyncOrdering

    Memory fence operation

  • Branch LlvmVar

    Always branch to the target label

  • BranchIf LlvmVar LlvmVar LlvmVar

    Branch to label targetTrue if cond is true otherwise to label targetFalse * cond: condition that will be tested, must be of type i1 * targetTrue: label to branch to if cond is true * targetFalse: label to branch to if cond is false

  • Comment [LMString]

    Comment Plain comment.

  • MkLabel LlvmBlockId

    Set a label on this position. * name: Identifier of this label, unique for this module

  • Store LlvmVar LlvmVar LMAlign [MetaAnnot]

    Store variable value in pointer ptr. If value is of type t then ptr must be of type t*. * value: Variable/Constant to store. * ptr: Location to store the value in

  • Switch LlvmVar LlvmVar [(LlvmVar, LlvmVar)]

    Multiway branch * scrutinee: Variable or constant which must be of integer type that is determines which arm is chosen. * def: The default label if there is no match in target. * target: A list of (value,label) where the value is an integer constant and label the corresponding label to jump to if the scrutinee matches the value.

  • Return (Maybe LlvmVar)

    Return a result. * result: The variable or constant to return

  • Unreachable

    An instruction for the optimizer that the code following is not reachable

  • Expr LlvmExpression

    Raise an expression to a statement (if don't want result or want to use Llvm unnamed values.

  • Nop

    A nop LLVM statement. Useful as its often more efficient to use this then to wrap LLvmStatement in a Just or [].

Instances1Eq
datadata LlvmExpression
#

Llvm Expressions

Constructors

  • Alloca LlvmType Int

    Allocate amount * sizeof(tp) bytes on the stack * tp: LlvmType to reserve room for * amount: The nr of tp's which must be allocated

  • LlvmOp LlvmMachOp LlvmVar LlvmVar

    Perform the machine operator op on the operands left and right * op: operator * left: left operand * right: right operand

  • Compare LlvmCmpOp LlvmVar LlvmVar

    Perform a compare operation on the operands left and right * op: operator * left: left operand * right: right operand

  • Extract LlvmVar LlvmVar

    Extract a scalar element from a vector * val: The vector * idx: The index of the scalar within the vector

  • ExtractV LlvmVar Int

    Extract a scalar element from a structure * val: The structure * idx: The index of the scalar within the structure Corresponds to "extractvalue" instruction.

  • Insert LlvmVar LlvmVar LlvmVar

    Insert a scalar element into a vector * val: The source vector * elt: The scalar to insert * index: The index at which to insert the scalar

  • Malloc LlvmType Int

    Allocate amount * sizeof(tp) bytes on the heap * tp: LlvmType to reserve room for * amount: The nr of tp's which must be allocated

  • Load LlvmVar LMAlign

    Load the value at location ptr

  • ALoad LlvmSyncOrdering SingleThreaded LlvmVar

    Atomic load of the value at location ptr

  • GetElemPtr Bool LlvmVar [LlvmVar]

    Navigate in a structure, selecting elements * inbound: Is the pointer inbounds? (computed pointer doesn't overflow) * ptr: Location of the structure * indexes: A list of indexes to select the correct value.

  • Cast LlvmCastOp LlvmVar LlvmType

    Cast the variable from to the to type. This is an abstraction of three cast operators in Llvm, inttoptr, ptrtoint and bitcast. * cast: Cast type * from: Variable to cast * to: type to cast to

  • AtomicRMW LlvmAtomicOp LlvmVar LlvmVar LlvmSyncOrdering

    Atomic read-modify-write operation * op: Atomic operation * addr: Address to modify * operand: Operand to operation * ordering: Ordering requirement

  • CmpXChg LlvmVar LlvmVar LlvmVar LlvmSyncOrdering LlvmSyncOrdering

    Compare-and-exchange operation * addr: Address to modify * old: Expected value * new: New value * suc_ord: Ordering required in success case * fail_ord: Ordering required in failure case, can be no stronger than suc_ord

    Result is an i1, true if store was successful.

  • Call LlvmCallType LlvmVar [LlvmVar] [LlvmFuncAttr]

    Call a function. The result is the value of the expression. * tailJumps: CallType to signal if the function should be tail called * fnptrval: An LLVM value containing a pointer to a function to be invoked. Can be indirect. Should be LMFunction type. * args: Concrete arguments for the parameters * attrs: A list of function attributes for the call. Only NoReturn, NoUnwind, ReadOnly and ReadNone are valid here.

  • CallM LlvmCallType LlvmVar [MetaExpr] [LlvmFuncAttr]

    Call a function as above but potentially taking metadata as arguments. * tailJumps: CallType to signal if the function should be tail called * fnptrval: An LLVM value containing a pointer to a function to be invoked. Can be indirect. Should be LMFunction type. * args: Arguments that may include metadata. * attrs: A list of function attributes for the call. Only NoReturn, NoUnwind, ReadOnly and ReadNone are valid here.

  • Phi LlvmType [(LlvmVar, LlvmVar)]

    Merge variables from different basic blocks which are predecessors of this basic block in a new variable of type tp. * tp: type of the merged variable, must match the types of the predecessor variables. * predecessors: A list of variables and the basic block that they originate from.

  • Asm LMString LMString LlvmType [LlvmVar] Bool Bool

    Inline assembly expression. Syntax is very similar to the style used by GCC. * assembly: Actual inline assembly code. * constraints: Operand constraints. * return ty: Return type of function. * vars: Any variables involved in the assembly code. * sideeffect: Does the expression have side effects not visible from the constraints list. * alignstack: Should the stack be conservatively aligned before this expression is executed.

  • MExpr [MetaAnnot] LlvmExpression

    A LLVM expression with metadata attached to it.

Instances1Eq
datadata LlvmParamAttr
#

LLVM Parameter Attributes.

Parameter attributes are used to communicate additional information about the result or parameters of a function

Constructors

  • ZeroExt

    This indicates to the code generator that the parameter or return value should be zero-extended to a 32-bit value by the caller (for a parameter) or the callee (for a return value).

  • SignExt

    This indicates to the code generator that the parameter or return value should be sign-extended to a 32-bit value by the caller (for a parameter) or the callee (for a return value).

  • InReg

    This indicates that this parameter or return value should be treated in a special target-dependent fashion during while emitting code for a function call or return (usually, by putting it in a register as opposed to memory).

  • ByVal

    This indicates that the pointer parameter should really be passed by value to the function.

  • SRet

    This indicates that the pointer parameter specifies the address of a structure that is the return value of the function in the source program.

  • NoAlias

    This indicates that the pointer does not alias any global or any other parameter.

  • NoCapture

    This indicates that the callee does not make any copies of the pointer that outlive the callee itself

  • Nest

    This indicates that the pointer parameter can be excised using the trampoline intrinsics.

Instances2Eq, Outputable

Atomic operations

1 declaration

Fence synchronization

1 declaration
datadata LlvmSyncOrdering
#

LLVM ordering types for synchronization purposes. (Introduced in LLVM 3.0). Please see the LLVM documentation for a better description.

Constructors

Instances2Eq, Show

Call Handling

5 declarations
datadata LlvmCallConvention
#

Different calling conventions a function can use.

Constructors

  • CC_Ccc

    The C calling convention. This calling convention (the default if no other calling convention is specified) matches the target C calling conventions. This calling convention supports varargs function calls and tolerates some mismatch in the declared prototype and implemented declaration of the function (as does normal C).

  • CC_Fastcc

    This calling convention attempts to make calls as fast as possible (e.g. by passing things in registers). This calling convention allows the target to use whatever tricks it wants to produce fast code for the target, without having to conform to an externally specified ABI (Application Binary Interface). Implementations of this convention should allow arbitrary tail call optimization to be supported. This calling convention does not support varargs and requires the prototype of al callees to exactly match the prototype of the function definition.

  • CC_Coldcc

    This calling convention attempts to make code in the caller as efficient as possible under the assumption that the call is not commonly executed. As such, these calls often preserve all registers so that the call does not break any live ranges in the caller side. This calling convention does not support varargs and requires the prototype of all callees to exactly match the prototype of the function definition.

  • CC_Ghc

    The GHC-specific registerised calling convention.

  • CC_Ncc Int

    Any calling convention may be specified by number, allowing target-specific calling conventions to be used. Target specific calling conventions start at 64.

  • CC_X86_Stdcc

    X86 Specific StdCall convention. LLVM includes a specific alias for it rather than just using CC_Ncc.

Instances2Eq, Outputable
datadata LlvmCallType
#

Different types to call a function.

Constructors

  • StdCall

    Normal call, allocate a new stack frame.

  • TailCall

    Tail call, perform the call in the current stack frame.

Instances2Eq, Show
datadata LlvmLinkageType
#

Linkage type of a symbol.

The description of the constructors is copied from the Llvm Assembly Language Reference Manual http://www.llvm.org/docs/LangRef.html#linkage, because they correspond to the Llvm linkage types.

Constructors

  • Internal

    Global values with internal linkage are only directly accessible by objects in the current module. In particular, linking code into a module with an internal global value may cause the internal to be renamed as necessary to avoid collisions. Because the symbol is internal to the module, all references can be updated. This corresponds to the notion of the static keyword in C.

  • LinkOnce

    Globals with linkonce linkage are merged with other globals of the same name when linkage occurs. This is typically used to implement inline functions, templates, or other code which must be generated in each translation unit that uses it. Unreferenced linkonce globals are allowed to be discarded.

  • Weak

    weak linkage is exactly the same as linkonce linkage, except that unreferenced weak globals may not be discarded. This is used for globals that may be emitted in multiple translation units, but that are not guaranteed to be emitted into every translation unit that uses them. One example of this are common globals in C, such as int X; at global scope.

  • Appending

    appending linkage may only be applied to global variables of pointer to array type. When two global variables with appending linkage are linked together, the two global arrays are appended together. This is the Llvm, typesafe, equivalent of having the system linker append together sections with identical names when .o files are linked.

  • ExternWeak

    The semantics of this linkage follow the ELF model: the symbol is weak until linked, if not linked, the symbol becomes null instead of being an undefined reference.

  • ExternallyVisible

    The symbol participates in linkage and can be used to resolve external symbol references.

  • External

    Alias for ExternallyVisible but with explicit textual form in LLVM assembly.

  • Private

    Symbol is private to the module and should not appear in the symbol table

Instances2Eq, Outputable
datadata LlvmFuncAttr
#

Llvm Function Attributes.

Function attributes are set to communicate additional information about a function. Function attributes are considered to be part of the function, not of the function type, so functions with different parameter attributes can have the same function type. Functions can have multiple attributes.

Descriptions taken from http://llvm.org/docs/LangRef.html#fnattrs

Constructors

  • AlwaysInline

    This attribute indicates that the inliner should attempt to inline this function into callers whenever possible, ignoring any active inlining size threshold for this caller.

  • InlineHint

    This attribute indicates that the source code contained a hint that inlining this function is desirable (such as the "inline" keyword in C/C++). It is just a hint; it imposes no requirements on the inliner.

  • NoInline

    This attribute indicates that the inliner should never inline this function in any situation. This attribute may not be used together with the alwaysinline attribute.

  • OptSize

    This attribute suggests that optimization passes and code generator passes make choices that keep the code size of this function low, and otherwise do optimizations specifically to reduce code size.

  • NoReturn

    This function attribute indicates that the function never returns normally. This produces undefined behavior at runtime if the function ever does dynamically return.

  • NoUnwind

    This function attribute indicates that the function never returns with an unwind or exceptional control flow. If the function does unwind, its runtime behavior is undefined.

  • ReadNone

    This attribute indicates that the function computes its result (or decides to unwind an exception) based strictly on its arguments, without dereferencing any pointer arguments or otherwise accessing any mutable state (e.g. memory, control registers, etc) visible to caller functions. It does not write through any pointer arguments (including byval arguments) and never changes any state visible to callers. This means that it cannot unwind exceptions by calling the C++ exception throwing methods, but could use the unwind instruction.

  • ReadOnly

    This attribute indicates that the function does not write through any pointer arguments (including byval arguments) or otherwise modify any state (e.g. memory, control registers, etc) visible to caller functions. It may dereference pointer arguments and read state that may be set in the caller. A readonly function always returns the same value (or unwinds an exception identically) when called with the same set of arguments and global state. It cannot unwind an exception by calling the C++ exception throwing methods, but may use the unwind instruction.

  • Ssp

    This attribute indicates that the function should emit a stack smashing protector. It is in the form of a "canary"—a random value placed on the stack before the local variables that's checked upon return from the function to see if it has been overwritten. A heuristic is used to determine if a function needs stack protectors or not.

    If a function that has an ssp attribute is inlined into a function that doesn't have an ssp attribute, then the resulting function will have an ssp attribute.

  • SspReq

    This attribute indicates that the function should always emit a stack smashing protector. This overrides the ssp function attribute.

    If a function that has an sspreq attribute is inlined into a function that doesn't have an sspreq attribute or which has an ssp attribute, then the resulting function will have an sspreq attribute.

  • NoRedZone

    This attribute indicates that the code generator should not use a red zone, even if the target-specific ABI normally permits it.

  • NoImplicitFloat

    This attributes disables implicit floating point instructions.

  • Naked

    This attribute disables prologue / epilogue emission for the function. This can have very system-specific consequences.

Instances2Eq, Outputable

Operations and Comparisons

3 declarations
datadata LlvmCmpOp
#

Llvm compare operations.

Constructors

Instances2Eq, Outputable
datadata LlvmMachOp
#

Llvm binary operators machine operations.

Constructors

Instances2Eq, Outputable
datadata LlvmCastOp
#

Llvm cast operations.

Constructors

Instances2Eq, Outputable

Variables and Type System

10 declarations
datadata LlvmStatic
#

Llvm Static Data.

These represent the possible global level variables and constants.

Constructors

datadata LlvmType
#

Llvm Types

Constructors

Instances2Eq, Outputable
datadata LMConst
#

Constructors

Instances1Eq
  • Eq LMConstDefined in ghc-9.10.3 · GHC.Llvm.Types

Some basic types

Metadata types

datadata MetaDecl
#

Metadata declarations. Metadata can only be declared in global scope.

Constructors

newtypenewtype MetaId
#

A reference to an un-named metadata node.

Constructors

Instances4Enum, Eq, Ord, Outputable
  • Enum MetaIdDefined in ghc-9.10.3 · GHC.Llvm.MetaData
  • Eq MetaIdDefined in ghc-9.10.3 · GHC.Llvm.MetaData
  • Ord MetaIdDefined in ghc-9.10.3 · GHC.Llvm.MetaData
  • Outputable MetaIdDefined in ghc-9.10.3 · GHC.Llvm.MetaData

Module flags

Operations on the type system.

Pretty Printing

18 declarations