From: Götz Lindenmaier Date: Wed, 9 Mar 2005 16:15:35 +0000 (+0000) Subject: more handling for compound graph path , X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=9f1d937fd2a1fd163618ee9c19eadc20dacabe98;p=libfirm more handling for compound graph path , more verification [r5323] --- diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 51fd0e63f..9a11278fb 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -696,6 +696,53 @@ get_compound_ent_value_path(entity *ent, int pos) { return ent->val_paths[pos]; } +static int equal_paths(compound_graph_path *path1, int *visited_indicees, compound_graph_path *path2) { + int i; + int len1 = get_compound_graph_path_length(path1); + int len2 = get_compound_graph_path_length(path2); + + if (len2 > len1) return false; + + for (i = 0; i < len1; i++) { + entity *node1 = get_compound_graph_path_node(path1, i); + entity *node2 = get_compound_graph_path_node(path2, i); + if (node1 != node2) return false; + type *tp = get_entity_owner(node1); + if (is_Array_type(tp)) { + /* Compute the index of this node. */ + assert(get_array_n_dimensions(tp) == 1 && "multidim not implemented"); + long low = get_array_lower_bound_int(tp, 0); + if (low+visited_indicees[i] < get_compound_graph_path_array_index(path2, i)) { + visited_indicees[i]++; + return false; + } else { + assert(low+visited_indicees[i] == get_compound_graph_path_array_index(path2, i)); + } + } + } + return true; +} + +/* Returns the position of a value with the given path. + * The path must contain array indicees for all array element entities. */ +int get_compound_ent_pos_by_path(entity *ent, compound_graph_path *path) { + int i, n_paths = get_compound_ent_n_values(ent); + int *visited_indicees = (int *)xcalloc(get_compound_graph_path_length(path), sizeof(int)); + for (i = 0; i < n_paths; i ++) { + if (equal_paths(get_compound_ent_value_path(ent, i), visited_indicees, path)) + return i; + } + assert(0 && "path not found"); + return -1; +} + +/* Returns a constant value given the access path. + * The path must contain array indicees for all array element entities. */ +ir_node *get_compound_ent_value_by_path(entity *ent, compound_graph_path *path) { + return get_compound_ent_value(ent, get_compound_ent_pos_by_path(ent, path)); +} + + void remove_compound_ent_value(entity *ent, entity *value_ent) { int i; @@ -889,7 +936,7 @@ static int get_next_index(entity *elem_ent) { * array bounds must be representable as ints. * * (If the bounds are not representable as ints we have to represent - * the indices as firm nodes. But the still we must be able to + * the indices as firm nodes. But still we must be able to * evaluate the index against the upper bound.) */ void compute_compound_ent_array_indicees(entity *ent) { @@ -947,7 +994,6 @@ void compute_compound_ent_array_indicees(entity *ent) { set_compound_graph_path_array_index (path, j, get_next_index(node)); } } - } /** resize: double the allocated buffer */ diff --git a/ir/tr/entity.h b/ir/tr/entity.h index e0786146c..89b549f78 100644 --- a/ir/tr/entity.h +++ b/ir/tr/entity.h @@ -376,7 +376,7 @@ void set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *n int get_compound_graph_path_array_index(compound_graph_path *gr, int pos); void set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index); -/** Checks wether the path up to pos is correct. If the path contains a NULL, +/** Checks whether the path up to pos is correct. If the path contains a NULL, * assumes the path is not complete and returns 'true'. */ int is_proper_compound_graph_path(compound_graph_path *gr, int pos); @@ -389,8 +389,16 @@ void set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph * Asserts if the entity has variability_uninitialized. * */ int get_compound_ent_n_values(entity *ent); +/** Returns a constant value given the position. */ ir_node *get_compound_ent_value(entity *ent, int pos); +/** Returns the access path for value at position pos. */ compound_graph_path *get_compound_ent_value_path(entity *ent, int pos); +/** Returns the position of a value with the given path. + * The path must contain array indicees for all array element entities. */ +int get_compound_ent_pos_by_path(entity *ent, compound_graph_path *path); +/** Returns a constant value given the access path. + * The path must contain array indicees for all array element entities. */ +ir_node *get_compound_ent_value_by_path(entity *ent, compound_graph_path *path); /** Removes all constant entries where the path ends at value_ent. Does not free the memory of the paths. (The same path might be used for several diff --git a/ir/tr/entity_t.h b/ir/tr/entity_t.h index 6f7a55267..8d37f80f3 100644 --- a/ir/tr/entity_t.h +++ b/ir/tr/entity_t.h @@ -39,6 +39,7 @@ # define _ENTITY_T_H_ #include "firm_common_t.h" +#include "firm_config.h" # include "entity.h" # include "typegmod.h" @@ -52,9 +53,9 @@ struct compound_graph_path { type *tp; /**< The type this path belongs to. */ int len; /**< length of the path */ int *arr_indicees; /**< List of array indeces. To compute position of - array elements */ + array elements */ entity *nodes[1]; /**< List of entities of length len to express the - access path. */ + access path. */ }; /** the type of an entity */ diff --git a/ir/tr/trvrfy.c b/ir/tr/trvrfy.c index 109535309..21054ecd2 100644 --- a/ir/tr/trvrfy.c +++ b/ir/tr/trvrfy.c @@ -169,6 +169,8 @@ static int constants_on_wrong_irg(entity *ent) { */ static int check_entity(entity *ent) { int rem_vpi; + type *tp = get_entity_type(ent); + type *owner = get_entity_owner(ent); current_ir_graph = get_const_code_irg(); if (constants_on_wrong_irg(ent)) { @@ -198,6 +200,21 @@ static int check_entity(entity *ent) { } } + /* Entities in global type are not dynamic or automatic allocated. */ + if (owner == get_glob_type()) { + assert(get_entity_allocation(ent) != allocation_dynamic && + get_entity_allocation(ent) != allocation_automatic); + } + + if (get_entity_variability(ent) != variability_uninitialized) { + if (is_atomic_type(tp)) { + ir_node *val = get_atomic_ent_value(ent); + if (val) + assert(get_irn_mode(val) == get_type_mode(tp) && + "Mode of constant in entity must match type."); + } + } + return no_error; }