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
26 * This file implements the creation of the architecture specific firm opcodes
27 * and the corresponding node constructors for the ia32 assembler irg.
36 #include "irgraph_t.h"
42 #include "irverify_t.h"
46 #include "raw_bitset.h"
49 #include "../bearch.h"
50 #include "../beinfo.h"
52 #include "bearch_ia32_t.h"
53 #include "ia32_common_transform.h"
54 #include "ia32_nodes_attr.h"
55 #include "ia32_new_nodes.h"
56 #include "gen_ia32_regalloc_if.h"
57 #include "gen_ia32_machine.h"
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, 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 if (is_ia32_AddrModeS(n)) {
131 fprintf(F, "[AM S] ");
132 } else if (is_ia32_AddrModeD(n)) {
133 fprintf(F, "[AM D] ");
139 case dump_node_info_txt:
140 arch_dump_reqs_and_registers(F, n);
144 switch (get_ia32_op_type(n)) {
146 fprintf(F, "Normal");
149 fprintf(F, "AM Dest (Load+Store)");
152 fprintf(F, "AM Source (Load)");
155 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
160 /* dump supported am */
161 fprintf(F, "AM support = ");
162 switch (get_ia32_am_support(n)) {
163 case ia32_am_none: fputs("none\n", F); break;
164 case ia32_am_unary: fputs("source (unary)\n", F); break;
165 case ia32_am_binary: fputs("source (binary)\n", F); break;
168 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
173 if (get_ia32_am_offs_int(n) != 0) {
174 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
177 /* dump AM symconst */
178 if (get_ia32_am_sc(n) != NULL) {
179 ir_entity *ent = get_ia32_am_sc(n);
180 ident *id = get_entity_ld_ident(ent);
181 fprintf(F, "AM symconst = %s\n", get_id_str(id));
185 fprintf(F, "AM scale = %u\n", get_ia32_am_scale(n));
188 if (is_ia32_SwitchJmp(n)) {
189 fprintf(F, "default_pn = %ld\n", get_ia32_default_pn(n));
190 } else if (is_ia32_CMovcc(n) || is_ia32_Setcc(n) || is_ia32_Jcc(n)) {
191 ia32_attr_t *attr = get_ia32_attr(n);
192 fprintf(F, "condition_code = 0x%X\n", get_ia32_condcode(n));
193 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
195 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
196 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
199 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
200 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
201 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
202 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
203 fprintf(F, "latency = %u\n", get_ia32_latency(n));
205 /* dump frame entity */
206 fprintf(F, "frame entity = ");
207 if (get_ia32_frame_ent(n)) {
208 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
216 fprintf(F, "ls_mode = ");
217 if (get_ia32_ls_mode(n)) {
218 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
226 /* dump original ir node name */
227 fprintf(F, "orig node = ");
228 if (get_ia32_orig_node(n)) {
229 fprintf(F, "%s", get_ia32_orig_node(n));
243 ia32_attr_t *get_ia32_attr(ir_node *node)
245 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
246 return (ia32_attr_t *)get_irn_generic_attr(node);
249 const ia32_attr_t *get_ia32_attr_const(const ir_node *node)
251 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
252 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
255 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node)
257 ia32_attr_t *attr = get_ia32_attr(node);
258 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
262 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node)
264 const ia32_attr_t *attr = get_ia32_attr_const(node);
265 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
269 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node)
271 const ia32_attr_t *attr = get_ia32_attr_const(node);
272 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
277 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node)
279 ia32_attr_t *attr = get_ia32_attr(node);
280 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
285 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
287 const ia32_attr_t *attr = get_ia32_attr_const(node);
288 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
293 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node)
295 ia32_attr_t *attr = get_ia32_attr(node);
296 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
301 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node)
303 const ia32_attr_t *attr = get_ia32_attr_const(node);
304 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
309 ia32_switch_attr_t *get_ia32_switch_attr(ir_node *node)
311 ia32_attr_t *attr = get_ia32_attr(node);
312 ia32_switch_attr_t *switch_attr = CAST_IA32_ATTR(ia32_switch_attr_t, attr);
316 const ia32_switch_attr_t *get_ia32_switch_attr_const(const ir_node *node)
318 const ia32_attr_t *attr = get_ia32_attr_const(node);
319 const ia32_switch_attr_t *switch_attr = CONST_CAST_IA32_ATTR(ia32_switch_attr_t, attr);
323 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
325 ia32_attr_t *attr = get_ia32_attr(node);
326 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
331 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
333 const ia32_attr_t *attr = get_ia32_attr_const(node);
334 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
339 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node)
341 ia32_attr_t *attr = get_ia32_attr(node);
342 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
347 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node)
349 const ia32_attr_t *attr = get_ia32_attr_const(node);
350 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
355 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node)
357 ia32_attr_t *attr = get_ia32_attr(node);
358 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
360 return climbframe_attr;
363 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node)
365 const ia32_attr_t *attr = get_ia32_attr_const(node);
366 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
368 return climbframe_attr;
372 * Gets the type of an ia32 node.
374 ia32_op_type_t get_ia32_op_type(const ir_node *node)
376 const ia32_attr_t *attr = get_ia32_attr_const(node);
377 return (ia32_op_type_t)attr->data.tp;
381 * Sets the type of an ia32 node.
383 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp)
385 ia32_attr_t *attr = get_ia32_attr(node);
389 ia32_am_type_t get_ia32_am_support(const ir_node *node)
391 const ia32_attr_t *attr = get_ia32_attr_const(node);
392 return (ia32_am_type_t)attr->data.am_arity;
396 * Sets the supported address mode of an ia32 node
398 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
400 ia32_attr_t *attr = get_ia32_attr(node);
401 attr->data.am_arity = arity;
405 * Gets the address mode offset as int.
407 int get_ia32_am_offs_int(const ir_node *node)
409 const ia32_attr_t *attr = get_ia32_attr_const(node);
410 return attr->am_offs;
414 * Sets the address mode offset from an int.
416 void set_ia32_am_offs_int(ir_node *node, int offset)
418 ia32_attr_t *attr = get_ia32_attr(node);
419 attr->am_offs = offset;
422 void add_ia32_am_offs_int(ir_node *node, int offset)
424 ia32_attr_t *attr = get_ia32_attr(node);
425 attr->am_offs += offset;
429 * Returns the symconst entity associated to address mode.
431 ir_entity *get_ia32_am_sc(const ir_node *node)
433 const ia32_attr_t *attr = get_ia32_attr_const(node);
438 * Sets the symconst entity associated to address mode.
440 void set_ia32_am_sc(ir_node *node, ir_entity *entity)
442 ia32_attr_t *attr = get_ia32_attr(node);
443 attr->am_sc = entity;
447 * Sets the sign bit for address mode symconst.
449 void set_ia32_am_sc_sign(ir_node *node)
451 ia32_attr_t *attr = get_ia32_attr(node);
452 attr->data.am_sc_sign = 1;
456 * Clears the sign bit for address mode symconst.
458 void clear_ia32_am_sc_sign(ir_node *node)
460 ia32_attr_t *attr = get_ia32_attr(node);
461 attr->data.am_sc_sign = 0;
465 * Returns the sign bit for address mode symconst.
467 int is_ia32_am_sc_sign(const ir_node *node)
469 const ia32_attr_t *attr = get_ia32_attr_const(node);
470 return attr->data.am_sc_sign;
474 * Gets the addr mode const.
476 unsigned get_ia32_am_scale(const ir_node *node)
478 const ia32_attr_t *attr = get_ia32_attr_const(node);
479 return attr->data.am_scale;
483 * Sets the index register scale for address mode.
485 void set_ia32_am_scale(ir_node *node, unsigned scale)
487 ia32_attr_t *attr = get_ia32_attr(node);
488 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
489 attr->data.am_scale = scale;
492 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
494 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
495 set_ia32_am_scale(to, get_ia32_am_scale(from));
496 set_ia32_am_sc(to, get_ia32_am_sc(from));
497 if (is_ia32_am_sc_sign(from))
498 set_ia32_am_sc_sign(to);
499 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
500 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
501 if (is_ia32_use_frame(from))
502 set_ia32_use_frame(to);
506 * Sets the uses_frame flag.
508 void set_ia32_use_frame(ir_node *node)
510 ia32_attr_t *attr = get_ia32_attr(node);
511 attr->data.use_frame = 1;
515 * Clears the uses_frame flag.
517 void clear_ia32_use_frame(ir_node *node)
519 ia32_attr_t *attr = get_ia32_attr(node);
520 attr->data.use_frame = 0;
524 * Gets the uses_frame flag.
526 int is_ia32_use_frame(const ir_node *node)
528 const ia32_attr_t *attr = get_ia32_attr_const(node);
529 return attr->data.use_frame;
533 * Sets node to commutative.
535 void set_ia32_commutative(ir_node *node)
537 ia32_attr_t *attr = get_ia32_attr(node);
538 attr->data.is_commutative = 1;
542 * Sets node to non-commutative.
544 void clear_ia32_commutative(ir_node *node)
546 ia32_attr_t *attr = get_ia32_attr(node);
547 attr->data.is_commutative = 0;
551 * Checks if node is commutative.
553 int is_ia32_commutative(const ir_node *node)
555 const ia32_attr_t *attr = get_ia32_attr_const(node);
556 return attr->data.is_commutative;
559 void set_ia32_need_stackent(ir_node *node)
561 ia32_attr_t *attr = get_ia32_attr(node);
562 attr->data.need_stackent = 1;
565 void clear_ia32_need_stackent(ir_node *node)
567 ia32_attr_t *attr = get_ia32_attr(node);
568 attr->data.need_stackent = 0;
571 int is_ia32_need_stackent(const ir_node *node)
573 const ia32_attr_t *attr = get_ia32_attr_const(node);
574 return attr->data.need_stackent;
577 void set_ia32_is_reload(ir_node *node)
579 ia32_attr_t *attr = get_ia32_attr(node);
580 attr->data.is_reload = 1;
583 int is_ia32_is_reload(const ir_node *node)
585 const ia32_attr_t *attr = get_ia32_attr_const(node);
586 return attr->data.is_reload;
589 void set_ia32_is_spill(ir_node *node)
591 ia32_attr_t *attr = get_ia32_attr(node);
592 attr->data.is_spill = 1;
595 int is_ia32_is_spill(const ir_node *node)
597 const ia32_attr_t *attr = get_ia32_attr_const(node);
598 return attr->data.is_spill;
601 void set_ia32_is_remat(ir_node *node)
603 ia32_attr_t *attr = get_ia32_attr(node);
604 attr->data.is_remat = 1;
607 int is_ia32_is_remat(const ir_node *node)
609 const ia32_attr_t *attr = get_ia32_attr_const(node);
610 return attr->data.is_remat;
614 * Gets the mode of the stored/loaded value (only set for Store/Load)
616 ir_mode *get_ia32_ls_mode(const ir_node *node)
618 const ia32_attr_t *attr = get_ia32_attr_const(node);
619 return attr->ls_mode;
623 * Sets the mode of the stored/loaded value (only set for Store/Load)
625 void set_ia32_ls_mode(ir_node *node, ir_mode *mode)
627 ia32_attr_t *attr = get_ia32_attr(node);
628 attr->ls_mode = mode;
632 * Gets the frame entity assigned to this node.
634 ir_entity *get_ia32_frame_ent(const ir_node *node)
636 const ia32_attr_t *attr = get_ia32_attr_const(node);
637 return attr->frame_ent;
641 * Sets the frame entity for this node.
643 void set_ia32_frame_ent(ir_node *node, ir_entity *ent)
645 ia32_attr_t *attr = get_ia32_attr(node);
646 attr->frame_ent = ent;
648 set_ia32_use_frame(node);
650 clear_ia32_use_frame(node);
655 * Gets the instruction latency.
657 unsigned get_ia32_latency(const ir_node *node)
659 const ir_op *op = get_irn_op(node);
660 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
661 return op_attr->latency;
665 * Returns the condition code of a node.
667 ia32_condition_code_t get_ia32_condcode(const ir_node *node)
669 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
670 return attr->condition_code;
674 * Sets the condition code of a node
676 void set_ia32_condcode(ir_node *node, ia32_condition_code_t code)
678 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
679 attr->condition_code = code;
682 long get_ia32_default_pn(const ir_node *node)
684 const ia32_switch_attr_t *attr = get_ia32_switch_attr_const(node);
685 return attr->default_pn;
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 list of available execution units.
700 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node)
702 const ia32_attr_t *attr = get_ia32_attr_const(node);
703 return attr->exec_units;
707 * Get the exception label attribute.
709 unsigned get_ia32_exc_label(const ir_node *node)
711 const ia32_attr_t *attr = get_ia32_attr_const(node);
712 return attr->data.has_except_label;
716 * Set the exception label attribute.
718 void set_ia32_exc_label(ir_node *node, unsigned flag)
720 ia32_attr_t *attr = get_ia32_attr(node);
721 attr->data.has_except_label = flag;
725 * Return the exception label id.
727 ir_label_t get_ia32_exc_label_id(const ir_node *node)
729 const ia32_attr_t *attr = get_ia32_attr_const(node);
731 assert(attr->data.has_except_label);
732 return attr->exc_label;
736 * Assign the exception label id.
738 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
740 ia32_attr_t *attr = get_ia32_attr(node);
742 assert(attr->data.has_except_label);
743 attr->exc_label = id;
749 * Returns the name of the original ir node.
751 const char *get_ia32_orig_node(const ir_node *node)
753 const ia32_attr_t *attr = get_ia32_attr_const(node);
754 return attr->orig_node;
757 static const char *ia32_get_old_node_name(const ir_node *irn)
759 ir_graph *irg = get_irn_irg(irn);
760 struct obstack *obst = be_get_be_obst(irg);
762 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
763 obstack_1grow(obst, 0);
764 return (const char*)obstack_finish(obst);
768 * Sets the name of the original ir node.
770 void set_ia32_orig_node(ir_node *node, const ir_node *old)
772 const char *name = ia32_get_old_node_name(old);
773 ia32_attr_t *attr = get_ia32_attr(node);
774 attr->orig_node = name;
781 * Returns whether or not the node is an AddrModeS node.
783 int is_ia32_AddrModeS(const ir_node *node)
785 const ia32_attr_t *attr = get_ia32_attr_const(node);
786 return (attr->data.tp == ia32_AddrModeS);
790 * Returns whether or not the node is an AddrModeD node.
792 int is_ia32_AddrModeD(const ir_node *node)
794 const ia32_attr_t *attr = get_ia32_attr_const(node);
795 return (attr->data.tp == ia32_AddrModeD);
798 void ia32_swap_left_right(ir_node *node)
800 ia32_attr_t *attr = get_ia32_attr(node);
801 ir_node *left = get_irn_n(node, n_ia32_binary_left);
802 ir_node *right = get_irn_n(node, n_ia32_binary_right);
804 assert(is_ia32_commutative(node));
805 attr->data.ins_permuted = !attr->data.ins_permuted;
806 set_irn_n(node, n_ia32_binary_left, right);
807 set_irn_n(node, n_ia32_binary_right, left);
811 * Initializes the nodes attributes.
813 static void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
814 const arch_register_req_t **in_reqs,
815 const be_execution_unit_t ***execution_units,
818 ir_graph *irg = get_irn_irg(node);
819 struct obstack *obst = get_irg_obstack(irg);
820 ia32_attr_t *attr = get_ia32_attr(node);
821 backend_info_t *info;
823 arch_irn_set_flags(node, flags);
824 arch_set_in_register_reqs(node, in_reqs);
826 attr->exec_units = execution_units;
828 attr->attr_type |= IA32_ATTR_ia32_attr_t;
831 info = be_get_info(node);
832 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
833 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
836 static void init_ia32_x87_attributes(ir_node *res)
838 ir_graph *irg = get_irn_irg(res);
839 ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
841 ia32_attr_t *attr = get_ia32_attr(res);
842 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
846 irg_data->do_x87_sim = 1;
849 static void init_ia32_asm_attributes(ir_node *res)
852 ia32_attr_t *attr = get_ia32_attr(res);
853 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
859 static void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
860 int symconst_sign, int no_pic_adjust,
863 ia32_immediate_attr_t *attr = (ia32_immediate_attr_t*)get_irn_generic_attr(res);
866 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
868 attr->symconst = symconst;
869 attr->sc_sign = symconst_sign;
870 attr->no_pic_adjust = no_pic_adjust;
871 attr->offset = offset;
874 static void init_ia32_call_attributes(ir_node* res, unsigned pop,
877 ia32_call_attr_t *attr = (ia32_call_attr_t*)get_irn_generic_attr(res);
880 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
883 attr->call_tp = call_tp;
886 static void init_ia32_copyb_attributes(ir_node *res, unsigned size)
888 ia32_copyb_attr_t *attr = (ia32_copyb_attr_t*)get_irn_generic_attr(res);
891 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
896 static void init_ia32_condcode_attributes(ir_node *res,
897 ia32_condition_code_t cc)
899 ia32_condcode_attr_t *attr = (ia32_condcode_attr_t*)get_irn_generic_attr(res);
902 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
904 attr->condition_code = cc;
907 static void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
909 ia32_climbframe_attr_t *attr = (ia32_climbframe_attr_t*)get_irn_generic_attr(res);
912 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
917 static void init_ia32_switch_attributes(ir_node *res, long default_pn)
919 ia32_switch_attr_t *attr = (ia32_switch_attr_t*) get_irn_generic_attr(res);
921 attr->attr.attr_type |= IA32_ATTR_ia32_switch_attr_t;
923 attr->default_pn = default_pn;
927 /* default compare operation to compare attributes */
928 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
930 if (a->data.tp != b->data.tp)
933 if (a->data.am_scale != b->data.am_scale
934 || a->data.am_sc_sign != b->data.am_sc_sign
935 || a->am_offs != b->am_offs
936 || a->am_sc != b->am_sc
937 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
938 || a->ls_mode != b->ls_mode)
941 /* nodes with not yet assigned entities shouldn't be CSEd (important for
942 * unsigned int -> double conversions */
943 if (a->data.use_frame && a->frame_ent == NULL)
945 if (b->data.use_frame && b->frame_ent == NULL)
948 if (a->data.use_frame != b->data.use_frame
949 || a->frame_ent != b->frame_ent)
952 if (a->data.has_except_label != b->data.has_except_label)
955 if (a->data.ins_permuted != b->data.ins_permuted)
961 /** Compare nodes attributes for all "normal" nodes. */
962 static int ia32_compare_nodes_attr(const ir_node *a, const ir_node *b)
964 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
965 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
967 return ia32_compare_attr(attr_a, attr_b);
970 /** Compare node attributes for nodes with condition code. */
971 static int ia32_compare_condcode_attr(const ir_node *a, const ir_node *b)
973 const ia32_condcode_attr_t *attr_a;
974 const ia32_condcode_attr_t *attr_b;
976 if (ia32_compare_nodes_attr(a, b))
979 attr_a = get_ia32_condcode_attr_const(a);
980 attr_b = get_ia32_condcode_attr_const(b);
982 if (attr_a->condition_code != attr_b->condition_code)
988 /** Compare node attributes for nodes with condition code. */
989 static int ia32_compare_switch_attr(const ir_node *a, const ir_node *b)
991 const ia32_switch_attr_t *attr_a;
992 const ia32_switch_attr_t *attr_b;
994 if (ia32_compare_nodes_attr(a, b))
997 attr_a = get_ia32_switch_attr_const(a);
998 attr_b = get_ia32_switch_attr_const(b);
1000 if (attr_a->default_pn != attr_b->default_pn)
1006 /** Compare node attributes for call nodes. */
1007 static int ia32_compare_call_attr(const ir_node *a, const ir_node *b)
1009 const ia32_call_attr_t *attr_a;
1010 const ia32_call_attr_t *attr_b;
1012 if (ia32_compare_nodes_attr(a, b))
1015 attr_a = get_ia32_call_attr_const(a);
1016 attr_b = get_ia32_call_attr_const(b);
1018 if (attr_a->pop != attr_b->pop)
1021 if (attr_a->call_tp != attr_b->call_tp)
1027 /** Compare node attributes for CopyB nodes. */
1028 static int ia32_compare_copyb_attr(const ir_node *a, const ir_node *b)
1030 const ia32_copyb_attr_t *attr_a;
1031 const ia32_copyb_attr_t *attr_b;
1033 if (ia32_compare_nodes_attr(a, b))
1036 attr_a = get_ia32_copyb_attr_const(a);
1037 attr_b = get_ia32_copyb_attr_const(b);
1039 if (attr_a->size != attr_b->size)
1046 /** Compare ASM node attributes. */
1047 static int ia32_compare_asm_attr(const ir_node *a, const ir_node *b)
1049 const ia32_asm_attr_t *attr_a;
1050 const ia32_asm_attr_t *attr_b;
1052 if (ia32_compare_nodes_attr(a, b))
1055 attr_a = get_ia32_asm_attr_const(a);
1056 attr_b = get_ia32_asm_attr_const(b);
1058 if (attr_a->asm_text != attr_b->asm_text)
1065 * Hash function for Immediates
1067 static unsigned ia32_hash_Immediate(const ir_node *irn)
1069 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1071 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1074 /** Compare node attributes for Immediates. */
1075 static int ia32_compare_immediate_attr(const ir_node *a, const ir_node *b)
1077 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1078 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1080 if (attr_a->symconst != attr_b->symconst
1081 || attr_a->sc_sign != attr_b->sc_sign
1082 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1083 || attr_a->offset != attr_b->offset) {
1090 /** Compare node attributes for x87 nodes. */
1091 static int ia32_compare_x87_attr(const ir_node *a, const ir_node *b)
1093 return ia32_compare_nodes_attr(a, b);
1096 /** Compare node attributes for ClimbFrame nodes. */
1097 static int ia32_compare_climbframe_attr(const ir_node *a, const ir_node *b)
1099 const ia32_climbframe_attr_t *attr_a;
1100 const ia32_climbframe_attr_t *attr_b;
1102 if (ia32_compare_nodes_attr(a, b))
1105 attr_a = get_ia32_climbframe_attr_const(a);
1106 attr_b = get_ia32_climbframe_attr_const(b);
1108 if (attr_a->count != attr_b->count)
1114 /* copies the ia32 attributes */
1115 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1118 struct obstack *obst = get_irg_obstack(irg);
1119 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1120 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1121 backend_info_t *old_info = be_get_info(old_node);
1122 backend_info_t *new_info = be_get_info(new_node);
1124 /* copy the attributes */
1125 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1127 /* copy out flags */
1128 new_info->out_infos =
1129 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1130 new_info->in_reqs = old_info->in_reqs;
1131 new_info->flags = old_info->flags;
1134 /* Include the generated constructor functions */
1135 #include "gen_ia32_new_nodes.c.inl"