introduced node index: a small unique per graph node number
[libfirm] / ir / ir / irnode_t.h
index e1bb0ee..1ec1f16 100644 (file)
@@ -50,22 +50,21 @@ typedef struct {
   /* Attributes private to construction: */
   unsigned matured:1;         /**< if set, all in-nodes of the block are fixed */
   unsigned dead:1;            /**< if set, the block is dead (and could be replace by a Bad */
-  struct ir_node **graph_arr; /**< array to store all parameters */
+  ir_node **graph_arr;        /**< array to store all parameters */
   /* Attributes holding analyses information */
-  struct dom_info dom;        /**< Datastructure that holds information about dominators.
-                 @@@ @todo
-                 Eventually overlay with graph_arr as only valid
-                 in different phases.  Eventually inline the whole
-                 datastructure. */
-  /*   exc_t exc;  */            /**< role of this block for exception handling */
-  /*   ir_node *handler_entry; */    /**< handler entry block iff this block is part of a region */
+  dom_info dom;               /**< Datastructure that holds information about dominators.
+                                   @@@ @todo
+                                   Eventually overlay with graph_arr as only valid
+                                   in different phases.  Eventually inline the whole
+                                   datastructure. */
+  dom_info pdom;              /**< Datastructure that holds information about post-dominators. */
   ir_node ** in_cg;           /**< array with predecessors in
-                   * interprocedural_view, if they differ
-                   * from intraprocedural predecessors */
+                               * interprocedural_view, if they differ
+                               * from intraprocedural predecessors */
   int *backedge;              /**< Field n set to true if pred n is backedge.
-                     @@@ @todo Ev. replace by bitfield! */
+                                   @@@ @todo Ev. replace by bit field! */
   int *cg_backedge;           /**< Field n set to true if pred n is interprocedural backedge.
-                     @@@ @todo Ev. replace by bitfield! */
+                                   @@@ @todo Ev. replace by bit field! */
   ir_extblk *extblk;          /**< the extended basic block this block belongs to */
 
   struct list_head succ_head; /**< A list head for all successor edges of a block. */
@@ -80,21 +79,21 @@ typedef struct {
 
 /** Cond attributes */
 typedef struct {
-  cond_kind kind;    /**< flavor of Cond */
-  long default_proj; /**< for optimization: biggest Proj number, i.e. the one
-                          used for default. */
+  cond_kind kind;           /**< flavor of Cond */
+  long default_proj;        /**< only for non-binary Conds: biggest Proj number, i.e. the one used for default. */
+  cond_jmp_predicate pred;  /**< only for binary Conds: The jump predication. */
 } cond_attr;
 
 /** Const attributes */
 typedef struct {
-  tarval *tv;        /**< the target value */
-  type   *tp;        /**< the source type, for analyses. default: type_unknown. */
+  tarval  *tv;       /**< the target value */
+  ir_type *tp;       /**< the source type, for analyses. default: type_unknown. */
 } const_attr;
 
 typedef struct {
   symconst_symbol sym;  // old tori
   symconst_kind num;
-  type *tp;          /**< the source type, for analyses. default: type_unknown. */
+  ir_type *tp;       /**< the source type, for analyses. default: type_unknown. */
 } symconst_attr;
 
 /** Sel attributes */
@@ -112,30 +111,30 @@ typedef struct {
 #endif
 } except_attr;
 
+/** Call attributes */
 typedef struct {
   except_attr    exc;           /**< the exception attribute. MUST be the first one. */
-  type *cld_tp;                 /**< type of called procedure */
+  ir_type *cld_tp;              /**< type of called procedure */
   entity ** callee_arr;         /**< result of callee analysis */
 } call_attr;
 
 /** Alloc attributes */
 typedef struct {
   except_attr    exc;           /**< the exception attribute. MUST be the first one. */
-  type *type;                   /**< Type of the allocated object.  */
+  ir_type *type;                /**< Type of the allocated object.  */
   where_alloc where;            /**< stack, heap or other managed part of memory */
 } alloc_attr;
 
 /** Free attributes */
 typedef struct {
-  type *type;                   /**< Type of the allocated object.  */
+  ir_type *type;                /**< Type of the allocated object.  */
   where_alloc where;            /**< stack, heap or other managed part of memory */
 } free_attr;
 
 /** InstOf attributes */
-typedef struct
-{
-  type *ent;
-  int dfn;
+typedef struct {
+  except_attr    exc;           /**< the exception attribute. MUST be the first one. */
+  ir_type *type;                /**< the type of which the object pointer must be */
 } io_attr;
 
 /** Filter attributes */
@@ -153,39 +152,50 @@ typedef struct {
 
 /** CallBegin attributes */
 typedef struct {
-  ir_node * call;            /**< associated Call-operation */
+  ir_node * call;               /**< Associated Call-operation. */
 } callbegin_attr;
 
 /** Cast attributes */
 typedef struct {
-  type *totype;
+  ir_type *totype;              /**< Type of the casted node. */
 } cast_attr;
 
 /** Load attributes */
 typedef struct {
-  except_attr    exc;           /**< the exception attribute. MUST be the first one. */
-  ir_mode        *load_mode;    /**< the mode of this Load operation */
-  ent_volatility volatility;   /**< the volatility of a Load/Store operation */
+  except_attr    exc;           /**< The exception attribute. MUST be the first one. */
+  ir_mode        *load_mode;    /**< The mode of this Load operation. */
+  ent_volatility volatility;     /**< The volatility of a Load/Store operation. */
 } load_attr;
 
 /** Store attributes */
 typedef struct {
   except_attr    exc;           /**< the exception attribute. MUST be the first one. */
-  ent_volatility volatility;   /**< the volatility of a Store operation */
+  ent_volatility volatility;     /**< the volatility of a Store operation */
 } store_attr;
 
 typedef pn_Cmp confirm_attr;    /**< Attribute to hold compare operation */
 
+/** CopyB attribute */
+typedef struct {
+  except_attr    exc;           /**< The exception attribute. MUST be the first one. */
+  ir_type        *data_type;    /**< Type of the copied entity. */
+} copyb_attr;
+
+/** Bound attribute */
+typedef struct {
+  except_attr    exc;           /**< The exception attribute. MUST be the first one. */
+} bound_attr;
+
 /**
  * Edge info to put into an irn.
  */
 typedef struct _irn_edge_info_t {
-  struct list_head outs_head;  /**< The list of all outs */
-  int out_count;               /**< number of outs in the list */
+  struct list_head outs_head;  /**< The list of all outs. */
+  int out_count;               /**< Number of outs in the list. */
 } irn_edge_info_t;
 
 
-/** Some irnodes just have one attribute, these are stored here,
+/** Some IR-nodes just have one attribute, these are stored here,
    some have more. Their name is 'irnodename_attr' */
 typedef union {
   start_attr     start; /**< For Start */
@@ -211,11 +221,13 @@ typedef union {
   int *phi_backedge;    /**< For Phi after construction.
                           Field n set to true if pred n is backedge.
                           @todo Ev. replace by bitfield! */
-  long           proj;  /**< For Proj: contains the result position to project */
+  long           proj;          /**< For Proj: contains the result position to project */
   confirm_attr   confirm_cmp;   /**< For Confirm: compare operation */
-  filter_attr    filter;    /**< For Filter */
-  end_attr       end;       /**< For EndReg, EndExcept */
-  except_attr    except; /**< For Phi node construction in case of exceptions */
+  filter_attr    filter;        /**< For Filter */
+  end_attr       end;           /**< For EndReg, EndExcept */
+  except_attr    except;        /**< For Phi node construction in case of exceptions */
+  copyb_attr     copyb;         /**< For CopyB operation */
+  bound_attr     bound;         /**< For Bound operation */
 } attr;
 
 
@@ -226,25 +238,26 @@ struct ir_node {
   firm_kind kind;          /**< distinguishes this node from others */
   ir_op *op;               /**< Opcode of this node. */
   ir_mode *mode;           /**< Mode of this node. */
-  unsigned long visited;   /**< visited counter for walks of the graph */
   struct ir_node **in;     /**< array with predecessors / operands */
+  unsigned long visited;   /**< visited counter for walks of the graph */
+  unsigned node_idx;       /**< the node index of this node in its graph */
   void *link;              /**< to attach additional information to the node, e.g.
                               used while construction to link Phi0 nodes and
-                             during optimization to link to nodes that
-                             shall replace a node. */
+                              during optimization to link to nodes that
+                              shall replace a node. */
   /* ------- Fields for optimizations / analysis information ------- */
   struct ir_node **out;    /**< @deprecated array of out edges. */
   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
   /* ------- For debugging ------- */
 #ifdef DEBUG_libfirm
-       int out_valid;
-  int node_nr;             /**< a unique node number for each node to make output
-                             readable. */
+  int out_valid;
+  long node_nr;            /**< a unique node number for each node to make output
+                                   readable. */
 #endif
   /* ------- For analyses -------- */
   ir_loop *loop;           /**< the loop the node is in. Access routines in irloop.h */
 #ifdef  DO_HEAPANALYSIS
-  struct abstval *av;
+  struct abstval *av;      /**< the abstract value of this node */
   struct section *sec;
 #endif
 #if FIRM_EDGES_INPLACE
@@ -256,8 +269,12 @@ struct ir_node {
 };
 
 
-/** Returns the array with the ins.  The content of the array may not be
-   changed.  */
+/**
+ * Returns the array with the ins.  The content of the array may not be
+ * changed.
+ * Note that this function returns the whole in array including the
+ * block predecessor. So, it is NOT symmetric with set_irn_in().
+ */
 ir_node     **get_irn_in            (const ir_node *node);
 
 /** @{ */
@@ -267,15 +284,14 @@ long          get_irn_proj_attr     (ir_node *node);
 alloc_attr    get_irn_alloc_attr    (ir_node *node);
 free_attr     get_irn_free_attr     (ir_node *node);
 symconst_attr get_irn_symconst_attr (ir_node *node);
-type         *get_irn_call_attr     (ir_node *node);
-type         *get_irn_funccall_attr (ir_node *node);
+ir_type      *get_irn_call_attr     (ir_node *node);
+ir_type      *get_irn_funccall_attr (ir_node *node);
 sel_attr      get_irn_sel_attr      (ir_node *node);
 int           get_irn_phi_attr      (ir_node *node);
 block_attr    get_irn_block_attr    (ir_node *node);
 load_attr     get_irn_load_attr     (ir_node *node);
 store_attr    get_irn_store_attr    (ir_node *node);
 except_attr   get_irn_except_attr   (ir_node *node);
-void         *get_irn_generic_attr  (ir_node *node);
 /** @} */
 
 /**
@@ -283,8 +299,38 @@ void         *get_irn_generic_attr  (ir_node *node);
  */
 extern unsigned firm_add_node_size;
 
-/** Set the get_type operation of an ir_op. */
-ir_op *firm_set_default_get_type(ir_op *op);
+/**
+ * Sets the get_type operation for an ir_op_ops.
+ *
+ * @param code   the opcode for the default operation
+ * @param ops    the operations initialized
+ *
+ * @return
+ *    The operations.
+ */
+ir_op_ops *firm_set_default_get_type(opcode code, ir_op_ops *ops);
+
+/**
+ * Sets the get_type_attr operation for an ir_op_ops.
+ *
+ * @param code   the opcode for the default operation
+ * @param ops    the operations initialized
+ *
+ * @return
+ *    The operations.
+ */
+ir_op_ops *firm_set_default_get_type_attr(opcode code, ir_op_ops *ops);
+
+/**
+ * Sets the get_entity_attr operation for an ir_op_ops.
+ *
+ * @param code   the opcode for the default operation
+ * @param ops    the operations initialized
+ *
+ * @return
+ *    The operations.
+ */
+ir_op_ops *firm_set_default_get_entity_attr(opcode code, ir_op_ops *ops);
 
 /*-------------------------------------------------------------------*/
 /*  These function are most used in libfirm.  Give them as static    */
@@ -310,6 +356,12 @@ _get_irn_op (const ir_node *node) {
   return node->op;
 }
 
+static INLINE void
+_set_irn_op (ir_node *node, ir_op *op) {
+  assert (node);
+  node->op = op;
+}
+
 /** Copies all attributes stored in the old node  to the new node.
     Assumes both have the same opcode and sufficient size. */
 static INLINE void
@@ -317,7 +369,7 @@ copy_node_attr(const ir_node *old_node, ir_node *new_node) {
   ir_op *op = _get_irn_op(old_node);
 
   /* must always exist */
-  op->copy_attr(old_node, new_node);
+  op->ops.copy_attr(old_node, new_node);
 }
 
 /**
@@ -348,10 +400,10 @@ _get_irn_intra_arity (const ir_node *node) {
 static INLINE int
 _get_irn_inter_arity (const ir_node *node) {
   assert(node);
-  if (_get_irn_opcode(node) == iro_Filter) {
+  if (_get_irn_op(node) == op_Filter) {
     assert(node->attr.filter.in_cg);
     return ARR_LEN(node->attr.filter.in_cg) - 1;
-  } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
+  } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
     return ARR_LEN(node->attr.block.in_cg) - 1;
   }
   return _get_irn_intra_arity(node);
@@ -368,9 +420,14 @@ extern int (*_get_irn_arity)(const ir_node *node);
  */
 static INLINE ir_node *
 _get_irn_intra_n (const ir_node *node, int n) {
+  ir_node *nn;
+
   assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
 
-  return (node->in[n + 1] = skip_Id(node->in[n + 1]));
+  nn = node->in[n + 1];
+  if (!nn || (nn->op != op_Id)) return nn;
+
+  return (node->in[n + 1] = skip_Id(nn));
 }
 
 /**
@@ -484,7 +541,7 @@ _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);
+  assert(get_irg_phase_state(get_irn_irg(node)) != phase_building);
 
   node->link = link;
 }
@@ -554,6 +611,34 @@ _is_Unknown (const ir_node *node) {
   return (node && _get_irn_op(node) == op_Unknown);
 }
 
+static INLINE int
+_is_Return (const ir_node *node) {
+  assert(node);
+  return (node && _get_irn_op(node) == op_Return);
+}
+
+static INLINE int
+_is_Call (const ir_node *node) {
+  assert(node);
+  return (node && _get_irn_op(node) == op_Call);
+}
+
+static INLINE int
+_is_Sel (const ir_node *node) {
+  assert(node);
+  return (node && _get_irn_op(node) == op_Sel);
+}
+
+static INLINE int
+_is_Mux (const ir_node *node) {
+  assert(node);
+  if (node) {
+    ir_op *op = _get_irn_op(node);
+    return (op == op_Mux || ((op == op_Psi) && _get_irn_arity(node) == 3));
+  }
+  return 0;
+}
+
 static INLINE int
 _is_no_Block(const ir_node *node) {
   assert(node && _is_ir_node(node));
@@ -661,8 +746,59 @@ static INLINE cnst_classify_t _classify_Const(ir_node *node) {
   return CNST_NO_CONST;
 }
 
-static INLINE type *_get_irn_type(ir_node *node) {
-  return _get_irn_op(node)->get_type(node);
+static INLINE int _is_irn_forking(const ir_node *node) {
+  return is_op_forking(_get_irn_op(node));
+}
+
+static INLINE ir_type *_get_irn_type(ir_node *node) {
+  return _get_irn_op(node)->ops.get_type(node);
+}
+
+static INLINE ir_type *_get_irn_type_attr(ir_node *node) {
+  return _get_irn_op(node)->ops.get_type_attr(node);
+}
+
+static INLINE entity *_get_irn_entity_attr(ir_node *node) {
+  return _get_irn_op(node)->ops.get_entity_attr(node);
+}
+
+static INLINE int _is_irn_constlike(const ir_node *node) {
+  return is_op_constlike(_get_irn_op(node));
+}
+
+static INLINE int _is_irn_keep(const ir_node *node) {
+  return is_op_keep(_get_irn_op(node));
+}
+
+static INLINE int _is_irn_machine_op(const ir_node *node) {
+  return is_op_machine(_get_irn_op(node));
+}
+
+static INLINE int _is_irn_machine_operand(const ir_node *node) {
+  return is_op_machine_operand(_get_irn_op(node));
+}
+
+static INLINE int _is_irn_machine_user(const ir_node *node, unsigned n) {
+  return is_op_machine_user(_get_irn_op(node), n);
+}
+
+static INLINE cond_jmp_predicate _get_Cond_jmp_pred(ir_node *node) {
+  assert (_get_irn_op(node) == op_Cond);
+  return node->attr.c.pred;
+}
+
+static INLINE void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
+  assert (_get_irn_op(node) == op_Cond);
+  node->attr.c.pred = pred;
+}
+
+static INLINE int _get_Psi_n_conds(ir_node *node) {
+  assert(_get_irn_op(node) == op_Psi);
+  return _get_irn_arity(node) >> 1;
+}
+
+static INLINE unsigned _get_irn_idx(const ir_node *node) {
+  return node->node_idx;
 }
 
 /* this section MUST contain all inline functions */
@@ -676,6 +812,7 @@ static INLINE type *_get_irn_type(ir_node *node) {
 #define get_irn_mode(node)                    _get_irn_mode(node)
 #define set_irn_mode(node, mode)              _set_irn_mode(node, mode)
 #define get_irn_op(node)                      _get_irn_op(node)
+#define set_irn_op(node, op)                  _set_irn_op(node, op)
 #define get_irn_opcode(node)                  _get_irn_opcode(node)
 #define get_irn_visited(node)                 _get_irn_visited(node)
 #define set_irn_visited(node, v)              _set_irn_visited(node, v)
@@ -690,6 +827,10 @@ static INLINE type *_get_irn_type(ir_node *node) {
 #define is_binop(node)                        _is_binop(node)
 #define is_Const(node)                        _is_Const(node)
 #define is_Unknown(node)                      _is_Unknown(node)
+#define is_Return(node)                       _is_Return(node)
+#define is_Call(node)                         _is_Call(node)
+#define is_Sel(node)                          _is_Sel(node)
+#define is_Mux(node)                          _is_Mux(node)
 #define is_Bad(node)                          _is_Bad(node)
 #define is_no_Block(node)                     _is_no_Block(node)
 #define is_Block(node)                        _is_Block(node)
@@ -704,6 +845,18 @@ static INLINE type *_get_irn_type(ir_node *node) {
 #define is_Block_dead(block)                  _is_Block_dead(block)
 #define get_Const_tarval(node)                _get_Const_tarval(node)
 #define classify_Const(node)                  _classify_Const(node)
+#define is_irn_forking(node)                  _is_irn_forking(node)
 #define get_irn_type(node)                    _get_irn_type(node)
+#define get_irn_type_attr(node)               _get_irn_type_attr(node)
+#define get_irn_entity_attr(node)             _get_irn_entity_attr(node)
+#define is_irn_constlike(node)                _is_irn_constlike(node)
+#define is_irn_keep(node)                     _is_irn_keep(node)
+#define is_irn_machine_op(node)               _is_irn_machine_op(node)
+#define is_irn_machine_operand(node)          _is_irn_machine_operand(node)
+#define is_irn_machine_user(node, n)          _is_irn_machine_user(node, n)
+#define get_Cond_jmp_pred(node)               _get_Cond_jmp_pred(node)
+#define set_Cond_jmp_pred(node, pred)         _set_Cond_jmp_pred(node, pred)
+#define get_Psi_n_conds(node)                 _get_Psi_n_conds(node)
+#define get_irn_idx(node)                     _get_irn_idx(node)
 
 # endif /* _IRNODE_T_H_ */