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
23 #include "irgraph_t.h"
29 #include "firm_common_t.h"
34 #include "../bearch.h"
36 #include "ia32_nodes_attr.h"
37 #include "ia32_new_nodes.h"
38 #include "gen_ia32_regalloc_if.h"
39 #include "gen_ia32_machine.h"
42 * Returns the ident of a SymConst.
43 * @param symc The SymConst
44 * @return The ident of the SymConst
46 static ident *get_sc_ident(ir_node *symc) {
51 switch (get_SymConst_kind(symc)) {
52 case symconst_addr_name:
53 return get_SymConst_name(symc);
55 case symconst_addr_ent:
56 ent = get_SymConst_entity(symc);
57 owner = get_entity_owner(ent);
58 id = get_entity_ld_ident(ent);
59 if (owner == get_tls_type()) {
60 if (get_entity_visibility(ent) == visibility_external_allocated)
61 id = mangle(id, new_id_from_chars("@INDNTPOFF", 10));
63 id = mangle(id, new_id_from_chars("@NTPOFF", 7));
68 assert(0 && "Unsupported SymConst");
75 * returns true if a node has x87 registers
77 int ia32_has_x87_register(const ir_node *n) {
78 assert(is_ia32_irn(n) && "Need ia32 node.");
79 return is_irn_machine_user(n, 0);
82 /***********************************************************************************
85 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
86 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
87 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
88 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
91 ***********************************************************************************/
94 * Returns a string containing the names of all registers within the limited bitset
96 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
97 bitset_t *bs = bitset_alloca(req->cls->n_regs);
102 req->limited(NULL, bs);
104 for (i = 0; i < req->cls->n_regs; i++) {
105 if (bitset_is_set(bs, i)) {
106 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
108 fprintf(stderr, "dumper problem, exiting\n");
124 * Dumps the register requirements for either in or out.
126 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
127 char *dir = inout ? "out" : "in";
128 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
129 char *buf = alloca(1024);
132 memset(buf, 0, 1024);
135 for (i = 0; i < max; i++) {
136 fprintf(F, "%sreq #%d =", dir, i);
138 if (reqs[i]->req.type == arch_register_req_type_none) {
142 if (reqs[i]->req.type & arch_register_req_type_normal) {
143 fprintf(F, " %s", reqs[i]->req.cls->name);
146 if (reqs[i]->req.type & arch_register_req_type_limited) {
147 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
150 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
151 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
154 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
155 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
164 fprintf(F, "%sreq = N/A\n", dir);
169 * Dumper interface for dumping ia32 nodes in vcg.
170 * @param n the node to dump
171 * @param F the output file
172 * @param reason indicates which kind of information should be dumped
173 * @return 0 on success or != 0 on failure
175 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
176 ir_mode *mode = NULL;
178 int i, n_res, am_flav, flags;
179 const ia32_register_req_t **reqs;
180 const arch_register_t **slots;
183 case dump_node_opcode_txt:
184 fprintf(F, "%s", get_irn_opname(n));
187 case dump_node_mode_txt:
188 mode = get_irn_mode(n);
190 if (is_ia32_Ld(n) || is_ia32_St(n)) {
191 mode = get_ia32_ls_mode(n);
194 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
197 case dump_node_nodeattr_txt:
198 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
199 char *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
200 const char *cnst = get_ia32_cnst(n);
202 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
205 if (! is_ia32_Lea(n)) {
206 if (is_ia32_AddrModeS(n)) {
207 fprintf(F, "[AM S] ");
209 else if (is_ia32_AddrModeD(n)) {
210 fprintf(F, "[AM D] ");
216 case dump_node_info_txt:
217 n_res = get_ia32_n_res(n);
218 fprintf(F, "=== IA32 attr begin ===\n");
220 /* dump IN requirements */
221 if (get_irn_arity(n) > 0) {
222 reqs = get_ia32_in_req_all(n);
223 dump_reg_req(F, n, reqs, 0);
226 /* dump OUT requirements */
228 reqs = get_ia32_out_req_all(n);
229 dump_reg_req(F, n, reqs, 1);
232 /* dump assigned registers */
233 slots = get_ia32_slots(n);
234 if (slots && n_res > 0) {
235 for (i = 0; i < n_res; i++) {
236 const arch_register_t *reg;
238 /* retrieve "real" x87 register */
239 if (ia32_has_x87_register(n))
240 reg = get_ia32_attr(n)->x87[i + 2];
244 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
251 switch (get_ia32_op_type(n)) {
253 fprintf(F, "Normal");
259 fprintf(F, "SymConst");
262 fprintf(F, "AM Dest (Load+Store)");
265 fprintf(F, "AM Source (Load)");
268 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
273 /* dump immop type */
274 fprintf(F, "immediate = ");
275 switch (get_ia32_immop_type(n)) {
282 case ia32_ImmSymConst:
283 fprintf(F, "SymConst");
286 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
291 /* dump supported am */
292 fprintf(F, "AM support = ");
293 switch (get_ia32_am_support(n)) {
298 fprintf(F, "source only (Load)");
301 fprintf(F, "dest only (Load+Store)");
307 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
312 /* dump am flavour */
313 fprintf(F, "AM flavour =");
314 am_flav = get_ia32_am_flavour(n);
315 if (am_flav == ia32_am_N) {
319 if (am_flav & ia32_O) {
322 if (am_flav & ia32_B) {
325 if (am_flav & ia32_I) {
328 if (am_flav & ia32_S) {
332 fprintf(F, " (%d)\n", am_flav);
335 fprintf(F, "AM offset = ");
336 if (get_ia32_am_offs(n)) {
337 fprintf(F, "%s", get_ia32_am_offs(n));
344 /* dump AM symconst */
345 if(get_ia32_am_sc(n) != NULL) {
346 fprintf(F, "AM symconst = %s\n", get_id_str(get_ia32_am_sc(n)));
350 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
353 fprintf(F, "pn_code = %ld (%s)\n", get_ia32_pncode(n), get_pnc_string(get_ia32_pncode(n)));
356 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
359 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
362 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
365 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
368 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
371 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
374 fprintf(F, "latency = %d\n", get_ia32_latency(n));
377 fprintf(F, "flags =");
378 flags = get_ia32_flags(n);
379 if (flags == arch_irn_flags_none) {
383 if (flags & arch_irn_flags_dont_spill) {
384 fprintf(F, " unspillable");
386 if (flags & arch_irn_flags_rematerializable) {
387 fprintf(F, " remat");
389 if (flags & arch_irn_flags_ignore) {
390 fprintf(F, " ignore");
392 if (flags & arch_irn_flags_modify_sp) {
393 fprintf(F, " modify_sp");
396 fprintf(F, " (%d)\n", flags);
398 /* dump frame entity */
399 fprintf(F, "frame entity = ");
400 if (get_ia32_frame_ent(n)) {
401 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
409 fprintf(F, "ls_mode = ");
410 if (get_ia32_ls_mode(n)) {
411 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
418 fprintf(F, "res_mode = ");
419 if (get_ia32_res_mode(n)) {
420 ir_fprintf(F, "%+F", get_ia32_res_mode(n));
428 /* dump original ir node name */
429 fprintf(F, "orig node = ");
430 if (get_ia32_orig_node(n)) {
431 fprintf(F, "%s", get_ia32_orig_node(n));
439 fprintf(F, "=== IA32 attr end ===\n");
440 /* end of: case dump_node_info_txt */
449 /***************************************************************************************************
451 * | | | | | | / / | | | | | | | |
452 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
453 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
454 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
455 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
458 ***************************************************************************************************/
461 * Returns an ident for the given tarval tv.
463 static ident *get_ident_for_tv(tarval *tv) {
465 int len = tarval_snprintf(buf, sizeof(buf), tv);
467 return new_id_from_str(buf);
471 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
472 * Firm was made by people hating const :-(
474 ia32_attr_t *get_ia32_attr(const ir_node *node) {
475 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
476 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
480 * Gets the type of an ia32 node.
482 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
483 ia32_attr_t *attr = get_ia32_attr(node);
484 return attr->data.tp;
488 * Sets the type of an ia32 node.
490 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
491 ia32_attr_t *attr = get_ia32_attr(node);
496 * Gets the immediate op type of an ia32 node.
498 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
499 ia32_attr_t *attr = get_ia32_attr(node);
500 return attr->data.imm_tp;
504 * Sets the immediate op type of an ia32 node.
506 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
507 ia32_attr_t *attr = get_ia32_attr(node);
508 attr->data.imm_tp = tp;
512 * Gets the supported addrmode of an ia32 node
514 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
515 ia32_attr_t *attr = get_ia32_attr(node);
516 return attr->data.am_support;
520 * Sets the supported addrmode of an ia32 node
522 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
523 ia32_attr_t *attr = get_ia32_attr(node);
524 attr->data.am_support = am_tp;
528 * Gets the addrmode flavour of an ia32 node
530 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
531 ia32_attr_t *attr = get_ia32_attr(node);
532 return attr->data.am_flavour;
536 * Sets the addrmode flavour of an ia32 node
538 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
539 ia32_attr_t *attr = get_ia32_attr(node);
540 attr->data.am_flavour = am_flavour;
544 * Joins all offsets to one string with adds.
546 char *get_ia32_am_offs(const ir_node *node) {
547 ia32_attr_t *attr = get_ia32_attr(node);
550 snprintf(res, sizeof(res), "%+d", attr->am_offs);
556 * Gets the addressmode offset as int.
558 int get_ia32_am_offs_int(const ir_node *node) {
559 ia32_attr_t *attr = get_ia32_attr(node);
560 return attr->am_offs;
564 * Sets the addressmode offset from an int.
566 void set_ia32_am_offs_int(ir_node *node, int offset) {
567 ia32_attr_t *attr = get_ia32_attr(node);
568 attr->am_offs = offset;
572 * Add an offset for addrmode.
574 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
575 ia32_attr_t *attr = get_ia32_attr(node);
578 if (offset == NULL || offset[0] == '\0')
581 if (offset[0] == '-')
582 res = sscanf(offset, "%d", &o);
584 res = sscanf(offset, "%u", &o);
596 * Add an offset for addrmode.
598 void add_ia32_am_offs(ir_node *node, const char *offset) {
599 extend_ia32_am_offs(node, (char *)offset, '+');
602 void add_ia32_am_offs_int(ir_node *node, int offset) {
603 ia32_attr_t *attr = get_ia32_attr(node);
604 attr->am_offs += offset;
608 * Sub an offset for addrmode.
610 void sub_ia32_am_offs(ir_node *node, const char *offset) {
611 extend_ia32_am_offs(node, (char *)offset, '-');
615 * Returns the symconst ident associated to addrmode.
617 ident *get_ia32_am_sc(const ir_node *node) {
618 ia32_attr_t *attr = get_ia32_attr(node);
623 * Sets the symconst ident associated to addrmode.
625 void set_ia32_am_sc(ir_node *node, ident *sc) {
626 ia32_attr_t *attr = get_ia32_attr(node);
631 * Sets the sign bit for address mode symconst.
633 void set_ia32_am_sc_sign(ir_node *node) {
634 ia32_attr_t *attr = get_ia32_attr(node);
635 attr->data.am_sc_sign = 1;
639 * Clears the sign bit for address mode symconst.
641 void clear_ia32_am_sc_sign(ir_node *node) {
642 ia32_attr_t *attr = get_ia32_attr(node);
643 attr->data.am_sc_sign = 0;
647 * Returns the sign bit for address mode symconst.
649 int is_ia32_am_sc_sign(const ir_node *node) {
650 ia32_attr_t *attr = get_ia32_attr(node);
651 return attr->data.am_sc_sign;
655 * Gets the addr mode const.
657 int get_ia32_am_scale(const ir_node *node) {
658 ia32_attr_t *attr = get_ia32_attr(node);
659 return attr->data.am_scale;
663 * Sets the index register scale for addrmode.
665 void set_ia32_am_scale(ir_node *node, int scale) {
666 ia32_attr_t *attr = get_ia32_attr(node);
667 attr->data.am_scale = scale;
671 * Return the tarval of an immediate operation or NULL in case of SymConst
673 tarval *get_ia32_Immop_tarval(const ir_node *node) {
674 ia32_attr_t *attr = get_ia32_attr(node);
675 return attr->cnst_val.tv;
679 * Sets the attributes of an immediate operation to the specified tarval
681 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
682 ia32_attr_t *attr = get_ia32_attr(node);
683 attr->cnst_val.tv = tv;
684 attr->cnst = get_ident_for_tv(tv);
688 * Gets the string representation of the internal const (tv or symconst)
690 const char *get_ia32_cnst(const ir_node *node) {
691 ia32_attr_t *attr = get_ia32_attr(node);
694 return get_id_str(attr->cnst);
698 * Sets the string representation of the internal const.
700 void set_ia32_cnst(ir_node *node, const char *cnst) {
701 ia32_attr_t *attr = get_ia32_attr(node);
702 attr->cnst = new_id_from_str(cnst);
706 * Gets the ident representation of the internal const (tv or symconst)
708 ident *get_ia32_id_cnst(const ir_node *node) {
709 ia32_attr_t *attr = get_ia32_attr(node);
714 * Sets the ident representation of the internal const.
716 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
717 ia32_attr_t *attr = get_ia32_attr(node);
722 * Sets the uses_frame flag.
724 void set_ia32_use_frame(ir_node *node) {
725 ia32_attr_t *attr = get_ia32_attr(node);
726 attr->data.use_frame = 1;
730 * Clears the uses_frame flag.
732 void clear_ia32_use_frame(ir_node *node) {
733 ia32_attr_t *attr = get_ia32_attr(node);
734 attr->data.use_frame = 0;
738 * Gets the uses_frame flag.
740 int is_ia32_use_frame(const ir_node *node) {
741 ia32_attr_t *attr = get_ia32_attr(node);
742 return attr->data.use_frame;
746 * Sets node to commutative.
748 void set_ia32_commutative(ir_node *node) {
749 ia32_attr_t *attr = get_ia32_attr(node);
750 attr->data.is_commutative = 1;
754 * Sets node to non-commutative.
756 void clear_ia32_commutative(ir_node *node) {
757 ia32_attr_t *attr = get_ia32_attr(node);
758 attr->data.is_commutative = 0;
762 * Checks if node is commutative.
764 int is_ia32_commutative(const ir_node *node) {
765 ia32_attr_t *attr = get_ia32_attr(node);
766 return attr->data.is_commutative;
772 void set_ia32_emit_cl(ir_node *node) {
773 ia32_attr_t *attr = get_ia32_attr(node);
774 attr->data.emit_cl = 1;
778 * Clears node emit_cl.
780 void clear_ia32_emit_cl(ir_node *node) {
781 ia32_attr_t *attr = get_ia32_attr(node);
782 attr->data.emit_cl = 0;
786 * Checks if node needs %cl.
788 int is_ia32_emit_cl(const ir_node *node) {
789 ia32_attr_t *attr = get_ia32_attr(node);
790 return attr->data.emit_cl;
796 void set_ia32_got_lea(ir_node *node) {
797 ia32_attr_t *attr = get_ia32_attr(node);
798 attr->data.got_lea = 1;
802 * Clears node got_lea.
804 void clear_ia32_got_lea(ir_node *node) {
805 ia32_attr_t *attr = get_ia32_attr(node);
806 attr->data.got_lea = 0;
810 * Checks if node got lea.
812 int is_ia32_got_lea(const ir_node *node) {
813 ia32_attr_t *attr = get_ia32_attr(node);
814 return attr->data.got_lea;
818 * Sets node got_reload.
820 void set_ia32_got_reload(ir_node *node) {
821 ia32_attr_t *attr = get_ia32_attr(node);
822 attr->data.got_reload = 1;
826 * Clears node got_reload.
828 void clear_ia32_got_reload(ir_node *node) {
829 ia32_attr_t *attr = get_ia32_attr(node);
830 attr->data.got_reload = 0;
834 * Checks if node got reload.
836 int is_ia32_got_reload(const ir_node *node) {
837 ia32_attr_t *attr = get_ia32_attr(node);
838 return attr->data.got_reload;
842 * Gets the mode of the stored/loaded value (only set for Store/Load)
844 ir_mode *get_ia32_ls_mode(const ir_node *node) {
845 ia32_attr_t *attr = get_ia32_attr(node);
846 return attr->ls_mode;
850 * Sets the mode of the stored/loaded value (only set for Store/Load)
852 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
853 ia32_attr_t *attr = get_ia32_attr(node);
854 attr->ls_mode = mode;
858 * Gets the mode of the result.
860 ir_mode *get_ia32_res_mode(const ir_node *node) {
861 ia32_attr_t *attr = get_ia32_attr(node);
862 return attr->res_mode;
866 * Sets the mode of the result.
868 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
869 ia32_attr_t *attr = get_ia32_attr(node);
870 attr->res_mode = mode;
874 * Gets the frame entity assigned to this node.
876 ir_entity *get_ia32_frame_ent(const ir_node *node) {
877 ia32_attr_t *attr = get_ia32_attr(node);
878 return attr->frame_ent;
882 * Sets the frame entity for this node.
884 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
885 ia32_attr_t *attr = get_ia32_attr(node);
886 attr->frame_ent = ent;
888 set_ia32_use_frame(node);
890 clear_ia32_use_frame(node);
895 * Gets the instruction latency.
897 unsigned get_ia32_latency(const ir_node *node) {
898 ia32_attr_t *attr = get_ia32_attr(node);
899 return attr->latency;
903 * Sets the instruction latency.
905 void set_ia32_latency(ir_node *node, unsigned latency) {
906 ia32_attr_t *attr = get_ia32_attr(node);
907 attr->latency = latency;
911 * Returns the argument register requirements of an ia32 node.
913 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
914 ia32_attr_t *attr = get_ia32_attr(node);
919 * Sets the argument register requirements of an ia32 node.
921 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
922 ia32_attr_t *attr = get_ia32_attr(node);
927 * Returns the result register requirements of an ia32 node.
929 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
930 ia32_attr_t *attr = get_ia32_attr(node);
931 return attr->out_req;
935 * Sets the result register requirements of an ia32 node.
937 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
938 ia32_attr_t *attr = get_ia32_attr(node);
939 attr->out_req = reqs;
943 * Returns the argument register requirement at position pos of an ia32 node.
945 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
946 ia32_attr_t *attr = get_ia32_attr(node);
947 return attr->in_req != NULL ? attr->in_req[pos] : NULL;
951 * Returns the result register requirement at position pos of an ia32 node.
953 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
954 ia32_attr_t *attr = get_ia32_attr(node);
955 return attr->out_req != NULL ? attr->out_req[pos] : NULL;
959 * Sets the OUT register requirements at position pos.
961 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
962 ia32_attr_t *attr = get_ia32_attr(node);
963 attr->out_req[pos] = req;
967 * Sets the IN register requirements at position pos.
969 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
970 ia32_attr_t *attr = get_ia32_attr(node);
971 attr->in_req[pos] = req;
975 * Returns the register flag of an ia32 node.
977 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
978 ia32_attr_t *attr = get_ia32_attr(node);
979 return attr->data.flags;
983 * Sets the register flag of an ia32 node.
985 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
986 ia32_attr_t *attr = get_ia32_attr(node);
987 attr->data.flags = flags;
991 * Returns the result register slots of an ia32 node.
993 const arch_register_t **get_ia32_slots(const ir_node *node) {
994 ia32_attr_t *attr = get_ia32_attr(node);
999 * Sets the number of results.
1001 void set_ia32_n_res(ir_node *node, int n_res) {
1002 ia32_attr_t *attr = get_ia32_attr(node);
1003 attr->data.n_res = n_res;
1007 * Returns the number of results.
1009 int get_ia32_n_res(const ir_node *node) {
1010 ia32_attr_t *attr = get_ia32_attr(node);
1011 return attr->data.n_res;
1015 * Returns the flavour of an ia32 node,
1017 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1018 ia32_attr_t *attr = get_ia32_attr(node);
1019 return attr->data.op_flav;
1023 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1025 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1026 ia32_attr_t *attr = get_ia32_attr(node);
1027 attr->data.op_flav = op_flav;
1031 * Returns the projnum code.
1033 long get_ia32_pncode(const ir_node *node) {
1034 ia32_attr_t *attr = get_ia32_attr(node);
1035 return attr->pn_code;
1039 * Sets the projnum code
1041 void set_ia32_pncode(ir_node *node, long code) {
1042 ia32_attr_t *attr = get_ia32_attr(node);
1043 attr->pn_code = code;
1047 * Sets the flags for the n'th out.
1049 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
1050 ia32_attr_t *attr = get_ia32_attr(node);
1051 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1052 attr->out_flags[pos] = flags;
1056 * Gets the flags for the n'th out.
1058 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
1059 ia32_attr_t *attr = get_ia32_attr(node);
1060 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
1064 * Get the list of available execution units.
1066 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
1067 ia32_attr_t *attr = get_ia32_attr(node);
1068 return attr->exec_units;
1074 * Returns the name of the original ir node.
1076 const char *get_ia32_orig_node(const ir_node *node) {
1077 ia32_attr_t *attr = get_ia32_attr(node);
1078 return attr->orig_node;
1082 * Sets the name of the original ir node.
1084 void set_ia32_orig_node(ir_node *node, const char *name) {
1085 ia32_attr_t *attr = get_ia32_attr(node);
1086 attr->orig_node = name;
1091 /******************************************************************************************************
1093 * (_) | | | | | | / _| | | (_)
1094 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1095 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1096 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1097 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1100 ******************************************************************************************************/
1103 * Gets the type of an ia32_Const.
1105 unsigned get_ia32_Const_type(const ir_node *node) {
1106 ia32_attr_t *attr = get_ia32_attr(node);
1108 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1110 return attr->data.tp;
1114 * Sets the type of an ia32_Const.
1116 void set_ia32_Const_type(ir_node *node, int type) {
1117 ia32_attr_t *attr = get_ia32_attr(node);
1119 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1120 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1122 attr->data.tp = type;
1126 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1128 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1129 ia32_attr_t *na = get_ia32_attr(node);
1130 ia32_attr_t *ca = get_ia32_attr(cnst);
1132 switch(get_ia32_Const_type(cnst)) {
1134 na->cnst_val.tv = ca->cnst_val.tv;
1135 na->cnst = ca->cnst;
1136 set_ia32_immop_type(node, ia32_ImmConst);
1139 na->cnst_val.sc = ca->cnst_val.sc;
1140 na->cnst = na->cnst_val.sc;
1141 set_ia32_immop_type(node, ia32_ImmSymConst);
1144 assert(0 && "Need ia32_Const to set Immop attr");
1149 * Copy the attributes from Immop to an Immop
1151 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1152 ia32_attr_t *da = get_ia32_attr(dst);
1153 ia32_attr_t *sa = get_ia32_attr(src);
1155 switch(get_ia32_immop_type(src)) {
1157 da->cnst_val.tv = sa->cnst_val.tv;
1158 da->cnst = sa->cnst;
1159 set_ia32_immop_type(dst, ia32_ImmConst);
1161 case ia32_ImmSymConst:
1162 da->cnst_val.sc = sa->cnst_val.sc;
1163 da->cnst = sa->cnst;
1164 set_ia32_immop_type(dst, ia32_ImmSymConst);
1167 assert(0 && "Need Immop to copy Immop attr");
1172 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1174 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1175 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1178 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1180 switch (get_irn_opcode(cnst)) {
1182 attr->data.tp = ia32_Const;
1183 attr->cnst_val.tv = get_Const_tarval(cnst);
1184 mode = get_tarval_mode(attr->cnst_val.tv);
1185 if (mode_is_reference(mode) &&
1186 get_mode_null(mode) == attr->cnst_val.tv) {
1187 attr->cnst_val.tv = get_mode_null(mode_Iu);
1189 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1192 attr->data.tp = ia32_SymConst;
1193 attr->cnst_val.sc = get_sc_ident(cnst);
1194 attr->cnst = attr->cnst_val.sc;
1197 assert(0 && "Unknown Const NYI");
1200 assert(0 && "Cannot create ia32_Const for this opcode");
1205 * Sets the AddrMode(S|D) attribute
1207 void set_ia32_AddrMode(ir_node *node, char direction) {
1208 ia32_attr_t *attr = get_ia32_attr(node);
1210 switch (direction) {
1212 attr->data.tp = ia32_AddrModeD;
1215 attr->data.tp = ia32_AddrModeS;
1218 assert(0 && "wrong AM type");
1223 * Returns whether or not the node is an immediate operation with Const.
1225 int is_ia32_ImmConst(const ir_node *node) {
1226 ia32_attr_t *attr = get_ia32_attr(node);
1227 return (attr->data.imm_tp == ia32_ImmConst);
1231 * Returns whether or not the node is an immediate operation with SymConst.
1233 int is_ia32_ImmSymConst(const ir_node *node) {
1234 ia32_attr_t *attr = get_ia32_attr(node);
1235 return (attr->data.imm_tp == ia32_ImmSymConst);
1239 * Returns whether or not the node is an AddrModeS node.
1241 int is_ia32_AddrModeS(const ir_node *node) {
1242 ia32_attr_t *attr = get_ia32_attr(node);
1243 return (attr->data.tp == ia32_AddrModeS);
1247 * Returns whether or not the node is an AddrModeD node.
1249 int is_ia32_AddrModeD(const ir_node *node) {
1250 ia32_attr_t *attr = get_ia32_attr(node);
1251 return (attr->data.tp == ia32_AddrModeD);
1255 * Checks if node is a Load or xLoad/vfLoad.
1257 int is_ia32_Ld(const ir_node *node) {
1258 int op = get_ia32_irn_opcode(node);
1259 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1263 * Checks if node is a Store or xStore/vfStore.
1265 int is_ia32_St(const ir_node *node) {
1266 int op = get_ia32_irn_opcode(node);
1267 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1271 * Checks if node is a Const or xConst/vfConst.
1273 int is_ia32_Cnst(const ir_node *node) {
1274 int op = get_ia32_irn_opcode(node);
1275 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1279 * Returns the name of the OUT register at position pos.
1281 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1282 ia32_attr_t *attr = get_ia32_attr(node);
1284 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1285 assert(attr->slots[pos] && "No register assigned");
1287 return arch_register_get_name(attr->slots[pos]);
1291 * Returns the index of the OUT register at position pos within its register class.
1293 int get_ia32_out_regnr(const ir_node *node, int pos) {
1294 ia32_attr_t *attr = get_ia32_attr(node);
1296 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1297 assert(attr->slots[pos] && "No register assigned");
1299 return arch_register_get_index(attr->slots[pos]);
1303 * Returns the OUT register at position pos.
1305 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1306 ia32_attr_t *attr = get_ia32_attr(node);
1308 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1309 assert(attr->slots[pos] && "No register assigned");
1311 return attr->slots[pos];
1315 * Initializes the nodes attributes.
1317 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1318 const ia32_register_req_t **out_reqs, const be_execution_unit_t ***execution_units,
1319 int n_res, unsigned latency)
1321 ia32_attr_t *attr = get_ia32_attr(node);
1323 set_ia32_flags(node, flags);
1324 set_ia32_in_req_all(node, in_reqs);
1325 set_ia32_out_req_all(node, out_reqs);
1326 set_ia32_latency(node, latency);
1327 set_ia32_n_res(node, n_res);
1329 attr->exec_units = execution_units;
1331 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1332 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1334 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1337 ir_node *get_ia32_result_proj(const ir_node *node)
1339 const ir_edge_t *edge;
1341 foreach_out_edge(node, edge) {
1342 ir_node *proj = get_edge_src_irn(edge);
1343 if(get_Proj_proj(proj) == 0) {
1350 ir_mode *get_ia32_Conv_src_mode(const ir_node *node)
1352 if(get_ia32_op_type(node) == ia32_AddrModeS) {
1353 return get_ia32_ls_mode(node);
1356 return get_irn_mode(get_irn_n(node, 2));
1359 ir_mode *get_ia32_Conv_tgt_mode(const ir_node *node)
1361 return get_irn_mode(node);
1364 /***************************************************************************************
1367 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1368 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1369 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1370 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1372 ***************************************************************************************/
1374 /* default compare operation to compare immediate ops */
1375 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1378 if (a->data.tp != b->data.tp)
1381 if (a->cnst != b->cnst)
1384 if (a->data.use_frame != b->data.use_frame)
1387 if (a->data.use_frame && a->frame_ent != b->frame_ent)
1390 if (a->data.am_flavour != b->data.am_flavour
1391 || a->data.am_scale != b->data.am_scale
1392 || a->data.offs_sign != b->data.offs_sign
1393 || a->data.am_sc_sign != b->data.am_sc_sign
1394 || a->am_offs != b->am_offs
1395 || a->am_sc != b->am_sc)
1398 if(a->pn_code != b->pn_code)
1404 /* copies the ia32 attributes */
1405 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1406 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1407 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1409 /* copy the attributes */
1410 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1412 /* copy out flags */
1413 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1417 * Registers the ia32_copy_attr function for all ia32 opcodes.
1419 void ia32_register_copy_attr_func(void) {
1420 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1422 for (i = f; i < l; i++) {
1423 ir_op *op = get_irp_opcode(i);
1424 op->ops.copy_attr = ia32_copy_attr;
1428 /* Include the generated constructor functions */
1429 #include "gen_ia32_new_nodes.c.inl"