cg_opt now frees interprocedural loop information automatically since
[libfirm] / ir / ir / irgmod.c
index 7aeb5ed..9cf12ff 100644 (file)
@@ -1,26 +1,28 @@
-
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Authors: Martin Trapp, Christian Schaefer
-**
-** irgmod: ir graph modification
-*/
-
-/* $Id$ */
+/*
+ * Project:     libFIRM
+ * File name:   ir/ir/irgmod.h
+ * Purpose:     Support for ir graph modification.
+ * Author:      Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1998-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
 # include "irvrfy.h"
-# include "irflag.h"
+# include "irflag_t.h"
 # include "irgwalk.h"
 # include "irnode_t.h"
 # include "irgraph_t.h"
 # include "irgmod.h"
 # include "array.h"
 # include "ircons.h"
+# include "firmstat.h"
 
 /* Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
    from several inputs.
@@ -31,7 +33,7 @@ turn_into_tuple (ir_node *node, int arity)
 {
   assert(node);
   set_irn_op(node, op_Tuple);
-  if (get_irn_arity(node) == arity) {
+  if (intern_get_irn_arity(node) == arity) {
     /* keep old array */
   } else {
     /* Allocate new array, don't free old in_array, it's on the obstack. */
@@ -44,10 +46,16 @@ turn_into_tuple (ir_node *node, int arity)
 /* Insert irnode `new' in place of irnode `old'
    Since `new' may be bigger than `old' replace `old'
    by an op_Id which is smaller than everything */
-inline void
+INLINE void
 exchange (ir_node *old, ir_node *nw)
 {
-  ir_node *block = old->in[0];
+  ir_node *block;
+
+  assert(get_irn_op(old)->opar != oparity_dynamic);
+
+  stat_turn_into_id(old);
+
+  block = old->in[0];
 
   old->op = op_Id;
   old->in = NEW_ARR_D (ir_node *, current_ir_graph->obst, 2);
@@ -55,25 +63,25 @@ exchange (ir_node *old, ir_node *nw)
   old->in[1] = nw;
 }
 
-/**********************************************************************/
-/*  Functionality for collect_phis                                     */
-/**********************************************************************/
+/*--------------------------------------------------------------------*/
+/*  Functionality for collect_phis                                    */
+/*--------------------------------------------------------------------*/
 
-void
+static void
 clear_link (ir_node *n, void *env) {
   set_irn_link(n, NULL);
 }
 
-void
+static void
 collect (ir_node *n, void *env) {
   ir_node *pred;
-  if (get_irn_op(n) == op_Phi) {
+  if (intern_get_irn_op(n) == op_Phi) {
     set_irn_link(n, get_irn_link(get_nodes_Block(n)));
     set_irn_link(get_nodes_Block(n), n);
   }
-  if (get_irn_op(n) == op_Proj) {
+  if (intern_get_irn_op(n) == op_Proj) {
     pred = n;
-    while (get_irn_op(pred) == op_Proj)
+    while (intern_get_irn_op(pred) == op_Proj)
       pred = get_Proj_pred(pred);
     set_irn_link(n, get_irn_link(pred));
     set_irn_link(pred, n);
@@ -93,14 +101,15 @@ void collect_phiprojs(ir_graph *irg) {
 }
 
 
-/**********************************************************************/
-/*  Funcionality for part_block                                       */
-/**********************************************************************/
-
-/* Moves node and all predecessors of node from from_bl to to_bl.
-   Does not move predecessors of Phi nodes (or block nodes). */
+/*--------------------------------------------------------------------*/
+/*  Functionality for part_block                                      */
+/*--------------------------------------------------------------------*/
 
-void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) {
+/**
+ * Moves node and all predecessors of node from from_bl to to_bl.
+ * Does not move predecessors of Phi nodes (or block nodes).
+ */
+static void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) {
   int i;
   ir_node *proj, *pred;
 
@@ -108,7 +117,7 @@ void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) {
   set_nodes_Block(node, to_bl);
 
   /* move its projs */
-  if (get_irn_mode(node) == mode_T) {
+  if (intern_get_irn_mode(node) == mode_T) {
     proj = get_irn_link(node);
     while (proj) {
       if (get_nodes_Block(proj) == from_bl)
@@ -118,9 +127,9 @@ void move (ir_node *node, ir_node *from_bl, ir_node *to_bl) {
   }
 
   /* recursion ... */
-  if (get_irn_op(node) == op_Phi) return;
+  if (intern_get_irn_op(node) == op_Phi) return;
 
-  for (i = 0; i < get_irn_arity(node); i++) {
+  for (i = 0; i < intern_get_irn_arity(node); i++) {
     pred = get_irn_n(node, i);
     if (get_nodes_Block(pred) == from_bl)
       move(pred, from_bl, to_bl);
@@ -133,7 +142,7 @@ void part_block(ir_node *node) {
   ir_node *phi;
 
   /* Turn off optimizations so that blocks are not merged again. */
-  int rem_opt = get_optimize();
+  int rem_opt = get_opt_optimize();
   set_optimize(0);
 
   /* Transform the control flow */
@@ -145,7 +154,7 @@ void part_block(ir_node *node) {
     ir_node *in[1];
     in[0] = new_Jmp();
     set_irn_in(old_block, 1, in);
-    irn_vrfy(old_block);
+    irn_vrfy_irg(old_block, current_ir_graph);
   }
 
   /* move node and its predecessors to new_block */
@@ -156,7 +165,10 @@ void part_block(ir_node *node) {
   set_irn_link(new_block, phi);
   set_irn_link(old_block, NULL);
   while (phi) {
-    set_nodes_Block(phi, new_block);
+    if(get_nodes_Block(phi) == old_block);   /* @@@ inlinening chokes on phis that don't
+                                              obey this condition.  How do they get into
+                                              the list??? Example: InterfaceIII */
+      set_nodes_Block(phi, new_block);
     phi = get_irn_link(phi);
   }