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));
247 /* dump supported am */
248 fprintf(F, "AM support = ");
249 switch (get_ia32_am_support(n)) {
254 fprintf(F, "source only (Load)");
257 fprintf(F, "dest only (Load+Store)");
263 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
268 /* dump am flavour */
269 fprintf(F, "AM flavour =");
270 am_flav = get_ia32_am_flavour(n);
271 if (am_flav == ia32_am_N) {
275 if (am_flav & ia32_O) {
278 if (am_flav & ia32_B) {
281 if (am_flav & ia32_I) {
284 if (am_flav & ia32_S) {
288 fprintf(F, " (%d)\n", am_flav);
291 fprintf(F, "AM offset = ");
292 if (get_ia32_am_offs(n)) {
293 fprintf(F, "%s", get_ia32_am_offs(n));
301 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
304 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
307 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
310 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
313 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
316 fprintf(F, "flags =");
317 flags = get_ia32_flags(n);
318 if (flags == arch_irn_flags_none) {
322 if (flags & arch_irn_flags_dont_spill) {
323 fprintf(F, " unspillable");
325 if (flags & arch_irn_flags_rematerializable) {
326 fprintf(F, " remat");
328 if (flags & arch_irn_flags_ignore) {
329 fprintf(F, " ignore");
332 fprintf(F, " (%d)\n", flags);
334 /* dump frame entity */
335 fprintf(F, "frame entity = ");
336 if (get_ia32_frame_ent(n)) {
337 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
345 /* dump original ir node name */
346 fprintf(F, "orig node = ");
347 if (get_ia32_orig_node(n)) {
348 fprintf(F, "%s", get_ia32_orig_node(n));
356 fprintf(F, "=== IA32 attr end ===\n");
357 /* end of: case dump_node_info_txt */
366 /***************************************************************************************************
368 * | | | | | | / / | | | | | | | |
369 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
370 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
371 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
372 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
375 ***************************************************************************************************/
378 * Returns an ident for the given tarval tv.
380 static ident *get_ident_for_tv(tarval *tv) {
382 int len = tarval_snprintf(buf, sizeof(buf), tv);
384 return new_id_from_str(buf);
388 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
389 * Firm was made by people hating const :-(
391 ia32_attr_t *get_ia32_attr(const ir_node *node) {
392 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
393 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
397 * Gets the type of an ia32 node.
399 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
400 ia32_attr_t *attr = get_ia32_attr(node);
401 return attr->data.tp;
405 * Sets the type of an ia32 node.
407 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
408 ia32_attr_t *attr = get_ia32_attr(node);
413 * Gets the immediate op type of an ia32 node.
415 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
416 ia32_attr_t *attr = get_ia32_attr(node);
417 return attr->data.imm_tp;
421 * Sets the immediate op type of an ia32 node.
423 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
424 ia32_attr_t *attr = get_ia32_attr(node);
425 attr->data.imm_tp = 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 * Joins all offsets to one string with adds.
463 char *get_ia32_am_offs(const ir_node *node) {
464 ia32_attr_t *attr = get_ia32_attr(node);
468 if (! attr->am_offs) {
472 if (! attr->plain_offs)
473 attr->plain_offs = (struct obstack *)_new_arr_d(get_irg_obstack(get_irn_irg(node)), 1, sizeof(*(attr->plain_offs)));
475 obstack_free(attr->plain_offs, NULL);
477 obstack_init(attr->plain_offs);
479 size = obstack_object_size(attr->am_offs);
481 res = obstack_alloc(attr->plain_offs, size + 2);
482 res[0] = attr->data.offs_sign ? '-' : '+';
483 memcpy(&res[1], obstack_base(attr->am_offs), size);
484 res[size + 1] = '\0';
491 * Add an offset for addrmode.
493 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
494 ia32_attr_t *attr = get_ia32_attr(node);
496 if (! offset || strlen(offset) < 1)
499 /* offset could already have an explicit sign */
500 /* -> supersede op if necessary */
501 if (offset[0] == '-' || offset[0] == '+') {
502 if (offset[0] == '-') {
503 op = (op == '-') ? '+' : '-';
506 /* skip explicit sign */
510 if (! attr->am_offs) {
511 /* obstack is not initialized */
512 attr->am_offs = (struct obstack *)_new_arr_d(get_irg_obstack(get_irn_irg(node)), 1, sizeof(*(attr->am_offs)));
513 obstack_init(attr->am_offs);
515 attr->data.offs_sign = (op == '-') ? 1 : 0;
518 /* If obstack is initialized, connect the new offset with op */
519 obstack_printf(attr->am_offs, "%c", op);
522 obstack_printf(attr->am_offs, "%s", offset);
526 * Add an offset for addrmode.
528 void add_ia32_am_offs(ir_node *node, const char *offset) {
529 extend_ia32_am_offs(node, (char *)offset, '+');
533 * Sub an offset for addrmode.
535 void sub_ia32_am_offs(ir_node *node, const char *offset) {
536 extend_ia32_am_offs(node, (char *)offset, '-');
540 * Returns the symconst ident associated to addrmode.
542 ident *get_ia32_am_sc(const ir_node *node) {
543 ia32_attr_t *attr = get_ia32_attr(node);
548 * Sets the symconst ident associated to addrmode.
550 void set_ia32_am_sc(ir_node *node, ident *sc) {
551 ia32_attr_t *attr = get_ia32_attr(node);
556 * Sets the sign bit for address mode symconst.
558 void set_ia32_am_sc_sign(ir_node *node) {
559 ia32_attr_t *attr = get_ia32_attr(node);
560 attr->data.am_sc_sign = 1;
564 * Clears the sign bit for address mode symconst.
566 void clear_ia32_am_sc_sign(ir_node *node) {
567 ia32_attr_t *attr = get_ia32_attr(node);
568 attr->data.am_sc_sign = 0;
572 * Returns the sign bit for address mode symconst.
574 int is_ia32_am_sc_sign(const ir_node *node) {
575 ia32_attr_t *attr = get_ia32_attr(node);
576 return attr->data.am_sc_sign;
580 * Gets the addr mode const.
582 int get_ia32_am_scale(const ir_node *node) {
583 ia32_attr_t *attr = get_ia32_attr(node);
584 return attr->data.am_scale;
588 * Sets the index register scale for addrmode.
590 void set_ia32_am_scale(ir_node *node, int scale) {
591 ia32_attr_t *attr = get_ia32_attr(node);
592 attr->data.am_scale = scale;
596 * Return the tarval of an immediate operation or NULL in case of SymConst
598 tarval *get_ia32_Immop_tarval(const ir_node *node) {
599 ia32_attr_t *attr = get_ia32_attr(node);
600 return attr->cnst_val.tv;
604 * Sets the attributes of an immediate operation to the specified tarval
606 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
607 ia32_attr_t *attr = get_ia32_attr(node);
608 attr->cnst_val.tv = tv;
609 attr->cnst = get_ident_for_tv(tv);
613 * Return the sc attribute.
615 ident *get_ia32_sc(const ir_node *node) {
616 ia32_attr_t *attr = get_ia32_attr(node);
617 return attr->cnst_val.sc;
621 * Sets the sc attribute.
623 void set_ia32_sc(ir_node *node, ident *sc) {
624 ia32_attr_t *attr = get_ia32_attr(node);
625 attr->cnst_val.sc = sc;
626 attr->cnst = attr->cnst_val.sc;
630 * Gets the string representation of the internal const (tv or symconst)
632 const char *get_ia32_cnst(const ir_node *node) {
633 ia32_attr_t *attr = get_ia32_attr(node);
636 return get_id_str(attr->cnst);
640 * Sets the string representation of the internal const.
642 void set_ia32_cnst(ir_node *node, char *cnst) {
643 ia32_attr_t *attr = get_ia32_attr(node);
644 attr->cnst = new_id_from_str(cnst);
648 * Gets the ident representation of the internal const (tv or symconst)
650 ident *get_ia32_id_cnst(const ir_node *node) {
651 ia32_attr_t *attr = get_ia32_attr(node);
656 * Sets the ident representation of the internal const.
658 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
659 ia32_attr_t *attr = get_ia32_attr(node);
664 * Sets the uses_frame flag.
666 void set_ia32_use_frame(ir_node *node) {
667 ia32_attr_t *attr = get_ia32_attr(node);
668 attr->data.use_frame = 1;
672 * Clears the uses_frame flag.
674 void clear_ia32_use_frame(ir_node *node) {
675 ia32_attr_t *attr = get_ia32_attr(node);
676 attr->data.use_frame = 0;
680 * Gets the uses_frame flag.
682 int is_ia32_use_frame(const ir_node *node) {
683 ia32_attr_t *attr = get_ia32_attr(node);
684 return attr->data.use_frame;
688 * Sets node to commutative.
690 void set_ia32_commutative(ir_node *node) {
691 ia32_attr_t *attr = get_ia32_attr(node);
692 attr->data.is_commutative = 1;
696 * Sets node to non-commutative.
698 void clear_ia32_commutative(ir_node *node) {
699 ia32_attr_t *attr = get_ia32_attr(node);
700 attr->data.is_commutative = 0;
704 * Checks if node is commutative.
706 int is_ia32_commutative(const ir_node *node) {
707 ia32_attr_t *attr = get_ia32_attr(node);
708 return attr->data.is_commutative;
714 void set_ia32_emit_cl(ir_node *node) {
715 ia32_attr_t *attr = get_ia32_attr(node);
716 attr->data.emit_cl = 1;
720 * Clears node emit_cl.
722 void clear_ia32_emit_cl(ir_node *node) {
723 ia32_attr_t *attr = get_ia32_attr(node);
724 attr->data.emit_cl = 0;
728 * Checks if node needs %cl.
730 int is_ia32_emit_cl(const ir_node *node) {
731 ia32_attr_t *attr = get_ia32_attr(node);
732 return attr->data.emit_cl;
738 void set_ia32_got_lea(ir_node *node) {
739 ia32_attr_t *attr = get_ia32_attr(node);
740 attr->data.got_lea = 1;
744 * Clears node got_lea.
746 void clear_ia32_got_lea(ir_node *node) {
747 ia32_attr_t *attr = get_ia32_attr(node);
748 attr->data.got_lea = 0;
752 * Checks if node got lea.
754 int is_ia32_got_lea(const ir_node *node) {
755 ia32_attr_t *attr = get_ia32_attr(node);
756 return attr->data.got_lea;
760 * Gets the mode of the stored/loaded value (only set for Store/Load)
762 ir_mode *get_ia32_ls_mode(const ir_node *node) {
763 ia32_attr_t *attr = get_ia32_attr(node);
764 return attr->ls_mode;
768 * Sets the mode of the stored/loaded value (only set for Store/Load)
770 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
771 ia32_attr_t *attr = get_ia32_attr(node);
772 attr->ls_mode = mode;
776 * Gets the mode of the result.
778 ir_mode *get_ia32_res_mode(const ir_node *node) {
779 ia32_attr_t *attr = get_ia32_attr(node);
780 return attr->res_mode;
784 * Sets the mode of the result.
786 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
787 ia32_attr_t *attr = get_ia32_attr(node);
788 attr->res_mode = mode;
792 * Gets the source mode of conversion.
794 ir_mode *get_ia32_src_mode(const ir_node *node) {
795 ia32_attr_t *attr = get_ia32_attr(node);
796 return attr->src_mode;
800 * Sets the source mode of conversion.
802 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
803 ia32_attr_t *attr = get_ia32_attr(node);
804 attr->src_mode = mode;
808 * Gets the target mode of conversion.
810 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
811 ia32_attr_t *attr = get_ia32_attr(node);
812 return attr->tgt_mode;
816 * Sets the target mode of conversion.
818 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
819 ia32_attr_t *attr = get_ia32_attr(node);
820 attr->tgt_mode = mode;
824 * Gets the frame entity assigned to this node;
826 entity *get_ia32_frame_ent(const ir_node *node) {
827 ia32_attr_t *attr = get_ia32_attr(node);
828 return attr->frame_ent;
832 * Sets the frame entity for this node;
834 void set_ia32_frame_ent(ir_node *node, entity *ent) {
835 ia32_attr_t *attr = get_ia32_attr(node);
836 attr->frame_ent = ent;
840 * Returns the argument register requirements of an ia32 node.
842 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
843 ia32_attr_t *attr = get_ia32_attr(node);
848 * Sets the argument register requirements of an ia32 node.
850 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
851 ia32_attr_t *attr = get_ia32_attr(node);
856 * Returns the result register requirements of an ia32 node.
858 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
859 ia32_attr_t *attr = get_ia32_attr(node);
860 return attr->out_req;
864 * Sets the result register requirements of an ia32 node.
866 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
867 ia32_attr_t *attr = get_ia32_attr(node);
868 attr->out_req = reqs;
872 * Returns the argument register requirement at position pos of an ia32 node.
874 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
875 ia32_attr_t *attr = get_ia32_attr(node);
876 return attr->in_req[pos];
880 * Returns the result register requirement at position pos of an ia32 node.
882 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
883 ia32_attr_t *attr = get_ia32_attr(node);
884 return attr->out_req[pos];
888 * Sets the OUT register requirements at position pos.
890 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
891 ia32_attr_t *attr = get_ia32_attr(node);
892 attr->out_req[pos] = req;
896 * Sets the IN register requirements at position pos.
898 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
899 ia32_attr_t *attr = get_ia32_attr(node);
900 attr->in_req[pos] = req;
904 * Returns the register flag of an ia32 node.
906 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
907 ia32_attr_t *attr = get_ia32_attr(node);
908 return attr->data.flags;
912 * Sets the register flag of an ia32 node.
914 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
915 ia32_attr_t *attr = get_ia32_attr(node);
916 attr->data.flags = flags;
920 * Returns the result register slots of an ia32 node.
922 const arch_register_t **get_ia32_slots(const ir_node *node) {
923 ia32_attr_t *attr = get_ia32_attr(node);
928 * Sets the number of results.
930 void set_ia32_n_res(ir_node *node, int n_res) {
931 ia32_attr_t *attr = get_ia32_attr(node);
932 attr->data.n_res = n_res;
936 * Returns the number of results.
938 int get_ia32_n_res(const ir_node *node) {
939 ia32_attr_t *attr = get_ia32_attr(node);
940 return attr->data.n_res;
944 * Returns the flavour of an ia32 node,
946 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
947 ia32_attr_t *attr = get_ia32_attr(node);
948 return attr->data.op_flav;
952 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
954 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
955 ia32_attr_t *attr = get_ia32_attr(node);
956 attr->data.op_flav = op_flav;
960 * Returns the projnum code.
962 long get_ia32_pncode(const ir_node *node) {
963 ia32_attr_t *attr = get_ia32_attr(node);
964 return attr->pn_code;
968 * Sets the projnum code
970 void set_ia32_pncode(ir_node *node, long code) {
971 ia32_attr_t *attr = get_ia32_attr(node);
972 attr->pn_code = code;
978 * Returns the name of the original ir node.
980 const char *get_ia32_orig_node(const ir_node *node) {
981 ia32_attr_t *attr = get_ia32_attr(node);
982 return attr->orig_node;
986 * Sets the name of the original ir node.
988 void set_ia32_orig_node(ir_node *node, const char *name) {
989 ia32_attr_t *attr = get_ia32_attr(node);
990 attr->orig_node = name;
995 /******************************************************************************************************
997 * (_) | | | | | | / _| | | (_)
998 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
999 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1000 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1001 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1004 ******************************************************************************************************/
1007 * Gets the type of an ia32_Const.
1009 unsigned get_ia32_Const_type(const ir_node *node) {
1010 ia32_attr_t *attr = get_ia32_attr(node);
1012 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1014 return attr->data.tp;
1018 * Sets the type of an ia32_Const.
1020 void set_ia32_Const_type(ir_node *node, int type) {
1021 ia32_attr_t *attr = get_ia32_attr(node);
1023 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1024 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1026 attr->data.tp = type;
1030 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1032 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1033 ia32_attr_t *na = get_ia32_attr(node);
1034 ia32_attr_t *ca = get_ia32_attr(cnst);
1036 switch(get_ia32_Const_type(cnst)) {
1038 na->cnst_val.tv = ca->cnst_val.tv;
1039 na->cnst = ca->cnst;
1040 set_ia32_immop_type(node, ia32_ImmConst);
1043 na->cnst_val.sc = ca->cnst_val.sc;
1044 na->cnst = na->cnst_val.sc;
1045 set_ia32_immop_type(node, ia32_ImmSymConst);
1048 assert(0 && "Need ia32_Const to set Immop attr");
1053 * Copy the attributes from Immop to an Immop
1055 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1056 ia32_attr_t *da = get_ia32_attr(dst);
1057 ia32_attr_t *sa = get_ia32_attr(src);
1059 switch(get_ia32_immop_type(src)) {
1061 da->cnst_val.tv = sa->cnst_val.tv;
1062 da->cnst = sa->cnst;
1063 set_ia32_immop_type(dst, ia32_ImmConst);
1065 case ia32_ImmSymConst:
1066 da->cnst_val.sc = sa->cnst_val.sc;
1067 da->cnst = sa->cnst;
1068 set_ia32_immop_type(dst, ia32_ImmSymConst);
1071 assert(0 && "Need Immop to copy Immop attr");
1076 * Copy the attributes from a Firm Const to an ia32_Const
1078 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1079 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1082 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1084 switch (get_irn_opcode(cnst)) {
1086 attr->data.tp = ia32_Const;
1087 attr->cnst_val.tv = get_Const_tarval(cnst);
1088 mode = get_tarval_mode(attr->cnst_val.tv);
1089 if (mode_is_reference(mode) &&
1090 get_mode_null(mode) == attr->cnst_val.tv)
1091 attr->cnst_val.tv = get_mode_null(mode_Is);
1092 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1095 attr->data.tp = ia32_SymConst;
1096 attr->cnst_val.sc = get_sc_ident(cnst);
1097 attr->cnst = attr->cnst_val.sc;
1100 assert(0 && "Unknown Const NYI");
1103 assert(0 && "Cannot create ia32_Const for this opcode");
1108 * Sets the AddrMode(S|D) attribute
1110 void set_ia32_AddrMode(ir_node *node, char direction) {
1111 ia32_attr_t *attr = get_ia32_attr(node);
1113 switch (direction) {
1115 attr->data.tp = ia32_AddrModeD;
1118 attr->data.tp = ia32_AddrModeS;
1121 assert(0 && "wrong AM type");
1126 * Returns whether or not the node is an immediate operation with Const.
1128 int is_ia32_ImmConst(const ir_node *node) {
1129 ia32_attr_t *attr = get_ia32_attr(node);
1130 return (attr->data.imm_tp == ia32_ImmConst);
1134 * Returns whether or not the node is an immediate operation with SymConst.
1136 int is_ia32_ImmSymConst(const ir_node *node) {
1137 ia32_attr_t *attr = get_ia32_attr(node);
1138 return (attr->data.imm_tp == ia32_ImmSymConst);
1142 * Returns whether or not the node is an AddrModeS node.
1144 int is_ia32_AddrModeS(const ir_node *node) {
1145 ia32_attr_t *attr = get_ia32_attr(node);
1146 return (attr->data.tp == ia32_AddrModeS);
1150 * Returns whether or not the node is an AddrModeD node.
1152 int is_ia32_AddrModeD(const ir_node *node) {
1153 ia32_attr_t *attr = get_ia32_attr(node);
1154 return (attr->data.tp == ia32_AddrModeD);
1158 * Checks if node is a Load or xLoad/vfLoad.
1160 int is_ia32_Ld(const ir_node *node) {
1161 return is_ia32_Load(node) || is_ia32_xLoad(node) || is_ia32_vfld(node) || is_ia32_fld(node);
1165 * Checks if node is a Store or xStore/vfStore.
1167 int is_ia32_St(const ir_node *node) {
1168 return is_ia32_Store(node) || is_ia32_xStore(node) || is_ia32_vfst(node) || is_ia32_fst(node) || is_ia32_fstp(node);
1172 * Checks if node is a Const or xConst/vfConst.
1174 int is_ia32_Cnst(const ir_node *node) {
1175 return is_ia32_Const(node) || is_ia32_xConst(node) || is_ia32_vfConst(node);
1179 * Returns the name of the OUT register at position pos.
1181 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1182 ia32_attr_t *attr = get_ia32_attr(node);
1184 assert(is_ia32_irn(node) && "Not an ia32 node.");
1185 assert(pos < attr->data.n_res && "Invalid OUT position.");
1186 assert(attr->slots[pos] && "No register assigned");
1188 return arch_register_get_name(attr->slots[pos]);
1192 * Returns the index of the OUT register at position pos within its register class.
1194 int get_ia32_out_regnr(const ir_node *node, int pos) {
1195 ia32_attr_t *attr = get_ia32_attr(node);
1197 assert(is_ia32_irn(node) && "Not an ia32 node.");
1198 assert(pos < attr->data.n_res && "Invalid OUT position.");
1199 assert(attr->slots[pos] && "No register assigned");
1201 return arch_register_get_index(attr->slots[pos]);
1205 * Returns the OUT register at position pos.
1207 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1208 ia32_attr_t *attr = get_ia32_attr(node);
1210 assert(is_ia32_irn(node) && "Not an ia32 node.");
1211 assert(pos < attr->data.n_res && "Invalid OUT position.");
1212 assert(attr->slots[pos] && "No register assigned");
1214 return attr->slots[pos];
1218 * Initializes the nodes attributes.
1220 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1221 const ia32_register_req_t **out_reqs, int n_res)
1223 ia32_attr_t *attr = get_ia32_attr(node);
1224 set_ia32_flags(node, flags);
1225 set_ia32_in_req_all(node, in_reqs);
1226 set_ia32_out_req_all(node, out_reqs);
1228 attr->data.n_res = n_res;
1229 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1232 /***************************************************************************************
1235 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1236 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1237 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1238 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1240 ***************************************************************************************/
1242 /* default compare operation to compare immediate ops */
1243 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1246 if (a->data.tp == b->data.tp) {
1247 equ = (a->cnst == b->cnst);
1248 equ = equ ? (a->data.use_frame == b->data.use_frame) : 0;
1250 if (equ && a->data.use_frame && b->data.use_frame)
1251 equ = (a->frame_ent == b->frame_ent);
1257 /* compare converts */
1258 int ia32_compare_conv_attr(ia32_attr_t *a, ia32_attr_t *b) {
1259 int equ = ! ia32_compare_immop_attr(a, b);
1261 equ = equ ? (a->src_mode == b->src_mode) && (a->tgt_mode == b->tgt_mode) : equ;
1266 /* Include the generated constructor functions */
1267 #include "gen_ia32_new_nodes.c.inl"