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

Side by Side Diff: src/ia32/codegen-ia32.cc

Issue 5274002: Version 2.5.8... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 10 years 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
« no previous file with comments | « src/ia32/codegen-ia32.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 4879 matching lines...) Expand 10 before | Expand all | Expand 10 after
4890 // Spill everything, even constants, to the frame. 4890 // Spill everything, even constants, to the frame.
4891 frame_->SpillAll(); 4891 frame_->SpillAll();
4892 4892
4893 frame_->DebugBreak(); 4893 frame_->DebugBreak();
4894 // Ignore the return value. 4894 // Ignore the return value.
4895 #endif 4895 #endif
4896 } 4896 }
4897 4897
4898 4898
4899 Result CodeGenerator::InstantiateFunction( 4899 Result CodeGenerator::InstantiateFunction(
4900 Handle<SharedFunctionInfo> function_info) { 4900 Handle<SharedFunctionInfo> function_info,
4901 bool pretenure) {
4901 // The inevitable call will sync frame elements to memory anyway, so 4902 // The inevitable call will sync frame elements to memory anyway, so
4902 // we do it eagerly to allow us to push the arguments directly into 4903 // we do it eagerly to allow us to push the arguments directly into
4903 // place. 4904 // place.
4904 frame()->SyncRange(0, frame()->element_count() - 1); 4905 frame()->SyncRange(0, frame()->element_count() - 1);
4905 4906
4906 // Use the fast case closure allocation code that allocates in new 4907 // Use the fast case closure allocation code that allocates in new
4907 // space for nested functions that don't need literals cloning. 4908 // space for nested functions that don't need literals cloning.
4908 if (scope()->is_function_scope() && function_info->num_literals() == 0) { 4909 if (scope()->is_function_scope() &&
4910 function_info->num_literals() == 0 &&
4911 !pretenure) {
4909 FastNewClosureStub stub; 4912 FastNewClosureStub stub;
4910 frame()->EmitPush(Immediate(function_info)); 4913 frame()->EmitPush(Immediate(function_info));
4911 return frame()->CallStub(&stub, 1); 4914 return frame()->CallStub(&stub, 1);
4912 } else { 4915 } else {
4913 // Call the runtime to instantiate the function based on the 4916 // Call the runtime to instantiate the function based on the
4914 // shared function info. 4917 // shared function info.
4915 frame()->EmitPush(esi); 4918 frame()->EmitPush(esi);
4916 frame()->EmitPush(Immediate(function_info)); 4919 frame()->EmitPush(Immediate(function_info));
4917 return frame()->CallRuntime(Runtime::kNewClosure, 2); 4920 frame()->EmitPush(Immediate(pretenure
4921 ? Factory::true_value()
4922 : Factory::false_value()));
4923 return frame()->CallRuntime(Runtime::kNewClosure, 3);
4918 } 4924 }
4919 } 4925 }
4920 4926
4921 4927
4922 void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { 4928 void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) {
4923 Comment cmnt(masm_, "[ FunctionLiteral"); 4929 Comment cmnt(masm_, "[ FunctionLiteral");
4924 ASSERT(!in_safe_int32_mode()); 4930 ASSERT(!in_safe_int32_mode());
4925 // Build the function info and instantiate it. 4931 // Build the function info and instantiate it.
4926 Handle<SharedFunctionInfo> function_info = 4932 Handle<SharedFunctionInfo> function_info =
4927 Compiler::BuildFunctionInfo(node, script()); 4933 Compiler::BuildFunctionInfo(node, script());
4928 // Check for stack-overflow exception. 4934 // Check for stack-overflow exception.
4929 if (function_info.is_null()) { 4935 if (function_info.is_null()) {
4930 SetStackOverflow(); 4936 SetStackOverflow();
4931 return; 4937 return;
4932 } 4938 }
4933 Result result = InstantiateFunction(function_info); 4939 Result result = InstantiateFunction(function_info, node->pretenure());
4934 frame()->Push(&result); 4940 frame()->Push(&result);
4935 } 4941 }
4936 4942
4937 4943
4938 void CodeGenerator::VisitSharedFunctionInfoLiteral( 4944 void CodeGenerator::VisitSharedFunctionInfoLiteral(
4939 SharedFunctionInfoLiteral* node) { 4945 SharedFunctionInfoLiteral* node) {
4940 ASSERT(!in_safe_int32_mode()); 4946 ASSERT(!in_safe_int32_mode());
4941 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); 4947 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
4942 Result result = InstantiateFunction(node->shared_function_info()); 4948 Result result = InstantiateFunction(node->shared_function_info(), false);
4943 frame()->Push(&result); 4949 frame()->Push(&result);
4944 } 4950 }
4945 4951
4946 4952
4947 void CodeGenerator::VisitConditional(Conditional* node) { 4953 void CodeGenerator::VisitConditional(Conditional* node) {
4948 Comment cmnt(masm_, "[ Conditional"); 4954 Comment cmnt(masm_, "[ Conditional");
4949 ASSERT(!in_safe_int32_mode()); 4955 ASSERT(!in_safe_int32_mode());
4950 JumpTarget then; 4956 JumpTarget then;
4951 JumpTarget else_; 4957 JumpTarget else_;
4952 JumpTarget exit; 4958 JumpTarget exit;
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after
6635 Result temp = allocator()->Allocate(); 6641 Result temp = allocator()->Allocate();
6636 ASSERT(temp.is_valid()); 6642 ASSERT(temp.is_valid());
6637 // Check if the object is a JS array or not. 6643 // Check if the object is a JS array or not.
6638 __ CmpObjectType(value.reg(), JS_ARRAY_TYPE, temp.reg()); 6644 __ CmpObjectType(value.reg(), JS_ARRAY_TYPE, temp.reg());
6639 value.Unuse(); 6645 value.Unuse();
6640 temp.Unuse(); 6646 temp.Unuse();
6641 destination()->Split(equal); 6647 destination()->Split(equal);
6642 } 6648 }
6643 6649
6644 6650
6651 void CodeGenerator::GenerateFastAsciiArrayJoin(ZoneList<Expression*>* args) {
6652 ASSERT(args->length() == 2);
6653 Load(args->at(1));
6654 Load(args->at(0));
6655 Result array_result = frame_->Pop();
6656 array_result.ToRegister(eax);
6657 frame_->SpillAll();
6658
6659 Label bailout;
6660 Label done;
6661 // All aliases of the same register have disjoint lifetimes.
6662 Register array = eax;
6663 Register result_pos = no_reg;
6664
6665 Register index = edi;
6666
6667 Register current_string_length = ecx; // Will be ecx when live.
6668
6669 Register current_string = edx;
6670
6671 Register scratch = ebx;
6672
6673 Register scratch_2 = esi;
6674 Register new_padding_chars = scratch_2;
6675
6676 Operand separator = Operand(esp, 4 * kPointerSize); // Already pushed.
6677 Operand elements = Operand(esp, 3 * kPointerSize);
6678 Operand result = Operand(esp, 2 * kPointerSize);
6679 Operand padding_chars = Operand(esp, 1 * kPointerSize);
6680 Operand array_length = Operand(esp, 0);
6681 __ sub(Operand(esp), Immediate(4 * kPointerSize));
6682
6683 // Check that eax is a JSArray
6684 __ test(array, Immediate(kSmiTagMask));
6685 __ j(zero, &bailout);
6686 __ CmpObjectType(array, JS_ARRAY_TYPE, scratch);
6687 __ j(not_equal, &bailout);
6688
6689 // Check that the array has fast elements.
6690 __ test_b(FieldOperand(scratch, Map::kBitField2Offset),
6691 1 << Map::kHasFastElements);
6692 __ j(zero, &bailout);
6693
6694 // If the array is empty, return the empty string.
6695 __ mov(scratch, FieldOperand(array, JSArray::kLengthOffset));
6696 __ sar(scratch, 1);
6697 Label non_trivial;
6698 __ j(not_zero, &non_trivial);
6699 __ mov(result, Factory::empty_string());
6700 __ jmp(&done);
6701
6702 __ bind(&non_trivial);
6703 __ mov(array_length, scratch);
6704
6705 __ mov(scratch, FieldOperand(array, JSArray::kElementsOffset));
6706 __ mov(elements, scratch);
6707
6708 // End of array's live range.
6709 result_pos = array;
6710 array = no_reg;
6711
6712
6713 // Check that the separator is a flat ascii string.
6714 __ mov(current_string, separator);
6715 __ test(current_string, Immediate(kSmiTagMask));
6716 __ j(zero, &bailout);
6717 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset));
6718 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
6719 __ and_(scratch, Immediate(
6720 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
6721 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
6722 __ j(not_equal, &bailout);
6723 // If the separator is the empty string, replace it with NULL.
6724 // The test for NULL is quicker than the empty string test, in a loop.
6725 __ cmp(FieldOperand(current_string, SeqAsciiString::kLengthOffset),
6726 Immediate(0));
6727 Label separator_checked;
6728 __ j(not_zero, &separator_checked);
6729 __ mov(separator, Immediate(0));
6730 __ bind(&separator_checked);
6731
6732 // Check that elements[0] is a flat ascii string, and copy it in new space.
6733 __ mov(scratch, elements);
6734 __ mov(current_string, FieldOperand(scratch, FixedArray::kHeaderSize));
6735 __ test(current_string, Immediate(kSmiTagMask));
6736 __ j(zero, &bailout);
6737 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset));
6738 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
6739 __ and_(scratch, Immediate(
6740 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
6741 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
6742 __ j(not_equal, &bailout);
6743
6744 // Allocate space to copy it. Round up the size to the alignment granularity.
6745 __ mov(current_string_length,
6746 FieldOperand(current_string, String::kLengthOffset));
6747 __ shr(current_string_length, 1);
6748
6749 // Live registers and stack values:
6750 // current_string_length: length of elements[0].
6751
6752 // New string result in new space = elements[0]
6753 __ AllocateAsciiString(result_pos, current_string_length, scratch_2,
6754 index, no_reg, &bailout);
6755 __ mov(result, result_pos);
6756
6757 // Adjust current_string_length to include padding bytes at end of string.
6758 // Keep track of the number of padding bytes.
6759 __ mov(new_padding_chars, current_string_length);
6760 __ add(Operand(current_string_length), Immediate(kObjectAlignmentMask));
6761 __ and_(Operand(current_string_length), Immediate(~kObjectAlignmentMask));
6762 __ sub(new_padding_chars, Operand(current_string_length));
6763 __ neg(new_padding_chars);
6764 __ mov(padding_chars, new_padding_chars);
6765
6766 Label copy_loop_1_done;
6767 Label copy_loop_1;
6768 __ test(current_string_length, Operand(current_string_length));
6769 __ j(zero, &copy_loop_1_done);
6770 __ bind(&copy_loop_1);
6771 __ sub(Operand(current_string_length), Immediate(kPointerSize));
6772 __ mov(scratch, FieldOperand(current_string, current_string_length,
6773 times_1, SeqAsciiString::kHeaderSize));
6774 __ mov(FieldOperand(result_pos, current_string_length,
6775 times_1, SeqAsciiString::kHeaderSize),
6776 scratch);
6777 __ j(not_zero, &copy_loop_1);
6778 __ bind(&copy_loop_1_done);
6779
6780 __ mov(index, Immediate(1));
6781 // Loop condition: while (index < length).
6782 Label loop;
6783 __ bind(&loop);
6784 __ cmp(index, array_length);
6785 __ j(greater_equal, &done);
6786
6787 // If the separator is the empty string, signalled by NULL, skip it.
6788 Label separator_done;
6789 __ mov(current_string, separator);
6790 __ test(current_string, Operand(current_string));
6791 __ j(zero, &separator_done);
6792
6793 // Append separator to result. It is known to be a flat ascii string.
6794 __ AppendStringToTopOfNewSpace(current_string, current_string_length,
6795 result_pos, scratch, scratch_2, result,
6796 padding_chars, &bailout);
6797 __ bind(&separator_done);
6798
6799 // Add next element of array to the end of the result.
6800 // Get current_string = array[index].
6801 __ mov(scratch, elements);
6802 __ mov(current_string, FieldOperand(scratch, index,
6803 times_pointer_size,
6804 FixedArray::kHeaderSize));
6805 // If current != flat ascii string drop result, return undefined.
6806 __ test(current_string, Immediate(kSmiTagMask));
6807 __ j(zero, &bailout);
6808 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset));
6809 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
6810 __ and_(scratch, Immediate(
6811 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
6812 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
6813 __ j(not_equal, &bailout);
6814
6815 // Append current to the result.
6816 __ AppendStringToTopOfNewSpace(current_string, current_string_length,
6817 result_pos, scratch, scratch_2, result,
6818 padding_chars, &bailout);
6819 __ add(Operand(index), Immediate(1));
6820 __ jmp(&loop); // End while (index < length).
6821
6822 __ bind(&bailout);
6823 __ mov(result, Factory::undefined_value());
6824 __ bind(&done);
6825 __ mov(eax, result);
6826 // Drop temp values from the stack, and restore context register.
6827 __ add(Operand(esp), Immediate(4 * kPointerSize));
6828
6829 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
6830 frame_->Drop(1);
6831 frame_->Push(&array_result);
6832 }
6833
6834
6645 void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { 6835 void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) {
6646 ASSERT(args->length() == 1); 6836 ASSERT(args->length() == 1);
6647 Load(args->at(0)); 6837 Load(args->at(0));
6648 Result value = frame_->Pop(); 6838 Result value = frame_->Pop();
6649 value.ToRegister(); 6839 value.ToRegister();
6650 ASSERT(value.is_valid()); 6840 ASSERT(value.is_valid());
6651 __ test(value.reg(), Immediate(kSmiTagMask)); 6841 __ test(value.reg(), Immediate(kSmiTagMask));
6652 destination()->false_target()->Branch(equal); 6842 destination()->false_target()->Branch(equal);
6653 // It is a heap object - get map. 6843 // It is a heap object - get map.
6654 Result temp = allocator()->Allocate(); 6844 Result temp = allocator()->Allocate();
(...skipping 3427 matching lines...) Expand 10 before | Expand all | Expand 10 after
10082 masm.GetCode(&desc); 10272 masm.GetCode(&desc);
10083 // Call the function from C++. 10273 // Call the function from C++.
10084 return FUNCTION_CAST<MemCopyFunction>(buffer); 10274 return FUNCTION_CAST<MemCopyFunction>(buffer);
10085 } 10275 }
10086 10276
10087 #undef __ 10277 #undef __
10088 10278
10089 } } // namespace v8::internal 10279 } } // namespace v8::internal
10090 10280
10091 #endif // V8_TARGET_ARCH_IA32 10281 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698