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