fehler119 is C99
[libfirm] / include / libfirm / irmemory.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    Memory disambiguator
23  * @author   Michael Beck
24  * @date     27.12.2006
25  * @version  $Id$
26  */
27 #ifndef FIRM_ANA_IRMEMORY_H
28 #define FIRM_ANA_IRMEMORY_H
29
30 #include "firm_types.h"
31
32 /** The alias relation of two memory addresses. */
33 typedef enum {
34         ir_no_alias,       /**< No alias. */
35         ir_may_alias,      /**< Unknown state, may alias. */
36         ir_sure_alias      /**< Sure alias. */
37 } ir_alias_relation;
38
39 /** The state of the address taken flags. */
40 typedef enum {
41         ir_address_taken_not_computed, /**< Address taken flag is not computed. */
42         ir_address_taken_computed      /**< Address taken flag is computed. */
43 } ir_address_taken_computed_state;
44
45 /** Possible options for the memory disambiguator. */
46 typedef enum {
47         aa_opt_no_opt              = 0,  /**< no options: most conservative */
48         aa_opt_type_based          = 1,  /**< use type based alias analysis: strict typed source language */
49         aa_opt_byte_type_may_alias = 2,  /**< if type based analysis is enabled: bytes types may alias other types */
50         aa_opt_no_alias            = 4,  /**< two addresses NEVER alias, use with CAUTION (gcc -fno-alias) */
51         aa_opt_inherited           = 128 /**< only for implementation: options from a graph are inherited from global */
52 } ir_disambuigator_options;
53
54 /**
55  * Classify storage locations.
56  * Except ir_sc_pointer they are all disjoint.
57  * ir_sc_pointer potentially aliases all classes which don't have a
58  * NOTTAKEN modifier.
59  */
60 typedef enum {
61         ir_sc_pointer           = 0x0,  /**< generic pointer, may be anything */
62         ir_sc_globalvar         = 0x1,  /**< an address of a global variable */
63         ir_sc_localvar          = 0x2,  /**< an address of a local variable */
64         ir_sc_argument          = 0x3,  /**< an method argument */
65         ir_sc_tls               = 0x4,  /**< an address of a thread local storage variable */
66         ir_sc_malloced          = 0x5,  /**< an allocated heap address */
67
68         ir_sc_modifier_nottaken = 0x80, /**< if set, the address of the variable was not taken */
69 } ir_storage_class_class_t;
70
71 /**
72  * A source language specific memory disambiguator function.
73  * Called by get_alias_relation().
74  */
75 typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
76         ir_graph *irg,
77         ir_node *adr1, ir_mode *mode1,
78         ir_node *adr2, ir_mode *mode2);
79
80 /**
81  * Classify a base pointer.
82  *
83  * @param irg  the graph of the pointer
84  * @param irn  the node representing the base address
85  * @param ent  the base entity of the base address iff any
86  */
87 ir_storage_class_class_t classify_pointer(ir_graph *irg, ir_node *irn, ir_entity *ent);
88
89 /**
90  * Returns a human readable name for an alias relation.
91  */
92 const char *get_ir_alias_relation_name(ir_alias_relation rel);
93
94 /**
95  * Determine the alias relation between two addresses.
96  *
97  * @param irg     The current graph.
98  * @param adr1    The first address.
99  * @param mode1   The mode of the first memory access.
100  * @param adr2    The second address.
101  * @param mode2   The mode of the second memory access.
102  *
103  * The memory disambiguator tries to determine the alias state between
104  * two memory addresses. The following rules are used:
105  *
106  * - different variable from the same segment never alias (R1 a)
107  * - variables from different segments never alias when:
108  *   - a global variable and a local one never alias (R1 b)
109  *   - a global variable and a TLS one never alias (R1 c)
110  *   - a local variable and a TLS one never alias (R1 d)
111  *   - a local variable and a parameter never alias (R1 e)
112  *   - a global variable and the result of a malloc routine never alias (R1 f)
113  *   - a local variable and the result of a malloc routine never alias (R1 g)
114  *   - a TLS variable and the result of a malloc routine never alias (R1 h)
115  *   - a parameter and the result of a malloc routine (obtained in the
116  *     same routine as the parameter) never alias (R1 i)
117  * - two different variables never alias (R2)
118  * - if one is a variable whose address has never been taken
119  *   there is no alias (R3)
120  * - if two memory addresses have the same base and their offsets
121  *   do not describe overlapping regions there is no alias (R4)
122  * - if opt_strong_typed is set and both addresses describe entities,
123  *   different types never alias (R5)
124  *
125  * If none of these rules apply, the points-to framework must be
126  * interrogated to detect the alias relation.
127  */
128 ir_alias_relation get_alias_relation(
129         ir_graph *irg,
130         ir_node *adr1, ir_mode *mode1,
131         ir_node *adr2, ir_mode *mode2);
132
133 /**
134  * Set a source language specific memory disambiguator function.
135  *
136  * @param func  The callback.
137  */
138 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
139
140 /**
141  * Initialize the relation cache.
142  */
143 void mem_disambig_init(void);
144
145 /*
146  * Determine the alias relation between two addresses and
147  * cache the result.
148  *
149  * @param irg     The current graph.
150  * @param adr1    The first address.
151  * @param mode1   The mode of the first memory access.
152  * @param adr2    The second address.
153  * @param mode2   The mode of the second memory access.
154  *
155  * @see get_alias_relation()
156  */
157 ir_alias_relation get_alias_relation_ex(
158         ir_graph *irg,
159         ir_node *adr1, ir_mode *mode1,
160         ir_node *adr2, ir_mode *mode2);
161
162 /**
163  * Free the relation cache.
164  */
165 void mem_disambig_term(void);
166
167 /**
168  * Returns the current address taken state of the graph.
169  */
170 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
171
172 /**
173  * Sets the current address taken state of the graph.
174  *
175  * @param irg    the graph
176  * @param state  the new state
177  */
178 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
179
180 /**
181  * Assure that the address taken flag is computed for the given graph.
182  *
183  * This is an intraprocedural analysis that computes the address_taken state
184  * for all local variables.
185  *
186  * Note that this is a conservative estimation that by no Firm transformation
187  * can be invalidated, so it's only recomputed if manually triggered by calling
188  * set_irg_address_taken_state(irg, ir_address_taken_not_computed).
189  * Even then the information is not cleaned from the variables, call
190  * assure_irg_address_taken_computed() again for recomputation.
191  */
192 void assure_irg_address_taken_computed(ir_graph *irg);
193
194 /**
195  * Returns the current address taken state of the globals.
196  */
197 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
198
199 /**
200  * Sets the current address taken state of the globals.
201  *
202  * @param state  the new state
203  */
204 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
205
206 /**
207  * Assure that the address taken flag is computed for the global and TLS entities (variables).
208  *
209  * This is an interprocedural analysis that computes the address_taken state
210  * for all global and TLS variables.
211  *
212  * Note that this is a conservative estimation that by no Firm transformation
213  * can be invalidated, so it's only recomputed if manually triggered by calling
214  * set_irp_globals_address_taken_state(ir_address_taken_not_computed).
215  * Even then the information is not cleaned from the variables, call
216  * assure_irp_globals_address_taken_computed() again for recomputation.
217  */
218 void assure_irp_globals_address_taken_computed(void);
219
220 /**
221  * Get the memory disambiguator options for a graph.
222  *
223  * @param irg  the graph
224  */
225 unsigned get_irg_memory_disambiguator_options(ir_graph *irg);
226
227 /**
228  * Set the memory disambiguator options for a graph.
229  *
230  * @param irg      the graph
231  * @param option   a set of options
232  */
233 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options);
234
235 /**
236  * Set the global disambiguator options for all graphs not having local options.
237  *
238  * @param option   a set of options
239  */
240 void set_irp_memory_disambiguator_options(unsigned options);
241
242 /**
243  * Mark all private methods, i.e. those of which all call sites are known.
244  * We use a very convervative estimation yet: If the address of a method is
245  * never taken AND its visibility is visibility_local, then it's private.
246  */
247 void mark_private_methods(void);
248
249 #endif /* FIRM_ANA_IRMEMORY_H */