2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Handling of ia32 specific firm opcodes.
23 * @author Christian Wuerdig
26 * This file implements the creation of the achitecture specific firm opcodes
27 * and the corresponding node constructors for the ia32 assembler irg.
35 #include "irgraph_t.h"
41 #include "irverify_t.h"
45 #include "raw_bitset.h"
48 #include "../bearch.h"
49 #include "../beinfo.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)", 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", 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_SwitchJmp(n)) {
188 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
189 } else if (is_ia32_CMovcc(n) || is_ia32_Setcc(n) || is_ia32_Jcc(n)) {
190 ia32_attr_t *attr = get_ia32_attr(n);
191 long pnc = get_ia32_condcode(n);
192 fprintf(F, "pn_code = 0x%X (%s)\n", (unsigned) pnc,
193 get_pnc_string(pnc & pn_Cmp_True));
194 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
195 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
197 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
198 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
201 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
202 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
203 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
204 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
205 fprintf(F, "latency = %u\n", get_ia32_latency(n));
207 /* dump frame entity */
208 fprintf(F, "frame entity = ");
209 if (get_ia32_frame_ent(n)) {
210 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
218 fprintf(F, "ls_mode = ");
219 if (get_ia32_ls_mode(n)) {
220 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
228 /* dump original ir node name */
229 fprintf(F, "orig node = ");
230 if (get_ia32_orig_node(n)) {
231 fprintf(F, "%s", get_ia32_orig_node(n));
245 ia32_attr_t *get_ia32_attr(ir_node *node)
247 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
248 return (ia32_attr_t *)get_irn_generic_attr(node);
251 const ia32_attr_t *get_ia32_attr_const(const ir_node *node)
253 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
254 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
257 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node)
259 ia32_attr_t *attr = get_ia32_attr(node);
260 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
264 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node)
266 const ia32_attr_t *attr = get_ia32_attr_const(node);
267 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
271 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node)
273 const ia32_attr_t *attr = get_ia32_attr_const(node);
274 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
279 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node)
281 ia32_attr_t *attr = get_ia32_attr(node);
282 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
287 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
289 const ia32_attr_t *attr = get_ia32_attr_const(node);
290 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
295 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node)
297 ia32_attr_t *attr = get_ia32_attr(node);
298 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
303 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node)
305 const ia32_attr_t *attr = get_ia32_attr_const(node);
306 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
311 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
313 ia32_attr_t *attr = get_ia32_attr(node);
314 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
319 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
321 const ia32_attr_t *attr = get_ia32_attr_const(node);
322 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
327 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node)
329 ia32_attr_t *attr = get_ia32_attr(node);
330 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
335 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node)
337 const ia32_attr_t *attr = get_ia32_attr_const(node);
338 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
343 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node)
345 ia32_attr_t *attr = get_ia32_attr(node);
346 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
348 return climbframe_attr;
351 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node)
353 const ia32_attr_t *attr = get_ia32_attr_const(node);
354 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
356 return climbframe_attr;
360 * Gets the type of an ia32 node.
362 ia32_op_type_t get_ia32_op_type(const ir_node *node)
364 const ia32_attr_t *attr = get_ia32_attr_const(node);
365 return attr->data.tp;
369 * Sets the type of an ia32 node.
371 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp)
373 ia32_attr_t *attr = get_ia32_attr(node);
377 ia32_am_type_t get_ia32_am_support(const ir_node *node)
379 const ia32_attr_t *attr = get_ia32_attr_const(node);
380 return attr->data.am_arity;
384 * Sets the supported address mode of an ia32 node
386 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
388 ia32_attr_t *attr = get_ia32_attr(node);
389 attr->data.am_arity = arity;
393 * Gets the address mode offset as int.
395 int get_ia32_am_offs_int(const ir_node *node)
397 const ia32_attr_t *attr = get_ia32_attr_const(node);
398 return attr->am_offs;
402 * Sets the address mode offset from an int.
404 void set_ia32_am_offs_int(ir_node *node, int offset)
406 ia32_attr_t *attr = get_ia32_attr(node);
407 attr->am_offs = offset;
410 void add_ia32_am_offs_int(ir_node *node, int offset)
412 ia32_attr_t *attr = get_ia32_attr(node);
413 attr->am_offs += offset;
417 * Returns the symconst entity associated to address mode.
419 ir_entity *get_ia32_am_sc(const ir_node *node)
421 const ia32_attr_t *attr = get_ia32_attr_const(node);
426 * Sets the symconst entity associated to address mode.
428 void set_ia32_am_sc(ir_node *node, ir_entity *entity)
430 ia32_attr_t *attr = get_ia32_attr(node);
431 attr->am_sc = entity;
435 * Sets the sign bit for address mode symconst.
437 void set_ia32_am_sc_sign(ir_node *node)
439 ia32_attr_t *attr = get_ia32_attr(node);
440 attr->data.am_sc_sign = 1;
444 * Clears the sign bit for address mode symconst.
446 void clear_ia32_am_sc_sign(ir_node *node)
448 ia32_attr_t *attr = get_ia32_attr(node);
449 attr->data.am_sc_sign = 0;
453 * Returns the sign bit for address mode symconst.
455 int is_ia32_am_sc_sign(const ir_node *node)
457 const ia32_attr_t *attr = get_ia32_attr_const(node);
458 return attr->data.am_sc_sign;
462 * Gets the addr mode const.
464 unsigned get_ia32_am_scale(const ir_node *node)
466 const ia32_attr_t *attr = get_ia32_attr_const(node);
467 return attr->data.am_scale;
471 * Sets the index register scale for address mode.
473 void set_ia32_am_scale(ir_node *node, unsigned scale)
475 ia32_attr_t *attr = get_ia32_attr(node);
476 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
477 attr->data.am_scale = scale;
480 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
482 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
483 set_ia32_am_scale(to, get_ia32_am_scale(from));
484 set_ia32_am_sc(to, get_ia32_am_sc(from));
485 if (is_ia32_am_sc_sign(from))
486 set_ia32_am_sc_sign(to);
487 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
488 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
489 if (is_ia32_use_frame(from))
490 set_ia32_use_frame(to);
494 * Sets the uses_frame flag.
496 void set_ia32_use_frame(ir_node *node)
498 ia32_attr_t *attr = get_ia32_attr(node);
499 attr->data.use_frame = 1;
503 * Clears the uses_frame flag.
505 void clear_ia32_use_frame(ir_node *node)
507 ia32_attr_t *attr = get_ia32_attr(node);
508 attr->data.use_frame = 0;
512 * Gets the uses_frame flag.
514 int is_ia32_use_frame(const ir_node *node)
516 const ia32_attr_t *attr = get_ia32_attr_const(node);
517 return attr->data.use_frame;
521 * Sets node to commutative.
523 void set_ia32_commutative(ir_node *node)
525 ia32_attr_t *attr = get_ia32_attr(node);
526 attr->data.is_commutative = 1;
530 * Sets node to non-commutative.
532 void clear_ia32_commutative(ir_node *node)
534 ia32_attr_t *attr = get_ia32_attr(node);
535 attr->data.is_commutative = 0;
539 * Checks if node is commutative.
541 int is_ia32_commutative(const ir_node *node)
543 const ia32_attr_t *attr = get_ia32_attr_const(node);
544 return attr->data.is_commutative;
547 void set_ia32_need_stackent(ir_node *node)
549 ia32_attr_t *attr = get_ia32_attr(node);
550 attr->data.need_stackent = 1;
553 void clear_ia32_need_stackent(ir_node *node)
555 ia32_attr_t *attr = get_ia32_attr(node);
556 attr->data.need_stackent = 0;
559 int is_ia32_need_stackent(const ir_node *node)
561 const ia32_attr_t *attr = get_ia32_attr_const(node);
562 return attr->data.need_stackent;
565 void set_ia32_is_reload(ir_node *node)
567 ia32_attr_t *attr = get_ia32_attr(node);
568 attr->data.is_reload = 1;
571 int is_ia32_is_reload(const ir_node *node)
573 const ia32_attr_t *attr = get_ia32_attr_const(node);
574 return attr->data.is_reload;
577 void set_ia32_is_spill(ir_node *node)
579 ia32_attr_t *attr = get_ia32_attr(node);
580 attr->data.is_spill = 1;
583 int is_ia32_is_spill(const ir_node *node)
585 const ia32_attr_t *attr = get_ia32_attr_const(node);
586 return attr->data.is_spill;
589 void set_ia32_is_remat(ir_node *node)
591 ia32_attr_t *attr = get_ia32_attr(node);
592 attr->data.is_remat = 1;
595 int is_ia32_is_remat(const ir_node *node)
597 const ia32_attr_t *attr = get_ia32_attr_const(node);
598 return attr->data.is_remat;
602 * Gets the mode of the stored/loaded value (only set for Store/Load)
604 ir_mode *get_ia32_ls_mode(const ir_node *node)
606 const ia32_attr_t *attr = get_ia32_attr_const(node);
607 return attr->ls_mode;
611 * Sets the mode of the stored/loaded value (only set for Store/Load)
613 void set_ia32_ls_mode(ir_node *node, ir_mode *mode)
615 ia32_attr_t *attr = get_ia32_attr(node);
616 attr->ls_mode = mode;
620 * Gets the frame entity assigned to this node.
622 ir_entity *get_ia32_frame_ent(const ir_node *node)
624 const ia32_attr_t *attr = get_ia32_attr_const(node);
625 return attr->frame_ent;
629 * Sets the frame entity for this node.
631 void set_ia32_frame_ent(ir_node *node, ir_entity *ent)
633 ia32_attr_t *attr = get_ia32_attr(node);
634 attr->frame_ent = ent;
636 set_ia32_use_frame(node);
638 clear_ia32_use_frame(node);
643 * Gets the instruction latency.
645 unsigned get_ia32_latency(const ir_node *node)
647 const ir_op *op = get_irn_op(node);
648 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
649 return op_attr->latency;
653 * Returns the argument register requirements of an ia32 node.
655 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node)
657 const ia32_attr_t *attr = get_ia32_attr_const(node);
662 * Sets the argument register requirements of an ia32 node.
664 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs)
666 ia32_attr_t *attr = get_ia32_attr(node);
671 * Returns the argument register requirement at position pos of an ia32 node.
673 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos)
675 const ia32_attr_t *attr = get_ia32_attr_const(node);
676 if (attr->in_req == NULL)
677 return arch_no_register_req;
679 return attr->in_req[pos];
683 * Sets the IN register requirements at position pos.
685 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos)
687 ia32_attr_t *attr = get_ia32_attr(node);
688 attr->in_req[pos] = req;
692 * Returns the condition code of a node.
694 long get_ia32_condcode(const ir_node *node)
696 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
697 return attr->pn_code;
701 * Sets the condition code of a node
703 void set_ia32_condcode(ir_node *node, long code)
705 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
706 attr->pn_code = code;
710 * Returns the condition code of a node.
712 unsigned get_ia32_copyb_size(const ir_node *node)
714 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
719 * Get the list of available execution units.
721 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node)
723 const ia32_attr_t *attr = get_ia32_attr_const(node);
724 return attr->exec_units;
728 * Get the exception label attribute.
730 unsigned get_ia32_exc_label(const ir_node *node)
732 const ia32_attr_t *attr = get_ia32_attr_const(node);
733 return attr->data.has_except_label;
737 * Set the exception label attribute.
739 void set_ia32_exc_label(ir_node *node, unsigned flag)
741 ia32_attr_t *attr = get_ia32_attr(node);
742 attr->data.has_except_label = flag;
746 * Return the exception label id.
748 ir_label_t get_ia32_exc_label_id(const ir_node *node)
750 const ia32_attr_t *attr = get_ia32_attr_const(node);
752 assert(attr->data.has_except_label);
753 return attr->exc_label;
757 * Assign the exception label id.
759 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
761 ia32_attr_t *attr = get_ia32_attr(node);
763 assert(attr->data.has_except_label);
764 attr->exc_label = id;
770 * Returns the name of the original ir node.
772 const char *get_ia32_orig_node(const ir_node *node)
774 const ia32_attr_t *attr = get_ia32_attr_const(node);
775 return attr->orig_node;
778 static const char *ia32_get_old_node_name(const ir_node *irn)
780 struct obstack *obst = env_cg->isa->name_obst;
782 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
783 obstack_1grow(obst, 0);
784 return obstack_finish(obst);
788 * Sets the name of the original ir node.
790 void set_ia32_orig_node(ir_node *node, const ir_node *old)
792 const char *name = ia32_get_old_node_name(old);
793 ia32_attr_t *attr = get_ia32_attr(node);
794 attr->orig_node = name;
801 * Returns whether or not the node is an AddrModeS node.
803 int is_ia32_AddrModeS(const ir_node *node)
805 const ia32_attr_t *attr = get_ia32_attr_const(node);
806 return (attr->data.tp == ia32_AddrModeS);
810 * Returns whether or not the node is an AddrModeD node.
812 int is_ia32_AddrModeD(const ir_node *node)
814 const ia32_attr_t *attr = get_ia32_attr_const(node);
815 return (attr->data.tp == ia32_AddrModeD);
818 void ia32_swap_left_right(ir_node *node)
820 ia32_attr_t *attr = get_ia32_attr(node);
821 ir_node *left = get_irn_n(node, n_ia32_binary_left);
822 ir_node *right = get_irn_n(node, n_ia32_binary_right);
824 assert(is_ia32_commutative(node));
825 attr->data.ins_permuted = !attr->data.ins_permuted;
826 set_irn_n(node, n_ia32_binary_left, right);
827 set_irn_n(node, n_ia32_binary_right, left);
831 * Initializes the nodes attributes.
833 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
834 const arch_register_req_t **in_reqs,
835 const be_execution_unit_t ***execution_units,
838 ir_graph *irg = get_irn_irg(node);
839 struct obstack *obst = get_irg_obstack(irg);
840 ia32_attr_t *attr = get_ia32_attr(node);
841 backend_info_t *info;
843 arch_irn_set_flags(node, flags);
844 set_ia32_in_req_all(node, in_reqs);
846 attr->exec_units = execution_units;
848 attr->attr_type |= IA32_ATTR_ia32_attr_t;
851 info = be_get_info(node);
852 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
853 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
856 void init_ia32_x87_attributes(ir_node *res)
859 ia32_attr_t *attr = get_ia32_attr(res);
860 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
864 ia32_current_cg->do_x87_sim = 1;
867 void init_ia32_asm_attributes(ir_node *res)
870 ia32_attr_t *attr = get_ia32_attr(res);
871 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
877 void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
878 int symconst_sign, int no_pic_adjust,
881 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
884 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
886 attr->symconst = symconst;
887 attr->sc_sign = symconst_sign;
888 attr->no_pic_adjust = no_pic_adjust;
889 attr->offset = offset;
892 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
894 ia32_call_attr_t *attr = get_irn_generic_attr(res);
897 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
900 attr->call_tp = call_tp;
903 void init_ia32_copyb_attributes(ir_node *res, unsigned size)
905 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
908 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
913 void init_ia32_condcode_attributes(ir_node *res, long pnc)
915 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
918 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
923 void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
925 ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
928 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
934 /* default compare operation to compare attributes */
935 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
937 if (a->data.tp != b->data.tp)
940 if (a->data.am_scale != b->data.am_scale
941 || a->data.am_sc_sign != b->data.am_sc_sign
942 || a->am_offs != b->am_offs
943 || a->am_sc != b->am_sc
944 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
945 || a->ls_mode != b->ls_mode)
948 /* nodes with not yet assigned entities shouldn't be CSEd (important for
949 * unsigned int -> double conversions */
950 if (a->data.use_frame && a->frame_ent == NULL)
952 if (b->data.use_frame && b->frame_ent == NULL)
955 if (a->data.use_frame != b->data.use_frame
956 || a->frame_ent != b->frame_ent)
959 if (a->data.has_except_label != b->data.has_except_label)
962 if (a->data.ins_permuted != b->data.ins_permuted
963 || a->data.cmp_unsigned != b->data.cmp_unsigned)
969 /** Compare nodes attributes for all "normal" nodes. */
970 static int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
972 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
973 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
975 return ia32_compare_attr(attr_a, attr_b);
978 /** Compare node attributes for nodes with condition code. */
979 static int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
981 const ia32_condcode_attr_t *attr_a;
982 const ia32_condcode_attr_t *attr_b;
984 if (ia32_compare_nodes_attr(a, b))
987 attr_a = get_ia32_condcode_attr_const(a);
988 attr_b = get_ia32_condcode_attr_const(b);
990 if (attr_a->pn_code != attr_b->pn_code)
996 /** Compare node attributes for call nodes. */
997 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
999 const ia32_call_attr_t *attr_a;
1000 const ia32_call_attr_t *attr_b;
1002 if (ia32_compare_nodes_attr(a, b))
1005 attr_a = get_ia32_call_attr_const(a);
1006 attr_b = get_ia32_call_attr_const(b);
1008 if (attr_a->pop != attr_b->pop)
1011 if (attr_a->call_tp != attr_b->call_tp)
1017 /** Compare node attributes for CopyB nodes. */
1018 static int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1020 const ia32_copyb_attr_t *attr_a;
1021 const ia32_copyb_attr_t *attr_b;
1023 if (ia32_compare_nodes_attr(a, b))
1026 attr_a = get_ia32_copyb_attr_const(a);
1027 attr_b = get_ia32_copyb_attr_const(b);
1029 if (attr_a->size != attr_b->size)
1036 /** Compare ASM node attributes. */
1037 static int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1039 const ia32_asm_attr_t *attr_a;
1040 const ia32_asm_attr_t *attr_b;
1042 if (ia32_compare_nodes_attr(a, b))
1045 attr_a = get_ia32_asm_attr_const(a);
1046 attr_b = get_ia32_asm_attr_const(b);
1048 if (attr_a->asm_text != attr_b->asm_text)
1055 * Hash function for Immediates
1057 static unsigned ia32_hash_Immediate(const ir_node *irn)
1059 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1061 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1064 /** Compare node attributes for Immediates. */
1065 static int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1067 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1068 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1070 if (attr_a->symconst != attr_b->symconst
1071 || attr_a->sc_sign != attr_b->sc_sign
1072 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1073 || attr_a->offset != attr_b->offset) {
1080 /** Compare node attributes for x87 nodes. */
1081 static int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1083 return ia32_compare_nodes_attr(a, b);
1086 /** Compare node attributes for ClimbFrame nodes. */
1087 static int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
1089 const ia32_climbframe_attr_t *attr_a;
1090 const ia32_climbframe_attr_t *attr_b;
1092 if (ia32_compare_nodes_attr(a, b))
1095 attr_a = get_ia32_climbframe_attr_const(a);
1096 attr_b = get_ia32_climbframe_attr_const(b);
1098 if (attr_a->count != attr_b->count)
1104 /* copies the ia32 attributes */
1105 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1108 struct obstack *obst = get_irg_obstack(irg);
1109 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1110 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1111 backend_info_t *old_info = be_get_info(old_node);
1112 backend_info_t *new_info = be_get_info(new_node);
1114 /* copy the attributes */
1115 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1117 /* copy out flags */
1118 new_info->out_infos =
1119 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1122 /* Include the generated constructor functions */
1123 #include "gen_ia32_new_nodes.c.inl"