326eef6511e15ae912fe7ef46369eee1e7f22d44
[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 #include "pseudo_irg.h"
31
32 #include "irloop.h"
33
34 #include "obst.h"
35 #include "pset.h"
36 #include "set.h"
37 #include "type_t.h"
38
39 #define FRAME_TP_SUFFIX "frame_tp"
40
41 /**
42  * Edge info to put into an irg.
43  */
44 typedef struct _irg_edge_info_t {
45         set *edges;
46         unsigned activated : 1;
47 } irg_edge_info_t;
48
49
50 /** ir_graph holds all information for a procedure */
51 struct ir_graph {
52   firm_kind         kind;            /**<  always set to k_ir_graph*/
53   /* --  Basics of the representation -- */
54   struct entity  *ent;               /**< The entity of this procedure, i.e.,
55                     the type of the procedure and the
56                     class it belongs to. */
57   struct type    *frame_type;    /**< A class type representing the stack frame.
58                     Can include "inner" methods. */
59   struct ir_node *start_block;   /**< block the start node will belong to */
60   struct ir_node *start;         /**< start node of this ir_graph */
61   struct ir_node *end_block;     /**< block the end node will belong to */
62   struct ir_node *end;           /**< end node of this ir_graph */
63   struct ir_node *end_reg;       /**< end node of this ir_graph */
64   struct ir_node *end_except;    /**< end node of this ir_graph */
65   struct ir_node *cstore;        /**< constant store -- no more needed!! */
66   struct ir_node *frame;         /**< method's frame */
67   struct ir_node *globals;       /**< pointer to the data segment containing all
68                     globals as well as global procedures. */
69   struct ir_node *initial_mem;   /**< initial memory of this graph */
70   struct ir_node *args;          /**< methods arguments */
71   struct ir_node **proj_args;    /**< projs of the methods arguments */
72   struct ir_node *bad;           /**< bad node of this ir_graph, the one and
73                     only in this graph */
74   struct ir_node *no_mem;        /**< NoMem node of this ir_graph, the one and
75                     only in this graph */
76   /* GL removed: we need unknown with mode for analyses. */
77   /*   struct ir_node *unknown;*/           /**< unknown node of this ir_graph */
78   struct obstack *obst;          /**< obstack where all of the ir_nodes live */
79   struct ir_node *current_block;     /**< block for newly gen_*()-erated
80                     ir_nodes */
81
82   /* -- Fields indicating different states of irgraph -- */
83   irg_phase_state phase_state;       /**< compiler phase */
84   op_pin_state op_pin_state_pinned;  /**< Flag for status of nodes */
85   irg_outs_state outs_state;         /**< Out edges. */
86   irg_dom_state dom_state;           /**< Dominator information */
87   ir_typeinfo_state typeinfo_state;        /**< Validity of type information */
88   irg_callee_info_state callee_info_state; /**< Validity of callee information */
89   irg_inline_property inline_property;     /**< How to handle inlineing. */
90   irg_loopinfo_state loopinfo_state;       /**< state of loop information */
91
92   /* -- Fields for construction -- */
93 #if USE_EXPLICIT_PHI_IN_STACK
94   struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
95 #endif
96   int n_loc;                         /**< number of local variable in this
97                                           procedure including procedure parameters. */
98   void **loc_descriptions;           /**< storage for local variable desriptions */
99
100   /* -- Fields for optimizations / analysis information -- */
101   pset *value_table;                 /**< hash table for global value numbering (cse)
102                     for optimizing use in iropt.c */
103   struct ir_node **outs;             /**< Space for the out arrays. */
104
105 #ifdef DEBUG_libfirm
106   int             n_outs;            /* < Size wasted for outs */
107 #endif /* defined DEBUG_libfirm */
108   struct ir_loop *loop;              /**< The outermost loop */
109   void *link;                        /**< A void* field to link any information to
110                     the node. */
111
112   ir_graph **callers;                /**< For callgraph analysis. */
113   unsigned char *caller_isbe;        /**< For callgraph analysis: set if backedge. */
114   ir_graph **callees;                /**< For callgraph analysis. */
115   unsigned char *callee_isbe;        /**< For callgraph analysis: set if backedge. */
116   int        callgraph_loop_depth;         /**< For callgraph analysis */
117   int        callgraph_recursion_depth;    /**< For callgraph analysis */
118   double     method_execution_frequency;   /**< For callgraph analysis */
119
120   ir_loop   *l;
121
122   /* -- Fields for Walking the graph -- */
123   unsigned long visited;             /**< this flag is an identifier for
124                     ir walk. it will be incremented
125                     every time someone walks through
126                     the graph */
127   unsigned long block_visited;       /**< same as visited, for a complete block */
128 #ifdef DEBUG_libfirm
129   int graph_nr;             /**< a unique graph number for each graph to make output
130                    readable. */
131 #endif
132
133 #if FIRM_EDGES_INPLACE
134   irg_edge_info_t edge_info;  /**< edge info for automatic outs */
135 #endif
136 };
137
138 /**
139  * Initializes the graph construction module
140  */
141 void init_irgraph(void);
142
143 /* Internal constructor that does not add to irp_irgs or the like. */
144 ir_graph *new_r_ir_graph (entity *ent, int n_loc);
145
146 /** Make a rudimentary ir graph for the constant code.
147    Must look like a correct irg, spare everything else. */
148 ir_graph *new_const_code_irg(void);
149
150 /**
151  * Set the op_pin_state_pinned state of a graph.
152  *
153  * @param irg     the IR graph
154  * @param p       new pin state
155  */
156 INLINE void
157 set_irg_pinned (ir_graph *irg, op_pin_state p);
158
159 /** Returns the obstack associated with the graph. */
160 struct obstack *get_irg_obstack(const ir_graph *irg);
161
162 /**
163  * Returns true if the node n is allocated on the storage of graph irg.
164  *
165  * @param irg   the IR graph
166  * @param n the IR node
167  */
168 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
169
170 /*-------------------------------------------------------------------*/
171 /* inline functions for graphs                                       */
172 /*-------------------------------------------------------------------*/
173
174 extern int __interprocedural_view;
175
176 static INLINE int
177 _get_interprocedural_view(void) {
178   return __interprocedural_view;
179 }
180
181 static INLINE int
182 _is_ir_graph(const void *thing) {
183   return (get_kind(thing) == k_ir_graph);
184 }
185
186 /** Returns the start block of a graph. */
187 static INLINE ir_node *
188 _get_irg_start_block(const ir_graph *irg) {
189   return irg->start_block;
190 }
191
192 static INLINE void
193 _set_irg_start_block(ir_graph *irg, ir_node *node) {
194   irg->start_block = node;
195 }
196
197 static INLINE ir_node *
198 _get_irg_start(const ir_graph *irg) {
199   return irg->start;
200 }
201
202 static INLINE void
203 _set_irg_start(ir_graph *irg, ir_node *node) {
204   irg->start = node;
205 }
206
207 static INLINE ir_node *
208 _get_irg_end_block(const ir_graph *irg) {
209   return irg->end_block;
210 }
211
212 static INLINE void
213 _set_irg_end_block(ir_graph *irg, ir_node *node) {
214   irg->end_block = node;
215 }
216
217 static INLINE ir_node *
218 _get_irg_end(const ir_graph *irg) {
219   return irg->end;
220 }
221
222 static INLINE void
223 _set_irg_end(ir_graph *irg, ir_node *node) {
224   irg->end = node;
225 }
226
227 static INLINE ir_node *
228 _get_irg_end_reg(const ir_graph *irg) {
229   return irg->end_reg;
230 }
231
232 static INLINE ir_node *
233 _get_irg_end_except (const ir_graph *irg) {
234   return irg->end_except;
235 }
236
237 static INLINE ir_node *
238 _get_irg_cstore(const ir_graph *irg) {
239   return irg->cstore;
240 }
241
242 static INLINE void
243 _set_irg_cstore(ir_graph *irg, ir_node *node) {
244   irg->cstore = node;
245 }
246
247 static INLINE ir_node *
248 _get_irg_frame(const ir_graph *irg) {
249   return irg->frame;
250 }
251
252 static INLINE void
253 _set_irg_frame(ir_graph *irg, ir_node *node) {
254   irg->frame = node;
255 }
256
257 static INLINE ir_node *
258 _get_irg_globals(const ir_graph *irg) {
259   return irg->globals;
260 }
261
262 static INLINE void
263 _set_irg_globals(ir_graph *irg, ir_node *node) {
264   irg->globals = node;
265 }
266
267 static INLINE ir_node *
268 _get_irg_initial_mem(const ir_graph *irg) {
269   return irg->initial_mem;
270 }
271
272 static INLINE void
273 _set_irg_initial_mem(ir_graph *irg, ir_node *node) {
274   irg->initial_mem = node;
275 }
276
277 static INLINE ir_node *
278 _get_irg_args(const ir_graph *irg) {
279   return irg->args;
280 }
281
282 static INLINE void
283 _set_irg_args(ir_graph *irg, ir_node *node) {
284   irg->args = node;
285 }
286
287 static INLINE ir_node **
288 _get_irg_proj_args(const ir_graph *irg) {
289   return irg->proj_args;
290 }
291
292 static INLINE void
293 _set_irg_proj_args(ir_graph *irg, ir_node **nodes) {
294   irg->proj_args = nodes;
295 }
296
297 static INLINE ir_node *
298 _get_irg_bad(const ir_graph *irg) {
299   return irg->bad;
300 }
301
302 static INLINE void
303 _set_irg_bad(ir_graph *irg, ir_node *node) {
304   irg->bad = node;
305 }
306
307 static INLINE ir_node *
308 _get_irg_no_mem(const ir_graph *irg) {
309   return irg->no_mem;
310 }
311
312 static INLINE void
313 _set_irg_no_mem(ir_graph *irg, ir_node *node) {
314   irg->no_mem = node;
315 }
316 static INLINE ir_node *
317 _get_irg_current_block(const ir_graph *irg) {
318   return irg->current_block;
319 }
320
321 static INLINE void
322 _set_irg_current_block(ir_graph *irg, ir_node *node) {
323   irg->current_block = node;
324 }
325
326 static INLINE entity *
327 _get_irg_entity(const ir_graph *irg) {
328   assert(irg && irg->ent);
329   return irg->ent;
330 }
331
332 static INLINE void
333 _set_irg_entity(ir_graph *irg, entity *ent) {
334   irg->ent = ent;
335 }
336
337 static INLINE type *
338 _get_irg_frame_type(const ir_graph *irg) {
339   assert(irg && irg->frame_type);
340   return irg->frame_type;
341 }
342
343 static INLINE void
344 _set_irg_frame_type(ir_graph *irg, type *ftp) {
345   assert(is_Class_type(ftp));
346   irg->frame_type = ftp;
347 }
348
349 static INLINE struct obstack *
350 _get_irg_obstack(const ir_graph *irg) {
351   return irg->obst;
352 }
353
354
355 static INLINE irg_phase_state
356 _get_irg_phase_state(const ir_graph *irg) {
357   return irg->phase_state;
358 }
359
360 static INLINE void
361 _set_irg_phase_low(ir_graph *irg) {
362   irg->phase_state = phase_low;
363 }
364
365 static INLINE op_pin_state
366 _get_irg_pinned(const ir_graph *irg) {
367   return irg->op_pin_state_pinned;
368 }
369
370 static INLINE irg_outs_state
371 _get_irg_outs_state(const ir_graph *irg) {
372   return irg->outs_state;
373 }
374
375 static INLINE void
376 _set_irg_outs_inconsistent(ir_graph *irg) {
377   irg->outs_state = outs_inconsistent;
378 }
379
380 static INLINE irg_dom_state
381 _get_irg_dom_state(const ir_graph *irg) {
382   return irg->dom_state;
383 }
384
385 static INLINE void
386 _set_irg_dom_inconsistent(ir_graph *irg) {
387   irg->dom_state = dom_inconsistent;
388 }
389
390 static INLINE irg_loopinfo_state
391 _get_irg_loopinfo_state(const ir_graph *irg) {
392   return irg->loopinfo_state;
393 }
394
395 static INLINE void
396 _set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
397   irg->loopinfo_state = s;
398 }
399
400 static INLINE void
401 _set_irg_pinned(ir_graph *irg, op_pin_state p) {
402   irg->op_pin_state_pinned = p;
403 }
404
405 static INLINE irg_callee_info_state
406 _get_irg_callee_info_state(const ir_graph *irg) {
407   return irg->callee_info_state;
408 }
409
410 static INLINE void
411 _set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
412   irg_callee_info_state irp_state = get_irp_callee_info_state();
413
414   irg->callee_info_state = s;
415
416   /* I could compare ... but who knows? */
417   if ((irp_state == irg_callee_info_consistent)  ||
418       ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
419       set_irp_callee_info_state(s);
420 }
421
422 static INLINE irg_inline_property
423 _get_irg_inline_property(const ir_graph *irg) {
424   return irg->inline_property;
425 }
426
427 static INLINE void
428 _set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
429   irg->inline_property = s;
430 }
431
432 static INLINE void
433 _set_irg_link(ir_graph *irg, void *thing) {
434   irg->link = thing;
435 }
436
437 static INLINE void *
438 _get_irg_link(const ir_graph *irg) {
439   return irg->link;
440 }
441
442 static INLINE unsigned long
443 _get_irg_visited(const ir_graph *irg) {
444   return irg->visited;
445 }
446
447 static INLINE unsigned long
448 _get_irg_block_visited(const ir_graph *irg) {
449   return irg->block_visited;
450 }
451
452 static INLINE void
453 _set_irg_block_visited(ir_graph *irg, unsigned long visited) {
454   irg->block_visited = visited;
455 }
456
457 static INLINE void
458 _inc_irg_block_visited(ir_graph *irg) {
459   ++irg->block_visited;
460 }
461
462 #define get_interprocedural_view()         _get_interprocedural_view()
463 #define is_ir_graph(thing)                 _is_ir_graph(thing)
464 #define get_irg_start_block(irg)           _get_irg_start_block(irg)
465 #define set_irg_start_block(irg, node)     _set_irg_start_block(irg, node)
466 #define get_irg_start(irg)                 _get_irg_start(irg)
467 #define set_irg_start(irg, node)           _set_irg_start(irg, node)
468 #define get_irg_end_block(irg)             _get_irg_end_block(irg)
469 #define set_irg_end_block(irg, node)       _set_irg_end_block(irg, node)
470 #define get_irg_end(irg)                   _get_irg_end(irg)
471 #define set_irg_end(irg, node)             _set_irg_end(irg, node)
472 #define get_irg_end_reg(irg)               _get_irg_end_reg(irg)
473 #define get_irg_end_except(irg)            _get_irg_end_except(irg)
474 #define get_irg_cstore(irg)                _get_irg_cstore(irg)
475 #define set_irg_cstore(irg, node)          _set_irg_cstore(irg, node)
476 #define get_irg_frame(irg)                 _get_irg_frame(irg)
477 #define set_irg_frame(irg, node)           _set_irg_frame(irg, node)
478 #define get_irg_globals(irg)               _get_irg_globals(irg)
479 #define set_irg_globals(irg, node)         _set_irg_globals(irg, node)
480 #define get_irg_initial_mem(irg)           _get_irg_initial_mem(irg)
481 #define set_irg_initial_mem(irg, node)     _set_irg_initial_mem(irg, node)
482 #define get_irg_args(irg)                  _get_irg_args(irg)
483 #define set_irg_args(irg, node)            _set_irg_args(irg, node)
484 #define get_irg_bad(irg)                   _get_irg_bad(irg)
485 #define set_irg_bad(irg, node)             _set_irg_bad(irg, node)
486 #define get_irg_no_mem(irg)                _get_irg_no_mem(irg)
487 #define set_irg_no_mem(irg, node)          _set_irg_no_mem(irg, node)
488 #define get_irg_current_block(irg)         _get_irg_current_block(irg)
489 #define set_irg_current_block(irg, node)   _set_irg_current_block(irg, node)
490 #define get_irg_entity(irg)                _get_irg_entity(irg)
491 #define set_irg_entity(irg, ent)           _set_irg_entity(irg, ent)
492 #define get_irg_frame_type(irg)            _get_irg_frame_type(irg)
493 #define set_irg_frame_type(irg, ftp)       _set_irg_frame_type(irg, ftp)
494 #define get_irg_obstack(irg)               _get_irg_obstack(irg)
495 #define get_irg_phase_state(irg)           _get_irg_phase_state(irg)
496 #define set_irg_phase_low(irg)             _set_irg_phase_low(irg)
497 #define get_irg_pinned(irg)                _get_irg_pinned(irg)
498 #define get_irg_outs_state(irg)            _get_irg_outs_state(irg)
499 #define set_irg_outs_inconsistent(irg)     _set_irg_outs_inconsistent(irg)
500 #define get_irg_dom_state(irg)             _get_irg_dom_state(irg)
501 #define set_irg_dom_inconsistent(irg)      _set_irg_dom_inconsistent(irg)
502 #define get_irg_loopinfo_state(irg)        _get_irg_loopinfo_state(irg)
503 #define set_irg_loopinfo_state(irg, s)     _set_irg_loopinfo_state(irg, s)
504 #define set_irg_pinned(irg, p)             _set_irg_pinned(irg, p)
505 #define get_irg_callee_info_state(irg)     _get_irg_callee_info_state(irg)
506 #define set_irg_callee_info_state(irg, s)  _set_irg_callee_info_state(irg, s)
507 #define get_irg_inline_property(irg)       _get_irg_inline_property(irg)
508 #define set_irg_inline_property(irg, s)    _set_irg_inline_property(irg, s)
509 #define set_irg_link(irg, thing)           _set_irg_link(irg, thing)
510 #define get_irg_link(irg)                  _get_irg_link(irg)
511 #define get_irg_visited(irg)               _get_irg_visited(irg)
512 #define get_irg_block_visited(irg)         _get_irg_block_visited(irg)
513 #define set_irg_block_visited(irg, v)      _set_irg_block_visited(irg, v)
514 #define inc_irg_block_visited(irg)         _inc_irg_block_visited(irg)
515
516 # endif /* _IRGRAPH_T_H_ */