moved firmext code into the backend dir
[libfirm] / ir / be / grgen / match.h
1 #ifndef _EXT_GRS_MATCH_H_
2 #define _EXT_GRS_MATCH_H_
3
4 /*
5  * Project:     libFIRM/extension module/graph rewriting system
6  * File name:   ext/grs/match.h
7  * Purpose:     provides an interface for subgraph matching
8  * Author:      Veit Batz
9  * Modified by: Andreas Schoesser
10  * Created:             6. August 2005
11  * CVS-ID:      $Id$
12  * Copyright:   (c) 2005 Universität Karlsruhe
13  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
14  */
15
16
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
29
30
31 #include "matchplan.h"
32
33
34
35 /** graph matching result */
36 typedef struct _ext_grs_match_t ext_grs_match_t;
37
38 /** wraps initial bindings for pivoted graph matching */
39 typedef struct _ext_grs_binding_t ext_grs_binding_t;
40
41
42
43
44
45
46
47 /** find at most n matches
48  *
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
56  */
57 ext_grs_match_t *ext_grs_match(
58         ir_graph *irg, ext_grs_match_plan_t *plan, int n, int compliant);
59
60 /** find at most n matches
61  *
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
72  *
73  * @returns     a matching result
74  */
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);
77
78 /** perform rewriting step
79  *
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);
91
92 /** get the number of matches in the given matching result
93  *  @param match        a matching result
94  *  @returns the number of matches
95  */
96 int ext_grs_get_n_matches(ext_grs_match_t *match);
97
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
101  */
102 ir_graph *ext_grs_get_match_irg(ext_grs_match_t *match);
103
104 /** get the node map of a match in a given matching result
105  *
106  *  @param      match   a matching result
107  *  @param which        the number of the match in the matching result
108  *
109  *  @returns the node map of the match
110  */
111 ir_node **ext_grs_get_match_node_map(ext_grs_match_t *match, int which);
112
113 /** get the node map of a match in a given matching result
114  *
115  *  @param      match   a matching result
116  *  @param which        the id of the match in the matching result
117  *
118  *  @returns the edge map of the match
119  */
120 const ir_edge_t **ext_grs_get_match_edge_map(ext_grs_match_t *match, int which);
121
122 ir_node **ext_grs_get_replace_node_map(ext_grs_match_t *match, int which);
123
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.
128
129  *  @param match        a matching result
130  *  @param
131  *
132  *  @returns the number of matches
133  */
134 void ext_grs_dump_match(ext_grs_match_t *match, const char *suffix);
135
136 int ext_grs_get_match_max_node_aiid(ext_grs_match_t *match);
137
138 int ext_grs_get_match_max_edge_aiid(ext_grs_match_t *match);
139
140
141
142 #endif /*_EXT_GRS_MATCH_H_*/