removed exc.h from libfirm interface
[libfirm] / ir / ir / irnode.c
index fef3dcb..18822a8 100644 (file)
@@ -1,21 +1,25 @@
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-* All rights reserved.
-*
-* Authors: Martin Trapp, Christian Schaefer, Goetz Lindenmaier
-*
-*/
-
-/* $Id$ */
+/*
+ * Project:     libFIRM
+ * File name:   ir/ir/irnode.c
+ * Purpose:     Representation of an intermediate operation.
+ * 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 <string.h>
 
+#include "ident.h"
 #include "irnode_t.h"
 #include "irgraph_t.h"
 #include "irmode_t.h"
-#include "typegmod_t.h"
+#include "typegmod.h"
 #include "array.h"
 #include "irbackedge_t.h"
 #include "irdump.h"
@@ -78,12 +82,12 @@ get_negated_pnc(int pnc) {
   return 99; /* to shut up gcc */
 }
 
-static const char *pns_name_arr [] = {
+const char *pns_name_arr [] = {
   "initial_exec", "global_store",
   "frame_base", "globals", "args"
 };
 
-static const char *symconst_name_arr [] = {
+const char *symconst_name_arr [] = {
   "type_tag", "size", "linkage_ptr_info"
 };
 
@@ -137,6 +141,15 @@ copy_attrs (ir_node *old, ir_node *new) {
 
 /** getting some parameters from ir_nodes **/
 
+int
+is_ir_node (void *thing) {
+  assert(thing);
+  if (get_kind(thing) == k_ir_node)
+    return 1;
+  else
+    return 0;
+}
+
 /* returns the number of predecessors without the block predecessor. */
 INLINE int
 get_irn_arity (const ir_node *node) {
@@ -306,7 +319,7 @@ INLINE const char *
 get_irn_opname (const ir_node *node)
 {
   assert(node);
-  return id_to_str(node->op->name);
+  return get_id_str(node->op->name);
 }
 
 INLINE ident *
@@ -375,7 +388,7 @@ get_irn_node_nr(const ir_node *node) {
 #endif
 }
 
-INLINE tarval *
+INLINE const_attr
 get_irn_const_attr (ir_node *node)
 {
   assert (node->op == op_Const);
@@ -629,6 +642,20 @@ void remove_Block_cg_cfgpred_arr(ir_node * node) {
   node->attr.block.in_cg = NULL;
 }
 
+/* Start references the irg it is in. */
+INLINE ir_graph *
+get_Start_irg(ir_node *node) {
+  assert(node->op == op_Start);
+  return node->attr.start.irg;
+}
+
+INLINE void
+set_Start_irg(ir_node *node, ir_graph *irg) {
+  assert(node->op == op_Start);
+  assert(is_ir_graph(irg));
+  node->attr.start.irg = irg;
+}
+
 INLINE int
 get_End_n_keepalives(ir_node *end) {
   assert (end->op == op_End);
@@ -656,6 +683,7 @@ set_End_keepalive(ir_node *end, int pos, ir_node *ka) {
 INLINE void
 free_End (ir_node *end) {
   assert (end->op == op_End);
+  end->kind = k_BAD;
   /* DEL_ARR_F(end->in);   GL @@@ tut nicht ! */
   end->in = NULL;   /* @@@ make sure we get an error if we use the
                       in array afterwards ... */
@@ -776,7 +804,7 @@ set_Return_res (ir_node *node, int pos, ir_node *res){
 
 INLINE ir_node *
 get_Raise_mem (ir_node *node) {
-  assert (node->op == op_Return);
+  assert (node->op == op_Raise);
   return get_irn_n(node, 0);
 }
 
@@ -800,15 +828,41 @@ set_Raise_exo_ptr (ir_node *node, ir_node *exo_ptr) {
 
 INLINE tarval *get_Const_tarval (ir_node *node) {
   assert (node->op == op_Const);
-  return get_irn_const_attr(node);
+  return node->attr.con.tv;
 }
 
 INLINE void
 set_Const_tarval (ir_node *node, tarval *con) {
   assert (node->op == op_Const);
-  node->attr.con = con;
+  node->attr.con.tv = con;
 }
 
+
+/* The source language type.  Must be an atomic type.  Mode of type must
+   be mode of node. For tarvals from entities type must be pointer to
+   entity type. */
+INLINE type *
+get_Const_type (ir_node *node) {
+  assert (node->op == op_Const);
+  return node->attr.con.tp;
+}
+
+INLINE void
+set_Const_type (ir_node *node, type *tp) {
+  assert (node->op == op_Const);
+  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))))));
+  }
+
+  node->attr.con.tp = tp;
+}
+
+
 INLINE symconst_kind
 get_SymConst_kind (const ir_node *node) {
   assert (node->op == op_SymConst);
@@ -967,7 +1021,7 @@ set_InstOf_obj (ir_node *node, ir_node *obj) {
 /* For unary and binary arithmetic operations the access to the
    operands can be factored out.  Left is the first, right the
    second arithmetic value  as listed in tech report 0999-33.
-   unops are: Minus, Abs, Not, Conv
+   unops are: Minus, Abs, Not, Conv, Cast
    binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
    Shr, Shrs, Rotate, Cmp */
 
@@ -1549,44 +1603,63 @@ set_Conv_op (ir_node *node, ir_node *op) {
   set_irn_n(node, 0, op);
 }
 
+INLINE ir_node *
+get_Cast_op (ir_node *node) {
+  assert (node->op == op_Cast);
+  return get_irn_n(node, 0);
+}
 
+INLINE void
+set_Cast_op (ir_node *node, ir_node *op) {
+  assert (node->op == op_Cast);
+  set_irn_n(node, 0, op);
+}
 
-int
+INLINE type *
+get_Cast_type (ir_node *node) {
+  assert (node->op == op_Cast);
+  return node->attr.cast.totype;
+}
+
+INLINE void
+set_Cast_type (ir_node *node, type *to_tp) {
+  assert (node->op == op_Cast);
+  node->attr.cast.totype = to_tp;
+}
+
+INLINE int
 is_unop (ir_node *node) {
   return ( node->op == op_Minus ||
            node->op == op_Abs  ||
           node->op == op_Not  ||
-           node->op == op_Conv );
+           node->op == op_Conv ||
+           node->op == op_Cast );
 }
 
 INLINE ir_node *
 get_unop_op (ir_node *node) {
-  assert ( node->op == op_Minus ||
-           node->op == op_Abs  ||
-           node->op == op_Not  ||
-           node->op == op_Conv );
+  assert (is_unop(node));
   switch (get_irn_opcode (node)) {
     case iro_Minus: return get_Minus_op(node); break;
     case iro_Abs:   return get_Abs_op(node);   break;
     case iro_Not:   return get_Not_op(node);   break;
     case iro_Conv:  return get_Conv_op(node);  break;
+    case iro_Cast:  return get_Cast_op(node);  break;
     default: return NULL;
   }
 }
 
 INLINE void
 set_unop_op (ir_node *node, ir_node *op) {
-    assert (node->op == op_Minus ||
-           node->op == op_Abs   ||
-           node->op == op_Not   ||
-           node->op == op_Conv    );
-    switch (get_irn_opcode (node)) {
+  assert (is_unop(node));
+  switch (get_irn_opcode (node)) {
     case iro_Minus:   set_Minus_op(node, op); break;
     case iro_Abs:     set_Abs_op(node, op);   break;
     case iro_Not:     set_Not_op(node, op);   break;
     case iro_Conv:    set_Conv_op(node, op);  break;
+    case iro_Cast:    set_Cast_op(node, op);  break;
     default:  ;
-    }
+  }
 
 }
 
@@ -2114,8 +2187,11 @@ get_irn_irg(ir_node *node) {
   } else if (get_irn_op(node) == op_EndReg ||
             get_irn_op(node) == op_EndExcept) {
     return node->attr.end.irg;
+  } else if (get_irn_op(node) == op_Start) {
+    return node->attr.start.irg;
   } else {
     assert(0 && "no irg attr");
+    return NULL;
   }
 }
 
@@ -2151,6 +2227,9 @@ skip_Tuple (ir_node *node) {
   return node;
 }
 
+/* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
+   than any other approach, as Id chains are resolved and all point to the real node, or
+   all id's are self loops. */
 INLINE ir_node *
 skip_nop (ir_node *node) {
   /* don't assert node !!! */
@@ -2160,8 +2239,17 @@ skip_nop (ir_node *node) {
   /* 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])) {
+    ir_node *rem_pred = node->in[0+1];
+    ir_node *res;
+
     assert (get_irn_arity (node) > 0);
-    return node->in[0+1];
+
+    node->in[0+1] = node;
+    res = skip_nop(rem_pred);
+    if (res->op == op_Id) /* self-loop */ return node;
+
+    node->in[0+1] = res;
+    return res;
   } else {
     return node;
   }