diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt --- a/mlir/python/CMakeLists.txt +++ b/mlir/python/CMakeLists.txt @@ -46,6 +46,14 @@ # Dialect bindings ################################################################################ +declare_mlir_dialect_python_bindings( + ADD_TO_PARENT MLIRPythonSources.Dialects + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir" + TD_FILE dialects/AffineOps.td + SOURCES + dialects/affine.py + DIALECT_NAME affine) + declare_mlir_dialect_python_bindings( ADD_TO_PARENT MLIRPythonSources.Dialects ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir" diff --git a/mlir/python/mlir/dialects/AffineOps.td b/mlir/python/mlir/dialects/AffineOps.td new file mode 100644 --- /dev/null +++ b/mlir/python/mlir/dialects/AffineOps.td @@ -0,0 +1,15 @@ +//===-- AffineOps.td - Entry point for AffineOps bindings ---------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_AFFINE_OPS +#define PYTHON_BINDINGS_AFFINE_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "mlir/Dialect/Affine/IR/AffineOps.td" + +#endif diff --git a/mlir/python/mlir/dialects/affine.py b/mlir/python/mlir/dialects/affine.py new file mode 100644 --- /dev/null +++ b/mlir/python/mlir/dialects/affine.py @@ -0,0 +1,5 @@ +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +from ._affine_ops_gen import * diff --git a/mlir/test/python/dialects/affine_dialect.py b/mlir/test/python/dialects/affine_dialect.py new file mode 100644 --- /dev/null +++ b/mlir/test/python/dialects/affine_dialect.py @@ -0,0 +1,32 @@ +# RUN: %PYTHON %s | FileCheck %s + +from mlir.ir import * +from mlir.dialects import arith +import mlir.dialects.affine as affine + + +def run(f): + print("\nTEST:", f.__name__) + f() + + +# CHECK-LABEL: TEST: testAffineOp +@run +def testAffineOp(): + with Context() as ctx, Location.unknown(): + module = Module.parse(r""" + func.func @emit_affine(%arg0: memref) { + return + } + """) + f = module.body.operations[0] + func_body = f.regions[0].blocks[0] + with InsertionPoint.at_block_terminator(func_body): + affine.AffineLoadOp(F32Type.get(), f.arguments[0], []) + + # CHECK-LABEL: func @emit_affine( + # CHECK-SAME: %[[ARG:.*]]: memref) { + # CHECK: %[[RES:.*]] = affine.load %[[ARG]][] : memref + # CHECK: return + # CHECK: } + print(module)