fix alignment for float constants
[libfirm] / ir / be / ia32 / ia32_new_nodes.c
index 4b3012a..0741cee 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <stdlib.h>
 
+#include "irargs_t.h"
 #include "irprog_t.h"
 #include "irgraph_t.h"
 #include "irnode_t.h"
@@ -49,6 +50,7 @@
 #include "../beinfo.h"
 
 #include "bearch_ia32_t.h"
+#include "ia32_common_transform.h"
 #include "ia32_nodes_attr.h"
 #include "ia32_new_nodes.h"
 #include "gen_ia32_regalloc_if.h"
@@ -205,7 +207,6 @@ static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
                        break;
 
                case dump_node_info_txt:
-                       n_res = arch_irn_get_n_outs(n);
                        fprintf(F, "=== IA32 attr begin ===\n");
 
                        /* dump IN requirements */
@@ -214,14 +215,13 @@ static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
                                dump_reg_req(F, n, reqs, 0);
                        }
 
-                       /* dump OUT requirements */
+                       n_res = arch_irn_get_n_outs(n);
                        if (n_res > 0) {
+                               /* dump OUT requirements */
                                reqs = get_ia32_out_req_all(n);
                                dump_reg_req(F, n, reqs, 1);
-                       }
 
-                       /* dump assigned registers */
-                       if (n_res > 0) {
+                               /* dump assigned registers */
                                for (i = 0; i < n_res; i++) {
                                        const arch_register_t *reg = arch_irn_get_register(n, i);
 
@@ -289,12 +289,12 @@ static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
                                fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
                        }
 
-                       fprintf(F, "n_res = %d\n", arch_irn_get_n_outs(n));
-                       fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
-                       fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
+                       fprintf(F, "n_res = %d\n",         n_res);
+                       fprintf(F, "use_frame = %d\n",     is_ia32_use_frame(n));
+                       fprintf(F, "commutative = %d\n",   is_ia32_commutative(n));
                        fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
-                       fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
-                       fprintf(F, "latency = %d\n", get_ia32_latency(n));
+                       fprintf(F, "is reload = %d\n",     is_ia32_is_reload(n));
+                       fprintf(F, "latency = %d\n",       get_ia32_latency(n));
 
                        /* dump flags */
                        fprintf(F, "flags =");
@@ -456,6 +456,20 @@ const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
        return copyb_attr;
 }
 
+ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node) {
+       ia32_attr_t            *attr            = get_ia32_attr(node);
+       ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
+
+       return climbframe_attr;
+}
+
+const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node) {
+       const ia32_attr_t            *attr            = get_ia32_attr_const(node);
+       const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
+
+       return climbframe_attr;
+}
+
 /**
  * Gets the type of an ia32 node.
  */
