2 * This file implements the creation of the achitecture specific firm opcodes
3 * and the coresponding node constructors for the ia32 assembler irg.
4 * @author Christian Wuerdig
14 #include "irgraph_t.h"
20 #include "firm_common_t.h"
25 #include "raw_bitset.h"
28 #include "../bearch_t.h"
30 #include "bearch_ia32_t.h"
31 #include "ia32_nodes_attr.h"
32 #include "ia32_new_nodes.h"
33 #include "gen_ia32_regalloc_if.h"
34 #include "gen_ia32_machine.h"
37 * returns true if a node has x87 registers
39 int ia32_has_x87_register(const ir_node *n) {
40 assert(is_ia32_irn(n) && "Need ia32 node.");
41 return is_irn_machine_user(n, 0);
44 /***********************************************************************************
47 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
48 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
49 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
50 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
53 ***********************************************************************************/
56 * Dumps the register requirements for either in or out.
58 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
60 char *dir = inout ? "out" : "in";
61 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
65 memset(buf, 0, sizeof(buf));
68 for (i = 0; i < max; i++) {
69 fprintf(F, "%sreq #%d =", dir, i);
71 if (reqs[i]->type == arch_register_req_type_none) {
75 if (reqs[i]->type & arch_register_req_type_normal) {
76 fprintf(F, " %s", reqs[i]->cls->name);
79 if (reqs[i]->type & arch_register_req_type_limited) {
81 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
84 if (reqs[i]->type & arch_register_req_type_should_be_same) {
85 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
88 if (reqs[i]->type & arch_register_req_type_should_be_different) {
89 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
98 fprintf(F, "%sreq = N/A\n", dir);
103 * Dumper interface for dumping ia32 nodes in vcg.
104 * @param n the node to dump
105 * @param F the output file
106 * @param reason indicates which kind of information should be dumped
107 * @return 0 on success or != 0 on failure
109 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
110 ir_mode *mode = NULL;
112 int i, n_res, am_flav, flags;
113 const arch_register_req_t **reqs;
114 const arch_register_t **slots;
117 case dump_node_opcode_txt:
118 fprintf(F, "%s", get_irn_opname(n));
121 case dump_node_mode_txt:
122 mode = get_irn_mode(n);
124 if (is_ia32_Ld(n) || is_ia32_St(n)) {
125 mode = get_ia32_ls_mode(n);
128 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
131 case dump_node_nodeattr_txt:
132 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
133 if(is_ia32_ImmSymConst(n)) {
134 ir_entity *ent = get_ia32_Immop_symconst(n);
135 ident *id = get_entity_ld_ident(ent);
136 fprintf(F, "[SymC %s]", get_id_str(id));
139 tarval *tv = get_ia32_Immop_tarval(n);
141 tarval_snprintf(buf, sizeof(buf), tv);
142 fprintf(F, "[%s]", buf);
146 if (! is_ia32_Lea(n)) {
147 if (is_ia32_AddrModeS(n)) {
148 fprintf(F, "[AM S] ");
150 else if (is_ia32_AddrModeD(n)) {
151 fprintf(F, "[AM D] ");
157 case dump_node_info_txt:
158 n_res = get_ia32_n_res(n);
159 fprintf(F, "=== IA32 attr begin ===\n");
161 /* dump IN requirements */
162 if (get_irn_arity(n) > 0) {
163 reqs = get_ia32_in_req_all(n);
164 dump_reg_req(F, n, reqs, 0);
167 /* dump OUT requirements */
169 reqs = get_ia32_out_req_all(n);
170 dump_reg_req(F, n, reqs, 1);
173 /* dump assigned registers */
174 slots = get_ia32_slots(n);
175 if (slots && n_res > 0) {
176 for (i = 0; i < n_res; i++) {
177 const arch_register_t *reg;
179 /* retrieve "real" x87 register */
180 if (ia32_has_x87_register(n))
181 reg = get_ia32_attr(n)->x87[i + 2];
185 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
192 switch (get_ia32_op_type(n)) {
194 fprintf(F, "Normal");
197 fprintf(F, "AM Dest (Load+Store)");
200 fprintf(F, "AM Source (Load)");
203 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
208 /* dump immop type */
209 fprintf(F, "immediate = ");
210 switch (get_ia32_immop_type(n)) {
217 case ia32_ImmSymConst:
218 fprintf(F, "SymConst");
221 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
226 /* dump supported am */
227 fprintf(F, "AM support = ");
228 switch (get_ia32_am_support(n)) {
233 fprintf(F, "source only (Load)");
236 fprintf(F, "dest only (Load+Store)");
242 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
247 /* dump am flavour */
248 fprintf(F, "AM flavour =");
249 am_flav = get_ia32_am_flavour(n);
250 if (am_flav == ia32_am_N) {
254 if (am_flav & ia32_O) {
257 if (am_flav & ia32_B) {
260 if (am_flav & ia32_I) {
263 if (am_flav & ia32_S) {
267 fprintf(F, " (%d)\n", am_flav);
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(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
286 fprintf(F, "pn_code = %d (%s, unsigned)\n", get_ia32_pncode(n),
287 get_pnc_string(get_ia32_pncode(n) & ~ia32_pn_Cmp_Unsigned));
289 fprintf(F, "pn_code = %d (%s)\n", get_ia32_pncode(n),
290 get_pnc_string(get_ia32_pncode(n)));
294 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
297 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
300 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
303 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
306 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
309 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
312 fprintf(F, "latency = %d\n", get_ia32_latency(n));
315 fprintf(F, "flags =");
316 flags = get_ia32_flags(n);
317 if (flags == arch_irn_flags_none) {
321 if (flags & arch_irn_flags_dont_spill) {
322 fprintf(F, " unspillable");
324 if (flags & arch_irn_flags_rematerializable) {
325 fprintf(F, " remat");
327 if (flags & arch_irn_flags_ignore) {
328 fprintf(F, " ignore");
330 if (flags & arch_irn_flags_modify_sp) {
331 fprintf(F, " modify_sp");
334 fprintf(F, " (%d)\n", flags);
336 /* dump frame entity */
337 fprintf(F, "frame entity = ");
338 if (get_ia32_frame_ent(n)) {
339 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
347 fprintf(F, "ls_mode = ");
348 if (get_ia32_ls_mode(n)) {
349 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
357 /* dump original ir node name */
358 fprintf(F, "orig node = ");
359 if (get_ia32_orig_node(n)) {
360 fprintf(F, "%s", get_ia32_orig_node(n));
368 fprintf(F, "=== IA32 attr end ===\n");
369 /* end of: case dump_node_info_txt */
378 /***************************************************************************************************
380 * | | | | | | / / | | | | | | | |
381 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
382 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
383 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
384 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
387 ***************************************************************************************************/
390 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
391 * Firm was made by people hating const :-(
393 ia32_attr_t *get_ia32_attr(const ir_node *node) {
394 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
395 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
399 * Gets the type of an ia32 node.
401 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
402 ia32_attr_t *attr = get_ia32_attr(node);
403 return attr->data.tp;
407 * Sets the type of an ia32 node.
409 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
410 ia32_attr_t *attr = get_ia32_attr(node);
415 * Gets the immediate op type of an ia32 node.
417 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
418 ia32_attr_t *attr = get_ia32_attr(node);
419 return attr->data.imm_tp;
423 * Gets the supported addrmode of an ia32 node
425 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
426 ia32_attr_t *attr = get_ia32_attr(node);
427 return attr->data.am_support;
431 * Sets the supported addrmode of an ia32 node
433 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
434 ia32_attr_t *attr = get_ia32_attr(node);
435 attr->data.am_support = am_tp;
439 * Gets the addrmode flavour of an ia32 node
441 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
442 ia32_attr_t *attr = get_ia32_attr(node);
443 return attr->data.am_flavour;
447 * Sets the addrmode flavour of an ia32 node
449 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
450 ia32_attr_t *attr = get_ia32_attr(node);
451 attr->data.am_flavour = am_flavour;
455 * Gets the addressmode offset as int.
457 int get_ia32_am_offs_int(const ir_node *node) {
458 ia32_attr_t *attr = get_ia32_attr(node);
459 return attr->am_offs;
463 * Sets the addressmode offset from an int.
465 void set_ia32_am_offs_int(ir_node *node, int offset) {
466 ia32_attr_t *attr = get_ia32_attr(node);
467 attr->am_offs = offset;
470 void add_ia32_am_offs_int(ir_node *node, int offset) {
471 ia32_attr_t *attr = get_ia32_attr(node);
472 attr->am_offs += offset;
476 * Returns the symconst entity associated to addrmode.
478 ir_entity *get_ia32_am_sc(const ir_node *node) {
479 ia32_attr_t *attr = get_ia32_attr(node);
484 * Sets the symconst entity associated to addrmode.
486 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
487 ia32_attr_t *attr = get_ia32_attr(node);
488 attr->am_sc = entity;
492 * Sets the sign bit for address mode symconst.
494 void set_ia32_am_sc_sign(ir_node *node) {
495 ia32_attr_t *attr = get_ia32_attr(node);
496 attr->data.am_sc_sign = 1;
500 * Clears the sign bit for address mode symconst.
502 void clear_ia32_am_sc_sign(ir_node *node) {
503 ia32_attr_t *attr = get_ia32_attr(node);
504 attr->data.am_sc_sign = 0;
508 * Returns the sign bit for address mode symconst.
510 int is_ia32_am_sc_sign(const ir_node *node) {
511 ia32_attr_t *attr = get_ia32_attr(node);
512 return attr->data.am_sc_sign;
516 * Gets the addr mode const.
518 int get_ia32_am_scale(const ir_node *node) {
519 ia32_attr_t *attr = get_ia32_attr(node);
520 return attr->data.am_scale;
524 * Sets the index register scale for addrmode.
526 void set_ia32_am_scale(ir_node *node, int scale) {
527 ia32_attr_t *attr = get_ia32_attr(node);
528 attr->data.am_scale = scale;
532 * Return the tarval of an immediate operation or NULL in case of SymConst
534 tarval *get_ia32_Immop_tarval(const ir_node *node) {
535 ia32_attr_t *attr = get_ia32_attr(node);
536 assert(attr->data.imm_tp == ia32_ImmConst);
537 return attr->cnst_val.tv;
541 * Sets the attributes of an immediate operation to the specified tarval
543 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
544 ia32_attr_t *attr = get_ia32_attr(node);
545 attr->data.imm_tp = ia32_ImmConst;
546 attr->cnst_val.tv = tv;
549 void set_ia32_Immop_symconst(ir_node *node, ir_entity *entity) {
550 ia32_attr_t *attr = get_ia32_attr(node);
551 attr->data.imm_tp = ia32_ImmSymConst;
552 attr->cnst_val.sc = entity;
555 ir_entity *get_ia32_Immop_symconst(const ir_node *node) {
556 ia32_attr_t *attr = get_ia32_attr(node);
557 assert(attr->data.imm_tp == ia32_ImmSymConst);
558 return attr->cnst_val.sc;
562 * Sets the uses_frame flag.
564 void set_ia32_use_frame(ir_node *node) {
565 ia32_attr_t *attr = get_ia32_attr(node);
566 attr->data.use_frame = 1;
570 * Clears the uses_frame flag.
572 void clear_ia32_use_frame(ir_node *node) {
573 ia32_attr_t *attr = get_ia32_attr(node);
574 attr->data.use_frame = 0;
578 * Gets the uses_frame flag.
580 int is_ia32_use_frame(const ir_node *node) {
581 ia32_attr_t *attr = get_ia32_attr(node);
582 return attr->data.use_frame;
586 * Sets node to commutative.
588 void set_ia32_commutative(ir_node *node) {
589 ia32_attr_t *attr = get_ia32_attr(node);
590 attr->data.is_commutative = 1;
594 * Sets node to non-commutative.
596 void clear_ia32_commutative(ir_node *node) {
597 ia32_attr_t *attr = get_ia32_attr(node);
598 attr->data.is_commutative = 0;
602 * Checks if node is commutative.
604 int is_ia32_commutative(const ir_node *node) {
605 ia32_attr_t *attr = get_ia32_attr(node);
606 return attr->data.is_commutative;
612 void set_ia32_emit_cl(ir_node *node) {
613 ia32_attr_t *attr = get_ia32_attr(node);
614 attr->data.emit_cl = 1;
618 * Clears node emit_cl.
620 void clear_ia32_emit_cl(ir_node *node) {
621 ia32_attr_t *attr = get_ia32_attr(node);
622 attr->data.emit_cl = 0;
626 * Checks if node needs %cl.
628 int is_ia32_emit_cl(const ir_node *node) {
629 ia32_attr_t *attr = get_ia32_attr(node);
630 return attr->data.emit_cl;
636 void set_ia32_got_lea(ir_node *node) {
637 ia32_attr_t *attr = get_ia32_attr(node);
638 attr->data.got_lea = 1;
642 * Clears node got_lea.
644 void clear_ia32_got_lea(ir_node *node) {
645 ia32_attr_t *attr = get_ia32_attr(node);
646 attr->data.got_lea = 0;
650 * Checks if node got lea.
652 int is_ia32_got_lea(const ir_node *node) {
653 ia32_attr_t *attr = get_ia32_attr(node);
654 return attr->data.got_lea;
657 void set_ia32_need_stackent(ir_node *node) {
658 ia32_attr_t *attr = get_ia32_attr(node);
659 attr->data.need_stackent = 1;
662 void clear_ia32_need_stackent(ir_node *node) {
663 ia32_attr_t *attr = get_ia32_attr(node);
664 attr->data.need_stackent = 0;
667 int is_ia32_need_stackent(const ir_node *node) {
668 ia32_attr_t *attr = get_ia32_attr(node);
669 return attr->data.need_stackent;
673 * Gets the mode of the stored/loaded value (only set for Store/Load)
675 ir_mode *get_ia32_ls_mode(const ir_node *node) {
676 ia32_attr_t *attr = get_ia32_attr(node);
677 return attr->ls_mode;
681 * Sets the mode of the stored/loaded value (only set for Store/Load)
683 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
684 ia32_attr_t *attr = get_ia32_attr(node);
685 attr->ls_mode = mode;
689 * Gets the frame entity assigned to this node.
691 ir_entity *get_ia32_frame_ent(const ir_node *node) {
692 ia32_attr_t *attr = get_ia32_attr(node);
693 return attr->frame_ent;
697 * Sets the frame entity for this node.
699 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
700 ia32_attr_t *attr = get_ia32_attr(node);
701 attr->frame_ent = ent;
703 set_ia32_use_frame(node);
705 clear_ia32_use_frame(node);
710 * Gets the instruction latency.
712 unsigned get_ia32_latency(const ir_node *node) {
713 ia32_attr_t *attr = get_ia32_attr(node);
714 return attr->latency;
718 * Sets the instruction latency.
720 void set_ia32_latency(ir_node *node, unsigned latency) {
721 ia32_attr_t *attr = get_ia32_attr(node);
722 attr->latency = latency;
726 * Returns the argument register requirements of an ia32 node.
728 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
729 ia32_attr_t *attr = get_ia32_attr(node);
734 * Sets the argument register requirements of an ia32 node.
736 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
737 ia32_attr_t *attr = get_ia32_attr(node);
742 * Returns the result register requirements of an ia32 node.
744 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
745 ia32_attr_t *attr = get_ia32_attr(node);
746 return attr->out_req;
750 * Sets the result register requirements of an ia32 node.
752 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
753 ia32_attr_t *attr = get_ia32_attr(node);
754 attr->out_req = reqs;
758 * Returns the argument register requirement at position pos of an ia32 node.
760 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
761 ia32_attr_t *attr = get_ia32_attr(node);
762 if(attr->in_req == NULL)
763 return arch_no_register_req;
765 return attr->in_req[pos];
769 * Returns the result register requirement at position pos of an ia32 node.
771 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
772 ia32_attr_t *attr = get_ia32_attr(node);
773 if(attr->out_req == NULL)
774 return arch_no_register_req;
776 return attr->out_req[pos];
780 * Sets the OUT register requirements at position pos.
782 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
783 ia32_attr_t *attr = get_ia32_attr(node);
784 attr->out_req[pos] = req;
788 * Sets the IN register requirements at position pos.
790 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
791 ia32_attr_t *attr = get_ia32_attr(node);
792 attr->in_req[pos] = req;
796 * Returns the register flag of an ia32 node.
798 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
799 ia32_attr_t *attr = get_ia32_attr(node);
800 return attr->data.flags;
804 * Sets the register flag of an ia32 node.
806 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
807 ia32_attr_t *attr = get_ia32_attr(node);
808 attr->data.flags = flags;
812 * Returns the result register slots of an ia32 node.
814 const arch_register_t **get_ia32_slots(const ir_node *node) {
815 ia32_attr_t *attr = get_ia32_attr(node);
820 * Sets the number of results.
822 void set_ia32_n_res(ir_node *node, int n_res) {
823 ia32_attr_t *attr = get_ia32_attr(node);
824 attr->data.n_res = n_res;
828 * Returns the number of results.
830 int get_ia32_n_res(const ir_node *node) {
831 ia32_attr_t *attr = get_ia32_attr(node);
832 return attr->data.n_res;
836 * Returns the flavour of an ia32 node,
838 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
839 ia32_attr_t *attr = get_ia32_attr(node);
840 return attr->data.op_flav;
844 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
846 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
847 ia32_attr_t *attr = get_ia32_attr(node);
848 attr->data.op_flav = op_flav;
852 * Returns the projnum code.
854 pn_Cmp get_ia32_pncode(const ir_node *node) {
855 ia32_attr_t *attr = get_ia32_attr(node);
856 return attr->pn_code;
860 * Sets the projnum code
862 void set_ia32_pncode(ir_node *node, pn_Cmp code) {
863 ia32_attr_t *attr = get_ia32_attr(node);
864 attr->pn_code = code;
868 * Sets the flags for the n'th out.
870 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
871 ia32_attr_t *attr = get_ia32_attr(node);
872 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
873 attr->out_flags[pos] = flags;
877 * Gets the flags for the n'th out.
879 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
880 ia32_attr_t *attr = get_ia32_attr(node);
881 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
885 * Get the list of available execution units.
887 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
888 ia32_attr_t *attr = get_ia32_attr(node);
889 return attr->exec_units;
895 * Returns the name of the original ir node.
897 const char *get_ia32_orig_node(const ir_node *node) {
898 ia32_attr_t *attr = get_ia32_attr(node);
899 return attr->orig_node;
903 * Sets the name of the original ir node.
905 void set_ia32_orig_node(ir_node *node, const char *name) {
906 ia32_attr_t *attr = get_ia32_attr(node);
907 attr->orig_node = name;
912 /******************************************************************************************************
914 * (_) | | | | | | / _| | | (_)
915 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
916 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
917 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
918 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
921 ******************************************************************************************************/
924 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
926 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
927 ia32_immop_type_t immop_type = get_ia32_immop_type(from);
929 if(immop_type == ia32_ImmConst) {
930 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
931 } else if(immop_type == ia32_ImmSymConst) {
932 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
934 ia32_attr_t *attr = get_ia32_attr(node);
935 assert(immop_type == ia32_ImmNone);
936 attr->data.imm_tp = ia32_ImmNone;
941 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
943 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
944 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
946 switch (get_irn_opcode(cnst)) {
948 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
951 assert(get_SymConst_kind(cnst) == symconst_addr_ent);
952 set_ia32_Immop_symconst(ia32_cnst, get_SymConst_entity(cnst));
955 assert(0 && "Unknown Const NYI");
958 assert(0 && "Cannot create ia32_Const for this opcode");
962 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
963 if(mode_is_reference(get_tarval_mode(tv))) {
964 if(tarval_is_null(tv)) {
965 tv = get_tarval_null(mode_Iu);
967 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
970 tv = tarval_convert_to(tv, mode_Iu);
973 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
975 set_ia32_Immop_tarval(ia32_cnst, tv);
980 * Sets the AddrMode(S|D) attribute
982 void set_ia32_AddrMode(ir_node *node, char direction) {
983 ia32_attr_t *attr = get_ia32_attr(node);
987 attr->data.tp = ia32_AddrModeD;
990 attr->data.tp = ia32_AddrModeS;
993 assert(0 && "wrong AM type");
998 * Returns whether or not the node is an immediate operation with Const.
1000 int is_ia32_ImmConst(const ir_node *node) {
1001 ia32_attr_t *attr = get_ia32_attr(node);
1002 return (attr->data.imm_tp == ia32_ImmConst);
1006 * Returns whether or not the node is an immediate operation with SymConst.
1008 int is_ia32_ImmSymConst(const ir_node *node) {
1009 ia32_attr_t *attr = get_ia32_attr(node);
1010 return (attr->data.imm_tp == ia32_ImmSymConst);
1014 * Returns whether or not the node is an AddrModeS node.
1016 int is_ia32_AddrModeS(const ir_node *node) {
1017 ia32_attr_t *attr = get_ia32_attr(node);
1018 return (attr->data.tp == ia32_AddrModeS);
1022 * Returns whether or not the node is an AddrModeD node.
1024 int is_ia32_AddrModeD(const ir_node *node) {
1025 ia32_attr_t *attr = get_ia32_attr(node);
1026 return (attr->data.tp == ia32_AddrModeD);
1030 * Checks if node is a Load or xLoad/vfLoad.
1032 int is_ia32_Ld(const ir_node *node) {
1033 int op = get_ia32_irn_opcode(node);
1034 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1038 * Checks if node is a Store or xStore/vfStore.
1040 int is_ia32_St(const ir_node *node) {
1041 int op = get_ia32_irn_opcode(node);
1042 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1046 * Checks if node is a Const or xConst/vfConst.
1048 int is_ia32_Cnst(const ir_node *node) {
1049 int op = get_ia32_irn_opcode(node);
1050 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1054 * Returns the name of the OUT register at position pos.
1056 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1057 ia32_attr_t *attr = get_ia32_attr(node);
1059 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1060 assert(attr->slots[pos] && "No register assigned");
1062 return arch_register_get_name(attr->slots[pos]);
1066 * Returns the index of the OUT register at position pos within its register class.
1068 int get_ia32_out_regnr(const ir_node *node, int pos) {
1069 ia32_attr_t *attr = get_ia32_attr(node);
1071 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1072 assert(attr->slots[pos] && "No register assigned");
1074 return arch_register_get_index(attr->slots[pos]);
1078 * Returns the OUT register at position pos.
1080 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1081 ia32_attr_t *attr = get_ia32_attr(node);
1083 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1084 assert(attr->slots[pos] && "No register assigned");
1086 return attr->slots[pos];
1090 * Initializes the nodes attributes.
1092 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1093 const arch_register_req_t **in_reqs,
1094 const arch_register_req_t **out_reqs,
1095 const be_execution_unit_t ***execution_units,
1096 int n_res, unsigned latency)
1098 ia32_attr_t *attr = get_ia32_attr(node);
1100 set_ia32_flags(node, flags);
1101 set_ia32_in_req_all(node, in_reqs);
1102 set_ia32_out_req_all(node, out_reqs);
1103 set_ia32_latency(node, latency);
1104 set_ia32_n_res(node, n_res);
1106 attr->exec_units = execution_units;
1108 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1109 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1111 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1114 ir_node *get_ia32_result_proj(const ir_node *node)
1116 const ir_edge_t *edge;
1118 foreach_out_edge(node, edge) {
1119 ir_node *proj = get_edge_src_irn(edge);
1120 if(get_Proj_proj(proj) == 0) {
1127 /***************************************************************************************
1130 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1131 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1132 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1133 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1135 ***************************************************************************************/
1137 /* default compare operation to compare attributes */
1138 int ia32_compare_attr(ia32_attr_t *a, ia32_attr_t *b) {
1139 if (a->data.tp != b->data.tp
1140 || a->data.imm_tp != b->data.imm_tp)
1143 if (a->data.imm_tp == ia32_ImmConst
1144 && a->cnst_val.tv != b->cnst_val.tv)
1147 if (a->data.imm_tp == ia32_ImmSymConst
1148 && a->cnst_val.sc != b->cnst_val.sc)
1151 if (a->data.am_flavour != b->data.am_flavour
1152 || a->data.am_scale != b->data.am_scale
1153 || a->data.offs_sign != b->data.offs_sign
1154 || a->data.am_sc_sign != b->data.am_sc_sign
1155 || a->am_offs != b->am_offs
1156 || a->am_sc != b->am_sc
1157 || a->ls_mode != b->ls_mode)
1160 if (a->data.use_frame != b->data.use_frame
1161 || a->data.use_frame != b->data.use_frame
1162 || a->frame_ent != b->frame_ent)
1165 if(a->pn_code != b->pn_code)
1168 if (a->data.tp != b->data.tp
1169 || a->data.op_flav != b->data.op_flav)
1175 /* copies the ia32 attributes */
1176 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1177 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1178 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1180 /* copy the attributes */
1181 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1183 /* copy out flags */
1184 attr_new->out_flags =
1185 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1189 * Registers the ia32_copy_attr function for all ia32 opcodes.
1191 void ia32_register_copy_attr_func(void) {
1192 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1194 for (i = f; i < l; i++) {
1195 ir_op *op = get_irp_opcode(i);
1196 op->ops.copy_attr = ia32_copy_attr;
1200 /* Include the generated constructor functions */
1201 #include "gen_ia32_new_nodes.c.inl"