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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 : graph()->GetConstantUndefined(); | 844 : graph()->GetConstantUndefined(); |
845 } | 845 } |
846 | 846 |
847 | 847 |
848 Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) { | 848 Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) { |
849 return DoGenerateCode(isolate, this); | 849 return DoGenerateCode(isolate, this); |
850 } | 850 } |
851 | 851 |
852 | 852 |
853 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 <> |
854 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { | 950 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { |
855 ToBooleanStub* stub = casted_stub(); | 951 ToBooleanStub* stub = casted_stub(); |
856 | 952 |
857 IfBuilder if_true(this); | 953 IfBuilder if_true(this); |
858 if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); | 954 if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); |
859 if_true.Then(); | 955 if_true.Then(); |
860 if_true.Return(graph()->GetConstant1()); | 956 if_true.Return(graph()->GetConstant1()); |
861 if_true.Else(); | 957 if_true.Else(); |
862 if_true.End(); | 958 if_true.End(); |
863 return graph()->GetConstant0(); | 959 return graph()->GetConstant0(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 return js_function; | 1232 return js_function; |
1137 } | 1233 } |
1138 | 1234 |
1139 | 1235 |
1140 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { | 1236 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { |
1141 return DoGenerateCode(isolate, this); | 1237 return DoGenerateCode(isolate, this); |
1142 } | 1238 } |
1143 | 1239 |
1144 | 1240 |
1145 } } // namespace v8::internal | 1241 } } // namespace v8::internal |
OLD | NEW |