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.
34 #include "irgraph_t.h"
40 #include "firm_common_t.h"
45 #include "raw_bitset.h"
48 #include "../bearch_t.h"
49 #include "../beinfo.h"
51 #include "bearch_ia32_t.h"
52 #include "ia32_nodes_attr.h"
53 #include "ia32_new_nodes.h"
54 #include "gen_ia32_regalloc_if.h"
55 #include "gen_ia32_machine.h"
57 /***********************************************************************************
60 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
61 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
62 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
63 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
66 ***********************************************************************************/
69 * Dumps the register requirements for either in or out.
71 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
73 char *dir = inout ? "out" : "in";
74 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
78 memset(buf, 0, sizeof(buf));
81 for (i = 0; i < max; i++) {
82 fprintf(F, "%sreq #%d =", dir, i);
84 if (reqs[i]->type == arch_register_req_type_none) {
88 if (reqs[i]->type & arch_register_req_type_normal) {
89 fprintf(F, " %s", reqs[i]->cls->name);
92 if (reqs[i]->type & arch_register_req_type_limited) {
94 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
97 if (reqs[i]->type & arch_register_req_type_should_be_same) {
98 unsigned other = reqs[i]->other_same;
101 ir_fprintf(F, " same as");
102 for (i = 0; 1U << i <= other; ++i) {
103 if (other & (1U << i)) {
104 ir_fprintf(F, " %+F", get_irn_n(n, i));
109 if (reqs[i]->type & arch_register_req_type_must_be_different) {
110 unsigned other = reqs[i]->other_different;
113 ir_fprintf(F, " different from");
114 for (i = 0; 1U << i <= other; ++i) {
115 if (other & (1U << i)) {
116 ir_fprintf(F, " %+F", get_irn_n(n, i));
127 fprintf(F, "%sreq = N/A\n", dir);
132 * Dumper interface for dumping ia32 nodes in vcg.
133 * @param n the node to dump
134 * @param F the output file
135 * @param reason indicates which kind of information should be dumped
136 * @return 0 on success or != 0 on failure
138 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
139 ir_mode *mode = NULL;
142 const arch_register_req_t **reqs;
145 case dump_node_opcode_txt:
146 fprintf(F, "%s", get_irn_opname(n));
148 if(is_ia32_Immediate(n) || is_ia32_Const(n)) {
149 const ia32_immediate_attr_t *attr
150 = get_ia32_immediate_attr_const(n);
157 fputs(get_entity_name(attr->symconst), F);
159 if(attr->offset != 0 || attr->symconst == NULL) {
160 if(attr->offset > 0 && attr->symconst != NULL) {
163 fprintf(F, "%ld", attr->offset);
167 const ia32_attr_t *attr = get_ia32_attr_const(n);
169 if(attr->am_sc != NULL || attr->am_offs != 0)
172 if(attr->am_sc != NULL) {
173 if(attr->data.am_sc_sign) {
176 fputs(get_entity_name(attr->am_sc), F);
178 if(attr->am_offs != 0) {
179 if(attr->am_offs > 0 && attr->am_sc != NULL) {
182 fprintf(F, "%d", attr->am_offs);
185 if(attr->am_sc != NULL || attr->am_offs != 0)
190 case dump_node_mode_txt:
191 mode = get_ia32_ls_mode(n);
193 fprintf(F, "[%s]", get_mode_name(mode));
196 case dump_node_nodeattr_txt:
197 if (! is_ia32_Lea(n)) {
198 if (is_ia32_AddrModeS(n)) {
199 fprintf(F, "[AM S] ");
200 } else if (is_ia32_AddrModeD(n)) {
201 fprintf(F, "[AM D] ");
207 case dump_node_info_txt:
208 n_res = arch_irn_get_n_outs(n);
209 fprintf(F, "=== IA32 attr begin ===\n");
211 /* dump IN requirements */
212 if (get_irn_arity(n) > 0) {
213 reqs = get_ia32_in_req_all(n);
214 dump_reg_req(F, n, reqs, 0);
217 /* dump OUT requirements */
219 reqs = get_ia32_out_req_all(n);
220 dump_reg_req(F, n, reqs, 1);
223 /* dump assigned registers */
225 for (i = 0; i < n_res; i++) {
226 const arch_register_t *reg = arch_irn_get_register(n, i);
228 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
235 switch (get_ia32_op_type(n)) {
237 fprintf(F, "Normal");
240 fprintf(F, "AM Dest (Load+Store)");
243 fprintf(F, "AM Source (Load)");
246 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
251 /* dump supported am */
252 fprintf(F, "AM support = ");
253 switch (get_ia32_am_support(n)) {
254 case ia32_am_none: fputs("none\n", F); break;
255 case ia32_am_unary: fputs("source (unary)\n", F); break;
256 case ia32_am_binary: fputs("source (binary)\n", F); break;
259 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
264 if(get_ia32_am_offs_int(n) != 0) {
265 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
268 /* dump AM symconst */
269 if(get_ia32_am_sc(n) != NULL) {
270 ir_entity *ent = get_ia32_am_sc(n);
271 ident *id = get_entity_ld_ident(ent);
272 fprintf(F, "AM symconst = %s\n", get_id_str(id));
276 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
279 if (is_ia32_SwitchJmp(n)) {
280 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
281 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
282 ia32_attr_t *attr = get_ia32_attr(n);
283 long pnc = get_ia32_condcode(n);
284 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
285 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
286 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
288 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
289 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
292 fprintf(F, "n_res = %d\n", arch_irn_get_n_outs(n));
293 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
294 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
295 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
296 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
297 fprintf(F, "latency = %d\n", get_ia32_latency(n));
300 fprintf(F, "flags =");
301 flags = arch_irn_get_flags(n);
302 if (flags == arch_irn_flags_none) {
306 if (flags & arch_irn_flags_dont_spill) {
307 fprintf(F, " unspillable");
309 if (flags & arch_irn_flags_rematerializable) {
310 fprintf(F, " remat");
312 if (flags & arch_irn_flags_modify_flags) {
313 fprintf(F, " modify_flags");
316 fprintf(F, " (%d)\n", flags);
318 /* dump frame entity */
319 fprintf(F, "frame entity = ");
320 if (get_ia32_frame_ent(n)) {
321 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
329 fprintf(F, "ls_mode = ");
330 if (get_ia32_ls_mode(n)) {
331 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
339 /* dump original ir node name */
340 fprintf(F, "orig node = ");
341 if (get_ia32_orig_node(n)) {
342 fprintf(F, "%s", get_ia32_orig_node(n));
350 fprintf(F, "=== IA32 attr end ===\n");
351 /* end of: case dump_node_info_txt */
360 /***************************************************************************************************
362 * | | | | | | / / | | | | | | | |
363 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
364 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
365 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
366 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
369 ***************************************************************************************************/
371 ia32_attr_t *get_ia32_attr(ir_node *node) {
372 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
373 return (ia32_attr_t *)get_irn_generic_attr(node);
376 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
377 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
378 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
381 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
382 ia32_attr_t *attr = get_ia32_attr(node);
383 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
387 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
388 const ia32_attr_t *attr = get_ia32_attr_const(node);
389 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
393 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
394 const ia32_attr_t *attr = get_ia32_attr_const(node);
395 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
400 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
401 ia32_attr_t *attr = get_ia32_attr(node);
402 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
407 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
409 const ia32_attr_t *attr = get_ia32_attr_const(node);
410 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
415 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
416 ia32_attr_t *attr = get_ia32_attr(node);
417 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
422 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
423 const ia32_attr_t *attr = get_ia32_attr_const(node);
424 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
429 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
431 ia32_attr_t *attr = get_ia32_attr(node);
432 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
437 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
439 const ia32_attr_t *attr = get_ia32_attr_const(node);
440 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
445 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
446 ia32_attr_t *attr = get_ia32_attr(node);
447 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
452 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
453 const ia32_attr_t *attr = get_ia32_attr_const(node);
454 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
460 * Gets the type of an ia32 node.
462 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
463 const ia32_attr_t *attr = get_ia32_attr_const(node);
464 return attr->data.tp;
468 * Sets the type of an ia32 node.
470 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
471 ia32_attr_t *attr = get_ia32_attr(node);
475 ia32_am_type_t get_ia32_am_support(const ir_node *node)
477 const ia32_attr_t *attr = get_ia32_attr_const(node);
478 return attr->data.am_arity;
482 * Sets the supported address mode of an ia32 node
484 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
486 ia32_attr_t *attr = get_ia32_attr(node);
487 attr->data.am_arity = arity;
491 * Gets the address mode offset as int.
493 int get_ia32_am_offs_int(const ir_node *node) {
494 const ia32_attr_t *attr = get_ia32_attr_const(node);
495 return attr->am_offs;
499 * Sets the address mode offset from an int.
501 void set_ia32_am_offs_int(ir_node *node, int offset) {
502 ia32_attr_t *attr = get_ia32_attr(node);
503 attr->am_offs = offset;
506 void add_ia32_am_offs_int(ir_node *node, int offset) {
507 ia32_attr_t *attr = get_ia32_attr(node);
508 attr->am_offs += offset;
512 * Returns the symconst entity associated to address mode.
514 ir_entity *get_ia32_am_sc(const ir_node *node) {
515 const ia32_attr_t *attr = get_ia32_attr_const(node);
520 * Sets the symconst entity associated to address mode.
522 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
523 ia32_attr_t *attr = get_ia32_attr(node);
524 attr->am_sc = entity;
528 * Sets the sign bit for address mode symconst.
530 void set_ia32_am_sc_sign(ir_node *node) {
531 ia32_attr_t *attr = get_ia32_attr(node);
532 attr->data.am_sc_sign = 1;
536 * Clears the sign bit for address mode symconst.
538 void clear_ia32_am_sc_sign(ir_node *node) {
539 ia32_attr_t *attr = get_ia32_attr(node);
540 attr->data.am_sc_sign = 0;
544 * Returns the sign bit for address mode symconst.
546 int is_ia32_am_sc_sign(const ir_node *node) {
547 const ia32_attr_t *attr = get_ia32_attr_const(node);
548 return attr->data.am_sc_sign;
552 * Gets the addr mode const.
554 int get_ia32_am_scale(const ir_node *node) {
555 const ia32_attr_t *attr = get_ia32_attr_const(node);
556 return attr->data.am_scale;
560 * Sets the index register scale for address mode.
562 void set_ia32_am_scale(ir_node *node, int scale) {
563 ia32_attr_t *attr = get_ia32_attr(node);
564 assert(0 <= scale && scale < 4 && "AM scale out of range");
565 attr->data.am_scale = scale;
568 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
570 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
571 set_ia32_am_scale(to, get_ia32_am_scale(from));
572 set_ia32_am_sc(to, get_ia32_am_sc(from));
573 if(is_ia32_am_sc_sign(from))
574 set_ia32_am_sc_sign(to);
575 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
576 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
577 if (is_ia32_use_frame(from))
578 set_ia32_use_frame(to);
582 * Sets the uses_frame flag.
584 void set_ia32_use_frame(ir_node *node) {
585 ia32_attr_t *attr = get_ia32_attr(node);
586 attr->data.use_frame = 1;
590 * Clears the uses_frame flag.
592 void clear_ia32_use_frame(ir_node *node) {
593 ia32_attr_t *attr = get_ia32_attr(node);
594 attr->data.use_frame = 0;
598 * Gets the uses_frame flag.
600 int is_ia32_use_frame(const ir_node *node) {
601 const ia32_attr_t *attr = get_ia32_attr_const(node);
602 return attr->data.use_frame;
606 * Sets node to commutative.
608 void set_ia32_commutative(ir_node *node) {
609 ia32_attr_t *attr = get_ia32_attr(node);
610 attr->data.is_commutative = 1;
614 * Sets node to non-commutative.
616 void clear_ia32_commutative(ir_node *node) {
617 ia32_attr_t *attr = get_ia32_attr(node);
618 attr->data.is_commutative = 0;
622 * Checks if node is commutative.
624 int is_ia32_commutative(const ir_node *node) {
625 const ia32_attr_t *attr = get_ia32_attr_const(node);
626 return attr->data.is_commutative;
629 void set_ia32_need_stackent(ir_node *node) {
630 ia32_attr_t *attr = get_ia32_attr(node);
631 attr->data.need_stackent = 1;
634 void clear_ia32_need_stackent(ir_node *node) {
635 ia32_attr_t *attr = get_ia32_attr(node);
636 attr->data.need_stackent = 0;
639 int is_ia32_need_stackent(const ir_node *node) {
640 const ia32_attr_t *attr = get_ia32_attr_const(node);
641 return attr->data.need_stackent;
644 void set_ia32_is_reload(ir_node *node) {
645 ia32_attr_t *attr = get_ia32_attr(node);
646 attr->data.is_reload = 1;
649 int is_ia32_is_reload(const ir_node *node) {
650 const ia32_attr_t *attr = get_ia32_attr_const(node);
651 return attr->data.is_reload;
654 void set_ia32_is_spill(ir_node *node) {
655 ia32_attr_t *attr = get_ia32_attr(node);
656 attr->data.is_spill = 1;
659 int is_ia32_is_spill(const ir_node *node) {
660 const ia32_attr_t *attr = get_ia32_attr_const(node);
661 return attr->data.is_spill;
664 void set_ia32_is_remat(ir_node *node) {
665 ia32_attr_t *attr = get_ia32_attr(node);
666 attr->data.is_remat = 1;
669 int is_ia32_is_remat(const ir_node *node) {
670 const ia32_attr_t *attr = get_ia32_attr_const(node);
671 return attr->data.is_remat;
675 * Gets the mode of the stored/loaded value (only set for Store/Load)
677 ir_mode *get_ia32_ls_mode(const ir_node *node) {
678 const ia32_attr_t *attr = get_ia32_attr_const(node);
679 return attr->ls_mode;
683 * Sets the mode of the stored/loaded value (only set for Store/Load)
685 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
686 ia32_attr_t *attr = get_ia32_attr(node);
687 attr->ls_mode = mode;
691 * Gets the frame entity assigned to this node.
693 ir_entity *get_ia32_frame_ent(const ir_node *node) {
694 const ia32_attr_t *attr = get_ia32_attr_const(node);
695 return attr->frame_ent;
699 * Sets the frame entity for this node.
701 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
702 ia32_attr_t *attr = get_ia32_attr(node);
703 attr->frame_ent = ent;
705 set_ia32_use_frame(node);
707 clear_ia32_use_frame(node);
712 * Gets the instruction latency.
714 unsigned get_ia32_latency(const ir_node *node) {
715 const ir_op *op = get_irn_op(node);
716 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
717 return op_attr->latency;
721 * Returns the argument register requirements of an ia32 node.
723 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
724 const ia32_attr_t *attr = get_ia32_attr_const(node);
729 * Sets the argument register requirements of an ia32 node.
731 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
732 ia32_attr_t *attr = get_ia32_attr(node);
737 * Returns the result register requirements of an ia32 node.
739 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
740 const ia32_attr_t *attr = get_ia32_attr_const(node);
741 return attr->out_req;
745 * Sets the result register requirements of an ia32 node.
747 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
748 ia32_attr_t *attr = get_ia32_attr(node);
749 attr->out_req = reqs;
753 * Returns the argument register requirement at position pos of an ia32 node.
755 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
756 const ia32_attr_t *attr = get_ia32_attr_const(node);
757 if(attr->in_req == NULL)
758 return arch_no_register_req;
760 return attr->in_req[pos];
764 * Returns the result register requirement at position pos of an ia32 node.
766 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
767 const ia32_attr_t *attr = get_ia32_attr_const(node);
768 if(attr->out_req == NULL)
769 return arch_no_register_req;
771 return attr->out_req[pos];
775 * Sets the OUT register requirements at position pos.
777 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
778 ia32_attr_t *attr = get_ia32_attr(node);
779 attr->out_req[pos] = req;
783 * Sets the IN register requirements at position pos.
785 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
786 ia32_attr_t *attr = get_ia32_attr(node);
787 attr->in_req[pos] = req;
791 * Returns the condition code of a node.
793 long get_ia32_condcode(const ir_node *node)
795 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
796 return attr->pn_code;
800 * Sets the condition code of a node
802 void set_ia32_condcode(ir_node *node, long code)
804 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
805 attr->pn_code = code;
809 * Returns the condition code of a node.
811 unsigned get_ia32_copyb_size(const ir_node *node)
813 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
818 * Get the list of available execution units.
820 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
821 const ia32_attr_t *attr = get_ia32_attr_const(node);
822 return attr->exec_units;
826 * Get the exception label attribute.
828 unsigned get_ia32_exc_label(const ir_node *node) {
829 const ia32_attr_t *attr = get_ia32_attr_const(node);
830 return attr->data.has_except_label;
834 * Set the exception label attribute.
836 void set_ia32_exc_label(ir_node *node, unsigned flag) {
837 ia32_attr_t *attr = get_ia32_attr(node);
838 attr->data.has_except_label = flag;
842 * Return the exception label id.
844 ir_label_t get_ia32_exc_label_id(const ir_node *node) {
845 const ia32_attr_t *attr = get_ia32_attr_const(node);
847 assert(attr->data.has_except_label);
848 return attr->exc_label;
852 * Assign the exception label id.
854 void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
855 ia32_attr_t *attr = get_ia32_attr(node);
857 assert(attr->data.has_except_label);
858 attr->exc_label = id;
864 * Returns the name of the original ir node.
866 const char *get_ia32_orig_node(const ir_node *node) {
867 const ia32_attr_t *attr = get_ia32_attr_const(node);
868 return attr->orig_node;
872 * Sets the name of the original ir node.
874 void set_ia32_orig_node(ir_node *node, const char *name) {
875 ia32_attr_t *attr = get_ia32_attr(node);
876 attr->orig_node = name;
881 /******************************************************************************************************
883 * (_) | | | | | | / _| | | (_)
884 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
885 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
886 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
887 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
890 ******************************************************************************************************/
893 * Returns whether or not the node is an AddrModeS node.
895 int is_ia32_AddrModeS(const ir_node *node) {
896 const ia32_attr_t *attr = get_ia32_attr_const(node);
897 return (attr->data.tp == ia32_AddrModeS);
901 * Returns whether or not the node is an AddrModeD node.
903 int is_ia32_AddrModeD(const ir_node *node) {
904 const ia32_attr_t *attr = get_ia32_attr_const(node);
905 return (attr->data.tp == ia32_AddrModeD);
908 void ia32_swap_left_right(ir_node *node)
910 ia32_attr_t *attr = get_ia32_attr(node);
911 ir_node *left = get_irn_n(node, n_ia32_binary_left);
912 ir_node *right = get_irn_n(node, n_ia32_binary_right);
914 assert(is_ia32_commutative(node));
915 attr->data.ins_permuted = !attr->data.ins_permuted;
916 set_irn_n(node, n_ia32_binary_left, right);
917 set_irn_n(node, n_ia32_binary_right, left);
921 * Initializes the nodes attributes.
923 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
924 const arch_register_req_t **in_reqs,
925 const arch_register_req_t **out_reqs,
926 const be_execution_unit_t ***execution_units,
929 ir_graph *irg = get_irn_irg(node);
930 struct obstack *obst = get_irg_obstack(irg);
931 ia32_attr_t *attr = get_ia32_attr(node);
932 backend_info_t *info;
934 arch_irn_set_flags(node, flags);
935 set_ia32_in_req_all(node, in_reqs);
936 set_ia32_out_req_all(node, out_reqs);
938 attr->exec_units = execution_units;
940 attr->attr_type |= IA32_ATTR_ia32_attr_t;
943 info = be_get_info(node);
944 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
945 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
949 init_ia32_x87_attributes(ir_node *res)
952 ia32_attr_t *attr = get_ia32_attr(res);
953 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
957 ia32_current_cg->do_x87_sim = 1;
961 init_ia32_asm_attributes(ir_node *res)
964 ia32_attr_t *attr = get_ia32_attr(res);
965 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
972 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
973 int symconst_sign, long offset)
975 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
978 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
980 attr->symconst = symconst;
981 attr->sc_sign = symconst_sign;
982 attr->offset = offset;
985 void init_ia32_call_attributes(ir_node *const res, unsigned const pop, ir_type *const call_tp)
987 ia32_call_attr_t *attr = get_irn_generic_attr(res);
990 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
993 attr->call_tp = call_tp;
997 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
998 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
1001 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
1007 init_ia32_condcode_attributes(ir_node *res, long pnc) {
1008 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
1011 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
1013 attr->pn_code = pnc;
1016 /***************************************************************************************
1019 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1020 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1021 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1022 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1024 ***************************************************************************************/
1026 /* default compare operation to compare attributes */
1027 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
1028 if (a->data.tp != b->data.tp)
1031 if (a->data.am_scale != b->data.am_scale
1032 || a->data.am_sc_sign != b->data.am_sc_sign
1033 || a->am_offs != b->am_offs
1034 || a->am_sc != b->am_sc
1035 || a->ls_mode != b->ls_mode)
1038 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1039 * unsigned int -> double conversions */
1040 if(a->data.use_frame && a->frame_ent == NULL)
1042 if(b->data.use_frame && b->frame_ent == NULL)
1045 if (a->data.use_frame != b->data.use_frame
1046 || a->frame_ent != b->frame_ent)
1049 if (a->data.tp != b->data.tp)
1052 if (a->data.has_except_label != b->data.has_except_label)
1055 if (a->data.ins_permuted != b->data.ins_permuted
1056 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1062 /** Compare nodes attributes for all "normal" nodes. */
1064 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1066 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1067 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1069 return ia32_compare_attr(attr_a, attr_b);
1072 /** Compare node attributes for nodes with condition code. */
1074 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1076 const ia32_condcode_attr_t *attr_a;
1077 const ia32_condcode_attr_t *attr_b;
1079 if (ia32_compare_nodes_attr(a, b))
1082 attr_a = get_ia32_condcode_attr_const(a);
1083 attr_b = get_ia32_condcode_attr_const(b);
1085 if(attr_a->pn_code != attr_b->pn_code)
1091 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1093 const ia32_call_attr_t *attr_a;
1094 const ia32_call_attr_t *attr_b;
1096 if (ia32_compare_nodes_attr(a, b))
1099 attr_a = get_ia32_call_attr_const(a);
1100 attr_b = get_ia32_call_attr_const(b);
1102 if (attr_a->pop != attr_b->pop)
1105 if (attr_a->call_tp != attr_b->call_tp)
1111 /** Compare node attributes for CopyB nodes. */
1113 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1115 const ia32_copyb_attr_t *attr_a;
1116 const ia32_copyb_attr_t *attr_b;
1118 if (ia32_compare_nodes_attr(a, b))
1121 attr_a = get_ia32_copyb_attr_const(a);
1122 attr_b = get_ia32_copyb_attr_const(b);
1124 if(attr_a->size != attr_b->size)
1131 /** Compare ASM node attributes. */
1133 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1135 const ia32_asm_attr_t *attr_a;
1136 const ia32_asm_attr_t *attr_b;
1138 if(ia32_compare_nodes_attr(a, b))
1141 attr_a = get_ia32_asm_attr_const(a);
1142 attr_b = get_ia32_asm_attr_const(b);
1144 if(attr_a->asm_text != attr_b->asm_text)
1151 * Hash function for Immediates
1153 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1154 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1156 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1159 /** Compare node attributes for Immediates. */
1161 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1163 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1164 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1166 if(attr_a->symconst != attr_b->symconst ||
1167 attr_a->sc_sign != attr_b->sc_sign ||
1168 attr_a->offset != attr_b->offset)
1174 /** Compare node attributes for x87 nodes. */
1176 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1178 return ia32_compare_nodes_attr(a, b);
1182 /* copies the ia32 attributes */
1183 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1185 ir_graph *irg = get_irn_irg(new_node);
1186 struct obstack *obst = get_irg_obstack(irg);
1187 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1188 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1189 backend_info_t *old_info = be_get_info(old_node);
1190 backend_info_t *new_info;
1192 new_info = be_get_info(new_node);
1194 /* copy the attributes */
1195 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1197 /* copy out flags */
1198 new_info->out_infos =
1199 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1202 /* Include the generated constructor functions */
1203 #include "gen_ia32_new_nodes.c.inl"