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"
43 #include "../bearch.h"
45 #include "mips_nodes_attr.h"
46 #include "mips_new_nodes.h"
47 #include "gen_mips_regalloc_if.h"
51 /***********************************************************************************
54 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
55 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
56 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
57 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
60 ***********************************************************************************/
63 * Dumps the register requirements for either in or out.
65 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
68 char *dir = inout ? "out" : "in";
69 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
73 memset(buf, 0, sizeof(buf));
76 for (i = 0; i < max; i++) {
77 fprintf(F, "%sreq #%d =", dir, i);
79 if (reqs[i]->type == arch_register_req_type_none) {
83 if (reqs[i]->type & arch_register_req_type_normal) {
84 fprintf(F, " %s", reqs[i]->cls->name);
87 if (reqs[i]->type & arch_register_req_type_limited) {
89 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
92 if (reqs[i]->type & arch_register_req_type_should_be_same) {
93 const unsigned other = reqs[i]->other_same;
96 ir_fprintf(F, " same as");
97 for (i = 0; 1U << i <= other; ++i) {
98 if (other & (1U << i)) {
99 ir_fprintf(F, " %+F", i);
104 if (reqs[i]->type & arch_register_req_type_must_be_different) {
105 const unsigned other = reqs[i]->other_different;
108 ir_fprintf(F, " different from");
109 for (i = 0; 1U << i <= other; ++i) {
110 if (other & (1U << i)) {
111 ir_fprintf(F, " %+F", i);
121 fprintf(F, "%sreq = N/A\n", dir);
127 * Dumper interface for dumping mips nodes in vcg.
128 * @param n the node to dump
129 * @param F the output file
130 * @param reason indicates which kind of information should be dumped
131 * @return 0 on success or != 0 on failure
133 static int mips_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
136 const arch_register_req_t **reqs;
139 case dump_node_opcode_txt:
140 fprintf(F, "%s", get_irn_opname(n));
143 case dump_node_mode_txt:
146 case dump_node_nodeattr_txt:
148 if(is_mips_Immediate(n)) {
149 const mips_immediate_attr_t *attr
150 = get_mips_immediate_attr_const(n);
151 switch(attr->imm_type) {
153 fprintf(F, " %ld ", attr->val);
155 case MIPS_IMM_SYMCONST_LO:
156 fprintf(F, " lo(%s", get_entity_ld_name(attr->entity));
158 fprintf(F, "%+ld", attr->val);
162 case MIPS_IMM_SYMCONST_HI:
163 fprintf(F, " hi(%s", get_entity_ld_name(attr->entity));
165 fprintf(F, "%+ld", attr->val);
170 fprintf(F, " INVALID ");
176 case dump_node_info_txt:
177 fprintf(F, "=== mips attr begin ===\n");
179 /* dump IN requirements */
180 if (get_irn_arity(n) > 0) {
181 reqs = get_mips_in_req_all(n);
182 dump_reg_req(F, n, reqs, 0);
185 n_res = arch_irn_get_n_outs(n);
187 /* dump OUT requirements */
188 reqs = get_mips_out_req_all(n);
189 dump_reg_req(F, n, reqs, 1);
191 /* dump assigned registers */
192 for (i = 0; i < n_res; i++) {
193 const arch_register_t *reg = arch_irn_get_register(n, i);
195 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
201 fprintf(F, "n_res = %d\n", n_res);
204 fprintf(F, "flags =");
205 flags = arch_irn_get_flags(n);
206 if (flags == arch_irn_flags_none) {
210 if (flags & arch_irn_flags_dont_spill) {
211 fprintf(F, " unspillable");
213 if (flags & arch_irn_flags_rematerializable) {
214 fprintf(F, " remat");
216 if (flags & arch_irn_flags_modify_flags) {
217 fprintf(F, " modify_flags");
220 fprintf(F, " (%d)\n", flags);
222 fprintf(F, "=== mips attr end ===\n");
223 /* end of: case dump_node_info_txt */
233 /***************************************************************************************************
235 * | | | | | | / / | | | | | | | |
236 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
237 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
238 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
239 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
242 ***************************************************************************************************/
244 mips_attr_t *get_mips_attr(ir_node *node)
246 assert(is_mips_irn(node) && "need mips node to get attributes");
247 return (mips_attr_t *) get_irn_generic_attr(node);
250 const mips_attr_t *get_mips_attr_const(const ir_node *node)
252 assert(is_mips_irn(node) && "need mips node to get attributes");
253 return get_irn_generic_attr_const(node);
256 const mips_immediate_attr_t *get_mips_immediate_attr_const(const ir_node *node)
258 assert(is_mips_irn(node) && "need mips node to get attributes");
259 return get_irn_generic_attr_const(node);
262 const mips_load_store_attr_t *get_mips_load_store_attr_const(
265 assert(is_mips_irn(node) && "need mips node to get attributes");
266 return get_irn_generic_attr_const(node);
270 * Returns the argument register requirements of a mips node.
272 const arch_register_req_t **get_mips_in_req_all(const ir_node *node)
274 const mips_attr_t *attr = get_mips_attr_const(node);
279 * Returns the result register requirements of an mips node.
281 const arch_register_req_t **get_mips_out_req_all(const ir_node *node)
283 const mips_attr_t *attr = get_mips_attr_const(node);
284 return attr->out_req;
288 * Returns the argument register requirement at position pos of an mips node.
290 const arch_register_req_t *get_mips_in_req(const ir_node *node, int pos)
292 const mips_attr_t *attr = get_mips_attr_const(node);
293 return attr->in_req[pos];
297 * Returns the result register requirement at position pos of an mips node.
299 const arch_register_req_t *get_mips_out_req(const ir_node *node, int pos)
301 const mips_attr_t *attr = get_mips_attr_const(node);
302 return attr->out_req[pos];
306 * Sets the OUT register requirements at position pos.
308 void set_mips_req_out(ir_node *node, const arch_register_req_t *req, int pos)
310 mips_attr_t *attr = get_mips_attr(node);
311 attr->out_req[pos] = req;
315 * Sets the IN register requirements at position pos.
317 void set_mips_req_in(ir_node *node, const arch_register_req_t *req, int pos)
319 mips_attr_t *attr = get_mips_attr(node);
320 attr->in_req[pos] = req;
324 * Initializes the nodes attributes.
326 static void init_mips_attributes(ir_node *node, arch_irn_flags_t flags,
327 const arch_register_req_t **in_reqs,
328 const arch_register_req_t **out_reqs,
329 const be_execution_unit_t ***execution_units,
332 ir_graph *irg = get_irn_irg(node);
333 struct obstack *obst = get_irg_obstack(irg);
334 mips_attr_t *attr = get_mips_attr(node);
335 backend_info_t *info;
336 (void) execution_units;
338 arch_irn_set_flags(node, flags);
339 attr->out_req = out_reqs;
340 attr->in_req = in_reqs;
342 info = be_get_info(node);
343 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
344 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
347 static void init_mips_immediate_attributes(ir_node *node,
348 mips_immediate_type_t type,
349 ir_entity *entity, long val)
351 mips_immediate_attr_t *attr = get_irn_generic_attr(node);
353 attr->imm_type = type;
354 attr->entity = entity;
358 static void init_mips_load_store_attributes(ir_node *node, ir_entity *entity,
361 mips_load_store_attr_t *attr = get_irn_generic_attr(node);
362 attr->stack_entity = entity;
363 attr->offset = offset;
366 static int mips_compare_nodes_attr(ir_node *node_a, ir_node *node_b)
368 const mips_attr_t *a = get_mips_attr_const(node_a);
369 const mips_attr_t *b = get_mips_attr_const(node_b);
371 if(a->switch_default_pn != b->switch_default_pn)
377 static int mips_compare_immediate_attr(ir_node *node_a, ir_node *node_b)
379 const mips_immediate_attr_t *a = get_mips_immediate_attr_const(node_a);
380 const mips_immediate_attr_t *b = get_mips_immediate_attr_const(node_b);
388 static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
390 const mips_load_store_attr_t *a = get_mips_load_store_attr_const(node_a);
391 const mips_load_store_attr_t *b = get_mips_load_store_attr_const(node_b);
393 if(mips_compare_nodes_attr(node_a, node_b))
395 if(a->stack_entity != b->stack_entity)
397 if(a->offset != b->offset)
403 static void mips_copy_attr(const ir_node *old_node , ir_node *new_node)
405 ir_graph *irg = get_irn_irg(new_node);
406 struct obstack *obst = get_irg_obstack(irg);
407 const mips_attr_t *attr_old = get_mips_attr_const(old_node);
408 mips_attr_t *attr_new = get_mips_attr(new_node);
409 backend_info_t *old_info = be_get_info(old_node);
410 backend_info_t *new_info = be_get_info(new_node);
412 /* copy the attributes */
413 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
416 new_info->out_infos =
417 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
420 /***************************************************************************************
423 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
424 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
425 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
426 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
428 ***************************************************************************************/
430 /* Include the generated constructor functions */
431 #include "gen_mips_new_nodes.c.inl"