Added NoMem node that represents a Memory that is Not used
[libfirm] / ir / ir / irgraph_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irgraph.c
4  * Purpose:     Entry point to the representation of procedure code -- internal header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irgraph_t.h
15  *
16  * ir graph construction.
17  *
18  * @author Martin Trapp, Christian Schaefer
19  */
20
21
22 #ifndef _IRGRAPH_T_H_
23 #define _IRGRAPH_T_H_
24
25 #include "irgraph.h"
26
27 #include "firm_common_t.h"
28 #include "irtypeinfo.h"
29 #include "irprog.h"
30
31 #include "irloop.h"
32
33 #include "obst.h"
34 #include "pset.h"
35 #include "type_t.h"
36
37 #define FRAME_TP_SUFFIX "frame_tp"
38
39 /** ir_graph holds all information for a procedure */
40 struct ir_graph {
41   firm_kind         kind;            /**<  always set to k_ir_graph*/
42   /* --  Basics of the representation -- */
43   struct entity  *ent;               /**< The entity of this procedure, i.e.,
44                     the type of the procedure and the
45                     class it belongs to. */
46   struct type    *frame_type;    /**< A class type representing the stack frame.
47                                     Can include "inner" methods. */
48   struct ir_node *start_block;   /**< block the start node will belong to */
49   struct ir_node *start;         /**< start node of this ir_graph */
50   struct ir_node *end_block;     /**< block the end node will belong to */
51   struct ir_node *end;           /**< end node of this ir_graph */
52   struct ir_node *end_reg;       /**< end node of this ir_graph */
53   struct ir_node *end_except;    /**< end node of this ir_graph */
54   struct ir_node *cstore;        /**< constant store -- no more needed!! */
55   struct ir_node *frame;         /**< method's frame */
56   struct ir_node *globals;       /**< pointer to the data segment containing all
57                                     globals as well as global procedures. */
58   struct ir_node *initial_mem;   /**< initial memory of this graph */
59   struct ir_node *args;          /**< methods arguments */
60   struct ir_node *bad;           /**< bad node of this ir_graph, the one and
61                                     only in this graph */
62   struct ir_node *no_mem;        /**< NoMem node of this ir_graph, the one and
63                                     only in this graph */
64   /* GL removed: we need unknown with mode for analyses. */
65   /*   struct ir_node *unknown;*/           /**< unknown node of this ir_graph */
66   struct obstack *obst;          /**< obstack where all of the ir_nodes live */
67   struct ir_node *current_block;     /**< block for newly gen_*()-erated
68                     ir_nodes */
69
70   /* -- Fields indicating different states of irgraph -- */
71   irg_phase_state phase_state;       /**< compiler phase */
72   op_pin_state op_pin_state_pinned;  /**< Flag for status of nodes */
73   irg_outs_state outs_state;         /**< Out edges. */
74   irg_dom_state dom_state;           /**< Dominator information */
75   irg_typeinfo_state typeinfo_state;       /**< Validity of type information */
76   irg_callee_info_state callee_info_state; /**< Validity of callee information */
77   irg_inline_property inline_property;     /**< How to handle inlineing. */
78   irg_loopinfo_state loopinfo_state;       /**< state of loop information */
79
80   /* -- Fields for construction -- */
81 #if USE_EXPLICIT_PHI_IN_STACK
82   struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
83 #endif
84   int n_loc;                         /**< number of local variable in this
85                                         procedure including procedure parameters. */
86
87   /* -- Fields for optimizations / analysis information -- */
88   pset *value_table;                 /**< hash table for global value numbering (cse)
89                                         for optimizing use in iropt.c */
90   struct ir_node **outs;             /**< Space for the out arrays. */
91
92 #ifdef DEBUG_libfirm
93   int             n_outs;            /* < Size wasted for outs */
94 #endif /* defined DEBUG_libfirm */
95   struct ir_loop *loop;              /**< The outermost loop */
96   void *link;                        /**< A void* field to link any information to
97                     the node. */
98
99   ir_graph **callers;                /**< For callgraph analyses. */
100   int       *caller_isbe;            /**< For callgraph analyses: set if backedge. */
101   ir_graph **callees;                /**< For callgraph analyses. */
102   int       *callee_isbe;            /**< For callgraph analyses: set if backedge. */
103   int        callgraph_loop_depth;
104   int        callgraph_recursion_depth;
105   ir_loop   *l;
106
107   /* -- Fields for Walking the graph -- */
108   unsigned long visited;             /**< this flag is an identifier for
109                                         ir walk. it will be incremented
110                                         every time someone walks through
111                                         the graph */
112   unsigned long block_visited;       /**< same as visited, for a complete block */
113 #ifdef DEBUG_libfirm
114   int graph_nr;             /**< a unique graph number for each graph to make output
115                                readable. */
116 #endif
117 };
118
119 /**
120  * Initializes the graph construction module
121  */
122 void init_irgraph(void);
123
124 /** Make a rudimentary ir graph for the constant code.
125    Must look like a correct irg, spare everything else. */
126 ir_graph *new_const_code_irg(void);
127
128 /**
129  * Set the op_pin_state_pinned state of a graph.
130  *
131  * @param irg     the IR graph
132  * @param p       new pin state
133  */
134 INLINE void
135 set_irg_pinned (ir_graph *irg, op_pin_state p);
136
137 /** Returns the obstack associated with the graph. */
138 struct obstack *get_irg_obstack(const ir_graph *irg);
139
140 /**
141  * Returns true if the node n is allocated on the storage of graph irg.
142  *
143  * @param irg   the IR graph
144  * @param n the IR node
145  */
146 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
147
148 /*-------------------------------------------------------------------*/
149 /* inline functions for graphs                                       */
150 /*-------------------------------------------------------------------*/
151
152 extern int __interprocedural_view;
153
154 static INLINE int
155 __get_interprocedural_view(void) {
156   return __interprocedural_view;
157 }
158
159 static INLINE int
160 __is_ir_graph(const void *thing) {
161   return (get_kind(thing) == k_ir_graph);
162 }
163
164 /** Returns the start block of a graph. */
165 static INLINE ir_node *
166 __get_irg_start_block(const ir_graph *irg) {
167   return irg->start_block;
168 }
169
170 static INLINE void
171 __set_irg_start_block(ir_graph *irg, ir_node *node) {
172   irg->start_block = node;
173 }
174
175 static INLINE ir_node *
176 __get_irg_start(const ir_graph *irg) {
177   return irg->start;
178 }
179
180 static INLINE void
181 __set_irg_start(ir_graph *irg, ir_node *node) {
182   irg->start = node;
183 }
184
185 static INLINE ir_node *
186 __get_irg_end_block(const ir_graph *irg) {
187   return irg->end_block;
188 }
189
190 static INLINE void
191 __set_irg_end_block(ir_graph *irg, ir_node *node) {
192   irg->end_block = node;
193 }
194
195 static INLINE ir_node *
196 __get_irg_end(const ir_graph *irg) {
197   return irg->end;
198 }
199
200 static INLINE void
201 __set_irg_end(ir_graph *irg, ir_node *node) {
202   irg->end = node;
203 }
204
205 static INLINE ir_node *
206 __get_irg_end_reg(const ir_graph *irg) {
207   return irg->end_reg;
208 }
209
210 static INLINE ir_node *
211 __get_irg_end_except (const ir_graph *irg) {
212   return irg->end_except;
213 }
214
215 static INLINE ir_node *
216 __get_irg_cstore(const ir_graph *irg) {
217   return irg->cstore;
218 }
219
220 static INLINE void
221 __set_irg_cstore(ir_graph *irg, ir_node *node) {
222   irg->cstore = node;
223 }
224
225 static INLINE ir_node *
226 __get_irg_frame(const ir_graph *irg) {
227   return irg->frame;
228 }
229
230 static INLINE void
231 __set_irg_frame(ir_graph *irg, ir_node *node) {
232   irg->frame = node;
233 }
234
235 static INLINE ir_node *
236 __get_irg_globals(const ir_graph *irg) {
237   return irg->globals;
238 }
239
240 static INLINE void
241 __set_irg_globals(ir_graph *irg, ir_node *node) {
242   irg->globals = node;
243 }
244
245 static INLINE ir_node *
246 __get_irg_initial_mem(const ir_graph *irg) {
247   return irg->initial_mem;
248 }
249
250 static INLINE void
251 __set_irg_initial_mem(ir_graph *irg, ir_node *node) {
252   irg->initial_mem = node;
253 }
254
255 static INLINE ir_node *
256 __get_irg_args(const ir_graph *irg) {
257   return irg->args;
258 }
259
260 static INLINE void
261 __set_irg_args(ir_graph *irg, ir_node *node) {
262   irg->args = node;
263 }
264
265 static INLINE ir_node *
266 __get_irg_bad(const ir_graph *irg) {
267   return irg->bad;
268 }
269
270 static INLINE void
271 __set_irg_bad(ir_graph *irg, ir_node *node) {
272   irg->bad = node;
273 }
274
275 static INLINE ir_node *
276 __get_irg_no_mem(const ir_graph *irg) {
277   return irg->no_mem;
278 }
279
280 static INLINE void
281 __set_irg_no_mem(ir_graph *irg, ir_node *node) {
282   irg->no_mem = node;
283 }
284 static INLINE ir_node *
285 __get_irg_current_block(const ir_graph *irg) {
286   return irg->current_block;
287 }
288
289 static INLINE void
290 __set_irg_current_block(ir_graph *irg, ir_node *node) {
291   irg->current_block = node;
292 }
293
294 static INLINE entity *
295 __get_irg_entity(const ir_graph *irg) {
296   assert(irg && irg->ent);
297   return irg->ent;
298 }
299
300 static INLINE void
301 __set_irg_entity(ir_graph *irg, entity *ent) {
302   irg->ent = ent;
303 }
304
305 static INLINE type *
306 __get_irg_frame_type(const ir_graph *irg) {
307   assert(irg && irg->frame_type);
308   return irg->frame_type;
309 }
310
311 static INLINE void
312 __set_irg_frame_type(ir_graph *irg, type *ftp) {
313   assert(is_class_type(ftp));
314   irg->frame_type = ftp;
315 }
316
317 static INLINE struct obstack *
318 __get_irg_obstack(const ir_graph *irg) {
319   return irg->obst;
320 }
321
322
323 static INLINE irg_phase_state
324 __get_irg_phase_state(const ir_graph *irg) {
325   return irg->phase_state;
326 }
327
328 static INLINE void
329 __set_irg_phase_low(ir_graph *irg) {
330   irg->phase_state = phase_low;
331 }
332
333 static INLINE op_pin_state
334 __get_irg_pinned(const ir_graph *irg) {
335   return irg->op_pin_state_pinned;
336 }
337
338 static INLINE irg_outs_state
339 __get_irg_outs_state(const ir_graph *irg) {
340   return irg->outs_state;
341 }
342
343 static INLINE void
344 __set_irg_outs_inconsistent(ir_graph *irg) {
345   irg->outs_state = outs_inconsistent;
346 }
347
348 static INLINE irg_dom_state
349 __get_irg_dom_state(const ir_graph *irg) {
350   return irg->dom_state;
351 }
352
353 static INLINE void
354 __set_irg_dom_inconsistent(ir_graph *irg) {
355   irg->dom_state = dom_inconsistent;
356 }
357
358 static INLINE irg_loopinfo_state
359 __get_irg_loopinfo_state(const ir_graph *irg) {
360   return irg->loopinfo_state;
361 }
362
363 static INLINE void
364 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
365   irg->loopinfo_state = s;
366 }
367
368 static INLINE void
369 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
370   irg->op_pin_state_pinned = p;
371 }
372
373 static INLINE irg_callee_info_state
374 __get_irg_callee_info_state(const ir_graph *irg) {
375   return irg->callee_info_state;
376 }
377
378 static INLINE void
379 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
380   irg_callee_info_state irp_state = get_irp_callee_info_state();
381
382   irg->callee_info_state = s;
383
384   /* I could compare ... but who knows? */
385   if ((irp_state == irg_callee_info_consistent)  ||
386       ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
387       set_irp_callee_info_state(s);
388 }
389
390 static INLINE irg_inline_property
391 __get_irg_inline_property(const ir_graph *irg) {
392   return irg->inline_property;
393 }
394
395 static INLINE void
396 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
397   irg->inline_property = s;
398 }
399
400 static INLINE void
401 __set_irg_link(ir_graph *irg, void *thing) {
402   irg->link = thing;
403 }
404
405 static INLINE void *
406 __get_irg_link(const ir_graph *irg) {
407   return irg->link;
408 }
409
410 static INLINE unsigned long
411 __get_irg_visited(const ir_graph *irg) {
412   return irg->visited;
413 }
414
415 static INLINE unsigned long
416 __get_irg_block_visited(const ir_graph *irg) {
417   return irg->block_visited;
418 }
419
420 static INLINE void
421 __set_irg_block_visited(ir_graph *irg, unsigned long visited) {
422   irg->block_visited = visited;
423 }
424
425 static INLINE void
426 __inc_irg_block_visited(ir_graph *irg) {
427   ++irg->block_visited;
428 }
429
430 #define get_interprocedural_view()         __get_interprocedural_view()
431 #define is_ir_graph(thing)                 __is_ir_graph(thing)
432 #define get_irg_start_block(irg)           __get_irg_start_block(irg)
433 #define set_irg_start_block(irg, node)     __set_irg_start_block(irg, node)
434 #define get_irg_start(irg)                 __get_irg_start(irg)
435 #define set_irg_start(irg, node)           __set_irg_start(irg, node)
436 #define get_irg_end_block(irg)             __get_irg_end_block(irg)
437 #define set_irg_end_block(irg, node)       __set_irg_end_block(irg, node)
438 #define get_irg_end(irg)                   __get_irg_end(irg)
439 #define set_irg_end(irg, node)             __set_irg_end(irg, node)
440 #define get_irg_end_reg(irg)               __get_irg_end_reg(irg)
441 #define get_irg_end_except(irg)            __get_irg_end_except(irg)
442 #define get_irg_cstore(irg)                __get_irg_cstore(irg)
443 #define set_irg_cstore(irg, node)          __set_irg_cstore(irg, node)
444 #define get_irg_frame(irg)                 __get_irg_frame(irg)
445 #define set_irg_frame(irg, node)           __set_irg_frame(irg, node)
446 #define get_irg_globals(irg)               __get_irg_globals(irg)
447 #define set_irg_globals(irg, node)         __set_irg_globals(irg, node)
448 #define get_irg_initial_mem(irg)           __get_irg_initial_mem(irg)
449 #define set_irg_initial_mem(irg, node)     __set_irg_initial_mem(irg, node)
450 #define get_irg_args(irg)                  __get_irg_args(irg)
451 #define set_irg_args(irg, node)            __set_irg_args(irg, node)
452 #define get_irg_bad(irg)                   __get_irg_bad(irg)
453 #define set_irg_bad(irg, node)             __set_irg_bad(irg, node)
454 #define get_irg_no_mem(irg)                __get_irg_no_mem(irg)
455 #define set_irg_no_mem(irg, node)          __set_irg_no_mem(irg, node)
456 #define get_irg_current_block(irg)         __get_irg_current_block(irg)
457 #define set_irg_current_block(irg, node)   __set_irg_current_block(irg, node)
458 #define get_irg_entity(irg)                __get_irg_entity(irg)
459 #define set_irg_entity(irg, ent)           __set_irg_entity(irg, ent)
460 #define get_irg_frame_type(irg)            __get_irg_frame_type(irg)
461 #define set_irg_frame_type(irg, ftp)       __set_irg_frame_type(irg, ftp)
462 #define get_irg_obstack(irg)               __get_irg_obstack(irg)
463 #define get_irg_phase_state(irg)           __get_irg_phase_state(irg)
464 #define set_irg_phase_low(irg)             __set_irg_phase_low(irg)
465 #define get_irg_pinned(irg)                __get_irg_pinned(irg)
466 #define get_irg_outs_state(irg)            __get_irg_outs_state(irg)
467 #define set_irg_outs_inconsistent(irg)     __set_irg_outs_inconsistent(irg)
468 #define get_irg_dom_state(irg)             __get_irg_dom_state(irg)
469 #define set_irg_dom_inconsistent(irg)      __set_irg_dom_inconsistent(irg)
470 #define get_irg_loopinfo_state(irg)        __get_irg_loopinfo_state(irg)
471 #define set_irg_loopinfo_state(irg, s)     __set_irg_loopinfo_state(irg, s)
472 #define set_irg_pinned(irg, p)             __set_irg_pinned(irg, p)
473 #define get_irg_callee_info_state(irg)     __get_irg_callee_info_state(irg)
474 #define set_irg_callee_info_state(irg, s)  __set_irg_callee_info_state(irg, s)
475 #define get_irg_inline_property(irg)       __get_irg_inline_property(irg)
476 #define set_irg_inline_property(irg, s)    __set_irg_inline_property(irg, s)
477 #define set_irg_link(irg, thing)           __set_irg_link(irg, thing)
478 #define get_irg_link(irg)                  __get_irg_link(irg)
479 #define get_irg_visited(irg)               __get_irg_visited(irg)
480 #define get_irg_block_visited(irg)         __get_irg_block_visited(irg)
481 #define set_irg_block_visited(irg, v)      __set_irg_block_visited(irg, v)
482 #define inc_irg_block_visited(irg)         __inc_irg_block_visited(irg)
483
484 # endif /* _IRGRAPH_T_H_ */