diff options
author | Anthony Shaw <anthony.p.shaw@gmail.com> | 2024-05-01 14:11:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 14:11:14 (GMT) |
commit | beb653cc24275025708758d444835db2ddbb74e4 (patch) | |
tree | 8e9752251cb31cb49be7d7ea927eb9b6a754f4eb | |
parent | 4a08a75cf4c490f7c43ede69bdf6e5a79c6a3af3 (diff) | |
download | cpython-beb653cc24275025708758d444835db2ddbb74e4.zip cpython-beb653cc24275025708758d444835db2ddbb74e4.tar.gz cpython-beb653cc24275025708758d444835db2ddbb74e4.tar.bz2 |
gh-117958: Expose JIT code via method in UOpExecutor (#117959)
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2024-04-18-03-49-41.gh-issue-117958.-EsfUs.rst | 2 | ||||
-rw-r--r-- | Python/optimizer.c | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-18-03-49-41.gh-issue-117958.-EsfUs.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-18-03-49-41.gh-issue-117958.-EsfUs.rst new file mode 100644 index 0000000..c127786 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-18-03-49-41.gh-issue-117958.-EsfUs.rst @@ -0,0 +1,2 @@ +Added a ``get_jit_code()`` method to access JIT compiled machine code from the UOp Executor when the experimental JIT is enabled. Patch
+by Anthony Shaw.
diff --git a/Python/optimizer.c b/Python/optimizer.c index 6576aa1..9ba8d84 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -393,6 +393,29 @@ executor_traverse(PyObject *o, visitproc visit, void *arg) return 0; } +static PyObject * +get_jit_code(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ +#ifndef _Py_JIT + PyErr_SetString(PyExc_RuntimeError, "JIT support not enabled."); + return NULL; +#else + _PyExecutorObject *executor = (_PyExecutorObject *)self; + if (executor->jit_code == NULL || executor->jit_size == 0) { + Py_RETURN_NONE; + } + return PyBytes_FromStringAndSize(executor->jit_code, executor->jit_size); +#endif +} + +static PyMethodDef uop_executor_methods[] = { + { "is_valid", is_valid, METH_NOARGS, NULL }, + { "get_jit_code", get_jit_code, METH_NOARGS, NULL}, + { "get_opcode", get_opcode, METH_NOARGS, NULL }, + { "get_oparg", get_oparg, METH_NOARGS, NULL }, + { NULL, NULL }, +}; + static int executor_is_gc(PyObject *o) { @@ -407,7 +430,7 @@ PyTypeObject _PyUOpExecutor_Type = { .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC, .tp_dealloc = (destructor)uop_dealloc, .tp_as_sequence = &uop_as_sequence, - .tp_methods = executor_methods, + .tp_methods = uop_executor_methods, .tp_traverse = executor_traverse, .tp_clear = (inquiry)executor_clear, .tp_is_gc = executor_is_gc, |