Changeset 184776 in webkit for trunk/Source/JavaScriptCore/dfg/DFGCSEPhase.cpp
- Timestamp:
- May 22, 2015, 10:24:05 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/dfg/DFGCSEPhase.cpp
r183497 r184776 149 149 } 150 150 151 Node*findReplacement(HeapLocation location)151 LazyNode findReplacement(HeapLocation location) 152 152 { 153 153 for (unsigned i = m_impureLength; i--;) { … … 158 158 } 159 159 160 Node* addImpure(HeapLocation location, Node* node) 161 { 162 if (Node* result = findReplacement(location)) 160 LazyNode addImpure(HeapLocation location, LazyNode node) 161 { 162 // FIXME: If we are using small maps, we must not def() derived values. 163 // For now the only derived values we def() are constant-based. 164 if (location.index() && !location.index().isNode()) 165 return nullptr; 166 if (LazyNode result = findReplacement(location)) 163 167 return result; 164 168 ASSERT(m_impureLength < capacity); 165 m_impureMap[m_impureLength++] = WTF::KeyValuePair<HeapLocation, Node*>(location, node);169 m_impureMap[m_impureLength++] = WTF::KeyValuePair<HeapLocation, LazyNode>(location, node); 166 170 return nullptr; 167 171 } … … 169 173 private: 170 174 WTF::KeyValuePair<PureValue, Node*> m_pureMap[capacity]; 171 WTF::KeyValuePair<HeapLocation, Node*> m_impureMap[capacity];175 WTF::KeyValuePair<HeapLocation, LazyNode> m_impureMap[capacity]; 172 176 unsigned m_pureLength; 173 177 unsigned m_impureLength; … … 199 203 } 200 204 201 Node*findReplacement(HeapLocation location)205 LazyNode findReplacement(HeapLocation location) 202 206 { 203 207 return m_impureMap.get(location); 204 208 } 205 209 206 Node* addImpure(HeapLocation location, Node*node)210 LazyNode addImpure(HeapLocation location, LazyNode node) 207 211 { 208 212 auto result = m_impureMap.add(location, node); … … 214 218 private: 215 219 HashMap<PureValue, Node*> m_pureMap; 216 HashMap<HeapLocation, Node*> m_impureMap;220 HashMap<HeapLocation, LazyNode> m_impureMap; 217 221 }; 218 222 … … 222 226 BlockCSE(Graph& graph) 223 227 : m_graph(graph) 228 , m_insertionSet(graph) 224 229 { 225 230 } … … 229 234 m_maps.clear(); 230 235 m_changed = false; 236 m_block = block; 231 237 232 238 for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) { … … 298 304 } 299 305 } 306 307 m_insertionSet.execute(block); 300 308 301 309 return m_changed; … … 319 327 } 320 328 321 void def(HeapLocation location, Node*value)322 { 323 Node*match = m_maps.addImpure(location, value);329 void def(HeapLocation location, LazyNode value) 330 { 331 LazyNode match = m_maps.addImpure(location, value); 324 332 if (!match) 325 333 return; … … 344 352 } 345 353 346 m_node->replaceWith(match); 347 m_changed = true; 354 if (value.isNode() && value.asNode() == m_node) { 355 match.ensureIsNode(m_insertionSet, m_block, 0)->owner = m_block; 356 ASSERT(match.isNode()); 357 m_node->replaceWith(match.asNode()); 358 m_changed = true; 359 } 348 360 } 349 361 … … 353 365 bool m_changed; 354 366 Node* m_node; 367 BasicBlock* m_block; 355 368 356 369 Maps m_maps; 370 371 InsertionSet m_insertionSet; 357 372 }; 358 373 … … 366 381 : Phase(graph, "global common subexpression elimination") 367 382 , m_impureDataMap(graph) 383 , m_insertionSet(graph) 368 384 { 369 385 } … … 430 446 431 447 for (unsigned nodeIndex = 0; nodeIndex < m_block->size(); ++nodeIndex) { 448 m_nodeIndex = nodeIndex; 432 449 m_node = m_block->at(nodeIndex); 433 450 if (verbose) … … 442 459 clobberize(m_graph, m_node, *this); 443 460 } 461 462 m_insertionSet.execute(m_block); 444 463 445 464 m_impureData->didVisit = true; … … 487 506 } 488 507 489 Node*findReplacement(HeapLocation location)508 LazyNode findReplacement(HeapLocation location) 490 509 { 491 510 // At this instant, our "availableAtTail" reflects the set of things that are available in 492 511 // this block so far. We check this map to find block-local CSE opportunities before doing 493 512 // a global search. 494 Node*match = m_impureData->availableAtTail.get(location);495 if ( match) {513 LazyNode match = m_impureData->availableAtTail.get(location); 514 if (!!match) { 496 515 if (verbose) 497 516 dataLog(" Found local match: ", match, "\n"); … … 576 595 if (verbose) 577 596 dataLog(" Availability: ", match, "\n"); 578 if ( match) {597 if (!!match) { 579 598 // Don't examine the predecessors of a match. At this point we just want to 580 599 // establish that other blocks on the path from here to there don't clobber … … 617 636 } 618 637 619 void def(HeapLocation location, Node*value)638 void def(HeapLocation location, LazyNode value) 620 639 { 621 640 if (verbose) 622 641 dataLog(" Got heap location def: ", location, " -> ", value, "\n"); 623 642 624 Node*match = findReplacement(location);643 LazyNode match = findReplacement(location); 625 644 626 645 if (verbose) … … 634 653 return; 635 654 } 636 637 m_node->replaceWith(match); 638 m_changed = true; 655 656 if (value.isNode() && value.asNode() == m_node) { 657 if (!match.isNode()) { 658 // We need to properly record the constant in order to use an existing one if applicable. 659 // This ensures that re-running GCSE will not find new optimizations. 660 match.ensureIsNode(m_insertionSet, m_block, m_nodeIndex)->owner = m_block; 661 auto result = m_pureValues.add(PureValue(match.asNode(), match->constant()), Vector<Node*>()); 662 bool replaced = false; 663 if (!result.isNewEntry) { 664 for (unsigned i = result.iterator->value.size(); i--;) { 665 Node* candidate = result.iterator->value[i]; 666 if (m_graph.m_dominators.dominates(candidate->owner, m_block)) { 667 ASSERT(candidate); 668 match->replaceWith(candidate); 669 match.setNode(candidate); 670 replaced = true; 671 break; 672 } 673 } 674 } 675 if (!replaced) 676 result.iterator->value.append(match.asNode()); 677 } 678 ASSERT(match.asNode()); 679 m_node->replaceWith(match.asNode()); 680 m_changed = true; 681 } 639 682 } 640 683 … … 657 700 BasicBlock* m_block; 658 701 Node* m_node; 702 unsigned m_nodeIndex; 659 703 ImpureBlockData* m_impureData; 660 704 ClobberSet m_writesSoFar; 705 InsertionSet m_insertionSet; 661 706 662 707 bool m_changed;
Note:
See TracChangeset
for help on using the changeset viewer.