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"
33 #include "../bearch.h"
35 #include "ia32_nodes_attr.h"
36 #include "ia32_new_nodes.h"
37 #include "gen_ia32_regalloc_if.h"
40 * Returns the ident of a SymConst.
41 * @param symc The SymConst
42 * @return The ident of the SymConst
44 static ident *get_sc_ident(ir_node *symc) {
45 assert(get_irn_opcode(symc) == iro_SymConst && "need symconst to get ident");
47 switch (get_SymConst_kind(symc)) {
48 case symconst_addr_name:
49 return get_SymConst_name(symc);
51 case symconst_addr_ent:
52 return get_entity_ld_ident(get_SymConst_entity(symc));
55 assert(0 && "Unsupported SymConst");
63 /***********************************************************************************
66 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
67 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
68 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
69 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
72 ***********************************************************************************/
75 * Returns a string containing the names of all registers within the limited bitset
77 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
78 bitset_t *bs = bitset_alloca(req->cls->n_regs);
83 req->limited(NULL, bs);
85 for (i = 0; i < req->cls->n_regs; i++) {
86 if (bitset_is_set(bs, i)) {
87 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
89 fprintf(stderr, "dumper problem, exiting\n");
105 * Dumps the register requirements for either in or out.
107 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
108 char *dir = inout ? "out" : "in";
109 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
110 char *buf = alloca(1024);
113 memset(buf, 0, 1024);
116 for (i = 0; i < max; i++) {
117 fprintf(F, "%sreq #%d =", dir, i);
119 if (reqs[i]->req.type == arch_register_req_type_none) {
123 if (reqs[i]->req.type & arch_register_req_type_normal) {
124 fprintf(F, " %s", reqs[i]->req.cls->name);
127 if (reqs[i]->req.type & arch_register_req_type_limited) {
128 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
131 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
132 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
135 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
136 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
145 fprintf(F, "%sreq = N/A\n", dir);
150 * Dumper interface for dumping ia32 nodes in vcg.
151 * @param n the node to dump
152 * @param F the output file
153 * @param reason indicates which kind of information should be dumped
154 * @return 0 on success or != 0 on failure
156 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
157 ir_mode *mode = NULL;
159 int i, n_res, am_flav, flags;
160 const ia32_register_req_t **reqs;
161 const arch_register_t **slots;
164 case dump_node_opcode_txt:
165 fprintf(F, "%s", get_irn_opname(n));
168 case dump_node_mode_txt:
169 mode = get_irn_mode(n);
171 if (is_ia32_Ld(n) || is_ia32_St(n)) {
172 mode = get_ia32_ls_mode(n);
175 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
178 case dump_node_nodeattr_txt:
179 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
180 char *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
181 const char *cnst = get_ia32_cnst(n);
183 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
186 if (! is_ia32_Lea(n)) {
187 if (is_ia32_AddrModeS(n)) {
188 fprintf(F, "[AM S] ");
190 else if (is_ia32_AddrModeD(n)) {
191 fprintf(F, "[AM D] ");
197 case dump_node_info_txt:
198 n_res = get_ia32_n_res(n);
199 fprintf(F, "=== IA32 attr begin ===\n");
201 /* dump IN requirements */
202 if (get_irn_arity(n) > 0) {
203 reqs = get_ia32_in_req_all(n);
204 dump_reg_req(F, n, reqs, 0);
207 /* dump OUT requirements */
209 reqs = get_ia32_out_req_all(n);
210 dump_reg_req(F, n, reqs, 1);
213 /* dump assigned registers */
214 slots = get_ia32_slots(n);
215 if (slots && n_res > 0) {
216 for (i = 0; i < n_res; i++) {
217 fprintf(F, "reg #%d = %s\n", i, slots[i] ? slots[i]->name : "n/a");
224 switch (get_ia32_op_type(n)) {
226 fprintf(F, "Normal");
232 fprintf(F, "SymConst");
235 fprintf(F, "AM Dest (Load+Store)");
238 fprintf(F, "AM Source (Load)");
241 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
246 /* dump immop type */
247 fprintf(F, "immediate = ");
248 switch (get_ia32_immop_type(n)) {
255 case ia32_ImmSymConst:
256 fprintf(F, "SymConst");
259 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
264 /* dump supported am */
265 fprintf(F, "AM support = ");
266 switch (get_ia32_am_support(n)) {
271 fprintf(F, "source only (Load)");
274 fprintf(F, "dest only (Load+Store)");
280 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
285 /* dump am flavour */
286 fprintf(F, "AM flavour =");
287 am_flav = get_ia32_am_flavour(n);
288 if (am_flav == ia32_am_N) {
292 if (am_flav & ia32_O) {
295 if (am_flav & ia32_B) {
298 if (am_flav & ia32_I) {
301 if (am_flav & ia32_S) {
305 fprintf(F, " (%d)\n", am_flav);
308 fprintf(F, "AM offset = ");
309 if (get_ia32_am_offs(n)) {
310 fprintf(F, "%s", get_ia32_am_offs(n));
318 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
321 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
324 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
327 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
330 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
333 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
336 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
339 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
342 fprintf(F, "latency = %d\n", get_ia32_latency(n));
345 fprintf(F, "flags =");
346 flags = get_ia32_flags(n);
347 if (flags == arch_irn_flags_none) {
351 if (flags & arch_irn_flags_dont_spill) {
352 fprintf(F, " unspillable");
354 if (flags & arch_irn_flags_rematerializable) {
355 fprintf(F, " remat");
357 if (flags & arch_irn_flags_ignore) {
358 fprintf(F, " ignore");
360 if (flags & arch_irn_flags_modify_sp) {
361 fprintf(F, " modify_sp");
364 fprintf(F, " (%d)\n", flags);
366 /* dump frame entity */
367 fprintf(F, "frame entity = ");
368 if (get_ia32_frame_ent(n)) {
369 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
377 fprintf(F, "ls_mode = ");
378 if (get_ia32_ls_mode(n)) {
379 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
386 fprintf(F, "res_mode = ");
387 if (get_ia32_res_mode(n)) {
388 ir_fprintf(F, "%+F", get_ia32_res_mode(n));
395 fprintf(F, "src_mode = ");
396 if (get_ia32_src_mode(n)) {
397 ir_fprintf(F, "%+F", get_ia32_src_mode(n));
404 fprintf(F, "tgt_mode = ");
405 if (get_ia32_tgt_mode(n)) {
406 ir_fprintf(F, "%+F", get_ia32_tgt_mode(n));
414 /* dump original ir node name */
415 fprintf(F, "orig node = ");
416 if (get_ia32_orig_node(n)) {
417 fprintf(F, "%s", get_ia32_orig_node(n));
425 fprintf(F, "=== IA32 attr end ===\n");
426 /* end of: case dump_node_info_txt */
435 /***************************************************************************************************
437 * | | | | | | / / | | | | | | | |
438 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
439 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
440 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
441 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
444 ***************************************************************************************************/
447 * Returns an ident for the given tarval tv.
449 static ident *get_ident_for_tv(tarval *tv) {
451 int len = tarval_snprintf(buf, sizeof(buf), tv);
453 return new_id_from_str(buf);
457 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
458 * Firm was made by people hating const :-(
460 ia32_attr_t *get_ia32_attr(const ir_node *node) {
461 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
462 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
466 * Gets the type of an ia32 node.
468 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
469 ia32_attr_t *attr = get_ia32_attr(node);
470 return attr->data.tp;
474 * Sets the type of an ia32 node.
476 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
477 ia32_attr_t *attr = get_ia32_attr(node);
482 * Gets the immediate op type of an ia32 node.
484 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
485 ia32_attr_t *attr = get_ia32_attr(node);
486 return attr->data.imm_tp;
490 * Sets the immediate op type of an ia32 node.
492 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
493 ia32_attr_t *attr = get_ia32_attr(node);
494 attr->data.imm_tp = tp;
498 * Gets the supported addrmode of an ia32 node
500 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
501 ia32_attr_t *attr = get_ia32_attr(node);
502 return attr->data.am_support;
506 * Sets the supported addrmode of an ia32 node
508 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
509 ia32_attr_t *attr = get_ia32_attr(node);
510 attr->data.am_support = am_tp;
514 * Gets the addrmode flavour of an ia32 node
516 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
517 ia32_attr_t *attr = get_ia32_attr(node);
518 return attr->data.am_flavour;
522 * Sets the addrmode flavour of an ia32 node
524 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
525 ia32_attr_t *attr = get_ia32_attr(node);
526 attr->data.am_flavour = am_flavour;
530 * Joins all offsets to one string with adds.
532 char *get_ia32_am_offs(const ir_node *node) {
533 ia32_attr_t *attr = get_ia32_attr(node);
537 if (! attr->am_offs) {
541 if (! attr->plain_offs)
542 attr->plain_offs = (struct obstack *)_new_arr_d(get_irg_obstack(get_irn_irg(node)), 1, sizeof(*(attr->plain_offs)));
544 obstack_free(attr->plain_offs, NULL);
546 obstack_init(attr->plain_offs);
548 size = obstack_object_size(attr->am_offs);
550 res = obstack_alloc(attr->plain_offs, size + 2);
551 res[0] = attr->data.offs_sign ? '-' : '+';
552 memcpy(&res[1], obstack_base(attr->am_offs), size);
553 res[size + 1] = '\0';
560 * Add an offset for addrmode.
562 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
563 ia32_attr_t *attr = get_ia32_attr(node);
565 if (! offset || strlen(offset) < 1)
568 /* offset could already have an explicit sign */
569 /* -> supersede op if necessary */
570 if (offset[0] == '-' || offset[0] == '+') {
571 if (offset[0] == '-') {
572 op = (op == '-') ? '+' : '-';
575 /* skip explicit sign */
579 if (! attr->am_offs) {
580 /* obstack is not initialized */
581 attr->am_offs = (struct obstack *)_new_arr_d(get_irg_obstack(get_irn_irg(node)), 1, sizeof(*(attr->am_offs)));
582 obstack_init(attr->am_offs);
584 attr->data.offs_sign = (op == '-') ? 1 : 0;
587 /* If obstack is initialized, connect the new offset with op */
588 obstack_printf(attr->am_offs, "%c", op);
591 obstack_printf(attr->am_offs, "%s", offset);
595 * Add an offset for addrmode.
597 void add_ia32_am_offs(ir_node *node, const char *offset) {
598 extend_ia32_am_offs(node, (char *)offset, '+');
602 * Sub an offset for addrmode.
604 void sub_ia32_am_offs(ir_node *node, const char *offset) {
605 extend_ia32_am_offs(node, (char *)offset, '-');
609 * Returns the symconst ident associated to addrmode.
611 ident *get_ia32_am_sc(const ir_node *node) {
612 ia32_attr_t *attr = get_ia32_attr(node);
617 * Sets the symconst ident associated to addrmode.
619 void set_ia32_am_sc(ir_node *node, ident *sc) {
620 ia32_attr_t *attr = get_ia32_attr(node);
625 * Sets the sign bit for address mode symconst.
627 void set_ia32_am_sc_sign(ir_node *node) {
628 ia32_attr_t *attr = get_ia32_attr(node);
629 attr->data.am_sc_sign = 1;
633 * Clears the sign bit for address mode symconst.
635 void clear_ia32_am_sc_sign(ir_node *node) {
636 ia32_attr_t *attr = get_ia32_attr(node);
637 attr->data.am_sc_sign = 0;
641 * Returns the sign bit for address mode symconst.
643 int is_ia32_am_sc_sign(const ir_node *node) {
644 ia32_attr_t *attr = get_ia32_attr(node);
645 return attr->data.am_sc_sign;
649 * Gets the addr mode const.
651 int get_ia32_am_scale(const ir_node *node) {
652 ia32_attr_t *attr = get_ia32_attr(node);
653 return attr->data.am_scale;
657 * Sets the index register scale for addrmode.
659 void set_ia32_am_scale(ir_node *node, int scale) {
660 ia32_attr_t *attr = get_ia32_attr(node);
661 attr->data.am_scale = scale;
665 * Return the tarval of an immediate operation or NULL in case of SymConst
667 tarval *get_ia32_Immop_tarval(const ir_node *node) {
668 ia32_attr_t *attr = get_ia32_attr(node);
669 return attr->cnst_val.tv;
673 * Sets the attributes of an immediate operation to the specified tarval
675 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
676 ia32_attr_t *attr = get_ia32_attr(node);
677 attr->cnst_val.tv = tv;
678 attr->cnst = get_ident_for_tv(tv);
682 * Return the sc attribute.
684 ident *get_ia32_sc(const ir_node *node) {
685 ia32_attr_t *attr = get_ia32_attr(node);
686 return attr->cnst_val.sc;
690 * Sets the sc attribute.
692 void set_ia32_sc(ir_node *node, ident *sc) {
693 ia32_attr_t *attr = get_ia32_attr(node);
694 attr->cnst_val.sc = sc;
695 attr->cnst = attr->cnst_val.sc;
699 * Gets the string representation of the internal const (tv or symconst)
701 const char *get_ia32_cnst(const ir_node *node) {
702 ia32_attr_t *attr = get_ia32_attr(node);
705 return get_id_str(attr->cnst);
709 * Sets the string representation of the internal const.
711 void set_ia32_cnst(ir_node *node, char *cnst) {
712 ia32_attr_t *attr = get_ia32_attr(node);
713 attr->cnst = new_id_from_str(cnst);
717 * Gets the ident representation of the internal const (tv or symconst)
719 ident *get_ia32_id_cnst(const ir_node *node) {
720 ia32_attr_t *attr = get_ia32_attr(node);
725 * Sets the ident representation of the internal const.
727 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
728 ia32_attr_t *attr = get_ia32_attr(node);
733 * Sets the uses_frame flag.
735 void set_ia32_use_frame(ir_node *node) {
736 ia32_attr_t *attr = get_ia32_attr(node);
737 attr->data.use_frame = 1;
741 * Clears the uses_frame flag.
743 void clear_ia32_use_frame(ir_node *node) {
744 ia32_attr_t *attr = get_ia32_attr(node);
745 attr->data.use_frame = 0;
749 * Gets the uses_frame flag.
751 int is_ia32_use_frame(const ir_node *node) {
752 ia32_attr_t *attr = get_ia32_attr(node);
753 return attr->data.use_frame;
757 * Sets node to commutative.
759 void set_ia32_commutative(ir_node *node) {
760 ia32_attr_t *attr = get_ia32_attr(node);
761 attr->data.is_commutative = 1;
765 * Sets node to non-commutative.
767 void clear_ia32_commutative(ir_node *node) {
768 ia32_attr_t *attr = get_ia32_attr(node);
769 attr->data.is_commutative = 0;
773 * Checks if node is commutative.
775 int is_ia32_commutative(const ir_node *node) {
776 ia32_attr_t *attr = get_ia32_attr(node);
777 return attr->data.is_commutative;
783 void set_ia32_emit_cl(ir_node *node) {
784 ia32_attr_t *attr = get_ia32_attr(node);
785 attr->data.emit_cl = 1;
789 * Clears node emit_cl.
791 void clear_ia32_emit_cl(ir_node *node) {
792 ia32_attr_t *attr = get_ia32_attr(node);
793 attr->data.emit_cl = 0;
797 * Checks if node needs %cl.
799 int is_ia32_emit_cl(const ir_node *node) {
800 ia32_attr_t *attr = get_ia32_attr(node);
801 return attr->data.emit_cl;
807 void set_ia32_got_lea(ir_node *node) {
808 ia32_attr_t *attr = get_ia32_attr(node);
809 attr->data.got_lea = 1;
813 * Clears node got_lea.
815 void clear_ia32_got_lea(ir_node *node) {
816 ia32_attr_t *attr = get_ia32_attr(node);
817 attr->data.got_lea = 0;
821 * Checks if node got lea.
823 int is_ia32_got_lea(const ir_node *node) {
824 ia32_attr_t *attr = get_ia32_attr(node);
825 return attr->data.got_lea;
829 * Sets node got_reload.
831 void set_ia32_got_reload(ir_node *node) {
832 ia32_attr_t *attr = get_ia32_attr(node);
833 attr->data.got_reload = 1;
837 * Clears node got_reload.
839 void clear_ia32_got_reload(ir_node *node) {
840 ia32_attr_t *attr = get_ia32_attr(node);
841 attr->data.got_reload = 0;
845 * Checks if node got reload.
847 int is_ia32_got_reload(const ir_node *node) {
848 ia32_attr_t *attr = get_ia32_attr(node);
849 return attr->data.got_reload;
853 * Gets the mode of the stored/loaded value (only set for Store/Load)
855 ir_mode *get_ia32_ls_mode(const ir_node *node) {
856 ia32_attr_t *attr = get_ia32_attr(node);
857 return attr->ls_mode;
861 * Sets the mode of the stored/loaded value (only set for Store/Load)
863 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
864 ia32_attr_t *attr = get_ia32_attr(node);
865 attr->ls_mode = mode;
869 * Gets the mode of the result.
871 ir_mode *get_ia32_res_mode(const ir_node *node) {
872 ia32_attr_t *attr = get_ia32_attr(node);
873 return attr->res_mode;
877 * Sets the mode of the result.
879 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
880 ia32_attr_t *attr = get_ia32_attr(node);
881 attr->res_mode = mode;
885 * Gets the source mode of conversion.
887 ir_mode *get_ia32_src_mode(const ir_node *node) {
888 ia32_attr_t *attr = get_ia32_attr(node);
889 return attr->src_mode;
893 * Sets the source mode of conversion.
895 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
896 ia32_attr_t *attr = get_ia32_attr(node);
897 attr->src_mode = mode;
901 * Gets the target mode of conversion.
903 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
904 ia32_attr_t *attr = get_ia32_attr(node);
905 return attr->tgt_mode;
909 * Sets the target mode of conversion.
911 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
912 ia32_attr_t *attr = get_ia32_attr(node);
913 attr->tgt_mode = mode;
917 * Gets the frame entity assigned to this node.
919 entity *get_ia32_frame_ent(const ir_node *node) {
920 ia32_attr_t *attr = get_ia32_attr(node);
921 return attr->frame_ent;
925 * Sets the frame entity for this node.
927 void set_ia32_frame_ent(ir_node *node, entity *ent) {
928 ia32_attr_t *attr = get_ia32_attr(node);
929 attr->frame_ent = ent;
930 set_ia32_use_frame(node);
935 * Gets the instruction latency.
937 unsigned get_ia32_latency(const ir_node *node) {
938 ia32_attr_t *attr = get_ia32_attr(node);
939 return attr->latency;
943 * Sets the instruction latency.
945 void set_ia32_latency(ir_node *node, unsigned latency) {
946 ia32_attr_t *attr = get_ia32_attr(node);
947 attr->latency = latency;
951 * Returns the argument register requirements of an ia32 node.
953 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
954 ia32_attr_t *attr = get_ia32_attr(node);
959 * Sets the argument register requirements of an ia32 node.
961 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
962 ia32_attr_t *attr = get_ia32_attr(node);
967 * Returns the result register requirements of an ia32 node.
969 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
970 ia32_attr_t *attr = get_ia32_attr(node);
971 return attr->out_req;
975 * Sets the result register requirements of an ia32 node.
977 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
978 ia32_attr_t *attr = get_ia32_attr(node);
979 attr->out_req = reqs;
983 * Returns the argument register requirement at position pos of an ia32 node.
985 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
986 ia32_attr_t *attr = get_ia32_attr(node);
987 return attr->in_req[pos];
991 * Returns the result register requirement at position pos of an ia32 node.
993 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
994 ia32_attr_t *attr = get_ia32_attr(node);
995 return attr->out_req[pos];
999 * Sets the OUT register requirements at position pos.
1001 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
1002 ia32_attr_t *attr = get_ia32_attr(node);
1003 attr->out_req[pos] = req;
1007 * Sets the IN register requirements at position pos.
1009 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
1010 ia32_attr_t *attr = get_ia32_attr(node);
1011 attr->in_req[pos] = req;
1015 * Returns the register flag of an ia32 node.
1017 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
1018 ia32_attr_t *attr = get_ia32_attr(node);
1019 return attr->data.flags;
1023 * Sets the register flag of an ia32 node.
1025 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
1026 ia32_attr_t *attr = get_ia32_attr(node);
1027 attr->data.flags = flags;
1031 * Returns the result register slots of an ia32 node.
1033 const arch_register_t **get_ia32_slots(const ir_node *node) {
1034 ia32_attr_t *attr = get_ia32_attr(node);
1039 * Sets the number of results.
1041 void set_ia32_n_res(ir_node *node, int n_res) {
1042 ia32_attr_t *attr = get_ia32_attr(node);
1043 attr->data.n_res = n_res;
1047 * Returns the number of results.
1049 int get_ia32_n_res(const ir_node *node) {
1050 ia32_attr_t *attr = get_ia32_attr(node);
1051 return attr->data.n_res;
1055 * Returns the flavour of an ia32 node,
1057 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1058 ia32_attr_t *attr = get_ia32_attr(node);
1059 return attr->data.op_flav;
1063 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1065 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1066 ia32_attr_t *attr = get_ia32_attr(node);
1067 attr->data.op_flav = op_flav;
1071 * Returns the projnum code.
1073 long get_ia32_pncode(const ir_node *node) {
1074 ia32_attr_t *attr = get_ia32_attr(node);
1075 return attr->pn_code;
1079 * Sets the projnum code
1081 void set_ia32_pncode(ir_node *node, long code) {
1082 ia32_attr_t *attr = get_ia32_attr(node);
1083 attr->pn_code = code;
1089 * Returns the name of the original ir node.
1091 const char *get_ia32_orig_node(const ir_node *node) {
1092 ia32_attr_t *attr = get_ia32_attr(node);
1093 return attr->orig_node;
1097 * Sets the name of the original ir node.
1099 void set_ia32_orig_node(ir_node *node, const char *name) {
1100 ia32_attr_t *attr = get_ia32_attr(node);
1101 attr->orig_node = name;
1106 /******************************************************************************************************
1108 * (_) | | | | | | / _| | | (_)
1109 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1110 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1111 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1112 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1115 ******************************************************************************************************/
1118 * Gets the type of an ia32_Const.
1120 unsigned get_ia32_Const_type(const ir_node *node) {
1121 ia32_attr_t *attr = get_ia32_attr(node);
1123 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1125 return attr->data.tp;
1129 * Sets the type of an ia32_Const.
1131 void set_ia32_Const_type(ir_node *node, int type) {
1132 ia32_attr_t *attr = get_ia32_attr(node);
1134 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1135 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1137 attr->data.tp = type;
1141 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1143 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1144 ia32_attr_t *na = get_ia32_attr(node);
1145 ia32_attr_t *ca = get_ia32_attr(cnst);
1147 switch(get_ia32_Const_type(cnst)) {
1149 na->cnst_val.tv = ca->cnst_val.tv;
1150 na->cnst = ca->cnst;
1151 set_ia32_immop_type(node, ia32_ImmConst);
1154 na->cnst_val.sc = ca->cnst_val.sc;
1155 na->cnst = na->cnst_val.sc;
1156 set_ia32_immop_type(node, ia32_ImmSymConst);
1159 assert(0 && "Need ia32_Const to set Immop attr");
1164 * Copy the attributes from Immop to an Immop
1166 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1167 ia32_attr_t *da = get_ia32_attr(dst);
1168 ia32_attr_t *sa = get_ia32_attr(src);
1170 switch(get_ia32_immop_type(src)) {
1172 da->cnst_val.tv = sa->cnst_val.tv;
1173 da->cnst = sa->cnst;
1174 set_ia32_immop_type(dst, ia32_ImmConst);
1176 case ia32_ImmSymConst:
1177 da->cnst_val.sc = sa->cnst_val.sc;
1178 da->cnst = sa->cnst;
1179 set_ia32_immop_type(dst, ia32_ImmSymConst);
1182 assert(0 && "Need Immop to copy Immop attr");
1187 * Copy the attributes from a Firm Const to an ia32_Const
1189 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1190 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1193 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1195 switch (get_irn_opcode(cnst)) {
1197 attr->data.tp = ia32_Const;
1198 attr->cnst_val.tv = get_Const_tarval(cnst);
1199 mode = get_tarval_mode(attr->cnst_val.tv);
1200 if (mode_is_reference(mode) &&
1201 get_mode_null(mode) == attr->cnst_val.tv)
1202 attr->cnst_val.tv = get_mode_null(mode_Is);
1203 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1206 attr->data.tp = ia32_SymConst;
1207 attr->cnst_val.sc = get_sc_ident(cnst);
1208 attr->cnst = attr->cnst_val.sc;
1211 assert(0 && "Unknown Const NYI");
1214 assert(0 && "Cannot create ia32_Const for this opcode");
1219 * Sets the AddrMode(S|D) attribute
1221 void set_ia32_AddrMode(ir_node *node, char direction) {
1222 ia32_attr_t *attr = get_ia32_attr(node);
1224 switch (direction) {
1226 attr->data.tp = ia32_AddrModeD;
1229 attr->data.tp = ia32_AddrModeS;
1232 assert(0 && "wrong AM type");
1237 * Returns whether or not the node is an immediate operation with Const.
1239 int is_ia32_ImmConst(const ir_node *node) {
1240 ia32_attr_t *attr = get_ia32_attr(node);
1241 return (attr->data.imm_tp == ia32_ImmConst);
1245 * Returns whether or not the node is an immediate operation with SymConst.
1247 int is_ia32_ImmSymConst(const ir_node *node) {
1248 ia32_attr_t *attr = get_ia32_attr(node);
1249 return (attr->data.imm_tp == ia32_ImmSymConst);
1253 * Returns whether or not the node is an AddrModeS node.
1255 int is_ia32_AddrModeS(const ir_node *node) {
1256 ia32_attr_t *attr = get_ia32_attr(node);
1257 return (attr->data.tp == ia32_AddrModeS);
1261 * Returns whether or not the node is an AddrModeD node.
1263 int is_ia32_AddrModeD(const ir_node *node) {
1264 ia32_attr_t *attr = get_ia32_attr(node);
1265 return (attr->data.tp == ia32_AddrModeD);
1269 * Checks if node is a Load or xLoad/vfLoad.
1271 int is_ia32_Ld(const ir_node *node) {
1272 return is_ia32_Load(node) || is_ia32_xLoad(node) || is_ia32_vfld(node) || is_ia32_fld(node);
1276 * Checks if node is a Store or xStore/vfStore.
1278 int is_ia32_St(const ir_node *node) {
1279 return is_ia32_Store(node) || is_ia32_xStore(node) || is_ia32_vfst(node) || is_ia32_fst(node) || is_ia32_fstp(node);
1283 * Checks if node is a Const or xConst/vfConst.
1285 int is_ia32_Cnst(const ir_node *node) {
1286 return is_ia32_Const(node) || is_ia32_xConst(node) || is_ia32_vfConst(node);
1290 * Returns the name of the OUT register at position pos.
1292 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1293 ia32_attr_t *attr = get_ia32_attr(node);
1295 assert(is_ia32_irn(node) && "Not an ia32 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_name(attr->slots[pos]);
1303 * Returns the index of the OUT register at position pos within its register class.
1305 int get_ia32_out_regnr(const ir_node *node, int pos) {
1306 ia32_attr_t *attr = get_ia32_attr(node);
1308 assert(is_ia32_irn(node) && "Not an ia32 node.");
1309 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1310 assert(attr->slots[pos] && "No register assigned");
1312 return arch_register_get_index(attr->slots[pos]);
1316 * Returns the OUT register at position pos.
1318 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1319 ia32_attr_t *attr = get_ia32_attr(node);
1321 assert(is_ia32_irn(node) && "Not an ia32 node.");
1322 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1323 assert(attr->slots[pos] && "No register assigned");
1325 return attr->slots[pos];
1329 * Initializes the nodes attributes.
1331 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1332 const ia32_register_req_t **out_reqs, int n_res, unsigned latency)
1334 ia32_attr_t *attr = get_ia32_attr(node);
1335 set_ia32_flags(node, flags);
1336 set_ia32_in_req_all(node, in_reqs);
1337 set_ia32_out_req_all(node, out_reqs);
1338 set_ia32_latency(node, latency);
1340 attr->data.n_res = n_res;
1341 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1344 /***************************************************************************************
1347 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1348 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1349 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1350 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1352 ***************************************************************************************/
1354 /* default compare operation to compare immediate ops */
1355 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1358 if (a->data.tp == b->data.tp) {
1359 equ = (a->cnst == b->cnst);
1360 equ = equ ? (a->data.use_frame == b->data.use_frame) : 0;
1362 if (equ && a->data.use_frame && b->data.use_frame)
1363 equ = (a->frame_ent == b->frame_ent);
1369 /* compare converts */
1370 int ia32_compare_conv_attr(ia32_attr_t *a, ia32_attr_t *b) {
1371 int equ = ! ia32_compare_immop_attr(a, b);
1373 equ = equ ? (a->src_mode == b->src_mode) && (a->tgt_mode == b->tgt_mode) : equ;
1378 /* Include the generated constructor functions */
1379 #include "gen_ia32_new_nodes.c.inl"