Wrap more stuff, move some things around.
[cl-llvm.git] / src / stuff.lisp
blob266deef91f67bcae330f7a9f83ad09a908f8701c
1 (in-package :llvm)
2 ;; Load up the native codegen.
3 (CLLLVM_LLVMInitializeNativeTarget)
5 ;; A global context. Most of LLVM is only thread-safe within a single "context". There is an
6 ;; internal-to-LLVM C default global context, implicitly used by a number of functions like
7 ;; LLVM*Type (without InContext on the end), but I make a lisp-side global context here for clarity.
8 ;;
9 ;; Delete with LLVMContextDispose when done.
11 ;; ...FIXME...or not. For some reason making a custom context makes things fail to verify, stating
12 ;; that I've mixed contexts. Need to figure out if this is my fault or a bug in LLVM.
14 ;; So just use the standard global context
15 ;; (defvar *llvm-context* (LLVMContextCreate))
16 (defvar *llvm-context* (LLVMGetGlobalContext))
18 ;; Top-level LLVM module for running the JIT in. Other modules can be made for codegen-to-disk, but
19 ;; only a single module for JIT execution can exist in the process.
20 (defvar *jit-module* (LLVMModuleCreateWithName "jit-module"))
22 ;; Module provider...dunno what the purpose of this is, it wraps the module
23 ;; Delete with LLVMDisposeModuleProvider; don't delete the wrapped module
24 (defvar *jit-module-provider* (LLVMCreateModuleProviderForExistingModule *jit-module*))
26 ;; Create the JIT compiler, optimization level 2 (whatever that means). This call fails if you run
27 ;; it twice in a process. (which is why we can have only one module for JIT code)
28 (defvar *jit-execution-engine* (LLVMCreateJITCompiler *jit-module-provider* 2))
30 ;; Optimization passes. Cleanup with LLVMDisposePassManager.
31 (defvar *jit-pass-manager* (LLVMCreateFunctionPassManager *jit-module-provider*))
32 (let ((pass *jit-pass-manager*))
33 (LLVMAddTargetData (LLVMGetExecutionEngineTargetData *jit-execution-engine*) pass)
34 (LLVMAddConstantPropagationPass pass)
35 (LLVMAddInstructionCombiningPass pass)
36 (LLVMAddPromoteMemoryToRegisterPass pass)
37 (LLVMAddGVNPass pass)
38 (LLVMAddCFGSimplificationPass pass))