+ if (all_preds_known) {
+ available = available_in_all_preds(pred_worksets, arity, node, false);
+ } else {
+ available = AVAILABLE_UNKNOWN;
+ }
+
+ loc = to_take_or_not_to_take(first, node, loop, available);
+
+ if (! USES_IS_INFINITE(loc.time)) {
+ if (USES_IS_PENDING(loc.time))
+ ARR_APP1(loc_t, delayed, loc);
+ else
+ ARR_APP1(loc_t, starters, loc);
+ }
+ }
+
+ pressure = be_get_loop_pressure(loop_ana, cls, loop);
+ assert(ARR_LEN(delayed) <= (signed)pressure);
+ free_slots = n_regs - ARR_LEN(starters);
+ free_pressure_slots = n_regs - (pressure - ARR_LEN(delayed));
+ free_slots = MIN(free_slots, free_pressure_slots);
+
+ /* so far we only put nodes into the starters list that are used inside
+ * the loop. If register pressure in the loop is low then we can take some
+ * values and let them live through the loop */
+ DB((dbg, DBG_START, "Loop pressure %d, taking %d delayed vals\n",
+ pressure, free_slots));
+ if (free_slots > 0) {
+ qsort(delayed, ARR_LEN(delayed), sizeof(delayed[0]), loc_compare);
+
+ for (i = 0; i < ARR_LEN(delayed) && free_slots > 0; ++i) {
+ int p, arity;
+ loc_t *loc = & delayed[i];
+
+ if (!is_Phi(loc->node)) {
+ /* don't use values which are dead in a known predecessors
+ * to not induce unnecessary reloads */
+ arity = get_irn_arity(block);
+ for (p = 0; p < arity; ++p) {
+ ir_node *pred_block = get_Block_cfgpred_block(block, p);
+ block_info_t *pred_info = get_block_info(pred_block);
+
+ if (pred_info == NULL)
+ continue;
+
+ if (!workset_contains(pred_info->end_workset, loc->node)) {
+ DB((dbg, DBG_START,
+ " delayed %+F not live at pred %+F\n", loc->node,
+ pred_block));
+ goto skip_delayed;
+ }
+ }
+ }
+
+ 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;
+ }
+}