Revert r28379.
[libfirm] / ir / opt / escape_ana.c
index 8c3d0f8..9d44435 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
 #include "ircons.h"
 #include "irprintf.h"
 #include "debug.h"
+#include "error.h"
 
 /**
  * walker environment
  */
-typedef struct _walk_env {
+typedef struct walk_env {
   ir_node *found_allocs;            /**< list of all found non-escaped allocs */
   ir_node *dead_allocs;             /**< list of all found dead alloc */
   check_alloc_entity_func callback; /**< callback that checks a given entity for allocation */
@@ -61,7 +62,7 @@ typedef struct _walk_env {
 
   /* these fields are only used in the global escape analysis */
   ir_graph *irg;                    /**< the irg for this environment */
-  struct _walk_env *next;           /**< for linking environments */
+  struct walk_env *next;           /**< for linking environments */
 
 } walk_env_t;
 
@@ -91,16 +92,14 @@ static int is_method_leaving_raise(ir_node *raise)
     /* Hmm: no ProjX from a Raise? This should be a verification
      * error. For now we just assert and return.
      */
-    assert(! "No ProjX after Raise found");
-    return 1;
+    panic("No ProjX after Raise found");
   }
 
   if (get_irn_n_outs(proj) != 1) {
     /* Hmm: more than one user of ProjX: This is a verification
      * error.
      */
-    assert(! "More than one user of ProjX");
-    return 1;
+    panic("More than one user of ProjX");
   }
 
   n = get_irn_out(proj, 0);
@@ -279,9 +278,9 @@ static int can_escape(ir_node *n)
  */
 static void find_allocations(ir_node *alloc, void *ctx)
 {
+  walk_env_t *env = (walk_env_t*)ctx;
   int i;
   ir_node *adr;
-  walk_env_t *env = ctx;
 
   if (! is_Alloc(alloc))
     return;
@@ -322,10 +321,10 @@ static void find_allocations(ir_node *alloc, void *ctx)
  */
 static void find_allocation_calls(ir_node *call, void *ctx)
 {
+  walk_env_t *env = (walk_env_t*)ctx;
   int        i;
   ir_node    *adr;
   ir_entity  *ent;
-  walk_env_t *env = ctx;
 
   if (! is_Call(call))
     return;
@@ -386,7 +385,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env)
 
   /* kill all dead allocs */
   for (alloc = env->dead_allocs; alloc; alloc = next) {
-    next = get_irn_link(alloc);
+    next = (ir_node*)get_irn_link(alloc);
 
     DBG((dbgHandle, LEVEL_1, "%+F allocation of %+F unused, deleted.\n", irg, alloc));
 
@@ -403,7 +402,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env)
   /* convert all non-escaped heap allocs into frame variables */
   ftp = get_irg_frame_type(irg);
   for (alloc = env->found_allocs; alloc; alloc = next) {
-    next = get_irn_link(alloc);
+    next = (ir_node*)get_irn_link(alloc);
     size = get_Alloc_count(alloc);
     atp  = get_Alloc_type(alloc);
 
@@ -412,9 +411,8 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env)
       /* if the size is a type size and the types matched */
       assert(atp == get_SymConst_type(size));
       tp = atp;
-    }
-    else if (is_Const(size)) {
-      tarval *tv = get_Const_tarval(size);
+    } else if (is_Const(size)) {
+      ir_tarval *tv = get_Const_tarval(size);
 
       if (tv != tarval_bad && tarval_is_long(tv) &&
           get_type_state(atp) == layout_fixed &&
@@ -480,7 +478,7 @@ static void transform_alloc_calls(ir_graph *irg, walk_env_t *env)
 
   /* kill all dead allocs */
   for (call = env->dead_allocs; call; call = next) {
-    next = get_irn_link(call);
+    next = (ir_node*)get_irn_link(call);
 
     DBG((dbgHandle, LEVEL_1, "%+F allocation of %+F unused, deleted.\n", irg, call));
 
@@ -499,7 +497,7 @@ static void transform_alloc_calls(ir_graph *irg, walk_env_t *env)
   /* convert all non-escaped heap allocs into frame variables */
   ftp = get_irg_frame_type(irg);
   for (call = env->found_allocs; call; call = next) {
-    next = get_irn_link(call);
+    next = (ir_node*)get_irn_link(call);
   }
 }
 
@@ -539,8 +537,7 @@ void escape_enalysis_irg(ir_graph *irg, check_alloc_entity_func callback)
 /* Do simple and fast escape analysis for all graphs. */
 void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback)
 {
-  ir_graph *irg;
-  int i;
+  size_t i, n;
   struct obstack obst;
   walk_env_t *env, *elist;
   (void) run_scalar_replace;
@@ -566,8 +563,8 @@ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback)
   env->dead_allocs  = NULL;
   env->callback     = callback;
 
-  for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-    irg = get_irp_irg(i);
+  for (i = 0, n = get_irp_n_irgs(); i < n; ++i) {
+    ir_graph *irg = get_irp_irg(i);
 
     assure_irg_outs(irg);