irnode_t.h 8.28 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * Project:     libFIRM
 * File name:   ir/ir/irnode_t.h
 * Purpose:     Representation of an intermediate operation -- private header.
 * 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.
 */

Götz Lindenmaier's avatar
Götz Lindenmaier committed
13

Michael Beck's avatar
Michael Beck committed
14
15
16
17
18
19
20
21
/**
 * @file irnode_t.h
 *
 * Declarations of an ir node.
 *
 * @author Martin Trapp, Christian Schaefer
 */

Boris Boesler's avatar
Boris Boesler committed
22

Götz Lindenmaier's avatar
Götz Lindenmaier committed
23
24
25
# ifndef _IRNODE_T_H_
# define _IRNODE_T_H_

26
27
28
29
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

Götz Lindenmaier's avatar
Götz Lindenmaier committed
30
# include "irnode.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
31
# include "irop_t.h"
32
# include "firm_common_t.h"
33
# include "irdom_t.h" /* For size of struct dom_info. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
34
# include "dbginfo.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
35

36
37
# include "exc.h"

Götz Lindenmaier's avatar
Götz Lindenmaier committed
38
/** ir node attributes **/
Götz Lindenmaier's avatar
Götz Lindenmaier committed
39

Michael Beck's avatar
Michael Beck committed
40
/** Block attributes */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
41
typedef struct {
42
43
  /* General attributes */
  ir_graph *irg;
Michael Beck's avatar
Michael Beck committed
44
  unsigned long block_visited;  /**< for the walker that walks over all blocks. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
45
  /* Attributes private to construction: */
Michael Beck's avatar
Michael Beck committed
46
47
  bool matured;               /**< if set, all in-nodes of the block are fixed */
  struct ir_node **graph_arr; /**< array to store all parameters */
48
  /* Attributes holding analyses information */
Michael Beck's avatar
Michael Beck committed
49
  struct dom_info dom;        /**< Datastructure that holds information about dominators.
50
51
52
53
54
55
				 @@@ @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 */
Michael Beck's avatar
Michael Beck committed
56
  ir_node ** in_cg;           /**< array with predecessors in
57
58
			       * interprocedural_view, if they differ
			       * from intraprocedural predecessors */
Michael Beck's avatar
Michael Beck committed
59
  int *backedge;              /**< Field n set to true if pred n is backedge.
60
			         @@@ @todo Ev. replace by bitfield! */
Michael Beck's avatar
Michael Beck committed
61
  int *cg_backedge;           /**< Field n set to true if pred n is interprocedural backedge.
62
			         @@@ @todo Ev. replace by bitfield! */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
63
64
} block_attr;

65
66
/** Start attributes */
typedef struct {
67
68
  char dummy;
  //  ir_graph *irg;   @@@ now in block
69
70
} start_attr;

Michael Beck's avatar
Michael Beck committed
71
/** Cond attributes */
72
typedef struct {
Michael Beck's avatar
Michael Beck committed
73
74
  cond_kind kind;    /**< flavor of Cond */
  long default_proj; /**< for optimization: biggest Proj number, i.e. the one
75
   	 	 	  used for default. */
76
77
} cond_attr;

78
79
80
81
82
83
/** Const attributes */
typedef struct {
  tarval *tv;        /**< the target value */
  type   *tp;        /**< the source type, for analyses. default: type_unknown. */
} const_attr;

Michael Beck's avatar
Michael Beck committed
84
85
/** SymConst attributes
    This union contains the symbolic information represented by the node */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
86
typedef union type_or_id {
87
  type  *typ;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
88
89
90
91
92
93
94
95
  ident *ptrinfo;
} type_or_id;

typedef struct {
  type_or_id tori;
  symconst_kind num;
} symconst_attr;

Michael Beck's avatar
Michael Beck committed
96
/** Sel attributes */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
97
typedef struct {
Michael Beck's avatar
Michael Beck committed
98
  entity *ent;          /**< entity to select */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
99
100
} sel_attr;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
101
typedef struct {
Michael Beck's avatar
Michael Beck committed
102
  type *cld_tp;         /**< type of called procedure */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
103
#if PRECISE_EXC_CONTEXT
Michael Beck's avatar
Michael Beck committed
104
  struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
105
#endif
Michael Beck's avatar
Michael Beck committed
106
  entity ** callee_arr; /**< result of callee analysis */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
107
108
} call_attr;

Michael Beck's avatar
Michael Beck committed
109
/** Alloc attributes */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
110
typedef struct {
Michael Beck's avatar
Michael Beck committed
111
112
  type *type;           /**< Type of the allocated object.  */
  where_alloc where;    /**< stack, heap or other managed part of memory */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
113
#if PRECISE_EXC_CONTEXT
Michael Beck's avatar
Michael Beck committed
114
  struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
115
#endif
Götz Lindenmaier's avatar
Götz Lindenmaier committed
116
117
} alloc_attr;

Michael Beck's avatar
Michael Beck committed
118
/** InstOf attributes */
119
120
121
122
123
124
typedef struct
{
  type *ent;
  int dfn;
} io_attr;

Michael Beck's avatar
Michael Beck committed
125
/** Filter attributes */
126
typedef struct {
Michael Beck's avatar
Michael Beck committed
127
128
129
130
  long proj;                 /**< contains the result position to project (Proj) */
  ir_node ** in_cg;          /**< array with interprocedural predecessors (Phi) */
  int *backedge;              /**< Field n set to true if pred n is backedge.
			         @todo Ev. replace by bitfield! */
131
132
} filter_attr;

Michael Beck's avatar
Michael Beck committed
133
/** EndReg/EndExcept attributes */
134
typedef struct {
135
136
137
138
  char dummy;
  //  ir_graph * irg;            /**< ir_graph this node belongs to (for
  //                              * navigating in interprocedural graphs)
  //         			  @@@ now in block */
139
140
} end_attr;

