+void
+add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path) {
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ assert(is_compound_graph_path(path));
+ ARR_APP1(ir_node *, ent->attr.cmpd_attr.values, val);
+ ARR_APP1(compound_graph_path *, ent->attr.cmpd_attr.val_paths, path);
+}
+
+void
+set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos) {
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ assert(is_compound_graph_path(path));
+ assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
+ ent->attr.cmpd_attr.values[pos] = val;
+ ent->attr.cmpd_attr.val_paths[pos] = path;
+}
+
+int
+get_compound_ent_n_values(ir_entity *ent) {
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ return ARR_LEN(ent->attr.cmpd_attr.values);
+}
+
+ir_node *
+get_compound_ent_value(ir_entity *ent, int pos) {
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
+ return ent->attr.cmpd_attr.values[pos];
+}
+
+compound_graph_path *
+get_compound_ent_value_path(ir_entity *ent, int pos) {
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.val_paths));
+ return ent->attr.cmpd_attr.val_paths[pos];
+}
+
+/**
+ * Returns non-zero, if two compound_graph_pathes are equal
+ */
+static int equal_paths(compound_graph_path *path1, int *visited_indices, 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 0;
+
+ for (i = 0; i < len1; i++) {
+ ir_type *tp;
+ ir_entity *node1 = get_compound_graph_path_node(path1, i);
+ ir_entity *node2 = get_compound_graph_path_node(path2, i);
+
+ if (node1 != node2) return 0;
+
+ 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_indices[i] < get_compound_graph_path_array_index(path2, i)) {
+ visited_indices[i]++;
+ return 0;
+ }
+ else
+ assert(low + visited_indices[i] == get_compound_graph_path_array_index(path2, i));
+ }
+ }
+ return 1;
+}
+
+/* Returns the position of a value with the given path.
+ * The path must contain array indices for all array element entities. */
+int get_compound_ent_pos_by_path(ir_entity *ent, compound_graph_path *path) {
+ int i, n_paths = get_compound_ent_n_values(ent);
+ int *visited_indices;
+ int path_len = get_compound_graph_path_length(path);
+
+ NEW_ARR_A(int *, visited_indices, path_len);
+ memset(visited_indices, 0, sizeof(*visited_indices) * path_len);
+ for (i = 0; i < n_paths; i ++) {
+ if (equal_paths(get_compound_ent_value_path(ent, i), visited_indices, 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) {
+ ir_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 indices for all array element entities. */
+ir_node *get_compound_ent_value_by_path(ir_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(ir_entity *ent, ir_entity *value_ent) {
+ int i;
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ for (i = 0; i < (ARR_LEN(ent->attr.cmpd_attr.val_paths)); ++i) {
+ compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i];
+ if (path->list[path->len-1].node == value_ent) {
+ for (; i < (ARR_LEN(ent->attr.cmpd_attr.val_paths))-1; ++i) {
+ ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1];
+ ent->attr.cmpd_attr.values[i] = ent->attr.cmpd_attr.values[i+1];
+ }
+ ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, ARR_LEN(ent->attr.cmpd_attr.val_paths) - 1);
+ ARR_SETLEN(ir_node*, ent->attr.cmpd_attr.values, ARR_LEN(ent->attr.cmpd_attr.values) - 1);
+ break;
+ }
+ }
+}
+
+void
+add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member) {
+ compound_graph_path *path;
+ ir_type *owner_tp = get_entity_owner(member);
+ assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+ path = new_compound_graph_path(get_entity_type(ent), 1);
+ path->list[0].node = member;
+ if (is_Array_type(owner_tp)) {
+ int max;
+ int i, n;
+
+ assert(get_array_n_dimensions(owner_tp) == 1 && has_array_lower_bound(owner_tp, 0));
+ max = get_array_lower_bound_int(owner_tp, 0) -1;
+ for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
+ int index = get_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0);
+ if (index > max) {
+ max = index;
+ }
+ }
+ path->list[0].index = max + 1;
+ }
+ add_compound_ent_value_w_path(ent, val, path);