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.
36 #include "iredges_t.h"
37 #include "irgraph_t.h"
39 #include "irprintf_t.h"
43 #include "bechordal_t.h"
45 #include "besched_t.h"
50 #include "bessaconstr.h"
54 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
58 |_ _|_ __ ___ ___ _ __| |_ | _ \ ___ _ __ _ __ ___
59 | || '_ \/ __|/ _ \ '__| __| | |_) / _ \ '__| '_ ` _ \
60 | || | | \__ \ __/ | | |_ | __/ __/ | | | | | | |
61 |___|_| |_|___/\___|_| \__| |_| \___|_| |_| |_| |_|
65 ir_node *insert_Perm_after(be_irg_t *birg,
66 const arch_register_class_t *cls,
69 const arch_env_t *arch_env = birg->main_env->arch_env;
70 be_lv_t *lv = birg->lv;
71 ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos);
72 ir_graph *irg = get_irn_irg(bl);
73 pset *live = pset_new_ptr_default();
75 ir_node *curr, *irn, *perm, **nodes;
78 DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos));
80 be_liveness_nodes_live_at(lv, arch_env, cls, pos, live);
89 nodes = xmalloc(n * sizeof(nodes[0]));
91 DBG((dbg, LEVEL_1, "live:\n"));
92 for(irn = pset_first(live), i = 0; irn; irn = pset_next(live), i++) {
93 DBG((dbg, LEVEL_1, "\t%+F\n", irn));
98 perm = be_new_Perm(cls, irg, bl, n, nodes);
99 sched_add_after(pos, perm);
103 for (i = 0; i < n; ++i) {
104 ir_node *perm_op = get_irn_n(perm, i);
105 const arch_register_t *reg = arch_get_irn_register(arch_env, perm_op);
106 be_ssa_construction_env_t senv;
108 ir_mode *mode = get_irn_mode(perm_op);
109 ir_node *proj = new_r_Proj(irg, bl, perm, mode, i);
110 arch_set_irn_register(arch_env, proj, reg);
112 sched_add_after(curr, proj);
115 be_ssa_construction_init(&senv, birg);
116 be_ssa_construction_add_copy(&senv, perm_op);
117 be_ssa_construction_add_copy(&senv, proj);
118 be_ssa_construction_fix_users(&senv, perm_op);
119 be_ssa_construction_update_liveness_phis(&senv, lv);
120 be_liveness_update(lv, perm_op);
121 be_liveness_update(lv, proj);
122 be_ssa_construction_destroy(&senv);
129 * Post-block-walker: Find blocks containing only one jump and
132 static void remove_empty_block(ir_node *block, void *data) {
133 const ir_edge_t *edge, *next;
136 ir_node *jump = NULL;
138 assert(is_Block(block));
140 if (get_Block_n_cfgpreds(block) != 1)
143 sched_foreach(block, node) {
147 /* we should never have 2 jumps in a block */
148 panic("We should never have 2 jumps in a block");
156 node = get_Block_cfgpred(block, 0);
157 foreach_out_edge_safe(jump, edge, next) {
158 ir_node *block = get_edge_src_irn(edge);
159 int pos = get_edge_src_pos(edge);
161 set_irn_n(block, pos, node);
164 set_Block_cfgpred(block, 0, new_Bad());
169 /* removes basic blocks that just contain a jump instruction */
170 int be_remove_empty_blocks(ir_graph *irg) {
173 irg_block_walk_graph(irg, remove_empty_block, NULL, &changed);
175 /* invalidate analysis info */
176 set_irg_doms_inconsistent(irg);
177 set_irg_extblk_inconsistent(irg);
178 set_irg_outs_inconsistent(irg);
183 void be_init_irgmod(void)
185 FIRM_DBG_REGISTER(dbg, "firm.be.irgmod");
188 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_irgmod);