replaced all recursive computed_value calls ba value_of()
[libfirm] / ir / ir / irnode.c
index 5812682..901bd90 100644 (file)
@@ -155,6 +155,8 @@ int
   return __get_irn_inter_arity(node);
 }
 
+int (*__get_irn_arity)(const ir_node *node) = __get_irn_intra_arity;
+
 int
 (get_irn_arity)(const ir_node *node) {
   return __get_irn_arity(node);
@@ -169,7 +171,7 @@ int
 ir_node **
 get_irn_in (const ir_node *node) {
   assert(node);
-  if (interprocedural_view) { /* handle Filter and Block specially */
+  if (get_interprocedural_view()) { /* handle Filter and Block specially */
     if (get_irn_opcode(node) == iro_Filter) {
       assert(node->attr.filter.in_cg);
       return node->attr.filter.in_cg;
@@ -185,7 +187,7 @@ void
 set_irn_in (ir_node *node, int arity, ir_node **in) {
   ir_node *** arr;
   assert(node);
-  if (interprocedural_view) { /* handle Filter and Block specially */
+  if (get_interprocedural_view()) { /* handle Filter and Block specially */
     if (get_irn_opcode(node) == iro_Filter) {
       assert(node->attr.filter.in_cg);
       arr = &node->attr.filter.in_cg;
@@ -216,14 +218,17 @@ ir_node *
   return __get_irn_inter_n (node, n);
 }
 
+ir_node *(*__get_irn_n)(ir_node *node, int n) = __get_irn_intra_n;
+
 ir_node *
 (get_irn_n)(ir_node *node, int n) {
-  return __get_irn_n (node, n);
+  return __get_irn_n(node, n);
 }
 
 void
 set_irn_n (ir_node *node, int n, ir_node *in) {
-  assert(node && -1 <= n && n < get_irn_arity(node));
+  assert(node && node->kind == k_ir_node && -1 <= n && n < get_irn_arity(node));
+  assert(in && in->kind == k_ir_node);
   if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) {
     /* Change block pred in both views! */
     node->in[n + 1] = in;
@@ -231,7 +236,7 @@ set_irn_n (ir_node *node, int n, ir_node *in) {
     node->attr.filter.in_cg[n + 1] = in;
     return;
   }
-  if (interprocedural_view) { /* handle Filter and Block specially */
+  if (get_interprocedural_view()) { /* handle Filter and Block specially */
     if (get_irn_opcode(node) == iro_Filter) {
       assert(node->attr.filter.in_cg);
       node->attr.filter.in_cg[n + 1] = in;
@@ -352,6 +357,21 @@ void *
   return __get_irn_link(node);
 }
 
+op_pin_state
+(get_irn_pinned)(const ir_node *node) {
+  return __get_irn_pinned(node);
+}
+
+void set_irn_pinned(ir_node *node, op_pin_state state) {
+  /* due to optimization an opt may be turned into a Tuple */
+  if (get_irn_op(node) == op_Tuple)
+    return;
+
+  assert(node && get_op_pinned(get_irn_op(node)) == op_pin_state_exc_pinned);
+  assert(state == op_pin_state_pinned || state == op_pin_state_floats);
+
+  node->attr.except.pin_state = state;
+}
 
 #ifdef DO_HEAPANALYSIS
 /* Access the abstract interpretation information of a node.
@@ -379,7 +399,7 @@ get_irn_node_nr(const ir_node *node) {
 #ifdef DEBUG_libfirm
   return node->node_nr;
 #else
-  return (long)&node;
+  return (long)node;
 #endif
 }
 
@@ -453,17 +473,39 @@ get_irn_block_attr (ir_node *node)
   return node->attr.block;
 }
 
+load_attr
+get_irn_load_attr (ir_node *node)
+{
+  assert (node->op == op_Load);
+  return node->attr.load;
+}
+
+store_attr
+get_irn_store_attr (ir_node *node)
+{
+  assert (node->op == op_Store);
+  return node->attr.store;
+}
+
+except_attr
+get_irn_except_attr (ir_node *node)
+{
+  assert (node->op == op_Div || node->op == op_Quot ||
+          node->op == op_DivMod || node->op == op_Mod);
+  return node->attr.except;
+}
+
 /** manipulate fields of individual nodes **/
 
 /* this works for all except Block */
 ir_node *
-get_nodes_Block (ir_node *node) {
+get_nodes_block (ir_node *node) {
   assert (!(node->op == op_Block));
   return get_irn_n(node, -1);
 }
 
 void
-set_nodes_Block (ir_node *node, ir_node *block) {
+set_nodes_block (ir_node *node, ir_node *block) {
   assert (!(node->op == op_Block));
   set_irn_n(node, -1, block);
 }
@@ -584,52 +626,6 @@ set_Block_graph_arr (ir_node *node, int pos, ir_node *value) {
   node->attr.block.graph_arr[pos+1] = value;
 }
 
-/* handler handling for Blocks * /
-void
-set_Block_handler (ir_node *block, ir_node *handler)  {
-  assert ((block->op == op_Block));
-  assert ((handler->op == op_Block));
-  block->attr.block.handler_entry = handler;
-}
-
-ir_node *
-get_Block_handler (ir_node *block) {
-  assert ((block->op == op_Block));
-  return (block->attr.block.handler_entry);
-}
-
-/ * handler handling for Nodes * /
-void
-set_Node_handler (ir_node *node, ir_node *handler) {
-  set_Block_handler (get_nodes_Block (node), handler);
-}
-
-ir_node *
-get_Node_handler (ir_node *node) {
-  return (get_Block_handler (get_nodes_Block (node)));
-}
-
-/ * exc_t handling for Blocks * /
-void set_Block_exc (ir_node *block, exc_t exc) {
-  assert ((block->op == op_Block));
-  block->attr.block.exc = exc;
-}
-
-exc_t get_Block_exc (ir_node *block) {
-  assert ((block->op == op_Block));
-  return (block->attr.block.exc);
-}
-
-/ * exc_t handling for Nodes * /
-void set_Node_exc (ir_node *node, exc_t exc) {
-  set_Block_exc (get_nodes_Block (node), exc);
-}
-
-exc_t get_Node_exc (ir_node *node) {
-  return (get_Block_exc (get_nodes_Block (node)));
-}
-*/
-
 void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) {
   assert(node->op == op_Block);
   if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
@@ -639,10 +635,10 @@ void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) {
     {
       /* Fix backedge array.  fix_backedges operates depending on
      interprocedural_view. */
-      bool ipv = interprocedural_view;
-      interprocedural_view = true;
+      int ipv = get_interprocedural_view();
+      set_interprocedural_view(true);
       fix_backedges(current_ir_graph->obst, node);
-      interprocedural_view = ipv;
+      set_interprocedural_view(ipv);
     }
   }
   memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity);
@@ -675,12 +671,6 @@ void remove_Block_cg_cfgpred_arr(ir_node * node) {
   node->attr.block.in_cg = NULL;
 }
 
-/* Start references the irg it is in. */
-ir_graph *
-get_Start_irg(ir_node *node) {
-  return get_irn_irg(node);
-}
-
 void
 set_Start_irg(ir_node *node, ir_graph *irg) {
   assert(node->op == op_Start);
@@ -721,13 +711,6 @@ free_End (ir_node *end) {
                in array afterwards ... */
 }
 
-ir_graph *get_EndReg_irg (ir_node *end) {
-  return get_irn_irg(end);
-}
-
-ir_graph *get_EndExcept_irg  (ir_node *end) {
-  return get_irn_irg(end);
-}
 
 /*
 > Implementing the case construct (which is where the constant Proj node is
@@ -889,12 +872,12 @@ set_Const_type (ir_node *node, type *tp) {
   if (tp != unknown_type) {
     assert (is_atomic_type(tp));
     assert (get_type_mode(tp) == get_irn_mode(node));
-    assert (!tarval_is_entity(get_Const_tarval(node)) ||
-        (is_pointer_type(tp) &&
-         (get_pointer_points_to_type(tp) ==
-          get_entity_type(get_tarval_entity(get_Const_tarval(node))))));
   }
 
+  if ((get_irn_node_nr(node) == 259216) && (tp == unknown_type))
+    assert(0);
+
+
   node->attr.con.tp = tp;
 }
 
@@ -955,7 +938,6 @@ void     set_SymConst_entity (ir_node *node, entity *ent) {
   node->attr.i.sym.entity_p  = ent;
 }
 
-
 union symconst_symbol
 get_SymConst_symbol (ir_node *node) {
   assert (node->op == op_SymConst);
@@ -969,6 +951,18 @@ set_SymConst_symbol (ir_node *node, union symconst_symbol sym) {
   node->attr.i.sym = sym;
 }
 
+type *
+get_SymConst_value_type (ir_node *node) {
+  assert (node->op == op_SymConst);
+  return node->attr.i.tp = skip_tid(node->attr.i.tp);
+}
+
+void
+set_SymConst_value_type (ir_node *node, type *tp) {
+  assert (node->op == op_SymConst);
+  node->attr.i.tp = tp;
+}
+
 ir_node *
 get_Sel_mem (ir_node *node) {
   assert (node->op == op_Sel);
@@ -1147,25 +1141,27 @@ get_Call_type (ir_node *node) {
 void
 set_Call_type (ir_node *node, type *tp) {
   assert (node->op == op_Call);
-  assert (is_method_type(tp));
+  assert ((get_unknown_type() == tp) || is_method_type(tp));
   node->attr.call.cld_tp = tp;
 }
 
 int Call_has_callees(ir_node *node) {
-  return (node->attr.call.callee_arr != NULL);
+  assert(node && node->op == op_Call);
+  return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
+      (node->attr.call.callee_arr != NULL));
 }
 
 int get_Call_n_callees(ir_node * node) {
-  assert(node->op == op_Call && node->attr.call.callee_arr);
+  assert(node && node->op == op_Call && node->attr.call.callee_arr);
   return ARR_LEN(node->attr.call.callee_arr);
 }
 
 entity * get_Call_callee(ir_node * node, int pos) {
-  assert(node->op == op_Call && node->attr.call.callee_arr);
+  assert(pos >= 0 && pos < get_Call_n_callees(node));
   return node->attr.call.callee_arr[pos];
 }
 
-void set_Call_callee_arr(ir_node * node, int n, entity ** arr) {
+void set_Call_callee_arr(ir_node * node, const int n, entity ** arr) {
   assert(node->op == op_Call);
   if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
     node->attr.call.callee_arr = NEW_ARR_D(entity *, current_ir_graph->obst, n);
@@ -1186,9 +1182,6 @@ void set_CallBegin_ptr (ir_node *node, ir_node *ptr) {
   assert(node->op == op_CallBegin);
   set_irn_n(node, 0, ptr);
 }
-ir_graph * get_CallBegin_irg (ir_node *node) {
-  return get_irn_irg(node);
-}
 ir_node * get_CallBegin_call (ir_node *node) {
   assert(node->op == op_CallBegin);
   return node->attr.callbegin.call;
@@ -1260,7 +1253,8 @@ set_FuncCall_type (ir_node *node, type *tp) {
 }
 
 int FuncCall_has_callees(ir_node *node) {
-  return (node->attr.call.callee_arr != NULL);
+  return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
+      (node->attr.call.callee_arr != NULL));
 }
 
 int get_FuncCall_n_callees(ir_node * node) {
@@ -1467,7 +1461,7 @@ int is_Phi (ir_node *n) {
   assert(n);
   op = get_irn_op(n);
 
-  if (op == op_Filter) return interprocedural_view;
+  if (op == op_Filter) return get_interprocedural_view();
 
   if (op == op_Phi)
     return  ((get_irg_phase_state(get_irn_irg(n)) !=  phase_building) ||
@@ -1514,6 +1508,31 @@ set_Phi_pred (ir_node *node, int pos, ir_node *pred) {
   set_irn_n(node, pos, pred);
 }
 
+
+int is_memop(ir_node *node) {
+  return ((get_irn_op(node) == op_Load) || (get_irn_op(node) == op_Store));
+}
+
+ir_node *get_memop_mem (ir_node *node) {
+  assert(is_memop(node));
+  return get_irn_n(node, 0);
+}
+
+void     set_memop_mem (ir_node *node, ir_node *mem) {
+  assert(is_memop(node));
+  set_irn_n(node, 0, mem);
+}
+
+ir_node *get_memop_ptr (ir_node *node) {
+  assert(is_memop(node));
+  return get_irn_n(node, 1);
+}
+
+void     set_memop_ptr (ir_node *node, ir_node *ptr) {
+  assert(is_memop(node));
+  set_irn_n(node, 1, ptr);
+}
+
 ir_node *
 get_Load_mem (ir_node *node) {
   assert (node->op == op_Load);
@@ -1538,6 +1557,30 @@ set_Load_ptr (ir_node *node, ir_node *ptr) {
   set_irn_n(node, 1, ptr);
 }
 
+ir_mode *
+get_Load_mode (ir_node *node) {
+  assert (node->op == op_Load);
+  return node->attr.load.load_mode;
+}
+
+void
+set_Load_mode (ir_node *node, ir_mode *mode) {
+  assert (node->op == op_Load);
+  node->attr.load.load_mode = mode;
+}
+
+ent_volatility
+get_Load_volatility (ir_node *node) {
+  assert (node->op == op_Load);
+  return node->attr.load.volatility;
+}
+
+void
+set_Load_volatility (ir_node *node, ent_volatility volatility) {
+  assert (node->op == op_Load);
+  node->attr.load.volatility = volatility;
+}
+
 
 ir_node *
 get_Store_mem (ir_node *node) {
@@ -1575,6 +1618,19 @@ set_Store_value (ir_node *node, ir_node *value) {
   set_irn_n(node, 2, value);
 }
 
+ent_volatility
+get_Store_volatility (ir_node *node) {
+  assert (node->op == op_Store);
+  return node->attr.store.volatility;
+}
+
+void
+set_Store_volatility (ir_node *node, ent_volatility volatility) {
+  assert (node->op == op_Store);
+  node->attr.store.volatility = volatility;
+}
+
+
 ir_node *
 get_Alloc_mem (ir_node *node) {
   assert (node->op == op_Alloc);
@@ -1885,11 +1941,11 @@ skip_Tuple (ir_node *node) {
 
   if (!get_opt_normalize()) return node;
 
-  node = skip_nop(node);
+  node = skip_Id(node);
   if (get_irn_op(node) == op_Proj) {
-    pred = skip_nop(get_Proj_pred(node));
+    pred = skip_Id(get_Proj_pred(node));
     if (get_irn_op(pred) == op_Proj) /* nested Tuple ? */
-      pred = skip_nop(skip_Tuple(pred));
+      pred = skip_Id(skip_Tuple(pred));
     if (get_irn_op(pred) == op_Tuple)
       return get_Tuple_pred(pred, get_Proj_proj(node));
   }
@@ -1899,7 +1955,7 @@ skip_Tuple (ir_node *node) {
 /** returns operand of node if node is a Cast */
 ir_node *skip_Cast  (ir_node *node) {
   if (node && get_irn_op(node) == op_Cast) {
-    return skip_nop(get_irn_n(node, 0));
+    return skip_Id(get_irn_n(node, 0));
   } else {
     return node;
   }
@@ -1910,7 +1966,7 @@ ir_node *skip_Cast  (ir_node *node) {
    than any other approach, as Id chains are resolved and all point to the real node, or
    all id's are self loops. */
 ir_node *
-skip_nop (ir_node *node) {
+skip_Id (ir_node *node) {
   /* don't assert node !!! */
 
   if (!get_opt_normalize()) return node;
@@ -1924,7 +1980,7 @@ skip_nop (ir_node *node) {
     assert (get_irn_arity (node) > 0);
 
     node->in[0+1] = node;
-    res = skip_nop(rem_pred);
+    res = skip_Id(rem_pred);
     if (res->op == op_Id) /* self-loop */ return node;
 
     node->in[0+1] = res;
@@ -1938,7 +1994,7 @@ skip_nop (ir_node *node) {
    than any other approach, as Id chains are resolved and all point to the real node, or
    all id's are self loops. */
 ir_node *
-skip_nop (ir_node *node) {
+skip_Id (ir_node *node) {
   ir_node *pred;
   /* don't assert node !!! */
 
@@ -1961,7 +2017,7 @@ skip_nop (ir_node *node) {
     assert (get_irn_arity (node) > 0);
 
     node->in[0+1] = node;   /* turn us into a self referencing Id:  shorten Id cycles. */
-    res = skip_nop(rem_pred);
+    res = skip_Id(rem_pred);
     if (res->op == op_Id) /* self-loop */ return node;
 
     node->in[0+1] = res;    /* Turn Id chain into Ids all referencing the chain end. */
@@ -1972,11 +2028,6 @@ skip_nop (ir_node *node) {
 }
 #endif
 
-ir_node *
-skip_Id (ir_node *node) {
-  return skip_nop(node);
-}
-
 int
 is_Bad (ir_node *node) {
   assert(node);
@@ -2008,7 +2059,7 @@ int
 is_Proj (const ir_node *node) {
   assert(node);
   return node->op == op_Proj
-    || (!interprocedural_view && node->op == op_Filter);
+    || (!get_interprocedural_view() && node->op == op_Filter);
 }
 
 /* Returns true if the operation manipulates control flow. */
@@ -2023,10 +2074,6 @@ int is_ip_cfop(ir_node *node) {
   return is_ip_cfopcode(get_irn_op(node));
 }
 
-ir_graph *get_ip_cfop_irg(ir_node *n) {
-  return get_irn_irg(n);
-}
-
 /* Returns true if the operation can change the control flow because
    of an exception. */
 int
@@ -2057,6 +2104,12 @@ ir_node *get_fragile_op_mem(ir_node *node) {
   }
 }
 
+/* Returns true if the operation is a forking control flow operation. */
+int
+is_forking_op(ir_node *node) {
+  return is_op_forking(get_irn_op(node));
+}
+
 #ifdef DEBUG_libfirm
 void dump_irn (ir_node *n) {
   int i, arity = get_irn_arity(n);