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 int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason)
82 case dump_node_opcode_txt:
83 fprintf(F, "%s", get_irn_opname(n));
85 if (is_ia32_Immediate(n) || is_ia32_Const(n)) {
86 const ia32_immediate_attr_t *attr
87 = get_ia32_immediate_attr_const(n);
94 fputs(get_entity_name(attr->symconst), F);
96 if (attr->offset != 0 || attr->symconst == NULL) {
97 if (attr->offset > 0 && attr->symconst != NULL) {
100 fprintf(F, "%ld", attr->offset);
101 if (attr->no_pic_adjust) {
102 fputs("(no_pic_adjust)", F);
107 const ia32_attr_t *attr = get_ia32_attr_const(n);
109 if (attr->am_sc != NULL || attr->am_offs != 0)
112 if (attr->am_sc != NULL) {
113 if (attr->data.am_sc_sign) {
116 fputs(get_entity_name(attr->am_sc), F);
117 if (attr->data.am_sc_no_pic_adjust) {
118 fputs("(no_pic_adjust)", F);
121 if (attr->am_offs != 0) {
122 if (attr->am_offs > 0 && attr->am_sc != NULL) {
125 fprintf(F, "%d", attr->am_offs);
128 if (attr->am_sc != NULL || attr->am_offs != 0)
133 case dump_node_mode_txt:
134 mode = get_ia32_ls_mode(n);
136 fprintf(F, "[%s]", get_mode_name(mode));
139 case dump_node_nodeattr_txt:
140 if (! is_ia32_Lea(n)) {
141 if (is_ia32_AddrModeS(n)) {
142 fprintf(F, "[AM S] ");
143 } else if (is_ia32_AddrModeD(n)) {
144 fprintf(F, "[AM D] ");
150 case dump_node_info_txt:
151 arch_dump_reqs_and_registers(F, n);
155 switch (get_ia32_op_type(n)) {
157 fprintf(F, "Normal");
160 fprintf(F, "AM Dest (Load+Store)");
163 fprintf(F, "AM Source (Load)");
166 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
171 /* dump supported am */
172 fprintf(F, "AM support = ");
173 switch (get_ia32_am_support(n)) {
174 case ia32_am_none: fputs("none\n", F); break;
175 case ia32_am_unary: fputs("source (unary)\n", F); break;
176 case ia32_am_binary: fputs("source (binary)\n", F); break;
179 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
184 if (get_ia32_am_offs_int(n) != 0) {
185 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
188 /* dump AM symconst */
189 if (get_ia32_am_sc(n) != NULL) {
190 ir_entity *ent = get_ia32_am_sc(n);
191 ident *id = get_entity_ld_ident(ent);
192 fprintf(F, "AM symconst = %s\n", get_id_str(id));
196 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
199 if (is_ia32_SwitchJmp(n)) {
200 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
201 } else if (is_ia32_CMovcc(n) || is_ia32_Setcc(n) || is_ia32_Jcc(n)) {
202 ia32_attr_t *attr = get_ia32_attr(n);
203 long pnc = get_ia32_condcode(n);
204 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, 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 = %d\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));
258 /***************************************************************************************************
260 * | | | | | | / / | | | | | | | |
261 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
262 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
263 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
264 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
267 ***************************************************************************************************/
269 ia32_attr_t *get_ia32_attr(ir_node *node)
271 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
272 return (ia32_attr_t *)get_irn_generic_attr(node);
275 const ia32_attr_t *get_ia32_attr_const(const ir_node *node)
277 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
278 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
281 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node)
283 ia32_attr_t *attr = get_ia32_attr(node);
284 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
288 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node)
290 const ia32_attr_t *attr = get_ia32_attr_const(node);
291 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
295 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node)
297 const ia32_attr_t *attr = get_ia32_attr_const(node);
298 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
303 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node)
305 ia32_attr_t *attr = get_ia32_attr(node);
306 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
311 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
313 const ia32_attr_t *attr = get_ia32_attr_const(node);
314 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
319 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node)
321 ia32_attr_t *attr = get_ia32_attr(node);
322 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
327 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node)
329 const ia32_attr_t *attr = get_ia32_attr_const(node);
330 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
335 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
337 ia32_attr_t *attr = get_ia32_attr(node);
338 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
343 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
345 const ia32_attr_t *attr = get_ia32_attr_const(node);
346 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
351 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node)
353 ia32_attr_t *attr = get_ia32_attr(node);
354 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
359 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node)
361 const ia32_attr_t *attr = get_ia32_attr_const(node);
362 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
367 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node)
369 ia32_attr_t *attr = get_ia32_attr(node);
370 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
372 return climbframe_attr;
375 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node)
377 const ia32_attr_t *attr = get_ia32_attr_const(node);
378 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
380 return climbframe_attr;
384 * Gets the type of an ia32 node.
386 ia32_op_type_t get_ia32_op_type(const ir_node *node)
388 const ia32_attr_t *attr = get_ia32_attr_const(node);
389 return attr->data.tp;
393 * Sets the type of an ia32 node.
395 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp)
397 ia32_attr_t *attr = get_ia32_attr(node);
401 ia32_am_type_t get_ia32_am_support(const ir_node *node)
403 const ia32_attr_t *attr = get_ia32_attr_const(node);
404 return attr->data.am_arity;
408 * Sets the supported address mode of an ia32 node
410 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
412 ia32_attr_t *attr = get_ia32_attr(node);
413 attr->data.am_arity = arity;
417 * Gets the address mode offset as int.
419 int get_ia32_am_offs_int(const ir_node *node)
421 const ia32_attr_t *attr = get_ia32_attr_const(node);
422 return attr->am_offs;
426 * Sets the address mode offset from an int.
428 void set_ia32_am_offs_int(ir_node *node, int offset)
430 ia32_attr_t *attr = get_ia32_attr(node);
431 attr->am_offs = offset;
434 void add_ia32_am_offs_int(ir_node *node, int offset)
436 ia32_attr_t *attr = get_ia32_attr(node);
437 attr->am_offs += offset;
441 * Returns the symconst entity associated to address mode.
443 ir_entity *get_ia32_am_sc(const ir_node *node)
445 const ia32_attr_t *attr = get_ia32_attr_const(node);
450 * Sets the symconst entity associated to address mode.
452 void set_ia32_am_sc(ir_node *node, ir_entity *entity)
454 ia32_attr_t *attr = get_ia32_attr(node);
455 attr->am_sc = entity;
459 * Sets the sign bit for address mode symconst.
461 void set_ia32_am_sc_sign(ir_node *node)
463 ia32_attr_t *attr = get_ia32_attr(node);
464 attr->data.am_sc_sign = 1;
468 * Clears the sign bit for address mode symconst.
470 void clear_ia32_am_sc_sign(ir_node *node)
472 ia32_attr_t *attr = get_ia32_attr(node);
473 attr->data.am_sc_sign = 0;
477 * Returns the sign bit for address mode symconst.
479 int is_ia32_am_sc_sign(const ir_node *node)
481 const ia32_attr_t *attr = get_ia32_attr_const(node);
482 return attr->data.am_sc_sign;
486 * Gets the addr mode const.
488 unsigned get_ia32_am_scale(const ir_node *node)
490 const ia32_attr_t *attr = get_ia32_attr_const(node);
491 return attr->data.am_scale;
495 * Sets the index register scale for address mode.
497 void set_ia32_am_scale(ir_node *node, unsigned scale)
499 ia32_attr_t *attr = get_ia32_attr(node);
500 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
501 attr->data.am_scale = scale;
504 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
506 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
507 set_ia32_am_scale(to, get_ia32_am_scale(from));
508 set_ia32_am_sc(to, get_ia32_am_sc(from));
509 if (is_ia32_am_sc_sign(from))
510 set_ia32_am_sc_sign(to);
511 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
512 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
513 if (is_ia32_use_frame(from))
514 set_ia32_use_frame(to);
518 * Sets the uses_frame flag.
520 void set_ia32_use_frame(ir_node *node)
522 ia32_attr_t *attr = get_ia32_attr(node);
523 attr->data.use_frame = 1;
527 * Clears the uses_frame flag.
529 void clear_ia32_use_frame(ir_node *node)
531 ia32_attr_t *attr = get_ia32_attr(node);
532 attr->data.use_frame = 0;
536 * Gets the uses_frame flag.
538 int is_ia32_use_frame(const ir_node *node)
540 const ia32_attr_t *attr = get_ia32_attr_const(node);
541 return attr->data.use_frame;
545 * Sets node to commutative.
547 void set_ia32_commutative(ir_node *node)
549 ia32_attr_t *attr = get_ia32_attr(node);
550 attr->data.is_commutative = 1;
554 * Sets node to non-commutative.
556 void clear_ia32_commutative(ir_node *node)
558 ia32_attr_t *attr = get_ia32_attr(node);
559 attr->data.is_commutative = 0;
563 * Checks if node is commutative.
565 int is_ia32_commutative(const ir_node *node)
567 const ia32_attr_t *attr = get_ia32_attr_const(node);
568 return attr->data.is_commutative;
571 void set_ia32_need_stackent(ir_node *node)
573 ia32_attr_t *attr = get_ia32_attr(node);
574 attr->data.need_stackent = 1;
577 void clear_ia32_need_stackent(ir_node *node)
579 ia32_attr_t *attr = get_ia32_attr(node);
580 attr->data.need_stackent = 0;
583 int is_ia32_need_stackent(const ir_node *node)
585 const ia32_attr_t *attr = get_ia32_attr_const(node);
586 return attr->data.need_stackent;
589 void set_ia32_is_reload(ir_node *node)
591 ia32_attr_t *attr = get_ia32_attr(node);
592 attr->data.is_reload = 1;
595 int is_ia32_is_reload(const ir_node *node)
597 const ia32_attr_t *attr = get_ia32_attr_const(node);
598 return attr->data.is_reload;
601 void set_ia32_is_spill(ir_node *node)
603 ia32_attr_t *attr = get_ia32_attr(node);
604 attr->data.is_spill = 1;
607 int is_ia32_is_spill(const ir_node *node)
609 const ia32_attr_t *attr = get_ia32_attr_const(node);
610 return attr->data.is_spill;
613 void set_ia32_is_remat(ir_node *node)
615 ia32_attr_t *attr = get_ia32_attr(node);
616 attr->data.is_remat = 1;
619 int is_ia32_is_remat(const ir_node *node)
621 const ia32_attr_t *attr = get_ia32_attr_const(node);
622 return attr->data.is_remat;
626 * Gets the mode of the stored/loaded value (only set for Store/Load)
628 ir_mode *get_ia32_ls_mode(const ir_node *node)
630 const ia32_attr_t *attr = get_ia32_attr_const(node);
631 return attr->ls_mode;
635 * Sets the mode of the stored/loaded value (only set for Store/Load)
637 void set_ia32_ls_mode(ir_node *node, ir_mode *mode)
639 ia32_attr_t *attr = get_ia32_attr(node);
640 attr->ls_mode = mode;
644 * Gets the frame entity assigned to this node.
646 ir_entity *get_ia32_frame_ent(const ir_node *node)
648 const ia32_attr_t *attr = get_ia32_attr_const(node);
649 return attr->frame_ent;
653 * Sets the frame entity for this node.
655 void set_ia32_frame_ent(ir_node *node, ir_entity *ent)
657 ia32_attr_t *attr = get_ia32_attr(node);
658 attr->frame_ent = ent;
660 set_ia32_use_frame(node);
662 clear_ia32_use_frame(node);
667 * Gets the instruction latency.
669 unsigned get_ia32_latency(const ir_node *node)
671 const ir_op *op = get_irn_op(node);
672 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
673 return op_attr->latency;
677 * Returns the argument register requirements of an ia32 node.
679 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node)
681 const ia32_attr_t *attr = get_ia32_attr_const(node);
686 * Sets the argument register requirements of an ia32 node.
688 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs)
690 ia32_attr_t *attr = get_ia32_attr(node);
695 * Returns the argument register requirement at position pos of an ia32 node.
697 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos)
699 const ia32_attr_t *attr = get_ia32_attr_const(node);
700 if (attr->in_req == NULL)
701 return arch_no_register_req;
703 return attr->in_req[pos];
707 * Sets the IN register requirements at position pos.
709 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos)
711 ia32_attr_t *attr = get_ia32_attr(node);
712 attr->in_req[pos] = req;
716 * Returns the condition code of a node.
718 long get_ia32_condcode(const ir_node *node)
720 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
721 return attr->pn_code;
725 * Sets the condition code of a node
727 void set_ia32_condcode(ir_node *node, long code)
729 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
730 attr->pn_code = code;
734 * Returns the condition code of a node.
736 unsigned get_ia32_copyb_size(const ir_node *node)
738 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
743 * Get the list of available execution units.
745 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node)
747 const ia32_attr_t *attr = get_ia32_attr_const(node);
748 return attr->exec_units;
752 * Get the exception label attribute.
754 unsigned get_ia32_exc_label(const ir_node *node)
756 const ia32_attr_t *attr = get_ia32_attr_const(node);
757 return attr->data.has_except_label;
761 * Set the exception label attribute.
763 void set_ia32_exc_label(ir_node *node, unsigned flag)
765 ia32_attr_t *attr = get_ia32_attr(node);
766 attr->data.has_except_label = flag;
770 * Return the exception label id.
772 ir_label_t get_ia32_exc_label_id(const ir_node *node)
774 const ia32_attr_t *attr = get_ia32_attr_const(node);
776 assert(attr->data.has_except_label);
777 return attr->exc_label;
781 * Assign the exception label id.
783 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
785 ia32_attr_t *attr = get_ia32_attr(node);
787 assert(attr->data.has_except_label);
788 attr->exc_label = id;
794 * Returns the name of the original ir node.
796 const char *get_ia32_orig_node(const ir_node *node)
798 const ia32_attr_t *attr = get_ia32_attr_const(node);
799 return attr->orig_node;
802 static const char *ia32_get_old_node_name(const ir_node *irn)
804 struct obstack *obst = env_cg->isa->name_obst;
806 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
807 obstack_1grow(obst, 0);
808 return obstack_finish(obst);
812 * Sets the name of the original ir node.
814 void set_ia32_orig_node(ir_node *node, const ir_node *old)
816 const char *name = ia32_get_old_node_name(old);
817 ia32_attr_t *attr = get_ia32_attr(node);
818 attr->orig_node = name;
823 /******************************************************************************************************
825 * (_) | | | | | | / _| | | (_)
826 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
827 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
828 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
829 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
832 ******************************************************************************************************/
835 * Returns whether or not the node is an AddrModeS node.
837 int is_ia32_AddrModeS(const ir_node *node)
839 const ia32_attr_t *attr = get_ia32_attr_const(node);
840 return (attr->data.tp == ia32_AddrModeS);
844 * Returns whether or not the node is an AddrModeD node.
846 int is_ia32_AddrModeD(const ir_node *node)
848 const ia32_attr_t *attr = get_ia32_attr_const(node);
849 return (attr->data.tp == ia32_AddrModeD);
852 void ia32_swap_left_right(ir_node *node)
854 ia32_attr_t *attr = get_ia32_attr(node);
855 ir_node *left = get_irn_n(node, n_ia32_binary_left);
856 ir_node *right = get_irn_n(node, n_ia32_binary_right);
858 assert(is_ia32_commutative(node));
859 attr->data.ins_permuted = !attr->data.ins_permuted;
860 set_irn_n(node, n_ia32_binary_left, right);
861 set_irn_n(node, n_ia32_binary_right, left);
865 * Initializes the nodes attributes.
867 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
868 const arch_register_req_t **in_reqs,
869 const be_execution_unit_t ***execution_units,
872 ir_graph *irg = get_irn_irg(node);
873 struct obstack *obst = get_irg_obstack(irg);
874 ia32_attr_t *attr = get_ia32_attr(node);
875 backend_info_t *info;
877 arch_irn_set_flags(node, flags);
878 set_ia32_in_req_all(node, in_reqs);
880 attr->exec_units = execution_units;
882 attr->attr_type |= IA32_ATTR_ia32_attr_t;
885 info = be_get_info(node);
886 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
887 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
890 void init_ia32_x87_attributes(ir_node *res)
893 ia32_attr_t *attr = get_ia32_attr(res);
894 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
898 ia32_current_cg->do_x87_sim = 1;
901 void init_ia32_asm_attributes(ir_node *res)
904 ia32_attr_t *attr = get_ia32_attr(res);
905 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
911 void init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
912 int symconst_sign, int no_pic_adjust,
915 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
918 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
920 attr->symconst = symconst;
921 attr->sc_sign = symconst_sign;
922 attr->no_pic_adjust = no_pic_adjust;
923 attr->offset = offset;
926 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
928 ia32_call_attr_t *attr = get_irn_generic_attr(res);
931 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
934 attr->call_tp = call_tp;
937 void init_ia32_copyb_attributes(ir_node *res, unsigned size)
939 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
942 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
947 void init_ia32_condcode_attributes(ir_node *res, long pnc)
949 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
952 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
957 void init_ia32_climbframe_attributes(ir_node *res, unsigned count)
959 ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
962 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
967 /***************************************************************************************
970 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
971 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
972 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
973 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
975 ***************************************************************************************/
977 /* default compare operation to compare attributes */
978 static int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
980 if (a->data.tp != b->data.tp)
983 if (a->data.am_scale != b->data.am_scale
984 || a->data.am_sc_sign != b->data.am_sc_sign
985 || a->am_offs != b->am_offs
986 || a->am_sc != b->am_sc
987 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
988 || a->ls_mode != b->ls_mode)
991 /* nodes with not yet assigned entities shouldn't be CSEd (important for
992 * unsigned int -> double conversions */
993 if (a->data.use_frame && a->frame_ent == NULL)
995 if (b->data.use_frame && b->frame_ent == NULL)
998 if (a->data.use_frame != b->data.use_frame
999 || a->frame_ent != b->frame_ent)
1002 if (a->data.has_except_label != b->data.has_except_label)
1005 if (a->data.ins_permuted != b->data.ins_permuted
1006 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1012 /** Compare nodes attributes for all "normal" nodes. */
1013 static int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1015 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1016 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1018 return ia32_compare_attr(attr_a, attr_b);
1021 /** Compare node attributes for nodes with condition code. */
1022 static int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1024 const ia32_condcode_attr_t *attr_a;
1025 const ia32_condcode_attr_t *attr_b;
1027 if (ia32_compare_nodes_attr(a, b))
1030 attr_a = get_ia32_condcode_attr_const(a);
1031 attr_b = get_ia32_condcode_attr_const(b);
1033 if (attr_a->pn_code != attr_b->pn_code)
1039 /** Compare node attributes for call nodes. */
1040 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1042 const ia32_call_attr_t *attr_a;
1043 const ia32_call_attr_t *attr_b;
1045 if (ia32_compare_nodes_attr(a, b))
1048 attr_a = get_ia32_call_attr_const(a);
1049 attr_b = get_ia32_call_attr_const(b);
1051 if (attr_a->pop != attr_b->pop)
1054 if (attr_a->call_tp != attr_b->call_tp)
1060 /** Compare node attributes for CopyB nodes. */
1061 static int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1063 const ia32_copyb_attr_t *attr_a;
1064 const ia32_copyb_attr_t *attr_b;
1066 if (ia32_compare_nodes_attr(a, b))
1069 attr_a = get_ia32_copyb_attr_const(a);
1070 attr_b = get_ia32_copyb_attr_const(b);
1072 if (attr_a->size != attr_b->size)
1079 /** Compare ASM node attributes. */
1080 static int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1082 const ia32_asm_attr_t *attr_a;
1083 const ia32_asm_attr_t *attr_b;
1085 if (ia32_compare_nodes_attr(a, b))
1088 attr_a = get_ia32_asm_attr_const(a);
1089 attr_b = get_ia32_asm_attr_const(b);
1091 if (attr_a->asm_text != attr_b->asm_text)
1098 * Hash function for Immediates
1100 static unsigned ia32_hash_Immediate(const ir_node *irn)
1102 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1104 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1107 /** Compare node attributes for Immediates. */
1108 static int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1110 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1111 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1113 if (attr_a->symconst != attr_b->symconst
1114 || attr_a->sc_sign != attr_b->sc_sign
1115 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1116 || attr_a->offset != attr_b->offset) {
1123 /** Compare node attributes for x87 nodes. */
1124 static int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1126 return ia32_compare_nodes_attr(a, b);
1129 /** Compare node attributes for ClimbFrame nodes. */
1130 static int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
1132 const ia32_climbframe_attr_t *attr_a;
1133 const ia32_climbframe_attr_t *attr_b;
1135 if (ia32_compare_nodes_attr(a, b))
1138 attr_a = get_ia32_climbframe_attr_const(a);
1139 attr_b = get_ia32_climbframe_attr_const(b);
1141 if (attr_a->count != attr_b->count)
1147 /* copies the ia32 attributes */
1148 static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
1151 struct obstack *obst = get_irg_obstack(irg);
1152 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1153 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1154 backend_info_t *old_info = be_get_info(old_node);
1155 backend_info_t *new_info = be_get_info(new_node);
1157 /* copy the attributes */
1158 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1160 /* copy out flags */
1161 new_info->out_infos =
1162 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1165 /* Include the generated constructor functions */
1166 #include "gen_ia32_new_nodes.c.inl"