summaryrefslogtreecommitdiffstats
path: root/Python/generated_cases.c.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-12-19 16:59:51 (GMT)
committerGitHub <noreply@github.com>2024-12-19 16:59:51 (GMT)
commitd2f1d917e8b3d2dd8f35495c7632a32688883332 (patch)
tree334558f483e0f41d80924973d16b68354bf95b82 /Python/generated_cases.c.h
parent7b811d0562a0bf7433165785f1549ac199610f8b (diff)
downloadcpython-d2f1d917e8b3d2dd8f35495c7632a32688883332.zip
cpython-d2f1d917e8b3d2dd8f35495c7632a32688883332.tar.gz
cpython-d2f1d917e8b3d2dd8f35495c7632a32688883332.tar.bz2
GH-122548: Implement branch taken and not taken events for sys.monitoring (GH-122564)
Diffstat (limited to 'Python/generated_cases.c.h')
-rw-r--r--Python/generated_cases.c.h74
1 files changed, 40 insertions, 34 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 8a89ba8..ac89891 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -4618,7 +4618,6 @@
next_instr += 2;
INSTRUCTION_STATS(INSTRUMENTED_FOR_ITER);
/* Skip 1 cache entry */
- _Py_CODEUNIT *target;
_PyStackRef iter_stackref = TOP();
PyObject *iter = PyStackRef_AsPyObjectBorrow(iter_stackref);
_PyFrame_SetStackPointer(frame, stack_pointer);
@@ -4626,7 +4625,6 @@
stack_pointer = _PyFrame_GetStackPointer(frame);
if (next != NULL) {
PUSH(PyStackRef_FromPyObjectSteal(next));
- target = next_instr;
}
else {
if (_PyErr_Occurred(tstate)) {
@@ -4647,9 +4645,9 @@
STACK_SHRINK(1);
PyStackRef_CLOSE(iter_stackref);
/* Skip END_FOR and POP_TOP */
- target = next_instr + oparg + 2;
+ _Py_CODEUNIT *target = next_instr + oparg + 2;
+ INSTRUMENTED_JUMP(this_instr, target, PY_MONITORING_EVENT_BRANCH_RIGHT);
}
- INSTRUMENTED_JUMP(this_instr, target, PY_MONITORING_EVENT_BRANCH);
DISPATCH();
}
@@ -4754,6 +4752,15 @@
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
}
+ TARGET(INSTRUMENTED_NOT_TAKEN) {
+ _Py_CODEUNIT* const this_instr = frame->instr_ptr = next_instr;
+ (void)this_instr;
+ next_instr += 1;
+ INSTRUCTION_STATS(INSTRUMENTED_NOT_TAKEN);
+ INSTRUMENTED_JUMP(this_instr, next_instr, PY_MONITORING_EVENT_BRANCH_LEFT);
+ DISPATCH();
+ }
+
TARGET(INSTRUMENTED_POP_JUMP_IF_FALSE) {
_Py_CODEUNIT* const this_instr = frame->instr_ptr = next_instr;
(void)this_instr;
@@ -4762,10 +4769,11 @@
/* Skip 1 cache entry */
_PyStackRef cond = POP();
assert(PyStackRef_BoolCheck(cond));
- int flag = PyStackRef_IsFalse(cond);
- int offset = flag * oparg;
- RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
+ int jump = PyStackRef_IsFalse(cond);
+ RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
+ if (jump) {
+ INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
+ }
DISPATCH();
}
@@ -4776,17 +4784,14 @@
INSTRUCTION_STATS(INSTRUMENTED_POP_JUMP_IF_NONE);
/* Skip 1 cache entry */
_PyStackRef value_stackref = POP();
- int flag = PyStackRef_IsNone(value_stackref);
- int offset;
- if (flag) {
- offset = oparg;
+ int jump = PyStackRef_IsNone(value_stackref);
+ RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
+ if (jump) {
+ INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
}
else {
PyStackRef_CLOSE(value_stackref);
- offset = 0;
}
- RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
DISPATCH();
}
@@ -4797,19 +4802,12 @@
INSTRUCTION_STATS(INSTRUMENTED_POP_JUMP_IF_NOT_NONE);
/* Skip 1 cache entry */
_PyStackRef value_stackref = POP();
- int offset;
- int nflag = PyStackRef_IsNone(value_stackref);
- if (nflag) {
- offset = 0;
- }
- else {
+ int jump = !PyStackRef_IsNone(value_stackref);
+ RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
+ if (jump) {
PyStackRef_CLOSE(value_stackref);
- offset = oparg;
+ INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
}
- #if ENABLE_SPECIALIZATION
- this_instr[1].cache = (this_instr[1].cache << 1) | !nflag;
- #endif
- INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
DISPATCH();
}
@@ -4821,10 +4819,11 @@
/* Skip 1 cache entry */
_PyStackRef cond = POP();
assert(PyStackRef_BoolCheck(cond));
- int flag = PyStackRef_IsTrue(cond);
- int offset = flag * oparg;
- RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
+ int jump = PyStackRef_IsTrue(cond);
+ RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
+ if (jump) {
+ INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
+ }
DISPATCH();
}
@@ -6659,6 +6658,13 @@
DISPATCH();
}
+ TARGET(NOT_TAKEN) {
+ frame->instr_ptr = next_instr;
+ next_instr += 1;
+ INSTRUCTION_STATS(NOT_TAKEN);
+ DISPATCH();
+ }
+
TARGET(POP_EXCEPT) {
frame->instr_ptr = next_instr;
next_instr += 1;
@@ -6687,7 +6693,7 @@
assert(PyStackRef_BoolCheck(cond));
int flag = PyStackRef_IsFalse(cond);
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- JUMPBY(oparg * flag);
+ JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@@ -6719,7 +6725,7 @@
assert(PyStackRef_BoolCheck(cond));
int flag = PyStackRef_IsTrue(cond);
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- JUMPBY(oparg * flag);
+ JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
}
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
@@ -6752,7 +6758,7 @@
assert(PyStackRef_BoolCheck(cond));
int flag = PyStackRef_IsFalse(cond);
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- JUMPBY(oparg * flag);
+ JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
}
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
@@ -6770,7 +6776,7 @@
assert(PyStackRef_BoolCheck(cond));
int flag = PyStackRef_IsTrue(cond);
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- JUMPBY(oparg * flag);
+ JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
DISPATCH();