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"
49 * Dumper interface for dumping sparc nodes in vcg.
50 * @param F the output file
51 * @param n the node to dump
52 * @param reason indicates which kind of information should be dumped
54 static void sparc_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
59 case dump_node_opcode_txt:
60 fprintf(F, "%s", get_irn_opname(n));
63 case dump_node_mode_txt:
64 mode = get_irn_mode(n);
67 fprintf(F, "[%s]", get_mode_name(mode));
69 fprintf(F, "[?NOMODE?]");
73 case dump_node_info_txt:
74 arch_dump_reqs_and_registers(F, n);
77 case dump_node_nodeattr_txt:
79 /* TODO: dump some attributes which should show up */
80 /* in node name in dump (e.g. consts or the like) */
83 if (is_sparc_FrameAddr(n)) {
84 const sparc_symconst_attr_t *attr = get_sparc_symconst_attr_const(n);
85 fprintf(F, "fp_offset: 0x%X\n", attr->fp_offset);
88 if (is_sparc_Ld(n) || is_sparc_St(n)) {
89 const sparc_load_store_attr_t *attr = get_sparc_load_store_attr_const(n);
90 fprintf(F, "offset: 0x%lX\n", attr->offset);
91 fprintf(F, "is_frame_entity: %s\n", attr->is_frame_entity == true ? "true" : "false");
98 /* ATTRIBUTE INIT SETTERS / HELPERS */
99 static void sparc_set_attr_imm(ir_node *res, int immediate_value)
101 sparc_attr_t *attr = get_irn_generic_attr(res);
102 attr->immediate_value = immediate_value;
105 void set_sparc_jmp_cond_proj_num(ir_node *node, int proj_num)
107 sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr(node);
108 attr->proj_num = proj_num;
111 void set_sparc_jmp_switch_n_projs(ir_node *node, int n_projs)
113 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
114 attr->n_projs = n_projs;
117 void set_sparc_jmp_switch_default_proj_num(ir_node *node, long def_proj_num)
119 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
120 attr->default_proj_num = def_proj_num;
125 int get_sparc_jmp_cond_proj_num(const ir_node *node)
127 const sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr_const(node);
128 return attr->proj_num;
131 int get_sparc_jmp_switch_n_projs(const ir_node *node)
133 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
134 return attr->n_projs;
137 long get_sparc_jmp_switch_default_proj_num(const ir_node *node)
139 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
140 return attr->default_proj_num;
144 /* ATTRIBUTE GETTERS */
145 sparc_attr_t *get_sparc_attr(ir_node *node)
147 assert(is_sparc_irn(node) && "need sparc node to get attributes");
148 return (sparc_attr_t *)get_irn_generic_attr(node);
151 const sparc_attr_t *get_sparc_attr_const(const ir_node *node)
153 assert(is_sparc_irn(node) && "need sparc node to get attributes");
154 return (const sparc_attr_t *)get_irn_generic_attr_const(node);
157 sparc_load_store_attr_t *get_sparc_load_store_attr(ir_node *node)
159 assert(is_sparc_irn(node) && "need sparc node to get attributes");
160 return (sparc_load_store_attr_t *)get_irn_generic_attr_const(node);
163 const sparc_load_store_attr_t *get_sparc_load_store_attr_const(const ir_node *node)
165 assert(is_sparc_irn(node) && "need sparc node to get attributes");
166 return (const sparc_load_store_attr_t *)get_irn_generic_attr_const(node);
171 sparc_symconst_attr_t *get_sparc_symconst_attr(ir_node *node)
173 assert((is_sparc_SymConst(node) || is_sparc_FrameAddr(node)) && "need sparc SymConst/FrameAddr node to get attributes");
174 return (sparc_symconst_attr_t *)get_irn_generic_attr_const(node);
177 const sparc_symconst_attr_t *get_sparc_symconst_attr_const(const ir_node *node)
179 assert((is_sparc_SymConst(node) || is_sparc_FrameAddr(node)) && "need sparc SymConst/FrameAddr node to get attributes");
180 return (const sparc_symconst_attr_t *)get_irn_generic_attr_const(node);
184 sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr(ir_node *node)
186 assert(is_sparc_BXX(node) && "need sparc B node to get attributes");
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(is_sparc_BXX(node) && "need sparc B node to get attributes");
193 return (const sparc_jmp_cond_attr_t *)get_irn_generic_attr_const(node);
197 sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr(ir_node *node)
199 assert(is_sparc_SwitchJmp(node) && "need sparc SwitchJmp node to get attributes");
200 return (sparc_jmp_switch_attr_t *)get_irn_generic_attr_const(node);
203 const sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr_const(const ir_node *node)
205 assert(is_sparc_SwitchJmp(node) && "need sparc SwitchJmp node to get attributes");
206 return (const sparc_jmp_switch_attr_t *)get_irn_generic_attr_const(node);
209 sparc_cmp_attr_t *get_sparc_cmp_attr(ir_node *node)
211 assert(is_sparc_irn(node) && "need sparc node to get attributes");
212 return (sparc_cmp_attr_t *)get_irn_generic_attr_const(node);
215 const sparc_cmp_attr_t *get_sparc_cmp_attr_const(const ir_node *node)
217 assert(is_sparc_irn(node) && "need sparc node to get attributes");
218 return (const sparc_cmp_attr_t *)get_irn_generic_attr_const(node);
222 sparc_save_attr_t *get_sparc_save_attr(ir_node *node)
224 assert(is_sparc_Save(node) && "need sparc Save node to get attributes");
225 return (sparc_save_attr_t *)get_irn_generic_attr_const(node);
228 const sparc_save_attr_t *get_sparc_save_attr_const(const ir_node *node)
230 assert(is_sparc_Save(node) && "need sparc Save node to get attributes");
231 return (const sparc_save_attr_t *)get_irn_generic_attr_const(node);
235 * Returns the argument register requirements of a sparc node.
237 const arch_register_req_t **get_sparc_in_req_all(const ir_node *node)
239 const sparc_attr_t *attr = get_sparc_attr_const(node);
244 * Returns the argument register requirement at position pos of an sparc node.
246 const arch_register_req_t *get_sparc_in_req(const ir_node *node, int pos)
248 const sparc_attr_t *attr = get_sparc_attr_const(node);
249 return attr->in_req[pos];
253 * Sets the IN register requirements at position pos.
255 void set_sparc_req_in(ir_node *node, const arch_register_req_t *req, int pos)
257 sparc_attr_t *attr = get_sparc_attr(node);
258 attr->in_req[pos] = req;
262 * Initializes the nodes attributes.
264 static void init_sparc_attributes(ir_node *node, arch_irn_flags_t flags,
265 const arch_register_req_t **in_reqs,
266 const be_execution_unit_t ***execution_units,
269 ir_graph *irg = get_irn_irg(node);
270 struct obstack *obst = get_irg_obstack(irg);
271 sparc_attr_t *attr = get_sparc_attr(node);
272 backend_info_t *info;
273 (void) execution_units;
275 arch_irn_set_flags(node, flags);
276 attr->in_req = in_reqs;
277 attr->is_load_store = false;
279 info = be_get_info(node);
280 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
281 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
284 /* CUSTOM ATTRIBUTE INIT FUNCTIONS */
285 static void init_sparc_load_store_attributes(ir_node *res, ir_mode *ls_mode,
287 int entity_sign, long offset,
288 bool is_frame_entity)
290 sparc_load_store_attr_t *attr = get_irn_generic_attr(res);
291 attr->load_store_mode = ls_mode;
292 attr->entity = entity;
293 attr->entity_sign = entity_sign;
294 attr->is_frame_entity = is_frame_entity;
295 attr->offset = offset;
296 attr->base.is_load_store = true;
299 static void init_sparc_cmp_attr(ir_node *res, bool ins_permuted, bool is_unsigned)
301 sparc_cmp_attr_t *attr = get_irn_generic_attr(res);
302 attr->ins_permuted = ins_permuted;
303 attr->is_unsigned = is_unsigned;
306 static void init_sparc_symconst_attributes(ir_node *res, ir_entity *entity)
308 sparc_symconst_attr_t *attr = get_irn_generic_attr(res);
309 attr->entity = entity;
313 static void init_sparc_save_attr(ir_node *res, int initial_stacksize)
315 sparc_save_attr_t *attr = get_irn_generic_attr(res);
316 attr->initial_stacksize = initial_stacksize;
320 * copies sparc attributes of node
322 static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
325 struct obstack *obst = get_irg_obstack(irg);
326 const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
327 sparc_attr_t *attr_new = get_sparc_attr(new_node);
328 backend_info_t *old_info = be_get_info(old_node);
329 backend_info_t *new_info = be_get_info(new_node);
331 /* copy the attributes */
332 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
334 new_info->out_infos =
335 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
340 * compare some node's attributes
342 static int cmp_attr_sparc(ir_node *a, ir_node *b)
344 const sparc_attr_t *attr_a = get_sparc_attr_const(a);
345 const sparc_attr_t *attr_b = get_sparc_attr_const(b);
347 return attr_a->immediate_value != attr_b->immediate_value
348 || attr_a->is_load_store != attr_b->is_load_store;
352 /* CUSTOM ATTRIBUTE CMP FUNCTIONS */
353 static int cmp_attr_sparc_load_store(ir_node *a, ir_node *b)
355 const sparc_load_store_attr_t *attr_a = get_sparc_load_store_attr_const(a);
356 const sparc_load_store_attr_t *attr_b = get_sparc_load_store_attr_const(b);
358 if (cmp_attr_sparc(a, b))
361 return attr_a->entity != attr_b->entity
362 || attr_a->entity_sign != attr_b->entity_sign
363 || attr_a->is_frame_entity != attr_b->is_frame_entity
364 || attr_a->load_store_mode != attr_b->load_store_mode
365 || attr_a->offset != attr_b->offset;
368 static int cmp_attr_sparc_symconst(ir_node *a, ir_node *b)
370 const sparc_symconst_attr_t *attr_a = get_sparc_symconst_attr_const(a);
371 const sparc_symconst_attr_t *attr_b = get_sparc_symconst_attr_const(b);
373 if (cmp_attr_sparc(a, b))
376 return attr_a->entity != attr_b->entity
377 || attr_a->fp_offset != attr_b->fp_offset;
380 static int cmp_attr_sparc_jmp_cond(ir_node *a, ir_node *b)
382 const sparc_jmp_cond_attr_t *attr_a = get_sparc_jmp_cond_attr_const(a);
383 const sparc_jmp_cond_attr_t *attr_b = get_sparc_jmp_cond_attr_const(b);
385 if (cmp_attr_sparc(a, b))
388 return attr_a->proj_num != attr_b->proj_num;
391 static int cmp_attr_sparc_jmp_switch(ir_node *a, ir_node *b)
393 const sparc_jmp_switch_attr_t *attr_a = get_sparc_jmp_switch_attr_const(a);
394 const sparc_jmp_switch_attr_t *attr_b = get_sparc_jmp_switch_attr_const(b);
396 if (cmp_attr_sparc(a, b))
399 return attr_a->default_proj_num != attr_b->default_proj_num
400 || attr_a->n_projs != attr_b->n_projs;
403 static int cmp_attr_sparc_cmp(ir_node *a, ir_node *b)
405 const sparc_cmp_attr_t *attr_a = get_sparc_cmp_attr_const(a);
406 const sparc_cmp_attr_t *attr_b = get_sparc_cmp_attr_const(b);
408 if (cmp_attr_sparc(a, b))
411 return attr_a->ins_permuted != attr_b->ins_permuted
412 || attr_a->is_unsigned != attr_b->is_unsigned;
415 static int cmp_attr_sparc_save(ir_node *a, ir_node *b)
417 const sparc_save_attr_t *attr_a = get_sparc_save_attr_const(a);
418 const sparc_save_attr_t *attr_b = get_sparc_save_attr_const(b);
420 if (cmp_attr_sparc(a, b))
423 return attr_a->initial_stacksize != attr_b->initial_stacksize;
426 /* Include the generated constructor functions */
427 #include "gen_sparc_new_nodes.c.inl"