llvm-tf-9.2.0.1: Bindings to the LLVM compiler toolkit using type families.

Safe HaskellNone
LanguageHaskell98

LLVM.Core

Contents

Description

The LLVM (Low Level Virtual Machine) is virtual machine at a machine code level. It supports both stand alone code generation and JITing. The Haskell llvm package is a (relatively) high level interface to the LLVM. The high level interface makes it easy to construct LLVM code. There is also an interface to the raw low level LLVM API as exposed by the LLVM C interface.

LLVM code is organized into modules (type Module). Each module contains a number of global variables and functions (type Function). Each functions has a number of basic blocks (type BasicBlock). Each basic block has a number instructions, where each instruction produces a value (type Value).

Unlike assembly code for a real processor the assembly code for LLVM is in SSA (Static Single Assignment) form. This means that each instruction generates a new bound variable which may not be assigned again. A consequence of this is that where control flow joins from several execution paths there has to be a phi pseudo instruction if you want different variables to be joined into one.

The definition of several of the LLVM entities (Module, Function, and BasicBlock) follow the same pattern. First the entity has to be created using newX (where X is one of Module, Function, or BasicBlock), then at some later point it has to given its definition using defineX. The reason for splitting the creation and definition is that you often need to be able to refer to an entity before giving it's body, e.g., in two mutually recursive functions. The the newX and defineX function can also be done at the same time by using createX. Furthermore, an explicit name can be given to an entity by the newNamedX function; the newX function just generates a fresh name.

Synopsis

Initialize

initializeNativeTarget :: IO () #

Initialize jitter to the native target. The operation is idempotent.

Modules

data Module #

Instances
Show Module 
Instance details

Defined in LLVM.Core.Util

data PassManager #

Instances
Show PassManager 
Instance details

Defined in LLVM.Core.Util

getFunctions :: Module -> IO [(String, Value)] #

data ModuleValue #

Instances
Show ModuleValue 
Instance details

Defined in LLVM.Core.CodeGen

castModuleValue :: IsType a => ModuleValue -> Maybe (Value a) #

Instructions

Types classification

Extra types

Values and constants

data Value a #

Instances
ValueCons Value 
Instance details

Defined in LLVM.Core.Instructions.Private

Methods

switchValueCons :: f ConstValue -> f Value -> f Value

ValueCons2 ConstValue Value 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type BinOpValue ConstValue Value :: Type -> Type

Methods

binop :: FFIConstBinOp -> FFIBinOp -> ConstValue a -> Value a -> CodeGenFunction r (BinOpValue ConstValue Value b)

ValueCons2 Value ConstValue 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type BinOpValue Value ConstValue :: Type -> Type

Methods

binop :: FFIConstBinOp -> FFIBinOp -> Value a -> ConstValue a -> CodeGenFunction r (BinOpValue Value ConstValue b)

ValueCons2 Value Value 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type BinOpValue Value Value :: Type -> Type

Methods

binop :: FFIConstBinOp -> FFIBinOp -> Value a -> Value a -> CodeGenFunction r (BinOpValue Value Value b)

