+ir_node *be_spill(
+ const be_node_factory_t *factory,
+ const arch_env_t *arch_env,
+ ir_node *irn)
+{
+ const arch_register_class_t *cls
+ = arch_get_irn_reg_class(arch_env, irn, arch_pos_make_out(0));
+ ir_node *bl = get_nodes_block(irn);
+ ir_graph *irg = get_irn_irg(bl);
+ ir_node *spill = new_Spill(factory, cls, irg, bl, irn);
+
+ ir_node *insert;
+
+ /*
+ * search the right insertion point. a spill of a phi cannot be put
+ * directly after the phi, if there are some phis behind the one which
+ * is spilled.
+ */
+ insert = sched_next(irn);
+ while(is_Phi(insert) && !sched_is_end(insert))
+ insert = sched_next(insert);
+
+ sched_add_before(insert, spill);
+ return spill;
+}
+
+ir_node *be_reload(
+ const be_node_factory_t *factory,
+ const arch_env_t *arch_env,
+ const arch_register_class_t *cls,
+ ir_node *irn, int pos, ir_mode *mode, ir_node *spill)
+{
+ ir_node *reload;
+
+ ir_node *bl = get_nodes_block(irn);
+ ir_graph *irg = get_irn_irg(bl);
+
+ assert(is_Spill(factory, spill)
+ || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
+
+ reload = new_Reload(factory, cls, irg, bl, mode, spill);
+
+ set_irn_n(irn, pos, reload);
+ sched_add_before(irn, reload);
+ return reload;
+}
+