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);
58 static bool has_jmp_cond_attr(const ir_node *node)
60 return is_sparc_BXX(node);
63 static bool has_jmp_switch_attr(const ir_node *node)
65 return is_sparc_SwitchJmp(node);
68 static bool has_save_attr(const ir_node *node)
70 return is_sparc_Save(node);
74 * Dumper interface for dumping sparc nodes in vcg.
75 * @param F the output file
76 * @param n the node to dump
77 * @param reason indicates which kind of information should be dumped
79 static void sparc_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
82 case dump_node_opcode_txt:
83 fprintf(F, "%s", get_irn_opname(n));
86 case dump_node_mode_txt:
89 case dump_node_info_txt:
90 arch_dump_reqs_and_registers(F, n);
91 if (has_save_attr(n)) {
92 const sparc_save_attr_t *attr = get_sparc_save_attr_const(n);
93 fprintf(F, "initial stacksize: %d\n", attr->initial_stacksize);
95 if (has_symconst_attr(n)) {
96 const sparc_symconst_attr_t *attr = get_sparc_symconst_attr_const(n);
97 ir_fprintf(F, "entity: %+F\n", attr->entity);
98 fprintf(F, "fp_offset: %d\n", attr->fp_offset);
100 if (has_load_store_attr(n)) {
101 const sparc_load_store_attr_t *attr = get_sparc_load_store_attr_const(n);
102 ir_fprintf(F, "load store mode: %+F\n", attr->load_store_mode);
103 ir_fprintf(F, "entity: (sign %d) %+F\n", attr->entity_sign,
105 fprintf(F, "offset: %ld\n", attr->offset);
106 fprintf(F, "is frame entity: %s\n",
107 attr->is_frame_entity ? "true" : "false");
109 if (has_jmp_cond_attr(n)) {
110 const sparc_jmp_cond_attr_t *attr
111 = get_sparc_jmp_cond_attr_const(n);
112 fprintf(F, "pnc: %d (%s)\n", attr->proj_num,
113 get_pnc_string(attr->proj_num));
114 fprintf(F, "unsigned: %s\n", attr->is_unsigned ? "true" : "false");
116 if (has_jmp_switch_attr(n)) {
117 const sparc_jmp_switch_attr_t *attr
118 = get_sparc_jmp_switch_attr_const(n);
119 fprintf(F, "n projs: %d\n", attr->n_projs);
120 fprintf(F, "default proj: %ld\n", attr->default_proj_num);
124 case dump_node_nodeattr_txt:
129 static void sparc_set_attr_imm(ir_node *res, int immediate_value)
131 sparc_attr_t *attr = get_irn_generic_attr(res);
132 attr->immediate_value = immediate_value;
135 static void init_sparc_jmp_cond_attr(ir_node *node, int proj_num,
138 sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr(node);
139 attr->proj_num = proj_num;
140 attr->is_unsigned = is_unsigned;
143 void set_sparc_jmp_switch_n_projs(ir_node *node, int n_projs)
145 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
146 attr->n_projs = n_projs;
149 void set_sparc_jmp_switch_default_proj_num(ir_node *node, long def_proj_num)
151 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
152 attr->default_proj_num = def_proj_num;
157 int get_sparc_jmp_switch_n_projs(const ir_node *node)
159 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
160 return attr->n_projs;
163 long get_sparc_jmp_switch_default_proj_num(const ir_node *node)
165 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
166 return attr->default_proj_num;
169 sparc_attr_t *get_sparc_attr(ir_node *node)
171 assert(is_sparc_irn(node));
172 return (sparc_attr_t*) get_irn_generic_attr(node);
175 const sparc_attr_t *get_sparc_attr_const(const ir_node *node)
177 assert(is_sparc_irn(node));
178 return (const sparc_attr_t*) get_irn_generic_attr_const(node);
181 sparc_load_store_attr_t *get_sparc_load_store_attr(ir_node *node)
183 assert(has_load_store_attr(node));
184 return (sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
187 const sparc_load_store_attr_t *get_sparc_load_store_attr_const(const ir_node *node)
189 assert(has_load_store_attr(node));
190 return (const sparc_load_store_attr_t*) get_irn_generic_attr_const(node);
193 sparc_symconst_attr_t *get_sparc_symconst_attr(ir_node *node)
195 assert(has_symconst_attr(node));
196 return (sparc_symconst_attr_t*) get_irn_generic_attr_const(node);
199 const sparc_symconst_attr_t *get_sparc_symconst_attr_const(const ir_node *node)
201 assert(has_symconst_attr(node));
202 return (const sparc_symconst_attr_t*) get_irn_generic_attr_const(node);
205 sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr(ir_node *node)
207 assert(has_jmp_cond_attr(node));
208 return (sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
211 const sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr_const(const ir_node *node)
213 assert(has_jmp_cond_attr(node));
214 return (const sparc_jmp_cond_attr_t*) get_irn_generic_attr_const(node);
217 sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr(ir_node *node)
219 assert(has_jmp_switch_attr(node));
220 return (sparc_jmp_switch_attr_t*) get_irn_generic_attr_const(node);
223 const sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr_const(const ir_node *node)
225 assert(has_jmp_switch_attr(node));
226 return (const sparc_jmp_switch_attr_t*) get_irn_generic_attr_const(node);
229 sparc_save_attr_t *get_sparc_save_attr(ir_node *node)
231 assert(has_save_attr(node));
232 return (sparc_save_attr_t*) get_irn_generic_attr_const(node);
235 const sparc_save_attr_t *get_sparc_save_attr_const(const ir_node *node)
237 assert(has_save_attr(node));
238 return (const sparc_save_attr_t*) get_irn_generic_attr_const(node);
242 * Returns the argument register requirements of a sparc node.
244 const arch_register_req_t **get_sparc_in_req_all(const ir_node *node)
246 const sparc_attr_t *attr = get_sparc_attr_const(node);
250 void set_sparc_in_req_all(ir_node *node, const arch_register_req_t **reqs)
252 sparc_attr_t *attr = get_sparc_attr(node);
257 * Returns the argument register requirement at position pos of an sparc node.
259 const arch_register_req_t *get_sparc_in_req(const ir_node *node, int pos)
261 const sparc_attr_t *attr = get_sparc_attr_const(node);
262 return attr->in_req[pos];
266 * Sets the IN register requirements at position pos.
268 void set_sparc_req_in(ir_node *node, const arch_register_req_t *req, int pos)
270 sparc_attr_t *attr = get_sparc_attr(node);
271 attr->in_req[pos] = req;
275 * Initializes the nodes attributes.
277 static void init_sparc_attributes(ir_node *node, arch_irn_flags_t flags,
278 const arch_register_req_t **in_reqs,
279 const be_execution_unit_t ***execution_units,
282 ir_graph *irg = get_irn_irg(node);
283 struct obstack *obst = get_irg_obstack(irg);
284 sparc_attr_t *attr = get_sparc_attr(node);
285 backend_info_t *info;
286 (void) execution_units;
288 arch_irn_set_flags(node, flags);
289 attr->in_req = in_reqs;
290 attr->is_load_store = false;
292 info = be_get_info(node);
293 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
294 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
297 /* CUSTOM ATTRIBUTE INIT FUNCTIONS */
298 static void init_sparc_load_store_attributes(ir_node *res, ir_mode *ls_mode,
300 int entity_sign, long offset,
301 bool is_frame_entity)
303 sparc_load_store_attr_t *attr = get_sparc_load_store_attr(res);
304 attr->load_store_mode = ls_mode;
305 attr->entity = entity;
306 attr->entity_sign = entity_sign;
307 attr->is_frame_entity = is_frame_entity;
308 attr->offset = offset;
309 attr->base.is_load_store = true;
312 static void init_sparc_symconst_attributes(ir_node *res, ir_entity *entity)
314 sparc_symconst_attr_t *attr = get_sparc_symconst_attr(res);
315 attr->entity = entity;
319 static void init_sparc_save_attr(ir_node *res, int initial_stacksize)
321 sparc_save_attr_t *attr = get_sparc_save_attr(res);
322 attr->initial_stacksize = initial_stacksize;
326 * copies sparc attributes of node
328 static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
331 struct obstack *obst = get_irg_obstack(irg);
332 const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
333 sparc_attr_t *attr_new = get_sparc_attr(new_node);
334 backend_info_t *old_info = be_get_info(old_node);
335 backend_info_t *new_info = be_get_info(new_node);
337 /* copy the attributes */
338 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
340 new_info->out_infos =
341 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
345 * compare some node's attributes
347 static int cmp_attr_sparc(ir_node *a, ir_node *b)
349 const sparc_attr_t *attr_a = get_sparc_attr_const(a);
350 const sparc_attr_t *attr_b = get_sparc_attr_const(b);
352 return attr_a->immediate_value != attr_b->immediate_value
353 || attr_a->is_load_store != attr_b->is_load_store;
357 /* CUSTOM ATTRIBUTE CMP FUNCTIONS */
358 static int cmp_attr_sparc_load_store(ir_node *a, ir_node *b)
360 const sparc_load_store_attr_t *attr_a = get_sparc_load_store_attr_const(a);
361 const sparc_load_store_attr_t *attr_b = get_sparc_load_store_attr_const(b);
363 if (cmp_attr_sparc(a, b))
366 return attr_a->entity != attr_b->entity
367 || attr_a->entity_sign != attr_b->entity_sign
368 || attr_a->is_frame_entity != attr_b->is_frame_entity
369 || attr_a->load_store_mode != attr_b->load_store_mode
370 || attr_a->offset != attr_b->offset;
373 static int cmp_attr_sparc_symconst(ir_node *a, ir_node *b)
375 const sparc_symconst_attr_t *attr_a = get_sparc_symconst_attr_const(a);
376 const sparc_symconst_attr_t *attr_b = get_sparc_symconst_attr_const(b);
378 if (cmp_attr_sparc(a, b))
381 return attr_a->entity != attr_b->entity
382 || attr_a->fp_offset != attr_b->fp_offset;
385 static int cmp_attr_sparc_jmp_cond(ir_node *a, ir_node *b)
387 const sparc_jmp_cond_attr_t *attr_a = get_sparc_jmp_cond_attr_const(a);
388 const sparc_jmp_cond_attr_t *attr_b = get_sparc_jmp_cond_attr_const(b);
390 if (cmp_attr_sparc(a, b))
393 return attr_a->proj_num != attr_b->proj_num
394 || attr_a->is_unsigned != attr_b->is_unsigned;
397 static int cmp_attr_sparc_jmp_switch(ir_node *a, ir_node *b)
399 const sparc_jmp_switch_attr_t *attr_a = get_sparc_jmp_switch_attr_const(a);
400 const sparc_jmp_switch_attr_t *attr_b = get_sparc_jmp_switch_attr_const(b);
402 if (cmp_attr_sparc(a, b))
405 return attr_a->default_proj_num != attr_b->default_proj_num
406 || attr_a->n_projs != attr_b->n_projs;
409 static int cmp_attr_sparc_save(ir_node *a, ir_node *b)
411 const sparc_save_attr_t *attr_a = get_sparc_save_attr_const(a);
412 const sparc_save_attr_t *attr_b = get_sparc_save_attr_const(b);
414 if (cmp_attr_sparc(a, b))
417 return attr_a->initial_stacksize != attr_b->initial_stacksize;
420 /* Include the generated constructor functions */
421 #include "gen_sparc_new_nodes.c.inl"