add local and parameter rule
[libfirm] / ir / ana / irmemory.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ana/irmemory.h
4  * Purpose:     Memory disambiguator
5  * Author:      Michael Beck
6  * Modified by:
7  * Created:     27.12.2006
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2006-2007 Universität Karlsruhe
10  * License:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12 #ifndef _FIRM_MEMORY_H
13 #define _FIRM_MEMORY_H
14
15 #include "firm_types.h"
16
17 /** The alias relation of two memory addresses. */
18 typedef enum {
19         no_alias,       /**< No alias. */
20         may_alias,      /**< Unknown state, may alias. */
21         sure_alias      /**< Sure alias. */
22 } ir_alias_relation;
23
24 /** The state of the address taken flags. */
25 typedef enum {
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;
29
30 /** Possible options for the memory disambiguator. */
31 typedef enum {
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;
38
39 /**
40  * A source language specific memory disambiguator function.
41  * Called by get_alias_relation().
42  */
43 typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
44         ir_graph *irg,
45         ir_node *adr1, ir_mode *mode1,
46         ir_node *adr2, ir_mode *mode2);
47
48 /**
49  * Determine the alias relation between two addresses.
50  *
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.
56  *
57  * The memory disambiguator tries to determine the alias state between
58  * two memory addresses. The following rules are used:
59  *
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)
72  *
73  * If none of these rules apply, the points-to framework must be
74  * interrogated to detect the alias relation.
75  */
76 ir_alias_relation get_alias_relation(
77         ir_graph *irg,
78         ir_node *adr1, ir_mode *mode1,
79         ir_node *adr2, ir_mode *mode2);
80
81 /**
82  * Set a source language specific memory disambiguator function.
83  *
84  * @param func  The callback.
85  */
86 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
87
88 /**
89  * Initialize the relation cache.
90  */
91 void mem_disambig_init(void);
92
93 /*
94  * Determine the alias relation between two addresses and
95  * cache the result.
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  * @param options Additional options.
103  *
104  * @see get_alias_relation()
105  */
106 ir_alias_relation get_alias_relation_ex(
107         ir_graph *irg,
108         ir_node *adr1, ir_mode *mode1,
109         ir_node *adr2, ir_mode *mode2);
110
111 /**
112  * Free the relation cache.
113  */
114 void mem_disambig_term(void);
115
116 /**
117  * Returns the current address taken state of the graph.
118  */
119 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
120
121 /**
122  * Sets the current address taken state of the graph.
123  *
124  * @param irg    the graph
125  * @param state  the new state
126  */
127 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
128
129 /**
130  * Assure that the address taken flag is computed for the given graph.
131  *
132  * This is an intraprocedural analysis that computes the address_taken state
133  * for all local variables.
134  *
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.
140  */
141 void assure_irg_address_taken_computed(ir_graph *irg);
142
143 /**
144  * Returns the current address taken state of the globals.
145  */
146 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
147
148 /**
149  * Sets the current address taken state of the globals.
150  *
151  * @param state  the new state
152  */
153 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
154
155 /**
156  * Assure that the address taken flag is computed for the global and TLS entities (variables).
157  *
158  * This is an interprocedural analysis that computes the address_taken state
159  * for all global and TLS variables.
160  *
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.
166  */
167 void assure_irp_globals_address_taken_computed(void);
168
169 /**
170  * Get the memory disambiguator options for a graph.
171  *
172  * @param irg  the graph
173  */
174 unsigned get_irg_memory_disambiguator_options(ir_graph *irg);
175
176 /**
177  * Set the memory disambiguator options for a graph.
178  *
179  * @param irg      the graph
180  * @param option   a set of options
181  */
182 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options);
183
184 /**
185  * Set the global disambiguator options for all graphs not having local options.
186  *
187  * @param option   a set of options
188  */
189 void set_irp_memory_disambiguator_options(unsigned options);
190
191 #endif /* _FIRM_MEMORY_H */