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 char const *orig = get_ia32_attr_const(n)->orig_node;
225 fprintf(F, "orig node = %s\n", orig ? orig : "n/a");
234 ia32_attr_t *get_ia32_attr(ir_node *node)
236 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
237 return (ia32_attr_t *)get_irn_generic_attr(node);
240 const ia32_attr_t *get_ia32_attr_const(const ir_node *node)
242 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
243 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
246 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node)
248 ia32_attr_t *attr = get_ia32_attr(node);
249 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
253 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node)
255 const ia32_attr_t *attr = get_ia32_attr_const(node);
256 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
260 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node)
262 const ia32_attr_t *attr = get_ia32_attr_const(node);
263 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
268 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node)
270 ia32_attr_t *attr = get_ia32_attr(node);
271 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
276 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
278 const ia32_attr_t *attr = get_ia32_attr_const(node);
279 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
284 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node)
286 ia32_attr_t *attr = get_ia32_attr(node);
287 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
292 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node)
294 const ia32_attr_t *attr = get_ia32_attr_const(node);
295 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
300 ia32_switch_attr_t *get_ia32_switch_attr(ir_node *node)
302 ia32_attr_t *attr = get_ia32_attr(node);
303 ia32_switch_attr_t *switch_attr = CAST_IA32_ATTR(ia32_switch_attr_t, attr);
307 const ia32_switch_attr_t *get_ia32_switch_attr_const(const ir_node *node)
309 const ia32_attr_t *attr = get_ia32_attr_const(node);
310 const ia32_switch_attr_t *switch_attr = CONST_CAST_IA32_ATTR(ia32_switch_attr_t, attr);
314 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
316 ia32_attr_t *attr = get_ia32_attr(node);
317 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
322 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
324 const ia32_attr_t *attr = get_ia32_attr_const(node);
325 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
330 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node)
332 ia32_attr_t *attr = get_ia32_attr(node);
333 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
338 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node)
340 const ia32_attr_t *attr = get_ia32_attr_const(node);
341 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
346 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node)
348 ia32_attr_t *attr = get_ia32_attr(node);
349 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
351 return climbframe_attr;
354 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node)
356 const ia32_attr_t *attr = get_ia32_attr_const(node);
357 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
359 return climbframe_attr;
363 * Gets the type of an ia32 node.
365 ia32_op_type_t get_ia32_op_type(const ir_node *node)
367 const ia32_attr_t *attr = get_ia32_attr_const(node);
368 return (ia32_op_type_t)attr->data.tp;
372 * Sets the type of an ia32 node.
374 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp)
376 ia32_attr_t *attr = get_ia32_attr(node);
380 ia32_am_type_t get_ia32_am_support(const ir_node *node)
382 const ia32_attr_t *attr = get_ia32_attr_const(node);
383 return (ia32_am_type_t)attr->data.am_arity;
387 * Sets the supported address mode of an ia32 node
389 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
391 ia32_attr_t *attr = get_ia32_attr(node);
392 attr->data.am_arity = arity;
396 * Gets the address mode offset as int.
398 int get_ia32_am_offs_int(const ir_node *node)
400 const ia32_attr_t *attr = get_ia32_attr_const(node);
401 return attr->am_offs;
405 * Sets the address mode offset from an int.
407 void set_ia32_am_offs_int(ir_node *node, int offset)
409 ia32_attr_t *attr = get_ia32_attr(node);
410 attr->am_offs = offset;
413 void add_ia32_am_offs_int(ir_node *node, int offset)
415 ia32_attr_t *attr = get_ia32_attr(node);
416 attr->am_offs += offset;
420 * Returns the symconst entity associated to address mode.
422 ir_entity *get_ia32_am_sc(const ir_node *node)
424 const ia32_attr_t *attr = get_ia32_attr_const(node);
429 * Sets the symconst entity associated to address mode.
431 void set_ia32_am_sc(ir_node *node, ir_entity *entity)
433 ia32_attr_t *attr = get_ia32_attr(node);
434 attr->am_sc = entity;
438 * Sets the sign bit for address mode symconst.
440 void set_ia32_am_sc_sign(ir_node *node)
442 ia32_attr_t *attr = get_ia32_attr(node);
443 attr->data.am_sc_sign = 1;
447 * Clears the sign bit for address mode symconst.
449 void clear_ia32_am_sc_sign(ir_node *node)
451 ia32_attr_t *attr = get_ia32_attr(node);
452 attr->data.am_sc_sign = 0;
456 * Returns the sign bit for address mode symconst.
458 int is_ia32_am_sc_sign(const ir_node *node)
460 const ia32_attr_t *attr = get_ia32_attr_const(node);
461 return attr->data.am_sc_sign;
464 void set_ia32_am_tls_segment(ir_node *node, bool value)
466 ia32_attr_t *attr = get_ia32_attr(node);
467 attr->data.am_tls_segment = value;
470 bool get_ia32_am_tls_segment(const ir_node *node)
472 const ia32_attr_t *attr = get_ia32_attr_const(node);
473 return attr->data.am_tls_segment;
477 * Gets the addr mode const.
479 unsigned get_ia32_am_scale(const ir_node *node)
481 const ia32_attr_t *attr = get_ia32_attr_const(node);
482 return attr->data.am_scale;
486 * Sets the index register scale for address mode.
488 void set_ia32_am_scale(ir_node *node, unsigned scale)
490 ia32_attr_t *attr = get_ia32_attr(node);
491 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
492 attr->data.am_scale = scale;
495 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
497 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
498 set_ia32_am_scale(to, get_ia32_am_scale(from));
499 set_ia32_am_sc(to, get_ia32_am_sc(from));
500 if (is_ia32_am_sc_sign(from))
501 set_ia32_am_sc_sign(to);
502 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
503 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
504 if (is_ia32_use_frame(from))
505 set_ia32_use_frame(to);
509 * Sets the uses_frame flag.
511 void set_ia32_use_frame(ir_node *node)
513 ia32_attr_t *attr = get_ia32_attr(node);
514 attr->data.use_frame = 1;
518 * Clears the uses_frame flag.
520 void clear_ia32_use_frame(ir_node *node)
522 ia32_attr_t *attr = get_ia32_attr(node);
523 attr->data.use_frame = 0;
527 * Gets the uses_frame flag.
529 int is_ia32_use_frame(const ir_node *node)
531 const ia32_attr_t *attr = get_ia32_attr_const(node);
532 return attr->data.use_frame;
536 * Sets node to commutative.
538 void set_ia32_commutative(ir_node *node)
540 ia32_attr_t *attr = get_ia32_attr(node);
541 attr->data.is_commutative = 1;
545 * Sets node to non-commutative.
547 void clear_ia32_commutative(ir_node *node)
549 ia32_attr_t *attr = get_ia32_attr(node);
550 attr->data.is_commutative = 0;
554 * Checks if node is commutative.
556 int is_ia32_commutative(const ir_node *node)
558 const ia32_attr_t *attr = get_ia32_attr_const(node);
559 return attr->data.is_commutative;
562 void set_ia32_need_stackent(ir_node *node)
564 ia32_attr_t *attr = get_ia32_attr(node);
565 attr->data.need_stackent = 1;
568 void clear_ia32_need_stackent(ir_node *node)
570 ia32_attr_t *attr = get_ia32_attr(node);
571 attr->data.need_stackent = 0;
574 int is_ia32_need_stackent(const ir_node *node)
576 const ia32_attr_t *attr = get_ia32_attr_const(node);
577 return attr->data.need_stackent;
580 void set_ia32_is_reload(ir_node *node)
582 ia32_attr_t *attr = get_ia32_attr(node);
583 attr->data.is_reload = 1;
586 int is_ia32_is_reload(const ir_node *node)
588 const ia32_attr_t *attr = get_ia32_attr_const(node);
589 return attr->data.is_reload;
592 void set_ia32_is_spill(ir_node *node)
594 ia32_attr_t *attr = get_ia32_attr(node);
595 attr->data.is_spill = 1;
598 int is_ia32_is_spill(const ir_node *node)
600 const ia32_attr_t *attr = get_ia32_attr_const(node);
601 return attr->data.is_spill;
604 void set_ia32_is_remat(ir_node *node)
606 ia32_attr_t *attr = get_ia32_attr(node);
607 attr->data.is_remat = 1;
610 int is_ia32_is_remat(const ir_node *node)
612 const ia32_attr_t *attr = get_ia32_attr_const(node);
613 return attr->data.is_remat;
617 * Gets the mode of the stored/loaded value (only set for Store/Load)
619 ir_mode *get_ia32_ls_mode(const ir_node *node)
621 const ia32_attr_t *attr = get_ia32_attr_const(node);
622 return attr->ls_mode;
626 * Sets the mode of the stored/loaded value (only set for Store/Load)
628 void set_ia32_ls_mode(ir_node *node, ir_mode *mode)
630 ia32_attr_t *attr = get_ia32_attr(node);
631 attr->ls_mode = mode;
635 * Gets the frame entity assigned to this node.
637 ir_entity *get_ia32_frame_ent(const ir_node *node)
639 const ia32_attr_t *attr = get_ia32_attr_const(node);
640 return attr->frame_ent;
644 * Sets the frame entity for this node.
646 void set_ia32_frame_ent(ir_node *node, ir_entity *ent)
648 ia32_attr_t *attr = get_ia32_attr(node);
649 attr->frame_ent = ent;
651 set_ia32_use_frame(node);
653 clear_ia32_use_frame(node);
658 * Gets the instruction latency.
660 unsigned get_ia32_latency(const ir_node *node)
662 const ir_op *op = get_irn_op(node);
663 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
664 return op_attr->latency;
667 const ir_switch_table *get_ia32_switch_table(const ir_node *node)
669 const ia32_switch_attr_t *attr = get_ia32_switch_attr_const(node);
673 ia32_condition_code_t get_ia32_condcode(const ir_node *node)
675 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
676 return attr->condition_code;
680 * Sets the condition code of a node
682 void set_ia32_condcode(ir_node *node, ia32_condition_code_t code)
684 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
685 attr->condition_code = code;
689 * Returns the condition code of a node.
691 unsigned get_ia32_copyb_size(const ir_node *node)
693 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
698 * Get the exception label attribute.
700 unsigned get_ia32_exc_label(const ir_node *node)
702 const ia32_attr_t *attr = get_ia32_attr_const(node);
703 return attr->data.has_except_label;
707 * Set the exception label attribute.
709 void set_ia32_exc_label(ir_node *node, unsigned flag)
711 ia32_attr_t *attr = get_ia32_attr(node);
712 attr->data.has_except_label = flag;
716 * Return the exception label id.
718 ir_label_t get_ia32_exc_label_id(const ir_node *node)
720 const ia32_attr_t *attr = get_ia32_attr_const(node);
722 assert(attr->data.has_except_label);
723 return attr->exc_label;
727 * Assign the exception label id.
729 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
731 ia32_attr_t *attr = get_ia32_attr(node);
733 assert(attr->data.has_except_label);
734 attr->exc_label = id;
739 static const char *ia32_get_old_node_name(const ir_node *irn)
741 ir_graph *irg = get_irn_irg(irn);
742 struct obstack *obst = be_get_be_obst(irg);
744 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
745 obstack_1grow(obst, 0);
746 return (const char*)obstack_finish(obst);
750 * Sets the name of the original ir node.
752 void set_ia32_orig_node(ir_node *node, const ir_node *old)
754 const char *name = ia32_get_old_node_name(old);
755 ia32_attr_t *attr = get_ia32_attr(node);
756 attr->orig_node = name;
761 void ia32_swap_left_right(ir_node *node)
763 ia32_attr_t *attr = get_ia32_attr(node);
764 ir_node *left = get_irn_n(node, n_ia32_binary_left);
765 ir_node *right = get_irn_n(node, n_ia32_binary_right);
767 assert(is_ia32_commutative(node));
768 attr->data.ins_permuted = !attr->data.ins_permuted;
769 set_irn_n(node, n_ia32_binary_left, right);
770 set_irn_n(node, n_ia32_binary_right, left);
774 * Initializes the nodes attributes.
776 static void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
777 const arch_register_req_t **in_reqs,
780 ir_graph *irg = get_irn_irg(node);
781 struct obstack *obst = get_irg_obstack(irg);
782 ia32_attr_t *attr = get_ia32_attr(node);
783 backend_info_t *info;
785 arch_set_irn_flags(node, flags);
786 arch_set_irn_register_reqs_in(node, in_reqs);
789 attr->attr_type |= IA32_ATTR_ia32_attr_t;
792 info = be_get_info(node);
793 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
794 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
797 static void init_ia32_x87_attributes(ir_node *res)
800 ia32_attr_t *attr = get_ia32_attr(res);
801 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
803 ir_graph *const irg = get_irn_irg(res);
804 ia32_request_x87_sim(irg);
807 static void init_ia32_asm_attributes(ir_node *res)
810 ia32_attr_t *attr = get_ia32_attr(res);
811 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
814 ir_graph *const irg = get_irn_irg(res);
815 ia32_request_x87_sim(irg); /* asm might have fp operands. */
818 static void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
819 int symconst_sign, int no_pic_adjust,
822 ia32_immediate_attr_t *attr = (ia32_immediate_attr_t*)get_irn_generic_attr(res);
825 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
827 attr->symconst = symconst;
828 attr->sc_sign = symconst_sign;
829 attr->no_pic_adjust = no_pic_adjust;
830 attr->offset = offset;
833 static void init_ia32_call_attributes(ir_node* res, unsigned pop,
836 ia32_call_attr_t *attr = (ia32_call_attr_t*)get_irn_generic_attr(res);
839 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
842 attr->call_tp = call_tp;
845 static void init_ia32_copyb_attributes(ir_node *res, unsigned size)
847 ia32_copyb_attr_t *attr = (ia32_copyb_attr_t*)get_irn_generic_attr(res);
850 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
855 static void init_ia32_condcode_attributes(ir_node *res,
856 ia32_condition_code_t cc)
858 ia32_condcode_attr_t *attr = (ia32_condcode_attr_t*)get_irn_generic_attr(res);
861 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
863 attr->condition_code = cc;
866 static void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
868 ia32_climbframe_attr_t *attr = (ia32_climbframe_attr_t*)get_irn_generic_attr(res);
871 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
876 static void init_ia32_switch_attributes(ir_node *node,
877 const ir_switch_table *table)
879 ia32_switch_attr_t *attr = (ia32_switch_attr_t*) get_irn_generic_attr(node);
881 attr->attr.attr_type |= IA32_ATTR_ia32_switch_attr_t;
885 be_foreach_out(node, o) {
886 arch_set_irn_register_req_out(node, o, arch_no_register_req);
890 /* default compare operation to compare attributes */
891 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
893 if (a->data.tp != b->data.tp)
896 if (a->data.am_scale != b->data.am_scale
897 || a->data.am_sc_sign != b->data.am_sc_sign
898 || a->am_offs != b->am_offs
899 || a->am_sc != b->am_sc
900 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
901 || a->ls_mode != b->ls_mode)
904 /* nodes with not yet assigned entities shouldn't be CSEd (important for
905 * unsigned int -> double conversions */
906 if (a->data.use_frame && a->frame_ent == NULL)
908 if (b->data.use_frame && b->frame_ent == NULL)
911 if (a->data.use_frame != b->data.use_frame
912 || a->frame_ent != b->frame_ent)
915 if (a->data.has_except_label != b->data.has_except_label)
918 if (a->data.ins_permuted != b->data.ins_permuted)
924 /** Compare nodes attributes for all "normal" nodes. */
925 static int ia32_compare_nodes_attr(const ir_node *a, const ir_node *b)
927 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
928 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
930 return ia32_compare_attr(attr_a, attr_b);
933 /** Compare node attributes for nodes with condition code. */
934 static int ia32_compare_condcode_attr(const ir_node *a, const ir_node *b)
936 const ia32_condcode_attr_t *attr_a;
937 const ia32_condcode_attr_t *attr_b;
939 if (ia32_compare_nodes_attr(a, b))
942 attr_a = get_ia32_condcode_attr_const(a);
943 attr_b = get_ia32_condcode_attr_const(b);
945 if (attr_a->condition_code != attr_b->condition_code)
951 /** Compare node attributes for call nodes. */
952 static int ia32_compare_call_attr(const ir_node *a, const ir_node *b)
954 const ia32_call_attr_t *attr_a;
955 const ia32_call_attr_t *attr_b;
957 if (ia32_compare_nodes_attr(a, b))
960 attr_a = get_ia32_call_attr_const(a);
961 attr_b = get_ia32_call_attr_const(b);
963 if (attr_a->pop != attr_b->pop)
966 if (attr_a->call_tp != attr_b->call_tp)
972 /** Compare node attributes for CopyB nodes. */
973 static int ia32_compare_copyb_attr(const ir_node *a, const ir_node *b)
975 const ia32_copyb_attr_t *attr_a;
976 const ia32_copyb_attr_t *attr_b;
978 if (ia32_compare_nodes_attr(a, b))
981 attr_a = get_ia32_copyb_attr_const(a);
982 attr_b = get_ia32_copyb_attr_const(b);
984 if (attr_a->size != attr_b->size)
991 /** Compare ASM node attributes. */
992 static int ia32_compare_asm_attr(const ir_node *a, const ir_node *b)
994 const ia32_asm_attr_t *attr_a;
995 const ia32_asm_attr_t *attr_b;
997 if (ia32_compare_nodes_attr(a, b))
1000 attr_a = get_ia32_asm_attr_const(a);
1001 attr_b = get_ia32_asm_attr_const(b);
1003 if (attr_a->asm_text != attr_b->asm_text)
1010 * Hash function for Immediates
1012 static unsigned ia32_hash_Immediate(const ir_node *irn)
1014 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1016 return hash_ptr(a->symconst) + (a->sc_sign << 16) + a->offset;
1019 /** Compare node attributes for Immediates. */
1020 static int ia32_compare_immediate_attr(const ir_node *a, const ir_node *b)
1022 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1023 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1025 if (attr_a->symconst != attr_b->symconst
1026 || attr_a->sc_sign != attr_b->sc_sign
1027 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1028 || attr_a->offset != attr_b->offset) {
1035 /** Compare node attributes for x87 nodes. */
1036 static int ia32_compare_x87_attr(const ir_node *a, const ir_node *b)
1038 return ia32_compare_nodes_attr(a, b);
1041 /** Compare node attributes for ClimbFrame nodes. */
1042 static int ia32_compare_climbframe_attr(const ir_node *a, const ir_node *b)
1044 const ia32_climbframe_attr_t *attr_a;
1045 const ia32_climbframe_attr_t *attr_b;
1047 if (ia32_compare_nodes_attr(a, b))
1050 attr_a = get_ia32_climbframe_attr_const(a);
1051 attr_b = get_ia32_climbframe_attr_const(b);
1053 if (attr_a->count != attr_b->count)
1059 /* copies the ia32 attributes */
1060 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1063 struct obstack *obst = get_irg_obstack(irg);
1064 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1065 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1066 backend_info_t *old_info = be_get_info(old_node);
1067 backend_info_t *new_info = be_get_info(new_node);
1069 /* copy the attributes */
1070 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1072 /* copy out flags */
1073 new_info->out_infos =
1074 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1075 new_info->in_reqs = old_info->in_reqs;
1076 new_info->flags = old_info->flags;
1079 static void ia32_init_op(ir_op *op, unsigned latency)
1081 ia32_op_attr_t *attr = OALLOCZ(&opcodes_obst, ia32_op_attr_t);
1082 attr->latency = latency;
1083 set_op_attr(op, attr);
1086 /* Include the generated constructor functions */
1087 #include "gen_ia32_new_nodes.c.inl"