moved firmext code into the backend dir
[libfirm] / ir / be / grgen / base_t.h
1 #ifndef _EXT_GRS_BASE_T_H_
2 #define _EXT_GRS_BASE_T_H_
3
4
5 #ifdef _WIN32
6 #include <malloc.h>
7 #else
8 #include <alloca.h>
9 #endif
10 #include "common_t.h"
11 #include "base.h"
12 #include "action_t.h"
13
14
15
16
17
18 #define OFFSET_OF(type, member) ((char*) &((((type)*)0)->(member)) - (char*)0)
19 #define CONTAINER_OF(ptr, type, member) \
20         (((type) *) ((char *) (ptr) - OFFSET_OF((type), (member))))
21
22
23
24
25
26
27 /* maps opcodes to ops */
28 extern ir_op **_ext_grs_op_map;
29 /* maps modecodes to modes */
30 extern ir_mode **_ext_grs_mode_map;
31
32
33 /**
34  * a 2-dim flexible array telling wether an opcode belongs
35  * to a sub op of the op given by a second opcode. usage:
36  * _ext_grs_op_is_a[o1][o2] != 0   IFF   o1 inherits o2 */
37 //extern int *_ext_grs_op_is_a;
38 extern unsigned char *_ext_grs_op_is_a;
39 /** the width of the  */
40 extern int _ext_grs_op_is_a_width;
41
42 /** comfortable acces to the is_a matrix (o1 and o2 are opcodes) */
43 #define _ext_grs_OP_IS_A(o1, o2) \
44         _ext_grs_op_is_a[((int)o1)*(_ext_grs_op_is_a_width) + ((int)o2)]
45
46 /**
47  * a flexible array of flexible arrays each containing all inheriting
48  * firm ops of that firm op, the opcode of wich is the index entered
49  * in the array of arrays
50  * USAGE: _ext_grs_all_sub_ops_of_op[opcode]
51  * this yields an flexible array of ptrs to firm ops inheriting
52  * form the given opcodes op */
53 extern ir_op ***_ext_grs_all_sub_ops_of_op;
54 /* a flexible array of flexible arrays each containing all firm ops
55  * a given firm op inherits from, the given opcode is the index entered
56  * in the array of arrays
57  * USAGE: _ext_grs_all_super_ops_of_op[opcode]
58  * this yields an flexible array of ptrs to firm ops inheriting
59  * form the given opcodes op */
60 extern ir_op ***_ext_grs_all_super_ops_of_op;
61
62 /** maps ir op names (e.g. "Add") to ir ops (i.e. *ir_op) */
63 extern lc_pset *_ext_grs_op_name_table;
64 /** maps mode names (e.g. "M") to modes (i.e. *ir_mode) */
65 extern lc_pset *_ext_grs_mode_name_table;
66 /** remembers the maximum opcode present */
67 extern int _ext_grs_max_opcode;
68 /** remembers the maximum modecode present */
69 extern int _ext_grs_max_modecode;
70
71
72 /** offset of private data area in ir graphs */
73 extern unsigned _ext_grs_private_ofs_g;
74 /** the private data area in ir graphs */
75 typedef struct _ext_grs_irg_private_t {
76         /** a flag, tells wether matching has been disabled
77          *  for this it graph by calling ext_grs_disable_matching() */
78         int matching_enabled;
79         /** lists of firm nodes according to their opcode and modecode */
80         lc_list_t *node_list;
81         /** number of instances according to the opcode and modecode */
82         int *n_instances;
83 } ext_grs_irg_private_t;
84
85 /* dimension of dynamic allocated 2-dim arrays in private data
86  * area of firm graphs. These two arrays are the n_instances
87  * and the node_list. Note that these two arrays have the same
88  * dimension for all ir graphs. That means if the maximal
89  * opcode/modecode exceeds the respsective dimension the
90  * arrays of ALL ir graphs have to be reallcated (this is done
91  * by the hooks of new ops and modes) */
92 extern int _ext_grs_irgpr_op_dim;
93 extern int _ext_grs_irgpr_mode_dim;
94
95 /* easy acces two these dynamic 2-dim arrays */
96 #define _ext_grs_N_INSTANCES(pr_g, opc, mc) \
97         ((pr_g)->n_instances[_ext_grs_irgpr_mode_dim * (opc) + (mc)])
98 #define _ext_grs_NODE_LIST(pr_g, opc, mc) \
99         ((pr_g)->node_list[_ext_grs_irgpr_mode_dim * (opc) + (mc)])
100
101 /** offset of private data in ir nodes */
102 extern unsigned _ext_grs_private_ofs_n;
103 /** the private data area in ir nodes */
104 typedef struct _ext_grs_irn_private_t {
105         /** list of firm nodes according to this nodes opcode and modecode */
106         lc_list_t node_list;
107         /** some auxilary data, needed to determine wether a ir node has
108          * already been matched. If so, it points to a pattern node it is
109          * matched from, otherwise it is NULL */
110         ext_grs_node_t *preimage;
111         /** flag, tells wether this nodes has been deleted on a rewrite step */
112         int deleted;
113 } ext_grs_irn_private_t;
114
115
116 /** offset of private data in ir edges */
117 extern unsigned _ext_grs_private_ofs_e;
118 /** the private data area in ir edges */
119 typedef struct _ext_grs_iredges_private_t {
120         ext_grs_edge_t *preimage;
121         unsigned long visited;
122 } ext_grs_iredges_private_t;
123
124
125 static INLINE ext_grs_irn_private_t *_ext_grs_get_irn_private(ir_node *irn) {
126         return get_irn_data(irn, ext_grs_irn_private_t, _ext_grs_private_ofs_n);
127 }
128
129 static INLINE ext_grs_irg_private_t *_ext_grs_get_irg_private(ir_graph *irg) {
130         return get_irg_data(irg, ext_grs_irg_private_t, _ext_grs_private_ofs_g);
131 }
132
133 static INLINE ir_op *_ext_grs_lookup_op(char *op_name) {
134
135         ir_op *op = alloca(sizeof(*op));
136
137         memset(op, 0, sizeof(*op));
138         op->name = new_id_from_str(op_name);
139
140         op = lc_pset_find(
141                 _ext_grs_op_name_table, op, HASH_STR(op_name, strlen(op_name)));
142         return op;
143 }
144
145 static INLINE ir_mode *_ext_grs_lookup_mode(char *name) {
146
147         ir_mode *mode = alloca(sizeof(*mode));
148
149         memset(mode, 0, sizeof(*mode));
150         mode->name = new_id_from_str(name);
151
152         mode = lc_pset_find(
153                 _ext_grs_mode_name_table, mode, HASH_STR(name, strlen(name)));
154         return mode;
155 }
156
157 /** get an op by its name */
158 #define ext_grs_lookup_op(name)                                 _ext_grs_lookup_op((name))
159 /** get a mode by its name */
160 #define ext_grs_lookup_mode(name)                               _ext_grs_lookup_mode((name))
161
162
163
164
165
166
167 #endif /* _EXT_GRS_BASE_T_H_ */