ir_visitor_test.cc 556 Bytes
Newer Older
tqchen committed
1 2 3 4
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <tvm/tvm.h>
#include <tvm/ir_visitor.h>
tqchen committed
5
#include <tvm/ir_pass.h>
tqchen committed
6 7 8 9 10 11 12 13

TEST(IRVisitor, CountVar) {
  using namespace Halide::Internal;
  using namespace tvm;
  int n_var = 0;
  Var x("x"), y;

  auto z = x + 1 + y + y;
14
  ir::PostOrderVisit(z, [&n_var](const NodeRef& n) {
tqchen committed
15 16 17 18 19 20 21 22 23 24
      if (n.as<Variable>()) ++n_var;
    });
  CHECK_EQ(n_var, 2);
}

int main(int argc, char ** argv) {
  testing::InitGoogleTest(&argc, argv);
  testing::FLAGS_gtest_death_test_style = "threadsafe";
  return RUN_ALL_TESTS();
}