summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index b67264f..cf089c3 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -148,6 +148,8 @@ dummy_func(
RESUME_CHECK,
};
+ macro(NOT_TAKEN) = NOP;
+
op(_CHECK_PERIODIC, (--)) {
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY();
QSBR_QUIESCENT_STATE(tstate);
@@ -2723,7 +2725,7 @@ dummy_func(
int flag = PyStackRef_IsFalse(cond);
DEAD(cond);
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- JUMPBY(oparg * flag);
+ JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
}
replaced op(_POP_JUMP_IF_TRUE, (cond -- )) {
@@ -2731,7 +2733,7 @@ dummy_func(
int flag = PyStackRef_IsTrue(cond);
DEAD(cond);
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
- JUMPBY(oparg * flag);
+ JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
}
op(_IS_NONE, (value -- b)) {
@@ -2923,13 +2925,11 @@ dummy_func(
macro(FOR_ITER) = _SPECIALIZE_FOR_ITER + _FOR_ITER;
inst(INSTRUMENTED_FOR_ITER, (unused/1 -- )) {
- _Py_CODEUNIT *target;
_PyStackRef iter_stackref = TOP();
PyObject *iter = PyStackRef_AsPyObjectBorrow(iter_stackref);
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
if (next != NULL) {
PUSH(PyStackRef_FromPyObjectSteal(next));
- target = next_instr;
}
else {
if (_PyErr_Occurred(tstate)) {
@@ -2946,9 +2946,9 @@ dummy_func(
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);
}
op(_ITER_CHECK_LIST, (iter -- iter)) {
@@ -4736,6 +4736,10 @@ dummy_func(
INSTRUMENTED_JUMP(this_instr, next_instr - oparg, PY_MONITORING_EVENT_JUMP);
}
+ inst(INSTRUMENTED_NOT_TAKEN, ( -- )) {
+ INSTRUMENTED_JUMP(this_instr, next_instr, PY_MONITORING_EVENT_BRANCH_LEFT);
+ }
+
macro(INSTRUMENTED_JUMP_BACKWARD) =
unused/1 +
_CHECK_PERIODIC +
@@ -4744,51 +4748,43 @@ dummy_func(
inst(INSTRUMENTED_POP_JUMP_IF_TRUE, (unused/1 -- )) {
_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);
+ }
}
inst(INSTRUMENTED_POP_JUMP_IF_FALSE, (unused/1 -- )) {
_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);
+ }
}
inst(INSTRUMENTED_POP_JUMP_IF_NONE, (unused/1 -- )) {
_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);
}
inst(INSTRUMENTED_POP_JUMP_IF_NOT_NONE, (unused/1 -- )) {
_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);
}
tier1 inst(EXTENDED_ARG, ( -- )) {