Overview

This section describes two methods of modifying a graph using passes. The following table describes the differences between the two methods.

Table 1 Comparison between the two methods that are implemented using passes

Graph Modification Method

Pass Based on Pattern Mapping (Recommended)

Pass Based on the Graph Modification API

Core approach

Define a matching template using a pattern. The framework automatically performs matching and search. You only need to define the replacement structure.

Directly write the graph modification function, manually traverse the graph structure, search for nodes, create new nodes, establish edge connections, and delete old nodes.

Key features

Only three steps are required: matching → decision-making → replacement.

  • Patterns: Define the matching template topology.
  • MeetRequirements: (Optional) Filter by criteria.
  • Replacement: Define the replacement structure.
  • Operations such as node search, edge processing, and node addition/deletion need to be manually implemented.
  • The code volume is large, and all graph modification details need to be processed.

Application scenario

When no constraint is triggered

  • Simple and one-time modification
  • The graph modification API is called to adjust the graph structure in real time.
  • Full control over the graph structure is required.

Constraints/Prohibited items

  • Control edge: The framework does not support control dependency matching. It supports only data edge matching.
  • Subgraph: Nested subgraph structures are not supported. The pattern must be a flat directed acyclic graph (DAG).
  • Dynamic input/output nodes: Uncertain number of inputs/outputs may cause matching ambiguity and cannot be accurately located.

-