Added support for out edges.
[libfirm] / ir / ir / ircons.c
index 7052db0..0669e1d 100644 (file)
@@ -37,6 +37,7 @@
 # include "array.h"
 # include "irbackedge_t.h"
 # include "irflag_t.h"
+# include "iredges_t.h"
 
 #if USE_EXPLICIT_PHI_IN_STACK
 /* A stack needed for the automatic Phi node construction in constructor
@@ -58,7 +59,7 @@ typedef struct Phi_in_stack Phi_in_stack;
 /*
  * language dependant initialization variable
  */
-static default_initialize_local_variable_func_t *default_initialize_local_variable = NULL;
+static uninitialized_local_variable_func_t *default_initialize_local_variable = NULL;
 
 /* -------------------------------------------- */
 /* privat interfaces, for professional use only */
@@ -163,9 +164,13 @@ new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, t
 ir_node *
 new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
 {
-  type *tp = firm_unknown_type;
-  /* removing this somehow causes errors in jack. */
-  return new_rd_Const_type (db, irg, block, mode, con, tp);
+  return new_rd_Const_type (db, irg, block, mode, con, firm_unknown_type);
+}
+
+ir_node *
+new_rd_Const_long (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, long value)
+{
+       return new_rd_Const(db, irg, block, mode, new_tarval_from_long(value, mode));
 }
 
 ir_node *
