Index: src/compiler/escape-analysis-reducer.cc |
diff --git a/src/compiler/escape-analysis-reducer.cc b/src/compiler/escape-analysis-reducer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db5994631278036378def123bbc32a3e72eb46bf |
--- /dev/null |
+++ b/src/compiler/escape-analysis-reducer.cc |
@@ -0,0 +1,186 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/compiler/escape-analysis-reducer.h" |
+ |
+#include "src/compiler/js-graph.h" |
+#include "src/compiler/js-operator.h" |
+ |
+namespace v8 { |
+namespace internal { |
+namespace compiler { |
+ |
+EscapeAnalysisReducer::EscapeAnalysisReducer( |
+ Editor* editor, JSGraph* jsgraph, EscapeStatusAnalysis* escape_status, |
+ EscapeObjectAnalysis* escape_analysis, Zone* zone) |
+ : AdvancedReducer(editor), |
+ jsgraph_(jsgraph), |
+ escape_status_(escape_status), |
+ escape_analysis_(escape_analysis), |
+ zone_(zone) {} |
+ |
+ |
+Reduction EscapeAnalysisReducer::Reduce(Node* node) { |
+ switch (node->opcode()) { |
+ case IrOpcode::kLoadField: |
+ return ReduceLoadField(node); |
+ case IrOpcode::kStoreField: |
+ return ReduceStoreField(node); |
+ case IrOpcode::kAllocate: |
+ return ReduceAllocate(node); |
+ case IrOpcode::kFinishRegion: |
+ return ReduceFinishRegion(node); |
+ case IrOpcode::kReferenceEqual: |
+ return ReduceReferenceEqual(node); |
+ case IrOpcode::kStateValues: |
+ case IrOpcode::kFrameState: |
+ return ReplaceWithDeoptDummy(node); |
+ default: |
+ break; |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
+Reduction EscapeAnalysisReducer::ReduceLoadField(Node* node) { |
+ DCHECK(node->opcode() == IrOpcode::kLoadField); |
Michael Starzinger
2015/11/30 10:05:38
nit: DCHECK_EQ, here and throughout the file.
sigurds
2015/11/30 13:50:23
Done.
|
+ if (Node* rep = escape_analysis()->representation(node, node->id())) { |
Michael Starzinger
2015/11/30 10:05:38
The term "representation" is already pretty overlo
sigurds
2015/11/30 13:50:23
Done.
|
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Replaced #%d with #%d\n", node->id(), rep->id()); |
+ } |
+ ReplaceWithValue(node, rep); |
+ return Changed(rep); |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
+Reduction EscapeAnalysisReducer::ReduceStoreField(Node* node) { |
+ DCHECK(node->opcode() == IrOpcode::kStoreField); |
+ if (escape_status()->IsVirtual(NodeProperties::GetValueInput(node, 0))) { |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Removed store field #%d from effect chain\n", node->id()); |
+ } |
+ RemoveFromEffectChain(node); |
+ return Changed(node); |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
+void EscapeAnalysisReducer::RemoveFromEffectChain(Node* node) { |
Michael Starzinger
2015/11/30 10:05:38
This should be equivalent with calling AdvancedRed
sigurds
2015/11/30 13:50:23
Done.
|
+ Node* effect = NodeProperties::GetEffectInput(node); |
+ for (Edge edge : node->use_edges()) { |
+ if (NodeProperties::IsEffectEdge(edge)) { |
+ DCHECK_NOT_NULL(effect); |
+ edge.UpdateTo(effect); |
+ Revisit(node); |
+ } |
+ } |
+} |
+ |
+ |
+Reduction EscapeAnalysisReducer::ReduceAllocate(Node* node) { |
+ DCHECK(node->opcode() == IrOpcode::kAllocate); |
+ if (escape_status()->IsVirtual(node)) { |
+ RemoveFromEffectChain(node); |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Removed allocate #%d from effect chain\n", node->id()); |
+ } |
+ return Changed(node); |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
+Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) { |
+ DCHECK(node->opcode() == IrOpcode::kFinishRegion); |
+ Node* effect = NodeProperties::GetEffectInput(node, 0); |
+ if (effect->opcode() == IrOpcode::kBeginRegion) { |
+ RemoveFromEffectChain(effect); |
+ Revisit(effect); |
+ RemoveFromEffectChain(node); |
+ Revisit(node); |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Removed region #%d / #%d from effect chain,", effect->id(), |
+ node->id()); |
+ PrintF("%d user(s) of #%d remain(s):", node->UseCount(), node->id()); |
+ for (Edge edge : node->use_edges()) { |
+ PrintF(" #%d", edge.from()->id()); |
+ } |
+ PrintF("\n"); |
+ } |
+ return Changed(node); |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
+Reduction EscapeAnalysisReducer::ReduceReferenceEqual(Node* node) { |
+ DCHECK(node->opcode() == IrOpcode::kReferenceEqual); |
+ Node* left = NodeProperties::GetValueInput(node, 0); |
+ Node* right = NodeProperties::GetValueInput(node, 1); |
+ if (escape_status()->IsVirtual(left)) { |
+ if (escape_status()->IsVirtual(right)) { |
+ if (Node* rep = escape_analysis()->representation(node, left->id())) { |
+ left = rep; |
+ } |
+ if (Node* rep = escape_analysis()->representation(node, right->id())) { |
+ right = rep; |
+ } |
+ // TODO(sigurds): What to do if either is a PHI? |
+ if (left == right) { |
+ ReplaceWithValue(node, jsgraph()->TrueConstant()); |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Replaced ref eq #%d with true\n", node->id()); |
+ } |
+ return Replace(node); |
+ } |
+ } |
+ // Right-hand side is either not virtual, or a different node. |
+ ReplaceWithValue(node, jsgraph()->FalseConstant()); |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Replaced ref eq #%d with false\n", node->id()); |
+ } |
+ return Replace(node); |
+ } else if (escape_status()->IsVirtual(right)) { |
+ // Left-hand side is not a virtual object. |
+ ReplaceWithValue(node, jsgraph()->FalseConstant()); |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Replaced ref eq #%d with false\n", node->id()); |
+ } |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
+Reduction EscapeAnalysisReducer::ReplaceWithDeoptDummy(Node* node) { |
Michael Starzinger
2015/11/30 10:05:38
nit: Let's add a TODO comment here, saying that th
sigurds
2015/11/30 13:50:23
Done.
|
+ DCHECK(node->opcode() == IrOpcode::kStateValues || |
+ node->opcode() == IrOpcode::kFrameState); |
+ Reduction r = NoChange(); |
+ for (int i = 0; i < node->op()->ValueInputCount(); ++i) { |
+ Node* input = NodeProperties::GetValueInput(node, i); |
+ if (input->opcode() == IrOpcode::kFinishRegion || |
+ input->opcode() == IrOpcode::kAllocate || |
+ input->opcode() == IrOpcode::kPhi) { |
+ if (escape_status()->IsVirtual(input)) { |
+ NodeProperties::ReplaceValueInput(node, jsgraph()->UndefinedConstant(), |
+ i); |
+ if (FLAG_trace_turbo_escape) { |
+ PrintF("Replaced state value (#%d) input with dummy\n", node->id()); |
+ } |
+ r = Changed(node); |
+ } |
+ } |
+ } |
+ return r; |
+} |
+ |
+ |
+Graph* EscapeAnalysisReducer::graph() const { return jsgraph()->graph(); } |
Michael Starzinger
2015/11/30 10:05:38
nit: Method seems to be unused, can we drop it?
sigurds
2015/11/30 13:50:23
Done.
|
+ |
+ |
+} // namespace compiler |
+} // namespace internal |
+} // namespace v8 |