From c9400316fd5c993e94b76d2a63a7740209289ced Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 16 Mar 2009 20:03:59 -0600 Subject: [PATCH] try harder to find a suitable stack frame site in pickTarget when there are no free registers left --- src/compiler.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index 74af58d4bf..f48fa446a6 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -1153,7 +1153,7 @@ pickFrameTarget(Context* c, Value* v) do { if (p->home >= 0) { Target mine(p->home, MemoryOperand, frameCost(c, v, p->home)); - if (mine.cost == 0) { + if (mine.cost == 1) { return mine; } else if (mine.cost < best.cost) { best = mine; @@ -1165,6 +1165,24 @@ pickFrameTarget(Context* c, Value* v) return best; } +Target +pickAnyFrameTarget(Context* c, Value* v) +{ + Target best; + + unsigned count = usableFrameSize(c) + c->parameterFootprint; + for (unsigned i = 0; i < count; ++i) { + Target mine(i, MemoryOperand, frameCost(c, v, i)); + if (mine.cost == 1) { + return mine; + } else if (mine.cost < best.cost) { + best = mine; + } + } + + return best; +} + Target pickTarget(Context* c, Read* read, bool intersectRead, unsigned registerReserveCount) @@ -1221,6 +1239,14 @@ pickTarget(Context* c, Read* read, bool intersectRead, } } + if (best.cost > 3 and c->availableRegisterCount == 0) { + // there are no free registers left, so moving from memory to + // memory isn't an option - try harder to find an available frame + // site: + best = pickAnyFrameTarget(c, read->value); + assert(c, best.cost <= 3); + } + return best; }