From 78ea4d20e3cc44e812ab524d73d44d40fef64033 Mon Sep 17 00:00:00 2001 From: Josh warner Date: Tue, 11 Aug 2009 13:46:51 -0600 Subject: [PATCH] added loneMatch to improve register allocation --- src/compiler.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index 0f1f37cdaa..e715f54cce 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -108,6 +108,8 @@ class Site { virtual unsigned copyCost(Context*, Site*) = 0; virtual bool match(Context*, const SiteMask&) = 0; + + virtual bool loneMatch(Context*, const SiteMask&) = 0; virtual void acquire(Context*, Value*) { } @@ -1429,6 +1431,10 @@ class ConstantSite: public Site { return mask.typeMask & (1 << ConstantOperand); } + virtual bool loneMatch(Context*, const SiteMask&) { + return true; + } + virtual OperandType type(Context*) { return ConstantOperand; } @@ -1501,6 +1507,10 @@ class AddressSite: public Site { return mask.typeMask & (1 << AddressOperand); } + virtual bool loneMatch(Context*, const SiteMask&) { + return false; + } + virtual OperandType type(Context*) { return AddressOperand; } @@ -1575,6 +1585,16 @@ class RegisterSite: public Site { } } + virtual bool loneMatch(Context* c UNUSED, const SiteMask& mask) { + assert(c, number != NoRegister); + + if ((mask.typeMask & (1 << RegisterOperand))) { + return ((static_cast(1) << number) == mask.registerMask); + } else { + return false; + } + } + virtual void acquire(Context* c, Value* v) { Target target; if (number != NoRegister) { @@ -1729,6 +1749,23 @@ class MemorySite: public Site { } } + virtual bool loneMatch(Context* c, const SiteMask& mask) { + assert(c, acquired); + + if (mask.typeMask & (1 << MemoryOperand)) { + if (base == c->arch->stack()) { + assert(c, index == NoRegister); + + if (mask.frameIndex == AnyFrameIndex) { + return false; + } else { + return true; + } + } + } + return false; + } + virtual void acquire(Context* c, Value* v) { increment(c, c->registerResources + base); if (index != NoRegister) { @@ -3145,7 +3182,8 @@ getTarget(Context* c, Value* value, Value* result, const SiteMask& resultMask) Site* s; Value* v; Read* r = liveNext(c, value); - if (value->source->match(c, static_cast(resultMask))) { + if (value->source->match(c, static_cast(resultMask)) and (r == 0 or + value->source->loneMatch(c, static_cast(resultMask)))) { s = value->source; v = value; if (r and not hasMoreThanOneSite(v)) {