New test.
[mono.git] / mono / mini / aliasing.h
1 /*
2  * aliasing.h: Alias Analysis
3  *
4  * Author:
5  *   Massimiliano Mantione (massi@ximian.com)
6  *
7  * (C) 2005 Novell, Inc.  http://www.novell.com
8  */
9
10 #ifndef __MONO_ALIASING_H__
11 #define __MONO_ALIASING_H__
12
13 #include "mini.h"
14
15 #define MONO_ALIASING_INVALID_VARIABLE_INDEX (-1)
16
17 /*
18  * A struct representing the element of a list of local variables.
19  */
20 typedef struct MonoLocalVariableList {
21         /* The index of the local variable */
22         int variable_index;
23         
24         /* Next in the list */
25         struct MonoLocalVariableList *next;
26 } MonoLocalVariableList;
27
28 /*
29  * A struct representing the information about the fact that an address
30  * that could be an alias is used.
31  */
32 typedef struct MonoAliasUsageInformation {
33         /* The inst where the address is used */
34         MonoInst *inst;
35         
36         /* The possibly aliased variables. Note that if this field is null */
37         /* it means that any "problematic" variable could be aliased! */
38         MonoLocalVariableList *affected_variables;
39         
40         /* Next in the list */
41         struct MonoAliasUsageInformation *next;
42 } MonoAliasUsageInformation;
43
44
45 /*
46  * All the different kinds of locations for a variable's address.
47  * "ANY" means the location is unknown or cannot be handled.
48  */
49 typedef enum {
50         MONO_ALIASING_TYPE_ANY,
51         MONO_ALIASING_TYPE_NO_ALIAS,
52         MONO_ALIASING_TYPE_LOCAL,
53         MONO_ALIASING_TYPE_LOCAL_FIELD
54 } MonoAliasType;
55
56 typedef struct MonoAliasValue {
57         MonoAliasType type;
58         int variable_index;
59 } MonoAliasValue;
60
61 /*
62  * A struct representing the aliasing information in a BB.
63  */
64 typedef struct MonoAliasingInformationInBB {
65         /* The BB to which these info are relaed. */
66         MonoBasicBlock *bb;
67         
68         /* Info on alias usage. */
69         MonoAliasUsageInformation *potential_alias_uses;
70 } MonoAliasingInformationInBB;
71
72 /*
73  * A struct representing the aliasing information in a MonoCompile.
74  */
75 typedef struct MonoAliasingInformation {
76         /* The MonoCompile to which these info are relaed. */
77         MonoCompile *cfg;
78         
79         /* The pool from where everything is allocated (including this struct). */
80         MonoMemPool *mempool;
81         
82         /* Aliasing info for each BB */
83         MonoAliasingInformationInBB *bb;
84         
85         /* The variables whose address has been taken and "lost": any pointer */
86         /* with an unknown value potentially aliases these variables. */
87         MonoLocalVariableList *uncontrollably_aliased_variables;
88         
89         /* Used to track the current inst when traversing inst trees in a BB. */
90         MonoAliasUsageInformation *next_interesting_inst;
91         
92         /* Array containing one MonoLocalVariableList for each local variable. */
93         MonoLocalVariableList *variables;
94         
95         /* Array containing one flag for each local variable stating if it is */
96         /* already in the uncontrollably_aliased_variables list. */
97         gboolean *variable_is_uncontrollably_aliased;
98         
99         /* This MonoLocalVariableList is a placeholder for uncontrollably_aliased_variables */
100         /* while the aliasing info are still being collected. */
101         MonoLocalVariableList *temporary_uncontrollably_aliased_variables;
102         
103         /* An array of MonoInst* containing all the arguments to the next call. */
104         MonoInst **arguments;
105         /* An array of MonoAliasValue containing all the aliases passed to the arguments of the next call. */
106         MonoAliasValue *arguments_aliases;
107         /* The total capacity of the "arguments" and "arguments_aliases" arrays. */
108         int arguments_capacity;
109         /* The number of used elements in the "arguments" and "arguments_aliases" arrays. */
110         int number_of_arguments;
111 } MonoAliasingInformation;
112
113 extern MonoAliasingInformation*
114 mono_build_aliasing_information (MonoCompile *cfg);
115 extern void
116 mono_destroy_aliasing_information (MonoAliasingInformation *info);
117 extern void
118 mono_aliasing_initialize_code_traversal (MonoAliasingInformation *info, MonoBasicBlock *bb);
119 extern MonoLocalVariableList*
120 mono_aliasing_get_affected_variables_for_inst_traversing_code (MonoAliasingInformation *info, MonoInst *inst);
121 extern MonoLocalVariableList*
122 mono_aliasing_get_affected_variables_for_inst (MonoAliasingInformation *info, MonoInst *inst);
123
124 extern void
125 mono_aliasing_deadce (MonoAliasingInformation *info);
126
127 #endif /* __MONO_ALIASING_H__ */