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"
57 struct obstack opcodes_obst;
60 * Dumper interface for dumping ia32 nodes in vcg.
61 * @param n the node to dump
62 * @param F the output file
63 * @param reason indicates which kind of information should be dumped
64 * @return 0 on success or != 0 on failure
66 static void ia32_dump_node(FILE *F, const ir_node *n, dump_reason_t reason)
71 case dump_node_opcode_txt:
72 fprintf(F, "%s", get_irn_opname(n));
74 if (is_ia32_Immediate(n) || is_ia32_Const(n)) {
75 const ia32_immediate_attr_t *attr
76 = get_ia32_immediate_attr_const(n);
83 fputs(get_entity_name(attr->symconst), F);
85 if (attr->offset != 0 || attr->symconst == NULL) {
86 if (attr->offset > 0 && attr->symconst != NULL) {
89 fprintf(F, "%ld", attr->offset);
90 if (attr->no_pic_adjust) {
91 fputs("(no_pic_adjust)", F);
96 const ia32_attr_t *attr = get_ia32_attr_const(n);
98 if (attr->am_sc != NULL || attr->am_offs != 0)
101 if (attr->am_sc != NULL) {
102 if (attr->data.am_sc_sign) {
105 fputs(get_entity_name(attr->am_sc), F);
106 if (attr->data.am_sc_no_pic_adjust) {
107 fputs("(no_pic_adjust)", F);
110 if (attr->am_offs != 0) {
111 if (attr->am_offs > 0 && attr->am_sc != NULL) {
114 fprintf(F, "%d", attr->am_offs);
117 if (attr->am_sc != NULL || attr->am_offs != 0)
122 case dump_node_mode_txt:
123 mode = get_ia32_ls_mode(n);
125 fprintf(F, "[%s]", get_mode_name(mode));
128 case dump_node_nodeattr_txt:
129 if (! is_ia32_Lea(n)) {
130 switch (get_ia32_op_type(n)) {
131 case ia32_Normal: break;
132 case ia32_AddrModeS: fprintf(F, "[AM S] "); break;
133 case ia32_AddrModeD: fprintf(F, "[AM D] "); break;
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 const ia32_attr_t *attr = get_ia32_attr_const(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 exception label attribute.
706 unsigned get_ia32_exc_label(const ir_node *node)
708 const ia32_attr_t *attr = get_ia32_attr_const(node);
709 return attr->data.has_except_label;
713 * Set the exception label attribute.
715 void set_ia32_exc_label(ir_node *node, unsigned flag)
717 ia32_attr_t *attr = get_ia32_attr(node);
718 attr->data.has_except_label = flag;
722 * Return the exception label id.
724 ir_label_t get_ia32_exc_label_id(const ir_node *node)
726 const ia32_attr_t *attr = get_ia32_attr_const(node);
728 assert(attr->data.has_except_label);
729 return attr->exc_label;
733 * Assign the exception label id.
735 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
737 ia32_attr_t *attr = get_ia32_attr(node);
739 assert(attr->data.has_except_label);
740 attr->exc_label = id;
746 * Returns the name of the original ir node.
748 const char *get_ia32_orig_node(const ir_node *node)
750 const ia32_attr_t *attr = get_ia32_attr_const(node);
751 return attr->orig_node;
754 static const char *ia32_get_old_node_name(const ir_node *irn)
756 ir_graph *irg = get_irn_irg(irn);
757 struct obstack *obst = be_get_be_obst(irg);
759 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
760 obstack_1grow(obst, 0);
761 return (const char*)obstack_finish(obst);
765 * Sets the name of the original ir node.
767 void set_ia32_orig_node(ir_node *node, const ir_node *old)
769 const char *name = ia32_get_old_node_name(old);
770 ia32_attr_t *attr = get_ia32_attr(node);
771 attr->orig_node = name;
776 void ia32_swap_left_right(ir_node *node)
778 ia32_attr_t *attr = get_ia32_attr(node);
779 ir_node *left = get_irn_n(node, n_ia32_binary_left);
780 ir_node *right = get_irn_n(node, n_ia32_binary_right);
782 assert(is_ia32_commutative(node));
783 attr->data.ins_permuted = !attr->data.ins_permuted;
784 set_irn_n(node, n_ia32_binary_left, right);
785 set_irn_n(node, n_ia32_binary_right, left);
789 * Initializes the nodes attributes.
791 static void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
792 const arch_register_req_t **in_reqs,
795 ir_graph *irg = get_irn_irg(node);
796 struct obstack *obst = get_irg_obstack(irg);
797 ia32_attr_t *attr = get_ia32_attr(node);
798 backend_info_t *info;
800 arch_set_irn_flags(node, flags);
801 arch_set_irn_register_reqs_in(node, in_reqs);
804 attr->attr_type |= IA32_ATTR_ia32_attr_t;
807 info = be_get_info(node);
808 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
809 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
812 static void init_ia32_x87_attributes(ir_node *res)
814 ir_graph *irg = get_irn_irg(res);
815 ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
817 ia32_attr_t *attr = get_ia32_attr(res);
818 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
822 irg_data->do_x87_sim = 1;
825 static void init_ia32_asm_attributes(ir_node *res)
828 ia32_attr_t *attr = get_ia32_attr(res);
829 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
835 static void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
836 int symconst_sign, int no_pic_adjust,
839 ia32_immediate_attr_t *attr = (ia32_immediate_attr_t*)get_irn_generic_attr(res);
842 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
844 attr->symconst = symconst;
845 attr->sc_sign = symconst_sign;
846 attr->no_pic_adjust = no_pic_adjust;
847 attr->offset = offset;
850 static void init_ia32_call_attributes(ir_node* res, unsigned pop,
853 ia32_call_attr_t *attr = (ia32_call_attr_t*)get_irn_generic_attr(res);
856 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
859 attr->call_tp = call_tp;
862 static void init_ia32_copyb_attributes(ir_node *res, unsigned size)
864 ia32_copyb_attr_t *attr = (ia32_copyb_attr_t*)get_irn_generic_attr(res);
867 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
872 static void init_ia32_condcode_attributes(ir_node *res,
873 ia32_condition_code_t cc)
875 ia32_condcode_attr_t *attr = (ia32_condcode_attr_t*)get_irn_generic_attr(res);
878 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
880 attr->condition_code = cc;
883 static void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
885 ia32_climbframe_attr_t *attr = (ia32_climbframe_attr_t*)get_irn_generic_attr(res);
888 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
893 static void init_ia32_switch_attributes(ir_node *node,
894 const ir_switch_table *table)
896 unsigned n_outs = arch_get_irn_n_outs(node);
899 ia32_switch_attr_t *attr = (ia32_switch_attr_t*) get_irn_generic_attr(node);
901 attr->attr.attr_type |= IA32_ATTR_ia32_switch_attr_t;
905 for (o = 0; o < n_outs; ++o) {
906 arch_set_irn_register_req_out(node, o, arch_no_register_req);
910 /* default compare operation to compare attributes */
911 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
913 if (a->data.tp != b->data.tp)
916 if (a->data.am_scale != b->data.am_scale
917 || a->data.am_sc_sign != b->data.am_sc_sign
918 || a->am_offs != b->am_offs
919 || a->am_sc != b->am_sc
920 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
921 || a->ls_mode != b->ls_mode)
924 /* nodes with not yet assigned entities shouldn't be CSEd (important for
925 * unsigned int -> double conversions */
926 if (a->data.use_frame && a->frame_ent == NULL)
928 if (b->data.use_frame && b->frame_ent == NULL)
931 if (a->data.use_frame != b->data.use_frame
932 || a->frame_ent != b->frame_ent)
935 if (a->data.has_except_label != b->data.has_except_label)
938 if (a->data.ins_permuted != b->data.ins_permuted)
944 /** Compare nodes attributes for all "normal" nodes. */
945 static int ia32_compare_nodes_attr(const ir_node *a, const ir_node *b)
947 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
948 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
950 return ia32_compare_attr(attr_a, attr_b);
953 /** Compare node attributes for nodes with condition code. */
954 static int ia32_compare_condcode_attr(const ir_node *a, const ir_node *b)
956 const ia32_condcode_attr_t *attr_a;
957 const ia32_condcode_attr_t *attr_b;
959 if (ia32_compare_nodes_attr(a, b))
962 attr_a = get_ia32_condcode_attr_const(a);
963 attr_b = get_ia32_condcode_attr_const(b);
965 if (attr_a->condition_code != attr_b->condition_code)
971 /** Compare node attributes for call nodes. */
972 static int ia32_compare_call_attr(const ir_node *a, const ir_node *b)
974 const ia32_call_attr_t *attr_a;
975 const ia32_call_attr_t *attr_b;
977 if (ia32_compare_nodes_attr(a, b))
980 attr_a = get_ia32_call_attr_const(a);
981 attr_b = get_ia32_call_attr_const(b);
983 if (attr_a->pop != attr_b->pop)
986 if (attr_a->call_tp != attr_b->call_tp)
992 /** Compare node attributes for CopyB nodes. */
993 static int ia32_compare_copyb_attr(const ir_node *a, const ir_node *b)
995 const ia32_copyb_attr_t *attr_a;
996 const ia32_copyb_attr_t *attr_b;
998 if (ia32_compare_nodes_attr(a, b))
1001 attr_a = get_ia32_copyb_attr_const(a);
1002 attr_b = get_ia32_copyb_attr_const(b);
1004 if (attr_a->size != attr_b->size)
1011 /** Compare ASM node attributes. */
1012 static int ia32_compare_asm_attr(const ir_node *a, const ir_node *b)
1014 const ia32_asm_attr_t *attr_a;
1015 const ia32_asm_attr_t *attr_b;
1017 if (ia32_compare_nodes_attr(a, b))
1020 attr_a = get_ia32_asm_attr_const(a);
1021 attr_b = get_ia32_asm_attr_const(b);
1023 if (attr_a->asm_text != attr_b->asm_text)
1030 * Hash function for Immediates
1032 static unsigned ia32_hash_Immediate(const ir_node *irn)
1034 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1036 return hash_ptr(a->symconst) + (a->sc_sign << 16) + a->offset;
1039 /** Compare node attributes for Immediates. */
1040 static int ia32_compare_immediate_attr(const ir_node *a, const ir_node *b)
1042 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1043 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1045 if (attr_a->symconst != attr_b->symconst
1046 || attr_a->sc_sign != attr_b->sc_sign
1047 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1048 || attr_a->offset != attr_b->offset) {
1055 /** Compare node attributes for x87 nodes. */
1056 static int ia32_compare_x87_attr(const ir_node *a, const ir_node *b)
1058 return ia32_compare_nodes_attr(a, b);
1061 /** Compare node attributes for ClimbFrame nodes. */
1062 static int ia32_compare_climbframe_attr(const ir_node *a, const ir_node *b)
1064 const ia32_climbframe_attr_t *attr_a;
1065 const ia32_climbframe_attr_t *attr_b;
1067 if (ia32_compare_nodes_attr(a, b))
1070 attr_a = get_ia32_climbframe_attr_const(a);
1071 attr_b = get_ia32_climbframe_attr_const(b);
1073 if (attr_a->count != attr_b->count)
1079 /* copies the ia32 attributes */
1080 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1083 struct obstack *obst = get_irg_obstack(irg);
1084 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1085 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1086 backend_info_t *old_info = be_get_info(old_node);
1087 backend_info_t *new_info = be_get_info(new_node);
1089 /* copy the attributes */
1090 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1092 /* copy out flags */
1093 new_info->out_infos =
1094 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1095 new_info->in_reqs = old_info->in_reqs;
1096 new_info->flags = old_info->flags;
1099 static void ia32_init_op(ir_op *op, unsigned latency)
1101 ia32_op_attr_t *attr = OALLOCZ(&opcodes_obst, ia32_op_attr_t);
1102 attr->latency = latency;
1103 set_op_attr(op, attr);
1106 /* Include the generated constructor functions */
1107 #include "gen_ia32_new_nodes.c.inl"