Fixed doxygen commnets, converted parameterless functions to (void)
[libfirm] / ir / ir / irnode.c
index 7a6d41e..932ed91 100644 (file)
@@ -1,8 +1,8 @@
 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Authors: Martin Trapp, Christian Schaefer, Goetz Lindenmaier
-**
+* All rights reserved.
+*
+* Authors: Martin Trapp, Christian Schaefer, Goetz Lindenmaier
+*
 */
 
 /* $Id$ */
 
 #include "irnode_t.h"
 #include "irgraph_t.h"
-#include "ident_t.h"
+#include "xp_help.h"
 #include "irmode_t.h"
 #include "typegmod_t.h"
 #include "array.h"
 #include "irbackedge_t.h"
+#include "irdump.h"
 
 #ifdef DEBUG_libfirm
 #include "irprog_t.h"
@@ -247,6 +248,7 @@ set_irn_in (ir_node *node, int arity, ir_node **in) {
     *arr = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
     (*arr)[0] = block;
   }
+  fix_backedges(current_ir_graph->obst, node);
   memcpy((*arr) + 1, in, sizeof(ir_node *) * arity);
 }
 
@@ -257,11 +259,11 @@ set_irn_in (ir_node *node, int arity, ir_node **in) {
    If it is a block, the entry -1 is NULL. */
 INLINE ir_node *
 get_irn_n (ir_node *node, int n) {
-  /* debug @@@ */
+  /* debug @@@
   if (-1 > n || get_irn_arity(node) <= n) {
     printf("pos: %d, arity: %d ", n, get_irn_arity(node));
     DDMN(node);
-  }
+    } */
   assert(node); assert(-1 <= n && n < get_irn_arity(node));
   if (interprocedural_view) { /* handle Filter and Block specially */
     if (get_irn_opcode(node) == iro_Filter) {
@@ -340,6 +342,8 @@ INLINE opcode
 get_irn_opcode (ir_node *node)
 {
   assert (node);
+  assert (k_ir_node == get_kind(node));
+  assert (node -> op);
   return node->op->code;
 }
 
@@ -392,6 +396,10 @@ irn_visited  (ir_node *node) {
 INLINE void
 set_irn_link (ir_node *node, void *link) {
   assert (node);
+  /* Link field is used for Phi construction and various optimizations
+     in iropt. */
+  assert(get_irg_phase_state(current_ir_graph) != phase_building);
+
   node->link = link;
 }
 
@@ -510,13 +518,13 @@ get_Block_n_cfgpreds (ir_node *node) {
 
 INLINE ir_node *
 get_Block_cfgpred (ir_node *node, int pos) {
-  /* debug @@@ */
   assert (node->op == op_Block);
+  /* debug @@@
   if (-1 > pos || get_irn_arity(node) <= pos) {
     dump_ir_block_graph(current_ir_graph);
     printf("pos: %d, arity: %d ", pos, get_irn_arity(node));
     DDMN(node);
-  }
+    } */
   assert(node); assert(-1 <= pos && pos < get_irn_arity(node));
   return get_irn_n(node, pos);
 }
@@ -627,6 +635,14 @@ void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) {
     node->attr.block.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
     node->attr.block.in_cg[0] = NULL;
     node->attr.block.cg_backedge = new_backedge_arr(current_ir_graph->obst, arity);
+    {
+      /* Fix backedge array.  fix_backedges operates depending on
+        interprocedural_view. */
+      bool ipv = interprocedural_view;
+      interprocedural_view = true;
+      fix_backedges(current_ir_graph->obst, node);
+      interprocedural_view = ipv;
+    }
   }
   memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity);
 }
@@ -644,8 +660,8 @@ ir_node ** get_Block_cg_cfgpred_arr(ir_node * node) {
 }
 
 int get_Block_cg_n_cfgpreds(ir_node * node) {
-  assert(node->op == op_Block && node->attr.block.in_cg);
-  return ARR_LEN(node->attr.block.in_cg) - 1;
+  assert(node->op == op_Block);
+  return node->attr.block.in_cg == NULL ? 0 : ARR_LEN(node->attr.block.in_cg) - 1;
 }
 
 ir_node * get_Block_cg_cfgpred(ir_node * node, int pos) {
@@ -859,11 +875,11 @@ get_SymConst_type (ir_node *node) {
 }
 
 INLINE void
-set_SymConst_type (ir_node *node, type *type) {
+set_SymConst_type (ir_node *node, type *tp) {
   assert (   (node->op == op_SymConst)
           && (   get_SymConst_kind(node) == type_tag
               || get_SymConst_kind(node) == size));
-  node->attr.i.tori.typ = type;
+  node->attr.i.tori.typ = tp;
 }
 
 INLINE ident *
@@ -1068,10 +1084,10 @@ get_Call_type (ir_node *node) {
 }
 
 INLINE void
-set_Call_type (ir_node *node, type *type) {
+set_Call_type (ir_node *node, type *tp) {
   assert (node->op == op_Call);
-  assert (is_method_type(type));
-  node->attr.call.cld_tp = type;
+  assert (is_method_type(tp));
+  node->attr.call.cld_tp = tp;
 }
 
 int get_Call_n_callees(ir_node * node) {
@@ -1913,9 +1929,9 @@ get_Alloc_type (ir_node *node) {
 }
 
 INLINE void
-set_Alloc_type (ir_node *node, type *type) {
+set_Alloc_type (ir_node *node, type *tp) {
   assert (node->op == op_Alloc);
-  node->attr.a.type = type;
+  node->attr.a.type = tp;
 }
 
 INLINE where_alloc
@@ -1974,9 +1990,9 @@ get_Free_type (ir_node *node) {
 }
 
 INLINE void
-set_Free_type (ir_node *node, type *type) {
+set_Free_type (ir_node *node, type *tp) {
   assert (node->op == op_Free);
-  node->attr.f = type;
+  node->attr.f = tp;
 }
 
 INLINE ir_node **
@@ -2182,9 +2198,9 @@ INLINE ir_node *
 skip_nop (ir_node *node) {
   /* don't assert node !!! */
 
-  if (node && (node->op == op_Id) && (node != get_Id_pred(node))) {
-    /* Don't use get_Id_pred:  We get into an endless loop for
-       self-referencing Ids. */
+  /* Don't use get_Id_pred:  We get into an endless loop for
+     self-referencing Ids. */
+  if (node && (node->op == op_Id) && (node != node->in[0+1])) {
     assert (get_irn_arity (node) > 0);
     return node->in[0+1];
   } else {
@@ -2211,6 +2227,12 @@ is_no_Block (ir_node *node) {
   return (get_irn_opcode(node) != iro_Block);
 }
 
+INLINE int
+is_Block (ir_node *node) {
+  assert(node);
+  return (get_irn_opcode(node) == iro_Block);
+}
+
 INLINE int
 is_Proj (ir_node *node) {
   assert(node);
@@ -2226,10 +2248,24 @@ is_cfop(ir_node *node) {
 
 /* Returns true if the operation manipulates interprocedural control flow:
    CallBegin, EndReg, EndExcept */
-int is_ip_cfop(ir_node *node) {
+INLINE int is_ip_cfop(ir_node *node) {
   return is_ip_cfopcode(get_irn_op(node));
 }
 
+ir_graph *get_ip_cfop_irg(ir_node *n) {
+  switch (get_irn_opcode(n)) {
+  case iro_EndReg:
+    return get_EndReg_irg(n);
+  case iro_EndExcept:
+    return get_EndExcept_irg(n);
+  case iro_CallBegin:
+    return get_CallBegin_irg(n);
+  default:
+    assert(is_ip_cfop(n));
+  }
+  return NULL; /* should never be reached */
+}
+
 /* Returns true if the operation can change the control flow because
    of an exception. */
 int