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 achitecture specific firm
23 * opcodes and the coresponding node constructors for the sparc
32 #include "irgraph_t.h"
42 #include "../bearch.h"
44 #include "sparc_nodes_attr.h"
45 #include "sparc_new_nodes.h"
46 #include "gen_sparc_regalloc_if.h"
48 static bool has_symconst_attr(const ir_node *node)
50 return is_sparc_SymConst(node) || is_sparc_FrameAddr(node);
53 static bool has_load_store_attr(const ir_node *node)
55 return is_sparc_Ld(node) || is_sparc_St(node) || is_sparc_Ldf(node)
56 || is_sparc_Stf(node);
59 static bool has_jmp_cond_attr(const ir_node *node)
61 return is_sparc_Bicc(node) || is_sparc_fbfcc(node);
64 static bool has_jmp_switch_attr(const ir_node *node)
66 return is_sparc_SwitchJmp(node);
69 static bool has_save_attr(const ir_node *node)
71 return is_sparc_Save(node);
74 static bool has_fp_attr(const ir_node *node)
76 return is_sparc_fadd(node) || is_sparc_fsub(node)
77 || is_sparc_fmul(node) || is_sparc_fdiv(node)
78 || is_sparc_fftoi(node) || is_sparc_fitof(node)
79 || is_sparc_fneg(node) || is_sparc_fcmp(node);
82 static bool has_fp_conv_attr(const ir_node *node)
84 return is_sparc_fftof(node);
88 * Dumper interface for dumping sparc nodes in vcg.
89 * @param F the output file
90 * @param n the node to dump
91 * @param reason indicates which kind of information should be dumped
93 static void sparc_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
96 case dump_node_opcode_txt:
97 fprintf(F, "%s", get_irn_opname(n));
100 case dump_node_mode_txt:
103 case dump_node_info_txt:
104 arch_dump_reqs_and_registers(F, n);
105 if (has_save_attr(n)) {
106 const sparc_save_attr_t *attr = get_sparc_save_attr_const(n);
107 fprintf(F, "initial stacksize: %d\n", attr->initial_stacksize);
109 if (has_symconst_attr(n)) {
110 const sparc_symconst_attr_t *attr = get_sparc_symconst_attr_const(n);
111 ir_fprintf(F, "entity: %+F\n", attr->entity);
112 fprintf(F, "fp_offset: %d\n", attr->fp_offset);
114 if (has_load_store_attr(n)) {
115 const sparc_load_store_attr_t *attr = get_sparc_load_store_attr_const(n);
116 ir_fprintf(F, "load store mode: %+F\n", attr->load_store_mode);
117 ir_fprintf(F, "entity: (sign %d) %+F\n", attr->entity_sign,
119 fprintf(F, "offset: %ld\n", attr->offset);
120 fprintf(F, "is frame entity: %s\n",
121 attr->is_frame_entity ? "true" : "false");
123 if (has_jmp_cond_attr(n)) {
124 const sparc_jmp_cond_attr_t *attr
125 = get_sparc_jmp_cond_attr_const(n);
126 fprintf(F, "pnc: %d (%s)\n", attr->pnc, get_pnc_string(attr->pnc));
127 fprintf(F, "unsigned: %s\n", attr->is_unsigned ? "true" : "false");
129 if (has_jmp_switch_attr(n)) {
130 const sparc_jmp_switch_attr_t *attr
131 = get_sparc_jmp_switch_attr_const(n);
132 fprintf(F, "n projs: %d\n", attr->n_projs);
133 fprintf(F, "default proj: %ld\n", attr->default_proj_num);
135 if (has_fp_attr(n)) {
136 const sparc_fp_attr_t *attr = get_sparc_fp_attr_const(n);
137 ir_fprintf(F, "fp_mode: %+F\n", attr->fp_mode);
139 if (has_fp_conv_attr(n)) {
140 const sparc_fp_conv_attr_t *attr = get_sparc_fp_conv_attr_const(n);
141 ir_fprintf(F, "conv from: %+F\n", attr->src_mode);
142 ir_fprintf(F, "conv to: %+F\n", attr->dest_mode);
146 case dump_node_nodeattr_txt:
151 static void sparc_set_attr_imm(ir_node *res, int immediate_value)
153 sparc_attr_t *attr = get_irn_generic_attr(res);
154 attr->immediate_value = immediate_value;
157 static void init_sparc_jmp_cond_attr(ir_node *node, int pnc, bool is_unsigned)
159 sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr(node);
161 attr->is_unsigned = is_unsigned;
164 void set_sparc_jmp_switch_n_projs(ir_node *node, int n_projs)
166 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
167 attr->n_projs = n_projs;
170 void set_sparc_jmp_switch_default_proj_num(ir_node *node, long def_proj_num)
172 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
173 attr->default_proj_num = def_proj_num;
178 int get_sparc_jmp_switch_n_projs(const ir_node *node)
180 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
181 return attr->n_projs;
184 long get_sparc_jmp_switch_default_proj_num(const ir_node *node)
186 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
187 return attr->default_proj_num;
190 sparc_attr_t *get_sparc_attr(ir_node *node)
192 assert(is_sparc_irn(node));
193 return (sparc_attr_t*) get_irn_generic_attr(node);
196 const sparc_attr_t *get_sparc_attr_const(const ir_node *node)
198 assert(is_sparc_irn(node));
199 return (const sparc_attr_t*) get_irn_generic_attr_const(node);
202 sparc_load_store_attr_t *get_sparc_load_store_attr(ir_node *node)
204 assert(has_load_store_attr(node));
205 return (sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
208 const sparc_load_store_attr_t *get_sparc_load_store_attr_const(const ir_node *node)
210 assert(has_load_store_attr(node));
211 return (const sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
214 sparc_symconst_attr_t *get_sparc_symconst_attr(ir_node *node)
216 assert(has_symconst_attr(node));
217 return (sparc_symconst_attr_t*) get_irn_generic_attr_const(node);
220 const sparc_symconst_attr_t *get_sparc_symconst_attr_const(const ir_node *node)
222 assert(has_symconst_attr(node));
223 return (const sparc_symconst_attr_t*) get_irn_generic_attr_const(node);
226 sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr(ir_node *node)
228 assert(has_jmp_cond_attr(node));
229 return (sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
232 const sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr_const(const ir_node *node)
234 assert(has_jmp_cond_attr(node));
235 return (const sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
238 sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr(ir_node *node)
240 assert(has_jmp_switch_attr(node));
241 return (sparc_jmp_switch_attr_t*) get_irn_generic_attr_const(node);
244 const sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr_const(const ir_node *node)
246 assert(has_jmp_switch_attr(node));
247 return (const sparc_jmp_switch_attr_t*) get_irn_generic_attr_const(node);
250 sparc_save_attr_t *get_sparc_save_attr(ir_node *node)
252 assert(has_save_attr(node));
253 return (sparc_save_attr_t*) get_irn_generic_attr_const(node);
256 const sparc_save_attr_t *get_sparc_save_attr_const(const ir_node *node)
258 assert(has_save_attr(node));
259 return (const sparc_save_attr_t*) get_irn_generic_attr_const(node);
262 sparc_fp_attr_t *get_sparc_fp_attr(ir_node *node)
264 assert(has_fp_attr(node));
265 return (sparc_fp_attr_t*) get_irn_generic_attr(node);
268 const sparc_fp_attr_t *get_sparc_fp_attr_const(const ir_node *node)
270 assert(has_fp_attr(node));
271 return (const sparc_fp_attr_t*) get_irn_generic_attr_const(node);
274 sparc_fp_conv_attr_t *get_sparc_fp_conv_attr(ir_node *node)
276 assert(has_fp_conv_attr(node));
277 return (sparc_fp_conv_attr_t*) get_irn_generic_attr(node);
280 const sparc_fp_conv_attr_t *get_sparc_fp_conv_attr_const(const ir_node *node)
282 assert(has_fp_conv_attr(node));
283 return (const sparc_fp_conv_attr_t*) get_irn_generic_attr_const(node);
287 * Returns the argument register requirements of a sparc node.
289 const arch_register_req_t **get_sparc_in_req_all(const ir_node *node)
291 const sparc_attr_t *attr = get_sparc_attr_const(node);
295 void set_sparc_in_req_all(ir_node *node, const arch_register_req_t **reqs)
297 sparc_attr_t *attr = get_sparc_attr(node);
302 * Returns the argument register requirement at position pos of an sparc node.
304 const arch_register_req_t *get_sparc_in_req(const ir_node *node, int pos)
306 const sparc_attr_t *attr = get_sparc_attr_const(node);
307 return attr->in_req[pos];
311 * Sets the IN register requirements at position pos.
313 void set_sparc_req_in(ir_node *node, const arch_register_req_t *req, int pos)
315 sparc_attr_t *attr = get_sparc_attr(node);
316 attr->in_req[pos] = req;
320 * Initializes the nodes attributes.
322 static void init_sparc_attributes(ir_node *node, arch_irn_flags_t flags,
323 const arch_register_req_t **in_reqs,
324 const be_execution_unit_t ***execution_units,
327 ir_graph *irg = get_irn_irg(node);
328 struct obstack *obst = get_irg_obstack(irg);
329 sparc_attr_t *attr = get_sparc_attr(node);
330 backend_info_t *info;
331 (void) execution_units;
333 arch_irn_set_flags(node, flags);
334 attr->in_req = in_reqs;
335 attr->is_load_store = false;
337 info = be_get_info(node);
338 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
339 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
342 static void init_sparc_load_store_attributes(ir_node *res, ir_mode *ls_mode,
344 int entity_sign, long offset,
345 bool is_frame_entity)
347 sparc_load_store_attr_t *attr = get_sparc_load_store_attr(res);
348 attr->load_store_mode = ls_mode;
349 attr->entity = entity;
350 attr->entity_sign = entity_sign;
351 attr->is_frame_entity = is_frame_entity;
352 attr->offset = offset;
353 attr->base.is_load_store = true;
356 static void init_sparc_symconst_attributes(ir_node *res, ir_entity *entity)
358 sparc_symconst_attr_t *attr = get_sparc_symconst_attr(res);
359 attr->entity = entity;
363 static void init_sparc_save_attributes(ir_node *res, int initial_stacksize)
365 sparc_save_attr_t *attr = get_sparc_save_attr(res);
366 attr->initial_stacksize = initial_stacksize;
369 static void init_sparc_fp_attributes(ir_node *res, ir_mode *fp_mode)
371 sparc_fp_attr_t *attr = get_sparc_fp_attr(res);
372 attr->fp_mode = fp_mode;
375 static void init_sparc_fp_conv_attributes(ir_node *res, ir_mode *src_mode,
378 sparc_fp_conv_attr_t *attr = get_sparc_fp_conv_attr(res);
379 attr->src_mode = src_mode;
380 attr->dest_mode = dest_mode;
384 * copies sparc attributes of node
386 static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
389 struct obstack *obst = get_irg_obstack(irg);
390 const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
391 sparc_attr_t *attr_new = get_sparc_attr(new_node);
392 backend_info_t *old_info = be_get_info(old_node);
393 backend_info_t *new_info = be_get_info(new_node);
395 /* copy the attributes */
396 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
398 new_info->out_infos =
399 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
403 * compare some node's attributes
405 static int cmp_attr_sparc(ir_node *a, ir_node *b)
407 const sparc_attr_t *attr_a = get_sparc_attr_const(a);
408 const sparc_attr_t *attr_b = get_sparc_attr_const(b);
410 return attr_a->immediate_value != attr_b->immediate_value
411 || attr_a->is_load_store != attr_b->is_load_store;
414 static int cmp_attr_sparc_load_store(ir_node *a, ir_node *b)
416 const sparc_load_store_attr_t *attr_a = get_sparc_load_store_attr_const(a);
417 const sparc_load_store_attr_t *attr_b = get_sparc_load_store_attr_const(b);
419 if (cmp_attr_sparc(a, b))
422 return attr_a->entity != attr_b->entity
423 || attr_a->entity_sign != attr_b->entity_sign
424 || attr_a->is_frame_entity != attr_b->is_frame_entity
425 || attr_a->load_store_mode != attr_b->load_store_mode
426 || attr_a->offset != attr_b->offset;
429 static int cmp_attr_sparc_symconst(ir_node *a, ir_node *b)
431 const sparc_symconst_attr_t *attr_a = get_sparc_symconst_attr_const(a);
432 const sparc_symconst_attr_t *attr_b = get_sparc_symconst_attr_const(b);
434 if (cmp_attr_sparc(a, b))
437 return attr_a->entity != attr_b->entity
438 || attr_a->fp_offset != attr_b->fp_offset;
441 static int cmp_attr_sparc_jmp_cond(ir_node *a, ir_node *b)
443 const sparc_jmp_cond_attr_t *attr_a = get_sparc_jmp_cond_attr_const(a);
444 const sparc_jmp_cond_attr_t *attr_b = get_sparc_jmp_cond_attr_const(b);
446 if (cmp_attr_sparc(a, b))
449 return attr_a->pnc != attr_b->pnc
450 || attr_a->is_unsigned != attr_b->is_unsigned;
453 static int cmp_attr_sparc_jmp_switch(ir_node *a, ir_node *b)
455 const sparc_jmp_switch_attr_t *attr_a = get_sparc_jmp_switch_attr_const(a);
456 const sparc_jmp_switch_attr_t *attr_b = get_sparc_jmp_switch_attr_const(b);
458 if (cmp_attr_sparc(a, b))
461 return attr_a->default_proj_num != attr_b->default_proj_num
462 || attr_a->n_projs != attr_b->n_projs;
465 static int cmp_attr_sparc_save(ir_node *a, ir_node *b)
467 const sparc_save_attr_t *attr_a = get_sparc_save_attr_const(a);
468 const sparc_save_attr_t *attr_b = get_sparc_save_attr_const(b);
470 if (cmp_attr_sparc(a, b))
473 return attr_a->initial_stacksize != attr_b->initial_stacksize;
476 static int cmp_attr_sparc_fp(ir_node *a, ir_node *b)
478 const sparc_fp_attr_t *attr_a = get_sparc_fp_attr_const(a);
479 const sparc_fp_attr_t *attr_b = get_sparc_fp_attr_const(b);
481 if (cmp_attr_sparc(a, b))
484 return attr_a->fp_mode != attr_b->fp_mode;
487 static int cmp_attr_sparc_fp_conv(ir_node *a, ir_node *b)
489 const sparc_fp_conv_attr_t *attr_a = get_sparc_fp_conv_attr_const(a);
490 const sparc_fp_conv_attr_t *attr_b = get_sparc_fp_conv_attr_const(b);
492 if (cmp_attr_sparc(a, b))
495 return attr_a->src_mode != attr_b->src_mode
496 || attr_a->dest_mode != attr_b->dest_mode;;
499 /* Include the generated constructor functions */
500 #include "gen_sparc_new_nodes.c.inl"