removed INLIEN before global functions
[libfirm] / ir / ir / ircons.c
index adf1739..7966d17 100644 (file)
  */
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
+#endif
+
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
 #endif
 
 # include "irgraph_t.h"
@@ -25,8 +35,6 @@
 # include "iropt_t.h"
 # include "irgmod.h"
 # include "array.h"
-/* memset belongs to string.h */
-# include "string.h"
 # include "irbackedge_t.h"
 # include "irflag_t.h"
 
@@ -52,8 +60,9 @@ typedef struct Phi_in_stack Phi_in_stack;
  */
 static default_initialize_local_variable_func_t *default_initialize_local_variable = NULL;
 
-/*** ******************************************** */
-/** privat interfaces, for professional use only */
+/* -------------------------------------------- */
+/* privat interfaces, for professional use only */
+/* -------------------------------------------- */
 
 /* Constructs a Block with a fixed number of predecessors.
    Does not set current_block.  Can not be used with automatic
@@ -69,9 +78,10 @@ new_rd_Block (dbg_info* db, ir_graph *irg,  int arity, ir_node **in)
 
   /* res->attr.block.exc = exc_normal; */
   /* res->attr.block.handler_entry = 0; */
-  res->attr.block.irg = irg;
-  res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
-  res->attr.block.in_cg = NULL;
+  res->attr.block.dead        = 0;
+  res->attr.block.irg         = irg;
+  res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
+  res->attr.block.in_cg       = NULL;
   res->attr.block.cg_backedge = NULL;
 
   IRN_VRFY_IRG(res, irg);
@@ -153,11 +163,8 @@ new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, t
 INLINE ir_node *
 new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
 {
-  type *tp = unknown_type;
+  type *tp = firm_unknown_type;
   /* removing this somehow causes errors in jack. */
-  if (tarval_is_entity(con))
-    tp = find_pointer_type_to_type(get_entity_type(get_tarval_entity(con)));
-
   return new_rd_Const_type (db, irg, block, mode, con, tp);
 }
 
@@ -183,7 +190,7 @@ new_rd_Proj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode
 
   assert(res);
   assert(get_Proj_pred(res));
-  assert(get_nodes_Block(get_Proj_pred(res)));
+  assert(get_nodes_block(get_Proj_pred(res)));
 
   res = optimize_node(res);
 
@@ -220,6 +227,8 @@ 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));
+
   res = new_ir_node(db, irg, block, op_Cast, get_irn_mode(op), 1, &op);
   res->attr.cast.totype = to_tp;
   res = optimize_node(res);
