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

Was using a local, pseudo overload rather than just using an overload proper.
This commit is contained in:
Jacques Pienaar
2023-10-02 21:17:49 -07:00
parent ef9666aa81
commit f1dbfcc14d

View File

@@ -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());
// Release state if allocated locally.
if (!state) {
mlirOpPrintingFlagsDestroy(flags);
mlirAsmStateDestroy(valueState);
}
mlirOpPrintingFlagsDestroy(flags);
mlirAsmStateDestroy(valueState);
return printAccum.join();
},
py::arg("use_local_scope") = std::nullopt,
py::arg("state") = std::nullopt, kGetNameAsOperand)
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());
return printAccum.join();
},
py::arg("state"), kGetNameAsOperand)
.def_property_readonly(
"type", [](PyValue &self) { return mlirValueGetType(self.get()); })
.def(