3 * File name: ir/ana/trouts.h
4 * Purpose: Reverse edges that reference types/entities.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2004 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
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).
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.
27 * @author Goetz Lindenmaier
34 #include "firm_types.h"
37 /*-----------------------------------------------------------------*/
38 /* Accessing the trout datastructures. */
39 /* These routines only work properly if firm is in state */
40 /* trouts_consistent or trouts_inconsistent. */
41 /*-----------------------------------------------------------------*/
43 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
45 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
47 /** Number of Load/Store nodes that possibly access this entity. */
48 int get_entity_n_accesses(ir_entity *ent);
49 /** Load/Store node that possibly access this entity. */
50 ir_node *get_entity_access(ir_entity *ent, int pos);
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(ir_entity *ent);
55 /** References to an entity, in form of SymConst/Sel
56 * Including references from constants. */
57 ir_node *get_entity_reference(ir_entity *ent, int pos);
59 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
61 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
63 /** Number of Alloc nodes that create an instance of this type. */
64 int get_type_n_allocs(ir_type *tp);
65 /** Alloc node that create an instance of this type. */
66 ir_node *get_type_alloc(ir_type *tp, int pos);
68 /** Number of Cast nodes that cast a pointer to this type. */
69 int get_type_n_casts(ir_type *tp);
70 /** Cast node that cast a pointer to this type. */
71 ir_node *get_type_cast(ir_type *tp, int pos);
72 void add_type_cast(ir_type *tp, ir_node *cast);
73 /** Return number of upcasts. O(#casts). */
74 int get_class_n_upcasts(ir_type *clss);
75 /** Return number of downcasts. O(#casts). */
76 int get_class_n_downcasts(ir_type *clss);
78 /* Access all pointer types that point to tp. */
79 int get_type_n_pointertypes_to(ir_type *tp);
80 ir_type *get_type_pointertype_to(ir_type *tp, int pos);
81 void add_type_pointertype_to(ir_type *tp, ir_type *ptp);
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(ir_type *tp);
87 ir_type *get_type_arraytype_of(ir_type *tp, int pos);
88 void add_type_arraytype_of(ir_type *tp, ir_type *atp);
92 /* @@@ TODO: compute all entities that use a type. */
94 /*------------------------------------------------------------------*/
95 /* Building and Removing the trout datastructure */
96 /*------------------------------------------------------------------*/
98 /** The state of the tr_out datastructure.
100 * We reuse the enum of irouts.
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);
106 /** Compute the outs of types and entities.
108 * Collects all reference from irnodes to types or entities in the
109 * corresponding types/entities. Further reverses references between
110 * types and entities.
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.
123 * type --> pointer type refering to this type.
124 * type --> entity of this type. @@@ to be implemented.
126 * Sets trout state to outs_consistent.
128 void compute_trouts(void);
130 /** Free trout data. */
131 void free_trouts(void);
134 #endif /* _TROUTS_H_ */