[Mlir-commits] [mlir] [mlir][python] Expose `PyInsertionPoint`'s reference operation (PR #69082)

Tomás Longeri llvmlistbot at llvm.org
Sun Oct 15 22:28:48 PDT 2023


https://github.com/tlongeri updated https://github.com/llvm/llvm-project/pull/69082

>From 5a6943873b92bd523b99b58089ee65a9af4b95ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1s=20Longeri?= <tlongeri at google.com>
Date: Fri, 13 Oct 2023 23:15:43 +0000
Subject: [PATCH] [mlir][python] Expose PyInsertionPoint's reference operation

---
 mlir/lib/Bindings/Python/IRCore.cpp | 8 +++++++-
 mlir/lib/Bindings/Python/IRModule.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index c8373e06f0db776..4d86ab2d9583834 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -3207,7 +3207,13 @@ void mlir::python::populateIRCore(py::module &m) {
            "Inserts an operation.")
       .def_property_readonly(
           "block", [](PyInsertionPoint &self) { return self.getBlock(); },
-          "Returns the block that this InsertionPoint points to.");
+          "Returns the block that this InsertionPoint points to.")
+      .def_property_readonly(
+          "ref_operation",
+          [](PyInsertionPoint &self) { return self.getRefOperation(); },
+          "The reference operation before which new operations are "
+          "inserted, or None if the insertion point is at the end of "
+          "the block");
 
   //----------------------------------------------------------------------------
   // Mapping of PyAttribute.
diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h
index 3ca7dd851961a46..c5412e735dddcb5 100644
--- a/mlir/lib/Bindings/Python/IRModule.h
+++ b/mlir/lib/Bindings/Python/IRModule.h
@@ -833,6 +833,7 @@ class PyInsertionPoint {
                    const pybind11::object &excTb);
 
   PyBlock &getBlock() { return block; }
+  std::optional<PyOperationRef> &getRefOperation() { return refOperation; }
 
 private:
   // Trampoline constructor that avoids null initializing members while



More information about the Mlir-commits mailing list