Safe Haskell | None |
---|---|
Language | Haskell98 |
- Initialize
- Modules
- Instructions
- ADT representation of IR
- Terminator instructions
- Arithmetic binary operations
- Logical binary operations
- Vector operations
- Aggregate operation
- Memory access
- Conversions
- Comparison
- Other
- Classes and types
- Types classification
- Type classifier
- Extra types
- Values and constants
- Code generation
- Functions
- Global variable creation
- Globals
- Basic blocks
- Misc
- Debugging
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.
- initializeNativeTarget :: IO ()
- data Module
- newModule :: IO Module
- newNamedModule :: String -> IO Module
- defineModule :: Module -> CodeGenModule a -> IO a
- destroyModule :: Module -> IO ()
- createModule :: CodeGenModule a -> IO a
- data ModuleProvider
- createModuleProviderForExistingModule :: Module -> IO ModuleProvider
- data PassManager
- createPassManager :: IO PassManager
- createFunctionPassManager :: ModuleProvider -> IO PassManager
- writeBitcodeToFile :: String -> Module -> IO ()
- readBitcodeFromFile :: String -> IO Module
- getModuleValues :: Module -> IO [(String, ModuleValue)]
- getFunctions :: Module -> IO [(String, Value)]
- getGlobalVariables :: Module -> IO [(String, Value)]
- data ModuleValue
- castModuleValue :: forall a. IsType a => ModuleValue -> Maybe (Value a)
- data BinOpDesc
- data InstrDesc
- = IDRet TypeDesc ArgDesc
- | IDRetVoid
- | IDBrCond ArgDesc ArgDesc ArgDesc
- | IDBrUncond ArgDesc
- | IDSwitch [(ArgDesc, ArgDesc)]
- | IDIndirectBr
- | IDInvoke
- | IDUnwind
- | IDUnreachable
- | IDBinOp BinOpDesc TypeDesc ArgDesc ArgDesc
- | IDAlloca TypeDesc Int Int
- | IDLoad TypeDesc ArgDesc
- | IDStore TypeDesc ArgDesc ArgDesc
- | IDGetElementPtr TypeDesc [ArgDesc]
- | IDTrunc TypeDesc TypeDesc ArgDesc
- | IDZExt TypeDesc TypeDesc ArgDesc
- | IDSExt TypeDesc TypeDesc ArgDesc
- | IDFPtoUI TypeDesc TypeDesc ArgDesc
- | IDFPtoSI TypeDesc TypeDesc ArgDesc
- | IDUItoFP TypeDesc TypeDesc ArgDesc
- | IDSItoFP TypeDesc TypeDesc ArgDesc
- | IDFPTrunc TypeDesc TypeDesc ArgDesc
- | IDFPExt TypeDesc TypeDesc ArgDesc
- | IDPtrToInt TypeDesc TypeDesc ArgDesc
- | IDIntToPtr TypeDesc TypeDesc ArgDesc
- | IDBitcast TypeDesc TypeDesc ArgDesc
- | IDICmp IntPredicate ArgDesc ArgDesc
- | IDFCmp FPPredicate ArgDesc ArgDesc
- | IDPhi TypeDesc [(ArgDesc, ArgDesc)]
- | IDCall TypeDesc ArgDesc [ArgDesc]
- | IDSelect TypeDesc ArgDesc ArgDesc
- | IDUserOp1
- | IDUserOp2
- | IDVAArg
- | IDExtractElement
- | IDInsertElement
- | IDShuffleVector
- | IDExtractValue
- | IDInsertValue
- | IDInvalidOp
- data ArgDesc
- getInstrDesc :: ValueRef -> IO (String, InstrDesc)
- ret :: Ret a r => a -> CodeGenFunction r Terminate
- condBr :: Value Bool -> BasicBlock -> BasicBlock -> CodeGenFunction r Terminate
- br :: BasicBlock -> CodeGenFunction r Terminate
- switch :: IsInteger a => Value a -> BasicBlock -> [(ConstValue a, BasicBlock)] -> CodeGenFunction r Terminate
- invoke :: CallArgs f g r => BasicBlock -> BasicBlock -> Function f -> g
- invokeWithConv :: CallArgs f g r => CallingConvention -> BasicBlock -> BasicBlock -> Function f -> g
- invokeFromFunction :: BasicBlock -> BasicBlock -> Function f -> Call f
- invokeWithConvFromFunction :: CallingConvention -> BasicBlock -> BasicBlock -> Function f -> Call f
- unreachable :: CodeGenFunction r Terminate
- add :: (IsArithmetic c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- sub :: (IsArithmetic c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- mul :: (IsArithmetic c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- neg :: (IsArithmetic b, AUnOp a, a ~ v b) => a -> CodeGenFunction r a
- iadd :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- isub :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- imul :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- ineg :: (IsInteger b, AUnOp a, a ~ v b) => a -> CodeGenFunction r a
- fadd :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- fsub :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- fmul :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- fneg :: (IsFloating b, AUnOp a, a ~ v b) => a -> CodeGenFunction r a
- idiv :: forall a b c r v. (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- irem :: forall a b c r v. (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- udiv :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- sdiv :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- fdiv :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- urem :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- srem :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- frem :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- shl :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- lshr :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- ashr :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- and :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- or :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- xor :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c)
- inv :: (IsInteger b, AUnOp a, a ~ v b) => a -> CodeGenFunction r a
- extractelement :: Positive n => Value (Vector n a) -> Value Word32 -> CodeGenFunction r (Value a)
- insertelement :: Positive n => Value (Vector n a) -> Value a -> Value Word32 -> CodeGenFunction r (Value (Vector n a))
- shufflevector :: (Positive n, Positive m) => Value (Vector n a) -> Value (Vector n a) -> ConstValue (Vector m Word32) -> CodeGenFunction r (Value (Vector m a))
- extractvalue :: forall r agg i. GetValue agg i => Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
- insertvalue :: forall r agg i. GetValue agg i => Value agg -> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
- malloc :: forall a r. IsSized a => CodeGenFunction r (Value (Ptr a))
- arrayMalloc :: forall a r s. (IsSized a, AllocArg s) => s -> CodeGenFunction r (Value (Ptr a))
- alloca :: forall a r. IsSized a => CodeGenFunction r (Value (Ptr a))
- arrayAlloca :: forall a r s. (IsSized a, AllocArg s) => s -> CodeGenFunction r (Value (Ptr a))
- free :: IsType a => Value (Ptr a) -> CodeGenFunction r ()
- load :: Value (Ptr a) -> CodeGenFunction r (Value a)
- store :: Value a -> Value (Ptr a) -> CodeGenFunction r ()
- getElementPtr :: forall a o i r. (GetElementPtr o i, IsIndexArg a) => Value (Ptr o) -> (a, i) -> CodeGenFunction r (Value (Ptr (ElementPtrType o i)))
- getElementPtr0 :: GetElementPtr o i => Value (Ptr o) -> i -> CodeGenFunction r (Value (Ptr (ElementPtrType o i)))
- trunc :: (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => Value a -> CodeGenFunction r (Value b)
- zext :: (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b)
- sext :: (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b)
- ext :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, Signed a ~ Signed b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b)
- zadapt :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- sadapt :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- adapt :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, Signed a ~ Signed b) => Value a -> CodeGenFunction r (Value b)
- fptrunc :: (IsFloating a, IsFloating b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => Value a -> CodeGenFunction r (Value b)
- fpext :: (IsFloating a, IsFloating b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b)
- fptoui :: (IsFloating a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- fptosi :: (IsFloating a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- fptoint :: forall r a b. (IsFloating a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- uitofp :: (IsInteger a, IsFloating b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- sitofp :: (IsInteger a, IsFloating b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- inttofp :: forall r a b. (IsInteger a, IsFloating b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b)
- ptrtoint :: (IsInteger b, IsPrimitive b) => Value (Ptr a) -> CodeGenFunction r (Value b)
- inttoptr :: (IsInteger a, IsType b) => Value a -> CodeGenFunction r (Value (Ptr b))
- bitcast :: (IsFirstClass a, IsFirstClass b, IsSized a, IsSized b, SizeOf a ~ SizeOf b) => Value a -> CodeGenFunction r (Value b)
- bitcastElements :: (Positive n, IsPrimitive a, IsPrimitive b, IsSized a, IsSized b, SizeOf a ~ SizeOf b) => Value (Vector n a) -> CodeGenFunction r (Value (Vector n b))
- data CmpPredicate
- data IntPredicate
- data FPPredicate
- class CmpRet (CmpType a b) => CmpOp a b
- class CmpRet c where
- type CmpValueResult a b = CmpValue a b (CmpResult (CmpType a b))
- cmp :: forall a b r. CmpOp a b => CmpPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b)
- pcmp :: (CmpOp a b, Ptr c ~ CmpType a b) => IntPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b)
- icmp :: (IsIntegerOrPointer c, CmpOp a b, c ~ CmpType a b) => IntPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b)
- fcmp :: (IsFloating c, CmpOp a b, c ~ CmpType a b) => FPPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b)
- select :: (IsFirstClass a, CmpRet a) => Value (CmpResult a) -> Value a -> Value a -> CodeGenFunction r (Value a)
- phi :: forall a r. IsFirstClass a => [(Value a, BasicBlock)] -> CodeGenFunction r (Value a)
- addPhiInputs :: forall a r. IsFirstClass a => Value a -> [(Value a, BasicBlock)] -> CodeGenFunction r ()
- call :: CallArgs f g r => Function f -> g
- callWithConv :: CallArgs f g r => CallingConvention -> Function f -> g
- callFromFunction :: Function a -> Call a
- callWithConvFromFunction :: CallingConvention -> Function f -> Call f
- data Call a
- applyCall :: Call (a -> b) -> Value a -> Call b
- runCall :: Call (IO a) -> CodeGenFunction r (Value a)
- type Terminate = ()
- class Ret a r
- class (f ~ CalledFunction g, r ~ CallerResult g, g ~ CallerFunction f r) => CallArgs f g r
- class AUnOp a
- class ABinOp a b where
- type ABinOpResult a b :: *
- class IsConst a
- class IsFunction f => FunctionArgs f where
- type FunctionCodeGen f :: *
- type FunctionResult f :: *
- class AllocArg a
- class GetElementPtr optr ixs where
- type ElementPtrType optr ixs :: *
- class IsIndexArg a
- class GetValue agg ix where
- class GetField as i where
- class IsType a where
- class Integer n => Natural n
- class Natural n => Positive n
- class IsFirstClass a => IsArithmetic a where
- data ArithmeticType a
- class (IsArithmetic a, IsIntegerOrPointer a) => IsInteger a where
- class IsIntegerOrPointer a
- class IsArithmetic a => IsFloating a
- class (IsType a, NumberOfElements a ~ D1) => IsPrimitive a
- class IsType a => IsFirstClass a
- class (IsType a, Natural (SizeOf a)) => IsSized a where
- sizeOf :: TypeDesc -> Integer
- class IsType a => IsFunction a
- class IsType a => IsScalarOrVector a where
- type NumberOfElements a :: *
- class StructFields as
- type UnknownSize = D99
- type (:&) a as = (a, as)
- (&) :: a -> as -> a :& as
- data TypeDesc
- isFloating :: IsArithmetic a => Proxy a -> Bool
- isSigned :: IsInteger a => Proxy a -> Bool
- typeRef :: IsType a => Proxy a -> IO TypeRef
- unsafeTypeRef :: IsType a => Proxy a -> TypeRef
- typeName :: IsType a => Proxy a -> String
- intrinsicTypeName :: IsType a => Proxy a -> String
- typeDesc2 :: TypeRef -> IO TypeDesc
- data VarArgs a
- class CastVarArgs a b
- newtype IntN n = IntN Integer
- newtype WordN n = WordN Integer
- newtype FP128 = FP128 Rational
- newtype Array n a = Array [a]
- newtype Vector n a = Vector (FixedList (ToUnary n) a)
- data Label
- newtype Struct a = Struct a
- newtype PackedStruct a = PackedStruct a
- type FixedList n = List n
- data Value a
- data ConstValue a
- valueOf :: IsConst a => a -> Value a
- constOf :: IsConst a => a -> ConstValue a
- value :: ConstValue a -> Value a
- zero :: forall a. IsType a => ConstValue a
- allOnes :: forall a. IsInteger a => ConstValue a
- undef :: forall a. IsType a => ConstValue a
- createString :: String -> TGlobal (Array n Word8)
- createStringNul :: String -> TGlobal (Array n Word8)
- 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 :: forall a n u. (Positive n, ToUnary n ~ u, Length (FixedList u) ~ u) => FixedList u (ConstValue a) -> ConstValue (Vector n a)
- constArray :: forall a n. (IsSized a, Natural n) => [ConstValue a] -> ConstValue (Array n a)
- constCyclicVector :: forall a n. Positive n => T [] (ConstValue a) -> ConstValue (Vector n a)
- constCyclicArray :: forall a n. (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 a => Tuple n a -> Vector n a
- fromVector :: MkVector n a => Vector n a -> Tuple n a
- vector :: Positive n => FixedList (ToUnary n) a -> Vector n a
- cyclicVector :: Positive n => T [] a -> Vector n a
- data CodeGenFunction r a
- data CodeGenModule a
- type Function a = Value (FunPtr a)
- newFunction :: forall a. IsFunction a => Linkage -> CodeGenModule (Function a)
- newNamedFunction :: forall a. IsFunction a => Linkage -> String -> CodeGenModule (Function a)
- defineFunction :: forall f. 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)
- setFuncCallConv :: Function a -> CallingConvention -> CodeGenModule ()
- type TFunction a = CodeGenModule (Function a)
- liftCodeGenModule :: CodeGenModule a -> CodeGenFunction r a
- getParams :: Value -> IO [(String, Value)]
- type Global a = Value (Ptr a)
- newGlobal :: forall a. IsType a => Bool -> Linkage -> TGlobal a
- newNamedGlobal :: forall a. IsType a => Bool -> Linkage -> String -> TGlobal a
- defineGlobal :: Global a -> ConstValue a -> CodeGenModule ()
- createGlobal :: IsType a => Bool -> Linkage -> ConstValue a -> TGlobal a
- createNamedGlobal :: IsType a => Bool -> Linkage -> String -> ConstValue a -> TGlobal a
- externFunction :: forall a r. IsFunction a => String -> CodeGenFunction r (Function a)
- staticFunction :: forall f r. IsFunction f => FunPtr f -> CodeGenFunction r (Function f)
- externGlobal :: forall a r. IsType a => Bool -> String -> CodeGenFunction r (Global a)
- staticGlobal :: forall a r. IsType a => Bool -> Ptr a -> CodeGenFunction r (Global a)
- data GlobalMappings
- getGlobalMappings :: CodeGenModule GlobalMappings
- type TGlobal a = CodeGenModule (Global a)
- data Linkage :: *
- data BasicBlock
- newBasicBlock :: CodeGenFunction r BasicBlock
- newNamedBasicBlock :: String -> CodeGenFunction r BasicBlock
- defineBasicBlock :: BasicBlock -> CodeGenFunction r ()
- createBasicBlock :: CodeGenFunction r BasicBlock
- getCurrentBasicBlock :: CodeGenFunction r BasicBlock
- getBasicBlocks :: Value -> IO [(String, Value)]
- fromLabel :: Value Label -> BasicBlock
- toLabel :: BasicBlock -> Value Label
- getInstructions :: Value -> 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)
- addAttributes :: Value a -> Int -> [Attribute] -> CodeGenFunction r ()
- data Attribute :: *
- = ZExtAttribute
- | SExtAttribute
- | NoReturnAttribute
- | InRegAttribute
- | StructRetAttribute
- | NoUnwindAttribute
- | NoAliasAttribute
- | ByValAttribute
- | NestAttribute
- | ReadNoneAttribute
- | ReadOnlyAttribute
- | NoInlineAttribute
- | AlwaysInlineAttribute
- | OptimizeForSizeAttribute
- | StackProtectAttribute
- | StackProtectReqAttribute
- | NoCaptureAttribute
- | NoRedZoneAttribute
- | NoImplicitFloatAttribute
- | NakedAttribute
- castVarArgs :: CastVarArgs a b => Function a -> Function b
- dumpValue :: Value a -> IO ()
- dumpType :: Value a -> IO ()
- getValueName :: Value a -> IO String
- annotateValueList :: [Value] -> IO [(String, Value)]
Initialize
initializeNativeTarget :: IO () #
Initialize jitter to the native target. The operation is idempotent.
Modules
:: Module | module that is defined |
-> CodeGenModule a | module body |
-> IO a |
Give the body for a module.
destroyModule :: Module -> IO () Source #
Free all storage related to a module. *Note*, this is a dangerous call, since referring to the module after this call is an error. The reason for the explicit call to free the module instead of an automatic lifetime management is that modules have a somewhat complicated ownership. Handing a module to a module provider changes the ownership of the module, and the module provider will free the module when necessary.
data ModuleProvider Source #
A module provider is used by the code generator to get access to a module.
createModuleProviderForExistingModule :: Module -> IO ModuleProvider Source #
Turn a module into a module provider.
createPassManager :: IO PassManager Source #
Create a pass manager.
createFunctionPassManager :: ModuleProvider -> IO PassManager Source #
Create a pass manager for a module.
getModuleValues :: Module -> IO [(String, ModuleValue)] Source #
data ModuleValue Source #
castModuleValue :: forall a. IsType a => ModuleValue -> Maybe (Value a) Source #
Instructions
ADT representation of IR
Terminator instructions
ret :: Ret a r => a -> CodeGenFunction r Terminate Source #
Return from the current function with the given value. Use () as the return value for what would be a void function in C.
:: Value Bool | Boolean to branch upon. |
-> BasicBlock | Target for true. |
-> BasicBlock | Target for false. |
-> CodeGenFunction r Terminate |
Branch to the first basic block if the boolean is true, otherwise to the second basic block.
:: BasicBlock | Branch target. |
-> CodeGenFunction r Terminate |
Unconditionally branch to the given basic block.
:: IsInteger a | |
=> Value a | Value to branch upon. |
-> BasicBlock | Default branch target. |
-> [(ConstValue a, BasicBlock)] | Labels and corresponding branch targets. |
-> CodeGenFunction r Terminate |
Branch table instruction.
:: CallArgs f g r | |
=> BasicBlock | Normal return point. |
-> BasicBlock | Exception return point. |
-> Function f | Function to call. |
-> g |
Call a function with exception handling.
:: CallArgs f g r | |
=> CallingConvention | Calling convention |
-> BasicBlock | Normal return point. |
-> BasicBlock | Exception return point. |
-> Function f | Function to call. |
-> g |
Call a function with exception handling. This also sets the calling convention of the call to the function. As LLVM itself defines, if the calling conventions of the calling instruction and the function being called are different, undefined behavior results.
:: BasicBlock | Normal return point. |
-> BasicBlock | Exception return point. |
-> Function f | Function to call. |
-> Call f |
invokeWithConvFromFunction Source #
:: CallingConvention | Calling convention |
-> BasicBlock | Normal return point. |
-> BasicBlock | Exception return point. |
-> Function f | Function to call. |
-> Call f |
unreachable :: CodeGenFunction r Terminate Source #
Inform the code generator that this code can never be reached.
Arithmetic binary operations
Arithmetic operations with the normal semantics. The u instractions are unsigned, the s instructions are signed.
add :: (IsArithmetic c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
sub :: (IsArithmetic c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
mul :: (IsArithmetic c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
neg :: (IsArithmetic b, AUnOp a, a ~ v b) => a -> CodeGenFunction r a Source #
iadd :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
isub :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
imul :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
fadd :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
fsub :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
fmul :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
fneg :: (IsFloating b, AUnOp a, a ~ v b) => a -> CodeGenFunction r a Source #
idiv :: forall a b c r v. (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
signed or unsigned integer division depending on the type
irem :: forall a b c r v. (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
signed or unsigned remainder depending on the type
udiv :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Deprecated: use idiv instead
sdiv :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Deprecated: use idiv instead
fdiv :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Floating point division.
urem :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Deprecated: use irem instead
srem :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Deprecated: use irem instead
frem :: (IsFloating c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Floating point remainder.
Logical binary operations
Logical instructions with the normal semantics.
shl :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
lshr :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
ashr :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
and :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
or :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
xor :: (IsInteger c, ABinOp a b, v c ~ ABinOpResult a b) => a -> b -> CodeGenFunction r (v c) Source #
Vector operations
:: Positive n | |
=> Value (Vector n a) | Vector |
-> Value Word32 | Index into the vector |
-> CodeGenFunction r (Value a) |
Get a value from a vector.
:: Positive n | |
=> Value (Vector n a) | Vector |
-> Value a | Value to insert |
-> Value Word32 | Index into the vector |
-> CodeGenFunction r (Value (Vector n a)) |
Insert a value into a vector, nondestructive.
shufflevector :: (Positive n, Positive m) => Value (Vector n a) -> Value (Vector n a) -> ConstValue (Vector m Word32) -> CodeGenFunction r (Value (Vector m a)) Source #
Permute vector.
Aggregate operation
:: GetValue agg i | |
=> Value agg | Aggregate |
-> i | Index into the aggregate |
-> CodeGenFunction r (Value (ValueType agg i)) |
Get a value from an aggregate.
:: GetValue agg i | |
=> Value agg | Aggregate |
-> Value (ValueType agg i) | Value to insert |
-> i | Index into the aggregate |
-> CodeGenFunction r (Value agg) |
Insert a value into an aggregate, nondestructive.
Memory access
arrayMalloc :: forall a r s. (IsSized a, AllocArg s) => s -> CodeGenFunction r (Value (Ptr a)) Source #
Allocate heap (array) memory.
arrayAlloca :: forall a r s. (IsSized a, AllocArg s) => s -> CodeGenFunction r (Value (Ptr a)) Source #
Allocate stack (array) memory.
:: Value (Ptr a) | Address to load from. |
-> CodeGenFunction r (Value a) |
Load a value from memory.
:: Value a | Value to store. |
-> Value (Ptr a) | Address to store to. |
-> CodeGenFunction r () |
Store a value in memory
getElementPtr :: forall a o i r. (GetElementPtr o i, IsIndexArg a) => Value (Ptr o) -> (a, i) -> CodeGenFunction r (Value (Ptr (ElementPtrType o i))) Source #
Address arithmetic. See LLVM description.
The index is a nested tuple of the form (i1,(i2,( ... ())))
.
(This is without a doubt the most confusing LLVM instruction, but the types help.)
getElementPtr0 :: GetElementPtr o i => Value (Ptr o) -> i -> CodeGenFunction r (Value (Ptr (ElementPtrType o i))) Source #
Like getElementPtr, but with an initial index that is 0. This is useful since any pointer first need to be indexed off the pointer, and then into its actual value. This first indexing is often with 0.
Conversions
trunc :: (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Truncate a value to a shorter bit width.
zext :: (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Zero extend a value to a wider width.
If possible, use ext
that chooses the right padding according to the types
sext :: (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Sign extend a value to wider width.
If possible, use ext
that chooses the right padding according to the types
ext :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, Signed a ~ Signed b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Extend a value to wider width. If the target type is signed, then preserve the sign, If the target type is unsigned, then extended by zeros.
zadapt :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
sadapt :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
adapt :: forall a b r. (IsInteger a, IsInteger b, NumberOfElements a ~ NumberOfElements b, Signed a ~ Signed b) => Value a -> CodeGenFunction r (Value b) Source #
fptrunc :: (IsFloating a, IsFloating b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :>: SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Truncate a floating point value.
fpext :: (IsFloating a, IsFloating b, NumberOfElements a ~ NumberOfElements b, IsSized a, IsSized b, SizeOf a :<: SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Extend a floating point value.
fptoui :: (IsFloating a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
Deprecated: use fptoint since it is type-safe with respect to signs
Convert a floating point value to an unsigned integer.
fptosi :: (IsFloating a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
Deprecated: use fptoint since it is type-safe with respect to signs
Convert a floating point value to a signed integer.
fptoint :: forall r a b. (IsFloating a, IsInteger b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
Convert a floating point value to an integer.
It is mapped to fptosi
or fptoui
depending on the type a
.
uitofp :: (IsInteger a, IsFloating b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
Convert an unsigned integer to a floating point value.
Although inttofp
should be prefered, this function may be useful for conversion from Bool.
sitofp :: (IsInteger a, IsFloating b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
Convert a signed integer to a floating point value.
Although inttofp
should be prefered, this function may be useful for conversion from Bool.
inttofp :: forall r a b. (IsInteger a, IsFloating b, NumberOfElements a ~ NumberOfElements b) => Value a -> CodeGenFunction r (Value b) Source #
Convert an integer to a floating point value.
It is mapped to sitofp
or uitofp
depending on the type a
.
ptrtoint :: (IsInteger b, IsPrimitive b) => Value (Ptr a) -> CodeGenFunction r (Value b) Source #
Convert a pointer to an integer.
inttoptr :: (IsInteger a, IsType b) => Value a -> CodeGenFunction r (Value (Ptr b)) Source #
Convert an integer to a pointer.
bitcast :: (IsFirstClass a, IsFirstClass b, IsSized a, IsSized b, SizeOf a ~ SizeOf b) => Value a -> CodeGenFunction r (Value b) Source #
Convert between to values of the same size by just copying the bit pattern.
bitcastElements :: (Positive n, IsPrimitive a, IsPrimitive b, IsSized a, IsSized b, SizeOf a ~ SizeOf b) => Value (Vector n a) -> CodeGenFunction r (Value (Vector n b)) Source #
Like bitcast
for vectors but it enforces that the number of elements remains the same.
Comparison
data CmpPredicate Source #
data IntPredicate Source #
data FPPredicate Source #
FPFalse | Always false (always folded) |
FPOEQ | True if ordered and equal |
FPOGT | True if ordered and greater than |
FPOGE | True if ordered and greater than or equal |
FPOLT | True if ordered and less than |
FPOLE | True if ordered and less than or equal |
FPONE | True if ordered and operands are unequal |
FPORD | True if ordered (no nans) |
FPUNO | True if unordered: isnan(X) | isnan(Y) |
FPUEQ | True if unordered or equal |
FPUGT | True if unordered or greater than |
FPUGE | True if unordered, greater than, or equal |
FPULT | True if unordered or less than |
FPULE | True if unordered, less than, or equal |
FPUNE | True if unordered or not equal |
FPT | Always true (always folded) |
class CmpRet (CmpType a b) => CmpOp a b Source #
Acceptable operands to comparison instructions.
cmpop
cmpBld, cmpCnst
CmpRet Bool Source # | |
CmpRet Double Source # | |
CmpRet Float Source # | |
CmpRet Int8 Source # | |
CmpRet Int16 Source # | |
CmpRet Int32 Source # | |
CmpRet Int64 Source # | |
CmpRet Word8 Source # | |
CmpRet Word16 Source # | |
CmpRet Word32 Source # | |
CmpRet Word64 Source # | |
CmpRet FP128 Source # | |
CmpRet (Ptr a) Source # | |
(CmpRet a, IsPrimitive a, Positive n) => CmpRet (Vector n a) Source # | |
type CmpValueResult a b = CmpValue a b (CmpResult (CmpType a b)) Source #
cmp :: forall a b r. CmpOp a b => CmpPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b) Source #
Compare values of ordered types
and choose predicates according to the compared types.
Floating point numbers are compared in "ordered" mode,
that is NaN
operands yields False
as result.
Pointers are compared unsigned.
These choices are consistent with comparison in plain Haskell.
pcmp :: (CmpOp a b, Ptr c ~ CmpType a b) => IntPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b) Source #
icmp :: (IsIntegerOrPointer c, CmpOp a b, c ~ CmpType a b) => IntPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b) Source #
Deprecated: use cmp or pcmp instead
Compare integers.
fcmp :: (IsFloating c, CmpOp a b, c ~ CmpType a b) => FPPredicate -> a -> b -> CodeGenFunction r (CmpValueResult a b) Source #
Compare floating point values.
select :: (IsFirstClass a, CmpRet a) => Value (CmpResult a) -> Value a -> Value a -> CodeGenFunction r (Value a) Source #
Select between two values depending on a boolean.
Other
phi :: forall a r. IsFirstClass a => [(Value a, BasicBlock)] -> CodeGenFunction r (Value a) Source #
Join several variables (virtual registers) from different basic blocks into one.
All of the variables in the list are joined. See also addPhiInputs
.
:: IsFirstClass a | |
=> Value a | Must be a variable from a call to |
-> [(Value a, BasicBlock)] | Variables to add. |
-> CodeGenFunction r () |
Add additional inputs to an existing phi node. The reason for this instruction is that sometimes the structure of the code makes it impossible to have all variables in scope at the point where you need the phi node.
call :: CallArgs f g r => Function f -> g Source #
Call a function with the given arguments. The call
instruction is variadic, i.e., the number of arguments
it takes depends on the type of f.
callWithConv :: CallArgs f g r => CallingConvention -> Function f -> g Source #
Call a function with the given arguments. The call
instruction
is variadic, i.e., the number of arguments it takes depends on the
type of f.
This also sets the calling convention of the call to the function.
As LLVM itself defines, if the calling conventions of the calling
instruction and the function being called are different, undefined
behavior results.
callFromFunction :: Function a -> Call a Source #
callWithConvFromFunction :: CallingConvention -> Function f -> Call f Source #
Classes and types
Acceptable arguments to the ret
instruction.
ret'
class (f ~ CalledFunction g, r ~ CallerResult g, g ~ CallerFunction f r) => CallArgs f g r Source #
Acceptable arguments to call
.
doCall
Acceptable arguments to arithmetic unary instructions.
aunop
Acceptable arguments to arithmetic binary instructions.
abinop
type ABinOpResult a b :: * Source #
ABinOp (ConstValue a) (ConstValue a) Source # | |
ABinOp (ConstValue a) (Value a) Source # | |
ABinOp (Value a) (ConstValue a) Source # | |
ABinOp (Value a) (Value a) Source # | |
IsConst Bool Source # | |
IsConst Double Source # | |
IsConst Float Source # | |
IsConst Int8 Source # | |
IsConst Int16 Source # | |
IsConst Int32 Source # | |
IsConst Int64 Source # | |
IsConst Word8 Source # | |
IsConst Word16 Source # | |
IsConst Word32 Source # | |
IsConst Word64 Source # | |
IsConst (StablePtr a) Source # | |
IsType a => IsConst (Ptr a) Source # | |
IsFunction a => IsConst (FunPtr a) Source # | |
IsConstFields a => IsConst (PackedStruct a) Source # | |
IsConstFields a => IsConst (Struct a) Source # | |
(IsPrimitive a, IsConst a, Positive n) => IsConst (Vector n a) Source # | |
(IsConst a, IsSized a, Natural n) => IsConst (Array n a) Source # | |
class IsFunction f => FunctionArgs f Source #
paramFunc
type FunctionCodeGen f :: * Source #
type FunctionResult f :: * Source #
IsFirstClass a => FunctionArgs (IO a) Source # | |
(FunctionArgs b, IsFirstClass a) => FunctionArgs (a -> b) Source # | |
Acceptable argument to array memory allocation.
getAllocArg
class GetElementPtr optr ixs Source #
Acceptable arguments to getElementPointer
.
getIxList
type ElementPtrType optr ixs :: * Source #
GetElementPtr a () Source # | |
(GetElementPtr (FieldType fs a) i, Natural a) => GetElementPtr (PackedStruct fs) (Proxy a, i) Source # | |
(GetElementPtr (FieldType fs a) i, Natural a) => GetElementPtr (Struct fs) (Proxy a, i) Source # | |
(GetElementPtr o i, IsIndexArg a, Positive k) => GetElementPtr (Vector k o) (a, i) Source # | |
(GetElementPtr o i, IsIndexArg a, Natural k) => GetElementPtr (Array k o) (a, i) Source # | |
class IsIndexArg a Source #
Acceptable single index to getElementPointer
.
getArg
Types classification
Type classifier
The IsType
class classifies all types that have an LLVM representation.
IsType Bool Source # | |
IsType Double Source # | |
IsType Float Source # | |
IsType Int8 Source # | |
IsType Int16 Source # | |
IsType Int32 Source # | |
IsType Int64 Source # | |
IsType Word8 Source # | |
IsType Word16 Source # | |
IsType Word32 Source # | |
IsType Word64 Source # | |
IsType () Source # | |
IsType Label Source # | |
IsType FP128 Source # | |
IsType (StablePtr a) Source # | |
IsFirstClass a => IsType (IO a) Source # | |
IsType a => IsType (Ptr a) Source # | |
IsFunction f => IsType (FunPtr f) Source # | |
StructFields a => IsType (PackedStruct a) Source # | |
StructFields a => IsType (Struct a) Source # | |
Positive n => IsType (WordN n) Source # | |
Positive n => IsType (IntN n) Source # | |
IsType (VarArgs a) Source # | |
(IsFirstClass a, IsFunction b) => IsType (a -> b) Source # | |
(Positive n, IsPrimitive a) => IsType (Vector n a) Source # | |
(Natural n, IsSized a) => IsType (Array n a) Source # | |
Special type classifiers
class IsFirstClass a => IsArithmetic a where Source #
Arithmetic types, i.e., integral and floating types.
class (IsArithmetic a, IsIntegerOrPointer a) => IsInteger a Source #
Integral types.
IsInteger Bool Source # | |
IsInteger Int8 Source # | |
IsInteger Int16 Source # | |
IsInteger Int32 Source # | |
IsInteger Int64 Source # | |
IsInteger Word8 Source # | |
IsInteger Word16 Source # | |
IsInteger Word32 Source # | |
IsInteger Word64 Source # | |
Positive n => IsInteger (WordN n) Source # | |
Positive n => IsInteger (IntN n) Source # | |
(Positive n, IsPrimitive a, IsInteger a) => IsInteger (Vector n a) Source # | |
class IsIntegerOrPointer a Source #
Integral or pointer type.
class IsArithmetic a => IsFloating a Source #
Floating types.
IsFloating Double Source # | |
IsFloating Float Source # | |
IsFloating FP128 Source # | |
(Positive n, IsPrimitive a, IsFloating a) => IsFloating (Vector n a) Source # | |
class (IsType a, NumberOfElements a ~ D1) => IsPrimitive a Source #
Primitive types. class (IsType a) => IsPrimitive a
class IsType a => IsFirstClass a Source #
First class types, i.e., the types that can be passed as arguments, etc.
IsFirstClass Bool Source # | |
IsFirstClass Double Source # | |
IsFirstClass Float Source # | |
IsFirstClass Int8 Source # | |
IsFirstClass Int16 Source # | |
IsFirstClass Int32 Source # | |
IsFirstClass Int64 Source # | |
IsFirstClass Word8 Source # | |
IsFirstClass Word16 Source # | |
IsFirstClass Word32 Source # | |
IsFirstClass Word64 Source # | |
IsFirstClass () Source # | |
IsFirstClass Label Source # | |
IsFirstClass FP128 Source # | |
IsFirstClass (StablePtr a) Source # | |
IsType a => IsFirstClass (Ptr a) Source # | |
IsFunction a => IsFirstClass (FunPtr a) Source # | |
StructFields as => IsFirstClass (Struct as) Source # | |
Positive n => IsFirstClass (WordN n) Source # | |
Positive n => IsFirstClass (IntN n) Source # | |
(Positive n, IsPrimitive a) => IsFirstClass (Vector n a) Source # | |
(Natural n, IsSized a) => IsFirstClass (Array n a) Source # | |
class (IsType a, Natural (SizeOf a)) => IsSized a Source #
Types with a fixed size.
IsSized Bool Source # | |
IsSized Double Source # | |
IsSized Float Source # | |
IsSized Int8 Source # | |
IsSized Int16 Source # | |
IsSized Int32 Source # | |
IsSized Int64 Source # | |
IsSized Word8 Source # | |
IsSized Word16 Source # | |
IsSized Word32 Source # | |
IsSized Word64 Source # | |
IsSized FP128 Source # | |
IsSized (StablePtr a) Source # | |
IsType a => IsSized (Ptr a) Source # | |
IsFunction a => IsSized (FunPtr a) Source # | |
StructFields as => IsSized (PackedStruct as) Source # | |
StructFields as => IsSized (Struct as) Source # | |
Positive n => IsSized (WordN n) Source # | |
Positive n => IsSized (IntN n) Source # | |
(Positive n, IsPrimitive a, IsSized a, Natural ((:*:) n (SizeOf a))) => IsSized (Vector n a) Source # | |
(Natural n, IsSized a, Natural ((:*:) n (SizeOf a))) => IsSized (Array n a) Source # | |
class IsType a => IsFunction a Source #
Function type.
funcType
IsFirstClass a => IsFunction (IO a) Source # | |
IsFirstClass a => IsFunction (VarArgs a) Source # | |
(IsFirstClass a, IsFunction b) => IsFunction (a -> b) Source # | |
Others
class IsType a => IsScalarOrVector a Source #
Number of elements for instructions that handle both primitive and vector types
type NumberOfElements a :: * Source #
class StructFields as Source #
fieldTypes
StructFields () Source # | |
(IsSized a, StructFields as) => StructFields ((:&) a as) Source # | |
type UnknownSize = D99 Source #
Structs
Type tests
Type descriptor, used to convey type information through the LLVM API.
isFloating :: IsArithmetic a => Proxy a -> Bool Source #
IsFirstClass a => IsFunction (VarArgs a) Source # | |
IsType (VarArgs a) Source # | |
CastVarArgs (VarArgs a) (IO a) Source # | |
(IsFirstClass a, CastVarArgs (VarArgs b) c) => CastVarArgs (VarArgs b) (a -> c) Source # | |
class CastVarArgs a b Source #
Define what vararg types are permissible.
CastVarArgs (VarArgs a) (IO a) Source # | |
(IsFirstClass a, CastVarArgs (VarArgs b) c) => CastVarArgs (VarArgs b) (a -> c) Source # | |
CastVarArgs b c => CastVarArgs (a -> b) (a -> c) Source # | |
Extra types
Variable sized signed integer.
The n parameter should belong to PosI
.
Show (IntN n) Source # | |
Positive n => IsSized (IntN n) Source # | |
Positive n => IsFirstClass (IntN n) Source # | |
Positive n => IsScalarOrVector (IntN n) Source # | |
Positive n => IsPrimitive (IntN n) Source # | |
Positive n => IsIntegerOrPointer (IntN n) Source # | |
Positive n => IsInteger (IntN n) Source # | |
Positive n => IsArithmetic (IntN n) Source # | |
Positive n => IsType (IntN n) Source # | |
type SizeOf (IntN n) Source # | |
type NumberOfElements (IntN n) Source # | |
type Signed (IntN n) Source # | |
Variable sized unsigned integer.
The n parameter should belong to PosI
.
Show (WordN n) Source # | |
Positive n => IsSized (WordN n) Source # | |
Positive n => IsFirstClass (WordN n) Source # | |
Positive n => IsScalarOrVector (WordN n) Source # | |
Positive n => IsPrimitive (WordN n) Source # | |
Positive n => IsIntegerOrPointer (WordN n) Source # | |
Positive n => IsInteger (WordN n) Source # | |
Positive n => IsArithmetic (WordN n) Source # | |
Positive n => IsType (WordN n) Source # | |
type SizeOf (WordN n) Source # | |
type NumberOfElements (WordN n) Source # | |
type Signed (WordN n) Source # | |
128 bit floating point.
Fixed sized arrays, the array size is encoded in the n parameter.
Array [a] |
Show a => Show (Array n a) Source # | |
(Natural n, IsSized a, Natural ((:*:) n (SizeOf a))) => IsSized (Array n a) Source # | |
(Natural n, IsSized a) => IsFirstClass (Array n a) Source # | |
(Natural n, IsSized a) => IsType (Array n a) Source # | |
(IsConst a, IsSized a, Natural n) => IsConst (Array n a) Source # | |
(IsFirstClass a, Natural n) => GetValue (Array n a) Word64 Source # | |
(IsFirstClass a, Natural n) => GetValue (Array n a) Word32 Source # | |
(IsFirstClass a, Natural n, Natural i, (:<:) i n) => GetValue (Array n a) (Proxy i) Source # | |
(GetElementPtr o i, IsIndexArg a, Natural k) => GetElementPtr (Array k o) (a, i) Source # | |
type SizeOf (Array n a) Source # | |
type ValueType (Array n a) Word64 Source # | |
type ValueType (Array n a) Word32 Source # | |
type ValueType (Array n a) (Proxy i) Source # | |
type ElementPtrType (Array k o) (a, i) Source # | |
Fixed sized vector, the array size is encoded in the n parameter.
Label type, produced by a basic block.
Struct types; a list (nested tuple) of component types.
Struct a |
Show a => Show (Struct a) Source # | |
StructFields as => IsSized (Struct as) Source # | |
StructFields as => IsFirstClass (Struct as) Source # | |
StructFields a => IsType (Struct a) Source # | |
IsConstFields a => IsConst (Struct a) Source # | |
(GetField as i, Natural i) => GetValue (Struct as) (Proxy i) Source # | |
(GetElementPtr (FieldType fs a) i, Natural a) => GetElementPtr (Struct fs) (Proxy a, i) Source # | |
type SizeOf (Struct as) Source # | |
type ValueType (Struct as) (Proxy i) Source # | |
type ElementPtrType (Struct fs) (Proxy a, i) Source # | |
newtype PackedStruct a Source #
Show a => Show (PackedStruct a) Source # | |
StructFields as => IsSized (PackedStruct as) Source # | |
StructFields a => IsType (PackedStruct a) Source # | |
IsConstFields a => IsConst (PackedStruct a) Source # | |
(GetElementPtr (FieldType fs a) i, Natural a) => GetElementPtr (PackedStruct fs) (Proxy a, i) Source # | |
type SizeOf (PackedStruct as) Source # | |
type ElementPtrType (PackedStruct fs) (Proxy a, i) Source # | |
Values and constants
ToArithFunction r (IO b) (CodeGenFunction r (Value b)) Source # | |
ToArithFunction r b0 b1 => ToArithFunction r (a -> b0) (CodeGenFunction r (Value a) -> b1) Source # | |
Show (Value a) Source # | |
IsIndexArg (Value Int32) Source # | |
IsIndexArg (Value Int64) Source # | |
IsIndexArg (Value Word32) Source # | |
IsIndexArg (Value Word64) Source # | |
AllocArg (Value Word32) Source # | |
AUnOp (Value a) Source # | |
IsFirstClass a => Phi (Value a) Source # | |
Ret (Value a) a Source # | |
CmpRet a => CmpOp (ConstValue a) (Value a) Source # | |
CmpRet a => CmpOp (Value a) (ConstValue a) Source # | |
CmpRet a => CmpOp (Value a) (Value a) Source # | |
ABinOp (ConstValue a) (Value a) Source # | |
ABinOp (Value a) (ConstValue a) Source # | |
ABinOp (Value a) (Value a) Source # | |
CallArgs (IO a) (CodeGenFunction r (Value a)) r Source # | |
CallArgs b b' r => CallArgs (a -> b) (Value a -> b') r Source # | |
type ABinOpResult (ConstValue a) (Value a) Source # | |
type ABinOpResult (Value a) (ConstValue a) Source # | |
type ABinOpResult (Value a) (Value a) Source # | |
data ConstValue a Source #
Show (ConstValue a) Source # | |
IsIndexArg (ConstValue Int32) Source # | |
IsIndexArg (ConstValue Int64) Source # | |
IsIndexArg (ConstValue Word32) Source # | |
IsIndexArg (ConstValue Word64) Source # | |
AllocArg (ConstValue Word32) Source # | |
AUnOp (ConstValue a) Source # | |
CmpRet a => CmpOp (ConstValue a) (ConstValue a) Source # | |
CmpRet a => CmpOp (ConstValue a) (Value a) Source # | |
CmpRet a => CmpOp (Value a) (ConstValue a) Source # | |
ABinOp (ConstValue a) (ConstValue a) Source # | |
ABinOp (ConstValue a) (Value a) Source # | |
ABinOp (Value a) (ConstValue a) Source # | |
type ABinOpResult (ConstValue a) (ConstValue a) Source # | |
type ABinOpResult (ConstValue a) (Value a) Source # | |
type ABinOpResult (Value a) (ConstValue a) Source # | |
constOf :: IsConst a => a -> ConstValue a Source #
value :: ConstValue a -> Value a Source #
zero :: forall a. IsType a => ConstValue a Source #
allOnes :: forall a. IsInteger a => ConstValue a Source #
undef :: forall a. IsType a => ConstValue a Source #
withString :: String -> (forall n. Natural n => Global (Array n Word8) -> CodeGenModule a) -> CodeGenModule a Source #
withStringNul :: String -> (forall n. Natural n => Global (Array n Word8) -> CodeGenModule a) -> CodeGenModule a Source #
constVector :: forall a n u. (Positive n, ToUnary n ~ u, Length (FixedList u) ~ u) => FixedList u (ConstValue a) -> ConstValue (Vector n a) Source #
Make a constant vector.
constArray :: forall a n. (IsSized a, Natural n) => [ConstValue a] -> ConstValue (Array n a) Source #
constCyclicVector :: forall a n. Positive n => T [] (ConstValue a) -> ConstValue (Vector n a) Source #
Make a constant vector.
Replicates or truncates the list to get length n
.
constCyclicArray :: forall a n. (IsSized a, Natural n) => T [] (ConstValue a) -> ConstValue (Vector n a) Source #
Make a constant array.
Replicates or truncates the list to get length n
.
constStruct :: IsConstStruct c => c -> ConstValue (Struct (ConstStructOf c)) Source #
Make a constant struct.
constPackedStruct :: IsConstStruct c => c -> ConstValue (PackedStruct (ConstStructOf c)) Source #
Make a constant packed struct.
fromVector :: MkVector n a => Vector n a -> Tuple n a Source #
cyclicVector :: Positive n => T [] a -> Vector n a Source #
Make a constant vector. Replicates or truncates the list to get length n.
This behaviour is consistent uncurry that of constCyclicVector
.
May be abused for constructing vectors from lists uncurry statically unknown size.
Code generation
data CodeGenFunction r a Source #
ArithFunction r z b0 b1 => ArithFunction r z (CodeGenFunction r a -> b0) (a -> b1) Source # | |
Ret a r => ArithFunction r a (CodeGenFunction r a) (CodeGenFunction r ()) Source # | |
ToArithFunction r (IO b) (CodeGenFunction r (Value b)) Source # | |
ToArithFunction r b0 b1 => ToArithFunction r (a -> b0) (CodeGenFunction r (Value a) -> b1) Source # | |
Monad (CodeGenFunction r) Source # | |
Functor (CodeGenFunction r) Source # | |
Applicative (CodeGenFunction r) Source # | |
MonadIO (CodeGenFunction r) Source # | |
CallArgs (IO a) (CodeGenFunction r (Value a)) r Source # | |
data CodeGenModule a Source #
Functions
newFunction :: forall a. IsFunction a => Linkage -> CodeGenModule (Function a) Source #
Create a new function. Use newNamedFunction
to create a function with external linkage, since
it needs a known name.
:: IsFunction a | |
=> Linkage | |
-> String | Function name |
-> CodeGenModule (Function a) |
Create a new named function.
:: FunctionArgs f | |
=> Function f | Function to define (created by |
-> FunctionCodeGen f | Function body. |
-> CodeGenModule () |
Define a function body. The basic block returned by the function is the function entry point.
:: FunctionArgs f | |
=> Linkage | |
-> FunctionCodeGen f | Function body. |
-> CodeGenModule (Function f) |
Create a new function with the given body.
:: FunctionArgs f | |
=> Linkage | |
-> String | |
-> FunctionCodeGen f | Function body. |
-> CodeGenModule (Function f) |
Create a new function with the given body.
setFuncCallConv :: Function a -> CallingConvention -> CodeGenModule () Source #
Set the calling convention of a function. By default it is the C calling convention.
type TFunction a = CodeGenModule (Function a) Source #
liftCodeGenModule :: CodeGenModule a -> CodeGenFunction r a Source #
Allows you to define part of a module while in the middle of defining a function.
Global variable creation
newGlobal :: forall a. IsType a => Bool -> Linkage -> TGlobal a Source #
Create a new global variable.
Create a new named global variable.
defineGlobal :: Global a -> ConstValue a -> CodeGenModule () Source #
Give a global variable a (constant) value.
createGlobal :: IsType a => Bool -> Linkage -> ConstValue a -> TGlobal a Source #
Create and define a global variable.
createNamedGlobal :: IsType a => Bool -> Linkage -> String -> ConstValue a -> TGlobal a Source #
Create and define a named global variable.
externFunction :: forall a r. IsFunction a => String -> CodeGenFunction r (Function a) Source #
Create a reference to an external function while code generating for a function.
If LLVM cannot resolve its name, then you may try staticFunction
.
staticFunction :: forall f r. IsFunction f => FunPtr f -> CodeGenFunction r (Function f) Source #
Make an external C function with a fixed address callable from LLVM code. This callback function can also be a Haskell function, that was imported like
foreign import ccall "&nextElement" nextElementFunPtr :: FunPtr (StablePtr (IORef [Word32]) -> IO Word32)
See examples/List.hs
.
When you only use externFunction
, then LLVM cannot resolve the name.
(However, I do not know why.)
Thus staticFunction
manages a list of static functions.
This list is automatically installed by simpleFunction
and can be manually obtained by getGlobalMappings
and installed by addGlobalMappings
.
"Installing" means calling LLVM's addGlobalMapping
according to
http://old.nabble.com/jit-with-external-functions-td7769793.html.
externGlobal :: forall a r. IsType a => Bool -> String -> CodeGenFunction r (Global a) Source #
As externFunction
, but for Global
s rather than Function
s
staticGlobal :: forall a r. IsType a => Bool -> Ptr a -> CodeGenFunction r (Global a) Source #
As staticFunction
, but for Global
s rather than Function
s
getGlobalMappings :: CodeGenModule GlobalMappings Source #
Get a list created by calls to staticFunction
that must be passed to the execution engine
via addGlobalMappings
.
type TGlobal a = CodeGenModule (Global a) Source #
Globals
An enumeration for the kinds of linkage for global values.
ExternalLinkage | Externally visible function |
AvailableExternallyLinkage | |
LinkOnceAnyLinkage | Keep one copy of function when linking (inline) |
LinkOnceODRLinkage | Same, but only replaced by something equivalent. |
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. |
Basic blocks
data BasicBlock Source #
A basic block is a sequence of non-branching instructions, terminated by a control flow instruction.
defineBasicBlock :: BasicBlock -> CodeGenFunction r () Source #
getBasicBlocks :: Value -> IO [(String, Value)] Source #
getInstructions :: Value -> IO [(String, Value)] Source #
getOperands :: Value -> IO [(String, Value)] Source #
Misc
addAttributes :: Value a -> Int -> [Attribute] -> CodeGenFunction r () Source #
Add attributes to a value. Beware, what attributes are allowed depends on what kind of value it is.
castVarArgs :: CastVarArgs a b => Function a -> Function b Source #
Convert a varargs function to a regular function.
Debugging
annotateValueList :: [Value] -> IO [(String, Value)] Source #