@@ -551,7 +565,7 @@ int is_ia32_am_sc_sign(const ir_node *node) {
 /**
  * Gets the addr mode const.
  */
-int get_ia32_am_scale(const ir_node *node) {
+unsigned get_ia32_am_scale(const ir_node *node) {
        const ia32_attr_t *attr = get_ia32_attr_const(node);
        return attr->data.am_scale;
 }
@@ -559,9 +573,9 @@ int get_ia32_am_scale(const ir_node *node) {
 /**
  * Sets the index register scale for address mode.
  */
-void set_ia32_am_scale(ir_node *node, int scale) {
+void set_ia32_am_scale(ir_node *node, unsigned scale) {
        ia32_attr_t *attr = get_ia32_attr(node);
-       assert(0 <= scale && scale < 4 && "AM scale out of range");
+       assert(scale <= 3 && "AM scale out of range [0 ... 3]");
        attr->data.am_scale = scale;
 }
 
@@ -863,15 +877,27 @@ void set_ia32_exc_label_id(ir_node *node, ir_label_t id) {
 /**
  * Returns the name of the original ir node.
  */
-const char *get_ia32_orig_node(const ir_node *node) {
+const char *get_ia32_orig_node(const ir_node *node)
+{
        const ia32_attr_t *attr = get_ia32_attr_const(node);
        return attr->orig_node;
 }
 
+static const char *ia32_get_old_node_name(const ir_node *irn)
+{
+       struct obstack *obst = env_cg->isa->name_obst;
+
+       lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
+       obstack_1grow(obst, 0);
+       return obstack_finish(obst);
+}
+
 /**
  * Sets the name of the original ir node.
  */
-void set_ia32_orig_node(ir_node *node, const char *name) {
+void set_ia32_orig_node(ir_node *node, const ir_node *old)
+{
+       const char  *name = ia32_get_old_node_name(old);
        ia32_attr_t *attr = get_ia32_attr(node);
        attr->orig_node   = name;
 }
@@ -982,7 +1008,7 @@ init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
        attr->offset   = offset;
 }
 
-void init_ia32_call_attributes(ir_node *const res, unsigned const pop, ir_type *const call_tp)
+void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
 {
        ia32_call_attr_t *attr = get_irn_generic_attr(res);
 
@@ -1013,6 +1039,16 @@ init_ia32_condcode_attributes(ir_node *res, long pnc) {
        attr->pn_code = pnc;
 }
 
+void
+init_ia32_climbframe_attributes(ir_node *res, unsigned count) {
+       ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
+
+#ifndef NDEBUG
+       attr->attr.attr_type  |= IA32_ATTR_ia32_climbframe_attr_t;
+#endif
+       attr->count = count;
+}
+
 /***************************************************************************************
  *                  _                            _                   _
  *                 | |                          | |                 | |
@@ -1024,7 +1060,8 @@ init_ia32_condcode_attributes(ir_node *res, long pnc) {
  ***************************************************************************************/
 
 /* default compare operation to compare attributes */
-int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
+int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
+{
        if (a->data.tp != b->data.tp)
                return 1;
 
@@ -1046,9 +1083,6 @@ int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
            || a->frame_ent != b->frame_ent)
                return 1;
 
-       if (a->data.tp != b->data.tp)
-               return 1;
-
        if (a->data.has_except_label != b->data.has_except_label)
                return 1;
 
@@ -1082,12 +1116,13 @@ int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
        attr_a = get_ia32_condcode_attr_const(a);
        attr_b = get_ia32_condcode_attr_const(b);
 
-       if(attr_a->pn_code != attr_b->pn_code)
+       if (attr_a->pn_code != attr_b->pn_code)
                return 1;
 
        return 0;
 }
 
+/** Compare node attributes for call nodes. */
 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
 {
        const ia32_call_attr_t *attr_a;
@@ -1121,7 +1156,7 @@ int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
        attr_a = get_ia32_copyb_attr_const(a);
        attr_b = get_ia32_copyb_attr_const(b);
 
-       if(attr_a->size != attr_b->size)
+       if (attr_a->size != attr_b->size)
                return 1;
 
        return 0;
@@ -1135,7 +1170,7 @@ int ia32_compare_asm_attr(ir_node *a, ir_node *b)
        const ia32_asm_attr_t *attr_a;
        const ia32_asm_attr_t *attr_b;
 
-       if(ia32_compare_nodes_attr(a, b))
+       if (ia32_compare_nodes_attr(a, b))
                return 1;
 
        attr_a = get_ia32_asm_attr_const(a);
@@ -1163,9 +1198,9 @@ int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
        const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
        const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
 
-       if(attr_a->symconst != attr_b->symconst ||
-          attr_a->sc_sign != attr_b->sc_sign ||
-          attr_a->offset != attr_b->offset)
+       if (attr_a->symconst != attr_b->symconst ||
+           attr_a->sc_sign != attr_b->sc_sign ||
+           attr_a->offset != attr_b->offset)
                return 1;
 
        return 0;
@@ -1178,6 +1213,24 @@ int ia32_compare_x87_attr(ir_node *a, ir_node *b)
        return ia32_compare_nodes_attr(a, b);
 }
 
+/** Compare node attributes for ClimbFrame nodes. */
+static
+int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
+{
+       const ia32_climbframe_attr_t *attr_a;
+       const ia32_climbframe_attr_t *attr_b;
+
+       if (ia32_compare_nodes_attr(a, b))
+               return 1;
+
+       attr_a = get_ia32_climbframe_attr_const(a);
+       attr_b = get_ia32_climbframe_attr_const(b);
+
+       if (attr_a->count != attr_b->count)
+               return 1;
+
+       return 0;
+}
 
 /* copies the ia32 attributes */
 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
@@ -1187,9 +1240,7 @@ static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
        const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
        ia32_attr_t       *attr_new = get_ia32_attr(new_node);
        backend_info_t    *old_info = be_get_info(old_node);
-       backend_info_t    *new_info;
-
-       new_info = be_get_info(new_node);
+       backend_info_t    *new_info = be_get_info(new_node);
 
        /* copy the attributes */
        memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));