-/*
-
- _____ _ ____ _ _
- | ___(_)_ __ / ___|| |_ __ _ ___| | __
- | |_ | \ \/ / \___ \| __/ _` |/ __| |/ /
- | _| | |> < ___) | || (_| | (__| <
- |_| |_/_/\_\ |____/ \__\__,_|\___|_|\_\
-
-*/
-
-typedef ir_node **node_array;
-
-typedef struct fix_stack_walker_env_t {
- node_array sp_nodes;
-} fix_stack_walker_env_t;
-
-/**
- * Walker. Collect all stack modifying nodes.
- */
-static void collect_stack_nodes_walker(ir_node *node, void *data)
-{
- fix_stack_walker_env_t *env = data;
- const arch_register_req_t *req;
-
- if (get_irn_mode(node) == mode_T)
- return;
-
- req = arch_get_register_req_out(node);
- if (! (req->type & arch_register_req_type_produces_sp))
- return;
-
- ARR_APP1(ir_node*, env->sp_nodes, node);
-}
-
-void be_abi_fix_stack_nodes(be_abi_irg_t *env)
-{
- be_ssa_construction_env_t senv;
- int i, len;
- ir_node **phis;
- be_irg_t *birg = env->birg;
- be_lv_t *lv = be_get_birg_liveness(birg);
- fix_stack_walker_env_t walker_env;
-
- walker_env.sp_nodes = NEW_ARR_F(ir_node*, 0);
-
- irg_walk_graph(birg->irg, collect_stack_nodes_walker, NULL, &walker_env);
-
- /* nothing to be done if we didn't find any node, in fact we mustn't
- * continue, as for endless loops incsp might have had no users and is bad
- * now.
- */
- len = ARR_LEN(walker_env.sp_nodes);
- if (len == 0) {
- DEL_ARR_F(walker_env.sp_nodes);
- return;
- }
-
- be_ssa_construction_init(&senv, birg);
- be_ssa_construction_add_copies(&senv, walker_env.sp_nodes,
- ARR_LEN(walker_env.sp_nodes));
- be_ssa_construction_fix_users_array(&senv, walker_env.sp_nodes,
- ARR_LEN(walker_env.sp_nodes));
-
- if (lv != NULL) {
- len = ARR_LEN(walker_env.sp_nodes);
- for (i = 0; i < len; ++i) {
- be_liveness_update(lv, walker_env.sp_nodes[i]);
- }
- be_ssa_construction_update_liveness_phis(&senv, lv);
- }
-
- phis = be_ssa_construction_get_new_phis(&senv);
-
- /* set register requirements for stack phis */
- len = ARR_LEN(phis);
- for (i = 0; i < len; ++i) {
- ir_node *phi = phis[i];
- be_set_phi_reg_req(phi, &env->sp_req, arch_register_req_type_produces_sp);
- arch_set_irn_register(phi, env->arch_env->sp);
- }
- be_ssa_construction_destroy(&senv);
-
- DEL_ARR_F(walker_env.sp_nodes);
-}
-
-/**
- * Fix all stack accessing operations in the block bl.
- *
- * @param env the abi environment
- * @param bl the block to process
- * @param real_bias the bias value
- *
- * @return the bias at the end of this block
- */
-static int process_stack_bias(be_abi_irg_t *env, ir_node *bl, int real_bias)