test_pass_basic.py 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
tqchen committed
17 18
import tvm

19
def test_simplify():
20
  x = tvm.var('x')
21 22 23 24 25 26 27 28
  e1 = tvm.ir_pass.Simplify(x + 2 + 1)
  assert(tvm.ir_pass.Equal(e1, x + 3))
  e2 = tvm.ir_pass.Simplify(x * 3 + 5 * x)
  assert(tvm.ir_pass.Equal(e2, x * 8))
  e3 = tvm.ir_pass.Simplify(x - x / 3 * 3)
  assert(tvm.ir_pass.Equal(e3, tvm.make.Mod(x, 3)))


tqchen committed
29
def test_verify_ssa():
30 31
    x = tvm.var('x')
    y = tvm.var()
tqchen committed
32 33 34 35 36
    z = tvm.make.Evaluate(x + y)
    assert(tvm.ir_pass.VerifySSA(z))


def test_convert_ssa():
37 38
    x = tvm.var('x')
    y = tvm.var()
39 40 41
    let1 = tvm.make.Let(x, 1, x + 1)
    let2 = tvm.make.Let(x, 1, x + y)
    z = tvm.make.Evaluate(let1 + let2)
tqchen committed
42 43 44
    assert(not tvm.ir_pass.VerifySSA(z))
    z_ssa = tvm.ir_pass.ConvertSSA(z)
    assert(tvm.ir_pass.VerifySSA(z_ssa))
45 46 47


def test_expr_use_var():
48
    x = tvm.var('x')
49 50 51 52 53 54
    assert(tvm.ir_pass.ExprUseVar(x+1, x))
    assert(not tvm.ir_pass.ExprUseVar(1+10, x))


if __name__ == "__main__":
    test_expr_use_var()