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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 stack_pop_count); | 203 stack_pop_count); |
204 FinishCurrentBlock(hreturn_instruction); | 204 FinishCurrentBlock(hreturn_instruction); |
205 } | 205 } |
206 return true; | 206 return true; |
207 } | 207 } |
208 | 208 |
209 | 209 |
210 template <class Stub> | 210 template <class Stub> |
211 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { | 211 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { |
212 public: | 212 public: |
213 explicit CodeStubGraphBuilder(Isolate* isolate, Stub* stub) | 213 CodeStubGraphBuilder(Isolate* isolate, Stub* stub) |
214 : CodeStubGraphBuilderBase(isolate, stub) {} | 214 : CodeStubGraphBuilderBase(isolate, stub) {} |
215 | 215 |
216 protected: | 216 protected: |
217 virtual HValue* BuildCodeStub() { | 217 virtual HValue* BuildCodeStub() { |
218 if (casted_stub()->IsUninitialized()) { | 218 if (casted_stub()->IsUninitialized()) { |
219 return BuildCodeUninitializedStub(); | 219 return BuildCodeUninitializedStub(); |
220 } else { | 220 } else { |
221 return BuildCodeInitializedStub(); | 221 return BuildCodeInitializedStub(); |
222 } | 222 } |
223 } | 223 } |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 | 1296 |
1297 return js_function; | 1297 return js_function; |
1298 } | 1298 } |
1299 | 1299 |
1300 | 1300 |
1301 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { | 1301 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { |
1302 return DoGenerateCode(isolate, this); | 1302 return DoGenerateCode(isolate, this); |
1303 } | 1303 } |
1304 | 1304 |
1305 | 1305 |
1306 template <> | 1306 template<> |
1307 class CodeStubGraphBuilder<KeyedLoadDictionaryElementStub> | 1307 HValue* CodeStubGraphBuilder<KeyedLoadDictionaryElementStub>::BuildCodeStub() { |
1308 : public CodeStubGraphBuilderBase { | 1308 HValue* receiver = GetParameter(0); |
1309 public: | 1309 HValue* key = GetParameter(1); |
1310 explicit CodeStubGraphBuilder(Isolate* isolate, | |
1311 KeyedLoadDictionaryElementStub* stub) | |
1312 : CodeStubGraphBuilderBase(isolate, stub) {} | |
1313 | 1310 |
1314 protected: | 1311 Add<HCheckSmi>(key); |
1315 HValue* BuildCodeStubHelper(HValue* dictionary, | |
1316 HValue* key, | |
1317 HValue* hash, | |
1318 HValue* mask, | |
1319 int current_probe); | |
1320 | 1312 |
1321 virtual HValue* BuildCodeStub(); | 1313 return BuildUncheckedDictionaryElementLoad(receiver, key); |
1322 | |
1323 KeyedLoadDictionaryElementStub* casted_stub() { | |
1324 return static_cast<KeyedLoadDictionaryElementStub*>(stub()); | |
1325 } | |
1326 }; | |
1327 | |
1328 | |
1329 HValue* CodeStubGraphBuilder<KeyedLoadDictionaryElementStub>:: | |
1330 BuildCodeStubHelper( | |
1331 HValue* elements, | |
1332 HValue* key, | |
1333 HValue* hash, | |
1334 HValue* mask, | |
1335 int current_probe) { | |
1336 if (current_probe == kNumberDictionaryProbes) { | |
1337 return NULL; | |
1338 } | |
1339 | |
1340 int32_t offset = SeededNumberDictionary::GetProbeOffset(current_probe); | |
1341 HValue* raw_index = (current_probe == 0) | |
1342 ? hash | |
1343 : Add<HAdd>(hash, Add<HConstant>(offset)); | |
1344 raw_index = Add<HBitwise>(Token::BIT_AND, raw_index, mask); | |
1345 int32_t entry_size = SeededNumberDictionary::kEntrySize; | |
1346 raw_index = Add<HMul>(raw_index, Add<HConstant>(entry_size)); | |
1347 raw_index->ClearFlag(HValue::kCanOverflow); | |
1348 | |
1349 int32_t base_offset = SeededNumberDictionary::kElementsStartIndex; | |
1350 HValue* key_index = Add<HAdd>(raw_index, Add<HConstant>(base_offset)); | |
1351 key_index->ClearFlag(HValue::kCanOverflow); | |
1352 | |
1353 HValue* candidate_key = Add<HLoadKeyed>(elements, key_index, | |
1354 static_cast<HValue*>(NULL), | |
1355 FAST_SMI_ELEMENTS); | |
1356 | |
1357 IfBuilder key_compare(this); | |
1358 key_compare.IfNot<HCompareObjectEqAndBranch>(key, candidate_key); | |
1359 key_compare.Then(); | |
1360 { | |
1361 // Key at the current probe doesn't match, try at the next probe. | |
1362 HValue* result = BuildCodeStubHelper(elements, key, hash, mask, | |
1363 current_probe + 1); | |
1364 if (result == NULL) { | |
1365 key_compare.Deopt("probes exhausted in keyed load dictionary lookup"); | |
1366 result = graph()->GetConstantUndefined(); | |
1367 } else { | |
1368 Push(result); | |
1369 } | |
1370 } | |
1371 key_compare.Else(); | |
1372 { | |
1373 // Key at current probe matches. Details must be zero, otherwise the | |
1374 // dictionary element requires special handling. | |
1375 HValue* details_index = Add<HAdd>(raw_index, | |
1376 Add<HConstant>(base_offset + 2)); | |
1377 details_index->ClearFlag(HValue::kCanOverflow); | |
1378 | |
1379 HValue* details = Add<HLoadKeyed>(elements, details_index, | |
1380 static_cast<HValue*>(NULL), | |
1381 FAST_SMI_ELEMENTS); | |
1382 IfBuilder details_compare(this); | |
1383 details_compare.If<HCompareNumericAndBranch>(details, | |
1384 graph()->GetConstant0(), | |
1385 Token::NE); | |
1386 details_compare.ThenDeopt("keyed load dictionary element not fast case"); | |
1387 | |
1388 details_compare.Else(); | |
1389 { | |
1390 // Key matches and details are zero --> fast case. Load and return the | |
1391 // value. | |
1392 HValue* result_index = Add<HAdd>(raw_index, | |
1393 Add<HConstant>(base_offset + 1)); | |
1394 result_index->ClearFlag(HValue::kCanOverflow); | |
1395 | |
1396 Push(Add<HLoadKeyed>(elements, result_index, | |
1397 static_cast<HValue*>(NULL), | |
1398 FAST_ELEMENTS)); | |
1399 } | |
1400 details_compare.End(); | |
1401 } | |
1402 key_compare.End(); | |
1403 | |
1404 return Pop(); | |
1405 } | 1314 } |
1406 | 1315 |
1407 | 1316 |
1408 HValue* CodeStubGraphBuilder<KeyedLoadDictionaryElementStub>::BuildCodeStub() { | |
1409 KeyedLoadDictionaryElementStub* stub = casted_stub(); | |
1410 | |
1411 HValue* dictionary = GetParameter(0); | |
1412 HValue* key = GetParameter(1); | |
1413 USE(stub); | |
1414 USE(dictionary); | |
1415 | |
1416 HValue* elements = AddLoadElements(dictionary); | |
1417 | |
1418 Add<HCheckSmi>(key); | |
1419 | |
1420 HValue* hash = BuildElementIndexHash(key); | |
1421 | |
1422 HValue* capacity = Add<HLoadKeyed>( | |
1423 elements, | |
1424 Add<HConstant>(NameDictionary::kCapacityIndex), | |
1425 static_cast<HValue*>(NULL), | |
1426 FAST_SMI_ELEMENTS); | |
1427 | |
1428 HValue* mask = Add<HSub>(capacity, graph()->GetConstant1()); | |
1429 mask->ChangeRepresentation(Representation::Integer32()); | |
1430 mask->ClearFlag(HValue::kCanOverflow); | |
1431 | |
1432 return BuildCodeStubHelper(elements, key, hash, mask, 0); | |
1433 } | |
1434 | |
1435 | |
1436 Handle<Code> KeyedLoadDictionaryElementStub::GenerateCode(Isolate* isolate) { | 1317 Handle<Code> KeyedLoadDictionaryElementStub::GenerateCode(Isolate* isolate) { |
1437 return DoGenerateCode(isolate, this); | 1318 return DoGenerateCode(isolate, this); |
1438 } | 1319 } |
1439 | 1320 |
1440 | 1321 |
1441 } } // namespace v8::internal | 1322 } } // namespace v8::internal |
OLD | NEW |