Michael Beck's avatar
Michael Beck committed
141
/** CallBegin attributes */
142
typedef struct {
143
144
145
  //  ir_graph * irg;            / **< ir_graph this node belongs to (for
  //			      * navigating in interprocedural graphs) */
  //                           @@@ now in block
Michael Beck's avatar
Michael Beck committed
146
  ir_node * call;            /**< associated Call-operation */
147
148
} callbegin_attr;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
149
150
151
152
153
/** Cast attributes */
typedef struct {
  type *totype;
} cast_attr;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
154
155
typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */

Michael Beck's avatar
Michael Beck committed
156
/** Some irnodes just have one attribute, these are stored here,
Götz Lindenmaier's avatar
Götz Lindenmaier committed
157
158
   some have more. Their name is 'irnodename_attr' */
typedef union {
159
  start_attr     start; /**< For Start */
Michael Beck's avatar
Michael Beck committed
160
161
  block_attr     block; /**< For Block: Fields needed to construct it */
  cond_attr      c;     /**< For Cond. */
162
  const_attr     con;   /**< For Const: contains the value of the constant and a type */
Michael Beck's avatar
Michael Beck committed
163
164
165
166
167
168
169
  symconst_attr  i;     /**< For SymConst. */
  sel_attr       s;     /**< For Sel. */
  call_attr      call;  /**< For Call: pointer to the type of the method to call */
  callbegin_attr callbegin; /**< For CallBegin */
  alloc_attr     a;     /**< For Alloc. */
  io_attr	 io;	/**< For InstOf */
  type          *f;     /**< For Free. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
170
  cast_attr      cast;  /**< For Cast. */
Michael Beck's avatar
Michael Beck committed
171
  int            phi0_pos;  /**< For Phi. Used to remember the value defined by
Götz Lindenmaier's avatar
Götz Lindenmaier committed
172
173
174
175
176
			       this Phi node.  Needed when the Phi is completed
			       to call get_r_internal_value to find the
			       predecessors. If this attribute is set, the Phi
			       node takes the role of the obsolete Phi0 node,
			       therefore the name. */
Michael Beck's avatar
Michael Beck committed
177
  int *phi_backedge;    /**< For Phi after construction.
178
			   Field n set to true if pred n is backedge.
Michael Beck's avatar
Michael Beck committed
179
180
			   @todo Ev. replace by bitfield! */
  long           proj;  /**< For Proj: contains the result position to project */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
181
  confirm_attr   confirm_cmp;   /**< For Confirm: compare operation */
Michael Beck's avatar
Michael Beck committed
182
183
  filter_attr    filter;    /**< For Filter */
  end_attr       end;       /**< For EndReg, EndExcept */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
184
#if PRECISE_EXC_CONTEXT
Michael Beck's avatar
Michael Beck committed
185
  struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions
Götz Lindenmaier's avatar
Götz Lindenmaier committed
186
187
			       for nodes Store, Load, Div, Mod, Quot, DivMod. */
#endif
Götz Lindenmaier's avatar
Götz Lindenmaier committed
188
189
190
} attr;


Michael Beck's avatar
Michael Beck committed
191
192
/** common structure of an irnode
    if the node has some attributes, they are stored in attr */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
193
struct ir_node {
Michael Beck's avatar
Michael Beck committed
194
195
196
197
198
199
200
  /* ------- Basics of the representation  ------- */
  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 */
  void *link;              /**< to attach additional information to the node, e.g.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
201
202
203
                              used while construction to link Phi0 nodes and
			      during optimization to link to nodes that
			      shall replace a node. */
Michael Beck's avatar
Michael Beck committed
204
205
206
207
  /* ------- Fields for optimizations / analysis information ------- */
  struct ir_node **out;    /**< array of out edges */
  struct dbg_info* dbi;    /**< A pointer to information for debug support. */
  /* ------- For debugging ------- */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
208
#ifdef DEBUG_libfirm
Michael Beck's avatar
Michael Beck committed
209
  int node_nr;             /**< a unique node number for each node to make output
Götz Lindenmaier's avatar
Götz Lindenmaier committed
210
211
			      readable. */
#endif
Michael Beck's avatar
Michael Beck committed
212
213
  attr attr;               /**< attribute of this node. Depends on opcode.
                              Must be last field of struct ir_node. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
214
215
};

Michael Beck's avatar
Michael Beck committed
216
217
/** Copies all attributes stored in the old node  to the new node.
    Assumes both have the same opcode and sufficient size. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
218
219
220
221
void
copy_attrs (ir_node *old, ir_node *new);


Michael Beck's avatar
Michael Beck committed
222
/** Returns the array with the ins.  The content of the array may not be
223
   changed.  */
224
ir_node     **get_irn_in            (const ir_node *node);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
225

Michael Beck's avatar
Michael Beck committed
226
227
/*@{*/
/** access attributes directly */
228
INLINE const_attr    get_irn_const_attr    (ir_node *node);
229
230
231
232
INLINE long          get_irn_proj_attr     (ir_node *node);
INLINE alloc_attr    get_irn_alloc_attr    (ir_node *node);
INLINE type         *get_irn_free_attr     (ir_node *node);
INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
233
type         *get_irn_call_attr     (ir_node *node);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
234
235
sel_attr      get_irn_sel_attr      (ir_node *node);
int           get_irn_phi_attr      (ir_node *node);
236
block_attr    get_irn_block_attr   (ir_node *node);
Michael Beck's avatar
Michael Beck committed
237
/*@}*/
Götz Lindenmaier's avatar
Götz Lindenmaier committed
238
239

# endif /* _IRNODE_T_H_ */