+ DB((dbg, DBG_START, " delayed %+F taken\n", loc->node));
+ ARR_APP1(loc_t, starters, *loc);
+ loc->node = NULL;
+ --free_slots;
+ skip_delayed:
+ ;
+ }
+ }
+
+ /* spill phis (the actual phis not just their values) that are in this block
+ * but not in the start workset */
+ for (i = ARR_LEN(delayed) - 1; i >= 0; --i) {
+ ir_node *node = delayed[i].node;
+ if (node == NULL || !is_Phi(node) || get_nodes_block(node) != block)
+ continue;
+
+ DB((dbg, DBG_START, " spilling delayed phi %+F\n", node));
+ be_spill_phi(senv, node);
+ }
+ DEL_ARR_F(delayed);
+
+ /* Sort start values by first use */
+ qsort(starters, ARR_LEN(starters), sizeof(starters[0]), loc_compare);
+
+ /* Copy the best ones from starters to start workset */
+ ws_count = MIN(ARR_LEN(starters), n_regs);
+ workset_clear(ws);
+ workset_bulk_fill(ws, ws_count, starters);
+
+ /* spill phis (the actual phis not just their values) that are in this block
+ * but not in the start workset */
+ len = ARR_LEN(starters);
+ for (i = ws_count; i < len; ++i) {
+ ir_node *node = starters[i].node;
+ if (! is_Phi(node) || get_nodes_block(node) != block)
+ continue;
+
+ DB((dbg, DBG_START, " spilling phi %+F\n", node));
+ be_spill_phi(senv, node);
+ }
+
+ DEL_ARR_F(starters);
+
+ /* determine spill status of the values: If there's 1 pred block (which
+ * is no backedge) where the value is spilled then we must set it to
+ * spilled here. */
+ for(i = 0; i < ws_count; ++i) {
+ loc_t *loc = &ws->vals[i];
+ ir_node *value = loc->node;
+ bool spilled;
+ int n;
+
+ /* phis from this block aren't spilled */
+ if (get_nodes_block(value) == block) {
+ assert(is_Phi(value));
+ loc->spilled = false;
+ continue;
+ }
+
+ /* determine if value was spilled on any predecessor */
+ spilled = false;
+ for(n = 0; n < arity; ++n) {
+ workset_t *pred_workset = pred_worksets[n];
+ int p_len;
+ int p;
+
+ if (pred_workset == NULL)
+ continue;
+
+ p_len = workset_get_length(pred_workset);
+ for(p = 0; p < p_len; ++p) {
+ loc_t *l = &pred_workset->vals[p];
+
+ if (l->node != value)
+ continue;
+
+ if (l->spilled) {
+ spilled = true;
+ }
+ break;
+ }
+ }
+
+ loc->spilled = spilled;
+ }
+}