LLVM JIT compiler

The LLVM JIT compiler facilitates performant implementations of numerical methods. The following example shows a function for negating integers implemented using LLVM. The function then is used to negate the number 42.

Setting the environment variable DEBUG to YES will cause the JIT compiler to display the LLVM intermediate code.

Compilation

The jit function provides an interface to LLVM. The following example defines a function for adding two integers:

(use-modules (oop goops) (aiscm core))
(define f (jit (list <int> <int>) (lambda (x y) (+ x y))))
(f 12 34)
; 46 

The jit function also instantiates loops for array processing. For example:

(use-modules (oop goops) (aiscm core))
(define f (jit (list (rgb <int>) (llvmarray <int> 1)) +))
(f (rgb 1 2 3) (arr <int> 4 5 6))
; #<multiarray<int<32,signed>,1>>:
; ((rgb 5 6 7) (rgb 6 7 8) (rgb 7 8 9))

Scheme callbacks

Operations on Scheme objects are facilitated by callbacks into the Scheme interpreter:

(use-modules (oop goops) (aiscm core))
(define f (jit (list <int> <obj>) +))
(f 1 (/ 2 3))
; 5/3

Callbacks into Scheme are used when handling arrays of Scheme objects:

(use-modules (oop goops) (aiscm core))
(<< 1 (* 10 (arr <obj> 1 2 4 8)))
;#<multiarray<obj,1>>:
;(1024 1048576 1099511627776 1208925819614629174706176)

AIscm documentation generated by Pandoc 2021-12-02