Fixed 'inline' lossage --flo
[libfirm] / ir / ir / ircons.c
index d3c5862..070168c 100644 (file)
@@ -1,15 +1,15 @@
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-* All rights reserved.
-*
-* Authors: Martin Trapp, Christian Schaefer
-*
-* ircons.c: basic and more detailed irnode constructors
-*           store, block and parameter administration.
-* Adapted to extended FIRM nodes (exceptions...) and commented
-*   by Goetz Lindenmaier
-*/
-
-/* $Id$ */
+/*
+ * Project:     libFIRM
+ * File name:   ir/ir/ircons.c
+ * Purpose:     Various irnode constructors.  Automatic construction
+ *              of SSA representation.
+ * Author:      Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier, Boris Boesler
+ * 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>
@@ -28,6 +28,7 @@
 /* memset belongs to string.h */
 # include "string.h"
 # include "irbackedge_t.h"
+# include "irflag_t.h"
 
 #if USE_EXPLICIT_PHI_IN_STACK
 /* A stack needed for the automatic Phi node construction in constructor
@@ -59,8 +60,9 @@ new_rd_Block (dbg_info* db, ir_graph *irg,  int arity, ir_node **in)
   set_Block_matured(res, 1);
   set_Block_block_visited(res, 0);
 
-  res->attr.block.exc = exc_normal;
-  res->attr.block.handler_entry = 0;
+  //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.cg_backedge = NULL;
@@ -75,6 +77,7 @@ new_rd_Start (dbg_info* db, ir_graph *irg, ir_node *block)
   ir_node *res;
 
   res = new_ir_node (db, irg, block, op_Start, mode_T, 0, NULL);
+  //res->attr.start.irg = irg;
 
   irn_vrfy_irg (res, irg);
   return res;
@@ -100,8 +103,10 @@ new_rd_Phi (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in
   int i;
   bool has_unknown = false;
 
-  assert( get_Block_matured(block) );
-  assert( get_irn_arity(block) == arity );
+  /* Don't assert that block matured: the use of this constructor is strongly
+     restricted ... */
+  if ( get_Block_matured(block) )
+    assert( get_irn_arity(block) == arity );
 
   res = new_ir_node (db, irg, block, op_Phi, mode, arity, in);
 
@@ -119,12 +124,14 @@ new_rd_Phi (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in
 }
 
 INLINE ir_node *
-new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
+new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, type *tp)
 {
   ir_node *res;
   res = new_ir_node (db, irg, block, op_Const, mode, 0, NULL);
-  res->attr.con = con;
+  res->attr.con.tv = con;
+  set_Const_type(res, tp);  /* Call method because of complex assertion. */
   res = optimize_node (res);
+  assert(get_Const_type(res) == tp);
   irn_vrfy_irg (res, irg);
 
 #if 0
@@ -134,6 +141,15 @@ new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval
   return res;
 }
 
