From 3a73948ecc6b9211eee21748808d09e9ebbd53ea Mon Sep 17 00:00:00 2001 From: Nirvedh Meshram Date: Thu, 13 Nov 2025 10:54:39 -0800 Subject: [PATCH 1/3] [mlir][python] Fix ir.Value type to not break other types Signed-off-by: Nirvedh Meshram --- mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp index f01563fd49d17..d0a25149cfe2a 100644 --- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp +++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp @@ -437,7 +437,7 @@ static void emitElementAccessors( type = std::strcmp(kind, "operand") == 0 ? "_ods_ir.Value" : "_ods_ir.OpResult"; } - if (std::strcmp(kind, "operand") == 0) { + if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0) { StringRef pythonType = getPythonType(element.constraint.getCppType()); if (!pythonType.empty()) type += "[" + pythonType.str() + "]"; @@ -473,7 +473,7 @@ static void emitElementAccessors( if (!element.isVariableLength() || element.isOptional()) { type = std::strcmp(kind, "operand") == 0 ? "_ods_ir.Value" : "_ods_ir.OpResult"; - if (std::strcmp(kind, "operand") == 0) { + if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0) { StringRef pythonType = getPythonType(element.constraint.getCppType()); if (!pythonType.empty()) type += "[" + pythonType.str() + "]"; From ce590f4a4d679bb0be1ae6e173838583ea650e57 Mon Sep 17 00:00:00 2001 From: Nirvedh Meshram Date: Thu, 13 Nov 2025 12:14:42 -0800 Subject: [PATCH 2/3] also handle OpResult --- mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp index d0a25149cfe2a..fe6cf76d6d825 100644 --- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp +++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp @@ -437,7 +437,7 @@ static void emitElementAccessors( type = std::strcmp(kind, "operand") == 0 ? "_ods_ir.Value" : "_ods_ir.OpResult"; } - if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0) { + if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0 || std::strcmp(type.c_str(), "_ods_ir.OpResult") == 0) { StringRef pythonType = getPythonType(element.constraint.getCppType()); if (!pythonType.empty()) type += "[" + pythonType.str() + "]"; @@ -473,7 +473,7 @@ static void emitElementAccessors( if (!element.isVariableLength() || element.isOptional()) { type = std::strcmp(kind, "operand") == 0 ? "_ods_ir.Value" : "_ods_ir.OpResult"; - if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0) { + if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0 || std::strcmp(type.c_str(), "_ods_ir.OpResult") == 0) { StringRef pythonType = getPythonType(element.constraint.getCppType()); if (!pythonType.empty()) type += "[" + pythonType.str() + "]"; From 7f40a2c04b470c56bbe443b282e6e6f8f1c1eaed Mon Sep 17 00:00:00 2001 From: Nirvedh Meshram Date: Thu, 13 Nov 2025 12:16:29 -0800 Subject: [PATCH 3/3] also handle OpResult --- mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp index fe6cf76d6d825..2c33f4efac3ac 100644 --- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp +++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp @@ -437,7 +437,8 @@ static void emitElementAccessors( type = std::strcmp(kind, "operand") == 0 ? "_ods_ir.Value" : "_ods_ir.OpResult"; } - if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0 || std::strcmp(type.c_str(), "_ods_ir.OpResult") == 0) { + if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0 || + std::strcmp(type.c_str(), "_ods_ir.OpResult") == 0) { StringRef pythonType = getPythonType(element.constraint.getCppType()); if (!pythonType.empty()) type += "[" + pythonType.str() + "]"; @@ -473,7 +474,8 @@ static void emitElementAccessors( if (!element.isVariableLength() || element.isOptional()) { type = std::strcmp(kind, "operand") == 0 ? "_ods_ir.Value" : "_ods_ir.OpResult"; - if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0 || std::strcmp(type.c_str(), "_ods_ir.OpResult") == 0) { + if (std::strcmp(type.c_str(), "_ods_ir.Value") == 0 || + std::strcmp(type.c_str(), "_ods_ir.OpResult") == 0) { StringRef pythonType = getPythonType(element.constraint.getCppType()); if (!pythonType.empty()) type += "[" + pythonType.str() + "]";