2021-06-10 19:00:34 +02:00
|
|
|
# RUN: %PYTHON %s | FileCheck %s
|
|
|
|
|
|
2021-11-25 08:56:19 +05:30
|
|
|
# Naming this file with a `_dialect` suffix to avoid a naming conflict with
|
|
|
|
|
# python package's math module (coming in from random.py).
|
|
|
|
|
|
2021-06-10 19:00:34 +02:00
|
|
|
from mlir.ir import *
|
2022-03-07 19:16:03 -08:00
|
|
|
import mlir.dialects.func as func
|
2021-06-10 19:00:34 +02:00
|
|
|
import mlir.dialects.math as mlir_math
|
|
|
|
|
|
2023-05-17 16:53:39 +02:00
|
|
|
|
2021-06-10 19:00:34 +02:00
|
|
|
def run(f):
|
|
|
|
|
print("\nTEST:", f.__name__)
|
|
|
|
|
f()
|
2023-05-17 16:53:39 +02:00
|
|
|
|
2021-06-10 19:00:34 +02:00
|
|
|
|
|
|
|
|
# CHECK-LABEL: TEST: testMathOps
|
|
|
|
|
@run
|
|
|
|
|
def testMathOps():
|
|
|
|
|
with Context() as ctx, Location.unknown():
|
|
|
|
|
module = Module.create()
|
|
|
|
|
with InsertionPoint(module.body):
|
2023-05-17 16:53:39 +02:00
|
|
|
|
2022-03-07 19:16:03 -08:00
|
|
|
@func.FuncOp.from_py_func(F32Type.get())
|
2021-06-10 19:00:34 +02:00
|
|
|
def emit_sqrt(arg):
|
2021-10-14 17:19:06 +02:00
|
|
|
return mlir_math.SqrtOp(arg)
|
2023-05-17 16:53:39 +02:00
|
|
|
|
2021-06-10 19:00:34 +02:00
|
|
|
# CHECK-LABEL: func @emit_sqrt(
|
2021-10-20 19:51:52 +00:00
|
|
|
# CHECK-SAME: %[[ARG:.*]]: f32) -> f32 {
|
2021-06-10 19:00:34 +02:00
|
|
|
# CHECK: math.sqrt %[[ARG]] : f32
|
|
|
|
|
# CHECK: return
|
|
|
|
|
# CHECK: }
|
|
|
|
|
print(module)
|