| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // The element must be on the physical stack, or the first | 189 // The element must be on the physical stack, or the first |
| 190 // element below the stack pointer (created by a single push). | 190 // element below the stack pointer (created by a single push). |
| 191 void VirtualFrame::RawSyncElementAt(int index) { | 191 void VirtualFrame::RawSyncElementAt(int index) { |
| 192 FrameElement element = elements_[index]; | 192 FrameElement element = elements_[index]; |
| 193 | 193 |
| 194 if (!element.is_synced()) { | 194 if (!element.is_synced()) { |
| 195 if (index <= stack_pointer_) { | 195 if (index <= stack_pointer_) { |
| 196 // Write elements below the stack pointer to their (already allocated) | 196 // Write elements below the stack pointer to their (already allocated) |
| 197 // actual frame location. | 197 // actual frame location. |
| 198 if (element.is_constant()) { | 198 if (element.is_constant()) { |
| 199 __ mov(Operand(ebp, fp_relative(index)), Immediate(element.handle())); | 199 ASSERT(!cgen_->has_cc()); |
| 200 __ Set(Operand(ebp, fp_relative(index)), Immediate(element.handle())); |
| 200 } else { | 201 } else { |
| 201 ASSERT(element.is_register()); | 202 ASSERT(element.is_register()); |
| 202 __ mov(Operand(ebp, fp_relative(index)), element.reg()); | 203 __ mov(Operand(ebp, fp_relative(index)), element.reg()); |
| 203 } | 204 } |
| 204 } else { | 205 } else { |
| 205 // Push elements above the stack pointer to allocate space and sync | 206 // Push elements above the stack pointer to allocate space and sync |
| 206 // them. Space should have already been allocated in the actual frame | 207 // them. Space should have already been allocated in the actual frame |
| 207 // for all the elements below this one. | 208 // for all the elements below this one. |
| 208 ASSERT(index == stack_pointer_ + 1); | 209 ASSERT(index == stack_pointer_ + 1); |
| 209 stack_pointer_++; | 210 stack_pointer_++; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 306 |
| 306 return false; | 307 return false; |
| 307 } | 308 } |
| 308 | 309 |
| 309 | 310 |
| 310 void VirtualFrame::MakeMergable() { | 311 void VirtualFrame::MakeMergable() { |
| 311 Comment cmnt(masm_, "[ Make frame mergable"); | 312 Comment cmnt(masm_, "[ Make frame mergable"); |
| 312 // We should always be merging the code generator's current frame to an | 313 // We should always be merging the code generator's current frame to an |
| 313 // expected frame. | 314 // expected frame. |
| 314 ASSERT(cgen_->frame() == this); | 315 ASSERT(cgen_->frame() == this); |
| 316 ASSERT(!cgen_->has_cc()); |
| 315 ASSERT(cgen_->HasValidEntryRegisters()); | 317 ASSERT(cgen_->HasValidEntryRegisters()); |
| 316 | 318 |
| 317 // Remove constants from the frame and ensure that no registers are | 319 // Remove constants from the frame and ensure that no registers are |
| 318 // multiply referenced within the frame. Allocate elements to their new | 320 // multiply referenced within the frame. Allocate elements to their new |
| 319 // locations from the top down so that the topmost elements have a chance | 321 // locations from the top down so that the topmost elements have a chance |
| 320 // to be in registers, then fill them into memory from the bottom up. | 322 // to be in registers, then fill them into memory from the bottom up. |
| 321 // (NB: Currently when spilling registers that are multiply referenced, it | 323 // (NB: Currently when spilling registers that are multiply referenced, it |
| 322 // is the lowermost occurrence that gets to stay in the register.) | 324 // is the lowermost occurrence that gets to stay in the register.) |
| 323 | 325 |
| 324 // The elements of new_elements are initially invalid. | 326 // The elements of new_elements are initially invalid. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 362 } |
| 361 } | 363 } |
| 362 | 364 |
| 363 // Perform the moves. | 365 // Perform the moves. |
| 364 for (int i = 0; i < elements_.length(); i++) { | 366 for (int i = 0; i < elements_.length(); i++) { |
| 365 FrameElement source = elements_[i]; | 367 FrameElement source = elements_[i]; |
| 366 FrameElement target = new_elements[i]; | 368 FrameElement target = new_elements[i]; |
| 367 ASSERT(!target.is_valid() || target.is_register() || target.is_memory()); | 369 ASSERT(!target.is_valid() || target.is_register() || target.is_memory()); |
| 368 if (target.is_register()) { | 370 if (target.is_register()) { |
| 369 if (source.is_constant()) { | 371 if (source.is_constant()) { |
| 370 __ mov(target.reg(), Immediate(source.handle())); | 372 __ Set(target.reg(), Immediate(source.handle())); |
| 371 } else if (source.is_register() && !source.reg().is(target.reg())) { | 373 } else if (source.is_register() && !source.reg().is(target.reg())) { |
| 372 __ mov(target.reg(), source.reg()); | 374 __ mov(target.reg(), source.reg()); |
| 373 } | 375 } |
| 374 elements_[i] = target; | 376 elements_[i] = target; |
| 375 } else if (target.is_memory()) { | 377 } else if (target.is_memory()) { |
| 376 if (!source.is_memory()) { | 378 if (!source.is_memory()) { |
| 377 // Spilling a source register would decrement its reference count, | 379 // Spilling a source register would decrement its reference count, |
| 378 // but we have already done that when computing new target elements, | 380 // but we have already done that when computing new target elements, |
| 379 // so we use a raw spill. | 381 // so we use a raw spill. |
| 380 RawSpillElementAt(i); | 382 RawSpillElementAt(i); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 // Invalid elements do not need to be moved. | 385 // Invalid elements do not need to be moved. |
| 384 } | 386 } |
| 385 | 387 |
| 386 delete[] new_elements; | 388 delete[] new_elements; |
| 387 ASSERT(cgen_->HasValidEntryRegisters()); | 389 ASSERT(cgen_->HasValidEntryRegisters()); |
| 388 } | 390 } |
| 389 | 391 |
| 390 | 392 |
| 391 void VirtualFrame::MergeTo(VirtualFrame* expected) { | 393 void VirtualFrame::MergeTo(VirtualFrame* expected) { |
| 392 Comment cmnt(masm_, "[ Merge frame"); | 394 Comment cmnt(masm_, "[ Merge frame"); |
| 393 // We should always be merging the code generator's current frame to an | 395 // We should always be merging the code generator's current frame to an |
| 394 // expected frame. | 396 // expected frame. |
| 395 ASSERT(cgen_->frame() == this); | 397 ASSERT(cgen_->frame() == this); |
| 398 ASSERT(!cgen_->has_cc()); |
| 396 | 399 |
| 397 ASSERT(cgen_ == expected->cgen_); | 400 ASSERT(cgen_ == expected->cgen_); |
| 398 ASSERT(masm_ == expected->masm_); | 401 ASSERT(masm_ == expected->masm_); |
| 399 ASSERT(elements_.length() == expected->elements_.length()); | 402 ASSERT(elements_.length() == expected->elements_.length()); |
| 400 ASSERT(parameter_count_ == expected->parameter_count_); | 403 ASSERT(parameter_count_ == expected->parameter_count_); |
| 401 ASSERT(local_count_ == expected->local_count_); | 404 ASSERT(local_count_ == expected->local_count_); |
| 402 ASSERT(frame_pointer_ == expected->frame_pointer_); | 405 ASSERT(frame_pointer_ == expected->frame_pointer_); |
| 403 | 406 |
| 404 // Mergable frames have all elements in locations, either memory or | 407 // Mergable frames have all elements in locations, either memory or |
| 405 // register. We thus have a series of to-memory and to-register moves. | 408 // register. We thus have a series of to-memory and to-register moves. |
| 406 // First perform all to-memory moves, register-to-memory moves because | 409 // First perform all to-memory moves, register-to-memory moves because |
| 407 // they can free registers and constant-to-memory moves because they do | 410 // they can free registers and constant-to-memory moves because they do |
| 408 // not use registers. | 411 // not use registers. |
| 409 MergeMoveRegistersToMemory(expected); | 412 MergeMoveRegistersToMemory(expected); |
| 410 MergeMoveRegistersToRegisters(expected); | 413 MergeMoveRegistersToRegisters(expected); |
| 411 MergeMoveMemoryToRegisters(expected); | 414 MergeMoveMemoryToRegisters(expected); |
| 412 | 415 |
| 413 int height_difference = stack_pointer_ - expected->stack_pointer_; | 416 int height_difference = stack_pointer_ - expected->stack_pointer_; |
| 414 if (stack_pointer_ > expected->stack_pointer_) { | 417 if (stack_pointer_ > expected->stack_pointer_) { |
| 415 #ifdef DEBUG | 418 #ifdef DEBUG |
| 416 for (int i = stack_pointer_; i > expected->stack_pointer_; i--) { | 419 for (int i = stack_pointer_; i > expected->stack_pointer_; i--) { |
| 417 ASSERT(!elements_[i].is_memory()); | 420 ASSERT(!elements_[i].is_memory()); |
| 418 ASSERT(!elements_[i].is_synced()); | 421 ASSERT(!elements_[i].is_synced()); |
| 419 } | 422 } |
| 420 #endif | 423 #endif |
| 421 ASSERT(!cgen_->has_cc()); | |
| 422 __ add(Operand(esp), Immediate(height_difference * kPointerSize)); | 424 __ add(Operand(esp), Immediate(height_difference * kPointerSize)); |
| 423 stack_pointer_ = expected->stack_pointer_; | 425 stack_pointer_ = expected->stack_pointer_; |
| 424 } else if (stack_pointer_ < expected->stack_pointer_) { | 426 } else if (stack_pointer_ < expected->stack_pointer_) { |
| 425 // Put valid data on the stack, that will only be accessed by GC. | 427 // Put valid data on the stack, that will only be accessed by GC. |
| 426 while (stack_pointer_ < expected->stack_pointer_) { | 428 while (stack_pointer_ < expected->stack_pointer_) { |
| 427 __ push(Immediate(Smi::FromInt(0))); | 429 __ push(Immediate(Smi::FromInt(0))); |
| 428 stack_pointer_++; | 430 stack_pointer_++; |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 | 433 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 if (stack_pointer_ > i) { | 552 if (stack_pointer_ > i) { |
| 551 // Sync elements between i and stack pointer, and bring | 553 // Sync elements between i and stack pointer, and bring |
| 552 // stack pointer down to i. | 554 // stack pointer down to i. |
| 553 #ifdef DEBUG | 555 #ifdef DEBUG |
| 554 // In debug builds check to ensure this is safe. | 556 // In debug builds check to ensure this is safe. |
| 555 for (int j = stack_pointer_; j > i; j--) { | 557 for (int j = stack_pointer_; j > i; j--) { |
| 556 ASSERT(!elements_[j].is_memory()); | 558 ASSERT(!elements_[j].is_memory()); |
| 557 } | 559 } |
| 558 #endif | 560 #endif |
| 559 int difference = stack_pointer_ - i; | 561 int difference = stack_pointer_ - i; |
| 560 ASSERT(!cgen_->has_cc()); | |
| 561 __ add(Operand(esp), Immediate(difference * kPointerSize)); | 562 __ add(Operand(esp), Immediate(difference * kPointerSize)); |
| 562 stack_pointer_ = i; | 563 stack_pointer_ = i; |
| 563 } | 564 } |
| 564 stack_pointer_--; | 565 stack_pointer_--; |
| 565 __ pop(target.reg()); | 566 __ pop(target.reg()); |
| 566 } | 567 } |
| 567 } else { | 568 } else { |
| 568 // Source is constant. | 569 // Source is constant. |
| 569 __ Set(target.reg(), Immediate(source.handle())); | 570 __ Set(target.reg(), Immediate(source.handle())); |
| 570 if (target.is_synced()) { | 571 if (target.is_synced()) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 Drop(height()); | 658 Drop(height()); |
| 658 | 659 |
| 659 // Validate state: The expression stack should be empty and the | 660 // Validate state: The expression stack should be empty and the |
| 660 // stack pointer should have been updated to reflect this. | 661 // stack pointer should have been updated to reflect this. |
| 661 ASSERT(height() == 0); | 662 ASSERT(height() == 0); |
| 662 ASSERT(stack_pointer_ == expression_base_index() - 1); | 663 ASSERT(stack_pointer_ == expression_base_index() - 1); |
| 663 } | 664 } |
| 664 | 665 |
| 665 | 666 |
| 666 void VirtualFrame::AllocateStackSlots(int count) { | 667 void VirtualFrame::AllocateStackSlots(int count) { |
| 668 ASSERT(!cgen_->has_cc()); |
| 667 ASSERT(height() == 0); | 669 ASSERT(height() == 0); |
| 668 local_count_ = count; | 670 local_count_ = count; |
| 669 | 671 |
| 670 if (count > 0) { | 672 if (count > 0) { |
| 671 Comment cmnt(masm_, "[ Allocate space for locals"); | 673 Comment cmnt(masm_, "[ Allocate space for locals"); |
| 672 // The locals are initialized to a constant (the undefined value), but | 674 // The locals are initialized to a constant (the undefined value), but |
| 673 // we sync them with the actual frame to allocate space for spilling | 675 // we sync them with the actual frame to allocate space for spilling |
| 674 // them later. First sync everything above the stack pointer so we can | 676 // them later. First sync everything above the stack pointer so we can |
| 675 // use pushes to allocate and initialize the locals. | 677 // use pushes to allocate and initialize the locals. |
| 676 SyncRange(stack_pointer_ + 1, elements_.length()); | 678 SyncRange(stack_pointer_ + 1, elements_.length()); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 ASSERT(cgen_->HasValidEntryRegisters()); | 920 ASSERT(cgen_->HasValidEntryRegisters()); |
| 919 PrepareForCall(frame_arg_count); | 921 PrepareForCall(frame_arg_count); |
| 920 __ call(code, rmode); | 922 __ call(code, rmode); |
| 921 Result result = cgen_->allocator()->Allocate(eax); | 923 Result result = cgen_->allocator()->Allocate(eax); |
| 922 ASSERT(result.is_valid()); | 924 ASSERT(result.is_valid()); |
| 923 return result; | 925 return result; |
| 924 } | 926 } |
| 925 | 927 |
| 926 | 928 |
| 927 void VirtualFrame::Drop(int count) { | 929 void VirtualFrame::Drop(int count) { |
| 930 ASSERT(!cgen_->has_cc()); |
| 928 ASSERT(height() >= count); | 931 ASSERT(height() >= count); |
| 929 int num_virtual_elements = (elements_.length() - 1) - stack_pointer_; | 932 int num_virtual_elements = (elements_.length() - 1) - stack_pointer_; |
| 930 | 933 |
| 931 // Emit code to lower the stack pointer if necessary. | 934 // Emit code to lower the stack pointer if necessary. |
| 932 if (num_virtual_elements < count) { | 935 if (num_virtual_elements < count) { |
| 933 int num_dropped = count - num_virtual_elements; | 936 int num_dropped = count - num_virtual_elements; |
| 934 stack_pointer_ -= num_dropped; | 937 stack_pointer_ -= num_dropped; |
| 935 ASSERT(!cgen_->has_cc()); | |
| 936 __ add(Operand(esp), Immediate(num_dropped * kPointerSize)); | 938 __ add(Operand(esp), Immediate(num_dropped * kPointerSize)); |
| 937 } | 939 } |
| 938 | 940 |
| 939 // Discard elements from the virtual frame and free any registers. | 941 // Discard elements from the virtual frame and free any registers. |
| 940 for (int i = 0; i < count; i++) { | 942 for (int i = 0; i < count; i++) { |
| 941 FrameElement dropped = elements_.RemoveLast(); | 943 FrameElement dropped = elements_.RemoveLast(); |
| 942 if (dropped.is_register()) { | 944 if (dropped.is_register()) { |
| 943 Unuse(dropped.reg()); | 945 Unuse(dropped.reg()); |
| 944 } | 946 } |
| 945 } | 947 } |
| 946 } | 948 } |
| 947 | 949 |
| 948 | 950 |
| 949 Result VirtualFrame::Pop() { | 951 Result VirtualFrame::Pop() { |
| 952 ASSERT(!cgen_->has_cc()); |
| 950 FrameElement popped = elements_.RemoveLast(); | 953 FrameElement popped = elements_.RemoveLast(); |
| 951 bool pop_needed = (stack_pointer_ == elements_.length()); | 954 bool pop_needed = (stack_pointer_ == elements_.length()); |
| 952 | 955 |
| 953 if (popped.is_constant()) { | 956 if (popped.is_constant()) { |
| 954 if (pop_needed) { | 957 if (pop_needed) { |
| 955 stack_pointer_--; | 958 stack_pointer_--; |
| 956 ASSERT(!cgen_->has_cc()); | |
| 957 __ add(Operand(esp), Immediate(kPointerSize)); | 959 __ add(Operand(esp), Immediate(kPointerSize)); |
| 958 } | 960 } |
| 959 return Result(popped.handle(), cgen_); | 961 return Result(popped.handle(), cgen_); |
| 960 } else if (popped.is_register()) { | 962 } else if (popped.is_register()) { |
| 961 Unuse(popped.reg()); | 963 Unuse(popped.reg()); |
| 962 if (pop_needed) { | 964 if (pop_needed) { |
| 963 stack_pointer_--; | 965 stack_pointer_--; |
| 964 ASSERT(!cgen_->has_cc()); | |
| 965 __ add(Operand(esp), Immediate(kPointerSize)); | 966 __ add(Operand(esp), Immediate(kPointerSize)); |
| 966 } | 967 } |
| 967 return Result(popped.reg(), cgen_); | 968 return Result(popped.reg(), cgen_); |
| 968 } else { | 969 } else { |
| 969 ASSERT(popped.is_memory()); | 970 ASSERT(popped.is_memory()); |
| 970 Result temp = cgen_->allocator()->Allocate(); | 971 Result temp = cgen_->allocator()->Allocate(); |
| 971 ASSERT(temp.is_valid()); | 972 ASSERT(temp.is_valid()); |
| 972 ASSERT(pop_needed); | 973 ASSERT(pop_needed); |
| 973 stack_pointer_--; | 974 stack_pointer_--; |
| 974 __ pop(temp.reg()); | 975 __ pop(temp.reg()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 return false; | 1060 return false; |
| 1060 } | 1061 } |
| 1061 } | 1062 } |
| 1062 return true; | 1063 return true; |
| 1063 } | 1064 } |
| 1064 #endif | 1065 #endif |
| 1065 | 1066 |
| 1066 #undef __ | 1067 #undef __ |
| 1067 | 1068 |
| 1068 } } // namespace v8::internal | 1069 } } // namespace v8::internal |
| OLD | NEW |