| 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/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 8 #include "src/counters.h" | 9 #include "src/counters.h" |
| 9 | 10 |
| 10 namespace v8 { | 11 namespace v8 { |
| 11 namespace internal { | 12 namespace internal { |
| 12 namespace compiler { | 13 namespace compiler { |
| 13 | 14 |
| 14 #ifdef DEBUG | 15 #ifdef DEBUG |
| 15 #define TRACE(...) \ | 16 #define TRACE(...) \ |
| 16 do { \ | 17 do { \ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 98 } |
| 98 | 99 |
| 99 | 100 |
| 100 Reduction EscapeAnalysisReducer::ReduceLoad(Node* node) { | 101 Reduction EscapeAnalysisReducer::ReduceLoad(Node* node) { |
| 101 DCHECK(node->opcode() == IrOpcode::kLoadField || | 102 DCHECK(node->opcode() == IrOpcode::kLoadField || |
| 102 node->opcode() == IrOpcode::kLoadElement); | 103 node->opcode() == IrOpcode::kLoadElement); |
| 103 if (node->id() < static_cast<NodeId>(fully_reduced_.length())) { | 104 if (node->id() < static_cast<NodeId>(fully_reduced_.length())) { |
| 104 fully_reduced_.Add(node->id()); | 105 fully_reduced_.Add(node->id()); |
| 105 } | 106 } |
| 106 if (Node* rep = escape_analysis()->GetReplacement(node)) { | 107 if (Node* rep = escape_analysis()->GetReplacement(node)) { |
| 107 counters()->turbo_escape_loads_replaced()->Increment(); | 108 isolate()->counters()->turbo_escape_loads_replaced()->Increment(); |
| 108 TRACE("Replaced #%d (%s) with #%d (%s)\n", node->id(), | 109 TRACE("Replaced #%d (%s) with #%d (%s)\n", node->id(), |
| 109 node->op()->mnemonic(), rep->id(), rep->op()->mnemonic()); | 110 node->op()->mnemonic(), rep->id(), rep->op()->mnemonic()); |
| 110 ReplaceWithValue(node, rep); | 111 ReplaceWithValue(node, rep); |
| 111 return Replace(rep); | 112 return Replace(rep); |
| 112 } | 113 } |
| 113 return NoChange(); | 114 return NoChange(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 | 117 |
| 117 Reduction EscapeAnalysisReducer::ReduceStore(Node* node) { | 118 Reduction EscapeAnalysisReducer::ReduceStore(Node* node) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 130 } | 131 } |
| 131 | 132 |
| 132 | 133 |
| 133 Reduction EscapeAnalysisReducer::ReduceAllocate(Node* node) { | 134 Reduction EscapeAnalysisReducer::ReduceAllocate(Node* node) { |
| 134 DCHECK_EQ(node->opcode(), IrOpcode::kAllocate); | 135 DCHECK_EQ(node->opcode(), IrOpcode::kAllocate); |
| 135 if (node->id() < static_cast<NodeId>(fully_reduced_.length())) { | 136 if (node->id() < static_cast<NodeId>(fully_reduced_.length())) { |
| 136 fully_reduced_.Add(node->id()); | 137 fully_reduced_.Add(node->id()); |
| 137 } | 138 } |
| 138 if (escape_analysis()->IsVirtual(node)) { | 139 if (escape_analysis()->IsVirtual(node)) { |
| 139 RelaxEffectsAndControls(node); | 140 RelaxEffectsAndControls(node); |
| 140 counters()->turbo_escape_allocs_replaced()->Increment(); | 141 isolate()->counters()->turbo_escape_allocs_replaced()->Increment(); |
| 141 TRACE("Removed allocate #%d from effect chain\n", node->id()); | 142 TRACE("Removed allocate #%d from effect chain\n", node->id()); |
| 142 return Changed(node); | 143 return Changed(node); |
| 143 } | 144 } |
| 144 return NoChange(); | 145 return NoChange(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 | 148 |
| 148 Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) { | 149 Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) { |
| 149 DCHECK_EQ(node->opcode(), IrOpcode::kFinishRegion); | 150 DCHECK_EQ(node->opcode(), IrOpcode::kFinishRegion); |
| 150 Node* effect = NodeProperties::GetEffectInput(node, 0); | 151 Node* effect = NodeProperties::GetEffectInput(node, 0); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 TRACE("No object state replacement for #%d at effect #%d available.\n", | 321 TRACE("No object state replacement for #%d at effect #%d available.\n", |
| 321 input->id(), effect->id()); | 322 input->id(), effect->id()); |
| 322 UNREACHABLE(); | 323 UNREACHABLE(); |
| 323 } | 324 } |
| 324 } | 325 } |
| 325 } | 326 } |
| 326 return clone; | 327 return clone; |
| 327 } | 328 } |
| 328 | 329 |
| 329 | 330 |
| 330 Counters* EscapeAnalysisReducer::counters() const { | 331 void EscapeAnalysisReducer::VerifyReplacement() const { |
| 331 return jsgraph_->isolate()->counters(); | 332 #ifdef DEBUG |
| 333 AllNodes all(zone(), jsgraph()->graph()); |
| 334 for (Node* node : all.live) { |
| 335 if (node->opcode() == IrOpcode::kAllocate) { |
| 336 CHECK(!escape_analysis_->IsVirtual(node)); |
| 337 } |
| 338 } |
| 339 #endif // DEBUG |
| 332 } | 340 } |
| 333 | 341 |
| 334 | 342 Isolate* EscapeAnalysisReducer::isolate() const { return jsgraph_->isolate(); } |
| 335 class EscapeAnalysisVerifier final : public AdvancedReducer { | |
| 336 public: | |
| 337 EscapeAnalysisVerifier(Editor* editor, EscapeAnalysis* escape_analysis) | |
| 338 : AdvancedReducer(editor), escape_analysis_(escape_analysis) {} | |
| 339 | |
| 340 Reduction Reduce(Node* node) final { | |
| 341 switch (node->opcode()) { | |
| 342 case IrOpcode::kAllocate: | |
| 343 CHECK(!escape_analysis_->IsVirtual(node)); | |
| 344 break; | |
| 345 default: | |
| 346 break; | |
| 347 } | |
| 348 return NoChange(); | |
| 349 } | |
| 350 | |
| 351 private: | |
| 352 EscapeAnalysis* escape_analysis_; | |
| 353 }; | |
| 354 | |
| 355 void EscapeAnalysisReducer::VerifyReplacement() const { | |
| 356 #ifdef DEBUG | |
| 357 GraphReducer graph_reducer(zone(), jsgraph()->graph()); | |
| 358 EscapeAnalysisVerifier verifier(&graph_reducer, escape_analysis()); | |
| 359 graph_reducer.AddReducer(&verifier); | |
| 360 graph_reducer.ReduceGraph(); | |
| 361 #endif // DEBUG | |
| 362 } | |
| 363 | 343 |
| 364 } // namespace compiler | 344 } // namespace compiler |
| 365 } // namespace internal | 345 } // namespace internal |
| 366 } // namespace v8 | 346 } // namespace v8 |
| OLD | NEW |