2 * Copyright (C) 1995-2011 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
25 * This file implements the creation of the architecture specific firm opcodes
26 * and the corresponding node constructors for the ia32 assembler irg.
35 #include "irgraph_t.h"
41 #include "irverify_t.h"
45 #include "raw_bitset.h"
51 #include "bearch_ia32_t.h"
52 #include "ia32_common_transform.h"
53 #include "ia32_nodes_attr.h"
54 #include "ia32_new_nodes.h"
55 #include "gen_ia32_regalloc_if.h"
56 #include "gen_ia32_machine.h"
59 * Dumper interface for dumping ia32 nodes in vcg.
60 * @param n the node to dump
61 * @param F the output file
62 * @param reason indicates which kind of information should be dumped
63 * @return 0 on success or != 0 on failure
65 static void ia32_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
70 case dump_node_opcode_txt:
71 fprintf(F, "%s", get_irn_opname(n));
73 if (is_ia32_Immediate(n) || is_ia32_Const(n)) {
74 const ia32_immediate_attr_t *attr
75 = get_ia32_immediate_attr_const(n);
82 fputs(get_entity_name(attr->symconst), F);
84 if (attr->offset != 0 || attr->symconst == NULL) {
85 if (attr->offset > 0 && attr->symconst != NULL) {
88 fprintf(F, "%ld", attr->offset);
89 if (attr->no_pic_adjust) {
90 fputs("(no_pic_adjust)", F);
95 const ia32_attr_t *attr = get_ia32_attr_const(n);
97 if (attr->am_sc != NULL || attr->am_offs != 0)
100 if (attr->am_sc != NULL) {
101 if (attr->data.am_sc_sign) {
104 fputs(get_entity_name(attr->am_sc), F);
105 if (attr->data.am_sc_no_pic_adjust) {
106 fputs("(no_pic_adjust)", F);
109 if (attr->am_offs != 0) {
110 if (attr->am_offs > 0 && attr->am_sc != NULL) {
113 fprintf(F, "%d", attr->am_offs);
116 if (attr->am_sc != NULL || attr->am_offs != 0)
121 case dump_node_mode_txt:
122 mode = get_ia32_ls_mode(n);
124 fprintf(F, "[%s]", get_mode_name(mode));
127 case dump_node_nodeattr_txt:
128 if (! is_ia32_Lea(n)) {
129 if (is_ia32_AddrModeS(n)) {
130 fprintf(F, "[AM S] ");
131 } else if (is_ia32_AddrModeD(n)) {
132 fprintf(F, "[AM D] ");
138 case dump_node_info_txt:
139 arch_dump_reqs_and_registers(F, n);
143 switch (get_ia32_op_type(n)) {
145 fprintf(F, "Normal");
148 fprintf(F, "AM Dest (Load+Store)");
151 fprintf(F, "AM Source (Load)");
154 fprintf(F, "unknown (%d)", (int)get_ia32_op_type(n));
159 /* dump supported am */
160 fprintf(F, "AM support = ");
161 switch (get_ia32_am_support(n)) {
162 case ia32_am_none: fputs("none\n", F); break;
163 case ia32_am_unary: fputs("source (unary)\n", F); break;
164 case ia32_am_binary: fputs("source (binary)\n", F); break;
167 fprintf(F, "unknown (%d)\n", (int)get_ia32_am_support(n));
172 if (get_ia32_am_offs_int(n) != 0) {
173 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
176 /* dump AM symconst */
177 if (get_ia32_am_sc(n) != NULL) {
178 ir_entity *ent = get_ia32_am_sc(n);
179 ident *id = get_entity_ld_ident(ent);
180 fprintf(F, "AM symconst = %s\n", get_id_str(id));
184 fprintf(F, "AM scale = %u\n", get_ia32_am_scale(n));
187 if (is_ia32_CMovcc(n) || is_ia32_Setcc(n) || is_ia32_Jcc(n)) {
188 ia32_attr_t *attr = get_ia32_attr(n);
189 fprintf(F, "condition_code = 0x%X\n", (unsigned)get_ia32_condcode(n));
190 fprintf(F, "ins_permuted = %u\n", (unsigned)attr->data.ins_permuted);
192 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
193 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
196 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
197 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
198 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
199 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
200 fprintf(F, "latency = %u\n", get_ia32_latency(n));
202 /* dump frame entity */
203 fprintf(F, "frame entity = ");
204 if (get_ia32_frame_ent(n)) {
205 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
213 fprintf(F, "ls_mode = ");
214 if (get_ia32_ls_mode(n)) {
215 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
223 /* dump original ir node name */
224 fprintf(F, "orig node = ");
225 if (get_ia32_orig_node(n)) {
226 fprintf(F, "%s", get_ia32_orig_node(n));
240 ia32_attr_t *get_ia32_attr(ir_node *node)
242 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
243 return (ia32_attr_t *)get_irn_generic_attr(node);
246 const ia32_attr_t *get_ia32_attr_const(const ir_node *node)
248 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
249 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
252 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node)
254 ia32_attr_t *attr = get_ia32_attr(node);
255 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
259 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node)
261 const ia32_attr_t *attr = get_ia32_attr_const(node);
262 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
266 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node)
268 const ia32_attr_t *attr = get_ia32_attr_const(node);
269 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
274 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node)
276 ia32_attr_t *attr = get_ia32_attr(node);
277 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
282 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
284 const ia32_attr_t *attr = get_ia32_attr_const(node);
285 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
290 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node)
292 ia32_attr_t *attr = get_ia32_attr(node);
293 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
298 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node)
300 const ia32_attr_t *attr = get_ia32_attr_const(node);
301 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
306 ia32_switch_attr_t *get_ia32_switch_attr(ir_node *node)
308 ia32_attr_t *attr = get_ia32_attr(node);
309 ia32_switch_attr_t *switch_attr = CAST_IA32_ATTR(ia32_switch_attr_t, attr);
313 const ia32_switch_attr_t *get_ia32_switch_attr_const(const ir_node *node)
315 const ia32_attr_t *attr = get_ia32_attr_const(node);
316 const ia32_switch_attr_t *switch_attr = CONST_CAST_IA32_ATTR(ia32_switch_attr_t, attr);
320 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
322 ia32_attr_t *attr = get_ia32_attr(node);
323 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
328 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
330 const ia32_attr_t *attr = get_ia32_attr_const(node);
331 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
336 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node)
338 ia32_attr_t *attr = get_ia32_attr(node);
339 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
344 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node)
346 const ia32_attr_t *attr = get_ia32_attr_const(node);
347 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
352 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node)
354 ia32_attr_t *attr = get_ia32_attr(node);
355 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
357 return climbframe_attr;
360 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node)
362 const ia32_attr_t *attr = get_ia32_attr_const(node);
363 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
365 return climbframe_attr;
369 * Gets the type of an ia32 node.
371 ia32_op_type_t get_ia32_op_type(const ir_node *node)
373 const ia32_attr_t *attr = get_ia32_attr_const(node);
374 return (ia32_op_type_t)attr->data.tp;
378 * Sets the type of an ia32 node.
380 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp)
382 ia32_attr_t *attr = get_ia32_attr(node);
386 ia32_am_type_t get_ia32_am_support(const ir_node *node)
388 const ia32_attr_t *attr = get_ia32_attr_const(node);
389 return (ia32_am_type_t)attr->data.am_arity;
393 * Sets the supported address mode of an ia32 node
395 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
397 ia32_attr_t *attr = get_ia32_attr(node);
398 attr->data.am_arity = arity;
402 * Gets the address mode offset as int.
404 int get_ia32_am_offs_int(const ir_node *node)
406 const ia32_attr_t *attr = get_ia32_attr_const(node);
407 return attr->am_offs;
411 * Sets the address mode offset from an int.
413 void set_ia32_am_offs_int(ir_node *node, int offset)
415 ia32_attr_t *attr = get_ia32_attr(node);
416 attr->am_offs = offset;
419 void add_ia32_am_offs_int(ir_node *node, int offset)
421 ia32_attr_t *attr = get_ia32_attr(node);
422 attr->am_offs += offset;
426 * Returns the symconst entity associated to address mode.
428 ir_entity *get_ia32_am_sc(const ir_node *node)
430 const ia32_attr_t *attr = get_ia32_attr_const(node);
435 * Sets the symconst entity associated to address mode.
437 void set_ia32_am_sc(ir_node *node, ir_entity *entity)
439 ia32_attr_t *attr = get_ia32_attr(node);
440 attr->am_sc = entity;
444 * Sets the sign bit for address mode symconst.
446 void set_ia32_am_sc_sign(ir_node *node)
448 ia32_attr_t *attr = get_ia32_attr(node);
449 attr->data.am_sc_sign = 1;
453 * Clears the sign bit for address mode symconst.
455 void clear_ia32_am_sc_sign(ir_node *node)
457 ia32_attr_t *attr = get_ia32_attr(node);
458 attr->data.am_sc_sign = 0;
462 * Returns the sign bit for address mode symconst.
464 int is_ia32_am_sc_sign(const ir_node *node)
466 const ia32_attr_t *attr = get_ia32_attr_const(node);
467 return attr->data.am_sc_sign;
470 void set_ia32_am_tls_segment(ir_node *node, bool value)
472 ia32_attr_t *attr = get_ia32_attr(node);
473 attr->data.am_tls_segment = value;
476 bool get_ia32_am_tls_segment(const ir_node *node)
478 const ia32_attr_t *attr = get_ia32_attr_const(node);
479 return attr->data.am_tls_segment;
483 * Gets the addr mode const.
485 unsigned get_ia32_am_scale(const ir_node *node)
487 const ia32_attr_t *attr = get_ia32_attr_const(node);
488 return attr->data.am_scale;
492 * Sets the index register scale for address mode.
494 void set_ia32_am_scale(ir_node *node, unsigned scale)
496 ia32_attr_t *attr = get_ia32_attr(node);
497 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
498 attr->data.am_scale = scale;
501 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
503 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
504 set_ia32_am_scale(to, get_ia32_am_scale(from));
505 set_ia32_am_sc(to, get_ia32_am_sc(from));
506 if (is_ia32_am_sc_sign(from))
507 set_ia32_am_sc_sign(to);
508 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
509 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
510 if (is_ia32_use_frame(from))
511 set_ia32_use_frame(to);
515 * Sets the uses_frame flag.
517 void set_ia32_use_frame(ir_node *node)
519 ia32_attr_t *attr = get_ia32_attr(node);
520 attr->data.use_frame = 1;
524 * Clears the uses_frame flag.
526 void clear_ia32_use_frame(ir_node *node)
528 ia32_attr_t *attr = get_ia32_attr(node);
529 attr->data.use_frame = 0;
533 * Gets the uses_frame flag.
535 int is_ia32_use_frame(const ir_node *node)
537 const ia32_attr_t *attr = get_ia32_attr_const(node);
538 return attr->data.use_frame;
542 * Sets node to commutative.
544 void set_ia32_commutative(ir_node *node)
546 ia32_attr_t *attr = get_ia32_attr(node);
547 attr->data.is_commutative = 1;
551 * Sets node to non-commutative.
553 void clear_ia32_commutative(ir_node *node)
555 ia32_attr_t *attr = get_ia32_attr(node);
556 attr->data.is_commutative = 0;
560 * Checks if node is commutative.
562 int is_ia32_commutative(const ir_node *node)
564 const ia32_attr_t *attr = get_ia32_attr_const(node);
565 return attr->data.is_commutative;
568 void set_ia32_need_stackent(ir_node *node)
570 ia32_attr_t *attr = get_ia32_attr(node);
571 attr->data.need_stackent = 1;
574 void clear_ia32_need_stackent(ir_node *node)
576 ia32_attr_t *attr = get_ia32_attr(node);
577 attr->data.need_stackent = 0;
580 int is_ia32_need_stackent(const ir_node *node)
582 const ia32_attr_t *attr = get_ia32_attr_const(node);
583 return attr->data.need_stackent;
586 void set_ia32_is_reload(ir_node *node)
588 ia32_attr_t *attr = get_ia32_attr(node);
589 attr->data.is_reload = 1;
592 int is_ia32_is_reload(const ir_node *node)
594 const ia32_attr_t *attr = get_ia32_attr_const(node);
595 return attr->data.is_reload;
598 void set_ia32_is_spill(ir_node *node)
600 ia32_attr_t *attr = get_ia32_attr(node);
601 attr->data.is_spill = 1;
604 int is_ia32_is_spill(const ir_node *node)
606 const ia32_attr_t *attr = get_ia32_attr_const(node);
607 return attr->data.is_spill;
610 void set_ia32_is_remat(ir_node *node)
612 ia32_attr_t *attr = get_ia32_attr(node);
613 attr->data.is_remat = 1;
616 int is_ia32_is_remat(const ir_node *node)
618 const ia32_attr_t *attr = get_ia32_attr_const(node);
619 return attr->data.is_remat;
623 * Gets the mode of the stored/loaded value (only set for Store/Load)
625 ir_mode *get_ia32_ls_mode(const ir_node *node)
627 const ia32_attr_t *attr = get_ia32_attr_const(node);
628 return attr->ls_mode;
632 * Sets the mode of the stored/loaded value (only set for Store/Load)
634 void set_ia32_ls_mode(ir_node *node, ir_mode *mode)
636 ia32_attr_t *attr = get_ia32_attr(node);
637 attr->ls_mode = mode;
641 * Gets the frame entity assigned to this node.
643 ir_entity *get_ia32_frame_ent(const ir_node *node)
645 const ia32_attr_t *attr = get_ia32_attr_const(node);
646 return attr->frame_ent;
650 * Sets the frame entity for this node.
652 void set_ia32_frame_ent(ir_node *node, ir_entity *ent)
654 ia32_attr_t *attr = get_ia32_attr(node);
655 attr->frame_ent = ent;
657 set_ia32_use_frame(node);
659 clear_ia32_use_frame(node);
664 * Gets the instruction latency.
666 unsigned get_ia32_latency(const ir_node *node)
668 const ir_op *op = get_irn_op(node);
669 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
670 return op_attr->latency;
673 const ir_switch_table *get_ia32_switch_table(const ir_node *node)
675 const ia32_switch_attr_t *attr = get_ia32_switch_attr_const(node);
679 ia32_condition_code_t get_ia32_condcode(const ir_node *node)
681 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
682 return attr->condition_code;
686 * Sets the condition code of a node
688 void set_ia32_condcode(ir_node *node, ia32_condition_code_t code)
690 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
691 attr->condition_code = code;
695 * Returns the condition code of a node.
697 unsigned get_ia32_copyb_size(const ir_node *node)
699 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
704 * Get the list of available execution units.
706 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node)
708 const ia32_attr_t *attr = get_ia32_attr_const(node);
709 return attr->exec_units;
713 * Get the exception label attribute.
715 unsigned get_ia32_exc_label(const ir_node *node)
717 const ia32_attr_t *attr = get_ia32_attr_const(node);
718 return attr->data.has_except_label;
722 * Set the exception label attribute.
724 void set_ia32_exc_label(ir_node *node, unsigned flag)
726 ia32_attr_t *attr = get_ia32_attr(node);
727 attr->data.has_except_label = flag;
731 * Return the exception label id.
733 ir_label_t get_ia32_exc_label_id(const ir_node *node)
735 const ia32_attr_t *attr = get_ia32_attr_const(node);
737 assert(attr->data.has_except_label);
738 return attr->exc_label;
742 * Assign the exception label id.
744 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
746 ia32_attr_t *attr = get_ia32_attr(node);
748 assert(attr->data.has_except_label);
749 attr->exc_label = id;
755 * Returns the name of the original ir node.
757 const char *get_ia32_orig_node(const ir_node *node)
759 const ia32_attr_t *attr = get_ia32_attr_const(node);
760 return attr->orig_node;
763 static const char *ia32_get_old_node_name(const ir_node *irn)
765 ir_graph *irg = get_irn_irg(irn);
766 struct obstack *obst = be_get_be_obst(irg);
768 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
769 obstack_1grow(obst, 0);
770 return (const char*)obstack_finish(obst);
774 * Sets the name of the original ir node.
776 void set_ia32_orig_node(ir_node *node, const ir_node *old)
778 const char *name = ia32_get_old_node_name(old);
779 ia32_attr_t *attr = get_ia32_attr(node);
780 attr->orig_node = name;
787 * Returns whether or not the node is an AddrModeS node.
789 int is_ia32_AddrModeS(const ir_node *node)
791 const ia32_attr_t *attr = get_ia32_attr_const(node);
792 return (attr->data.tp == ia32_AddrModeS);
796 * Returns whether or not the node is an AddrModeD node.
798 int is_ia32_AddrModeD(const ir_node *node)
800 const ia32_attr_t *attr = get_ia32_attr_const(node);
801 return (attr->data.tp == ia32_AddrModeD);
804 void ia32_swap_left_right(ir_node *node)
806 ia32_attr_t *attr = get_ia32_attr(node);
807 ir_node *left = get_irn_n(node, n_ia32_binary_left);
808 ir_node *right = get_irn_n(node, n_ia32_binary_right);
810 assert(is_ia32_commutative(node));
811 attr->data.ins_permuted = !attr->data.ins_permuted;
812 set_irn_n(node, n_ia32_binary_left, right);
813 set_irn_n(node, n_ia32_binary_right, left);
817 * Initializes the nodes attributes.
819 static void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
820 const arch_register_req_t **in_reqs,
821 const be_execution_unit_t ***execution_units,
824 ir_graph *irg = get_irn_irg(node);
825 struct obstack *obst = get_irg_obstack(irg);
826 ia32_attr_t *attr = get_ia32_attr(node);
827 backend_info_t *info;
829 arch_set_irn_flags(node, flags);
830 arch_set_irn_register_reqs_in(node, in_reqs);
832 attr->exec_units = execution_units;
834 attr->attr_type |= IA32_ATTR_ia32_attr_t;
837 info = be_get_info(node);
838 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
839 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
842 static void init_ia32_x87_attributes(ir_node *res)
844 ir_graph *irg = get_irn_irg(res);
845 ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
847 ia32_attr_t *attr = get_ia32_attr(res);
848 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
852 irg_data->do_x87_sim = 1;
855 static void init_ia32_asm_attributes(ir_node *res)
858 ia32_attr_t *attr = get_ia32_attr(res);
859 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
865 static void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
866 int symconst_sign, int no_pic_adjust,
869 ia32_immediate_attr_t *attr = (ia32_immediate_attr_t*)get_irn_generic_attr(res);
872 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
874 attr->symconst = symconst;
875 attr->sc_sign = symconst_sign;
876 attr->no_pic_adjust = no_pic_adjust;
877 attr->offset = offset;
880 static void init_ia32_call_attributes(ir_node* res, unsigned pop,
883 ia32_call_attr_t *attr = (ia32_call_attr_t*)get_irn_generic_attr(res);
886 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
889 attr->call_tp = call_tp;
892 static void init_ia32_copyb_attributes(ir_node *res, unsigned size)
894 ia32_copyb_attr_t *attr = (ia32_copyb_attr_t*)get_irn_generic_attr(res);
897 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
902 static void init_ia32_condcode_attributes(ir_node *res,
903 ia32_condition_code_t cc)
905 ia32_condcode_attr_t *attr = (ia32_condcode_attr_t*)get_irn_generic_attr(res);
908 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
910 attr->condition_code = cc;
913 static void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
915 ia32_climbframe_attr_t *attr = (ia32_climbframe_attr_t*)get_irn_generic_attr(res);
918 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
923 static void init_ia32_switch_attributes(ir_node *node,
924 const ir_switch_table *table)
926 unsigned n_outs = arch_get_irn_n_outs(node);
929 ia32_switch_attr_t *attr = (ia32_switch_attr_t*) get_irn_generic_attr(node);
931 attr->attr.attr_type |= IA32_ATTR_ia32_switch_attr_t;
935 for (o = 0; o < n_outs; ++o) {
936 arch_set_irn_register_req_out(node, o, arch_no_register_req);
940 /* default compare operation to compare attributes */
941 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
943 if (a->data.tp != b->data.tp)
946 if (a->data.am_scale != b->data.am_scale
947 || a->data.am_sc_sign != b->data.am_sc_sign
948 || a->am_offs != b->am_offs
949 || a->am_sc != b->am_sc
950 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
951 || a->ls_mode != b->ls_mode)
954 /* nodes with not yet assigned entities shouldn't be CSEd (important for
955 * unsigned int -> double conversions */
956 if (a->data.use_frame && a->frame_ent == NULL)
958 if (b->data.use_frame && b->frame_ent == NULL)
961 if (a->data.use_frame != b->data.use_frame
962 || a->frame_ent != b->frame_ent)
965 if (a->data.has_except_label != b->data.has_except_label)
968 if (a->data.ins_permuted != b->data.ins_permuted)
974 /** Compare nodes attributes for all "normal" nodes. */
975 static int ia32_compare_nodes_attr(const ir_node *a, const ir_node *b)
977 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
978 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
980 return ia32_compare_attr(attr_a, attr_b);
983 /** Compare node attributes for nodes with condition code. */
984 static int ia32_compare_condcode_attr(const ir_node *a, const ir_node *b)
986 const ia32_condcode_attr_t *attr_a;
987 const ia32_condcode_attr_t *attr_b;
989 if (ia32_compare_nodes_attr(a, b))
992 attr_a = get_ia32_condcode_attr_const(a);
993 attr_b = get_ia32_condcode_attr_const(b);
995 if (attr_a->condition_code != attr_b->condition_code)
1001 /** Compare node attributes for call nodes. */
1002 static int ia32_compare_call_attr(const ir_node *a, const ir_node *b)
1004 const ia32_call_attr_t *attr_a;
1005 const ia32_call_attr_t *attr_b;
1007 if (ia32_compare_nodes_attr(a, b))
1010 attr_a = get_ia32_call_attr_const(a);
1011 attr_b = get_ia32_call_attr_const(b);
1013 if (attr_a->pop != attr_b->pop)
1016 if (attr_a->call_tp != attr_b->call_tp)
1022 /** Compare node attributes for CopyB nodes. */
1023 static int ia32_compare_copyb_attr(const ir_node *a, const ir_node *b)
1025 const ia32_copyb_attr_t *attr_a;
1026 const ia32_copyb_attr_t *attr_b;
1028 if (ia32_compare_nodes_attr(a, b))
1031 attr_a = get_ia32_copyb_attr_const(a);
1032 attr_b = get_ia32_copyb_attr_const(b);
1034 if (attr_a->size != attr_b->size)
1041 /** Compare ASM node attributes. */
1042 static int ia32_compare_asm_attr(const ir_node *a, const ir_node *b)
1044 const ia32_asm_attr_t *attr_a;
1045 const ia32_asm_attr_t *attr_b;
1047 if (ia32_compare_nodes_attr(a, b))
1050 attr_a = get_ia32_asm_attr_const(a);
1051 attr_b = get_ia32_asm_attr_const(b);
1053 if (attr_a->asm_text != attr_b->asm_text)
1060 * Hash function for Immediates
1062 static unsigned ia32_hash_Immediate(const ir_node *irn)
1064 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1066 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1069 /** Compare node attributes for Immediates. */
1070 static int ia32_compare_immediate_attr(const ir_node *a, const ir_node *b)
1072 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1073 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1075 if (attr_a->symconst != attr_b->symconst
1076 || attr_a->sc_sign != attr_b->sc_sign
1077 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1078 || attr_a->offset != attr_b->offset) {
1085 /** Compare node attributes for x87 nodes. */
1086 static int ia32_compare_x87_attr(const ir_node *a, const ir_node *b)
1088 return ia32_compare_nodes_attr(a, b);
1091 /** Compare node attributes for ClimbFrame nodes. */
1092 static int ia32_compare_climbframe_attr(const ir_node *a, const ir_node *b)
1094 const ia32_climbframe_attr_t *attr_a;
1095 const ia32_climbframe_attr_t *attr_b;
1097 if (ia32_compare_nodes_attr(a, b))
1100 attr_a = get_ia32_climbframe_attr_const(a);
1101 attr_b = get_ia32_climbframe_attr_const(b);
1103 if (attr_a->count != attr_b->count)
1109 /* copies the ia32 attributes */
1110 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1113 struct obstack *obst = get_irg_obstack(irg);
1114 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1115 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1116 backend_info_t *old_info = be_get_info(old_node);
1117 backend_info_t *new_info = be_get_info(new_node);
1119 /* copy the attributes */
1120 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1122 /* copy out flags */
1123 new_info->out_infos =
1124 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1125 new_info->in_reqs = old_info->in_reqs;
1126 new_info->flags = old_info->flags;
1129 /* Include the generated constructor functions */
1130 #include "gen_ia32_new_nodes.c.inl"