mirror of
https://github.com/python/cpython.git
synced 2025-10-27 16:57:08 +00:00
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.
This commit is contained in:
parent
d3af83b934
commit
51fc725117
21 changed files with 2559 additions and 305 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
31
Include/internal/pycore_uops.h
Normal file
31
Include/internal/pycore_uops.h
Normal file
|
|
@ -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 */
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue