| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 stub->InitializeInterfaceDescriptor(isolate, descriptor); | 294 stub->InitializeInterfaceDescriptor(isolate, descriptor); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // If we are uninitialized we can use a light-weight stub to enter | 297 // If we are uninitialized we can use a light-weight stub to enter |
| 298 // the runtime that is significantly faster than using the standard | 298 // the runtime that is significantly faster than using the standard |
| 299 // stub-failure deopt mechanism. | 299 // stub-failure deopt mechanism. |
| 300 if (stub->IsUninitialized() && descriptor->has_miss_handler()) { | 300 if (stub->IsUninitialized() && descriptor->has_miss_handler()) { |
| 301 ASSERT(descriptor->stack_parameter_count_ == NULL); | 301 ASSERT(descriptor->stack_parameter_count_ == NULL); |
| 302 return stub->GenerateLightweightMissCode(isolate); | 302 return stub->GenerateLightweightMissCode(isolate); |
| 303 } | 303 } |
| 304 ElapsedTimer timer; |
| 305 if (FLAG_profile_hydrogen_code_stub_compilation) { |
| 306 timer.Start(); |
| 307 } |
| 304 CodeStubGraphBuilder<Stub> builder(isolate, stub); | 308 CodeStubGraphBuilder<Stub> builder(isolate, stub); |
| 305 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 309 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 306 return chunk->Codegen(); | 310 Handle<Code> code = chunk->Codegen(); |
| 311 if (FLAG_profile_hydrogen_code_stub_compilation) { |
| 312 double ms = timer.Elapsed().InMillisecondsF(); |
| 313 PrintF("[Lazy compilation of %s took %0.3f ms]\n", *stub->GetName(), ms); |
| 314 } |
| 315 return code; |
| 307 } | 316 } |
| 308 | 317 |
| 309 | 318 |
| 310 template <> | 319 template <> |
| 311 HValue* CodeStubGraphBuilder<ToNumberStub>::BuildCodeStub() { | 320 HValue* CodeStubGraphBuilder<ToNumberStub>::BuildCodeStub() { |
| 312 HValue* value = GetParameter(0); | 321 HValue* value = GetParameter(0); |
| 313 | 322 |
| 314 // Check if the parameter is already a SMI or heap number. | 323 // Check if the parameter is already a SMI or heap number. |
| 315 IfBuilder if_number(this); | 324 IfBuilder if_number(this); |
| 316 if_number.If<HIsSmiAndBranch>(value); | 325 if_number.If<HIsSmiAndBranch>(value); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 : graph()->GetConstantUndefined(); | 844 : graph()->GetConstantUndefined(); |
| 836 } | 845 } |
| 837 | 846 |
| 838 | 847 |
| 839 Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) { | 848 Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) { |
| 840 return DoGenerateCode(isolate, this); | 849 return DoGenerateCode(isolate, this); |
| 841 } | 850 } |
| 842 | 851 |
| 843 | 852 |
| 844 template <> | 853 template <> |
| 854 HValue* CodeStubGraphBuilder<BinaryOpStub>::BuildCodeInitializedStub() { |
| 855 BinaryOpStub* stub = casted_stub(); |
| 856 HValue* left = GetParameter(0); |
| 857 HValue* right = GetParameter(1); |
| 858 |
| 859 Handle<Type> left_type = stub->GetLeftType(isolate()); |
| 860 Handle<Type> right_type = stub->GetRightType(isolate()); |
| 861 Handle<Type> result_type = stub->GetResultType(isolate()); |
| 862 |
| 863 ASSERT(!left_type->Is(Type::None()) && !right_type->Is(Type::None()) && |
| 864 (stub->HasSideEffects(isolate()) || !result_type->Is(Type::None()))); |
| 865 |
| 866 HValue* result = NULL; |
| 867 if (stub->operation() == Token::ADD && |
| 868 (left_type->Maybe(Type::String()) || right_type->Maybe(Type::String())) && |
| 869 !left_type->Is(Type::String()) && !right_type->Is(Type::String())) { |
| 870 // For the generic add stub a fast case for String add is performance |
| 871 // critical. |
| 872 if (left_type->Maybe(Type::String())) { |
| 873 IfBuilder left_string(this); |
| 874 left_string.IfNot<HIsSmiAndBranch>(left); |
| 875 left_string.AndIf<HIsStringAndBranch>(left); |
| 876 left_string.Then(); |
| 877 Push(Add<HStringAdd>(left, right, STRING_ADD_CHECK_RIGHT)); |
| 878 left_string.Else(); |
| 879 Push(AddInstruction(BuildBinaryOperation(stub->operation(), |
| 880 left, right, left_type, right_type, result_type, |
| 881 stub->fixed_right_arg(), true))); |
| 882 left_string.End(); |
| 883 result = Pop(); |
| 884 } else { |
| 885 IfBuilder right_string(this); |
| 886 right_string.IfNot<HIsSmiAndBranch>(right); |
| 887 right_string.AndIf<HIsStringAndBranch>(right); |
| 888 right_string.Then(); |
| 889 Push(Add<HStringAdd>(left, right, STRING_ADD_CHECK_LEFT)); |
| 890 right_string.Else(); |
| 891 Push(AddInstruction(BuildBinaryOperation(stub->operation(), |
| 892 left, right, left_type, right_type, result_type, |
| 893 stub->fixed_right_arg(), true))); |
| 894 right_string.End(); |
| 895 result = Pop(); |
| 896 } |
| 897 } else { |
| 898 result = AddInstruction(BuildBinaryOperation(stub->operation(), |
| 899 left, right, left_type, right_type, result_type, |
| 900 stub->fixed_right_arg(), true)); |
| 901 } |
| 902 |
| 903 // If we encounter a generic argument, the number conversion is |
| 904 // observable, thus we cannot afford to bail out after the fact. |
| 905 if (!stub->HasSideEffects(isolate())) { |
| 906 if (result_type->Is(Type::Smi())) { |
| 907 if (stub->operation() == Token::SHR) { |
| 908 // TODO(olivf) Replace this by a SmiTagU Instruction. |
| 909 // 0x40000000: this number would convert to negative when interpreting |
| 910 // the register as signed value; |
| 911 IfBuilder if_of(this); |
| 912 if_of.IfNot<HCompareNumericAndBranch>(result, |
| 913 Add<HConstant>(static_cast<int>(SmiValuesAre32Bits() |
| 914 ? 0x80000000 : 0x40000000)), Token::EQ_STRICT); |
| 915 if_of.Then(); |
| 916 if_of.ElseDeopt("UInt->Smi oveflow"); |
| 917 if_of.End(); |
| 918 } |
| 919 } |
| 920 result = EnforceNumberType(result, result_type); |
| 921 } |
| 922 |
| 923 // Reuse the double box if we are allowed to (i.e. chained binops). |
| 924 if (stub->CanReuseDoubleBox()) { |
| 925 HValue* reuse = (stub->mode() == OVERWRITE_LEFT) ? left : right; |
| 926 IfBuilder if_heap_number(this); |
| 927 if_heap_number.IfNot<HIsSmiAndBranch>(reuse); |
| 928 if_heap_number.Then(); |
| 929 HValue* res_val = Add<HForceRepresentation>(result, |
| 930 Representation::Double()); |
| 931 HObjectAccess access = HObjectAccess::ForHeapNumberValue(); |
| 932 Add<HStoreNamedField>(reuse, access, res_val); |
| 933 Push(reuse); |
| 934 if_heap_number.Else(); |
| 935 Push(result); |
| 936 if_heap_number.End(); |
| 937 result = Pop(); |
| 938 } |
| 939 |
| 940 return result; |
| 941 } |
| 942 |
| 943 |
| 944 Handle<Code> BinaryOpStub::GenerateCode(Isolate* isolate) { |
| 945 return DoGenerateCode(isolate, this); |
| 946 } |
| 947 |
| 948 |
| 949 template <> |
| 845 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { | 950 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { |
| 846 ToBooleanStub* stub = casted_stub(); | 951 ToBooleanStub* stub = casted_stub(); |
| 847 | 952 |
| 848 IfBuilder if_true(this); | 953 IfBuilder if_true(this); |
| 849 if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); | 954 if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); |
| 850 if_true.Then(); | 955 if_true.Then(); |
| 851 if_true.Return(graph()->GetConstant1()); | 956 if_true.Return(graph()->GetConstant1()); |
| 852 if_true.Else(); | 957 if_true.Else(); |
| 853 if_true.End(); | 958 if_true.End(); |
| 854 return graph()->GetConstant0(); | 959 return graph()->GetConstant0(); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 return js_function; | 1232 return js_function; |
| 1128 } | 1233 } |
| 1129 | 1234 |
| 1130 | 1235 |
| 1131 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { | 1236 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { |
| 1132 return DoGenerateCode(isolate, this); | 1237 return DoGenerateCode(isolate, this); |
| 1133 } | 1238 } |
| 1134 | 1239 |
| 1135 | 1240 |
| 1136 } } // namespace v8::internal | 1241 } } // namespace v8::internal |
| OLD | NEW |