2 * Copyright (C) 1995-2007 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 coresponding 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 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
102 if (reqs[i]->type & arch_register_req_type_should_be_different) {
103 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
112 fprintf(F, "%sreq = N/A\n", dir);
117 * Dumper interface for dumping ia32 nodes in vcg.
118 * @param n the node to dump
119 * @param F the output file
120 * @param reason indicates which kind of information should be dumped
121 * @return 0 on success or != 0 on failure
123 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
124 ir_mode *mode = NULL;
126 int i, n_res, am_flav, flags;
127 const arch_register_req_t **reqs;
128 const arch_register_t **slots;
131 case dump_node_opcode_txt:
132 fprintf(F, "%s", get_irn_opname(n));
135 case dump_node_mode_txt:
136 if (is_ia32_Ld(n) || is_ia32_St(n)) {
137 mode = get_ia32_ls_mode(n);
138 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
141 if(is_ia32_Immediate(n)) {
142 const ia32_immediate_attr_t *attr
143 = get_ia32_immediate_attr_const(n);
147 if(attr->attr.data.am_sc_sign) {
150 fputs(get_entity_name(attr->symconst), F);
152 if(attr->offset != 0 || attr->symconst == NULL) {
153 if(attr->offset > 0 && attr->symconst != NULL) {
156 fprintf(F, "%ld", attr->offset);
161 const ia32_attr_t *attr = get_ia32_attr_const(n);
163 if(attr->am_sc != NULL || attr->am_offs != 0)
166 if(attr->am_sc != NULL) {
167 if(attr->data.am_sc_sign) {
170 fputs(get_entity_name(attr->am_sc), F);
172 if(attr->am_offs != 0) {
173 if(attr->am_offs > 0 && attr->am_sc != NULL) {
176 fprintf(F, "%d", attr->am_offs);
179 if(attr->am_sc != NULL || attr->am_offs != 0)
184 case dump_node_nodeattr_txt:
185 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
186 if(is_ia32_ImmSymConst(n)) {
187 ir_entity *ent = get_ia32_Immop_symconst(n);
188 ident *id = get_entity_ld_ident(ent);
189 fprintf(F, "[SymC %s]", get_id_str(id));
192 tarval *tv = get_ia32_Immop_tarval(n);
194 tarval_snprintf(buf, sizeof(buf), tv);
195 fprintf(F, "[%s]", buf);
199 if (! is_ia32_Lea(n)) {
200 if (is_ia32_AddrModeS(n)) {
201 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 immop type */
258 fprintf(F, "immediate = ");
259 switch (get_ia32_immop_type(n)) {
266 case ia32_ImmSymConst:
267 fprintf(F, "SymConst");
270 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
275 /* dump supported am */
276 fprintf(F, "AM support = ");
277 switch (get_ia32_am_support(n)) {
282 fprintf(F, "source only (Load)");
285 fprintf(F, "dest only (Load+Store)");
291 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
296 /* dump am flavour */
297 fprintf(F, "AM flavour =");
298 am_flav = get_ia32_am_flavour(n);
299 if (am_flav == ia32_am_N) {
303 if (am_flav & ia32_O) {
306 if (am_flav & ia32_B) {
309 if (am_flav & ia32_I) {
312 if (am_flav & ia32_S) {
316 fprintf(F, " (%d)\n", am_flav);
319 if(get_ia32_am_offs_int(n) != 0) {
320 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
323 /* dump AM symconst */
324 if(get_ia32_am_sc(n) != NULL) {
325 ir_entity *ent = get_ia32_am_sc(n);
326 ident *id = get_entity_ld_ident(ent);
327 fprintf(F, "AM symconst = %s\n", get_id_str(id));
331 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
334 if(is_ia32_SwitchJmp(n)) {
335 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
337 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
338 long pnc = get_ia32_pncode(n);
339 fprintf(F, "pn_code = %ld (%s, unsigned)\n",
340 pnc, get_pnc_string(pnc & ~ia32_pn_Cmp_Unsigned));
342 fprintf(F, "pn_code = %ld (%s)\n", get_ia32_pncode(n),
343 get_pnc_string(get_ia32_pncode(n)));
348 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
351 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
354 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
357 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
360 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
363 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
366 fprintf(F, "latency = %d\n", get_ia32_latency(n));
369 fprintf(F, "flags =");
370 flags = get_ia32_flags(n);
371 if (flags == arch_irn_flags_none) {
375 if (flags & arch_irn_flags_dont_spill) {
376 fprintf(F, " unspillable");
378 if (flags & arch_irn_flags_rematerializable) {
379 fprintf(F, " remat");
381 if (flags & arch_irn_flags_ignore) {
382 fprintf(F, " ignore");
384 if (flags & arch_irn_flags_modify_sp) {
385 fprintf(F, " modify_sp");
388 fprintf(F, " (%d)\n", flags);
390 /* dump frame entity */
391 fprintf(F, "frame entity = ");
392 if (get_ia32_frame_ent(n)) {
393 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
401 fprintf(F, "ls_mode = ");
402 if (get_ia32_ls_mode(n)) {
403 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
411 /* dump original ir node name */
412 fprintf(F, "orig node = ");
413 if (get_ia32_orig_node(n)) {
414 fprintf(F, "%s", get_ia32_orig_node(n));
422 fprintf(F, "=== IA32 attr end ===\n");
423 /* end of: case dump_node_info_txt */
432 /***************************************************************************************************
434 * | | | | | | / / | | | | | | | |
435 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
436 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
437 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
438 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
441 ***************************************************************************************************/
443 ia32_attr_t *get_ia32_attr(ir_node *node) {
444 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
445 return (ia32_attr_t *)get_irn_generic_attr(node);
448 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
449 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
450 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
453 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
454 ia32_attr_t *attr = get_ia32_attr(node);
455 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
459 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
460 const ia32_attr_t *attr = get_ia32_attr_const(node);
461 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
465 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
466 const ia32_attr_t *attr = get_ia32_attr_const(node);
467 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
472 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
474 const ia32_attr_t *attr = get_ia32_attr_const(node);
475 const ia32_immediate_attr_t *immediate_attr
476 = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
478 return immediate_attr;
482 * Gets the type of an ia32 node.
484 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
485 const ia32_attr_t *attr = get_ia32_attr_const(node);
486 return attr->data.tp;
490 * Sets the type of an ia32 node.
492 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
493 ia32_attr_t *attr = get_ia32_attr(node);
498 * Gets the immediate op type of an ia32 node.
500 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
501 const ia32_attr_t *attr = get_ia32_attr_const(node);
502 return attr->data.imm_tp;
506 * Gets the supported address mode of an ia32 node
508 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
509 const ia32_attr_t *attr = get_ia32_attr_const(node);
510 return attr->data.am_support;
513 ia32_am_arity_t get_ia32_am_arity(const ir_node *node) {
514 const ia32_attr_t *attr = get_ia32_attr_const(node);
515 return attr->data.am_arity;
519 * Sets the supported address mode of an ia32 node
521 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp,
522 ia32_am_arity_t arity) {
523 ia32_attr_t *attr = get_ia32_attr(node);
524 attr->data.am_support = am_tp;
525 attr->data.am_arity = arity;
527 assert((am_tp == ia32_am_None && arity == ia32_am_arity_none) ||
528 (am_tp != ia32_am_None &&
529 ((arity == ia32_am_unary) || (arity == ia32_am_binary))));
533 * Gets the address mode flavour of an ia32 node
535 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
536 const ia32_attr_t *attr = get_ia32_attr_const(node);
537 return attr->data.am_flavour;
541 * Sets the address mode flavour of an ia32 node
543 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
544 ia32_attr_t *attr = get_ia32_attr(node);
545 attr->data.am_flavour = am_flavour;
549 * Gets the address mode offset as int.
551 int get_ia32_am_offs_int(const ir_node *node) {
552 const ia32_attr_t *attr = get_ia32_attr_const(node);
553 return attr->am_offs;
557 * Sets the address mode offset from an int.
559 void set_ia32_am_offs_int(ir_node *node, int offset) {
560 ia32_attr_t *attr = get_ia32_attr(node);
561 attr->am_offs = offset;
564 void add_ia32_am_offs_int(ir_node *node, int offset) {
565 ia32_attr_t *attr = get_ia32_attr(node);
566 attr->am_offs += offset;
570 * Returns the symconst entity associated to address mode.
572 ir_entity *get_ia32_am_sc(const ir_node *node) {
573 const ia32_attr_t *attr = get_ia32_attr_const(node);
578 * Sets the symconst entity associated to address mode.
580 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
581 ia32_attr_t *attr = get_ia32_attr(node);
582 attr->am_sc = entity;
586 * Sets the sign bit for address mode symconst.
588 void set_ia32_am_sc_sign(ir_node *node) {
589 ia32_attr_t *attr = get_ia32_attr(node);
590 attr->data.am_sc_sign = 1;
594 * Clears the sign bit for address mode symconst.
596 void clear_ia32_am_sc_sign(ir_node *node) {
597 ia32_attr_t *attr = get_ia32_attr(node);
598 attr->data.am_sc_sign = 0;
602 * Returns the sign bit for address mode symconst.
604 int is_ia32_am_sc_sign(const ir_node *node) {
605 const ia32_attr_t *attr = get_ia32_attr_const(node);
606 return attr->data.am_sc_sign;
610 * Gets the addr mode const.
612 int get_ia32_am_scale(const ir_node *node) {
613 const ia32_attr_t *attr = get_ia32_attr_const(node);
614 return attr->data.am_scale;
618 * Sets the index register scale for address mode.
620 void set_ia32_am_scale(ir_node *node, int scale) {
621 ia32_attr_t *attr = get_ia32_attr(node);
622 attr->data.am_scale = scale;
626 * Return the tarval of an immediate operation or NULL in case of SymConst
628 tarval *get_ia32_Immop_tarval(const ir_node *node) {
629 const ia32_attr_t *attr = get_ia32_attr_const(node);
630 assert(attr->data.imm_tp == ia32_ImmConst);
631 return attr->cnst_val.tv;
635 * Sets the attributes of an immediate operation to the specified tarval
637 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
638 ia32_attr_t *attr = get_ia32_attr(node);
639 attr->data.imm_tp = ia32_ImmConst;
640 attr->cnst_val.tv = tv;
643 void set_ia32_Immop_symconst(ir_node *node, ir_entity *entity) {
644 ia32_attr_t *attr = get_ia32_attr(node);
645 attr->data.imm_tp = ia32_ImmSymConst;
646 attr->cnst_val.sc = entity;
649 ir_entity *get_ia32_Immop_symconst(const ir_node *node) {
650 const ia32_attr_t *attr = get_ia32_attr_const(node);
651 assert(attr->data.imm_tp == ia32_ImmSymConst);
652 return attr->cnst_val.sc;
656 * Sets the uses_frame flag.
658 void set_ia32_use_frame(ir_node *node) {
659 ia32_attr_t *attr = get_ia32_attr(node);
660 attr->data.use_frame = 1;
664 * Clears the uses_frame flag.
666 void clear_ia32_use_frame(ir_node *node) {
667 ia32_attr_t *attr = get_ia32_attr(node);
668 attr->data.use_frame = 0;
672 * Gets the uses_frame flag.
674 int is_ia32_use_frame(const ir_node *node) {
675 const ia32_attr_t *attr = get_ia32_attr_const(node);
676 return attr->data.use_frame;
680 * Sets node to commutative.
682 void set_ia32_commutative(ir_node *node) {
683 ia32_attr_t *attr = get_ia32_attr(node);
684 attr->data.is_commutative = 1;
688 * Sets node to non-commutative.
690 void clear_ia32_commutative(ir_node *node) {
691 ia32_attr_t *attr = get_ia32_attr(node);
692 attr->data.is_commutative = 0;
696 * Checks if node is commutative.
698 int is_ia32_commutative(const ir_node *node) {
699 const ia32_attr_t *attr = get_ia32_attr_const(node);
700 return attr->data.is_commutative;
706 void set_ia32_emit_cl(ir_node *node) {
707 ia32_attr_t *attr = get_ia32_attr(node);
708 attr->data.emit_cl = 1;
712 * Clears node emit_cl.
714 void clear_ia32_emit_cl(ir_node *node) {
715 ia32_attr_t *attr = get_ia32_attr(node);
716 attr->data.emit_cl = 0;
720 * Checks if node needs %cl.
722 int is_ia32_emit_cl(const ir_node *node) {
723 const ia32_attr_t *attr = get_ia32_attr_const(node);
724 return attr->data.emit_cl;
730 void set_ia32_got_lea(ir_node *node) {
731 ia32_attr_t *attr = get_ia32_attr(node);
732 attr->data.got_lea = 1;
736 * Clears node got_lea.
738 void clear_ia32_got_lea(ir_node *node) {
739 ia32_attr_t *attr = get_ia32_attr(node);
740 attr->data.got_lea = 0;
744 * Checks if node got lea.
746 int is_ia32_got_lea(const ir_node *node) {
747 const ia32_attr_t *attr = get_ia32_attr_const(node);
748 return attr->data.got_lea;
751 void set_ia32_need_stackent(ir_node *node) {
752 ia32_attr_t *attr = get_ia32_attr(node);
753 attr->data.need_stackent = 1;
756 void clear_ia32_need_stackent(ir_node *node) {
757 ia32_attr_t *attr = get_ia32_attr(node);
758 attr->data.need_stackent = 0;
761 int is_ia32_need_stackent(const ir_node *node) {
762 const ia32_attr_t *attr = get_ia32_attr_const(node);
763 return attr->data.need_stackent;
767 * Gets the mode of the stored/loaded value (only set for Store/Load)
769 ir_mode *get_ia32_ls_mode(const ir_node *node) {
770 const ia32_attr_t *attr = get_ia32_attr_const(node);
771 return attr->ls_mode;
775 * Sets the mode of the stored/loaded value (only set for Store/Load)
777 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
778 ia32_attr_t *attr = get_ia32_attr(node);
779 attr->ls_mode = mode;
783 * Gets the frame entity assigned to this node.
785 ir_entity *get_ia32_frame_ent(const ir_node *node) {
786 const ia32_attr_t *attr = get_ia32_attr_const(node);
787 return attr->frame_ent;
791 * Sets the frame entity for this node.
793 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
794 ia32_attr_t *attr = get_ia32_attr(node);
795 attr->frame_ent = ent;
797 set_ia32_use_frame(node);
799 clear_ia32_use_frame(node);
804 * Gets the instruction latency.
806 unsigned get_ia32_latency(const ir_node *node) {
807 const ia32_attr_t *attr = get_ia32_attr_const(node);
808 return attr->latency;
812 * Sets the instruction latency.
814 void set_ia32_latency(ir_node *node, unsigned latency) {
815 ia32_attr_t *attr = get_ia32_attr(node);
816 attr->latency = latency;
820 * Returns the argument register requirements of an ia32 node.
822 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
823 const ia32_attr_t *attr = get_ia32_attr_const(node);
828 * Sets the argument register requirements of an ia32 node.
830 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
831 ia32_attr_t *attr = get_ia32_attr(node);
836 * Returns the result register requirements of an ia32 node.
838 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
839 const ia32_attr_t *attr = get_ia32_attr_const(node);
840 return attr->out_req;
844 * Sets the result register requirements of an ia32 node.
846 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
847 ia32_attr_t *attr = get_ia32_attr(node);
848 attr->out_req = reqs;
852 * Returns the argument register requirement at position pos of an ia32 node.
854 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
855 const ia32_attr_t *attr = get_ia32_attr_const(node);
856 if(attr->in_req == NULL)
857 return arch_no_register_req;
859 return attr->in_req[pos];
863 * Returns the result register requirement at position pos of an ia32 node.
865 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
866 const ia32_attr_t *attr = get_ia32_attr_const(node);
867 if(attr->out_req == NULL)
868 return arch_no_register_req;
870 return attr->out_req[pos];
874 * Sets the OUT register requirements at position pos.
876 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
877 ia32_attr_t *attr = get_ia32_attr(node);
878 attr->out_req[pos] = req;
882 * Sets the IN register requirements at position pos.
884 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
885 ia32_attr_t *attr = get_ia32_attr(node);
886 attr->in_req[pos] = req;
890 * Returns the register flag of an ia32 node.
892 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
893 const ia32_attr_t *attr = get_ia32_attr_const(node);
894 return attr->data.flags;
898 * Sets the register flag of an ia32 node.
900 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
901 ia32_attr_t *attr = get_ia32_attr(node);
902 attr->data.flags = flags;
906 * Returns the result register slots of an ia32 node.
908 const arch_register_t **get_ia32_slots(const ir_node *node) {
909 const ia32_attr_t *attr = get_ia32_attr_const(node);
914 * Returns the number of results.
916 int get_ia32_n_res(const ir_node *node) {
917 const ia32_attr_t *attr = get_ia32_attr_const(node);
918 return ARR_LEN(attr->slots);
922 * Returns the flavour of an ia32 node,
924 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
925 const ia32_attr_t *attr = get_ia32_attr_const(node);
926 return attr->data.op_flav;
930 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
932 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
933 ia32_attr_t *attr = get_ia32_attr(node);
934 attr->data.op_flav = op_flav;
938 * Returns the projnum code.
940 long get_ia32_pncode(const ir_node *node)
942 const ia32_attr_t *attr = get_ia32_attr_const(node);
943 return attr->pn_code;
947 * Sets the projnum code
949 void set_ia32_pncode(ir_node *node, long code)
951 ia32_attr_t *attr = get_ia32_attr(node);
952 attr->pn_code = code;
956 * Sets the flags for the n'th out.
958 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
959 ia32_attr_t *attr = get_ia32_attr(node);
960 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
961 attr->out_flags[pos] = flags;
965 * Gets the flags for the n'th out.
967 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
968 const ia32_attr_t *attr = get_ia32_attr_const(node);
969 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
970 return attr->out_flags[pos];
974 * Get the list of available execution units.
976 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
977 const ia32_attr_t *attr = get_ia32_attr_const(node);
978 return attr->exec_units;
982 * Get the exception label attribute.
984 unsigned get_ia32_exc_label(const ir_node *node) {
985 const ia32_attr_t *attr = get_ia32_attr_const(node);
986 return attr->data.except_label;
990 * Set the exception label attribute.
992 void set_ia32_exc_label(ir_node *node, unsigned flag) {
993 ia32_attr_t *attr = get_ia32_attr(node);
994 attr->data.except_label = flag;
1000 * Returns the name of the original ir node.
1002 const char *get_ia32_orig_node(const ir_node *node) {
1003 const ia32_attr_t *attr = get_ia32_attr_const(node);
1004 return attr->orig_node;
1008 * Sets the name of the original ir node.
1010 void set_ia32_orig_node(ir_node *node, const char *name) {
1011 ia32_attr_t *attr = get_ia32_attr(node);
1012 attr->orig_node = name;
1017 /******************************************************************************************************
1019 * (_) | | | | | | / _| | | (_)
1020 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1021 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1022 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1023 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1026 ******************************************************************************************************/
1029 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1031 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
1032 ia32_immop_type_t immop_type = get_ia32_immop_type(from);
1034 if(immop_type == ia32_ImmConst) {
1035 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
1036 } else if(immop_type == ia32_ImmSymConst) {
1037 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
1039 ia32_attr_t *attr = get_ia32_attr(node);
1040 assert(immop_type == ia32_ImmNone);
1041 attr->data.imm_tp = ia32_ImmNone;
1046 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1048 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1049 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1051 switch (get_irn_opcode(cnst)) {
1053 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
1056 assert(get_SymConst_kind(cnst) == symconst_addr_ent);
1057 set_ia32_Immop_symconst(ia32_cnst, get_SymConst_entity(cnst));
1060 assert(0 && "Unknown Const NYI");
1063 assert(0 && "Cannot create ia32_Const for this opcode");
1067 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
1069 if(mode_is_reference(get_tarval_mode(tv))) {
1070 if(tarval_is_null(tv)) {
1071 tv = get_tarval_null(mode_Iu);
1075 if(!tarval_is_long(tv))
1076 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
1077 val = get_tarval_long(tv);
1078 tv = new_tarval_from_long(val, mode_Iu);
1081 tv = tarval_convert_to(tv, mode_Iu);
1084 tv = tarval_convert_to(tv, mode_Iu);
1087 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
1089 set_ia32_Immop_tarval(ia32_cnst, tv);
1094 * Sets the AddrMode(S|D) attribute
1096 void set_ia32_AddrMode(ir_node *node, char direction) {
1097 ia32_attr_t *attr = get_ia32_attr(node);
1099 switch (direction) {
1101 attr->data.tp = ia32_AddrModeD;
1104 attr->data.tp = ia32_AddrModeS;
1107 assert(0 && "wrong AM type");
1112 * Returns whether or not the node is an immediate operation with Const.
1114 int is_ia32_ImmConst(const ir_node *node) {
1115 const ia32_attr_t *attr = get_ia32_attr_const(node);
1116 return (attr->data.imm_tp == ia32_ImmConst);
1120 * Returns whether or not the node is an immediate operation with SymConst.
1122 int is_ia32_ImmSymConst(const ir_node *node) {
1123 const ia32_attr_t *attr = get_ia32_attr_const(node);
1124 return (attr->data.imm_tp == ia32_ImmSymConst);
1128 * Returns whether or not the node is an AddrModeS node.
1130 int is_ia32_AddrModeS(const ir_node *node) {
1131 const ia32_attr_t *attr = get_ia32_attr_const(node);
1132 return (attr->data.tp == ia32_AddrModeS);
1136 * Returns whether or not the node is an AddrModeD node.
1138 int is_ia32_AddrModeD(const ir_node *node) {
1139 const ia32_attr_t *attr = get_ia32_attr_const(node);
1140 return (attr->data.tp == ia32_AddrModeD);
1144 * Checks if node is a Load or xLoad/vfLoad.
1146 int is_ia32_Ld(const ir_node *node) {
1147 int op = get_ia32_irn_opcode(node);
1148 return op == iro_ia32_Load ||
1149 op == iro_ia32_xLoad ||
1150 op == iro_ia32_vfld ||
1155 * Checks if node is a Store or xStore/vfStore.
1157 int is_ia32_St(const ir_node *node) {
1158 int op = get_ia32_irn_opcode(node);
1159 return op == iro_ia32_Store ||
1160 op == iro_ia32_Store8Bit ||
1161 op == iro_ia32_xStore ||
1162 op == iro_ia32_vfst ||
1163 op == iro_ia32_fst ||
1164 op == iro_ia32_fstp;
1168 * Checks if node is a Const or xConst/vfConst.
1170 int is_ia32_Cnst(const ir_node *node) {
1171 int op = get_ia32_irn_opcode(node);
1172 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1176 * Returns the name of the OUT register at position pos.
1178 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1179 const ia32_attr_t *attr = get_ia32_attr_const(node);
1181 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1182 assert(attr->slots[pos] && "No register assigned");
1184 return arch_register_get_name(attr->slots[pos]);
1188 * Returns the index of the OUT register at position pos within its register class.
1190 int get_ia32_out_regnr(const ir_node *node, int pos) {
1191 const ia32_attr_t *attr = get_ia32_attr_const(node);
1193 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1194 assert(attr->slots[pos] && "No register assigned");
1196 return arch_register_get_index(attr->slots[pos]);
1199 void ia32_swap_left_right(ir_node *node)
1201 ir_node *left = get_irn_n(node, 2);
1202 ir_node *right = get_irn_n(node, 3);
1203 assert(is_ia32_commutative(node));
1204 set_irn_n(node, 2, right);
1205 set_irn_n(node, 3, left);
1206 set_ia32_pncode(node, get_inversed_pnc(get_ia32_pncode(node)));
1210 * Returns the OUT register at position pos.
1212 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1213 const ia32_attr_t *attr = get_ia32_attr_const(node);
1215 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1216 assert(attr->slots[pos] && "No register assigned");
1218 return attr->slots[pos];
1222 * Initializes the nodes attributes.
1224 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1225 const arch_register_req_t **in_reqs,
1226 const arch_register_req_t **out_reqs,
1227 const be_execution_unit_t ***execution_units,
1228 int n_res, unsigned latency)
1230 ir_graph *irg = get_irn_irg(node);
1231 struct obstack *obst = get_irg_obstack(irg);
1232 ia32_attr_t *attr = get_ia32_attr(node);
1234 set_ia32_flags(node, flags);
1235 set_ia32_in_req_all(node, in_reqs);
1236 set_ia32_out_req_all(node, out_reqs);
1237 set_ia32_latency(node, latency);
1239 attr->exec_units = execution_units;
1241 attr->attr_type |= IA32_ATTR_ia32_attr_t;
1244 attr->out_flags = NEW_ARR_D(int, obst, n_res);
1245 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1247 attr->slots = NEW_ARR_D(const arch_register_t*, obst, n_res);
1248 memset(attr->slots, 0, n_res * sizeof(attr->slots[0]));
1252 init_ia32_x87_attributes(ir_node *res)
1255 ia32_attr_t *attr = get_ia32_attr(res);
1256 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
1258 ia32_current_cg->do_x87_sim = 1;
1262 init_ia32_asm_attributes(ir_node *res)
1265 ia32_attr_t *attr = get_ia32_attr(res);
1266 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
1271 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
1272 int symconst_sign, long offset)
1274 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
1277 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
1279 attr->symconst = symconst;
1280 attr->attr.data.am_sc_sign = symconst_sign;
1281 attr->offset = offset;
1284 ir_node *get_ia32_result_proj(const ir_node *node)
1286 const ir_edge_t *edge;
1288 foreach_out_edge(node, edge) {
1289 ir_node *proj = get_edge_src_irn(edge);
1290 if(get_Proj_proj(proj) == 0) {
1297 /***************************************************************************************
1300 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1301 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1302 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1303 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1305 ***************************************************************************************/
1307 /* default compare operation to compare attributes */
1308 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
1309 if (a->data.tp != b->data.tp
1310 || a->data.imm_tp != b->data.imm_tp)
1313 if (a->data.imm_tp == ia32_ImmConst
1314 && a->cnst_val.tv != b->cnst_val.tv)
1317 if (a->data.imm_tp == ia32_ImmSymConst
1318 && a->cnst_val.sc != b->cnst_val.sc)
1321 if (a->data.am_flavour != b->data.am_flavour
1322 || a->data.am_scale != b->data.am_scale
1323 || a->data.am_sc_sign != b->data.am_sc_sign
1324 || a->am_offs != b->am_offs
1325 || a->am_sc != b->am_sc
1326 || a->ls_mode != b->ls_mode)
1329 /* nodes with not yet assigned entities shouldn't be CSEd (important for
1330 * unsigned int -> double conversions */
1331 if(a->data.use_frame && a->frame_ent == NULL)
1333 if(b->data.use_frame && b->frame_ent == NULL)
1336 if (a->data.use_frame != b->data.use_frame
1337 || a->frame_ent != b->frame_ent)
1340 if(a->pn_code != b->pn_code)
1343 if (a->data.tp != b->data.tp
1344 || a->data.op_flav != b->data.op_flav)
1347 if (a->data.except_label != b->data.except_label)
1354 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1356 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1357 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1359 return ia32_compare_attr(attr_a, attr_b);
1363 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1365 return ia32_compare_nodes_attr(a, b);
1369 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1371 const ia32_asm_attr_t *attr_a;
1372 const ia32_asm_attr_t *attr_b;
1374 if(ia32_compare_nodes_attr(a, b))
1377 attr_a = get_ia32_asm_attr_const(a);
1378 attr_b = get_ia32_asm_attr_const(b);
1380 if(attr_a->asm_text != attr_b->asm_text)
1387 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1389 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1390 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1392 if(attr_a->symconst != attr_b->symconst ||
1393 attr_a->attr.data.am_sc_sign != attr_b->attr.data.am_sc_sign ||
1394 attr_a->offset != attr_b->offset)
1400 /* copies the ia32 attributes */
1401 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1403 ir_graph *irg = get_irn_irg(new_node);
1404 struct obstack *obst = get_irg_obstack(irg);
1405 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1406 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1408 /* copy the attributes */
1409 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1411 /* copy out flags */
1412 attr_new->out_flags =
1413 DUP_ARR_D(int, obst, attr_old->out_flags);
1414 /* copy register assignments */
1416 DUP_ARR_D(arch_register_t*, obst, attr_old->slots);
1419 /* Include the generated constructor functions */
1420 #include "gen_ia32_new_nodes.c.inl"