Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: src/code-stub-assembler.cc

Issue 2407813002: [stubs] Port StringAddStub to TF (Closed)
Patch Set: Remove printf Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4
5 #include "src/code-stub-assembler.h" 5 #include "src/code-stub-assembler.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/frames-inl.h" 7 #include "src/frames-inl.h"
8 #include "src/frames.h" 8 #include "src/frames.h"
9 #include "src/ic/handler-configuration.h" 9 #include "src/ic/handler-configuration.h"
10 #include "src/ic/stub-cache.h" 10 #include "src/ic/stub-cache.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 Node* CodeStubAssembler::IntPtrOrSmiConstant(int value, ParameterMode mode) { 83 Node* CodeStubAssembler::IntPtrOrSmiConstant(int value, ParameterMode mode) {
84 if (mode == SMI_PARAMETERS) { 84 if (mode == SMI_PARAMETERS) {
85 return SmiConstant(Smi::FromInt(value)); 85 return SmiConstant(Smi::FromInt(value));
86 } else { 86 } else {
87 DCHECK(mode == INTEGER_PARAMETERS || mode == INTPTR_PARAMETERS); 87 DCHECK(mode == INTEGER_PARAMETERS || mode == INTPTR_PARAMETERS);
88 return IntPtrConstant(value); 88 return IntPtrConstant(value);
89 } 89 }
90 } 90 }
91 91
92 Node* CodeStubAssembler::IntPtrAddFoldConstants(Node* left, Node* right) {
93 int32_t left_constant;
94 bool is_left_constant = ToInt32Constant(left, left_constant);
95 int32_t right_constant;
96 bool is_right_constant = ToInt32Constant(right, right_constant);
97 if (is_left_constant) {
98 if (is_right_constant) {
99 return IntPtrConstant(left_constant + right_constant);
100 }
101 if (left_constant == 0) {
102 return right;
103 }
104 } else if (is_right_constant) {
105 if (right_constant == 0) {
106 return left;
107 }
108 }
109 return IntPtrAdd(left, right);
110 }
111
112 Node* CodeStubAssembler::IntPtrSubFoldConstants(Node* left, Node* right) {
113 int32_t left_constant;
114 bool is_left_constant = ToInt32Constant(left, left_constant);
115 int32_t right_constant;
116 bool is_right_constant = ToInt32Constant(right, right_constant);
117 if (is_left_constant) {
118 if (is_right_constant) {
119 return IntPtrConstant(left_constant - right_constant);
120 }
121 } else if (is_right_constant) {
122 if (right_constant == 0) {
123 return left;
124 }
125 }
126 return IntPtrSub(left, right);
127 }
128
92 Node* CodeStubAssembler::Float64Round(Node* x) { 129 Node* CodeStubAssembler::Float64Round(Node* x) {
93 Node* one = Float64Constant(1.0); 130 Node* one = Float64Constant(1.0);
94 Node* one_half = Float64Constant(0.5); 131 Node* one_half = Float64Constant(0.5);
95 132
96 Variable var_x(this, MachineRepresentation::kFloat64); 133 Variable var_x(this, MachineRepresentation::kFloat64);
97 Label return_x(this); 134 Label return_x(this);
98 135
99 // Round up {x} towards Infinity. 136 // Round up {x} towards Infinity.
100 var_x.Bind(Float64Ceil(x)); 137 var_x.Bind(Float64Ceil(x));
101 138
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 return result; 1253 return result;
1217 } 1254 }
1218 1255
1219 Node* CodeStubAssembler::AllocateHeapNumberWithValue(Node* value, 1256 Node* CodeStubAssembler::AllocateHeapNumberWithValue(Node* value,
1220 MutableMode mode) { 1257 MutableMode mode) {
1221 Node* result = AllocateHeapNumber(mode); 1258 Node* result = AllocateHeapNumber(mode);
1222 StoreHeapNumberValue(result, value); 1259 StoreHeapNumberValue(result, value);
1223 return result; 1260 return result;
1224 } 1261 }
1225 1262
1226 Node* CodeStubAssembler::AllocateSeqOneByteString(int length) { 1263 Node* CodeStubAssembler::AllocateSeqOneByteString(int length,
1227 Node* result = Allocate(SeqOneByteString::SizeFor(length)); 1264 AllocationFlags flags) {
1265 Comment("AllocateSeqOneByteString");
1266 Node* result = Allocate(SeqOneByteString::SizeFor(length), flags);
1267 DCHECK(Heap::RootIsImmortalImmovable(Heap::kOneByteStringMapRootIndex));
1228 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kOneByteStringMapRootIndex)); 1268 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kOneByteStringMapRootIndex));
1229 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kLengthOffset, 1269 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kLengthOffset,
1230 SmiConstant(Smi::FromInt(length))); 1270 SmiConstant(Smi::FromInt(length)));
1231 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kHashFieldOffset, 1271 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kHashFieldOffset,
1232 IntPtrConstant(String::kEmptyHashField), 1272 IntPtrConstant(String::kEmptyHashField),
1233 MachineRepresentation::kWord32); 1273 MachineRepresentation::kWord32);
1234 return result; 1274 return result;
1235 } 1275 }
1236 1276
1237 Node* CodeStubAssembler::AllocateSeqOneByteString(Node* context, Node* length) { 1277 Node* CodeStubAssembler::AllocateSeqOneByteString(Node* context, Node* length,
1278 ParameterMode mode,
1279 AllocationFlags flags) {
1280 Comment("AllocateSeqOneByteString");
1238 Variable var_result(this, MachineRepresentation::kTagged); 1281 Variable var_result(this, MachineRepresentation::kTagged);
1239 1282
1240 // Compute the SeqOneByteString size and check if it fits into new space. 1283 // Compute the SeqOneByteString size and check if it fits into new space.
1241 Label if_sizeissmall(this), if_notsizeissmall(this, Label::kDeferred), 1284 Label if_sizeissmall(this), if_notsizeissmall(this, Label::kDeferred),
1242 if_join(this); 1285 if_join(this);
1243 Node* size = WordAnd( 1286 Node* raw_size = GetArrayAllocationSize(
1244 IntPtrAdd( 1287 length, UINT8_ELEMENTS, mode,
1245 IntPtrAdd(length, IntPtrConstant(SeqOneByteString::kHeaderSize)), 1288 SeqOneByteString::kHeaderSize + kObjectAlignmentMask);
1246 IntPtrConstant(kObjectAlignmentMask)), 1289 Node* size = WordAnd(raw_size, IntPtrConstant(~kObjectAlignmentMask));
1247 IntPtrConstant(~kObjectAlignmentMask));
1248 Branch(IntPtrLessThanOrEqual(size, IntPtrConstant(kMaxRegularHeapObjectSize)), 1290 Branch(IntPtrLessThanOrEqual(size, IntPtrConstant(kMaxRegularHeapObjectSize)),
1249 &if_sizeissmall, &if_notsizeissmall); 1291 &if_sizeissmall, &if_notsizeissmall);
1250 1292
1251 Bind(&if_sizeissmall); 1293 Bind(&if_sizeissmall);
1252 { 1294 {
1253 // Just allocate the SeqOneByteString in new space. 1295 // Just allocate the SeqOneByteString in new space.
1254 Node* result = Allocate(size); 1296 Node* result = Allocate(size, flags);
1297 DCHECK(Heap::RootIsImmortalImmovable(Heap::kOneByteStringMapRootIndex));
1255 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kOneByteStringMapRootIndex)); 1298 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kOneByteStringMapRootIndex));
1256 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kLengthOffset, 1299 StoreObjectFieldNoWriteBarrier(
1257 SmiFromWord(length)); 1300 result, SeqOneByteString::kLengthOffset,
1301 mode == SMI_PARAMETERS ? length : SmiFromWord(length));
1258 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kHashFieldOffset, 1302 StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kHashFieldOffset,
1259 IntPtrConstant(String::kEmptyHashField), 1303 IntPtrConstant(String::kEmptyHashField),
1260 MachineRepresentation::kWord32); 1304 MachineRepresentation::kWord32);
1261 var_result.Bind(result); 1305 var_result.Bind(result);
1262 Goto(&if_join); 1306 Goto(&if_join);
1263 } 1307 }
1264 1308
1265 Bind(&if_notsizeissmall); 1309 Bind(&if_notsizeissmall);
1266 { 1310 {
1267 // We might need to allocate in large object space, go to the runtime. 1311 // We might need to allocate in large object space, go to the runtime.
1268 Node* result = CallRuntime(Runtime::kAllocateSeqOneByteString, context, 1312 Node* result =
1269 SmiFromWord(length)); 1313 CallRuntime(Runtime::kAllocateSeqOneByteString, context,
1314 mode == SMI_PARAMETERS ? length : SmiFromWord(length));
1270 var_result.Bind(result); 1315 var_result.Bind(result);
1271 Goto(&if_join); 1316 Goto(&if_join);
1272 } 1317 }
1273 1318
1274 Bind(&if_join); 1319 Bind(&if_join);
1275 return var_result.value(); 1320 return var_result.value();
1276 } 1321 }
1277 1322
1278 Node* CodeStubAssembler::AllocateSeqTwoByteString(int length) { 1323 Node* CodeStubAssembler::AllocateSeqTwoByteString(int length,
1279 Node* result = Allocate(SeqTwoByteString::SizeFor(length)); 1324 AllocationFlags flags) {
1325 Comment("AllocateSeqTwoByteString");
1326 Node* result = Allocate(SeqTwoByteString::SizeFor(length), flags);
1327 DCHECK(Heap::RootIsImmortalImmovable(Heap::kStringMapRootIndex));
1280 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kStringMapRootIndex)); 1328 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kStringMapRootIndex));
1281 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kLengthOffset, 1329 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kLengthOffset,
1282 SmiConstant(Smi::FromInt(length))); 1330 SmiConstant(Smi::FromInt(length)));
1283 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kHashFieldOffset, 1331 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kHashFieldOffset,
1284 IntPtrConstant(String::kEmptyHashField), 1332 IntPtrConstant(String::kEmptyHashField),
1285 MachineRepresentation::kWord32); 1333 MachineRepresentation::kWord32);
1286 return result; 1334 return result;
1287 } 1335 }
1288 1336
1289 Node* CodeStubAssembler::AllocateSeqTwoByteString(Node* context, Node* length) { 1337 Node* CodeStubAssembler::AllocateSeqTwoByteString(Node* context, Node* length,
1338 ParameterMode mode,
1339 AllocationFlags flags) {
1340 Comment("AllocateSeqTwoByteString");
1290 Variable var_result(this, MachineRepresentation::kTagged); 1341 Variable var_result(this, MachineRepresentation::kTagged);
1291 1342
1292 // Compute the SeqTwoByteString size and check if it fits into new space. 1343 // Compute the SeqTwoByteString size and check if it fits into new space.
1293 Label if_sizeissmall(this), if_notsizeissmall(this, Label::kDeferred), 1344 Label if_sizeissmall(this), if_notsizeissmall(this, Label::kDeferred),
1294 if_join(this); 1345 if_join(this);
1295 Node* size = WordAnd( 1346 Node* raw_size = GetArrayAllocationSize(
1296 IntPtrAdd(IntPtrAdd(WordShl(length, 1), 1347 length, UINT16_ELEMENTS, mode,
1297 IntPtrConstant(SeqTwoByteString::kHeaderSize)), 1348 SeqOneByteString::kHeaderSize + kObjectAlignmentMask);
1298 IntPtrConstant(kObjectAlignmentMask)), 1349 Node* size = WordAnd(raw_size, IntPtrConstant(~kObjectAlignmentMask));
1299 IntPtrConstant(~kObjectAlignmentMask));
1300 Branch(IntPtrLessThanOrEqual(size, IntPtrConstant(kMaxRegularHeapObjectSize)), 1350 Branch(IntPtrLessThanOrEqual(size, IntPtrConstant(kMaxRegularHeapObjectSize)),
1301 &if_sizeissmall, &if_notsizeissmall); 1351 &if_sizeissmall, &if_notsizeissmall);
1302 1352
1303 Bind(&if_sizeissmall); 1353 Bind(&if_sizeissmall);
1304 { 1354 {
1305 // Just allocate the SeqTwoByteString in new space. 1355 // Just allocate the SeqTwoByteString in new space.
1306 Node* result = Allocate(size); 1356 Node* result = Allocate(size, flags);
1357 DCHECK(Heap::RootIsImmortalImmovable(Heap::kStringMapRootIndex));
1307 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kStringMapRootIndex)); 1358 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kStringMapRootIndex));
1308 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kLengthOffset, 1359 StoreObjectFieldNoWriteBarrier(
1309 SmiFromWord(length)); 1360 result, SeqTwoByteString::kLengthOffset,
1361 mode == SMI_PARAMETERS ? length : SmiFromWord(length));
1310 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kHashFieldOffset, 1362 StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kHashFieldOffset,
1311 IntPtrConstant(String::kEmptyHashField), 1363 IntPtrConstant(String::kEmptyHashField),
1312 MachineRepresentation::kWord32); 1364 MachineRepresentation::kWord32);
1313 var_result.Bind(result); 1365 var_result.Bind(result);
1314 Goto(&if_join); 1366 Goto(&if_join);
1315 } 1367 }
1316 1368
1317 Bind(&if_notsizeissmall); 1369 Bind(&if_notsizeissmall);
1318 { 1370 {
1319 // We might need to allocate in large object space, go to the runtime. 1371 // We might need to allocate in large object space, go to the runtime.
1320 Node* result = CallRuntime(Runtime::kAllocateSeqTwoByteString, context, 1372 Node* result =
1321 SmiFromWord(length)); 1373 CallRuntime(Runtime::kAllocateSeqTwoByteString, context,
1374 mode == SMI_PARAMETERS ? length : SmiFromWord(length));
1322 var_result.Bind(result); 1375 var_result.Bind(result);
1323 Goto(&if_join); 1376 Goto(&if_join);
1324 } 1377 }
1325 1378
1326 Bind(&if_join); 1379 Bind(&if_join);
1327 return var_result.value(); 1380 return var_result.value();
1328 } 1381 }
1329 1382
1330 Node* CodeStubAssembler::AllocateSlicedOneByteString(Node* length, Node* parent, 1383 Node* CodeStubAssembler::AllocateSlicedOneByteString(Node* length, Node* parent,
1331 Node* offset) { 1384 Node* offset) {
1332 Node* result = Allocate(SlicedString::kSize); 1385 Node* result = Allocate(SlicedString::kSize);
1333 Node* map = LoadRoot(Heap::kSlicedOneByteStringMapRootIndex); 1386 Node* map = LoadRoot(Heap::kSlicedOneByteStringMapRootIndex);
1334 StoreMapNoWriteBarrier(result, map); 1387 StoreMapNoWriteBarrier(result, map);
1335 StoreObjectFieldNoWriteBarrier(result, SlicedString::kLengthOffset, length, 1388 StoreObjectFieldNoWriteBarrier(result, SlicedString::kLengthOffset, length,
1336 MachineRepresentation::kTagged); 1389 MachineRepresentation::kTagged);
1337 StoreObjectFieldNoWriteBarrier(result, SlicedString::kHashFieldOffset, 1390 StoreObjectFieldNoWriteBarrier(result, SlicedString::kHashFieldOffset,
1338 Int32Constant(String::kEmptyHashField), 1391 Int32Constant(String::kEmptyHashField),
1339 MachineRepresentation::kWord32); 1392 MachineRepresentation::kWord32);
1340 StoreObjectFieldNoWriteBarrier(result, SlicedString::kParentOffset, parent, 1393 StoreObjectFieldNoWriteBarrier(result, SlicedString::kParentOffset, parent,
1341 MachineRepresentation::kTagged); 1394 MachineRepresentation::kTagged);
1342 StoreObjectFieldNoWriteBarrier(result, SlicedString::kOffsetOffset, offset, 1395 StoreObjectFieldNoWriteBarrier(result, SlicedString::kOffsetOffset, offset,
1343 MachineRepresentation::kTagged); 1396 MachineRepresentation::kTagged);
1344 return result; 1397 return result;
1345 } 1398 }
1346 1399
1347 Node* CodeStubAssembler::AllocateSlicedTwoByteString(Node* length, Node* parent, 1400 Node* CodeStubAssembler::AllocateSlicedTwoByteString(Node* length, Node* parent,
1348 Node* offset) { 1401 Node* offset) {
1402 CSA_ASSERT(TaggedIsSmi(length));
1349 Node* result = Allocate(SlicedString::kSize); 1403 Node* result = Allocate(SlicedString::kSize);
1350 Node* map = LoadRoot(Heap::kSlicedStringMapRootIndex); 1404 Node* map = LoadRoot(Heap::kSlicedStringMapRootIndex);
1351 StoreMapNoWriteBarrier(result, map); 1405 StoreMapNoWriteBarrier(result, map);
1352 StoreObjectFieldNoWriteBarrier(result, SlicedString::kLengthOffset, length, 1406 StoreObjectFieldNoWriteBarrier(result, SlicedString::kLengthOffset, length,
1353 MachineRepresentation::kTagged); 1407 MachineRepresentation::kTagged);
1354 StoreObjectFieldNoWriteBarrier(result, SlicedString::kHashFieldOffset, 1408 StoreObjectFieldNoWriteBarrier(result, SlicedString::kHashFieldOffset,
1355 Int32Constant(String::kEmptyHashField), 1409 Int32Constant(String::kEmptyHashField),
1356 MachineRepresentation::kWord32); 1410 MachineRepresentation::kWord32);
1357 StoreObjectFieldNoWriteBarrier(result, SlicedString::kParentOffset, parent, 1411 StoreObjectFieldNoWriteBarrier(result, SlicedString::kParentOffset, parent,
1358 MachineRepresentation::kTagged); 1412 MachineRepresentation::kTagged);
1359 StoreObjectFieldNoWriteBarrier(result, SlicedString::kOffsetOffset, offset, 1413 StoreObjectFieldNoWriteBarrier(result, SlicedString::kOffsetOffset, offset,
1360 MachineRepresentation::kTagged); 1414 MachineRepresentation::kTagged);
1361 return result; 1415 return result;
1362 } 1416 }
1363 1417
1364 Node* CodeStubAssembler::AllocateOneByteConsString(Node* length, Node* first, 1418 Node* CodeStubAssembler::AllocateOneByteConsString(Node* length, Node* first,
1365 Node* second) { 1419 Node* second,
1366 Node* result = Allocate(ConsString::kSize); 1420 AllocationFlags flags) {
1421 CSA_ASSERT(TaggedIsSmi(length));
1422 Node* result = Allocate(ConsString::kSize, flags);
1367 Node* map = LoadRoot(Heap::kConsOneByteStringMapRootIndex); 1423 Node* map = LoadRoot(Heap::kConsOneByteStringMapRootIndex);
1424 DCHECK(Heap::RootIsImmortalImmovable(Heap::kConsOneByteStringMapRootIndex));
1368 StoreMapNoWriteBarrier(result, map); 1425 StoreMapNoWriteBarrier(result, map);
1369 StoreObjectFieldNoWriteBarrier(result, ConsString::kLengthOffset, length, 1426 StoreObjectFieldNoWriteBarrier(result, ConsString::kLengthOffset, length,
1370 MachineRepresentation::kTagged); 1427 MachineRepresentation::kTagged);
1371 StoreObjectFieldNoWriteBarrier(result, ConsString::kHashFieldOffset, 1428 StoreObjectFieldNoWriteBarrier(result, ConsString::kHashFieldOffset,
1372 Int32Constant(String::kEmptyHashField), 1429 Int32Constant(String::kEmptyHashField),
1373 MachineRepresentation::kWord32); 1430 MachineRepresentation::kWord32);
1374 StoreObjectFieldNoWriteBarrier(result, ConsString::kFirstOffset, first, 1431 bool const new_space = !(flags & kPretenured);
1375 MachineRepresentation::kTagged); 1432 if (new_space) {
1376 StoreObjectFieldNoWriteBarrier(result, ConsString::kSecondOffset, second, 1433 StoreObjectFieldNoWriteBarrier(result, ConsString::kFirstOffset, first,
1377 MachineRepresentation::kTagged); 1434 MachineRepresentation::kTagged);
1435 StoreObjectFieldNoWriteBarrier(result, ConsString::kSecondOffset, second,
1436 MachineRepresentation::kTagged);
1437 } else {
1438 StoreObjectField(result, ConsString::kFirstOffset, first);
1439 StoreObjectField(result, ConsString::kSecondOffset, second);
1440 }
1378 return result; 1441 return result;
1379 } 1442 }
1380 1443
1381 Node* CodeStubAssembler::AllocateTwoByteConsString(Node* length, Node* first, 1444 Node* CodeStubAssembler::AllocateTwoByteConsString(Node* length, Node* first,
1382 Node* second) { 1445 Node* second,
1383 Node* result = Allocate(ConsString::kSize); 1446 AllocationFlags flags) {
1447 CSA_ASSERT(TaggedIsSmi(length));
1448 Node* result = Allocate(ConsString::kSize, flags);
1384 Node* map = LoadRoot(Heap::kConsStringMapRootIndex); 1449 Node* map = LoadRoot(Heap::kConsStringMapRootIndex);
1450 DCHECK(Heap::RootIsImmortalImmovable(Heap::kConsStringMapRootIndex));
1385 StoreMapNoWriteBarrier(result, map); 1451 StoreMapNoWriteBarrier(result, map);
1386 StoreObjectFieldNoWriteBarrier(result, ConsString::kLengthOffset, length, 1452 StoreObjectFieldNoWriteBarrier(result, ConsString::kLengthOffset, length,
1387 MachineRepresentation::kTagged); 1453 MachineRepresentation::kTagged);
1388 StoreObjectFieldNoWriteBarrier(result, ConsString::kHashFieldOffset, 1454 StoreObjectFieldNoWriteBarrier(result, ConsString::kHashFieldOffset,
1389 Int32Constant(String::kEmptyHashField), 1455 Int32Constant(String::kEmptyHashField),
1390 MachineRepresentation::kWord32); 1456 MachineRepresentation::kWord32);
1391 StoreObjectFieldNoWriteBarrier(result, ConsString::kFirstOffset, first, 1457 bool const new_space = !(flags & kPretenured);
1392 MachineRepresentation::kTagged); 1458 if (new_space) {
1393 StoreObjectFieldNoWriteBarrier(result, ConsString::kSecondOffset, second, 1459 StoreObjectFieldNoWriteBarrier(result, ConsString::kFirstOffset, first,
1394 MachineRepresentation::kTagged); 1460 MachineRepresentation::kTagged);
1461 StoreObjectFieldNoWriteBarrier(result, ConsString::kSecondOffset, second,
1462 MachineRepresentation::kTagged);
1463 } else {
1464 StoreObjectField(result, ConsString::kFirstOffset, first);
1465 StoreObjectField(result, ConsString::kSecondOffset, second);
1466 }
1395 return result; 1467 return result;
1396 } 1468 }
1397 1469
1470 Node* CodeStubAssembler::NewConsString(Node* context, Node* length, Node* left,
1471 Node* right, AllocationFlags flags) {
1472 CSA_ASSERT(TaggedIsSmi(length));
1473 // Added string can be a cons string.
1474 Comment("Allocating ConsString");
1475 Node* left_instance_type = LoadInstanceType(left);
1476 Node* right_instance_type = LoadInstanceType(right);
1477
1478 // Compute intersection and difference of instance types.
1479 Node* anded_instance_types = WordAnd(left_instance_type, right_instance_type);
1480 Node* xored_instance_types = WordXor(left_instance_type, right_instance_type);
1481
1482 // We create a one-byte cons string if
1483 // 1. both strings are one-byte, or
1484 // 2. at least one of the strings is two-byte, but happens to contain only
1485 // one-byte characters.
1486 // To do this, we check
1487 // 1. if both strings are one-byte, or if the one-byte data hint is set in
1488 // both strings, or
1489 // 2. if one of the strings has the one-byte data hint set and the other
1490 // string is one-byte.
1491 STATIC_ASSERT(kOneByteStringTag != 0);
1492 STATIC_ASSERT(kOneByteDataHintTag != 0);
1493 Label one_byte_map(this);
1494 Label two_byte_map(this);
1495 Variable result(this, MachineRepresentation::kTagged);
1496 Label done(this, &result);
1497 GotoIf(WordNotEqual(
1498 WordAnd(anded_instance_types,
1499 IntPtrConstant(kStringEncodingMask | kOneByteDataHintTag)),
1500 IntPtrConstant(0)),
1501 &one_byte_map);
1502 Branch(WordNotEqual(WordAnd(xored_instance_types,
1503 IntPtrConstant(kStringEncodingMask |
1504 kOneByteDataHintMask)),
1505 IntPtrConstant(kOneByteStringTag | kOneByteDataHintTag)),
1506 &two_byte_map, &one_byte_map);
1507
1508 Bind(&one_byte_map);
1509 Comment("One-byte ConsString");
1510 result.Bind(AllocateOneByteConsString(length, left, right, flags));
1511 Goto(&done);
1512
1513 Bind(&two_byte_map);
1514 Comment("Two-byte ConsString");
1515 result.Bind(AllocateTwoByteConsString(length, left, right, flags));
1516 Goto(&done);
1517
1518 Bind(&done);
1519
1520 return result.value();
1521 }
1522
1398 Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length, 1523 Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length,
1399 Node* index, Node* input) { 1524 Node* index, Node* input) {
1400 Node* const max_length = 1525 Node* const max_length =
1401 SmiConstant(Smi::FromInt(JSArray::kInitialMaxFastElementArray)); 1526 SmiConstant(Smi::FromInt(JSArray::kInitialMaxFastElementArray));
1402 CSA_ASSERT(SmiLessThanOrEqual(length, max_length)); 1527 CSA_ASSERT(SmiLessThanOrEqual(length, max_length));
1403 1528
1404 // Allocate the JSRegExpResult. 1529 // Allocate the JSRegExpResult.
1405 // TODO(jgruber): Fold JSArray and FixedArray allocations, then remove 1530 // TODO(jgruber): Fold JSArray and FixedArray allocations, then remove
1406 // unneeded store of elements. 1531 // unneeded store of elements.
1407 Node* const result = Allocate(JSRegExpResult::kSize); 1532 Node* const result = Allocate(JSRegExpResult::kSize);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 Bind(&done); 1852 Bind(&done);
1728 IncrementCounter(isolate()->counters()->inlined_copied_elements(), 1); 1853 IncrementCounter(isolate()->counters()->inlined_copied_elements(), 1);
1729 Comment("] CopyFixedArrayElements"); 1854 Comment("] CopyFixedArrayElements");
1730 } 1855 }
1731 1856
1732 void CodeStubAssembler::CopyStringCharacters(compiler::Node* from_string, 1857 void CodeStubAssembler::CopyStringCharacters(compiler::Node* from_string,
1733 compiler::Node* to_string, 1858 compiler::Node* to_string,
1734 compiler::Node* from_index, 1859 compiler::Node* from_index,
1735 compiler::Node* to_index, 1860 compiler::Node* to_index,
1736 compiler::Node* character_count, 1861 compiler::Node* character_count,
1737 String::Encoding encoding) { 1862 String::Encoding encoding,
1738 Label out(this); 1863 ParameterMode mode) {
1864 bool one_byte = encoding == String::ONE_BYTE_ENCODING;
1865 Comment(one_byte ? "CopyStringCharacters ONE_BYTE_ENCODING"
1866 : "CopyStringCharacters TWO_BYTE_ENCODING");
1739 1867
1740 // Nothing to do for zero characters. 1868 ElementsKind kind = one_byte ? UINT8_ELEMENTS : UINT16_ELEMENTS;
1869 int header_size = (one_byte ? SeqOneByteString::kHeaderSize
1870 : SeqTwoByteString::kHeaderSize) -
1871 kHeapObjectTag;
1872 Node* from_offset = ElementOffsetFromIndex(from_index, kind, mode);
1873 Node* to_offset = ElementOffsetFromIndex(to_index, kind, mode);
1874 Node* byte_count = ElementOffsetFromIndex(character_count, kind, mode);
1875 Node* limit_offset = IntPtrAddFoldConstants(from_offset, byte_count);
1741 1876
1742 GotoIf(SmiLessThanOrEqual(character_count, SmiConstant(Smi::kZero)), &out); 1877 // Prepare the fast loop
1878 MachineType type = one_byte ? MachineType::Uint8() : MachineType::Uint16();
1879 MachineRepresentation rep =
1880 one_byte ? MachineRepresentation::kWord8 : MachineRepresentation::kWord16;
1881 int increment = -(1 << ElementsKindToShiftSize(kind));
1743 1882
1744 // Calculate offsets into the strings. 1883 Node* to_string_adjusted = IntPtrAddFoldConstants(
1884 to_string, IntPtrSubFoldConstants(to_offset, from_offset));
1885 limit_offset =
1886 IntPtrAddFoldConstants(limit_offset, IntPtrConstant(header_size));
1887 from_offset =
1888 IntPtrAddFoldConstants(from_offset, IntPtrConstant(header_size));
1745 1889
1746 Node* from_offset; 1890 BuildFastLoop(MachineType::PointerRepresentation(), limit_offset, from_offset,
1747 Node* limit_offset; 1891 [from_string, to_string_adjusted, type, rep](
1748 Node* to_offset; 1892 CodeStubAssembler* assembler, Node* offset) {
1749 1893 Node* value = assembler->Load(type, from_string, offset);
1750 { 1894 assembler->StoreNoWriteBarrier(rep, to_string_adjusted,
1751 Node* byte_count = SmiUntag(character_count); 1895 offset, value);
1752 Node* from_byte_index = SmiUntag(from_index); 1896 },
1753 Node* to_byte_index = SmiUntag(to_index); 1897 increment);
1754 if (encoding == String::ONE_BYTE_ENCODING) {
1755 const int offset = SeqOneByteString::kHeaderSize - kHeapObjectTag;
1756 from_offset = IntPtrAdd(IntPtrConstant(offset), from_byte_index);
1757 limit_offset = IntPtrAdd(from_offset, byte_count);
1758 to_offset = IntPtrAdd(IntPtrConstant(offset), to_byte_index);
1759 } else {
1760 STATIC_ASSERT(2 == sizeof(uc16));
1761 byte_count = WordShl(byte_count, 1);
1762 from_byte_index = WordShl(from_byte_index, 1);
1763 to_byte_index = WordShl(to_byte_index, 1);
1764
1765 const int offset = SeqTwoByteString::kHeaderSize - kHeapObjectTag;
1766 from_offset = IntPtrAdd(IntPtrConstant(offset), from_byte_index);
1767 limit_offset = IntPtrAdd(from_offset, byte_count);
1768 to_offset = IntPtrAdd(IntPtrConstant(offset), to_byte_index);
1769 }
1770 }
1771
1772 Variable var_from_offset(this, MachineType::PointerRepresentation());
1773 Variable var_to_offset(this, MachineType::PointerRepresentation());
1774
1775 var_from_offset.Bind(from_offset);
1776 var_to_offset.Bind(to_offset);
1777
1778 Variable* vars[] = {&var_from_offset, &var_to_offset};
1779 Label decrement(this, 2, vars);
1780
1781 Label loop(this, 2, vars);
1782 Goto(&loop);
1783 Bind(&loop);
1784 {
1785 from_offset = var_from_offset.value();
1786 to_offset = var_to_offset.value();
1787
1788 // TODO(jgruber): We could make this faster through larger copy unit sizes.
1789 Node* value = Load(MachineType::Uint8(), from_string, from_offset);
1790 StoreNoWriteBarrier(MachineRepresentation::kWord8, to_string, to_offset,
1791 value);
1792
1793 Node* new_from_offset = IntPtrAdd(from_offset, IntPtrConstant(1));
1794 var_from_offset.Bind(new_from_offset);
1795 var_to_offset.Bind(IntPtrAdd(to_offset, IntPtrConstant(1)));
1796
1797 Branch(WordNotEqual(new_from_offset, limit_offset), &loop, &out);
1798 }
1799
1800 Bind(&out);
1801 } 1898 }
1802 1899
1803 Node* CodeStubAssembler::LoadElementAndPrepareForStore(Node* array, 1900 Node* CodeStubAssembler::LoadElementAndPrepareForStore(Node* array,
1804 Node* offset, 1901 Node* offset,
1805 ElementsKind from_kind, 1902 ElementsKind from_kind,
1806 ElementsKind to_kind, 1903 ElementsKind to_kind,
1807 Label* if_hole) { 1904 Label* if_hole) {
1808 if (IsFastDoubleElementsKind(from_kind)) { 1905 if (IsFastDoubleElementsKind(from_kind)) {
1809 Node* value = 1906 Node* value =
1810 LoadDoubleWithHoleCheck(array, offset, if_hole, MachineType::Float64()); 1907 LoadDoubleWithHoleCheck(array, offset, if_hole, MachineType::Float64());
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 a->GotoIf(a->Word32Equal(a->Word32And(from_instance_type, 2666 a->GotoIf(a->Word32Equal(a->Word32And(from_instance_type,
2570 a->Int32Constant(kStringEncodingMask)), 2667 a->Int32Constant(kStringEncodingMask)),
2571 a->Int32Constant(0)), 2668 a->Int32Constant(0)),
2572 &two_byte_sequential); 2669 &two_byte_sequential);
2573 2670
2574 // The subject string is a sequential one-byte string. 2671 // The subject string is a sequential one-byte string.
2575 { 2672 {
2576 Node* result = 2673 Node* result =
2577 a->AllocateSeqOneByteString(context, a->SmiToWord(character_count)); 2674 a->AllocateSeqOneByteString(context, a->SmiToWord(character_count));
2578 a->CopyStringCharacters(from, result, from_index, smi_zero, character_count, 2675 a->CopyStringCharacters(from, result, from_index, smi_zero, character_count,
2579 String::ONE_BYTE_ENCODING); 2676 String::ONE_BYTE_ENCODING,
2677 CodeStubAssembler::SMI_PARAMETERS);
2580 var_result.Bind(result); 2678 var_result.Bind(result);
2581 2679
2582 a->Goto(&end); 2680 a->Goto(&end);
2583 } 2681 }
2584 2682
2585 // The subject string is a sequential two-byte string. 2683 // The subject string is a sequential two-byte string.
2586 a->Bind(&two_byte_sequential); 2684 a->Bind(&two_byte_sequential);
2587 { 2685 {
2588 Node* result = 2686 Node* result =
2589 a->AllocateSeqTwoByteString(context, a->SmiToWord(character_count)); 2687 a->AllocateSeqTwoByteString(context, a->SmiToWord(character_count));
2590 a->CopyStringCharacters(from, result, from_index, smi_zero, character_count, 2688 a->CopyStringCharacters(from, result, from_index, smi_zero, character_count,
2591 String::TWO_BYTE_ENCODING); 2689 String::TWO_BYTE_ENCODING,
2690 CodeStubAssembler::SMI_PARAMETERS);
2592 var_result.Bind(result); 2691 var_result.Bind(result);
2593 2692
2594 a->Goto(&end); 2693 a->Goto(&end);
2595 } 2694 }
2596 2695
2597 a->Bind(&end); 2696 a->Bind(&end);
2598 return var_result.value(); 2697 return var_result.value();
2599 } 2698 }
2600 2699
2601 } // namespace 2700 } // namespace
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 { 2914 {
2816 var_result.Bind( 2915 var_result.Bind(
2817 CallRuntime(Runtime::kSubString, context, string, from, to)); 2916 CallRuntime(Runtime::kSubString, context, string, from, to));
2818 Goto(&end); 2917 Goto(&end);
2819 } 2918 }
2820 2919
2821 Bind(&end); 2920 Bind(&end);
2822 return var_result.value(); 2921 return var_result.value();
2823 } 2922 }
2824 2923
2825 Node* CodeStubAssembler::StringConcat(Node* context, Node* first, 2924 Node* CodeStubAssembler::StringAdd(Node* context, Node* left, Node* right,
2826 Node* second) { 2925 AllocationFlags flags) {
2827 Variable var_result(this, MachineRepresentation::kTagged); 2926 Label check_right(this);
2927 Label runtime(this, Label::kDeferred);
2928 Label cons(this);
2929 Label non_cons(this);
2930 Variable result(this, MachineRepresentation::kTagged);
2931 Label done(this, &result);
2932 Label done_native(this, &result);
2933 Counters* counters = isolate()->counters();
2828 2934
2829 Label out(this), runtime(this, Label::kDeferred); 2935 Node* left_length = LoadStringLength(left);
2936 GotoIf(WordNotEqual(IntPtrConstant(0), left_length), &check_right);
2937 result.Bind(right);
2938 Goto(&done_native);
2830 2939
2831 // TODO(jgruber): Handle indirect, external, and two-byte strings. 2940 Bind(&check_right);
2941 Node* right_length = LoadStringLength(right);
2942 GotoIf(WordNotEqual(IntPtrConstant(0), right_length), &cons);
2943 result.Bind(left);
2944 Goto(&done_native);
2832 2945
2833 Node* const one_byte_seq_mask = Int32Constant( 2946 Bind(&cons);
2834 kIsIndirectStringMask | kExternalStringTag | kStringEncodingMask); 2947 CSA_ASSERT(TaggedIsSmi(left_length));
2835 Node* const expected_masked = Int32Constant(kOneByteStringTag); 2948 CSA_ASSERT(TaggedIsSmi(right_length));
2949 Node* new_length = SmiAdd(left_length, right_length);
2950 GotoIf(UintPtrGreaterThanOrEqual(
2951 new_length, SmiConstant(Smi::FromInt(String::kMaxLength))),
2952 &runtime);
2836 2953
2837 Node* const first_instance_type = LoadInstanceType(first); 2954 GotoIf(IntPtrLessThan(new_length,
2838 GotoUnless(Word32Equal(Word32And(first_instance_type, one_byte_seq_mask), 2955 SmiConstant(Smi::FromInt(ConsString::kMinLength))),
2839 expected_masked), 2956 &non_cons);
2840 &runtime);
2841 2957
2842 Node* const second_instance_type = LoadInstanceType(second); 2958 result.Bind(NewConsString(context, new_length, left, right, flags));
2843 GotoUnless(Word32Equal(Word32And(second_instance_type, one_byte_seq_mask), 2959 Goto(&done_native);
2844 expected_masked),
2845 &runtime);
2846 2960
2847 Node* const smi_zero = SmiConstant(Smi::kZero); 2961 Bind(&non_cons);
2848 Node* const first_length = LoadStringLength(first);
2849 Node* const second_length = LoadStringLength(second);
2850 Node* const length = SmiAdd(first_length, second_length);
2851 2962
2852 Label if_makeseqstring(this), if_makeconsstring(this); 2963 Comment("Full string concatenate");
2853 Node* const min_cons_length = 2964 Node* left_instance_type = LoadInstanceType(left);
2854 SmiConstant(Smi::FromInt(ConsString::kMinLength)); 2965 Node* right_instance_type = LoadInstanceType(right);
2855 Branch(SmiLessThan(length, min_cons_length), &if_makeseqstring, 2966 // Compute intersection and difference of instance types.
2856 &if_makeconsstring);
2857 2967
2858 Bind(&if_makeseqstring); 2968 Node* ored_instance_types = WordOr(left_instance_type, right_instance_type);
2969 Node* xored_instance_types = WordXor(left_instance_type, right_instance_type);
2970
2971 // Check if both strings have the same encoding and both are sequential.
2972 GotoIf(WordNotEqual(
2973 WordAnd(xored_instance_types, IntPtrConstant(kStringEncodingMask)),
2974 IntPtrConstant(0)),
2975 &runtime);
2976 GotoIf(WordNotEqual(WordAnd(ored_instance_types,
2977 IntPtrConstant(kStringRepresentationMask)),
2978 IntPtrConstant(0)),
2979 &runtime);
2980
2981 Label two_byte(this);
2982 GotoIf(WordEqual(
2983 WordAnd(ored_instance_types, IntPtrConstant(kStringEncodingMask)),
2984 IntPtrConstant(kTwoByteStringTag)),
2985 &two_byte);
2986 // One-byte sequential string case
2987 Node* new_string =
2988 AllocateSeqOneByteString(context, new_length, SMI_PARAMETERS);
2989 CopyStringCharacters(left, new_string, SmiConstant(Smi::kZero),
2990 SmiConstant(Smi::kZero), left_length,
2991 String::ONE_BYTE_ENCODING, SMI_PARAMETERS);
2992 CopyStringCharacters(right, new_string, SmiConstant(Smi::kZero), left_length,
2993 right_length, String::ONE_BYTE_ENCODING, SMI_PARAMETERS);
2994 result.Bind(new_string);
2995 Goto(&done_native);
2996
2997 Bind(&two_byte);
2859 { 2998 {
2860 Node* result = AllocateSeqOneByteString(context, SmiToWord(length)); 2999 // Two-byte sequential string case
2861 3000 new_string = AllocateSeqTwoByteString(context, new_length, SMI_PARAMETERS);
2862 CopyStringCharacters(first, result, smi_zero, smi_zero, first_length, 3001 CopyStringCharacters(left, new_string, SmiConstant(Smi::kZero),
2863 String::ONE_BYTE_ENCODING); 3002 SmiConstant(Smi::kZero), left_length,
2864 CopyStringCharacters(second, result, smi_zero, first_length, second_length, 3003 String::TWO_BYTE_ENCODING, SMI_PARAMETERS);
2865 String::ONE_BYTE_ENCODING); 3004 CopyStringCharacters(right, new_string, SmiConstant(Smi::kZero),
2866 3005 left_length, right_length, String::TWO_BYTE_ENCODING,
2867 var_result.Bind(result); 3006 SMI_PARAMETERS);
2868 Goto(&out); 3007 result.Bind(new_string);
2869 } 3008 Goto(&done_native);
2870
2871 Bind(&if_makeconsstring);
2872 {
2873 Node* result = AllocateOneByteConsString(length, first, second);
2874 var_result.Bind(result);
2875 Goto(&out);
2876 } 3009 }
2877 3010
2878 Bind(&runtime); 3011 Bind(&runtime);
2879 { 3012 {
2880 Node* const result = 3013 result.Bind(CallRuntime(Runtime::kStringAdd, context, left, right));
2881 CallRuntime(Runtime::kStringAdd, context, first, second); 3014 Goto(&done);
2882 var_result.Bind(result);
2883 Goto(&out);
2884 } 3015 }
2885 3016
2886 Bind(&out); 3017 Bind(&done_native);
2887 return var_result.value(); 3018 {
3019 IncrementCounter(counters->string_add_native(), 1);
3020 Goto(&done);
3021 }
3022
3023 Bind(&done);
3024 return result.value();
2888 } 3025 }
2889 3026
2890 Node* CodeStubAssembler::StringIndexOfChar(Node* context, Node* string, 3027 Node* CodeStubAssembler::StringIndexOfChar(Node* context, Node* string,
2891 Node* needle_char, Node* from) { 3028 Node* needle_char, Node* from) {
2892 Variable var_result(this, MachineRepresentation::kTagged); 3029 Variable var_result(this, MachineRepresentation::kTagged);
2893 3030
2894 Label out(this), runtime(this, Label::kDeferred); 3031 Label out(this), runtime(this, Label::kDeferred);
2895 3032
2896 // Let runtime handle non-one-byte {needle_char}. 3033 // Let runtime handle non-one-byte {needle_char}.
2897 3034
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
3279 { 3416 {
3280 var_result.Bind(NonNumberToNumber(context, input)); 3417 var_result.Bind(NonNumberToNumber(context, input));
3281 Goto(&end); 3418 Goto(&end);
3282 } 3419 }
3283 } 3420 }
3284 3421
3285 Bind(&end); 3422 Bind(&end);
3286 return var_result.value(); 3423 return var_result.value();
3287 } 3424 }
3288 3425
3426 Node* CodeStubAssembler::ToString(Node* context, Node* input) {
3427 Label is_number(this);
3428 Label runtime(this, Label::kDeferred);
3429 Variable result(this, MachineRepresentation::kTagged);
3430 Label done(this, &result);
3431
3432 GotoIf(TaggedIsSmi(input), &is_number);
3433
3434 Node* input_map = LoadMap(input);
3435 Node* input_instance_type = LoadMapInstanceType(input_map);
3436
3437 result.Bind(input);
3438 GotoIf(IsStringInstanceType(input_instance_type), &done);
3439
3440 Label not_heap_number(this);
3441 Branch(WordNotEqual(input_map, HeapNumberMapConstant()), &not_heap_number,
3442 &is_number);
3443
3444 Bind(&is_number);
3445 result.Bind(NumberToString(context, input));
3446 Goto(&done);
3447
3448 Bind(&not_heap_number);
3449 {
3450 GotoIf(Word32NotEqual(input_instance_type, Int32Constant(ODDBALL_TYPE)),
3451 &runtime);
3452 result.Bind(LoadObjectField(input, Oddball::kToStringOffset));
3453 Goto(&done);
3454 }
3455
3456 Bind(&runtime);
3457 {
3458 result.Bind(CallRuntime(Runtime::kToString, context, input));
3459 Goto(&done);
3460 }
3461
3462 Bind(&done);
3463 return result.value();
3464 }
3465
3466 Node* CodeStubAssembler::JSReceiverToPrimitive(Node* context, Node* input) {
3467 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
3468 Label if_isreceiver(this, Label::kDeferred), if_isnotreceiver(this);
3469 Variable result(this, MachineRepresentation::kTagged);
3470 Label done(this, &result);
3471
3472 GotoIf(TaggedIsSmi(input), &if_isnotreceiver);
3473
3474 Node* map = LoadMap(input);
3475 Node* instance_type = LoadMapInstanceType(map);
3476 Branch(IsJSReceiverInstanceType(instance_type), &if_isreceiver,
3477 &if_isnotreceiver);
3478
3479 Bind(&if_isreceiver);
3480 {
3481 // Convert {input} to a primitive first passing Number hint.
3482 Callable callable = CodeFactory::NonPrimitiveToPrimitive(isolate());
3483 result.Bind(CallStub(callable, context, input));
3484 Goto(&done);
3485 }
3486
3487 Bind(&if_isnotreceiver);
3488 {
3489 result.Bind(input);
3490 Goto(&done);
3491 }
3492
3493 Bind(&done);
3494 return result.value();
3495 }
3496
3289 Node* CodeStubAssembler::ToInteger(Node* context, Node* input, 3497 Node* CodeStubAssembler::ToInteger(Node* context, Node* input,
3290 ToIntegerTruncationMode mode) { 3498 ToIntegerTruncationMode mode) {
3291 // We might need to loop once for ToNumber conversion. 3499 // We might need to loop once for ToNumber conversion.
3292 Variable var_arg(this, MachineRepresentation::kTagged); 3500 Variable var_arg(this, MachineRepresentation::kTagged);
3293 Label loop(this, &var_arg), out(this); 3501 Label loop(this, &var_arg), out(this);
3294 var_arg.Bind(input); 3502 var_arg.Bind(input);
3295 Goto(&loop); 3503 Goto(&loop);
3296 Bind(&loop); 3504 Bind(&loop);
3297 { 3505 {
3298 // Shared entry points. 3506 // Shared entry points.
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
4325 ElementsKind kind, 4533 ElementsKind kind,
4326 ParameterMode mode, 4534 ParameterMode mode,
4327 int base_size) { 4535 int base_size) {
4328 int element_size_shift = ElementsKindToShiftSize(kind); 4536 int element_size_shift = ElementsKindToShiftSize(kind);
4329 int element_size = 1 << element_size_shift; 4537 int element_size = 1 << element_size_shift;
4330 int const kSmiShiftBits = kSmiShiftSize + kSmiTagSize; 4538 int const kSmiShiftBits = kSmiShiftSize + kSmiTagSize;
4331 intptr_t index = 0; 4539 intptr_t index = 0;
4332 bool constant_index = false; 4540 bool constant_index = false;
4333 if (mode == SMI_PARAMETERS) { 4541 if (mode == SMI_PARAMETERS) {
4334 element_size_shift -= kSmiShiftBits; 4542 element_size_shift -= kSmiShiftBits;
4335 constant_index = ToIntPtrConstant(index_node, index); 4543 Smi* smi_index;
4336 index = index >> kSmiShiftBits; 4544 constant_index = ToSmiConstant(index_node, smi_index);
4545 if (constant_index) index = smi_index->value();
4337 index_node = BitcastTaggedToWord(index_node); 4546 index_node = BitcastTaggedToWord(index_node);
4338 } else if (mode == INTEGER_PARAMETERS) { 4547 } else if (mode == INTEGER_PARAMETERS) {
4339 int32_t temp = 0; 4548 int32_t temp = 0;
4340 constant_index = ToInt32Constant(index_node, temp); 4549 constant_index = ToInt32Constant(index_node, temp);
4341 index = static_cast<intptr_t>(temp); 4550 index = static_cast<intptr_t>(temp);
4342 } else { 4551 } else {
4343 DCHECK(mode == INTPTR_PARAMETERS); 4552 DCHECK(mode == INTPTR_PARAMETERS);
4344 constant_index = ToIntPtrConstant(index_node, index); 4553 constant_index = ToIntPtrConstant(index_node, index);
4345 } 4554 }
4346 if (constant_index) { 4555 if (constant_index) {
4347 return IntPtrConstant(base_size + element_size * index); 4556 return IntPtrConstant(base_size + element_size * index);
4348 } 4557 }
4349 if (Is64() && mode == INTEGER_PARAMETERS) { 4558 if (Is64() && mode == INTEGER_PARAMETERS) {
4350 index_node = ChangeInt32ToInt64(index_node); 4559 index_node = ChangeInt32ToInt64(index_node);
4351 } 4560 }
4352 if (base_size == 0) { 4561
4353 return (element_size_shift >= 0) 4562 Node* shifted_index =
4354 ? WordShl(index_node, IntPtrConstant(element_size_shift)) 4563 (element_size_shift == 0)
4355 : WordShr(index_node, IntPtrConstant(-element_size_shift)); 4564 ? index_node
4356 } 4565 : ((element_size_shift > 0)
4357 return IntPtrAdd( 4566 ? WordShl(index_node, IntPtrConstant(element_size_shift))
4358 IntPtrConstant(base_size), 4567 : WordShr(index_node, IntPtrConstant(-element_size_shift)));
4359 (element_size_shift >= 0) 4568 return IntPtrAddFoldConstants(IntPtrConstant(base_size), shifted_index);
4360 ? WordShl(index_node, IntPtrConstant(element_size_shift))
4361 : WordShr(index_node, IntPtrConstant(-element_size_shift)));
4362 } 4569 }
4363 4570
4364 compiler::Node* CodeStubAssembler::LoadTypeFeedbackVectorForStub() { 4571 compiler::Node* CodeStubAssembler::LoadTypeFeedbackVectorForStub() {
4365 Node* function = 4572 Node* function =
4366 LoadFromParentFrame(JavaScriptFrameConstants::kFunctionOffset); 4573 LoadFromParentFrame(JavaScriptFrameConstants::kFunctionOffset);
4367 Node* literals = LoadObjectField(function, JSFunction::kLiteralsOffset); 4574 Node* literals = LoadObjectField(function, JSFunction::kLiteralsOffset);
4368 return LoadObjectField(literals, LiteralsArray::kFeedbackVectorOffset); 4575 return LoadObjectField(literals, LiteralsArray::kFeedbackVectorOffset);
4369 } 4576 }
4370 4577
4371 void CodeStubAssembler::UpdateFeedback(compiler::Node* feedback, 4578 void CodeStubAssembler::UpdateFeedback(compiler::Node* feedback,
(...skipping 3113 matching lines...) Expand 10 before | Expand all | Expand 10 after
7485 result.Bind(CallRuntime(Runtime::kInstanceOf, context, object, callable)); 7692 result.Bind(CallRuntime(Runtime::kInstanceOf, context, object, callable));
7486 Goto(&end); 7693 Goto(&end);
7487 } 7694 }
7488 7695
7489 Bind(&end); 7696 Bind(&end);
7490 return result.value(); 7697 return result.value();
7491 } 7698 }
7492 7699
7493 } // namespace internal 7700 } // namespace internal
7494 } // namespace v8 7701 } // namespace v8
OLDNEW
« no previous file with comments | « src/code-stub-assembler.h ('k') | src/code-stubs.h » ('j') | src/compiler/code-assembler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698