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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 : graph()->GetConstantUndefined(); | 835 : graph()->GetConstantUndefined(); |
836 } | 836 } |
837 | 837 |
838 | 838 |
839 Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) { | 839 Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) { |
840 return DoGenerateCode(isolate, this); | 840 return DoGenerateCode(isolate, this); |
841 } | 841 } |
842 | 842 |
843 | 843 |
844 template <> | 844 template <> |
845 HValue* CodeStubGraphBuilder<BinaryOpStub>::BuildCodeInitializedStub() { | |
846 BinaryOpStub* stub = casted_stub(); | |
847 HValue* left = GetParameter(0); | |
848 HValue* right = GetParameter(1); | |
849 | |
850 Handle<Type> left_type = stub->GetLeftType(isolate()); | |
851 Handle<Type> right_type = stub->GetRightType(isolate()); | |
852 Handle<Type> result_type = stub->GetResultType(isolate()); | |
853 | |
854 ASSERT(!left_type->Is(Type::None()) && !right_type->Is(Type::None()) && | |
855 (stub->HasSideEffects(isolate()) || !result_type->Is(Type::None()))); | |
856 | |
857 HValue* result = NULL; | |
858 if (stub->operation() == Token::ADD && | |
859 (left_type->Maybe(Type::String()) || right_type->Maybe(Type::String())) && | |
860 !left_type->Is(Type::String()) && !right_type->Is(Type::String())) { | |
861 // For the generic add stub a fast case for String add is performance | |
862 // critical. | |
863 if (left_type->Maybe(Type::String())) { | |
864 IfBuilder left_string(this); | |
865 left_string.IfNot<HIsSmiAndBranch>(left); | |
866 left_string.AndIf<HIsStringAndBranch>(left); | |
867 left_string.Then(); | |
868 Push(Add<HStringAdd>(left, right, STRING_ADD_CHECK_RIGHT)); | |
869 left_string.Else(); | |
870 Push(AddInstruction(BuildBinaryOperation(stub->operation(), | |
871 left, right, left_type, right_type, result_type, | |
872 stub->fixed_right_arg(), true))); | |
873 left_string.End(); | |
874 result = Pop(); | |
875 } else { | |
876 IfBuilder right_string(this); | |
877 right_string.IfNot<HIsSmiAndBranch>(right); | |
878 right_string.AndIf<HIsStringAndBranch>(right); | |
879 right_string.Then(); | |
880 Push(Add<HStringAdd>(left, right, STRING_ADD_CHECK_LEFT)); | |
881 right_string.Else(); | |
882 Push(AddInstruction(BuildBinaryOperation(stub->operation(), | |
883 left, right, left_type, right_type, result_type, | |
884 stub->fixed_right_arg(), true))); | |
885 right_string.End(); | |
886 result = Pop(); | |
887 } | |
888 } else { | |
889 result = AddInstruction(BuildBinaryOperation(stub->operation(), | |
890 left, right, left_type, right_type, result_type, | |
891 stub->fixed_right_arg(), true)); | |
892 } | |
893 | |
894 // If we encounter a generic argument, the number conversion is | |
895 // observable, thus we cannot afford to bail out after the fact. | |
896 if (!stub->HasSideEffects(isolate())) { | |
897 if (result_type->Is(Type::Smi())) { | |
898 if (stub->operation() == Token::SHR) { | |
899 // TODO(olivf) Replace this by a SmiTagU Instruction. | |
900 // 0x40000000: this number would convert to negative when interpreting | |
901 // the register as signed value; | |
902 IfBuilder if_of(this); | |
903 if_of.IfNot<HCompareNumericAndBranch>(result, | |
904 Add<HConstant>(static_cast<int>(0x40000000)), Token::EQ_STRICT); | |
905 if_of.Then(); | |
906 if_of.ElseDeopt("UInt->Smi oveflow"); | |
907 if_of.End(); | |
908 } | |
909 } | |
910 result = EnforceNumberType(result, result_type); | |
911 } | |
912 | |
913 // Reuse the double box if we are allowed to (i.e. chained binops). | |
914 if (stub->CanReuseDoubleBox()) { | |
915 HValue* reuse = (stub->mode() == OVERWRITE_LEFT) ? left : right; | |
916 IfBuilder if_heap_number(this); | |
917 if_heap_number.IfNot<HIsSmiAndBranch>(reuse); | |
918 if_heap_number.Then(); | |
919 HValue* res_val = Add<HForceRepresentation>(result, | |
920 Representation::Double()); | |
921 HObjectAccess access = HObjectAccess::ForHeapNumberValue(); | |
922 Add<HStoreNamedField>(reuse, access, res_val); | |
923 Push(reuse); | |
924 if_heap_number.Else(); | |
925 Push(result); | |
926 if_heap_number.End(); | |
927 result = Pop(); | |
928 } | |
929 | |
930 return result; | |
931 } | |
932 | |
933 | |
934 Handle<Code> BinaryOpStub::GenerateCode(Isolate* isolate) { | |
935 return DoGenerateCode(isolate, this); | |
936 } | |
937 | |
938 | |
939 template <> | |
940 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { | 845 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { |
941 ToBooleanStub* stub = casted_stub(); | 846 ToBooleanStub* stub = casted_stub(); |
942 | 847 |
943 IfBuilder if_true(this); | 848 IfBuilder if_true(this); |
944 if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); | 849 if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); |
945 if_true.Then(); | 850 if_true.Then(); |
946 if_true.Return(graph()->GetConstant1()); | 851 if_true.Return(graph()->GetConstant1()); |
947 if_true.Else(); | 852 if_true.Else(); |
948 if_true.End(); | 853 if_true.End(); |
949 return graph()->GetConstant0(); | 854 return graph()->GetConstant0(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 return js_function; | 1127 return js_function; |
1223 } | 1128 } |
1224 | 1129 |
1225 | 1130 |
1226 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { | 1131 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { |
1227 return DoGenerateCode(isolate, this); | 1132 return DoGenerateCode(isolate, this); |
1228 } | 1133 } |
1229 | 1134 |
1230 | 1135 |
1231 } } // namespace v8::internal | 1136 } } // namespace v8::internal |
OLD | NEW |