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