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 ppc assembler
25 * @author Moritz Kroll, Jens Mueller
35 #include "irgraph_t.h"
41 #include "firm_common_t.h"
46 #include "../bearch_t.h"
48 #include "ppc32_nodes_attr.h"
49 #include "ppc32_new_nodes.h"
50 #include "gen_ppc32_regalloc_if.h"
54 /***********************************************************************************
57 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
58 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
59 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
60 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
63 ***********************************************************************************/
66 * Dumps the register requirements for either in or out.
68 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs, int inout) {
69 char *dir = inout ? "out" : "in";
70 int max = inout ? get_ppc32_n_res(n) : get_irn_arity(n);
74 memset(buf, 0, sizeof(buf));
77 for (i = 0; i < max; i++) {
78 fprintf(F, "%sreq #%d =", dir, i);
80 if (reqs[i]->type == arch_register_req_type_none) {
84 if (reqs[i]->type & arch_register_req_type_normal) {
85 fprintf(F, " %s", reqs[i]->cls->name);
88 if (reqs[i]->type & arch_register_req_type_limited) {
90 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
93 if (reqs[i]->type & arch_register_req_type_should_be_same) {
94 const unsigned other = reqs[i]->other_same;
97 ir_fprintf(F, " same as");
98 for (i = 0; 1U << i <= other; ++i) {
99 if (other & (1U << i)) {
100 ir_fprintf(F, " %+F", get_irn_n(n, i));
105 if (reqs[i]->type & arch_register_req_type_should_be_different) {
106 const unsigned other = reqs[i]->other_different;
109 ir_fprintf(F, " different from");
110 for (i = 0; 1U << i <= other; ++i) {
111 if (other & (1U << i)) {
112 ir_fprintf(F, " %+F", get_irn_n(n, i));
122 fprintf(F, "%sreq = N/A\n", dir);
128 * Dumper interface for dumping ppc32 nodes in vcg.
129 * @param n the node to dump
130 * @param F the output file
131 * @param reason indicates which kind of information should be dumped
132 * @return 0 on success or != 0 on failure
134 static int ppc32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
135 ir_mode *mode = NULL;
139 const arch_register_req_t **reqs;
140 const arch_register_t **slots;
143 case dump_node_opcode_txt:
144 fprintf(F, "%s", get_irn_opname(n));
147 case dump_node_mode_txt:
148 mode = get_irn_mode(n);
151 fprintf(F, "[%s]", get_mode_name(mode));
154 fprintf(F, "[?NOMODE?]");
158 case dump_node_nodeattr_txt:
160 /* TODO: dump some attributes which should show up */
161 /* in node name in dump (e.g. consts or the like) */
165 case dump_node_info_txt:
166 attr = get_ppc32_attr(n);
167 fprintf(F, "=== ppc attr begin ===\n");
169 /* dump IN requirements */
170 if (get_irn_arity(n) > 0) {
171 reqs = get_ppc32_in_req_all(n);
172 dump_reg_req(F, n, reqs, 0);
175 /* dump OUT requirements */
176 if (ARR_LEN(attr->slots) > 0) {
177 reqs = get_ppc32_out_req_all(n);
178 dump_reg_req(F, n, reqs, 1);
181 /* dump assigned registers */
182 slots = get_ppc32_slots(n);
183 if (slots && ARR_LEN(attr->slots) > 0) {
184 for (i = 0; i < ARR_LEN(attr->slots); i++) {
186 fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
189 fprintf(F, "reg #%d = n/a\n", i);
196 fprintf(F, "n_res = %d\n", get_ppc32_n_res(n));
199 fprintf(F, "flags =");
200 if (attr->flags == arch_irn_flags_none) {
204 if (attr->flags & arch_irn_flags_dont_spill) {
205 fprintf(F, " unspillable");
207 if (attr->flags & arch_irn_flags_rematerializable) {
208 fprintf(F, " remat");
210 if (attr->flags & arch_irn_flags_ignore) {
211 fprintf(F, " ignore");
214 fprintf(F, " (%d)\n", attr->flags);
216 /* TODO: dump all additional attributes */
218 fprintf(F, "=== ppc attr end ===\n");
219 /* end of: case dump_node_info_txt */
229 /***************************************************************************************************
231 * | | | | | | / / | | | | | | | |
232 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
233 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
234 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
235 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
238 ***************************************************************************************************/
240 ppc32_attr_t *get_ppc32_attr(ir_node *node) {
241 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
242 return (ppc32_attr_t *)get_irn_generic_attr(node);
245 const ppc32_attr_t *get_ppc32_attr_const(const ir_node *node) {
246 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
247 return (const ppc32_attr_t *)get_irn_generic_attr_const(node);
253 * Returns the argument register requirements of a ppc node.
255 const arch_register_req_t **get_ppc32_in_req_all(const ir_node *node) {
256 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
261 * Returns the result register requirements of an ppc node.
263 const arch_register_req_t **get_ppc32_out_req_all(const ir_node *node) {
264 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
265 return attr->out_req;
269 * Returns the argument register requirement at position pos of an ppc node.
271 const arch_register_req_t *get_ppc32_in_req(const ir_node *node, int pos) {
272 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
273 return attr->in_req[pos];
277 * Returns the result register requirement at position pos of an ppc node.
279 const arch_register_req_t *get_ppc32_out_req(const ir_node *node, int pos) {
280 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
281 return attr->out_req[pos];
285 * Sets the OUT register requirements at position pos.
287 void set_ppc32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
288 ppc32_attr_t *attr = get_ppc32_attr(node);
289 attr->out_req[pos] = req;
293 * Sets the IN register requirements at position pos.
295 void set_ppc32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
296 ppc32_attr_t *attr = get_ppc32_attr(node);
297 attr->in_req[pos] = req;
301 * Returns the register flag of an ppc node.
303 arch_irn_flags_t get_ppc32_flags(const ir_node *node) {
304 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
309 * Sets the register flag of an ppc node.
311 void set_ppc32_flags(ir_node *node, arch_irn_flags_t flags) {
312 ppc32_attr_t *attr = get_ppc32_attr(node);
317 * Returns the result register slots of an ppc node.
319 const arch_register_t **get_ppc32_slots(const ir_node *node) {
320 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
325 * Returns the name of the OUT register at position pos.
327 const char *get_ppc32_out_reg_name(const ir_node *node, int pos) {
328 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
330 assert(is_ppc32_irn(node) && "Not an ppc node.");
331 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
332 assert(attr->slots[pos] && "No register assigned");
334 return arch_register_get_name(attr->slots[pos]);
338 * Returns the index of the OUT register at position pos within its register class.
340 int get_ppc32_out_regnr(const ir_node *node, int pos) {
341 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
343 assert(is_ppc32_irn(node) && "Not an ppc node.");
344 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
345 assert(attr->slots[pos] && "No register assigned");
347 return arch_register_get_index(attr->slots[pos]);
351 * Returns the OUT register at position pos.
353 const arch_register_t *get_ppc32_out_reg(const ir_node *node, int pos) {
354 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
356 assert(is_ppc32_irn(node) && "Not an ppc node.");
357 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
358 assert(attr->slots[pos] && "No register assigned");
360 return attr->slots[pos];
364 * Returns the number of results.
366 int get_ppc32_n_res(const ir_node *node) {
367 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
368 return ARR_LEN(attr->slots);
372 * Sets the type of the constant (if any)
373 * May be either iro_Const or iro_SymConst
375 /* void set_ppc32_type(const ir_node *node, opcode type) {
376 ppc32_attr_t *attr = get_ppc32_attr(node);
381 * Returns the type of the content (if any)
383 ppc32_attr_content_type get_ppc32_type(const ir_node *node) {
384 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
385 return attr->content_type;
389 * Sets a tarval type content (also updating the content_type)
391 void set_ppc32_constant_tarval(ir_node *node, tarval *const_tarval) {
392 ppc32_attr_t *attr = get_ppc32_attr(node);
393 attr->content_type = ppc32_ac_Const;
394 attr->data.constant_tarval = const_tarval;
398 * Returns a tarval type constant
400 tarval *get_ppc32_constant_tarval(const ir_node *node) {
401 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
402 return attr->data.constant_tarval;
406 * Sets an ident type constant (also updating the content_type)
408 void set_ppc32_symconst_ident(ir_node *node, ident *symconst_ident) {
409 ppc32_attr_t *attr = get_ppc32_attr(node);
410 attr->content_type = ppc32_ac_SymConst;
411 attr->data.symconst_ident = symconst_ident;
415 * Returns an ident type constant
417 ident *get_ppc32_symconst_ident(const ir_node *node) {
418 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
419 return attr->data.symconst_ident;
424 * Sets an entity (also updating the content_type)
426 void set_ppc32_frame_entity(ir_node *node, ir_entity *ent) {
427 ppc32_attr_t *attr = get_ppc32_attr(node);
428 attr->content_type = ppc32_ac_FrameEntity;
429 attr->data.frame_entity = ent;
435 ir_entity *get_ppc32_frame_entity(const ir_node *node) {
436 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
437 return attr->data.frame_entity;
441 * Sets a Rlwimi const (also updating the content_type)
443 void set_ppc32_rlwimi_const(ir_node *node, unsigned shift, unsigned maskA, unsigned maskB) {
444 ppc32_attr_t *attr = get_ppc32_attr(node);
445 attr->content_type = ppc32_ac_RlwimiConst;
446 attr->data.rlwimi_const.shift = shift;
447 attr->data.rlwimi_const.maskA = maskA;
448 attr->data.rlwimi_const.maskB = maskB;
452 * Returns the rlwimi const structure
454 const rlwimi_const_t *get_ppc32_rlwimi_const(const ir_node *node) {
455 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
456 return &attr->data.rlwimi_const;
460 * Sets a Proj number (also updating the content_type)
462 void set_ppc32_proj_nr(ir_node *node, int proj_nr) {
463 ppc32_attr_t *attr = get_ppc32_attr(node);
464 attr->content_type = ppc32_ac_BranchProj;
465 attr->data.proj_nr = proj_nr;
469 * Returns the proj number
471 int get_ppc32_proj_nr(const ir_node *node) {
472 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
473 return attr->data.proj_nr;
477 * Sets an offset for a memory access (also updating the content_type)
479 void set_ppc32_offset(ir_node *node, int offset) {
480 ppc32_attr_t *attr = get_ppc32_attr(node);
481 attr->content_type = ppc32_ac_Offset;
482 attr->data.offset = offset;
488 int get_ppc32_offset(const ir_node *node) {
489 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
490 return attr->data.offset;
494 * Sets the offset mode (ppc32_ao_None, ppc32_ao_Lo16, ppc32_ao_Hi16 or ppc32_ao_Ha16)
496 void set_ppc32_offset_mode(ir_node *node, ppc32_attr_offset_mode mode) {
497 ppc32_attr_t *attr = get_ppc32_attr(node);
498 attr->offset_mode = mode;
502 * Returns the offset mode
504 ppc32_attr_offset_mode get_ppc32_offset_mode(const ir_node *node) {
505 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
506 return attr->offset_mode;
511 * Initializes ppc specific node attributes
513 void init_ppc32_attributes(ir_node *node, int flags,
514 const arch_register_req_t **in_reqs, const arch_register_req_t **out_reqs,
515 const be_execution_unit_t ***execution_units,
517 ir_graph *irg = get_irn_irg(node);
518 struct obstack *obst = get_irg_obstack(irg);
519 ppc32_attr_t *attr = get_ppc32_attr(node);
520 (void) execution_units;
523 attr->in_req = in_reqs;
524 attr->out_req = out_reqs;
526 attr->content_type = ppc32_ac_None;
527 attr->offset_mode = ppc32_ao_Illegal;
528 attr->data.empty = NULL;
530 attr->slots = NEW_ARR_D(const arch_register_t*, obst, n_res);
531 memset(attr->slots, 0, n_res * sizeof(attr->slots[0]));
535 /***************************************************************************************
538 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
539 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
540 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
541 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
543 ***************************************************************************************/
545 /* Include the generated constructor functions */
546 #include "gen_ppc32_new_nodes.c.inl"