aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bindings/Python
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Bindings/Python')
-rw-r--r--mlir/lib/Bindings/Python/DialectLLVM.cpp13
-rw-r--r--mlir/lib/Bindings/Python/IRAttributes.cpp4
2 files changed, 16 insertions, 1 deletions
diff --git a/mlir/lib/Bindings/Python/DialectLLVM.cpp b/mlir/lib/Bindings/Python/DialectLLVM.cpp
index 38de4a0..870a713 100644
--- a/mlir/lib/Bindings/Python/DialectLLVM.cpp
+++ b/mlir/lib/Bindings/Python/DialectLLVM.cpp
@@ -11,6 +11,7 @@
#include "mlir-c/Dialect/LLVM.h"
#include "mlir-c/IR.h"
#include "mlir-c/Support.h"
+#include "mlir-c/Target/LLVMIR.h"
#include "mlir/Bindings/Python/Diagnostics.h"
#include "mlir/Bindings/Python/Nanobind.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
@@ -24,7 +25,7 @@ using namespace mlir;
using namespace mlir::python;
using namespace mlir::python::nanobind_adaptors;
-static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
+static void populateDialectLLVMSubmodule(nanobind::module_ &m) {
//===--------------------------------------------------------------------===//
// StructType
@@ -154,6 +155,16 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
.def_property_readonly("address_space", [](MlirType type) {
return mlirLLVMPointerTypeGetAddressSpace(type);
});
+
+ m.def(
+ "translate_module_to_llvmir",
+ [](MlirOperation module) {
+ return mlirTranslateModuleToLLVMIRToString(module);
+ },
+ // clang-format off
+ nb::sig("def translate_module_to_llvmir(module: " MAKE_MLIR_PYTHON_QUALNAME("ir.Operation") ") -> str"),
+ // clang-format on
+ "module"_a, nb::rv_policy::take_ownership);
}
NB_MODULE(_mlirDialectsLLVM, m) {
diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index 045c0fb..c0a945e 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -1306,6 +1306,10 @@ PyType_Slot PyDenseElementsAttribute::slots[] = {
e.restore();
nb::chain_error(PyExc_BufferError, "Error converting attribute to buffer");
return -1;
+ } catch (std::exception &e) {
+ nb::chain_error(PyExc_BufferError,
+ "Error converting attribute to buffer: %s", e.what());
+ return -1;
}
view->obj = obj;
view->ndim = 1;