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