-static int is_mem_phi(const ir_node *irn, void *data) {
- ir_node *blk = get_nodes_block(irn);
- workset_t *sws = ((block_info_t *)get_irn_link(blk))->ws_start;
- return !workset_contains(sws, irn);
+/**
+ * Finds all unused reloads and remove them from the schedule
+ * Also removes spills if they are not used anymore after removing reloads
+ */
+static void remove_unused_reloads(ir_graph *irg, belady_env_t *bel) {
+ ir_node *irn;
+
+ irg_walk_graph(irg, rescue_used_reloads, NULL, bel->reloads);
+ for(irn = pset_first(bel->reloads); irn; irn = pset_next(bel->reloads)) {
+ ir_node *spill;
+ DBG((dbg, DBG_SPILL, "Removing %+F before %+F in %+F\n", irn, sched_next(irn), get_nodes_block(irn)));
+
+ spill = get_irn_n(irn, 0);
+
+ /* remove reload */
+ set_irn_n(irn, 0, new_Bad());
+ sched_remove(irn);
+
+ /* if spill not used anymore, remove it too
+ * test of regclass is necessary since spill may be a phi-M */
+ if (get_irn_n_edges(spill) == 0 && bel->cls == arch_get_irn_reg_class(bel->arch, spill, -1)) {
+ set_irn_n(spill, 0, new_Bad());
+ sched_remove(spill);
+ }
+ }