+/**
+ * Returns non-zero, if two compound_graph_pathes are equal
+ */
+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++) {
+ type *tp;
+ entity *node1 = get_compound_graph_path_node(path1, i);
+ entity *node2 = get_compound_graph_path_node(path2, i);
+
+ if (node1 != node2) return false;
+
+ tp = get_entity_owner(node1);
+ if (is_Array_type(tp)) {
+ long low;
+
+ /* Compute the index of this node. */
+ assert(get_array_n_dimensions(tp) == 1 && "multidim not implemented");
+
+ 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;
+ }
+
+#if 0
+ {
+ int j;
+ printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
+ printf("Entity %s : ", get_entity_name(ent));
+ for (j = 0; j < get_compound_graph_path_length(path); ++j) {
+ entity *node = get_compound_graph_path_node(path, j);
+ printf("%s", get_entity_name(node));
+ if (is_Array_type(get_entity_owner(node)))
+ printf("[%d]", get_compound_graph_path_array_index(path, j));
+ }
+ printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
+ }
+#endif
+
+ 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));
+}
+
+