bugfix
[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 #include "besched_t.h"
21
22 static void eliminate_phi_int_walker(ir_node *irn, void *data)
23 {
24   const be_main_session_env_t *env = data;
25   const arch_register_class_t *cls =
26     arch_get_irn_reg_class(env->main_env->arch_env, irn, arch_pos_make_out(0));
27
28   if(is_Phi(irn) && cls != NULL) {
29     int i, n;
30     ir_node *phi_bl = get_nodes_block(irn);
31
32     for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
33       ir_node *operand   = get_irn_n(irn, i);
34       ir_node *bl        = get_Block_cfgpred_block(phi_bl, i);
35
36       if(is_live_in(phi_bl, irn)) { // values_interfere(irn, operand)) {
37         ir_node *copy = new_Copy(env->main_env->node_factory, cls, env->irg, bl, operand);
38         set_irn_n(irn, i, copy);
39         sched_add_after(sched_last(bl), copy);
40       }
41     }
42   }
43 }
44
45 void be_eliminate_phi_interferences(const be_main_session_env_t *env)
46 {
47   irg_walk_graph(env->irg, eliminate_phi_int_walker, NULL, (void *) env);
48 }