Show (Value a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

showsPrec :: Int -> Value a -> ShowS #

show :: Value a -> String #

showList :: [Value a] -> ShowS #

i ~ Word => AllocArg (Value i) 
Instance details

Defined in LLVM.Core.Instructions

Methods

getAllocArg :: Value i -> Value Word

Ret (Value a) 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type Result (Value a) :: Type

Methods

ret' :: Value a -> CodeGenFunction (Result (Value a)) Terminate

IsIndexType i => IsIndexArg (Value i) 
Instance details

Defined in LLVM.Core.Instructions.Private

Methods

getArg :: Value i -> ValueRef

IsFirstClass a => Phi (Value a) Source # 
Instance details

Defined in LLVM.Util.Loop

type BinOpValue ConstValue Value 
Instance details

Defined in LLVM.Core.Instructions

type BinOpValue ConstValue Value = Value
type BinOpValue Value ConstValue 
Instance details

Defined in LLVM.Core.Instructions

type BinOpValue Value ConstValue = Value
type BinOpValue Value Value 
Instance details

Defined in LLVM.Core.Instructions

type BinOpValue Value Value = Value
type UnValue (Value a) 
Instance details

Defined in LLVM.Core.CodeGen

type UnValue (Value a) = a
type Result (Value a) 
Instance details

Defined in LLVM.Core.Instructions

type Result (Value a) = a

data ConstValue a #

Instances
ValueCons ConstValue 
Instance details

Defined in LLVM.Core.Instructions.Private

ValueCons2 ConstValue ConstValue 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type BinOpValue ConstValue ConstValue :: Type -> Type

Methods

binop :: FFIConstBinOp -> FFIBinOp -> ConstValue a -> ConstValue a -> CodeGenFunction r (BinOpValue ConstValue ConstValue b)

ValueCons2 ConstValue Value 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type BinOpValue ConstValue Value :: Type -> Type

Methods

binop :: FFIConstBinOp -> FFIBinOp -> ConstValue a -> Value a -> CodeGenFunction r (BinOpValue ConstValue Value b)

ValueCons2 Value ConstValue 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type BinOpValue Value ConstValue :: Type -> Type

Methods

binop :: FFIConstBinOp -> FFIBinOp -> Value a -> ConstValue a -> CodeGenFunction r (BinOpValue Value ConstValue b)

Show (ConstValue a) 
Instance details

Defined in LLVM.Core.CodeGen

i ~ Word => AllocArg (ConstValue i) 
Instance details

Defined in LLVM.Core.Instructions

IsIndexType i => IsIndexArg (ConstValue i) 
Instance details

Defined in LLVM.Core.Instructions.Private

Methods

getArg :: ConstValue i -> ValueRef

(IsConst a, IsConstStruct cs) => IsConstStruct (ConstValue a, cs) 
Instance details

Defined in LLVM.Core.CodeGen

Associated Types

type ConstStructOf (ConstValue a, cs) :: Type

Methods

constValueFieldsOf :: (ConstValue a, cs) -> [ValueRef]

type BinOpValue ConstValue ConstValue 
Instance details

Defined in LLVM.Core.Instructions

type BinOpValue ConstValue ConstValue = ConstValue
type BinOpValue ConstValue Value 
Instance details

Defined in LLVM.Core.Instructions

type BinOpValue ConstValue Value = Value
type BinOpValue Value ConstValue 
Instance details

Defined in LLVM.Core.Instructions

type BinOpValue Value ConstValue = Value
type ConstStructOf (ConstValue a, cs) 
Instance details

Defined in LLVM.Core.CodeGen

type ConstStructOf (ConstValue a, cs) = (a, ConstStructOf cs)

valueOf :: IsConst a => a -> Value a #

constOf :: IsConst a => a -> ConstValue a #

zero :: IsType a => ConstValue a #

allOnes :: IsInteger a => ConstValue a #

undef :: IsType a => ConstValue a #

class IsConst a #

Minimal complete definition

constOf

Instances
IsConst Bool 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Double 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Float 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Int 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: Int -> ConstValue Int #

IsConst Int8 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Int16 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Int32 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Int64 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Word 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Word8 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Word16 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Word32 
Instance details

Defined in LLVM.Core.CodeGen

IsConst Word64 
Instance details

Defined in LLVM.Core.CodeGen

IsConst (StablePtr a) 
Instance details

Defined in LLVM.Core.CodeGen

IsConst (Ptr a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: Ptr a -> ConstValue (Ptr a) #

IsFunction a => IsConst (FunPtr a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: FunPtr a -> ConstValue (FunPtr a) #

Positive n => IsConst (IntN n) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: IntN n -> ConstValue (IntN n) #

IsConstFields a => IsConst (PackedStruct a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: PackedStruct a -> ConstValue (PackedStruct a) #

IsType a => IsConst (Ptr a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: Ptr a -> ConstValue (Ptr a) #

IsConstFields a => IsConst (Struct a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: Struct a -> ConstValue (Struct a) #

Positive n => IsConst (WordN n) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: WordN n -> ConstValue (WordN n) #

(IsConst a, IsSized a, Natural n) => IsConst (Array n a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: Array n a -> ConstValue (Array n a) #

(IsPrimitive a, IsConst a, Positive n) => IsConst (Vector n a) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constOf :: Vector n a -> ConstValue (Vector n a) #

class IsConstFields a #

Minimal complete definition

constFieldsOf

Instances
IsConstFields () 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constFieldsOf :: () -> [ValueRef]

(IsConst a, IsConstFields as) => IsConstFields (a, as) 
Instance details

Defined in LLVM.Core.CodeGen

Methods

constFieldsOf :: (a, as) -> [ValueRef]

withString :: String -> (forall n. Natural n => Global (Array n Word8) -> CodeGenModule a) -> CodeGenModule a #

withStringNul :: String -> (forall n. Natural n => Global (Array n Word8) -> CodeGenModule a) -> CodeGenModule a #

constVector :: (Positive n, ToUnary n ~ u, Length (FixedList u) ~ u) => FixedList u (ConstValue a) -> ConstValue (Vector n a) #

constArray :: (IsSized a, Natural n) => [ConstValue a] -> ConstValue (Array n a) #

constCyclicVector :: Positive n => T [] (ConstValue a) -> ConstValue (Vector n a) #

constCyclicArray :: (IsSized a, Natural n) => T [] (ConstValue a) -> ConstValue (Vector n a) #

constStruct :: IsConstStruct c => c -> ConstValue (Struct (ConstStructOf c)) #

constPackedStruct :: IsConstStruct c => c -> ConstValue (PackedStruct (ConstStructOf c)) #

toVector :: MkVector n => Tuple n a -> Vector n a #

fromVector :: MkVector n => Vector n a -> Tuple n a #

vector :: Positive n => FixedList (ToUnary n) a -> Vector n a #

cyclicVector :: Positive n => T [] a -> Vector n a #

consVector :: (ConsVector f, ResultSize f ~ n, NumberOfArguments f ~ u, u ~ ToUnary n, FromUnary u ~ n, Natural n) => f #

Code generation

data CodeGenFunction r a #

Instances
(r ~ r', Value a ~ a') => CallArgs r (IO a) (CodeGenFunction r' a') 
Instance details

Defined in LLVM.Core.Instructions

Associated Types

type CalledFunction (CodeGenFunction r' a') :: Type

type CallerFunction r (IO a) :: Type

Methods

doCall :: Call (IO a) -> CodeGenFunction r' a'

Value a ~ b => ToArithFunction r (IO a) (CodeGenFunction r b) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Associated Types

type TFunA (CodeGenFunction r b) :: Type

type TFunB r (IO a) :: Type

Methods

toArithFunction' :: CodeGenFunction r (Call (IO a)) -> CodeGenFunction r b

(r ~ ra, r ~ rb, a ~ b) => ArithFunction r (CodeGenFunction ra a) (CodeGenFunction rb b) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Associated Types

type FunA r (CodeGenFunction rb b) :: Type

type FunB (CodeGenFunction ra a) :: Type

(Ret z, Result z ~ r, r ~ ra, r ~ rb, z ~ a, unit ~ ()) => Return z (CodeGenFunction ra a) (CodeGenFunction rb unit) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Associated Types

type RetA z (CodeGenFunction rb unit) :: Type

type RetB (CodeGenFunction ra a) :: Type

Methods

addRet :: CodeGenFunction ra a -> CodeGenFunction rb unit

Monad (CodeGenFunction r) 
Instance details

Defined in LLVM.Core.CodeGenMonad

Functor (CodeGenFunction r) 
Instance details

Defined in LLVM.Core.CodeGenMonad

Methods

fmap :: (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b #

(<$) :: a -> CodeGenFunction r b -> CodeGenFunction r a #

Applicative (CodeGenFunction r) 
Instance details

Defined in LLVM.Core.CodeGenMonad

MonadIO (CodeGenFunction r) 
Instance details

Defined in LLVM.Core.CodeGenMonad

Methods

liftIO :: IO a -> CodeGenFunction r a #

(IsArithmetic a, CmpRet a, Num a, IsConst a, Value a ~ av) => Enum (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Eq (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Methods

(==) :: CodeGenFunction r av -> CodeGenFunction r av -> Bool #

(/=) :: CodeGenFunction r av -> CodeGenFunction r av -> Bool #

(CmpRet a, CallIntrinsic a, Floating a, IsConst a, IsFloating a, Value a ~ av) => Floating (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

(CmpRet a, Fractional a, IsConst a, IsFloating a, Value a ~ av) => Fractional (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

(CmpRet a, Num a, IsConst a, IsInteger a, Value a ~ av) => Integral (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

(IsArithmetic a, CmpRet a, Num a, IsConst a, Value a ~ av) => Num (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Ord (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

(IsArithmetic a, CmpRet a, Num a, IsConst a, Value a ~ av) => Real (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

(CmpRet a, CallIntrinsic a, RealFloat a, IsConst a, IsFloating a, Value a ~ av) => RealFloat (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

(CmpRet a, Fractional a, IsConst a, IsFloating a, Value a ~ av) => RealFrac (CodeGenFunction r av) Source # 
Instance details

Defined in LLVM.Util.Arithmetic

Methods

properFraction :: Integral b => CodeGenFunction r av -> (b, CodeGenFunction r av) #

truncate :: Integral b => CodeGenFunction r av -> b #

round :: Integral b => CodeGenFunction r av -> b #

ceiling :: Integral b => CodeGenFunction r av -> b #

floor :: Integral b => CodeGenFunction r av -> b #

type CodeResult (CodeGenFunction r a) 
Instance details

Defined in LLVM.Core.CodeGen

type CodeResult (CodeGenFunction r a) = r
type CodeValue (CodeGenFunction r a) 
Instance details

Defined in LLVM.Core.CodeGen

type CodeValue (CodeGenFunction r a) = a
type CalledFunction (CodeGenFunction r' a') 
Instance details

Defined in LLVM.Core.Instructions

type CalledFunction (CodeGenFunction r' a') = IO (UnValue a')

data CodeGenModule a #

Instances
Monad CodeGenModule 
Instance details

Defined in LLVM.Core.CodeGenMonad

Functor CodeGenModule 
Instance details

Defined in LLVM.Core.CodeGenMonad

Methods

fmap :: (a -> b) -> CodeGenModule a -> CodeGenModule b #

(<$) :: a -> CodeGenModule b -> CodeGenModule a #

Applicative CodeGenModule 
Instance details

Defined in LLVM.Core.CodeGenMonad

MonadIO CodeGenModule 
Instance details

Defined in LLVM.Core.CodeGenMonad

Methods

liftIO :: IO a -> CodeGenModule a #

Functions

type Function a = Value (FunPtr a) #

newFunction :: IsFunction a => Linkage -> CodeGenModule (Function a) #

newNamedFunction :: IsFunction a => Linkage -> String -> CodeGenModule (Function a) #

defineFunction :: FunctionArgs f => Function f -> FunctionCodeGen f -> CodeGenModule () #

createFunction :: FunctionArgs f => Linkage -> FunctionCodeGen f -> CodeGenModule (Function f) #

createNamedFunction :: FunctionArgs f => Linkage -> String -> FunctionCodeGen f -> CodeGenModule (Function f) #

functionParameter :: Natural i => Function f -> Proxy i -> Value (FunctionParameter f i) #

getParams :: Value -> IO [(String, Value)] #

Global variable creation

type Global a = Value (Ptr a) #

newGlobal :: IsType a => Bool -> Linkage -> TGlobal a #

newNamedGlobal :: IsType a => Bool -> Linkage -> String -> TGlobal a #

createGlobal :: IsType a => Bool -> Linkage -> ConstValue a -> TGlobal a #

createNamedGlobal :: IsType a => Bool -> Linkage -> String -> ConstValue a -> TGlobal a #

externFunction :: IsFunction a => String -> CodeGenFunction r (Function a) #

staticFunction :: IsFunction f => FunPtr f -> CodeGenFunction r (Function f) #

staticNamedFunction :: IsFunction f => String -> FunPtr f -> CodeGenFunction r (Function f) #

externGlobal :: IsType a => Bool -> String -> CodeGenFunction r (Global a) #

staticGlobal :: IsType a => Bool -> Ptr a -> CodeGenFunction r (Global a) #

Globals

data Linkage #

An enumeration for the kinds of linkage for global values.

Constructors

ExternalLinkage

Externally visible function

AvailableExternallyLinkage 
LinkOnceAnyLinkage

Keep one copy of function when linking (inline)

LinkOnceODRLinkage

Same, but only replaced by something equivalent.

LinkOnceODRAutoHideLinkage

Like LinkOnceODR, but possibly hidden.

WeakAnyLinkage

Keep one copy of named function when linking (weak)

WeakODRLinkage

Same, but only replaced by something equivalent.

AppendingLinkage

Special purpose, only applies to global arrays

InternalLinkage

Rename collisions when linking (static functions)

PrivateLinkage

Like Internal, but omit from symbol table

DLLImportLinkage

Function to be imported from DLL

DLLExportLinkage

Function to be accessible from DLL

ExternalWeakLinkage

ExternalWeak linkage description

GhostLinkage

Stand-in functions for streaming fns from BC files

CommonLinkage

Tentative definitions

LinkerPrivateLinkage

Like Private, but linker removes.

LinkerPrivateWeakLinkage

Like LinkerPrivate, but is weak.

Instances
Enum Linkage 
Instance details

Defined in LLVM.FFI.Core

Eq Linkage 
Instance details

Defined in LLVM.FFI.Core

Methods

(==) :: Linkage -> Linkage -> Bool #

(/=) :: Linkage -> Linkage -> Bool #

Ord Linkage 
Instance details

Defined in LLVM.FFI.Core

Show Linkage 
Instance details

Defined in LLVM.FFI.Core

Basic blocks

data BasicBlock #

Instances
Show BasicBlock 
Instance details

Defined in LLVM.Core.CodeGen

getBasicBlocks :: Value -> IO [(String, BasicBlock)] #

getInstructions :: BasicBlock -> IO [(String, Value)] #

getOperands :: Value -> IO [(String, Value)] #

hasUsers :: Value -> IO Bool #

getUsers :: [Use] -> IO [(String, Value)] #

getUses :: Value -> IO [Use] #

getUser :: Use -> IO Value #

isChildOf :: BasicBlock -> Value -> IO Bool #

getDep :: Use -> IO (String, String) #

Misc

newtype AttributeIndex #

Constructors

AttributeIndex Word32 

castVarArgs :: CastVarArgs a b => Function a -> Function b Source #

Convert a varargs function to a regular function.

Debugging

dumpValue :: Value a -> IO () Source #

Print a value.

dumpType :: Value a -> IO () Source #

Print a type.

getValueName :: Value a -> IO String Source #

Get the name of a Value.

annotateValueList :: [Value] -> IO [(String, Value)] #