+INLINE ir_node *
+new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
+{
+  type *tp = unknown_type;
+  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);
+}
+
 INLINE ir_node *
 new_rd_Id (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
 {
@@ -189,7 +205,17 @@ new_rd_Conv (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *
   res = optimize_node (res);
   irn_vrfy_irg (res, irg);
   return res;
+}
 
+INLINE ir_node *
+new_rd_Cast (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, type *to_tp)
+{
+  ir_node *res;
+  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);
+  irn_vrfy_irg (res, irg);
+  return res;
 }
 
 INLINE ir_node *
@@ -611,6 +637,8 @@ new_rd_Sel (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_node
   ir_node *res;
   int r_arity;
 
+  assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
+
   r_arity = arity + 2;
   NEW_ARR_A (ir_node *, r_in, r_arity);  /* uses alloca */
   r_in[0] = store;
@@ -692,9 +720,25 @@ new_rd_Bad (ir_graph *irg)
 }
 
 INLINE ir_node *
-new_rd_Unknown (ir_graph *irg)
+new_rd_Confirm (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp)
 {
-  return irg->unknown;
+  ir_node *in[2], *res;
+  in[0] = val;
+  in[1] = bound;
+
+  res = new_ir_node (db, irg, block, op_Confirm, get_irn_mode(val), 2, in);
+
+  res->attr.confirm_cmp = cmp;
+
+  res = optimize_node (res);
+  irn_vrfy_irg(res, irg);
+  return res;
+}
+
+INLINE ir_node *
+new_rd_Unknown (ir_graph *irg, ir_mode *m)
+{
+  return new_ir_node (NULL, irg, irg->start_block, op_Unknown, m, 0, NULL);
 }
 
 INLINE ir_node *
@@ -704,7 +748,7 @@ new_rd_CallBegin (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *call)
   ir_node *res;
   in[0] = get_Call_ptr(call);
   res = new_ir_node (db, irg, block, op_CallBegin, mode_T, 1, in);
-  res->attr.callbegin.irg = irg;
+  //res->attr.callbegin.irg = irg;
   res->attr.callbegin.call = call;
   res = optimize_node (res);
   irn_vrfy_irg (res, irg);
@@ -717,7 +761,7 @@ new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block)
   ir_node *res;
 
   res = new_ir_node (db, irg, block, op_EndReg, mode_T, -1, NULL);
-  res->attr.end.irg = irg;
+  //res->attr.end.irg = irg;
 
   irn_vrfy_irg (res, irg);
   return res;
@@ -729,7 +773,7 @@ new_rd_EndExcept (dbg_info *db, ir_graph *irg, ir_node *block)
   ir_node *res;
 
   res = new_ir_node (db, irg, block, op_EndExcept, mode_T, -1, NULL);
-  res->attr.end.irg = irg;
+  //res->attr.end.irg = irg;
 
   irn_vrfy_irg (res, irg);
   return res;
@@ -768,6 +812,30 @@ new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mod
 
 }
 
+ir_node *
+new_rd_FuncCall (dbg_info* db, ir_graph *irg, ir_node *block,
+           ir_node *callee, int arity, ir_node **in, type *tp)
+{
+  ir_node **r_in;
+  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);
+
+  res = new_ir_node (db, irg, block, op_FuncCall, mode_T, r_arity, r_in);
+
+  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;
+}
+
+
 INLINE ir_node *new_r_Block  (ir_graph *irg,  int arity, ir_node **in) {
   return new_rd_Block(NULL, irg, arity, in);
 }
@@ -800,65 +868,65 @@ INLINE ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
   return new_rd_SymConst(NULL, irg, block, value, symkind);
 }
 INLINE ir_node *new_r_Sel    (ir_graph *irg, ir_node *block, ir_node *store,
-                       ir_node *objptr, int n_index, ir_node **index,
-                      entity *ent) {
+                             ir_node *objptr, int n_index, ir_node **index,
+                             entity *ent) {
   return new_rd_Sel(NULL, irg, block, store, objptr, n_index, index, ent);
 }
 INLINE ir_node *new_r_InstOf (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
-                                          type *ent) {
+                             type *ent) {
   return (new_rd_InstOf (NULL, irg, block, store, objptr, ent));
 }
 INLINE ir_node *new_r_Call   (ir_graph *irg, ir_node *block, ir_node *store,
-                      ir_node *callee, int arity, ir_node **in,
-                      type *tp) {
+                             ir_node *callee, int arity, ir_node **in,
+                             type *tp) {
   return new_rd_Call(NULL, irg, block, store, callee, arity, in, tp);
 }
 INLINE ir_node *new_r_Add    (ir_graph *irg, ir_node *block,
-                      ir_node *op1, ir_node *op2, ir_mode *mode) {
+                             ir_node *op1, ir_node *op2, ir_mode *mode) {
   return new_rd_Add(NULL, irg, block, op1, op2, mode);
 }
 INLINE ir_node *new_r_Sub    (ir_graph *irg, ir_node *block,
-                      ir_node *op1, ir_node *op2, ir_mode *mode) {
+                             ir_node *op1, ir_node *op2, ir_mode *mode) {
   return new_rd_Sub(NULL, irg, block, op1, op2, mode);
 }
 INLINE ir_node *new_r_Minus  (ir_graph *irg, ir_node *block,
-                      ir_node *op,  ir_mode *mode) {
+                             ir_node *op,  ir_mode *mode) {
   return new_rd_Minus(NULL, irg, block,  op, mode);
 }
 INLINE ir_node *new_r_Mul    (ir_graph *irg, ir_node *block,
-                                          ir_node *op1, ir_node *op2, ir_mode *mode) {
+                             ir_node *op1, ir_node *op2, ir_mode *mode) {
   return new_rd_Mul(NULL, irg, block, op1, op2, mode);
 }
 INLINE ir_node *new_r_Quot   (ir_graph *irg, ir_node *block,
-                      ir_node *memop, ir_node *op1, ir_node *op2) {
+                             ir_node *memop, ir_node *op1, ir_node *op2) {
   return new_rd_Quot(NULL, irg, block, memop, op1, op2);
 }
 INLINE ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
