- ir_node *sel, *next;
- path_t *key, *path;
- set *pathes = new_set(path_cmp, 8);
-
- /* visit all Sel nodes in the chain of the entity */
- for (sel = get_entity_link(ent); sel; sel = next) {
- next = get_irn_link(sel);
-
- key = find_path(sel, 0);
- path = set_find(pathes, key, sizeof(*key) + sizeof(key->path[0]) * key->path_len, path_hash(key));
-
- if (path)
- set_irn_link(sel, (void *)path->vnum);
- else {
- unsigned i;
-
- key->vnum = vnum++;
-
- set_insert(pathes, key, sizeof(*key) + sizeof(key->path[0]) * key->path_len, path_hash(key));
-
- set_irn_link(sel, (void *)key->vnum);
- ARR_EXTO(ir_mode *, *modes, (key->vnum + 15) & ~15);
-
- (*modes)[key->vnum] = get_type_mode(get_entity_type(get_Sel_entity(sel)));
-
- printf(" %s", get_entity_name(ent));
- for (i = 1; i < key->path_len; ++i) {
- if (is_entity(key->path[i].ent))
- printf(".%s", get_entity_name(key->path[i].ent));
- else
- printf("[%ld]", get_tarval_long(key->path[i].tv));
- }
- printf(" = %u (%s)\n", (int)get_irn_link(sel), get_mode_name((*modes)[key->vnum]));
- }
- free(key);
- }
-
- del_set(pathes);
- set_entity_link(ent, NULL);
- return vnum;
-}
-
-static char p;
-static void *NODE_VISITED = &p;
-static char t;
-static void *LOOP_WALK = &t;
-static char s;
-static void *LOOP_HEAD_PHI = &s;
-
-/**
- * environment for memory walker
- */
-typedef struct _env_t {
- struct obstack obst; /**< a obstack for the value blocks */
- int nvals; /**< number of values */
- ir_mode **modes; /**< the modes of the values */
-} env_t;
-
-static char q;
-static void *PRED_SEARCH = &q;
-
-/**
- * Recursive walk over the blocks, that are predecessors of "node".
- *
- * @param node A Load or Phi node. The predecessor of this node muss be faund.
- * @param value A struct pointer, that contains the block of node and their link.
- * @param repairs A set, that contains all blocks, that have a array as link, and all Phis, that
- * have copies to repair.
- * @param pos The position, that muss contain the predecessor of node, in the array, that have got the bloks
- * from the repairs set.
- * @param phi_pred If node is a Phi, phi_pred is the predecessor number of this Phi, that muss be repair.
- */
-static void pred_search(ir_node *node, repairs_t *value, set *repairs, int pos, int phi_pred)
-{
- ir_node *nodes_block;
- repairs_t key, *value_pred;
- int i, n;
-
- DDMN(node);
- nodes_block = get_nodes_block(node);
-
- /* If the predecessor is found. */
- if ((pos == -2 && value->link[pos] != NULL))
- return;
-
- n = get_Block_n_cfgpreds(nodes_block);
-
- for (i = n - 1; i >= 0; --i) {
- ir_node *pred = get_Block_cfgpred(nodes_block, i);
-
- key.irn = nodes_block;
- value_pred = set_find(repairs, &key, sizeof(key), HASH_PTR(key.irn));
- /* If nodes_block don't have the necessary information and the predecessor of it isn't
- visited "pred_search" was called recursive. Else the necessary information is found
- and the recursion stops. */
- if (value_pred == NULL || value_pred->link[pos] == NULL) {
- if (get_irn_link(pred) != PRED_SEARCH) {
- set_irn_link(node, PRED_SEARCH);
- pred_search(pred, value, repairs, pos, phi_pred);
- }
- }
- else {
- if (value->link[pos] == NULL && pos != -2) {
- if (get_Block_dom_depth(value->irn) >=
- get_Block_dom_depth(get_nodes_block(value_pred->link[pos]))) {
- value->link[pos] = value_pred->link[pos];
- pos = -2;
- break;
- }
- }
- else {
- if (get_irn_op(value->link[pos]) == op_Phi && pos != -2 &&
- value->link[pos] != value_pred->link[pos]) {
- set_Phi_pred(value->link[pos], phi_pred, value_pred->link[pos]);
- pos = -2;
- break;
+ ir_node *sel, *next;
+ path_t *key, *path;
+ set *pathes = new_set(path_cmp, 8);
+
+ DB((dbg, SET_LEVEL_3, " Visiting Sel nodes of entity %+F\n", ent));
+ /* visit all Sel nodes in the chain of the entity */
+ for (sel = (ir_node*)get_entity_link(ent); sel != NULL;
+ sel = next) {
+ next = (ir_node*)get_irn_link(sel);
+
+ /* we must mark this sel for later */
+ pset_insert_ptr(sels, sel);
+
+ key = find_path(sel, 0);
+ path = (path_t*)set_find(pathes, key, PATH_SIZE(key), path_hash(key));
+
+ if (path) {
+ SET_VNUM(sel, path->vnum);
+ DB((dbg, SET_LEVEL_3, " %+F represents value %u\n", sel, path->vnum));
+ } else {
+ key->vnum = vnum++;
+
+ set_insert(pathes, key, PATH_SIZE(key), path_hash(key));
+
+ SET_VNUM(sel, key->vnum);
+ DB((dbg, SET_LEVEL_3, " %+F represents value %u\n", sel, key->vnum));
+
+ ARR_EXTO(ir_mode *, *modes, (int)((key->vnum + 15) & ~15));
+
+ (*modes)[key->vnum] = get_type_mode(get_entity_type(get_Sel_entity(sel)));
+
+ assert((*modes)[key->vnum] && "Value is not atomic");
+
+#ifdef DEBUG_libfirm
+ /* Debug output */
+ {
+ unsigned i;
+ DB((dbg, SET_LEVEL_2, " %s", get_entity_name(key->path[0].ent)));
+ for (i = 1; i < key->path_len; ++i) {
+ if (is_entity(key->path[i].ent))
+ DB((dbg, SET_LEVEL_2, ".%s", get_entity_name(key->path[i].ent)));
+ else
+ DB((dbg, SET_LEVEL_2, "[%ld]", get_tarval_long(key->path[i].tv)));
+ }
+ DB((dbg, SET_LEVEL_2, " = %u (%s)\n", PTR_TO_INT(get_irn_link(sel)), get_mode_name((*modes)[key->vnum])));
+ }
+#endif /* DEBUG_libfirm */
+ }
+ free(key);