summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-06-27 02:02:57 (GMT)
committerGitHub <noreply@github.com>2023-06-27 02:02:57 (GMT)
commit51fc72511733353de15bc633a3d7b6da366842e4 (patch)
tree13c7075d57530adf90f82ba0025649f163b51abb /Include
parentd3af83b9342457d8b24476baeb799f7506ff04f3 (diff)
downloadcpython-51fc72511733353de15bc633a3d7b6da366842e4.zip
cpython-51fc72511733353de15bc633a3d7b6da366842e4.tar.gz
cpython-51fc72511733353de15bc633a3d7b6da366842e4.tar.bz2
gh-104584: Baby steps towards generating and executing traces (#105924)
Added a new, experimental, tracing optimizer and interpreter (a.k.a. "tier 2"). This currently pessimizes, so don't use yet -- this is infrastructure so we can experiment with optimizing passes. To enable it, pass ``-Xuops`` or set ``PYTHONUOPS=1``. To get debug output, set ``PYTHONUOPSDEBUG=N`` where ``N`` is a debug level (0-4, where 0 is no debug output and 4 is excessively verbose). All of this code is likely to change dramatically before the 3.13 feature freeze. But this is a first step.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/optimizer.h1
-rw-r--r--Include/internal/pycore_uops.h31
-rw-r--r--Include/pystats.h3
3 files changed, 35 insertions, 0 deletions
diff --git a/Include/cpython/optimizer.h b/Include/cpython/optimizer.h
index b2d173f..2664f5b 100644
--- a/Include/cpython/optimizer.h
+++ b/Include/cpython/optimizer.h
@@ -45,6 +45,7 @@ extern _PyOptimizerObject _PyOptimizer_Default;
/* For testing */
PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewCounter(void);
+PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewUOpOptimizer(void);
#define OPTIMIZER_BITS_IN_COUNTER 4
diff --git a/Include/internal/pycore_uops.h b/Include/internal/pycore_uops.h
new file mode 100644
index 0000000..0e88d7e
--- /dev/null
+++ b/Include/internal/pycore_uops.h
@@ -0,0 +1,31 @@
+#ifndef Py_INTERNAL_UOPS_H
+#define Py_INTERNAL_UOPS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
+#endif
+
+#define _Py_UOP_MAX_TRACE_LENGTH 16
+
+typedef struct {
+ int opcode;
+ uint64_t operand; // Sometimes oparg, sometimes a cache entry
+} _PyUOpInstruction;
+
+typedef struct {
+ _PyExecutorObject base;
+ _PyUOpInstruction trace[_Py_UOP_MAX_TRACE_LENGTH]; // TODO: variable length
+} _PyUOpExecutorObject;
+
+_PyInterpreterFrame *_PyUopExecute(
+ _PyExecutorObject *executor,
+ _PyInterpreterFrame *frame,
+ PyObject **stack_pointer);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_UOPS_H */
diff --git a/Include/pystats.h b/Include/pystats.h
index 034bf05..54c9b8d 100644
--- a/Include/pystats.h
+++ b/Include/pystats.h
@@ -71,6 +71,9 @@ typedef struct _object_stats {
uint64_t type_cache_dunder_misses;
uint64_t type_cache_collisions;
uint64_t optimization_attempts;
+ uint64_t optimization_traces_created;
+ uint64_t optimization_traces_executed;
+ uint64_t optimization_uops_executed;
} ObjectStats;
typedef struct _stats {