| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 Result fresh = cgen_->allocator()->Allocate(target); | 86 Result fresh = cgen_->allocator()->Allocate(target); |
| 87 ASSERT(fresh.is_valid()); | 87 ASSERT(fresh.is_valid()); |
| 88 if (is_register()) { | 88 if (is_register()) { |
| 89 cgen_->masm()->mov(fresh.reg(), reg()); | 89 cgen_->masm()->mov(fresh.reg(), reg()); |
| 90 } else { | 90 } else { |
| 91 ASSERT(is_constant()); | 91 ASSERT(is_constant()); |
| 92 cgen_->masm()->Set(fresh.reg(), Immediate(handle())); | 92 cgen_->masm()->Set(fresh.reg(), Immediate(handle())); |
| 93 } | 93 } |
| 94 *this = fresh; | 94 *this = fresh; |
| 95 } else if (is_register() && reg().is(target)) { | 95 } else if (is_register() && reg().is(target)) { |
| 96 ASSERT(cgen_->frame() != NULL); | 96 ASSERT(cgen_->has_valid_frame()); |
| 97 cgen_->frame()->Spill(target); | 97 cgen_->frame()->Spill(target); |
| 98 ASSERT(cgen_->allocator()->count(target) == 1); | 98 ASSERT(cgen_->allocator()->count(target) == 1); |
| 99 } | 99 } |
| 100 ASSERT(is_register()); | 100 ASSERT(is_register()); |
| 101 ASSERT(reg().is(target)); | 101 ASSERT(reg().is(target)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 // ------------------------------------------------------------------------- | 105 // ------------------------------------------------------------------------- |
| 106 // RegisterAllocator implementation. | 106 // RegisterAllocator implementation. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return Result(cgen_); | 125 return Result(cgen_); |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 Result RegisterAllocator::Allocate() { | 129 Result RegisterAllocator::Allocate() { |
| 130 Result result = AllocateWithoutSpilling(); | 130 Result result = AllocateWithoutSpilling(); |
| 131 if (!result.is_valid()) { | 131 if (!result.is_valid()) { |
| 132 // Ask the current frame to spill a register. | 132 // Ask the current frame to spill a register. |
| 133 ASSERT(cgen_->frame() != NULL); | 133 ASSERT(cgen_->has_valid_frame()); |
| 134 Register free_reg = cgen_->frame()->SpillAnyRegister(); | 134 Register free_reg = cgen_->frame()->SpillAnyRegister(); |
| 135 if (free_reg.is_valid()) { | 135 if (free_reg.is_valid()) { |
| 136 ASSERT(!is_used(free_reg)); | 136 ASSERT(!is_used(free_reg)); |
| 137 return Result(free_reg, cgen_); | 137 return Result(free_reg, cgen_); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 return result; | 140 return result; |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 Result RegisterAllocator::Allocate(Register target) { | 144 Result RegisterAllocator::Allocate(Register target) { |
| 145 // If the target is not referenced, it can simply be allocated. | 145 // If the target is not referenced, it can simply be allocated. |
| 146 if (!is_used(target)) { | 146 if (!is_used(target)) { |
| 147 return Result(target, cgen_); | 147 return Result(target, cgen_); |
| 148 } | 148 } |
| 149 // If the target is only referenced in the frame, it can be spilled and | 149 // If the target is only referenced in the frame, it can be spilled and |
| 150 // then allocated. | 150 // then allocated. |
| 151 ASSERT(cgen_->frame() != NULL); | 151 ASSERT(cgen_->has_valid_frame()); |
| 152 if (count(target) == cgen_->frame()->register_count(target)) { | 152 if (count(target) == cgen_->frame()->register_count(target)) { |
| 153 cgen_->frame()->Spill(target); | 153 cgen_->frame()->Spill(target); |
| 154 ASSERT(!is_used(target)); | 154 ASSERT(!is_used(target)); |
| 155 return Result(target, cgen_); | 155 return Result(target, cgen_); |
| 156 } | 156 } |
| 157 // Otherwise (if it's referenced outside the frame) we cannot allocate it. | 157 // Otherwise (if it's referenced outside the frame) we cannot allocate it. |
| 158 return Result(cgen_); | 158 return Result(cgen_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 } } // namespace v8::internal | 162 } } // namespace v8::internal |
| OLD | NEW |