Initial version of the memory disambiguator added
[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  * Licence:     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         opt_non_opt      = 0,   /**< no options */
33         opt_strong_typed = 1,   /**< strong typed source language */
34 } disambuigator_options;
35
36 /**
37  * A source language specific memory disambiguator function.
38  * Called by get_alias_relation().
39  */
40 typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
41         ir_graph *irg,
42         ir_node *adr1, ir_mode *mode1,
43         ir_node *adr2, ir_mode *mode2);
44
45 /**
46  * Determine the alias relation between two addresses.
47  *
48  * @param irg     The current graph.
49  * @param adr1    The first address.
50  * @param mode1   The mode of the first memory access.
51  * @param adr2    The second address.
52  * @param mode2   The mode of the second memory access.
53  * @param options Additional options.
54  *
55  * The memory disambiguator tries to determine the alias state between
56  * two memory addresses. The following rules are used:
57  *
58  * - variables from different segments never alias (R1)
59  *   - a global variable and a local one never alias (R1 b)
60  *   - a global variable and a TLS one never alias (R1 c)
61  *   - a local variable and a TLS one never alias (R1 d)
62  * - two different variables never alias (R2)
63  * - if one is a variable which address has never taken
64  *   there is no alias (R3)
65  * - if two memory addresses have the same base and there offsets
66  *   do not describe overlapping regions there is no alias (R4)
67  * - if opt_strong_typed is set and both addresses describe entities,
68  *   different types never alias (R5)
69  *
70  * If none of these rules apply, the points-to framework must be
71  * interrogated to detect the alias relation.
72  */
73 ir_alias_relation get_alias_relation(
74         ir_graph *irg,
75         ir_node *adr1, ir_mode *mode1,
76         ir_node *adr2, ir_mode *mode2,
77         unsigned options);
78
79 /**
80  * Set a source language specific memory disambiguator function.
81  *
82  * @param func  The callback.
83  */
84 void set_language_memory_disambiguator(DISAMBIGUATOR_FUNC func);
85
86 /**
87  * Initialize the relation cache.
88  */
89 void mem_disambig_init(void);
90
91 /*
92  * Determine the alias relation between two addresses and
93  * cache the result.
94  *
95  * @param irg     The current graph.
96  * @param adr1    The first address.
97  * @param mode1   The mode of the first memory access.
98  * @param adr2    The second address.
99  * @param mode2   The mode of the second memory access.
100  * @param options Additional options.
101  *
102  * @see get_alias_relation()
103  */
104 ir_alias_relation get_alias_relation_ex(
105         ir_graph *irg,
106         ir_node *adr1, ir_mode *mode1,
107         ir_node *adr2, ir_mode *mode2,
108         unsigned options);
109
110 /**
111  * Free the relation cache.
112  */
113 void mem_disambig_term(void);
114
115 /**
116  * Returns the current address taken state of the graph.
117  */
118 ir_address_taken_computed_state get_irg_address_taken_state(const ir_graph *irg);
119
120 /**
121  * Sets the current address taken state of the graph.
122  */
123 void set_irg_address_taken_state(ir_graph *irg, ir_address_taken_computed_state state);
124
125 /**
126  * Assure that the address taken flag is computed for the given graph.
127  */
128 void assure_irg_address_taken_computed(ir_graph *irg);
129
130 /**
131  * Returns the current address taken state of the globals.
132  */
133 ir_address_taken_computed_state get_irp_globals_address_taken_state(void);
134
135 /**
136  * Sets the current address taken state of the globals.
137  */
138 void set_irp_globals_address_taken_state(ir_address_taken_computed_state state);
139
140 /**
141  * Assure that the address taken flag is computed for the globals.
142  */
143 void assure_irp_globals_address_taken_computed(void);
144
145 #endif /* _FIRM_MEMORY_H */