[all-commits] [llvm/llvm-project] 429b0c: [mlir][python] Directly implement sequence protoco...

Stella Laurenzo via All-commits all-commits at lists.llvm.org
Mon Feb 14 09:45:42 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 429b0cf1de14471c9d258467bfc9936c3a9d52f7
      https://github.com/llvm/llvm-project/commit/429b0cf1de14471c9d258467bfc9936c3a9d52f7
  Author: Stella Laurenzo <stellaraccident at gmail.com>
  Date:   2022-02-14 (Mon, 14 Feb 2022)

  Changed paths:
    M mlir/lib/Bindings/Python/PybindUtils.h
    M mlir/test/python/ir/operation.py

  Log Message:
  -----------
  [mlir][python] Directly implement sequence protocol on Sliceable.

* While annoying, this is the only way to get C++ exception handling out of the happy path for normal iteration.
* Implements sq_length and sq_item for the sequence protocol (used for iteration, including list() construction).
* Implements mp_subscript for general use (i.e. foo[1] and foo[1:1]).
* For constructing a `list(op.results)`, this reduces the time from ~4-5us to ~1.5us on my machine (give or take measurement overhead) and eliminates C++ exceptions, which is a worthy goal in itself.
  * Compared to a baseline of similar construction of a three-integer list, which takes 450ns (might just be measuring function call overhead).
  * See issue discussed on the pybind side: https://github.com/pybind/pybind11/issues/2842

Differential Revision: https://reviews.llvm.org/D119691




More information about the All-commits mailing list