Changed the implementation of nlz in bitfiddle.
[libfirm] / include / libfirm / irmemory.h
1 /*
2  * Copyright (C) 1995-2007 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  * @version  $Id$
26  */
27 #ifndef FIRM_ANA_IRMEMORY_H
28 #define FIRM_ANA_IRMEMORY_H
29
30 #include "firm_types.h"
31
32 /** The alias relation of two memory addresses. */
33 typedef enum {
34         no_alias,       /**< No alias. */
35         may_alias,      /**< Unknown state, may alias. */
36         sure_alias      /**< Sure alias. */
37 } ir_alias_relation;
38
39 /** The state of the address taken flags. */
40 typedef enum {
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;
44
45 /** Possible options for the memory disambiguator. */
46 typedef enum {
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;
53
54 /**
55  * A source language specific memory disambiguator function.
56  * Called by get_alias_relation().
57  */
58 typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
59         ir_graph *irg,
60         ir_node *adr1, ir_mode *mode1,
61         ir_node *adr2, ir_mode *mode2);
62
63 /**
64  * Determine the alias relation between two addresses.
65  *
66  * @param irg     The current graph.
67  * @param adr1    The first address.
68  * @param mode1   The mode of the first memory access.
69  * @param adr2    The second address.
70  * @param mode2   The mode of the second memory access.
71  *
72  * The memory disambiguator tries to determine the alias state between
73  * two memory addresses. The following rules are used:
74  *
75  * - variables from different segments never alias (R1)
76  *   - a global variable and a local one never alias (R1 b)
77  *   - a global variable and a TLS one never alias (R1 c)
78  *   - a local variable and a TLS one never alias (R1 d)
79  *   - a local variable and a parameter never alias (R1 e)
80  * - two different variables never alias (R2)
81  * - if one is a variable whose address has never been taken
82  *   there is no alias (R3)
83  * - if two memory addresses have the same base and their offsets
84  *   do not describe overlapping regions there is no alias (R4)
85  * - if opt_strong_typed is set and both addresses describe entities,
86  *   different types never alias (R5)
87  *
88  * If none of these rules apply, the points-to framework must be
89  * interrogated to detect the alias relation.
90  */
91 ir_alias_relation get_alias_relation(
92         ir_graph *irg,
93         ir_node *adr1, ir_mode *mode1,
94         ir_node *adr2, ir_mode *mode2);
95
96 /**
97  * Set a source language specific memory disambiguator function.
98  *
99  * @param func  The callback.
100  */
101 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
102
103 /**
104  * Initialize the relation cache.
105  */
106 void mem_disambig_init(void);
107
108 /*
109  * Determine the alias relation between two addresses and
110  * cache the result.
111  *
112  * @param irg     The current graph.
113  * @param adr1    The first address.
114  * @param mode1   The mode of the first memory access.
115  * @param adr2    The second address.
116  * @param mode2   The mode of the second memory access.
117  *
118  * @see get_alias_relation()
119  */
120 ir_alias_relation get_alias_relation_ex(
121         ir_graph *irg,
122         ir_node *adr1, ir_mode *mode1,
123         ir_node *adr2, ir_mode *mode2);
124
125 /**
126  * Free the relation cache.
127  */
128 void mem_disambig_term(void);
129
130 /**
131  * Returns the current address taken state of the graph.
132  */
133 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
134
135 /**
136  * Sets the current address taken state of the graph.
137  *
138  * @param irg    the graph
139  * @param state  the new state
140  */
141 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
142
143 /**
144  * Assure that the address taken flag is computed for the given graph.
145  *
146  * This is an intraprocedural analysis that computes the address_taken state
147  * for all local variables.
148  *
149  * Note that this is a conservative estimation that by no Firm transformation
150  * can be invalidated, so it's only recomputed if manually triggered by calling
151  * set_irg_address_taken_state(irg, ir_address_taken_not_computed).
152  * Even then the information is not cleaned from the variables, call
153  * assure_irg_address_taken_computed() again for recomputation.
154  */
155 void assure_irg_address_taken_computed(ir_graph *irg);
156
157 /**
158  * Returns the current address taken state of the globals.
159  */
160 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
161
162 /**
163  * Sets the current address taken state of the globals.
164  *
165  * @param state  the new state
166  */
167 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
168
169 /**
170  * Assure that the address taken flag is computed for the global and TLS entities (variables).
171  *
172  * This is an interprocedural analysis that computes the address_taken state
173  * for all global and TLS variables.
174  *
175  * Note that this is a conservative estimation that by no Firm transformation
176  * can be invalidated, so it's only recomputed if manually triggered by calling
177  * set_irp_globals_address_taken_state(ir_address_taken_not_computed).
178  * Even then the information is not cleaned from the variables, call
179  * assure_irp_globals_address_taken_computed() again for recomputation.
180  */
181 void assure_irp_globals_address_taken_computed(void);
182
183 /**
184  * Get the memory disambiguator options for a graph.
185  *
186  * @param irg  the graph
187  */
188 unsigned get_irg_memory_disambiguator_options(ir_graph *irg);
189
190 /**
191  * Set the memory disambiguator options for a graph.
192  *
193  * @param irg      the graph
194  * @param option   a set of options
195  */
196 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options);
197
198 /**
199  * Set the global disambiguator options for all graphs not having local options.
200  *
201  * @param option   a set of options
202  */
203 void set_irp_memory_disambiguator_options(unsigned options);
204
205 #endif /* FIRM_ANA_IRMEMORY_H */