@@ -227,7 +232,7 @@ new_rd_Cast (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, type *to_
 {
   ir_node *res;
 
-  assert(is_Atomic_type(to_tp));
+  assert(is_atomic_type(to_tp));
 
   res = new_ir_node(db, irg, block, op_Cast, get_irn_mode(op), 1, &op);
   res->attr.cast.totype = to_tp;
@@ -649,7 +654,7 @@ new_rd_Alloc (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
 
 ir_node *
 new_rd_Free (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
-        ir_node *ptr, ir_node *size, type *free_type)
+        ir_node *ptr, ir_node *size, type *free_type, where_alloc where)
 {
   ir_node *in[3];
   ir_node *res;
@@ -657,8 +662,9 @@ new_rd_Free (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
   in[0] = store;
   in[1] = ptr;
   in[2] = size;
-  res = new_ir_node (db, irg, block, op_Free, mode_T, 3, in);
-  res->attr.f = free_type;
+  res = new_ir_node (db, irg, block, op_Free, mode_M, 3, in);
+  res->attr.f.where = where;
+  res->attr.f.type  = free_type;
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -914,6 +920,13 @@ ir_node *new_r_Const  (ir_graph *irg, ir_node *block,
                ir_mode *mode, tarval *con) {
   return new_rd_Const(NULL, irg, block, mode, con);
 }
+
+ir_node *new_r_Const_long(ir_graph *irg, ir_node *block,
+               ir_mode *mode, long value) {
+  return new_rd_Const_long(NULL, irg, block, mode, value);
+}
+
+
 ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
                        symconst_symbol value, symconst_kind symkind) {
   return new_rd_SymConst(NULL, irg, block, value, symkind);
@@ -1028,8 +1041,8 @@ ir_node *new_r_Alloc  (ir_graph *irg, ir_node *block, ir_node *store,
   return new_rd_Alloc(NULL, irg, block, store, size, alloc_type, where);
 }
 ir_node *new_r_Free   (ir_graph *irg, ir_node *block, ir_node *store,
-               ir_node *ptr, ir_node *size, type *free_type) {
-  return new_rd_Free(NULL, irg, block, store, ptr, size, free_type);
+               ir_node *ptr, ir_node *size, type *free_type, where_alloc where) {
+  return new_rd_Free(NULL, irg, block, store, ptr, size, free_type, where);
 }
 ir_node *new_r_Sync   (ir_graph *irg, ir_node *block, int arity, ir_node **in) {
   return new_rd_Sync(NULL, irg, block, arity, in);
@@ -1332,6 +1345,7 @@ new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int i
 #if USE_EXPLICIT_PHI_IN_STACK
     free_to_Phi_in_stack(res);
 #else
+               edges_node_deleted(res, current_ir_graph);
     obstack_free (current_ir_graph->obst, res);
 #endif
     res = known;
@@ -1555,6 +1569,7 @@ new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
   /* i==ins: there is at most one predecessor, we don't need a phi node. */
   if (i == ins) {
     if (res != known) {
+                       edges_node_deleted(res, current_ir_graph);
       obstack_free (current_ir_graph->obst, res);
       if (is_Phi(known)) {
        /* If pred is a phi node we want to optmize it: If loops are matured in a bad
@@ -1738,7 +1753,7 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
          before recuring.
       */
       if (default_initialize_local_variable)
-        block->attr.block.graph_arr[pos] = default_initialize_local_variable(mode, pos - 1);
+        block->attr.block.graph_arr[pos] = default_initialize_local_variable(current_ir_graph, mode, pos - 1);
       else
         block->attr.block.graph_arr[pos] = new_Const(mode, tarval_bad);
       /* We don't need to care about exception ops in the start block.
@@ -1975,6 +1990,12 @@ new_d_Const (dbg_info* db, ir_mode *mode, tarval *con)
 }
 
 ir_node *
+new_d_Const_long(dbg_info* db, ir_mode *mode, long value)
+{
+  return new_rd_Const_long(db, current_ir_graph, current_ir_graph->start_block, mode, value);
+}
+
+       ir_node *
 new_d_Const_type (dbg_info* db, ir_mode *mode, tarval *con, type *tp)
 {
   return new_rd_Const_type(db, current_ir_graph, current_ir_graph->start_block,
@@ -2277,10 +2298,11 @@ new_d_Alloc (dbg_info* db, ir_node *store, ir_node *size, type *alloc_type,
 }
 
 ir_node *
-new_d_Free (dbg_info* db, ir_node *store, ir_node *ptr, ir_node *size, type *free_type)
+new_d_Free (dbg_info* db, ir_node *store, ir_node *ptr,
+    ir_node *size, type *free_type, where_alloc where)
 {
   return new_rd_Free (db, current_ir_graph, current_ir_graph->current_block,
-             store, ptr, size, free_type);
+             store, ptr, size, free_type, where);
 }
 
 ir_node *
@@ -2331,7 +2353,7 @@ new_d_Sync (dbg_info* db, int arity, ir_node** in)
 ir_node *
 (new_d_Bad)(void)
 {
-  return __new_d_Bad();
+  return _new_d_Bad();
 }
 
 ir_node *
@@ -2387,7 +2409,7 @@ new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj)
 ir_node *
 (new_d_NoMem)(void)
 {
-  return __new_d_NoMem();
+  return _new_d_NoMem();
 }
 
 ir_node *
@@ -2528,7 +2550,7 @@ type *get_cur_frame_type() {
 
 /* call once for each run of the library */
 void
-init_cons (default_initialize_local_variable_func_t *func)
+init_cons(uninitialized_local_variable_func_t *func)
 {
   default_initialize_local_variable = func;
 }
@@ -2565,6 +2587,11 @@ ir_node *new_Const  (ir_mode *mode, tarval *con) {
   return new_d_Const(NULL, mode, con);
 }
 
+ir_node *new_Const_long(ir_mode *mode, long value)
+{
+       return new_d_Const_long(NULL, mode, value);
+}
+
 ir_node *new_Const_type(tarval *con, type *tp) {
   return new_d_Const_type(NULL, get_type_mode(tp), con, tp);
 }
@@ -2661,8 +2688,8 @@ ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
   return new_d_Alloc(NULL, store, size, alloc_type, where);
 }
 ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
-             type *free_type) {
-  return new_d_Free(NULL, store, ptr, size, free_type);
+             type *free_type, where_alloc where) {
+  return new_d_Free(NULL, store, ptr, size, free_type, where);
 }
 ir_node *new_Sync   (int arity, ir_node **in) {
   return new_d_Sync(NULL, arity, in);