| 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 ASSERT(!cgen_->has_cc()); | |
| 200 __ Set(Operand(ebp, fp_relative(index)), Immediate(element.handle())); | 199 __ Set(Operand(ebp, fp_relative(index)), Immediate(element.handle())); |
| 201 } else { | 200 } else { |
| 202 ASSERT(element.is_register()); | 201 ASSERT(element.is_register()); |
| 203 __ mov(Operand(ebp, fp_relative(index)), element.reg()); | 202 __ mov(Operand(ebp, fp_relative(index)), element.reg()); |
| 204 } | 203 } |
| 205 } else { | 204 } else { |
| 206 // Push elements above the stack pointer to allocate space and sync | 205 // Push elements above the stack pointer to allocate space and sync |
| 207 // them. Space should have already been allocated in the actual frame | 206 // them. Space should have already been allocated in the actual frame |
| 208 // for all the elements below this one. | 207 // for all the elements below this one. |
| 209 ASSERT(index == stack_pointer_ + 1); | 208 ASSERT(index == stack_pointer_ + 1); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 305 |
| 307 return false; | 306 return false; |
| 308 } | 307 } |
| 309 | 308 |
| 310 | 309 |
| 311 void VirtualFrame::MakeMergable() { | 310 void VirtualFrame::MakeMergable() { |
| 312 Comment cmnt(masm_, "[ Make frame mergable"); | 311 Comment cmnt(masm_, "[ Make frame mergable"); |
| 313 // We should always be merging the code generator's current frame to an | 312 // We should always be merging the code generator's current frame to an |
| 314 // expected frame. | 313 // expected frame. |
| 315 ASSERT(cgen_->frame() == this); | 314 ASSERT(cgen_->frame() == this); |
| 316 ASSERT(!cgen_->has_cc()); | |
| 317 ASSERT(cgen_->HasValidEntryRegisters()); | 315 ASSERT(cgen_->HasValidEntryRegisters()); |
| 318 | 316 |
| 319 // Remove constants from the frame and ensure that no registers are | 317 // Remove constants from the frame and ensure that no registers are |
| 320 // multiply referenced within the frame. Allocate elements to their new | 318 // multiply referenced within the frame. Allocate elements to their new |
| 321 // locations from the top down so that the topmost elements have a chance | 319 // locations from the top down so that the topmost elements have a chance |
| 322 // to be in registers, then fill them into memory from the bottom up. | 320 // to be in registers, then fill them into memory from the bottom up. |
| 323 // (NB: Currently when spilling registers that are multiply referenced, it | 321 // (NB: Currently when spilling registers that are multiply referenced, it |
| 324 // is the lowermost occurrence that gets to stay in the register.) | 322 // is the lowermost occurrence that gets to stay in the register.) |
| 325 | 323 |
| 326 // The elements of new_elements are initially invalid. | 324 // The elements of new_elements are initially invalid. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 delete[] new_elements; | 386 delete[] new_elements; |
| 389 ASSERT(cgen_->HasValidEntryRegisters()); | 387 ASSERT(cgen_->HasValidEntryRegisters()); |
| 390 } | 388 } |
| 391 | 389 |
| 392 | 390 |
| 393 void VirtualFrame::MergeTo(VirtualFrame* expected) { | 391 void VirtualFrame::MergeTo(VirtualFrame* expected) { |
| 394 Comment cmnt(masm_, "[ Merge frame"); | 392 Comment cmnt(masm_, "[ Merge frame"); |
| 395 // We should always be merging the code generator's current frame to an | 393 // We should always be merging the code generator's current frame to an |
| 396 // expected frame. | 394 // expected frame. |
| 397 ASSERT(cgen_->frame() == this); | 395 ASSERT(cgen_->frame() == this); |
| 398 ASSERT(!cgen_->has_cc()); | |
| 399 | 396 |
| 400 ASSERT(cgen_ == expected->cgen_); | 397 ASSERT(cgen_ == expected->cgen_); |
| 401 ASSERT(masm_ == expected->masm_); | 398 ASSERT(masm_ == expected->masm_); |
| 402 ASSERT(elements_.length() == expected->elements_.length()); | 399 ASSERT(elements_.length() == expected->elements_.length()); |
| 403 ASSERT(parameter_count_ == expected->parameter_count_); | 400 ASSERT(parameter_count_ == expected->parameter_count_); |
| 404 ASSERT(local_count_ == expected->local_count_); | 401 ASSERT(local_count_ == expected->local_count_); |
| 405 ASSERT(frame_pointer_ == expected->frame_pointer_); | 402 ASSERT(frame_pointer_ == expected->frame_pointer_); |
| 406 | 403 |
| 407 // Mergable frames have all elements in locations, either memory or | 404 // Mergable frames have all elements in locations, either memory or |
| 408 // register. We thus have a series of to-memory and to-register moves. | 405 // register. We thus have a series of to-memory and to-register moves. |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 Drop(height()); | 655 Drop(height()); |
| 659 | 656 |
| 660 // Validate state: The expression stack should be empty and the | 657 // Validate state: The expression stack should be empty and the |
| 661 // stack pointer should have been updated to reflect this. | 658 // stack pointer should have been updated to reflect this. |
| 662 ASSERT(height() == 0); | 659 ASSERT(height() == 0); |
| 663 ASSERT(stack_pointer_ == expression_base_index() - 1); | 660 ASSERT(stack_pointer_ == expression_base_index() - 1); |
| 664 } | 661 } |
| 665 | 662 |
| 666 | 663 |
| 667 void VirtualFrame::AllocateStackSlots(int count) { | 664 void VirtualFrame::AllocateStackSlots(int count) { |
| 668 ASSERT(!cgen_->has_cc()); | |
| 669 ASSERT(height() == 0); | 665 ASSERT(height() == 0); |
| 670 local_count_ = count; | 666 local_count_ = count; |
| 671 | 667 |
| 672 if (count > 0) { | 668 if (count > 0) { |
| 673 Comment cmnt(masm_, "[ Allocate space for locals"); | 669 Comment cmnt(masm_, "[ Allocate space for locals"); |
| 674 // The locals are initialized to a constant (the undefined value), but | 670 // The locals are initialized to a constant (the undefined value), but |
| 675 // we sync them with the actual frame to allocate space for spilling | 671 // we sync them with the actual frame to allocate space for spilling |
| 676 // them later. First sync everything above the stack pointer so we can | 672 // them later. First sync everything above the stack pointer so we can |
| 677 // use pushes to allocate and initialize the locals. | 673 // use pushes to allocate and initialize the locals. |
| 678 SyncRange(stack_pointer_ + 1, elements_.length()); | 674 SyncRange(stack_pointer_ + 1, elements_.length()); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 ASSERT(cgen_->HasValidEntryRegisters()); | 913 ASSERT(cgen_->HasValidEntryRegisters()); |
| 918 PrepareForCall(frame_arg_count); | 914 PrepareForCall(frame_arg_count); |
| 919 __ call(code, rmode); | 915 __ call(code, rmode); |
| 920 Result result = cgen_->allocator()->Allocate(eax); | 916 Result result = cgen_->allocator()->Allocate(eax); |
| 921 ASSERT(result.is_valid()); | 917 ASSERT(result.is_valid()); |
| 922 return result; | 918 return result; |
| 923 } | 919 } |
| 924 | 920 |
| 925 | 921 |
| 926 void VirtualFrame::Drop(int count) { | 922 void VirtualFrame::Drop(int count) { |
| 927 ASSERT(!cgen_->has_cc()); | |
| 928 ASSERT(height() >= count); | 923 ASSERT(height() >= count); |
| 929 int num_virtual_elements = (elements_.length() - 1) - stack_pointer_; | 924 int num_virtual_elements = (elements_.length() - 1) - stack_pointer_; |
| 930 | 925 |
| 931 // Emit code to lower the stack pointer if necessary. | 926 // Emit code to lower the stack pointer if necessary. |
| 932 if (num_virtual_elements < count) { | 927 if (num_virtual_elements < count) { |
| 933 int num_dropped = count - num_virtual_elements; | 928 int num_dropped = count - num_virtual_elements; |
| 934 stack_pointer_ -= num_dropped; | 929 stack_pointer_ -= num_dropped; |
| 935 __ add(Operand(esp), Immediate(num_dropped * kPointerSize)); | 930 __ add(Operand(esp), Immediate(num_dropped * kPointerSize)); |
| 936 } | 931 } |
| 937 | 932 |
| 938 // Discard elements from the virtual frame and free any registers. | 933 // Discard elements from the virtual frame and free any registers. |
| 939 for (int i = 0; i < count; i++) { | 934 for (int i = 0; i < count; i++) { |
| 940 FrameElement dropped = elements_.RemoveLast(); | 935 FrameElement dropped = elements_.RemoveLast(); |
| 941 if (dropped.is_register()) { | 936 if (dropped.is_register()) { |
| 942 Unuse(dropped.reg()); | 937 Unuse(dropped.reg()); |
| 943 } | 938 } |
| 944 } | 939 } |
| 945 } | 940 } |
| 946 | 941 |
| 947 | 942 |
| 948 Result VirtualFrame::Pop() { | 943 Result VirtualFrame::Pop() { |
| 949 ASSERT(!cgen_->has_cc()); | |
| 950 FrameElement popped = elements_.RemoveLast(); | 944 FrameElement popped = elements_.RemoveLast(); |
| 951 bool pop_needed = (stack_pointer_ == elements_.length()); | 945 bool pop_needed = (stack_pointer_ == elements_.length()); |
| 952 | 946 |
| 953 if (popped.is_constant()) { | 947 if (popped.is_constant()) { |
| 954 if (pop_needed) { | 948 if (pop_needed) { |
| 955 stack_pointer_--; | 949 stack_pointer_--; |
| 956 __ add(Operand(esp), Immediate(kPointerSize)); | 950 __ add(Operand(esp), Immediate(kPointerSize)); |
| 957 } | 951 } |
| 958 return Result(popped.handle(), cgen_); | 952 return Result(popped.handle(), cgen_); |
| 959 } else if (popped.is_register()) { | 953 } else if (popped.is_register()) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 return false; | 1051 return false; |
| 1058 } | 1052 } |
| 1059 } | 1053 } |
| 1060 return true; | 1054 return true; |
| 1061 } | 1055 } |
| 1062 #endif | 1056 #endif |
| 1063 | 1057 |
| 1064 #undef __ | 1058 #undef __ |
| 1065 | 1059 |
| 1066 } } // namespace v8::internal | 1060 } } // namespace v8::internal |
| OLD | NEW |