xo-pyjit: refactor: Jit -> MachPipeline

This commit is contained in:
Roland Conybeare 2024-06-16 11:49:50 -04:00
commit a4af2a79d0
2 changed files with 19 additions and 18 deletions

View file

@ -58,8 +58,8 @@ PYTHONPATH=~/local2/lib:$PYTHONPATH python
create a jit from within python
```
>>> jit=Jit.make()
>>> jit.dump_execution_sesion()
>>> mp=MachPipeline.make()
>>> mp.dump_execution_sesion()
JITDylib "<main>" (ES: 0x0000000000446ee0, State = Open)
Link order: [ ("<main>", MatchAllSymbols) ]
Symbol table:
@ -79,7 +79,7 @@ build an AST from within python
generate llvm IR for our AST
```
>>> code=jit.codegen(lm)
>>> code=mp.codegen(lm)
>>> print(code.print())
define double @foo(double %x) {
entry:
@ -91,15 +91,15 @@ entry:
generate machine code for our AST, lookup compiled function so we can invoke it directly
```
>>> jit.machgen_current_module()
>>> jit.dump_execution_session()
>>> mp.machgen_current_module()
>>> mp.dump_execution_session()
JITDylib "<main>" (ES: 0x0000000000446ee0, State = Open)
Link order: [ ("<main>", MatchAllSymbols) ]
Symbol table:
"foo": <not resolved> [Callable] Never-Searched (Materializer 0x646fe0, xojit)
>>> fn=jit.lookup_dbl_dbl_fn('foo')
>>> fn=mp.lookup_dbl_dbl_fn('foo')
>>> jit.dump_execution_session()
>>> mp.dump_execution_session()
JITDylib "<main>" (ES: 0x0000000000446ee0, State = Open)
Link order: [ ("<main>", MatchAllSymbols) ]
Symbol table:

View file

@ -2,7 +2,7 @@
#include "pyjit.hpp"
#include "xo/pyexpression/pyexpression.hpp"
#include "xo/jit/Jit.hpp"
#include "xo/jit/MachPipeline.hpp"
#include "xo/pyutil/pyutil.hpp"
#include <pybind11/stl.h>
@ -29,19 +29,20 @@ namespace xo {
m.doc() = "pybind11 plugin for xo-jit";
py::class_<Jit, rp<Jit>>(m, "Jit")
.def_static("make", &Jit::make,
py::doc("create Jit instance. Not threadsafe,"
" but does not share resources with any other Jit instance"))
py::class_<MachPipeline, rp<MachPipeline>>(m, "MachPipeline")
.def_static("make", &MachPipeline::make,
py::doc("Create machine pipeline for in-process code generation"
" and execution. Not threadsafe.\n"
"Does not share resources with any other instance"))
.def_property_readonly("target_triple", &Jit::target_triple,
.def_property_readonly("target_triple", &MachPipeline::target_triple,
py::doc("string describing target host for code generation"))
.def("get_function_name_v", &Jit::get_function_name_v,
.def("get_function_name_v", &MachPipeline::get_function_name_v,
py::doc("get vector of function names defined in jit module"))
.def("dump_execution_session", &Jit::dump_execution_session,
.def("dump_execution_session", &MachPipeline::dump_execution_session,
py::doc("write to console with state of all jit-owned dynamic libraries"))
.def("codegen",
[](Jit & jit, const rp<Expression> & expr) {
[](MachPipeline & jit, const rp<Expression> & expr) {
return jit.codegen(expr.borrow());
},
py::arg("x"),
@ -52,11 +53,11 @@ namespace xo {
* RC 14jun2024 - I think this is true, modulo use of llvm resource trackers.
*/
py::return_value_policy::reference_internal)
.def("machgen_current_module", &Jit::machgen_current_module,
.def("machgen_current_module", &MachPipeline::machgen_current_module,
py::doc("Make current module available for execution via the jit.\n"
"Adds all functions generated since last call to this method."))
.def("lookup_dbl_dbl_fn",
[](Jit & jit, const std::string & symbol) {
[](MachPipeline & jit, const std::string & symbol) {
auto llvm_addr = jit.lookup_symbol(symbol);
auto fn_addr = llvm_addr.toPtr<double (*) (double)>();