From e7b7d5d9b607181e1ef5ffc0c0e6b963df877d82 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 11:44:29 -0400 Subject: [PATCH 01/13] Add type version and offset to optimizer header --- Include/internal/pycore_optimizer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h index 76123987ac99f5..e19e416c25b0cd 100644 --- a/Include/internal/pycore_optimizer.h +++ b/Include/internal/pycore_optimizer.h @@ -33,6 +33,8 @@ struct _Py_UopsSymbol { int flags; // 0 bits: Top; 2 or more bits: Bottom PyTypeObject *typ; // Borrowed reference PyObject *const_val; // Owned reference (!) + int32_t typ_version; // currently stores type version + int32_t typ_version_offset; // bytecode offset where the last type version was set }; #define UOP_FORMAT_TARGET 0 From c90227661ec1c97c03d5f001a9477113d3c291e1 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 12:16:40 -0400 Subject: [PATCH 02/13] Start adding type version --- Python/optimizer_bytecodes.c | 7 +++++++ Python/optimizer_symbols.c | 1 + 2 files changed, 8 insertions(+) diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index e5c982befb2411..83a8f7917f8252 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -113,6 +113,13 @@ dummy_func(void) { sym_set_type(right, &PyLong_Type); } + op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) { + if (sym_matches_type_version(owner, type_version)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_type_version(owner, type_version); + } + op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) { if (sym_matches_type(left, &PyFloat_Type)) { if (sym_matches_type(right, &PyFloat_Type)) { diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index e546eef306eeca..d02314b0ee4ba1 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -76,6 +76,7 @@ sym_new(_Py_UOpsContext *ctx) self->flags = 0; self->typ = NULL; self->const_val = NULL; + self->typ_version = return self; } From 89e3649ef1ac9e47054f8f5edafc6bf5b2b8a0cc Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 13:11:22 -0400 Subject: [PATCH 03/13] Add type version functions and struct initialization --- Python/optimizer_bytecodes.c | 2 ++ Python/optimizer_symbols.c | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 83a8f7917f8252..e87472c36be1a1 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -21,11 +21,13 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame; #define sym_new_const _Py_uop_sym_new_const #define sym_new_null _Py_uop_sym_new_null #define sym_matches_type _Py_uop_sym_matches_type +#define sym_matches_type_version _Py_uop_sym_matches_type_version #define sym_get_type _Py_uop_sym_get_type #define sym_has_type _Py_uop_sym_has_type #define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM) #define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM) #define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE) +#define sym_set_type_version(SYM, VERSION) _Py_uop_sym_set_type_version(ctx, SYM, VERSION) #define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST) #define sym_is_bottom _Py_uop_sym_is_bottom #define frame_new _Py_uop_frame_new diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index d02314b0ee4ba1..c5d197e2f323ff 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -52,7 +52,9 @@ static inline int get_lltrace(void) { static _Py_UopsSymbol NO_SPACE_SYMBOL = { .flags = IS_NULL | NOT_NULL | NO_SPACE, .typ = NULL, - .const_val = NULL + .const_val = NULL, + .typ_version = 0, + .typ_version_offset = 0, }; _Py_UopsSymbol * @@ -76,7 +78,8 @@ sym_new(_Py_UOpsContext *ctx) self->flags = 0; self->typ = NULL; self->const_val = NULL; - self->typ_version = + self->typ_version = 0; + self->typ_version_offset = 0; return self; } @@ -153,6 +156,12 @@ _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *ty } } +void +_Py_uop_sym_set_type_version(_Py_UopsContext *ctx, _Py_UopsSymbol *sym, int32_t version) +{ + sym->typ_version = version; +} + void _Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val) { @@ -257,6 +266,12 @@ _Py_uop_sym_get_type(_Py_UopsSymbol *sym) return sym->typ; } +int32_t +_Py_uop_sym_get_type_version(_Py_UopsSymbol *sym) +{ + return sym->typ_version; +} + bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym) { @@ -273,6 +288,13 @@ _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ) return _Py_uop_sym_get_type(sym) == typ; } +bool +_Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version) +{ + return _Py_uop_sym_get_type_version(sym) == version; +} + + int _Py_uop_sym_truthiness(_Py_UopsSymbol *sym) { From b8525bef8196d1ca4984a854d6ee432cf3b5d1fc Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 13:52:08 -0400 Subject: [PATCH 04/13] fix typo --- Python/optimizer_symbols.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index c5d197e2f323ff..2a56eb5d5f9fed 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -157,7 +157,7 @@ _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *ty } void -_Py_uop_sym_set_type_version(_Py_UopsContext *ctx, _Py_UopsSymbol *sym, int32_t version) +_Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, int32_t version) { sym->typ_version = version; } From 4bd1608802dae24e0fda2e6b2126f10d3d5d4e46 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 14:16:52 -0400 Subject: [PATCH 05/13] Add failing test case --- Lib/test/test_capi/test_opt.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 0491ff9b84d486..c8e749b7150453 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1333,6 +1333,27 @@ def test_modified_local_is_seen_by_optimized_code(self): self.assertIs(type(s), float) self.assertEqual(s, 1024.0) + def test_guard_type_version_removed(self): + def thing(a): + x = 0 + for _ in range(100): + x += a.attr + x += a.attr + return x + + class Foo: + attr = 1 + + res, ex = self._run_with_optimizer(thing, Foo()) + opnames = list(iter_opnames(ex)) + for i in iter_opnames(ex): + print(i) + + self.assertIsNotNone(ex) + self.assertEqual(res, 200) + guard_type_version_count = opnames.count("_GUARD_TYPE_VERSION") + self.assertEqual(guard_type_version_count, 1) + if __name__ == "__main__": unittest.main() From ddbfd9443c4c39463f6bdbbbc000992b383e7f1a Mon Sep 17 00:00:00 2001 From: parmeggiani Date: Mon, 20 May 2024 20:31:14 +0200 Subject: [PATCH 06/13] breakpoints and prints --- Lib/test/test_capi/test_opt.py | 2 ++ Python/optimizer_bytecodes.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index c8e749b7150453..9ec842862e54d9 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1344,6 +1344,8 @@ def thing(a): class Foo: attr = 1 + breakpoint() + res, ex = self._run_with_optimizer(thing, Foo()) opnames = list(iter_opnames(ex)) for i in iter_opnames(ex): diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index e87472c36be1a1..8a8158c3c50cf1 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -116,6 +116,7 @@ dummy_func(void) { } op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) { + printf("%d %d %d\n", type_version, owner->typ_version, owner->typ_version_offset); if (sym_matches_type_version(owner, type_version)) { REPLACE_OP(this_instr, _NOP, 0, 0); } @@ -711,6 +712,7 @@ dummy_func(void) { } op(_ITER_NEXT_RANGE, (iter -- iter, next)) { + printf("ciao"); next = sym_new_type(ctx, &PyLong_Type); (void)iter; } From f22130b0bffb11aaa7a66ff7056a798611ce395d Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 14:41:41 -0400 Subject: [PATCH 07/13] Add function definitions --- Include/internal/pycore_optimizer.h | 2 ++ Python/optimizer_analysis.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h index e19e416c25b0cd..138c202db8a58b 100644 --- a/Include/internal/pycore_optimizer.h +++ b/Include/internal/pycore_optimizer.h @@ -125,9 +125,11 @@ extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *con extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx); extern bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym); extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ); +extern bool _Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version); extern void _Py_uop_sym_set_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym); extern void _Py_uop_sym_set_non_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym); extern void _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *typ); +extern void _Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, int32_t version); extern void _Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val); extern bool _Py_uop_sym_is_bottom(_Py_UopsSymbol *sym); extern int _Py_uop_sym_truthiness(_Py_UopsSymbol *sym); diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index e5d3793bd4d204..047d1a6a8cf9f0 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -310,9 +310,11 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, #define sym_has_type _Py_uop_sym_has_type #define sym_get_type _Py_uop_sym_get_type #define sym_matches_type _Py_uop_sym_matches_type +#define sym_matches_type_version _Py_uop_sym_matches_type_version #define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM) #define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM) #define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE) +#define sym_set_type_version(SYM, VERSION) _Py_uop_sym_set_type_version(ctx, SYM, VERSION) #define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST) #define sym_is_bottom _Py_uop_sym_is_bottom #define sym_truthiness _Py_uop_sym_truthiness From 77bc293e6a959f8fca87a7d65acb47c8c079b4dd Mon Sep 17 00:00:00 2001 From: dpdani Date: Mon, 20 May 2024 21:31:24 +0200 Subject: [PATCH 08/13] wooohoooo --- Include/internal/pycore_optimizer.h | 7 ++++--- Lib/test/test_capi/test_opt.py | 27 +++++++++++++++++++++++++++ Python/optimizer_analysis.c | 8 +++++++- Python/optimizer_bytecodes.c | 6 +++--- Python/optimizer_cases.c.h | 9 +++++++++ Python/optimizer_symbols.c | 14 +++++++++++--- 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h index 138c202db8a58b..0aec3d7250d914 100644 --- a/Include/internal/pycore_optimizer.h +++ b/Include/internal/pycore_optimizer.h @@ -34,7 +34,7 @@ struct _Py_UopsSymbol { PyTypeObject *typ; // Borrowed reference PyObject *const_val; // Owned reference (!) int32_t typ_version; // currently stores type version - int32_t typ_version_offset; // bytecode offset where the last type version was set + int typ_version_offset; // bytecode offset where the last type version was set }; #define UOP_FORMAT_TARGET 0 @@ -98,6 +98,7 @@ struct _Py_UOpsContext { char done; char out_of_space; bool contradiction; + int64_t latest_escape_offset; // The current "executing" frame. _Py_UOpsAbstractFrame *frame; _Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH]; @@ -125,11 +126,11 @@ extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *con extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx); extern bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym); extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ); -extern bool _Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version); +extern bool _Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version, int offset); extern void _Py_uop_sym_set_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym); extern void _Py_uop_sym_set_non_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym); extern void _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *typ); -extern void _Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, int32_t version); +extern void _Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, int32_t version, int offset); extern void _Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val); extern bool _Py_uop_sym_is_bottom(_Py_UopsSymbol *sym); extern int _Py_uop_sym_truthiness(_Py_UopsSymbol *sym); diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 9ec842862e54d9..78208eff729a4c 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1356,6 +1356,33 @@ class Foo: guard_type_version_count = opnames.count("_GUARD_TYPE_VERSION") self.assertEqual(guard_type_version_count, 1) + def test_guard_type_version_not_removed(self): + def fn(): + pass + + def thing(a): + x = 0 + for _ in range(100): + x += a.attr + fn() + x += a.attr + return x + + class Foo: + attr = 1 + + breakpoint() + + res, ex = self._run_with_optimizer(thing, Foo()) + opnames = list(iter_opnames(ex)) + for i in iter_opnames(ex): + print(i) + + self.assertIsNotNone(ex) + self.assertEqual(res, 200) + guard_type_version_count = opnames.count("_GUARD_TYPE_VERSION") + self.assertEqual(guard_type_version_count, 2) + if __name__ == "__main__": unittest.main() diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index 047d1a6a8cf9f0..6d7736ed15bd22 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -314,7 +314,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, #define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM) #define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM) #define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE) -#define sym_set_type_version(SYM, VERSION) _Py_uop_sym_set_type_version(ctx, SYM, VERSION) +#define sym_set_type_version(SYM, VERSION, OFFSET) _Py_uop_sym_set_type_version(ctx, SYM, VERSION, OFFSET) #define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST) #define sym_is_bottom _Py_uop_sym_is_bottom #define sym_truthiness _Py_uop_sym_truthiness @@ -406,6 +406,7 @@ optimize_uops( ctx->done = false; ctx->out_of_space = false; ctx->contradiction = false; + ctx->latest_escape_offset = 0; _PyUOpInstruction *this_instr = NULL; for (int i = 0; !ctx->done; i++) { @@ -416,6 +417,11 @@ optimize_uops( opcode = this_instr->opcode; _Py_UopsSymbol **stack_pointer = ctx->frame->stack_pointer; + if (_PyUop_Flags[opcode] & HAS_ESCAPES_FLAG) { + printf("opcode: %d ", opcode); + ctx->latest_escape_offset = i; // i is the offset we're looping on + } + #ifdef Py_DEBUG if (get_lltrace() >= 3) { printf("%4d abs: ", (int)(this_instr - trace)); diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 8a8158c3c50cf1..980d6e4bf1dd84 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -27,7 +27,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame; #define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM) #define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM) #define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE) -#define sym_set_type_version(SYM, VERSION) _Py_uop_sym_set_type_version(ctx, SYM, VERSION) +#define sym_set_type_version(SYM, VERSION, OFFSET) _Py_uop_sym_set_type_version(ctx, SYM, VERSION, OFFSET) #define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST) #define sym_is_bottom _Py_uop_sym_is_bottom #define frame_new _Py_uop_frame_new @@ -117,10 +117,10 @@ dummy_func(void) { op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) { printf("%d %d %d\n", type_version, owner->typ_version, owner->typ_version_offset); - if (sym_matches_type_version(owner, type_version)) { + if (sym_matches_type_version(owner, type_version, ctx->latest_escape_offset)) { REPLACE_OP(this_instr, _NOP, 0, 0); } - sym_set_type_version(owner, type_version); + sym_set_type_version(owner, type_version, i); } op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) { diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index cd4431d55ad908..26e72ec4e7a987 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -935,6 +935,14 @@ } case _GUARD_TYPE_VERSION: { + _Py_UopsSymbol *owner; + owner = stack_pointer[-1]; + uint32_t type_version = (uint32_t)this_instr->operand; + printf("%d %d %d\n", type_version, owner->typ_version, owner->typ_version_offset); + if (sym_matches_type_version(owner, type_version, ctx->latest_escape_offset)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_type_version(owner, type_version, i); break; } @@ -1335,6 +1343,7 @@ _Py_UopsSymbol *iter; _Py_UopsSymbol *next; iter = stack_pointer[-1]; + printf("ciao"); next = sym_new_type(ctx, &PyLong_Type); (void)iter; stack_pointer[0] = next; diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 2a56eb5d5f9fed..47ccc908fcccdb 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -157,9 +157,10 @@ _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *ty } void -_Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, int32_t version) +_Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, int32_t version, int offset) { sym->typ_version = version; + sym->typ_version_offset = offset; } void @@ -272,6 +273,12 @@ _Py_uop_sym_get_type_version(_Py_UopsSymbol *sym) return sym->typ_version; } +int +_Py_uop_sym_get_type_version_offset(_Py_UopsSymbol *sym) +{ + return sym->typ_version_offset; +} + bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym) { @@ -289,9 +296,10 @@ _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ) } bool -_Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version) +_Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version, int offset) { - return _Py_uop_sym_get_type_version(sym) == version; + return _Py_uop_sym_get_type_version(sym) == version + && _Py_uop_sym_get_type_version_offset(sym) > offset; } From a2ebc49f8c385ae07f1ebaf890dc1272cbfcc787 Mon Sep 17 00:00:00 2001 From: dpdani Date: Mon, 20 May 2024 21:33:59 +0200 Subject: [PATCH 09/13] unprint --- Python/optimizer_analysis.c | 1 - Python/optimizer_bytecodes.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index 6d7736ed15bd22..75a8aa8f8573fe 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -418,7 +418,6 @@ optimize_uops( _Py_UopsSymbol **stack_pointer = ctx->frame->stack_pointer; if (_PyUop_Flags[opcode] & HAS_ESCAPES_FLAG) { - printf("opcode: %d ", opcode); ctx->latest_escape_offset = i; // i is the offset we're looping on } diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 980d6e4bf1dd84..c679f6b5674a59 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -116,7 +116,6 @@ dummy_func(void) { } op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) { - printf("%d %d %d\n", type_version, owner->typ_version, owner->typ_version_offset); if (sym_matches_type_version(owner, type_version, ctx->latest_escape_offset)) { REPLACE_OP(this_instr, _NOP, 0, 0); } @@ -712,7 +711,6 @@ dummy_func(void) { } op(_ITER_NEXT_RANGE, (iter -- iter, next)) { - printf("ciao"); next = sym_new_type(ctx, &PyLong_Type); (void)iter; } From e982837c15e0d846055a72c873279aedb1dfc1f1 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 15:35:33 -0400 Subject: [PATCH 10/13] Remove generated printf --- Python/optimizer_cases.c.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 26e72ec4e7a987..c4c820ba1d1e41 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -938,7 +938,6 @@ _Py_UopsSymbol *owner; owner = stack_pointer[-1]; uint32_t type_version = (uint32_t)this_instr->operand; - printf("%d %d %d\n", type_version, owner->typ_version, owner->typ_version_offset); if (sym_matches_type_version(owner, type_version, ctx->latest_escape_offset)) { REPLACE_OP(this_instr, _NOP, 0, 0); } @@ -1343,7 +1342,6 @@ _Py_UopsSymbol *iter; _Py_UopsSymbol *next; iter = stack_pointer[-1]; - printf("ciao"); next = sym_new_type(ctx, &PyLong_Type); (void)iter; stack_pointer[0] = next; From 0e7e7eb572d776d449fa7d64f51c879c734b88d6 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 15:35:44 -0400 Subject: [PATCH 11/13] Remove test breakpoints --- Lib/test/test_capi/test_opt.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 78208eff729a4c..07ec1f0ac2f22f 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1344,13 +1344,8 @@ def thing(a): class Foo: attr = 1 - breakpoint() - res, ex = self._run_with_optimizer(thing, Foo()) opnames = list(iter_opnames(ex)) - for i in iter_opnames(ex): - print(i) - self.assertIsNotNone(ex) self.assertEqual(res, 200) guard_type_version_count = opnames.count("_GUARD_TYPE_VERSION") @@ -1371,12 +1366,8 @@ def thing(a): class Foo: attr = 1 - breakpoint() - res, ex = self._run_with_optimizer(thing, Foo()) opnames = list(iter_opnames(ex)) - for i in iter_opnames(ex): - print(i) self.assertIsNotNone(ex) self.assertEqual(res, 200) From 4060ab8e64488cf236dbbf8c4230501e8767443c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 20:15:49 +0000 Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst new file mode 100644 index 00000000000000..1f744f95805a0f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst @@ -0,0 +1 @@ +Tier 2 optimizer eliminate type version guards From 1520928862135e8420e0cadbfc2a63ce07972f92 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 20 May 2024 16:55:29 -0400 Subject: [PATCH 13/13] =?UTF-8?q?Revert=20"=F0=9F=93=9C=F0=9F=A4=96=20Adde?= =?UTF-8?q?d=20by=20blurb=5Fit."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4060ab8e64488cf236dbbf8c4230501e8767443c --- .../2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst deleted file mode 100644 index 1f744f95805a0f..00000000000000 --- a/Misc/NEWS.d/next/Core and Builtins/2024-05-20-20-15-47.gh-issue-119258.6R2Vf4.rst +++ /dev/null @@ -1 +0,0 @@ -Tier 2 optimizer eliminate type version guards