analyses polymorphic calls if callee info is available
[libfirm] / ir / ana / trouts.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ana/trouts.h
4  * Purpose:     Reverse edges that reference types/entities.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     29.10.2004
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2004 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file trouts.h
15  *
16  * Trouts list all uses of types and entities.
17  * Each type gets a list of all Alloc nodes allocating it.
18  * Each entity gets two lists:
19  *   - one containing all accesses (Load, (Call), Store),
20  *   - and one containing all uses to get a reference (Sel, SymConst).
21  *
22  * @todo
23  *   To list all uses of entities of a type, we also should list all
24  *   static/automatic allocated entities in types.  The Alloc nodes
25  *   represent only the dynamic allocated entities.
26  *
27  * @author Goetz Lindenmaier
28  *
29  */
30
31 # ifndef _TROUTS_H_
32 # define _TROUTS_H_
33
34 #include "firm_types.h"
35 #include "irgraph.h"
36
37 /*-----------------------------------------------------------------*/
38 /* Accessing the trout datastructures.                             */
39 /* These routines only work properly if firm is in state           */
40 /* trouts_consistent or trouts_inconsistent.                       */
41 /*-----------------------------------------------------------------*/
42
43 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
44 /* entities                                                        */
45 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
46
47 /** Number of Load/Store nodes that possibly access this entity. */
48 int get_entity_n_accesses(entity *ent);
49 /** Load/Store node that possibly access this entity. */
50 ir_node *get_entity_access(entity *ent, int pos);
51
52 /** Number of references to an entity, in form of SymConst/Sel.
53  *  Including references from constant entities and the like. */
54 int get_entity_n_references(entity *ent);
55 /** References to an entity, in form of SymConst/Sel
56  *  Including references from constants. */
57 ir_node *get_entity_reference(entity *ent, int pos);
58
59 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
60 /* types                                                           */
61 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
62
63 /** Number of Alloc nodes that create an instance of this type. */
64 int get_type_n_allocs(type *tp);
65 /** Alloc node that create an instance of this type. */
66 ir_node *get_type_alloc(type *tp, int pos);
67
68 /** Number of Cast nodes that cast a pointer to this type. */
69 int get_type_n_casts(type *tp);
70 /** Cast node that cast a pointer to this type. */
71 ir_node *get_type_cast(type *tp, int pos);
72 void add_type_cast(type *tp, ir_node *cast);
73 /** Return number of upcasts. O(#casts). */
74 int get_class_n_upcasts(type *clss);
75 /** Return number of downcasts. O(#casts). */
76 int get_class_n_downcasts(type *clss);
77
78 /* Access all pointer types that point to tp. */
79 int   get_type_n_pointertypes_to(type *tp);
80 type *get_type_pointertype_to(type *tp, int pos);
81 void  add_type_pointertype_to(type *tp, type *ptp);
82
83 /* Access all array types that contain elements of type tp.
84  * Does not find subarrays, e.g., int[] being element of int[][]
85  * for multi dimensional arrays. */
86 int   get_type_n_arraytypes_of(type *tp);
87 type *get_type_arraytype_of(type *tp, int pos);
88 void  add_type_arraytype_of(type *tp, type *atp);
89
90
91
92 /* @@@ TODO: compute all entities that use a type. */
93
94 /*------------------------------------------------------------------*/
95 /* Building and Removing the trout datastructure                    */
96 /*------------------------------------------------------------------*/
97
98 /** The state of the tr_out datastructure.
99  *
100  *  We reuse the enum of irouts.
101  *  @see irouts.h. */
102 irg_outs_state get_trouts_state(void);
103 /** Set the tr out state to inconsistent if it is consistent. */
104 void           set_trouts_inconsistent(void);
105
106 /** Compute the outs of types and entities.
107  *
108  *  Collects all reference from irnodes to types or entities in the
109  *  corresponding types/entities.  Further reverses references between
110  *  types and entities.
111  *
112  *  Annotates the following nodes:
113  *    Alloc    --> get_Alloc_type()
114  *    Cast     --> get_Cast_type()
115  *    Sel      --> get_Sel_entity()
116  *    SymConst --> get_SymConst_entity()
117  *    Load(addr)  --> get_addr_entity() \  ent von SymConst, oder falls Sel: ent von
118  *    Store(addr) --> get_addr_entity() /  outermost im compound.  Ansonsten: nirgends.
119  *                                         d.h. wir bekommen die array Elementzugriffe
120  *                                         an die jack array Klasse annotiert.
121  *    Call(Sel)   --> get_Sel_entity()  // ev. Tabellenzugriff --> Load.
122  *
123  *   type --> pointer type refering to this type.
124  *   type --> entity of this type. @@@ to be implemented.
125  *
126  *  Sets trout state to outs_consistent.
127  */
128 void compute_trouts(void);
129
130 /** Free trout data. */
131 void free_trouts(void);
132
133
134 #endif /* _TROUTS_H_ */