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
14 #include "irgraph_t.h"
20 #include "firm_common_t.h"
25 #include "raw_bitset.h"
28 #include "../bearch.h"
30 #include "ia32_nodes_attr.h"
31 #include "ia32_new_nodes.h"
32 #include "gen_ia32_regalloc_if.h"
33 #include "gen_ia32_machine.h"
36 * returns true if a node has x87 registers
38 int ia32_has_x87_register(const ir_node *n) {
39 assert(is_ia32_irn(n) && "Need ia32 node.");
40 return is_irn_machine_user(n, 0);
43 /***********************************************************************************
46 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
47 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
48 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
49 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
52 ***********************************************************************************/
55 * Dumps the register requirements for either in or out.
57 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
59 char *dir = inout ? "out" : "in";
60 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
64 memset(buf, 0, sizeof(buf));
67 for (i = 0; i < max; i++) {
68 fprintf(F, "%sreq #%d =", dir, i);
70 if (reqs[i]->type == arch_register_req_type_none) {
74 if (reqs[i]->type & arch_register_req_type_normal) {
75 fprintf(F, " %s", reqs[i]->cls->name);
78 if (reqs[i]->type & arch_register_req_type_limited) {
80 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
83 if (reqs[i]->type & arch_register_req_type_should_be_same) {
84 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
87 if (reqs[i]->type & arch_register_req_type_should_be_different) {
88 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
97 fprintf(F, "%sreq = N/A\n", dir);
102 * Dumper interface for dumping ia32 nodes in vcg.
103 * @param n the node to dump
104 * @param F the output file
105 * @param reason indicates which kind of information should be dumped
106 * @return 0 on success or != 0 on failure
108 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
109 ir_mode *mode = NULL;
111 int i, n_res, am_flav, flags;
112 const arch_register_req_t **reqs;
113 const arch_register_t **slots;
116 case dump_node_opcode_txt:
117 fprintf(F, "%s", get_irn_opname(n));
120 case dump_node_mode_txt:
121 mode = get_irn_mode(n);
123 if (is_ia32_Ld(n) || is_ia32_St(n)) {
124 mode = get_ia32_ls_mode(n);
127 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
130 case dump_node_nodeattr_txt:
131 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
132 if(is_ia32_ImmSymConst(n)) {
133 ir_entity *ent = get_ia32_Immop_symconst(n);
134 ident *id = get_entity_ld_ident(ent);
135 fprintf(F, "[SymC %s]", get_id_str(id));
138 tarval *tv = get_ia32_Immop_tarval(n);
140 tarval_snprintf(buf, sizeof(buf), tv);
141 fprintf(F, "[%s]", buf);
145 if (! is_ia32_Lea(n)) {
146 if (is_ia32_AddrModeS(n)) {
147 fprintf(F, "[AM S] ");
149 else if (is_ia32_AddrModeD(n)) {
150 fprintf(F, "[AM D] ");
156 case dump_node_info_txt:
157 n_res = get_ia32_n_res(n);
158 fprintf(F, "=== IA32 attr begin ===\n");
160 /* dump IN requirements */
161 if (get_irn_arity(n) > 0) {
162 reqs = get_ia32_in_req_all(n);
163 dump_reg_req(F, n, reqs, 0);
166 /* dump OUT requirements */
168 reqs = get_ia32_out_req_all(n);
169 dump_reg_req(F, n, reqs, 1);
172 /* dump assigned registers */
173 slots = get_ia32_slots(n);
174 if (slots && n_res > 0) {
175 for (i = 0; i < n_res; i++) {
176 const arch_register_t *reg;
178 /* retrieve "real" x87 register */
179 if (ia32_has_x87_register(n))
180 reg = get_ia32_attr(n)->x87[i + 2];
184 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
191 switch (get_ia32_op_type(n)) {
193 fprintf(F, "Normal");
196 fprintf(F, "AM Dest (Load+Store)");
199 fprintf(F, "AM Source (Load)");
202 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
207 /* dump immop type */
208 fprintf(F, "immediate = ");
209 switch (get_ia32_immop_type(n)) {
216 case ia32_ImmSymConst:
217 fprintf(F, "SymConst");
220 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
225 /* dump supported am */
226 fprintf(F, "AM support = ");
227 switch (get_ia32_am_support(n)) {
232 fprintf(F, "source only (Load)");
235 fprintf(F, "dest only (Load+Store)");
241 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
246 /* dump am flavour */
247 fprintf(F, "AM flavour =");
248 am_flav = get_ia32_am_flavour(n);
249 if (am_flav == ia32_am_N) {
253 if (am_flav & ia32_O) {
256 if (am_flav & ia32_B) {
259 if (am_flav & ia32_I) {
262 if (am_flav & ia32_S) {
266 fprintf(F, " (%d)\n", am_flav);
269 if(get_ia32_am_offs_int(n) != 0) {
270 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
273 /* dump AM symconst */
274 if(get_ia32_am_sc(n) != NULL) {
275 ir_entity *ent = get_ia32_am_sc(n);
276 ident *id = get_entity_ld_ident(ent);
277 fprintf(F, "AM symconst = %s\n", get_id_str(id));
281 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
284 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
285 fprintf(F, "pn_code = %d (%s, unsigned)\n", get_ia32_pncode(n),
286 get_pnc_string(get_ia32_pncode(n) & ~ia32_pn_Cmp_Unsigned));
288 fprintf(F, "pn_code = %d (%s)\n", get_ia32_pncode(n),
289 get_pnc_string(get_ia32_pncode(n)));
293 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
296 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
299 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
302 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
305 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
308 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
311 fprintf(F, "latency = %d\n", get_ia32_latency(n));
314 fprintf(F, "flags =");
315 flags = get_ia32_flags(n);
316 if (flags == arch_irn_flags_none) {
320 if (flags & arch_irn_flags_dont_spill) {
321 fprintf(F, " unspillable");
323 if (flags & arch_irn_flags_rematerializable) {
324 fprintf(F, " remat");
326 if (flags & arch_irn_flags_ignore) {
327 fprintf(F, " ignore");
329 if (flags & arch_irn_flags_modify_sp) {
330 fprintf(F, " modify_sp");
333 fprintf(F, " (%d)\n", flags);
335 /* dump frame entity */
336 fprintf(F, "frame entity = ");
337 if (get_ia32_frame_ent(n)) {
338 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
346 fprintf(F, "ls_mode = ");
347 if (get_ia32_ls_mode(n)) {
348 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
356 /* dump original ir node name */
357 fprintf(F, "orig node = ");
358 if (get_ia32_orig_node(n)) {
359 fprintf(F, "%s", get_ia32_orig_node(n));
367 fprintf(F, "=== IA32 attr end ===\n");
368 /* end of: case dump_node_info_txt */
377 /***************************************************************************************************
379 * | | | | | | / / | | | | | | | |
380 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
381 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
382 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
383 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
386 ***************************************************************************************************/
389 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
390 * Firm was made by people hating const :-(
392 ia32_attr_t *get_ia32_attr(const ir_node *node) {
393 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
394 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
398 * Gets the type of an ia32 node.
400 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
401 ia32_attr_t *attr = get_ia32_attr(node);
402 return attr->data.tp;
406 * Sets the type of an ia32 node.
408 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
409 ia32_attr_t *attr = get_ia32_attr(node);
414 * Gets the immediate op type of an ia32 node.
416 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
417 ia32_attr_t *attr = get_ia32_attr(node);
418 return attr->data.imm_tp;
422 * Gets the supported addrmode of an ia32 node
424 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
425 ia32_attr_t *attr = get_ia32_attr(node);
426 return attr->data.am_support;
430 * Sets the supported addrmode of an ia32 node
432 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
433 ia32_attr_t *attr = get_ia32_attr(node);
434 attr->data.am_support = am_tp;
438 * Gets the addrmode flavour of an ia32 node
440 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
441 ia32_attr_t *attr = get_ia32_attr(node);
442 return attr->data.am_flavour;
446 * Sets the addrmode flavour of an ia32 node
448 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
449 ia32_attr_t *attr = get_ia32_attr(node);
450 attr->data.am_flavour = am_flavour;
454 * Gets the addressmode offset as int.
456 int get_ia32_am_offs_int(const ir_node *node) {
457 ia32_attr_t *attr = get_ia32_attr(node);
458 return attr->am_offs;
462 * Sets the addressmode offset from an int.
464 void set_ia32_am_offs_int(ir_node *node, int offset) {
465 ia32_attr_t *attr = get_ia32_attr(node);
466 attr->am_offs = offset;
469 void add_ia32_am_offs_int(ir_node *node, int offset) {
470 ia32_attr_t *attr = get_ia32_attr(node);
471 attr->am_offs += offset;
475 * Returns the symconst entity associated to addrmode.
477 ir_entity *get_ia32_am_sc(const ir_node *node) {
478 ia32_attr_t *attr = get_ia32_attr(node);
483 * Sets the symconst entity associated to addrmode.
485 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
486 ia32_attr_t *attr = get_ia32_attr(node);
487 attr->am_sc = entity;
491 * Sets the sign bit for address mode symconst.
493 void set_ia32_am_sc_sign(ir_node *node) {
494 ia32_attr_t *attr = get_ia32_attr(node);
495 attr->data.am_sc_sign = 1;
499 * Clears the sign bit for address mode symconst.
501 void clear_ia32_am_sc_sign(ir_node *node) {
502 ia32_attr_t *attr = get_ia32_attr(node);
503 attr->data.am_sc_sign = 0;
507 * Returns the sign bit for address mode symconst.
509 int is_ia32_am_sc_sign(const ir_node *node) {
510 ia32_attr_t *attr = get_ia32_attr(node);
511 return attr->data.am_sc_sign;
515 * Gets the addr mode const.
517 int get_ia32_am_scale(const ir_node *node) {
518 ia32_attr_t *attr = get_ia32_attr(node);
519 return attr->data.am_scale;
523 * Sets the index register scale for addrmode.
525 void set_ia32_am_scale(ir_node *node, int scale) {
526 ia32_attr_t *attr = get_ia32_attr(node);
527 attr->data.am_scale = scale;
531 * Return the tarval of an immediate operation or NULL in case of SymConst
533 tarval *get_ia32_Immop_tarval(const ir_node *node) {
534 ia32_attr_t *attr = get_ia32_attr(node);
535 assert(attr->data.imm_tp == ia32_ImmConst);
536 return attr->cnst_val.tv;
540 * Sets the attributes of an immediate operation to the specified tarval
542 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
543 ia32_attr_t *attr = get_ia32_attr(node);
544 attr->data.imm_tp = ia32_ImmConst;
545 attr->cnst_val.tv = tv;
548 void set_ia32_Immop_symconst(ir_node *node, ir_entity *entity) {
549 ia32_attr_t *attr = get_ia32_attr(node);
550 attr->data.imm_tp = ia32_ImmSymConst;
551 attr->cnst_val.sc = entity;
554 ir_entity *get_ia32_Immop_symconst(const ir_node *node) {
555 ia32_attr_t *attr = get_ia32_attr(node);
556 assert(attr->data.imm_tp == ia32_ImmSymConst);
557 return attr->cnst_val.sc;
561 * Sets the uses_frame flag.
563 void set_ia32_use_frame(ir_node *node) {
564 ia32_attr_t *attr = get_ia32_attr(node);
565 attr->data.use_frame = 1;
569 * Clears the uses_frame flag.
571 void clear_ia32_use_frame(ir_node *node) {
572 ia32_attr_t *attr = get_ia32_attr(node);
573 attr->data.use_frame = 0;
577 * Gets the uses_frame flag.
579 int is_ia32_use_frame(const ir_node *node) {
580 ia32_attr_t *attr = get_ia32_attr(node);
581 return attr->data.use_frame;
585 * Sets node to commutative.
587 void set_ia32_commutative(ir_node *node) {
588 ia32_attr_t *attr = get_ia32_attr(node);
589 attr->data.is_commutative = 1;
593 * Sets node to non-commutative.
595 void clear_ia32_commutative(ir_node *node) {
596 ia32_attr_t *attr = get_ia32_attr(node);
597 attr->data.is_commutative = 0;
601 * Checks if node is commutative.
603 int is_ia32_commutative(const ir_node *node) {
604 ia32_attr_t *attr = get_ia32_attr(node);
605 return attr->data.is_commutative;
611 void set_ia32_emit_cl(ir_node *node) {
612 ia32_attr_t *attr = get_ia32_attr(node);
613 attr->data.emit_cl = 1;
617 * Clears node emit_cl.
619 void clear_ia32_emit_cl(ir_node *node) {
620 ia32_attr_t *attr = get_ia32_attr(node);
621 attr->data.emit_cl = 0;
625 * Checks if node needs %cl.
627 int is_ia32_emit_cl(const ir_node *node) {
628 ia32_attr_t *attr = get_ia32_attr(node);
629 return attr->data.emit_cl;
635 void set_ia32_got_lea(ir_node *node) {
636 ia32_attr_t *attr = get_ia32_attr(node);
637 attr->data.got_lea = 1;
641 * Clears node got_lea.
643 void clear_ia32_got_lea(ir_node *node) {
644 ia32_attr_t *attr = get_ia32_attr(node);
645 attr->data.got_lea = 0;
649 * Checks if node got lea.
651 int is_ia32_got_lea(const ir_node *node) {
652 ia32_attr_t *attr = get_ia32_attr(node);
653 return attr->data.got_lea;
656 void set_ia32_need_stackent(ir_node *node) {
657 ia32_attr_t *attr = get_ia32_attr(node);
658 attr->data.need_stackent = 1;
661 void clear_ia32_need_stackent(ir_node *node) {
662 ia32_attr_t *attr = get_ia32_attr(node);
663 attr->data.need_stackent = 0;
666 int is_ia32_need_stackent(const ir_node *node) {
667 ia32_attr_t *attr = get_ia32_attr(node);
668 return attr->data.need_stackent;
672 * Gets the mode of the stored/loaded value (only set for Store/Load)
674 ir_mode *get_ia32_ls_mode(const ir_node *node) {
675 ia32_attr_t *attr = get_ia32_attr(node);
676 return attr->ls_mode;
680 * Sets the mode of the stored/loaded value (only set for Store/Load)
682 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
683 ia32_attr_t *attr = get_ia32_attr(node);
684 attr->ls_mode = mode;
688 * Gets the frame entity assigned to this node.
690 ir_entity *get_ia32_frame_ent(const ir_node *node) {
691 ia32_attr_t *attr = get_ia32_attr(node);
692 return attr->frame_ent;
696 * Sets the frame entity for this node.
698 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
699 ia32_attr_t *attr = get_ia32_attr(node);
700 attr->frame_ent = ent;
702 set_ia32_use_frame(node);
704 clear_ia32_use_frame(node);
709 * Gets the instruction latency.
711 unsigned get_ia32_latency(const ir_node *node) {
712 ia32_attr_t *attr = get_ia32_attr(node);
713 return attr->latency;
717 * Sets the instruction latency.
719 void set_ia32_latency(ir_node *node, unsigned latency) {
720 ia32_attr_t *attr = get_ia32_attr(node);
721 attr->latency = latency;
725 * Returns the argument register requirements of an ia32 node.
727 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
728 ia32_attr_t *attr = get_ia32_attr(node);
733 * Sets the argument register requirements of an ia32 node.
735 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
736 ia32_attr_t *attr = get_ia32_attr(node);
741 * Returns the result register requirements of an ia32 node.
743 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
744 ia32_attr_t *attr = get_ia32_attr(node);
745 return attr->out_req;
749 * Sets the result register requirements of an ia32 node.
751 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
752 ia32_attr_t *attr = get_ia32_attr(node);
753 attr->out_req = reqs;
757 * Returns the argument register requirement at position pos of an ia32 node.
759 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
760 ia32_attr_t *attr = get_ia32_attr(node);
761 if(attr->in_req == NULL)
762 return arch_no_register_req;
764 return attr->in_req[pos];
768 * Returns the result register requirement at position pos of an ia32 node.
770 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
771 ia32_attr_t *attr = get_ia32_attr(node);
772 if(attr->out_req == NULL)
773 return arch_no_register_req;
775 return attr->out_req[pos];
779 * Sets the OUT register requirements at position pos.
781 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
782 ia32_attr_t *attr = get_ia32_attr(node);
783 attr->out_req[pos] = req;
787 * Sets the IN register requirements at position pos.
789 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
790 ia32_attr_t *attr = get_ia32_attr(node);
791 attr->in_req[pos] = req;
795 * Returns the register flag of an ia32 node.
797 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
798 ia32_attr_t *attr = get_ia32_attr(node);
799 return attr->data.flags;
803 * Sets the register flag of an ia32 node.
805 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
806 ia32_attr_t *attr = get_ia32_attr(node);
807 attr->data.flags = flags;
811 * Returns the result register slots of an ia32 node.
813 const arch_register_t **get_ia32_slots(const ir_node *node) {
814 ia32_attr_t *attr = get_ia32_attr(node);
819 * Sets the number of results.
821 void set_ia32_n_res(ir_node *node, int n_res) {
822 ia32_attr_t *attr = get_ia32_attr(node);
823 attr->data.n_res = n_res;
827 * Returns the number of results.
829 int get_ia32_n_res(const ir_node *node) {
830 ia32_attr_t *attr = get_ia32_attr(node);
831 return attr->data.n_res;
835 * Returns the flavour of an ia32 node,
837 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
838 ia32_attr_t *attr = get_ia32_attr(node);
839 return attr->data.op_flav;
843 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
845 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
846 ia32_attr_t *attr = get_ia32_attr(node);
847 attr->data.op_flav = op_flav;
851 * Returns the projnum code.
853 pn_Cmp get_ia32_pncode(const ir_node *node) {
854 ia32_attr_t *attr = get_ia32_attr(node);
855 return attr->pn_code;
859 * Sets the projnum code
861 void set_ia32_pncode(ir_node *node, pn_Cmp code) {
862 ia32_attr_t *attr = get_ia32_attr(node);
863 attr->pn_code = code;
867 * Sets the flags for the n'th out.
869 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
870 ia32_attr_t *attr = get_ia32_attr(node);
871 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
872 attr->out_flags[pos] = flags;
876 * Gets the flags for the n'th out.
878 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
879 ia32_attr_t *attr = get_ia32_attr(node);
880 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
884 * Get the list of available execution units.
886 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
887 ia32_attr_t *attr = get_ia32_attr(node);
888 return attr->exec_units;
894 * Returns the name of the original ir node.
896 const char *get_ia32_orig_node(const ir_node *node) {
897 ia32_attr_t *attr = get_ia32_attr(node);
898 return attr->orig_node;
902 * Sets the name of the original ir node.
904 void set_ia32_orig_node(ir_node *node, const char *name) {
905 ia32_attr_t *attr = get_ia32_attr(node);
906 attr->orig_node = name;
911 /******************************************************************************************************
913 * (_) | | | | | | / _| | | (_)
914 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
915 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
916 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
917 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
920 ******************************************************************************************************/
923 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
925 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
926 ia32_immop_type_t immop_type = get_ia32_immop_type(from);
928 if(immop_type == ia32_ImmConst) {
929 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
930 } else if(immop_type == ia32_ImmSymConst) {
931 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
933 ia32_attr_t *attr = get_ia32_attr(node);
934 assert(immop_type == ia32_ImmNone);
935 attr->data.imm_tp = ia32_ImmNone;
940 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
942 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
943 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
945 switch (get_irn_opcode(cnst)) {
947 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
950 assert(get_SymConst_kind(cnst) == symconst_addr_ent);
951 set_ia32_Immop_symconst(ia32_cnst, get_SymConst_entity(cnst));
954 assert(0 && "Unknown Const NYI");
957 assert(0 && "Cannot create ia32_Const for this opcode");
961 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
962 if(mode_is_reference(get_tarval_mode(tv))) {
963 if(tarval_is_null(tv)) {
964 tv = get_tarval_null(mode_Iu);
966 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
969 tv = tarval_convert_to(tv, mode_Iu);
972 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
974 set_ia32_Immop_tarval(ia32_cnst, tv);
979 * Sets the AddrMode(S|D) attribute
981 void set_ia32_AddrMode(ir_node *node, char direction) {
982 ia32_attr_t *attr = get_ia32_attr(node);
986 attr->data.tp = ia32_AddrModeD;
989 attr->data.tp = ia32_AddrModeS;
992 assert(0 && "wrong AM type");
997 * Returns whether or not the node is an immediate operation with Const.
999 int is_ia32_ImmConst(const ir_node *node) {
1000 ia32_attr_t *attr = get_ia32_attr(node);
1001 return (attr->data.imm_tp == ia32_ImmConst);
1005 * Returns whether or not the node is an immediate operation with SymConst.
1007 int is_ia32_ImmSymConst(const ir_node *node) {
1008 ia32_attr_t *attr = get_ia32_attr(node);
1009 return (attr->data.imm_tp == ia32_ImmSymConst);
1013 * Returns whether or not the node is an AddrModeS node.
1015 int is_ia32_AddrModeS(const ir_node *node) {
1016 ia32_attr_t *attr = get_ia32_attr(node);
1017 return (attr->data.tp == ia32_AddrModeS);
1021 * Returns whether or not the node is an AddrModeD node.
1023 int is_ia32_AddrModeD(const ir_node *node) {
1024 ia32_attr_t *attr = get_ia32_attr(node);
1025 return (attr->data.tp == ia32_AddrModeD);
1029 * Checks if node is a Load or xLoad/vfLoad.
1031 int is_ia32_Ld(const ir_node *node) {
1032 int op = get_ia32_irn_opcode(node);
1033 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1037 * Checks if node is a Store or xStore/vfStore.
1039 int is_ia32_St(const ir_node *node) {
1040 int op = get_ia32_irn_opcode(node);
1041 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1045 * Checks if node is a Const or xConst/vfConst.
1047 int is_ia32_Cnst(const ir_node *node) {
1048 int op = get_ia32_irn_opcode(node);
1049 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1053 * Returns the name of the OUT register at position pos.
1055 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1056 ia32_attr_t *attr = get_ia32_attr(node);
1058 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1059 assert(attr->slots[pos] && "No register assigned");
1061 return arch_register_get_name(attr->slots[pos]);
1065 * Returns the index of the OUT register at position pos within its register class.
1067 int get_ia32_out_regnr(const ir_node *node, int pos) {
1068 ia32_attr_t *attr = get_ia32_attr(node);
1070 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1071 assert(attr->slots[pos] && "No register assigned");
1073 return arch_register_get_index(attr->slots[pos]);
1077 * Returns the OUT register at position pos.
1079 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1080 ia32_attr_t *attr = get_ia32_attr(node);
1082 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1083 assert(attr->slots[pos] && "No register assigned");
1085 return attr->slots[pos];
1089 * Initializes the nodes attributes.
1091 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1092 const arch_register_req_t **in_reqs,
1093 const arch_register_req_t **out_reqs,
1094 const be_execution_unit_t ***execution_units,
1095 int n_res, unsigned latency)
1097 ia32_attr_t *attr = get_ia32_attr(node);
1099 set_ia32_flags(node, flags);
1100 set_ia32_in_req_all(node, in_reqs);
1101 set_ia32_out_req_all(node, out_reqs);
1102 set_ia32_latency(node, latency);
1103 set_ia32_n_res(node, n_res);
1105 attr->exec_units = execution_units;
1107 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1108 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1110 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1113 ir_node *get_ia32_result_proj(const ir_node *node)
1115 const ir_edge_t *edge;
1117 foreach_out_edge(node, edge) {
1118 ir_node *proj = get_edge_src_irn(edge);
1119 if(get_Proj_proj(proj) == 0) {
1126 /***************************************************************************************
1129 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1130 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1131 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1132 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1134 ***************************************************************************************/
1136 /* default compare operation to compare attributes */
1137 int ia32_compare_attr(ia32_attr_t *a, ia32_attr_t *b) {
1138 if (a->data.tp != b->data.tp
1139 || a->data.imm_tp != b->data.imm_tp)
1142 if (a->data.imm_tp == ia32_ImmConst
1143 && a->cnst_val.tv != b->cnst_val.tv)
1146 if (a->data.imm_tp == ia32_ImmSymConst
1147 && a->cnst_val.sc != b->cnst_val.sc)
1150 if (a->data.am_flavour != b->data.am_flavour
1151 || a->data.am_scale != b->data.am_scale
1152 || a->data.offs_sign != b->data.offs_sign
1153 || a->data.am_sc_sign != b->data.am_sc_sign
1154 || a->am_offs != b->am_offs
1155 || a->am_sc != b->am_sc
1156 || a->ls_mode != b->ls_mode)
1159 if (a->data.use_frame != b->data.use_frame
1160 || a->data.use_frame != b->data.use_frame
1161 || a->frame_ent != b->frame_ent)
1164 if(a->pn_code != b->pn_code)
1167 if (a->data.tp != b->data.tp
1168 || a->data.op_flav != b->data.op_flav)
1174 /* copies the ia32 attributes */
1175 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1176 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1177 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1179 /* copy the attributes */
1180 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1182 /* copy out flags */
1183 attr_new->out_flags =
1184 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1188 * Registers the ia32_copy_attr function for all ia32 opcodes.
1190 void ia32_register_copy_attr_func(void) {
1191 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1193 for (i = f; i < l; i++) {
1194 ir_op *op = get_irp_opcode(i);
1195 op->ops.copy_attr = ia32_copy_attr;
1199 /* Include the generated constructor functions */
1200 #include "gen_ia32_new_nodes.c.inl"