Skip to content

Code generator: support variable stack effects in macros #106812

Closed

Description

@gvanrossum

Currently you can't split e.g.

inst(CALL_PY_EXACT_ARGS, (unused/1, func_version/2, method, callable, args[oparg] -- unused))
{ ... }

into two micro-ops

op(_CHECK_PY_FUNCTION, (func_version/2, method, callable, args[oparg] -- method, callable, args[oparg]))
{ ... }
op(_CALL_PY_EXACT_ARGS, (method, callable, args[oparg] -- unused))
{ ... }
macro(CALL_PY_EXACT_ARGS) = unused/1 + _CHECK_PY_FUNCTION + _CALL_PY_EXACT_ARGS;

We need at least to handle micro-ops that have the same variable-length input effect as output effect, and a final (action) op that has a variable-length stack input effect and a fixed output effect. This should handle all the CALL specializations. (For UNPACK_SEQUENCE we also need to support a fixed input effect and a variable output effect, in he action op.)

Linked PRs

Activity

  1. gvanrossum commented on Jul 19, 2023

    @gvanrossum
    MemberAuthor

    This is turning into a bit of a research project. I would like to refactor all the handling of stack effects in the generator.

    I'm thinking of having an algorithm that takes a sequence of operations such as pop/push, peek/poke, shrink/grow, and copy, and which applies certain transformations (e.g. push+pop can be replaced by copy under certain conditions), trying to reach an optimal end state, which can then be turned into optimal C code.

    But the right set of operations, transformations and conditions is still elusive.

  2. added a commit that references this issue on Aug 4, 2023
  3. added 2 commits that reference this issue on Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions