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
22 #include "irgraph_t.h"
28 #include "firm_common_t.h"
33 #include "raw_bitset.h"
35 #include "../bearch.h"
37 #include "ia32_nodes_attr.h"
38 #include "ia32_new_nodes.h"
39 #include "gen_ia32_regalloc_if.h"
40 #include "gen_ia32_machine.h"
43 * returns true if a node has x87 registers
45 int ia32_has_x87_register(const ir_node *n) {
46 assert(is_ia32_irn(n) && "Need ia32 node.");
47 return is_irn_machine_user(n, 0);
50 /***********************************************************************************
53 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
54 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
55 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
56 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
59 ***********************************************************************************/
62 * Dumps the register requirements for either in or out.
64 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
66 char *dir = inout ? "out" : "in";
67 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
71 memset(buf, 0, sizeof(buf));
74 for (i = 0; i < max; i++) {
75 fprintf(F, "%sreq #%d =", dir, i);
77 if (reqs[i]->type == arch_register_req_type_none) {
81 if (reqs[i]->type & arch_register_req_type_normal) {
82 fprintf(F, " %s", reqs[i]->cls->name);
85 if (reqs[i]->type & arch_register_req_type_limited) {
87 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
90 if (reqs[i]->type & arch_register_req_type_should_be_same) {
91 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
94 if (reqs[i]->type & arch_register_req_type_should_be_different) {
95 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
104 fprintf(F, "%sreq = N/A\n", dir);
109 * Dumper interface for dumping ia32 nodes in vcg.
110 * @param n the node to dump
111 * @param F the output file
112 * @param reason indicates which kind of information should be dumped
113 * @return 0 on success or != 0 on failure
115 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
116 ir_mode *mode = NULL;
118 int i, n_res, am_flav, flags;
119 const arch_register_req_t **reqs;
120 const arch_register_t **slots;
123 case dump_node_opcode_txt:
124 fprintf(F, "%s", get_irn_opname(n));
127 case dump_node_mode_txt:
128 mode = get_irn_mode(n);
130 if (is_ia32_Ld(n) || is_ia32_St(n)) {
131 mode = get_ia32_ls_mode(n);
134 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
137 case dump_node_nodeattr_txt:
138 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
139 if(is_ia32_ImmSymConst(n)) {
140 ir_entity *ent = get_ia32_Immop_symconst(n);
141 ident *id = get_entity_ld_ident(ent);
142 fprintf(F, "[SymC %s]", get_id_str(id));
145 tarval *tv = get_ia32_Immop_tarval(n);
147 tarval_snprintf(buf, sizeof(buf), tv);
148 fprintf(F, "[%s]", buf);
152 if (! is_ia32_Lea(n)) {
153 if (is_ia32_AddrModeS(n)) {
154 fprintf(F, "[AM S] ");
156 else if (is_ia32_AddrModeD(n)) {
157 fprintf(F, "[AM D] ");
163 case dump_node_info_txt:
164 n_res = get_ia32_n_res(n);
165 fprintf(F, "=== IA32 attr begin ===\n");
167 /* dump IN requirements */
168 if (get_irn_arity(n) > 0) {
169 reqs = get_ia32_in_req_all(n);
170 dump_reg_req(F, n, reqs, 0);
173 /* dump OUT requirements */
175 reqs = get_ia32_out_req_all(n);
176 dump_reg_req(F, n, reqs, 1);
179 /* dump assigned registers */
180 slots = get_ia32_slots(n);
181 if (slots && n_res > 0) {
182 for (i = 0; i < n_res; i++) {
183 const arch_register_t *reg;
185 /* retrieve "real" x87 register */
186 if (ia32_has_x87_register(n))
187 reg = get_ia32_attr(n)->x87[i + 2];
191 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
198 switch (get_ia32_op_type(n)) {
200 fprintf(F, "Normal");
203 fprintf(F, "AM Dest (Load+Store)");
206 fprintf(F, "AM Source (Load)");
209 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
214 /* dump immop type */
215 fprintf(F, "immediate = ");
216 switch (get_ia32_immop_type(n)) {
223 case ia32_ImmSymConst:
224 fprintf(F, "SymConst");
227 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
232 /* dump supported am */
233 fprintf(F, "AM support = ");
234 switch (get_ia32_am_support(n)) {
239 fprintf(F, "source only (Load)");
242 fprintf(F, "dest only (Load+Store)");
248 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
253 /* dump am flavour */
254 fprintf(F, "AM flavour =");
255 am_flav = get_ia32_am_flavour(n);
256 if (am_flav == ia32_am_N) {
260 if (am_flav & ia32_O) {
263 if (am_flav & ia32_B) {
266 if (am_flav & ia32_I) {
269 if (am_flav & ia32_S) {
273 fprintf(F, " (%d)\n", am_flav);
276 if(get_ia32_am_offs_int(n) != 0) {
277 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
280 /* dump AM symconst */
281 if(get_ia32_am_sc(n) != NULL) {
282 ir_entity *ent = get_ia32_am_sc(n);
283 ident *id = get_entity_ld_ident(ent);
284 fprintf(F, "AM symconst = %s\n", get_id_str(id));
288 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
291 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
292 fprintf(F, "pn_code = %d (%s, unsigned)\n", get_ia32_pncode(n),
293 get_pnc_string(get_ia32_pncode(n) & ~ia32_pn_Cmp_Unsigned));
295 fprintf(F, "pn_code = %d (%s)\n", get_ia32_pncode(n),
296 get_pnc_string(get_ia32_pncode(n)));
300 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
303 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
306 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
309 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
312 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
315 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
318 fprintf(F, "latency = %d\n", get_ia32_latency(n));
321 fprintf(F, "flags =");
322 flags = get_ia32_flags(n);
323 if (flags == arch_irn_flags_none) {
327 if (flags & arch_irn_flags_dont_spill) {
328 fprintf(F, " unspillable");
330 if (flags & arch_irn_flags_rematerializable) {
331 fprintf(F, " remat");
333 if (flags & arch_irn_flags_ignore) {
334 fprintf(F, " ignore");
336 if (flags & arch_irn_flags_modify_sp) {
337 fprintf(F, " modify_sp");
340 fprintf(F, " (%d)\n", flags);
342 /* dump frame entity */
343 fprintf(F, "frame entity = ");
344 if (get_ia32_frame_ent(n)) {
345 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
353 fprintf(F, "ls_mode = ");
354 if (get_ia32_ls_mode(n)) {
355 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
363 /* dump original ir node name */
364 fprintf(F, "orig node = ");
365 if (get_ia32_orig_node(n)) {
366 fprintf(F, "%s", get_ia32_orig_node(n));
374 fprintf(F, "=== IA32 attr end ===\n");
375 /* end of: case dump_node_info_txt */
384 /***************************************************************************************************
386 * | | | | | | / / | | | | | | | |
387 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
388 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
389 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
390 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
393 ***************************************************************************************************/
396 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
397 * Firm was made by people hating const :-(
399 ia32_attr_t *get_ia32_attr(const ir_node *node) {
400 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
401 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
405 * Gets the type of an ia32 node.
407 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
408 ia32_attr_t *attr = get_ia32_attr(node);
409 return attr->data.tp;
413 * Sets the type of an ia32 node.
415 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
416 ia32_attr_t *attr = get_ia32_attr(node);
421 * Gets the immediate op type of an ia32 node.
423 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
424 ia32_attr_t *attr = get_ia32_attr(node);
425 return attr->data.imm_tp;
429 * Gets the supported addrmode of an ia32 node
431 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
432 ia32_attr_t *attr = get_ia32_attr(node);
433 return attr->data.am_support;
437 * Sets the supported addrmode of an ia32 node
439 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
440 ia32_attr_t *attr = get_ia32_attr(node);
441 attr->data.am_support = am_tp;
445 * Gets the addrmode flavour of an ia32 node
447 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
448 ia32_attr_t *attr = get_ia32_attr(node);
449 return attr->data.am_flavour;
453 * Sets the addrmode flavour of an ia32 node
455 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
456 ia32_attr_t *attr = get_ia32_attr(node);
457 attr->data.am_flavour = am_flavour;
461 * Gets the addressmode offset as int.
463 int get_ia32_am_offs_int(const ir_node *node) {
464 ia32_attr_t *attr = get_ia32_attr(node);
465 return attr->am_offs;
469 * Sets the addressmode offset from an int.
471 void set_ia32_am_offs_int(ir_node *node, int offset) {
472 ia32_attr_t *attr = get_ia32_attr(node);
473 attr->am_offs = offset;
476 void add_ia32_am_offs_int(ir_node *node, int offset) {
477 ia32_attr_t *attr = get_ia32_attr(node);
478 attr->am_offs += offset;
482 * Returns the symconst entity associated to addrmode.
484 ir_entity *get_ia32_am_sc(const ir_node *node) {
485 ia32_attr_t *attr = get_ia32_attr(node);
490 * Sets the symconst entity associated to addrmode.
492 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
493 ia32_attr_t *attr = get_ia32_attr(node);
494 attr->am_sc = entity;
498 * Sets the sign bit for address mode symconst.
500 void set_ia32_am_sc_sign(ir_node *node) {
501 ia32_attr_t *attr = get_ia32_attr(node);
502 attr->data.am_sc_sign = 1;
506 * Clears the sign bit for address mode symconst.
508 void clear_ia32_am_sc_sign(ir_node *node) {
509 ia32_attr_t *attr = get_ia32_attr(node);
510 attr->data.am_sc_sign = 0;
514 * Returns the sign bit for address mode symconst.
516 int is_ia32_am_sc_sign(const ir_node *node) {
517 ia32_attr_t *attr = get_ia32_attr(node);
518 return attr->data.am_sc_sign;
522 * Gets the addr mode const.
524 int get_ia32_am_scale(const ir_node *node) {
525 ia32_attr_t *attr = get_ia32_attr(node);
526 return attr->data.am_scale;
530 * Sets the index register scale for addrmode.
532 void set_ia32_am_scale(ir_node *node, int scale) {
533 ia32_attr_t *attr = get_ia32_attr(node);
534 attr->data.am_scale = scale;
538 * Return the tarval of an immediate operation or NULL in case of SymConst
540 tarval *get_ia32_Immop_tarval(const ir_node *node) {
541 ia32_attr_t *attr = get_ia32_attr(node);
542 assert(attr->data.imm_tp == ia32_ImmConst);
543 return attr->cnst_val.tv;
547 * Sets the attributes of an immediate operation to the specified tarval
549 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
550 ia32_attr_t *attr = get_ia32_attr(node);
551 attr->data.imm_tp = ia32_ImmConst;
552 attr->cnst_val.tv = tv;
555 void set_ia32_Immop_symconst(ir_node *node, ir_entity *entity) {
556 ia32_attr_t *attr = get_ia32_attr(node);
557 attr->data.imm_tp = ia32_ImmSymConst;
558 attr->cnst_val.sc = entity;
561 ir_entity *get_ia32_Immop_symconst(const ir_node *node) {
562 ia32_attr_t *attr = get_ia32_attr(node);
563 assert(attr->data.imm_tp == ia32_ImmSymConst);
564 return attr->cnst_val.sc;
568 * Sets the uses_frame flag.
570 void set_ia32_use_frame(ir_node *node) {
571 ia32_attr_t *attr = get_ia32_attr(node);
572 attr->data.use_frame = 1;
576 * Clears the uses_frame flag.
578 void clear_ia32_use_frame(ir_node *node) {
579 ia32_attr_t *attr = get_ia32_attr(node);
580 attr->data.use_frame = 0;
584 * Gets the uses_frame flag.
586 int is_ia32_use_frame(const ir_node *node) {
587 ia32_attr_t *attr = get_ia32_attr(node);
588 return attr->data.use_frame;
592 * Sets node to commutative.
594 void set_ia32_commutative(ir_node *node) {
595 ia32_attr_t *attr = get_ia32_attr(node);
596 attr->data.is_commutative = 1;
600 * Sets node to non-commutative.
602 void clear_ia32_commutative(ir_node *node) {
603 ia32_attr_t *attr = get_ia32_attr(node);
604 attr->data.is_commutative = 0;
608 * Checks if node is commutative.
610 int is_ia32_commutative(const ir_node *node) {
611 ia32_attr_t *attr = get_ia32_attr(node);
612 return attr->data.is_commutative;
618 void set_ia32_emit_cl(ir_node *node) {
619 ia32_attr_t *attr = get_ia32_attr(node);
620 attr->data.emit_cl = 1;
624 * Clears node emit_cl.
626 void clear_ia32_emit_cl(ir_node *node) {
627 ia32_attr_t *attr = get_ia32_attr(node);
628 attr->data.emit_cl = 0;
632 * Checks if node needs %cl.
634 int is_ia32_emit_cl(const ir_node *node) {
635 ia32_attr_t *attr = get_ia32_attr(node);
636 return attr->data.emit_cl;
642 void set_ia32_got_lea(ir_node *node) {
643 ia32_attr_t *attr = get_ia32_attr(node);
644 attr->data.got_lea = 1;
648 * Clears node got_lea.
650 void clear_ia32_got_lea(ir_node *node) {
651 ia32_attr_t *attr = get_ia32_attr(node);
652 attr->data.got_lea = 0;
656 * Checks if node got lea.
658 int is_ia32_got_lea(const ir_node *node) {
659 ia32_attr_t *attr = get_ia32_attr(node);
660 return attr->data.got_lea;
663 void set_ia32_need_stackent(ir_node *node) {
664 ia32_attr_t *attr = get_ia32_attr(node);
665 attr->data.need_stackent = 1;
668 void clear_ia32_need_stackent(ir_node *node) {
669 ia32_attr_t *attr = get_ia32_attr(node);
670 attr->data.need_stackent = 0;
673 int is_ia32_need_stackent(const ir_node *node) {
674 ia32_attr_t *attr = get_ia32_attr(node);
675 return attr->data.need_stackent;
679 * Gets the mode of the stored/loaded value (only set for Store/Load)
681 ir_mode *get_ia32_ls_mode(const ir_node *node) {
682 ia32_attr_t *attr = get_ia32_attr(node);
683 return attr->ls_mode;
687 * Sets the mode of the stored/loaded value (only set for Store/Load)
689 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
690 ia32_attr_t *attr = get_ia32_attr(node);
691 attr->ls_mode = mode;
695 * Gets the frame entity assigned to this node.
697 ir_entity *get_ia32_frame_ent(const ir_node *node) {
698 ia32_attr_t *attr = get_ia32_attr(node);
699 return attr->frame_ent;
703 * Sets the frame entity for this node.
705 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
706 ia32_attr_t *attr = get_ia32_attr(node);
707 attr->frame_ent = ent;
709 set_ia32_use_frame(node);
711 clear_ia32_use_frame(node);
716 * Gets the instruction latency.
718 unsigned get_ia32_latency(const ir_node *node) {
719 ia32_attr_t *attr = get_ia32_attr(node);
720 return attr->latency;
724 * Sets the instruction latency.
726 void set_ia32_latency(ir_node *node, unsigned latency) {
727 ia32_attr_t *attr = get_ia32_attr(node);
728 attr->latency = latency;
732 * Returns the argument register requirements of an ia32 node.
734 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
735 ia32_attr_t *attr = get_ia32_attr(node);
740 * Sets the argument register requirements of an ia32 node.
742 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
743 ia32_attr_t *attr = get_ia32_attr(node);
748 * Returns the result register requirements of an ia32 node.
750 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
751 ia32_attr_t *attr = get_ia32_attr(node);
752 return attr->out_req;
756 * Sets the result register requirements of an ia32 node.
758 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
759 ia32_attr_t *attr = get_ia32_attr(node);
760 attr->out_req = reqs;
764 * Returns the argument register requirement at position pos of an ia32 node.
766 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
767 ia32_attr_t *attr = get_ia32_attr(node);
768 if(attr->in_req == NULL)
769 return arch_no_register_req;
771 return attr->in_req[pos];
775 * Returns the result register requirement at position pos of an ia32 node.
777 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
778 ia32_attr_t *attr = get_ia32_attr(node);
779 if(attr->out_req == NULL)
780 return arch_no_register_req;
782 return attr->out_req[pos];
786 * Sets the OUT register requirements at position pos.
788 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
789 ia32_attr_t *attr = get_ia32_attr(node);
790 attr->out_req[pos] = req;
794 * Sets the IN register requirements at position pos.
796 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
797 ia32_attr_t *attr = get_ia32_attr(node);
798 attr->in_req[pos] = req;
802 * Returns the register flag of an ia32 node.
804 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
805 ia32_attr_t *attr = get_ia32_attr(node);
806 return attr->data.flags;
810 * Sets the register flag of an ia32 node.
812 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
813 ia32_attr_t *attr = get_ia32_attr(node);
814 attr->data.flags = flags;
818 * Returns the result register slots of an ia32 node.
820 const arch_register_t **get_ia32_slots(const ir_node *node) {
821 ia32_attr_t *attr = get_ia32_attr(node);
826 * Sets the number of results.
828 void set_ia32_n_res(ir_node *node, int n_res) {
829 ia32_attr_t *attr = get_ia32_attr(node);
830 attr->data.n_res = n_res;
834 * Returns the number of results.
836 int get_ia32_n_res(const ir_node *node) {
837 ia32_attr_t *attr = get_ia32_attr(node);
838 return attr->data.n_res;
842 * Returns the flavour of an ia32 node,
844 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
845 ia32_attr_t *attr = get_ia32_attr(node);
846 return attr->data.op_flav;
850 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
852 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
853 ia32_attr_t *attr = get_ia32_attr(node);
854 attr->data.op_flav = op_flav;
858 * Returns the projnum code.
860 pn_Cmp get_ia32_pncode(const ir_node *node) {
861 ia32_attr_t *attr = get_ia32_attr(node);
862 return attr->pn_code;
866 * Sets the projnum code
868 void set_ia32_pncode(ir_node *node, pn_Cmp code) {
869 ia32_attr_t *attr = get_ia32_attr(node);
870 attr->pn_code = code;
874 * Sets the flags for the n'th out.
876 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
877 ia32_attr_t *attr = get_ia32_attr(node);
878 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
879 attr->out_flags[pos] = flags;
883 * Gets the flags for the n'th out.
885 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
886 ia32_attr_t *attr = get_ia32_attr(node);
887 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
891 * Get the list of available execution units.
893 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
894 ia32_attr_t *attr = get_ia32_attr(node);
895 return attr->exec_units;
901 * Returns the name of the original ir node.
903 const char *get_ia32_orig_node(const ir_node *node) {
904 ia32_attr_t *attr = get_ia32_attr(node);
905 return attr->orig_node;
909 * Sets the name of the original ir node.
911 void set_ia32_orig_node(ir_node *node, const char *name) {
912 ia32_attr_t *attr = get_ia32_attr(node);
913 attr->orig_node = name;
918 /******************************************************************************************************
920 * (_) | | | | | | / _| | | (_)
921 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
922 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
923 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
924 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
927 ******************************************************************************************************/
930 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
932 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
933 ia32_immop_type_t immop_type = get_ia32_immop_type(from);
935 if(immop_type == ia32_ImmConst) {
936 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
937 } else if(immop_type == ia32_ImmSymConst) {
938 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
940 ia32_attr_t *attr = get_ia32_attr(node);
941 assert(immop_type == ia32_ImmNone);
942 attr->data.imm_tp = ia32_ImmNone;
947 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
949 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
950 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
952 switch (get_irn_opcode(cnst)) {
954 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
957 assert(get_SymConst_kind(cnst) == symconst_addr_ent);
958 set_ia32_Immop_symconst(ia32_cnst, get_SymConst_entity(cnst));
961 assert(0 && "Unknown Const NYI");
964 assert(0 && "Cannot create ia32_Const for this opcode");
968 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
969 if(mode_is_reference(get_tarval_mode(tv))) {
970 if(tarval_is_null(tv)) {
971 tv = get_tarval_null(mode_Iu);
973 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
976 tv = tarval_convert_to(tv, mode_Iu);
979 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
981 set_ia32_Immop_tarval(ia32_cnst, tv);
986 * Sets the AddrMode(S|D) attribute
988 void set_ia32_AddrMode(ir_node *node, char direction) {
989 ia32_attr_t *attr = get_ia32_attr(node);
993 attr->data.tp = ia32_AddrModeD;
996 attr->data.tp = ia32_AddrModeS;
999 assert(0 && "wrong AM type");
1004 * Returns whether or not the node is an immediate operation with Const.
1006 int is_ia32_ImmConst(const ir_node *node) {
1007 ia32_attr_t *attr = get_ia32_attr(node);
1008 return (attr->data.imm_tp == ia32_ImmConst);
1012 * Returns whether or not the node is an immediate operation with SymConst.
1014 int is_ia32_ImmSymConst(const ir_node *node) {
1015 ia32_attr_t *attr = get_ia32_attr(node);
1016 return (attr->data.imm_tp == ia32_ImmSymConst);
1020 * Returns whether or not the node is an AddrModeS node.
1022 int is_ia32_AddrModeS(const ir_node *node) {
1023 ia32_attr_t *attr = get_ia32_attr(node);
1024 return (attr->data.tp == ia32_AddrModeS);
1028 * Returns whether or not the node is an AddrModeD node.
1030 int is_ia32_AddrModeD(const ir_node *node) {
1031 ia32_attr_t *attr = get_ia32_attr(node);
1032 return (attr->data.tp == ia32_AddrModeD);
1036 * Checks if node is a Load or xLoad/vfLoad.
1038 int is_ia32_Ld(const ir_node *node) {
1039 int op = get_ia32_irn_opcode(node);
1040 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1044 * Checks if node is a Store or xStore/vfStore.
1046 int is_ia32_St(const ir_node *node) {
1047 int op = get_ia32_irn_opcode(node);
1048 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1052 * Checks if node is a Const or xConst/vfConst.
1054 int is_ia32_Cnst(const ir_node *node) {
1055 int op = get_ia32_irn_opcode(node);
1056 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1060 * Returns the name of the OUT register at position pos.
1062 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1063 ia32_attr_t *attr = get_ia32_attr(node);
1065 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1066 assert(attr->slots[pos] && "No register assigned");
1068 return arch_register_get_name(attr->slots[pos]);
1072 * Returns the index of the OUT register at position pos within its register class.
1074 int get_ia32_out_regnr(const ir_node *node, int pos) {
1075 ia32_attr_t *attr = get_ia32_attr(node);
1077 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1078 assert(attr->slots[pos] && "No register assigned");
1080 return arch_register_get_index(attr->slots[pos]);
1084 * Returns the OUT register at position pos.
1086 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1087 ia32_attr_t *attr = get_ia32_attr(node);
1089 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1090 assert(attr->slots[pos] && "No register assigned");
1092 return attr->slots[pos];
1096 * Initializes the nodes attributes.
1098 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1099 const arch_register_req_t **in_reqs,
1100 const arch_register_req_t **out_reqs,
1101 const be_execution_unit_t ***execution_units,
1102 int n_res, unsigned latency)
1104 ia32_attr_t *attr = get_ia32_attr(node);
1106 set_ia32_flags(node, flags);
1107 set_ia32_in_req_all(node, in_reqs);
1108 set_ia32_out_req_all(node, out_reqs);
1109 set_ia32_latency(node, latency);
1110 set_ia32_n_res(node, n_res);
1112 attr->exec_units = execution_units;
1114 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1115 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1117 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1120 ir_node *get_ia32_result_proj(const ir_node *node)
1122 const ir_edge_t *edge;
1124 foreach_out_edge(node, edge) {
1125 ir_node *proj = get_edge_src_irn(edge);
1126 if(get_Proj_proj(proj) == 0) {
1133 /***************************************************************************************
1136 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1137 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1138 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1139 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1141 ***************************************************************************************/
1143 /* default compare operation to compare attributes */
1144 int ia32_compare_attr(ia32_attr_t *a, ia32_attr_t *b) {
1145 if (a->data.tp != b->data.tp
1146 || a->data.imm_tp != b->data.imm_tp)
1149 if (a->data.imm_tp == ia32_ImmConst
1150 && a->cnst_val.tv != b->cnst_val.tv)
1153 if (a->data.imm_tp == ia32_ImmSymConst
1154 && a->cnst_val.sc != b->cnst_val.sc)
1157 if (a->data.am_flavour != b->data.am_flavour
1158 || a->data.am_scale != b->data.am_scale
1159 || a->data.offs_sign != b->data.offs_sign
1160 || a->data.am_sc_sign != b->data.am_sc_sign
1161 || a->am_offs != b->am_offs
1162 || a->am_sc != b->am_sc
1163 || a->ls_mode != b->ls_mode)
1166 if (a->data.use_frame != b->data.use_frame
1167 || a->data.use_frame != b->data.use_frame
1168 || a->frame_ent != b->frame_ent)
1171 if(a->pn_code != b->pn_code)
1174 if (a->data.tp != b->data.tp
1175 || a->data.op_flav != b->data.op_flav)
1181 /* copies the ia32 attributes */
1182 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1183 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1184 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1186 /* copy the attributes */
1187 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1189 /* copy out flags */
1190 attr_new->out_flags =
1191 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1195 * Registers the ia32_copy_attr function for all ia32 opcodes.
1197 void ia32_register_copy_attr_func(void) {
1198 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1200 for (i = f; i < l; i++) {
1201 ir_op *op = get_irp_opcode(i);
1202 op->ops.copy_attr = ia32_copy_attr;
1206 /* Include the generated constructor functions */
1207 #include "gen_ia32_new_nodes.c.inl"