Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/arm/virtual-frame-arm.h

Issue 1961004: First step towards making JumpTarget work on ARM. Instead... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 #ifndef V8_ARM_VIRTUAL_FRAME_ARM_H_ 28 #ifndef V8_ARM_VIRTUAL_FRAME_ARM_H_
29 #define V8_ARM_VIRTUAL_FRAME_ARM_H_ 29 #define V8_ARM_VIRTUAL_FRAME_ARM_H_
30 30
31 #include "register-allocator.h" 31 #include "register-allocator.h"
32 #include "scopes.h"
33 32
34 namespace v8 { 33 namespace v8 {
35 namespace internal { 34 namespace internal {
36 35
36 // This dummy class is only used to create invalid virtual frames.
37 extern class InvalidVirtualFrameInitializer {}* kInvalidVirtualFrameInitializer;
38
39
37 // ------------------------------------------------------------------------- 40 // -------------------------------------------------------------------------
38 // Virtual frames 41 // Virtual frames
39 // 42 //
40 // The virtual frame is an abstraction of the physical stack frame. It 43 // The virtual frame is an abstraction of the physical stack frame. It
41 // encapsulates the parameters, frame-allocated locals, and the expression 44 // encapsulates the parameters, frame-allocated locals, and the expression
42 // stack. It supports push/pop operations on the expression stack, as well 45 // stack. It supports push/pop operations on the expression stack, as well
43 // as random access to the expression stack elements, locals, and 46 // as random access to the expression stack elements, locals, and
44 // parameters. 47 // parameters.
45 48
46 class VirtualFrame : public ZoneObject { 49 class VirtualFrame : public ZoneObject {
(...skipping 28 matching lines...) Expand all
75 78
76 friend class RegisterAllocationScope; 79 friend class RegisterAllocationScope;
77 }; 80 };
78 81
79 class RegisterAllocationScope BASE_EMBEDDED { 82 class RegisterAllocationScope BASE_EMBEDDED {
80 public: 83 public:
81 // A utility class to introduce a scope where the virtual frame 84 // A utility class to introduce a scope where the virtual frame
82 // is not spilled, ie. where register allocation occurs. Eventually 85 // is not spilled, ie. where register allocation occurs. Eventually
83 // when RegisterAllocationScope is ubiquitous it can be removed 86 // when RegisterAllocationScope is ubiquitous it can be removed
84 // along with the (by then unused) SpilledScope class. 87 // along with the (by then unused) SpilledScope class.
85 explicit RegisterAllocationScope(CodeGenerator* cgen) 88 inline explicit RegisterAllocationScope(CodeGenerator* cgen);
86 : cgen_(cgen), 89 inline ~RegisterAllocationScope();
87 old_is_spilled_(SpilledScope::is_spilled_) {
88 SpilledScope::is_spilled_ = false;
89 if (old_is_spilled_) {
90 VirtualFrame* frame = cgen->frame();
91 if (frame != NULL) {
92 frame->AssertIsSpilled();
93 }
94 }
95 }
96 ~RegisterAllocationScope() {
97 SpilledScope::is_spilled_ = old_is_spilled_;
98 if (old_is_spilled_) {
99 VirtualFrame* frame = cgen_->frame();
100 if (frame != NULL) {
101 frame->SpillAll();
102 }
103 }
104 }
105 90
106 private: 91 private:
107 CodeGenerator* cgen_; 92 CodeGenerator* cgen_;
108 bool old_is_spilled_; 93 bool old_is_spilled_;
109 94
110 RegisterAllocationScope() { } 95 RegisterAllocationScope() { }
111 }; 96 };
112 97
113 // An illegal index into the virtual frame. 98 // An illegal index into the virtual frame.
114 static const int kIllegalIndex = -1; 99 static const int kIllegalIndex = -1;
115 100
116 // Construct an initial virtual frame on entry to a JS function. 101 // Construct an initial virtual frame on entry to a JS function.
117 inline VirtualFrame(); 102 inline VirtualFrame();
118 103
104 // Construct an invalid virtual frame, used by JumpTargets.
105 inline VirtualFrame(InvalidVirtualFrameInitializer* dummy);
106
119 // Construct a virtual frame as a clone of an existing one. 107 // Construct a virtual frame as a clone of an existing one.
120 explicit inline VirtualFrame(VirtualFrame* original); 108 explicit inline VirtualFrame(VirtualFrame* original);
121 109
122 CodeGenerator* cgen() { return CodeGeneratorScope::Current(); } 110 inline CodeGenerator* cgen();
123 MacroAssembler* masm() { return cgen()->masm(); } 111 inline MacroAssembler* masm();
124 112
125 // The number of elements on the virtual frame. 113 // The number of elements on the virtual frame.
126 int element_count() { return element_count_; } 114 int element_count() { return element_count_; }
127 115
128 // The height of the virtual expression stack. 116 // The height of the virtual expression stack.
129 int height() { 117 inline int height();
130 return element_count() - expression_base_index();
131 }
132 118
133 bool is_used(int num) { 119 bool is_used(int num) {
134 switch (num) { 120 switch (num) {
135 case 0: { // r0. 121 case 0: { // r0.
136 return kR0InUse[top_of_stack_state_]; 122 return kR0InUse[top_of_stack_state_];
137 } 123 }
138 case 1: { // r1. 124 case 1: { // r1.
139 return kR1InUse[top_of_stack_state_]; 125 return kR1InUse[top_of_stack_state_];
140 } 126 }
141 case 2: 127 case 2:
(...skipping 11 matching lines...) Expand all
153 } 139 }
154 } 140 }
155 default: { 141 default: {
156 ASSERT(num < kFirstAllocatedRegister || 142 ASSERT(num < kFirstAllocatedRegister ||
157 num >= kFirstAllocatedRegister + kNumberOfAllocatedRegisters); 143 num >= kFirstAllocatedRegister + kNumberOfAllocatedRegisters);
158 return false; 144 return false;
159 } 145 }
160 } 146 }
161 } 147 }
162 148
163 bool is_used(Register reg) {
164 return is_used(RegisterAllocator::ToNumber(reg));
165 }
166
167 // Add extra in-memory elements to the top of the frame to match an actual 149 // Add extra in-memory elements to the top of the frame to match an actual
168 // frame (eg, the frame after an exception handler is pushed). No code is 150 // frame (eg, the frame after an exception handler is pushed). No code is
169 // emitted. 151 // emitted.
170 void Adjust(int count); 152 void Adjust(int count);
171 153
172 // Forget elements from the top of the frame to match an actual frame (eg, 154 // Forget elements from the top of the frame to match an actual frame (eg,
173 // the frame after a runtime call). No code is emitted except to bring the 155 // the frame after a runtime call). No code is emitted except to bring the
174 // frame to a spilled state. 156 // frame to a spilled state.
175 void Forget(int count) { 157 void Forget(int count) {
176 SpillAll(); 158 SpillAll();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return MemOperand(sp, 0); 227 return MemOperand(sp, 0);
246 } 228 }
247 229
248 // An element of the expression stack as an assembly operand. 230 // An element of the expression stack as an assembly operand.
249 MemOperand ElementAt(int index) { 231 MemOperand ElementAt(int index) {
250 AssertIsSpilled(); 232 AssertIsSpilled();
251 return MemOperand(sp, index * kPointerSize); 233 return MemOperand(sp, index * kPointerSize);
252 } 234 }
253 235
254 // A frame-allocated local as an assembly operand. 236 // A frame-allocated local as an assembly operand.
255 MemOperand LocalAt(int index) { 237 inline MemOperand LocalAt(int index);
256 ASSERT(0 <= index);
257 ASSERT(index < local_count());
258 return MemOperand(fp, kLocal0Offset - index * kPointerSize);
259 }
260 238
261 // Push the address of the receiver slot on the frame. 239 // Push the address of the receiver slot on the frame.
262 void PushReceiverSlotAddress(); 240 void PushReceiverSlotAddress();
263 241
264 // The function frame slot. 242 // The function frame slot.
265 MemOperand Function() { return MemOperand(fp, kFunctionOffset); } 243 MemOperand Function() { return MemOperand(fp, kFunctionOffset); }
266 244
267 // The context frame slot. 245 // The context frame slot.
268 MemOperand Context() { return MemOperand(fp, kContextOffset); } 246 MemOperand Context() { return MemOperand(fp, kContextOffset); }
269 247
270 // A parameter as an assembly operand. 248 // A parameter as an assembly operand.
271 MemOperand ParameterAt(int index) { 249 inline MemOperand ParameterAt(int index);
272 // Index -1 corresponds to the receiver.
273 ASSERT(-1 <= index); // -1 is the receiver.
274 ASSERT(index <= parameter_count());
275 return MemOperand(fp, (1 + parameter_count() - index) * kPointerSize);
276 }
277 250
278 // The receiver frame slot. 251 // The receiver frame slot.
279 MemOperand Receiver() { return ParameterAt(-1); } 252 inline MemOperand Receiver();
280 253
281 // Push a try-catch or try-finally handler on top of the virtual frame. 254 // Push a try-catch or try-finally handler on top of the virtual frame.
282 void PushTryHandler(HandlerType type); 255 void PushTryHandler(HandlerType type);
283 256
284 // Call stub given the number of arguments it expects on (and 257 // Call stub given the number of arguments it expects on (and
285 // removes from) the stack. 258 // removes from) the stack.
286 void CallStub(CodeStub* stub, int arg_count) { 259 inline void CallStub(CodeStub* stub, int arg_count);
287 if (arg_count != 0) Forget(arg_count);
288 ASSERT(cgen()->HasValidEntryRegisters());
289 masm()->CallStub(stub);
290 }
291 260
292 // Call JS function from top of the stack with arguments 261 // Call JS function from top of the stack with arguments
293 // taken from the stack. 262 // taken from the stack.
294 void CallJSFunction(int arg_count); 263 void CallJSFunction(int arg_count);
295 264
296 // Call runtime given the number of arguments expected on (and 265 // Call runtime given the number of arguments expected on (and
297 // removed from) the stack. 266 // removed from) the stack.
298 void CallRuntime(Runtime::Function* f, int arg_count); 267 void CallRuntime(Runtime::Function* f, int arg_count);
299 void CallRuntime(Runtime::FunctionId id, int arg_count); 268 void CallRuntime(Runtime::FunctionId id, int arg_count);
300 269
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 int element_count_; 408 int element_count_;
440 TopOfStack top_of_stack_state_:3; 409 TopOfStack top_of_stack_state_:3;
441 int register_allocation_map_:kNumberOfAllocatedRegisters; 410 int register_allocation_map_:kNumberOfAllocatedRegisters;
442 411
443 // The index of the element that is at the processor's stack pointer 412 // The index of the element that is at the processor's stack pointer
444 // (the sp register). For now since everything is in memory it is given 413 // (the sp register). For now since everything is in memory it is given
445 // by the number of elements on the not-very-virtual stack frame. 414 // by the number of elements on the not-very-virtual stack frame.
446 int stack_pointer() { return element_count_ - 1; } 415 int stack_pointer() { return element_count_ - 1; }
447 416
448 // The number of frame-allocated locals and parameters respectively. 417 // The number of frame-allocated locals and parameters respectively.
449 int parameter_count() { return cgen()->scope()->num_parameters(); } 418 inline int parameter_count();
450 int local_count() { return cgen()->scope()->num_stack_slots(); } 419 inline int local_count();
451 420
452 // The index of the element that is at the processor's frame pointer 421 // The index of the element that is at the processor's frame pointer
453 // (the fp register). The parameters, receiver, function, and context 422 // (the fp register). The parameters, receiver, function, and context
454 // are below the frame pointer. 423 // are below the frame pointer.
455 int frame_pointer() { return parameter_count() + 3; } 424 inline int frame_pointer();
456 425
457 // The index of the first parameter. The receiver lies below the first 426 // The index of the first parameter. The receiver lies below the first
458 // parameter. 427 // parameter.
459 int param0_index() { return 1; } 428 int param0_index() { return 1; }
460 429
461 // The index of the context slot in the frame. It is immediately 430 // The index of the context slot in the frame. It is immediately
462 // below the frame pointer. 431 // below the frame pointer.
463 int context_index() { return frame_pointer() - 1; } 432 inline int context_index();
464 433
465 // The index of the function slot in the frame. It is below the frame 434 // The index of the function slot in the frame. It is below the frame
466 // pointer and context slot. 435 // pointer and context slot.
467 int function_index() { return frame_pointer() - 2; } 436 inline int function_index();
468 437
469 // The index of the first local. Between the frame pointer and the 438 // The index of the first local. Between the frame pointer and the
470 // locals lies the return address. 439 // locals lies the return address.
471 int local0_index() { return frame_pointer() + 2; } 440 inline int local0_index();
472 441
473 // The index of the base of the expression stack. 442 // The index of the base of the expression stack.
474 int expression_base_index() { return local0_index() + local_count(); } 443 inline int expression_base_index();
475 444
476 // Convert a frame index into a frame pointer relative offset into the 445 // Convert a frame index into a frame pointer relative offset into the
477 // actual stack. 446 // actual stack.
478 int fp_relative(int index) { 447 inline int fp_relative(int index);
479 ASSERT(index < element_count());
480 ASSERT(frame_pointer() < element_count()); // FP is on the frame.
481 return (frame_pointer() - index) * kPointerSize;
482 }
483 448
484 // Spill all elements in registers. Spill the top spilled_args elements 449 // Spill all elements in registers. Spill the top spilled_args elements
485 // on the frame. Sync all other frame elements. 450 // on the frame. Sync all other frame elements.
486 // Then drop dropped_args elements from the virtual frame, to match 451 // Then drop dropped_args elements from the virtual frame, to match
487 // the effect of an upcoming call that will drop them from the stack. 452 // the effect of an upcoming call that will drop them from the stack.
488 void PrepareForCall(int spilled_args, int dropped_args); 453 void PrepareForCall(int spilled_args, int dropped_args);
489 454
490 // If all top-of-stack registers are in use then the lowest one is pushed 455 // If all top-of-stack registers are in use then the lowest one is pushed
491 // onto the physical stack and made free. 456 // onto the physical stack and made free.
492 void EnsureOneFreeTOSRegister(); 457 void EnsureOneFreeTOSRegister();
493 458
494 inline bool Equals(VirtualFrame* other); 459 inline bool Equals(VirtualFrame* other);
495 460
496 friend class JumpTarget; 461 friend class JumpTarget;
497 friend class DeferredCode; 462 //friend class DeferredCode;
Søren Thygesen Gjesse 2010/05/06 07:48:11 Friend in comment.
498 }; 463 };
499 464
500 465
501 } } // namespace v8::internal 466 } } // namespace v8::internal
502 467
503 #endif // V8_ARM_VIRTUAL_FRAME_ARM_H_ 468 #endif // V8_ARM_VIRTUAL_FRAME_ARM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698