Build the allocation_color class from the conflict_table
| 213 | |
| 214 | // Build the allocation_color class from the conflict_table |
| 215 | static allocation_segment |
| 216 | build(const module& m, const instruction_set_map& conflict_table, std::size_t alignment) |
| 217 | { |
| 218 | allocation_segment as{}; |
| 219 | std::vector<instruction_ref> conflict_queue; |
| 220 | // Add all allocations to the conflict_queue |
| 221 | std::transform(conflict_table.begin(), |
| 222 | conflict_table.end(), |
| 223 | std::back_inserter(conflict_queue), |
| 224 | [](auto&& pp) { return pp.first; }); |
| 225 | |
| 226 | auto alloc_index = create_allocation_index(m, conflict_table); |
| 227 | |
| 228 | // Sort the conflict queue so we process the allocation with the most |
| 229 | // number of adjacent allocations first |
| 230 | std::sort(conflict_queue.begin(), conflict_queue.end(), by(std::greater<>{}, [&](auto x) { |
| 231 | return std::make_tuple( |
| 232 | conflict_table.at(x).size(), x->get_shape().bytes(), alloc_index.at(x)); |
| 233 | })); |
| 234 | // Process the conflict_queue, we refer to the current allocation as |
| 235 | // the parent and the adjacent allocations as children |
| 236 | for(auto parent : conflict_queue) |
| 237 | { |
| 238 | // Sort children by size |
| 239 | std::vector<instruction_ref> children(conflict_table.at(parent).begin(), |
| 240 | conflict_table.at(parent).end()); |
| 241 | std::sort(children.begin(), children.end(), by(std::less<>{}, [&](auto x) { |
| 242 | return std::make_tuple(x->get_shape().bytes(), alloc_index.at(x)); |
| 243 | })); |
| 244 | assert(not contains(children, parent)); |
| 245 | // This set is to track the segments already processed |
| 246 | std::set<segment> segments; |
| 247 | // Add all segments for the children to the segments already processed |
| 248 | transform_if( |
| 249 | children.begin(), |
| 250 | children.end(), |
| 251 | std::inserter(segments, segments.begin()), |
| 252 | [&](auto child) { return as.get_segment(child); }, |
| 253 | [&](auto child) { return *as.get_segment(child); }); |
| 254 | |
| 255 | assert(as.get_segment(parent) == nullptr); |
| 256 | as.add_segment(parent, next_segment(segments, parent, alignment)); |
| 257 | } |
| 258 | // Reduce the number of segments |
| 259 | for(std::size_t n = 0; n < 3; n++) |
| 260 | { |
| 261 | for(auto parent : conflict_queue) |
| 262 | { |
| 263 | auto children = conflict_table.at(parent); |
| 264 | // This set is to track the segments already processed |
| 265 | std::set<segment> segments; |
| 266 | // Add all segments for the children to the segments already processed |
| 267 | transform_if( |
| 268 | children.begin(), |
| 269 | children.end(), |
| 270 | std::inserter(segments, segments.begin()), |
| 271 | [&](auto child) { return as.get_segment(child); }, |
| 272 | [&](auto child) { return *as.get_segment(child); }); |
nothing calls this directly
no test coverage detected