- /* we found a spill id which can be assigned to current spill slot */
- vgpr_slot[id] = slot_idx;
- is_assigned[id] = true;
- for (unsigned i = slot_idx; i < slot_idx + ctx.interferences[id].first.size(); i++)
- spill_slot_interferences[i].insert(ctx.interferences[id].second.begin(), ctx.interferences[id].second.end());
-
- /* add all affinities: there are no additional interferences */
- for (std::vector<uint32_t>& vec : ctx.affinities) {
- bool found_affinity = false;
- for (uint32_t entry : vec) {
- if (entry == id) {
- found_affinity = true;
- break;
- }
- }
- if (!found_affinity)
- continue;
- for (uint32_t entry : vec) {
- vgpr_slot[entry] = slot_idx;
- is_assigned[entry] = true;
- }
+ slots[id] = slot;
+ is_assigned[id] = true;
+ }
+
+ *num_slots = slots_used.size();
+}
+
+void assign_spill_slots(spill_ctx& ctx, unsigned spills_to_vgpr) {
+ std::vector<uint32_t> slots(ctx.interferences.size());
+ std::vector<bool> is_assigned(ctx.interferences.size());
+
+ /* first, handle affinities: just merge all interferences into both spill ids */
+ for (std::vector<uint32_t>& vec : ctx.affinities) {
+ for (unsigned i = 0; i < vec.size(); i++) {
+ for (unsigned j = i + 1; j < vec.size(); j++) {
+ assert(vec[i] != vec[j]);
+ bool reloaded = ctx.is_reloaded[vec[i]] || ctx.is_reloaded[vec[j]];
+ ctx.is_reloaded[vec[i]] = reloaded;
+ ctx.is_reloaded[vec[j]] = reloaded;