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.
36 #include "irgraph_t.h"
42 #include "firm_common_t.h"
47 #include "raw_bitset.h"
50 #include "../bearch_t.h"
52 #include "bearch_ia32_t.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 ? get_ia32_n_res(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;
144 const arch_register_t **slots;
147 case dump_node_opcode_txt:
148 fprintf(F, "%s", get_irn_opname(n));
150 if(is_ia32_Immediate(n) || is_ia32_Const(n)) {
151 const ia32_immediate_attr_t *attr
152 = get_ia32_immediate_attr_const(n);
159 fputs(get_entity_name(attr->symconst), F);
161 if(attr->offset != 0 || attr->symconst == NULL) {
162 if(attr->offset > 0 && attr->symconst != NULL) {
165 fprintf(F, "%ld", attr->offset);
169 const ia32_attr_t *attr = get_ia32_attr_const(n);
171 if(attr->am_sc != NULL || attr->am_offs != 0)
174 if(attr->am_sc != NULL) {
175 if(attr->data.am_sc_sign) {
178 fputs(get_entity_name(attr->am_sc), F);
180 if(attr->am_offs != 0) {
181 if(attr->am_offs > 0 && attr->am_sc != NULL) {
184 fprintf(F, "%d", attr->am_offs);
187 if(attr->am_sc != NULL || attr->am_offs != 0)
192 case dump_node_mode_txt:
193 if (is_ia32_Ld(n) || is_ia32_St(n)) {
194 mode = get_ia32_ls_mode(n);
195 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
199 case dump_node_nodeattr_txt:
200 if (! is_ia32_Lea(n)) {
201 if (is_ia32_AddrModeS(n)) {
202 fprintf(F, "[AM S] ");
203 } else if (is_ia32_AddrModeD(n)) {
204 fprintf(F, "[AM D] ");
210 case dump_node_info_txt:
211 n_res = get_ia32_n_res(n);
212 fprintf(F, "=== IA32 attr begin ===\n");
214 /* dump IN requirements */
215 if (get_irn_arity(n) > 0) {
216 reqs = get_ia32_in_req_all(n);
217 dump_reg_req(F, n, reqs, 0);
220 /* dump OUT requirements */
222 reqs = get_ia32_out_req_all(n);
223 dump_reg_req(F, n, reqs, 1);
226 /* dump assigned registers */
227 slots = get_ia32_slots(n);
228 if (slots && n_res > 0) {
229 for (i = 0; i < n_res; i++) {
230 const arch_register_t *reg;
234 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
241 switch (get_ia32_op_type(n)) {
243 fprintf(F, "Normal");
246 fprintf(F, "AM Dest (Load+Store)");
249 fprintf(F, "AM Source (Load)");
252 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
257 /* dump supported am */
258 fprintf(F, "AM support = ");
259 switch (get_ia32_am_support(n)) {
260 case ia32_am_none: fputs("none\n", F); break;
261 case ia32_am_unary: fputs("source (unary)\n", F); break;
262 case ia32_am_binary: fputs("source (binary)\n", F); break;
265 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
270 if(get_ia32_am_offs_int(n) != 0) {
271 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
274 /* dump AM symconst */
275 if(get_ia32_am_sc(n) != NULL) {
276 ir_entity *ent = get_ia32_am_sc(n);
277 ident *id = get_entity_ld_ident(ent);
278 fprintf(F, "AM symconst = %s\n", get_id_str(id));
282 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
285 if (is_ia32_SwitchJmp(n)) {
286 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
287 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
288 ia32_attr_t *attr = get_ia32_attr(n);
289 long pnc = get_ia32_condcode(n);
290 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
291 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
292 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
294 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
295 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
298 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
299 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
300 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
301 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
302 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
303 fprintf(F, "latency = %d\n", get_ia32_latency(n));
306 fprintf(F, "flags =");
307 flags = get_ia32_flags(n);
308 if (flags == arch_irn_flags_none) {
312 if (flags & arch_irn_flags_dont_spill) {
313 fprintf(F, " unspillable");
315 if (flags & arch_irn_flags_rematerializable) {
316 fprintf(F, " remat");
318 if (flags & arch_irn_flags_ignore) {
319 fprintf(F, " ignore");
321 if (flags & arch_irn_flags_modify_sp) {
322 fprintf(F, " modify_sp");
324 if (flags & arch_irn_flags_modify_flags) {
325 fprintf(F, " modify_flags");
328 fprintf(F, " (%d)\n", flags);
330 /* dump frame entity */
331 fprintf(F, "frame entity = ");
332 if (get_ia32_frame_ent(n)) {
333 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
341 fprintf(F, "ls_mode = ");
342 if (get_ia32_ls_mode(n)) {
343 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
351 /* dump original ir node name */
352 fprintf(F, "orig node = ");
353 if (get_ia32_orig_node(n)) {
354 fprintf(F, "%s", get_ia32_orig_node(n));
362 fprintf(F, "=== IA32 attr end ===\n");
363 /* end of: case dump_node_info_txt */
372 /***************************************************************************************************
374 * | | | | | | / / | | | | | | | |
375 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
376 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
377 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
378 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
381 ***************************************************************************************************/
383 ia32_attr_t *get_ia32_attr(ir_node *node) {
384 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
385 return (ia32_attr_t *)get_irn_generic_attr(node);
388 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
389 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
390 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
393 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
394 ia32_attr_t *attr = get_ia32_attr(node);
395 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
399 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
400 const ia32_attr_t *attr = get_ia32_attr_const(node);
401 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
405 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
406 const ia32_attr_t *attr = get_ia32_attr_const(node);
407 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
412 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
413 ia32_attr_t *attr = get_ia32_attr(node);
414 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
419 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
421 const ia32_attr_t *attr = get_ia32_attr_const(node);
422 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
427 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
428 ia32_attr_t *attr = get_ia32_attr(node);
429 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
434 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
435 const ia32_attr_t *attr = get_ia32_attr_const(node);
436 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
441 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
443 ia32_attr_t *attr = get_ia32_attr(node);
444 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
449 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
451 const ia32_attr_t *attr = get_ia32_attr_const(node);
452 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
457 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
458 ia32_attr_t *attr = get_ia32_attr(node);
459 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
464 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
465 const ia32_attr_t *attr = get_ia32_attr_const(node);
466 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
472 * Gets the type of an ia32 node.
474 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
475 const ia32_attr_t *attr = get_ia32_attr_const(node);
476 return attr->data.tp;
480 * Sets the type of an ia32 node.
482 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
483 ia32_attr_t *attr = get_ia32_attr(node);
487 ia32_am_type_t get_ia32_am_support(const ir_node *node)
489 const ia32_attr_t *attr = get_ia32_attr_const(node);
490 return attr->data.am_arity;
494 * Sets the supported address mode of an ia32 node
496 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
498 ia32_attr_t *attr = get_ia32_attr(node);
499 attr->data.am_arity = arity;
503 * Gets the address mode offset as int.
505 int get_ia32_am_offs_int(const ir_node *node) {
506 const ia32_attr_t *attr = get_ia32_attr_const(node);
507 return attr->am_offs;
511 * Sets the address mode offset from an int.
513 void set_ia32_am_offs_int(ir_node *node, int offset) {
514 ia32_attr_t *attr = get_ia32_attr(node);
515 attr->am_offs = offset;
518 void add_ia32_am_offs_int(ir_node *node, int offset) {
519 ia32_attr_t *attr = get_ia32_attr(node);
520 attr->am_offs += offset;
524 * Returns the symconst entity associated to address mode.
526 ir_entity *get_ia32_am_sc(const ir_node *node) {
527 const ia32_attr_t *attr = get_ia32_attr_const(node);
532 * Sets the symconst entity associated to address mode.
534 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
535 ia32_attr_t *attr = get_ia32_attr(node);
536 attr->am_sc = entity;
540 * Sets the sign bit for address mode symconst.
542 void set_ia32_am_sc_sign(ir_node *node) {
543 ia32_attr_t *attr = get_ia32_attr(node);
544 attr->data.am_sc_sign = 1;
548 * Clears the sign bit for address mode symconst.
550 void clear_ia32_am_sc_sign(ir_node *node) {
551 ia32_attr_t *attr = get_ia32_attr(node);
552 attr->data.am_sc_sign = 0;
556 * Returns the sign bit for address mode symconst.
558 int is_ia32_am_sc_sign(const ir_node *node) {
559 const ia32_attr_t *attr = get_ia32_attr_const(node);
560 return attr->data.am_sc_sign;
564 * Gets the addr mode const.
566 int get_ia32_am_scale(const ir_node *node) {
567 const ia32_attr_t *attr = get_ia32_attr_const(node);
568 return attr->data.am_scale;
572 * Sets the index register scale for address mode.
574 void set_ia32_am_scale(ir_node *node, int scale) {
575 ia32_attr_t *attr = get_ia32_attr(node);
576 assert(0 <= scale && scale < 4 && "AM scale out of range");
577 attr->data.am_scale = scale;
580 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
582 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
583 set_ia32_am_scale(to, get_ia32_am_scale(from));
584 set_ia32_am_sc(to, get_ia32_am_sc(from));
585 if(is_ia32_am_sc_sign(from))
586 set_ia32_am_sc_sign(to);
587 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
588 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
589 if (is_ia32_use_frame(from))
590 set_ia32_use_frame(to);
594 * Sets the uses_frame flag.
596 void set_ia32_use_frame(ir_node *node) {
597 ia32_attr_t *attr = get_ia32_attr(node);
598 attr->data.use_frame = 1;
602 * Clears the uses_frame flag.
604 void clear_ia32_use_frame(ir_node *node) {
605 ia32_attr_t *attr = get_ia32_attr(node);
606 attr->data.use_frame = 0;
610 * Gets the uses_frame flag.
612 int is_ia32_use_frame(const ir_node *node) {
613 const ia32_attr_t *attr = get_ia32_attr_const(node);
614 return attr->data.use_frame;
618 * Sets node to commutative.
620 void set_ia32_commutative(ir_node *node) {
621 ia32_attr_t *attr = get_ia32_attr(node);
622 attr->data.is_commutative = 1;
626 * Sets node to non-commutative.
628 void clear_ia32_commutative(ir_node *node) {
629 ia32_attr_t *attr = get_ia32_attr(node);
630 attr->data.is_commutative = 0;
634 * Checks if node is commutative.
636 int is_ia32_commutative(const ir_node *node) {
637 const ia32_attr_t *attr = get_ia32_attr_const(node);
638 return attr->data.is_commutative;
641 void set_ia32_need_stackent(ir_node *node) {
642 ia32_attr_t *attr = get_ia32_attr(node);
643 attr->data.need_stackent = 1;
646 void clear_ia32_need_stackent(ir_node *node) {
647 ia32_attr_t *attr = get_ia32_attr(node);
648 attr->data.need_stackent = 0;
651 int is_ia32_need_stackent(const ir_node *node) {
652 const ia32_attr_t *attr = get_ia32_attr_const(node);
653 return attr->data.need_stackent;
656 void set_ia32_is_reload(ir_node *node) {
657 ia32_attr_t *attr = get_ia32_attr(node);
658 attr->data.is_reload = 1;
661 int is_ia32_is_reload(const ir_node *node) {
662 const ia32_attr_t *attr = get_ia32_attr_const(node);
663 return attr->data.is_reload;
666 void set_ia32_is_spill(ir_node *node) {
667 ia32_attr_t *attr = get_ia32_attr(node);
668 attr->data.is_spill = 1;
671 int is_ia32_is_spill(const ir_node *node) {
672 const ia32_attr_t *attr = get_ia32_attr_const(node);
673 return attr->data.is_spill;
676 void set_ia32_is_remat(ir_node *node) {
677 ia32_attr_t *attr = get_ia32_attr(node);
678 attr->data.is_remat = 1;
681 int is_ia32_is_remat(const ir_node *node) {
682 const ia32_attr_t *attr = get_ia32_attr_const(node);
683 return attr->data.is_remat;
687 * Gets the mode of the stored/loaded value (only set for Store/Load)
689 ir_mode *get_ia32_ls_mode(const ir_node *node) {
690 const ia32_attr_t *attr = get_ia32_attr_const(node);
691 return attr->ls_mode;
695 * Sets the mode of the stored/loaded value (only set for Store/Load)
697 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
698 ia32_attr_t *attr = get_ia32_attr(node);
699 attr->ls_mode = mode;
703 * Gets the frame entity assigned to this node.
705 ir_entity *get_ia32_frame_ent(const ir_node *node) {
706 const ia32_attr_t *attr = get_ia32_attr_const(node);
707 return attr->frame_ent;
711 * Sets the frame entity for this node.
713 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
714 ia32_attr_t *attr = get_ia32_attr(node);
715 attr->frame_ent = ent;
717 set_ia32_use_frame(node);
719 clear_ia32_use_frame(node);
724 * Gets the instruction latency.
726 unsigned get_ia32_latency(const ir_node *node) {
727 const ir_op *op = get_irn_op(node);
728 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
729 return op_attr->latency;
733 * Returns the argument register requirements of an ia32 node.
735 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
736 const ia32_attr_t *attr = get_ia32_attr_const(node);
741 * Sets the argument register requirements of an ia32 node.
743 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
744 ia32_attr_t *attr = get_ia32_attr(node);
749 * Returns the result register requirements of an ia32 node.
751 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
752 const ia32_attr_t *attr = get_ia32_attr_const(node);
753 return attr->out_req;
757 * Sets the result register requirements of an ia32 node.
759 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
760 ia32_attr_t *attr = get_ia32_attr(node);
761 attr->out_req = reqs;
765 * Returns the argument register requirement at position pos of an ia32 node.
767 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
768 const ia32_attr_t *attr = get_ia32_attr_const(node);
769 if(attr->in_req == NULL)
770 return arch_no_register_req;
772 return attr->in_req[pos];
776 * Returns the result register requirement at position pos of an ia32 node.
778 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
779 const ia32_attr_t *attr = get_ia32_attr_const(node);
780 if(attr->out_req == NULL)
781 return arch_no_register_req;
783 return attr->out_req[pos];
787 * Sets the OUT register requirements at position pos.
789 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
790 ia32_attr_t *attr = get_ia32_attr(node);
791 attr->out_req[pos] = req;
795 * Sets the IN register requirements at position pos.
797 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
798 ia32_attr_t *attr = get_ia32_attr(node);
799 attr->in_req[pos] = req;
803 * Returns the register flag of an ia32 node.
805 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
806 const ia32_attr_t *attr = get_ia32_attr_const(node);
807 return attr->data.flags;
811 * Sets the register flag of an ia32 node.
813 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
814 ia32_attr_t *attr = get_ia32_attr(node);
815 attr->data.flags = flags;
818 void add_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
819 ia32_attr_t *attr = get_ia32_attr(node);
820 attr->data.flags |= flags;
824 * Returns the result register slots of an ia32 node.
826 const arch_register_t **get_ia32_slots(const ir_node *node) {
827 const ia32_attr_t *attr = get_ia32_attr_const(node);
832 * Returns the number of results.
834 int get_ia32_n_res(const ir_node *node) {
835 const ia32_attr_t *attr = get_ia32_attr_const(node);
836 return ARR_LEN(attr->slots);
840 * Returns the condition code of a node.
842 long get_ia32_condcode(const ir_node *node)
844 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
845 return attr->pn_code;
849 * Sets the condition code of a node
851 void set_ia32_condcode(ir_node *node, long code)
853 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
854 attr->pn_code = code;
858 * Returns the condition code of a node.
860 unsigned get_ia32_copyb_size(const ir_node *node)
862 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
867 * Sets the flags for the n'th out.
869 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
870 ia32_attr_t *attr = get_ia32_attr(node);
871 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
872 attr->out_flags[pos] = flags;
876 * Gets the flags for the n'th out.
878 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
879 const ia32_attr_t *attr = get_ia32_attr_const(node);
880 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
881 return attr->out_flags[pos];
885 * Get the list of available execution units.
887 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
888 const ia32_attr_t *attr = get_ia32_attr_const(node);
889 return attr->exec_units;
893 * Get the exception label attribute.
895 unsigned get_ia32_exc_label(const ir_node *node) {
896 const ia32_attr_t *attr = get_ia32_attr_const(node);
897 return attr->data.has_except_label;
901 * Set the exception label attribute.
903 void set_ia32_exc_label(ir_node *node, unsigned flag) {
904 ia32_attr_t *attr = get_ia32_attr(node);
905 attr->data.has_except_label = flag;
909 * Return the exception label id.
911 ir_label_t get_ia32_exc_label_id(const ir_node *node) {
912 const ia32_attr_t *attr = get_ia32_attr_const(node);
914 assert(attr->data.has_except_label);
915 return attr->exc_label;
919 * Assign the exception label id.
921 void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
922 ia32_attr_t *attr = get_ia32_attr(node);
924 assert(attr->data.has_except_label);
925 attr->exc_label = id;
931 * Returns the name of the original ir node.
933 const char *get_ia32_orig_node(const ir_node *node) {
934 const ia32_attr_t *attr = get_ia32_attr_const(node);
935 return attr->orig_node;
939 * Sets the name of the original ir node.
941 void set_ia32_orig_node(ir_node *node, const char *name) {
942 ia32_attr_t *attr = get_ia32_attr(node);
943 attr->orig_node = name;
948 /******************************************************************************************************
950 * (_) | | | | | | / _| | | (_)
951 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
952 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
953 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
954 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
957 ******************************************************************************************************/
960 * Returns whether or not the node is an AddrModeS node.
962 int is_ia32_AddrModeS(const ir_node *node) {
963 const ia32_attr_t *attr = get_ia32_attr_const(node);
964 return (attr->data.tp == ia32_AddrModeS);
968 * Returns whether or not the node is an AddrModeD node.
970 int is_ia32_AddrModeD(const ir_node *node) {
971 const ia32_attr_t *attr = get_ia32_attr_const(node);
972 return (attr->data.tp == ia32_AddrModeD);
976 * Checks if node is a Load or xLoad/vfLoad.
978 int is_ia32_Ld(const ir_node *node) {
979 int op = get_ia32_irn_opcode(node);
980 return op == iro_ia32_Load ||
981 op == iro_ia32_xLoad ||
982 op == iro_ia32_vfld ||
987 * Checks if node is a Store or xStore/vfStore.
989 int is_ia32_St(const ir_node *node) {
990 int op = get_ia32_irn_opcode(node);
991 return op == iro_ia32_Store ||
992 op == iro_ia32_Store8Bit ||
993 op == iro_ia32_xStore ||
994 op == iro_ia32_vfst ||
995 op == iro_ia32_fst ||
1000 * Returns the name of the OUT register at position pos.
1002 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1003 const ia32_attr_t *attr = get_ia32_attr_const(node);
1005 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1006 assert(attr->slots[pos] && "No register assigned");
1008 return arch_register_get_name(attr->slots[pos]);
1012 * Returns the index of the OUT register at position pos within its register class.
1014 int get_ia32_out_regnr(const ir_node *node, int pos) {
1015 const ia32_attr_t *attr = get_ia32_attr_const(node);
1017 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1018 assert(attr->slots[pos] && "No register assigned");
1020 return arch_register_get_index(attr->slots[pos]);
1023 void ia32_swap_left_right(ir_node *node)
1025 ia32_attr_t *attr = get_ia32_attr(node);
1026 ir_node *left = get_irn_n(node, n_ia32_binary_left);
1027 ir_node *right = get_irn_n(node, n_ia32_binary_right);
1029 assert(is_ia32_commutative(node));
1030 attr->data.ins_permuted = !attr->data.ins_permuted;
1031 set_irn_n(node, n_ia32_binary_left, right);
1032 set_irn_n(node, n_ia32_binary_right, left);
1036 * Returns the OUT register at position pos.
1038 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1039 const ia32_attr_t *attr = get_ia32_attr_const(node);
1041 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1042 assert(attr->slots[pos] && "No register assigned");
1044 return attr->slots[pos];
1048 * Initializes the nodes attributes.
1050 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1051 const arch_register_req_t **in_reqs,
1052 const arch_register_req_t **out_reqs,
1053 const be_execution_unit_t ***execution_units,
1056 ir_graph *irg = get_irn_irg(node);
1057 struct obstack *obst = get_irg_obstack(irg);
1058 ia32_attr_t *attr = get_ia32_attr(node);
1060 set_ia32_flags(node, flags);
1061 set_ia32_in_req_all(node, in_reqs);
1062 set_ia32_out_req_all(node, out_reqs);
1064 attr->exec_units = execution_units;
1066 attr->attr_type |= IA32_ATTR_ia32_attr_t;
1069 attr->out_flags = NEW_ARR_D(int, obst, n_res);
1070 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1072 attr->slots = NEW_ARR_D(const arch_register_t*, obst, n_res);
1073 /* void* cast to suppress an incorrect warning on MSVC */
1074 memset((void*)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1078 init_ia32_x87_attributes(ir_node *res)
1081 ia32_attr_t *attr = get_ia32_attr(res);
1082 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
1086 ia32_current_cg->do_x87_sim = 1;
1090 init_ia32_asm_attributes(ir_node *res)
1093 ia32_attr_t *attr = get_ia32_attr(res);
1094 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
1101 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
1102 int symconst_sign, long offset)
1104 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
1107 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
1109 attr->symconst = symconst;
1110 attr->sc_sign = symconst_sign;
1111 attr->offset = offset;
1114 void init_ia32_call_attributes(ir_node *const res, unsigned const pop, ir_type *const call_tp)
1116 ia32_call_attr_t *attr = get_irn_generic_attr(res);
1119 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
1122 attr->call_tp = call_tp;
1126 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
1127 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
1130 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
1136 init_ia32_condcode_attributes(ir_node *res, long pnc) {
1137 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
1140 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
1142 attr->pn_code = pnc;
1145 ir_node *get_ia32_result_proj(const ir_node *node)
1147 const ir_edge_t *edge;
1149 foreach_out_edge(node, edge) {
1150 ir_node *proj = get_edge_src_irn(edge);
1151 if(get_Proj_proj(proj) == 0) {
1158 /***************************************************************************************
1161 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1162 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1163 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1164 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1166 ***************************************************************************************/
1168 /* default compare operation to compare attributes */
1169 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
1170 if (a->data.tp != b->data.tp)
1173 if (a->data.am_scale != b->data.am_scale
1174 || a->data.am_sc_sign != b->data.am_sc_sign
1175 || a->am_offs != b->am_offs
1176 || a->am_sc != b->am_sc
1177 || a->ls_mode != b->ls_mode)
1180 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1181 * unsigned int -> double conversions */
1182 if(a->data.use_frame && a->frame_ent == NULL)
1184 if(b->data.use_frame && b->frame_ent == NULL)
1187 if (a->data.use_frame != b->data.use_frame
1188 || a->frame_ent != b->frame_ent)
1191 if (a->data.tp != b->data.tp)
1194 if (a->data.has_except_label != b->data.has_except_label)
1197 if (a->data.ins_permuted != b->data.ins_permuted
1198 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1204 /** Compare nodes attributes for all "normal" nodes. */
1206 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1208 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1209 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1211 return ia32_compare_attr(attr_a, attr_b);
1214 /** Compare node attributes for nodes with condition code. */
1216 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1218 const ia32_condcode_attr_t *attr_a;
1219 const ia32_condcode_attr_t *attr_b;
1221 if (ia32_compare_nodes_attr(a, b))
1224 attr_a = get_ia32_condcode_attr_const(a);
1225 attr_b = get_ia32_condcode_attr_const(b);
1227 if(attr_a->pn_code != attr_b->pn_code)
1233 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1235 const ia32_call_attr_t *attr_a;
1236 const ia32_call_attr_t *attr_b;
1238 if (ia32_compare_nodes_attr(a, b))
1241 attr_a = get_ia32_call_attr_const(a);
1242 attr_b = get_ia32_call_attr_const(b);
1244 if (attr_a->pop != attr_b->pop)
1247 if (attr_a->call_tp != attr_b->call_tp)
1253 /** Compare node attributes for CopyB nodes. */
1255 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1257 const ia32_copyb_attr_t *attr_a;
1258 const ia32_copyb_attr_t *attr_b;
1260 if (ia32_compare_nodes_attr(a, b))
1263 attr_a = get_ia32_copyb_attr_const(a);
1264 attr_b = get_ia32_copyb_attr_const(b);
1266 if(attr_a->size != attr_b->size)
1273 /** Compare ASM node attributes. */
1275 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1277 const ia32_asm_attr_t *attr_a;
1278 const ia32_asm_attr_t *attr_b;
1280 if(ia32_compare_nodes_attr(a, b))
1283 attr_a = get_ia32_asm_attr_const(a);
1284 attr_b = get_ia32_asm_attr_const(b);
1286 if(attr_a->asm_text != attr_b->asm_text)
1293 * Hash function for Immediates
1295 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1296 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1298 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1301 /** Compare node attributes for Immediates. */
1303 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1305 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1306 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1308 if(attr_a->symconst != attr_b->symconst ||
1309 attr_a->sc_sign != attr_b->sc_sign ||
1310 attr_a->offset != attr_b->offset)
1316 /** Compare node attributes for x87 nodes. */
1318 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1320 return ia32_compare_nodes_attr(a, b);
1324 /* copies the ia32 attributes */
1325 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1327 ir_graph *irg = get_irn_irg(new_node);
1328 struct obstack *obst = get_irg_obstack(irg);
1329 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1330 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1332 /* copy the attributes */
1333 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1335 /* copy out flags */
1336 attr_new->out_flags =
1337 DUP_ARR_D(int, obst, attr_old->out_flags);
1338 /* copy register assignments */
1340 DUP_ARR_D(arch_register_t*, obst, attr_old->slots);
1343 /* Include the generated constructor functions */
1344 #include "gen_ia32_new_nodes.c.inl"