[Mlir-commits] [mlir] [mlir][python] Expose AsmState python side. (PR #66819)

Jacques Pienaar llvmlistbot at llvm.org
Wed Sep 20 11:26:23 PDT 2023


================
@@ -3425,19 +3425,35 @@ void mlir::python::populateIRCore(py::module &m) {
           kValueDunderStrDocstring)
       .def(
           "get_name",
-          [](PyValue &self, bool useLocalScope) {
+          [](PyValue &self, std::optional<bool> useLocalScope,
+             std::optional<std::reference_wrapper<PyAsmState>> state) {
             PyPrintAccumulator printAccum;
-            MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
-            if (useLocalScope)
-              mlirOpPrintingFlagsUseLocalScope(flags);
-            MlirAsmState state = mlirAsmStateCreateForValue(self.get(), flags);
-            mlirValuePrintAsOperand(self.get(), state, printAccum.getCallback(),
+            MlirOpPrintingFlags flags;
+            MlirAsmState valueState;
+            // Use state if provided, else create a new state.
+            if (state) {
+              valueState = state.value().get().get();
+              // Don't allow setting using local scope and state at same time.
+              if (useLocalScope)
----------------
jpienaar wrote:

That is the intention though: this should check not the value of the flag, but whether it was set. Let me add has_value() to make that clearer.

https://github.com/llvm/llvm-project/pull/66819


More information about the Mlir-commits mailing list