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 * - a local variable and a parameter never alias (R1 e)
65 * - two different variables never alias (R2)
66 * - if one is a variable which address has never taken
67 * there is no alias (R3)
68 * - if two memory addresses have the same base and there offsets
69 * do not describe overlapping regions there is no alias (R4)
70 * - if opt_strong_typed is set and both addresses describe entities,
71 * different types never alias (R5)
73 * If none of these rules apply, the points-to framework must be
74 * interrogated to detect the alias relation.
76 ir_alias_relation get_alias_relation(
78 ir_node *adr1, ir_mode *mode1,
79 ir_node *adr2, ir_mode *mode2);
82 * Set a source language specific memory disambiguator function.
84 * @param func The callback.
86 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
89 * Initialize the relation cache.
91 void mem_disambig_init(void);
94 * Determine the alias relation between two addresses and
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 * @param options Additional options.
104 * @see get_alias_relation()
106 ir_alias_relation get_alias_relation_ex(
108 ir_node *adr1, ir_mode *mode1,
109 ir_node *adr2, ir_mode *mode2);
112 * Free the relation cache.
114 void mem_disambig_term(void);
117 * Returns the current address taken state of the graph.
119 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
122 * Sets the current address taken state of the graph.
124 * @param irg the graph
125 * @param state the new state
127 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
130 * Assure that the address taken flag is computed for the given graph.
132 * This is an intraprocedural analysis that computes the address_taken state
133 * for all local variables.
135 * Note that this is a conservative estimation that by no Firm transformation
136 * can be invalidated, so it's only recomputed if manually triggered by calling
137 * set_irg_address_taken_state(irg, ir_address_taken_not_computed).
138 * Even then the information is not cleaned from the variables, call
139 * assure_irg_address_taken_computed() again for recomputation.
141 void assure_irg_address_taken_computed(ir_graph *irg);
144 * Returns the current address taken state of the globals.
146 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
149 * Sets the current address taken state of the globals.
151 * @param state the new state
153 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
156 * Assure that the address taken flag is computed for the global and TLS entities (variables).
158 * This is an interprocedural analysis that computes the address_taken state
159 * for all global and TLS variables.
161 * Note that this is a conservative estimation that by no Firm transformation
162 * can be invalidated, so it's only recomputed if manually triggered by calling
163 * set_irp_globals_address_taken_state(ir_address_taken_not_computed).
164 * Even then the information is not cleaned from the variables, call
165 * assure_irp_globals_address_taken_computed() again for recomputation.
167 void assure_irp_globals_address_taken_computed(void);
170 * Get the memory disambiguator options for a graph.
172 * @param irg the graph
174 unsigned get_irg_memory_disambiguator_options(ir_graph *irg);
177 * Set the memory disambiguator options for a graph.
179 * @param irg the graph
180 * @param option a set of options
182 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options);
185 * Set the global disambiguator options for all graphs not having local options.
187 * @param option a set of options
189 void set_irp_memory_disambiguator_options(unsigned options);
191 #endif /* _FIRM_MEMORY_H */