Further pushed size_t: trouts functions uses size_t now.
[libfirm] / include / libfirm / trouts.h
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Reverse edges that reference types/entities.
23  * @author   Goetz Lindenmaier
24  * @date     29.10.2004
25  * @version  $Id$
26  * @brief
27  *  Trouts list all uses of types and entities.
28  *  Each type gets a list of all Alloc nodes allocating it.
29  *  Each entity gets two lists:
30  *    - one containing all accesses (Load, (Call), Store),
31  *    - and one containing all uses to get a reference (Sel, SymConst).
32  */
33 #ifndef FIRM_ANA_TROUTS_H
34 #define FIRM_ANA_TROUTS_H
35
36 #include "firm_types.h"
37 #include "irgraph.h"
38
39 #include "begin.h"
40
41 /*-----------------------------------------------------------------*/
42 /* Accessing the trout datastructures.                             */
43 /* These routines only work properly if firm is in state           */
44 /* trouts_consistent or trouts_inconsistent.                       */
45 /*-----------------------------------------------------------------*/
46
47 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
48 /* entities                                                        */
49 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
50
51 /** Number of Load/Store nodes that possibly access this entity. */
52 FIRM_API size_t get_entity_n_accesses(const ir_entity *ent);
53 /** Load/Store node that possibly access this entity. */
54 FIRM_API ir_node *get_entity_access(const ir_entity *ent, int pos);
55
56 /** Number of references to an entity, in form of SymConst/Sel.
57  *  Including references from constant entities and the like. */
58 FIRM_API size_t get_entity_n_references(const ir_entity *ent);
59 /** References to an entity, in form of SymConst/Sel
60  *  Including references from constants. */
61 FIRM_API ir_node *get_entity_reference(const ir_entity *ent, size_t pos);
62
63 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
64 /* types                                                           */
65 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
66
67 /** Number of Alloc nodes that create an instance of this type. */
68 FIRM_API size_t get_type_n_allocs(const ir_type *tp);
69 /** Alloc node that create an instance of this type. */
70 FIRM_API ir_node *get_type_alloc(const ir_type *tp, size_t pos);
71
72 /** Number of Cast nodes that cast a pointer to this type. */
73 FIRM_API size_t get_type_n_casts(const ir_type *tp);
74 /** Cast node that cast a pointer to this type. */
75 FIRM_API ir_node *get_type_cast(const ir_type *tp, size_t pos);
76 FIRM_API void add_type_cast(const ir_type *tp, ir_node *cast);
77 /** Return number of upcasts. O(\#casts). */
78 FIRM_API size_t get_class_n_upcasts(const ir_type *clss);
79 /** Return number of downcasts. O(\#casts). */
80 FIRM_API size_t get_class_n_downcasts(const ir_type *clss);
81
82 /* Access all pointer types that point to tp. */
83 FIRM_API size_t  get_type_n_pointertypes_to(const ir_type *tp);
84 FIRM_API ir_type *get_type_pointertype_to(const ir_type *tp, size_t pos);
85 FIRM_API void    add_type_pointertype_to(const ir_type *tp, ir_type *ptp);
86
87 /* Access all array types that contain elements of type tp.
88  * Does not find subarrays, e.g., int[] being element of int[][]
89  * for multi dimensional arrays. */
90 FIRM_API size_t  get_type_n_arraytypes_of(const ir_type *tp);
91 FIRM_API ir_type *get_type_arraytype_of(const ir_type *tp, size_t pos);
92 FIRM_API void    add_type_arraytype_of(const ir_type *tp, ir_type *atp);
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 FIRM_API irg_outs_state get_trouts_state(void);
103 /** Set the tr out state to inconsistent if it is consistent. */
104 FIRM_API 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 FIRM_API void compute_trouts(void);
129
130 /** Free trout data. */
131 FIRM_API void free_trouts(void);
132
133 #include "end.h"
134
135 #endif