|
|
|
|
@ -599,7 +599,8 @@ namespace mir
|
|
|
|
|
static GraphColoringResult ColorGraph(
|
|
|
|
|
InterferenceGraph &graph,
|
|
|
|
|
const std::vector<int> &allocatable_regs,
|
|
|
|
|
MachineFunction & /*function*/)
|
|
|
|
|
MachineFunction & /*function*/,
|
|
|
|
|
int caller_saved_threshold = 19)
|
|
|
|
|
{
|
|
|
|
|
const int K = static_cast<int>(allocatable_regs.size());
|
|
|
|
|
GraphColoringResult result;
|
|
|
|
|
@ -726,24 +727,29 @@ namespace mir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int assigned_color = -1;
|
|
|
|
|
// 收集可用颜色,区分caller-saved和callee-saved
|
|
|
|
|
std::vector<int> caller_saved_avail;
|
|
|
|
|
std::vector<int> callee_saved_avail;
|
|
|
|
|
// 第一遍:优先选 caller-saved 颜色 (c < caller_saved_threshold)
|
|
|
|
|
for (int c : allocatable_regs)
|
|
|
|
|
{
|
|
|
|
|
if (c >= caller_saved_threshold) break;
|
|
|
|
|
if (used_colors.find(c) == used_colors.end())
|
|
|
|
|
{
|
|
|
|
|
if (c < 19)
|
|
|
|
|
caller_saved_avail.push_back(c);
|
|
|
|
|
else
|
|
|
|
|
callee_saved_avail.push_back(c);
|
|
|
|
|
assigned_color = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 第二遍:若 caller-saved 无可用,选 callee-saved
|
|
|
|
|
if (assigned_color < 0)
|
|
|
|
|
{
|
|
|
|
|
for (int c : allocatable_regs)
|
|
|
|
|
{
|
|
|
|
|
if (c < caller_saved_threshold) continue;
|
|
|
|
|
if (used_colors.find(c) == used_colors.end())
|
|
|
|
|
{
|
|
|
|
|
assigned_color = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 优先选择caller-saved颜色
|
|
|
|
|
if (!caller_saved_avail.empty())
|
|
|
|
|
assigned_color = caller_saved_avail[0];
|
|
|
|
|
else if (!callee_saved_avail.empty())
|
|
|
|
|
assigned_color = callee_saved_avail[0];
|
|
|
|
|
|
|
|
|
|
if (assigned_color >= 0)
|
|
|
|
|
{
|
|
|
|
|
@ -996,8 +1002,8 @@ namespace mir
|
|
|
|
|
BuildInterferenceForGP(function, block_liveness, gp_alloc, gp_graph);
|
|
|
|
|
BuildInterferenceForFP(function, block_liveness, fp_alloc, fp_graph);
|
|
|
|
|
|
|
|
|
|
auto gp_result = ColorGraph(gp_graph, gp_alloc, function);
|
|
|
|
|
auto fp_result = ColorGraph(fp_graph, fp_alloc, function);
|
|
|
|
|
auto gp_result = ColorGraph(gp_graph, gp_alloc, function, 19);
|
|
|
|
|
auto fp_result = ColorGraph(fp_graph, fp_alloc, function, 16);
|
|
|
|
|
|
|
|
|
|
if (gp_result.spilled.empty() && fp_result.spilled.empty())
|
|
|
|
|
{
|
|
|
|
|
|