From: Alex Zinenko Date: Thu, 10 Oct 2019 17:25:46 +0000 (-0700) Subject: Python bindings: export index_cast X-Git-Tag: llvmorg-11-init~1466^2~559 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea34c2a7a4eba46a1ab7d81ed6c6159b852510da;p=platform%2Fupstream%2Fllvm.git Python bindings: export index_cast We are now properly enforcing the absence of index elements in memrefs and tensors. Instead, users are expected to store sized integers and cast them to index type if necessary. Expose the respective operation to Python bindings. PiperOrigin-RevId: 273985856 --- diff --git a/mlir/bindings/python/pybind.cpp b/mlir/bindings/python/pybind.cpp index 3e4f5db..399adf4 100644 --- a/mlir/bindings/python/pybind.cpp +++ b/mlir/bindings/python/pybind.cpp @@ -692,6 +692,11 @@ PYBIND11_MODULE(pybind, m) { falseArguments); return PythonValueHandle(nullptr); }); + m.def("index_cast", + [](PythonValueHandle element, PythonType type) -> PythonValueHandle { + return ValueHandle::create( + element.value, Type::getFromOpaquePointer(type.type)); + }); m.def("select", [](PythonValueHandle condition, PythonValueHandle trueValue, PythonValueHandle falseValue) -> PythonValueHandle { diff --git a/mlir/bindings/python/test/test_py2and3.py b/mlir/bindings/python/test/test_py2and3.py index c658c94..12013b1 100644 --- a/mlir/bindings/python/test/test_py2and3.py +++ b/mlir/bindings/python/test/test_py2and3.py @@ -297,6 +297,15 @@ class EdscTest: # CHECK: func @foo_0() # CHECK: %{{.*}} = constant 0 : index + def testIndexCast(self): + self.setUp() + with self.module.function_context("testIndexCast", [], []): + index = E.constant_index(0) + E.index_cast(index, self.module.make_scalar_type("i", 32)) + printWithCurrentFunctionName(str(self.module)) + # CHECK-LABEL: testIndexCast + # CHECK: index_cast %{{.*}} : index to i32 + def testIndexedValue(self): self.setUp() memrefType = self.module.make_memref_type(self.f32Type, [10, 42])