summaryrefslogtreecommitdiffstats
path: root/Include/cpython/optimizer.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-06-02 10:46:18 (GMT)
committerGitHub <noreply@github.com>2023-06-02 10:46:18 (GMT)
commit4bfa01b9d911ce9358cf1a453bee15554f8e4c07 (patch)
treebd61d8459bf30d42abf0be7258de91360bea434b /Include/cpython/optimizer.h
parent601ae09f0c8eda213b9050892f5ce9b91f0aa522 (diff)
downloadcpython-4bfa01b9d911ce9358cf1a453bee15554f8e4c07.zip
cpython-4bfa01b9d911ce9358cf1a453bee15554f8e4c07.tar.gz
cpython-4bfa01b9d911ce9358cf1a453bee15554f8e4c07.tar.bz2
GH-104584: Plugin optimizer API (GH-105100)
Diffstat (limited to 'Include/cpython/optimizer.h')
-rw-r--r--Include/cpython/optimizer.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/Include/cpython/optimizer.h b/Include/cpython/optimizer.h
new file mode 100644
index 0000000..eb257d7
--- /dev/null
+++ b/Include/cpython/optimizer.h
@@ -0,0 +1,54 @@
+
+#ifndef Py_LIMITED_API
+#ifndef Py_OPTIMIZER_H
+#define Py_OPTIMIZER_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uint8_t opcode;
+ uint8_t oparg;
+} _PyVMData;
+
+typedef struct _PyExecutorObject {
+ PyObject_HEAD
+ /* WARNING: execute consumes a reference to self. This is necessary to allow executors to tail call into each other. */
+ struct _PyInterpreterFrame *(*execute)(struct _PyExecutorObject *self, struct _PyInterpreterFrame *frame, PyObject **stack_pointer);
+ _PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */
+ /* Data needed by the executor goes here, but is opaque to the VM */
+} _PyExecutorObject;
+
+typedef struct _PyOptimizerObject _PyOptimizerObject;
+
+typedef _PyExecutorObject *(*optimize_func)(_PyOptimizerObject* self, PyCodeObject *code, _Py_CODEUNIT *instr);
+
+typedef struct _PyOptimizerObject {
+ PyObject_HEAD
+ optimize_func optimize;
+ uint16_t resume_threshold;
+ uint16_t backedge_threshold;
+ /* Data needed by the optimizer goes here, but is opaque to the VM */
+} _PyOptimizerObject;
+
+PyAPI_FUNC(int) PyUnstable_Replace_Executor(PyCodeObject *code, _Py_CODEUNIT *instr, _PyExecutorObject *executor);
+
+PyAPI_FUNC(void) PyUnstable_SetOptimizer(_PyOptimizerObject* optimizer);
+
+PyAPI_FUNC(_PyOptimizerObject *) PyUnstable_GetOptimizer(void);
+
+struct _PyInterpreterFrame *
+_PyOptimizer_BackEdge(struct _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest, PyObject **stack_pointer);
+
+extern _PyOptimizerObject _PyOptimizer_Default;
+
+/* For testing */
+PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewCounter(void);
+
+#define OPTIMIZER_BITS_IN_COUNTER 4
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_OPTIMIZER_H */
+#endif /* Py_LIMITED_API */