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"
41 #include "firm_common_t.h"
46 #include "raw_bitset.h"
49 #include "../bearch_t.h"
50 #include "../beinfo.h"
52 #include "bearch_ia32_t.h"
53 #include "ia32_common_transform.h"
54 #include "ia32_nodes_attr.h"
55 #include "ia32_new_nodes.h"
56 #include "gen_ia32_regalloc_if.h"
57 #include "gen_ia32_machine.h"
59 /***********************************************************************************
62 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
63 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
64 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
65 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
68 ***********************************************************************************/
71 * Dumps the register requirements for either in or out.
73 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
75 char *dir = inout ? "out" : "in";
76 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
80 memset(buf, 0, sizeof(buf));
83 for (i = 0; i < max; i++) {
84 fprintf(F, "%sreq #%d =", dir, i);
86 if (reqs[i]->type == arch_register_req_type_none) {
90 if (reqs[i]->type & arch_register_req_type_normal) {
91 fprintf(F, " %s", reqs[i]->cls->name);
94 if (reqs[i]->type & arch_register_req_type_limited) {
96 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
99 if (reqs[i]->type & arch_register_req_type_should_be_same) {
100 unsigned other = reqs[i]->other_same;
103 ir_fprintf(F, " same as");
104 for (i = 0; 1U << i <= other; ++i) {
105 if (other & (1U << i)) {
106 ir_fprintf(F, " %+F", get_irn_n(n, i));
111 if (reqs[i]->type & arch_register_req_type_must_be_different) {
112 unsigned other = reqs[i]->other_different;
115 ir_fprintf(F, " different from");
116 for (i = 0; 1U << i <= other; ++i) {
117 if (other & (1U << i)) {
118 ir_fprintf(F, " %+F", get_irn_n(n, i));
129 fprintf(F, "%sreq = N/A\n", dir);
134 * Dumper interface for dumping ia32 nodes in vcg.
135 * @param n the node to dump
136 * @param F the output file
137 * @param reason indicates which kind of information should be dumped
138 * @return 0 on success or != 0 on failure
140 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
141 ir_mode *mode = NULL;
144 const arch_register_req_t **reqs;
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 mode = get_ia32_ls_mode(n);
195 fprintf(F, "[%s]", get_mode_name(mode));
198 case dump_node_nodeattr_txt:
199 if (! is_ia32_Lea(n)) {
200 if (is_ia32_AddrModeS(n)) {
201 fprintf(F, "[AM S] ");
202 } else if (is_ia32_AddrModeD(n)) {
203 fprintf(F, "[AM D] ");
209 case dump_node_info_txt:
210 n_res = arch_irn_get_n_outs(n);
211 fprintf(F, "=== IA32 attr begin ===\n");
213 /* dump IN requirements */
214 if (get_irn_arity(n) > 0) {
215 reqs = get_ia32_in_req_all(n);
216 dump_reg_req(F, n, reqs, 0);
219 /* dump OUT requirements */
221 reqs = get_ia32_out_req_all(n);
222 dump_reg_req(F, n, reqs, 1);
225 /* dump assigned registers */
227 for (i = 0; i < n_res; i++) {
228 const arch_register_t *reg = arch_irn_get_register(n, i);
230 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
237 switch (get_ia32_op_type(n)) {
239 fprintf(F, "Normal");
242 fprintf(F, "AM Dest (Load+Store)");
245 fprintf(F, "AM Source (Load)");
248 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
253 /* dump supported am */
254 fprintf(F, "AM support = ");
255 switch (get_ia32_am_support(n)) {
256 case ia32_am_none: fputs("none\n", F); break;
257 case ia32_am_unary: fputs("source (unary)\n", F); break;
258 case ia32_am_binary: fputs("source (binary)\n", F); break;
261 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
266 if(get_ia32_am_offs_int(n) != 0) {
267 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
270 /* dump AM symconst */
271 if(get_ia32_am_sc(n) != NULL) {
272 ir_entity *ent = get_ia32_am_sc(n);
273 ident *id = get_entity_ld_ident(ent);
274 fprintf(F, "AM symconst = %s\n", get_id_str(id));
278 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
281 if (is_ia32_SwitchJmp(n)) {
282 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
283 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
284 ia32_attr_t *attr = get_ia32_attr(n);
285 long pnc = get_ia32_condcode(n);
286 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
287 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
288 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
290 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
291 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
294 fprintf(F, "n_res = %d\n", arch_irn_get_n_outs(n));
295 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
296 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
297 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
298 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
299 fprintf(F, "latency = %d\n", get_ia32_latency(n));
302 fprintf(F, "flags =");
303 flags = arch_irn_get_flags(n);
304 if (flags == arch_irn_flags_none) {
308 if (flags & arch_irn_flags_dont_spill) {
309 fprintf(F, " unspillable");
311 if (flags & arch_irn_flags_rematerializable) {
312 fprintf(F, " remat");
314 if (flags & arch_irn_flags_modify_flags) {
315 fprintf(F, " modify_flags");
318 fprintf(F, " (%d)\n", flags);
320 /* dump frame entity */
321 fprintf(F, "frame entity = ");
322 if (get_ia32_frame_ent(n)) {
323 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
331 fprintf(F, "ls_mode = ");
332 if (get_ia32_ls_mode(n)) {
333 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
341 /* dump original ir node name */
342 fprintf(F, "orig node = ");
343 if (get_ia32_orig_node(n)) {
344 fprintf(F, "%s", get_ia32_orig_node(n));
352 fprintf(F, "=== IA32 attr end ===\n");
353 /* end of: case dump_node_info_txt */
362 /***************************************************************************************************
364 * | | | | | | / / | | | | | | | |
365 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
366 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
367 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
368 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
371 ***************************************************************************************************/
373 ia32_attr_t *get_ia32_attr(ir_node *node) {
374 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
375 return (ia32_attr_t *)get_irn_generic_attr(node);
378 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
379 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
380 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
383 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
384 ia32_attr_t *attr = get_ia32_attr(node);
385 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
389 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
390 const ia32_attr_t *attr = get_ia32_attr_const(node);
391 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
395 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
396 const ia32_attr_t *attr = get_ia32_attr_const(node);
397 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
402 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
403 ia32_attr_t *attr = get_ia32_attr(node);
404 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
409 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
411 const ia32_attr_t *attr = get_ia32_attr_const(node);
412 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
417 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
418 ia32_attr_t *attr = get_ia32_attr(node);
419 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
424 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
425 const ia32_attr_t *attr = get_ia32_attr_const(node);
426 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
431 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
433 ia32_attr_t *attr = get_ia32_attr(node);
434 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
439 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
441 const ia32_attr_t *attr = get_ia32_attr_const(node);
442 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
447 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
448 ia32_attr_t *attr = get_ia32_attr(node);
449 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
454 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
455 const ia32_attr_t *attr = get_ia32_attr_const(node);
456 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
462 * Gets the type of an ia32 node.
464 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
465 const ia32_attr_t *attr = get_ia32_attr_const(node);
466 return attr->data.tp;
470 * Sets the type of an ia32 node.
472 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
473 ia32_attr_t *attr = get_ia32_attr(node);
477 ia32_am_type_t get_ia32_am_support(const ir_node *node)
479 const ia32_attr_t *attr = get_ia32_attr_const(node);
480 return attr->data.am_arity;
484 * Sets the supported address mode of an ia32 node
486 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
488 ia32_attr_t *attr = get_ia32_attr(node);
489 attr->data.am_arity = arity;
493 * Gets the address mode offset as int.
495 int get_ia32_am_offs_int(const ir_node *node) {
496 const ia32_attr_t *attr = get_ia32_attr_const(node);
497 return attr->am_offs;
501 * Sets the address mode offset from an int.
503 void set_ia32_am_offs_int(ir_node *node, int offset) {
504 ia32_attr_t *attr = get_ia32_attr(node);
505 attr->am_offs = offset;
508 void add_ia32_am_offs_int(ir_node *node, int offset) {
509 ia32_attr_t *attr = get_ia32_attr(node);
510 attr->am_offs += offset;
514 * Returns the symconst entity associated to address mode.
516 ir_entity *get_ia32_am_sc(const ir_node *node) {
517 const ia32_attr_t *attr = get_ia32_attr_const(node);
522 * Sets the symconst entity associated to address mode.
524 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
525 ia32_attr_t *attr = get_ia32_attr(node);
526 attr->am_sc = entity;
530 * Sets the sign bit for address mode symconst.
532 void set_ia32_am_sc_sign(ir_node *node) {
533 ia32_attr_t *attr = get_ia32_attr(node);
534 attr->data.am_sc_sign = 1;
538 * Clears the sign bit for address mode symconst.
540 void clear_ia32_am_sc_sign(ir_node *node) {
541 ia32_attr_t *attr = get_ia32_attr(node);
542 attr->data.am_sc_sign = 0;
546 * Returns the sign bit for address mode symconst.
548 int is_ia32_am_sc_sign(const ir_node *node) {
549 const ia32_attr_t *attr = get_ia32_attr_const(node);
550 return attr->data.am_sc_sign;
554 * Gets the addr mode const.
556 unsigned get_ia32_am_scale(const ir_node *node) {
557 const ia32_attr_t *attr = get_ia32_attr_const(node);
558 return attr->data.am_scale;
562 * Sets the index register scale for address mode.
564 void set_ia32_am_scale(ir_node *node, unsigned scale) {
565 ia32_attr_t *attr = get_ia32_attr(node);
566 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
567 attr->data.am_scale = scale;
570 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
572 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
573 set_ia32_am_scale(to, get_ia32_am_scale(from));
574 set_ia32_am_sc(to, get_ia32_am_sc(from));
575 if(is_ia32_am_sc_sign(from))
576 set_ia32_am_sc_sign(to);
577 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
578 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
579 if (is_ia32_use_frame(from))
580 set_ia32_use_frame(to);
584 * Sets the uses_frame flag.
586 void set_ia32_use_frame(ir_node *node) {
587 ia32_attr_t *attr = get_ia32_attr(node);
588 attr->data.use_frame = 1;
592 * Clears the uses_frame flag.
594 void clear_ia32_use_frame(ir_node *node) {
595 ia32_attr_t *attr = get_ia32_attr(node);
596 attr->data.use_frame = 0;
600 * Gets the uses_frame flag.
602 int is_ia32_use_frame(const ir_node *node) {
603 const ia32_attr_t *attr = get_ia32_attr_const(node);
604 return attr->data.use_frame;
608 * Sets node to commutative.
610 void set_ia32_commutative(ir_node *node) {
611 ia32_attr_t *attr = get_ia32_attr(node);
612 attr->data.is_commutative = 1;
616 * Sets node to non-commutative.
618 void clear_ia32_commutative(ir_node *node) {
619 ia32_attr_t *attr = get_ia32_attr(node);
620 attr->data.is_commutative = 0;
624 * Checks if node is commutative.
626 int is_ia32_commutative(const ir_node *node) {
627 const ia32_attr_t *attr = get_ia32_attr_const(node);
628 return attr->data.is_commutative;
631 void set_ia32_need_stackent(ir_node *node) {
632 ia32_attr_t *attr = get_ia32_attr(node);
633 attr->data.need_stackent = 1;
636 void clear_ia32_need_stackent(ir_node *node) {
637 ia32_attr_t *attr = get_ia32_attr(node);
638 attr->data.need_stackent = 0;
641 int is_ia32_need_stackent(const ir_node *node) {
642 const ia32_attr_t *attr = get_ia32_attr_const(node);
643 return attr->data.need_stackent;
646 void set_ia32_is_reload(ir_node *node) {
647 ia32_attr_t *attr = get_ia32_attr(node);
648 attr->data.is_reload = 1;
651 int is_ia32_is_reload(const ir_node *node) {
652 const ia32_attr_t *attr = get_ia32_attr_const(node);
653 return attr->data.is_reload;
656 void set_ia32_is_spill(ir_node *node) {
657 ia32_attr_t *attr = get_ia32_attr(node);
658 attr->data.is_spill = 1;
661 int is_ia32_is_spill(const ir_node *node) {
662 const ia32_attr_t *attr = get_ia32_attr_const(node);
663 return attr->data.is_spill;
666 void set_ia32_is_remat(ir_node *node) {
667 ia32_attr_t *attr = get_ia32_attr(node);
668 attr->data.is_remat = 1;
671 int is_ia32_is_remat(const ir_node *node) {
672 const ia32_attr_t *attr = get_ia32_attr_const(node);
673 return attr->data.is_remat;
677 * Gets the mode of the stored/loaded value (only set for Store/Load)
679 ir_mode *get_ia32_ls_mode(const ir_node *node) {
680 const ia32_attr_t *attr = get_ia32_attr_const(node);
681 return attr->ls_mode;
685 * Sets the mode of the stored/loaded value (only set for Store/Load)
687 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
688 ia32_attr_t *attr = get_ia32_attr(node);
689 attr->ls_mode = mode;
693 * Gets the frame entity assigned to this node.
695 ir_entity *get_ia32_frame_ent(const ir_node *node) {
696 const ia32_attr_t *attr = get_ia32_attr_const(node);
697 return attr->frame_ent;
701 * Sets the frame entity for this node.
703 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
704 ia32_attr_t *attr = get_ia32_attr(node);
705 attr->frame_ent = ent;
707 set_ia32_use_frame(node);
709 clear_ia32_use_frame(node);
714 * Gets the instruction latency.
716 unsigned get_ia32_latency(const ir_node *node) {
717 const ir_op *op = get_irn_op(node);
718 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
719 return op_attr->latency;
723 * Returns the argument register requirements of an ia32 node.
725 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
726 const ia32_attr_t *attr = get_ia32_attr_const(node);
731 * Sets the argument register requirements of an ia32 node.
733 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
734 ia32_attr_t *attr = get_ia32_attr(node);
739 * Returns the result register requirements of an ia32 node.
741 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
742 const ia32_attr_t *attr = get_ia32_attr_const(node);
743 return attr->out_req;
747 * Sets the result register requirements of an ia32 node.
749 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
750 ia32_attr_t *attr = get_ia32_attr(node);
751 attr->out_req = reqs;
755 * Returns the argument register requirement at position pos of an ia32 node.
757 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
758 const ia32_attr_t *attr = get_ia32_attr_const(node);
759 if(attr->in_req == NULL)
760 return arch_no_register_req;
762 return attr->in_req[pos];
766 * Returns the result register requirement at position pos of an ia32 node.
768 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
769 const ia32_attr_t *attr = get_ia32_attr_const(node);
770 if(attr->out_req == NULL)
771 return arch_no_register_req;
773 return attr->out_req[pos];
777 * Sets the OUT register requirements at position pos.
779 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
780 ia32_attr_t *attr = get_ia32_attr(node);
781 attr->out_req[pos] = req;
785 * Sets the IN register requirements at position pos.
787 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
788 ia32_attr_t *attr = get_ia32_attr(node);
789 attr->in_req[pos] = req;
793 * Returns the condition code of a node.
795 long get_ia32_condcode(const ir_node *node)
797 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
798 return attr->pn_code;
802 * Sets the condition code of a node
804 void set_ia32_condcode(ir_node *node, long code)
806 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
807 attr->pn_code = code;
811 * Returns the condition code of a node.
813 unsigned get_ia32_copyb_size(const ir_node *node)
815 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
820 * Get the list of available execution units.
822 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
823 const ia32_attr_t *attr = get_ia32_attr_const(node);
824 return attr->exec_units;
828 * Get the exception label attribute.
830 unsigned get_ia32_exc_label(const ir_node *node) {
831 const ia32_attr_t *attr = get_ia32_attr_const(node);
832 return attr->data.has_except_label;
836 * Set the exception label attribute.
838 void set_ia32_exc_label(ir_node *node, unsigned flag) {
839 ia32_attr_t *attr = get_ia32_attr(node);
840 attr->data.has_except_label = flag;
844 * Return the exception label id.
846 ir_label_t get_ia32_exc_label_id(const ir_node *node) {
847 const ia32_attr_t *attr = get_ia32_attr_const(node);
849 assert(attr->data.has_except_label);
850 return attr->exc_label;
854 * Assign the exception label id.
856 void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
857 ia32_attr_t *attr = get_ia32_attr(node);
859 assert(attr->data.has_except_label);
860 attr->exc_label = id;
866 * Returns the name of the original ir node.
868 const char *get_ia32_orig_node(const ir_node *node)
870 const ia32_attr_t *attr = get_ia32_attr_const(node);
871 return attr->orig_node;
874 static const char *ia32_get_old_node_name(const ir_node *irn)
876 struct obstack *obst = env_cg->isa->name_obst;
878 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
879 obstack_1grow(obst, 0);
880 return obstack_finish(obst);
884 * Sets the name of the original ir node.
886 void set_ia32_orig_node(ir_node *node, const ir_node *old)
888 const char *name = ia32_get_old_node_name(old);
889 ia32_attr_t *attr = get_ia32_attr(node);
890 attr->orig_node = name;
895 /******************************************************************************************************
897 * (_) | | | | | | / _| | | (_)
898 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
899 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
900 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
901 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
904 ******************************************************************************************************/
907 * Returns whether or not the node is an AddrModeS node.
909 int is_ia32_AddrModeS(const ir_node *node) {
910 const ia32_attr_t *attr = get_ia32_attr_const(node);
911 return (attr->data.tp == ia32_AddrModeS);
915 * Returns whether or not the node is an AddrModeD node.
917 int is_ia32_AddrModeD(const ir_node *node) {
918 const ia32_attr_t *attr = get_ia32_attr_const(node);
919 return (attr->data.tp == ia32_AddrModeD);
922 void ia32_swap_left_right(ir_node *node)
924 ia32_attr_t *attr = get_ia32_attr(node);
925 ir_node *left = get_irn_n(node, n_ia32_binary_left);
926 ir_node *right = get_irn_n(node, n_ia32_binary_right);
928 assert(is_ia32_commutative(node));
929 attr->data.ins_permuted = !attr->data.ins_permuted;
930 set_irn_n(node, n_ia32_binary_left, right);
931 set_irn_n(node, n_ia32_binary_right, left);
935 * Initializes the nodes attributes.
937 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
938 const arch_register_req_t **in_reqs,
939 const arch_register_req_t **out_reqs,
940 const be_execution_unit_t ***execution_units,
943 ir_graph *irg = get_irn_irg(node);
944 struct obstack *obst = get_irg_obstack(irg);
945 ia32_attr_t *attr = get_ia32_attr(node);
946 backend_info_t *info;
948 arch_irn_set_flags(node, flags);
949 set_ia32_in_req_all(node, in_reqs);
950 set_ia32_out_req_all(node, out_reqs);
952 attr->exec_units = execution_units;
954 attr->attr_type |= IA32_ATTR_ia32_attr_t;
957 info = be_get_info(node);
958 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
959 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
963 init_ia32_x87_attributes(ir_node *res)
966 ia32_attr_t *attr = get_ia32_attr(res);
967 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
971 ia32_current_cg->do_x87_sim = 1;
975 init_ia32_asm_attributes(ir_node *res)
978 ia32_attr_t *attr = get_ia32_attr(res);
979 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
986 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
987 int symconst_sign, long offset)
989 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
992 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
994 attr->symconst = symconst;
995 attr->sc_sign = symconst_sign;
996 attr->offset = offset;
999 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
1001 ia32_call_attr_t *attr = get_irn_generic_attr(res);
1004 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
1007 attr->call_tp = call_tp;
1011 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
1012 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
1015 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
1021 init_ia32_condcode_attributes(ir_node *res, long pnc) {
1022 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
1025 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
1027 attr->pn_code = pnc;
1030 /***************************************************************************************
1033 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1034 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1035 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1036 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1038 ***************************************************************************************/
1040 /* default compare operation to compare attributes */
1041 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
1043 if (a->data.tp != b->data.tp)
1046 if (a->data.am_scale != b->data.am_scale
1047 || a->data.am_sc_sign != b->data.am_sc_sign
1048 || a->am_offs != b->am_offs
1049 || a->am_sc != b->am_sc
1050 || a->ls_mode != b->ls_mode)
1053 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1054 * unsigned int -> double conversions */
1055 if(a->data.use_frame && a->frame_ent == NULL)
1057 if(b->data.use_frame && b->frame_ent == NULL)
1060 if (a->data.use_frame != b->data.use_frame
1061 || a->frame_ent != b->frame_ent)
1064 if (a->data.has_except_label != b->data.has_except_label)
1067 if (a->data.ins_permuted != b->data.ins_permuted
1068 || a->data.cmp_unsigned != b->data.cmp_unsigned)
1074 /** Compare nodes attributes for all "normal" nodes. */
1076 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1078 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1079 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1081 return ia32_compare_attr(attr_a, attr_b);
1084 /** Compare node attributes for nodes with condition code. */
1086 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
1088 const ia32_condcode_attr_t *attr_a;
1089 const ia32_condcode_attr_t *attr_b;
1091 if (ia32_compare_nodes_attr(a, b))
1094 attr_a = get_ia32_condcode_attr_const(a);
1095 attr_b = get_ia32_condcode_attr_const(b);
1097 if(attr_a->pn_code != attr_b->pn_code)
1103 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
1105 const ia32_call_attr_t *attr_a;
1106 const ia32_call_attr_t *attr_b;
1108 if (ia32_compare_nodes_attr(a, b))
1111 attr_a = get_ia32_call_attr_const(a);
1112 attr_b = get_ia32_call_attr_const(b);
1114 if (attr_a->pop != attr_b->pop)
1117 if (attr_a->call_tp != attr_b->call_tp)
1123 /** Compare node attributes for CopyB nodes. */
1125 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1127 const ia32_copyb_attr_t *attr_a;
1128 const ia32_copyb_attr_t *attr_b;
1130 if (ia32_compare_nodes_attr(a, b))
1133 attr_a = get_ia32_copyb_attr_const(a);
1134 attr_b = get_ia32_copyb_attr_const(b);
1136 if(attr_a->size != attr_b->size)
1143 /** Compare ASM node attributes. */
1145 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1147 const ia32_asm_attr_t *attr_a;
1148 const ia32_asm_attr_t *attr_b;
1150 if(ia32_compare_nodes_attr(a, b))
1153 attr_a = get_ia32_asm_attr_const(a);
1154 attr_b = get_ia32_asm_attr_const(b);
1156 if(attr_a->asm_text != attr_b->asm_text)
1163 * Hash function for Immediates
1165 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1166 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1168 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1171 /** Compare node attributes for Immediates. */
1173 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1175 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1176 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1178 if(attr_a->symconst != attr_b->symconst ||
1179 attr_a->sc_sign != attr_b->sc_sign ||
1180 attr_a->offset != attr_b->offset)
1186 /** Compare node attributes for x87 nodes. */
1188 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1190 return ia32_compare_nodes_attr(a, b);
1194 /* copies the ia32 attributes */
1195 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1197 ir_graph *irg = get_irn_irg(new_node);
1198 struct obstack *obst = get_irg_obstack(irg);
1199 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1200 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1201 backend_info_t *old_info = be_get_info(old_node);
1202 backend_info_t *new_info;
1204 new_info = be_get_info(new_node);
1206 /* copy the attributes */
1207 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1209 /* copy out flags */
1210 new_info->out_infos =
1211 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1214 /* Include the generated constructor functions */
1215 #include "gen_ia32_new_nodes.c.inl"