44056e1400d589eb07e782e5f5688a376203f3df
[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 "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 } block_attr;
41
42 /* Cond attributes */
43 typedef struct {
44   cond_kind kind;    /* flavor of Cond */
45   long default_proj; /* for optimization: biggest Proj number, i.e. the one
46                         used for default. */
47 } cond_attr;
48
49 /* SymConst attributes */
50 /*   This union contains the symbolic information represented by the node */
51 typedef union type_or_id {
52   type *typ;
53   ident *ptrinfo;
54 } type_or_id;
55
56 typedef struct {
57   type_or_id tori;
58   symconst_kind num;
59 } symconst_attr;
60
61 /* Sel attributes */
62 typedef struct {
63   entity *ent;          /* entity to select */
64   linkage_type ltyp;    /* linkage type of the entity */
65 } sel_attr;
66
67 typedef struct {
68   type *cld_tp;         /* type of called procedure */
69 #if PRECISE_EXC_CONTEXT
70   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions */
71 #endif
72   entity ** callee_arr; /* result of callee analysis */
73 } call_attr;
74
75 /* Alloc attributes */
76 typedef struct {
77   type *type;           /* Type of the allocated object.  */
78   where_alloc where;    /* stack, heap or other managed part of memory */
79 #if PRECISE_EXC_CONTEXT
80   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions */
81 #endif
82 } alloc_attr;
83
84 /* InstOf attributes */
85 typedef struct
86 {
87   type *ent;
88   int dfn;
89 } io_attr;
90
91 /* Filter attributes */
92 typedef struct {
93   long proj;                 /* contains the result position to project (Proj) */
94   ir_node ** in_cg;          /* array with interprocedural predecessors (Phi) */
95 } filter_attr;
96
97 /* EndReg/EndExcept attributes */
98 typedef struct {
99   ir_graph * irg;            /* ir_graph this node belongs to (for
100                               * navigating in interprocedural graphs) */
101 } end_attr;
102
103 /* CallBegin attributes */
104 typedef struct {
105   ir_graph * irg;            /* ir_graph this node belongs to (for
106                               * navigating in interprocedural graphs) */
107   ir_node * call;            /* associated Call-operation */
108 } callbegin_attr;
109
110 /* Some irnodes just have one attribute, these are stored here,
111    some have more. Their name is 'irnodename_attr' */
112 typedef union {
113   block_attr     block; /* For Block: Fields needed to construct it */
114   cond_attr      c;     /* For Cond. */
115   struct tarval *con;   /* For Const: contains the value of the constant */
116   symconst_attr  i;     /* For SymConst. */
117   sel_attr       s;     /* For Sel. */
118   call_attr      call;  /* For Call: pointer to the type of the method to call */
119   alloc_attr     a;     /* For Alloc. */
120   io_attr                io;    /* For InstOf */
121   type          *f;     /* For Free. */
122   int            phi0_pos;  /* For Phi. Used to remember the value defined by
123                                this Phi node.  Needed when the Phi is completed
124                                to call get_r_internal_value to find the
125                                predecessors. If this attribute is set, the Phi
126                                node takes the role of the obsolete Phi0 node,
127                                therefore the name. */
128   long           proj;  /* For Proj: contains the result position to project */
129   filter_attr    filter;    /* For Filter */
130   end_attr       end;       /* For EndReg, EndExcept */
131   callbegin_attr callbegin; /* For CallBegin */
132 #if PRECISE_EXC_CONTEXT
133   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions
134                                for nodes Store, Load, Div, Mod, Quot, DivMod. */
135 #endif
136 } attr;
137
138
139 /* common structure of an irnode */
140 /* if the node has some attributes, they are stored in attr */
141
142 struct ir_node {
143   /** Basics of the representation **/
144   firm_kind kind;          /* distinguishes this node from others */
145   ir_op *op;               /* Opcode of this node. */
146   ir_mode *mode;           /* Mode of this node. */
147   unsigned long visited;   /* visited counter for walks of the graph */
148   struct ir_node **in;     /* array with predecessors / operands */
149   struct ir_node *link;    /* for linking nodes somehow to a list, e.g.
150                               used while construction to link Phi0 nodes and
151                               during optimization to link to nodes that
152                               shall replace a node. */
153   /**  Fields for optimizations / analysis information **/
154   struct ir_node **out;    /* array of out edges */
155   struct dbg_info* dbi;           /* A pointer to information for debug support. */
156   /** For debugging **/
157 #ifdef DEBUG_libfirm
158   int node_nr;             /* a unique node number for each node to make output
159                               readable. */
160 #endif
161   attr attr;               /* attribute of this node. Depends on opcode. */
162                            /* Must be last field of struct ir_node. */
163 };
164
165 /* Copies all attributes stored in the old node  to the new node.
166    Assumes both have the same opcode and sufficient size. */
167 void
168 copy_attrs (ir_node *old, ir_node *new);
169
170
171 /* Print IR-Nodes with attributes */
172 /* @@@@ brauchen wir dienoch? dann fliegt ev. das xprint raus?*/
173 int ir_node_print (XP_PAR1, const xprintf_info *, XP_PARN);
174
175
176 /** access attributes directly **/
177 inline tarval       *get_irn_const_attr    (ir_node *node);
178 inline long          get_irn_proj_attr     (ir_node *node);
179 inline alloc_attr    get_irn_alloc_attr    (ir_node *node);
180 inline type         *get_irn_free_attr     (ir_node *node);
181 inline symconst_attr get_irn_symconst_attr (ir_node *node);
182 type         *get_irn_call_attr     (ir_node *node);
183 sel_attr      get_irn_sel_attr      (ir_node *node);
184 int           get_irn_phi_attr      (ir_node *node);
185 block_attr    get_irn_block_attr   (ir_node *node);
186
187 # endif /* _IRNODE_T_H_ */