@@ -543,9 +552,10 @@ new_rd_Call (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
 
   res = new_ir_node(db, irg, block, op_Call, mode_T, r_arity, r_in);
 
-  assert(is_method_type(tp));
+  assert((get_unknown_type() == tp) || is_method_type(tp));
   set_Call_type(res, tp);
-  res->attr.call.callee_arr = NULL;
+  res->attr.call.exc.pin_state = op_pin_state_pinned;
+  res->attr.call.callee_arr    = NULL;
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -585,7 +595,7 @@ new_rd_Raise (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_no
 
 INLINE ir_node *
 new_rd_Load (dbg_info* db, ir_graph *irg, ir_node *block,
-        ir_node *store, ir_node *adr)
+        ir_node *store, ir_node *adr, ir_mode *mode)
 {
   ir_node *in[2];
   ir_node *res;
@@ -593,6 +603,9 @@ new_rd_Load (dbg_info* db, ir_graph *irg, ir_node *block,
   in[0] = store;
   in[1] = adr;
   res = new_ir_node(db, irg, block, op_Load, mode_T, 2, in);
+  res->attr.load.exc.pin_state = op_pin_state_pinned;
+  res->attr.load.load_mode     = mode;
+  res->attr.load.volatility    = volatility_non_volatile;
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -609,6 +622,8 @@ new_rd_Store (dbg_info* db, ir_graph *irg, ir_node *block,
   in[1] = adr;
   in[2] = val;
   res = new_ir_node(db, irg, block, op_Store, mode_T, 3, in);
+  res->attr.store.exc.pin_state = op_pin_state_pinned;
+  res->attr.store.volatility    = volatility_non_volatile;
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -624,8 +639,9 @@ new_rd_Alloc (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
   in[0] = store;
   in[1] = size;
   res = new_ir_node(db, irg, block, op_Alloc, mode_T, 2, in);
-  res->attr.a.where = where;
-  res->attr.a.type  = alloc_type;
+  res->attr.a.exc.pin_state = op_pin_state_pinned;
+  res->attr.a.where         = where;
+  res->attr.a.type          = alloc_type;
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -693,8 +709,7 @@ new_rd_InstOf (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
 
 INLINE 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;
 
@@ -702,6 +717,7 @@ new_rd_SymConst_type (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symb
     mode = mode_P_mach;
   else
     mode = mode_Iu;
+
   res = new_ir_node(db, irg, block, op_SymConst, mode, 0, NULL);
 
   res->attr.i.num = symkind;
@@ -717,7 +733,7 @@ INLINE ir_node *
 new_rd_SymConst (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symbol value,
                 symconst_kind symkind)
 {
-  ir_node *res = new_rd_SymConst_type(db, irg, block, value, symkind, unknown_type);
+  ir_node *res = new_rd_SymConst_type(db, irg, block, value, symkind, firm_unknown_type);
   return res;
 }
 
@@ -839,32 +855,32 @@ new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mod
 
   assert(res);
   assert(get_Proj_pred(res));
-  assert(get_nodes_Block(get_Proj_pred(res)));
+  assert(get_nodes_block(get_Proj_pred(res)));
 
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
+}
 
+INLINE ir_node *
+new_rd_NoMem (ir_graph *irg) {
+  return irg->no_mem;
 }
 
-ir_node *
-new_rd_FuncCall (dbg_info* db, ir_graph *irg, ir_node *block,
-        ir_node *callee, int arity, ir_node **in, type *tp)
+INLINE ir_node *
+new_rd_Mux  (dbg_info *db, ir_graph *irg, ir_node *block,
+    ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode)
 {
-  ir_node **r_in;
+  ir_node *in[3];
   ir_node *res;
-  int r_arity;
 
-  r_arity = arity+1;
-  NEW_ARR_A(ir_node *, r_in, r_arity);
-  r_in[0] = callee;
-  memcpy(&r_in[1], in, sizeof (ir_node *) * arity);
+  in[0] = sel;
+  in[1] = ir_false;
+  in[2] = ir_true;
 
-  res = new_ir_node(db, irg, block, op_FuncCall, mode_T, r_arity, r_in);
+  res = new_ir_node(db, irg, block, op_Mux, mode, 3, in);
+  assert(res);
 
-  assert(is_method_type(tp));
-  set_FuncCall_type(res, tp);
-  res->attr.call.callee_arr = NULL;
   res = optimize_node(res);
   IRN_VRFY_IRG(res, irg);
   return res;
@@ -1000,8 +1016,8 @@ INLINE ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
   return new_rd_Phi(NULL, irg, block, arity, in, mode);
 }
 INLINE ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
-               ir_node *store, ir_node *adr) {
-  return new_rd_Load(NULL, irg, block, store, adr);
+               ir_node *store, ir_node *adr, ir_mode *mode) {
+  return new_rd_Load(NULL, irg, block, store, adr, mode);
 }
 INLINE ir_node *new_r_Store  (ir_graph *irg, ir_node *block,
                ir_node *store, ir_node *adr, ir_node *val) {
@@ -1059,10 +1075,12 @@ INLINE ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
                ir_mode *mode, long proj) {
   return new_rd_Filter(NULL, irg, block, arg, mode, proj);
 }
-INLINE ir_node *new_r_FuncCall (ir_graph *irg, ir_node *block,
-                  ir_node *callee, int arity, ir_node **in,
-                  type *tp) {
-  return new_rd_FuncCall(NULL, irg, block, callee, arity, in, tp);
+INLINE ir_node *new_r_NoMem  (ir_graph *irg) {
+  return new_rd_NoMem(irg);
+}
+INLINE ir_node *new_r_Mux (ir_graph *irg, ir_node *block,
+    ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
+  return new_rd_Mux(NULL, irg, block, sel, ir_false, ir_true, mode);
 }
 
 
@@ -1147,7 +1165,7 @@ new_d_Block (dbg_info* db, int arity, ir_node **in)
 
   Call Graph:   ( A ---> B == A "calls" B)
 
-       get_value         mature_block
+       get_value         mature_immBlock
           |                   |
           |                   |
           |                   |
@@ -1369,7 +1387,7 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
      The call order
        get_value    (makes Phi0, put's it into graph_arr)
        set_value    (overwrites Phi0 in graph_arr)
-       mature_block (upgrades Phi0, puts it again into graph_arr, overwriting
+       mature_immBlock (upgrades Phi0, puts it again into graph_arr, overwriting
                      the proper value.)
      fails. */
   if (!block->attr.block.graph_arr[pos]) {
@@ -1460,7 +1478,7 @@ get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
     /* The block is not mature, we don't know how many in's are needed.  A Phi
        with zero predecessors is created.  Such a Phi node is called Phi0
        node.  (There is also an obsolete Phi0 opcode.) The Phi0 is then added
-       to the list of Phi0 nodes in this block to be matured by mature_block
+       to the list of Phi0 nodes in this block to be matured by mature_immBlock
        later.
        The Phi0 has to remember the pos of it's internal value.  If the real
        Phi is computed, pos is used to update the array with the local
@@ -1606,14 +1624,22 @@ static INLINE ir_node ** new_frag_arr (ir_node *n)
   return arr;
 }
 
+/**
+ * returns the frag_arr from a node
+ */
 static INLINE ir_node **
 get_frag_arr (ir_node *n) {
-  if (get_irn_op(n) == op_Call) {
-    return n->attr.call.frag_arr;
-  } else if (get_irn_op(n) == op_Alloc) {
-    return n->attr.a.frag_arr;
-  } else {
-    return n->attr.frag_arr;
+  switch (get_irn_opcode(n)) {
+  case iro_Call:
+    return n->attr.call.exc.frag_arr;
+  case iro_Alloc:
+    return n->attr.a.exc.frag_arr;
+  case iro_Load:
+    return n->attr.load.exc.frag_arr;
+  case iro_Store:
+    return n->attr.store.exc.frag_arr;
+  default:
+    return n->attr.except.frag_arr;
   }
 }
 
@@ -1764,7 +1790,7 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
      optimization possibilities.
      The Phi0 node either is allocated in this function, or it comes from
      a former call to get_r_value_internal. In this case we may not yet
-     exchange phi0, as this is done in mature_block. */
+     exchange phi0, as this is done in mature_immBlock. */
   if (!phi0) {
     phi0_all = block->attr.block.graph_arr[pos];
     if (!((get_irn_op(phi0_all) == op_Phi) &&
@@ -1861,7 +1887,7 @@ get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
     /* The block is not mature, we don't know how many in's are needed.  A Phi
        with zero predecessors is created.  Such a Phi node is called Phi0
        node.  The Phi0 is then added to the list of Phi0 nodes in this block
-       to be matured by mature_block later.
+       to be matured by mature_immBlock later.
        The Phi0 has to remember the pos of it's internal value.  If the real
        Phi is computed, pos is used to update the array with the local
        values. */
@@ -1893,7 +1919,7 @@ get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
 /** Finalize a Block node, when all control flows are known.  */
 /** Acceptable parameters are only Block nodes.               */
 void
-mature_block (ir_node *block)
+mature_immBlock (ir_node *block)
 {
 
   int ins;
@@ -2050,8 +2076,9 @@ new_d_Quot (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
   ir_node *res;
   res = new_rd_Quot (db, current_ir_graph, current_ir_graph->current_block,
              memop, op1, op2);
+  res->attr.except.pin_state = op_pin_state_pinned;
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Quot, &res->attr.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Quot, &res->attr.except.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2063,8 +2090,9 @@ new_d_DivMod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
   ir_node *res;
   res = new_rd_DivMod (db, current_ir_graph, current_ir_graph->current_block,
                memop, op1, op2);
+  res->attr.except.pin_state = op_pin_state_pinned;
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_DivMod, &res->attr.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2076,8 +2104,9 @@ new_d_Div (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
   ir_node *res;
   res = new_rd_Div (db, current_ir_graph, current_ir_graph->current_block,
             memop, op1, op2);
+  res->attr.except.pin_state = op_pin_state_pinned;
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Div, &res->attr.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Div, &res->attr.except.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2089,8 +2118,9 @@ new_d_Mod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
   ir_node *res;
   res = new_rd_Mod (db, current_ir_graph, current_ir_graph->current_block,
             memop, op1, op2);
+  res->attr.except.pin_state = op_pin_state_pinned;
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Mod, &res->attr.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Mod, &res->attr.except.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2186,7 +2216,7 @@ new_d_Call (dbg_info* db, ir_node *store, ir_node *callee, int arity, ir_node **
   res = new_rd_Call (db, current_ir_graph, current_ir_graph->current_block,
              store, callee, arity, in, tp);
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Call, &res->attr.call.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2207,13 +2237,13 @@ new_d_Raise (dbg_info* db, ir_node *store, ir_node *obj)
 }
 
 ir_node *
-new_d_Load (dbg_info* db, ir_node *store, ir_node *addr)
+new_d_Load (dbg_info* db, ir_node *store, ir_node *addr, ir_mode *mode)
 {
   ir_node *res;
   res = new_rd_Load (db, current_ir_graph, current_ir_graph->current_block,
-             store, addr);
+             store, addr, mode);
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Load, &res->attr.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2226,7 +2256,7 @@ new_d_Store (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val)
   res = new_rd_Store (db, current_ir_graph, current_ir_graph->current_block,
               store, addr, val);
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Store, &res->attr.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2240,7 +2270,7 @@ new_d_Alloc (dbg_info* db, ir_node *store, ir_node *size, type *alloc_type,
   res = new_rd_Alloc (db, current_ir_graph, current_ir_graph->current_block,
               store, size, alloc_type, where);
 #if PRECISE_EXC_CONTEXT
-  allocate_frag_arr(res, op_Alloc, &res->attr.a.frag_arr);  /* Could be optimized away. */
+  allocate_frag_arr(res, op_Alloc, &res->attr.a.exc.frag_arr);  /* Could be optimized away. */
 #endif
 
   return res;
@@ -2355,14 +2385,16 @@ new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj)
 }
 
 ir_node *
-new_d_FuncCall (dbg_info* db, ir_node *callee, int arity, ir_node **in,
-      type *tp)
+(new_d_NoMem)(void)
 {
-  ir_node *res;
-  res = new_rd_FuncCall (db, current_ir_graph, current_ir_graph->current_block,
-             callee, arity, in, tp);
+  return __new_d_NoMem();
+}
 
-  return res;
+ir_node *
+new_d_Mux (dbg_info *db, ir_node *sel, ir_node *ir_false,
+    ir_node *ir_true, ir_mode *mode) {
+  return new_rd_Mux (db, current_ir_graph, current_ir_graph->current_block,
+      sel, ir_false, ir_true, mode);
 }
 
 /* ********************************************************************* */
@@ -2379,12 +2411,13 @@ ir_node *new_d_immBlock (dbg_info* db) {
   /* creates a new dynamic in-array as length of in is -1 */
   res = new_ir_node (db, current_ir_graph, NULL, op_Block, mode_BB, -1, NULL);
   current_ir_graph->current_block = res;
-  res->attr.block.matured = 0;
+  res->attr.block.matured     = 0;
+  res->attr.block.dead        = 0;
   /* res->attr.block.exc = exc_normal; */
   /* res->attr.block.handler_entry = 0; */
-  res->attr.block.irg = current_ir_graph;
-  res->attr.block.backedge = NULL;
-  res->attr.block.in_cg = NULL;
+  res->attr.block.irg         = current_ir_graph;
+  res->attr.block.backedge    = NULL;
+  res->attr.block.in_cg       = NULL;
   res->attr.block.cg_backedge = NULL;
   set_Block_block_visited(res, 0);
 
@@ -2406,7 +2439,7 @@ new_immBlock (void) {
 
 /* add an adge to a jmp/control flow node */
 void
-add_in_edge (ir_node *block, ir_node *jmp)
+add_immBlock_pred (ir_node *block, ir_node *jmp)
 {
   if (block->attr.block.matured) {
     assert(0 && "Error: Block already matured!\n");
@@ -2419,7 +2452,7 @@ add_in_edge (ir_node *block, ir_node *jmp)
 
 /* changing the current block */
 void
-switch_block (ir_node *target)
+set_cur_block (ir_node *target)
 {
   current_ir_graph->current_block = target;
 }
@@ -2479,7 +2512,7 @@ keep_alive (ir_node *ka)
 
 /** Useful access routines **/
 /* Returns the current block of the current graph.  To set the current
-   block use switch_block(). */
+   block use set_cur_block. */
 ir_node *get_cur_block() {
   return get_irg_current_block(current_ir_graph);
 }
@@ -2531,6 +2564,11 @@ ir_node *new_Raise  (ir_node *store, ir_node *obj) {
 ir_node *new_Const  (ir_mode *mode, tarval *con) {
   return new_d_Const(NULL, mode, con);
 }
+
+ir_node *new_Const_type(tarval *con, type *tp) {
+  return new_d_Const_type(NULL, get_type_mode(tp), con, tp);
+}
+
 ir_node *new_SymConst (symconst_symbol value, symconst_kind kind) {
   return new_d_SymConst(NULL, value, kind);
 }
@@ -2612,8 +2650,8 @@ ir_node *new_Cast   (ir_node *op, type *to_tp) {
 ir_node *new_Phi    (int arity, ir_node **in, ir_mode *mode) {
   return new_d_Phi(NULL, arity, in, mode);
 }
-ir_node *new_Load   (ir_node *store, ir_node *addr) {
-  return new_d_Load(NULL, store, addr);
+ir_node *new_Load   (ir_node *store, ir_node *addr, ir_mode *mode) {
+  return new_d_Load(NULL, store, addr, mode);
 }
 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val) {
   return new_d_Store(NULL, store, addr, val);
@@ -2665,6 +2703,9 @@ ir_node *new_Break  (void) {
 ir_node *new_Filter (ir_node *arg, ir_mode *mode, long proj) {
   return new_d_Filter(NULL, arg, mode, proj);
 }
-ir_node *new_FuncCall (ir_node *callee, int arity, ir_node **in, type *tp) {
-  return new_d_FuncCall(NULL, callee, arity, in, tp);
+ir_node *new_NoMem  (void) {
+  return new_d_NoMem();
+}
+ir_node *new_Mux (ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
+  return new_d_Mux(NULL, sel, ir_false, ir_true, mode);
 }