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