| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 // Construct an initial virtual frame on entry to a JS function. | 61 // Construct an initial virtual frame on entry to a JS function. |
| 62 inline VirtualFrame(); | 62 inline VirtualFrame(); |
| 63 | 63 |
| 64 // Construct a virtual frame as a clone of an existing one. | 64 // Construct a virtual frame as a clone of an existing one. |
| 65 explicit inline VirtualFrame(VirtualFrame* original); | 65 explicit inline VirtualFrame(VirtualFrame* original); |
| 66 | 66 |
| 67 CodeGenerator* cgen() { return CodeGeneratorScope::Current(); } | 67 CodeGenerator* cgen() { return CodeGeneratorScope::Current(); } |
| 68 MacroAssembler* masm() { return cgen()->masm(); } | 68 MacroAssembler* masm() { return cgen()->masm(); } |
| 69 | 69 |
| 70 // Create a duplicate of an existing valid frame element. | |
| 71 FrameElement CopyElementAt(int index, | |
| 72 NumberInfo info = NumberInfo::Unknown()); | |
| 73 | |
| 74 // The number of elements on the virtual frame. | 70 // The number of elements on the virtual frame. |
| 75 int element_count() { return elements_.length(); } | 71 int element_count() { return element_count_; } |
| 76 | 72 |
| 77 // The height of the virtual expression stack. | 73 // The height of the virtual expression stack. |
| 78 int height() { | 74 int height() { |
| 79 return element_count() - expression_base_index(); | 75 return element_count() - expression_base_index(); |
| 80 } | 76 } |
| 81 | 77 |
| 82 int register_location(int num) { | 78 int register_location(int num) { |
| 83 ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters); | 79 ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters); |
| 84 return register_locations_[num]; | 80 return register_locations_[num]; |
| 85 } | 81 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 108 void Adjust(int count); | 104 void Adjust(int count); |
| 109 | 105 |
| 110 // Forget elements from the top of the frame to match an actual frame (eg, | 106 // Forget elements from the top of the frame to match an actual frame (eg, |
| 111 // the frame after a runtime call). No code is emitted. | 107 // the frame after a runtime call). No code is emitted. |
| 112 void Forget(int count) { | 108 void Forget(int count) { |
| 113 ASSERT(count >= 0); | 109 ASSERT(count >= 0); |
| 114 ASSERT(stack_pointer_ == element_count() - 1); | 110 ASSERT(stack_pointer_ == element_count() - 1); |
| 115 stack_pointer_ -= count; | 111 stack_pointer_ -= count; |
| 116 // On ARM, all elements are in memory, so there is no extra bookkeeping | 112 // On ARM, all elements are in memory, so there is no extra bookkeeping |
| 117 // (registers, copies, etc.) beyond dropping the elements. | 113 // (registers, copies, etc.) beyond dropping the elements. |
| 118 elements_.Rewind(stack_pointer_ + 1); | 114 element_count_ -= count; |
| 119 } | 115 } |
| 120 | 116 |
| 121 // Forget count elements from the top of the frame and adjust the stack | 117 // Forget count elements from the top of the frame and adjust the stack |
| 122 // pointer downward. This is used, for example, before merging frames at | 118 // pointer downward. This is used, for example, before merging frames at |
| 123 // break, continue, and return targets. | 119 // break, continue, and return targets. |
| 124 void ForgetElements(int count); | 120 void ForgetElements(int count); |
| 125 | 121 |
| 126 // Spill all values from the frame to memory. | 122 // Spill all values from the frame to memory. |
| 127 void SpillAll(); | 123 inline void SpillAll(); |
| 128 | 124 |
| 129 // Spill all occurrences of a specific register from the frame. | 125 // Spill all occurrences of a specific register from the frame. |
| 130 void Spill(Register reg) { | 126 void Spill(Register reg) { |
| 131 if (is_used(reg)) SpillElementAt(register_location(reg)); | 127 if (is_used(reg)) SpillElementAt(register_location(reg)); |
| 132 } | 128 } |
| 133 | 129 |
| 134 // Spill all occurrences of an arbitrary register if possible. Return the | 130 // Spill all occurrences of an arbitrary register if possible. Return the |
| 135 // register spilled or no_reg if it was not possible to free any register | 131 // register spilled or no_reg if it was not possible to free any register |
| 136 // (ie, they all have frame-external references). | 132 // (ie, they all have frame-external references). |
| 137 Register SpillAnyRegister(); | 133 Register SpillAnyRegister(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // calling Enter, the virtual frame is ready for use; and after calling | 168 // calling Enter, the virtual frame is ready for use; and after calling |
| 173 // Exit it should not be used. Note that Enter does not allocate space in | 169 // Exit it should not be used. Note that Enter does not allocate space in |
| 174 // the physical frame for storing frame-allocated locals. | 170 // the physical frame for storing frame-allocated locals. |
| 175 void Enter(); | 171 void Enter(); |
| 176 void Exit(); | 172 void Exit(); |
| 177 | 173 |
| 178 // Prepare for returning from the frame by spilling locals and | 174 // Prepare for returning from the frame by spilling locals and |
| 179 // dropping all non-locals elements in the virtual frame. This | 175 // dropping all non-locals elements in the virtual frame. This |
| 180 // avoids generating unnecessary merge code when jumping to the | 176 // avoids generating unnecessary merge code when jumping to the |
| 181 // shared return site. Emits code for spills. | 177 // shared return site. Emits code for spills. |
| 182 void PrepareForReturn(); | 178 inline void PrepareForReturn(); |
| 183 | 179 |
| 184 // Number of local variables after when we use a loop for allocating. | 180 // Number of local variables after when we use a loop for allocating. |
| 185 static const int kLocalVarBound = 5; | 181 static const int kLocalVarBound = 5; |
| 186 | 182 |
| 187 // Allocate and initialize the frame-allocated locals. | 183 // Allocate and initialize the frame-allocated locals. |
| 188 void AllocateStackSlots(); | 184 void AllocateStackSlots(); |
| 189 | 185 |
| 190 // The current top of the expression stack as an assembly operand. | 186 // The current top of the expression stack as an assembly operand. |
| 191 MemOperand Top() { return MemOperand(sp, 0); } | 187 MemOperand Top() { return MemOperand(sp, 0); } |
| 192 | 188 |
| 193 // An element of the expression stack as an assembly operand. | 189 // An element of the expression stack as an assembly operand. |
| 194 MemOperand ElementAt(int index) { | 190 MemOperand ElementAt(int index) { |
| 195 return MemOperand(sp, index * kPointerSize); | 191 return MemOperand(sp, index * kPointerSize); |
| 196 } | 192 } |
| 197 | 193 |
| 198 // Random-access store to a frame-top relative frame element. The result | 194 // Random-access store to a frame-top relative frame element. The result |
| 199 // becomes owned by the frame and is invalidated. | 195 // becomes owned by the frame and is invalidated. |
| 200 void SetElementAt(int index, Result* value); | 196 void SetElementAt(int index, Result* value); |
| 201 | 197 |
| 202 // Set a frame element to a constant. The index is frame-top relative. | 198 // Set a frame element to a constant. The index is frame-top relative. |
| 203 void SetElementAt(int index, Handle<Object> value) { | 199 void SetElementAt(int index, Handle<Object> value) { |
| 204 Result temp(value); | 200 Result temp(value); |
| 205 SetElementAt(index, &temp); | 201 SetElementAt(index, &temp); |
| 206 } | 202 } |
| 207 | 203 |
| 208 void PushElementAt(int index) { | |
| 209 PushFrameSlotAt(element_count() - index - 1); | |
| 210 } | |
| 211 | |
| 212 // A frame-allocated local as an assembly operand. | 204 // A frame-allocated local as an assembly operand. |
| 213 MemOperand LocalAt(int index) { | 205 MemOperand LocalAt(int index) { |
| 214 ASSERT(0 <= index); | 206 ASSERT(0 <= index); |
| 215 ASSERT(index < local_count()); | 207 ASSERT(index < local_count()); |
| 216 return MemOperand(fp, kLocal0Offset - index * kPointerSize); | 208 return MemOperand(fp, kLocal0Offset - index * kPointerSize); |
| 217 } | 209 } |
| 218 | 210 |
| 219 // Push a copy of the value of a local frame slot on top of the frame. | |
| 220 void PushLocalAt(int index) { | |
| 221 PushFrameSlotAt(local0_index() + index); | |
| 222 } | |
| 223 | |
| 224 // Push the value of a local frame slot on top of the frame and invalidate | 211 // Push the value of a local frame slot on top of the frame and invalidate |
| 225 // the local slot. The slot should be written to before trying to read | 212 // the local slot. The slot should be written to before trying to read |
| 226 // from it again. | 213 // from it again. |
| 227 void TakeLocalAt(int index) { | 214 void TakeLocalAt(int index) { |
| 228 TakeFrameSlotAt(local0_index() + index); | 215 TakeFrameSlotAt(local0_index() + index); |
| 229 } | 216 } |
| 230 | 217 |
| 231 // Store the top value on the virtual frame into a local frame slot. The | |
| 232 // value is left in place on top of the frame. | |
| 233 void StoreToLocalAt(int index) { | |
| 234 StoreToFrameSlotAt(local0_index() + index); | |
| 235 } | |
| 236 | |
| 237 // Push the address of the receiver slot on the frame. | 218 // Push the address of the receiver slot on the frame. |
| 238 void PushReceiverSlotAddress(); | 219 void PushReceiverSlotAddress(); |
| 239 | 220 |
| 240 // The function frame slot. | 221 // The function frame slot. |
| 241 MemOperand Function() { return MemOperand(fp, kFunctionOffset); } | 222 MemOperand Function() { return MemOperand(fp, kFunctionOffset); } |
| 242 | 223 |
| 243 // Push the function on top of the frame. | |
| 244 void PushFunction() { PushFrameSlotAt(function_index()); } | |
| 245 | |
| 246 // The context frame slot. | 224 // The context frame slot. |
| 247 MemOperand Context() { return MemOperand(fp, kContextOffset); } | 225 MemOperand Context() { return MemOperand(fp, kContextOffset); } |
| 248 | 226 |
| 249 // Save the value of the esi register to the context frame slot. | 227 // Save the value of the esi register to the context frame slot. |
| 250 void SaveContextRegister(); | 228 void SaveContextRegister(); |
| 251 | 229 |
| 252 // Restore the esi register from the value of the context frame | 230 // Restore the esi register from the value of the context frame |
| 253 // slot. | 231 // slot. |
| 254 void RestoreContextRegister(); | 232 void RestoreContextRegister(); |
| 255 | 233 |
| 256 // A parameter as an assembly operand. | 234 // A parameter as an assembly operand. |
| 257 MemOperand ParameterAt(int index) { | 235 MemOperand ParameterAt(int index) { |
| 258 // Index -1 corresponds to the receiver. | 236 // Index -1 corresponds to the receiver. |
| 259 ASSERT(-1 <= index); // -1 is the receiver. | 237 ASSERT(-1 <= index); // -1 is the receiver. |
| 260 ASSERT(index <= parameter_count()); | 238 ASSERT(index <= parameter_count()); |
| 261 return MemOperand(fp, (1 + parameter_count() - index) * kPointerSize); | 239 return MemOperand(fp, (1 + parameter_count() - index) * kPointerSize); |
| 262 } | 240 } |
| 263 | 241 |
| 264 // Push a copy of the value of a parameter frame slot on top of the frame. | |
| 265 void PushParameterAt(int index) { | |
| 266 PushFrameSlotAt(param0_index() + index); | |
| 267 } | |
| 268 | |
| 269 // Push the value of a paramter frame slot on top of the frame and | 242 // Push the value of a paramter frame slot on top of the frame and |
| 270 // invalidate the parameter slot. The slot should be written to before | 243 // invalidate the parameter slot. The slot should be written to before |
| 271 // trying to read from it again. | 244 // trying to read from it again. |
| 272 void TakeParameterAt(int index) { | 245 void TakeParameterAt(int index) { |
| 273 TakeFrameSlotAt(param0_index() + index); | 246 TakeFrameSlotAt(param0_index() + index); |
| 274 } | 247 } |
| 275 | 248 |
| 276 // Store the top value on the virtual frame into a parameter frame slot. | 249 // Store the top value on the virtual frame into a parameter frame slot. |
| 277 // The value is left in place on top of the frame. | 250 // The value is left in place on top of the frame. |
| 278 void StoreToParameterAt(int index) { | 251 void StoreToParameterAt(int index) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 int dropped_args); | 289 int dropped_args); |
| 317 | 290 |
| 318 // Drop a number of elements from the top of the expression stack. May | 291 // Drop a number of elements from the top of the expression stack. May |
| 319 // emit code to affect the physical frame. Does not clobber any registers | 292 // emit code to affect the physical frame. Does not clobber any registers |
| 320 // excepting possibly the stack pointer. | 293 // excepting possibly the stack pointer. |
| 321 void Drop(int count); | 294 void Drop(int count); |
| 322 | 295 |
| 323 // Drop one element. | 296 // Drop one element. |
| 324 void Drop() { Drop(1); } | 297 void Drop() { Drop(1); } |
| 325 | 298 |
| 326 // Duplicate the top element of the frame. | |
| 327 void Dup() { PushFrameSlotAt(element_count() - 1); } | |
| 328 | |
| 329 // Pop an element from the top of the expression stack. Returns a | 299 // Pop an element from the top of the expression stack. Returns a |
| 330 // Result, which may be a constant or a register. | 300 // Result, which may be a constant or a register. |
| 331 Result Pop(); | 301 Result Pop(); |
| 332 | 302 |
| 333 // Pop and save an element from the top of the expression stack and | 303 // Pop and save an element from the top of the expression stack and |
| 334 // emit a corresponding pop instruction. | 304 // emit a corresponding pop instruction. |
| 335 void EmitPop(Register reg); | 305 void EmitPop(Register reg); |
| 336 | 306 |
| 337 // Push an element on top of the expression stack and emit a | 307 // Push an element on top of the expression stack and emit a |
| 338 // corresponding push instruction. | 308 // corresponding push instruction. |
| 339 void EmitPush(Register reg); | 309 void EmitPush(Register reg); |
| 340 | 310 |
| 341 // Push multiple registers on the stack and the virtual frame | 311 // Push multiple registers on the stack and the virtual frame |
| 342 // Register are selected by setting bit in src_regs and | 312 // Register are selected by setting bit in src_regs and |
| 343 // are pushed in decreasing order: r15 .. r0. | 313 // are pushed in decreasing order: r15 .. r0. |
| 344 void EmitPushMultiple(int count, int src_regs); | 314 void EmitPushMultiple(int count, int src_regs); |
| 345 | 315 |
| 346 // Push an element on the virtual frame. | 316 // Push an element on the virtual frame. |
| 347 inline void Push(Register reg, NumberInfo info = NumberInfo::Unknown()); | |
| 348 inline void Push(Handle<Object> value); | 317 inline void Push(Handle<Object> value); |
| 349 inline void Push(Smi* value); | 318 inline void Push(Smi* value); |
| 350 | 319 |
| 351 // Pushing a result invalidates it (its contents become owned by the frame). | |
| 352 void Push(Result* result) { | |
| 353 if (result->is_register()) { | |
| 354 Push(result->reg()); | |
| 355 } else { | |
| 356 ASSERT(result->is_constant()); | |
| 357 Push(result->handle()); | |
| 358 } | |
| 359 result->Unuse(); | |
| 360 } | |
| 361 | |
| 362 // Nip removes zero or more elements from immediately below the top | 320 // Nip removes zero or more elements from immediately below the top |
| 363 // of the frame, leaving the previous top-of-frame value on top of | 321 // of the frame, leaving the previous top-of-frame value on top of |
| 364 // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x). | 322 // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x). |
| 365 inline void Nip(int num_dropped); | 323 inline void Nip(int num_dropped); |
| 366 | 324 |
| 367 inline void SetTypeForLocalAt(int index, NumberInfo info); | 325 inline void SetTypeForLocalAt(int index, NumberInfo info); |
| 368 inline void SetTypeForParamAt(int index, NumberInfo info); | 326 inline void SetTypeForParamAt(int index, NumberInfo info); |
| 369 | 327 |
| 370 private: | 328 private: |
| 371 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; | 329 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
| 372 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; | 330 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; |
| 373 static const int kContextOffset = StandardFrameConstants::kContextOffset; | 331 static const int kContextOffset = StandardFrameConstants::kContextOffset; |
| 374 | 332 |
| 375 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; | 333 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; |
| 376 static const int kPreallocatedElements = 5 + 8; // 8 expression stack slots. | 334 static const int kPreallocatedElements = 5 + 8; // 8 expression stack slots. |
| 377 | 335 |
| 378 ZoneList<FrameElement> elements_; | 336 int element_count_; |
| 379 | 337 |
| 380 // The index of the element that is at the processor's stack pointer | 338 // The index of the element that is at the processor's stack pointer |
| 381 // (the sp register). | 339 // (the sp register). |
| 382 int stack_pointer_; | 340 int stack_pointer_; |
| 383 | 341 |
| 384 // The index of the register frame element using each register, or | 342 // The index of the register frame element using each register, or |
| 385 // kIllegalIndex if a register is not on the frame. | 343 // kIllegalIndex if a register is not on the frame. |
| 386 int register_locations_[RegisterAllocator::kNumRegisters]; | 344 int register_locations_[RegisterAllocator::kNumRegisters]; |
| 387 | 345 |
| 388 // The number of frame-allocated locals and parameters respectively. | 346 // The number of frame-allocated locals and parameters respectively. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 409 |
| 452 // Sync the range of elements in [begin, end] with memory. | 410 // Sync the range of elements in [begin, end] with memory. |
| 453 void SyncRange(int begin, int end); | 411 void SyncRange(int begin, int end); |
| 454 | 412 |
| 455 // Sync a single unsynced element that lies beneath or at the stack pointer. | 413 // Sync a single unsynced element that lies beneath or at the stack pointer. |
| 456 void SyncElementBelowStackPointer(int index); | 414 void SyncElementBelowStackPointer(int index); |
| 457 | 415 |
| 458 // Sync a single unsynced element that lies just above the stack pointer. | 416 // Sync a single unsynced element that lies just above the stack pointer. |
| 459 void SyncElementByPushing(int index); | 417 void SyncElementByPushing(int index); |
| 460 | 418 |
| 461 // Push a copy of a frame slot (typically a local or parameter) on top of | |
| 462 // the frame. | |
| 463 inline void PushFrameSlotAt(int index); | |
| 464 | |
| 465 // Push a the value of a frame slot (typically a local or parameter) on | 419 // Push a the value of a frame slot (typically a local or parameter) on |
| 466 // top of the frame and invalidate the slot. | 420 // top of the frame and invalidate the slot. |
| 467 void TakeFrameSlotAt(int index); | 421 void TakeFrameSlotAt(int index); |
| 468 | 422 |
| 469 // Store the value on top of the frame to a frame slot (typically a local | 423 // Store the value on top of the frame to a frame slot (typically a local |
| 470 // or parameter). | 424 // or parameter). |
| 471 void StoreToFrameSlotAt(int index); | 425 void StoreToFrameSlotAt(int index); |
| 472 | 426 |
| 473 // Spill all elements in registers. Spill the top spilled_args elements | 427 // Spill all elements in registers. Spill the top spilled_args elements |
| 474 // on the frame. Sync all other frame elements. | 428 // on the frame. Sync all other frame elements. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 498 | 452 |
| 499 // Invalidates a frame slot (puts an invalid frame element in it). | 453 // Invalidates a frame slot (puts an invalid frame element in it). |
| 500 // Copies on the frame are correctly handled, and if this slot was | 454 // Copies on the frame are correctly handled, and if this slot was |
| 501 // the backing store of copies, the index of the new backing store | 455 // the backing store of copies, the index of the new backing store |
| 502 // is returned. Otherwise, returns kIllegalIndex. | 456 // is returned. Otherwise, returns kIllegalIndex. |
| 503 // Register counts are correctly updated. | 457 // Register counts are correctly updated. |
| 504 int InvalidateFrameSlotAt(int index); | 458 int InvalidateFrameSlotAt(int index); |
| 505 | 459 |
| 506 inline bool Equals(VirtualFrame* other); | 460 inline bool Equals(VirtualFrame* other); |
| 507 | 461 |
| 508 // Classes that need raw access to the elements_ array. | 462 friend class JumpTarget; |
| 509 friend class DeferredCode; | 463 friend class DeferredCode; |
| 510 friend class JumpTarget; | |
| 511 }; | 464 }; |
| 512 | 465 |
| 513 | 466 |
| 514 } } // namespace v8::internal | 467 } } // namespace v8::internal |
| 515 | 468 |
| 516 #endif // V8_ARM_VIRTUAL_FRAME_ARM_H_ | 469 #endif // V8_ARM_VIRTUAL_FRAME_ARM_H_ |
| OLD | NEW |