Commit e11232be authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

bugfix

[r5339]
parent ed5876ae
This diff is collapsed.
...@@ -34,20 +34,22 @@ ...@@ -34,20 +34,22 @@
* *
* Die main-Methode ist immer in der Menge enthalten. * Die main-Methode ist immer in der Menge enthalten.
* *
* Die Links an den "ir_node"s werden geloescht. */ * Die Links an den "ir_node"s werden geloescht.
*/
/** Analyses a rough estimation of the possible call graph. /** Analyses a rough estimation of the possible call graph.
* *
* Determines for each Call node the set of possibly called methods. * Determines for each Call node the set of possibly called methods.
* Stores the result in the field 'callees' of the Call node. If the * Stores the result in the field 'callees' of the Call node. If the
* address can not be analysed, e.g. because it is loaded from a * address can not be analysed, e.g. because it is loaded from a
* variable, the array contains NULL. @@@ the array should contain a * variable, the array contains the unknown_entity. (See
* special entity 'unknown'. (See "set_Call_callee"). cgana returns * "set_Call_callee"). cgana returns the set of 'free' methods, i.e.,
* the set of 'free' methods, i.e., the methods that can be called * the methods that can be called from external or via function
* from external or via function pointers. This datastructure must * pointers. This datastructure must be freed with 'free()' by the
* be freed with 'free()' by the caller of cgana. * caller of cgana.
* *
* cgana sets the callee_info_state of each graph to consistent. * cgana sets the callee_info_state of each graph and the program to
* consistent.
* *
* The algorithm implements roughly Static Class Hierarchy Analysis * The algorithm implements roughly Static Class Hierarchy Analysis
* as described in "Optimization of Object-Oriented Programs Using * as described in "Optimization of Object-Oriented Programs Using
...@@ -58,7 +60,7 @@ ...@@ -58,7 +60,7 @@
* - Replace SymConst-name nodes by SymConst-entity nodes if possible. * - Replace SymConst-name nodes by SymConst-entity nodes if possible.
* - Replace (Sel-method(Alloc)) by SymConst-entity. * - Replace (Sel-method(Alloc)) by SymConst-entity.
* - Replaces Sel nodes by Bad if there is no implementation for the * - Replaces Sel nodes by Bad if there is no implementation for the
* selected entity. (@@@ was genau meint unreachable?) * selected entity.
* - Replaces Sel-method by SymConst-entity if the method is never overwritten. * - Replaces Sel-method by SymConst-entity if the method is never overwritten.
* - Replaces Calls by Tuple containing Bads if callee array is empty * - Replaces Calls by Tuple containing Bads if callee array is empty
* (there is no implementation to call) * (there is no implementation to call)
......
...@@ -307,12 +307,15 @@ static long get_Sel_array_index_long(ir_node *n, int dim) { ...@@ -307,12 +307,15 @@ static long get_Sel_array_index_long(ir_node *n, int dim) {
return get_tarval_long(get_Const_tarval(index)); return get_tarval_long(get_Const_tarval(index));
} }
compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) { static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) {
compound_graph_path *res; compound_graph_path *res;
if (get_irn_op(ptr) == op_SymConst) { if (get_irn_op(ptr) == op_SymConst) {
assert(get_SymConst_kind(ptr) == symconst_addr_ent); assert(get_SymConst_kind(ptr) == symconst_addr_ent);
entity *root = get_SymConst_entity(ptr); entity *root = get_SymConst_entity(ptr);
res = new_compound_graph_path(get_entity_type(root), depth); if (depth == 0)
res = NULL;
else
res = new_compound_graph_path(get_entity_type(root), depth);
} else { } else {
assert(get_irn_op(ptr) == op_Sel); assert(get_irn_op(ptr) == op_Sel);
res = rec_get_accessed_path(get_Sel_ptr(ptr), depth+1); res = rec_get_accessed_path(get_Sel_ptr(ptr), depth+1);
...@@ -328,7 +331,10 @@ compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) { ...@@ -328,7 +331,10 @@ compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) {
return res; return res;
} }
compound_graph_path *get_accessed_path(ir_node *ptr) {
/** Returns an access path or NULL. The access path is only
* valid, if the graph is in phase_high and _no_ address computation is used. */
static compound_graph_path *get_accessed_path(ir_node *ptr) {
return rec_get_accessed_path(ptr, 0); return rec_get_accessed_path(ptr, 0);
} }
...@@ -463,27 +469,30 @@ static int optimize_load(ir_node *load) ...@@ -463,27 +469,30 @@ static int optimize_load(ir_node *load)
printf(" ptr: "); DDMN(ptr); printf(" ptr: "); DDMN(ptr);
compound_graph_path *path = get_accessed_path(ptr); compound_graph_path *path = get_accessed_path(ptr);
assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1)); if (path) {
ir_node *c = get_compound_ent_value_by_path(ent, path); assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1));
ir_node *c = get_compound_ent_value_by_path(ent, path);
printf(" cons: "); DDMN(c);
printf(" cons: "); DDMN(c);
if (info->projs[pn_Load_M])
exchange(info->projs[pn_Load_M], mem); if (info->projs[pn_Load_M])
if (info->projs[pn_Load_res]) exchange(info->projs[pn_Load_M], mem);
exchange(info->projs[pn_Load_res], copy_const_value(c)); if (info->projs[pn_Load_res])
exchange(info->projs[pn_Load_res], copy_const_value(c));
{
int j; {
for (j = 0; j < get_compound_graph_path_length(path); ++j) { int j;
entity *node = get_compound_graph_path_node(path, j); for (j = 0; j < get_compound_graph_path_length(path); ++j) {
fprintf(stdout, ".%s", get_entity_name(node)); entity *node = get_compound_graph_path_node(path, j);
if (is_Array_type(get_entity_owner(node))) fprintf(stdout, ".%s", get_entity_name(node));
fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j)); if (is_Array_type(get_entity_owner(node)))
} fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j));
printf("\n"); }
printf("\n");
}
} else {
printf("cannot optimize.\n");
} }
} }
/* we changed the irg, but try further */ /* we changed the irg, but try further */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment