2 * This file implements the creation of the achitecture specific firm opcodes
3 * and the coresponding node constructors for the $arch assembler irg.
4 * @author Christian Wuerdig
21 #include "irgraph_t.h"
27 #include "firm_common_t.h"
31 #include "../bearch.h"
33 #include "ia32_nodes_attr.h"
34 #include "ia32_new_nodes.h"
35 #include "gen_ia32_regalloc_if.h"
37 #ifdef obstack_chunk_alloc
38 # undef obstack_chunk_alloc
39 # define obstack_chunk_alloc xmalloc
41 # define obstack_chunk_alloc xmalloc
42 # define obstack_chunk_free free
45 extern int obstack_printf(struct obstack *obst, char *fmt, ...);
48 * Returns the ident of a SymConst.
49 * @param symc The SymConst
50 * @return The ident of the SymConst
52 static ident *get_sc_ident(ir_node *symc) {
53 assert(get_irn_opcode(symc) == iro_SymConst && "need symconst to get ident");
55 switch (get_SymConst_kind(symc)) {
56 case symconst_addr_name:
57 return get_SymConst_name(symc);
59 case symconst_addr_ent:
60 return get_entity_ld_ident(get_SymConst_entity(symc));
63 assert(0 && "Unsupported SymConst");
71 /***********************************************************************************
74 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
75 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
76 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
77 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
80 ***********************************************************************************/
83 * Returns a string containing the names of all registers within the limited bitset
85 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
86 bitset_t *bs = bitset_alloca(req->cls->n_regs);
91 req->limited(NULL, bs);
93 for (i = 0; i < req->cls->n_regs; i++) {
94 if (bitset_is_set(bs, i)) {
95 cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
97 fprintf(stderr, "dumper problem, exiting\n");
113 * Dumps the register requirements for either in or out.
115 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
116 char *dir = inout ? "out" : "in";
117 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
118 char *buf = alloca(1024);
121 memset(buf, 0, 1024);
124 for (i = 0; i < max; i++) {
125 fprintf(F, "%sreq #%d =", dir, i);
127 if (reqs[i]->req.type == arch_register_req_type_none) {
131 if (reqs[i]->req.type & arch_register_req_type_normal) {
132 fprintf(F, " %s", reqs[i]->req.cls->name);
135 if (reqs[i]->req.type & arch_register_req_type_limited) {
136 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
139 if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
140 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
143 if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
144 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
153 fprintf(F, "%sreq = N/A\n", dir);
158 * Dumper interface for dumping ia32 nodes in vcg.
159 * @param n the node to dump
160 * @param F the output file
161 * @param reason indicates which kind of information should be dumped
162 * @return 0 on success or != 0 on failure
164 static int dump_node_ia32(ir_node *n, FILE *F, dump_reason_t reason) {
165 ir_mode *mode = NULL;
167 int i, n_res, am_flav, flags;
168 const ia32_register_req_t **reqs;
169 const arch_register_t **slots;
172 case dump_node_opcode_txt:
173 fprintf(F, "%s", get_irn_opname(n));
176 case dump_node_mode_txt:
177 mode = get_irn_mode(n);
179 if (is_ia32_Ld(n) || is_ia32_St(n)) {
180 mode = get_ia32_ls_mode(n);
183 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
186 case dump_node_nodeattr_txt:
187 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
188 char *pref = is_ia32_ImmSymConst(n) ? "SymC" : "";
190 fprintf(F, "[%s%s]", pref, get_ia32_cnst(n));
193 if (! is_ia32_Lea(n)) {
194 if (is_ia32_AddrModeS(n)) {
195 fprintf(F, "[AM S] ");
197 else if (is_ia32_AddrModeD(n)) {
198 fprintf(F, "[AM D] ");
204 case dump_node_info_txt:
205 n_res = get_ia32_n_res(n);
206 fprintf(F, "=== IA32 attr begin ===\n");
208 /* dump IN requirements */
209 if (get_irn_arity(n) > 0) {
210 reqs = get_ia32_in_req_all(n);
211 dump_reg_req(F, n, reqs, 0);
214 /* dump OUT requirements */
216 reqs = get_ia32_out_req_all(n);
217 dump_reg_req(F, n, reqs, 1);
220 /* dump assigned registers */
221 slots = get_ia32_slots(n);
222 if (slots && n_res > 0) {
223 for (i = 0; i < n_res; i++) {
224 fprintf(F, "reg #%d = %s\n", i, slots[i] ? slots[i]->name : "n/a");
231 switch (get_ia32_op_type(n)) {
233 fprintf(F, "Normal");
239 fprintf(F, "SymConst");
242 fprintf(F, "AM Dest (Load+Store)");
245 fprintf(F, "AM Source (Load)");
248 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
254 /* dump supported am */
255 fprintf(F, "AM support = ");
256 switch (get_ia32_am_support(n)) {
261 fprintf(F, "source only (Load)");
264 fprintf(F, "dest only (Load+Store)");
270 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
275 /* dump am flavour */
276 fprintf(F, "AM flavour =");
277 am_flav = get_ia32_am_flavour(n);
278 if (am_flav == ia32_am_N) {
282 if (am_flav & ia32_O) {
285 if (am_flav & ia32_B) {
288 if (am_flav & ia32_I) {
291 if (am_flav & ia32_S) {
295 fprintf(F, " (%d)\n", am_flav);
298 fprintf(F, "AM offset = ");
299 if (get_ia32_am_offs(n)) {
300 fprintf(F, "%s", get_ia32_am_offs(n));
308 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
311 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
314 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
317 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
320 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
323 fprintf(F, "flags =");
324 flags = get_ia32_flags(n);
325 if (flags == arch_irn_flags_none) {
329 if (flags & arch_irn_flags_dont_spill) {
330 fprintf(F, " unspillable");
332 if (flags & arch_irn_flags_rematerializable) {
333 fprintf(F, " remat");
335 if (flags & arch_irn_flags_ignore) {
336 fprintf(F, " ignore");
339 fprintf(F, " (%d)\n", flags);
341 /* dump frame entity */
342 fprintf(F, "frame entity = ");
343 if (get_ia32_frame_ent(n)) {
344 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
352 /* dump original ir node name */
353 fprintf(F, "orig node = ");
354 if (get_ia32_orig_node(n)) {
355 fprintf(F, "%s", get_ia32_orig_node(n));
363 fprintf(F, "=== IA32 attr end ===\n");
364 /* end of: case dump_node_info_txt */
373 /***************************************************************************************************
375 * | | | | | | / / | | | | | | | |
376 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
377 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
378 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
379 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
382 ***************************************************************************************************/
385 * Returns an ident for the given tarval tv.
387 static ident *get_ident_for_tv(tarval *tv) {
390 assert(tarval_snprintf(buf, sizeof(buf), tv));
391 return new_id_from_str(buf);
395 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
396 * Firm was made by people hating const :-(
398 ia32_attr_t *get_ia32_attr(const ir_node *node) {
399 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
400 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
404 * Gets the type of an ia32 node.
406 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
407 ia32_attr_t *attr = get_ia32_attr(node);
408 return attr->data.tp;
412 * Sets the type of an ia32 node.
414 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
415 ia32_attr_t *attr = get_ia32_attr(node);
420 * Gets the immediate op type of an ia32 node.
422 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
423 ia32_attr_t *attr = get_ia32_attr(node);
424 return attr->data.imm_tp;
428 * Sets the immediate op type of an ia32 node.
430 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
431 ia32_attr_t *attr = get_ia32_attr(node);
432 attr->data.imm_tp = tp;
436 * Gets the supported addrmode of an ia32 node
438 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
439 ia32_attr_t *attr = get_ia32_attr(node);
440 return attr->data.am_support;
444 * Sets the supported addrmode of an ia32 node
446 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
447 ia32_attr_t *attr = get_ia32_attr(node);
448 attr->data.am_support = am_tp;
452 * Gets the addrmode flavour of an ia32 node
454 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
455 ia32_attr_t *attr = get_ia32_attr(node);
456 return attr->data.am_flavour;
460 * Sets the addrmode flavour of an ia32 node
462 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
463 ia32_attr_t *attr = get_ia32_attr(node);
464 attr->data.am_flavour = am_flavour;
468 * Joins all offsets to one string with adds.
470 char *get_ia32_am_offs(const ir_node *node) {
471 ia32_attr_t *attr = get_ia32_attr(node);
475 if (! attr->am_offs) {
479 size = obstack_object_size(attr->am_offs);
481 res = xmalloc(size + 2);
482 res[0] = attr->data.offs_sign ? '-' : '+';
483 memcpy(&res[1], obstack_base(attr->am_offs), size);
484 res[size + 1] = '\0';
491 * Add an offset for addrmode.
493 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
494 ia32_attr_t *attr = get_ia32_attr(node);
496 if (! offset || strlen(offset) < 1)
499 /* offset could already have an explicit sign */
500 /* -> supersede op if necessary */
501 if (offset[0] == '-' || offset[0] == '+') {
502 if (offset[0] == '-') {
503 op = (op == '-') ? '+' : '-';
506 /* skip explicit sign */
510 if (! attr->am_offs) {
511 /* obstack is not initialized */
512 attr->am_offs = xcalloc(1, sizeof(*(attr->am_offs)));
513 obstack_init(attr->am_offs);
515 attr->data.offs_sign = (op == '-') ? 1 : 0;
518 /* If obstack is initialized, connect the new offset with op */
519 obstack_printf(attr->am_offs, "%c", op);
522 obstack_printf(attr->am_offs, "%s", offset);
526 * Add an offset for addrmode.
528 void add_ia32_am_offs(ir_node *node, const char *offset) {
529 extend_ia32_am_offs(node, (char *)offset, '+');
533 * Sub an offset for addrmode.
535 void sub_ia32_am_offs(ir_node *node, const char *offset) {
536 extend_ia32_am_offs(node, (char *)offset, '-');
540 * Gets the addr mode const.
542 int get_ia32_am_scale(const ir_node *node) {
543 ia32_attr_t *attr = get_ia32_attr(node);
544 return attr->data.am_scale;
548 * Sets the index register scale for addrmode.
550 void set_ia32_am_scale(ir_node *node, int scale) {
551 ia32_attr_t *attr = get_ia32_attr(node);
552 attr->data.am_scale = scale;
556 * Return the tarval of an immediate operation or NULL in case of SymConst
558 tarval *get_ia32_Immop_tarval(const ir_node *node) {
559 ia32_attr_t *attr = get_ia32_attr(node);
560 return attr->cnst_val.tv;
564 * Sets the attributes of an immediate operation to the specified tarval
566 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
567 ia32_attr_t *attr = get_ia32_attr(node);
568 attr->cnst_val.tv = tv;
569 attr->cnst = get_ident_for_tv(tv);
573 * Return the sc attribute.
575 ident *get_ia32_sc(const ir_node *node) {
576 ia32_attr_t *attr = get_ia32_attr(node);
577 return attr->cnst_val.sc;
581 * Sets the sc attribute.
583 void set_ia32_sc(ir_node *node, ident *sc) {
584 ia32_attr_t *attr = get_ia32_attr(node);
585 attr->cnst_val.sc = sc;
586 attr->cnst = attr->cnst_val.sc;
590 * Gets the string representation of the internal const (tv or symconst)
592 const char *get_ia32_cnst(const ir_node *node) {
593 ia32_attr_t *attr = get_ia32_attr(node);
594 return get_id_str(attr->cnst);
598 * Sets the string representation of the internal const.
600 void set_ia32_cnst(ir_node *node, char *cnst) {
601 ia32_attr_t *attr = get_ia32_attr(node);
602 attr->cnst = new_id_from_str(cnst);
606 * Gets the ident representation of the internal const (tv or symconst)
608 ident *get_ia32_id_cnst(const ir_node *node) {
609 ia32_attr_t *attr = get_ia32_attr(node);
614 * Sets the ident representation of the internal const.
616 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
617 ia32_attr_t *attr = get_ia32_attr(node);
622 * Sets the uses_frame flag.
624 void set_ia32_use_frame(ir_node *node) {
625 ia32_attr_t *attr = get_ia32_attr(node);
626 attr->data.use_frame = 1;
630 * Clears the uses_frame flag.
632 void clear_ia32_use_frame(ir_node *node) {
633 ia32_attr_t *attr = get_ia32_attr(node);
634 attr->data.use_frame = 0;
638 * Gets the uses_frame flag.
640 int is_ia32_use_frame(const ir_node *node) {
641 ia32_attr_t *attr = get_ia32_attr(node);
642 return attr->data.use_frame;
646 * Sets node to commutative.
648 void set_ia32_commutative(ir_node *node) {
649 ia32_attr_t *attr = get_ia32_attr(node);
650 attr->data.is_commutative = 1;
654 * Sets node to non-commutative.
656 void clear_ia32_commutative(ir_node *node) {
657 ia32_attr_t *attr = get_ia32_attr(node);
658 attr->data.is_commutative = 0;
662 * Checks if node is commutative.
664 int is_ia32_commutative(const ir_node *node) {
665 ia32_attr_t *attr = get_ia32_attr(node);
666 return attr->data.is_commutative;
670 * Gets the mode of the stored/loaded value (only set for Store/Load)
672 ir_mode *get_ia32_ls_mode(const ir_node *node) {
673 ia32_attr_t *attr = get_ia32_attr(node);
674 return attr->ls_mode;
678 * Sets the mode of the stored/loaded value (only set for Store/Load)
680 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
681 ia32_attr_t *attr = get_ia32_attr(node);
682 attr->ls_mode = mode;
686 * Gets the mode of the result.
688 ir_mode *get_ia32_res_mode(const ir_node *node) {
689 ia32_attr_t *attr = get_ia32_attr(node);
690 return attr->res_mode;
694 * Sets the mode of the result.
696 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
697 ia32_attr_t *attr = get_ia32_attr(node);
698 attr->res_mode = mode;
702 * Gets the frame entity assigned to this node;
704 entity *get_ia32_frame_ent(const ir_node *node) {
705 ia32_attr_t *attr = get_ia32_attr(node);
706 return attr->frame_ent;
710 * Sets the frame entity for this node;
712 void set_ia32_frame_ent(ir_node *node, entity *ent) {
713 ia32_attr_t *attr = get_ia32_attr(node);
714 attr->frame_ent = ent;
718 * Returns the argument register requirements of an ia32 node.
720 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
721 ia32_attr_t *attr = get_ia32_attr(node);
726 * Sets the argument register requirements of an ia32 node.
728 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
729 ia32_attr_t *attr = get_ia32_attr(node);
734 * Returns the result register requirements of an ia32 node.
736 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
737 ia32_attr_t *attr = get_ia32_attr(node);
738 return attr->out_req;
742 * Sets the result register requirements of an ia32 node.
744 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
745 ia32_attr_t *attr = get_ia32_attr(node);
746 attr->out_req = reqs;
750 * Returns the argument register requirement at position pos of an ia32 node.
752 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
753 ia32_attr_t *attr = get_ia32_attr(node);
754 return attr->in_req[pos];
758 * Returns the result register requirement at position pos of an ia32 node.
760 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
761 ia32_attr_t *attr = get_ia32_attr(node);
762 return attr->out_req[pos];
766 * Sets the OUT register requirements at position pos.
768 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
769 ia32_attr_t *attr = get_ia32_attr(node);
770 attr->out_req[pos] = req;
774 * Sets the IN register requirements at position pos.
776 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
777 ia32_attr_t *attr = get_ia32_attr(node);
778 attr->in_req[pos] = req;
782 * Returns the register flag of an ia32 node.
784 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
785 ia32_attr_t *attr = get_ia32_attr(node);
786 return attr->data.flags;
790 * Sets the register flag of an ia32 node.
792 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
793 ia32_attr_t *attr = get_ia32_attr(node);
794 attr->data.flags = flags;
798 * Returns the result register slots of an ia32 node.
800 const arch_register_t **get_ia32_slots(const ir_node *node) {
801 ia32_attr_t *attr = get_ia32_attr(node);
806 * Sets the number of results.
808 void set_ia32_n_res(ir_node *node, int n_res) {
809 ia32_attr_t *attr = get_ia32_attr(node);
810 attr->data.n_res = n_res;
814 * Returns the number of results.
816 int get_ia32_n_res(const ir_node *node) {
817 ia32_attr_t *attr = get_ia32_attr(node);
818 return attr->data.n_res;
822 * Returns the flavour of an ia32 node,
824 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
825 ia32_attr_t *attr = get_ia32_attr(node);
826 return attr->data.op_flav;
830 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
832 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
833 ia32_attr_t *attr = get_ia32_attr(node);
834 attr->data.op_flav = op_flav;
838 * Returns the projnum code.
840 long get_ia32_pncode(const ir_node *node) {
841 ia32_attr_t *attr = get_ia32_attr(node);
842 return attr->pn_code;
846 * Sets the projnum code
848 void set_ia32_pncode(ir_node *node, long code) {
849 ia32_attr_t *attr = get_ia32_attr(node);
850 attr->pn_code = code;
856 * Returns the name of the original ir node.
858 const char *get_ia32_orig_node(const ir_node *node) {
859 ia32_attr_t *attr = get_ia32_attr(node);
860 return attr->orig_node;
864 * Sets the name of the original ir node.
866 void set_ia32_orig_node(ir_node *node, const char *name) {
867 ia32_attr_t *attr = get_ia32_attr(node);
868 attr->orig_node = name;
873 /******************************************************************************************************
875 * (_) | | | | | | / _| | | (_)
876 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
877 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
878 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
879 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
882 ******************************************************************************************************/
885 * Gets the type of an ia32_Const.
887 unsigned get_ia32_Const_type(const ir_node *node) {
888 ia32_attr_t *attr = get_ia32_attr(node);
890 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
892 return attr->data.tp;
896 * Sets the type of an ia32_Const.
898 void set_ia32_Const_type(ir_node *node, int type) {
899 ia32_attr_t *attr = get_ia32_attr(node);
901 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
902 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
904 attr->data.tp = type;
908 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
910 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
911 ia32_attr_t *na = get_ia32_attr(node);
912 ia32_attr_t *ca = get_ia32_attr(cnst);
914 switch(get_ia32_Const_type(cnst)) {
916 na->cnst_val.tv = ca->cnst_val.tv;
918 set_ia32_immop_type(node, ia32_ImmConst);
921 na->cnst_val.sc = ca->cnst_val.sc;
922 na->cnst = na->cnst_val.sc;
923 set_ia32_immop_type(node, ia32_ImmSymConst);
926 assert(0 && "Need ia32_Const to set Immop attr");
931 * Copy the attributes from Immop to an Immop
933 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
934 ia32_attr_t *da = get_ia32_attr(dst);
935 ia32_attr_t *sa = get_ia32_attr(src);
937 switch(get_ia32_immop_type(src)) {
939 da->cnst_val.tv = sa->cnst_val.tv;
941 set_ia32_immop_type(dst, ia32_ImmConst);
943 case ia32_ImmSymConst:
944 da->cnst_val.sc = sa->cnst_val.sc;
946 set_ia32_immop_type(dst, ia32_ImmSymConst);
949 assert(0 && "Need Immop to copy Immop attr");
954 * Copy the attributes from a Firm Const to an ia32_Const
956 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
957 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
959 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
961 switch (get_irn_opcode(cnst)) {
963 attr->data.tp = ia32_Const;
964 attr->cnst_val.tv = get_Const_tarval(cnst);
965 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
968 attr->data.tp = ia32_SymConst;
969 attr->cnst_val.sc = get_sc_ident(cnst);
970 attr->cnst = attr->cnst_val.sc;
973 assert(0 && "Unknown Const NYI");
976 assert(0 && "Cannot create ia32_Const for this opcode");
981 * Sets the AddrMode(S|D) attribute
983 void set_ia32_AddrMode(ir_node *node, char direction) {
984 ia32_attr_t *attr = get_ia32_attr(node);
988 attr->data.tp = ia32_AddrModeD;
991 attr->data.tp = ia32_AddrModeS;
994 assert(0 && "wrong AM type");
999 * Returns whether or not the node is an immediate operation with Const.
1001 int is_ia32_ImmConst(const ir_node *node) {
1002 ia32_attr_t *attr = get_ia32_attr(node);
1003 return (attr->data.imm_tp == ia32_ImmConst);
1007 * Returns whether or not the node is an immediate operation with SymConst.
1009 int is_ia32_ImmSymConst(const ir_node *node) {
1010 ia32_attr_t *attr = get_ia32_attr(node);
1011 return (attr->data.imm_tp == ia32_ImmSymConst);
1015 * Returns whether or not the node is an AddrModeS node.
1017 int is_ia32_AddrModeS(const ir_node *node) {
1018 ia32_attr_t *attr = get_ia32_attr(node);
1019 return (attr->data.tp == ia32_AddrModeS);
1023 * Returns whether or not the node is an AddrModeD node.
1025 int is_ia32_AddrModeD(const ir_node *node) {
1026 ia32_attr_t *attr = get_ia32_attr(node);
1027 return (attr->data.tp == ia32_AddrModeD);
1031 * Checks if node is a Load or fLoad.
1033 int is_ia32_Ld(const ir_node *node) {
1034 return is_ia32_Load(node) || is_ia32_fLoad(node);
1038 * Checks if node is a Store or fStore.
1040 int is_ia32_St(const ir_node *node) {
1041 return is_ia32_Store(node) || is_ia32_fStore(node);
1045 * Checks if node is a Const or fConst.
1047 int is_ia32_Cnst(const ir_node *node) {
1048 return is_ia32_Const(node) || is_ia32_fConst(node);
1052 * Returns the name of the OUT register at position pos.
1054 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1055 ia32_attr_t *attr = get_ia32_attr(node);
1057 assert(is_ia32_irn(node) && "Not an ia32 node.");
1058 assert(pos < 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(is_ia32_irn(node) && "Not an ia32 node.");
1071 assert(pos < attr->data.n_res && "Invalid OUT position.");
1072 assert(attr->slots[pos] && "No register assigned");
1074 return arch_register_get_index(attr->slots[pos]);
1078 * Returns the OUT register at position pos.
1080 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1081 ia32_attr_t *attr = get_ia32_attr(node);
1083 assert(is_ia32_irn(node) && "Not an ia32 node.");
1084 assert(pos < attr->data.n_res && "Invalid OUT position.");
1085 assert(attr->slots[pos] && "No register assigned");
1087 return attr->slots[pos];
1091 * Allocates num register slots for node.
1093 void alloc_ia32_reg_slots(ir_node *node, int num) {
1094 ia32_attr_t *attr = get_ia32_attr(node);
1097 attr->slots = NEW_ARR_D(arch_register_t *, get_irg_obstack(get_irn_irg(node)), num);
1098 memset(attr->slots, 0, sizeof(attr->slots[0]) * num);
1104 attr->data.n_res = num;
1108 * Initializes the nodes attributes.
1110 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1111 const ia32_register_req_t **out_reqs, int n_res)
1113 set_ia32_flags(node, flags);
1114 set_ia32_in_req_all(node, in_reqs);
1115 set_ia32_out_req_all(node, out_reqs);
1116 alloc_ia32_reg_slots(node, n_res);
1119 /***************************************************************************************
1122 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1123 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1124 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1125 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1127 ***************************************************************************************/
1129 /* default compare operation to compare immediate ops */
1130 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1131 if (a->data.tp == b->data.tp) {
1132 return a->cnst == b->cnst;
1138 /* copies the ia32 attributes */
1139 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1140 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1141 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1142 int n_res = get_ia32_n_res(old_node);
1144 /* copy the attributes */
1145 memcpy(attr_new, attr_old, sizeof(*attr_new));
1147 /* copy the register slots */
1148 attr_new->slots = NEW_ARR_D(arch_register_t *, get_irg_obstack(get_irn_irg(new_node)), n_res);
1149 memcpy((void *)attr_new->slots, (void *)attr_old->slots, sizeof(attr_new->slots[0]) * n_res);
1153 * Registers the ia32_copy_attr function for all ia32 opcodes.
1155 void ia32_register_copy_attr_func(void) {
1156 unsigned i, f = get_ia32_opcode_first(), l = get_ia32_opcode_last();
1158 for (i = f; i < l; i++) {
1159 ir_op *op = get_irp_opcode(i);
1160 op->ops.copy_attr = ia32_copy_attr;
1164 static void ia32_register_additional_opcodes(int n) {
1165 /* we don't need any additional opcodes */
1168 /* Include the generated constructor functions */
1169 #include "gen_ia32_new_nodes.c.inl"