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
25 * @version $Id: TEMPLATE_new_nodes.c 26673 2009-10-01 16:43:13Z matze $
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 n the node to dump
51 * @param F the output file
52 * @param reason indicates which kind of information should be dumped
53 * @return 0 on success or != 0 on failure
55 static int sparc_dump_node(ir_node *n, FILE *F, dump_reason_t reason)
60 case dump_node_opcode_txt:
61 fprintf(F, "%s", get_irn_opname(n));
64 case dump_node_mode_txt:
65 mode = get_irn_mode(n);
68 fprintf(F, "[%s]", get_mode_name(mode));
70 fprintf(F, "[?NOMODE?]");
74 case dump_node_nodeattr_txt:
76 /* TODO: dump some attributes which should show up */
77 /* in node name in dump (e.g. consts or the like) */
81 case dump_node_info_txt:
82 arch_dump_reqs_and_registers(F, n);
89 /* ATTRIBUTE INIT SETTERS / HELPERS */
90 static void sparc_set_attr_imm(ir_node *res, int immediate_value)
92 sparc_attr_t *attr = get_irn_generic_attr(res);
93 attr->immediate_value = immediate_value;
96 void set_sparc_jmp_cond_proj_num(ir_node *node, int proj_num)
98 sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr(node);
99 attr->proj_num = proj_num;
102 void set_sparc_jmp_switch_n_projs(ir_node *node, int n_projs)
104 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
105 attr->n_projs = n_projs;
108 void set_sparc_jmp_switch_default_proj_num(ir_node *node, long def_proj_num)
110 sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr(node);
111 attr->default_proj_num = def_proj_num;
116 int get_sparc_jmp_cond_proj_num(const ir_node *node) {
117 const sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr_const(node);
118 return attr->proj_num;
121 int get_sparc_jmp_switch_n_projs(const ir_node *node) {
122 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
123 return attr->n_projs;
126 long get_sparc_jmp_switch_default_proj_num(const ir_node *node) {
127 const sparc_jmp_switch_attr_t *attr = get_sparc_jmp_switch_attr_const(node);
128 return attr->default_proj_num;
132 /* ATTRIBUTE GETTERS */
133 sparc_attr_t *get_sparc_attr(ir_node *node)
135 assert(is_sparc_irn(node) && "need sparc node to get attributes");
136 return (sparc_attr_t *)get_irn_generic_attr(node);
139 const sparc_attr_t *get_sparc_attr_const(const ir_node *node)
141 assert(is_sparc_irn(node) && "need sparc node to get attributes");
142 return (const sparc_attr_t *)get_irn_generic_attr_const(node);
147 sparc_load_store_attr_t *get_sparc_load_store_attr(ir_node *node)
149 assert(is_sparc_irn(node) && "need sparc node to get attributes");
150 return (sparc_load_store_attr_t *)get_irn_generic_attr_const(node);
153 const sparc_load_store_attr_t *get_sparc_load_store_attr_const(const ir_node *node)
155 assert(is_sparc_irn(node) && "need sparc node to get attributes");
156 return (const sparc_load_store_attr_t *)get_irn_generic_attr_const(node);
161 sparc_symconst_attr_t *get_sparc_symconst_attr(ir_node *node)
163 assert((is_sparc_SymConst(node) || is_sparc_FrameAddr(node)) && "need sparc SymConst/FrameAddr node to get attributes");
164 return (sparc_symconst_attr_t *)get_irn_generic_attr_const(node);
167 const sparc_symconst_attr_t *get_sparc_symconst_attr_const(const ir_node *node)
169 assert((is_sparc_SymConst(node) || is_sparc_FrameAddr(node)) && "need sparc SymConst/FrameAddr node to get attributes");
170 return (const sparc_symconst_attr_t *)get_irn_generic_attr_const(node);
174 sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr(ir_node *node)
176 assert(is_sparc_Branch(node) && "need sparc B node to get attributes");
177 return (sparc_jmp_cond_attr_t *)get_irn_generic_attr_const(node);
180 const sparc_jmp_cond_attr_t *get_sparc_jmp_cond_attr_const(const ir_node *node)
182 assert(is_sparc_Branch(node) && "need sparc B node to get attributes");
183 return (const sparc_jmp_cond_attr_t *)get_irn_generic_attr_const(node);
187 sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr(ir_node *node)
189 assert(is_sparc_SwitchJmp(node) && "need sparc SwitchJmp node to get attributes");
190 return (sparc_jmp_switch_attr_t *)get_irn_generic_attr_const(node);
193 const sparc_jmp_switch_attr_t *get_sparc_jmp_switch_attr_const(const ir_node *node)
195 assert(is_sparc_SwitchJmp(node) && "need sparc SwitchJmp node to get attributes");
196 return (const sparc_jmp_switch_attr_t *)get_irn_generic_attr_const(node);
200 sparc_cmp_attr_t *get_sparc_cmp_attr(ir_node *node)
202 assert(is_sparc_irn(node) && "need sparc node to get attributes");
203 return (sparc_cmp_attr_t *)get_irn_generic_attr_const(node);
206 const sparc_cmp_attr_t *get_sparc_cmp_attr_const(const ir_node *node)
208 assert(is_sparc_irn(node) && "need sparc node to get attributes");
209 return (const sparc_cmp_attr_t *)get_irn_generic_attr_const(node);
213 * Returns the argument register requirements of a sparc node.
215 const arch_register_req_t **get_sparc_in_req_all(const ir_node *node)
217 const sparc_attr_t *attr = get_sparc_attr_const(node);
222 * Returns the argument register requirement at position pos of an sparc node.
224 const arch_register_req_t *get_sparc_in_req(const ir_node *node, int pos)
226 const sparc_attr_t *attr = get_sparc_attr_const(node);
227 return attr->in_req[pos];
231 * Sets the IN register requirements at position pos.
233 void set_sparc_req_in(ir_node *node, const arch_register_req_t *req, int pos)
235 sparc_attr_t *attr = get_sparc_attr(node);
236 attr->in_req[pos] = req;
240 * Initializes the nodes attributes.
242 void init_sparc_attributes(ir_node *node, arch_irn_flags_t flags,
243 const arch_register_req_t **in_reqs,
244 const be_execution_unit_t ***execution_units,
247 ir_graph *irg = get_irn_irg(node);
248 struct obstack *obst = get_irg_obstack(irg);
249 sparc_attr_t *attr = get_sparc_attr(node);
250 backend_info_t *info;
251 (void) execution_units;
253 arch_irn_set_flags(node, flags);
254 attr->in_req = in_reqs;
255 attr->is_load_store = false;
257 info = be_get_info(node);
258 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
259 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
262 /* CUSTOM ATTRIBUTE INIT FUNCTIONS */
263 static void init_sparc_load_store_attributes(ir_node *res, ir_mode *ls_mode,
265 int entity_sign, long offset,
266 bool is_frame_entity)
268 sparc_load_store_attr_t *attr = get_irn_generic_attr(res);
269 attr->load_store_mode = ls_mode;
270 attr->entity = entity;
271 attr->entity_sign = entity_sign;
272 attr->is_frame_entity = is_frame_entity;
273 attr->offset = offset;
274 attr->base.is_load_store = true;
277 static void init_sparc_cmp_attr(ir_node *res, bool ins_permuted, bool is_unsigned)
279 sparc_cmp_attr_t *attr = get_irn_generic_attr(res);
280 attr->ins_permuted = ins_permuted;
281 attr->is_unsigned = is_unsigned;
284 static void init_sparc_symconst_attributes(ir_node *res, ir_entity *entity)
286 sparc_symconst_attr_t *attr = get_irn_generic_attr(res);
287 attr->entity = entity;
292 * copies sparc attributes of node
294 static void sparc_copy_attr(const ir_node *old_node, ir_node *new_node) {
295 ir_graph *irg = get_irn_irg(new_node);
296 struct obstack *obst = get_irg_obstack(irg);
297 const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
298 sparc_attr_t *attr_new = get_sparc_attr(new_node);
299 backend_info_t *old_info = be_get_info(old_node);
300 backend_info_t *new_info = be_get_info(new_node);
302 /* copy the attributes */
303 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
305 new_info->out_infos =
306 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
311 * compare some node's attributes
313 static int cmp_attr_sparc(ir_node *a, ir_node *b)
315 const sparc_attr_t *attr_a = get_sparc_attr_const(a);
316 const sparc_attr_t *attr_b = get_sparc_attr_const(b);
318 return attr_a->immediate_value != attr_b->immediate_value
319 || attr_a->is_load_store != attr_b->is_load_store;
323 /* CUSTOM ATTRIBUTE CMP FUNCTIONS */
324 static int cmp_attr_sparc_load_store(ir_node *a, ir_node *b)
326 const sparc_load_store_attr_t *attr_a = get_sparc_load_store_attr_const(a);
327 const sparc_load_store_attr_t *attr_b = get_sparc_load_store_attr_const(b);
329 if (cmp_attr_sparc(a, b))
332 return attr_a->entity != attr_b->entity
333 || attr_a->entity_sign != attr_b->entity_sign
334 || attr_a->is_frame_entity != attr_b->is_frame_entity
335 || attr_a->load_store_mode != attr_b->load_store_mode
336 || attr_a->offset != attr_b->offset;
339 static int cmp_attr_sparc_symconst(ir_node *a, ir_node *b)
341 const sparc_symconst_attr_t *attr_a = get_sparc_symconst_attr_const(a);
342 const sparc_symconst_attr_t *attr_b = get_sparc_symconst_attr_const(b);
344 if (cmp_attr_sparc(a, b))
347 return attr_a->entity != attr_b->entity
348 || attr_a->fp_offset != attr_b->fp_offset;
351 static int cmp_attr_sparc_jmp_cond(ir_node *a, ir_node *b)
353 const sparc_jmp_cond_attr_t *attr_a = get_sparc_jmp_cond_attr_const(a);
354 const sparc_jmp_cond_attr_t *attr_b = get_sparc_jmp_cond_attr_const(b);
356 if (cmp_attr_sparc(a, b))
359 return attr_a->proj_num != attr_b->proj_num;
362 static int cmp_attr_sparc_jmp_switch(ir_node *a, ir_node *b)
364 const sparc_jmp_switch_attr_t *attr_a = get_sparc_jmp_switch_attr_const(a);
365 const sparc_jmp_switch_attr_t *attr_b = get_sparc_jmp_switch_attr_const(b);
367 if (cmp_attr_sparc(a, b))
370 return attr_a->default_proj_num != attr_b->default_proj_num
371 || attr_a->n_projs != attr_b->n_projs;
374 static int cmp_attr_sparc_cmp(ir_node *a, ir_node *b)
376 const sparc_cmp_attr_t *attr_a = get_sparc_cmp_attr_const(a);
377 const sparc_cmp_attr_t *attr_b = get_sparc_cmp_attr_const(b);
379 if (cmp_attr_sparc(a, b))
382 return attr_a->ins_permuted != attr_b->ins_permuted
383 || attr_a->is_unsigned != attr_b->is_unsigned;
386 /* Include the generated constructor functions */
387 #include "gen_sparc_new_nodes.c.inl"