OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3696 AddInstruction(new HCheckInstanceType(array, JS_ARRAY_TYPE, JS_ARRAY_TYPE)); | 3696 AddInstruction(new HCheckInstanceType(array, JS_ARRAY_TYPE, JS_ARRAY_TYPE)); |
3697 instr = new HJSArrayLength(array); | 3697 instr = new HJSArrayLength(array); |
3698 | 3698 |
3699 } else if (expr->IsStringLength()) { | 3699 } else if (expr->IsStringLength()) { |
3700 HValue* string = Pop(); | 3700 HValue* string = Pop(); |
3701 AddInstruction(new HCheckNonSmi(string)); | 3701 AddInstruction(new HCheckNonSmi(string)); |
3702 AddInstruction(new HCheckInstanceType(string, | 3702 AddInstruction(new HCheckInstanceType(string, |
3703 FIRST_STRING_TYPE, | 3703 FIRST_STRING_TYPE, |
3704 LAST_STRING_TYPE)); | 3704 LAST_STRING_TYPE)); |
3705 instr = new HStringLength(string); | 3705 instr = new HStringLength(string); |
3706 } else if (expr->IsStringAccess()) { | |
3707 VISIT_FOR_VALUE(expr->key()); | |
3708 HValue* index = Pop(); | |
3709 HValue* string = Pop(); | |
3710 HStringCharCodeAt* char_code = BuildStringCharCodeAt(string, index); | |
3711 AddInstruction(char_code); | |
3712 instr = new HStringCharFromCode(char_code); | |
3706 | 3713 |
3707 } else if (expr->IsFunctionPrototype()) { | 3714 } else if (expr->IsFunctionPrototype()) { |
3708 HValue* function = Pop(); | 3715 HValue* function = Pop(); |
3709 AddInstruction(new HCheckNonSmi(function)); | 3716 AddInstruction(new HCheckNonSmi(function)); |
3710 instr = new HLoadFunctionPrototype(function); | 3717 instr = new HLoadFunctionPrototype(function); |
3711 | 3718 |
3712 } else if (expr->key()->IsPropertyName()) { | 3719 } else if (expr->key()->IsPropertyName()) { |
3713 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); | 3720 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); |
3714 ZoneMapList* types = expr->GetReceiverTypes(); | 3721 ZoneMapList* types = expr->GetReceiverTypes(); |
3715 | 3722 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4076 HValue* receiver, | 4083 HValue* receiver, |
4077 Handle<Map> receiver_map, | 4084 Handle<Map> receiver_map, |
4078 CheckType check_type) { | 4085 CheckType check_type) { |
4079 ASSERT(check_type != RECEIVER_MAP_CHECK || !receiver_map.is_null()); | 4086 ASSERT(check_type != RECEIVER_MAP_CHECK || !receiver_map.is_null()); |
4080 // Try to inline calls like Math.* as operations in the calling function. | 4087 // Try to inline calls like Math.* as operations in the calling function. |
4081 if (!expr->target()->shared()->HasBuiltinFunctionId()) return false; | 4088 if (!expr->target()->shared()->HasBuiltinFunctionId()) return false; |
4082 BuiltinFunctionId id = expr->target()->shared()->builtin_function_id(); | 4089 BuiltinFunctionId id = expr->target()->shared()->builtin_function_id(); |
4083 int argument_count = expr->arguments()->length() + 1; // Plus receiver. | 4090 int argument_count = expr->arguments()->length() + 1; // Plus receiver. |
4084 switch (id) { | 4091 switch (id) { |
4085 case kStringCharCodeAt: | 4092 case kStringCharCodeAt: |
4093 case kStringCharAt: | |
4086 if (argument_count == 2 && check_type == STRING_CHECK) { | 4094 if (argument_count == 2 && check_type == STRING_CHECK) { |
4087 HValue* index = Pop(); | 4095 HValue* index = Pop(); |
4088 HValue* string = Pop(); | 4096 HValue* string = Pop(); |
4089 ASSERT(!expr->holder().is_null()); | 4097 ASSERT(!expr->holder().is_null()); |
4090 AddInstruction(new HCheckPrototypeMaps( | 4098 AddInstruction(new HCheckPrototypeMaps( |
4091 oracle()->GetPrototypeForPrimitiveCheck(STRING_CHECK), | 4099 oracle()->GetPrototypeForPrimitiveCheck(STRING_CHECK), |
4092 expr->holder())); | 4100 expr->holder())); |
4093 HStringCharCodeAt* result = BuildStringCharCodeAt(string, index); | 4101 HStringCharCodeAt* char_code = BuildStringCharCodeAt(string, index); |
4102 if (id == kStringCharCodeAt) { | |
4103 ast_context()->ReturnInstruction(char_code, expr->id()); | |
4104 return true; | |
4105 } | |
fschneider
2011/03/14 11:34:17
You could save a line by writing:
if (id == kStrin
Vitaly Repeshko
2011/03/14 14:15:50
This would replace "return true" with "} else {".
| |
4106 AddInstruction(char_code); | |
4107 HStringCharFromCode* result = new HStringCharFromCode(char_code); | |
4094 ast_context()->ReturnInstruction(result, expr->id()); | 4108 ast_context()->ReturnInstruction(result, expr->id()); |
4095 return true; | 4109 return true; |
4096 } | 4110 } |
4097 break; | 4111 break; |
4098 case kMathRound: | 4112 case kMathRound: |
4099 case kMathFloor: | 4113 case kMathFloor: |
4100 case kMathAbs: | 4114 case kMathAbs: |
4101 case kMathSqrt: | 4115 case kMathSqrt: |
4102 case kMathLog: | 4116 case kMathLog: |
4103 case kMathSin: | 4117 case kMathSin: |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5169 VISIT_FOR_VALUE(call->arguments()->at(1)); | 5183 VISIT_FOR_VALUE(call->arguments()->at(1)); |
5170 HValue* index = Pop(); | 5184 HValue* index = Pop(); |
5171 HValue* string = Pop(); | 5185 HValue* string = Pop(); |
5172 HStringCharCodeAt* result = BuildStringCharCodeAt(string, index); | 5186 HStringCharCodeAt* result = BuildStringCharCodeAt(string, index); |
5173 ast_context()->ReturnInstruction(result, call->id()); | 5187 ast_context()->ReturnInstruction(result, call->id()); |
5174 } | 5188 } |
5175 | 5189 |
5176 | 5190 |
5177 // Fast support for string.charAt(n) and string[n]. | 5191 // Fast support for string.charAt(n) and string[n]. |
5178 void HGraphBuilder::GenerateStringCharFromCode(CallRuntime* call) { | 5192 void HGraphBuilder::GenerateStringCharFromCode(CallRuntime* call) { |
5179 BAILOUT("inlined runtime function: StringCharFromCode"); | 5193 ASSERT(call->arguments()->length() == 1); |
5194 VISIT_FOR_VALUE(call->arguments()->at(0)); | |
5195 HValue* char_code = Pop(); | |
5196 HStringCharFromCode* result = new HStringCharFromCode(char_code); | |
5197 ast_context()->ReturnInstruction(result, call->id()); | |
5180 } | 5198 } |
5181 | 5199 |
5182 | 5200 |
5183 // Fast support for string.charAt(n) and string[n]. | 5201 // Fast support for string.charAt(n) and string[n]. |
5184 void HGraphBuilder::GenerateStringCharAt(CallRuntime* call) { | 5202 void HGraphBuilder::GenerateStringCharAt(CallRuntime* call) { |
5185 ASSERT_EQ(2, call->arguments()->length()); | 5203 ASSERT(call->arguments()->length() == 2); |
5186 VisitArgumentList(call->arguments()); | 5204 VISIT_FOR_VALUE(call->arguments()->at(0)); |
5187 CHECK_BAILOUT; | 5205 VISIT_FOR_VALUE(call->arguments()->at(1)); |
5188 HContext* context = new HContext; | 5206 HValue* index = Pop(); |
5189 AddInstruction(context); | 5207 HValue* string = Pop(); |
5190 HCallStub* result = new HCallStub(context, CodeStub::StringCharAt, 2); | 5208 HStringCharCodeAt* char_code = BuildStringCharCodeAt(string, index); |
5191 Drop(2); | 5209 AddInstruction(char_code); |
5210 HStringCharFromCode* result = new HStringCharFromCode(char_code); | |
5192 ast_context()->ReturnInstruction(result, call->id()); | 5211 ast_context()->ReturnInstruction(result, call->id()); |
5193 } | 5212 } |
5194 | 5213 |
5195 | 5214 |
5196 // Fast support for object equality testing. | 5215 // Fast support for object equality testing. |
5197 void HGraphBuilder::GenerateObjectEquals(CallRuntime* call) { | 5216 void HGraphBuilder::GenerateObjectEquals(CallRuntime* call) { |
5198 ASSERT(call->arguments()->length() == 2); | 5217 ASSERT(call->arguments()->length() == 2); |
5199 VISIT_FOR_VALUE(call->arguments()->at(0)); | 5218 VISIT_FOR_VALUE(call->arguments()->at(0)); |
5200 VISIT_FOR_VALUE(call->arguments()->at(1)); | 5219 VISIT_FOR_VALUE(call->arguments()->at(1)); |
5201 HValue* right = Pop(); | 5220 HValue* right = Pop(); |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5904 } | 5923 } |
5905 } | 5924 } |
5906 | 5925 |
5907 #ifdef DEBUG | 5926 #ifdef DEBUG |
5908 if (graph_ != NULL) graph_->Verify(); | 5927 if (graph_ != NULL) graph_->Verify(); |
5909 if (allocator_ != NULL) allocator_->Verify(); | 5928 if (allocator_ != NULL) allocator_->Verify(); |
5910 #endif | 5929 #endif |
5911 } | 5930 } |
5912 | 5931 |
5913 } } // namespace v8::internal | 5932 } } // namespace v8::internal |
OLD | NEW |