code: def test_merge_order():
      r"""Test that patterns are merged in the order they exist in the pattern table.
  
      There can be cases where one pattern is a subgraph of another, in which case
      it is not clear which match should take priority. The priority should come
      from the order in which the patterns are declared in the pattern table. The
      first patterns will be merged with highest priority and the last with lowest.
  
      A:       B:       C:
      add      add      abs
       |        |        |
      abs      abs      relu
       |
      relu
  
      """
  
      def pattern_A():
          x = wildcard()
          y = wildcard()
          out = is_op("add")(x, y)
          out = is_op("abs")(out)
          out = is_op("nn.relu")(out)
          return out
  
      def pattern_B():
          x = wildcard()
          y = wildcard()
          out = is_op("add")(x, y)
          out = is_op("abs")(out)
          return out
  
      def pattern_C():
          x = wildcard()
          out = is_op("abs")(x)
          out = is_op("nn.relu")(out)
          return out
  
      def before():
          input_1 = relay.var("input_1", shape=(10, 10))
          input_2 = relay.var("input_2", shape=(10, 10))
          out = relay.add(input_1, input_2)
          out = relay.abs(out)
          out = relay.nn.relu(out)
          return relay.Function([input_1, input_2], out)
  
      def after_A_priority():
          input_1 = relay.var("input_1", shape=(10, 10))
          input_2 = relay.var("input_2", shape=(10, 10))
          x = relay.var("x")
          y = relay.var("y")
          out = relay.add(x, y)
          out = relay.abs(out)
          out = relay.nn.relu(out)
          merged_func = relay.Function([x, y], out)
          merged_func = merged_func.with_attr("Composite", "A")
          merged_func = merged_func.with_attr(
              "PartitionedFromPattern", "add_abs_nn.relu_"
          )
          ret = relay.Call(merged_func, [input_1, input_2])
          return relay.Function([input_1, input_2], ret)
  
      def after_B_priority():
          input_1 = relay.var("input_1", shape=(10, 10))
          input_2 = relay.var("input_2", shape=(10, 10))
          x = relay.var("x")
          y = relay.var("y")
          out = relay.add(x, y)
          out = relay.abs(out)
          merged_func = relay.Function([x, y], out)
          merged_func = merged_func.with_attr("Composite", "B")
          merged_func = merged_func.with_attr(
              "PartitionedFromPattern", "add_abs_"
          )
          out = relay.Call(merged_func, [input_1, input_2])
          ret = relay.nn.relu(out)
          return relay.Function([input_1, input_2], ret)
  
      def after_C_priority():
          input_1 = relay.var("input_1", shape=(10, 10))
          input_2 = relay.var("input_2", shape=(10, 10))
          x = relay.var("x")
          out = relay.abs(x)
          out = relay.nn.relu(out)
          merged_func = relay.Function([x], out)
          merged_func = merged_func.with_attr("Composite", "C")
          merged_func = merged_func.with_attr(
              "PartitionedFromPattern", "abs_nn.relu_"
          )
          out = relay.add(input_1, input_2)
          ret = relay.Call(merged_func, [out])
          return relay.Function([input_1, input_2], ret)
  
      # check A highest priority
      pattern_table = [
          ("A", pattern_A()),
          ("B", pattern_B()),
          ("C", pattern_C()),
      ]
      check_result(pattern_table, before(), after_A_priority())
  
      # check B highest priority
      pattern_table = [
          ("B", pattern_B()),
          ("C", pattern_C()),
          ("A", pattern_A()),
      ]
      check_result(pattern_table, before(), after_B_priority())
  
      # check C highest priority
      pattern_table = [
          ("C", pattern_C()),
          ("A", pattern_A()),
          ("B", pattern_B()),
      ]
      check_result(pattern_table, before(), after_C_priority())
  
imports: import pytest
  import tvm
  from tvm import relay, tir
  from tvm.relay.dataflow_pattern import TuplePattern, TupleGetItemPattern, is_op, wildcard
  from tvm.relay.testing import run_opt_pass
label_desc: Use image node_id 13 for calling a global function with example usage: test_merge_order() and returns: out, out, out, relay, relay, relay, relay