xref: /llvm-project/mlir/test/python/dialects/complex_dialect.py (revision f9008e6366c2496b1ca1785b891d5578174ad63e)
1# RUN: %PYTHON %s | FileCheck %s
2
3# Naming this file with a `_dialect` suffix to avoid a naming conflict with
4# python package's math module (coming in from random.py).
5
6from mlir.ir import *
7import mlir.dialects.func as func
8import mlir.dialects.complex as mlir_complex
9
10
11def run(f):
12    print("\nTEST:", f.__name__)
13    f()
14
15
16# CHECK-LABEL: TEST: testComplexOps
17@run
18def testComplexOps():
19    with Context() as ctx, Location.unknown():
20        module = Module.create()
21        with InsertionPoint(module.body):
22
23            @func.FuncOp.from_py_func(ComplexType.get(F32Type.get()))
24            def emit_add(arg):
25                return mlir_complex.AddOp(arg, arg)
26
27        # CHECK-LABEL: func @emit_add(
28        # CHECK-SAME:                  %[[ARG:.*]]: complex<f32>) -> complex<f32> {
29        # CHECK:         %[[RES:.*]] = complex.add %[[ARG]], %[[ARG]] : complex<f32>
30        # CHECK:         return %[[RES]] : complex<f32>
31        # CHECK:       }
32        print(module)
33