use tv_t.h instead of tv.h
[libfirm] / ir / ir / ircons.c
index 7052db0..a9f161d 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #endif
 
+# include "irprog_t.h"
 # include "irgraph_t.h"
 # include "irnode_t.h"
 # include "irmode_t.h"
@@ -37,6 +38,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 +60,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 */
@@ -83,6 +85,7 @@ new_rd_Block (dbg_info* db, ir_graph *irg,  int arity, ir_node **in)
   res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
   res->attr.block.in_cg       = NULL;
   res->attr.block.cg_backedge = NULL;
+  res->attr.block.extblk      = NULL;
 
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -163,9 +166,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 +234,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;
@@ -279,7 +286,7 @@ new_rd_Sub (dbg_info* db, ir_graph *irg, ir_node *block,
 
 ir_node *
 new_rd_Minus (dbg_info* db, ir_graph *irg, ir_node *block,
-         ir_node *op, ir_mode *mode)
+              ir_node *op, ir_mode *mode)
 {
   ir_node *res;
 
@@ -649,7 +656,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 +664,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;
@@ -709,7 +717,7 @@ new_rd_InstOf (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
 
 ir_node *
 new_rd_SymConst_type (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symbol value,
-                     symconst_kind symkind, type *tp) {
+              symconst_kind symkind, type *tp) {
   ir_node *res;
   ir_mode *mode;
 
@@ -731,7 +739,7 @@ new_rd_SymConst_type (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symb
 
 ir_node *
 new_rd_SymConst (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symbol value,
-                symconst_kind symkind)
+         symconst_kind symkind)
 {
   ir_node *res = new_rd_SymConst_type(db, irg, block, value, symkind, firm_unknown_type);
   return res;
@@ -914,6 +922,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 +1043,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);
@@ -1137,7 +1152,7 @@ new_d_Block (dbg_info* db, int arity, ir_node **in)
   /* Create and initialize array for Phi-node construction. */
   if (get_irg_phase_state(current_ir_graph) == phase_building) {
     res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
-                                         current_ir_graph->n_loc);
+                      current_ir_graph->n_loc);
     memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
   }
 
@@ -1317,9 +1332,9 @@ new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int i
      If so, it is a real Phi node and we break the loop.  Else the Phi
      node merges the same definition on several paths and therefore is
      not needed. */
-  for (i = 0;  i < ins;  ++i)
-  {
-    if (in[i] == res || in[i] == known) continue;
+  for (i = 0;  i < ins;  ++i) {
+    if (in[i] == res || in[i] == known)
+      continue;
 
     if (known == res)
       known = in[i];
@@ -1332,7 +1347,8 @@ 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
-    obstack_free (current_ir_graph->obst, res);
+    edges_node_deleted(res, current_ir_graph);
+    obstack_free(current_ir_graph->obst, res);
 #endif
     res = known;
   } else {
@@ -1519,7 +1535,7 @@ void free_Phi_in_stack(Phi_in_stack *s) { }
 
 static INLINE ir_node *
 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
-              ir_node **in, int ins, ir_node *phi0)
+           ir_node **in, int ins, ir_node *phi0)
 {
   int i;
   ir_node *res, *known;
@@ -1555,15 +1571,18 @@ 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
-          order, an enclosing Phi know may get superfluous. */
-       res = optimize_in_place_2(known);
-       if (res != known) { exchange(known, res); }
-      } else {
-       res = known;
+        /* If pred is a phi node we want to optimize it: If loops are matured in a bad
+           order, an enclosing Phi know may get superfluous. */
+        res = optimize_in_place_2(known);
+        if (res != known)
+          exchange(known, res);
+
       }
+      else
+        res = known;
     } else {
       /* A undefined value, e.g., in unreachable code. */
       res = new_Bad();
@@ -1611,11 +1630,11 @@ static INLINE ir_node ** new_frag_arr (ir_node *n)
     arr[0] = new_Proj(n, mode_M, pn_Call_M_except);
   else {
     assert((pn_Quot_M == pn_DivMod_M) &&
-          (pn_Quot_M == pn_Div_M)    &&
-          (pn_Quot_M == pn_Mod_M)    &&
-          (pn_Quot_M == pn_Load_M)   &&
-          (pn_Quot_M == pn_Store_M)  &&
-          (pn_Quot_M == pn_Alloc_M)    );
+       (pn_Quot_M == pn_Div_M)    &&
+       (pn_Quot_M == pn_Mod_M)    &&
+       (pn_Quot_M == pn_Load_M)   &&
+       (pn_Quot_M == pn_Store_M)  &&
+       (pn_Quot_M == pn_Alloc_M)    );
     arr[0] = new_Proj(n, mode_M, pn_Alloc_M);
   }
   set_optimize(opt);