-                      ir_node *memop, ir_node *op1, ir_node *op2) {
+                             ir_node *memop, ir_node *op1, ir_node *op2) {
   return new_rd_DivMod(NULL, irg, block, memop, op1, op2);
 }
 INLINE ir_node *new_r_Div    (ir_graph *irg, ir_node *block,
-                      ir_node *memop, ir_node *op1, ir_node *op2) {
+                             ir_node *memop, ir_node *op1, ir_node *op2) {
   return new_rd_Div(NULL, irg, block, memop, op1, op2);
 }
 INLINE ir_node *new_r_Mod    (ir_graph *irg, ir_node *block,
-                      ir_node *memop, ir_node *op1, ir_node *op2) {
+                             ir_node *memop, ir_node *op1, ir_node *op2) {
   return new_rd_Mod(NULL, irg, block, memop, op1, op2);
 }
 INLINE ir_node *new_r_Abs    (ir_graph *irg, ir_node *block,
-                       ir_node *op, ir_mode *mode) {
+                             ir_node *op, ir_mode *mode) {
   return new_rd_Abs(NULL, irg, block, op, mode);
 }
 INLINE ir_node *new_r_And    (ir_graph *irg, ir_node *block,
-                      ir_node *op1, ir_node *op2, ir_mode *mode) {
+                             ir_node *op1, ir_node *op2, ir_mode *mode) {
   return new_rd_And(NULL, irg, block,  op1, op2, mode);
 }
 INLINE ir_node *new_r_Or     (ir_graph *irg, ir_node *block,
-                      ir_node *op1, ir_node *op2, ir_mode *mode) {
+                             ir_node *op1, ir_node *op2, ir_mode *mode) {
   return new_rd_Or(NULL, irg, block,  op1, op2, mode);
 }
 INLINE ir_node *new_r_Eor    (ir_graph *irg, ir_node *block,
-                      ir_node *op1, ir_node *op2, ir_mode *mode) {
+                             ir_node *op1, ir_node *op2, ir_mode *mode) {
   return new_rd_Eor(NULL, irg, block,  op1, op2, mode);
 }
 INLINE ir_node *new_r_Not    (ir_graph *irg, ir_node *block,
@@ -889,6 +957,9 @@ INLINE ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
                       ir_node *op, ir_mode *mode) {
   return new_rd_Conv(NULL, irg, block, op, mode);
 }
