1 #ifndef _EXT_GRS_BASE_T_H_
2 #define _EXT_GRS_BASE_T_H_
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))))
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;
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;
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)]
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;
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;
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() */
79 /** lists of firm nodes according to their opcode and modecode */
81 /** number of instances according to the opcode and modecode */
83 } ext_grs_irg_private_t;
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;
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)])
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 */
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 */
113 } ext_grs_irn_private_t;
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;
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);
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);
133 static INLINE ir_op *_ext_grs_lookup_op(char *op_name) {
135 ir_op *op = alloca(sizeof(*op));
137 memset(op, 0, sizeof(*op));
138 op->name = new_id_from_str(op_name);
141 _ext_grs_op_name_table, op, HASH_STR(op_name, strlen(op_name)));
145 static INLINE ir_mode *_ext_grs_lookup_mode(char *name) {
147 ir_mode *mode = alloca(sizeof(*mode));
149 memset(mode, 0, sizeof(*mode));
150 mode->name = new_id_from_str(name);
153 _ext_grs_mode_name_table, mode, HASH_STR(name, strlen(name)));
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))
167 #endif /* _EXT_GRS_BASE_T_H_ */