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");
73 * returns true if a node has x87 registers
75 int ia32_has_x87_register(const ir_node *n) {
76 assert(is_ia32_irn(n) && "Need ia32 node.");
77 return is_irn_machine_user(n, 0);
80 /***********************************************************************************
83 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
84 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
85 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
86 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
89 ***********************************************************************************/
92 * Returns a string containing the names of all registers within the limited bitset
94 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
95 bitset_t *bs = bitset_alloca(req->cls->n_regs);
100 req->limited(NULL, bs);
102 for (i = 0; i < req->cls->n_regs; i++) {
103 if (bitset_is_set(bs, i)) {
104 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
106 fprintf(stderr, "dumper problem, exiting\n");
122 * Dumps the register requirements for either in or out.
124 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
125 char *dir = inout ? "out" : "in";
126 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
127 char *buf = alloca(1024);
130 memset(buf, 0, 1024);
133 for (i = 0; i < max; i++) {
134 fprintf(F, "%sreq #%d =", dir, i);
136 if (reqs[i]->req.type == arch_register_req_type_none) {
140 if (reqs[i]->req.type & arch_register_req_type_normal) {
141 fprintf(F, " %s", reqs[i]->req.cls->name);
144 if (reqs[i]->req.type & arch_register_req_type_limited) {
145 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
148 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
149 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
152 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
153 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
162 fprintf(F, "%sreq = N/A\n", dir);
167 * Dumper interface for dumping ia32 nodes in vcg.
168 * @param n the node to dump
169 * @param F the output file
170 * @param reason indicates which kind of information should be dumped
171 * @return 0 on success or != 0 on failure
173 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
174 ir_mode *mode = NULL;
176 int i, n_res, am_flav, flags;
177 const ia32_register_req_t **reqs;
178 const arch_register_t **slots;
181 case dump_node_opcode_txt:
182 fprintf(F, "%s", get_irn_opname(n));
185 case dump_node_mode_txt:
186 mode = get_irn_mode(n);
188 if (is_ia32_Ld(n) || is_ia32_St(n)) {
189 mode = get_ia32_ls_mode(n);
192 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
195 case dump_node_nodeattr_txt:
196 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
197 char *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
198 const char *cnst = get_ia32_cnst(n);
200 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
203 if (! is_ia32_Lea(n)) {
204 if (is_ia32_AddrModeS(n)) {
205 fprintf(F, "[AM S] ");
207 else if (is_ia32_AddrModeD(n)) {
208 fprintf(F, "[AM D] ");
214 case dump_node_info_txt:
215 n_res = get_ia32_n_res(n);
216 fprintf(F, "=== IA32 attr begin ===\n");
218 /* dump IN requirements */
219 if (get_irn_arity(n) > 0) {
220 reqs = get_ia32_in_req_all(n);
221 dump_reg_req(F, n, reqs, 0);
224 /* dump OUT requirements */
226 reqs = get_ia32_out_req_all(n);
227 dump_reg_req(F, n, reqs, 1);
230 /* dump assigned registers */
231 slots = get_ia32_slots(n);
232 if (slots && n_res > 0) {
233 for (i = 0; i < n_res; i++) {
234 const arch_register_t *reg;
236 /* retrieve "real" x87 register */
237 if (ia32_has_x87_register(n))
238 reg = get_ia32_attr(n)->x87[i + 2];
242 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
249 switch (get_ia32_op_type(n)) {
251 fprintf(F, "Normal");
257 fprintf(F, "SymConst");
260 fprintf(F, "AM Dest (Load+Store)");
263 fprintf(F, "AM Source (Load)");
266 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
271 /* dump immop type */
272 fprintf(F, "immediate = ");
273 switch (get_ia32_immop_type(n)) {
280 case ia32_ImmSymConst:
281 fprintf(F, "SymConst");
284 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
289 /* dump supported am */
290 fprintf(F, "AM support = ");
291 switch (get_ia32_am_support(n)) {
296 fprintf(F, "source only (Load)");
299 fprintf(F, "dest only (Load+Store)");
305 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
310 /* dump am flavour */
311 fprintf(F, "AM flavour =");
312 am_flav = get_ia32_am_flavour(n);
313 if (am_flav == ia32_am_N) {
317 if (am_flav & ia32_O) {
320 if (am_flav & ia32_B) {
323 if (am_flav & ia32_I) {
326 if (am_flav & ia32_S) {
330 fprintf(F, " (%d)\n", am_flav);
333 fprintf(F, "AM offset = ");
334 if (get_ia32_am_offs(n)) {
335 fprintf(F, "%s", get_ia32_am_offs(n));
343 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
346 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
349 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
352 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
355 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
358 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
361 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
364 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
367 fprintf(F, "latency = %d\n", get_ia32_latency(n));
370 fprintf(F, "flags =");
371 flags = get_ia32_flags(n);
372 if (flags == arch_irn_flags_none) {
376 if (flags & arch_irn_flags_dont_spill) {
377 fprintf(F, " unspillable");
379 if (flags & arch_irn_flags_rematerializable) {
380 fprintf(F, " remat");
382 if (flags & arch_irn_flags_ignore) {
383 fprintf(F, " ignore");
385 if (flags & arch_irn_flags_modify_sp) {
386 fprintf(F, " modify_sp");
389 fprintf(F, " (%d)\n", flags);
391 /* dump frame entity */
392 fprintf(F, "frame entity = ");
393 if (get_ia32_frame_ent(n)) {
394 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
402 fprintf(F, "ls_mode = ");
403 if (get_ia32_ls_mode(n)) {
404 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
411 fprintf(F, "res_mode = ");
412 if (get_ia32_res_mode(n)) {
413 ir_fprintf(F, "%+F", get_ia32_res_mode(n));
420 fprintf(F, "src_mode = ");
421 if (get_ia32_src_mode(n)) {
422 ir_fprintf(F, "%+F", get_ia32_src_mode(n));
429 fprintf(F, "tgt_mode = ");
430 if (get_ia32_tgt_mode(n)) {
431 ir_fprintf(F, "%+F", get_ia32_tgt_mode(n));
439 /* dump original ir node name */
440 fprintf(F, "orig node = ");
441 if (get_ia32_orig_node(n)) {
442 fprintf(F, "%s", get_ia32_orig_node(n));
450 fprintf(F, "=== IA32 attr end ===\n");
451 /* end of: case dump_node_info_txt */
460 /***************************************************************************************************
462 * | | | | | | / / | | | | | | | |
463 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
464 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
465 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
466 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
469 ***************************************************************************************************/
472 * Returns an ident for the given tarval tv.
474 static ident *get_ident_for_tv(tarval *tv) {
476 int len = tarval_snprintf(buf, sizeof(buf), tv);
478 return new_id_from_str(buf);
482 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
483 * Firm was made by people hating const :-(
485 ia32_attr_t *get_ia32_attr(const ir_node *node) {
486 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
487 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
491 * Gets the type of an ia32 node.
493 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
494 ia32_attr_t *attr = get_ia32_attr(node);
495 return attr->data.tp;
499 * Sets the type of an ia32 node.
501 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
502 ia32_attr_t *attr = get_ia32_attr(node);
507 * Gets the immediate op type of an ia32 node.
509 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
510 ia32_attr_t *attr = get_ia32_attr(node);
511 return attr->data.imm_tp;
515 * Sets the immediate op type of an ia32 node.
517 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
518 ia32_attr_t *attr = get_ia32_attr(node);
519 attr->data.imm_tp = tp;
523 * Gets the supported addrmode of an ia32 node
525 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
526 ia32_attr_t *attr = get_ia32_attr(node);
527 return attr->data.am_support;
531 * Sets the supported addrmode of an ia32 node
533 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
534 ia32_attr_t *attr = get_ia32_attr(node);
535 attr->data.am_support = am_tp;
539 * Gets the addrmode flavour of an ia32 node
541 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
542 ia32_attr_t *attr = get_ia32_attr(node);
543 return attr->data.am_flavour;
547 * Sets the addrmode flavour of an ia32 node
549 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
550 ia32_attr_t *attr = get_ia32_attr(node);
551 attr->data.am_flavour = am_flavour;
555 * Joins all offsets to one string with adds.
557 char *get_ia32_am_offs(const ir_node *node) {
558 ia32_attr_t *attr = get_ia32_attr(node);
561 snprintf(res, sizeof(res), "%+d", attr->am_offs);
567 * Gets the addressmode offset as long.
569 int get_ia32_am_offs_int(const ir_node *node) {
570 ia32_attr_t *attr = get_ia32_attr(node);
571 return attr->am_offs;
575 * Add an offset for addrmode.
577 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
578 ia32_attr_t *attr = get_ia32_attr(node);
581 if (offset == NULL || offset[0] == '\0')
584 if (offset[0] == '-')
585 res = sscanf(offset, "%d", &o);
587 res = sscanf(offset, "%u", &o);
599 * Add an offset for addrmode.
601 void add_ia32_am_offs(ir_node *node, const char *offset) {
602 extend_ia32_am_offs(node, (char *)offset, '+');
605 void add_ia32_am_offs_int(ir_node *node, int offset) {
606 ia32_attr_t *attr = get_ia32_attr(node);
607 attr->am_offs += offset;
611 * Sub an offset for addrmode.
613 void sub_ia32_am_offs(ir_node *node, const char *offset) {
614 extend_ia32_am_offs(node, (char *)offset, '-');
618 * Returns the symconst ident associated to addrmode.
620 ident *get_ia32_am_sc(const ir_node *node) {
621 ia32_attr_t *attr = get_ia32_attr(node);
626 * Sets the symconst ident associated to addrmode.
628 void set_ia32_am_sc(ir_node *node, ident *sc) {
629 ia32_attr_t *attr = get_ia32_attr(node);
634 * Sets the sign bit for address mode symconst.
636 void set_ia32_am_sc_sign(ir_node *node) {
637 ia32_attr_t *attr = get_ia32_attr(node);
638 attr->data.am_sc_sign = 1;
642 * Clears the sign bit for address mode symconst.
644 void clear_ia32_am_sc_sign(ir_node *node) {
645 ia32_attr_t *attr = get_ia32_attr(node);
646 attr->data.am_sc_sign = 0;
650 * Returns the sign bit for address mode symconst.
652 int is_ia32_am_sc_sign(const ir_node *node) {
653 ia32_attr_t *attr = get_ia32_attr(node);
654 return attr->data.am_sc_sign;
658 * Gets the addr mode const.
660 int get_ia32_am_scale(const ir_node *node) {
661 ia32_attr_t *attr = get_ia32_attr(node);
662 return attr->data.am_scale;
666 * Sets the index register scale for addrmode.
668 void set_ia32_am_scale(ir_node *node, int scale) {
669 ia32_attr_t *attr = get_ia32_attr(node);
670 attr->data.am_scale = scale;
674 * Return the tarval of an immediate operation or NULL in case of SymConst
676 tarval *get_ia32_Immop_tarval(const ir_node *node) {
677 ia32_attr_t *attr = get_ia32_attr(node);
678 return attr->cnst_val.tv;
682 * Sets the attributes of an immediate operation to the specified tarval
684 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
685 ia32_attr_t *attr = get_ia32_attr(node);
686 attr->cnst_val.tv = tv;
687 attr->cnst = get_ident_for_tv(tv);
691 * Gets the string representation of the internal const (tv or symconst)
693 const char *get_ia32_cnst(const ir_node *node) {
694 ia32_attr_t *attr = get_ia32_attr(node);
697 return get_id_str(attr->cnst);
701 * Sets the string representation of the internal const.
703 void set_ia32_cnst(ir_node *node, const char *cnst) {
704 ia32_attr_t *attr = get_ia32_attr(node);
705 attr->cnst = new_id_from_str(cnst);
709 * Gets the ident representation of the internal const (tv or symconst)
711 ident *get_ia32_id_cnst(const ir_node *node) {
712 ia32_attr_t *attr = get_ia32_attr(node);
717 * Sets the ident representation of the internal const.
719 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
720 ia32_attr_t *attr = get_ia32_attr(node);
725 * Sets the uses_frame flag.
727 void set_ia32_use_frame(ir_node *node) {
728 ia32_attr_t *attr = get_ia32_attr(node);
729 attr->data.use_frame = 1;
733 * Clears the uses_frame flag.
735 void clear_ia32_use_frame(ir_node *node) {
736 ia32_attr_t *attr = get_ia32_attr(node);
737 attr->data.use_frame = 0;
741 * Gets the uses_frame flag.
743 int is_ia32_use_frame(const ir_node *node) {
744 ia32_attr_t *attr = get_ia32_attr(node);
745 return attr->data.use_frame;
749 * Sets node to commutative.
751 void set_ia32_commutative(ir_node *node) {
752 ia32_attr_t *attr = get_ia32_attr(node);
753 attr->data.is_commutative = 1;
757 * Sets node to non-commutative.
759 void clear_ia32_commutative(ir_node *node) {
760 ia32_attr_t *attr = get_ia32_attr(node);
761 attr->data.is_commutative = 0;
765 * Checks if node is commutative.
767 int is_ia32_commutative(const ir_node *node) {
768 ia32_attr_t *attr = get_ia32_attr(node);
769 return attr->data.is_commutative;
775 void set_ia32_emit_cl(ir_node *node) {
776 ia32_attr_t *attr = get_ia32_attr(node);
777 attr->data.emit_cl = 1;
781 * Clears node emit_cl.
783 void clear_ia32_emit_cl(ir_node *node) {
784 ia32_attr_t *attr = get_ia32_attr(node);
785 attr->data.emit_cl = 0;
789 * Checks if node needs %cl.
791 int is_ia32_emit_cl(const ir_node *node) {
792 ia32_attr_t *attr = get_ia32_attr(node);
793 return attr->data.emit_cl;
799 void set_ia32_got_lea(ir_node *node) {
800 ia32_attr_t *attr = get_ia32_attr(node);
801 attr->data.got_lea = 1;
805 * Clears node got_lea.
807 void clear_ia32_got_lea(ir_node *node) {
808 ia32_attr_t *attr = get_ia32_attr(node);
809 attr->data.got_lea = 0;
813 * Checks if node got lea.
815 int is_ia32_got_lea(const ir_node *node) {
816 ia32_attr_t *attr = get_ia32_attr(node);
817 return attr->data.got_lea;
821 * Sets node got_reload.
823 void set_ia32_got_reload(ir_node *node) {
824 ia32_attr_t *attr = get_ia32_attr(node);
825 attr->data.got_reload = 1;
829 * Clears node got_reload.
831 void clear_ia32_got_reload(ir_node *node) {
832 ia32_attr_t *attr = get_ia32_attr(node);
833 attr->data.got_reload = 0;
837 * Checks if node got reload.
839 int is_ia32_got_reload(const ir_node *node) {
840 ia32_attr_t *attr = get_ia32_attr(node);
841 return attr->data.got_reload;
845 * Gets the mode of the stored/loaded value (only set for Store/Load)
847 ir_mode *get_ia32_ls_mode(const ir_node *node) {
848 ia32_attr_t *attr = get_ia32_attr(node);
849 return attr->ls_mode;
853 * Sets the mode of the stored/loaded value (only set for Store/Load)
855 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
856 ia32_attr_t *attr = get_ia32_attr(node);
857 attr->ls_mode = mode;
861 * Gets the mode of the result.
863 ir_mode *get_ia32_res_mode(const ir_node *node) {
864 ia32_attr_t *attr = get_ia32_attr(node);
865 return attr->res_mode;
869 * Sets the mode of the result.
871 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
872 ia32_attr_t *attr = get_ia32_attr(node);
873 attr->res_mode = mode;
877 * Gets the source mode of conversion.
879 ir_mode *get_ia32_src_mode(const ir_node *node) {
880 ia32_attr_t *attr = get_ia32_attr(node);
881 return attr->src_mode;
885 * Sets the source mode of conversion.
887 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
888 ia32_attr_t *attr = get_ia32_attr(node);
889 attr->src_mode = mode;
893 * Gets the target mode of conversion.
895 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
896 ia32_attr_t *attr = get_ia32_attr(node);
897 return attr->tgt_mode;
901 * Sets the target mode of conversion.
903 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
904 ia32_attr_t *attr = get_ia32_attr(node);
905 attr->tgt_mode = mode;
909 * Gets the frame entity assigned to this node.
911 entity *get_ia32_frame_ent(const ir_node *node) {
912 ia32_attr_t *attr = get_ia32_attr(node);
913 return attr->frame_ent;
917 * Sets the frame entity for this node.
919 void set_ia32_frame_ent(ir_node *node, entity *ent) {
920 ia32_attr_t *attr = get_ia32_attr(node);
921 attr->frame_ent = ent;
922 set_ia32_use_frame(node);
927 * Gets the instruction latency.
929 unsigned get_ia32_latency(const ir_node *node) {
930 ia32_attr_t *attr = get_ia32_attr(node);
931 return attr->latency;
935 * Sets the instruction latency.
937 void set_ia32_latency(ir_node *node, unsigned latency) {
938 ia32_attr_t *attr = get_ia32_attr(node);
939 attr->latency = latency;
943 * Returns the argument register requirements of an ia32 node.
945 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
946 ia32_attr_t *attr = get_ia32_attr(node);
951 * Sets the argument register requirements of an ia32 node.
953 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
954 ia32_attr_t *attr = get_ia32_attr(node);
959 * Returns the result register requirements of an ia32 node.
961 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
962 ia32_attr_t *attr = get_ia32_attr(node);
963 return attr->out_req;
967 * Sets the result register requirements of an ia32 node.
969 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
970 ia32_attr_t *attr = get_ia32_attr(node);
971 attr->out_req = reqs;
975 * Returns the argument register requirement at position pos of an ia32 node.
977 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
978 ia32_attr_t *attr = get_ia32_attr(node);
979 return attr->in_req[pos];
983 * Returns the result register requirement at position pos of an ia32 node.
985 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
986 ia32_attr_t *attr = get_ia32_attr(node);
987 return attr->out_req[pos];
991 * Sets the OUT register requirements at position pos.
993 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
994 ia32_attr_t *attr = get_ia32_attr(node);
995 attr->out_req[pos] = req;
999 * Sets the IN register requirements at position pos.
1001 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
1002 ia32_attr_t *attr = get_ia32_attr(node);
1003 attr->in_req[pos] = req;
1007 * Returns the register flag of an ia32 node.
1009 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
1010 ia32_attr_t *attr = get_ia32_attr(node);
1011 return attr->data.flags;
1015 * Sets the register flag of an ia32 node.
1017 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
1018 ia32_attr_t *attr = get_ia32_attr(node);
1019 attr->data.flags = flags;
1023 * Returns the result register slots of an ia32 node.
1025 const arch_register_t **get_ia32_slots(const ir_node *node) {
1026 ia32_attr_t *attr = get_ia32_attr(node);
1031 * Sets the number of results.
1033 void set_ia32_n_res(ir_node *node, int n_res) {
1034 ia32_attr_t *attr = get_ia32_attr(node);
1035 attr->data.n_res = n_res;
1039 * Returns the number of results.
1041 int get_ia32_n_res(const ir_node *node) {
1042 ia32_attr_t *attr = get_ia32_attr(node);
1043 return attr->data.n_res;
1047 * Returns the flavour of an ia32 node,
1049 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1050 ia32_attr_t *attr = get_ia32_attr(node);
1051 return attr->data.op_flav;
1055 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1057 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1058 ia32_attr_t *attr = get_ia32_attr(node);
1059 attr->data.op_flav = op_flav;
1063 * Returns the projnum code.
1065 long get_ia32_pncode(const ir_node *node) {
1066 ia32_attr_t *attr = get_ia32_attr(node);
1067 return attr->pn_code;
1071 * Sets the projnum code
1073 void set_ia32_pncode(ir_node *node, long code) {
1074 ia32_attr_t *attr = get_ia32_attr(node);
1075 attr->pn_code = code;
1081 * Returns the name of the original ir node.
1083 const char *get_ia32_orig_node(const ir_node *node) {
1084 ia32_attr_t *attr = get_ia32_attr(node);
1085 return attr->orig_node;
1089 * Sets the name of the original ir node.
1091 void set_ia32_orig_node(ir_node *node, const char *name) {
1092 ia32_attr_t *attr = get_ia32_attr(node);
1093 attr->orig_node = name;
1098 /******************************************************************************************************
1100 * (_) | | | | | | / _| | | (_)
1101 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1102 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1103 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1104 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1107 ******************************************************************************************************/
1110 * Gets the type of an ia32_Const.
1112 unsigned get_ia32_Const_type(const ir_node *node) {
1113 ia32_attr_t *attr = get_ia32_attr(node);
1115 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1117 return attr->data.tp;
1121 * Sets the type of an ia32_Const.
1123 void set_ia32_Const_type(ir_node *node, int type) {
1124 ia32_attr_t *attr = get_ia32_attr(node);
1126 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1127 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1129 attr->data.tp = type;
1133 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1135 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1136 ia32_attr_t *na = get_ia32_attr(node);
1137 ia32_attr_t *ca = get_ia32_attr(cnst);
1139 switch(get_ia32_Const_type(cnst)) {
1141 na->cnst_val.tv = ca->cnst_val.tv;
1142 na->cnst = ca->cnst;
1143 set_ia32_immop_type(node, ia32_ImmConst);
1146 na->cnst_val.sc = ca->cnst_val.sc;
1147 na->cnst = na->cnst_val.sc;
1148 set_ia32_immop_type(node, ia32_ImmSymConst);
1151 assert(0 && "Need ia32_Const to set Immop attr");
1156 * Copy the attributes from Immop to an Immop
1158 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1159 ia32_attr_t *da = get_ia32_attr(dst);
1160 ia32_attr_t *sa = get_ia32_attr(src);
1162 switch(get_ia32_immop_type(src)) {
1164 da->cnst_val.tv = sa->cnst_val.tv;
1165 da->cnst = sa->cnst;
1166 set_ia32_immop_type(dst, ia32_ImmConst);
1168 case ia32_ImmSymConst:
1169 da->cnst_val.sc = sa->cnst_val.sc;
1170 da->cnst = sa->cnst;
1171 set_ia32_immop_type(dst, ia32_ImmSymConst);
1174 assert(0 && "Need Immop to copy Immop attr");
1179 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1181 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1182 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1185 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1187 switch (get_irn_opcode(cnst)) {
1189 attr->data.tp = ia32_Const;
1190 attr->cnst_val.tv = get_Const_tarval(cnst);
1191 mode = get_tarval_mode(attr->cnst_val.tv);
1192 if (mode_is_reference(mode) &&
1193 get_mode_null(mode) == attr->cnst_val.tv) {
1194 attr->cnst_val.tv = get_mode_null(mode_Iu);
1196 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1199 attr->data.tp = ia32_SymConst;
1200 attr->cnst_val.sc = get_sc_ident(cnst);
1201 attr->cnst = attr->cnst_val.sc;
1204 assert(0 && "Unknown Const NYI");
1207 assert(0 && "Cannot create ia32_Const for this opcode");
1212 * Sets the AddrMode(S|D) attribute
1214 void set_ia32_AddrMode(ir_node *node, char direction) {
1215 ia32_attr_t *attr = get_ia32_attr(node);
1217 switch (direction) {
1219 attr->data.tp = ia32_AddrModeD;
1222 attr->data.tp = ia32_AddrModeS;
1225 assert(0 && "wrong AM type");
1230 * Returns whether or not the node is an immediate operation with Const.
1232 int is_ia32_ImmConst(const ir_node *node) {
1233 ia32_attr_t *attr = get_ia32_attr(node);
1234 return (attr->data.imm_tp == ia32_ImmConst);
1238 * Returns whether or not the node is an immediate operation with SymConst.
1240 int is_ia32_ImmSymConst(const ir_node *node) {
1241 ia32_attr_t *attr = get_ia32_attr(node);
1242 return (attr->data.imm_tp == ia32_ImmSymConst);
1246 * Returns whether or not the node is an AddrModeS node.
1248 int is_ia32_AddrModeS(const ir_node *node) {
1249 ia32_attr_t *attr = get_ia32_attr(node);
1250 return (attr->data.tp == ia32_AddrModeS);
1254 * Returns whether or not the node is an AddrModeD node.
1256 int is_ia32_AddrModeD(const ir_node *node) {
1257 ia32_attr_t *attr = get_ia32_attr(node);
1258 return (attr->data.tp == ia32_AddrModeD);
1262 * Checks if node is a Load or xLoad/vfLoad.
1264 int is_ia32_Ld(const ir_node *node) {
1265 int op = get_ia32_irn_opcode(node);
1266 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1270 * Checks if node is a Store or xStore/vfStore.
1272 int is_ia32_St(const ir_node *node) {
1273 int op = get_ia32_irn_opcode(node);
1274 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1278 * Checks if node is a Const or xConst/vfConst.
1280 int is_ia32_Cnst(const ir_node *node) {
1281 int op = get_ia32_irn_opcode(node);
1282 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1286 * Returns the name of the OUT register at position pos.
1288 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1289 ia32_attr_t *attr = get_ia32_attr(node);
1291 assert(is_ia32_irn(node) && "Not an ia32 node.");
1292 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1293 assert(attr->slots[pos] && "No register assigned");
1295 return arch_register_get_name(attr->slots[pos]);
1299 * Returns the index of the OUT register at position pos within its register class.
1301 int get_ia32_out_regnr(const ir_node *node, int pos) {
1302 ia32_attr_t *attr = get_ia32_attr(node);
1304 assert(is_ia32_irn(node) && "Not an ia32 node.");
1305 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1306 assert(attr->slots[pos] && "No register assigned");
1308 return arch_register_get_index(attr->slots[pos]);
1312 * Returns the OUT register at position pos.
1314 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1315 ia32_attr_t *attr = get_ia32_attr(node);
1317 assert(is_ia32_irn(node) && "Not an ia32 node.");
1318 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1319 assert(attr->slots[pos] && "No register assigned");
1321 return attr->slots[pos];
1325 * Initializes the nodes attributes.
1327 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1328 const ia32_register_req_t **out_reqs, int n_res, unsigned latency)
1330 ia32_attr_t *attr = get_ia32_attr(node);
1331 set_ia32_flags(node, flags);
1332 set_ia32_in_req_all(node, in_reqs);
1333 set_ia32_out_req_all(node, out_reqs);
1334 set_ia32_latency(node, latency);
1336 attr->data.n_res = n_res;
1337 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1340 /***************************************************************************************
1343 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1344 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1345 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1346 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1348 ***************************************************************************************/
1350 /* default compare operation to compare immediate ops */
1351 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1354 if (a->data.tp == b->data.tp) {
1355 equ = (a->cnst == b->cnst);
1356 equ = equ ? (a->data.use_frame == b->data.use_frame) : 0;
1358 if (equ && a->data.use_frame && b->data.use_frame)
1359 equ = (a->frame_ent == b->frame_ent);
1365 /* compare converts */
1366 int ia32_compare_conv_attr(ia32_attr_t *a, ia32_attr_t *b) {
1367 int equ = ! ia32_compare_immop_attr(a, b);
1369 equ = equ ? (a->src_mode == b->src_mode) && (a->tgt_mode == b->tgt_mode) : equ;
1374 /* Copy attribute function not needed any more, but might be of use later. */
1376 /* copies the ia32 attributes */
1377 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1378 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1379 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1380 int n_res = get_ia32_n_res(old_node);
1382 /* copy the attributes */
1383 memcpy(attr_new, attr_old, sizeof(*attr_new));
1387 * Registers the ia32_copy_attr function for all ia32 opcodes.
1389 void ia32_register_copy_attr_func(void) {
1390 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1392 for (i = f; i < l; i++) {
1393 ir_op *op = get_irp_opcode(i);
1394 op->ops.copy_attr = ia32_copy_attr;
1399 /* Include the generated constructor functions */
1400 #include "gen_ia32_new_nodes.c.inl"