2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief This file implements the creation of the architecture specific firm
23 * opcodes and the corresponding node constructors for the MIPS
25 * @author Matthias Braun, Mehdi
33 #include "irgraph_t.h"
39 #include "firm_common_t.h"
44 #include "../bearch_t.h"
46 #include "mips_nodes_attr.h"
47 #include "mips_new_nodes.h"
48 #include "gen_mips_regalloc_if.h"
52 /***********************************************************************************
55 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
56 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
57 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
58 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
61 ***********************************************************************************/
64 * Dumps the register requirements for either in or out.
66 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
69 const mips_attr_t *attr = get_mips_attr_const(n);
70 char *dir = inout ? "out" : "in";
71 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
75 memset(buf, 0, sizeof(buf));
78 for (i = 0; i < max; i++) {
79 fprintf(F, "%sreq #%d =", dir, i);
81 if (reqs[i]->type == arch_register_req_type_none) {
85 if (reqs[i]->type & arch_register_req_type_normal) {
86 fprintf(F, " %s", reqs[i]->cls->name);
89 if (reqs[i]->type & arch_register_req_type_limited) {
91 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
94 if (reqs[i]->type & arch_register_req_type_should_be_same) {
95 const unsigned other = reqs[i]->other_same;
98 ir_fprintf(F, " same as");
99 for (i = 0; 1U << i <= other; ++i) {
100 if (other & (1U << i)) {
101 ir_fprintf(F, " %+F", i);
106 if (reqs[i]->type & arch_register_req_type_must_be_different) {
107 const unsigned other = reqs[i]->other_different;
110 ir_fprintf(F, " different from");
111 for (i = 0; 1U << i <= other; ++i) {
112 if (other & (1U << i)) {
113 ir_fprintf(F, " %+F", i);
123 fprintf(F, "%sreq = N/A\n", dir);
129 * Dumper interface for dumping mips nodes in vcg.
130 * @param n the node to dump
131 * @param F the output file
132 * @param reason indicates which kind of information should be dumped
133 * @return 0 on success or != 0 on failure
135 static int mips_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
138 const arch_register_req_t **reqs;
141 case dump_node_opcode_txt:
142 fprintf(F, "%s", get_irn_opname(n));
145 case dump_node_mode_txt:
148 case dump_node_nodeattr_txt:
150 if(is_mips_Immediate(n)) {
151 const mips_immediate_attr_t *attr
152 = get_mips_immediate_attr_const(n);
153 switch(attr->imm_type) {
155 fprintf(F, " %ld ", attr->val);
157 case MIPS_IMM_SYMCONST_LO:
158 fprintf(F, " lo(%s", get_entity_ld_name(attr->entity));
160 fprintf(F, "%+ld", attr->val);
164 case MIPS_IMM_SYMCONST_HI:
165 fprintf(F, " hi(%s", get_entity_ld_name(attr->entity));
167 fprintf(F, "%+ld", attr->val);
172 fprintf(F, " INVALID ");
178 case dump_node_info_txt:
179 fprintf(F, "=== mips attr begin ===\n");
181 /* dump IN requirements */
182 if (get_irn_arity(n) > 0) {
183 reqs = get_mips_in_req_all(n);
184 dump_reg_req(F, n, reqs, 0);
187 n_res = arch_irn_get_n_outs(n);
189 /* dump OUT requirements */
190 reqs = get_mips_out_req_all(n);
191 dump_reg_req(F, n, reqs, 1);
193 /* dump assigned registers */
194 for (i = 0; i < n_res; i++) {
195 const arch_register_t *reg = arch_irn_get_register(n, i);
197 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
203 fprintf(F, "n_res = %d\n", n_res);
206 fprintf(F, "flags =");
207 flags = arch_irn_get_flags(n);
208 if (flags == arch_irn_flags_none) {
212 if (flags & arch_irn_flags_dont_spill) {
213 fprintf(F, " unspillable");
215 if (flags & arch_irn_flags_rematerializable) {
216 fprintf(F, " remat");
218 if (flags & arch_irn_flags_modify_flags) {
219 fprintf(F, " modify_flags");
222 fprintf(F, " (%d)\n", flags);
224 fprintf(F, "=== mips attr end ===\n");
225 /* end of: case dump_node_info_txt */
235 /***************************************************************************************************
237 * | | | | | | / / | | | | | | | |
238 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
239 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
240 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
241 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
244 ***************************************************************************************************/
246 mips_attr_t *get_mips_attr(ir_node *node)
248 assert(is_mips_irn(node) && "need mips node to get attributes");
249 return (mips_attr_t *) get_irn_generic_attr(node);
252 const mips_attr_t *get_mips_attr_const(const ir_node *node)
254 assert(is_mips_irn(node) && "need mips node to get attributes");
255 return get_irn_generic_attr_const(node);
258 const mips_immediate_attr_t *get_mips_immediate_attr_const(const ir_node *node)
260 assert(is_mips_irn(node) && "need mips node to get attributes");
261 return get_irn_generic_attr_const(node);
264 const mips_load_store_attr_t *get_mips_load_store_attr_const(
267 assert(is_mips_irn(node) && "need mips node to get attributes");
268 return get_irn_generic_attr_const(node);
272 * Returns the argument register requirements of a mips node.
274 const arch_register_req_t **get_mips_in_req_all(const ir_node *node)
276 const mips_attr_t *attr = get_mips_attr_const(node);
281 * Returns the result register requirements of an mips node.
283 const arch_register_req_t **get_mips_out_req_all(const ir_node *node)
285 const mips_attr_t *attr = get_mips_attr_const(node);
286 return attr->out_req;
290 * Returns the argument register requirement at position pos of an mips node.
292 const arch_register_req_t *get_mips_in_req(const ir_node *node, int pos)
294 const mips_attr_t *attr = get_mips_attr_const(node);
295 return attr->in_req[pos];
299 * Returns the result register requirement at position pos of an mips node.
301 const arch_register_req_t *get_mips_out_req(const ir_node *node, int pos)
303 const mips_attr_t *attr = get_mips_attr_const(node);
304 return attr->out_req[pos];
308 * Sets the OUT register requirements at position pos.
310 void set_mips_req_out(ir_node *node, const arch_register_req_t *req, int pos)
312 mips_attr_t *attr = get_mips_attr(node);
313 attr->out_req[pos] = req;
317 * Sets the IN register requirements at position pos.
319 void set_mips_req_in(ir_node *node, const arch_register_req_t *req, int pos)
321 mips_attr_t *attr = get_mips_attr(node);
322 attr->in_req[pos] = req;
326 * Initializes the nodes attributes.
328 static void init_mips_attributes(ir_node *node, arch_irn_flags_t flags,
329 const arch_register_req_t **in_reqs,
330 const arch_register_req_t **out_reqs,
331 const be_execution_unit_t ***execution_units,
334 ir_graph *irg = get_irn_irg(node);
335 struct obstack *obst = get_irg_obstack(irg);
336 mips_attr_t *attr = get_mips_attr(node);
337 backend_info_t *info;
338 (void) execution_units;
340 arch_irn_set_flags(node, flags);
341 attr->out_req = out_reqs;
342 attr->in_req = in_reqs;
344 info = be_get_info(node);
345 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
346 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
349 static void init_mips_immediate_attributes(ir_node *node,
350 mips_immediate_type_t type,
351 ir_entity *entity, long val)
353 mips_immediate_attr_t *attr = get_irn_generic_attr(node);
355 attr->imm_type = type;
356 attr->entity = entity;
360 static void init_mips_load_store_attributes(ir_node *node, ir_entity *entity,
363 mips_load_store_attr_t *attr = get_irn_generic_attr(node);
364 attr->stack_entity = entity;
365 attr->offset = offset;
368 static int mips_compare_nodes_attr(ir_node *node_a, ir_node *node_b)
370 const mips_attr_t *a = get_mips_attr_const(node_a);
371 const mips_attr_t *b = get_mips_attr_const(node_b);
373 if(a->switch_default_pn != b->switch_default_pn)
379 static int mips_compare_immediate_attr(ir_node *node_a, ir_node *node_b)
381 const mips_immediate_attr_t *a = get_mips_immediate_attr_const(node_a);
382 const mips_immediate_attr_t *b = get_mips_immediate_attr_const(node_b);
390 static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
392 const mips_load_store_attr_t *a = get_mips_load_store_attr_const(node_a);
393 const mips_load_store_attr_t *b = get_mips_load_store_attr_const(node_b);
395 if(mips_compare_nodes_attr(node_a, node_b))
397 if(a->stack_entity != b->stack_entity)
399 if(a->offset != b->offset)
405 static void mips_copy_attr(const ir_node *old_node , ir_node *new_node)
407 ir_graph *irg = get_irn_irg(new_node);
408 struct obstack *obst = get_irg_obstack(irg);
409 const mips_attr_t *attr_old = get_mips_attr_const(old_node);
410 mips_attr_t *attr_new = get_mips_attr(new_node);
411 backend_info_t *old_info = be_get_info(old_node);
412 backend_info_t *new_info = be_get_info(new_node);
414 /* copy the attributes */
415 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
418 new_info->out_infos =
419 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
422 /***************************************************************************************
425 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
426 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
427 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
428 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
430 ***************************************************************************************/
432 /* Include the generated constructor functions */
433 #include "gen_mips_new_nodes.c.inl"