This will build the conflict table or interference graph. This is essentially a map from one instruction to a set of instruction that are used together. Each instruction will be the allocation instruction.
| 48 | // essentially a map from one instruction to a set of instruction that are |
| 49 | // used together. Each instruction will be the allocation instruction. |
| 50 | static instruction_set_map build_conflict_table(const module& m, std::string allocation_op) |
| 51 | { |
| 52 | instruction_set_map conflict_table; |
| 53 | liveness(m, [&](auto ins, const auto& live_set) { |
| 54 | // Skip variables that aren't allocations |
| 55 | if(ins->name() != allocation_op) |
| 56 | return; |
| 57 | // Skip zero allocations |
| 58 | if(ins->get_shape().bytes() == 0) |
| 59 | return; |
| 60 | conflict_table[ins]; |
| 61 | for(auto i : live_set) |
| 62 | { |
| 63 | if(i == ins) |
| 64 | continue; |
| 65 | // Skip variables that aren't allocations |
| 66 | if(i->name() != allocation_op) |
| 67 | continue; |
| 68 | // Skip zero allocations |
| 69 | if(i->get_shape().bytes() == 0) |
| 70 | continue; |
| 71 | conflict_table[i].insert(ins); |
| 72 | conflict_table[ins].insert(i); |
| 73 | } |
| 74 | }); |
| 75 | assert(std::all_of(conflict_table.begin(), conflict_table.end(), [](auto&& pp) { |
| 76 | return pp.second.count(pp.first) == 0; |
| 77 | })); |
| 78 | return conflict_table; |
| 79 | } |
| 80 | |
| 81 | // Check if intervals overlap |
| 82 | static bool is_overlap(std::pair<std::size_t, std::size_t> x, std::pair<std::size_t, std::size_t> y) |