jit: Initial commit for LLVM backend

Lets see how hard it is to write a LLVM backend for Jato...

You can enable it with the '-Xllvm' command line option. `EntryTest`
aborts like this:

  [penberg@tux jato]$ ./jato -Xllvm -cp test/functional jvm/EntryTest
  jato: jit/llvm/core.c:325: llvm_bc2ir_insn: Assertion `0' failed.
  Aborted

which is caused by missing bytecode translation for OPC_NEW. That's
hardly surprising as we don't translate any bytecodes. We do, however,
generate code with full LLVM stack that rest of Jato's JIT is able to
call.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Make 'execution engine' and 'module' per-process

I'm unable to find good documentation on recommened life cycle for
'execution engine' and 'module' for LLVM JIT compiling but they
certainly cannot be per-compilation because we cannot dispose them. Make
them per-process for now.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
llvm/jit: Add LLVM mapping for 'vm_object_alloc()' function

Add a global mapping for LLVM to 'vm_object_alloc()' JVM internal
function so that generated code can call it.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
llvm/core: Drop comment about JVM `char`s being unsigned

There are no unsigned *types* in LLVM, only instructions that interpret
the data either as signed or unsigned.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
llvm/core: Use LLVMReferenceType() in llvm_type()

Use the LLVMReferenceType() helper function in llvm_type() also.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add OPC_RETURN translation to LLVM IR

We already have a hard-coded 'LLVMBuildRetVoid()' call in 'llvm_bc2ir()'
which we might as well move under OPC_RETURN translation proper.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Move function creation to 'llvm_codegen'

Move the call to 'llvm_function()' to 'llvm_codegen' to keep
'llvm_bc2ir' strictly about converting JVM bytecode to LLVM IR.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Fix JVM function LLVM mapping

The call to LLVMAddGlobalMapping() caused a SIGSEGV because
'vm_alloc_object_func' is NULL at that point. Fix that up.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for OPC_NEW instruction

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for OPC_DUP instruction

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for OPC_NOP

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for const opcodes

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Document mimic stack data structure

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for OPC_POP

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for return opcodes

Signed-off-by: Pekka Enberg <penberg@kernel.org>
test/integration: Disable LLVM from bytecode tests

Signed-off-by: Pekka Enberg <penberg@kernel.org>
vm: Fix exit when LLVM is disabled

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for arithmetic opcodes

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Add LLVM translation for conversion opcodes

Signed-off-by: Pekka Enberg <penberg@kernel.org>
jit/llvm: Clean up OPC_NEW codegen

Signed-off-by: Pekka Enberg <penberg@kernel.org>