Skip to content

Commit f1dbfcc

Browse files
committed
[mlir][py] Use overloads instead (NFC)
Was using a local, pseudo overload rather than just using an overload proper.
1 parent ef9666a commit f1dbfcc

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,36 +3488,32 @@ void mlir::python::populateIRCore(py::module &m) {
34883488
kValueDunderStrDocstring)
34893489
.def(
34903490
"get_name",
3491-
[](PyValue &self, std::optional<bool> useLocalScope,
3492-
std::optional<std::reference_wrapper<PyAsmState>> state) {
3491+
[](PyValue &self, bool useLocalScope) {
34933492
PyPrintAccumulator printAccum;
3494-
MlirOpPrintingFlags flags;
3495-
MlirAsmState valueState;
3496-
// Use state if provided, else create a new state.
3497-
if (state) {
3498-
valueState = state.value().get().get();
3499-
// Don't allow setting using local scope and state at same time.
3500-
if (useLocalScope.has_value())
3501-
throw py::value_error(
3502-
"setting AsmState and local scope together not supported");
3503-
} else {
3504-
flags = mlirOpPrintingFlagsCreate();
3505-
if (useLocalScope.value_or(false))
3506-
mlirOpPrintingFlagsUseLocalScope(flags);
3507-
valueState = mlirAsmStateCreateForValue(self.get(), flags);
3508-
}
3493+
MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
3494+
if (useLocalScope)
3495+
mlirOpPrintingFlagsUseLocalScope(flags);
3496+
MlirAsmState valueState =
3497+
mlirAsmStateCreateForValue(self.get(), flags);
3498+
mlirValuePrintAsOperand(self.get(), valueState,
3499+
printAccum.getCallback(),
3500+
printAccum.getUserData());
3501+
mlirOpPrintingFlagsDestroy(flags);
3502+
mlirAsmStateDestroy(valueState);
3503+
return printAccum.join();
3504+
},
3505+
py::arg("use_local_scope") = false)
3506+
.def(
3507+
"get_name",
3508+
[](PyValue &self, std::reference_wrapper<PyAsmState> state) {
3509+
PyPrintAccumulator printAccum;
3510+
MlirAsmState valueState = state.get().get();
35093511
mlirValuePrintAsOperand(self.get(), valueState,
35103512
printAccum.getCallback(),
35113513
printAccum.getUserData());
3512-
// Release state if allocated locally.
3513-
if (!state) {
3514-
mlirOpPrintingFlagsDestroy(flags);
3515-
mlirAsmStateDestroy(valueState);
3516-
}
35173514
return printAccum.join();
35183515
},
3519-
py::arg("use_local_scope") = std::nullopt,
3520-
py::arg("state") = std::nullopt, kGetNameAsOperand)
3516+
py::arg("state"), kGetNameAsOperand)
35213517
.def_property_readonly(
35223518
"type", [](PyValue &self) { return mlirValueGetType(self.get()); })
35233519
.def(

0 commit comments

Comments
 (0)