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"
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"
58 /***********************************************************************************
61 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
62 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
63 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
64 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
67 ***********************************************************************************/
70 * Dumper interface for dumping ia32 nodes in vcg.
71 * @param n the node to dump
72 * @param F the output file
73 * @param reason indicates which kind of information should be dumped
74 * @return 0 on success or != 0 on failure
76 static void ia32_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
81 case dump_node_opcode_txt:
82 fprintf(F, "%s", get_irn_opname(n));
84 if (is_ia32_Immediate(n) || is_ia32_Const(n)) {
85 const ia32_immediate_attr_t *attr
86 = get_ia32_immediate_attr_const(n);
93 fputs(get_entity_name(attr->symconst), F);
95 if (attr->offset != 0 || attr->symconst == NULL) {
96 if (attr->offset > 0 && attr->symconst != NULL) {
99 fprintf(F, "%ld", attr->offset);
100 if (attr->no_pic_adjust) {
101 fputs("(no_pic_adjust)", F);
106 const ia32_attr_t *attr = get_ia32_attr_const(n);
108 if (attr->am_sc != NULL || attr->am_offs != 0)
111 if (attr->am_sc != NULL) {
112 if (attr->data.am_sc_sign) {
115 fputs(get_entity_name(attr->am_sc), F);
116 if (attr->data.am_sc_no_pic_adjust) {
117 fputs("(no_pic_adjust)", F);
120 if (attr->am_offs != 0) {
121 if (attr->am_offs > 0 && attr->am_sc != NULL) {
124 fprintf(F, "%d", attr->am_offs);
127 if (attr->am_sc != NULL || attr->am_offs != 0)
132 case dump_node_mode_txt:
133 mode = get_ia32_ls_mode(n);
135 fprintf(F, "[%s]", get_mode_name(mode));
138 case dump_node_nodeattr_txt:
139 if (! is_ia32_Lea(n)) {
140 if (is_ia32_AddrModeS(n)) {
141 fprintf(F, "[AM S] ");
142 } else if (is_ia32_AddrModeD(n)) {
143 fprintf(F, "[AM D] ");
149 case dump_node_info_txt:
150 arch_dump_reqs_and_registers(F, n);
154 switch (get_ia32_op_type(n)) {
156 fprintf(F, "Normal");
159 fprintf(F, "AM Dest (Load+Store)");
162 fprintf(F, "AM Source (Load)");
165 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
170 /* dump supported am */
171 fprintf(F, "AM support = ");
172 switch (get_ia32_am_support(n)) {
173 case ia32_am_none: fputs("none\n", F); break;
174 case ia32_am_unary: fputs("source (unary)\n", F); break;
175 case ia32_am_binary: fputs("source (binary)\n", F); break;
178 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
183 if (get_ia32_am_offs_int(n) != 0) {
184 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
187 /* dump AM symconst */
188 if (get_ia32_am_sc(n) != NULL) {
189 ir_entity *ent = get_ia32_am_sc(n);
190 ident *id = get_entity_ld_ident(ent);
191 fprintf(F, "AM symconst = %s\n", get_id_str(id));
195 fprintf(F, "AM scale = %u\n", get_ia32_am_scale(n));
198 if (is_ia32_SwitchJmp(n)) {
199 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
200 } else if (is_ia32_CMovcc(n) || is_ia32_Setcc(n) || is_ia32_Jcc(n)) {
201 ia32_attr_t *attr = get_ia32_attr(n);
202 long pnc = get_ia32_condcode(n);
203 fprintf(F, "pn_code = 0x%X (%s)\n", (unsigned) pnc,
204 get_pnc_string(pnc & pn_Cmp_True));
205 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
206 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
208 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
209 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
212 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
213 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
214 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
215 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
216 fprintf(F, "latency = %u\n", get_ia32_latency(n));
218 /* dump frame entity */
219 fprintf(F, "frame entity = ");
220 if (get_ia32_frame_ent(n)) {
221 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
229 fprintf(F, "ls_mode = ");
230 if (get_ia32_ls_mode(n)) {
231 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
239 /* dump original ir node name */
240 fprintf(F, "orig node = ");
241 if (get_ia32_orig_node(n)) {
242 fprintf(F, "%s", get_ia32_orig_node(n));
256 /***************************************************************************************************
258 * | | | | | | / / | | | | | | | |
259 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
260 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
261 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
262 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
265 ***************************************************************************************************/
267 ia32_attr_t *get_ia32_attr(ir_node *node)
269 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
270 return (ia32_attr_t *)get_irn_generic_attr(node);
273 const ia32_attr_t *get_ia32_attr_const(const ir_node *node)
275 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
276 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
279 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node)
281 ia32_attr_t *attr = get_ia32_attr(node);
282 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
286 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node)
288 const ia32_attr_t *attr = get_ia32_attr_const(node);
289 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
293 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node)
295 const ia32_attr_t *attr = get_ia32_attr_const(node);
296 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
301 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node)
303 ia32_attr_t *attr = get_ia32_attr(node);
304 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
309 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
311 const ia32_attr_t *attr = get_ia32_attr_const(node);
312 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
317 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node)
319 ia32_attr_t *attr = get_ia32_attr(node);
320 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
325 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node)
327 const ia32_attr_t *attr = get_ia32_attr_const(node);
328 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
333 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
335 ia32_attr_t *attr = get_ia32_attr(node);
336 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
341 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
343 const ia32_attr_t *attr = get_ia32_attr_const(node);
344 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
349 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node)
351 ia32_attr_t *attr = get_ia32_attr(node);
352 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
357 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node)
359 const ia32_attr_t *attr = get_ia32_attr_const(node);
360 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
365 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node)
367 ia32_attr_t *attr = get_ia32_attr(node);
368 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
370 return climbframe_attr;
373 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node)
375 const ia32_attr_t *attr = get_ia32_attr_const(node);
376 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
378 return climbframe_attr;
382 * Gets the type of an ia32 node.
384 ia32_op_type_t get_ia32_op_type(const ir_node *node)
386 const ia32_attr_t *attr = get_ia32_attr_const(node);
387 return attr->data.tp;
391 * Sets the type of an ia32 node.
393 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp)
395 ia32_attr_t *attr = get_ia32_attr(node);
399 ia32_am_type_t get_ia32_am_support(const ir_node *node)
401 const ia32_attr_t *attr = get_ia32_attr_const(node);
402 return attr->data.am_arity;
406 * Sets the supported address mode of an ia32 node
408 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
410 ia32_attr_t *attr = get_ia32_attr(node);
411 attr->data.am_arity = arity;
415 * Gets the address mode offset as int.
417 int get_ia32_am_offs_int(const ir_node *node)
419 const ia32_attr_t *attr = get_ia32_attr_const(node);
420 return attr->am_offs;
424 * Sets the address mode offset from an int.
426 void set_ia32_am_offs_int(ir_node *node, int offset)
428 ia32_attr_t *attr = get_ia32_attr(node);
429 attr->am_offs = offset;
432 void add_ia32_am_offs_int(ir_node *node, int offset)
434 ia32_attr_t *attr = get_ia32_attr(node);
435 attr->am_offs += offset;
439 * Returns the symconst entity associated to address mode.
441 ir_entity *get_ia32_am_sc(const ir_node *node)
443 const ia32_attr_t *attr = get_ia32_attr_const(node);
448 * Sets the symconst entity associated to address mode.
450 void set_ia32_am_sc(ir_node *node, ir_entity *entity)
452 ia32_attr_t *attr = get_ia32_attr(node);
453 attr->am_sc = entity;
457 * Sets the sign bit for address mode symconst.
459 void set_ia32_am_sc_sign(ir_node *node)
461 ia32_attr_t *attr = get_ia32_attr(node);
462 attr->data.am_sc_sign = 1;
466 * Clears the sign bit for address mode symconst.
468 void clear_ia32_am_sc_sign(ir_node *node)
470 ia32_attr_t *attr = get_ia32_attr(node);
471 attr->data.am_sc_sign = 0;
475 * Returns the sign bit for address mode symconst.
477 int is_ia32_am_sc_sign(const ir_node *node)
479 const ia32_attr_t *attr = get_ia32_attr_const(node);
480 return attr->data.am_sc_sign;
484 * Gets the addr mode const.
486 unsigned get_ia32_am_scale(const ir_node *node)
488 const ia32_attr_t *attr = get_ia32_attr_const(node);
489 return attr->data.am_scale;
493 * Sets the index register scale for address mode.
495 void set_ia32_am_scale(ir_node *node, unsigned scale)
497 ia32_attr_t *attr = get_ia32_attr(node);
498 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
499 attr->data.am_scale = scale;
502 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
504 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
505 set_ia32_am_scale(to, get_ia32_am_scale(from));
506 set_ia32_am_sc(to, get_ia32_am_sc(from));
507 if (is_ia32_am_sc_sign(from))
508 set_ia32_am_sc_sign(to);
509 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
510 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
511 if (is_ia32_use_frame(from))
512 set_ia32_use_frame(to);
516 * Sets the uses_frame flag.
518 void set_ia32_use_frame(ir_node *node)
520 ia32_attr_t *attr = get_ia32_attr(node);
521 attr->data.use_frame = 1;
525 * Clears the uses_frame flag.
527 void clear_ia32_use_frame(ir_node *node)
529 ia32_attr_t *attr = get_ia32_attr(node);
530 attr->data.use_frame = 0;
534 * Gets the uses_frame flag.
536 int is_ia32_use_frame(const ir_node *node)
538 const ia32_attr_t *attr = get_ia32_attr_const(node);
539 return attr->data.use_frame;
543 * Sets node to commutative.
545 void set_ia32_commutative(ir_node *node)
547 ia32_attr_t *attr = get_ia32_attr(node);
548 attr->data.is_commutative = 1;
552 * Sets node to non-commutative.
554 void clear_ia32_commutative(ir_node *node)
556 ia32_attr_t *attr = get_ia32_attr(node);
557 attr->data.is_commutative = 0;
561 * Checks if node is commutative.
563 int is_ia32_commutative(const ir_node *node)
565 const ia32_attr_t *attr = get_ia32_attr_const(node);
566 return attr->data.is_commutative;
569 void set_ia32_need_stackent(ir_node *node)
571 ia32_attr_t *attr = get_ia32_attr(node);
572 attr->data.need_stackent = 1;
575 void clear_ia32_need_stackent(ir_node *node)
577 ia32_attr_t *attr = get_ia32_attr(node);
578 attr->data.need_stackent = 0;
581 int is_ia32_need_stackent(const ir_node *node)
583 const ia32_attr_t *attr = get_ia32_attr_const(node);
584 return attr->data.need_stackent;
587 void set_ia32_is_reload(ir_node *node)
589 ia32_attr_t *attr = get_ia32_attr(node);
590 attr->data.is_reload = 1;
593 int is_ia32_is_reload(const ir_node *node)
595 const ia32_attr_t *attr = get_ia32_attr_const(node);
596 return attr->data.is_reload;
599 void set_ia32_is_spill(ir_node *node)
601 ia32_attr_t *attr = get_ia32_attr(node);
602 attr->data.is_spill = 1;
605 int is_ia32_is_spill(const ir_node *node)
607 const ia32_attr_t *attr = get_ia32_attr_const(node);
608 return attr->data.is_spill;
611 void set_ia32_is_remat(ir_node *node)
613 ia32_attr_t *attr = get_ia32_attr(node);
614 attr->data.is_remat = 1;
617 int is_ia32_is_remat(const ir_node *node)
619 const ia32_attr_t *attr = get_ia32_attr_const(node);
620 return attr->data.is_remat;
624 * Gets the mode of the stored/loaded value (only set for Store/Load)
626 ir_mode *get_ia32_ls_mode(const ir_node *node)
628 const ia32_attr_t *attr = get_ia32_attr_const(node);
629 return attr->ls_mode;
633 * Sets the mode of the stored/loaded value (only set for Store/Load)
635 void set_ia32_ls_mode(ir_node *node, ir_mode *mode)
637 ia32_attr_t *attr = get_ia32_attr(node);
638 attr->ls_mode = mode;
642 * Gets the frame entity assigned to this node.
644 ir_entity *get_ia32_frame_ent(const ir_node *node)
646 const ia32_attr_t *attr = get_ia32_attr_const(node);
647 return attr->frame_ent;
651 * Sets the frame entity for this node.
653 void set_ia32_frame_ent(ir_node *node, ir_entity *ent)
655 ia32_attr_t *attr = get_ia32_attr(node);
656 attr->frame_ent = ent;
658 set_ia32_use_frame(node);
660 clear_ia32_use_frame(node);
665 * Gets the instruction latency.
667 unsigned get_ia32_latency(const ir_node *node)
669 const ir_op *op = get_irn_op(node);
670 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
671 return op_attr->latency;
675 * Returns the argument register requirements of an ia32 node.
677 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node)
679 const ia32_attr_t *attr = get_ia32_attr_const(node);
684 * Sets the argument register requirements of an ia32 node.
686 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs)
688 ia32_attr_t *attr = get_ia32_attr(node);
693 * Returns the argument register requirement at position pos of an ia32 node.
695 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos)
697 const ia32_attr_t *attr = get_ia32_attr_const(node);
698 if (attr->in_req == NULL)
699 return arch_no_register_req;
701 return attr->in_req[pos];
705 * Sets the IN register requirements at position pos.
707 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos)
709 ia32_attr_t *attr = get_ia32_attr(node);
710 attr->in_req[pos] = req;
714 * Returns the condition code of a node.
716 long get_ia32_condcode(const ir_node *node)
718 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
719 return attr->pn_code;
723 * Sets the condition code of a node
725 void set_ia32_condcode(ir_node *node, long code)
727 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
728 attr->pn_code = code;
732 * Returns the condition code of a node.
734 unsigned get_ia32_copyb_size(const ir_node *node)
736 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
741 * Get the list of available execution units.
743 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node)
745 const ia32_attr_t *attr = get_ia32_attr_const(node);
746 return attr->exec_units;
750 * Get the exception label attribute.
752 unsigned get_ia32_exc_label(const ir_node *node)
754 const ia32_attr_t *attr = get_ia32_attr_const(node);
755 return attr->data.has_except_label;
759 * Set the exception label attribute.
761 void set_ia32_exc_label(ir_node *node, unsigned flag)
763 ia32_attr_t *attr = get_ia32_attr(node);
764 attr->data.has_except_label = flag;
768 * Return the exception label id.
770 ir_label_t get_ia32_exc_label_id(const ir_node *node)
772 const ia32_attr_t *attr = get_ia32_attr_const(node);
774 assert(attr->data.has_except_label);
775 return attr->exc_label;
779 * Assign the exception label id.
781 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
783 ia32_attr_t *attr = get_ia32_attr(node);
785 assert(attr->data.has_except_label);
786 attr->exc_label = id;
792 * Returns the name of the original ir node.
794 const char *get_ia32_orig_node(const ir_node *node)
796 const ia32_attr_t *attr = get_ia32_attr_const(node);
797 return attr->orig_node;
800 static const char *ia32_get_old_node_name(const ir_node *irn)
802 struct obstack *obst = env_cg->isa->name_obst;
804 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
805 obstack_1grow(obst, 0);
806 return obstack_finish(obst);
810 * Sets the name of the original ir node.
812 void set_ia32_orig_node(ir_node *node, const ir_node *old)
814 const char *name = ia32_get_old_node_name(old);
815 ia32_attr_t *attr = get_ia32_attr(node);
816 attr->orig_node = name;
821 /******************************************************************************************************
823 * (_) | | | | | | / _| | | (_)
824 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
825 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
826 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
827 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
830 ******************************************************************************************************/
833 * Returns whether or not the node is an AddrModeS node.
835 int is_ia32_AddrModeS(const ir_node *node)
837 const ia32_attr_t *attr = get_ia32_attr_const(node);
838 return (attr->data.tp == ia32_AddrModeS);
842 * Returns whether or not the node is an AddrModeD node.
844 int is_ia32_AddrModeD(const ir_node *node)
846 const ia32_attr_t *attr = get_ia32_attr_const(node);
847 return (attr->data.tp == ia32_AddrModeD);
850 void ia32_swap_left_right(ir_node *node)
852 ia32_attr_t *attr = get_ia32_attr(node);
853 ir_node *left = get_irn_n(node, n_ia32_binary_left);
854 ir_node *right = get_irn_n(node, n_ia32_binary_right);
856 assert(is_ia32_commutative(node));
857 attr->data.ins_permuted = !attr->data.ins_permuted;
858 set_irn_n(node, n_ia32_binary_left, right);
859 set_irn_n(node, n_ia32_binary_right, left);
863 * Initializes the nodes attributes.
865 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
866 const arch_register_req_t **in_reqs,
867 const be_execution_unit_t ***execution_units,
870 ir_graph *irg = get_irn_irg(node);
871 struct obstack *obst = get_irg_obstack(irg);
872 ia32_attr_t *attr = get_ia32_attr(node);
873 backend_info_t *info;
875 arch_irn_set_flags(node, flags);
876 set_ia32_in_req_all(node, in_reqs);
878 attr->exec_units = execution_units;
880 attr->attr_type |= IA32_ATTR_ia32_attr_t;
883 info = be_get_info(node);
884 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
885 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
888 void init_ia32_x87_attributes(ir_node *res)
891 ia32_attr_t *attr = get_ia32_attr(res);
892 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
896 ia32_current_cg->do_x87_sim = 1;
899 void init_ia32_asm_attributes(ir_node *res)
902 ia32_attr_t *attr = get_ia32_attr(res);
903 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
909 void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
910 int symconst_sign, int no_pic_adjust,
913 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
916 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
918 attr->symconst = symconst;
919 attr->sc_sign = symconst_sign;
920 attr->no_pic_adjust = no_pic_adjust;
921 attr->offset = offset;
924 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
926 ia32_call_attr_t *attr = get_irn_generic_attr(res);
929 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
932 attr->call_tp = call_tp;
935 void init_ia32_copyb_attributes(ir_node *res, unsigned size)
937 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
940 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
945 void init_ia32_condcode_attributes(ir_node *res, long pnc)
947 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
950 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
955 void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
957 ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
960 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
965 /***************************************************************************************
968 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
969 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
970 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
971 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
973 ***************************************************************************************/
975 /* default compare operation to compare attributes */
976 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
978 if (a->data.tp != b->data.tp)
981 if (a->data.am_scale != b->data.am_scale
982 || a->data.am_sc_sign != b->data.am_sc_sign
983 || a->am_offs != b->am_offs
984 || a->am_sc != b->am_sc
985 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
986 || a->ls_mode != b->ls_mode)
989 /* nodes with not yet assigned entities shouldn't be CSEd (important for
990 * unsigned int -> double conversions */
991 if (a->data.use_frame && a->frame_ent == NULL)
993 if (b->data.use_frame && b->frame_ent == NULL)
996 if (a->data.use_frame != b->data.use_frame
997 || a->frame_ent != b->frame_ent)
1000 if (a->data.has_except_label != b->data.has_except_label)
1003 if (a->data.ins_permuted != b->data.ins_permuted
1004 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1010 /** Compare nodes attributes for all "normal" nodes. */
1011 static int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1013 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1014 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1016 return ia32_compare_attr(attr_a, attr_b);
1019 /** Compare node attributes for nodes with condition code. */
1020 static int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1022 const ia32_condcode_attr_t *attr_a;
1023 const ia32_condcode_attr_t *attr_b;
1025 if (ia32_compare_nodes_attr(a, b))
1028 attr_a = get_ia32_condcode_attr_const(a);
1029 attr_b = get_ia32_condcode_attr_const(b);
1031 if (attr_a->pn_code != attr_b->pn_code)
1037 /** Compare node attributes for call nodes. */
1038 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1040 const ia32_call_attr_t *attr_a;
1041 const ia32_call_attr_t *attr_b;
1043 if (ia32_compare_nodes_attr(a, b))
1046 attr_a = get_ia32_call_attr_const(a);
1047 attr_b = get_ia32_call_attr_const(b);
1049 if (attr_a->pop != attr_b->pop)
1052 if (attr_a->call_tp != attr_b->call_tp)
1058 /** Compare node attributes for CopyB nodes. */
1059 static int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1061 const ia32_copyb_attr_t *attr_a;
1062 const ia32_copyb_attr_t *attr_b;
1064 if (ia32_compare_nodes_attr(a, b))
1067 attr_a = get_ia32_copyb_attr_const(a);
1068 attr_b = get_ia32_copyb_attr_const(b);
1070 if (attr_a->size != attr_b->size)
1077 /** Compare ASM node attributes. */
1078 static int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1080 const ia32_asm_attr_t *attr_a;
1081 const ia32_asm_attr_t *attr_b;
1083 if (ia32_compare_nodes_attr(a, b))
1086 attr_a = get_ia32_asm_attr_const(a);
1087 attr_b = get_ia32_asm_attr_const(b);
1089 if (attr_a->asm_text != attr_b->asm_text)
1096 * Hash function for Immediates
1098 static unsigned ia32_hash_Immediate(const ir_node *irn)
1100 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1102 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1105 /** Compare node attributes for Immediates. */
1106 static int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1108 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1109 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1111 if (attr_a->symconst != attr_b->symconst
1112 || attr_a->sc_sign != attr_b->sc_sign
1113 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1114 || attr_a->offset != attr_b->offset) {
1121 /** Compare node attributes for x87 nodes. */
1122 static int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1124 return ia32_compare_nodes_attr(a, b);
1127 /** Compare node attributes for ClimbFrame nodes. */
1128 static int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
1130 const ia32_climbframe_attr_t *attr_a;
1131 const ia32_climbframe_attr_t *attr_b;
1133 if (ia32_compare_nodes_attr(a, b))
1136 attr_a = get_ia32_climbframe_attr_const(a);
1137 attr_b = get_ia32_climbframe_attr_const(b);
1139 if (attr_a->count != attr_b->count)
1145 /* copies the ia32 attributes */
1146 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1149 struct obstack *obst = get_irg_obstack(irg);
1150 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1151 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1152 backend_info_t *old_info = be_get_info(old_node);
1153 backend_info_t *new_info = be_get_info(new_node);
1155 /* copy the attributes */
1156 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1158 /* copy out flags */
1159 new_info->out_infos =
1160 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1163 /* Include the generated constructor functions */
1164 #include "gen_ia32_new_nodes.c.inl"