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"
35 #include "../bearch.h"
37 #include "ia32_nodes_attr.h"
38 #include "ia32_new_nodes.h"
39 #include "gen_ia32_regalloc_if.h"
40 #include "gen_ia32_machine.h"
43 * Returns the ident of an entity
44 * @param ent The entity
45 * @return The ident of the entity
47 ident *ia32_get_ent_ident(ir_entity *ent) {
48 ir_type *owner = get_entity_owner(ent);
49 ident *id = get_entity_ld_ident(ent);
51 if (owner == get_tls_type()) {
52 if (get_entity_visibility(ent) == visibility_external_allocated)
53 id = mangle(id, new_id_from_chars("@INDNTPOFF", 10));
55 id = mangle(id, new_id_from_chars("@NTPOFF", 7));
61 * Returns the ident of a SymConst.
62 * @param symc The SymConst
63 * @return The ident of the SymConst
65 static ident *get_sc_ident(ir_node *symc) {
66 switch (get_SymConst_kind(symc)) {
67 case symconst_addr_name:
68 return get_SymConst_name(symc);
70 case symconst_addr_ent:
71 return ia32_get_ent_ident(get_SymConst_entity(symc));
74 assert(0 && "Unsupported SymConst");
81 * returns true if a node has x87 registers
83 int ia32_has_x87_register(const ir_node *n) {
84 assert(is_ia32_irn(n) && "Need ia32 node.");
85 return is_irn_machine_user(n, 0);
88 /***********************************************************************************
91 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
92 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
93 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
94 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
97 ***********************************************************************************/
100 * Returns a string containing the names of all registers within the limited bitset
102 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
103 bitset_t *bs = bitset_alloca(req->cls->n_regs);
108 req->limited(NULL, bs);
110 for (i = 0; i < req->cls->n_regs; i++) {
111 if (bitset_is_set(bs, i)) {
112 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
114 fprintf(stderr, "dumper problem, exiting\n");
130 * Dumps the register requirements for either in or out.
132 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
133 char *dir = inout ? "out" : "in";
134 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
135 char *buf = alloca(1024);
138 memset(buf, 0, 1024);
141 for (i = 0; i < max; i++) {
142 fprintf(F, "%sreq #%d =", dir, i);
144 if (reqs[i]->req.type == arch_register_req_type_none) {
148 if (reqs[i]->req.type & arch_register_req_type_normal) {
149 fprintf(F, " %s", reqs[i]->req.cls->name);
152 if (reqs[i]->req.type & arch_register_req_type_limited) {
153 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
156 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
157 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
160 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
161 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
170 fprintf(F, "%sreq = N/A\n", dir);
175 * Dumper interface for dumping ia32 nodes in vcg.
176 * @param n the node to dump
177 * @param F the output file
178 * @param reason indicates which kind of information should be dumped
179 * @return 0 on success or != 0 on failure
181 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
182 ir_mode *mode = NULL;
184 int i, n_res, am_flav, flags;
185 const ia32_register_req_t **reqs;
186 const arch_register_t **slots;
189 case dump_node_opcode_txt:
190 fprintf(F, "%s", get_irn_opname(n));
193 case dump_node_mode_txt:
194 mode = get_irn_mode(n);
196 if (is_ia32_Ld(n) || is_ia32_St(n)) {
197 mode = get_ia32_ls_mode(n);
200 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
203 case dump_node_nodeattr_txt:
204 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
205 char *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
206 const char *cnst = get_ia32_cnst(n);
208 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
211 if (! is_ia32_Lea(n)) {
212 if (is_ia32_AddrModeS(n)) {
213 fprintf(F, "[AM S] ");
215 else if (is_ia32_AddrModeD(n)) {
216 fprintf(F, "[AM D] ");
222 case dump_node_info_txt:
223 n_res = get_ia32_n_res(n);
224 fprintf(F, "=== IA32 attr begin ===\n");
226 /* dump IN requirements */
227 if (get_irn_arity(n) > 0) {
228 reqs = get_ia32_in_req_all(n);
229 dump_reg_req(F, n, reqs, 0);
232 /* dump OUT requirements */
234 reqs = get_ia32_out_req_all(n);
235 dump_reg_req(F, n, reqs, 1);
238 /* dump assigned registers */
239 slots = get_ia32_slots(n);
240 if (slots && n_res > 0) {
241 for (i = 0; i < n_res; i++) {
242 const arch_register_t *reg;
244 /* retrieve "real" x87 register */
245 if (ia32_has_x87_register(n))
246 reg = get_ia32_attr(n)->x87[i + 2];
250 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
257 switch (get_ia32_op_type(n)) {
259 fprintf(F, "Normal");
265 fprintf(F, "SymConst");
268 fprintf(F, "AM Dest (Load+Store)");
271 fprintf(F, "AM Source (Load)");
274 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
279 /* dump immop type */
280 fprintf(F, "immediate = ");
281 switch (get_ia32_immop_type(n)) {
288 case ia32_ImmSymConst:
289 fprintf(F, "SymConst");
292 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
297 /* dump supported am */
298 fprintf(F, "AM support = ");
299 switch (get_ia32_am_support(n)) {
304 fprintf(F, "source only (Load)");
307 fprintf(F, "dest only (Load+Store)");
313 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
318 /* dump am flavour */
319 fprintf(F, "AM flavour =");
320 am_flav = get_ia32_am_flavour(n);
321 if (am_flav == ia32_am_N) {
325 if (am_flav & ia32_O) {
328 if (am_flav & ia32_B) {
331 if (am_flav & ia32_I) {
334 if (am_flav & ia32_S) {
338 fprintf(F, " (%d)\n", am_flav);
341 fprintf(F, "AM offset = ");
342 if (get_ia32_am_offs(n)) {
343 fprintf(F, "%s", get_ia32_am_offs(n));
350 /* dump AM symconst */
351 if(get_ia32_am_sc(n) != NULL) {
352 fprintf(F, "AM symconst = %s\n", get_id_str(get_ia32_am_sc(n)));
356 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
359 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
360 fprintf(F, "pn_code = %d (%s, unsigned)\n", get_ia32_pncode(n),
361 get_pnc_string(get_ia32_pncode(n) & ~ia32_pn_Cmp_Unsigned));
363 fprintf(F, "pn_code = %d (%s)\n", get_ia32_pncode(n),
364 get_pnc_string(get_ia32_pncode(n)));
368 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
371 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
374 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
377 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
380 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
383 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
386 fprintf(F, "latency = %d\n", get_ia32_latency(n));
389 fprintf(F, "flags =");
390 flags = get_ia32_flags(n);
391 if (flags == arch_irn_flags_none) {
395 if (flags & arch_irn_flags_dont_spill) {
396 fprintf(F, " unspillable");
398 if (flags & arch_irn_flags_rematerializable) {
399 fprintf(F, " remat");
401 if (flags & arch_irn_flags_ignore) {
402 fprintf(F, " ignore");
404 if (flags & arch_irn_flags_modify_sp) {
405 fprintf(F, " modify_sp");
408 fprintf(F, " (%d)\n", flags);
410 /* dump frame entity */
411 fprintf(F, "frame entity = ");
412 if (get_ia32_frame_ent(n)) {
413 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
421 fprintf(F, "ls_mode = ");
422 if (get_ia32_ls_mode(n)) {
423 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
431 /* dump original ir node name */
432 fprintf(F, "orig node = ");
433 if (get_ia32_orig_node(n)) {
434 fprintf(F, "%s", get_ia32_orig_node(n));
442 fprintf(F, "=== IA32 attr end ===\n");
443 /* end of: case dump_node_info_txt */
452 /***************************************************************************************************
454 * | | | | | | / / | | | | | | | |
455 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
456 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
457 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
458 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
461 ***************************************************************************************************/
464 * Returns an ident for the given tarval tv.
466 static ident *get_ident_for_tv(tarval *tv) {
468 int len = tarval_snprintf(buf, sizeof(buf), tv);
470 return new_id_from_str(buf);
474 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
475 * Firm was made by people hating const :-(
477 ia32_attr_t *get_ia32_attr(const ir_node *node) {
478 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
479 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
483 * Gets the type of an ia32 node.
485 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
486 ia32_attr_t *attr = get_ia32_attr(node);
487 return attr->data.tp;
491 * Sets the type of an ia32 node.
493 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
494 ia32_attr_t *attr = get_ia32_attr(node);
499 * Gets the immediate op type of an ia32 node.
501 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
502 ia32_attr_t *attr = get_ia32_attr(node);
503 return attr->data.imm_tp;
507 * Sets the immediate op type of an ia32 node.
509 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
510 ia32_attr_t *attr = get_ia32_attr(node);
511 attr->data.imm_tp = tp;
515 * Gets the supported addrmode of an ia32 node
517 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
518 ia32_attr_t *attr = get_ia32_attr(node);
519 return attr->data.am_support;
523 * Sets the supported addrmode of an ia32 node
525 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
526 ia32_attr_t *attr = get_ia32_attr(node);
527 attr->data.am_support = am_tp;
531 * Gets the addrmode flavour of an ia32 node
533 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
534 ia32_attr_t *attr = get_ia32_attr(node);
535 return attr->data.am_flavour;
539 * Sets the addrmode flavour of an ia32 node
541 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
542 ia32_attr_t *attr = get_ia32_attr(node);
543 attr->data.am_flavour = am_flavour;
547 * Joins all offsets to one string with adds.
549 char *get_ia32_am_offs(const ir_node *node) {
550 ia32_attr_t *attr = get_ia32_attr(node);
553 snprintf(res, sizeof(res), "%+d", attr->am_offs);
559 * Gets the addressmode offset as int.
561 int get_ia32_am_offs_int(const ir_node *node) {
562 ia32_attr_t *attr = get_ia32_attr(node);
563 return attr->am_offs;
567 * Sets the addressmode offset from an int.
569 void set_ia32_am_offs_int(ir_node *node, int offset) {
570 ia32_attr_t *attr = get_ia32_attr(node);
571 attr->am_offs = offset;
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, '+');
607 void add_ia32_am_offs_int(ir_node *node, int offset) {
608 ia32_attr_t *attr = get_ia32_attr(node);
609 attr->am_offs += offset;
614 * Sub an offset for addrmode.
616 void sub_ia32_am_offs(ir_node *node, const char *offset) {
617 extend_ia32_am_offs(node, (char *)offset, '-');
622 * Returns the symconst ident associated to addrmode.
624 ident *get_ia32_am_sc(const ir_node *node) {
625 ia32_attr_t *attr = get_ia32_attr(node);
630 * Sets the symconst ident associated to addrmode.
632 void set_ia32_am_sc(ir_node *node, ident *sc) {
633 ia32_attr_t *attr = get_ia32_attr(node);
638 * Sets the sign bit for address mode symconst.
640 void set_ia32_am_sc_sign(ir_node *node) {
641 ia32_attr_t *attr = get_ia32_attr(node);
642 attr->data.am_sc_sign = 1;
646 * Clears the sign bit for address mode symconst.
648 void clear_ia32_am_sc_sign(ir_node *node) {
649 ia32_attr_t *attr = get_ia32_attr(node);
650 attr->data.am_sc_sign = 0;
654 * Returns the sign bit for address mode symconst.
656 int is_ia32_am_sc_sign(const ir_node *node) {
657 ia32_attr_t *attr = get_ia32_attr(node);
658 return attr->data.am_sc_sign;
662 * Gets the addr mode const.
664 int get_ia32_am_scale(const ir_node *node) {
665 ia32_attr_t *attr = get_ia32_attr(node);
666 return attr->data.am_scale;
670 * Sets the index register scale for addrmode.
672 void set_ia32_am_scale(ir_node *node, int scale) {
673 ia32_attr_t *attr = get_ia32_attr(node);
674 attr->data.am_scale = scale;
678 * Return the tarval of an immediate operation or NULL in case of SymConst
680 tarval *get_ia32_Immop_tarval(const ir_node *node) {
681 ia32_attr_t *attr = get_ia32_attr(node);
682 return attr->cnst_val.tv;
686 * Sets the attributes of an immediate operation to the specified tarval
688 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
689 ia32_attr_t *attr = get_ia32_attr(node);
690 attr->cnst_val.tv = tv;
691 attr->cnst = get_ident_for_tv(tv);
695 * Sets a symconsts ident
697 void set_ia32_Symconst_ident(ir_node *node, ident *ident)
699 ia32_attr_t *attr = get_ia32_attr(node);
700 attr->cnst_val.sc = ident;
705 * Gets the string representation of the internal const (tv or symconst)
707 const char *get_ia32_cnst(const ir_node *node) {
708 ia32_attr_t *attr = get_ia32_attr(node);
711 return get_id_str(attr->cnst);
714 tarval *get_ia32_cnst_tv(const ir_node *node) {
715 ia32_attr_t *attr = get_ia32_attr(node);
716 assert(attr->data.tp == ia32_Const);
717 return attr->cnst_val.tv;
722 * Sets the string representation of the internal const.
724 void set_ia32_cnst(ir_node *node, const char *cnst) {
725 ia32_attr_t *attr = get_ia32_attr(node);
726 attr->cnst = new_id_from_str(cnst);
730 * Gets the ident representation of the internal const (tv or symconst)
732 ident *get_ia32_id_cnst(const ir_node *node) {
733 ia32_attr_t *attr = get_ia32_attr(node);
738 * Sets the ident representation of the internal const.
740 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
741 ia32_attr_t *attr = get_ia32_attr(node);
746 * Sets the uses_frame flag.
748 void set_ia32_use_frame(ir_node *node) {
749 ia32_attr_t *attr = get_ia32_attr(node);
750 attr->data.use_frame = 1;
754 * Clears the uses_frame flag.
756 void clear_ia32_use_frame(ir_node *node) {
757 ia32_attr_t *attr = get_ia32_attr(node);
758 attr->data.use_frame = 0;
762 * Gets the uses_frame flag.
764 int is_ia32_use_frame(const ir_node *node) {
765 ia32_attr_t *attr = get_ia32_attr(node);
766 return attr->data.use_frame;
770 * Sets node to commutative.
772 void set_ia32_commutative(ir_node *node) {
773 ia32_attr_t *attr = get_ia32_attr(node);
774 attr->data.is_commutative = 1;
778 * Sets node to non-commutative.
780 void clear_ia32_commutative(ir_node *node) {
781 ia32_attr_t *attr = get_ia32_attr(node);
782 attr->data.is_commutative = 0;
786 * Checks if node is commutative.
788 int is_ia32_commutative(const ir_node *node) {
789 ia32_attr_t *attr = get_ia32_attr(node);
790 return attr->data.is_commutative;
796 void set_ia32_emit_cl(ir_node *node) {
797 ia32_attr_t *attr = get_ia32_attr(node);
798 attr->data.emit_cl = 1;
802 * Clears node emit_cl.
804 void clear_ia32_emit_cl(ir_node *node) {
805 ia32_attr_t *attr = get_ia32_attr(node);
806 attr->data.emit_cl = 0;
810 * Checks if node needs %cl.
812 int is_ia32_emit_cl(const ir_node *node) {
813 ia32_attr_t *attr = get_ia32_attr(node);
814 return attr->data.emit_cl;
820 void set_ia32_got_lea(ir_node *node) {
821 ia32_attr_t *attr = get_ia32_attr(node);
822 attr->data.got_lea = 1;
826 * Clears node got_lea.
828 void clear_ia32_got_lea(ir_node *node) {
829 ia32_attr_t *attr = get_ia32_attr(node);
830 attr->data.got_lea = 0;
834 * Checks if node got lea.
836 int is_ia32_got_lea(const ir_node *node) {
837 ia32_attr_t *attr = get_ia32_attr(node);
838 return attr->data.got_lea;
842 * Sets node got_reload.
844 void set_ia32_got_reload(ir_node *node) {
845 ia32_attr_t *attr = get_ia32_attr(node);
846 attr->data.got_reload = 1;
850 * Clears node got_reload.
852 void clear_ia32_got_reload(ir_node *node) {
853 ia32_attr_t *attr = get_ia32_attr(node);
854 attr->data.got_reload = 0;
858 * Checks if node got reload.
860 int is_ia32_got_reload(const ir_node *node) {
861 ia32_attr_t *attr = get_ia32_attr(node);
862 return attr->data.got_reload;
866 * Gets the mode of the stored/loaded value (only set for Store/Load)
868 ir_mode *get_ia32_ls_mode(const ir_node *node) {
869 ia32_attr_t *attr = get_ia32_attr(node);
870 return attr->ls_mode;
874 * Sets the mode of the stored/loaded value (only set for Store/Load)
876 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
877 ia32_attr_t *attr = get_ia32_attr(node);
878 attr->ls_mode = mode;
882 * Gets the frame entity assigned to this node.
884 ir_entity *get_ia32_frame_ent(const ir_node *node) {
885 ia32_attr_t *attr = get_ia32_attr(node);
886 return attr->frame_ent;
890 * Sets the frame entity for this node.
892 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
893 ia32_attr_t *attr = get_ia32_attr(node);
894 attr->frame_ent = ent;
896 set_ia32_use_frame(node);
898 clear_ia32_use_frame(node);
903 * Gets the instruction latency.
905 unsigned get_ia32_latency(const ir_node *node) {
906 ia32_attr_t *attr = get_ia32_attr(node);
907 return attr->latency;
911 * Sets the instruction latency.
913 void set_ia32_latency(ir_node *node, unsigned latency) {
914 ia32_attr_t *attr = get_ia32_attr(node);
915 attr->latency = latency;
919 * Returns the argument register requirements of an ia32 node.
921 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
922 ia32_attr_t *attr = get_ia32_attr(node);
927 * Sets the argument register requirements of an ia32 node.
929 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
930 ia32_attr_t *attr = get_ia32_attr(node);
935 * Returns the result register requirements of an ia32 node.
937 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
938 ia32_attr_t *attr = get_ia32_attr(node);
939 return attr->out_req;
943 * Sets the result register requirements of an ia32 node.
945 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
946 ia32_attr_t *attr = get_ia32_attr(node);
947 attr->out_req = reqs;
951 * Returns the argument register requirement at position pos of an ia32 node.
953 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
954 ia32_attr_t *attr = get_ia32_attr(node);
955 return attr->in_req != NULL ? attr->in_req[pos] : NULL;
959 * Returns the result register requirement at position pos of an ia32 node.
961 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
962 ia32_attr_t *attr = get_ia32_attr(node);
963 return attr->out_req != NULL ? attr->out_req[pos] : NULL;
967 * Sets the OUT register requirements at position pos.
969 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
970 ia32_attr_t *attr = get_ia32_attr(node);
971 attr->out_req[pos] = req;
975 * Sets the IN register requirements at position pos.
977 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
978 ia32_attr_t *attr = get_ia32_attr(node);
979 attr->in_req[pos] = req;
983 * Returns the register flag of an ia32 node.
985 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
986 ia32_attr_t *attr = get_ia32_attr(node);
987 return attr->data.flags;
991 * Sets the register flag of an ia32 node.
993 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
994 ia32_attr_t *attr = get_ia32_attr(node);
995 attr->data.flags = flags;
999 * Returns the result register slots of an ia32 node.
1001 const arch_register_t **get_ia32_slots(const ir_node *node) {
1002 ia32_attr_t *attr = get_ia32_attr(node);
1007 * Sets the number of results.
1009 void set_ia32_n_res(ir_node *node, int n_res) {
1010 ia32_attr_t *attr = get_ia32_attr(node);
1011 attr->data.n_res = n_res;
1015 * Returns the number of results.
1017 int get_ia32_n_res(const ir_node *node) {
1018 ia32_attr_t *attr = get_ia32_attr(node);
1019 return attr->data.n_res;
1023 * Returns the flavour of an ia32 node,
1025 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
1026 ia32_attr_t *attr = get_ia32_attr(node);
1027 return attr->data.op_flav;
1031 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
1033 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
1034 ia32_attr_t *attr = get_ia32_attr(node);
1035 attr->data.op_flav = op_flav;
1039 * Returns the projnum code.
1041 pn_Cmp get_ia32_pncode(const ir_node *node) {
1042 ia32_attr_t *attr = get_ia32_attr(node);
1043 return attr->pn_code;
1047 * Sets the projnum code
1049 void set_ia32_pncode(ir_node *node, pn_Cmp code) {
1050 ia32_attr_t *attr = get_ia32_attr(node);
1051 attr->pn_code = code;
1055 * Sets the flags for the n'th out.
1057 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
1058 ia32_attr_t *attr = get_ia32_attr(node);
1059 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1060 attr->out_flags[pos] = flags;
1064 * Gets the flags for the n'th out.
1066 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
1067 ia32_attr_t *attr = get_ia32_attr(node);
1068 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
1072 * Get the list of available execution units.
1074 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
1075 ia32_attr_t *attr = get_ia32_attr(node);
1076 return attr->exec_units;
1082 * Returns the name of the original ir node.
1084 const char *get_ia32_orig_node(const ir_node *node) {
1085 ia32_attr_t *attr = get_ia32_attr(node);
1086 return attr->orig_node;
1090 * Sets the name of the original ir node.
1092 void set_ia32_orig_node(ir_node *node, const char *name) {
1093 ia32_attr_t *attr = get_ia32_attr(node);
1094 attr->orig_node = name;
1099 /******************************************************************************************************
1101 * (_) | | | | | | / _| | | (_)
1102 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
1103 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
1104 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1105 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1108 ******************************************************************************************************/
1111 * Gets the type of an ia32_Const.
1113 unsigned get_ia32_Const_type(const ir_node *node) {
1114 ia32_attr_t *attr = get_ia32_attr(node);
1116 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
1118 return attr->data.tp;
1122 * Sets the type of an ia32_Const.
1124 void set_ia32_Const_type(ir_node *node, int type) {
1125 ia32_attr_t *attr = get_ia32_attr(node);
1127 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1128 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1130 attr->data.tp = type;
1134 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1136 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1137 ia32_attr_t *na = get_ia32_attr(node);
1138 ia32_attr_t *ca = get_ia32_attr(cnst);
1140 switch(get_ia32_Const_type(cnst)) {
1142 assert(ca->cnst_val.tv != NULL);
1143 na->cnst_val.tv = ca->cnst_val.tv;
1144 na->cnst = ca->cnst;
1145 set_ia32_immop_type(node, ia32_ImmConst);
1148 na->cnst_val.sc = ca->cnst_val.sc;
1149 na->cnst = na->cnst_val.sc;
1150 set_ia32_immop_type(node, ia32_ImmSymConst);
1153 assert(0 && "Need ia32_Const to set Immop attr");
1158 * Copy the attributes from Immop to an Immop
1160 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1161 ia32_attr_t *da = get_ia32_attr(dst);
1162 ia32_attr_t *sa = get_ia32_attr(src);
1164 switch(get_ia32_immop_type(src)) {
1166 da->cnst_val.tv = sa->cnst_val.tv;
1167 da->cnst = sa->cnst;
1168 set_ia32_immop_type(dst, ia32_ImmConst);
1170 case ia32_ImmSymConst:
1171 da->cnst_val.sc = sa->cnst_val.sc;
1172 da->cnst = sa->cnst;
1173 set_ia32_immop_type(dst, ia32_ImmSymConst);
1176 assert(0 && "Need Immop to copy Immop attr");
1181 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1183 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1184 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1186 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1188 switch (get_irn_opcode(cnst)) {
1190 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
1193 attr->data.tp = ia32_SymConst;
1194 attr->cnst_val.sc = get_sc_ident(cnst);
1195 attr->cnst = attr->cnst_val.sc;
1198 assert(0 && "Unknown Const NYI");
1201 assert(0 && "Cannot create ia32_Const for this opcode");
1205 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
1206 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1208 if(mode_is_reference(get_tarval_mode(tv))) {
1209 if(tarval_is_null(tv)) {
1210 tv = get_tarval_null(mode_Iu);
1212 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
1215 tv = tarval_convert_to(tv, mode_Iu);
1218 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
1220 attr->data.tp = ia32_Const;
1221 attr->cnst_val.tv = tv;
1222 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1227 * Sets the AddrMode(S|D) attribute
1229 void set_ia32_AddrMode(ir_node *node, char direction) {
1230 ia32_attr_t *attr = get_ia32_attr(node);
1232 switch (direction) {
1234 attr->data.tp = ia32_AddrModeD;
1237 attr->data.tp = ia32_AddrModeS;
1240 assert(0 && "wrong AM type");
1245 * Returns whether or not the node is an immediate operation with Const.
1247 int is_ia32_ImmConst(const ir_node *node) {
1248 ia32_attr_t *attr = get_ia32_attr(node);
1249 return (attr->data.imm_tp == ia32_ImmConst);
1253 * Returns whether or not the node is an immediate operation with SymConst.
1255 int is_ia32_ImmSymConst(const ir_node *node) {
1256 ia32_attr_t *attr = get_ia32_attr(node);
1257 return (attr->data.imm_tp == ia32_ImmSymConst);
1261 * Returns whether or not the node is an AddrModeS node.
1263 int is_ia32_AddrModeS(const ir_node *node) {
1264 ia32_attr_t *attr = get_ia32_attr(node);
1265 return (attr->data.tp == ia32_AddrModeS);
1269 * Returns whether or not the node is an AddrModeD node.
1271 int is_ia32_AddrModeD(const ir_node *node) {
1272 ia32_attr_t *attr = get_ia32_attr(node);
1273 return (attr->data.tp == ia32_AddrModeD);
1277 * Checks if node is a Load or xLoad/vfLoad.
1279 int is_ia32_Ld(const ir_node *node) {
1280 int op = get_ia32_irn_opcode(node);
1281 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1285 * Checks if node is a Store or xStore/vfStore.
1287 int is_ia32_St(const ir_node *node) {
1288 int op = get_ia32_irn_opcode(node);
1289 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1293 * Checks if node is a Const or xConst/vfConst.
1295 int is_ia32_Cnst(const ir_node *node) {
1296 int op = get_ia32_irn_opcode(node);
1297 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1301 * Returns the name of the OUT register at position pos.
1303 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1304 ia32_attr_t *attr = get_ia32_attr(node);
1306 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1307 assert(attr->slots[pos] && "No register assigned");
1309 return arch_register_get_name(attr->slots[pos]);
1313 * Returns the index of the OUT register at position pos within its register class.
1315 int get_ia32_out_regnr(const ir_node *node, int pos) {
1316 ia32_attr_t *attr = get_ia32_attr(node);
1318 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1319 assert(attr->slots[pos] && "No register assigned");
1321 return arch_register_get_index(attr->slots[pos]);
1325 * Returns the OUT register at position pos.
1327 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1328 ia32_attr_t *attr = get_ia32_attr(node);
1330 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1331 assert(attr->slots[pos] && "No register assigned");
1333 return attr->slots[pos];
1337 * Initializes the nodes attributes.
1339 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1340 const ia32_register_req_t **out_reqs, const be_execution_unit_t ***execution_units,
1341 int n_res, unsigned latency)
1343 ia32_attr_t *attr = get_ia32_attr(node);
1345 set_ia32_flags(node, flags);
1346 set_ia32_in_req_all(node, in_reqs);
1347 set_ia32_out_req_all(node, out_reqs);
1348 set_ia32_latency(node, latency);
1349 set_ia32_n_res(node, n_res);
1351 attr->exec_units = execution_units;
1353 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1354 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1356 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1359 ir_node *get_ia32_result_proj(const ir_node *node)
1361 const ir_edge_t *edge;
1363 foreach_out_edge(node, edge) {
1364 ir_node *proj = get_edge_src_irn(edge);
1365 if(get_Proj_proj(proj) == 0) {
1372 /***************************************************************************************
1375 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1376 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1377 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1378 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1380 ***************************************************************************************/
1382 /* default compare operation to compare attributes */
1383 int ia32_compare_attr(ia32_attr_t *a, ia32_attr_t *b) {
1384 if (a->data.tp != b->data.tp)
1387 if (a->cnst != b->cnst)
1390 if (a->data.use_frame != b->data.use_frame
1391 || a->data.use_frame != b->data.use_frame
1392 || a->frame_ent != b->frame_ent)
1395 if (a->data.am_flavour != b->data.am_flavour
1396 || a->data.am_scale != b->data.am_scale
1397 || a->data.offs_sign != b->data.offs_sign
1398 || a->data.am_sc_sign != b->data.am_sc_sign
1399 || a->am_offs != b->am_offs
1400 || a->am_sc != b->am_sc
1401 || a->ls_mode != b->ls_mode)
1404 if(a->pn_code != b->pn_code)
1407 if (a->data.tp != b->data.tp
1408 || a->data.op_flav != b->data.op_flav)
1414 /* copies the ia32 attributes */
1415 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1416 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1417 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1419 /* copy the attributes */
1420 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1422 /* copy out flags */
1423 attr_new->out_flags =
1424 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1428 * Registers the ia32_copy_attr function for all ia32 opcodes.
1430 void ia32_register_copy_attr_func(void) {
1431 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1433 for (i = f; i < l; i++) {
1434 ir_op *op = get_irp_opcode(i);
1435 op->ops.copy_attr = ia32_copy_attr;
1439 /* Include the generated constructor functions */
1440 #include "gen_ia32_new_nodes.c.inl"