@@ -1738,21 +1757,21 @@ 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.
-        There are none by definition. */
+     There are none by definition. */
       return block->attr.block.graph_arr[pos];
     } else {
       phi0 = new_rd_Phi0(current_ir_graph, block, mode);
       block->attr.block.graph_arr[pos] = phi0;
 #if PRECISE_EXC_CONTEXT
       if (get_opt_precise_exc_context()) {
-       /* Set graph_arr for fragile ops.  Also here we should break recursion.
-          We could choose a cyclic path through an cfop.  But the recursion would
-          break at some point. */
-       set_frag_value(block->attr.block.graph_arr, pos, phi0);
+    /* Set graph_arr for fragile ops.  Also here we should break recursion.
+       We could choose a cyclic path through an cfop.  But the recursion would
+       break at some point. */
+    set_frag_value(block->attr.block.graph_arr, pos, phi0);
       }
 #endif
     }
@@ -1775,9 +1794,9 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
     if (!is_Bad(prevBlock)) {
 #if PRECISE_EXC_CONTEXT
       if (get_opt_precise_exc_context() &&
-         is_fragile_op(prevCfOp) && (get_irn_op (prevCfOp) != op_Bad)) {
-       assert(get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode));
-       nin[i-1] = get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode);
+      is_fragile_op(prevCfOp) && (get_irn_op (prevCfOp) != op_Bad)) {
+    assert(get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode));
+    nin[i-1] = get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode);
       } else
 #endif
       nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
@@ -1794,8 +1813,8 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
   if (!phi0) {
     phi0_all = block->attr.block.graph_arr[pos];
     if (!((get_irn_op(phi0_all) == op_Phi) &&
-         (get_irn_arity(phi0_all) == 0)   &&
-         (get_nodes_block(phi0_all) == block)))
+      (get_irn_arity(phi0_all) == 0)   &&
+      (get_nodes_block(phi0_all) == block)))
       phi0_all = NULL;
   } else {
     phi0_all = phi0;
@@ -1903,7 +1922,7 @@ get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
     printf("Error: no value set.  Use of undefined variable.  Initializing to zero.\n");
     assert (mode->code >= irm_F && mode->code <= irm_P);
     res = new_rd_Const (NULL, current_ir_graph, block, mode,
-                       get_mode_null(mode));
+            get_mode_null(mode));
   }
 
   /* The local valid value is available now. */
@@ -1975,6 +1994,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,
@@ -2062,8 +2087,8 @@ new_d_Mul (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
 static void allocate_frag_arr(ir_node *res, ir_op *op, ir_node ***frag_store) {
   if (get_opt_precise_exc_context()) {
     if ((current_ir_graph->phase_state == phase_building) &&
-       (get_irn_op(res) == op) && /* Could be optimized away. */
-       !*frag_store)    /* Could be a cse where the arr is already set. */ {
+    (get_irn_op(res) == op) && /* Could be optimized away. */
+    !*frag_store)    /* Could be a cse where the arr is already set. */ {
       *frag_store = new_frag_arr(res);
     }
   }
@@ -2277,10 +2302,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 +2357,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 +2413,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,17 +2554,28 @@ 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;
 }
 
 /* call for each graph */
 void
-finalize_cons (ir_graph *irg) {
+irg_finalize_cons (ir_graph *irg) {
   irg->phase_state = phase_high;
 }
 
+void
+irp_finalize_cons (void) {
+  int i, n_irgs = get_irp_n_irgs();
+  for (i = 0; i < n_irgs; i++) {
+    irg_finalize_cons(get_irp_irg(i));
+  }
+  irp->phase_state = phase_high;\
+}
+
+
+
 
 ir_node *new_Block(int arity, ir_node **in) {
   return new_d_Block(NULL, arity, in);
@@ -2565,6 +2602,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 +2703,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);