4 * This file contains the following IRG modifications for be routines:
5 * - insertion of Perm nodes
6 * - empty block elimination
7 * - a simple dead node elimination (set inputs of unreachable nodes to BAD)
9 * @author Sebastian Hack, Daniel Grund, Matthias Braun, Christian Wuerdig
12 * Copyright: (c) Universitaet Karlsruhe
13 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
42 #include "iredges_t.h"
43 #include "irgraph_t.h"
45 #include "irprintf_t.h"
49 #include "bechordal_t.h"
51 #include "besched_t.h"
56 #include "bessaconstr.h"
60 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
64 |_ _|_ __ ___ ___ _ __| |_ | _ \ ___ _ __ _ __ ___
65 | || '_ \/ __|/ _ \ '__| __| | |_) / _ \ '__| '_ ` _ \
66 | || | | \__ \ __/ | | |_ | __/ __/ | | | | | | |
67 |___|_| |_|___/\___|_| \__| |_| \___|_| |_| |_| |_|
71 ir_node *insert_Perm_after(be_irg_t *birg,
72 const arch_register_class_t *cls,
75 const arch_env_t *arch_env = birg->main_env->arch_env;
76 be_lv_t *lv = birg->lv;
77 ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos);
78 ir_graph *irg = get_irn_irg(bl);
79 pset *live = pset_new_ptr_default();
81 ir_node *curr, *irn, *perm, **nodes;
84 DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos));
86 be_liveness_nodes_live_at(lv, arch_env, cls, pos, live);
95 nodes = xmalloc(n * sizeof(nodes[0]));
97 DBG((dbg, LEVEL_1, "live:\n"));
98 for(irn = pset_first(live), i = 0; irn; irn = pset_next(live), i++) {
99 DBG((dbg, LEVEL_1, "\t%+F\n", irn));
104 perm = be_new_Perm(cls, irg, bl, n, nodes);
105 sched_add_after(pos, perm);
109 for (i = 0; i < n; ++i) {
110 ir_node *perm_op = get_irn_n(perm, i);
111 const arch_register_t *reg = arch_get_irn_register(arch_env, perm_op);
112 be_ssa_construction_env_t senv;
114 ir_mode *mode = get_irn_mode(perm_op);
115 ir_node *proj = new_r_Proj(irg, bl, perm, mode, i);
116 arch_set_irn_register(arch_env, proj, reg);
118 sched_add_after(curr, proj);
121 be_ssa_construction_init(&senv, birg);
122 be_ssa_construction_add_copy(&senv, perm_op);
123 be_ssa_construction_add_copy(&senv, proj);
124 be_ssa_construction_fix_users(&senv, perm_op);
125 be_ssa_construction_update_liveness_phis(&senv, lv);
126 be_liveness_update(lv, perm_op);
127 be_liveness_update(lv, proj);
128 be_ssa_construction_destroy(&senv);
135 * Post-block-walker: Find blocks containing only one jump and
138 static void remove_empty_block(ir_node *block, void *data) {
139 const ir_edge_t *edge, *next;
142 ir_node *jump = NULL;
144 assert(is_Block(block));
146 if (get_Block_n_cfgpreds(block) != 1)
149 sched_foreach(block, node) {
153 /* we should never have 2 jumps in a block */
154 panic("We should never have 2 jumps in a block");
162 node = get_Block_cfgpred(block, 0);
163 foreach_out_edge_safe(jump, edge, next) {
164 ir_node *block = get_edge_src_irn(edge);
165 int pos = get_edge_src_pos(edge);
167 set_irn_n(block, pos, node);
170 set_Block_cfgpred(block, 0, new_Bad());
175 /* removes basic blocks that just contain a jump instruction */
176 int be_remove_empty_blocks(ir_graph *irg) {
179 irg_block_walk_graph(irg, remove_empty_block, NULL, &changed);
181 /* invalidate analysis info */
182 set_irg_doms_inconsistent(irg);
183 set_irg_extblk_inconsistent(irg);
184 set_irg_outs_inconsistent(irg);
189 void be_init_irgmod(void)
191 FIRM_DBG_REGISTER(dbg, "firm.be.irgmod");
194 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_irgmod);