Skip to content

Commit 9466417

Browse files
Skip refcounting where possible for common float ops
1 parent b8f5526 commit 9466417

File tree

10 files changed

+523
-239
lines changed

10 files changed

+523
-239
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,38 +180,63 @@ typedef enum _JitSymType {
180180
JIT_SYM_TRUTHINESS_TAG = 9,
181181
} JitSymType;
182182

183+
#define DONT_SKIP_REFCOUNT 0
184+
#define SKIP_REFCOUNT 1
185+
183186
typedef struct _jit_opt_known_class {
184-
uint8_t tag;
187+
struct {
188+
uint8_t tag;
189+
uint8_t skip_refcount;
190+
};
185191
uint32_t version;
186192
PyTypeObject *type;
187193
} JitOptKnownClass;
188194

189195
typedef struct _jit_opt_known_version {
190-
uint8_t tag;
196+
struct {
197+
uint8_t tag;
198+
uint8_t skip_refcount;
199+
};
191200
uint32_t version;
192201
} JitOptKnownVersion;
193202

194203
typedef struct _jit_opt_known_value {
195-
uint8_t tag;
204+
struct {
205+
uint8_t tag;
206+
uint8_t skip_refcount;
207+
};
196208
PyObject *value;
197209
} JitOptKnownValue;
198210

199211
#define MAX_SYMBOLIC_TUPLE_SIZE 7
200212

201213
typedef struct _jit_opt_tuple {
202-
uint8_t tag;
214+
struct {
215+
uint8_t tag;
216+
uint8_t skip_refcount;
217+
};
203218
uint8_t length;
204219
uint16_t items[MAX_SYMBOLIC_TUPLE_SIZE];
205220
} JitOptTuple;
206221

207222
typedef struct {
208-
uint8_t tag;
223+
struct {
224+
uint8_t tag;
225+
uint8_t skip_refcount;
226+
};
209227
bool invert;
210228
uint16_t value;
211229
} JitOptTruthiness;
212230

213231
typedef union _jit_opt_symbol {
214-
uint8_t tag;
232+
struct {
233+
uint8_t tag;
234+
// Whether this object skips refcount on the stack
235+
// (using the _PyStackRef API), or not.
236+
// 0 - normal refcounting
237+
// 1 - skip refcounting
238+
int8_t skip_refcount;
239+
};
215240
JitOptKnownClass cls;
216241
JitOptKnownValue value;
217242
JitOptKnownVersion version;
@@ -283,6 +308,10 @@ extern JitOptSymbol *_Py_uop_sym_tuple_getitem(JitOptContext *ctx, JitOptSymbol
283308
extern int _Py_uop_sym_tuple_length(JitOptSymbol *sym);
284309
extern JitOptSymbol *_Py_uop_sym_new_truthiness(JitOptContext *ctx, JitOptSymbol *value, bool truthy);
285310

311+
extern void _Py_uop_sym_set_dont_skip_refcount(JitOptContext *ctx, JitOptSymbol *sym);
312+
extern bool _Py_uop_sym_is_skip_refcount(JitOptContext *ctx, JitOptSymbol *sym);
313+
extern void _Py_uop_sym_set_skip_refcount(JitOptContext *ctx, JitOptSymbol *sym);
314+
286315
extern void _Py_uop_abstractcontext_init(JitOptContext *ctx);
287316
extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx);
288317

0 commit comments

Comments
 (0)