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) {
49 switch (get_SymConst_kind(symc)) {
50 case symconst_addr_name:
51 return get_SymConst_name(symc);
53 case symconst_addr_ent:
54 ent = get_SymConst_entity(symc);
55 owner = get_entity_owner(ent);
56 id = get_entity_ld_ident(ent);
57 if (owner == get_tls_type()) {
58 if (get_entity_visibility(ent) == visibility_external_allocated)
59 id = mangle(id, new_id_from_chars("@INDNTPOFF", 10));
61 id = mangle(id, new_id_from_chars("@NTPOFF", 7));
66 assert(0 && "Unsupported SymConst");
74 /***********************************************************************************
77 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
78 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
79 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
80 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
83 ***********************************************************************************/
86 * Returns a string containing the names of all registers within the limited bitset
88 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
89 bitset_t *bs = bitset_alloca(req->cls->n_regs);
94 req->limited(NULL, bs);
96 for (i = 0; i < req->cls->n_regs; i++) {
97 if (bitset_is_set(bs, i)) {
98 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
100 fprintf(stderr, "dumper problem, exiting\n");
116 * Dumps the register requirements for either in or out.
118 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
119 char *dir = inout ? "out" : "in";
120 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
121 char *buf = alloca(1024);
124 memset(buf, 0, 1024);
127 for (i = 0; i < max; i++) {
128 fprintf(F, "%sreq #%d =", dir, i);
130 if (reqs[i]->req.type == arch_register_req_type_none) {
134 if (reqs[i]->req.type & arch_register_req_type_normal) {
135 fprintf(F, " %s", reqs[i]->req.cls->name);
138 if (reqs[i]->req.type & arch_register_req_type_limited) {
139 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
142 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
143 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
146 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
147 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
156 fprintf(F, "%sreq = N/A\n", dir);
161 * Dumper interface for dumping ia32 nodes in vcg.
162 * @param n the node to dump
163 * @param F the output file
164 * @param reason indicates which kind of information should be dumped
165 * @return 0 on success or != 0 on failure
167 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
168 ir_mode *mode = NULL;
170 int i, n_res, am_flav, flags;
171 const ia32_register_req_t **reqs;
172 const arch_register_t **slots;
175 case dump_node_opcode_txt:
176 fprintf(F, "%s", get_irn_opname(n));
179 case dump_node_mode_txt:
180 mode = get_irn_mode(n);
182 if (is_ia32_Ld(n) || is_ia32_St(n)) {
183 mode = get_ia32_ls_mode(n);
186 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
189 case dump_node_nodeattr_txt:
190 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
191 char *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
192 const char *cnst = get_ia32_cnst(n);
194 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
197 if (! is_ia32_Lea(n)) {
198 if (is_ia32_AddrModeS(n)) {
199 fprintf(F, "[AM S] ");
201 else if (is_ia32_AddrModeD(n)) {
202 fprintf(F, "[AM D] ");
208 case dump_node_info_txt:
209 n_res = get_ia32_n_res(n);
210 fprintf(F, "=== IA32 attr begin ===\n");
212 /* dump IN requirements */
213 if (get_irn_arity(n) > 0) {
214 reqs = get_ia32_in_req_all(n);
215 dump_reg_req(F, n, reqs, 0);
218 /* dump OUT requirements */
220 reqs = get_ia32_out_req_all(n);
221 dump_reg_req(F, n, reqs, 1);
224 /* dump assigned registers */
225 slots = get_ia32_slots(n);
226 if (slots && n_res > 0) {
227 for (i = 0; i < n_res; i++) {
228 fprintf(F, "reg #%d = %s\n", i, slots[i] ? slots[i]->name : "n/a");
235 switch (get_ia32_op_type(n)) {
237 fprintf(F, "Normal");
243 fprintf(F, "SymConst");
246 fprintf(F, "AM Dest (Load+Store)");
249 fprintf(F, "AM Source (Load)");
252 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
257 /* dump immop type */
258 fprintf(F, "immediate = ");
259 switch (get_ia32_immop_type(n)) {
266 case ia32_ImmSymConst:
267 fprintf(F, "SymConst");
270 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
275 /* dump supported am */
276 fprintf(F, "AM support = ");
277 switch (get_ia32_am_support(n)) {
282 fprintf(F, "source only (Load)");
285 fprintf(F, "dest only (Load+Store)");
291 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
296 /* dump am flavour */
297 fprintf(F, "AM flavour =");
298 am_flav = get_ia32_am_flavour(n);
299 if (am_flav == ia32_am_N) {
303 if (am_flav & ia32_O) {
306 if (am_flav & ia32_B) {
309 if (am_flav & ia32_I) {
312 if (am_flav & ia32_S) {
316 fprintf(F, " (%d)\n", am_flav);
319 fprintf(F, "AM offset = ");
320 if (get_ia32_am_offs(n)) {
321 fprintf(F, "%s", get_ia32_am_offs(n));
329 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
332 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
335 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
338 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
341 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
344 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
347 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
350 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
353 fprintf(F, "latency = %d\n", get_ia32_latency(n));
356 fprintf(F, "flags =");
357 flags = get_ia32_flags(n);
358 if (flags == arch_irn_flags_none) {
362 if (flags & arch_irn_flags_dont_spill) {
363 fprintf(F, " unspillable");
365 if (flags & arch_irn_flags_rematerializable) {
366 fprintf(F, " remat");
368 if (flags & arch_irn_flags_ignore) {
369 fprintf(F, " ignore");
371 if (flags & arch_irn_flags_modify_sp) {
372 fprintf(F, " modify_sp");
375 fprintf(F, " (%d)\n", flags);
377 /* dump frame entity */
378 fprintf(F, "frame entity = ");
379 if (get_ia32_frame_ent(n)) {
380 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
388 fprintf(F, "ls_mode = ");
389 if (get_ia32_ls_mode(n)) {
390 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
397 fprintf(F, "res_mode = ");
398 if (get_ia32_res_mode(n)) {
399 ir_fprintf(F, "%+F", get_ia32_res_mode(n));
406 fprintf(F, "src_mode = ");
407 if (get_ia32_src_mode(n)) {
408 ir_fprintf(F, "%+F", get_ia32_src_mode(n));
415 fprintf(F, "tgt_mode = ");
416 if (get_ia32_tgt_mode(n)) {
417 ir_fprintf(F, "%+F", get_ia32_tgt_mode(n));
425 /* dump original ir node name */
426 fprintf(F, "orig node = ");
427 if (get_ia32_orig_node(n)) {
428 fprintf(F, "%s", get_ia32_orig_node(n));
436 fprintf(F, "=== IA32 attr end ===\n");
437 /* end of: case dump_node_info_txt */
446 /***************************************************************************************************
448 * | | | | | | / / | | | | | | | |
449 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
450 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
451 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
452 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
455 ***************************************************************************************************/
458 * Returns an ident for the given tarval tv.
460 static ident *get_ident_for_tv(tarval *tv) {
462 int len = tarval_snprintf(buf, sizeof(buf), tv);
464 return new_id_from_str(buf);
468 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
469 * Firm was made by people hating const :-(
471 ia32_attr_t *get_ia32_attr(const ir_node *node) {
472 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
473 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
477 * Gets the type of an ia32 node.
479 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
480 ia32_attr_t *attr = get_ia32_attr(node);
481 return attr->data.tp;
485 * Sets the type of an ia32 node.
487 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
488 ia32_attr_t *attr = get_ia32_attr(node);
493 * Gets the immediate op type of an ia32 node.
495 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
496 ia32_attr_t *attr = get_ia32_attr(node);
497 return attr->data.imm_tp;
501 * Sets the immediate op type of an ia32 node.
503 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
504 ia32_attr_t *attr = get_ia32_attr(node);
505 attr->data.imm_tp = tp;
509 * Gets the supported addrmode of an ia32 node
511 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
512 ia32_attr_t *attr = get_ia32_attr(node);
513 return attr->data.am_support;
517 * Sets the supported addrmode of an ia32 node
519 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
520 ia32_attr_t *attr = get_ia32_attr(node);
521 attr->data.am_support = am_tp;
525 * Gets the addrmode flavour of an ia32 node
527 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
528 ia32_attr_t *attr = get_ia32_attr(node);
529 return attr->data.am_flavour;
533 * Sets the addrmode flavour of an ia32 node
535 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
536 ia32_attr_t *attr = get_ia32_attr(node);
537 attr->data.am_flavour = am_flavour;
541 * Joins all offsets to one string with adds.
543 char *get_ia32_am_offs(const ir_node *node) {
544 ia32_attr_t *attr = get_ia32_attr(node);
548 if (! attr->am_offs) {
552 if (! attr->plain_offs)
553 attr->plain_offs = (struct obstack *)_new_arr_d(get_irg_obstack(get_irn_irg(node)), 1, sizeof(*(attr->plain_offs)));
555 obstack_free(attr->plain_offs, NULL);
557 obstack_init(attr->plain_offs);
559 size = obstack_object_size(attr->am_offs);
561 res = obstack_alloc(attr->plain_offs, size + 2);
562 res[0] = attr->data.offs_sign ? '-' : '+';
563 memcpy(&res[1], obstack_base(attr->am_offs), size);
564 res[size + 1] = '\0';
571 * Add an offset for addrmode.
573 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
574 ia32_attr_t *attr = get_ia32_attr(node);
576 if (! offset || strlen(offset) < 1)
579 /* offset could already have an explicit sign */
580 /* -> supersede op if necessary */
581 if (offset[0] == '-' || offset[0] == '+') {
582 if (offset[0] == '-') {
583 op = (op == '-') ? '+' : '-';
586 /* skip explicit sign */
590 if (! attr->am_offs) {
591 /* obstack is not initialized */
592 attr->am_offs = (struct obstack *)_new_arr_d(get_irg_obstack(get_irn_irg(node)), 1, sizeof(*(attr->am_offs)));
593 obstack_init(attr->am_offs);
595 attr->data.offs_sign = (op == '-') ? 1 : 0;
598 /* If obstack is initialized, connect the new offset with op */
599 obstack_printf(attr->am_offs, "%c", op);
602 obstack_printf(attr->am_offs, "%s", offset);
606 * Add an offset for addrmode.
608 void add_ia32_am_offs(ir_node *node, const char *offset) {
609 extend_ia32_am_offs(node, (char *)offset, '+');
613 * Sub an offset for addrmode.
615 void sub_ia32_am_offs(ir_node *node, const char *offset) {
616 extend_ia32_am_offs(node, (char *)offset, '-');
620 * Returns the symconst ident associated to addrmode.
622 ident *get_ia32_am_sc(const ir_node *node) {
623 ia32_attr_t *attr = get_ia32_attr(node);
628 * Sets the symconst ident associated to addrmode.
630 void set_ia32_am_sc(ir_node *node, ident *sc) {
631 ia32_attr_t *attr = get_ia32_attr(node);
636 * Sets the sign bit for address mode symconst.
638 void set_ia32_am_sc_sign(ir_node *node) {
639 ia32_attr_t *attr = get_ia32_attr(node);
640 attr->data.am_sc_sign = 1;
644 * Clears the sign bit for address mode symconst.
646 void clear_ia32_am_sc_sign(ir_node *node) {
647 ia32_attr_t *attr = get_ia32_attr(node);
648 attr->data.am_sc_sign = 0;
652 * Returns the sign bit for address mode symconst.
654 int is_ia32_am_sc_sign(const ir_node *node) {
655 ia32_attr_t *attr = get_ia32_attr(node);
656 return attr->data.am_sc_sign;
660 * Gets the addr mode const.
662 int get_ia32_am_scale(const ir_node *node) {
663 ia32_attr_t *attr = get_ia32_attr(node);
664 return attr->data.am_scale;
668 * Sets the index register scale for addrmode.
670 void set_ia32_am_scale(ir_node *node, int scale) {
671 ia32_attr_t *attr = get_ia32_attr(node);
672 attr->data.am_scale = scale;
676 * Return the tarval of an immediate operation or NULL in case of SymConst
678 tarval *get_ia32_Immop_tarval(const ir_node *node) {
679 ia32_attr_t *attr = get_ia32_attr(node);
680 return attr->cnst_val.tv;
684 * Sets the attributes of an immediate operation to the specified tarval
686 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
687 ia32_attr_t *attr = get_ia32_attr(node);
688 attr->cnst_val.tv = tv;
689 attr->cnst = get_ident_for_tv(tv);
693 * Gets the string representation of the internal const (tv or symconst)
695 const char *get_ia32_cnst(const ir_node *node) {
696 ia32_attr_t *attr = get_ia32_attr(node);
699 return get_id_str(attr->cnst);
703 * Sets the string representation of the internal const.
705 void set_ia32_cnst(ir_node *node, char *cnst) {
706 ia32_attr_t *attr = get_ia32_attr(node);
707 attr->cnst = new_id_from_str(cnst);
711 * Gets the ident representation of the internal const (tv or symconst)
713 ident *get_ia32_id_cnst(const ir_node *node) {
714 ia32_attr_t *attr = get_ia32_attr(node);
719 * Sets the ident representation of the internal const.
721 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
722 ia32_attr_t *attr = get_ia32_attr(node);
727 * Sets the uses_frame flag.
729 void set_ia32_use_frame(ir_node *node) {
730 ia32_attr_t *attr = get_ia32_attr(node);
731 attr->data.use_frame = 1;
735 * Clears the uses_frame flag.
737 void clear_ia32_use_frame(ir_node *node) {
738 ia32_attr_t *attr = get_ia32_attr(node);
739 attr->data.use_frame = 0;
743 * Gets the uses_frame flag.
745 int is_ia32_use_frame(const ir_node *node) {
746 ia32_attr_t *attr = get_ia32_attr(node);
747 return attr->data.use_frame;
751 * Sets node to commutative.
753 void set_ia32_commutative(ir_node *node) {
754 ia32_attr_t *attr = get_ia32_attr(node);
755 attr->data.is_commutative = 1;
759 * Sets node to non-commutative.
761 void clear_ia32_commutative(ir_node *node) {
762 ia32_attr_t *attr = get_ia32_attr(node);
763 attr->data.is_commutative = 0;
767 * Checks if node is commutative.
769 int is_ia32_commutative(const ir_node *node) {
770 ia32_attr_t *attr = get_ia32_attr(node);
771 return attr->data.is_commutative;
777 void set_ia32_emit_cl(ir_node *node) {
778 ia32_attr_t *attr = get_ia32_attr(node);
779 attr->data.emit_cl = 1;
783 * Clears node emit_cl.
785 void clear_ia32_emit_cl(ir_node *node) {
786 ia32_attr_t *attr = get_ia32_attr(node);
787 attr->data.emit_cl = 0;
791 * Checks if node needs %cl.
793 int is_ia32_emit_cl(const ir_node *node) {
794 ia32_attr_t *attr = get_ia32_attr(node);
795 return attr->data.emit_cl;
801 void set_ia32_got_lea(ir_node *node) {
802 ia32_attr_t *attr = get_ia32_attr(node);
803 attr->data.got_lea = 1;
807 * Clears node got_lea.
809 void clear_ia32_got_lea(ir_node *node) {
810 ia32_attr_t *attr = get_ia32_attr(node);
811 attr->data.got_lea = 0;
815 * Checks if node got lea.
817 int is_ia32_got_lea(const ir_node *node) {
818 ia32_attr_t *attr = get_ia32_attr(node);
819 return attr->data.got_lea;
823 * Sets node got_reload.
825 void set_ia32_got_reload(ir_node *node) {
826 ia32_attr_t *attr = get_ia32_attr(node);
827 attr->data.got_reload = 1;
831 * Clears node got_reload.
833 void clear_ia32_got_reload(ir_node *node) {
834 ia32_attr_t *attr = get_ia32_attr(node);
835 attr->data.got_reload = 0;
839 * Checks if node got reload.
841 int is_ia32_got_reload(const ir_node *node) {
842 ia32_attr_t *attr = get_ia32_attr(node);
843 return attr->data.got_reload;
847 * Gets the mode of the stored/loaded value (only set for Store/Load)
849 ir_mode *get_ia32_ls_mode(const ir_node *node) {
850 ia32_attr_t *attr = get_ia32_attr(node);
851 return attr->ls_mode;
855 * Sets the mode of the stored/loaded value (only set for Store/Load)
857 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
858 ia32_attr_t *attr = get_ia32_attr(node);
859 attr->ls_mode = mode;
863 * Gets the mode of the result.
865 ir_mode *get_ia32_res_mode(const ir_node *node) {
866 ia32_attr_t *attr = get_ia32_attr(node);
867 return attr->res_mode;
871 * Sets the mode of the result.
873 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
874 ia32_attr_t *attr = get_ia32_attr(node);
875 attr->res_mode = mode;
879 * Gets the source mode of conversion.
881 ir_mode *get_ia32_src_mode(const ir_node *node) {
882 ia32_attr_t *attr = get_ia32_attr(node);
883 return attr->src_mode;
887 * Sets the source mode of conversion.
889 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
890 ia32_attr_t *attr = get_ia32_attr(node);
891 attr->src_mode = mode;
895 * Gets the target mode of conversion.
897 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
898 ia32_attr_t *attr = get_ia32_attr(node);
899 return attr->tgt_mode;
903 * Sets the target mode of conversion.
905 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
906 ia32_attr_t *attr = get_ia32_attr(node);
907 attr->tgt_mode = mode;
911 * Gets the frame entity assigned to this node.
913 entity *get_ia32_frame_ent(const ir_node *node) {
914 ia32_attr_t *attr = get_ia32_attr(node);
915 return attr->frame_ent;
919 * Sets the frame entity for this node.
921 void set_ia32_frame_ent(ir_node *node, entity *ent) {
922 ia32_attr_t *attr = get_ia32_attr(node);
923 attr->frame_ent = ent;
924 set_ia32_use_frame(node);
929 * Gets the instruction latency.
931 unsigned get_ia32_latency(const ir_node *node) {
932 ia32_attr_t *attr = get_ia32_attr(node);
933 return attr->latency;
937 * Sets the instruction latency.
939 void set_ia32_latency(ir_node *node, unsigned latency) {
940 ia32_attr_t *attr = get_ia32_attr(node);
941 attr->latency = latency;
945 * Returns the argument register requirements of an ia32 node.
947 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
948 ia32_attr_t *attr = get_ia32_attr(node);
953 * Sets the argument register requirements of an ia32 node.
955 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
956 ia32_attr_t *attr = get_ia32_attr(node);
961 * Returns the result register requirements of an ia32 node.
963 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
964 ia32_attr_t *attr = get_ia32_attr(node);
965 return attr->out_req;
969 * Sets the result register requirements of an ia32 node.
971 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
972 ia32_attr_t *attr = get_ia32_attr(node);
973 attr->out_req = reqs;
977 * Returns the argument register requirement at position pos of an ia32 node.
979 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
980 ia32_attr_t *attr = get_ia32_attr(node);
981 return attr->in_req[pos];
985 * Returns the result register requirement at position pos of an ia32 node.
987 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
988 ia32_attr_t *attr = get_ia32_attr(node);
989 return attr->out_req[pos];
993 * Sets the OUT register requirements at position pos.
995 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
996 ia32_attr_t *attr = get_ia32_attr(node);
997 attr->out_req[pos] = req;
1001 * Sets the IN register requirements at position pos.
1003 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
1004 ia32_attr_t *attr = get_ia32_attr(node);
1005 attr->in_req[pos] = req;
1009 * Returns the register flag of an ia32 node.
1011 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
1012 ia32_attr_t *attr = get_ia32_attr(node);
1013 return attr->data.flags;
1017 * Sets the register flag of an ia32 node.
1019 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
1020 ia32_attr_t *attr = get_ia32_attr(node);
1021 attr->data.flags = flags;
1025 * Returns the result register slots of an ia32 node.
1027 const arch_register_t **get_ia32_slots(const ir_node *node) {
1028 ia32_attr_t *attr = get_ia32_attr(node);
1033 * Sets the number of results.
1035 void set_ia32_n_res(ir_node *node, int n_res) {
1036 ia32_attr_t *attr = get_ia32_attr(node);
1037 attr->data.n_res = n_res;
1041 * Returns the number of results.
1043 int get_ia32_n_res(const ir_node *node) {
1044 ia32_attr_t *attr = get_ia32_attr(node);
1045 return attr->data.n_res;
1049 * Returns the flavour of an ia32 node,
1051 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1052 ia32_attr_t *attr = get_ia32_attr(node);
1053 return attr->data.op_flav;
1057 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1059 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1060 ia32_attr_t *attr = get_ia32_attr(node);
1061 attr->data.op_flav = op_flav;
1065 * Returns the projnum code.
1067 long get_ia32_pncode(const ir_node *node) {
1068 ia32_attr_t *attr = get_ia32_attr(node);
1069 return attr->pn_code;
1073 * Sets the projnum code
1075 void set_ia32_pncode(ir_node *node, long code) {
1076 ia32_attr_t *attr = get_ia32_attr(node);
1077 attr->pn_code = code;
1083 * Returns the name of the original ir node.
1085 const char *get_ia32_orig_node(const ir_node *node) {
1086 ia32_attr_t *attr = get_ia32_attr(node);
1087 return attr->orig_node;
1091 * Sets the name of the original ir node.
1093 void set_ia32_orig_node(ir_node *node, const char *name) {
1094 ia32_attr_t *attr = get_ia32_attr(node);
1095 attr->orig_node = name;
1100 /******************************************************************************************************
1102 * (_) | | | | | | / _| | | (_)
1103 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1104 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1105 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1106 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1109 ******************************************************************************************************/
1112 * Gets the type of an ia32_Const.
1114 unsigned get_ia32_Const_type(const ir_node *node) {
1115 ia32_attr_t *attr = get_ia32_attr(node);
1117 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1119 return attr->data.tp;
1123 * Sets the type of an ia32_Const.
1125 void set_ia32_Const_type(ir_node *node, int type) {
1126 ia32_attr_t *attr = get_ia32_attr(node);
1128 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1129 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1131 attr->data.tp = type;
1135 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1137 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1138 ia32_attr_t *na = get_ia32_attr(node);
1139 ia32_attr_t *ca = get_ia32_attr(cnst);
1141 switch(get_ia32_Const_type(cnst)) {
1143 na->cnst_val.tv = ca->cnst_val.tv;
1144 na->cnst = ca->cnst;
1145 set_ia32_immop_type(node, ia32_ImmConst);
1148 na->cnst_val.sc = ca->cnst_val.sc;
1149 na->cnst = na->cnst_val.sc;
1150 set_ia32_immop_type(node, ia32_ImmSymConst);
1153 assert(0 && "Need ia32_Const to set Immop attr");
1158 * Copy the attributes from Immop to an Immop
1160 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1161 ia32_attr_t *da = get_ia32_attr(dst);
1162 ia32_attr_t *sa = get_ia32_attr(src);
1164 switch(get_ia32_immop_type(src)) {
1166 da->cnst_val.tv = sa->cnst_val.tv;
1167 da->cnst = sa->cnst;
1168 set_ia32_immop_type(dst, ia32_ImmConst);
1170 case ia32_ImmSymConst:
1171 da->cnst_val.sc = sa->cnst_val.sc;
1172 da->cnst = sa->cnst;
1173 set_ia32_immop_type(dst, ia32_ImmSymConst);
1176 assert(0 && "Need Immop to copy Immop attr");
1181 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1183 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1184 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1187 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1189 switch (get_irn_opcode(cnst)) {
1191 attr->data.tp = ia32_Const;
1192 attr->cnst_val.tv = get_Const_tarval(cnst);
1193 mode = get_tarval_mode(attr->cnst_val.tv);
1194 if (mode_is_reference(mode) &&
1195 get_mode_null(mode) == attr->cnst_val.tv)
1196 attr->cnst_val.tv = get_mode_null(mode_Is);
1197 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1200 attr->data.tp = ia32_SymConst;
1201 attr->cnst_val.sc = get_sc_ident(cnst);
1202 attr->cnst = attr->cnst_val.sc;
1205 assert(0 && "Unknown Const NYI");
1208 assert(0 && "Cannot create ia32_Const for this opcode");
1213 * Sets the AddrMode(S|D) attribute
1215 void set_ia32_AddrMode(ir_node *node, char direction) {
1216 ia32_attr_t *attr = get_ia32_attr(node);
1218 switch (direction) {
1220 attr->data.tp = ia32_AddrModeD;
1223 attr->data.tp = ia32_AddrModeS;
1226 assert(0 && "wrong AM type");
1231 * Returns whether or not the node is an immediate operation with Const.
1233 int is_ia32_ImmConst(const ir_node *node) {
1234 ia32_attr_t *attr = get_ia32_attr(node);
1235 return (attr->data.imm_tp == ia32_ImmConst);
1239 * Returns whether or not the node is an immediate operation with SymConst.
1241 int is_ia32_ImmSymConst(const ir_node *node) {
1242 ia32_attr_t *attr = get_ia32_attr(node);
1243 return (attr->data.imm_tp == ia32_ImmSymConst);
1247 * Returns whether or not the node is an AddrModeS node.
1249 int is_ia32_AddrModeS(const ir_node *node) {
1250 ia32_attr_t *attr = get_ia32_attr(node);
1251 return (attr->data.tp == ia32_AddrModeS);
1255 * Returns whether or not the node is an AddrModeD node.
1257 int is_ia32_AddrModeD(const ir_node *node) {
1258 ia32_attr_t *attr = get_ia32_attr(node);
1259 return (attr->data.tp == ia32_AddrModeD);
1263 * Checks if node is a Load or xLoad/vfLoad.
1265 int is_ia32_Ld(const ir_node *node) {
1266 return is_ia32_Load(node) || is_ia32_xLoad(node) || is_ia32_vfld(node) || is_ia32_fld(node);
1270 * Checks if node is a Store or xStore/vfStore.
1272 int is_ia32_St(const ir_node *node) {
1273 return is_ia32_Store(node) || is_ia32_xStore(node) || is_ia32_vfst(node) || is_ia32_fst(node) || is_ia32_fstp(node);
1277 * Checks if node is a Const or xConst/vfConst.
1279 int is_ia32_Cnst(const ir_node *node) {
1280 return is_ia32_Const(node) || is_ia32_xConst(node) || is_ia32_vfConst(node);
1284 * Returns the name of the OUT register at position pos.
1286 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1287 ia32_attr_t *attr = get_ia32_attr(node);
1289 assert(is_ia32_irn(node) && "Not an ia32 node.");
1290 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1291 assert(attr->slots[pos] && "No register assigned");
1293 return arch_register_get_name(attr->slots[pos]);
1297 * Returns the index of the OUT register at position pos within its register class.
1299 int get_ia32_out_regnr(const ir_node *node, int pos) {
1300 ia32_attr_t *attr = get_ia32_attr(node);
1302 assert(is_ia32_irn(node) && "Not an ia32 node.");
1303 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1304 assert(attr->slots[pos] && "No register assigned");
1306 return arch_register_get_index(attr->slots[pos]);
1310 * Returns the OUT register at position pos.
1312 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1313 ia32_attr_t *attr = get_ia32_attr(node);
1315 assert(is_ia32_irn(node) && "Not an ia32 node.");
1316 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1317 assert(attr->slots[pos] && "No register assigned");
1319 return attr->slots[pos];
1323 * Initializes the nodes attributes.
1325 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1326 const ia32_register_req_t **out_reqs, int n_res, unsigned latency)
1328 ia32_attr_t *attr = get_ia32_attr(node);
1329 set_ia32_flags(node, flags);
1330 set_ia32_in_req_all(node, in_reqs);
1331 set_ia32_out_req_all(node, out_reqs);
1332 set_ia32_latency(node, latency);
1334 attr->data.n_res = n_res;
1335 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1338 /***************************************************************************************
1341 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1342 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1343 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1344 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1346 ***************************************************************************************/
1348 /* default compare operation to compare immediate ops */
1349 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1352 if (a->data.tp == b->data.tp) {
1353 equ = (a->cnst == b->cnst);
1354 equ = equ ? (a->data.use_frame == b->data.use_frame) : 0;
1356 if (equ && a->data.use_frame && b->data.use_frame)
1357 equ = (a->frame_ent == b->frame_ent);
1363 /* compare converts */
1364 int ia32_compare_conv_attr(ia32_attr_t *a, ia32_attr_t *b) {
1365 int equ = ! ia32_compare_immop_attr(a, b);
1367 equ = equ ? (a->src_mode == b->src_mode) && (a->tgt_mode == b->tgt_mode) : equ;
1372 /* Include the generated constructor functions */
1373 #include "gen_ia32_new_nodes.c.inl"