Skip to content
Prev Previous commit
Next Next commit
Replace ENTER_EXECUTOR with the original in trace projection
  • Loading branch information
gvanrossum committed Jul 7, 2023
commit 28b3951b4b4a8039ca4f0ee01b76b4772182903b
6 changes: 6 additions & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ translate_bytecode_to_trace(
opcode = instr->op.code;
operand = (operand << 8) | instr->op.arg;
}
if (opcode == ENTER_EXECUTOR) {
_PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[operand&255];
opcode = executor->vm_data.opcode;
DPRINTF(2, " * ENTER_EXECUTOR -> %s\n", _PyOpcode_OpName[opcode]);
operand = (operand & 0xffffff00) | executor->vm_data.oparg;
}
switch (opcode) {
case LOAD_FAST_LOAD_FAST:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than special case individual instructions, can we test on flags?
That way, this will continue to work if we add LOAD_FAST_LOAD_CONST.
Something like if (_Py_OpcodeMetadata[opcode].is_super_instruction)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do something where the code generator encodes this in the size field of the expansions, in the switch (currently) at line 405 below. E.g. -1 means operand >> 4 and -2 means operand & 0xF. Should probably switch to an enum. The generator would have to work a little harder but that seems doable (e.g. it could detect the use of oparg1 and oparg2 and then parse the instruction name into two pieces).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work, although I was thinking of the dumber approach of just annotating LOAD_FAST_LOAD_FAST, etc as a superinstruction in bytecodes.c. Something like adding /* superinstruction */

case STORE_FAST_LOAD_FAST:
Expand Down