properly mark symbols in the public API to be exported. This allows us to use -fvisib...
[libfirm] / include / libfirm / trouts.h
1 /*
2  * Copyright (C) 1995-2008 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  * @todo
34  *   To list all uses of entities of a type, we also should list all
35  *   static/automatic allocated entities in types.  The Alloc nodes
36  *   represent only the dynamic allocated entities.
37  */
38 #ifndef FIRM_ANA_TROUTS_H
39 #define FIRM_ANA_TROUTS_H
40
41 #include "firm_types.h"
42 #include "irgraph.h"
43
44 #include "begin.h"
45
46 /*-----------------------------------------------------------------*/
47 /* Accessing the trout datastructures.                             */
48 /* These routines only work properly if firm is in state           */
49 /* trouts_consistent or trouts_inconsistent.                       */
50 /*-----------------------------------------------------------------*/
51
52 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
53 /* entities                                                        */
54 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
55
56 /** Number of Load/Store nodes that possibly access this entity. */
57 FIRM_DLL int get_entity_n_accesses(const ir_entity *ent);
58 /** Load/Store node that possibly access this entity. */
59 FIRM_DLL ir_node *get_entity_access(const ir_entity *ent, int pos);
60
61 /** Number of references to an entity, in form of SymConst/Sel.
62  *  Including references from constant entities and the like. */
63 FIRM_DLL int get_entity_n_references(const ir_entity *ent);
64 /** References to an entity, in form of SymConst/Sel
65  *  Including references from constants. */
66 FIRM_DLL ir_node *get_entity_reference(const ir_entity *ent, int pos);
67
68 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
69 /* types                                                           */
70 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
71
72 /** Number of Alloc nodes that create an instance of this type. */
73 FIRM_DLL int get_type_n_allocs(const ir_type *tp);
74 /** Alloc node that create an instance of this type. */
75 FIRM_DLL ir_node *get_type_alloc(const ir_type *tp, int pos);
76
77 /** Number of Cast nodes that cast a pointer to this type. */
78 FIRM_DLL int get_type_n_casts(const ir_type *tp);
79 /** Cast node that cast a pointer to this type. */
80 FIRM_DLL ir_node *get_type_cast(const ir_type *tp, int pos);
81 FIRM_DLL void add_type_cast(const ir_type *tp, ir_node *cast);
82 /** Return number of upcasts. O(\#casts). */
83 FIRM_DLL int get_class_n_upcasts(const ir_type *clss);
84 /** Return number of downcasts. O(\#casts). */
85 FIRM_DLL int get_class_n_downcasts(const ir_type *clss);
86
87 /* Access all pointer types that point to tp. */
88 FIRM_DLL int     get_type_n_pointertypes_to(const ir_type *tp);
89 FIRM_DLL ir_type *get_type_pointertype_to(const ir_type *tp, int pos);
90 FIRM_DLL void    add_type_pointertype_to(const ir_type *tp, ir_type *ptp);
91
92 /* Access all array types that contain elements of type tp.
93  * Does not find subarrays, e.g., int[] being element of int[][]
94  * for multi dimensional arrays. */
95 FIRM_DLL int     get_type_n_arraytypes_of(const ir_type *tp);
96 FIRM_DLL ir_type *get_type_arraytype_of(const ir_type *tp, int pos);
97 FIRM_DLL void    add_type_arraytype_of(const ir_type *tp, ir_type *atp);
98
99 /*------------------------------------------------------------------*/
100 /* Building and Removing the trout datastructure                    */
101 /*------------------------------------------------------------------*/
102
103 /** The state of the tr_out datastructure.
104  *
105  *  We reuse the enum of irouts.
106  *  @see irouts.h. */
107 FIRM_DLL irg_outs_state get_trouts_state(void);
108 /** Set the tr out state to inconsistent if it is consistent. */
109 FIRM_DLL void           set_trouts_inconsistent(void);
110
111 /** Compute the outs of types and entities.
112  *
113  *  Collects all reference from irnodes to types or entities in the
114  *  corresponding types/entities.  Further reverses references between
115  *  types and entities.
116  *
117  *  Annotates the following nodes:
118  *    Alloc    --> get_Alloc_type()
119  *    Cast     --> get_Cast_type()
120  *    Sel      --> get_Sel_entity()
121  *    SymConst --> get_SymConst_entity()
122  *    Load(addr)  --> get_addr_entity() \  ent von SymConst, oder falls Sel: ent von
123  *    Store(addr) --> get_addr_entity() /  outermost im compound.  Ansonsten: nirgends.
124  *                                         d.h. wir bekommen die array Elementzugriffe
125  *                                         an die jack array Klasse annotiert.
126  *    Call(Sel)   --> get_Sel_entity()  // ev. Tabellenzugriff --> Load.
127  *
128  *   type --> pointer type refering to this type.
129  *   type --> entity of this type. @@@ to be implemented.
130  *
131  *  Sets trout state to outs_consistent.
132  */
133 FIRM_DLL void compute_trouts(void);
134
135 /** Free trout data. */
136 FIRM_DLL void free_trouts(void);
137
138 #include "end.h"
139
140 #endif