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)) {
205 if(is_ia32_ImmSymConst(n)) {
206 ident *id = get_ia32_Immop_symconst(n);
207 fprintf(F, "[SymC %s]", get_id_str(id));
210 tarval *tv = get_ia32_Immop_tarval(n);
212 tarval_snprintf(buf, sizeof(buf), tv);
213 fprintf(F, "[%s]", buf);
217 if (! is_ia32_Lea(n)) {
218 if (is_ia32_AddrModeS(n)) {
219 fprintf(F, "[AM S] ");
221 else if (is_ia32_AddrModeD(n)) {
222 fprintf(F, "[AM D] ");
228 case dump_node_info_txt:
229 n_res = get_ia32_n_res(n);
230 fprintf(F, "=== IA32 attr begin ===\n");
232 /* dump IN requirements */
233 if (get_irn_arity(n) > 0) {
234 reqs = get_ia32_in_req_all(n);
235 dump_reg_req(F, n, reqs, 0);
238 /* dump OUT requirements */
240 reqs = get_ia32_out_req_all(n);
241 dump_reg_req(F, n, reqs, 1);
244 /* dump assigned registers */
245 slots = get_ia32_slots(n);
246 if (slots && n_res > 0) {
247 for (i = 0; i < n_res; i++) {
248 const arch_register_t *reg;
250 /* retrieve "real" x87 register */
251 if (ia32_has_x87_register(n))
252 reg = get_ia32_attr(n)->x87[i + 2];
256 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
263 switch (get_ia32_op_type(n)) {
265 fprintf(F, "Normal");
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 if(get_ia32_am_offs_int(n) != 0) {
342 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
345 /* dump AM symconst */
346 if(get_ia32_am_sc(n) != NULL) {
347 fprintf(F, "AM symconst = %s\n", get_id_str(get_ia32_am_sc(n)));
351 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
354 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
355 fprintf(F, "pn_code = %d (%s, unsigned)\n", get_ia32_pncode(n),
356 get_pnc_string(get_ia32_pncode(n) & ~ia32_pn_Cmp_Unsigned));
358 fprintf(F, "pn_code = %d (%s)\n", get_ia32_pncode(n),
359 get_pnc_string(get_ia32_pncode(n)));
363 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
366 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
369 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
372 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
375 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
378 fprintf(F, "got reload = %d\n", is_ia32_got_reload(n));
381 fprintf(F, "latency = %d\n", get_ia32_latency(n));
384 fprintf(F, "flags =");
385 flags = get_ia32_flags(n);
386 if (flags == arch_irn_flags_none) {
390 if (flags & arch_irn_flags_dont_spill) {
391 fprintf(F, " unspillable");
393 if (flags & arch_irn_flags_rematerializable) {
394 fprintf(F, " remat");
396 if (flags & arch_irn_flags_ignore) {
397 fprintf(F, " ignore");
399 if (flags & arch_irn_flags_modify_sp) {
400 fprintf(F, " modify_sp");
403 fprintf(F, " (%d)\n", flags);
405 /* dump frame entity */
406 fprintf(F, "frame entity = ");
407 if (get_ia32_frame_ent(n)) {
408 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
416 fprintf(F, "ls_mode = ");
417 if (get_ia32_ls_mode(n)) {
418 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
426 /* dump original ir node name */
427 fprintf(F, "orig node = ");
428 if (get_ia32_orig_node(n)) {
429 fprintf(F, "%s", get_ia32_orig_node(n));
437 fprintf(F, "=== IA32 attr end ===\n");
438 /* end of: case dump_node_info_txt */
447 /***************************************************************************************************
449 * | | | | | | / / | | | | | | | |
450 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
451 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
452 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
453 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
456 ***************************************************************************************************/
459 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
460 * Firm was made by people hating const :-(
462 ia32_attr_t *get_ia32_attr(const ir_node *node) {
463 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
464 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
468 * Gets the type of an ia32 node.
470 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
471 ia32_attr_t *attr = get_ia32_attr(node);
472 return attr->data.tp;
476 * Sets the type of an ia32 node.
478 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
479 ia32_attr_t *attr = get_ia32_attr(node);
484 * Gets the immediate op type of an ia32 node.
486 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
487 ia32_attr_t *attr = get_ia32_attr(node);
488 return attr->data.imm_tp;
492 * Gets the supported addrmode of an ia32 node
494 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
495 ia32_attr_t *attr = get_ia32_attr(node);
496 return attr->data.am_support;
500 * Sets the supported addrmode of an ia32 node
502 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
503 ia32_attr_t *attr = get_ia32_attr(node);
504 attr->data.am_support = am_tp;
508 * Gets the addrmode flavour of an ia32 node
510 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
511 ia32_attr_t *attr = get_ia32_attr(node);
512 return attr->data.am_flavour;
516 * Sets the addrmode flavour of an ia32 node
518 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
519 ia32_attr_t *attr = get_ia32_attr(node);
520 attr->data.am_flavour = am_flavour;
524 * Gets the addressmode offset as int.
526 int get_ia32_am_offs_int(const ir_node *node) {
527 ia32_attr_t *attr = get_ia32_attr(node);
528 return attr->am_offs;
532 * Sets the addressmode offset from an int.
534 void set_ia32_am_offs_int(ir_node *node, int offset) {
535 ia32_attr_t *attr = get_ia32_attr(node);
536 attr->am_offs = offset;
539 void add_ia32_am_offs_int(ir_node *node, int offset) {
540 ia32_attr_t *attr = get_ia32_attr(node);
541 attr->am_offs += offset;
545 * Returns the symconst ident associated to addrmode.
547 ident *get_ia32_am_sc(const ir_node *node) {
548 ia32_attr_t *attr = get_ia32_attr(node);
553 * Sets the symconst ident associated to addrmode.
555 void set_ia32_am_sc(ir_node *node, ident *sc) {
556 ia32_attr_t *attr = get_ia32_attr(node);
561 * Sets the sign bit for address mode symconst.
563 void set_ia32_am_sc_sign(ir_node *node) {
564 ia32_attr_t *attr = get_ia32_attr(node);
565 attr->data.am_sc_sign = 1;
569 * Clears the sign bit for address mode symconst.
571 void clear_ia32_am_sc_sign(ir_node *node) {
572 ia32_attr_t *attr = get_ia32_attr(node);
573 attr->data.am_sc_sign = 0;
577 * Returns the sign bit for address mode symconst.
579 int is_ia32_am_sc_sign(const ir_node *node) {
580 ia32_attr_t *attr = get_ia32_attr(node);
581 return attr->data.am_sc_sign;
585 * Gets the addr mode const.
587 int get_ia32_am_scale(const ir_node *node) {
588 ia32_attr_t *attr = get_ia32_attr(node);
589 return attr->data.am_scale;
593 * Sets the index register scale for addrmode.
595 void set_ia32_am_scale(ir_node *node, int scale) {
596 ia32_attr_t *attr = get_ia32_attr(node);
597 attr->data.am_scale = scale;
601 * Return the tarval of an immediate operation or NULL in case of SymConst
603 tarval *get_ia32_Immop_tarval(const ir_node *node) {
604 ia32_attr_t *attr = get_ia32_attr(node);
605 assert(attr->data.imm_tp == ia32_ImmConst);
606 return attr->cnst_val.tv;
610 * Sets the attributes of an immediate operation to the specified tarval
612 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
613 ia32_attr_t *attr = get_ia32_attr(node);
614 attr->data.imm_tp = ia32_ImmConst;
615 attr->cnst_val.tv = tv;
618 void set_ia32_Immop_symconst(ir_node *node, ident *ident) {
619 ia32_attr_t *attr = get_ia32_attr(node);
620 attr->data.imm_tp = ia32_ImmSymConst;
621 attr->cnst_val.sc = ident;
624 ident *get_ia32_Immop_symconst(const ir_node *node) {
625 ia32_attr_t *attr = get_ia32_attr(node);
626 assert(attr->data.imm_tp == ia32_ImmSymConst);
627 return attr->cnst_val.sc;
631 * Sets the uses_frame flag.
633 void set_ia32_use_frame(ir_node *node) {
634 ia32_attr_t *attr = get_ia32_attr(node);
635 attr->data.use_frame = 1;
639 * Clears the uses_frame flag.
641 void clear_ia32_use_frame(ir_node *node) {
642 ia32_attr_t *attr = get_ia32_attr(node);
643 attr->data.use_frame = 0;
647 * Gets the uses_frame flag.
649 int is_ia32_use_frame(const ir_node *node) {
650 ia32_attr_t *attr = get_ia32_attr(node);
651 return attr->data.use_frame;
655 * Sets node to commutative.
657 void set_ia32_commutative(ir_node *node) {
658 ia32_attr_t *attr = get_ia32_attr(node);
659 attr->data.is_commutative = 1;
663 * Sets node to non-commutative.
665 void clear_ia32_commutative(ir_node *node) {
666 ia32_attr_t *attr = get_ia32_attr(node);
667 attr->data.is_commutative = 0;
671 * Checks if node is commutative.
673 int is_ia32_commutative(const ir_node *node) {
674 ia32_attr_t *attr = get_ia32_attr(node);
675 return attr->data.is_commutative;
681 void set_ia32_emit_cl(ir_node *node) {
682 ia32_attr_t *attr = get_ia32_attr(node);
683 attr->data.emit_cl = 1;
687 * Clears node emit_cl.
689 void clear_ia32_emit_cl(ir_node *node) {
690 ia32_attr_t *attr = get_ia32_attr(node);
691 attr->data.emit_cl = 0;
695 * Checks if node needs %cl.
697 int is_ia32_emit_cl(const ir_node *node) {
698 ia32_attr_t *attr = get_ia32_attr(node);
699 return attr->data.emit_cl;
705 void set_ia32_got_lea(ir_node *node) {
706 ia32_attr_t *attr = get_ia32_attr(node);
707 attr->data.got_lea = 1;
711 * Clears node got_lea.
713 void clear_ia32_got_lea(ir_node *node) {
714 ia32_attr_t *attr = get_ia32_attr(node);
715 attr->data.got_lea = 0;
719 * Checks if node got lea.
721 int is_ia32_got_lea(const ir_node *node) {
722 ia32_attr_t *attr = get_ia32_attr(node);
723 return attr->data.got_lea;
727 * Sets node got_reload.
729 void set_ia32_got_reload(ir_node *node) {
730 ia32_attr_t *attr = get_ia32_attr(node);
731 attr->data.got_reload = 1;
735 * Clears node got_reload.
737 void clear_ia32_got_reload(ir_node *node) {
738 ia32_attr_t *attr = get_ia32_attr(node);
739 attr->data.got_reload = 0;
743 * Checks if node got reload.
745 int is_ia32_got_reload(const ir_node *node) {
746 ia32_attr_t *attr = get_ia32_attr(node);
747 return attr->data.got_reload;
751 * Gets the mode of the stored/loaded value (only set for Store/Load)
753 ir_mode *get_ia32_ls_mode(const ir_node *node) {
754 ia32_attr_t *attr = get_ia32_attr(node);
755 return attr->ls_mode;
759 * Sets the mode of the stored/loaded value (only set for Store/Load)
761 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
762 ia32_attr_t *attr = get_ia32_attr(node);
763 attr->ls_mode = mode;
767 * Gets the frame entity assigned to this node.
769 ir_entity *get_ia32_frame_ent(const ir_node *node) {
770 ia32_attr_t *attr = get_ia32_attr(node);
771 return attr->frame_ent;
775 * Sets the frame entity for this node.
777 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
778 ia32_attr_t *attr = get_ia32_attr(node);
779 attr->frame_ent = ent;
781 set_ia32_use_frame(node);
783 clear_ia32_use_frame(node);
788 * Gets the instruction latency.
790 unsigned get_ia32_latency(const ir_node *node) {
791 ia32_attr_t *attr = get_ia32_attr(node);
792 return attr->latency;
796 * Sets the instruction latency.
798 void set_ia32_latency(ir_node *node, unsigned latency) {
799 ia32_attr_t *attr = get_ia32_attr(node);
800 attr->latency = latency;
804 * Returns the argument register requirements of an ia32 node.
806 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
807 ia32_attr_t *attr = get_ia32_attr(node);
812 * Sets the argument register requirements of an ia32 node.
814 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
815 ia32_attr_t *attr = get_ia32_attr(node);
820 * Returns the result register requirements of an ia32 node.
822 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
823 ia32_attr_t *attr = get_ia32_attr(node);
824 return attr->out_req;
828 * Sets the result register requirements of an ia32 node.
830 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
831 ia32_attr_t *attr = get_ia32_attr(node);
832 attr->out_req = reqs;
836 * Returns the argument register requirement at position pos of an ia32 node.
838 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
839 ia32_attr_t *attr = get_ia32_attr(node);
840 return attr->in_req != NULL ? attr->in_req[pos] : NULL;
844 * Returns the result register requirement at position pos of an ia32 node.
846 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
847 ia32_attr_t *attr = get_ia32_attr(node);
848 return attr->out_req != NULL ? attr->out_req[pos] : NULL;
852 * Sets the OUT register requirements at position pos.
854 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
855 ia32_attr_t *attr = get_ia32_attr(node);
856 attr->out_req[pos] = req;
860 * Sets the IN register requirements at position pos.
862 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
863 ia32_attr_t *attr = get_ia32_attr(node);
864 attr->in_req[pos] = req;
868 * Returns the register flag of an ia32 node.
870 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
871 ia32_attr_t *attr = get_ia32_attr(node);
872 return attr->data.flags;
876 * Sets the register flag of an ia32 node.
878 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
879 ia32_attr_t *attr = get_ia32_attr(node);
880 attr->data.flags = flags;
884 * Returns the result register slots of an ia32 node.
886 const arch_register_t **get_ia32_slots(const ir_node *node) {
887 ia32_attr_t *attr = get_ia32_attr(node);
892 * Sets the number of results.
894 void set_ia32_n_res(ir_node *node, int n_res) {
895 ia32_attr_t *attr = get_ia32_attr(node);
896 attr->data.n_res = n_res;
900 * Returns the number of results.
902 int get_ia32_n_res(const ir_node *node) {
903 ia32_attr_t *attr = get_ia32_attr(node);
904 return attr->data.n_res;
908 * Returns the flavour of an ia32 node,
910 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
911 ia32_attr_t *attr = get_ia32_attr(node);
912 return attr->data.op_flav;
916 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
918 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
919 ia32_attr_t *attr = get_ia32_attr(node);
920 attr->data.op_flav = op_flav;
924 * Returns the projnum code.
926 pn_Cmp get_ia32_pncode(const ir_node *node) {
927 ia32_attr_t *attr = get_ia32_attr(node);
928 return attr->pn_code;
932 * Sets the projnum code
934 void set_ia32_pncode(ir_node *node, pn_Cmp code) {
935 ia32_attr_t *attr = get_ia32_attr(node);
936 attr->pn_code = code;
940 * Sets the flags for the n'th out.
942 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
943 ia32_attr_t *attr = get_ia32_attr(node);
944 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
945 attr->out_flags[pos] = flags;
949 * Gets the flags for the n'th out.
951 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
952 ia32_attr_t *attr = get_ia32_attr(node);
953 return pos < (int)attr->data.n_res ? attr->out_flags[pos] : arch_irn_flags_none;
957 * Get the list of available execution units.
959 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
960 ia32_attr_t *attr = get_ia32_attr(node);
961 return attr->exec_units;
967 * Returns the name of the original ir node.
969 const char *get_ia32_orig_node(const ir_node *node) {
970 ia32_attr_t *attr = get_ia32_attr(node);
971 return attr->orig_node;
975 * Sets the name of the original ir node.
977 void set_ia32_orig_node(ir_node *node, const char *name) {
978 ia32_attr_t *attr = get_ia32_attr(node);
979 attr->orig_node = name;
984 /******************************************************************************************************
986 * (_) | | | | | | / _| | | (_)
987 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
988 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
989 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
990 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
993 ******************************************************************************************************/
996 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
998 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
999 ia32_immop_type_t immop_type = get_ia32_immop_type(from);
1001 if(immop_type == ia32_ImmConst) {
1002 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
1003 } else if(immop_type == ia32_ImmSymConst) {
1004 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
1006 ia32_attr_t *attr = get_ia32_attr(node);
1007 assert(immop_type == ia32_ImmNone);
1008 attr->data.imm_tp = ia32_ImmNone;
1013 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1015 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1016 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1018 switch (get_irn_opcode(cnst)) {
1020 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
1023 set_ia32_Immop_symconst(ia32_cnst, get_sc_ident(cnst));
1026 assert(0 && "Unknown Const NYI");
1029 assert(0 && "Cannot create ia32_Const for this opcode");
1033 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
1034 if(mode_is_reference(get_tarval_mode(tv))) {
1035 if(tarval_is_null(tv)) {
1036 tv = get_tarval_null(mode_Iu);
1038 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
1041 tv = tarval_convert_to(tv, mode_Iu);
1044 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
1046 set_ia32_Immop_tarval(ia32_cnst, tv);
1051 * Sets the AddrMode(S|D) attribute
1053 void set_ia32_AddrMode(ir_node *node, char direction) {
1054 ia32_attr_t *attr = get_ia32_attr(node);
1056 switch (direction) {
1058 attr->data.tp = ia32_AddrModeD;
1061 attr->data.tp = ia32_AddrModeS;
1064 assert(0 && "wrong AM type");
1069 * Returns whether or not the node is an immediate operation with Const.
1071 int is_ia32_ImmConst(const ir_node *node) {
1072 ia32_attr_t *attr = get_ia32_attr(node);
1073 return (attr->data.imm_tp == ia32_ImmConst);
1077 * Returns whether or not the node is an immediate operation with SymConst.
1079 int is_ia32_ImmSymConst(const ir_node *node) {
1080 ia32_attr_t *attr = get_ia32_attr(node);
1081 return (attr->data.imm_tp == ia32_ImmSymConst);
1085 * Returns whether or not the node is an AddrModeS node.
1087 int is_ia32_AddrModeS(const ir_node *node) {
1088 ia32_attr_t *attr = get_ia32_attr(node);
1089 return (attr->data.tp == ia32_AddrModeS);
1093 * Returns whether or not the node is an AddrModeD node.
1095 int is_ia32_AddrModeD(const ir_node *node) {
1096 ia32_attr_t *attr = get_ia32_attr(node);
1097 return (attr->data.tp == ia32_AddrModeD);
1101 * Checks if node is a Load or xLoad/vfLoad.
1103 int is_ia32_Ld(const ir_node *node) {
1104 int op = get_ia32_irn_opcode(node);
1105 return op == iro_ia32_Load || op == iro_ia32_xLoad || op == iro_ia32_vfld || op == iro_ia32_fld;
1109 * Checks if node is a Store or xStore/vfStore.
1111 int is_ia32_St(const ir_node *node) {
1112 int op = get_ia32_irn_opcode(node);
1113 return op == iro_ia32_Store || op == iro_ia32_xStore || op == iro_ia32_vfst || op == iro_ia32_fst || op == iro_ia32_fstp;
1117 * Checks if node is a Const or xConst/vfConst.
1119 int is_ia32_Cnst(const ir_node *node) {
1120 int op = get_ia32_irn_opcode(node);
1121 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1125 * Returns the name of the OUT register at position pos.
1127 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1128 ia32_attr_t *attr = get_ia32_attr(node);
1130 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1131 assert(attr->slots[pos] && "No register assigned");
1133 return arch_register_get_name(attr->slots[pos]);
1137 * Returns the index of the OUT register at position pos within its register class.
1139 int get_ia32_out_regnr(const ir_node *node, int pos) {
1140 ia32_attr_t *attr = get_ia32_attr(node);
1142 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1143 assert(attr->slots[pos] && "No register assigned");
1145 return arch_register_get_index(attr->slots[pos]);
1149 * Returns the OUT register at position pos.
1151 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1152 ia32_attr_t *attr = get_ia32_attr(node);
1154 assert(pos < (int) attr->data.n_res && "Invalid OUT position.");
1155 assert(attr->slots[pos] && "No register assigned");
1157 return attr->slots[pos];
1161 * Initializes the nodes attributes.
1163 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1164 const ia32_register_req_t **out_reqs, const be_execution_unit_t ***execution_units,
1165 int n_res, unsigned latency)
1167 ia32_attr_t *attr = get_ia32_attr(node);
1169 set_ia32_flags(node, flags);
1170 set_ia32_in_req_all(node, in_reqs);
1171 set_ia32_out_req_all(node, out_reqs);
1172 set_ia32_latency(node, latency);
1173 set_ia32_n_res(node, n_res);
1175 attr->exec_units = execution_units;
1177 attr->out_flags = NEW_ARR_D(int, get_irg_obstack(get_irn_irg(node)), n_res);
1178 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1180 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1183 ir_node *get_ia32_result_proj(const ir_node *node)
1185 const ir_edge_t *edge;
1187 foreach_out_edge(node, edge) {
1188 ir_node *proj = get_edge_src_irn(edge);
1189 if(get_Proj_proj(proj) == 0) {
1196 /***************************************************************************************
1199 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1200 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1201 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1202 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1204 ***************************************************************************************/
1206 /* default compare operation to compare attributes */
1207 int ia32_compare_attr(ia32_attr_t *a, ia32_attr_t *b) {
1208 if (a->data.tp != b->data.tp
1209 || a->data.imm_tp != b->data.imm_tp)
1212 if (a->data.imm_tp == ia32_ImmConst
1213 && a->cnst_val.tv != b->cnst_val.tv)
1216 if (a->data.imm_tp == ia32_ImmSymConst
1217 && a->cnst_val.sc != b->cnst_val.sc)
1220 if (a->data.am_flavour != b->data.am_flavour
1221 || a->data.am_scale != b->data.am_scale
1222 || a->data.offs_sign != b->data.offs_sign
1223 || a->data.am_sc_sign != b->data.am_sc_sign
1224 || a->am_offs != b->am_offs
1225 || a->am_sc != b->am_sc
1226 || a->ls_mode != b->ls_mode)
1229 if (a->data.use_frame != b->data.use_frame
1230 || a->data.use_frame != b->data.use_frame
1231 || a->frame_ent != b->frame_ent)
1234 if(a->pn_code != b->pn_code)
1237 if (a->data.tp != b->data.tp
1238 || a->data.op_flav != b->data.op_flav)
1244 /* copies the ia32 attributes */
1245 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1246 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1247 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1249 /* copy the attributes */
1250 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1252 /* copy out flags */
1253 attr_new->out_flags =
1254 DUP_ARR_D(int, get_irg_obstack(get_irn_irg(new_node)), attr_old->out_flags);
1258 * Registers the ia32_copy_attr function for all ia32 opcodes.
1260 void ia32_register_copy_attr_func(void) {
1261 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1263 for (i = f; i < l; i++) {
1264 ir_op *op = get_irp_opcode(i);
1265 op->ops.copy_attr = ia32_copy_attr;
1269 /* Include the generated constructor functions */
1270 #include "gen_ia32_new_nodes.c.inl"