+INLINE ir_node *new_r_Cast   (ir_graph *irg, ir_node *block, ir_node *op, type *to_tp) {
+  return new_rd_Cast(NULL, irg, block, op, to_tp);
+}
 INLINE ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
                       ir_node **in, ir_mode *mode) {
   return new_rd_Phi(NULL, irg, block, arity, in, mode);
@@ -931,8 +1002,11 @@ INLINE ir_node *new_r_Id     (ir_graph *irg, ir_node *block,
 INLINE ir_node *new_r_Bad    (ir_graph *irg) {
   return new_rd_Bad(irg);
 }
-INLINE ir_node *new_r_Unknown (ir_graph *irg) {
-  return new_rd_Unknown(irg);
+INLINE ir_node *new_r_Confirm (ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
+  return new_rd_Confirm (NULL, irg, block, val, bound, cmp);
+}
+INLINE ir_node *new_r_Unknown (ir_graph *irg, ir_mode *m) {
+  return new_rd_Unknown(irg, m);
 }
 INLINE ir_node *new_r_CallBegin (ir_graph *irg, ir_node *block, ir_node *callee) {
   return new_rd_CallBegin(NULL, irg, block, callee);
@@ -950,6 +1024,11 @@ 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);
+}
 
 
 /** ********************/
@@ -971,6 +1050,7 @@ new_d_Start (dbg_info* db)
 
   res = new_ir_node (db, current_ir_graph, current_ir_graph->current_block,
                     op_Start, mode_T, 0, NULL);
+  //res->attr.start.irg = current_ir_graph;
 
   res = optimize_node (res);
   irn_vrfy_irg (res, current_ir_graph);
@@ -1066,7 +1146,7 @@ new_rd_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
 */
 #if USE_EXPLICIT_PHI_IN_STACK
 INLINE Phi_in_stack *
-new_Phi_in_stack() {
+new_Phi_in_stack(void) {
   Phi_in_stack *res;
 
   res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
@@ -1256,7 +1336,7 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
     block->attr.block.graph_arr[pos] = res;
   } else {
     /*  printf(" value already computed by %s\n",
-        id_to_str(block->attr.block.graph_arr[pos]->op->name));  */
+        get_id_str(block->attr.block.graph_arr[pos]->op->name));  */
   }
 
   return res;
@@ -1436,8 +1516,8 @@ get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
 static ir_node *
 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins);
 
-static INLINE ir_node **
-new_frag_arr (ir_node *n) {
+static INLINE ir_node ** new_frag_arr (ir_node *n)
+{
   ir_node **arr;
   int opt;
   arr = NEW_ARR_D (ir_node *, current_ir_graph->obst, current_ir_graph->n_loc);
@@ -1445,7 +1525,7 @@ new_frag_arr (ir_node *n) {
         sizeof(ir_node *)*current_ir_graph->n_loc);
   /* turn off optimization before allocating Proj nodes, as res isn't
      finished yet. */
-  opt = get_optimize(); set_optimize(0);
+  opt = get_opt_optimize(); set_optimize(0);
   /* Here we rely on the fact that all frag ops have Memory as first result! */
   if (get_irn_op(n) == op_Call)
     arr[0] = new_Proj(n, mode_M, 3);
@@ -1760,6 +1840,14 @@ new_d_Const (dbg_info* db, ir_mode *mode, tarval *con)
                      mode, con);
 }
 
+ir_node *
+new_d_Const_type (dbg_info* db, ir_mode *mode, tarval *con, type *tp)
+{
+  return new_rd_Const_type (db, current_ir_graph, current_ir_graph->start_block,
+                           mode, con, tp);
+}
+
+
 ir_node *
 new_d_Id (dbg_info* db, ir_node *val, ir_mode *mode)
 {
@@ -1792,6 +1880,12 @@ new_d_Conv (dbg_info* db, ir_node *op, ir_mode *mode)
                     op, mode);
 }
 
