2 * This file implements the creation of the achitecture specific firm opcodes
3 * and the coresponding node constructors for the ppc assembler irg.
19 #include "irgraph_t.h"
25 #include "firm_common_t.h"
29 #include "../bearch.h"
31 #include "ppc32_nodes_attr.h"
32 #include "ppc32_new_nodes.h"
33 #include "gen_ppc32_regalloc_if.h"
37 /***********************************************************************************
40 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
41 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
42 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
43 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
46 ***********************************************************************************/
49 * Dumps the register requirements for either in or out.
51 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs, int inout) {
52 char *dir = inout ? "out" : "in";
53 int max = inout ? get_ppc32_n_res(n) : get_irn_arity(n);
57 memset(buf, 0, sizeof(buf));
60 for (i = 0; i < max; i++) {
61 fprintf(F, "%sreq #%d =", dir, i);
63 if (reqs[i]->type == arch_register_req_type_none) {
67 if (reqs[i]->type & arch_register_req_type_normal) {
68 fprintf(F, " %s", reqs[i]->cls->name);
71 if (reqs[i]->type & arch_register_req_type_limited) {
73 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
76 if (reqs[i]->type & arch_register_req_type_should_be_same) {
77 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
80 if (reqs[i]->type & arch_register_req_type_should_be_different) {
81 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
89 fprintf(F, "%sreq = N/A\n", dir);
95 * Dumper interface for dumping ppc32 nodes in vcg.
96 * @param n the node to dump
97 * @param F the output file
98 * @param reason indicates which kind of information should be dumped
99 * @return 0 on success or != 0 on failure
101 static int ppc32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
102 ir_mode *mode = NULL;
106 const arch_register_req_t **reqs;
107 const arch_register_t **slots;
110 case dump_node_opcode_txt:
111 fprintf(F, "%s", get_irn_opname(n));
114 case dump_node_mode_txt:
115 mode = get_irn_mode(n);
118 fprintf(F, "[%s]", get_mode_name(mode));
121 fprintf(F, "[?NOMODE?]");
125 case dump_node_nodeattr_txt:
127 /* TODO: dump some attributes which should show up */
128 /* in node name in dump (e.g. consts or the like) */
132 case dump_node_info_txt:
133 attr = get_ppc32_attr(n);
134 fprintf(F, "=== ppc attr begin ===\n");
136 /* dump IN requirements */
137 if (get_irn_arity(n) > 0) {
138 reqs = get_ppc32_in_req_all(n);
139 dump_reg_req(F, n, reqs, 0);
142 /* dump OUT requirements */
143 if (attr->n_res > 0) {
144 reqs = get_ppc32_out_req_all(n);
145 dump_reg_req(F, n, reqs, 1);
148 /* dump assigned registers */
149 slots = get_ppc32_slots(n);
150 if (slots && attr->n_res > 0) {
151 for (i = 0; i < attr->n_res; i++) {
153 fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
156 fprintf(F, "reg #%d = n/a\n", i);
163 fprintf(F, "n_res = %d\n", get_ppc32_n_res(n));
166 fprintf(F, "flags =");
167 if (attr->flags == arch_irn_flags_none) {
171 if (attr->flags & arch_irn_flags_dont_spill) {
172 fprintf(F, " unspillable");
174 if (attr->flags & arch_irn_flags_rematerializable) {
175 fprintf(F, " remat");
177 if (attr->flags & arch_irn_flags_ignore) {
178 fprintf(F, " ignore");
181 fprintf(F, " (%d)\n", attr->flags);
183 /* TODO: dump all additional attributes */
185 fprintf(F, "=== ppc attr end ===\n");
186 /* end of: case dump_node_info_txt */
196 /***************************************************************************************************
198 * | | | | | | / / | | | | | | | |
199 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
200 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
201 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
202 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
205 ***************************************************************************************************/
208 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
209 * Firm was made by people hating const :-(
211 ppc32_attr_t *get_ppc32_attr(const ir_node *node) {
212 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
213 return (ppc32_attr_t *)get_irn_generic_attr((ir_node *)node);
217 * Returns the argument register requirements of a ppc node.
219 const arch_register_req_t **get_ppc32_in_req_all(const ir_node *node) {
220 ppc32_attr_t *attr = get_ppc32_attr(node);
225 * Returns the result register requirements of an ppc node.
227 const arch_register_req_t **get_ppc32_out_req_all(const ir_node *node) {
228 ppc32_attr_t *attr = get_ppc32_attr(node);
229 return attr->out_req;
233 * Returns the argument register requirement at position pos of an ppc node.
235 const arch_register_req_t *get_ppc32_in_req(const ir_node *node, int pos) {
236 ppc32_attr_t *attr = get_ppc32_attr(node);
237 return attr->in_req[pos];
241 * Returns the result register requirement at position pos of an ppc node.
243 const arch_register_req_t *get_ppc32_out_req(const ir_node *node, int pos) {
244 ppc32_attr_t *attr = get_ppc32_attr(node);
245 return attr->out_req[pos];
249 * Sets the OUT register requirements at position pos.
251 void set_ppc32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
252 ppc32_attr_t *attr = get_ppc32_attr(node);
253 attr->out_req[pos] = req;
257 * Sets the IN register requirements at position pos.
259 void set_ppc32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
260 ppc32_attr_t *attr = get_ppc32_attr(node);
261 attr->in_req[pos] = req;
265 * Returns the register flag of an ppc node.
267 arch_irn_flags_t get_ppc32_flags(const ir_node *node) {
268 ppc32_attr_t *attr = get_ppc32_attr(node);
273 * Sets the register flag of an ppc node.
275 void set_ppc32_flags(const ir_node *node, arch_irn_flags_t flags) {
276 ppc32_attr_t *attr = get_ppc32_attr(node);
281 * Returns the result register slots of an ppc node.
283 const arch_register_t **get_ppc32_slots(const ir_node *node) {
284 ppc32_attr_t *attr = get_ppc32_attr(node);
289 * Returns the name of the OUT register at position pos.
291 const char *get_ppc32_out_reg_name(const ir_node *node, int pos) {
292 ppc32_attr_t *attr = get_ppc32_attr(node);
294 assert(is_ppc32_irn(node) && "Not an ppc node.");
295 assert(pos < attr->n_res && "Invalid OUT position.");
296 assert(attr->slots[pos] && "No register assigned");
298 return arch_register_get_name(attr->slots[pos]);
302 * Returns the index of the OUT register at position pos within its register class.
304 int get_ppc32_out_regnr(const ir_node *node, int pos) {
305 ppc32_attr_t *attr = get_ppc32_attr(node);
307 assert(is_ppc32_irn(node) && "Not an ppc node.");
308 assert(pos < attr->n_res && "Invalid OUT position.");
309 assert(attr->slots[pos] && "No register assigned");
311 return arch_register_get_index(attr->slots[pos]);
315 * Returns the OUT register at position pos.
317 const arch_register_t *get_ppc32_out_reg(const ir_node *node, int pos) {
318 ppc32_attr_t *attr = get_ppc32_attr(node);
320 assert(is_ppc32_irn(node) && "Not an ppc node.");
321 assert(pos < attr->n_res && "Invalid OUT position.");
322 assert(attr->slots[pos] && "No register assigned");
324 return attr->slots[pos];
328 * Sets the number of results.
330 void set_ppc32_n_res(ir_node *node, int n_res) {
331 ppc32_attr_t *attr = get_ppc32_attr(node);
336 * Returns the number of results.
338 int get_ppc32_n_res(const ir_node *node) {
339 ppc32_attr_t *attr = get_ppc32_attr(node);
344 * Sets the type of the constant (if any)
345 * May be either iro_Const or iro_SymConst
347 /* void set_ppc32_type(const ir_node *node, opcode type) {
348 ppc32_attr_t *attr = get_ppc32_attr(node);
353 * Returns the type of the content (if any)
355 ppc32_attr_content_type get_ppc32_type(const ir_node *node) {
356 ppc32_attr_t *attr = get_ppc32_attr(node);
357 return attr->content_type;
361 * Sets a tarval type content (also updating the content_type)
363 void set_ppc32_constant_tarval(const ir_node *node, tarval *const_tarval) {
364 ppc32_attr_t *attr = get_ppc32_attr(node);
365 attr->content_type = ppc32_ac_Const;
366 attr->data.constant_tarval = const_tarval;
370 * Returns a tarval type constant
372 tarval *get_ppc32_constant_tarval(const ir_node *node) {
373 ppc32_attr_t *attr = get_ppc32_attr(node);
374 return attr->data.constant_tarval;
378 * Sets an ident type constant (also updating the content_type)
380 void set_ppc32_symconst_ident(const ir_node *node, ident *symconst_ident) {
381 ppc32_attr_t *attr = get_ppc32_attr(node);
382 attr->content_type = ppc32_ac_SymConst;
383 attr->data.symconst_ident = symconst_ident;
387 * Returns an ident type constant
389 ident *get_ppc32_symconst_ident(const ir_node *node) {
390 ppc32_attr_t *attr = get_ppc32_attr(node);
391 return attr->data.symconst_ident;
396 * Sets an entity (also updating the content_type)
398 void set_ppc32_frame_entity(const ir_node *node, ir_entity *ent) {
399 ppc32_attr_t *attr = get_ppc32_attr(node);
400 attr->content_type = ppc32_ac_FrameEntity;
401 attr->data.frame_entity = ent;
407 ir_entity *get_ppc32_frame_entity(const ir_node *node) {
408 ppc32_attr_t *attr = get_ppc32_attr(node);
409 return attr->data.frame_entity;
413 * Sets a Rlwimi const (also updating the content_type)
415 void set_ppc32_rlwimi_const(const ir_node *node, unsigned shift, unsigned maskA, unsigned maskB) {
416 ppc32_attr_t *attr = get_ppc32_attr(node);
417 attr->content_type = ppc32_ac_RlwimiConst;
418 attr->data.rlwimi_const.shift = shift;
419 attr->data.rlwimi_const.maskA = maskA;
420 attr->data.rlwimi_const.maskB = maskB;
424 * Returns the rlwimi const structure
426 rlwimi_const_t *get_ppc32_rlwimi_const(const ir_node *node) {
427 ppc32_attr_t *attr = get_ppc32_attr(node);
428 return &attr->data.rlwimi_const;
432 * Sets a Proj number (also updating the content_type)
434 void set_ppc32_proj_nr(const ir_node *node, int proj_nr) {
435 ppc32_attr_t *attr = get_ppc32_attr(node);
436 attr->content_type = ppc32_ac_BranchProj;
437 attr->data.proj_nr = proj_nr;
441 * Returns the proj number
443 int get_ppc32_proj_nr(const ir_node *node) {
444 ppc32_attr_t *attr = get_ppc32_attr(node);
445 return attr->data.proj_nr;
449 * Sets an offset for a memory access (also updating the content_type)
451 void set_ppc32_offset(const ir_node *node, int offset) {
452 ppc32_attr_t *attr = get_ppc32_attr(node);
453 attr->content_type = ppc32_ac_Offset;
454 attr->data.offset = offset;
460 int get_ppc32_offset(const ir_node *node) {
461 ppc32_attr_t *attr = get_ppc32_attr(node);
462 return attr->data.offset;
466 * Sets the offset mode (ppc32_ao_None, ppc32_ao_Lo16, ppc32_ao_Hi16 or ppc32_ao_Ha16)
468 void set_ppc32_offset_mode(const ir_node *node, ppc32_attr_offset_mode mode) {
469 ppc32_attr_t *attr = get_ppc32_attr(node);
470 attr->offset_mode = mode;
474 * Returns the offset mode
476 ppc32_attr_offset_mode get_ppc32_offset_mode(const ir_node *node) {
477 ppc32_attr_t *attr = get_ppc32_attr(node);
478 return attr->offset_mode;
483 * Initializes ppc specific node attributes
485 void init_ppc32_attributes(ir_node *node, int flags,
486 const arch_register_req_t **in_reqs, const arch_register_req_t **out_reqs,
487 const be_execution_unit_t ***execution_units,
488 int n_res, unsigned latency) {
489 ppc32_attr_t *attr = get_ppc32_attr(node);
492 attr->in_req = in_reqs;
493 attr->out_req = out_reqs;
496 attr->content_type = ppc32_ac_None;
497 attr->offset_mode = ppc32_ao_Illegal;
498 attr->data.empty = NULL;
500 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
504 /***************************************************************************************
507 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
508 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
509 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
510 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
512 ***************************************************************************************/
514 /* Include the generated constructor functions */
515 #include "gen_ppc32_new_nodes.c.inl"