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" : "";
189 const char *cnst = get_ia32_cnst(n);
191 fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
194 if (! is_ia32_Lea(n)) {
195 if (is_ia32_AddrModeS(n)) {
196 fprintf(F, "[AM S] ");
198 else if (is_ia32_AddrModeD(n)) {
199 fprintf(F, "[AM D] ");
205 case dump_node_info_txt:
206 n_res = get_ia32_n_res(n);
207 fprintf(F, "=== IA32 attr begin ===\n");
209 /* dump IN requirements */
210 if (get_irn_arity(n) > 0) {
211 reqs = get_ia32_in_req_all(n);
212 dump_reg_req(F, n, reqs, 0);
215 /* dump OUT requirements */
217 reqs = get_ia32_out_req_all(n);
218 dump_reg_req(F, n, reqs, 1);
221 /* dump assigned registers */
222 slots = get_ia32_slots(n);
223 if (slots && n_res > 0) {
224 for (i = 0; i < n_res; i++) {
225 fprintf(F, "reg #%d = %s\n", i, slots[i] ? slots[i]->name : "n/a");
232 switch (get_ia32_op_type(n)) {
234 fprintf(F, "Normal");
240 fprintf(F, "SymConst");
243 fprintf(F, "AM Dest (Load+Store)");
246 fprintf(F, "AM Source (Load)");
249 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
255 /* dump supported am */
256 fprintf(F, "AM support = ");
257 switch (get_ia32_am_support(n)) {
262 fprintf(F, "source only (Load)");
265 fprintf(F, "dest only (Load+Store)");
271 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
276 /* dump am flavour */
277 fprintf(F, "AM flavour =");
278 am_flav = get_ia32_am_flavour(n);
279 if (am_flav == ia32_am_N) {
283 if (am_flav & ia32_O) {
286 if (am_flav & ia32_B) {
289 if (am_flav & ia32_I) {
292 if (am_flav & ia32_S) {
296 fprintf(F, " (%d)\n", am_flav);
299 fprintf(F, "AM offset = ");
300 if (get_ia32_am_offs(n)) {
301 fprintf(F, "%s", get_ia32_am_offs(n));
309 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
312 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
315 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
318 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
321 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
324 fprintf(F, "flags =");
325 flags = get_ia32_flags(n);
326 if (flags == arch_irn_flags_none) {
330 if (flags & arch_irn_flags_dont_spill) {
331 fprintf(F, " unspillable");
333 if (flags & arch_irn_flags_rematerializable) {
334 fprintf(F, " remat");
336 if (flags & arch_irn_flags_ignore) {
337 fprintf(F, " ignore");
340 fprintf(F, " (%d)\n", flags);
342 /* dump frame entity */
343 fprintf(F, "frame entity = ");
344 if (get_ia32_frame_ent(n)) {
345 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
353 /* dump original ir node name */
354 fprintf(F, "orig node = ");
355 if (get_ia32_orig_node(n)) {
356 fprintf(F, "%s", get_ia32_orig_node(n));
364 fprintf(F, "=== IA32 attr end ===\n");
365 /* end of: case dump_node_info_txt */
374 /***************************************************************************************************
376 * | | | | | | / / | | | | | | | |
377 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
378 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
379 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
380 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
383 ***************************************************************************************************/
386 * Returns an ident for the given tarval tv.
388 static ident *get_ident_for_tv(tarval *tv) {
391 assert(tarval_snprintf(buf, sizeof(buf), tv));
392 return new_id_from_str(buf);
396 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
397 * Firm was made by people hating const :-(
399 ia32_attr_t *get_ia32_attr(const ir_node *node) {
400 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
401 return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
405 * Gets the type of an ia32 node.
407 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
408 ia32_attr_t *attr = get_ia32_attr(node);
409 return attr->data.tp;
413 * Sets the type of an ia32 node.
415 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
416 ia32_attr_t *attr = get_ia32_attr(node);
421 * Gets the immediate op type of an ia32 node.
423 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
424 ia32_attr_t *attr = get_ia32_attr(node);
425 return attr->data.imm_tp;
429 * Sets the immediate op type of an ia32 node.
431 void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
432 ia32_attr_t *attr = get_ia32_attr(node);
433 attr->data.imm_tp = tp;
437 * Gets the supported addrmode of an ia32 node
439 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
440 ia32_attr_t *attr = get_ia32_attr(node);
441 return attr->data.am_support;
445 * Sets the supported addrmode of an ia32 node
447 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
448 ia32_attr_t *attr = get_ia32_attr(node);
449 attr->data.am_support = am_tp;
453 * Gets the addrmode flavour of an ia32 node
455 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
456 ia32_attr_t *attr = get_ia32_attr(node);
457 return attr->data.am_flavour;
461 * Sets the addrmode flavour of an ia32 node
463 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
464 ia32_attr_t *attr = get_ia32_attr(node);
465 attr->data.am_flavour = am_flavour;
469 * Joins all offsets to one string with adds.
471 char *get_ia32_am_offs(const ir_node *node) {
472 ia32_attr_t *attr = get_ia32_attr(node);
476 if (! attr->am_offs) {
480 size = obstack_object_size(attr->am_offs);
482 res = xmalloc(size + 2);
483 res[0] = attr->data.offs_sign ? '-' : '+';
484 memcpy(&res[1], obstack_base(attr->am_offs), size);
485 res[size + 1] = '\0';
492 * Add an offset for addrmode.
494 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
495 ia32_attr_t *attr = get_ia32_attr(node);
497 if (! offset || strlen(offset) < 1)
500 /* offset could already have an explicit sign */
501 /* -> supersede op if necessary */
502 if (offset[0] == '-' || offset[0] == '+') {
503 if (offset[0] == '-') {
504 op = (op == '-') ? '+' : '-';
507 /* skip explicit sign */
511 if (! attr->am_offs) {
512 /* obstack is not initialized */
513 attr->am_offs = xcalloc(1, sizeof(*(attr->am_offs)));
514 obstack_init(attr->am_offs);
516 attr->data.offs_sign = (op == '-') ? 1 : 0;
519 /* If obstack is initialized, connect the new offset with op */
520 obstack_printf(attr->am_offs, "%c", op);
523 obstack_printf(attr->am_offs, "%s", offset);
527 * Add an offset for addrmode.
529 void add_ia32_am_offs(ir_node *node, const char *offset) {
530 extend_ia32_am_offs(node, (char *)offset, '+');
534 * Sub an offset for addrmode.
536 void sub_ia32_am_offs(ir_node *node, const char *offset) {
537 extend_ia32_am_offs(node, (char *)offset, '-');
541 * Returns the symconst ident associated to addrmode.
543 ident *get_ia32_am_sc(const ir_node *node) {
544 ia32_attr_t *attr = get_ia32_attr(node);
549 * Sets the symconst ident associated to addrmode.
551 void set_ia32_am_sc(ir_node *node, ident *sc) {
552 ia32_attr_t *attr = get_ia32_attr(node);
557 * Sets the sign bit for address mode symconst.
559 void set_ia32_am_sc_sign(ir_node *node) {
560 ia32_attr_t *attr = get_ia32_attr(node);
561 attr->data.am_sc_sign = 1;
565 * Clears the sign bit for address mode symconst.
567 void clear_ia32_am_sc_sign(ir_node *node) {
568 ia32_attr_t *attr = get_ia32_attr(node);
569 attr->data.am_sc_sign = 0;
573 * Returns the sign bit for address mode symconst.
575 int is_ia32_am_sc_sign(const ir_node *node) {
576 ia32_attr_t *attr = get_ia32_attr(node);
577 return attr->data.am_sc_sign;
581 * Gets the addr mode const.
583 int get_ia32_am_scale(const ir_node *node) {
584 ia32_attr_t *attr = get_ia32_attr(node);
585 return attr->data.am_scale;
589 * Sets the index register scale for addrmode.
591 void set_ia32_am_scale(ir_node *node, int scale) {
592 ia32_attr_t *attr = get_ia32_attr(node);
593 attr->data.am_scale = scale;
597 * Return the tarval of an immediate operation or NULL in case of SymConst
599 tarval *get_ia32_Immop_tarval(const ir_node *node) {
600 ia32_attr_t *attr = get_ia32_attr(node);
601 return attr->cnst_val.tv;
605 * Sets the attributes of an immediate operation to the specified tarval
607 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
608 ia32_attr_t *attr = get_ia32_attr(node);
609 attr->cnst_val.tv = tv;
610 attr->cnst = get_ident_for_tv(tv);
614 * Return the sc attribute.
616 ident *get_ia32_sc(const ir_node *node) {
617 ia32_attr_t *attr = get_ia32_attr(node);
618 return attr->cnst_val.sc;
622 * Sets the sc attribute.
624 void set_ia32_sc(ir_node *node, ident *sc) {
625 ia32_attr_t *attr = get_ia32_attr(node);
626 attr->cnst_val.sc = sc;
627 attr->cnst = attr->cnst_val.sc;
631 * Gets the string representation of the internal const (tv or symconst)
633 const char *get_ia32_cnst(const ir_node *node) {
634 ia32_attr_t *attr = get_ia32_attr(node);
637 return get_id_str(attr->cnst);
641 * Sets the string representation of the internal const.
643 void set_ia32_cnst(ir_node *node, char *cnst) {
644 ia32_attr_t *attr = get_ia32_attr(node);
645 attr->cnst = new_id_from_str(cnst);
649 * Gets the ident representation of the internal const (tv or symconst)
651 ident *get_ia32_id_cnst(const ir_node *node) {
652 ia32_attr_t *attr = get_ia32_attr(node);
657 * Sets the ident representation of the internal const.
659 void set_ia32_id_cnst(ir_node *node, ident *cnst) {
660 ia32_attr_t *attr = get_ia32_attr(node);
665 * Sets the uses_frame flag.
667 void set_ia32_use_frame(ir_node *node) {
668 ia32_attr_t *attr = get_ia32_attr(node);
669 attr->data.use_frame = 1;
673 * Clears the uses_frame flag.
675 void clear_ia32_use_frame(ir_node *node) {
676 ia32_attr_t *attr = get_ia32_attr(node);
677 attr->data.use_frame = 0;
681 * Gets the uses_frame flag.
683 int is_ia32_use_frame(const ir_node *node) {
684 ia32_attr_t *attr = get_ia32_attr(node);
685 return attr->data.use_frame;
689 * Sets node to commutative.
691 void set_ia32_commutative(ir_node *node) {
692 ia32_attr_t *attr = get_ia32_attr(node);
693 attr->data.is_commutative = 1;
697 * Sets node to non-commutative.
699 void clear_ia32_commutative(ir_node *node) {
700 ia32_attr_t *attr = get_ia32_attr(node);
701 attr->data.is_commutative = 0;
705 * Checks if node is commutative.
707 int is_ia32_commutative(const ir_node *node) {
708 ia32_attr_t *attr = get_ia32_attr(node);
709 return attr->data.is_commutative;
715 void set_ia32_emit_cl(ir_node *node) {
716 ia32_attr_t *attr = get_ia32_attr(node);
717 attr->data.emit_cl = 1;
721 * Clears node emit_cl.
723 void clear_ia32_emit_cl(ir_node *node) {
724 ia32_attr_t *attr = get_ia32_attr(node);
725 attr->data.emit_cl = 0;
729 * Checks if node is commutative.
731 int is_ia32_emit_cl(const ir_node *node) {
732 ia32_attr_t *attr = get_ia32_attr(node);
733 return attr->data.emit_cl;
737 * Gets the mode of the stored/loaded value (only set for Store/Load)
739 ir_mode *get_ia32_ls_mode(const ir_node *node) {
740 ia32_attr_t *attr = get_ia32_attr(node);
741 return attr->ls_mode;
745 * Sets the mode of the stored/loaded value (only set for Store/Load)
747 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
748 ia32_attr_t *attr = get_ia32_attr(node);
749 attr->ls_mode = mode;
753 * Gets the mode of the result.
755 ir_mode *get_ia32_res_mode(const ir_node *node) {
756 ia32_attr_t *attr = get_ia32_attr(node);
757 return attr->res_mode;
761 * Sets the mode of the result.
763 void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
764 ia32_attr_t *attr = get_ia32_attr(node);
765 attr->res_mode = mode;
769 * Gets the source mode of conversion.
771 ir_mode *get_ia32_src_mode(const ir_node *node) {
772 ia32_attr_t *attr = get_ia32_attr(node);
773 return attr->src_mode;
777 * Sets the source mode of conversion.
779 void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
780 ia32_attr_t *attr = get_ia32_attr(node);
781 attr->src_mode = mode;
785 * Gets the target mode of conversion.
787 ir_mode *get_ia32_tgt_mode(const ir_node *node) {
788 ia32_attr_t *attr = get_ia32_attr(node);
789 return attr->tgt_mode;
793 * Sets the target mode of conversion.
795 void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
796 ia32_attr_t *attr = get_ia32_attr(node);
797 attr->tgt_mode = mode;
801 * Gets the frame entity assigned to this node;
803 entity *get_ia32_frame_ent(const ir_node *node) {
804 ia32_attr_t *attr = get_ia32_attr(node);
805 return attr->frame_ent;
809 * Sets the frame entity for this node;
811 void set_ia32_frame_ent(ir_node *node, entity *ent) {
812 ia32_attr_t *attr = get_ia32_attr(node);
813 attr->frame_ent = ent;
817 * Returns the argument register requirements of an ia32 node.
819 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
820 ia32_attr_t *attr = get_ia32_attr(node);
825 * Sets the argument register requirements of an ia32 node.
827 void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
828 ia32_attr_t *attr = get_ia32_attr(node);
833 * Returns the result register requirements of an ia32 node.
835 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
836 ia32_attr_t *attr = get_ia32_attr(node);
837 return attr->out_req;
841 * Sets the result register requirements of an ia32 node.
843 void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
844 ia32_attr_t *attr = get_ia32_attr(node);
845 attr->out_req = reqs;
849 * Returns the argument register requirement at position pos of an ia32 node.
851 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
852 ia32_attr_t *attr = get_ia32_attr(node);
853 return attr->in_req[pos];
857 * Returns the result register requirement at position pos of an ia32 node.
859 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
860 ia32_attr_t *attr = get_ia32_attr(node);
861 return attr->out_req[pos];
865 * Sets the OUT register requirements at position pos.
867 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
868 ia32_attr_t *attr = get_ia32_attr(node);
869 attr->out_req[pos] = req;
873 * Sets the IN register requirements at position pos.
875 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
876 ia32_attr_t *attr = get_ia32_attr(node);
877 attr->in_req[pos] = req;
881 * Returns the register flag of an ia32 node.
883 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
884 ia32_attr_t *attr = get_ia32_attr(node);
885 return attr->data.flags;
889 * Sets the register flag of an ia32 node.
891 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
892 ia32_attr_t *attr = get_ia32_attr(node);
893 attr->data.flags = flags;
897 * Returns the result register slots of an ia32 node.
899 const arch_register_t **get_ia32_slots(const ir_node *node) {
900 ia32_attr_t *attr = get_ia32_attr(node);
905 * Sets the number of results.
907 void set_ia32_n_res(ir_node *node, int n_res) {
908 ia32_attr_t *attr = get_ia32_attr(node);
909 attr->data.n_res = n_res;
913 * Returns the number of results.
915 int get_ia32_n_res(const ir_node *node) {
916 ia32_attr_t *attr = get_ia32_attr(node);
917 return attr->data.n_res;
921 * Returns the flavour of an ia32 node,
923 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
924 ia32_attr_t *attr = get_ia32_attr(node);
925 return attr->data.op_flav;
929 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
931 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
932 ia32_attr_t *attr = get_ia32_attr(node);
933 attr->data.op_flav = op_flav;
937 * Returns the projnum code.
939 long get_ia32_pncode(const ir_node *node) {
940 ia32_attr_t *attr = get_ia32_attr(node);
941 return attr->pn_code;
945 * Sets the projnum code
947 void set_ia32_pncode(ir_node *node, long code) {
948 ia32_attr_t *attr = get_ia32_attr(node);
949 attr->pn_code = code;
955 * Returns the name of the original ir node.
957 const char *get_ia32_orig_node(const ir_node *node) {
958 ia32_attr_t *attr = get_ia32_attr(node);
959 return attr->orig_node;
963 * Sets the name of the original ir node.
965 void set_ia32_orig_node(ir_node *node, const char *name) {
966 ia32_attr_t *attr = get_ia32_attr(node);
967 attr->orig_node = name;
972 /******************************************************************************************************
974 * (_) | | | | | | / _| | | (_)
975 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
976 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
977 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
978 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
981 ******************************************************************************************************/
984 * Gets the type of an ia32_Const.
986 unsigned get_ia32_Const_type(const ir_node *node) {
987 ia32_attr_t *attr = get_ia32_attr(node);
989 assert(is_ia32_Cnst(node) && "Need ia32_Const to get type");
991 return attr->data.tp;
995 * Sets the type of an ia32_Const.
997 void set_ia32_Const_type(ir_node *node, int type) {
998 ia32_attr_t *attr = get_ia32_attr(node);
1000 assert(is_ia32_Cnst(node) && "Need ia32_Const to set type");
1001 assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
1003 attr->data.tp = type;
1007 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1009 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
1010 ia32_attr_t *na = get_ia32_attr(node);
1011 ia32_attr_t *ca = get_ia32_attr(cnst);
1013 switch(get_ia32_Const_type(cnst)) {
1015 na->cnst_val.tv = ca->cnst_val.tv;
1016 na->cnst = ca->cnst;
1017 set_ia32_immop_type(node, ia32_ImmConst);
1020 na->cnst_val.sc = ca->cnst_val.sc;
1021 na->cnst = na->cnst_val.sc;
1022 set_ia32_immop_type(node, ia32_ImmSymConst);
1025 assert(0 && "Need ia32_Const to set Immop attr");
1030 * Copy the attributes from Immop to an Immop
1032 void copy_ia32_Immop_attr(ir_node *dst, ir_node *src) {
1033 ia32_attr_t *da = get_ia32_attr(dst);
1034 ia32_attr_t *sa = get_ia32_attr(src);
1036 switch(get_ia32_immop_type(src)) {
1038 da->cnst_val.tv = sa->cnst_val.tv;
1039 da->cnst = sa->cnst;
1040 set_ia32_immop_type(dst, ia32_ImmConst);
1042 case ia32_ImmSymConst:
1043 da->cnst_val.sc = sa->cnst_val.sc;
1044 da->cnst = sa->cnst;
1045 set_ia32_immop_type(dst, ia32_ImmSymConst);
1048 assert(0 && "Need Immop to copy Immop attr");
1053 * Copy the attributes from a Firm Const to an ia32_Const
1055 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1056 ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
1058 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1060 switch (get_irn_opcode(cnst)) {
1062 attr->data.tp = ia32_Const;
1063 attr->cnst_val.tv = get_Const_tarval(cnst);
1064 attr->cnst = get_ident_for_tv(attr->cnst_val.tv);
1067 attr->data.tp = ia32_SymConst;
1068 attr->cnst_val.sc = get_sc_ident(cnst);
1069 attr->cnst = attr->cnst_val.sc;
1072 assert(0 && "Unknown Const NYI");
1075 assert(0 && "Cannot create ia32_Const for this opcode");
1080 * Sets the AddrMode(S|D) attribute
1082 void set_ia32_AddrMode(ir_node *node, char direction) {
1083 ia32_attr_t *attr = get_ia32_attr(node);
1085 switch (direction) {
1087 attr->data.tp = ia32_AddrModeD;
1090 attr->data.tp = ia32_AddrModeS;
1093 assert(0 && "wrong AM type");
1098 * Returns whether or not the node is an immediate operation with Const.
1100 int is_ia32_ImmConst(const ir_node *node) {
1101 ia32_attr_t *attr = get_ia32_attr(node);
1102 return (attr->data.imm_tp == ia32_ImmConst);
1106 * Returns whether or not the node is an immediate operation with SymConst.
1108 int is_ia32_ImmSymConst(const ir_node *node) {
1109 ia32_attr_t *attr = get_ia32_attr(node);
1110 return (attr->data.imm_tp == ia32_ImmSymConst);
1114 * Returns whether or not the node is an AddrModeS node.
1116 int is_ia32_AddrModeS(const ir_node *node) {
1117 ia32_attr_t *attr = get_ia32_attr(node);
1118 return (attr->data.tp == ia32_AddrModeS);
1122 * Returns whether or not the node is an AddrModeD node.
1124 int is_ia32_AddrModeD(const ir_node *node) {
1125 ia32_attr_t *attr = get_ia32_attr(node);
1126 return (attr->data.tp == ia32_AddrModeD);
1130 * Checks if node is a Load or fLoad/vfLoad.
1132 int is_ia32_Ld(const ir_node *node) {
1133 return is_ia32_Load(node) || is_ia32_fLoad(node) || is_ia32_vfld(node) || is_ia32_fld(node);
1137 * Checks if node is a Store or fStore/vfStore.
1139 int is_ia32_St(const ir_node *node) {
1140 return is_ia32_Store(node) || is_ia32_fStore(node) || is_ia32_vfst(node) || is_ia32_fst(node) || is_ia32_fstp(node);
1144 * Checks if node is a Const or fConst/vfConst.
1146 int is_ia32_Cnst(const ir_node *node) {
1147 return is_ia32_Const(node) || is_ia32_fConst(node) || is_ia32_vfConst(node);
1151 * Returns the name of the OUT register at position pos.
1153 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1154 ia32_attr_t *attr = get_ia32_attr(node);
1156 assert(is_ia32_irn(node) && "Not an ia32 node.");
1157 assert(pos < attr->data.n_res && "Invalid OUT position.");
1158 assert(attr->slots[pos] && "No register assigned");
1160 return arch_register_get_name(attr->slots[pos]);
1164 * Returns the index of the OUT register at position pos within its register class.
1166 int get_ia32_out_regnr(const ir_node *node, int pos) {
1167 ia32_attr_t *attr = get_ia32_attr(node);
1169 assert(is_ia32_irn(node) && "Not an ia32 node.");
1170 assert(pos < attr->data.n_res && "Invalid OUT position.");
1171 assert(attr->slots[pos] && "No register assigned");
1173 return arch_register_get_index(attr->slots[pos]);
1177 * Returns the OUT register at position pos.
1179 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1180 ia32_attr_t *attr = get_ia32_attr(node);
1182 assert(is_ia32_irn(node) && "Not an ia32 node.");
1183 assert(pos < attr->data.n_res && "Invalid OUT position.");
1184 assert(attr->slots[pos] && "No register assigned");
1186 return attr->slots[pos];
1190 * Allocates num register slots for node.
1192 void alloc_ia32_reg_slots(ir_node *node, int num) {
1193 ia32_attr_t *attr = get_ia32_attr(node);
1196 attr->slots = (const arch_register_t **)NEW_ARR_D(arch_register_t*, get_irg_obstack(get_irn_irg(node)), num);
1197 memset(attr->slots, 0, sizeof(attr->slots[0]) * num);
1203 attr->data.n_res = num;
1207 * Initializes the nodes attributes.
1209 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags, const ia32_register_req_t **in_reqs,
1210 const ia32_register_req_t **out_reqs, int n_res)
1212 set_ia32_flags(node, flags);
1213 set_ia32_in_req_all(node, in_reqs);
1214 set_ia32_out_req_all(node, out_reqs);
1215 alloc_ia32_reg_slots(node, n_res);
1218 /***************************************************************************************
1221 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1222 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1223 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1224 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1226 ***************************************************************************************/
1228 /* default compare operation to compare immediate ops */
1229 int ia32_compare_immop_attr(ia32_attr_t *a, ia32_attr_t *b) {
1232 if (a->data.tp == b->data.tp) {
1233 equ = (a->cnst == b->cnst);
1234 equ = equ ? (a->data.use_frame == b->data.use_frame) : 0;
1236 if (equ && a->data.use_frame && b->data.use_frame)
1237 equ = (a->frame_ent == b->frame_ent);
1243 /* copies the ia32 attributes */
1244 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node) {
1245 ia32_attr_t *attr_old = get_ia32_attr(old_node);
1246 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1247 int n_res = get_ia32_n_res(old_node);
1249 /* copy the attributes */
1250 memcpy(attr_new, attr_old, sizeof(*attr_new));
1252 /* copy the register slots */
1253 attr_new->slots = (const arch_register_t **)NEW_ARR_D(arch_register_t*, get_irg_obstack(get_irn_irg(new_node)), n_res);
1254 memcpy((void *)attr_new->slots, (void *)attr_old->slots, sizeof(attr_new->slots[0]) * n_res);
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 static void ia32_register_additional_opcodes(int n) {
1270 /* we don't need any additional opcodes */
1273 /* Include the generated constructor functions */
1274 #include "gen_ia32_new_nodes.c.inl"