3 * File name: ir/ana/irmemory.h
4 * Purpose: Memory disambiguator
9 * Copyright: (c) 2006-2007 Universität Karlsruhe
10 * License: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
12 #ifndef _FIRM_MEMORY_H
13 #define _FIRM_MEMORY_H
15 #include "firm_types.h"
17 /** The alias relation of two memory addresses. */
19 no_alias, /**< No alias. */
20 may_alias, /**< Unknown state, may alias. */
21 sure_alias /**< Sure alias. */
24 /** The state of the address taken flags. */
26 ir_address_taken_not_computed, /**< Address taken flag is not computed. */
27 ir_address_taken_computed /**< Address taken flag is computed. */
28 } ir_address_taken_computed_state;
30 /** Possible options for the memory disambiguator. */
32 aa_opt_no_opt = 0, /**< no options: most conservative */
33 aa_opt_type_based = 1, /**< use type based alias analysis: strict typed source language */
34 aa_opt_byte_type_may_alias = 2, /**< if type based analysis is enabled: bytes types may alias other types */
35 aa_opt_no_alias = 4, /**< two addresses NEVER alias, use with CAUTION (gcc -fno-alias) */
36 aa_opt_inherited = 128 /**< only for implementation: options from a graph are inherited from global */
37 } disambuigator_options;
40 * A source language specific memory disambiguator function.
41 * Called by get_alias_relation().
43 typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
45 ir_node *adr1, ir_mode *mode1,
46 ir_node *adr2, ir_mode *mode2);
49 * Determine the alias relation between two addresses.
51 * @param irg The current graph.
52 * @param adr1 The first address.
53 * @param mode1 The mode of the first memory access.
54 * @param adr2 The second address.
55 * @param mode2 The mode of the second memory access.
57 * The memory disambiguator tries to determine the alias state between
58 * two memory addresses. The following rules are used:
60 * - variables from different segments never alias (R1)
61 * - a global variable and a local one never alias (R1 b)
62 * - a global variable and a TLS one never alias (R1 c)
63 * - a local variable and a TLS one never alias (R1 d)
64 * - two different variables never alias (R2)
65 * - if one is a variable which address has never taken
66 * there is no alias (R3)
67 * - if two memory addresses have the same base and there offsets
68 * do not describe overlapping regions there is no alias (R4)
69 * - if opt_strong_typed is set and both addresses describe entities,
70 * different types never alias (R5)
72 * If none of these rules apply, the points-to framework must be
73 * interrogated to detect the alias relation.
75 ir_alias_relation get_alias_relation(
77 ir_node *adr1, ir_mode *mode1,
78 ir_node *adr2, ir_mode *mode2);
81 * Set a source language specific memory disambiguator function.
83 * @param func The callback.
85 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
88 * Initialize the relation cache.
90 void mem_disambig_init(void);
93 * Determine the alias relation between two addresses and
96 * @param irg The current graph.
97 * @param adr1 The first address.
98 * @param mode1 The mode of the first memory access.
99 * @param adr2 The second address.
100 * @param mode2 The mode of the second memory access.
101 * @param options Additional options.
103 * @see get_alias_relation()
105 ir_alias_relation get_alias_relation_ex(
107 ir_node *adr1, ir_mode *mode1,
108 ir_node *adr2, ir_mode *mode2);
111 * Free the relation cache.
113 void mem_disambig_term(void);
116 * Returns the current address taken state of the graph.
118 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
121 * Sets the current address taken state of the graph.
123 * @param irg the graph
124 * @param state the new state
126 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
129 * Assure that the address taken flag is computed for the given graph.
131 * This is an intraprocedural analysis that computes the address_taken state
132 * for all local variables.
134 * Note that this is a conservative estimation that by no Firm transformation
135 * can be invalidated, so it's only recomputed if manually triggered by calling
136 * set_irg_address_taken_state(irg, ir_address_taken_not_computed).
137 * Even then the information is not cleaned from the variables, call
138 * assure_irg_address_taken_computed() again for recomputation.
140 void assure_irg_address_taken_computed(ir_graph *irg);
143 * Returns the current address taken state of the globals.
145 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
148 * Sets the current address taken state of the globals.
150 * @param state the new state
152 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
155 * Assure that the address taken flag is computed for the global and TLS entities (variables).
157 * This is an interprocedural analysis that computes the address_taken state
158 * for all global and TLS 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_irp_globals_address_taken_state(ir_address_taken_not_computed).
163 * Even then the information is not cleaned from the variables, call
164 * assure_irp_globals_address_taken_computed() again for recomputation.
166 void assure_irp_globals_address_taken_computed(void);
169 * Get the memory disambiguator options for a graph.
171 * @param irg the graph
173 unsigned get_irg_memory_disambiguator_options(ir_graph *irg);
176 * Set the memory disambiguator options for a graph.
178 * @param irg the graph
179 * @param option a set of options
181 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options);
184 * Set the global disambiguator options for all graphs not having local options.
186 * @param option a set of options
188 void set_irp_memory_disambiguator_options(unsigned options);
190 #endif /* _FIRM_MEMORY_H */