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));
344 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
347 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
350 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
353 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
356 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
359 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
362 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
365 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
368 fprintf(F, "latency = %d\n", get_ia32_latency(n));
371 fprintf(F, "flags =");
372 flags = get_ia32_flags(n);
373 if (flags == arch_irn_flags_none) {
377 if (flags & arch_irn_flags_dont_spill) {
378 fprintf(F, " unspillable");
380 if (flags & arch_irn_flags_rematerializable) {
381 fprintf(F, " remat");
383 if (flags & arch_irn_flags_ignore) {
384 fprintf(F, " ignore");
386 if (flags & arch_irn_flags_modify_sp) {
387 fprintf(F, " modify_sp");
390 fprintf(F, " (%d)\n", flags);
392 /* dump frame entity */
393 fprintf(F, "frame entity = ");
394 if (get_ia32_frame_ent(n)) {
395 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
403 fprintf(F, "ls_mode = ");
404 if (get_ia32_ls_mode(n)) {
405 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
412 fprintf(F, "res_mode = ");
413 if (get_ia32_res_mode(n)) {
414 ir_fprintf(F, "%+F", get_ia32_res_mode(n));
421 fprintf(F, "src_mode = ");
422 if (get_ia32_src_mode(n)) {
423 ir_fprintf(F, "%+F", get_ia32_src_mode(n));
430 fprintf(F, "tgt_mode = ");
431 if (get_ia32_tgt_mode(n)) {
432 ir_fprintf(F, "%+F", get_ia32_tgt_mode(n));
440 /* dump original ir node name */
441 fprintf(F, "orig node = ");
442 if (get_ia32_orig_node(n)) {
443 fprintf(F, "%s", get_ia32_orig_node(n));
451 fprintf(F, "=== IA32 attr end ===\n");
452 /* end of: case dump_node_info_txt */
461 /***************************************************************************************************
463 * | | | | | | / / | | | | | | | |
464 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
465 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
466 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
467 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
470 ***************************************************************************************************/
473 * Returns an ident for the given tarval tv.
475 static ident *get_ident_for_tv(tarval *tv) {
477 int len = tarval_snprintf(buf, sizeof(buf), tv);
479 return new_id_from_str(buf);
483 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
484 * Firm was made by people hating const :-(
486 ia32_attr_t *get_ia32_attr(const ir_node *node) {
487 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
488 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
492 * Gets the type of an ia32 node.
494 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
495 ia32_attr_t *attr = get_ia32_attr(node);
496 return attr->data.tp;
500 * Sets the type of an ia32 node.
502 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
503 ia32_attr_t *attr = get_ia32_attr(node);
508 * Gets the immediate op type of an ia32 node.
510 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
511 ia32_attr_t *attr = get_ia32_attr(node);
512 return attr->data.imm_tp;
516 * Sets the immediate op type of an ia32 node.
518 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
519 ia32_attr_t *attr = get_ia32_attr(node);
520 attr->data.imm_tp = tp;
524 * Gets the supported addrmode of an ia32 node
526 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
527 ia32_attr_t *attr = get_ia32_attr(node);
528 return attr->data.am_support;
532 * Sets the supported addrmode of an ia32 node
534 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
535 ia32_attr_t *attr = get_ia32_attr(node);
536 attr->data.am_support = am_tp;
540 * Gets the addrmode flavour of an ia32 node
542 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
543 ia32_attr_t *attr = get_ia32_attr(node);
544 return attr->data.am_flavour;
548 * Sets the addrmode flavour of an ia32 node
550 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
551 ia32_attr_t *attr = get_ia32_attr(node);
552 attr->data.am_flavour = am_flavour;
556 * Joins all offsets to one string with adds.
558 char *get_ia32_am_offs(const ir_node *node) {
559 ia32_attr_t *attr = get_ia32_attr(node);
562 snprintf(res, sizeof(res), "%+d", attr->am_offs);
568 * Gets the addressmode offset as long.
570 int get_ia32_am_offs_int(const ir_node *node) {
571 ia32_attr_t *attr = get_ia32_attr(node);
572 return attr->am_offs;
576 * Add an offset for addrmode.
578 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
579 ia32_attr_t *attr = get_ia32_attr(node);
582 if (offset == NULL || offset[0] == '\0')
585 if (offset[0] == '-')
586 res = sscanf(offset, "%d", &o);
588 res = sscanf(offset, "%u", &o);
600 * Add an offset for addrmode.
602 void add_ia32_am_offs(ir_node *node, const char *offset) {
603 extend_ia32_am_offs(node, (char *)offset, '+');
606 void add_ia32_am_offs_int(ir_node *node, int offset) {
607 ia32_attr_t *attr = get_ia32_attr(node);
608 attr->am_offs += offset;
612 * Sub an offset for addrmode.
614 void sub_ia32_am_offs(ir_node *node, const char *offset) {
615 extend_ia32_am_offs(node, (char *)offset, '-');
619 * Returns the symconst ident associated to addrmode.
621 ident *get_ia32_am_sc(const ir_node *node) {
622 ia32_attr_t *attr = get_ia32_attr(node);
627 * Sets the symconst ident associated to addrmode.
629 void set_ia32_am_sc(ir_node *node, ident *sc) {
630 ia32_attr_t *attr = get_ia32_attr(node);
635 * Sets the sign bit for address mode symconst.
637 void set_ia32_am_sc_sign(ir_node *node) {
638 ia32_attr_t *attr = get_ia32_attr(node);
639 attr->data.am_sc_sign = 1;
643 * Clears the sign bit for address mode symconst.
645 void clear_ia32_am_sc_sign(ir_node *node) {
646 ia32_attr_t *attr = get_ia32_attr(node);
647 attr->data.am_sc_sign = 0;
651 * Returns the sign bit for address mode symconst.
653 int is_ia32_am_sc_sign(const ir_node *node) {
654 ia32_attr_t *attr = get_ia32_attr(node);
655 return attr->data.am_sc_sign;
659 * Gets the addr mode const.
661 int get_ia32_am_scale(const ir_node *node) {
662 ia32_attr_t *attr = get_ia32_attr(node);
663 return attr->data.am_scale;
667 * Sets the index register scale for addrmode.
669 void set_ia32_am_scale(ir_node *node, int scale) {
670 ia32_attr_t *attr = get_ia32_attr(node);
671 attr->data.am_scale = scale;
675 * Return the tarval of an immediate operation or NULL in case of SymConst
677 tarval *get_ia32_Immop_tarval(const ir_node *node) {
678 ia32_attr_t *attr = get_ia32_attr(node);
679 return attr->cnst_val.tv;
683 * Sets the attributes of an immediate operation to the specified tarval
685 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
686 ia32_attr_t *attr = get_ia32_attr(node);
687 attr->cnst_val.tv = tv;
688 attr->cnst = get_ident_for_tv(tv);
692 * Gets the string representation of the internal const (tv or symconst)
694 const char *get_ia32_cnst(const ir_node *node) {
695 ia32_attr_t *attr = get_ia32_attr(node);
698 return get_id_str(attr->cnst);
702 * Sets the string representation of the internal const.
704 void set_ia32_cnst(ir_node *node, const char *cnst) {
705 ia32_attr_t *attr = get_ia32_attr(node);
706 attr->cnst = new_id_from_str(cnst);
710 * Gets the ident representation of the internal const (tv or symconst)
712 ident *get_ia32_id_cnst(const ir_node *node) {
713 ia32_attr_t *attr = get_ia32_attr(node);
718 * Sets the ident representation of the internal const.
720 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
721 ia32_attr_t *attr = get_ia32_attr(node);
726 * Sets the uses_frame flag.
728 void set_ia32_use_frame(ir_node *node) {
729 ia32_attr_t *attr = get_ia32_attr(node);
730 attr->data.use_frame = 1;
734 * Clears the uses_frame flag.
736 void clear_ia32_use_frame(ir_node *node) {
737 ia32_attr_t *attr = get_ia32_attr(node);
738 attr->data.use_frame = 0;
742 * Gets the uses_frame flag.
744 int is_ia32_use_frame(const ir_node *node) {
745 ia32_attr_t *attr = get_ia32_attr(node);
746 return attr->data.use_frame;
750 * Sets node to commutative.
752 void set_ia32_commutative(ir_node *node) {
753 ia32_attr_t *attr = get_ia32_attr(node);
754 attr->data.is_commutative = 1;
758 * Sets node to non-commutative.
760 void clear_ia32_commutative(ir_node *node) {
761 ia32_attr_t *attr = get_ia32_attr(node);
762 attr->data.is_commutative = 0;
766 * Checks if node is commutative.
768 int is_ia32_commutative(const ir_node *node) {
769 ia32_attr_t *attr = get_ia32_attr(node);
770 return attr->data.is_commutative;
776 void set_ia32_emit_cl(ir_node *node) {
777 ia32_attr_t *attr = get_ia32_attr(node);
778 attr->data.emit_cl = 1;
782 * Clears node emit_cl.
784 void clear_ia32_emit_cl(ir_node *node) {
785 ia32_attr_t *attr = get_ia32_attr(node);
786 attr->data.emit_cl = 0;
790 * Checks if node needs %cl.
792 int is_ia32_emit_cl(const ir_node *node) {
793 ia32_attr_t *attr = get_ia32_attr(node);
794 return attr->data.emit_cl;
800 void set_ia32_got_lea(ir_node *node) {
801 ia32_attr_t *attr = get_ia32_attr(node);
802 attr->data.got_lea = 1;
806 * Clears node got_lea.
808 void clear_ia32_got_lea(ir_node *node) {
809 ia32_attr_t *attr = get_ia32_attr(node);
810 attr->data.got_lea = 0;
814 * Checks if node got lea.
816 int is_ia32_got_lea(const ir_node *node) {
817 ia32_attr_t *attr = get_ia32_attr(node);
818 return attr->data.got_lea;
822 * Sets node got_reload.
824 void set_ia32_got_reload(ir_node *node) {
825 ia32_attr_t *attr = get_ia32_attr(node);
826 attr->data.got_reload = 1;
830 * Clears node got_reload.
832 void clear_ia32_got_reload(ir_node *node) {
833 ia32_attr_t *attr = get_ia32_attr(node);
834 attr->data.got_reload = 0;
838 * Checks if node got reload.
840 int is_ia32_got_reload(const ir_node *node) {
841 ia32_attr_t *attr = get_ia32_attr(node);
842 return attr->data.got_reload;
846 * Gets the mode of the stored/loaded value (only set for Store/Load)
848 ir_mode *get_ia32_ls_mode(const ir_node *node) {
849 ia32_attr_t *attr = get_ia32_attr(node);
850 return attr->ls_mode;
854 * Sets the mode of the stored/loaded value (only set for Store/Load)
856 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
857 ia32_attr_t *attr = get_ia32_attr(node);
858 attr->ls_mode = mode;
862 * Gets the mode of the result.
864 ir_mode *get_ia32_res_mode(const ir_node *node) {
865 ia32_attr_t *attr = get_ia32_attr(node);
866 return attr->res_mode;
870 * Sets the mode of the result.
872 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
873 ia32_attr_t *attr = get_ia32_attr(node);
874 attr->res_mode = mode;
878 * Gets the source mode of conversion.
880 ir_mode *get_ia32_src_mode(const ir_node *node) {
881 ia32_attr_t *attr = get_ia32_attr(node);
882 return attr->src_mode;
886 * Sets the source mode of conversion.
888 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
889 ia32_attr_t *attr = get_ia32_attr(node);
890 attr->src_mode = mode;
894 * Gets the target mode of conversion.
896 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
897 ia32_attr_t *attr = get_ia32_attr(node);
898 return attr->tgt_mode;
902 * Sets the target mode of conversion.
904 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
905 ia32_attr_t *attr = get_ia32_attr(node);
906 attr->tgt_mode = mode;
910 * Gets the frame entity assigned to this node.
912 entity *get_ia32_frame_ent(const ir_node *node) {
913 ia32_attr_t *attr = get_ia32_attr(node);
914 return attr->frame_ent;
918 * Sets the frame entity for this node.
920 void set_ia32_frame_ent(ir_node *node, entity *ent) {
921 ia32_attr_t *attr = get_ia32_attr(node);
922 attr->frame_ent = ent;
923 set_ia32_use_frame(node);
928 * Gets the instruction latency.
930 unsigned get_ia32_latency(const ir_node *node) {
931 ia32_attr_t *attr = get_ia32_attr(node);
932 return attr->latency;
936 * Sets the instruction latency.
938 void set_ia32_latency(ir_node *node, unsigned latency) {
939 ia32_attr_t *attr = get_ia32_attr(node);
940 attr->latency = latency;
944 * Returns the argument register requirements of an ia32 node.
946 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
947 ia32_attr_t *attr = get_ia32_attr(node);
952 * Sets the argument register requirements of an ia32 node.
954 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
955 ia32_attr_t *attr = get_ia32_attr(node);
960 * Returns the result register requirements of an ia32 node.
962 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
963 ia32_attr_t *attr = get_ia32_attr(node);
964 return attr->out_req;
968 * Sets the result register requirements of an ia32 node.
970 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
971 ia32_attr_t *attr = get_ia32_attr(node);
972 attr->out_req = reqs;
976 * Returns the argument register requirement at position pos of an ia32 node.
978 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
979 ia32_attr_t *attr = get_ia32_attr(node);
980 return attr->in_req != NULL ? attr->in_req[pos] : NULL;
984 * Returns the result register requirement at position pos of an ia32 node.
986 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
987 ia32_attr_t *attr = get_ia32_attr(node);
988 return attr->out_req != NULL ? attr->out_req[pos] : NULL;
992 * Sets the OUT register requirements at position pos.
994 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
995 ia32_attr_t *attr = get_ia32_attr(node);
996 attr->out_req[pos] = req;
1000 * Sets the IN register requirements at position pos.
1002 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
1003 ia32_attr_t *attr = get_ia32_attr(node);
1004 attr->in_req[pos] = req;
1008 * Returns the register flag of an ia32 node.
1010 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
1011 ia32_attr_t *attr = get_ia32_attr(node);
1012 return attr->data.flags;
1016 * Sets the register flag of an ia32 node.
1018 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
1019 ia32_attr_t *attr = get_ia32_attr(node);
1020 attr->data.flags = flags;
1024 * Returns the result register slots of an ia32 node.
1026 const arch_register_t **get_ia32_slots(const ir_node *node) {
1027 ia32_attr_t *attr = get_ia32_attr(node);
1032 * Sets the number of results.
1034 void set_ia32_n_res(ir_node *node, int n_res) {
1035 ia32_attr_t *attr = get_ia32_attr(node);
1036 attr->data.n_res = n_res;
1040 * Returns the number of results.
1042 int get_ia32_n_res(const ir_node *node) {
1043 ia32_attr_t *attr = get_ia32_attr(node);
1044 return attr->data.n_res;
1048 * Returns the flavour of an ia32 node,
1050 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1051 ia32_attr_t *attr = get_ia32_attr(node);
1052 return attr->data.op_flav;
1056 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1058 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1059 ia32_attr_t *attr = get_ia32_attr(node);
1060 attr->data.op_flav = op_flav;
1064 * Returns the projnum code.
1066 long get_ia32_pncode(const ir_node *node) {
1067 ia32_attr_t *attr = get_ia32_attr(node);
1068 return attr->pn_code;
1072 * Sets the projnum code
1074 void set_ia32_pncode(ir_node *node, long code) {
1075 ia32_attr_t *attr = get_ia32_attr(node);
1076 attr->pn_code = code;
1080 * Sets the flags for the n'th out.
1082 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
1083 ia32_attr_t *attr = get_ia32_attr(node);
1084 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1085 attr->out_flags[pos] = flags;
1089 * Gets the flags for the n'th out.
1091 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
1092 ia32_attr_t *attr = get_ia32_attr(node);
1093 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
1097 * Get the list of available execution units.
1099 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
1100 ia32_attr_t *attr = get_ia32_attr(node);
1101 return attr->exec_units;
1107 * Returns the name of the original ir node.
1109 const char *get_ia32_orig_node(const ir_node *node) {
1110 ia32_attr_t *attr = get_ia32_attr(node);
1111 return attr->orig_node;
1115 * Sets the name of the original ir node.
1117 void set_ia32_orig_node(ir_node *node, const char *name) {
1118 ia32_attr_t *attr = get_ia32_attr(node);
1119 attr->orig_node = name;
1124 /******************************************************************************************************
1126 * (_) | | | | | | / _| | | (_)
1127 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1128 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1129 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1130 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1133 ******************************************************************************************************/
1136 * Gets the type of an ia32_Const.
1138 unsigned get_ia32_Const_type(const ir_node *node) {
1139 ia32_attr_t *attr = get_ia32_attr(node);
1141 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1143 return attr->data.tp;
1147 * Sets the type of an ia32_Const.
1149 void set_ia32_Const_type(ir_node *node, int type) {
1150 ia32_attr_t *attr = get_ia32_attr(node);
1152 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1153 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1155 attr->data.tp = type;
1159 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1161 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1162 ia32_attr_t *na = get_ia32_attr(node);
1163 ia32_attr_t *ca = get_ia32_attr(cnst);
1165 switch(get_ia32_Const_type(cnst)) {
1167 na->cnst_val.tv = ca->cnst_val.tv;
1168 na->cnst = ca->cnst;
1169 set_ia32_immop_type(node, ia32_ImmConst);
1172 na->cnst_val.sc = ca->cnst_val.sc;
1173 na->cnst = na->cnst_val.sc;
1174 set_ia32_immop_type(node, ia32_ImmSymConst);
1177 assert(0 && "Need ia32_Const to set Immop attr");
1182 * Copy the attributes from Immop to an Immop
1184 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1185 ia32_attr_t *da = get_ia32_attr(dst);
1186 ia32_attr_t *sa = get_ia32_attr(src);
1188 switch(get_ia32_immop_type(src)) {
1190 da->cnst_val.tv = sa->cnst_val.tv;
1191 da->cnst = sa->cnst;
1192 set_ia32_immop_type(dst, ia32_ImmConst);
1194 case ia32_ImmSymConst:
1195 da->cnst_val.sc = sa->cnst_val.sc;
1196 da->cnst = sa->cnst;
1197 set_ia32_immop_type(dst, ia32_ImmSymConst);
1200 assert(0 && "Need Immop to copy Immop attr");
1205 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1207 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1208 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1211 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1213 switch (get_irn_opcode(cnst)) {
1215 attr->data.tp = ia32_Const;
1216 attr->cnst_val.tv = get_Const_tarval(cnst);
1217 mode = get_tarval_mode(attr->cnst_val.tv);
1218 if (mode_is_reference(mode) &&
1219 get_mode_null(mode) == attr->cnst_val.tv) {
1220 attr->cnst_val.tv = get_mode_null(mode_Iu);
1222 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1225 attr->data.tp = ia32_SymConst;
1226 attr->cnst_val.sc = get_sc_ident(cnst);
1227 attr->cnst = attr->cnst_val.sc;
1230 assert(0 && "Unknown Const NYI");
1233 assert(0 && "Cannot create ia32_Const for this opcode");
1238 * Sets the AddrMode(S|D) attribute
1240 void set_ia32_AddrMode(ir_node *node, char direction) {
1241 ia32_attr_t *attr = get_ia32_attr(node);
1243 switch (direction) {
1245 attr->data.tp = ia32_AddrModeD;
1248 attr->data.tp = ia32_AddrModeS;
1251 assert(0 && "wrong AM type");
1256 * Returns whether or not the node is an immediate operation with Const.
1258 int is_ia32_ImmConst(const ir_node *node) {
1259 ia32_attr_t *attr = get_ia32_attr(node);
1260 return (attr->data.imm_tp == ia32_ImmConst);
1264 * Returns whether or not the node is an immediate operation with SymConst.
1266 int is_ia32_ImmSymConst(const ir_node *node) {
1267 ia32_attr_t *attr = get_ia32_attr(node);
1268 return (attr->data.imm_tp == ia32_ImmSymConst);
1272 * Returns whether or not the node is an AddrModeS node.
1274 int is_ia32_AddrModeS(const ir_node *node) {
1275 ia32_attr_t *attr = get_ia32_attr(node);
1276 return (attr->data.tp == ia32_AddrModeS);
1280 * Returns whether or not the node is an AddrModeD node.
1282 int is_ia32_AddrModeD(const ir_node *node) {
1283 ia32_attr_t *attr = get_ia32_attr(node);
1284 return (attr->data.tp == ia32_AddrModeD);
1288 * Checks if node is a Load or xLoad/vfLoad.
1290 int is_ia32_Ld(const ir_node *node) {
1291 int op = get_ia32_irn_opcode(node);
1292 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1296 * Checks if node is a Store or xStore/vfStore.
1298 int is_ia32_St(const ir_node *node) {
1299 int op = get_ia32_irn_opcode(node);
1300 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1304 * Checks if node is a Const or xConst/vfConst.
1306 int is_ia32_Cnst(const ir_node *node) {
1307 int op = get_ia32_irn_opcode(node);
1308 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1312 * Returns the name of the OUT register at position pos.
1314 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1315 ia32_attr_t *attr = get_ia32_attr(node);
1317 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1318 assert(attr->slots[pos] && "No register assigned");
1320 return arch_register_get_name(attr->slots[pos]);
1324 * Returns the index of the OUT register at position pos within its register class.
1326 int get_ia32_out_regnr(const ir_node *node, int pos) {
1327 ia32_attr_t *attr = get_ia32_attr(node);
1329 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1330 assert(attr->slots[pos] && "No register assigned");
1332 return arch_register_get_index(attr->slots[pos]);
1336 * Returns the OUT register at position pos.
1338 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1339 ia32_attr_t *attr = get_ia32_attr(node);
1341 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1342 assert(attr->slots[pos] && "No register assigned");
1344 return attr->slots[pos];
1348 * Initializes the nodes attributes.
1350 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1351 const ia32_register_req_t **out_reqs, const be_execution_unit_t ***execution_units,
1352 int n_res, unsigned latency)
1354 ia32_attr_t *attr = get_ia32_attr(node);
1356 set_ia32_flags(node, flags);
1357 set_ia32_in_req_all(node, in_reqs);
1358 set_ia32_out_req_all(node, out_reqs);
1359 set_ia32_latency(node, latency);
1360 set_ia32_n_res(node, n_res);
1362 attr->exec_units = execution_units;
1364 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1365 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1367 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1370 /***************************************************************************************
1373 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1374 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1375 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1376 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1378 ***************************************************************************************/
1380 /* default compare operation to compare immediate ops */
1381 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1384 if (a->data.tp == b->data.tp) {
1385 equ = (a->cnst == b->cnst);
1386 equ = equ ? (a->data.use_frame == b->data.use_frame) : 0;
1388 if (equ && a->data.use_frame && b->data.use_frame)
1389 equ = (a->frame_ent == b->frame_ent);
1395 /* compare converts */
1396 int ia32_compare_conv_attr(ia32_attr_t *a, ia32_attr_t *b) {
1397 int equ = ! ia32_compare_immop_attr(a, b);
1399 equ = equ ? (a->src_mode == b->src_mode) && (a->tgt_mode == b->tgt_mode) : equ;
1404 /* copies the ia32 attributes */
1405 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1406 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1407 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1409 /* copy the attributes */
1410 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1412 /* copy out flags */
1413 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1417 * Registers the ia32_copy_attr function for all ia32 opcodes.
1419 void ia32_register_copy_attr_func(void) {
1420 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1422 for (i = f; i < l; i++) {
1423 ir_op *op = get_irp_opcode(i);
1424 op->ops.copy_attr = ia32_copy_attr;
1428 /* Include the generated constructor functions */
1429 #include "gen_ia32_new_nodes.c.inl"