File tree Expand file tree Collapse file tree 4 files changed +36
-31
lines changed
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 4 files changed +36
-31
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ extern "C" {
11
11
#include "pycore_typedefs.h" // _PyInterpreterFrame
12
12
#include "pycore_uop_ids.h"
13
13
#include "pycore_stackref.h" // _PyStackRef
14
+ #include "pycore_tstate.h" // _PyUOpInstruction
14
15
#include <stdbool.h>
15
16
16
17
@@ -41,32 +42,6 @@ typedef struct {
41
42
PyCodeObject * code ; // Weak (NULL if no corresponding ENTER_EXECUTOR).
42
43
} _PyVMData ;
43
44
44
- /* Depending on the format,
45
- * the 32 bits between the oparg and operand are:
46
- * UOP_FORMAT_TARGET:
47
- * uint32_t target;
48
- * UOP_FORMAT_JUMP
49
- * uint16_t jump_target;
50
- * uint16_t error_target;
51
- */
52
- typedef struct {
53
- uint16_t opcode :15 ;
54
- uint16_t format :1 ;
55
- uint16_t oparg ;
56
- union {
57
- uint32_t target ;
58
- struct {
59
- uint16_t jump_target ;
60
- uint16_t error_target ;
61
- };
62
- };
63
- uint64_t operand0 ; // A cache entry
64
- uint64_t operand1 ;
65
- #ifdef Py_STATS
66
- uint64_t execution_count ;
67
- #endif
68
- } _PyUOpInstruction ;
69
-
70
45
typedef struct _PyExitData {
71
46
uint32_t target ;
72
47
uint16_t index ;
@@ -118,9 +93,6 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
118
93
// trace_run_counter is greater than this value.
119
94
#define JIT_CLEANUP_THRESHOLD 100000
120
95
121
- // This is the length of the trace we project initially.
122
- #define UOP_MAX_TRACE_LENGTH 1200
123
-
124
96
#define TRACE_STACK_SIZE 5
125
97
126
98
int _Py_uop_analyze_and_optimize (_PyInterpreterFrame * frame ,
Original file line number Diff line number Diff line change @@ -13,14 +13,43 @@ extern "C" {
13
13
#include "pycore_mimalloc.h" // struct _mimalloc_thread_state
14
14
#include "pycore_qsbr.h" // struct qsbr
15
15
16
-
17
16
#ifdef Py_GIL_DISABLED
18
17
struct _gc_thread_state {
19
18
/* Thread-local allocation count. */
20
19
Py_ssize_t alloc_count ;
21
20
};
22
21
#endif
23
22
23
+ /* Depending on the format,
24
+ * the 32 bits between the oparg and operand are:
25
+ * UOP_FORMAT_TARGET:
26
+ * uint32_t target;
27
+ * UOP_FORMAT_JUMP
28
+ * uint16_t jump_target;
29
+ * uint16_t error_target;
30
+ */
31
+ typedef struct _PyUOpInstruction {
32
+ uint16_t opcode :15 ;
33
+ uint16_t format :1 ;
34
+ uint16_t oparg ;
35
+ union {
36
+ uint32_t target ;
37
+ struct {
38
+ uint16_t jump_target ;
39
+ uint16_t error_target ;
40
+ };
41
+ };
42
+ uint64_t operand0 ; // A cache entry
43
+ uint64_t operand1 ;
44
+ #ifdef Py_STATS
45
+ uint64_t execution_count ;
46
+ #endif
47
+ } _PyUOpInstruction ;
48
+
49
+ // This is the length of the trace we project initially.
50
+ #define UOP_MAX_TRACE_LENGTH 1200
51
+
52
+
24
53
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
25
54
// PyThreadState fields are exposed as part of the C API, although most fields
26
55
// are intended to be private. The _PyThreadStateImpl fields not exposed.
@@ -75,6 +104,7 @@ typedef struct _PyThreadStateImpl {
75
104
#if defined(Py_REF_DEBUG ) && defined(Py_GIL_DISABLED )
76
105
Py_ssize_t reftotal ; // this thread's total refcount operations
77
106
#endif
107
+ struct _PyUOpInstruction buffer [1200 ];
78
108
79
109
} _PyThreadStateImpl ;
80
110
Original file line number Diff line number Diff line change
1
+ Move _PyUOpInstruction buffer[UOP_MAX_TRACE_LENGTH] to _PyThreadStateImpl.
2
+ Patch By Donghee Na.
Original file line number Diff line number Diff line change @@ -1280,7 +1280,8 @@ uop_optimize(
1280
1280
{
1281
1281
_PyBloomFilter dependencies ;
1282
1282
_Py_BloomFilter_Init (& dependencies );
1283
- _PyUOpInstruction buffer [UOP_MAX_TRACE_LENGTH ];
1283
+ _PyThreadStateImpl * tstate = (_PyThreadStateImpl * )_PyThreadState_GET ();
1284
+ _PyUOpInstruction * buffer = tstate -> buffer ;
1284
1285
OPT_STAT_INC (attempts );
1285
1286
char * env_var = Py_GETENV ("PYTHON_UOPS_OPTIMIZE" );
1286
1287
bool is_noopt = true;
You can’t perform that action at this time.
0 commit comments