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 Handling of ia32 specific firm opcodes.
23 * @author Christian Wuerdig
26 * This file implements the creation of the achitecture specific firm opcodes
27 * and the corresponding node constructors for the ia32 assembler irg.
34 #include "irgraph_t.h"
40 #include "firm_common_t.h"
45 #include "raw_bitset.h"
48 #include "../bearch_t.h"
50 #include "bearch_ia32_t.h"
51 #include "ia32_nodes_attr.h"
52 #include "ia32_new_nodes.h"
53 #include "gen_ia32_regalloc_if.h"
54 #include "gen_ia32_machine.h"
56 /***********************************************************************************
59 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
60 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
61 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
62 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
65 ***********************************************************************************/
68 * Dumps the register requirements for either in or out.
70 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
72 char *dir = inout ? "out" : "in";
73 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
77 memset(buf, 0, sizeof(buf));
80 for (i = 0; i < max; i++) {
81 fprintf(F, "%sreq #%d =", dir, i);
83 if (reqs[i]->type == arch_register_req_type_none) {
87 if (reqs[i]->type & arch_register_req_type_normal) {
88 fprintf(F, " %s", reqs[i]->cls->name);
91 if (reqs[i]->type & arch_register_req_type_limited) {
93 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
96 if (reqs[i]->type & arch_register_req_type_should_be_same) {
97 unsigned other = reqs[i]->other_same;
100 ir_fprintf(F, " same as");
101 for (i = 0; 1U << i <= other; ++i) {
102 if (other & (1U << i)) {
103 ir_fprintf(F, " %+F", get_irn_n(n, i));
108 if (reqs[i]->type & arch_register_req_type_must_be_different) {
109 unsigned other = reqs[i]->other_different;
112 ir_fprintf(F, " different from");
113 for (i = 0; 1U << i <= other; ++i) {
114 if (other & (1U << i)) {
115 ir_fprintf(F, " %+F", get_irn_n(n, i));
126 fprintf(F, "%sreq = N/A\n", dir);
131 * Dumper interface for dumping ia32 nodes in vcg.
132 * @param n the node to dump
133 * @param F the output file
134 * @param reason indicates which kind of information should be dumped
135 * @return 0 on success or != 0 on failure
137 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
138 ir_mode *mode = NULL;
141 const arch_register_req_t **reqs;
142 const arch_register_t **slots;
145 case dump_node_opcode_txt:
146 fprintf(F, "%s", get_irn_opname(n));
148 if(is_ia32_Immediate(n) || is_ia32_Const(n)) {
149 const ia32_immediate_attr_t *attr
150 = get_ia32_immediate_attr_const(n);
157 fputs(get_entity_name(attr->symconst), F);
159 if(attr->offset != 0 || attr->symconst == NULL) {
160 if(attr->offset > 0 && attr->symconst != NULL) {
163 fprintf(F, "%ld", attr->offset);
167 const ia32_attr_t *attr = get_ia32_attr_const(n);
169 if(attr->am_sc != NULL || attr->am_offs != 0)
172 if(attr->am_sc != NULL) {
173 if(attr->data.am_sc_sign) {
176 fputs(get_entity_name(attr->am_sc), F);
178 if(attr->am_offs != 0) {
179 if(attr->am_offs > 0 && attr->am_sc != NULL) {
182 fprintf(F, "%d", attr->am_offs);
185 if(attr->am_sc != NULL || attr->am_offs != 0)
190 case dump_node_mode_txt:
191 mode = get_ia32_ls_mode(n);
193 fprintf(F, "[%s]", get_mode_name(mode));
196 case dump_node_nodeattr_txt:
197 if (! is_ia32_Lea(n)) {
198 if (is_ia32_AddrModeS(n)) {
199 fprintf(F, "[AM S] ");
200 } else if (is_ia32_AddrModeD(n)) {
201 fprintf(F, "[AM D] ");
207 case dump_node_info_txt:
208 n_res = get_ia32_n_res(n);
209 fprintf(F, "=== IA32 attr begin ===\n");
211 /* dump IN requirements */
212 if (get_irn_arity(n) > 0) {
213 reqs = get_ia32_in_req_all(n);
214 dump_reg_req(F, n, reqs, 0);
217 /* dump OUT requirements */
219 reqs = get_ia32_out_req_all(n);
220 dump_reg_req(F, n, reqs, 1);
223 /* dump assigned registers */
224 slots = get_ia32_slots(n);
225 if (slots && n_res > 0) {
226 for (i = 0; i < n_res; i++) {
227 const arch_register_t *reg;
231 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
238 switch (get_ia32_op_type(n)) {
240 fprintf(F, "Normal");
243 fprintf(F, "AM Dest (Load+Store)");
246 fprintf(F, "AM Source (Load)");
249 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
254 /* dump supported am */
255 fprintf(F, "AM support = ");
256 switch (get_ia32_am_support(n)) {
257 case ia32_am_none: fputs("none\n", F); break;
258 case ia32_am_unary: fputs("source (unary)\n", F); break;
259 case ia32_am_binary: fputs("source (binary)\n", F); break;
262 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
267 if(get_ia32_am_offs_int(n) != 0) {
268 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
271 /* dump AM symconst */
272 if(get_ia32_am_sc(n) != NULL) {
273 ir_entity *ent = get_ia32_am_sc(n);
274 ident *id = get_entity_ld_ident(ent);
275 fprintf(F, "AM symconst = %s\n", get_id_str(id));
279 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
282 if (is_ia32_SwitchJmp(n)) {
283 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
284 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
285 ia32_attr_t *attr = get_ia32_attr(n);
286 long pnc = get_ia32_condcode(n);
287 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
288 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
289 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
291 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
292 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
295 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
296 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
297 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
298 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
299 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
300 fprintf(F, "latency = %d\n", get_ia32_latency(n));
303 fprintf(F, "flags =");
304 flags = get_ia32_flags(n);
305 if (flags == arch_irn_flags_none) {
309 if (flags & arch_irn_flags_dont_spill) {
310 fprintf(F, " unspillable");
312 if (flags & arch_irn_flags_rematerializable) {
313 fprintf(F, " remat");
315 if (flags & arch_irn_flags_ignore) {
316 fprintf(F, " ignore");
318 if (flags & arch_irn_flags_modify_sp) {
319 fprintf(F, " modify_sp");
321 if (flags & arch_irn_flags_modify_flags) {
322 fprintf(F, " modify_flags");
325 fprintf(F, " (%d)\n", flags);
327 /* dump frame entity */
328 fprintf(F, "frame entity = ");
329 if (get_ia32_frame_ent(n)) {
330 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
338 fprintf(F, "ls_mode = ");
339 if (get_ia32_ls_mode(n)) {
340 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
348 /* dump original ir node name */
349 fprintf(F, "orig node = ");
350 if (get_ia32_orig_node(n)) {
351 fprintf(F, "%s", get_ia32_orig_node(n));
359 fprintf(F, "=== IA32 attr end ===\n");
360 /* end of: case dump_node_info_txt */
369 /***************************************************************************************************
371 * | | | | | | / / | | | | | | | |
372 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
373 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
374 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
375 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
378 ***************************************************************************************************/
380 ia32_attr_t *get_ia32_attr(ir_node *node) {
381 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
382 return (ia32_attr_t *)get_irn_generic_attr(node);
385 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
386 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
387 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
390 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
391 ia32_attr_t *attr = get_ia32_attr(node);
392 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
396 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
397 const ia32_attr_t *attr = get_ia32_attr_const(node);
398 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
402 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
403 const ia32_attr_t *attr = get_ia32_attr_const(node);
404 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
409 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
410 ia32_attr_t *attr = get_ia32_attr(node);
411 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
416 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
418 const ia32_attr_t *attr = get_ia32_attr_const(node);
419 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
424 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
425 ia32_attr_t *attr = get_ia32_attr(node);
426 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
431 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
432 const ia32_attr_t *attr = get_ia32_attr_const(node);
433 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
438 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
440 ia32_attr_t *attr = get_ia32_attr(node);
441 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
446 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
448 const ia32_attr_t *attr = get_ia32_attr_const(node);
449 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
454 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
455 ia32_attr_t *attr = get_ia32_attr(node);
456 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
461 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
462 const ia32_attr_t *attr = get_ia32_attr_const(node);
463 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
469 * Gets the type of an ia32 node.
471 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
472 const ia32_attr_t *attr = get_ia32_attr_const(node);
473 return attr->data.tp;
477 * Sets the type of an ia32 node.
479 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
480 ia32_attr_t *attr = get_ia32_attr(node);
484 ia32_am_type_t get_ia32_am_support(const ir_node *node)
486 const ia32_attr_t *attr = get_ia32_attr_const(node);
487 return attr->data.am_arity;
491 * Sets the supported address mode of an ia32 node
493 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
495 ia32_attr_t *attr = get_ia32_attr(node);
496 attr->data.am_arity = arity;
500 * Gets the address mode offset as int.
502 int get_ia32_am_offs_int(const ir_node *node) {
503 const ia32_attr_t *attr = get_ia32_attr_const(node);
504 return attr->am_offs;
508 * Sets the address mode offset from an int.
510 void set_ia32_am_offs_int(ir_node *node, int offset) {
511 ia32_attr_t *attr = get_ia32_attr(node);
512 attr->am_offs = offset;
515 void add_ia32_am_offs_int(ir_node *node, int offset) {
516 ia32_attr_t *attr = get_ia32_attr(node);
517 attr->am_offs += offset;
521 * Returns the symconst entity associated to address mode.
523 ir_entity *get_ia32_am_sc(const ir_node *node) {
524 const ia32_attr_t *attr = get_ia32_attr_const(node);
529 * Sets the symconst entity associated to address mode.
531 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
532 ia32_attr_t *attr = get_ia32_attr(node);
533 attr->am_sc = entity;
537 * Sets the sign bit for address mode symconst.
539 void set_ia32_am_sc_sign(ir_node *node) {
540 ia32_attr_t *attr = get_ia32_attr(node);
541 attr->data.am_sc_sign = 1;
545 * Clears the sign bit for address mode symconst.
547 void clear_ia32_am_sc_sign(ir_node *node) {
548 ia32_attr_t *attr = get_ia32_attr(node);
549 attr->data.am_sc_sign = 0;
553 * Returns the sign bit for address mode symconst.
555 int is_ia32_am_sc_sign(const ir_node *node) {
556 const ia32_attr_t *attr = get_ia32_attr_const(node);
557 return attr->data.am_sc_sign;
561 * Gets the addr mode const.
563 int get_ia32_am_scale(const ir_node *node) {
564 const ia32_attr_t *attr = get_ia32_attr_const(node);
565 return attr->data.am_scale;
569 * Sets the index register scale for address mode.
571 void set_ia32_am_scale(ir_node *node, int scale) {
572 ia32_attr_t *attr = get_ia32_attr(node);
573 assert(0 <= scale && scale < 4 && "AM scale out of range");
574 attr->data.am_scale = scale;
577 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
579 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
580 set_ia32_am_scale(to, get_ia32_am_scale(from));
581 set_ia32_am_sc(to, get_ia32_am_sc(from));
582 if(is_ia32_am_sc_sign(from))
583 set_ia32_am_sc_sign(to);
584 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
585 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
586 if (is_ia32_use_frame(from))
587 set_ia32_use_frame(to);
591 * Sets the uses_frame flag.
593 void set_ia32_use_frame(ir_node *node) {
594 ia32_attr_t *attr = get_ia32_attr(node);
595 attr->data.use_frame = 1;
599 * Clears the uses_frame flag.
601 void clear_ia32_use_frame(ir_node *node) {
602 ia32_attr_t *attr = get_ia32_attr(node);
603 attr->data.use_frame = 0;
607 * Gets the uses_frame flag.
609 int is_ia32_use_frame(const ir_node *node) {
610 const ia32_attr_t *attr = get_ia32_attr_const(node);
611 return attr->data.use_frame;
615 * Sets node to commutative.
617 void set_ia32_commutative(ir_node *node) {
618 ia32_attr_t *attr = get_ia32_attr(node);
619 attr->data.is_commutative = 1;
623 * Sets node to non-commutative.
625 void clear_ia32_commutative(ir_node *node) {
626 ia32_attr_t *attr = get_ia32_attr(node);
627 attr->data.is_commutative = 0;
631 * Checks if node is commutative.
633 int is_ia32_commutative(const ir_node *node) {
634 const ia32_attr_t *attr = get_ia32_attr_const(node);
635 return attr->data.is_commutative;
638 void set_ia32_need_stackent(ir_node *node) {
639 ia32_attr_t *attr = get_ia32_attr(node);
640 attr->data.need_stackent = 1;
643 void clear_ia32_need_stackent(ir_node *node) {
644 ia32_attr_t *attr = get_ia32_attr(node);
645 attr->data.need_stackent = 0;
648 int is_ia32_need_stackent(const ir_node *node) {
649 const ia32_attr_t *attr = get_ia32_attr_const(node);
650 return attr->data.need_stackent;
653 void set_ia32_is_reload(ir_node *node) {
654 ia32_attr_t *attr = get_ia32_attr(node);
655 attr->data.is_reload = 1;
658 int is_ia32_is_reload(const ir_node *node) {
659 const ia32_attr_t *attr = get_ia32_attr_const(node);
660 return attr->data.is_reload;
663 void set_ia32_is_spill(ir_node *node) {
664 ia32_attr_t *attr = get_ia32_attr(node);
665 attr->data.is_spill = 1;
668 int is_ia32_is_spill(const ir_node *node) {
669 const ia32_attr_t *attr = get_ia32_attr_const(node);
670 return attr->data.is_spill;
673 void set_ia32_is_remat(ir_node *node) {
674 ia32_attr_t *attr = get_ia32_attr(node);
675 attr->data.is_remat = 1;
678 int is_ia32_is_remat(const ir_node *node) {
679 const ia32_attr_t *attr = get_ia32_attr_const(node);
680 return attr->data.is_remat;
684 * Gets the mode of the stored/loaded value (only set for Store/Load)
686 ir_mode *get_ia32_ls_mode(const ir_node *node) {
687 const ia32_attr_t *attr = get_ia32_attr_const(node);
688 return attr->ls_mode;
692 * Sets the mode of the stored/loaded value (only set for Store/Load)
694 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
695 ia32_attr_t *attr = get_ia32_attr(node);
696 attr->ls_mode = mode;
700 * Gets the frame entity assigned to this node.
702 ir_entity *get_ia32_frame_ent(const ir_node *node) {
703 const ia32_attr_t *attr = get_ia32_attr_const(node);
704 return attr->frame_ent;
708 * Sets the frame entity for this node.
710 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
711 ia32_attr_t *attr = get_ia32_attr(node);
712 attr->frame_ent = ent;
714 set_ia32_use_frame(node);
716 clear_ia32_use_frame(node);
721 * Gets the instruction latency.
723 unsigned get_ia32_latency(const ir_node *node) {
724 const ir_op *op = get_irn_op(node);
725 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
726 return op_attr->latency;
730 * Returns the argument register requirements of an ia32 node.
732 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
733 const ia32_attr_t *attr = get_ia32_attr_const(node);
738 * Sets the argument register requirements of an ia32 node.
740 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
741 ia32_attr_t *attr = get_ia32_attr(node);
746 * Returns the result register requirements of an ia32 node.
748 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
749 const ia32_attr_t *attr = get_ia32_attr_const(node);
750 return attr->out_req;
754 * Sets the result register requirements of an ia32 node.
756 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
757 ia32_attr_t *attr = get_ia32_attr(node);
758 attr->out_req = reqs;
762 * Returns the argument register requirement at position pos of an ia32 node.
764 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
765 const ia32_attr_t *attr = get_ia32_attr_const(node);
766 if(attr->in_req == NULL)
767 return arch_no_register_req;
769 return attr->in_req[pos];
773 * Returns the result register requirement at position pos of an ia32 node.
775 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
776 const ia32_attr_t *attr = get_ia32_attr_const(node);
777 if(attr->out_req == NULL)
778 return arch_no_register_req;
780 return attr->out_req[pos];
784 * Sets the OUT register requirements at position pos.
786 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
787 ia32_attr_t *attr = get_ia32_attr(node);
788 attr->out_req[pos] = req;
792 * Sets the IN register requirements at position pos.
794 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
795 ia32_attr_t *attr = get_ia32_attr(node);
796 attr->in_req[pos] = req;
800 * Returns the register flag of an ia32 node.
802 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
803 const ia32_attr_t *attr = get_ia32_attr_const(node);
804 return attr->data.flags;
808 * Sets the register flag of an ia32 node.
810 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
811 ia32_attr_t *attr = get_ia32_attr(node);
812 attr->data.flags = flags;
815 void add_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
816 ia32_attr_t *attr = get_ia32_attr(node);
817 attr->data.flags |= flags;
821 * Returns the result register slots of an ia32 node.
823 const arch_register_t **get_ia32_slots(const ir_node *node) {
824 const ia32_attr_t *attr = get_ia32_attr_const(node);
829 * Returns the number of results.
831 int get_ia32_n_res(const ir_node *node) {
832 const ia32_attr_t *attr = get_ia32_attr_const(node);
833 return ARR_LEN(attr->slots);
837 * Returns the condition code of a node.
839 long get_ia32_condcode(const ir_node *node)
841 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
842 return attr->pn_code;
846 * Sets the condition code of a node
848 void set_ia32_condcode(ir_node *node, long code)
850 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
851 attr->pn_code = code;
855 * Returns the condition code of a node.
857 unsigned get_ia32_copyb_size(const ir_node *node)
859 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
864 * Sets the flags for the n'th out.
866 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
867 ia32_attr_t *attr = get_ia32_attr(node);
868 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
869 attr->out_flags[pos] = flags;
873 * Gets the flags for the n'th out.
875 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
876 const ia32_attr_t *attr = get_ia32_attr_const(node);
877 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
878 return attr->out_flags[pos];
882 * Get the list of available execution units.
884 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
885 const ia32_attr_t *attr = get_ia32_attr_const(node);
886 return attr->exec_units;
890 * Get the exception label attribute.
892 unsigned get_ia32_exc_label(const ir_node *node) {
893 const ia32_attr_t *attr = get_ia32_attr_const(node);
894 return attr->data.has_except_label;
898 * Set the exception label attribute.
900 void set_ia32_exc_label(ir_node *node, unsigned flag) {
901 ia32_attr_t *attr = get_ia32_attr(node);
902 attr->data.has_except_label = flag;
906 * Return the exception label id.
908 ir_label_t get_ia32_exc_label_id(const ir_node *node) {
909 const ia32_attr_t *attr = get_ia32_attr_const(node);
911 assert(attr->data.has_except_label);
912 return attr->exc_label;
916 * Assign the exception label id.
918 void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
919 ia32_attr_t *attr = get_ia32_attr(node);
921 assert(attr->data.has_except_label);
922 attr->exc_label = id;
928 * Returns the name of the original ir node.
930 const char *get_ia32_orig_node(const ir_node *node) {
931 const ia32_attr_t *attr = get_ia32_attr_const(node);
932 return attr->orig_node;
936 * Sets the name of the original ir node.
938 void set_ia32_orig_node(ir_node *node, const char *name) {
939 ia32_attr_t *attr = get_ia32_attr(node);
940 attr->orig_node = name;
945 /******************************************************************************************************
947 * (_) | | | | | | / _| | | (_)
948 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
949 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
950 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
951 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
954 ******************************************************************************************************/
957 * Returns whether or not the node is an AddrModeS node.
959 int is_ia32_AddrModeS(const ir_node *node) {
960 const ia32_attr_t *attr = get_ia32_attr_const(node);
961 return (attr->data.tp == ia32_AddrModeS);
965 * Returns whether or not the node is an AddrModeD node.
967 int is_ia32_AddrModeD(const ir_node *node) {
968 const ia32_attr_t *attr = get_ia32_attr_const(node);
969 return (attr->data.tp == ia32_AddrModeD);
972 void ia32_swap_left_right(ir_node *node)
974 ia32_attr_t *attr = get_ia32_attr(node);
975 ir_node *left = get_irn_n(node, n_ia32_binary_left);
976 ir_node *right = get_irn_n(node, n_ia32_binary_right);
978 assert(is_ia32_commutative(node));
979 attr->data.ins_permuted = !attr->data.ins_permuted;
980 set_irn_n(node, n_ia32_binary_left, right);
981 set_irn_n(node, n_ia32_binary_right, left);
985 * Returns the OUT register at position pos.
987 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
988 const ia32_attr_t *attr = get_ia32_attr_const(node);
990 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
991 assert(attr->slots[pos] && "No register assigned");
993 return attr->slots[pos];
997 * Initializes the nodes attributes.
999 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1000 const arch_register_req_t **in_reqs,
1001 const arch_register_req_t **out_reqs,
1002 const be_execution_unit_t ***execution_units,
1005 ir_graph *irg = get_irn_irg(node);
1006 struct obstack *obst = get_irg_obstack(irg);
1007 ia32_attr_t *attr = get_ia32_attr(node);
1009 set_ia32_flags(node, flags);
1010 set_ia32_in_req_all(node, in_reqs);
1011 set_ia32_out_req_all(node, out_reqs);
1013 attr->exec_units = execution_units;
1015 attr->attr_type |= IA32_ATTR_ia32_attr_t;
1018 attr->out_flags = NEW_ARR_D(int, obst, n_res);
1019 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1021 attr->slots = NEW_ARR_D(const arch_register_t*, obst, n_res);
1022 /* void* cast to suppress an incorrect warning on MSVC */
1023 memset((void*)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1027 init_ia32_x87_attributes(ir_node *res)
1030 ia32_attr_t *attr = get_ia32_attr(res);
1031 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
1035 ia32_current_cg->do_x87_sim = 1;
1039 init_ia32_asm_attributes(ir_node *res)
1042 ia32_attr_t *attr = get_ia32_attr(res);
1043 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
1050 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
1051 int symconst_sign, long offset)
1053 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
1056 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
1058 attr->symconst = symconst;
1059 attr->sc_sign = symconst_sign;
1060 attr->offset = offset;
1063 void init_ia32_call_attributes(ir_node *const res, unsigned const pop, ir_type *const call_tp)
1065 ia32_call_attr_t *attr = get_irn_generic_attr(res);
1068 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
1071 attr->call_tp = call_tp;
1075 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
1076 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
1079 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
1085 init_ia32_condcode_attributes(ir_node *res, long pnc) {
1086 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
1089 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
1091 attr->pn_code = pnc;
1094 /***************************************************************************************
1097 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1098 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1099 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1100 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1102 ***************************************************************************************/
1104 /* default compare operation to compare attributes */
1105 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
1106 if (a->data.tp != b->data.tp)
1109 if (a->data.am_scale != b->data.am_scale
1110 || a->data.am_sc_sign != b->data.am_sc_sign
1111 || a->am_offs != b->am_offs
1112 || a->am_sc != b->am_sc
1113 || a->ls_mode != b->ls_mode)
1116 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1117 * unsigned int -> double conversions */
1118 if(a->data.use_frame && a->frame_ent == NULL)
1120 if(b->data.use_frame && b->frame_ent == NULL)
1123 if (a->data.use_frame != b->data.use_frame
1124 || a->frame_ent != b->frame_ent)
1127 if (a->data.tp != b->data.tp)
1130 if (a->data.has_except_label != b->data.has_except_label)
1133 if (a->data.ins_permuted != b->data.ins_permuted
1134 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1140 /** Compare nodes attributes for all "normal" nodes. */
1142 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1144 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1145 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1147 return ia32_compare_attr(attr_a, attr_b);
1150 /** Compare node attributes for nodes with condition code. */
1152 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1154 const ia32_condcode_attr_t *attr_a;
1155 const ia32_condcode_attr_t *attr_b;
1157 if (ia32_compare_nodes_attr(a, b))
1160 attr_a = get_ia32_condcode_attr_const(a);
1161 attr_b = get_ia32_condcode_attr_const(b);
1163 if(attr_a->pn_code != attr_b->pn_code)
1169 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1171 const ia32_call_attr_t *attr_a;
1172 const ia32_call_attr_t *attr_b;
1174 if (ia32_compare_nodes_attr(a, b))
1177 attr_a = get_ia32_call_attr_const(a);
1178 attr_b = get_ia32_call_attr_const(b);
1180 if (attr_a->pop != attr_b->pop)
1183 if (attr_a->call_tp != attr_b->call_tp)
1189 /** Compare node attributes for CopyB nodes. */
1191 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1193 const ia32_copyb_attr_t *attr_a;
1194 const ia32_copyb_attr_t *attr_b;
1196 if (ia32_compare_nodes_attr(a, b))
1199 attr_a = get_ia32_copyb_attr_const(a);
1200 attr_b = get_ia32_copyb_attr_const(b);
1202 if(attr_a->size != attr_b->size)
1209 /** Compare ASM node attributes. */
1211 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1213 const ia32_asm_attr_t *attr_a;
1214 const ia32_asm_attr_t *attr_b;
1216 if(ia32_compare_nodes_attr(a, b))
1219 attr_a = get_ia32_asm_attr_const(a);
1220 attr_b = get_ia32_asm_attr_const(b);
1222 if(attr_a->asm_text != attr_b->asm_text)
1229 * Hash function for Immediates
1231 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1232 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1234 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1237 /** Compare node attributes for Immediates. */
1239 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1241 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1242 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1244 if(attr_a->symconst != attr_b->symconst ||
1245 attr_a->sc_sign != attr_b->sc_sign ||
1246 attr_a->offset != attr_b->offset)
1252 /** Compare node attributes for x87 nodes. */
1254 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1256 return ia32_compare_nodes_attr(a, b);
1260 /* copies the ia32 attributes */
1261 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1263 ir_graph *irg = get_irn_irg(new_node);
1264 struct obstack *obst = get_irg_obstack(irg);
1265 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1266 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1268 /* copy the attributes */
1269 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1271 /* copy out flags */
1272 attr_new->out_flags =
1273 DUP_ARR_D(int, obst, attr_old->out_flags);
1274 /* copy register assignments */
1276 DUP_ARR_D(arch_register_t*, obst, attr_old->slots);
1279 /* Include the generated constructor functions */
1280 #include "gen_ia32_new_nodes.c.inl"