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);
85 if (reqs[i]->type == arch_register_req_type_none) {
89 if (reqs[i]->type & arch_register_req_type_normal) {
90 fprintf(F, " %s", reqs[i]->cls->name);
93 if (reqs[i]->type & arch_register_req_type_limited) {
95 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
98 if (reqs[i]->type & arch_register_req_type_should_be_same) {
99 unsigned other = reqs[i]->other_same;
102 ir_fprintf(F, " same as");
103 for (i = 0; 1U << i <= other; ++i) {
104 if (other & (1U << i)) {
105 ir_fprintf(F, " %+F", get_irn_n(n, i));
110 if (reqs[i]->type & arch_register_req_type_must_be_different) {
111 unsigned other = reqs[i]->other_different;
114 ir_fprintf(F, " different from");
115 for (i = 0; 1U << i <= other; ++i) {
116 if (other & (1U << i)) {
117 ir_fprintf(F, " %+F", get_irn_n(n, i));
128 fprintf(F, "%sreq = N/A\n", dir);
133 * Dumper interface for dumping ia32 nodes in vcg.
134 * @param n the node to dump
135 * @param F the output file
136 * @param reason indicates which kind of information should be dumped
137 * @return 0 on success or != 0 on failure
139 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
140 ir_mode *mode = NULL;
143 const arch_register_req_t **reqs;
146 case dump_node_opcode_txt:
147 fprintf(F, "%s", get_irn_opname(n));
149 if(is_ia32_Immediate(n) || is_ia32_Const(n)) {
150 const ia32_immediate_attr_t *attr
151 = get_ia32_immediate_attr_const(n);
158 fputs(get_entity_name(attr->symconst), F);
160 if(attr->offset != 0 || attr->symconst == NULL) {
161 if(attr->offset > 0 && attr->symconst != NULL) {
164 fprintf(F, "%ld", attr->offset);
165 if (attr->no_pic_adjust) {
166 fputs("(no_pic_adjust)", F);
171 const ia32_attr_t *attr = get_ia32_attr_const(n);
173 if(attr->am_sc != NULL || attr->am_offs != 0)
176 if(attr->am_sc != NULL) {
177 if(attr->data.am_sc_sign) {
180 fputs(get_entity_name(attr->am_sc), F);
181 if(attr->data.am_sc_no_pic_adjust) {
182 fputs("(no_pic_adjust)", F);
185 if(attr->am_offs != 0) {
186 if(attr->am_offs > 0 && attr->am_sc != NULL) {
189 fprintf(F, "%d", attr->am_offs);
192 if(attr->am_sc != NULL || attr->am_offs != 0)
197 case dump_node_mode_txt:
198 mode = get_ia32_ls_mode(n);
200 fprintf(F, "[%s]", get_mode_name(mode));
203 case dump_node_nodeattr_txt:
204 if (! is_ia32_Lea(n)) {
205 if (is_ia32_AddrModeS(n)) {
206 fprintf(F, "[AM S] ");
207 } else if (is_ia32_AddrModeD(n)) {
208 fprintf(F, "[AM D] ");
214 case dump_node_info_txt:
215 fprintf(F, "=== IA32 attr begin ===\n");
217 /* dump IN requirements */
218 if (get_irn_arity(n) > 0) {
219 reqs = get_ia32_in_req_all(n);
220 dump_reg_req(F, n, reqs, 0);
223 n_res = arch_irn_get_n_outs(n);
225 /* dump OUT requirements */
226 reqs = get_ia32_out_req_all(n);
227 dump_reg_req(F, n, reqs, 1);
229 /* dump assigned registers */
230 for (i = 0; i < n_res; i++) {
231 const arch_register_t *reg = arch_irn_get_register(n, i);
233 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
240 switch (get_ia32_op_type(n)) {
242 fprintf(F, "Normal");
245 fprintf(F, "AM Dest (Load+Store)");
248 fprintf(F, "AM Source (Load)");
251 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
256 /* dump supported am */
257 fprintf(F, "AM support = ");
258 switch (get_ia32_am_support(n)) {
259 case ia32_am_none: fputs("none\n", F); break;
260 case ia32_am_unary: fputs("source (unary)\n", F); break;
261 case ia32_am_binary: fputs("source (binary)\n", F); break;
264 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
269 if(get_ia32_am_offs_int(n) != 0) {
270 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
273 /* dump AM symconst */
274 if(get_ia32_am_sc(n) != NULL) {
275 ir_entity *ent = get_ia32_am_sc(n);
276 ident *id = get_entity_ld_ident(ent);
277 fprintf(F, "AM symconst = %s\n", get_id_str(id));
281 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
284 if (is_ia32_SwitchJmp(n)) {
285 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
286 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
287 ia32_attr_t *attr = get_ia32_attr(n);
288 long pnc = get_ia32_condcode(n);
289 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
290 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
291 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
293 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
294 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
297 fprintf(F, "n_res = %d\n", n_res);
298 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
299 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
300 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
301 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
302 fprintf(F, "latency = %d\n", get_ia32_latency(n));
305 fprintf(F, "flags =");
306 flags = arch_irn_get_flags(n);
307 if (flags == arch_irn_flags_none) {
311 if (flags & arch_irn_flags_dont_spill) {
312 fprintf(F, " unspillable");
314 if (flags & arch_irn_flags_rematerializable) {
315 fprintf(F, " remat");
317 if (flags & arch_irn_flags_modify_flags) {
318 fprintf(F, " modify_flags");
321 fprintf(F, " (%d)\n", flags);
323 /* dump frame entity */
324 fprintf(F, "frame entity = ");
325 if (get_ia32_frame_ent(n)) {
326 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
334 fprintf(F, "ls_mode = ");
335 if (get_ia32_ls_mode(n)) {
336 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
344 /* dump original ir node name */
345 fprintf(F, "orig node = ");
346 if (get_ia32_orig_node(n)) {
347 fprintf(F, "%s", get_ia32_orig_node(n));
355 fprintf(F, "=== IA32 attr end ===\n");
356 /* end of: case dump_node_info_txt */
365 /***************************************************************************************************
367 * | | | | | | / / | | | | | | | |
368 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
369 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
370 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
371 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
374 ***************************************************************************************************/
376 ia32_attr_t *get_ia32_attr(ir_node *node) {
377 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
378 return (ia32_attr_t *)get_irn_generic_attr(node);
381 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
382 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
383 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
386 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
387 ia32_attr_t *attr = get_ia32_attr(node);
388 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
392 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
393 const ia32_attr_t *attr = get_ia32_attr_const(node);
394 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
398 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
399 const ia32_attr_t *attr = get_ia32_attr_const(node);
400 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
405 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
406 ia32_attr_t *attr = get_ia32_attr(node);
407 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
412 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
414 const ia32_attr_t *attr = get_ia32_attr_const(node);
415 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
420 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
421 ia32_attr_t *attr = get_ia32_attr(node);
422 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
427 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
428 const ia32_attr_t *attr = get_ia32_attr_const(node);
429 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
434 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
436 ia32_attr_t *attr = get_ia32_attr(node);
437 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
442 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
444 const ia32_attr_t *attr = get_ia32_attr_const(node);
445 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
450 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
451 ia32_attr_t *attr = get_ia32_attr(node);
452 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
457 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
458 const ia32_attr_t *attr = get_ia32_attr_const(node);
459 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
464 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node) {
465 ia32_attr_t *attr = get_ia32_attr(node);
466 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
468 return climbframe_attr;
471 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node) {
472 const ia32_attr_t *attr = get_ia32_attr_const(node);
473 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
475 return climbframe_attr;
479 * Gets the type of an ia32 node.
481 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
482 const ia32_attr_t *attr = get_ia32_attr_const(node);
483 return attr->data.tp;
487 * Sets the type of an ia32 node.
489 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
490 ia32_attr_t *attr = get_ia32_attr(node);
494 ia32_am_type_t get_ia32_am_support(const ir_node *node)
496 const ia32_attr_t *attr = get_ia32_attr_const(node);
497 return attr->data.am_arity;
501 * Sets the supported address mode of an ia32 node
503 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
505 ia32_attr_t *attr = get_ia32_attr(node);
506 attr->data.am_arity = arity;
510 * Gets the address mode offset as int.
512 int get_ia32_am_offs_int(const ir_node *node) {
513 const ia32_attr_t *attr = get_ia32_attr_const(node);
514 return attr->am_offs;
518 * Sets the address mode offset from an int.
520 void set_ia32_am_offs_int(ir_node *node, int offset) {
521 ia32_attr_t *attr = get_ia32_attr(node);
522 attr->am_offs = offset;
525 void add_ia32_am_offs_int(ir_node *node, int offset) {
526 ia32_attr_t *attr = get_ia32_attr(node);
527 attr->am_offs += offset;
531 * Returns the symconst entity associated to address mode.
533 ir_entity *get_ia32_am_sc(const ir_node *node) {
534 const ia32_attr_t *attr = get_ia32_attr_const(node);
539 * Sets the symconst entity associated to address mode.
541 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
542 ia32_attr_t *attr = get_ia32_attr(node);
543 attr->am_sc = entity;
547 * Sets the sign bit for address mode symconst.
549 void set_ia32_am_sc_sign(ir_node *node) {
550 ia32_attr_t *attr = get_ia32_attr(node);
551 attr->data.am_sc_sign = 1;
555 * Clears the sign bit for address mode symconst.
557 void clear_ia32_am_sc_sign(ir_node *node) {
558 ia32_attr_t *attr = get_ia32_attr(node);
559 attr->data.am_sc_sign = 0;
563 * Returns the sign bit for address mode symconst.
565 int is_ia32_am_sc_sign(const ir_node *node) {
566 const ia32_attr_t *attr = get_ia32_attr_const(node);
567 return attr->data.am_sc_sign;
571 * Gets the addr mode const.
573 unsigned get_ia32_am_scale(const ir_node *node) {
574 const ia32_attr_t *attr = get_ia32_attr_const(node);
575 return attr->data.am_scale;
579 * Sets the index register scale for address mode.
581 void set_ia32_am_scale(ir_node *node, unsigned scale) {
582 ia32_attr_t *attr = get_ia32_attr(node);
583 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
584 attr->data.am_scale = scale;
587 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
589 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
590 set_ia32_am_scale(to, get_ia32_am_scale(from));
591 set_ia32_am_sc(to, get_ia32_am_sc(from));
592 if(is_ia32_am_sc_sign(from))
593 set_ia32_am_sc_sign(to);
594 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
595 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
596 if (is_ia32_use_frame(from))
597 set_ia32_use_frame(to);
601 * Sets the uses_frame flag.
603 void set_ia32_use_frame(ir_node *node) {
604 ia32_attr_t *attr = get_ia32_attr(node);
605 attr->data.use_frame = 1;
609 * Clears the uses_frame flag.
611 void clear_ia32_use_frame(ir_node *node) {
612 ia32_attr_t *attr = get_ia32_attr(node);
613 attr->data.use_frame = 0;
617 * Gets the uses_frame flag.
619 int is_ia32_use_frame(const ir_node *node) {
620 const ia32_attr_t *attr = get_ia32_attr_const(node);
621 return attr->data.use_frame;
625 * Sets node to commutative.
627 void set_ia32_commutative(ir_node *node) {
628 ia32_attr_t *attr = get_ia32_attr(node);
629 attr->data.is_commutative = 1;
633 * Sets node to non-commutative.
635 void clear_ia32_commutative(ir_node *node) {
636 ia32_attr_t *attr = get_ia32_attr(node);
637 attr->data.is_commutative = 0;
641 * Checks if node is commutative.
643 int is_ia32_commutative(const ir_node *node) {
644 const ia32_attr_t *attr = get_ia32_attr_const(node);
645 return attr->data.is_commutative;
648 void set_ia32_need_stackent(ir_node *node) {
649 ia32_attr_t *attr = get_ia32_attr(node);
650 attr->data.need_stackent = 1;
653 void clear_ia32_need_stackent(ir_node *node) {
654 ia32_attr_t *attr = get_ia32_attr(node);
655 attr->data.need_stackent = 0;
658 int is_ia32_need_stackent(const ir_node *node) {
659 const ia32_attr_t *attr = get_ia32_attr_const(node);
660 return attr->data.need_stackent;
663 void set_ia32_is_reload(ir_node *node) {
664 ia32_attr_t *attr = get_ia32_attr(node);
665 attr->data.is_reload = 1;
668 int is_ia32_is_reload(const ir_node *node) {
669 const ia32_attr_t *attr = get_ia32_attr_const(node);
670 return attr->data.is_reload;
673 void set_ia32_is_spill(ir_node *node) {
674 ia32_attr_t *attr = get_ia32_attr(node);
675 attr->data.is_spill = 1;
678 int is_ia32_is_spill(const ir_node *node) {
679 const ia32_attr_t *attr = get_ia32_attr_const(node);
680 return attr->data.is_spill;
683 void set_ia32_is_remat(ir_node *node) {
684 ia32_attr_t *attr = get_ia32_attr(node);
685 attr->data.is_remat = 1;
688 int is_ia32_is_remat(const ir_node *node) {
689 const ia32_attr_t *attr = get_ia32_attr_const(node);
690 return attr->data.is_remat;
694 * Gets the mode of the stored/loaded value (only set for Store/Load)
696 ir_mode *get_ia32_ls_mode(const ir_node *node) {
697 const ia32_attr_t *attr = get_ia32_attr_const(node);
698 return attr->ls_mode;
702 * Sets the mode of the stored/loaded value (only set for Store/Load)
704 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
705 ia32_attr_t *attr = get_ia32_attr(node);
706 attr->ls_mode = mode;
710 * Gets the frame entity assigned to this node.
712 ir_entity *get_ia32_frame_ent(const ir_node *node) {
713 const ia32_attr_t *attr = get_ia32_attr_const(node);
714 return attr->frame_ent;
718 * Sets the frame entity for this node.
720 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
721 ia32_attr_t *attr = get_ia32_attr(node);
722 attr->frame_ent = ent;
724 set_ia32_use_frame(node);
726 clear_ia32_use_frame(node);
731 * Gets the instruction latency.
733 unsigned get_ia32_latency(const ir_node *node) {
734 const ir_op *op = get_irn_op(node);
735 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
736 return op_attr->latency;
740 * Returns the argument register requirements of an ia32 node.
742 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
743 const ia32_attr_t *attr = get_ia32_attr_const(node);
748 * Sets the argument register requirements of an ia32 node.
750 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
751 ia32_attr_t *attr = get_ia32_attr(node);
756 * Returns the result register requirements of an ia32 node.
758 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
759 const ia32_attr_t *attr = get_ia32_attr_const(node);
760 return attr->out_req;
764 * Sets the result register requirements of an ia32 node.
766 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
767 ia32_attr_t *attr = get_ia32_attr(node);
768 attr->out_req = reqs;
772 * Returns the argument register requirement at position pos of an ia32 node.
774 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
775 const ia32_attr_t *attr = get_ia32_attr_const(node);
776 if(attr->in_req == NULL)
777 return arch_no_register_req;
779 return attr->in_req[pos];
783 * Returns the result register requirement at position pos of an ia32 node.
785 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
786 const ia32_attr_t *attr = get_ia32_attr_const(node);
787 if(attr->out_req == NULL)
788 return arch_no_register_req;
790 return attr->out_req[pos];
794 * Sets the OUT register requirements at position pos.
796 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
797 ia32_attr_t *attr = get_ia32_attr(node);
798 attr->out_req[pos] = req;
802 * Sets the IN register requirements at position pos.
804 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
805 ia32_attr_t *attr = get_ia32_attr(node);
806 attr->in_req[pos] = req;
810 * Returns the condition code of a node.
812 long get_ia32_condcode(const ir_node *node)
814 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
815 return attr->pn_code;
819 * Sets the condition code of a node
821 void set_ia32_condcode(ir_node *node, long code)
823 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
824 attr->pn_code = code;
828 * Returns the condition code of a node.
830 unsigned get_ia32_copyb_size(const ir_node *node)
832 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
837 * Get the list of available execution units.
839 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
840 const ia32_attr_t *attr = get_ia32_attr_const(node);
841 return attr->exec_units;
845 * Get the exception label attribute.
847 unsigned get_ia32_exc_label(const ir_node *node) {
848 const ia32_attr_t *attr = get_ia32_attr_const(node);
849 return attr->data.has_except_label;
853 * Set the exception label attribute.
855 void set_ia32_exc_label(ir_node *node, unsigned flag) {
856 ia32_attr_t *attr = get_ia32_attr(node);
857 attr->data.has_except_label = flag;
861 * Return the exception label id.
863 ir_label_t get_ia32_exc_label_id(const ir_node *node) {
864 const ia32_attr_t *attr = get_ia32_attr_const(node);
866 assert(attr->data.has_except_label);
867 return attr->exc_label;
871 * Assign the exception label id.
873 void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
874 ia32_attr_t *attr = get_ia32_attr(node);
876 assert(attr->data.has_except_label);
877 attr->exc_label = id;
883 * Returns the name of the original ir node.
885 const char *get_ia32_orig_node(const ir_node *node)
887 const ia32_attr_t *attr = get_ia32_attr_const(node);
888 return attr->orig_node;
891 static const char *ia32_get_old_node_name(const ir_node *irn)
893 struct obstack *obst = env_cg->isa->name_obst;
895 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
896 obstack_1grow(obst, 0);
897 return obstack_finish(obst);
901 * Sets the name of the original ir node.
903 void set_ia32_orig_node(ir_node *node, const ir_node *old)
905 const char *name = ia32_get_old_node_name(old);
906 ia32_attr_t *attr = get_ia32_attr(node);
907 attr->orig_node = name;
912 /******************************************************************************************************
914 * (_) | | | | | | / _| | | (_)
915 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
916 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
917 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
918 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
921 ******************************************************************************************************/
924 * Returns whether or not the node is an AddrModeS node.
926 int is_ia32_AddrModeS(const ir_node *node) {
927 const ia32_attr_t *attr = get_ia32_attr_const(node);
928 return (attr->data.tp == ia32_AddrModeS);
932 * Returns whether or not the node is an AddrModeD node.
934 int is_ia32_AddrModeD(const ir_node *node) {
935 const ia32_attr_t *attr = get_ia32_attr_const(node);
936 return (attr->data.tp == ia32_AddrModeD);
939 void ia32_swap_left_right(ir_node *node)
941 ia32_attr_t *attr = get_ia32_attr(node);
942 ir_node *left = get_irn_n(node, n_ia32_binary_left);
943 ir_node *right = get_irn_n(node, n_ia32_binary_right);
945 assert(is_ia32_commutative(node));
946 attr->data.ins_permuted = !attr->data.ins_permuted;
947 set_irn_n(node, n_ia32_binary_left, right);
948 set_irn_n(node, n_ia32_binary_right, left);
952 * Initializes the nodes attributes.
954 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
955 const arch_register_req_t **in_reqs,
956 const arch_register_req_t **out_reqs,
957 const be_execution_unit_t ***execution_units,
960 ir_graph *irg = get_irn_irg(node);
961 struct obstack *obst = get_irg_obstack(irg);
962 ia32_attr_t *attr = get_ia32_attr(node);
963 backend_info_t *info;
965 arch_irn_set_flags(node, flags);
966 set_ia32_in_req_all(node, in_reqs);
967 set_ia32_out_req_all(node, out_reqs);
969 attr->exec_units = execution_units;
971 attr->attr_type |= IA32_ATTR_ia32_attr_t;
974 info = be_get_info(node);
975 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
976 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
980 init_ia32_x87_attributes(ir_node *res)
983 ia32_attr_t *attr = get_ia32_attr(res);
984 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
988 ia32_current_cg->do_x87_sim = 1;
992 init_ia32_asm_attributes(ir_node *res)
995 ia32_attr_t *attr = get_ia32_attr(res);
996 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
1003 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
1004 int symconst_sign, int no_pic_adjust,
1007 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
1010 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
1012 attr->symconst = symconst;
1013 attr->sc_sign = symconst_sign;
1014 attr->no_pic_adjust = no_pic_adjust;
1015 attr->offset = offset;
1018 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
1020 ia32_call_attr_t *attr = get_irn_generic_attr(res);
1023 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
1026 attr->call_tp = call_tp;
1030 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
1031 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
1034 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
1040 init_ia32_condcode_attributes(ir_node *res, long pnc) {
1041 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
1044 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
1046 attr->pn_code = pnc;
1050 init_ia32_climbframe_attributes(ir_node *res, unsigned count) {
1051 ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
1054 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
1056 attr->count = count;
1059 /***************************************************************************************
1062 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1063 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1064 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1065 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1067 ***************************************************************************************/
1069 /* default compare operation to compare attributes */
1070 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
1072 if (a->data.tp != b->data.tp)
1075 if (a->data.am_scale != b->data.am_scale
1076 || a->data.am_sc_sign != b->data.am_sc_sign
1077 || a->am_offs != b->am_offs
1078 || a->am_sc != b->am_sc
1079 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
1080 || a->ls_mode != b->ls_mode)
1083 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1084 * unsigned int -> double conversions */
1085 if(a->data.use_frame && a->frame_ent == NULL)
1087 if(b->data.use_frame && b->frame_ent == NULL)
1090 if (a->data.use_frame != b->data.use_frame
1091 || a->frame_ent != b->frame_ent)
1094 if (a->data.has_except_label != b->data.has_except_label)
1097 if (a->data.ins_permuted != b->data.ins_permuted
1098 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1104 /** Compare nodes attributes for all "normal" nodes. */
1106 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1108 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1109 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1111 return ia32_compare_attr(attr_a, attr_b);
1114 /** Compare node attributes for nodes with condition code. */
1116 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1118 const ia32_condcode_attr_t *attr_a;
1119 const ia32_condcode_attr_t *attr_b;
1121 if (ia32_compare_nodes_attr(a, b))
1124 attr_a = get_ia32_condcode_attr_const(a);
1125 attr_b = get_ia32_condcode_attr_const(b);
1127 if (attr_a->pn_code != attr_b->pn_code)
1133 /** Compare node attributes for call nodes. */
1134 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1136 const ia32_call_attr_t *attr_a;
1137 const ia32_call_attr_t *attr_b;
1139 if (ia32_compare_nodes_attr(a, b))
1142 attr_a = get_ia32_call_attr_const(a);
1143 attr_b = get_ia32_call_attr_const(b);
1145 if (attr_a->pop != attr_b->pop)
1148 if (attr_a->call_tp != attr_b->call_tp)
1154 /** Compare node attributes for CopyB nodes. */
1156 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1158 const ia32_copyb_attr_t *attr_a;
1159 const ia32_copyb_attr_t *attr_b;
1161 if (ia32_compare_nodes_attr(a, b))
1164 attr_a = get_ia32_copyb_attr_const(a);
1165 attr_b = get_ia32_copyb_attr_const(b);
1167 if (attr_a->size != attr_b->size)
1174 /** Compare ASM node attributes. */
1176 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1178 const ia32_asm_attr_t *attr_a;
1179 const ia32_asm_attr_t *attr_b;
1181 if (ia32_compare_nodes_attr(a, b))
1184 attr_a = get_ia32_asm_attr_const(a);
1185 attr_b = get_ia32_asm_attr_const(b);
1187 if(attr_a->asm_text != attr_b->asm_text)
1194 * Hash function for Immediates
1196 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1197 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1199 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1202 /** Compare node attributes for Immediates. */
1204 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1206 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1207 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1209 if (attr_a->symconst != attr_b->symconst
1210 || attr_a->sc_sign != attr_b->sc_sign
1211 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1212 || attr_a->offset != attr_b->offset) {
1219 /** Compare node attributes for x87 nodes. */
1221 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1223 return ia32_compare_nodes_attr(a, b);
1226 /** Compare node attributes for ClimbFrame nodes. */
1228 int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
1230 const ia32_climbframe_attr_t *attr_a;
1231 const ia32_climbframe_attr_t *attr_b;
1233 if (ia32_compare_nodes_attr(a, b))
1236 attr_a = get_ia32_climbframe_attr_const(a);
1237 attr_b = get_ia32_climbframe_attr_const(b);
1239 if (attr_a->count != attr_b->count)
1245 /* copies the ia32 attributes */
1246 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1248 ir_graph *irg = get_irn_irg(new_node);
1249 struct obstack *obst = get_irg_obstack(irg);
1250 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1251 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1252 backend_info_t *old_info = be_get_info(old_node);
1253 backend_info_t *new_info = be_get_info(new_node);
1255 /* copy the attributes */
1256 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1258 /* copy out flags */
1259 new_info->out_infos =
1260 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1263 /* Include the generated constructor functions */
1264 #include "gen_ia32_new_nodes.c.inl"