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"
38 #include "gen_ia32_machine.h"
41 * Returns the ident of a SymConst.
42 * @param symc The SymConst
43 * @return The ident of the SymConst
45 static ident *get_sc_ident(ir_node *symc) {
50 switch (get_SymConst_kind(symc)) {
51 case symconst_addr_name:
52 return get_SymConst_name(symc);
54 case symconst_addr_ent:
55 ent = get_SymConst_entity(symc);
56 owner = get_entity_owner(ent);
57 id = get_entity_ld_ident(ent);
58 if (owner == get_tls_type()) {
59 if (get_entity_visibility(ent) == visibility_external_allocated)
60 id = mangle(id, new_id_from_chars("@INDNTPOFF", 10));
62 id = mangle(id, new_id_from_chars("@NTPOFF", 7));
67 assert(0 && "Unsupported SymConst");
74 * returns true if a node has x87 registers
76 int ia32_has_x87_register(const ir_node *n) {
77 assert(is_ia32_irn(n) && "Need ia32 node.");
78 return is_irn_machine_user(n, 0);
81 /***********************************************************************************
84 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
85 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
86 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
87 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
90 ***********************************************************************************/
93 * Returns a string containing the names of all registers within the limited bitset
95 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
96 bitset_t *bs = bitset_alloca(req->cls->n_regs);
101 req->limited(NULL, bs);
103 for (i = 0; i < req->cls->n_regs; i++) {
104 if (bitset_is_set(bs, i)) {
105 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
107 fprintf(stderr, "dumper problem, exiting\n");
123 * Dumps the register requirements for either in or out.
125 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
126 char *dir = inout ? "out" : "in";
127 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
128 char *buf = alloca(1024);
131 memset(buf, 0, 1024);
134 for (i = 0; i < max; i++) {
135 fprintf(F, "%sreq #%d =", dir, i);
137 if (reqs[i]->req.type == arch_register_req_type_none) {
141 if (reqs[i]->req.type & arch_register_req_type_normal) {
142 fprintf(F, " %s", reqs[i]->req.cls->name);
145 if (reqs[i]->req.type & arch_register_req_type_limited) {
146 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
149 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
150 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
153 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
154 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
163 fprintf(F, "%sreq = N/A\n", dir);
168 * Dumper interface for dumping ia32 nodes in vcg.
169 * @param n the node to dump
170 * @param F the output file
171 * @param reason indicates which kind of information should be dumped
172 * @return 0 on success or != 0 on failure
174 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
175 ir_mode *mode = NULL;
177 int i, n_res, am_flav, flags;
178 const ia32_register_req_t **reqs;
179 const arch_register_t **slots;
182 case dump_node_opcode_txt:
183 fprintf(F, "%s", get_irn_opname(n));
186 case dump_node_mode_txt:
187 mode = get_irn_mode(n);
189 if (is_ia32_Ld(n) || is_ia32_St(n)) {
190 mode = get_ia32_ls_mode(n);
193 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
196 case dump_node_nodeattr_txt:
197 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
198 char *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
199 const char *cnst = get_ia32_cnst(n);
201 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
204 if (! is_ia32_Lea(n)) {
205 if (is_ia32_AddrModeS(n)) {
206 fprintf(F, "[AM S] ");
208 else if (is_ia32_AddrModeD(n)) {
209 fprintf(F, "[AM D] ");
215 case dump_node_info_txt:
216 n_res = get_ia32_n_res(n);
217 fprintf(F, "=== IA32 attr begin ===\n");
219 /* dump IN requirements */
220 if (get_irn_arity(n) > 0) {
221 reqs = get_ia32_in_req_all(n);
222 dump_reg_req(F, n, reqs, 0);
225 /* dump OUT requirements */
227 reqs = get_ia32_out_req_all(n);
228 dump_reg_req(F, n, reqs, 1);
231 /* dump assigned registers */
232 slots = get_ia32_slots(n);
233 if (slots && n_res > 0) {
234 for (i = 0; i < n_res; i++) {
235 const arch_register_t *reg;
237 /* retrieve "real" x87 register */
238 if (ia32_has_x87_register(n))
239 reg = get_ia32_attr(n)->x87[i + 2];
243 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
250 switch (get_ia32_op_type(n)) {
252 fprintf(F, "Normal");
258 fprintf(F, "SymConst");
261 fprintf(F, "AM Dest (Load+Store)");
264 fprintf(F, "AM Source (Load)");
267 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
272 /* dump immop type */
273 fprintf(F, "immediate = ");
274 switch (get_ia32_immop_type(n)) {
281 case ia32_ImmSymConst:
282 fprintf(F, "SymConst");
285 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
290 /* dump supported am */
291 fprintf(F, "AM support = ");
292 switch (get_ia32_am_support(n)) {
297 fprintf(F, "source only (Load)");
300 fprintf(F, "dest only (Load+Store)");
306 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
311 /* dump am flavour */
312 fprintf(F, "AM flavour =");
313 am_flav = get_ia32_am_flavour(n);
314 if (am_flav == ia32_am_N) {
318 if (am_flav & ia32_O) {
321 if (am_flav & ia32_B) {
324 if (am_flav & ia32_I) {
327 if (am_flav & ia32_S) {
331 fprintf(F, " (%d)\n", am_flav);
334 fprintf(F, "AM offset = ");
335 if (get_ia32_am_offs(n)) {
336 fprintf(F, "%s", get_ia32_am_offs(n));
343 /* dump AM symconst */
344 if(get_ia32_am_sc(n) != NULL) {
345 fprintf(F, "AM symconst = %s\n", get_id_str(get_ia32_am_sc(n)));
349 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
352 fprintf(F, "pn_code = %ld (%s)\n", get_ia32_pncode(n), get_pnc_string(get_ia32_pncode(n)));
355 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
358 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
361 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
364 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
367 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
370 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
373 fprintf(F, "latency = %d\n", get_ia32_latency(n));
376 fprintf(F, "flags =");
377 flags = get_ia32_flags(n);
378 if (flags == arch_irn_flags_none) {
382 if (flags & arch_irn_flags_dont_spill) {
383 fprintf(F, " unspillable");
385 if (flags & arch_irn_flags_rematerializable) {
386 fprintf(F, " remat");
388 if (flags & arch_irn_flags_ignore) {
389 fprintf(F, " ignore");
391 if (flags & arch_irn_flags_modify_sp) {
392 fprintf(F, " modify_sp");
395 fprintf(F, " (%d)\n", flags);
397 /* dump frame entity */
398 fprintf(F, "frame entity = ");
399 if (get_ia32_frame_ent(n)) {
400 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
408 fprintf(F, "ls_mode = ");
409 if (get_ia32_ls_mode(n)) {
410 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
417 fprintf(F, "res_mode = ");
418 if (get_ia32_res_mode(n)) {
419 ir_fprintf(F, "%+F", get_ia32_res_mode(n));
426 fprintf(F, "src_mode = ");
427 if (get_ia32_src_mode(n)) {
428 ir_fprintf(F, "%+F", get_ia32_src_mode(n));
435 fprintf(F, "tgt_mode = ");
436 if (get_ia32_tgt_mode(n)) {
437 ir_fprintf(F, "%+F", get_ia32_tgt_mode(n));
445 /* dump original ir node name */
446 fprintf(F, "orig node = ");
447 if (get_ia32_orig_node(n)) {
448 fprintf(F, "%s", get_ia32_orig_node(n));
456 fprintf(F, "=== IA32 attr end ===\n");
457 /* end of: case dump_node_info_txt */
466 /***************************************************************************************************
468 * | | | | | | / / | | | | | | | |
469 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
470 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
471 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
472 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
475 ***************************************************************************************************/
478 * Returns an ident for the given tarval tv.
480 static ident *get_ident_for_tv(tarval *tv) {
482 int len = tarval_snprintf(buf, sizeof(buf), tv);
484 return new_id_from_str(buf);
488 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
489 * Firm was made by people hating const :-(
491 ia32_attr_t *get_ia32_attr(const ir_node *node) {
492 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
493 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
497 * Gets the type of an ia32 node.
499 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
500 ia32_attr_t *attr = get_ia32_attr(node);
501 return attr->data.tp;
505 * Sets the type of an ia32 node.
507 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
508 ia32_attr_t *attr = get_ia32_attr(node);
513 * Gets the immediate op type of an ia32 node.
515 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
516 ia32_attr_t *attr = get_ia32_attr(node);
517 return attr->data.imm_tp;
521 * Sets the immediate op type of an ia32 node.
523 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
524 ia32_attr_t *attr = get_ia32_attr(node);
525 attr->data.imm_tp = tp;
529 * Gets the supported addrmode of an ia32 node
531 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
532 ia32_attr_t *attr = get_ia32_attr(node);
533 return attr->data.am_support;
537 * Sets the supported addrmode of an ia32 node
539 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
540 ia32_attr_t *attr = get_ia32_attr(node);
541 attr->data.am_support = am_tp;
545 * Gets the addrmode flavour of an ia32 node
547 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
548 ia32_attr_t *attr = get_ia32_attr(node);
549 return attr->data.am_flavour;
553 * Sets the addrmode flavour of an ia32 node
555 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
556 ia32_attr_t *attr = get_ia32_attr(node);
557 attr->data.am_flavour = am_flavour;
561 * Joins all offsets to one string with adds.
563 char *get_ia32_am_offs(const ir_node *node) {
564 ia32_attr_t *attr = get_ia32_attr(node);
567 snprintf(res, sizeof(res), "%+d", attr->am_offs);
573 * Gets the addressmode offset as long.
575 int get_ia32_am_offs_int(const ir_node *node) {
576 ia32_attr_t *attr = get_ia32_attr(node);
577 return attr->am_offs;
581 * Add an offset for addrmode.
583 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
584 ia32_attr_t *attr = get_ia32_attr(node);
587 if (offset == NULL || offset[0] == '\0')
590 if (offset[0] == '-')
591 res = sscanf(offset, "%d", &o);
593 res = sscanf(offset, "%u", &o);
605 * Add an offset for addrmode.
607 void add_ia32_am_offs(ir_node *node, const char *offset) {
608 extend_ia32_am_offs(node, (char *)offset, '+');
611 void add_ia32_am_offs_int(ir_node *node, int offset) {
612 ia32_attr_t *attr = get_ia32_attr(node);
613 attr->am_offs += offset;
617 * Sub an offset for addrmode.
619 void sub_ia32_am_offs(ir_node *node, const char *offset) {
620 extend_ia32_am_offs(node, (char *)offset, '-');
624 * Returns the symconst ident associated to addrmode.
626 ident *get_ia32_am_sc(const ir_node *node) {
627 ia32_attr_t *attr = get_ia32_attr(node);
632 * Sets the symconst ident associated to addrmode.
634 void set_ia32_am_sc(ir_node *node, ident *sc) {
635 ia32_attr_t *attr = get_ia32_attr(node);
640 * Sets the sign bit for address mode symconst.
642 void set_ia32_am_sc_sign(ir_node *node) {
643 ia32_attr_t *attr = get_ia32_attr(node);
644 attr->data.am_sc_sign = 1;
648 * Clears the sign bit for address mode symconst.
650 void clear_ia32_am_sc_sign(ir_node *node) {
651 ia32_attr_t *attr = get_ia32_attr(node);
652 attr->data.am_sc_sign = 0;
656 * Returns the sign bit for address mode symconst.
658 int is_ia32_am_sc_sign(const ir_node *node) {
659 ia32_attr_t *attr = get_ia32_attr(node);
660 return attr->data.am_sc_sign;
664 * Gets the addr mode const.
666 int get_ia32_am_scale(const ir_node *node) {
667 ia32_attr_t *attr = get_ia32_attr(node);
668 return attr->data.am_scale;
672 * Sets the index register scale for addrmode.
674 void set_ia32_am_scale(ir_node *node, int scale) {
675 ia32_attr_t *attr = get_ia32_attr(node);
676 attr->data.am_scale = scale;
680 * Return the tarval of an immediate operation or NULL in case of SymConst
682 tarval *get_ia32_Immop_tarval(const ir_node *node) {
683 ia32_attr_t *attr = get_ia32_attr(node);
684 return attr->cnst_val.tv;
688 * Sets the attributes of an immediate operation to the specified tarval
690 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
691 ia32_attr_t *attr = get_ia32_attr(node);
692 attr->cnst_val.tv = tv;
693 attr->cnst = get_ident_for_tv(tv);
697 * Gets the string representation of the internal const (tv or symconst)
699 const char *get_ia32_cnst(const ir_node *node) {
700 ia32_attr_t *attr = get_ia32_attr(node);
703 return get_id_str(attr->cnst);
707 * Sets the string representation of the internal const.
709 void set_ia32_cnst(ir_node *node, const char *cnst) {
710 ia32_attr_t *attr = get_ia32_attr(node);
711 attr->cnst = new_id_from_str(cnst);
715 * Gets the ident representation of the internal const (tv or symconst)
717 ident *get_ia32_id_cnst(const ir_node *node) {
718 ia32_attr_t *attr = get_ia32_attr(node);
723 * Sets the ident representation of the internal const.
725 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
726 ia32_attr_t *attr = get_ia32_attr(node);
731 * Sets the uses_frame flag.
733 void set_ia32_use_frame(ir_node *node) {
734 ia32_attr_t *attr = get_ia32_attr(node);
735 attr->data.use_frame = 1;
739 * Clears the uses_frame flag.
741 void clear_ia32_use_frame(ir_node *node) {
742 ia32_attr_t *attr = get_ia32_attr(node);
743 attr->data.use_frame = 0;
747 * Gets the uses_frame flag.
749 int is_ia32_use_frame(const ir_node *node) {
750 ia32_attr_t *attr = get_ia32_attr(node);
751 return attr->data.use_frame;
755 * Sets node to commutative.
757 void set_ia32_commutative(ir_node *node) {
758 ia32_attr_t *attr = get_ia32_attr(node);
759 attr->data.is_commutative = 1;
763 * Sets node to non-commutative.
765 void clear_ia32_commutative(ir_node *node) {
766 ia32_attr_t *attr = get_ia32_attr(node);
767 attr->data.is_commutative = 0;
771 * Checks if node is commutative.
773 int is_ia32_commutative(const ir_node *node) {
774 ia32_attr_t *attr = get_ia32_attr(node);
775 return attr->data.is_commutative;
781 void set_ia32_emit_cl(ir_node *node) {
782 ia32_attr_t *attr = get_ia32_attr(node);
783 attr->data.emit_cl = 1;
787 * Clears node emit_cl.
789 void clear_ia32_emit_cl(ir_node *node) {
790 ia32_attr_t *attr = get_ia32_attr(node);
791 attr->data.emit_cl = 0;
795 * Checks if node needs %cl.
797 int is_ia32_emit_cl(const ir_node *node) {
798 ia32_attr_t *attr = get_ia32_attr(node);
799 return attr->data.emit_cl;
805 void set_ia32_got_lea(ir_node *node) {
806 ia32_attr_t *attr = get_ia32_attr(node);
807 attr->data.got_lea = 1;
811 * Clears node got_lea.
813 void clear_ia32_got_lea(ir_node *node) {
814 ia32_attr_t *attr = get_ia32_attr(node);
815 attr->data.got_lea = 0;
819 * Checks if node got lea.
821 int is_ia32_got_lea(const ir_node *node) {
822 ia32_attr_t *attr = get_ia32_attr(node);
823 return attr->data.got_lea;
827 * Sets node got_reload.
829 void set_ia32_got_reload(ir_node *node) {
830 ia32_attr_t *attr = get_ia32_attr(node);
831 attr->data.got_reload = 1;
835 * Clears node got_reload.
837 void clear_ia32_got_reload(ir_node *node) {
838 ia32_attr_t *attr = get_ia32_attr(node);
839 attr->data.got_reload = 0;
843 * Checks if node got reload.
845 int is_ia32_got_reload(const ir_node *node) {
846 ia32_attr_t *attr = get_ia32_attr(node);
847 return attr->data.got_reload;
851 * Gets the mode of the stored/loaded value (only set for Store/Load)
853 ir_mode *get_ia32_ls_mode(const ir_node *node) {
854 ia32_attr_t *attr = get_ia32_attr(node);
855 return attr->ls_mode;
859 * Sets the mode of the stored/loaded value (only set for Store/Load)
861 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
862 ia32_attr_t *attr = get_ia32_attr(node);
863 attr->ls_mode = mode;
867 * Gets the mode of the result.
869 ir_mode *get_ia32_res_mode(const ir_node *node) {
870 ia32_attr_t *attr = get_ia32_attr(node);
871 return attr->res_mode;
875 * Sets the mode of the result.
877 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
878 ia32_attr_t *attr = get_ia32_attr(node);
879 attr->res_mode = mode;
883 * Gets the source mode of conversion.
885 ir_mode *get_ia32_src_mode(const ir_node *node) {
886 ia32_attr_t *attr = get_ia32_attr(node);
887 return attr->src_mode;
891 * Sets the source mode of conversion.
893 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
894 ia32_attr_t *attr = get_ia32_attr(node);
895 attr->src_mode = mode;
899 * Gets the target mode of conversion.
901 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
902 ia32_attr_t *attr = get_ia32_attr(node);
903 return attr->tgt_mode;
907 * Sets the target mode of conversion.
909 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
910 ia32_attr_t *attr = get_ia32_attr(node);
911 attr->tgt_mode = mode;
915 * Gets the frame entity assigned to this node.
917 ir_entity *get_ia32_frame_ent(const ir_node *node) {
918 ia32_attr_t *attr = get_ia32_attr(node);
919 return attr->frame_ent;
923 * Sets the frame entity for this node.
925 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
926 ia32_attr_t *attr = get_ia32_attr(node);
927 attr->frame_ent = ent;
928 set_ia32_use_frame(node);
933 * Gets the instruction latency.
935 unsigned get_ia32_latency(const ir_node *node) {
936 ia32_attr_t *attr = get_ia32_attr(node);
937 return attr->latency;
941 * Sets the instruction latency.
943 void set_ia32_latency(ir_node *node, unsigned latency) {
944 ia32_attr_t *attr = get_ia32_attr(node);
945 attr->latency = latency;
949 * Returns the argument register requirements of an ia32 node.
951 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
952 ia32_attr_t *attr = get_ia32_attr(node);
957 * Sets the argument register requirements of an ia32 node.
959 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
960 ia32_attr_t *attr = get_ia32_attr(node);
965 * Returns the result register requirements of an ia32 node.
967 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
968 ia32_attr_t *attr = get_ia32_attr(node);
969 return attr->out_req;
973 * Sets the result register requirements of an ia32 node.
975 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
976 ia32_attr_t *attr = get_ia32_attr(node);
977 attr->out_req = reqs;
981 * Returns the argument register requirement at position pos of an ia32 node.
983 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
984 ia32_attr_t *attr = get_ia32_attr(node);
985 return attr->in_req != NULL ? attr->in_req[pos] : NULL;
989 * Returns the result register requirement at position pos of an ia32 node.
991 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
992 ia32_attr_t *attr = get_ia32_attr(node);
993 return attr->out_req != NULL ? attr->out_req[pos] : NULL;
997 * Sets the OUT register requirements at position pos.
999 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
1000 ia32_attr_t *attr = get_ia32_attr(node);
1001 attr->out_req[pos] = req;
1005 * Sets the IN register requirements at position pos.
1007 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
1008 ia32_attr_t *attr = get_ia32_attr(node);
1009 attr->in_req[pos] = req;
1013 * Returns the register flag of an ia32 node.
1015 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
1016 ia32_attr_t *attr = get_ia32_attr(node);
1017 return attr->data.flags;
1021 * Sets the register flag of an ia32 node.
1023 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
1024 ia32_attr_t *attr = get_ia32_attr(node);
1025 attr->data.flags = flags;
1029 * Returns the result register slots of an ia32 node.
1031 const arch_register_t **get_ia32_slots(const ir_node *node) {
1032 ia32_attr_t *attr = get_ia32_attr(node);
1037 * Sets the number of results.
1039 void set_ia32_n_res(ir_node *node, int n_res) {
1040 ia32_attr_t *attr = get_ia32_attr(node);
1041 attr->data.n_res = n_res;
1045 * Returns the number of results.
1047 int get_ia32_n_res(const ir_node *node) {
1048 ia32_attr_t *attr = get_ia32_attr(node);
1049 return attr->data.n_res;
1053 * Returns the flavour of an ia32 node,
1055 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1056 ia32_attr_t *attr = get_ia32_attr(node);
1057 return attr->data.op_flav;
1061 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1063 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1064 ia32_attr_t *attr = get_ia32_attr(node);
1065 attr->data.op_flav = op_flav;
1069 * Returns the projnum code.
1071 long get_ia32_pncode(const ir_node *node) {
1072 ia32_attr_t *attr = get_ia32_attr(node);
1073 return attr->pn_code;
1077 * Sets the projnum code
1079 void set_ia32_pncode(ir_node *node, long code) {
1080 ia32_attr_t *attr = get_ia32_attr(node);
1081 attr->pn_code = code;
1085 * Sets the flags for the n'th out.
1087 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
1088 ia32_attr_t *attr = get_ia32_attr(node);
1089 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1090 attr->out_flags[pos] = flags;
1094 * Gets the flags for the n'th out.
1096 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
1097 ia32_attr_t *attr = get_ia32_attr(node);
1098 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
1102 * Get the list of available execution units.
1104 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
1105 ia32_attr_t *attr = get_ia32_attr(node);
1106 return attr->exec_units;
1112 * Returns the name of the original ir node.
1114 const char *get_ia32_orig_node(const ir_node *node) {
1115 ia32_attr_t *attr = get_ia32_attr(node);
1116 return attr->orig_node;
1120 * Sets the name of the original ir node.
1122 void set_ia32_orig_node(ir_node *node, const char *name) {
1123 ia32_attr_t *attr = get_ia32_attr(node);
1124 attr->orig_node = name;
1129 /******************************************************************************************************
1131 * (_) | | | | | | / _| | | (_)
1132 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1133 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1134 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1135 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1138 ******************************************************************************************************/
1141 * Gets the type of an ia32_Const.
1143 unsigned get_ia32_Const_type(const ir_node *node) {
1144 ia32_attr_t *attr = get_ia32_attr(node);
1146 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1148 return attr->data.tp;
1152 * Sets the type of an ia32_Const.
1154 void set_ia32_Const_type(ir_node *node, int type) {
1155 ia32_attr_t *attr = get_ia32_attr(node);
1157 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1158 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1160 attr->data.tp = type;
1164 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1166 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1167 ia32_attr_t *na = get_ia32_attr(node);
1168 ia32_attr_t *ca = get_ia32_attr(cnst);
1170 switch(get_ia32_Const_type(cnst)) {
1172 na->cnst_val.tv = ca->cnst_val.tv;
1173 na->cnst = ca->cnst;
1174 set_ia32_immop_type(node, ia32_ImmConst);
1177 na->cnst_val.sc = ca->cnst_val.sc;
1178 na->cnst = na->cnst_val.sc;
1179 set_ia32_immop_type(node, ia32_ImmSymConst);
1182 assert(0 && "Need ia32_Const to set Immop attr");
1187 * Copy the attributes from Immop to an Immop
1189 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1190 ia32_attr_t *da = get_ia32_attr(dst);
1191 ia32_attr_t *sa = get_ia32_attr(src);
1193 switch(get_ia32_immop_type(src)) {
1195 da->cnst_val.tv = sa->cnst_val.tv;
1196 da->cnst = sa->cnst;
1197 set_ia32_immop_type(dst, ia32_ImmConst);
1199 case ia32_ImmSymConst:
1200 da->cnst_val.sc = sa->cnst_val.sc;
1201 da->cnst = sa->cnst;
1202 set_ia32_immop_type(dst, ia32_ImmSymConst);
1205 assert(0 && "Need Immop to copy Immop attr");
1210 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1212 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1213 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1216 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1218 switch (get_irn_opcode(cnst)) {
1220 attr->data.tp = ia32_Const;
1221 attr->cnst_val.tv = get_Const_tarval(cnst);
1222 mode = get_tarval_mode(attr->cnst_val.tv);
1223 if (mode_is_reference(mode) &&
1224 get_mode_null(mode) == attr->cnst_val.tv) {
1225 attr->cnst_val.tv = get_mode_null(mode_Iu);
1227 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1230 attr->data.tp = ia32_SymConst;
1231 attr->cnst_val.sc = get_sc_ident(cnst);
1232 attr->cnst = attr->cnst_val.sc;
1235 assert(0 && "Unknown Const NYI");
1238 assert(0 && "Cannot create ia32_Const for this opcode");
1243 * Sets the AddrMode(S|D) attribute
1245 void set_ia32_AddrMode(ir_node *node, char direction) {
1246 ia32_attr_t *attr = get_ia32_attr(node);
1248 switch (direction) {
1250 attr->data.tp = ia32_AddrModeD;
1253 attr->data.tp = ia32_AddrModeS;
1256 assert(0 && "wrong AM type");
1261 * Returns whether or not the node is an immediate operation with Const.
1263 int is_ia32_ImmConst(const ir_node *node) {
1264 ia32_attr_t *attr = get_ia32_attr(node);
1265 return (attr->data.imm_tp == ia32_ImmConst);
1269 * Returns whether or not the node is an immediate operation with SymConst.
1271 int is_ia32_ImmSymConst(const ir_node *node) {
1272 ia32_attr_t *attr = get_ia32_attr(node);
1273 return (attr->data.imm_tp == ia32_ImmSymConst);
1277 * Returns whether or not the node is an AddrModeS node.
1279 int is_ia32_AddrModeS(const ir_node *node) {
1280 ia32_attr_t *attr = get_ia32_attr(node);
1281 return (attr->data.tp == ia32_AddrModeS);
1285 * Returns whether or not the node is an AddrModeD node.
1287 int is_ia32_AddrModeD(const ir_node *node) {
1288 ia32_attr_t *attr = get_ia32_attr(node);
1289 return (attr->data.tp == ia32_AddrModeD);
1293 * Checks if node is a Load or xLoad/vfLoad.
1295 int is_ia32_Ld(const ir_node *node) {
1296 int op = get_ia32_irn_opcode(node);
1297 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1301 * Checks if node is a Store or xStore/vfStore.
1303 int is_ia32_St(const ir_node *node) {
1304 int op = get_ia32_irn_opcode(node);
1305 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1309 * Checks if node is a Const or xConst/vfConst.
1311 int is_ia32_Cnst(const ir_node *node) {
1312 int op = get_ia32_irn_opcode(node);
1313 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1317 * Returns the name of the OUT register at position pos.
1319 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1320 ia32_attr_t *attr = get_ia32_attr(node);
1322 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1323 assert(attr->slots[pos] && "No register assigned");
1325 return arch_register_get_name(attr->slots[pos]);
1329 * Returns the index of the OUT register at position pos within its register class.
1331 int get_ia32_out_regnr(const ir_node *node, int pos) {
1332 ia32_attr_t *attr = get_ia32_attr(node);
1334 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1335 assert(attr->slots[pos] && "No register assigned");
1337 return arch_register_get_index(attr->slots[pos]);
1341 * Returns the OUT register at position pos.
1343 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1344 ia32_attr_t *attr = get_ia32_attr(node);
1346 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1347 assert(attr->slots[pos] && "No register assigned");
1349 return attr->slots[pos];
1353 * Initializes the nodes attributes.
1355 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1356 const ia32_register_req_t **out_reqs, const be_execution_unit_t ***execution_units,
1357 int n_res, unsigned latency)
1359 ia32_attr_t *attr = get_ia32_attr(node);
1361 set_ia32_flags(node, flags);
1362 set_ia32_in_req_all(node, in_reqs);
1363 set_ia32_out_req_all(node, out_reqs);
1364 set_ia32_latency(node, latency);
1365 set_ia32_n_res(node, n_res);
1367 attr->exec_units = execution_units;
1369 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1370 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1372 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1375 /***************************************************************************************
1378 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1379 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1380 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1381 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1383 ***************************************************************************************/
1385 /* default compare operation to compare immediate ops */
1386 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1389 if (a->data.tp != b->data.tp)
1392 if (a->cnst != b->cnst)
1395 if (a->data.use_frame != b->data.use_frame)
1398 if (a->data.use_frame && a->frame_ent != b->frame_ent)
1401 if (a->data.am_flavour != b->data.am_flavour
1402 || a->data.am_scale != b->data.am_scale
1403 || a->data.offs_sign != b->data.offs_sign
1404 || a->data.am_sc_sign != b->data.am_sc_sign
1405 || a->am_offs != b->am_offs
1406 || a->am_sc != b->am_sc)
1409 if(a->pn_code != b->pn_code)
1415 /* compare converts */
1416 int ia32_compare_conv_attr(ia32_attr_t *a, ia32_attr_t *b) {
1417 int equ = ! ia32_compare_immop_attr(a, b);
1419 equ = equ ? (a->src_mode == b->src_mode) && (a->tgt_mode == b->tgt_mode) : equ;
1424 /* copies the ia32 attributes */
1425 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1426 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1427 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1429 /* copy the attributes */
1430 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1432 /* copy out flags */
1433 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1437 * Registers the ia32_copy_attr function for all ia32 opcodes.
1439 void ia32_register_copy_attr_func(void) {
1440 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1442 for (i = f; i < l; i++) {
1443 ir_op *op = get_irp_opcode(i);
1444 op->ops.copy_attr = ia32_copy_attr;
1448 /* Include the generated constructor functions */
1449 #include "gen_ia32_new_nodes.c.inl"