Chromium Code Reviews| Index: src/register-allocator-ia32.cc |
| =================================================================== |
| --- src/register-allocator-ia32.cc (revision 1012) |
| +++ src/register-allocator-ia32.cc (working copy) |
| @@ -39,7 +39,7 @@ |
| : type_(REGISTER), |
| cgen_(cgen) { |
| data_.reg_ = reg; |
| - ASSERT(!reg.is(no_reg)); |
| + ASSERT(reg.is_valid()); |
| cgen_->allocator()->Use(reg); |
| } |
| @@ -74,14 +74,30 @@ |
| ASSERT(fresh.is_valid()); |
| cgen_->masm()->Set(fresh.reg(), Immediate(handle())); |
| // This result becomes a copy of the fresh one. |
| - cgen_->allocator()->Use(fresh.reg()); |
| - type_ = REGISTER; |
| - data_.reg_ = fresh.reg(); |
| + *this = fresh; |
| } |
| ASSERT(is_register()); |
| } |
| +void Result::ToRegister(Register target) { |
| + ASSERT(is_valid()); |
| + if (!is_register() || !reg().is(target)) { |
| + Result fresh = cgen_->allocator()->Allocate(target); |
| + ASSERT(fresh.is_valid()); |
| + if (is_register()) { |
| + cgen_->masm()->mov(fresh.reg(), reg()); |
| + } else { |
| + ASSERT(is_constant()); |
| + cgen_->masm()->Set(fresh.reg(), Immediate(handle())); |
| + } |
| + *this = fresh; |
| + } |
|
William Hesse
2008/12/22 13:55:21
I think we are missing the case where this.reg() i
Kevin Millikin (Chromium)
2008/12/22 14:40:00
Yes, according to the comment in the header we do.
|
| + ASSERT(is_register()); |
| + ASSERT(reg().is(target)); |
| +} |
| + |
| + |
| // ------------------------------------------------------------------------- |
| // RegisterAllocator implementation. |
| @@ -113,7 +129,7 @@ |
| ASSERT(cgen_->frame() != NULL); |
| Register free_reg = cgen_->frame()->SpillAnyRegister(); |
| if (free_reg.is_valid()) { |
| - ASSERT(!is_used(free_reg.code())); |
| + ASSERT(!is_used(free_reg)); |
| return Result(free_reg, cgen_); |
| } |
| } |
| @@ -121,4 +137,22 @@ |
| } |
| +Result RegisterAllocator::Allocate(Register target) { |
| + // If the target is not referenced, it can simply be allocated. |
| + if (!is_used(target)) { |
| + return Result(target, cgen_); |
| + } |
| + // If the target is only referenced in the frame, it can be spilled and |
| + // then allocated. |
| + ASSERT(cgen_->frame() != NULL); |
| + if (count(target) == cgen_->frame()->register_count(target)) { |
| + cgen_->frame()->Spill(target); |
| + ASSERT(!is_used(target)); |
| + return Result(target, cgen_); |
| + } |
| + // Otherwise (if it's referenced outside the frame) we cannot allocate it. |
| + return Result(cgen_); |
| +} |
| + |
| + |
| } } // namespace v8::internal |