OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/code-stub-assembler.h" | 4 #include "src/code-stub-assembler.h" |
5 #include "src/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/frames-inl.h" | 6 #include "src/frames-inl.h" |
7 #include "src/frames.h" | 7 #include "src/frames.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 Node* CodeStubAssembler::IntPtrOrSmiConstant(int value, ParameterMode mode) { | 165 Node* CodeStubAssembler::IntPtrOrSmiConstant(int value, ParameterMode mode) { |
166 if (mode == SMI_PARAMETERS) { | 166 if (mode == SMI_PARAMETERS) { |
167 return SmiConstant(Smi::FromInt(value)); | 167 return SmiConstant(Smi::FromInt(value)); |
168 } else { | 168 } else { |
169 DCHECK_EQ(INTPTR_PARAMETERS, mode); | 169 DCHECK_EQ(INTPTR_PARAMETERS, mode); |
170 return IntPtrConstant(value); | 170 return IntPtrConstant(value); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
| 174 bool CodeStubAssembler::IsIntPtrOrSmiConstantZero(Node* test) { |
| 175 int32_t constant_test; |
| 176 Smi* smi_test; |
| 177 if ((ToInt32Constant(test, constant_test) && constant_test == 0) || |
| 178 (ToSmiConstant(test, smi_test) && smi_test->value() == 0)) { |
| 179 return true; |
| 180 } |
| 181 return false; |
| 182 } |
| 183 |
174 Node* CodeStubAssembler::IntPtrRoundUpToPowerOfTwo32(Node* value) { | 184 Node* CodeStubAssembler::IntPtrRoundUpToPowerOfTwo32(Node* value) { |
175 Comment("IntPtrRoundUpToPowerOfTwo32"); | 185 Comment("IntPtrRoundUpToPowerOfTwo32"); |
176 CSA_ASSERT(this, UintPtrLessThanOrEqual(value, IntPtrConstant(0x80000000u))); | 186 CSA_ASSERT(this, UintPtrLessThanOrEqual(value, IntPtrConstant(0x80000000u))); |
177 value = IntPtrSub(value, IntPtrConstant(1)); | 187 value = IntPtrSub(value, IntPtrConstant(1)); |
178 for (int i = 1; i <= 16; i *= 2) { | 188 for (int i = 1; i <= 16; i *= 2) { |
179 value = WordOr(value, WordShr(value, IntPtrConstant(i))); | 189 value = WordOr(value, WordShr(value, IntPtrConstant(i))); |
180 } | 190 } |
181 return IntPtrAdd(value, IntPtrConstant(1)); | 191 return IntPtrAdd(value, IntPtrConstant(1)); |
182 } | 192 } |
183 | 193 |
(...skipping 1871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 InitializeAllocationMemento(array, JSArray::kSize, allocation_site); | 2065 InitializeAllocationMemento(array, JSArray::kSize, allocation_site); |
2056 } | 2066 } |
2057 return array; | 2067 return array; |
2058 } | 2068 } |
2059 | 2069 |
2060 Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map, | 2070 Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map, |
2061 Node* capacity, Node* length, | 2071 Node* capacity, Node* length, |
2062 Node* allocation_site, | 2072 Node* allocation_site, |
2063 ParameterMode capacity_mode) { | 2073 ParameterMode capacity_mode) { |
2064 Node *array = nullptr, *elements = nullptr; | 2074 Node *array = nullptr, *elements = nullptr; |
2065 int32_t constant_capacity; | 2075 if (IsIntPtrOrSmiConstantZero(capacity)) { |
2066 if (ToInt32Constant(capacity, constant_capacity) && constant_capacity == 0) { | |
2067 // Array is empty. Use the shared empty fixed array instead of allocating a | 2076 // Array is empty. Use the shared empty fixed array instead of allocating a |
2068 // new one. | 2077 // new one. |
2069 array = AllocateUninitializedJSArrayWithoutElements(kind, array_map, length, | 2078 array = AllocateUninitializedJSArrayWithoutElements(kind, array_map, length, |
2070 nullptr); | 2079 nullptr); |
2071 StoreObjectFieldRoot(array, JSArray::kElementsOffset, | 2080 StoreObjectFieldRoot(array, JSArray::kElementsOffset, |
2072 Heap::kEmptyFixedArrayRootIndex); | 2081 Heap::kEmptyFixedArrayRootIndex); |
2073 } else { | 2082 } else { |
2074 // Allocate both array and elements object, and initialize the JSArray. | 2083 // Allocate both array and elements object, and initialize the JSArray. |
2075 std::tie(array, elements) = AllocateUninitializedJSArrayWithElements( | 2084 std::tie(array, elements) = AllocateUninitializedJSArrayWithElements( |
2076 kind, array_map, length, allocation_site, capacity, capacity_mode); | 2085 kind, array_map, length, allocation_site, capacity, capacity_mode); |
(...skipping 6311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8388 formatted.c_str(), TENURED); | 8397 formatted.c_str(), TENURED); |
8389 CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), | 8398 CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), |
8390 HeapConstant(string)); | 8399 HeapConstant(string)); |
8391 } | 8400 } |
8392 CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), tagged_value); | 8401 CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), tagged_value); |
8393 #endif | 8402 #endif |
8394 } | 8403 } |
8395 | 8404 |
8396 } // namespace internal | 8405 } // namespace internal |
8397 } // namespace v8 | 8406 } // namespace v8 |
OLD | NEW |