| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/compiler/escape-analysis-reducer.h" | 5 #include "src/compiler/escape-analysis-reducer.h" |
| 6 | 6 |
| 7 #include "src/compiler/all-nodes.h" | 7 #include "src/compiler/all-nodes.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/counters.h" | 9 #include "src/counters.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 EscapeAnalysisReducer::EscapeAnalysisReducer(Editor* editor, JSGraph* jsgraph, | 24 EscapeAnalysisReducer::EscapeAnalysisReducer(Editor* editor, JSGraph* jsgraph, |
| 25 EscapeAnalysis* escape_analysis, | 25 EscapeAnalysis* escape_analysis, |
| 26 Zone* zone) | 26 Zone* zone) |
| 27 : AdvancedReducer(editor), | 27 : AdvancedReducer(editor), |
| 28 jsgraph_(jsgraph), | 28 jsgraph_(jsgraph), |
| 29 escape_analysis_(escape_analysis), | 29 escape_analysis_(escape_analysis), |
| 30 zone_(zone), | 30 zone_(zone), |
| 31 fully_reduced_(static_cast<int>(jsgraph->graph()->NodeCount() * 2), zone), | 31 fully_reduced_(static_cast<int>(jsgraph->graph()->NodeCount() * 2), zone), |
| 32 exists_virtual_allocate_(escape_analysis->ExistsVirtualAllocate()) {} | 32 exists_virtual_allocate_(escape_analysis->ExistsVirtualAllocate()) {} |
| 33 | 33 |
| 34 Reduction EscapeAnalysisReducer::Reduce(Node* node) { | 34 Reduction EscapeAnalysisReducer::ReduceNode(Node* node) { |
| 35 if (node->id() < static_cast<NodeId>(fully_reduced_.length()) && | 35 if (node->id() < static_cast<NodeId>(fully_reduced_.length()) && |
| 36 fully_reduced_.Contains(node->id())) { | 36 fully_reduced_.Contains(node->id())) { |
| 37 return NoChange(); | 37 return NoChange(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 switch (node->opcode()) { | 40 switch (node->opcode()) { |
| 41 case IrOpcode::kLoadField: | 41 case IrOpcode::kLoadField: |
| 42 case IrOpcode::kLoadElement: | 42 case IrOpcode::kLoadElement: |
| 43 return ReduceLoad(node); | 43 return ReduceLoad(node); |
| 44 case IrOpcode::kStoreField: | 44 case IrOpcode::kStoreField: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // it is working. For now we use EffectInputCount > 0 to determine | 90 // it is working. For now we use EffectInputCount > 0 to determine |
| 91 // whether a node might have a frame state input. | 91 // whether a node might have a frame state input. |
| 92 if (exists_virtual_allocate_ && node->op()->EffectInputCount() > 0) { | 92 if (exists_virtual_allocate_ && node->op()->EffectInputCount() > 0) { |
| 93 return ReduceFrameStateUses(node); | 93 return ReduceFrameStateUses(node); |
| 94 } | 94 } |
| 95 break; | 95 break; |
| 96 } | 96 } |
| 97 return NoChange(); | 97 return NoChange(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 Reduction EscapeAnalysisReducer::Reduce(Node* node) { |
| 101 Reduction reduction = ReduceNode(node); |
| 102 if (reduction.Changed() && node != reduction.replacement()) { |
| 103 escape_analysis()->SetReplacement(node, reduction.replacement()); |
| 104 } |
| 105 return reduction; |
| 106 } |
| 107 |
| 100 namespace { | 108 namespace { |
| 101 | 109 |
| 102 Node* MaybeGuard(JSGraph* jsgraph, Node* original, Node* replacement) { | 110 Node* MaybeGuard(JSGraph* jsgraph, Node* original, Node* replacement) { |
| 103 // We might need to guard the replacement if the type of the {replacement} | 111 // We might need to guard the replacement if the type of the {replacement} |
| 104 // node is not in a sub-type relation to the type of the the {original} node. | 112 // node is not in a sub-type relation to the type of the the {original} node. |
| 105 Type* const replacement_type = NodeProperties::GetType(replacement); | 113 Type* const replacement_type = NodeProperties::GetType(replacement); |
| 106 Type* const original_type = NodeProperties::GetType(original); | 114 Type* const original_type = NodeProperties::GetType(original); |
| 107 if (!replacement_type->Is(original_type)) { | 115 if (!replacement_type->Is(original_type)) { |
| 108 Node* const control = NodeProperties::GetControlInput(original); | 116 Node* const control = NodeProperties::GetControlInput(original); |
| 109 replacement = jsgraph->graph()->NewNode( | 117 replacement = jsgraph->graph()->NewNode( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 203 |
| 196 Reduction EscapeAnalysisReducer::ReduceReferenceEqual(Node* node) { | 204 Reduction EscapeAnalysisReducer::ReduceReferenceEqual(Node* node) { |
| 197 DCHECK_EQ(node->opcode(), IrOpcode::kReferenceEqual); | 205 DCHECK_EQ(node->opcode(), IrOpcode::kReferenceEqual); |
| 198 Node* left = NodeProperties::GetValueInput(node, 0); | 206 Node* left = NodeProperties::GetValueInput(node, 0); |
| 199 Node* right = NodeProperties::GetValueInput(node, 1); | 207 Node* right = NodeProperties::GetValueInput(node, 1); |
| 200 if (escape_analysis()->IsVirtual(left)) { | 208 if (escape_analysis()->IsVirtual(left)) { |
| 201 if (escape_analysis()->IsVirtual(right) && | 209 if (escape_analysis()->IsVirtual(right) && |
| 202 escape_analysis()->CompareVirtualObjects(left, right)) { | 210 escape_analysis()->CompareVirtualObjects(left, right)) { |
| 203 ReplaceWithValue(node, jsgraph()->TrueConstant()); | 211 ReplaceWithValue(node, jsgraph()->TrueConstant()); |
| 204 TRACE("Replaced ref eq #%d with true\n", node->id()); | 212 TRACE("Replaced ref eq #%d with true\n", node->id()); |
| 205 Replace(jsgraph()->TrueConstant()); | 213 return Replace(jsgraph()->TrueConstant()); |
| 206 } | 214 } |
| 207 // Right-hand side is not a virtual object, or a different one. | 215 // Right-hand side is not a virtual object, or a different one. |
| 208 ReplaceWithValue(node, jsgraph()->FalseConstant()); | 216 ReplaceWithValue(node, jsgraph()->FalseConstant()); |
| 209 TRACE("Replaced ref eq #%d with false\n", node->id()); | 217 TRACE("Replaced ref eq #%d with false\n", node->id()); |
| 210 return Replace(jsgraph()->FalseConstant()); | 218 return Replace(jsgraph()->FalseConstant()); |
| 211 } else if (escape_analysis()->IsVirtual(right)) { | 219 } else if (escape_analysis()->IsVirtual(right)) { |
| 212 // Left-hand side is not a virtual object. | 220 // Left-hand side is not a virtual object. |
| 213 ReplaceWithValue(node, jsgraph()->FalseConstant()); | 221 ReplaceWithValue(node, jsgraph()->FalseConstant()); |
| 214 TRACE("Replaced ref eq #%d with false\n", node->id()); | 222 TRACE("Replaced ref eq #%d with false\n", node->id()); |
| 215 return Replace(jsgraph()->FalseConstant()); | 223 return Replace(jsgraph()->FalseConstant()); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 370 } |
| 363 } | 371 } |
| 364 #endif // DEBUG | 372 #endif // DEBUG |
| 365 } | 373 } |
| 366 | 374 |
| 367 Isolate* EscapeAnalysisReducer::isolate() const { return jsgraph_->isolate(); } | 375 Isolate* EscapeAnalysisReducer::isolate() const { return jsgraph_->isolate(); } |
| 368 | 376 |
| 369 } // namespace compiler | 377 } // namespace compiler |
| 370 } // namespace internal | 378 } // namespace internal |
| 371 } // namespace v8 | 379 } // namespace v8 |
| OLD | NEW |