Mark LLVMAttribute as a bitfield, add some missing functions, note URLs for upstreame...
[cl-llvm.git] / src / stuff.lisp
blobb5c0540b7bdf50d4cb01659ce93b84fa90d5d3d4
1 (in-package :llvm)
2 ;; Load up the native codegen.
3 (cffi:defcfun ("CLLLVM_LLVMInitializeNativeTarget" CLLLVM_LLVMInitializeNativeTarget) :int)
4 (cffi:defcfun ("CLLLVM_LLVMModuleProviderGetModule" CLLLVM_LLVMModuleProviderGetModule) :pointer
5 (modprovider :pointer))
6 (cffi:defcfun ("CLLLVM_LLVMParseAssemblyString" CLLLVM_LLVMParseAssemblyString) :pointer
7 (asm-string :string)
8 (module :pointer)
9 (context :pointer))
10 (cffi:defcfun ("CLLLVM_LLVMDumpModuleToString" CLLLVM_LLVMDumpModuleToString) :string
11 (module :pointer))
12 (cffi:defcfun ("CLLLVM_LLVMDumpTypeToString" CLLLVM_LLVMDumpTypeToString) :string
13 (module :pointer))
14 (cffi:defcfun ("CLLLVM_LLVMDumpValueToString" CLLLVM_LLVMDumpValueToString) :string
15 (module :pointer))
17 (CLLLVM_LLVMInitializeNativeTarget)
19 ;; A global context. Most of LLVM is only thread-safe within a single "context". There is an
20 ;; internal-to-LLVM C default global context, implicitly used by a number of functions like
21 ;; LLVM*Type (without InContext on the end), but I make a lisp-side global context here for clarity.
23 ;; Delete with LLVMContextDispose when done.
25 ;; ...FIXME...or not. For some reason making a custom context makes things fail to verify, stating
26 ;; that I've mixed contexts. Need to figure out if this is my fault or a bug in LLVM.
28 ;; So just use the standard global context
29 ;; (defvar *llvm-context* (LLVMContextCreate))
30 (defvar *llvm-context* (LLVMGetGlobalContext))
32 ;; Top-level LLVM module for running the JIT in. Other modules can be made for codegen-to-disk, but
33 ;; only a single module for JIT execution can exist in the process.
34 (defvar *jit-module* (LLVMModuleCreateWithName "jit-module"))
36 ;; Module provider...dunno what the purpose of this is, it wraps the module
37 ;; Delete with LLVMDisposeModuleProvider; don't delete the wrapped module
38 (defvar *jit-module-provider* (LLVMCreateModuleProviderForExistingModule *jit-module*))
40 ;; Create the JIT compiler, optimization level 2 (whatever that means). This call fails if you run
41 ;; it twice in a process. (which is why we can have only one module for JIT code)
42 (defvar *jit-execution-engine* (LLVMCreateJITCompiler *jit-module-provider* 2))
44 ;; Optimization passes. Cleanup with LLVMDisposePassManager.
45 (defvar *jit-pass-manager* (LLVMCreateFunctionPassManager *jit-module-provider*))
46 (let ((pass *jit-pass-manager*))
47 (LLVMAddTargetData (LLVMGetExecutionEngineTargetData *jit-execution-engine*) pass)
48 (LLVMAddConstantPropagationPass pass)
49 (LLVMAddInstructionCombiningPass pass)
50 (LLVMAddPromoteMemoryToRegisterPass pass)
51 (LLVMAddGVNPass pass)
52 (LLVMAddCFGSimplificationPass pass))