| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/crankshaft/hydrogen.h" | 5 #include "src/crankshaft/hydrogen.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "src/allocation-site-scopes.h" | 10 #include "src/allocation-site-scopes.h" |
| (...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 JSIteratorResult::kValueOffset), | 1837 JSIteratorResult::kValueOffset), |
| 1838 value); | 1838 value); |
| 1839 Add<HStoreNamedField>(result, HObjectAccess::ForObservableJSObjectOffset( | 1839 Add<HStoreNamedField>(result, HObjectAccess::ForObservableJSObjectOffset( |
| 1840 JSIteratorResult::kDoneOffset), | 1840 JSIteratorResult::kDoneOffset), |
| 1841 done); | 1841 done); |
| 1842 STATIC_ASSERT(JSIteratorResult::kSize == 5 * kPointerSize); | 1842 STATIC_ASSERT(JSIteratorResult::kSize == 5 * kPointerSize); |
| 1843 return result; | 1843 return result; |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 | 1846 |
| 1847 HValue* HGraphBuilder::BuildRegExpConstructResult(HValue* length, | |
| 1848 HValue* index, | |
| 1849 HValue* input) { | |
| 1850 NoObservableSideEffectsScope scope(this); | |
| 1851 HConstant* max_length = Add<HConstant>(JSArray::kInitialMaxFastElementArray); | |
| 1852 Add<HBoundsCheck>(length, max_length); | |
| 1853 | |
| 1854 // Generate size calculation code here in order to make it dominate | |
| 1855 // the JSRegExpResult allocation. | |
| 1856 ElementsKind elements_kind = FAST_ELEMENTS; | |
| 1857 HValue* size = BuildCalculateElementsSize(elements_kind, length); | |
| 1858 | |
| 1859 // Allocate the JSRegExpResult and the FixedArray in one step. | |
| 1860 HValue* result = | |
| 1861 Add<HAllocate>(Add<HConstant>(JSRegExpResult::kSize), HType::JSArray(), | |
| 1862 NOT_TENURED, JS_ARRAY_TYPE, graph()->GetConstant0()); | |
| 1863 | |
| 1864 // Initialize the JSRegExpResult header. | |
| 1865 HValue* native_context = Add<HLoadNamedField>( | |
| 1866 context(), nullptr, | |
| 1867 HObjectAccess::ForContextSlot(Context::NATIVE_CONTEXT_INDEX)); | |
| 1868 Add<HStoreNamedField>( | |
| 1869 result, HObjectAccess::ForMap(), | |
| 1870 Add<HLoadNamedField>( | |
| 1871 native_context, nullptr, | |
| 1872 HObjectAccess::ForContextSlot(Context::REGEXP_RESULT_MAP_INDEX))); | |
| 1873 HConstant* empty_fixed_array = | |
| 1874 Add<HConstant>(isolate()->factory()->empty_fixed_array()); | |
| 1875 Add<HStoreNamedField>( | |
| 1876 result, HObjectAccess::ForJSArrayOffset(JSArray::kPropertiesOffset), | |
| 1877 empty_fixed_array); | |
| 1878 Add<HStoreNamedField>( | |
| 1879 result, HObjectAccess::ForJSArrayOffset(JSArray::kElementsOffset), | |
| 1880 empty_fixed_array); | |
| 1881 Add<HStoreNamedField>( | |
| 1882 result, HObjectAccess::ForJSArrayOffset(JSArray::kLengthOffset), length); | |
| 1883 | |
| 1884 // Initialize the additional fields. | |
| 1885 Add<HStoreNamedField>( | |
| 1886 result, HObjectAccess::ForJSArrayOffset(JSRegExpResult::kIndexOffset), | |
| 1887 index); | |
| 1888 Add<HStoreNamedField>( | |
| 1889 result, HObjectAccess::ForJSArrayOffset(JSRegExpResult::kInputOffset), | |
| 1890 input); | |
| 1891 | |
| 1892 // Allocate and initialize the elements header. | |
| 1893 HAllocate* elements = BuildAllocateElements(elements_kind, size); | |
| 1894 BuildInitializeElementsHeader(elements, elements_kind, length); | |
| 1895 | |
| 1896 Add<HStoreNamedField>( | |
| 1897 result, HObjectAccess::ForJSArrayOffset(JSArray::kElementsOffset), | |
| 1898 elements); | |
| 1899 | |
| 1900 // Initialize the elements contents with undefined. | |
| 1901 BuildFillElementsWithValue( | |
| 1902 elements, elements_kind, graph()->GetConstant0(), length, | |
| 1903 graph()->GetConstantUndefined()); | |
| 1904 | |
| 1905 return result; | |
| 1906 } | |
| 1907 | |
| 1908 HValue* HGraphBuilder::BuildNumberToString(HValue* object, AstType* type) { | 1847 HValue* HGraphBuilder::BuildNumberToString(HValue* object, AstType* type) { |
| 1909 NoObservableSideEffectsScope scope(this); | 1848 NoObservableSideEffectsScope scope(this); |
| 1910 | 1849 |
| 1911 // Convert constant numbers at compile time. | 1850 // Convert constant numbers at compile time. |
| 1912 if (object->IsConstant() && HConstant::cast(object)->HasNumberValue()) { | 1851 if (object->IsConstant() && HConstant::cast(object)->HasNumberValue()) { |
| 1913 Handle<Object> number = HConstant::cast(object)->handle(isolate()); | 1852 Handle<Object> number = HConstant::cast(object)->handle(isolate()); |
| 1914 Handle<String> result = isolate()->factory()->NumberToString(number); | 1853 Handle<String> result = isolate()->factory()->NumberToString(number); |
| 1915 return Add<HConstant>(result); | 1854 return Add<HConstant>(result); |
| 1916 } | 1855 } |
| 1917 | 1856 |
| (...skipping 10243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12161 HValue* subject = Pop(); | 12100 HValue* subject = Pop(); |
| 12162 HValue* regexp_object = Pop(); | 12101 HValue* regexp_object = Pop(); |
| 12163 HValue* stub = Add<HConstant>(callable.code()); | 12102 HValue* stub = Add<HConstant>(callable.code()); |
| 12164 HValue* values[] = {regexp_object, subject, index, last_match_info}; | 12103 HValue* values[] = {regexp_object, subject, index, last_match_info}; |
| 12165 HInstruction* result = New<HCallWithDescriptor>( | 12104 HInstruction* result = New<HCallWithDescriptor>( |
| 12166 stub, 0, callable.descriptor(), ArrayVector(values)); | 12105 stub, 0, callable.descriptor(), ArrayVector(values)); |
| 12167 return ast_context()->ReturnInstruction(result, call->id()); | 12106 return ast_context()->ReturnInstruction(result, call->id()); |
| 12168 } | 12107 } |
| 12169 | 12108 |
| 12170 | 12109 |
| 12171 void HOptimizedGraphBuilder::GenerateRegExpFlags(CallRuntime* call) { | |
| 12172 DCHECK_EQ(1, call->arguments()->length()); | |
| 12173 CHECK_ALIVE(VisitExpressions(call->arguments())); | |
| 12174 HValue* regexp = Pop(); | |
| 12175 HInstruction* result = | |
| 12176 New<HLoadNamedField>(regexp, nullptr, HObjectAccess::ForJSRegExpFlags()); | |
| 12177 return ast_context()->ReturnInstruction(result, call->id()); | |
| 12178 } | |
| 12179 | |
| 12180 | |
| 12181 void HOptimizedGraphBuilder::GenerateRegExpSource(CallRuntime* call) { | |
| 12182 DCHECK_EQ(1, call->arguments()->length()); | |
| 12183 CHECK_ALIVE(VisitExpressions(call->arguments())); | |
| 12184 HValue* regexp = Pop(); | |
| 12185 HInstruction* result = | |
| 12186 New<HLoadNamedField>(regexp, nullptr, HObjectAccess::ForJSRegExpSource()); | |
| 12187 return ast_context()->ReturnInstruction(result, call->id()); | |
| 12188 } | |
| 12189 | |
| 12190 | |
| 12191 // Construct a RegExp exec result with two in-object properties. | |
| 12192 void HOptimizedGraphBuilder::GenerateRegExpConstructResult(CallRuntime* call) { | |
| 12193 DCHECK_EQ(3, call->arguments()->length()); | |
| 12194 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | |
| 12195 CHECK_ALIVE(VisitForValue(call->arguments()->at(1))); | |
| 12196 CHECK_ALIVE(VisitForValue(call->arguments()->at(2))); | |
| 12197 HValue* input = Pop(); | |
| 12198 HValue* index = Pop(); | |
| 12199 HValue* length = Pop(); | |
| 12200 HValue* result = BuildRegExpConstructResult(length, index, input); | |
| 12201 return ast_context()->ReturnValue(result); | |
| 12202 } | |
| 12203 | |
| 12204 | |
| 12205 // Fast support for number to string. | 12110 // Fast support for number to string. |
| 12206 void HOptimizedGraphBuilder::GenerateNumberToString(CallRuntime* call) { | 12111 void HOptimizedGraphBuilder::GenerateNumberToString(CallRuntime* call) { |
| 12207 DCHECK_EQ(1, call->arguments()->length()); | 12112 DCHECK_EQ(1, call->arguments()->length()); |
| 12208 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 12113 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
| 12209 HValue* number = Pop(); | 12114 HValue* number = Pop(); |
| 12210 HValue* result = BuildNumberToString(number, AstType::Any()); | 12115 HValue* result = BuildNumberToString(number, AstType::Any()); |
| 12211 return ast_context()->ReturnValue(result); | 12116 return ast_context()->ReturnValue(result); |
| 12212 } | 12117 } |
| 12213 | 12118 |
| 12214 | 12119 |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13082 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 12987 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 13083 } | 12988 } |
| 13084 | 12989 |
| 13085 #ifdef DEBUG | 12990 #ifdef DEBUG |
| 13086 graph_->Verify(false); // No full verify. | 12991 graph_->Verify(false); // No full verify. |
| 13087 #endif | 12992 #endif |
| 13088 } | 12993 } |
| 13089 | 12994 |
| 13090 } // namespace internal | 12995 } // namespace internal |
| 13091 } // namespace v8 | 12996 } // namespace v8 |
| OLD | NEW |