Changed behaviour of new_ir_mode to accept all predefined modes.
[libfirm] / ir / ir / irgraph.c
index c394b63..8e9125a 100644 (file)
@@ -68,6 +68,8 @@ new_ir_graph (entity *ent, int n_loc)
   ir_node *projX;
 
   res = (ir_graph *) malloc (sizeof (ir_graph));
+  res->kind=k_ir_graph;
+
   current_ir_graph = res;
   add_irp_irg(res);          /* remember this graph global. */
 
@@ -93,6 +95,7 @@ new_ir_graph (entity *ent, int n_loc)
   res->Phi_in_stack = new_Phi_in_stack();  /* A stack needed for automatic Phi
                                 generation */
 #endif
+  res->kind = k_ir_graph;
   res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack));
   obstack_init (res->obst);
   res->value_table = new_identities (); /* value table for global value
@@ -127,8 +130,8 @@ new_ir_graph (entity *ent, int n_loc)
   /* Proj results of start node */
   projX        = new_Proj (res->start, mode_X, pns_initial_exec);
   set_store (new_Proj (res->start, mode_M, pns_global_store));
-  res->frame   = new_Proj (res->start, mode_P, pns_frame_base);
-  res->globals = new_Proj (res->start, mode_P, pns_globals);
+  res->frame   = new_Proj (res->start, mode_P_mach, pns_frame_base);
+  res->globals = new_Proj (res->start, mode_P_mach, pns_globals);
   res->args    = new_Proj (res->start, mode_T, pns_args);
 #ifdef DEBUG_libfirm
   res->graph_nr = get_irp_new_node_nr();
@@ -165,6 +168,7 @@ ir_graph *new_const_code_irg() {
 #if USE_EXPLICIT_PHI_IN_STACK
   res->Phi_in_stack = NULL;
 #endif
+  res->kind = k_ir_graph;
   res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack));
   obstack_init (res->obst);
   res->phase_state = phase_building;
@@ -216,6 +220,15 @@ void free_ir_graph (ir_graph *irg) {
    {attr type} get_irg_{attribute name} (ir_graph *irg);
    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
 
+int
+is_ir_graph(void *thing) {
+  assert(thing);
+  if (get_kind(thing) == k_ir_graph)
+    return 1;
+  else
+    return 0;
+}
+
 /* Outputs a unique number for this node */
 
 INLINE long
@@ -422,6 +435,27 @@ struct obstack *get_irg_obstack(ir_graph *irg) {
   return irg->obst;
 }
 
+/*
+ * Returns true if the node n is allocated on the storage of graph irg.
+ *
+ * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation.
+ */
+int node_is_in_irgs_storage(ir_graph *irg, ir_node *n)
+{
+  struct _obstack_chunk        *p;
+
+  /*
+   * checks wheater the ir_node pointer i on the obstack.
+   * A more sophisticated chaeck would test the "whole" ir_node
+   */
+  for (p = irg->obst->chunk; p; p = p->prev) {
+    if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit))
+      return 1;
+  }
+
+  return 0;
+}
+
 irg_phase_state
 get_irg_phase_state (ir_graph *irg) {
   return irg->phase_state;
@@ -501,9 +535,11 @@ inc_irg_visited (ir_graph *irg)
 unsigned long
 get_max_irg_visited(void)
 {
-  //int i;
-  //for(i = 0; i < get_irp_n_irgs(); i++)
-  //  assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
+  /*
+  int i;
+  for(i = 0; i < get_irp_n_irgs(); i++)
+  assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
+   */
   return max_irg_visited;
 }
 
@@ -514,9 +550,11 @@ void set_max_irg_visited(int val) {
 unsigned long
 inc_max_irg_visited(void)
 {
-  //int i;
-  //  for(i = 0; i < get_irp_n_irgs(); i++)
-  //assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
+  /*
+  int i;
+  for(i = 0; i < get_irp_n_irgs(); i++)
+  assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
+  */
   max_irg_visited++;
   return max_irg_visited;
 }