17549a77c8bf68ffd53a54808df0ea2efe9fe5e0
[libfirm] / ir / ir / irnode_t.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 * All rights reserved.
3 *
4 * Authors: Martin Trapp, Christian Schaefer
5 *
6 * declarations of an ir node
7 */
8
9 /* $Id$ */
10
11 # ifndef _IRNODE_T_H_
12 # define _IRNODE_T_H_
13
14 # include "irnode.h"
15 # include "xprintf.h"
16 # include "irop_t.h"
17 # include "firm_common_t.h"
18 # include "irdom_t.h" /* For size of struct dom_info. */
19 # include "dbginfo.h"
20
21 # include "exc.h"
22
23 /** ir node attributes **/
24
25 /* Block attributes */
26 typedef struct {
27   unsigned long block_visited;  /* for the walker that walks over all blocks. */
28   /* Attributes private to construction: */
29   bool matured;               /* if set, all in-nodes of the block are fixed */
30   struct ir_node **graph_arr; /* array to store all parameters */
31   struct dom_info dom;        /* Datastructure that holds information about dominators.
32                                  @@@ Eventually overlay with graph_arr as only valid
33                                  in different phases.  Eventually inline the whole
34                                  datastructure. */
35   exc_t exc;                  /* role of this block for exception handling */
36   ir_node *handler_entry;     /* handler entry block iff this block is part of a region */
37   ir_node ** in_cg;           /* array with predecessors in
38                                * interprocedural_view, if they differ
39                                * from intraprocedural predecessors */
40   int *backedge;              /* Field n set to true if pred n is backedge.
41                                  @@@ Ev. replace by bitfield! */
42   int *cg_backedge;           /* Field n set to true if pred n is interprocedural backedge.
43                                  @@@ Ev. replace by bitfield! */
44 } block_attr;
45
46 /* Cond attributes */
47 typedef struct {
48   cond_kind kind;    /* flavor of Cond */
49   long default_proj; /* for optimization: biggest Proj number, i.e. the one
50                         used for default. */
51 } cond_attr;
52
53 /* SymConst attributes */
54 /*   This union contains the symbolic information represented by the node */
55 typedef union type_or_id {
56   type *typ;
57   ident *ptrinfo;
58 } type_or_id;
59
60 typedef struct {
61   type_or_id tori;
62   symconst_kind num;
63 } symconst_attr;
64
65 /* Sel attributes */
66 typedef struct {
67   entity *ent;          /* entity to select */
68 } sel_attr;
69
70 typedef struct {
71   type *cld_tp;         /* type of called procedure */
72 #if PRECISE_EXC_CONTEXT
73   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions */
74 #endif
75   entity ** callee_arr; /* result of callee analysis */
76 } call_attr;
77
78 /* Alloc attributes */
79 typedef struct {
80   type *type;           /* Type of the allocated object.  */
81   where_alloc where;    /* stack, heap or other managed part of memory */
82 #if PRECISE_EXC_CONTEXT
83   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions */
84 #endif
85 } alloc_attr;
86
87 /* InstOf attributes */
88 typedef struct
89 {
90   type *ent;
91   int dfn;
92 } io_attr;
93
94 /* Filter attributes */
95 typedef struct {
96   long proj;                 /* contains the result position to project (Proj) */
97   ir_node ** in_cg;          /* array with interprocedural predecessors (Phi) */
98   int *backedge;              /* Field n set to true if pred n is backedge.
99                                  @@@ Ev. replace by bitfield! */
100 } filter_attr;
101
102 /* EndReg/EndExcept attributes */
103 typedef struct {
104   ir_graph * irg;            /* ir_graph this node belongs to (for
105                               * navigating in interprocedural graphs) */
106 } end_attr;
107
108 /* CallBegin attributes */
109 typedef struct {
110   ir_graph * irg;            /* ir_graph this node belongs to (for
111                               * navigating in interprocedural graphs) */
112   ir_node * call;            /* associated Call-operation */
113 } callbegin_attr;
114
115 /* Some irnodes just have one attribute, these are stored here,
116    some have more. Their name is 'irnodename_attr' */
117 typedef union {
118   block_attr     block; /* For Block: Fields needed to construct it */
119   cond_attr      c;     /* For Cond. */
120   struct tarval *con;   /* For Const: contains the value of the constant */
121   symconst_attr  i;     /* For SymConst. */
122   sel_attr       s;     /* For Sel. */
123   call_attr      call;  /* For Call: pointer to the type of the method to call */
124   callbegin_attr callbegin; /* For CallBegin */
125   alloc_attr     a;     /* For Alloc. */
126   io_attr        io;    /* For InstOf */
127   type          *f;     /* For Free. */
128   int            phi0_pos;  /* For Phi. Used to remember the value defined by
129                                this Phi node.  Needed when the Phi is completed
130                                to call get_r_internal_value to find the
131                                predecessors. If this attribute is set, the Phi
132                                node takes the role of the obsolete Phi0 node,
133                                therefore the name. */
134   int *phi_backedge;    /* For Phi after construction.
135                            Field n set to true if pred n is backedge.
136                            @@@ Ev. replace by bitfield! */
137   long           proj;  /* For Proj: contains the result position to project */
138   filter_attr    filter;    /* For Filter */
139   end_attr       end;       /* For EndReg, EndExcept */
140 #if PRECISE_EXC_CONTEXT
141   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions
142                                for nodes Store, Load, Div, Mod, Quot, DivMod. */
143 #endif
144 } attr;
145
146
147 /* common structure of an irnode */
148 /* if the node has some attributes, they are stored in attr */
149
150 struct ir_node {
151   /** Basics of the representation **/
152   firm_kind kind;          /* distinguishes this node from others */
153   ir_op *op;               /* Opcode of this node. */
154   ir_mode *mode;           /* Mode of this node. */
155   unsigned long visited;   /* visited counter for walks of the graph */
156   struct ir_node **in;     /* array with predecessors / operands */
157   void *link;              /* to attach additional information to the node, e.g.
158                               used while construction to link Phi0 nodes and
159                               during optimization to link to nodes that
160                               shall replace a node. */
161   /**  Fields for optimizations / analysis information **/
162   struct ir_node **out;    /* array of out edges */
163   struct dbg_info* dbi;    /* A pointer to information for debug support. */
164   /** For debugging **/
165 #ifdef DEBUG_libfirm
166   int node_nr;             /* a unique node number for each node to make output
167                               readable. */
168 #endif
169   attr attr;               /* attribute of this node. Depends on opcode. */
170                            /* Must be last field of struct ir_node. */
171 };
172
173 /* Copies all attributes stored in the old node  to the new node.
174    Assumes both have the same opcode and sufficient size. */
175 void
176 copy_attrs (ir_node *old, ir_node *new);
177
178
179 /* Print IR-Nodes with attributes */
180 /* @@@@ brauchen wir dienoch? dann fliegt ev. das xprint raus?*/
181 int ir_node_print (XP_PAR1, const xprintf_info *, XP_PARN);
182
183 /* Returns the array with the ins.  The content of the array may not be
184    changed.  */
185 ir_node     **get_irn_in            (ir_node *node);
186
187 /** access attributes directly **/
188 INLINE tarval       *get_irn_const_attr    (ir_node *node);
189 INLINE long          get_irn_proj_attr     (ir_node *node);
190 INLINE alloc_attr    get_irn_alloc_attr    (ir_node *node);
191 INLINE type         *get_irn_free_attr     (ir_node *node);
192 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
193 type         *get_irn_call_attr     (ir_node *node);
194 sel_attr      get_irn_sel_attr      (ir_node *node);
195 int           get_irn_phi_attr      (ir_node *node);
196 block_attr    get_irn_block_attr   (ir_node *node);
197
198 # endif /* _IRNODE_T_H_ */