[Mlir-commits] [mlir] f1dbfcc - [mlir][py] Use overloads instead (NFC)

Jacques Pienaar llvmlistbot at llvm.org
Mon Oct 2 21:17:58 PDT 2023


Author: Jacques Pienaar
Date: 2023-10-02T21:17:49-07:00
New Revision: f1dbfcc14d68a1a089bd0398263ea2719800dc86

URL: https://github.com/llvm/llvm-project/commit/f1dbfcc14d68a1a089bd0398263ea2719800dc86
DIFF: https://github.com/llvm/llvm-project/commit/f1dbfcc14d68a1a089bd0398263ea2719800dc86.diff

LOG: [mlir][py] Use overloads instead (NFC)

Was using a local, pseudo overload rather than just using an overload proper.

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/IRCore.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 84f980d79beebf6..c8373e06f0db776 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -3488,36 +3488,32 @@ void mlir::python::populateIRCore(py::module &m) {
           kValueDunderStrDocstring)
       .def(
           "get_name",
-          [](PyValue &self, std::optional<bool> useLocalScope,
-             std::optional<std::reference_wrapper<PyAsmState>> state) {
+          [](PyValue &self, bool useLocalScope) {
             PyPrintAccumulator printAccum;
-            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.has_value())
-                throw py::value_error(
-                    "setting AsmState and local scope together not supported");
-            } else {
-              flags = mlirOpPrintingFlagsCreate();
-              if (useLocalScope.value_or(false))
-                mlirOpPrintingFlagsUseLocalScope(flags);
-              valueState = mlirAsmStateCreateForValue(self.get(), flags);
-            }
+            MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
+            if (useLocalScope)
+              mlirOpPrintingFlagsUseLocalScope(flags);
+            MlirAsmState valueState =
+                mlirAsmStateCreateForValue(self.get(), flags);
+            mlirValuePrintAsOperand(self.get(), valueState,
+                                    printAccum.getCallback(),
+                                    printAccum.getUserData());
+            mlirOpPrintingFlagsDestroy(flags);
+            mlirAsmStateDestroy(valueState);
+            return printAccum.join();
+          },
+          py::arg("use_local_scope") = false)
+      .def(
+          "get_name",
+          [](PyValue &self, std::reference_wrapper<PyAsmState> state) {
+            PyPrintAccumulator printAccum;
+            MlirAsmState valueState = state.get().get();
             mlirValuePrintAsOperand(self.get(), valueState,
                                     printAccum.getCallback(),
                                     printAccum.getUserData());
-            // Release state if allocated locally.
-            if (!state) {
-              mlirOpPrintingFlagsDestroy(flags);
-              mlirAsmStateDestroy(valueState);
-            }
             return printAccum.join();
           },
-          py::arg("use_local_scope") = std::nullopt,
-          py::arg("state") = std::nullopt, kGetNameAsOperand)
+          py::arg("state"), kGetNameAsOperand)
       .def_property_readonly(
           "type", [](PyValue &self) { return mlirValueGetType(self.get()); })
       .def(


        


More information about the Mlir-commits mailing list