Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "codegen.h" | 30 #include "codegen.h" |
| 31 #include "register-allocator.h" | 31 #include "register-allocator.h" |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 void RegisterAllocator::Initialize() { | 35 // ------------------------------------------------------------------------- |
| 36 registers_.Reset(); | 36 // Result implementation. |
| 37 registers_.Use(esp); | 37 |
| 38 registers_.Use(ebp); | 38 Result::Result(Register reg, CodeGenerator* cgen) |
| 39 registers_.Use(esi); | 39 : type_(REGISTER), |
| 40 registers_.Use(edi); | 40 cgen_(cgen) { |
| 41 data_.reg_ = reg; | |
| 42 ASSERT(!reg.is(no_reg)); | |
| 43 cgen_->allocator()->Use(reg); | |
|
William Hesse
2008/12/19 08:41:03
Do we want Result(no_reg) to be INVALID?
This way,
| |
| 41 } | 44 } |
| 42 | 45 |
| 43 | 46 |
| 44 Register RegisterAllocator::AllocateWithoutSpilling() { | 47 void Result::CopyTo(Result* destination) const { |
| 45 // Return the first free register, if any. | 48 destination->type_ = type(); |
| 46 for (int i = 0; i < num_registers(); i++) { | 49 destination->cgen_ = cgen_; |
| 47 if (!registers_.is_used(i)) { | 50 |
| 48 Register result = { i }; | 51 if (is_register()) { |
| 49 registers_.Use(result); | 52 destination->data_.reg_ = reg(); |
| 50 return result; | 53 cgen_->allocator()->Use(reg()); |
| 51 } | 54 } else if (is_constant()) { |
| 55 destination->data_.handle_ = data_.handle_; | |
| 56 } else { | |
| 57 ASSERT(!is_valid()); | |
| 52 } | 58 } |
| 53 return no_reg; | |
| 54 } | 59 } |
| 55 | 60 |
| 56 | 61 |
| 57 Register RegisterAllocator::Allocate() { | 62 void Result::Unuse() { |
| 58 Register result = AllocateWithoutSpilling(); | 63 if (is_register()) { |
| 59 if (result.is(no_reg)) { | 64 cgen_->allocator()->Unuse(reg()); |
| 65 } | |
| 66 type_ = INVALID; | |
| 67 } | |
| 68 | |
| 69 | |
| 70 void Result::ToRegister() { | |
| 71 ASSERT(is_valid()); | |
| 72 if (is_constant()) { | |
| 73 Result fresh = cgen_->allocator()->Allocate(); | |
| 74 ASSERT(fresh.is_valid()); | |
| 75 cgen_->masm()->Set(fresh.reg(), Immediate(handle())); | |
| 76 // This result becomes a copy of the fresh one. | |
| 77 cgen_->allocator()->Use(fresh.reg()); | |
| 78 type_ = REGISTER; | |
| 79 data_.reg_ = fresh.reg(); | |
| 80 } | |
| 81 ASSERT(is_register()); | |
| 82 } | |
| 83 | |
| 84 | |
| 85 // ------------------------------------------------------------------------- | |
| 86 // RegisterAllocator implementation. | |
| 87 | |
| 88 void RegisterAllocator::Initialize() { | |
| 89 registers_.Reset(); | |
| 90 Use(esp); | |
| 91 Use(ebp); | |
| 92 Use(esi); | |
| 93 Use(edi); | |
|
William Hesse
2008/12/19 08:41:03
Pretty sad, that we use all of these. :(
Kevin Millikin (Chromium)
2008/12/19 08:48:11
Those are the callee-save registers at JS function
| |
| 94 } | |
| 95 | |
| 96 | |
| 97 Result RegisterAllocator::AllocateWithoutSpilling() { | |
| 98 // Return the first free register, if any. | |
| 99 for (int i = 0; i < num_registers(); i++) { | |
| 100 if (!is_used(i)) { | |
| 101 Register free_reg = { i }; | |
| 102 return Result(free_reg, cgen_); | |
| 103 } | |
| 104 } | |
| 105 return Result(cgen_); | |
| 106 } | |
| 107 | |
| 108 | |
| 109 Result RegisterAllocator::Allocate() { | |
| 110 Result result = AllocateWithoutSpilling(); | |
| 111 if (!result.is_valid()) { | |
| 60 // Ask the current frame to spill a register. | 112 // Ask the current frame to spill a register. |
| 61 ASSERT(code_generator_->frame() != NULL); | 113 ASSERT(cgen_->frame() != NULL); |
| 62 result = code_generator_->frame()->SpillAnyRegister(); | 114 Register free_reg = cgen_->frame()->SpillAnyRegister(); |
| 63 if (!result.is(no_reg)) { | 115 if (free_reg.is_valid()) { |
| 64 ASSERT(!registers_.is_used(result.code())); | 116 ASSERT(!is_used(free_reg.code())); |
| 65 registers_.Use(result); | 117 return Result(free_reg, cgen_); |
| 66 } | 118 } |
| 67 } | 119 } |
| 68 return result; | 120 return result; |
| 69 } | 121 } |
| 70 | 122 |
| 71 | 123 |
| 72 } } // namespace v8::internal | 124 } } // namespace v8::internal |
| OLD | NEW |