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 char *dir = inout ? "out" : "in";
70 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
74 memset(buf, 0, sizeof(buf));
77 for (i = 0; i < max; i++) {
78 fprintf(F, "%sreq #%d =", dir, i);
80 if (reqs[i]->type == arch_register_req_type_none) {
84 if (reqs[i]->type & arch_register_req_type_normal) {
85 fprintf(F, " %s", reqs[i]->cls->name);
88 if (reqs[i]->type & arch_register_req_type_limited) {
90 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
93 if (reqs[i]->type & arch_register_req_type_should_be_same) {
94 const unsigned other = reqs[i]->other_same;
97 ir_fprintf(F, " same as");
98 for (i = 0; 1U << i <= other; ++i) {
99 if (other & (1U << i)) {
100 ir_fprintf(F, " %+F", i);
105 if (reqs[i]->type & arch_register_req_type_must_be_different) {
106 const unsigned other = reqs[i]->other_different;
109 ir_fprintf(F, " different from");
110 for (i = 0; 1U << i <= other; ++i) {
111 if (other & (1U << i)) {
112 ir_fprintf(F, " %+F", i);
122 fprintf(F, "%sreq = N/A\n", dir);
128 * Dumper interface for dumping mips nodes in vcg.
129 * @param n the node to dump
130 * @param F the output file
131 * @param reason indicates which kind of information should be dumped
132 * @return 0 on success or != 0 on failure
134 static int mips_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
137 const arch_register_req_t **reqs;
140 case dump_node_opcode_txt:
141 fprintf(F, "%s", get_irn_opname(n));
144 case dump_node_mode_txt:
147 case dump_node_nodeattr_txt:
149 if(is_mips_Immediate(n)) {
150 const mips_immediate_attr_t *attr
151 = get_mips_immediate_attr_const(n);
152 switch(attr->imm_type) {
154 fprintf(F, " %ld ", attr->val);
156 case MIPS_IMM_SYMCONST_LO:
157 fprintf(F, " lo(%s", get_entity_ld_name(attr->entity));
159 fprintf(F, "%+ld", attr->val);
163 case MIPS_IMM_SYMCONST_HI:
164 fprintf(F, " hi(%s", get_entity_ld_name(attr->entity));
166 fprintf(F, "%+ld", attr->val);
171 fprintf(F, " INVALID ");
177 case dump_node_info_txt:
178 fprintf(F, "=== mips attr begin ===\n");
180 /* dump IN requirements */
181 if (get_irn_arity(n) > 0) {
182 reqs = get_mips_in_req_all(n);
183 dump_reg_req(F, n, reqs, 0);
186 n_res = arch_irn_get_n_outs(n);
188 /* dump OUT requirements */
189 reqs = get_mips_out_req_all(n);
190 dump_reg_req(F, n, reqs, 1);
192 /* dump assigned registers */
193 for (i = 0; i < n_res; i++) {
194 const arch_register_t *reg = arch_irn_get_register(n, i);
196 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
202 fprintf(F, "n_res = %d\n", n_res);
205 fprintf(F, "flags =");
206 flags = arch_irn_get_flags(n);
207 if (flags == arch_irn_flags_none) {
211 if (flags & arch_irn_flags_dont_spill) {
212 fprintf(F, " unspillable");
214 if (flags & arch_irn_flags_rematerializable) {
215 fprintf(F, " remat");
217 if (flags & arch_irn_flags_modify_flags) {
218 fprintf(F, " modify_flags");
221 fprintf(F, " (%d)\n", flags);
223 fprintf(F, "=== mips attr end ===\n");
224 /* end of: case dump_node_info_txt */
234 /***************************************************************************************************
236 * | | | | | | / / | | | | | | | |
237 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
238 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
239 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
240 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
243 ***************************************************************************************************/
245 mips_attr_t *get_mips_attr(ir_node *node)
247 assert(is_mips_irn(node) && "need mips node to get attributes");
248 return (mips_attr_t *) get_irn_generic_attr(node);
251 const mips_attr_t *get_mips_attr_const(const ir_node *node)
253 assert(is_mips_irn(node) && "need mips node to get attributes");
254 return get_irn_generic_attr_const(node);
257 const mips_immediate_attr_t *get_mips_immediate_attr_const(const ir_node *node)
259 assert(is_mips_irn(node) && "need mips node to get attributes");
260 return get_irn_generic_attr_const(node);
263 const mips_load_store_attr_t *get_mips_load_store_attr_const(
266 assert(is_mips_irn(node) && "need mips node to get attributes");
267 return get_irn_generic_attr_const(node);
271 * Returns the argument register requirements of a mips node.
273 const arch_register_req_t **get_mips_in_req_all(const ir_node *node)
275 const mips_attr_t *attr = get_mips_attr_const(node);
280 * Returns the result register requirements of an mips node.
282 const arch_register_req_t **get_mips_out_req_all(const ir_node *node)
284 const mips_attr_t *attr = get_mips_attr_const(node);
285 return attr->out_req;
289 * Returns the argument register requirement at position pos of an mips node.
291 const arch_register_req_t *get_mips_in_req(const ir_node *node, int pos)
293 const mips_attr_t *attr = get_mips_attr_const(node);
294 return attr->in_req[pos];
298 * Returns the result register requirement at position pos of an mips node.
300 const arch_register_req_t *get_mips_out_req(const ir_node *node, int pos)
302 const mips_attr_t *attr = get_mips_attr_const(node);
303 return attr->out_req[pos];
307 * Sets the OUT register requirements at position pos.
309 void set_mips_req_out(ir_node *node, const arch_register_req_t *req, int pos)
311 mips_attr_t *attr = get_mips_attr(node);
312 attr->out_req[pos] = req;
316 * Sets the IN register requirements at position pos.
318 void set_mips_req_in(ir_node *node, const arch_register_req_t *req, int pos)
320 mips_attr_t *attr = get_mips_attr(node);
321 attr->in_req[pos] = req;
325 * Initializes the nodes attributes.
327 static void init_mips_attributes(ir_node *node, arch_irn_flags_t flags,
328 const arch_register_req_t **in_reqs,
329 const arch_register_req_t **out_reqs,
330 const be_execution_unit_t ***execution_units,
333 ir_graph *irg = get_irn_irg(node);
334 struct obstack *obst = get_irg_obstack(irg);
335 mips_attr_t *attr = get_mips_attr(node);
336 backend_info_t *info;
337 (void) execution_units;
339 arch_irn_set_flags(node, flags);
340 attr->out_req = out_reqs;
341 attr->in_req = in_reqs;
343 info = be_get_info(node);
344 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
345 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
348 static void init_mips_immediate_attributes(ir_node *node,
349 mips_immediate_type_t type,
350 ir_entity *entity, long val)
352 mips_immediate_attr_t *attr = get_irn_generic_attr(node);
354 attr->imm_type = type;
355 attr->entity = entity;
359 static void init_mips_load_store_attributes(ir_node *node, ir_entity *entity,
362 mips_load_store_attr_t *attr = get_irn_generic_attr(node);
363 attr->stack_entity = entity;
364 attr->offset = offset;
367 static int mips_compare_nodes_attr(ir_node *node_a, ir_node *node_b)
369 const mips_attr_t *a = get_mips_attr_const(node_a);
370 const mips_attr_t *b = get_mips_attr_const(node_b);
372 if(a->switch_default_pn != b->switch_default_pn)
378 static int mips_compare_immediate_attr(ir_node *node_a, ir_node *node_b)
380 const mips_immediate_attr_t *a = get_mips_immediate_attr_const(node_a);
381 const mips_immediate_attr_t *b = get_mips_immediate_attr_const(node_b);
389 static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
391 const mips_load_store_attr_t *a = get_mips_load_store_attr_const(node_a);
392 const mips_load_store_attr_t *b = get_mips_load_store_attr_const(node_b);
394 if(mips_compare_nodes_attr(node_a, node_b))
396 if(a->stack_entity != b->stack_entity)
398 if(a->offset != b->offset)
404 static void mips_copy_attr(const ir_node *old_node , ir_node *new_node)
406 ir_graph *irg = get_irn_irg(new_node);
407 struct obstack *obst = get_irg_obstack(irg);
408 const mips_attr_t *attr_old = get_mips_attr_const(old_node);
409 mips_attr_t *attr_new = get_mips_attr(new_node);
410 backend_info_t *old_info = be_get_info(old_node);
411 backend_info_t *new_info = be_get_info(new_node);
413 /* copy the attributes */
414 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
417 new_info->out_infos =
418 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
421 /***************************************************************************************
424 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
425 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
426 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
427 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
429 ***************************************************************************************/
431 /* Include the generated constructor functions */
432 #include "gen_mips_new_nodes.c.inl"