| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 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_IA32_VIRTUAL_FRAME_IA32_H_ | |
| 29 #define V8_IA32_VIRTUAL_FRAME_IA32_H_ | |
| 30 | |
| 31 #include "codegen.h" | |
| 32 #include "register-allocator.h" | |
| 33 #include "scopes.h" | |
| 34 #include "type-info.h" | |
| 35 | |
| 36 namespace v8 { | |
| 37 namespace internal { | |
| 38 | |
| 39 // ------------------------------------------------------------------------- | |
| 40 // Virtual frames | |
| 41 // | |
| 42 // The virtual frame is an abstraction of the physical stack frame. It | |
| 43 // encapsulates the parameters, frame-allocated locals, and the expression | |
| 44 // stack. It supports push/pop operations on the expression stack, as well | |
| 45 // as random access to the expression stack elements, locals, and | |
| 46 // parameters. | |
| 47 | |
| 48 class VirtualFrame: public ZoneObject { | |
| 49 public: | |
| 50 // A utility class to introduce a scope where the virtual frame is | |
| 51 // expected to remain spilled. The constructor spills the code | |
| 52 // generator's current frame, but no attempt is made to require it | |
| 53 // to stay spilled. It is intended as documentation while the code | |
| 54 // generator is being transformed. | |
| 55 class SpilledScope BASE_EMBEDDED { | |
| 56 public: | |
| 57 SpilledScope() : previous_state_(cgen()->in_spilled_code()) { | |
| 58 ASSERT(cgen()->has_valid_frame()); | |
| 59 cgen()->frame()->SpillAll(); | |
| 60 cgen()->set_in_spilled_code(true); | |
| 61 } | |
| 62 | |
| 63 ~SpilledScope() { | |
| 64 cgen()->set_in_spilled_code(previous_state_); | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 bool previous_state_; | |
| 69 | |
| 70 CodeGenerator* cgen() { | |
| 71 return CodeGeneratorScope::Current(Isolate::Current()); | |
| 72 } | |
| 73 }; | |
| 74 | |
| 75 // An illegal index into the virtual frame. | |
| 76 static const int kIllegalIndex = -1; | |
| 77 | |
| 78 // Construct an initial virtual frame on entry to a JS function. | |
| 79 inline VirtualFrame(); | |
| 80 | |
| 81 // Construct a virtual frame as a clone of an existing one. | |
| 82 explicit inline VirtualFrame(VirtualFrame* original); | |
| 83 | |
| 84 CodeGenerator* cgen() { | |
| 85 return CodeGeneratorScope::Current(Isolate::Current()); | |
| 86 } | |
| 87 | |
| 88 MacroAssembler* masm() { return cgen()->masm(); } | |
| 89 | |
| 90 // Create a duplicate of an existing valid frame element. | |
| 91 FrameElement CopyElementAt(int index, | |
| 92 TypeInfo info = TypeInfo::Uninitialized()); | |
| 93 | |
| 94 // The number of elements on the virtual frame. | |
| 95 int element_count() { return elements_.length(); } | |
| 96 | |
| 97 // The height of the virtual expression stack. | |
| 98 int height() { return element_count() - expression_base_index(); } | |
| 99 | |
| 100 int register_location(int num) { | |
| 101 ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters); | |
| 102 return register_locations_[num]; | |
| 103 } | |
| 104 | |
| 105 inline int register_location(Register reg); | |
| 106 | |
| 107 inline void set_register_location(Register reg, int index); | |
| 108 | |
| 109 bool is_used(int num) { | |
| 110 ASSERT(num >= 0 && num < RegisterAllocator::kNumRegisters); | |
| 111 return register_locations_[num] != kIllegalIndex; | |
| 112 } | |
| 113 | |
| 114 inline bool is_used(Register reg); | |
| 115 | |
| 116 // Add extra in-memory elements to the top of the frame to match an actual | |
| 117 // frame (eg, the frame after an exception handler is pushed). No code is | |
| 118 // emitted. | |
| 119 void Adjust(int count); | |
| 120 | |
| 121 // Forget count elements from the top of the frame all in-memory | |
| 122 // (including synced) and adjust the stack pointer downward, to | |
| 123 // match an external frame effect (examples include a call removing | |
| 124 // its arguments, and exiting a try/catch removing an exception | |
| 125 // handler). No code will be emitted. | |
| 126 void Forget(int count) { | |
| 127 ASSERT(count >= 0); | |
| 128 ASSERT(stack_pointer_ == element_count() - 1); | |
| 129 stack_pointer_ -= count; | |
| 130 ForgetElements(count); | |
| 131 } | |
| 132 | |
| 133 // Forget count elements from the top of the frame without adjusting | |
| 134 // the stack pointer downward. This is used, for example, before | |
| 135 // merging frames at break, continue, and return targets. | |
| 136 void ForgetElements(int count); | |
| 137 | |
| 138 // Spill all values from the frame to memory. | |
| 139 inline void SpillAll(); | |
| 140 | |
| 141 // Spill all occurrences of a specific register from the frame. | |
| 142 void Spill(Register reg) { | |
| 143 if (is_used(reg)) SpillElementAt(register_location(reg)); | |
| 144 } | |
| 145 | |
| 146 // Make the two registers distinct and spill them. Returns the second | |
| 147 // register. If the registers were not distinct then it returns the new | |
| 148 // second register. | |
| 149 Result MakeDistinctAndSpilled(Result* left, Result* right) { | |
| 150 Spill(left->reg()); | |
| 151 Spill(right->reg()); | |
| 152 if (left->reg().is(right->reg())) { | |
| 153 RegisterAllocator* allocator = cgen()->allocator(); | |
| 154 Result fresh = allocator->Allocate(); | |
| 155 ASSERT(fresh.is_valid()); | |
| 156 masm()->mov(fresh.reg(), right->reg()); | |
| 157 return fresh; | |
| 158 } | |
| 159 return *right; | |
| 160 } | |
| 161 | |
| 162 // Spill all occurrences of an arbitrary register if possible. Return the | |
| 163 // register spilled or no_reg if it was not possible to free any register | |
| 164 // (ie, they all have frame-external references). | |
| 165 Register SpillAnyRegister(); | |
| 166 | |
| 167 // Spill the top element of the frame. | |
| 168 void SpillTop() { SpillElementAt(element_count() - 1); } | |
| 169 | |
| 170 // Sync the range of elements in [begin, end] with memory. | |
| 171 void SyncRange(int begin, int end); | |
| 172 | |
| 173 // Make this frame so that an arbitrary frame of the same height can | |
| 174 // be merged to it. Copies and constants are removed from the frame. | |
| 175 void MakeMergable(); | |
| 176 | |
| 177 // Prepare this virtual frame for merging to an expected frame by | |
| 178 // performing some state changes that do not require generating | |
| 179 // code. It is guaranteed that no code will be generated. | |
| 180 void PrepareMergeTo(VirtualFrame* expected); | |
| 181 | |
| 182 // Make this virtual frame have a state identical to an expected virtual | |
| 183 // frame. As a side effect, code may be emitted to make this frame match | |
| 184 // the expected one. | |
| 185 void MergeTo(VirtualFrame* expected); | |
| 186 | |
| 187 // Detach a frame from its code generator, perhaps temporarily. This | |
| 188 // tells the register allocator that it is free to use frame-internal | |
| 189 // registers. Used when the code generator's frame is switched from this | |
| 190 // one to NULL by an unconditional jump. | |
| 191 void DetachFromCodeGenerator() { | |
| 192 RegisterAllocator* cgen_allocator = cgen()->allocator(); | |
| 193 for (int i = 0; i < RegisterAllocator::kNumRegisters; i++) { | |
| 194 if (is_used(i)) cgen_allocator->Unuse(i); | |
| 195 } | |
| 196 } | |
| 197 | |
| 198 // (Re)attach a frame to its code generator. This informs the register | |
| 199 // allocator that the frame-internal register references are active again. | |
| 200 // Used when a code generator's frame is switched from NULL to this one by | |
| 201 // binding a label. | |
| 202 void AttachToCodeGenerator() { | |
| 203 RegisterAllocator* cgen_allocator = cgen()->allocator(); | |
| 204 for (int i = 0; i < RegisterAllocator::kNumRegisters; i++) { | |
| 205 if (is_used(i)) cgen_allocator->Use(i); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 // Emit code for the physical JS entry and exit frame sequences. After | |
| 210 // calling Enter, the virtual frame is ready for use; and after calling | |
| 211 // Exit it should not be used. Note that Enter does not allocate space in | |
| 212 // the physical frame for storing frame-allocated locals. | |
| 213 void Enter(); | |
| 214 void Exit(); | |
| 215 | |
| 216 // Prepare for returning from the frame by spilling locals. This | |
| 217 // avoids generating unnecessary merge code when jumping to the | |
| 218 // shared return site. Emits code for spills. | |
| 219 inline void PrepareForReturn(); | |
| 220 | |
| 221 // Number of local variables after when we use a loop for allocating. | |
| 222 static const int kLocalVarBound = 10; | |
| 223 | |
| 224 // Allocate and initialize the frame-allocated locals. | |
| 225 void AllocateStackSlots(); | |
| 226 | |
| 227 // An element of the expression stack as an assembly operand. | |
| 228 Operand ElementAt(int index) const { | |
| 229 return Operand(esp, index * kPointerSize); | |
| 230 } | |
| 231 | |
| 232 // Random-access store to a frame-top relative frame element. The result | |
| 233 // becomes owned by the frame and is invalidated. | |
| 234 void SetElementAt(int index, Result* value); | |
| 235 | |
| 236 // Set a frame element to a constant. The index is frame-top relative. | |
| 237 inline void SetElementAt(int index, Handle<Object> value); | |
| 238 | |
| 239 void PushElementAt(int index) { | |
| 240 PushFrameSlotAt(element_count() - index - 1); | |
| 241 } | |
| 242 | |
| 243 void StoreToElementAt(int index) { | |
| 244 StoreToFrameSlotAt(element_count() - index - 1); | |
| 245 } | |
| 246 | |
| 247 // A frame-allocated local as an assembly operand. | |
| 248 Operand LocalAt(int index) { | |
| 249 ASSERT(0 <= index); | |
| 250 ASSERT(index < local_count()); | |
| 251 return Operand(ebp, kLocal0Offset - index * kPointerSize); | |
| 252 } | |
| 253 | |
| 254 // Push a copy of the value of a local frame slot on top of the frame. | |
| 255 void PushLocalAt(int index) { | |
| 256 PushFrameSlotAt(local0_index() + index); | |
| 257 } | |
| 258 | |
| 259 // Push a copy of the value of a local frame slot on top of the frame. | |
| 260 void UntaggedPushLocalAt(int index) { | |
| 261 UntaggedPushFrameSlotAt(local0_index() + index); | |
| 262 } | |
| 263 | |
| 264 // Push the value of a local frame slot on top of the frame and invalidate | |
| 265 // the local slot. The slot should be written to before trying to read | |
| 266 // from it again. | |
| 267 void TakeLocalAt(int index) { | |
| 268 TakeFrameSlotAt(local0_index() + index); | |
| 269 } | |
| 270 | |
| 271 // Store the top value on the virtual frame into a local frame slot. The | |
| 272 // value is left in place on top of the frame. | |
| 273 void StoreToLocalAt(int index) { | |
| 274 StoreToFrameSlotAt(local0_index() + index); | |
| 275 } | |
| 276 | |
| 277 // Push the address of the receiver slot on the frame. | |
| 278 void PushReceiverSlotAddress(); | |
| 279 | |
| 280 // Push the function on top of the frame. | |
| 281 void PushFunction() { | |
| 282 PushFrameSlotAt(function_index()); | |
| 283 } | |
| 284 | |
| 285 // Save the value of the esi register to the context frame slot. | |
| 286 void SaveContextRegister(); | |
| 287 | |
| 288 // Restore the esi register from the value of the context frame | |
| 289 // slot. | |
| 290 void RestoreContextRegister(); | |
| 291 | |
| 292 // A parameter as an assembly operand. | |
| 293 Operand ParameterAt(int index) { | |
| 294 ASSERT(-1 <= index); // -1 is the receiver. | |
| 295 ASSERT(index < parameter_count()); | |
| 296 return Operand(ebp, (1 + parameter_count() - index) * kPointerSize); | |
| 297 } | |
| 298 | |
| 299 // Push a copy of the value of a parameter frame slot on top of the frame. | |
| 300 void PushParameterAt(int index) { | |
| 301 PushFrameSlotAt(param0_index() + index); | |
| 302 } | |
| 303 | |
| 304 // Push a copy of the value of a parameter frame slot on top of the frame. | |
| 305 void UntaggedPushParameterAt(int index) { | |
| 306 UntaggedPushFrameSlotAt(param0_index() + index); | |
| 307 } | |
| 308 | |
| 309 // Push the value of a paramter frame slot on top of the frame and | |
| 310 // invalidate the parameter slot. The slot should be written to before | |
| 311 // trying to read from it again. | |
| 312 void TakeParameterAt(int index) { | |
| 313 TakeFrameSlotAt(param0_index() + index); | |
| 314 } | |
| 315 | |
| 316 // Store the top value on the virtual frame into a parameter frame slot. | |
| 317 // The value is left in place on top of the frame. | |
| 318 void StoreToParameterAt(int index) { | |
| 319 StoreToFrameSlotAt(param0_index() + index); | |
| 320 } | |
| 321 | |
| 322 // The receiver frame slot. | |
| 323 Operand Receiver() { | |
| 324 return ParameterAt(-1); | |
| 325 } | |
| 326 | |
| 327 // Push a try-catch or try-finally handler on top of the virtual frame. | |
| 328 void PushTryHandler(HandlerType type); | |
| 329 | |
| 330 // Call stub given the number of arguments it expects on (and | |
| 331 // removes from) the stack. | |
| 332 inline Result CallStub(CodeStub* stub, int arg_count); | |
| 333 | |
| 334 // Call stub that takes a single argument passed in eax. The | |
| 335 // argument is given as a result which does not have to be eax or | |
| 336 // even a register. The argument is consumed by the call. | |
| 337 Result CallStub(CodeStub* stub, Result* arg); | |
| 338 | |
| 339 // Call stub that takes a pair of arguments passed in edx (arg0) and | |
| 340 // eax (arg1). The arguments are given as results which do not have | |
| 341 // to be in the proper registers or even in registers. The | |
| 342 // arguments are consumed by the call. | |
| 343 Result CallStub(CodeStub* stub, Result* arg0, Result* arg1); | |
| 344 | |
| 345 // Call JS function from top of the stack with arguments | |
| 346 // taken from the stack. | |
| 347 Result CallJSFunction(int arg_count); | |
| 348 | |
| 349 // Call runtime given the number of arguments expected on (and | |
| 350 // removed from) the stack. | |
| 351 Result CallRuntime(const Runtime::Function* f, int arg_count); | |
| 352 Result CallRuntime(Runtime::FunctionId id, int arg_count); | |
| 353 | |
| 354 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 355 void DebugBreak(); | |
| 356 #endif | |
| 357 | |
| 358 // Invoke builtin given the number of arguments it expects on (and | |
| 359 // removes from) the stack. | |
| 360 Result InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag, int arg_count); | |
| 361 | |
| 362 // Call load IC. Name and receiver are found on top of the frame. | |
| 363 // Both are dropped. | |
| 364 Result CallLoadIC(RelocInfo::Mode mode); | |
| 365 | |
| 366 // Call keyed load IC. Key and receiver are found on top of the | |
| 367 // frame. Both are dropped. | |
| 368 Result CallKeyedLoadIC(RelocInfo::Mode mode); | |
| 369 | |
| 370 // Call store IC. If the load is contextual, value is found on top of the | |
| 371 // frame. If not, value and receiver are on the frame. Both are dropped. | |
| 372 Result CallStoreIC(Handle<String> name, bool is_contextual, | |
| 373 StrictModeFlag strict_mode); | |
| 374 | |
| 375 // Call keyed store IC. Value, key, and receiver are found on top | |
| 376 // of the frame. All three are dropped. | |
| 377 Result CallKeyedStoreIC(StrictModeFlag strict_mode); | |
| 378 | |
| 379 // Call call IC. Function name, arguments, and receiver are found on top | |
| 380 // of the frame and dropped by the call. The argument count does not | |
| 381 // include the receiver. | |
| 382 Result CallCallIC(RelocInfo::Mode mode, int arg_count, int loop_nesting); | |
| 383 | |
| 384 // Call keyed call IC. Same calling convention as CallCallIC. | |
| 385 Result CallKeyedCallIC(RelocInfo::Mode mode, int arg_count, int loop_nesting); | |
| 386 | |
| 387 // Allocate and call JS function as constructor. Arguments, | |
| 388 // receiver (global object), and function are found on top of the | |
| 389 // frame. Function is not dropped. The argument count does not | |
| 390 // include the receiver. | |
| 391 Result CallConstructor(int arg_count); | |
| 392 | |
| 393 // Drop a number of elements from the top of the expression stack. May | |
| 394 // emit code to affect the physical frame. Does not clobber any registers | |
| 395 // excepting possibly the stack pointer. | |
| 396 void Drop(int count); | |
| 397 | |
| 398 // Drop one element. | |
| 399 void Drop() { | |
| 400 Drop(1); | |
| 401 } | |
| 402 | |
| 403 // Duplicate the top element of the frame. | |
| 404 void Dup() { | |
| 405 PushFrameSlotAt(element_count() - 1); | |
| 406 } | |
| 407 | |
| 408 // Pop an element from the top of the expression stack. Returns a | |
| 409 // Result, which may be a constant or a register. | |
| 410 Result Pop(); | |
| 411 | |
| 412 // Pop and save an element from the top of the expression stack and | |
| 413 // emit a corresponding pop instruction. | |
| 414 void EmitPop(Register reg); | |
| 415 void EmitPop(Operand operand); | |
| 416 | |
| 417 // Push an element on top of the expression stack and emit a | |
| 418 // corresponding push instruction. | |
| 419 void EmitPush(Register reg, | |
| 420 TypeInfo info = TypeInfo::Unknown()); | |
| 421 void EmitPush(Operand operand, | |
| 422 TypeInfo info = TypeInfo::Unknown()); | |
| 423 void EmitPush(Immediate immediate, | |
| 424 TypeInfo info = TypeInfo::Unknown()); | |
| 425 | |
| 426 inline bool ConstantPoolOverflowed(); | |
| 427 | |
| 428 // Push an element on the virtual frame. | |
| 429 void Push(Handle<Object> value); | |
| 430 inline void Push(Register reg, TypeInfo info = TypeInfo::Unknown()); | |
| 431 inline void Push(Smi* value); | |
| 432 | |
| 433 void PushUntaggedElement(Handle<Object> value); | |
| 434 | |
| 435 // Pushing a result invalidates it (its contents become owned by the | |
| 436 // frame). | |
| 437 void Push(Result* result) { | |
| 438 // This assert will trigger if you try to push the same value twice. | |
| 439 ASSERT(result->is_valid()); | |
| 440 if (result->is_register()) { | |
| 441 Push(result->reg(), result->type_info()); | |
| 442 } else { | |
| 443 ASSERT(result->is_constant()); | |
| 444 Push(result->handle()); | |
| 445 } | |
| 446 if (cgen()->in_safe_int32_mode()) { | |
| 447 ASSERT(result->is_untagged_int32()); | |
| 448 elements_[element_count() - 1].set_untagged_int32(true); | |
| 449 } | |
| 450 result->Unuse(); | |
| 451 } | |
| 452 | |
| 453 // Pushing an expression expects that the expression is trivial (according | |
| 454 // to Expression::IsTrivial). | |
| 455 void Push(Expression* expr); | |
| 456 | |
| 457 // Nip removes zero or more elements from immediately below the top | |
| 458 // of the frame, leaving the previous top-of-frame value on top of | |
| 459 // the frame. Nip(k) is equivalent to x = Pop(), Drop(k), Push(x). | |
| 460 inline void Nip(int num_dropped); | |
| 461 | |
| 462 // Check that the frame has no elements containing untagged int32 elements. | |
| 463 bool HasNoUntaggedInt32Elements() { | |
| 464 for (int i = 0; i < element_count(); ++i) { | |
| 465 if (elements_[i].is_untagged_int32()) return false; | |
| 466 } | |
| 467 return true; | |
| 468 } | |
| 469 | |
| 470 // Update the type information of a variable frame element directly. | |
| 471 inline void SetTypeForLocalAt(int index, TypeInfo info); | |
| 472 inline void SetTypeForParamAt(int index, TypeInfo info); | |
| 473 | |
| 474 private: | |
| 475 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; | |
| 476 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; | |
| 477 static const int kContextOffset = StandardFrameConstants::kContextOffset; | |
| 478 | |
| 479 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; | |
| 480 static const int kPreallocatedElements = 5 + 8; // 8 expression stack slots. | |
| 481 | |
| 482 ZoneList<FrameElement> elements_; | |
| 483 | |
| 484 // The index of the element that is at the processor's stack pointer | |
| 485 // (the esp register). | |
| 486 int stack_pointer_; | |
| 487 | |
| 488 // The index of the register frame element using each register, or | |
| 489 // kIllegalIndex if a register is not on the frame. | |
| 490 int register_locations_[RegisterAllocator::kNumRegisters]; | |
| 491 | |
| 492 // The number of frame-allocated locals and parameters respectively. | |
| 493 inline int parameter_count(); | |
| 494 | |
| 495 inline int local_count(); | |
| 496 | |
| 497 // The index of the element that is at the processor's frame pointer | |
| 498 // (the ebp register). The parameters, receiver, and return address | |
| 499 // are below the frame pointer. | |
| 500 int frame_pointer() { | |
| 501 return parameter_count() + 2; | |
| 502 } | |
| 503 | |
| 504 // The index of the first parameter. The receiver lies below the first | |
| 505 // parameter. | |
| 506 int param0_index() { | |
| 507 return 1; | |
| 508 } | |
| 509 | |
| 510 // The index of the context slot in the frame. It is immediately | |
| 511 // above the frame pointer. | |
| 512 int context_index() { | |
| 513 return frame_pointer() + 1; | |
| 514 } | |
| 515 | |
| 516 // The index of the function slot in the frame. It is above the frame | |
| 517 // pointer and the context slot. | |
| 518 int function_index() { | |
| 519 return frame_pointer() + 2; | |
| 520 } | |
| 521 | |
| 522 // The index of the first local. Between the frame pointer and the | |
| 523 // locals lie the context and the function. | |
| 524 int local0_index() { | |
| 525 return frame_pointer() + 3; | |
| 526 } | |
| 527 | |
| 528 // The index of the base of the expression stack. | |
| 529 int expression_base_index() { | |
| 530 return local0_index() + local_count(); | |
| 531 } | |
| 532 | |
| 533 // Convert a frame index into a frame pointer relative offset into the | |
| 534 // actual stack. | |
| 535 int fp_relative(int index) { | |
| 536 ASSERT(index < element_count()); | |
| 537 ASSERT(frame_pointer() < element_count()); // FP is on the frame. | |
| 538 return (frame_pointer() - index) * kPointerSize; | |
| 539 } | |
| 540 | |
| 541 // Record an occurrence of a register in the virtual frame. This has the | |
| 542 // effect of incrementing the register's external reference count and | |
| 543 // of updating the index of the register's location in the frame. | |
| 544 void Use(Register reg, int index) { | |
| 545 ASSERT(!is_used(reg)); | |
| 546 set_register_location(reg, index); | |
| 547 cgen()->allocator()->Use(reg); | |
| 548 } | |
| 549 | |
| 550 // Record that a register reference has been dropped from the frame. This | |
| 551 // decrements the register's external reference count and invalidates the | |
| 552 // index of the register's location in the frame. | |
| 553 void Unuse(Register reg) { | |
| 554 ASSERT(is_used(reg)); | |
| 555 set_register_location(reg, kIllegalIndex); | |
| 556 cgen()->allocator()->Unuse(reg); | |
| 557 } | |
| 558 | |
| 559 // Spill the element at a particular index---write it to memory if | |
| 560 // necessary, free any associated register, and forget its value if | |
| 561 // constant. | |
| 562 void SpillElementAt(int index); | |
| 563 | |
| 564 // Sync the element at a particular index. If it is a register or | |
| 565 // constant that disagrees with the value on the stack, write it to memory. | |
| 566 // Keep the element type as register or constant, and clear the dirty bit. | |
| 567 void SyncElementAt(int index); | |
| 568 | |
| 569 // Sync a single unsynced element that lies beneath or at the stack pointer. | |
| 570 void SyncElementBelowStackPointer(int index); | |
| 571 | |
| 572 // Sync a single unsynced element that lies just above the stack pointer. | |
| 573 void SyncElementByPushing(int index); | |
| 574 | |
| 575 // Push a copy of a frame slot (typically a local or parameter) on top of | |
| 576 // the frame. | |
| 577 inline void PushFrameSlotAt(int index); | |
| 578 | |
| 579 // Push a copy of a frame slot (typically a local or parameter) on top of | |
| 580 // the frame, at an untagged int32 value. Bails out if the value is not | |
| 581 // an int32. | |
| 582 void UntaggedPushFrameSlotAt(int index); | |
| 583 | |
| 584 // Push a the value of a frame slot (typically a local or parameter) on | |
| 585 // top of the frame and invalidate the slot. | |
| 586 void TakeFrameSlotAt(int index); | |
| 587 | |
| 588 // Store the value on top of the frame to a frame slot (typically a local | |
| 589 // or parameter). | |
| 590 void StoreToFrameSlotAt(int index); | |
| 591 | |
| 592 // Spill all elements in registers. Spill the top spilled_args elements | |
| 593 // on the frame. Sync all other frame elements. | |
| 594 // Then drop dropped_args elements from the virtual frame, to match | |
| 595 // the effect of an upcoming call that will drop them from the stack. | |
| 596 void PrepareForCall(int spilled_args, int dropped_args); | |
| 597 | |
| 598 // Move frame elements currently in registers or constants, that | |
| 599 // should be in memory in the expected frame, to memory. | |
| 600 void MergeMoveRegistersToMemory(VirtualFrame* expected); | |
| 601 | |
| 602 // Make the register-to-register moves necessary to | |
| 603 // merge this frame with the expected frame. | |
| 604 // Register to memory moves must already have been made, | |
| 605 // and memory to register moves must follow this call. | |
| 606 // This is because some new memory-to-register moves are | |
| 607 // created in order to break cycles of register moves. | |
| 608 // Used in the implementation of MergeTo(). | |
| 609 void MergeMoveRegistersToRegisters(VirtualFrame* expected); | |
| 610 | |
| 611 // Make the memory-to-register and constant-to-register moves | |
| 612 // needed to make this frame equal the expected frame. | |
| 613 // Called after all register-to-memory and register-to-register | |
| 614 // moves have been made. After this function returns, the frames | |
| 615 // should be equal. | |
| 616 void MergeMoveMemoryToRegisters(VirtualFrame* expected); | |
| 617 | |
| 618 // Invalidates a frame slot (puts an invalid frame element in it). | |
| 619 // Copies on the frame are correctly handled, and if this slot was | |
| 620 // the backing store of copies, the index of the new backing store | |
| 621 // is returned. Otherwise, returns kIllegalIndex. | |
| 622 // Register counts are correctly updated. | |
| 623 int InvalidateFrameSlotAt(int index); | |
| 624 | |
| 625 // This function assumes that a and b are the only results that could be in | |
| 626 // the registers a_reg or b_reg. Other results can be live, but must not | |
| 627 // be in the registers a_reg or b_reg. The results a and b are invalidated. | |
| 628 void MoveResultsToRegisters(Result* a, | |
| 629 Result* b, | |
| 630 Register a_reg, | |
| 631 Register b_reg); | |
| 632 | |
| 633 // Call a code stub that has already been prepared for calling (via | |
| 634 // PrepareForCall). | |
| 635 Result RawCallStub(CodeStub* stub); | |
| 636 | |
| 637 // Calls a code object which has already been prepared for calling | |
| 638 // (via PrepareForCall). | |
| 639 Result RawCallCodeObject(Handle<Code> code, RelocInfo::Mode rmode); | |
| 640 | |
| 641 inline bool Equals(VirtualFrame* other); | |
| 642 | |
| 643 // Classes that need raw access to the elements_ array. | |
| 644 friend class FrameRegisterState; | |
| 645 friend class JumpTarget; | |
| 646 }; | |
| 647 | |
| 648 } } // namespace v8::internal | |
| 649 | |
| 650 #endif // V8_IA32_VIRTUAL_FRAME_IA32_H_ | |
| OLD | NEW |