Added call to eliminate_phi_interferences. Enabled phi-destruction.
[libfirm] / ir / be / bedupl.c
1 /**
2  * @file   bedupl.c
3  * @date   15.07.2005
4  * @author Sebastian Hack
5  *
6  * Insert duplicates for phi operands which interfere with the phi.
7  *
8  * Copyright (C) 2005 Universitaet Karlsruhe
9  * Released under the GPL
10  */
11
12 #include "irnode_t.h"
13 #include "irgraph_t.h"
14 #include "irgwalk.h"
15
16 #include "be_t.h"
17 #include "bearch.h"
18 #include "bera.h"
19 #include "benode_t.h"
20
21 static void eliminate_phi_int_walker(ir_node *irn, void *data)
22 {
23   const be_main_session_env_t *env = data;
24   const arch_register_class_t *cls =
25     arch_get_irn_reg_class(env->main_env->arch_env, irn, arch_pos_make_out(0));
26
27   if(is_Phi(irn) && cls != NULL) {
28     int i, n;
29     ir_node *phi_bl = get_nodes_block(irn);
30
31     for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
32       ir_node *operand   = get_irn_n(irn, i);
33       ir_node *bl        = get_Block_cfgpred_block(phi_bl, i);
34
35       if(values_interfere(irn, operand)) {
36         ir_node *copy = new_Copy(env->main_env->node_factory, cls, env->irg, bl, operand);
37         set_irn_n(irn, i, copy);
38       }
39     }
40   }
41 }
42
43 void be_eliminate_phi_interferences(const be_main_session_env_t *env)
44 {
45   irg_walk_graph(env->irg, eliminate_phi_int_walker, NULL, (void *) env);
46 }