2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Memory disambiguator
23 * @author Michael Beck
27 #ifndef FIRM_ANA_IRMEMORY_H
28 #define FIRM_ANA_IRMEMORY_H
30 #include "firm_types.h"
32 /** The alias relation of two memory addresses. */
34 no_alias, /**< No alias. */
35 may_alias, /**< Unknown state, may alias. */
36 sure_alias /**< Sure alias. */
39 /** The state of the address taken flags. */
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;
45 /** Possible options for the memory disambiguator. */
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 } disambuigator_options;
55 * A source language specific memory disambiguator function.
56 * Called by get_alias_relation().
58 typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
60 ir_node *adr1, ir_mode *mode1,
61 ir_node *adr2, ir_mode *mode2);
64 * Returns a human readable name for an alias relation.
66 const char *get_ir_alias_relation_name(ir_alias_relation rel);
69 * Determine the alias relation between two addresses.
71 * @param irg The current graph.
72 * @param adr1 The first address.
73 * @param mode1 The mode of the first memory access.
74 * @param adr2 The second address.
75 * @param mode2 The mode of the second memory access.
77 * The memory disambiguator tries to determine the alias state between
78 * two memory addresses. The following rules are used:
80 * - different variable from the same segment never alias (R1 a)
81 * - variables from different segments never alias when:
82 * - a global variable and a local one never alias (R1 b)
83 * - a global variable and a TLS one never alias (R1 c)
84 * - a local variable and a TLS one never alias (R1 d)
85 * - a local variable and a parameter never alias (R1 e)
86 * - a global variable and the result of a malloc routine never alias (R1 f)
87 * - a local variable and the result of a malloc routine never alias (R1 g)
88 * - a TLS variable and the result of a malloc routine never alias (R1 h)
89 * - a parameter and the result of a malloc routine (obtained in the
90 * same routine as the parameter) never alias (R1 i)
91 * - two different variables never alias (R2)
92 * - if one is a variable whose address has never been taken
93 * there is no alias (R3)
94 * - if two memory addresses have the same base and their offsets
95 * do not describe overlapping regions there is no alias (R4)
96 * - if opt_strong_typed is set and both addresses describe entities,
97 * different types never alias (R5)
99 * If none of these rules apply, the points-to framework must be
100 * interrogated to detect the alias relation.
102 ir_alias_relation get_alias_relation(
104 ir_node *adr1, ir_mode *mode1,
105 ir_node *adr2, ir_mode *mode2);
108 * Set a source language specific memory disambiguator function.
110 * @param func The callback.
112 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
115 * Initialize the relation cache.
117 void mem_disambig_init(void);
120 * Determine the alias relation between two addresses and
123 * @param irg The current graph.
124 * @param adr1 The first address.
125 * @param mode1 The mode of the first memory access.
126 * @param adr2 The second address.
127 * @param mode2 The mode of the second memory access.
129 * @see get_alias_relation()
131 ir_alias_relation get_alias_relation_ex(
133 ir_node *adr1, ir_mode *mode1,
134 ir_node *adr2, ir_mode *mode2);
137 * Free the relation cache.
139 void mem_disambig_term(void);
142 * Returns the current address taken state of the graph.
144 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
147 * Sets the current address taken state of the graph.
149 * @param irg the graph
150 * @param state the new state
152 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
155 * Assure that the address taken flag is computed for the given graph.
157 * This is an intraprocedural analysis that computes the address_taken state
158 * for all local variables.
160 * Note that this is a conservative estimation that by no Firm transformation
161 * can be invalidated, so it's only recomputed if manually triggered by calling
162 * set_irg_address_taken_state(irg, ir_address_taken_not_computed).
163 * Even then the information is not cleaned from the variables, call
164 * assure_irg_address_taken_computed() again for recomputation.
166 void assure_irg_address_taken_computed(ir_graph *irg);
169 * Returns the current address taken state of the globals.
171 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
174 * Sets the current address taken state of the globals.
176 * @param state the new state
178 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
181 * Assure that the address taken flag is computed for the global and TLS entities (variables).
183 * This is an interprocedural analysis that computes the address_taken state
184 * for all global and TLS variables.
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_irp_globals_address_taken_state(ir_address_taken_not_computed).
189 * Even then the information is not cleaned from the variables, call
190 * assure_irp_globals_address_taken_computed() again for recomputation.
192 void assure_irp_globals_address_taken_computed(void);
195 * Get the memory disambiguator options for a graph.
197 * @param irg the graph
199 unsigned get_irg_memory_disambiguator_options(ir_graph *irg);
202 * Set the memory disambiguator options for a graph.
204 * @param irg the graph
205 * @param option a set of options
207 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options);
210 * Set the global disambiguator options for all graphs not having local options.
212 * @param option a set of options
214 void set_irp_memory_disambiguator_options(unsigned options);
217 * Mark all private methods, i.e. those of which all call sites are known.
218 * We use a very convervative estimation yet: If the address of a method is
219 * never taken AND its visibility is visibility_local, then it's private.
221 void mark_private_methods(void);
223 #endif /* FIRM_ANA_IRMEMORY_H */