Commit 9b859a88 authored by sigurds's avatar sigurds Committed by Commit bot

[turbofan] Add TRACE macro for escape analysis

R=jarin@chromium.org
BUG=v8:4586
LOG=n

Review URL: https://codereview.chromium.org/1608073003

Cr-Commit-Position: refs/heads/master@{#33468}
parent 867fc715
...@@ -11,6 +11,15 @@ namespace v8 { ...@@ -11,6 +11,15 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
#ifdef DEBUG
#define TRACE(...) \
do { \
if (FLAG_trace_turbo_escape) PrintF(__VA_ARGS__); \
} while (false)
#else
#define TRACE(...)
#endif // DEBUG
EscapeAnalysisReducer::EscapeAnalysisReducer(Editor* editor, JSGraph* jsgraph, EscapeAnalysisReducer::EscapeAnalysisReducer(Editor* editor, JSGraph* jsgraph,
EscapeAnalysis* escape_analysis, EscapeAnalysis* escape_analysis,
Zone* zone) Zone* zone)
...@@ -89,10 +98,8 @@ Reduction EscapeAnalysisReducer::ReduceLoad(Node* node) { ...@@ -89,10 +98,8 @@ Reduction EscapeAnalysisReducer::ReduceLoad(Node* node) {
if (Node* rep = escape_analysis()->GetReplacement(node)) { if (Node* rep = escape_analysis()->GetReplacement(node)) {
visited_.Add(node->id()); visited_.Add(node->id());
counters()->turbo_escape_loads_replaced()->Increment(); counters()->turbo_escape_loads_replaced()->Increment();
if (FLAG_trace_turbo_escape) { TRACE("Replaced #%d (%s) with #%d (%s)\n", node->id(),
PrintF("Replaced #%d (%s) with #%d (%s)\n", node->id(), node->op()->mnemonic(), rep->id(), rep->op()->mnemonic());
node->op()->mnemonic(), rep->id(), rep->op()->mnemonic());
}
ReplaceWithValue(node, rep); ReplaceWithValue(node, rep);
return Changed(rep); return Changed(rep);
} }
...@@ -106,10 +113,8 @@ Reduction EscapeAnalysisReducer::ReduceStore(Node* node) { ...@@ -106,10 +113,8 @@ Reduction EscapeAnalysisReducer::ReduceStore(Node* node) {
if (visited_.Contains(node->id())) return NoChange(); if (visited_.Contains(node->id())) return NoChange();
visited_.Add(node->id()); visited_.Add(node->id());
if (escape_analysis()->IsVirtual(NodeProperties::GetValueInput(node, 0))) { if (escape_analysis()->IsVirtual(NodeProperties::GetValueInput(node, 0))) {
if (FLAG_trace_turbo_escape) { TRACE("Removed #%d (%s) from effect chain\n", node->id(),
PrintF("Removed #%d (%s) from effect chain\n", node->id(), node->op()->mnemonic());
node->op()->mnemonic());
}
RelaxEffectsAndControls(node); RelaxEffectsAndControls(node);
return Changed(node); return Changed(node);
} }
...@@ -124,9 +129,7 @@ Reduction EscapeAnalysisReducer::ReduceAllocate(Node* node) { ...@@ -124,9 +129,7 @@ Reduction EscapeAnalysisReducer::ReduceAllocate(Node* node) {
if (escape_analysis()->IsVirtual(node)) { if (escape_analysis()->IsVirtual(node)) {
RelaxEffectsAndControls(node); RelaxEffectsAndControls(node);
counters()->turbo_escape_allocs_replaced()->Increment(); counters()->turbo_escape_allocs_replaced()->Increment();
if (FLAG_trace_turbo_escape) { TRACE("Removed allocate #%d from effect chain\n", node->id());
PrintF("Removed allocate #%d from effect chain\n", node->id());
}
return Changed(node); return Changed(node);
} }
return NoChange(); return NoChange();
...@@ -139,6 +142,7 @@ Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) { ...@@ -139,6 +142,7 @@ Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) {
if (effect->opcode() == IrOpcode::kBeginRegion) { if (effect->opcode() == IrOpcode::kBeginRegion) {
RelaxEffectsAndControls(effect); RelaxEffectsAndControls(effect);
RelaxEffectsAndControls(node); RelaxEffectsAndControls(node);
#ifdef DEBUG
if (FLAG_trace_turbo_escape) { if (FLAG_trace_turbo_escape) {
PrintF("Removed region #%d / #%d from effect chain,", effect->id(), PrintF("Removed region #%d / #%d from effect chain,", effect->id(),
node->id()); node->id());
...@@ -148,6 +152,7 @@ Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) { ...@@ -148,6 +152,7 @@ Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) {
} }
PrintF("\n"); PrintF("\n");
} }
#endif // DEBUG
return Changed(node); return Changed(node);
} }
return NoChange(); return NoChange();
...@@ -162,22 +167,16 @@ Reduction EscapeAnalysisReducer::ReduceReferenceEqual(Node* node) { ...@@ -162,22 +167,16 @@ Reduction EscapeAnalysisReducer::ReduceReferenceEqual(Node* node) {
if (escape_analysis()->IsVirtual(right) && if (escape_analysis()->IsVirtual(right) &&
escape_analysis()->CompareVirtualObjects(left, right)) { escape_analysis()->CompareVirtualObjects(left, right)) {
ReplaceWithValue(node, jsgraph()->TrueConstant()); ReplaceWithValue(node, jsgraph()->TrueConstant());
if (FLAG_trace_turbo_escape) { TRACE("Replaced ref eq #%d with true\n", node->id());
PrintF("Replaced ref eq #%d with true\n", node->id());
}
} }
// Right-hand side is not a virtual object, or a different one. // Right-hand side is not a virtual object, or a different one.
ReplaceWithValue(node, jsgraph()->FalseConstant()); ReplaceWithValue(node, jsgraph()->FalseConstant());
if (FLAG_trace_turbo_escape) { TRACE("Replaced ref eq #%d with false\n", node->id());
PrintF("Replaced ref eq #%d with false\n", node->id());
}
return Replace(node); return Replace(node);
} else if (escape_analysis()->IsVirtual(right)) { } else if (escape_analysis()->IsVirtual(right)) {
// Left-hand side is not a virtual object. // Left-hand side is not a virtual object.
ReplaceWithValue(node, jsgraph()->FalseConstant()); ReplaceWithValue(node, jsgraph()->FalseConstant());
if (FLAG_trace_turbo_escape) { TRACE("Replaced ref eq #%d with false\n", node->id());
PrintF("Replaced ref eq #%d with false\n", node->id());
}
} }
return NoChange(); return NoChange();
} }
...@@ -188,9 +187,7 @@ Reduction EscapeAnalysisReducer::ReduceObjectIsSmi(Node* node) { ...@@ -188,9 +187,7 @@ Reduction EscapeAnalysisReducer::ReduceObjectIsSmi(Node* node) {
Node* input = NodeProperties::GetValueInput(node, 0); Node* input = NodeProperties::GetValueInput(node, 0);
if (escape_analysis()->IsVirtual(input)) { if (escape_analysis()->IsVirtual(input)) {
ReplaceWithValue(node, jsgraph()->FalseConstant()); ReplaceWithValue(node, jsgraph()->FalseConstant());
if (FLAG_trace_turbo_escape) { TRACE("Replaced ObjectIsSmi #%d with false\n", node->id());
PrintF("Replaced ObjectIsSmi #%d with false\n", node->id());
}
return Replace(node); return Replace(node);
} }
return NoChange(); return NoChange();
...@@ -227,9 +224,7 @@ Node* EscapeAnalysisReducer::ReduceDeoptState(Node* node, Node* effect, ...@@ -227,9 +224,7 @@ Node* EscapeAnalysisReducer::ReduceDeoptState(Node* node, Node* effect,
visited_.Contains(node->id())) { visited_.Contains(node->id())) {
return nullptr; return nullptr;
} }
if (FLAG_trace_turbo_escape) { TRACE("Reducing %s %d\n", node->op()->mnemonic(), node->id());
PrintF("Reducing %s %d\n", node->op()->mnemonic(), node->id());
}
Node* clone = nullptr; Node* clone = nullptr;
bool node_multiused = node->UseCount() > 1; bool node_multiused = node->UseCount() > 1;
bool multiple_users_rec = multiple_users || node_multiused; bool multiple_users_rec = multiple_users || node_multiused;
...@@ -238,13 +233,9 @@ Node* EscapeAnalysisReducer::ReduceDeoptState(Node* node, Node* effect, ...@@ -238,13 +233,9 @@ Node* EscapeAnalysisReducer::ReduceDeoptState(Node* node, Node* effect,
if (input->opcode() == IrOpcode::kStateValues) { if (input->opcode() == IrOpcode::kStateValues) {
if (Node* ret = ReduceDeoptState(input, effect, multiple_users_rec)) { if (Node* ret = ReduceDeoptState(input, effect, multiple_users_rec)) {
if (node_multiused || (multiple_users && !clone)) { if (node_multiused || (multiple_users && !clone)) {
if (FLAG_trace_turbo_escape) { TRACE(" Cloning #%d", node->id());
PrintF(" Cloning #%d", node->id());
}
node = clone = jsgraph()->graph()->CloneNode(node); node = clone = jsgraph()->graph()->CloneNode(node);
if (FLAG_trace_turbo_escape) { TRACE(" to #%d\n", node->id());
PrintF(" to #%d\n", node->id());
}
node_multiused = false; node_multiused = false;
} }
NodeProperties::ReplaceValueInput(node, ret, i); NodeProperties::ReplaceValueInput(node, ret, i);
...@@ -264,13 +255,9 @@ Node* EscapeAnalysisReducer::ReduceDeoptState(Node* node, Node* effect, ...@@ -264,13 +255,9 @@ Node* EscapeAnalysisReducer::ReduceDeoptState(Node* node, Node* effect,
if (Node* ret = if (Node* ret =
ReduceDeoptState(outer_frame_state, effect, multiple_users_rec)) { ReduceDeoptState(outer_frame_state, effect, multiple_users_rec)) {
if (node_multiused || (multiple_users && !clone)) { if (node_multiused || (multiple_users && !clone)) {
if (FLAG_trace_turbo_escape) { TRACE(" Cloning #%d", node->id());
PrintF(" Cloning #%d", node->id());
}
node = clone = jsgraph()->graph()->CloneNode(node); node = clone = jsgraph()->graph()->CloneNode(node);
if (FLAG_trace_turbo_escape) { TRACE(" to #%d\n", node->id());
PrintF(" to #%d\n", node->id());
}
} }
NodeProperties::ReplaceFrameStateInput(node, 0, ret); NodeProperties::ReplaceFrameStateInput(node, 0, ret);
} }
...@@ -287,10 +274,8 @@ Node* EscapeAnalysisReducer::ReduceStateValueInput(Node* node, int node_index, ...@@ -287,10 +274,8 @@ Node* EscapeAnalysisReducer::ReduceStateValueInput(Node* node, int node_index,
bool already_cloned, bool already_cloned,
bool multiple_users) { bool multiple_users) {
Node* input = NodeProperties::GetValueInput(node, node_index); Node* input = NodeProperties::GetValueInput(node, node_index);
if (FLAG_trace_turbo_escape) { TRACE("Reducing State Input #%d (%s)\n", input->id(),
PrintF("Reducing State Input #%d (%s)\n", input->id(), input->op()->mnemonic());
input->op()->mnemonic());
}
Node* clone = nullptr; Node* clone = nullptr;
if (input->opcode() == IrOpcode::kFinishRegion || if (input->opcode() == IrOpcode::kFinishRegion ||
input->opcode() == IrOpcode::kAllocate) { input->opcode() == IrOpcode::kAllocate) {
...@@ -298,25 +283,19 @@ Node* EscapeAnalysisReducer::ReduceStateValueInput(Node* node, int node_index, ...@@ -298,25 +283,19 @@ Node* EscapeAnalysisReducer::ReduceStateValueInput(Node* node, int node_index,
if (Node* object_state = if (Node* object_state =
escape_analysis()->GetOrCreateObjectState(effect, input)) { escape_analysis()->GetOrCreateObjectState(effect, input)) {
if (node_multiused || (multiple_users && !already_cloned)) { if (node_multiused || (multiple_users && !already_cloned)) {
if (FLAG_trace_turbo_escape) { TRACE("Cloning #%d", node->id());
PrintF("Cloning #%d", node->id());
}
node = clone = jsgraph()->graph()->CloneNode(node); node = clone = jsgraph()->graph()->CloneNode(node);
if (FLAG_trace_turbo_escape) { TRACE(" to #%d\n", node->id());
PrintF(" to #%d\n", node->id());
}
node_multiused = false; node_multiused = false;
already_cloned = true; already_cloned = true;
} }
NodeProperties::ReplaceValueInput(node, object_state, node_index); NodeProperties::ReplaceValueInput(node, object_state, node_index);
if (FLAG_trace_turbo_escape) { TRACE("Replaced state #%d input #%d with object state #%d\n",
PrintF("Replaced state #%d input #%d with object state #%d\n", node->id(), input->id(), object_state->id());
node->id(), input->id(), object_state->id());
}
} else { } else {
if (FLAG_trace_turbo_escape) { TRACE("No object state replacement for #%d at effect #%d available.\n",
PrintF("No object state replacement available.\n"); input->id(), effect->id());
} UNREACHABLE();
} }
} }
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment