Use be_emit_irprintf("%T", x) instead of be_emit_tarval().
[libfirm] / ir / be / ia32 / ia32_intrinsics.c
index d5282df..7410b91 100644 (file)
@@ -22,7 +22,6 @@
  * @brief       This file implements the mapping of 64Bit intrinsic
  *              functions to code or library calls.
  * @author      Michael Beck
- * @version     $Id$
  */
 #include "config.h"
 
@@ -32,6 +31,7 @@
 #include "irnode_t.h"
 #include "ircons.h"
 #include "irprog_t.h"
+#include "iroptimize.h"
 #include "lower_dw.h"
 #include "array.h"
 #include "error.h"
@@ -67,15 +67,15 @@ void ia32_handle_intrinsics(void)
 /**
  * Reroute edges from the pn_Call_T_result proj of a call.
  *
- * @param proj   the pn_Call_T_result Proj
- * @param l_res  the lower 32 bit result
- * @param h_res  the upper 32 bit result or NULL
+ * @param resproj  the pn_Call_T_result Proj
+ * @param l_res    the lower 32 bit result
+ * @param h_res    the upper 32 bit result or NULL
  */
-static void reroute_result(ir_node *proj, ir_node *l_res, ir_node *h_res)
+static void reroute_result(ir_node *resproj, ir_node *l_res, ir_node *h_res)
 {
        const ir_edge_t *edge, *next;
 
-       foreach_out_edge_safe(proj, edge, next) {
+       foreach_out_edge_safe(resproj, edge, next) {
                ir_node *proj = get_edge_src_irn(edge);
                long    pn    = get_Proj_proj(proj);
 
@@ -154,7 +154,6 @@ static void resolve_call(ir_node *call, ir_node *l_res, ir_node *h_res, ir_graph
                        res = new_r_Tuple(block, 2, in);
                }
 
-               turn_into_tuple(call, pn_Call_max);
                /*
                 * Beware:
                 * We do not check here if this call really has exception and regular Proj's.
@@ -167,6 +166,7 @@ static void resolve_call(ir_node *call, ir_node *l_res, ir_node *h_res, ir_graph
                jmp = new_r_Jmp(block);
                set_opt_cse(old_cse);
 
+               turn_into_tuple(call, pn_Call_max+1);
                set_Tuple_pred(call, pn_Call_M,         nomem);
                set_Tuple_pred(call, pn_Call_X_regular, jmp);
                set_Tuple_pred(call, pn_Call_X_except,  new_r_Bad(irg, mode_X));
@@ -408,27 +408,6 @@ static int map_Abs(ir_node *call, void *ctx)
 
 #define ID(x) new_id_from_chars(x, sizeof(x)-1)
 
-static ir_entity *create_compiler_lib_entity(const char *name, ir_type *type)
-{
-       ir_type   *glob   = get_glob_type();
-       ident     *id     = new_id_from_str(name);
-       ir_entity *entity;
-
-       /* Hack: we need to know the type of runtime library we use. Strictly
-          speaking it's not the same as the object-file-format. But in practice
-          the following should be enough */
-       if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O
-                       || be_gas_object_file_format == OBJECT_FILE_FORMAT_COFF) {
-               id = id_mangle3("___", id, "");
-       } else {
-               id = id_mangle3("__", id, "");
-       }
-       entity = new_entity(glob, id, type);
-       set_entity_visibility(entity, ir_visibility_external);
-       set_entity_ld_ident(entity, id);
-       return entity;
-}
-
 /**
  * Maps a Div. Change into a library call.
  */
@@ -446,14 +425,17 @@ static int map_Div(ir_node *call, void *ctx)
                /* 64bit signed Division */
                ent = env->divdi3;
                if (ent == NULL) {
-                       ent = env->divdi3 = create_compiler_lib_entity("divdi3", method);
+                       /* create library entity */
+                       ident *id = ID("__divdi3");
+                       ent = env->divdi3 = create_compilerlib_entity(id, method);
                }
        } else {
                /* 64bit unsigned Division */
                ent = env->udivdi3;
                if (ent == NULL) {
                        /* create library entity */
-                       ent = env->udivdi3 = create_compiler_lib_entity("udivdi3", method);
+                       ident *id = ID("__udivdi3");
+                       ent = env->udivdi3 = create_compilerlib_entity(id, method);
                }
        }
 
@@ -483,14 +465,16 @@ static int map_Mod(ir_node *call, void *ctx)
                ent = env->moddi3;
                if (ent == NULL) {
                        /* create library entity */
-                       ent = env->moddi3 = create_compiler_lib_entity("moddi3", method);
+                       ident *id = ID("__moddi3");
+                       ent = env->moddi3 = create_compilerlib_entity(id, method);
                }
        } else {
                /* 64bit signed Modulo */
                ent = env->umoddi3;
                if (ent == NULL) {
                        /* create library entity */
-                       ent = env->umoddi3 = create_compiler_lib_entity("umoddi3", method);
+                       ident *id = ID("__umoddi3");
+                       ent = env->umoddi3 = create_compilerlib_entity(id, method);
                }
        }
 
@@ -535,7 +519,7 @@ static int map_Conv(ir_node *call, void *ctx)
                        h_res = new_r_Proj(float_to_ll, h_res_mode,
                                                           pn_ia32_l_FloattoLL_res_high);
                } else {
-                       /* convert from float to signed 64bit */
+                       /* Convert from float to unsigned 64bit. */
                        ir_mode   *flt_mode = get_irn_mode(a_f);
                        ir_tarval *flt_tv   = new_tarval_from_str("9223372036854775808", 19, flt_mode);
                        ir_node   *flt_corr = new_r_Const(irg, flt_tv);