summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorKen Jin <kenjin@python.org>2024-03-06 19:30:11 (GMT)
committerGitHub <noreply@github.com>2024-03-06 19:30:11 (GMT)
commit7114cf20c015b99123b32c1ba4f5475b7a6c3a13 (patch)
tree1c5392c31ac5d921cfb0b5856ff2df66cdfd4682 /Python/specialize.c
parent73807eb634315f70a464a18feaae33d9e065de09 (diff)
downloadcpython-7114cf20c015b99123b32c1ba4f5475b7a6c3a13.zip
cpython-7114cf20c015b99123b32c1ba4f5475b7a6c3a13.tar.gz
cpython-7114cf20c015b99123b32c1ba4f5475b7a6c3a13.tar.bz2
gh-116381: Specialize CONTAINS_OP (GH-116385)
* Specialize CONTAINS_OP * 📜🤖 Added by blurb_it. * Add PyAPI_FUNC for JIT --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index f83d8a9..5d339b8 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -103,6 +103,7 @@ _Py_GetSpecializationStats(void) {
return NULL;
}
int err = 0;
+ err += add_stat_dict(stats, CONTAINS_OP, "contains_op");
err += add_stat_dict(stats, LOAD_SUPER_ATTR, "load_super_attr");
err += add_stat_dict(stats, LOAD_ATTR, "load_attr");
err += add_stat_dict(stats, LOAD_GLOBAL, "load_global");
@@ -2561,6 +2562,43 @@ success:
cache->counter = adaptive_counter_cooldown();
}
+void
+_Py_Specialize_ContainsOp(PyObject *value, _Py_CODEUNIT *instr)
+{
+ assert(ENABLE_SPECIALIZATION);
+ assert(_PyOpcode_Caches[CONTAINS_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
+ _PyContainsOpCache *cache = (_PyContainsOpCache *)(instr + 1);
+ if (PyUnicode_CheckExact(value)) {
+ instr->op.code = CONTAINS_OP_STR;
+ goto success;
+ }
+ if (PyList_CheckExact(value)) {
+ instr->op.code = CONTAINS_OP_LIST;
+ goto success;
+ }
+ if (PyTuple_CheckExact(value)) {
+ instr->op.code = CONTAINS_OP_TUPLE;
+ goto success;
+ }
+ if (PyDict_CheckExact(value)) {
+ instr->op.code = CONTAINS_OP_DICT;
+ goto success;
+ }
+ if (PySet_CheckExact(value)) {
+ instr->op.code = CONTAINS_OP_SET;
+ goto success;
+ }
+
+
+ STAT_INC(CONTAINS_OP, failure);
+ instr->op.code = CONTAINS_OP;
+ cache->counter = adaptive_counter_backoff(cache->counter);
+ return;
+success:
+ STAT_INC(CONTAINS_OP, success);
+ cache->counter = adaptive_counter_cooldown();
+}
+
/* Code init cleanup.
* CALL_ALLOC_AND_ENTER_INIT will set up
* the frame to execute the EXIT_INIT_CHECK