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"
41 #include "../bearch.h"
43 #include "sparc_nodes_attr.h"
44 #include "sparc_new_nodes.h"
45 #include "gen_sparc_regalloc_if.h"
47 bool sparc_has_load_store_attr(const ir_node *node)
49 return is_sparc_Ld(node) || is_sparc_St(node) || is_sparc_Ldf(node)
50 || is_sparc_Stf(node);
53 static bool has_jmp_cond_attr(const ir_node *node)
55 return is_sparc_Bicc(node) || is_sparc_fbfcc(node);
58 static bool has_switch_jmp_attr(const ir_node *node)
60 return is_sparc_SwitchJmp(node);
63 static bool has_save_attr(const ir_node *node)
65 return is_sparc_Save(node);
68 static bool has_fp_attr(const ir_node *node)
70 return is_sparc_fadd(node) || is_sparc_fsub(node)
71 || is_sparc_fmul(node) || is_sparc_fdiv(node)
72 || is_sparc_fftoi(node) || is_sparc_fitof(node)
73 || is_sparc_fneg(node) || is_sparc_fcmp(node);
76 static bool has_fp_conv_attr(const ir_node *node)
78 return is_sparc_fftof(node);
82 * Dumper interface for dumping sparc nodes in vcg.
83 * @param F the output file
84 * @param n the node to dump
85 * @param reason indicates which kind of information should be dumped
87 static void sparc_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
89 const sparc_attr_t *attr;
92 case dump_node_opcode_txt:
93 fprintf(F, "%s", get_irn_opname(n));
96 case dump_node_mode_txt:
99 case dump_node_info_txt:
100 arch_dump_reqs_and_registers(F, n);
101 attr = get_sparc_attr_const(n);
102 if (attr->immediate_value_entity) {
103 ir_fprintf(F, "entity: %+F (offset %d)\n",
104 attr->immediate_value_entity, attr->immediate_value);
106 ir_fprintf(F, "immediate value: %d\n", attr->immediate_value);
108 if (has_save_attr(n)) {
109 const sparc_save_attr_t *attr = get_sparc_save_attr_const(n);
110 fprintf(F, "initial stacksize: %d\n", attr->initial_stacksize);
112 if (sparc_has_load_store_attr(n)) {
113 const sparc_load_store_attr_t *attr = get_sparc_load_store_attr_const(n);
114 ir_fprintf(F, "load store mode: %+F\n", attr->load_store_mode);
115 fprintf(F, "is frame entity: %s\n",
116 attr->is_frame_entity ? "true" : "false");
118 if (has_jmp_cond_attr(n)) {
119 const sparc_jmp_cond_attr_t *attr
120 = get_sparc_jmp_cond_attr_const(n);
121 fprintf(F, "pnc: %d (%s)\n", attr->pnc, get_pnc_string(attr->pnc));
122 fprintf(F, "unsigned: %s\n", attr->is_unsigned ? "true" : "false");
124 if (has_switch_jmp_attr(n)) {
125 const sparc_switch_jmp_attr_t *attr
126 = get_sparc_switch_jmp_attr_const(n);
127 fprintf(F, "default proj: %ld\n", attr->default_proj_num);
129 if (has_fp_attr(n)) {
130 const sparc_fp_attr_t *attr = get_sparc_fp_attr_const(n);
131 ir_fprintf(F, "fp_mode: %+F\n", attr->fp_mode);
133 if (has_fp_conv_attr(n)) {
134 const sparc_fp_conv_attr_t *attr = get_sparc_fp_conv_attr_const(n);
135 ir_fprintf(F, "conv from: %+F\n", attr->src_mode);
136 ir_fprintf(F, "conv to: %+F\n", attr->dest_mode);
140 case dump_node_nodeattr_txt:
145 static void sparc_set_attr_imm(ir_node *res, ir_entity *entity,
146 int32_t immediate_value)
148 sparc_attr_t *attr = get_irn_generic_attr(res);
149 attr->immediate_value_entity = entity;
150 attr->immediate_value = immediate_value;
153 static void init_sparc_jmp_cond_attr(ir_node *node, int pnc, bool is_unsigned)
155 sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr(node);
157 attr->is_unsigned = is_unsigned;
160 sparc_attr_t *get_sparc_attr(ir_node *node)
162 assert(is_sparc_irn(node));
163 return (sparc_attr_t*) get_irn_generic_attr(node);
166 const sparc_attr_t *get_sparc_attr_const(const ir_node *node)
168 assert(is_sparc_irn(node));
169 return (const sparc_attr_t*) get_irn_generic_attr_const(node);
172 sparc_load_store_attr_t *get_sparc_load_store_attr(ir_node *node)
174 assert(sparc_has_load_store_attr(node));
175 return (sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
178 const sparc_load_store_attr_t *get_sparc_load_store_attr_const(const ir_node *node)
180 assert(sparc_has_load_store_attr(node));
181 return (const sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
184 sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr(ir_node *node)
186 assert(has_jmp_cond_attr(node));
187 return (sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
190 const sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr_const(const ir_node *node)
192 assert(has_jmp_cond_attr(node));
193 return (const sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
196 sparc_switch_jmp_attr_t *get_sparc_switch_jmp_attr(ir_node *node)
198 assert(has_switch_jmp_attr(node));
199 return (sparc_switch_jmp_attr_t*) get_irn_generic_attr_const(node);
202 const sparc_switch_jmp_attr_t *get_sparc_switch_jmp_attr_const(const ir_node *node)
204 assert(has_switch_jmp_attr(node));
205 return (const sparc_switch_jmp_attr_t*) get_irn_generic_attr_const(node);
208 sparc_save_attr_t *get_sparc_save_attr(ir_node *node)
210 assert(has_save_attr(node));
211 return (sparc_save_attr_t*) get_irn_generic_attr_const(node);
214 const sparc_save_attr_t *get_sparc_save_attr_const(const ir_node *node)
216 assert(has_save_attr(node));
217 return (const sparc_save_attr_t*) get_irn_generic_attr_const(node);
220 sparc_fp_attr_t *get_sparc_fp_attr(ir_node *node)
222 assert(has_fp_attr(node));
223 return (sparc_fp_attr_t*) get_irn_generic_attr(node);
226 const sparc_fp_attr_t *get_sparc_fp_attr_const(const ir_node *node)
228 assert(has_fp_attr(node));
229 return (const sparc_fp_attr_t*) get_irn_generic_attr_const(node);
232 sparc_fp_conv_attr_t *get_sparc_fp_conv_attr(ir_node *node)
234 assert(has_fp_conv_attr(node));
235 return (sparc_fp_conv_attr_t*) get_irn_generic_attr(node);
238 const sparc_fp_conv_attr_t *get_sparc_fp_conv_attr_const(const ir_node *node)
240 assert(has_fp_conv_attr(node));
241 return (const sparc_fp_conv_attr_t*) get_irn_generic_attr_const(node);
245 * Returns the argument register requirements of a sparc node.
247 const arch_register_req_t **get_sparc_in_req_all(const ir_node *node)
249 const sparc_attr_t *attr = get_sparc_attr_const(node);
253 void set_sparc_in_req_all(ir_node *node, const arch_register_req_t **reqs)
255 sparc_attr_t *attr = get_sparc_attr(node);
260 * Returns the argument register requirement at position pos of an sparc node.
262 const arch_register_req_t *get_sparc_in_req(const ir_node *node, int pos)
264 const sparc_attr_t *attr = get_sparc_attr_const(node);
265 return attr->in_req[pos];
269 * Sets the IN register requirements at position pos.
271 void set_sparc_req_in(ir_node *node, const arch_register_req_t *req, int pos)
273 sparc_attr_t *attr = get_sparc_attr(node);
274 attr->in_req[pos] = req;
278 * Initializes the nodes attributes.
280 static void init_sparc_attributes(ir_node *node, arch_irn_flags_t flags,
281 const arch_register_req_t **in_reqs,
282 const be_execution_unit_t ***execution_units,
285 ir_graph *irg = get_irn_irg(node);
286 struct obstack *obst = get_irg_obstack(irg);
287 sparc_attr_t *attr = get_sparc_attr(node);
288 backend_info_t *info;
289 (void) execution_units;
291 arch_irn_set_flags(node, flags);
292 attr->in_req = in_reqs;
294 info = be_get_info(node);
295 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
296 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
299 static void init_sparc_load_store_attributes(ir_node *res, ir_mode *ls_mode,
300 ir_entity *entity, int32_t offset,
301 bool is_frame_entity,
304 sparc_load_store_attr_t *attr = get_sparc_load_store_attr(res);
305 attr->base.immediate_value_entity = entity;
306 attr->base.immediate_value = offset;
307 attr->load_store_mode = ls_mode;
308 attr->is_frame_entity = is_frame_entity;
309 attr->is_reg_reg = is_reg_reg;
312 static void init_sparc_save_attributes(ir_node *res, int initial_stacksize)
314 sparc_save_attr_t *attr = get_sparc_save_attr(res);
315 attr->initial_stacksize = initial_stacksize;
318 static void init_sparc_fp_attributes(ir_node *res, ir_mode *fp_mode)
320 sparc_fp_attr_t *attr = get_sparc_fp_attr(res);
321 attr->fp_mode = fp_mode;
324 static void init_sparc_fp_conv_attributes(ir_node *res, ir_mode *src_mode,
327 sparc_fp_conv_attr_t *attr = get_sparc_fp_conv_attr(res);
328 attr->src_mode = src_mode;
329 attr->dest_mode = dest_mode;
332 static void init_sparc_switch_jmp_attributes(ir_node *res, long default_pn,
333 ir_entity *jump_table)
335 sparc_switch_jmp_attr_t *attr = get_sparc_switch_jmp_attr(res);
336 attr->default_proj_num = default_pn;
337 attr->jump_table = jump_table;
341 * copies sparc attributes of node
343 static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
346 struct obstack *obst = get_irg_obstack(irg);
347 const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
348 sparc_attr_t *attr_new = get_sparc_attr(new_node);
349 backend_info_t *old_info = be_get_info(old_node);
350 backend_info_t *new_info = be_get_info(new_node);
352 /* copy the attributes */
353 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
355 new_info->out_infos =
356 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
360 * compare some node's attributes
362 static int cmp_attr_sparc(ir_node *a, ir_node *b)
364 const sparc_attr_t *attr_a = get_sparc_attr_const(a);
365 const sparc_attr_t *attr_b = get_sparc_attr_const(b);
367 return attr_a->immediate_value != attr_b->immediate_value
368 || attr_a->immediate_value_entity != attr_b->immediate_value_entity;
371 static int cmp_attr_sparc_load_store(ir_node *a, ir_node *b)
373 const sparc_load_store_attr_t *attr_a = get_sparc_load_store_attr_const(a);
374 const sparc_load_store_attr_t *attr_b = get_sparc_load_store_attr_const(b);
376 if (cmp_attr_sparc(a, b))
379 return attr_a->is_frame_entity != attr_b->is_frame_entity
380 || attr_a->load_store_mode != attr_b->load_store_mode;
383 static int cmp_attr_sparc_jmp_cond(ir_node *a, ir_node *b)
385 const sparc_jmp_cond_attr_t *attr_a = get_sparc_jmp_cond_attr_const(a);
386 const sparc_jmp_cond_attr_t *attr_b = get_sparc_jmp_cond_attr_const(b);
388 if (cmp_attr_sparc(a, b))
391 return attr_a->pnc != attr_b->pnc
392 || attr_a->is_unsigned != attr_b->is_unsigned;
395 static int cmp_attr_sparc_switch_jmp(ir_node *a, ir_node *b)
397 const sparc_switch_jmp_attr_t *attr_a = get_sparc_switch_jmp_attr_const(a);
398 const sparc_switch_jmp_attr_t *attr_b = get_sparc_switch_jmp_attr_const(b);
400 if (cmp_attr_sparc(a, b))
403 return attr_a->default_proj_num != attr_b->default_proj_num;
406 static int cmp_attr_sparc_save(ir_node *a, ir_node *b)
408 const sparc_save_attr_t *attr_a = get_sparc_save_attr_const(a);
409 const sparc_save_attr_t *attr_b = get_sparc_save_attr_const(b);
411 if (cmp_attr_sparc(a, b))
414 return attr_a->initial_stacksize != attr_b->initial_stacksize;
417 static int cmp_attr_sparc_fp(ir_node *a, ir_node *b)
419 const sparc_fp_attr_t *attr_a = get_sparc_fp_attr_const(a);
420 const sparc_fp_attr_t *attr_b = get_sparc_fp_attr_const(b);
422 if (cmp_attr_sparc(a, b))
425 return attr_a->fp_mode != attr_b->fp_mode;
428 static int cmp_attr_sparc_fp_conv(ir_node *a, ir_node *b)
430 const sparc_fp_conv_attr_t *attr_a = get_sparc_fp_conv_attr_const(a);
431 const sparc_fp_conv_attr_t *attr_b = get_sparc_fp_conv_attr_const(b);
433 if (cmp_attr_sparc(a, b))
436 return attr_a->src_mode != attr_b->src_mode
437 || attr_a->dest_mode != attr_b->dest_mode;;
440 /* Include the generated constructor functions */
441 #include "gen_sparc_new_nodes.c.inl"