-/**
- * A walker along the memory edge in a loop.The walker walk from the node to the loop head.
- * Load and Phi nodes muss be found for optimisation
- *
- * @param *node A node from the graph.
- * @param *env Contains information about scalars number and mode.
- * @param *repairs A set, that contains all blocks, that have a link, and all Phis, that
- * have copies to repair.
-*/
-static void loop_walk(ir_node *node, env_t *env, set *repairs)
-{
- int i, p, n = get_irn_arity(node);
- repairs_t key, *value, *value_block;
- ir_node *phi_pred;
- DDMN(node);
-
- /* Test if the loop head have been achieved. */
- if (has_backedges(get_nodes_block(node)))
- return;
-
- for (i = 0; i < n; i++) {
- ir_node *pred = get_irn_n(node, i);
-
- if((get_irn_op(pred) == op_Proj &&
- get_irn_mode(pred) == mode_M) ||
- get_irn_mode(pred) == mode_T ||
- is_memop(pred) ||
- get_irn_op(pred) == op_Call ||
- get_irn_op(pred) == op_Alloc)
- loop_walk(pred, env, repairs);
-
- if(get_irn_op(pred) == op_Phi &&
- get_irn_mode(pred) == mode_M &&
- get_irn_link(pred) != LOOP_WALK) {
- set_irn_link(pred, LOOP_WALK);
- loop_walk(pred, env, repairs);
- }
- }
-
- if (get_irn_op(node) == op_Load)
- load_handling(node, env, repairs);
-
- if (get_irn_op(node) == op_Phi && get_irn_mode(node) == mode_M){
- key.irn = node;
- value = set_find(repairs, &key, sizeof(key), HASH_PTR(key.irn));
- /* If the phi is in the set " repairs ", then muss be handled.*/
- if(value != NULL){
- DDMN(node);
- key.irn = get_nodes_block(node);
- value_block = set_find(repairs, &key, sizeof(key), HASH_PTR(key.irn));
- n = get_irn_arity(node);
- /* All predecessors of a Phi node muss be found.*/
- for(i = 0; i < env->nvals; i ++)
- for(p = 0; p < n; p ++){
- phi_pred = get_Phi_pred(value->irn, p);
- pred_search(phi_pred, value_block, repairs, i, p);
- }
- }
- }
- /* Reset the links, that have beeb used by the walk.*/
- if(get_irn_link(node) == LOOP_WALK)
- set_irn_link(node, NULL);
-}
-
-/**
- * Handle Stores that were been scalar replaced or
- * will be scalar replaced.
- *
- * @param load A store node.
- * @param env Contains information about scalars number and mode.
- * @param repairs A set, that contains all blocks, that have a link, and all Phis, that
- * have copies to repair.
- */
-static void store_handling(ir_node *store, env_t *env, set *repairs)
-{
- repairs_t key, *value;
- ir_node *nods_block, *store_mem, *store_ptr, *store_value, *phi;
- ir_loop *store_l;
-
- store_ptr = get_Store_ptr(store);
-
- /* The pointer predecessor of Store must be a Sel node.*/
- if (get_irn_op(store_ptr) == op_Sel) {
- /* If the link field of a Store's is set to "ADDRESS_TAKEN", that mean this value
- can't be scalar replaced. It's nothing to do and store_handling() must be exit.*/
- if (get_entity_link(get_Sel_entity(store_ptr)) == ADDRESS_TAKEN)
- return;
-
- /* If the Store node is in a loop, than the loop head of the Store
- * must be handled, if this was not already done. */
- store_l = get_irn_loop(store);
- if (store_l != NULL) {
- phi = get_loop_node(store_l, 0);
- if (get_irn_op(phi) != op_Block) {
- key.irn = get_nodes_block(phi);
- value = set_find(repairs, &key, sizeof(key), HASH_PTR(key.irn));
- if (value == NULL) {
- set_irn_link(phi, LOOP_HEAD_PHI);
- block_link(phi, env, repairs);
- phi_handling(phi, env, repairs);
- }
- }
- }
-
- DDMN(store);
- nods_block = get_nodes_block(store);
-
- key.irn = nods_block;
- value = set_find(repairs, &key, sizeof(key), HASH_PTR(nods_block));
-
- store_mem = get_Store_mem(store);
- store_value = get_Store_value(store);
-
- if (store_l != NULL)
- loop_walk(store, env, repairs);
- else
- memory_edge_walk2(store, env, repairs);
- /* Store's pointer predecessor's link field contains the position in the block's link, where
- must be saved the value predecessor of this store. */
- value->link[(unsigned)get_irn_link(store_ptr)] = store_value;
-
- /* The store node can be turned into a tuple now. This tuple will be optimized later. */
- turn_into_tuple(store, pn_Store_max);
- set_Tuple_pred(store, pn_Store_M, store_mem);
- set_Tuple_pred(store, pn_Store_X_except, new_Bad());
- }
-}