1 #ifndef _EXT_GRS_MATCH_H_
2 #define _EXT_GRS_MATCH_H_
5 * Project: libFIRM/extension module/graph rewriting system
6 * File name: ext/grs/match.h
7 * Purpose: provides an interface for subgraph matching
9 * Modified by: Andreas Schoesser
10 * Created: 6. August 2005
12 * Copyright: (c) 2005 Universität Karlsruhe
13 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 /** Do the matching \b compliant, i.e. the matching allows
18 * parallel independent rule application. */
19 #define ext_grs_COMPLIANT 1
20 /** Do the matching \b not compliant, i.e. the
21 * matching does \b not regard parallel independent rule application. */
22 #define ext_grs_REGARDLESS 0
23 /** Find \b all occurences of the pattern graph in a given host graph,
24 * or in case of compliant matching, as much as possible occurences,
25 * which can be replaced parallel independent.
26 * @note It is \b not guarantied that the maximal possible number
27 * of matches is found. */
28 #define ext_grs_ALL -1
31 #include "matchplan.h"
35 /** graph matching result */
36 typedef struct _ext_grs_match_t ext_grs_match_t;
38 /** wraps initial bindings for pivoted graph matching */
39 typedef struct _ext_grs_binding_t ext_grs_binding_t;
47 /** find at most n matches
49 * @param irg the host graph to be matched in
50 * @param plan the matching plan parametrizing the search
51 * @param n the maximum number of matches (-1 means all, if compliant
52 * matching is activated not all, but as many as feasible
53 * \b compliant matches are found)
54 * @param compliant match compliant if nonzero, i.e. find only matches
55 * that can be rewritten concurrently
57 ext_grs_match_t *ext_grs_match(
58 ir_graph *irg, ext_grs_match_plan_t *plan, int n, int compliant);
60 /** find at most n matches
62 * @param irg the host graph to be matched in
63 * @param plan the matching plan parametrizing the search
64 * @param n the maximum number of matches (-1 means all, if compliant
65 * matching is activated not all, but as many as feasible
66 * \b compliant matches are found)
67 * @param compliant match compliant if non zero, i.e. find only matches
68 * that can be rewritten concurrently
69 * @param binding initial binding of pattern nodes/edges to host graph
70 * nodes/edges, in the binding struct the appropriate
71 * pattern and host graph nodes/edges have the same index
73 * @returns a matching result
75 ext_grs_match_t *ext_grs_match_pivot(ir_graph *irg,
76 ext_grs_match_plan_t *plan, int n, int compliant, ext_grs_binding_t *binding);
78 /** perform rewriting step
80 * @param match a matching result
81 * @param n The number of matches to be replaced, if n=0 no
82 * replacement is performed, if n=-1 \b all matches
83 * will be replaced. If n=-1 or n>1 the matching result
84 * has to be compliant.
85 * @param which An array containing the indices of the n matches to
86 * be replaced. If \b all matches shall be replaced this
87 * parameter will be ignored.
88 * @note The match object is freed afterwards. */
89 void ext_grs_finish_match(ext_grs_match_t *match, int n, int *which);
90 void ext_grs_free_match(ext_grs_match_t *match);
92 /** get the number of matches in the given matching result
93 * @param match a matching result
94 * @returns the number of matches
96 int ext_grs_get_n_matches(ext_grs_match_t *match);
98 /** get the ir graph of a given matching result
99 * @param match a matching result
100 * @returns the ir graph the matching result belongs to
102 ir_graph *ext_grs_get_match_irg(ext_grs_match_t *match);
104 /** get the node map of a match in a given matching result
106 * @param match a matching result
107 * @param which the number of the match in the matching result
109 * @returns the node map of the match
111 ir_node **ext_grs_get_match_node_map(ext_grs_match_t *match, int which);
113 /** get the node map of a match in a given matching result
115 * @param match a matching result
116 * @param which the id of the match in the matching result
118 * @returns the edge map of the match
120 const ir_edge_t **ext_grs_get_match_edge_map(ext_grs_match_t *match, int which);
122 ir_node **ext_grs_get_replace_node_map(ext_grs_match_t *match, int which);
124 /** dump the given ir graph the matching result belongs to where all matches
125 * of the given matching result are represented by a virtual "Match" node and
126 * some edges pointing from the Match node to the regarding nodes. All nodes
127 * and edges which belong to am match are drawed in red color.
129 * @param match a matching result
132 * @returns the number of matches
134 void ext_grs_dump_match(ext_grs_match_t *match, const char *suffix);
136 int ext_grs_get_match_max_node_aiid(ext_grs_match_t *match);
138 int ext_grs_get_match_max_edge_aiid(ext_grs_match_t *match);
142 #endif /*_EXT_GRS_MATCH_H_*/