sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | #ifndef V8_VIRTUAL_FRAME_LIGHT_INL_H_ |
| 29 | #define V8_VIRTUAL_FRAME_LIGHT_INL_H_ |
| 30 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 31 | #include "codegen.h" |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 32 | #include "register-allocator.h" |
| 33 | #include "scopes.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 34 | #include "type-info.h" |
| 35 | |
| 36 | #include "codegen-inl.h" |
| 37 | #include "jump-target-light-inl.h" |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 42 | VirtualFrame::VirtualFrame(InvalidVirtualFrameInitializer* dummy) |
| 43 | : element_count_(0), |
| 44 | top_of_stack_state_(NO_TOS_REGISTERS), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 45 | register_allocation_map_(0), |
| 46 | tos_known_smi_map_(0) { } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 47 | |
| 48 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 49 | // On entry to a function, the virtual frame already contains the receiver, |
| 50 | // the parameters, and a return address. All frame elements are in memory. |
| 51 | VirtualFrame::VirtualFrame() |
| 52 | : element_count_(parameter_count() + 2), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 53 | top_of_stack_state_(NO_TOS_REGISTERS), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 54 | register_allocation_map_(0), |
| 55 | tos_known_smi_map_(0) { } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | // When cloned, a frame is a deep copy of the original. |
| 59 | VirtualFrame::VirtualFrame(VirtualFrame* original) |
| 60 | : element_count_(original->element_count()), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 61 | top_of_stack_state_(original->top_of_stack_state_), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 62 | register_allocation_map_(original->register_allocation_map_), |
| 63 | tos_known_smi_map_(0) { } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 64 | |
| 65 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 66 | bool VirtualFrame::Equals(const VirtualFrame* other) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 67 | ASSERT(element_count() == other->element_count()); |
| 68 | if (top_of_stack_state_ != other->top_of_stack_state_) return false; |
| 69 | if (register_allocation_map_ != other->register_allocation_map_) return false; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 70 | if (tos_known_smi_map_ != other->tos_known_smi_map_) return false; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 71 | |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 76 | void VirtualFrame::PrepareForReturn() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 77 | // Don't bother flushing tos registers as returning does not require more |
| 78 | // access to the expression stack. |
| 79 | top_of_stack_state_ = NO_TOS_REGISTERS; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 83 | VirtualFrame::RegisterAllocationScope::RegisterAllocationScope( |
| 84 | CodeGenerator* cgen) |
| 85 | : cgen_(cgen), |
| 86 | old_is_spilled_(SpilledScope::is_spilled_) { |
| 87 | SpilledScope::is_spilled_ = false; |
| 88 | if (old_is_spilled_) { |
| 89 | VirtualFrame* frame = cgen->frame(); |
| 90 | if (frame != NULL) { |
| 91 | frame->AssertIsSpilled(); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | |
| 97 | VirtualFrame::RegisterAllocationScope::~RegisterAllocationScope() { |
| 98 | SpilledScope::is_spilled_ = old_is_spilled_; |
| 99 | if (old_is_spilled_) { |
| 100 | VirtualFrame* frame = cgen_->frame(); |
| 101 | if (frame != NULL) { |
| 102 | frame->SpillAll(); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 108 | CodeGenerator* VirtualFrame::cgen() const { |
| 109 | return CodeGeneratorScope::Current(); |
| 110 | } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 111 | |
| 112 | |
| 113 | MacroAssembler* VirtualFrame::masm() { return cgen()->masm(); } |
| 114 | |
| 115 | |
| 116 | void VirtualFrame::CallStub(CodeStub* stub, int arg_count) { |
| 117 | if (arg_count != 0) Forget(arg_count); |
| 118 | ASSERT(cgen()->HasValidEntryRegisters()); |
| 119 | masm()->CallStub(stub); |
| 120 | } |
| 121 | |
| 122 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 123 | int VirtualFrame::parameter_count() const { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 124 | return cgen()->scope()->num_parameters(); |
| 125 | } |
| 126 | |
| 127 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 128 | int VirtualFrame::local_count() const { |
| 129 | return cgen()->scope()->num_stack_slots(); |
| 130 | } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 131 | |
| 132 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 133 | int VirtualFrame::frame_pointer() const { return parameter_count() + 3; } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 134 | |
| 135 | |
| 136 | int VirtualFrame::context_index() { return frame_pointer() - 1; } |
| 137 | |
| 138 | |
| 139 | int VirtualFrame::function_index() { return frame_pointer() - 2; } |
| 140 | |
| 141 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 142 | int VirtualFrame::local0_index() const { return frame_pointer() + 2; } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 143 | |
| 144 | |
| 145 | int VirtualFrame::fp_relative(int index) { |
| 146 | ASSERT(index < element_count()); |
| 147 | ASSERT(frame_pointer() < element_count()); // FP is on the frame. |
| 148 | return (frame_pointer() - index) * kPointerSize; |
| 149 | } |
| 150 | |
| 151 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 152 | int VirtualFrame::expression_base_index() const { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 153 | return local0_index() + local_count(); |
| 154 | } |
| 155 | |
| 156 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 157 | int VirtualFrame::height() const { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 158 | return element_count() - expression_base_index(); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | MemOperand VirtualFrame::LocalAt(int index) { |
| 163 | ASSERT(0 <= index); |
| 164 | ASSERT(index < local_count()); |
| 165 | return MemOperand(fp, kLocal0Offset - index * kPointerSize); |
| 166 | } |
| 167 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 168 | } } // namespace v8::internal |
| 169 | |
| 170 | #endif // V8_VIRTUAL_FRAME_LIGHT_INL_H_ |