+ir_node *
+new_d_Cast (dbg_info* db, ir_node *op, type *to_tp)
+{
+  return new_rd_Cast (db, current_ir_graph, current_ir_graph->current_block, op, to_tp);
+}
+
 ir_node *
 new_d_Tuple (dbg_info* db, int arity, ir_node **in)
 {
@@ -2079,7 +2173,7 @@ new_d_InstOf (dbg_info *db, ir_node *store, ir_node *objptr, type *ent)
 ir_node *
 new_d_SymConst (dbg_info* db, type_or_id_p value, symconst_kind kind)
 {
-  return new_rd_SymConst (db, current_ir_graph, current_ir_graph->current_block,
+  return new_rd_SymConst (db, current_ir_graph, current_ir_graph->start_block,
                          value, kind);
 }
 
@@ -2087,7 +2181,7 @@ ir_node *
 new_d_Sync (dbg_info* db, int arity, ir_node** in)
 {
   return new_rd_Sync (db, current_ir_graph, current_ir_graph->current_block,
-                    arity, in);
+                     arity, in);
 }
 
 
@@ -2098,9 +2192,16 @@ new_d_Bad (void)
 }
 
 ir_node *
-new_d_Unknown (void)
+new_d_Confirm (dbg_info *db, ir_node *val, ir_node *bound, pn_Cmp cmp)
+{
+  return new_rd_Confirm (db, current_ir_graph, current_ir_graph->current_block,
+                        val, bound, cmp);
+}
+
+ir_node *
+new_d_Unknown (ir_mode *m)
 {
-  return current_ir_graph->unknown;
+  return new_rd_Unknown(current_ir_graph, m);
 }
 
 ir_node *
@@ -2140,6 +2241,17 @@ new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj)
                        arg, mode, proj);
 }
 
+ir_node *
+new_d_FuncCall (dbg_info* db, ir_node *callee, int arity, ir_node **in,
+         type *tp)
+{
+  ir_node *res;
+  res = new_rd_FuncCall (db, current_ir_graph, current_ir_graph->current_block,
+                    callee, arity, in, tp);
+
+  return res;
+}
+
 /* ********************************************************************* */
 /* Comfortable interface with automatic Phi node construction.           */
 /* (Uses also constructors of ?? interface, except new_Block.            */
@@ -2155,8 +2267,9 @@ ir_node *new_d_immBlock (dbg_info* db) {
   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.exc = exc_normal;
-  res->attr.block.handler_entry = 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.cg_backedge = NULL;
@@ -2316,7 +2429,7 @@ ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity, ir_node **in,
   return new_d_Sel(NULL, store, objptr, arity, in, ent);
 }
 ir_node *new_InstOf (ir_node *store, ir_node *objptr, type *ent) {
-  return (new_d_InstOf (NULL, store, objptr, ent));
+  return new_d_InstOf (NULL, store, objptr, ent);
 }
 ir_node *new_Call   (ir_node *store, ir_node *callee, int arity, ir_node **in,
                     type *tp) {
@@ -2380,6 +2493,9 @@ ir_node *new_Cmp    (ir_node *op1, ir_node *op2) {
 ir_node *new_Conv   (ir_node *op, ir_mode *mode) {
   return new_d_Conv(NULL, op, mode);
 }
+ir_node *new_Cast   (ir_node *op, type *to_tp) {
+  return new_d_Cast(NULL, op, to_tp);
+}
 ir_node *new_Phi    (int arity, ir_node **in, ir_mode *mode) {
   return new_d_Phi(NULL, arity, in, mode);
 }
@@ -2415,8 +2531,11 @@ ir_node *new_Id     (ir_node *val, ir_mode *mode) {
 ir_node *new_Bad    (void) {
   return new_d_Bad();
 }
-ir_node *new_Unknown(void) {
-  return new_d_Unknown();
+ir_node *new_Confirm (ir_node *val, ir_node *bound, pn_Cmp cmp) {
+  return new_d_Confirm (NULL, val, bound, cmp);
+}
+ir_node *new_Unknown(ir_mode *m) {
+  return new_d_Unknown(m);
 }
 ir_node *new_CallBegin (ir_node *callee) {
   return new_d_CallBegin(NULL, callee);
@@ -2433,3 +2552,6 @@ 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);
+}