2009-01-07 Zoltan Varga <vargaz@gmail.com>
[mono-project.git] / mono / mini / aliasing.h
blob58db763c72a653a676bc878fc9b964a5f65d3e17
1 /*
2 * aliasing.h: Alias Analysis
4 * Author:
5 * Massimiliano Mantione (massi@ximian.com)
7 * (C) 2005 Novell, Inc. http://www.novell.com
8 */
10 #ifndef __MONO_ALIASING_H__
11 #define __MONO_ALIASING_H__
13 #include "mini.h"
15 #define MONO_ALIASING_INVALID_VARIABLE_INDEX (-1)
18 * A struct representing the element of a list of local variables.
20 typedef struct MonoLocalVariableList {
21 /* The index of the local variable */
22 int variable_index;
24 /* Next in the list */
25 struct MonoLocalVariableList *next;
26 } MonoLocalVariableList;
29 * A struct representing the information about the fact that an address
30 * that could be an alias is used.
32 typedef struct MonoAliasUsageInformation {
33 /* The inst where the address is used */
34 MonoInst *inst;
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;
40 /* Next in the list */
41 struct MonoAliasUsageInformation *next;
42 } MonoAliasUsageInformation;
46 * All the different kinds of locations for a variable's address.
47 * "ANY" means the location is unknown or cannot be handled.
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;
56 typedef struct MonoAliasValue {
57 MonoAliasType type;
58 int variable_index;
59 } MonoAliasValue;
62 * A struct representing the aliasing information in a BB.
64 typedef struct MonoAliasingInformationInBB {
65 /* The BB to which these info are relaed. */
66 MonoBasicBlock *bb;
68 /* Info on alias usage. */
69 MonoAliasUsageInformation *potential_alias_uses;
70 } MonoAliasingInformationInBB;
73 * A struct representing the aliasing information in a MonoCompile.
75 typedef struct MonoAliasingInformation {
76 /* The MonoCompile to which these info are relaed. */
77 MonoCompile *cfg;
79 /* The pool from where everything is allocated (including this struct). */
80 MonoMemPool *mempool;
82 /* Aliasing info for each BB */
83 MonoAliasingInformationInBB *bb;
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;
89 /* Used to track the current inst when traversing inst trees in a BB. */
90 MonoAliasUsageInformation *next_interesting_inst;
92 /* Array containing one MonoLocalVariableList for each local variable. */
93 MonoLocalVariableList *variables;
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;
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;
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;
113 extern MonoAliasingInformation*
114 mono_build_aliasing_information (MonoCompile *cfg) MONO_INTERNAL;
115 extern void
116 mono_destroy_aliasing_information (MonoAliasingInformation *info) MONO_INTERNAL;
117 extern void
118 mono_aliasing_initialize_code_traversal (MonoAliasingInformation *info, MonoBasicBlock *bb) MONO_INTERNAL;
119 extern MonoLocalVariableList*
120 mono_aliasing_get_affected_variables_for_inst_traversing_code (MonoAliasingInformation *info, MonoInst *inst) MONO_INTERNAL;
121 extern MonoLocalVariableList*
122 mono_aliasing_get_affected_variables_for_inst (MonoAliasingInformation *info, MonoInst *inst) MONO_INTERNAL;
124 extern void
125 mono_aliasing_deadce (MonoAliasingInformation *info) MONO_INTERNAL;
127 #endif /* __MONO_ALIASING_H__ */