blob: 19520a6349d63dfce500276da7edba2ceec989ba [file] [log] [blame]
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +00001// 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.orgdff694e2010-05-17 09:10:26 +000031#include "codegen.h"
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000032#include "register-allocator.h"
33#include "scopes.h"
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +000034#include "type-info.h"
35
36#include "codegen-inl.h"
37#include "jump-target-light-inl.h"
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000038
39namespace v8 {
40namespace internal {
41
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +000042VirtualFrame::VirtualFrame(InvalidVirtualFrameInitializer* dummy)
43 : element_count_(0),
44 top_of_stack_state_(NO_TOS_REGISTERS),
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +000045 register_allocation_map_(0),
46 tos_known_smi_map_(0) { }
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +000047
48
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000049// 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.
51VirtualFrame::VirtualFrame()
52 : element_count_(parameter_count() + 2),
ager@chromium.org357bf652010-04-12 11:30:10 +000053 top_of_stack_state_(NO_TOS_REGISTERS),
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +000054 register_allocation_map_(0),
55 tos_known_smi_map_(0) { }
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000056
57
58// When cloned, a frame is a deep copy of the original.
59VirtualFrame::VirtualFrame(VirtualFrame* original)
60 : element_count_(original->element_count()),
ager@chromium.org357bf652010-04-12 11:30:10 +000061 top_of_stack_state_(original->top_of_stack_state_),
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +000062 register_allocation_map_(original->register_allocation_map_),
63 tos_known_smi_map_(0) { }
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000064
65
ricow@chromium.org30ce4112010-05-31 10:38:25 +000066bool VirtualFrame::Equals(const VirtualFrame* other) {
ager@chromium.org357bf652010-04-12 11:30:10 +000067 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.org1af7e1b2010-06-07 11:12:01 +000070 if (tos_known_smi_map_ != other->tos_known_smi_map_) return false;
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000071
72 return true;
73}
74
75
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +000076void VirtualFrame::PrepareForReturn() {
whesse@chromium.org2c186ca2010-06-16 11:32:39 +000077 // 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.orgdf7a2842010-03-25 14:34:15 +000080}
81
82
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +000083VirtualFrame::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
97VirtualFrame::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.org30ce4112010-05-31 10:38:25 +0000108CodeGenerator* VirtualFrame::cgen() const {
109 return CodeGeneratorScope::Current();
110}
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000111
112
113MacroAssembler* VirtualFrame::masm() { return cgen()->masm(); }
114
115
116void 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.org30ce4112010-05-31 10:38:25 +0000123int VirtualFrame::parameter_count() const {
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000124 return cgen()->scope()->num_parameters();
125}
126
127
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000128int VirtualFrame::local_count() const {
129 return cgen()->scope()->num_stack_slots();
130}
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000131
132
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000133int VirtualFrame::frame_pointer() const { return parameter_count() + 3; }
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000134
135
136int VirtualFrame::context_index() { return frame_pointer() - 1; }
137
138
139int VirtualFrame::function_index() { return frame_pointer() - 2; }
140
141
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000142int VirtualFrame::local0_index() const { return frame_pointer() + 2; }
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000143
144
145int 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.org30ce4112010-05-31 10:38:25 +0000152int VirtualFrame::expression_base_index() const {
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000153 return local0_index() + local_count();
154}
155
156
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000157int VirtualFrame::height() const {
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000158 return element_count() - expression_base_index();
159}
160
161
162MemOperand VirtualFrame::LocalAt(int index) {
163 ASSERT(0 <= index);
164 ASSERT(index < local_count());
165 return MemOperand(fp, kLocal0Offset - index * kPointerSize);
166}
167
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +0000168} } // namespace v8::internal
169
170#endif // V8_VIRTUAL_FRAME_LIGHT_INL_H_