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 * Dumps the register requirements for either in or out.
72 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
74 char *dir = inout ? "out" : "in";
75 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
79 memset(buf, 0, sizeof(buf));
82 for (i = 0; i < max; i++) {
83 fprintf(F, "%sreq #%d =", dir, i);
84 arch_dump_register_req(F, reqs[i], n);
91 fprintf(F, "%sreq = N/A\n", dir);
96 * Dumper interface for dumping ia32 nodes in vcg.
97 * @param n the node to dump
98 * @param F the output file
99 * @param reason indicates which kind of information should be dumped
100 * @return 0 on success or != 0 on failure
102 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
103 ir_mode *mode = NULL;
106 const arch_register_req_t **reqs;
109 case dump_node_opcode_txt:
110 fprintf(F, "%s", get_irn_opname(n));
112 if(is_ia32_Immediate(n) || is_ia32_Const(n)) {
113 const ia32_immediate_attr_t *attr
114 = get_ia32_immediate_attr_const(n);
121 fputs(get_entity_name(attr->symconst), F);
123 if(attr->offset != 0 || attr->symconst == NULL) {
124 if(attr->offset > 0 && attr->symconst != NULL) {
127 fprintf(F, "%ld", attr->offset);
128 if (attr->no_pic_adjust) {
129 fputs("(no_pic_adjust)", F);
134 const ia32_attr_t *attr = get_ia32_attr_const(n);
136 if(attr->am_sc != NULL || attr->am_offs != 0)
139 if(attr->am_sc != NULL) {
140 if(attr->data.am_sc_sign) {
143 fputs(get_entity_name(attr->am_sc), F);
144 if(attr->data.am_sc_no_pic_adjust) {
145 fputs("(no_pic_adjust)", F);
148 if(attr->am_offs != 0) {
149 if(attr->am_offs > 0 && attr->am_sc != NULL) {
152 fprintf(F, "%d", attr->am_offs);
155 if(attr->am_sc != NULL || attr->am_offs != 0)
160 case dump_node_mode_txt:
161 mode = get_ia32_ls_mode(n);
163 fprintf(F, "[%s]", get_mode_name(mode));
166 case dump_node_nodeattr_txt:
167 if (! is_ia32_Lea(n)) {
168 if (is_ia32_AddrModeS(n)) {
169 fprintf(F, "[AM S] ");
170 } else if (is_ia32_AddrModeD(n)) {
171 fprintf(F, "[AM D] ");
177 case dump_node_info_txt:
178 fprintf(F, "=== IA32 attr begin ===\n");
180 /* dump IN requirements */
181 if (get_irn_arity(n) > 0) {
182 reqs = get_ia32_in_req_all(n);
183 dump_reg_req(F, n, reqs, 0);
186 n_res = arch_irn_get_n_outs(n);
188 /* dump OUT requirements */
189 reqs = get_ia32_out_req_all(n);
190 dump_reg_req(F, n, reqs, 1);
192 /* dump assigned registers */
193 for (i = 0; i < n_res; i++) {
194 const arch_register_t *reg = arch_irn_get_register(n, i);
196 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
203 switch (get_ia32_op_type(n)) {
205 fprintf(F, "Normal");
208 fprintf(F, "AM Dest (Load+Store)");
211 fprintf(F, "AM Source (Load)");
214 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
219 /* dump supported am */
220 fprintf(F, "AM support = ");
221 switch (get_ia32_am_support(n)) {
222 case ia32_am_none: fputs("none\n", F); break;
223 case ia32_am_unary: fputs("source (unary)\n", F); break;
224 case ia32_am_binary: fputs("source (binary)\n", F); break;
227 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
232 if(get_ia32_am_offs_int(n) != 0) {
233 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
236 /* dump AM symconst */
237 if(get_ia32_am_sc(n) != NULL) {
238 ir_entity *ent = get_ia32_am_sc(n);
239 ident *id = get_entity_ld_ident(ent);
240 fprintf(F, "AM symconst = %s\n", get_id_str(id));
244 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
247 if (is_ia32_SwitchJmp(n)) {
248 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
249 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
250 ia32_attr_t *attr = get_ia32_attr(n);
251 long pnc = get_ia32_condcode(n);
252 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
253 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
254 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
256 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
257 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
260 fprintf(F, "n_res = %d\n", n_res);
261 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
262 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
263 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
264 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
265 fprintf(F, "latency = %d\n", get_ia32_latency(n));
268 fprintf(F, "flags =");
269 flags = arch_irn_get_flags(n);
270 if (flags == arch_irn_flags_none) {
274 if (flags & arch_irn_flags_dont_spill) {
275 fprintf(F, " unspillable");
277 if (flags & arch_irn_flags_rematerializable) {
278 fprintf(F, " remat");
280 if (flags & arch_irn_flags_modify_flags) {
281 fprintf(F, " modify_flags");
284 fprintf(F, " (%d)\n", flags);
286 /* dump frame entity */
287 fprintf(F, "frame entity = ");
288 if (get_ia32_frame_ent(n)) {
289 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
297 fprintf(F, "ls_mode = ");
298 if (get_ia32_ls_mode(n)) {
299 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
307 /* dump original ir node name */
308 fprintf(F, "orig node = ");
309 if (get_ia32_orig_node(n)) {
310 fprintf(F, "%s", get_ia32_orig_node(n));
318 fprintf(F, "=== IA32 attr end ===\n");
319 /* end of: case dump_node_info_txt */
328 /***************************************************************************************************
330 * | | | | | | / / | | | | | | | |
331 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
332 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
333 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
334 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
337 ***************************************************************************************************/
339 ia32_attr_t *get_ia32_attr(ir_node *node) {
340 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
341 return (ia32_attr_t *)get_irn_generic_attr(node);
344 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
345 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
346 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
349 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
350 ia32_attr_t *attr = get_ia32_attr(node);
351 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
355 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
356 const ia32_attr_t *attr = get_ia32_attr_const(node);
357 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
361 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
362 const ia32_attr_t *attr = get_ia32_attr_const(node);
363 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
368 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
369 ia32_attr_t *attr = get_ia32_attr(node);
370 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
375 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
377 const ia32_attr_t *attr = get_ia32_attr_const(node);
378 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
383 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
384 ia32_attr_t *attr = get_ia32_attr(node);
385 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
390 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
391 const ia32_attr_t *attr = get_ia32_attr_const(node);
392 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
397 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
399 ia32_attr_t *attr = get_ia32_attr(node);
400 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
405 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
407 const ia32_attr_t *attr = get_ia32_attr_const(node);
408 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
413 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
414 ia32_attr_t *attr = get_ia32_attr(node);
415 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
420 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
421 const ia32_attr_t *attr = get_ia32_attr_const(node);
422 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
427 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node) {
428 ia32_attr_t *attr = get_ia32_attr(node);
429 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
431 return climbframe_attr;
434 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node) {
435 const ia32_attr_t *attr = get_ia32_attr_const(node);
436 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
438 return climbframe_attr;
442 * Gets the type of an ia32 node.
444 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
445 const ia32_attr_t *attr = get_ia32_attr_const(node);
446 return attr->data.tp;
450 * Sets the type of an ia32 node.
452 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
453 ia32_attr_t *attr = get_ia32_attr(node);
457 ia32_am_type_t get_ia32_am_support(const ir_node *node)
459 const ia32_attr_t *attr = get_ia32_attr_const(node);
460 return attr->data.am_arity;
464 * Sets the supported address mode of an ia32 node
466 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
468 ia32_attr_t *attr = get_ia32_attr(node);
469 attr->data.am_arity = arity;
473 * Gets the address mode offset as int.
475 int get_ia32_am_offs_int(const ir_node *node) {
476 const ia32_attr_t *attr = get_ia32_attr_const(node);
477 return attr->am_offs;
481 * Sets the address mode offset from an int.
483 void set_ia32_am_offs_int(ir_node *node, int offset) {
484 ia32_attr_t *attr = get_ia32_attr(node);
485 attr->am_offs = offset;
488 void add_ia32_am_offs_int(ir_node *node, int offset) {
489 ia32_attr_t *attr = get_ia32_attr(node);
490 attr->am_offs += offset;
494 * Returns the symconst entity associated to address mode.
496 ir_entity *get_ia32_am_sc(const ir_node *node) {
497 const ia32_attr_t *attr = get_ia32_attr_const(node);
502 * Sets the symconst entity associated to address mode.
504 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
505 ia32_attr_t *attr = get_ia32_attr(node);
506 attr->am_sc = entity;
510 * Sets the sign bit for address mode symconst.
512 void set_ia32_am_sc_sign(ir_node *node) {
513 ia32_attr_t *attr = get_ia32_attr(node);
514 attr->data.am_sc_sign = 1;
518 * Clears the sign bit for address mode symconst.
520 void clear_ia32_am_sc_sign(ir_node *node) {
521 ia32_attr_t *attr = get_ia32_attr(node);
522 attr->data.am_sc_sign = 0;
526 * Returns the sign bit for address mode symconst.
528 int is_ia32_am_sc_sign(const ir_node *node) {
529 const ia32_attr_t *attr = get_ia32_attr_const(node);
530 return attr->data.am_sc_sign;
534 * Gets the addr mode const.
536 unsigned get_ia32_am_scale(const ir_node *node) {
537 const ia32_attr_t *attr = get_ia32_attr_const(node);
538 return attr->data.am_scale;
542 * Sets the index register scale for address mode.
544 void set_ia32_am_scale(ir_node *node, unsigned scale) {
545 ia32_attr_t *attr = get_ia32_attr(node);
546 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
547 attr->data.am_scale = scale;
550 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
552 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
553 set_ia32_am_scale(to, get_ia32_am_scale(from));
554 set_ia32_am_sc(to, get_ia32_am_sc(from));
555 if(is_ia32_am_sc_sign(from))
556 set_ia32_am_sc_sign(to);
557 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
558 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
559 if (is_ia32_use_frame(from))
560 set_ia32_use_frame(to);
564 * Sets the uses_frame flag.
566 void set_ia32_use_frame(ir_node *node) {
567 ia32_attr_t *attr = get_ia32_attr(node);
568 attr->data.use_frame = 1;
572 * Clears the uses_frame flag.
574 void clear_ia32_use_frame(ir_node *node) {
575 ia32_attr_t *attr = get_ia32_attr(node);
576 attr->data.use_frame = 0;
580 * Gets the uses_frame flag.
582 int is_ia32_use_frame(const ir_node *node) {
583 const ia32_attr_t *attr = get_ia32_attr_const(node);
584 return attr->data.use_frame;
588 * Sets node to commutative.
590 void set_ia32_commutative(ir_node *node) {
591 ia32_attr_t *attr = get_ia32_attr(node);
592 attr->data.is_commutative = 1;
596 * Sets node to non-commutative.
598 void clear_ia32_commutative(ir_node *node) {
599 ia32_attr_t *attr = get_ia32_attr(node);
600 attr->data.is_commutative = 0;
604 * Checks if node is commutative.
606 int is_ia32_commutative(const ir_node *node) {
607 const ia32_attr_t *attr = get_ia32_attr_const(node);
608 return attr->data.is_commutative;
611 void set_ia32_need_stackent(ir_node *node) {
612 ia32_attr_t *attr = get_ia32_attr(node);
613 attr->data.need_stackent = 1;
616 void clear_ia32_need_stackent(ir_node *node) {
617 ia32_attr_t *attr = get_ia32_attr(node);
618 attr->data.need_stackent = 0;
621 int is_ia32_need_stackent(const ir_node *node) {
622 const ia32_attr_t *attr = get_ia32_attr_const(node);
623 return attr->data.need_stackent;
626 void set_ia32_is_reload(ir_node *node) {
627 ia32_attr_t *attr = get_ia32_attr(node);
628 attr->data.is_reload = 1;
631 int is_ia32_is_reload(const ir_node *node) {
632 const ia32_attr_t *attr = get_ia32_attr_const(node);
633 return attr->data.is_reload;
636 void set_ia32_is_spill(ir_node *node) {
637 ia32_attr_t *attr = get_ia32_attr(node);
638 attr->data.is_spill = 1;
641 int is_ia32_is_spill(const ir_node *node) {
642 const ia32_attr_t *attr = get_ia32_attr_const(node);
643 return attr->data.is_spill;
646 void set_ia32_is_remat(ir_node *node) {
647 ia32_attr_t *attr = get_ia32_attr(node);
648 attr->data.is_remat = 1;
651 int is_ia32_is_remat(const ir_node *node) {
652 const ia32_attr_t *attr = get_ia32_attr_const(node);
653 return attr->data.is_remat;
657 * Gets the mode of the stored/loaded value (only set for Store/Load)
659 ir_mode *get_ia32_ls_mode(const ir_node *node) {
660 const ia32_attr_t *attr = get_ia32_attr_const(node);
661 return attr->ls_mode;
665 * Sets the mode of the stored/loaded value (only set for Store/Load)
667 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
668 ia32_attr_t *attr = get_ia32_attr(node);
669 attr->ls_mode = mode;
673 * Gets the frame entity assigned to this node.
675 ir_entity *get_ia32_frame_ent(const ir_node *node) {
676 const ia32_attr_t *attr = get_ia32_attr_const(node);
677 return attr->frame_ent;
681 * Sets the frame entity for this node.
683 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
684 ia32_attr_t *attr = get_ia32_attr(node);
685 attr->frame_ent = ent;
687 set_ia32_use_frame(node);
689 clear_ia32_use_frame(node);
694 * Gets the instruction latency.
696 unsigned get_ia32_latency(const ir_node *node) {
697 const ir_op *op = get_irn_op(node);
698 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
699 return op_attr->latency;
703 * Returns the argument register requirements of an ia32 node.
705 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
706 const ia32_attr_t *attr = get_ia32_attr_const(node);
711 * Sets the argument register requirements of an ia32 node.
713 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
714 ia32_attr_t *attr = get_ia32_attr(node);
719 * Returns the result register requirements of an ia32 node.
721 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
722 const ia32_attr_t *attr = get_ia32_attr_const(node);
723 return attr->out_req;
727 * Sets the result register requirements of an ia32 node.
729 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
730 ia32_attr_t *attr = get_ia32_attr(node);
731 attr->out_req = reqs;
735 * Returns the argument register requirement at position pos of an ia32 node.
737 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
738 const ia32_attr_t *attr = get_ia32_attr_const(node);
739 if(attr->in_req == NULL)
740 return arch_no_register_req;
742 return attr->in_req[pos];
746 * Returns the result register requirement at position pos of an ia32 node.
748 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
749 const ia32_attr_t *attr = get_ia32_attr_const(node);
750 if(attr->out_req == NULL)
751 return arch_no_register_req;
753 return attr->out_req[pos];
757 * Sets the OUT register requirements at position pos.
759 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
760 ia32_attr_t *attr = get_ia32_attr(node);
761 attr->out_req[pos] = req;
765 * Sets the IN register requirements at position pos.
767 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
768 ia32_attr_t *attr = get_ia32_attr(node);
769 attr->in_req[pos] = req;
773 * Returns the condition code of a node.
775 long get_ia32_condcode(const ir_node *node)
777 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
778 return attr->pn_code;
782 * Sets the condition code of a node
784 void set_ia32_condcode(ir_node *node, long code)
786 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
787 attr->pn_code = code;
791 * Returns the condition code of a node.
793 unsigned get_ia32_copyb_size(const ir_node *node)
795 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
800 * Get the list of available execution units.
802 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
803 const ia32_attr_t *attr = get_ia32_attr_const(node);
804 return attr->exec_units;
808 * Get the exception label attribute.
810 unsigned get_ia32_exc_label(const ir_node *node) {
811 const ia32_attr_t *attr = get_ia32_attr_const(node);
812 return attr->data.has_except_label;
816 * Set the exception label attribute.
818 void set_ia32_exc_label(ir_node *node, unsigned flag) {
819 ia32_attr_t *attr = get_ia32_attr(node);
820 attr->data.has_except_label = flag;
824 * Return the exception label id.
826 ir_label_t get_ia32_exc_label_id(const ir_node *node) {
827 const ia32_attr_t *attr = get_ia32_attr_const(node);
829 assert(attr->data.has_except_label);
830 return attr->exc_label;
834 * Assign the exception label id.
836 void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
837 ia32_attr_t *attr = get_ia32_attr(node);
839 assert(attr->data.has_except_label);
840 attr->exc_label = id;
846 * Returns the name of the original ir node.
848 const char *get_ia32_orig_node(const ir_node *node)
850 const ia32_attr_t *attr = get_ia32_attr_const(node);
851 return attr->orig_node;
854 static const char *ia32_get_old_node_name(const ir_node *irn)
856 struct obstack *obst = env_cg->isa->name_obst;
858 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
859 obstack_1grow(obst, 0);
860 return obstack_finish(obst);
864 * Sets the name of the original ir node.
866 void set_ia32_orig_node(ir_node *node, const ir_node *old)
868 const char *name = ia32_get_old_node_name(old);
869 ia32_attr_t *attr = get_ia32_attr(node);
870 attr->orig_node = name;
875 /******************************************************************************************************
877 * (_) | | | | | | / _| | | (_)
878 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
879 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
880 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
881 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
884 ******************************************************************************************************/
887 * Returns whether or not the node is an AddrModeS node.
889 int is_ia32_AddrModeS(const ir_node *node) {
890 const ia32_attr_t *attr = get_ia32_attr_const(node);
891 return (attr->data.tp == ia32_AddrModeS);
895 * Returns whether or not the node is an AddrModeD node.
897 int is_ia32_AddrModeD(const ir_node *node) {
898 const ia32_attr_t *attr = get_ia32_attr_const(node);
899 return (attr->data.tp == ia32_AddrModeD);
902 void ia32_swap_left_right(ir_node *node)
904 ia32_attr_t *attr = get_ia32_attr(node);
905 ir_node *left = get_irn_n(node, n_ia32_binary_left);
906 ir_node *right = get_irn_n(node, n_ia32_binary_right);
908 assert(is_ia32_commutative(node));
909 attr->data.ins_permuted = !attr->data.ins_permuted;
910 set_irn_n(node, n_ia32_binary_left, right);
911 set_irn_n(node, n_ia32_binary_right, left);
915 * Initializes the nodes attributes.
917 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
918 const arch_register_req_t **in_reqs,
919 const arch_register_req_t **out_reqs,
920 const be_execution_unit_t ***execution_units,
923 ir_graph *irg = get_irn_irg(node);
924 struct obstack *obst = get_irg_obstack(irg);
925 ia32_attr_t *attr = get_ia32_attr(node);
926 backend_info_t *info;
928 arch_irn_set_flags(node, flags);
929 set_ia32_in_req_all(node, in_reqs);
930 set_ia32_out_req_all(node, out_reqs);
932 attr->exec_units = execution_units;
934 attr->attr_type |= IA32_ATTR_ia32_attr_t;
937 info = be_get_info(node);
938 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
939 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
943 init_ia32_x87_attributes(ir_node *res)
946 ia32_attr_t *attr = get_ia32_attr(res);
947 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
951 ia32_current_cg->do_x87_sim = 1;
955 init_ia32_asm_attributes(ir_node *res)
958 ia32_attr_t *attr = get_ia32_attr(res);
959 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
966 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
967 int symconst_sign, int no_pic_adjust,
970 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
973 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
975 attr->symconst = symconst;
976 attr->sc_sign = symconst_sign;
977 attr->no_pic_adjust = no_pic_adjust;
978 attr->offset = offset;
981 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
983 ia32_call_attr_t *attr = get_irn_generic_attr(res);
986 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
989 attr->call_tp = call_tp;
993 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
994 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
997 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
1003 init_ia32_condcode_attributes(ir_node *res, long pnc) {
1004 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
1007 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
1009 attr->pn_code = pnc;
1013 init_ia32_climbframe_attributes(ir_node *res, unsigned count) {
1014 ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
1017 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
1019 attr->count = count;
1022 /***************************************************************************************
1025 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1026 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1027 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1028 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1030 ***************************************************************************************/
1032 /* default compare operation to compare attributes */
1033 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
1035 if (a->data.tp != b->data.tp)
1038 if (a->data.am_scale != b->data.am_scale
1039 || a->data.am_sc_sign != b->data.am_sc_sign
1040 || a->am_offs != b->am_offs
1041 || a->am_sc != b->am_sc
1042 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
1043 || a->ls_mode != b->ls_mode)
1046 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1047 * unsigned int -> double conversions */
1048 if(a->data.use_frame && a->frame_ent == NULL)
1050 if(b->data.use_frame && b->frame_ent == NULL)
1053 if (a->data.use_frame != b->data.use_frame
1054 || a->frame_ent != b->frame_ent)
1057 if (a->data.has_except_label != b->data.has_except_label)
1060 if (a->data.ins_permuted != b->data.ins_permuted
1061 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1067 /** Compare nodes attributes for all "normal" nodes. */
1069 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1071 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1072 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1074 return ia32_compare_attr(attr_a, attr_b);
1077 /** Compare node attributes for nodes with condition code. */
1079 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1081 const ia32_condcode_attr_t *attr_a;
1082 const ia32_condcode_attr_t *attr_b;
1084 if (ia32_compare_nodes_attr(a, b))
1087 attr_a = get_ia32_condcode_attr_const(a);
1088 attr_b = get_ia32_condcode_attr_const(b);
1090 if (attr_a->pn_code != attr_b->pn_code)
1096 /** Compare node attributes for call nodes. */
1097 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1099 const ia32_call_attr_t *attr_a;
1100 const ia32_call_attr_t *attr_b;
1102 if (ia32_compare_nodes_attr(a, b))
1105 attr_a = get_ia32_call_attr_const(a);
1106 attr_b = get_ia32_call_attr_const(b);
1108 if (attr_a->pop != attr_b->pop)
1111 if (attr_a->call_tp != attr_b->call_tp)
1117 /** Compare node attributes for CopyB nodes. */
1119 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1121 const ia32_copyb_attr_t *attr_a;
1122 const ia32_copyb_attr_t *attr_b;
1124 if (ia32_compare_nodes_attr(a, b))
1127 attr_a = get_ia32_copyb_attr_const(a);
1128 attr_b = get_ia32_copyb_attr_const(b);
1130 if (attr_a->size != attr_b->size)
1137 /** Compare ASM node attributes. */
1139 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1141 const ia32_asm_attr_t *attr_a;
1142 const ia32_asm_attr_t *attr_b;
1144 if (ia32_compare_nodes_attr(a, b))
1147 attr_a = get_ia32_asm_attr_const(a);
1148 attr_b = get_ia32_asm_attr_const(b);
1150 if(attr_a->asm_text != attr_b->asm_text)
1157 * Hash function for Immediates
1159 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1160 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1162 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1165 /** Compare node attributes for Immediates. */
1167 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1169 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1170 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1172 if (attr_a->symconst != attr_b->symconst
1173 || attr_a->sc_sign != attr_b->sc_sign
1174 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1175 || attr_a->offset != attr_b->offset) {
1182 /** Compare node attributes for x87 nodes. */
1184 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1186 return ia32_compare_nodes_attr(a, b);
1189 /** Compare node attributes for ClimbFrame nodes. */
1191 int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
1193 const ia32_climbframe_attr_t *attr_a;
1194 const ia32_climbframe_attr_t *attr_b;
1196 if (ia32_compare_nodes_attr(a, b))
1199 attr_a = get_ia32_climbframe_attr_const(a);
1200 attr_b = get_ia32_climbframe_attr_const(b);
1202 if (attr_a->count != attr_b->count)
1208 /* copies the ia32 attributes */
1209 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1211 ir_graph *irg = get_irn_irg(new_node);
1212 struct obstack *obst = get_irg_obstack(irg);
1213 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1214 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1215 backend_info_t *old_info = be_get_info(old_node);
1216 backend_info_t *new_info = be_get_info(new_node);
1218 /* copy the attributes */
1219 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1221 /* copy out flags */
1222 new_info->out_infos =
1223 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1226 /* Include the generated constructor functions */
1227 #include "gen_ia32_new_nodes.c.inl"