Commit 7a75da34 authored by Alexandre Talon's avatar Alexandre Talon Committed by Commit Bot

[Turbofan] Enable reducers to report their name to make reducer tracing clearer

Each reducer now has a virtual reducer_name function, returning its name
(the name of the class containing this reducer). This gets displayed when
using the --trace_turbo_reduction flag. Also when using this flags more
messages are displayed.

Actually when a node is replaced in-place (which is called an update
of the node), other reducers can still update it right after the
in-place replacement. When a node is really replaced (not in-place),
then we stop trying to apply reducers to it before we propagate the
reduction through the relevant nodes.

Before a message got printed only for the last reduction it went
through. So in case a node was reduced in-place several times
in a row, only the last update was printed, or none at all if after
being reduced in-place it got reduced by being replaced by another
node: only the non-in-place replacement was showed. 

Now each time an in-place reduction is applied to a node, a message
gets printed.

Bug: 
Change-Id: Id0f816fecd44c01d0253966c6decc4861be0c2fa
Reviewed-on: https://chromium-review.googlesource.com/563365Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Alexandre Talon <alexandret@google.com>
Cr-Commit-Position: refs/heads/master@{#46552}
parent f8a7b0e9
......@@ -23,6 +23,8 @@ class V8_EXPORT_PRIVATE BranchElimination final
BranchElimination(Editor* editor, JSGraph* js_graph, Zone* zone);
~BranchElimination() final;
const char* reducer_name() const override { return "BranchElimination"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -24,6 +24,8 @@ class V8_EXPORT_PRIVATE CheckElimination final
: AdvancedReducer(editor), jsgraph_(jsgraph) {}
~CheckElimination() final {}
const char* reducer_name() const override { return "CheckElimination"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -20,6 +20,8 @@ class V8_EXPORT_PRIVATE CheckpointElimination final
explicit CheckpointElimination(Editor* editor);
~CheckpointElimination() final {}
const char* reducer_name() const override { return "CheckpointElimination"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -29,6 +29,8 @@ class V8_EXPORT_PRIVATE CommonOperatorReducer final
MachineOperatorBuilder* machine);
~CommonOperatorReducer() final {}
const char* reducer_name() const override { return "CommonOperatorReducer"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -28,6 +28,8 @@ class V8_EXPORT_PRIVATE DeadCodeElimination final
CommonOperatorBuilder* common);
~DeadCodeElimination() final {}
const char* reducer_name() const override { return "DeadCodeElimination"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -24,6 +24,8 @@ class V8_EXPORT_PRIVATE EscapeAnalysisReducer final
EscapeAnalysisReducer(Editor* editor, JSGraph* jsgraph,
EscapeAnalysis* escape_analysis, Zone* zone);
const char* reducer_name() const override { return "EscapeAnalysisReducer"; }
Reduction Reduce(Node* node) final;
void Finalize() override;
......
......@@ -89,11 +89,22 @@ Reduction GraphReducer::Reduce(Node* const node) {
// {replacement} == {node} represents an in-place reduction. Rerun
// all the other reducers for this node, as now there may be more
// opportunities for reduction.
if (FLAG_trace_turbo_reduction) {
OFStream os(stdout);
os << "- In-place update of " << *node << " by reducer "
<< (*i)->reducer_name() << std::endl;
}
skip = i;
i = reducers_.begin();
continue;
} else {
// {node} was replaced by another node.
if (FLAG_trace_turbo_reduction) {
OFStream os(stdout);
os << "- Replacement of " << *node << " with "
<< *(reduction.replacement()) << " by reducer "
<< (*i)->reducer_name() << std::endl;
}
return reduction;
}
}
......@@ -146,10 +157,6 @@ void GraphReducer::ReduceTop() {
// Check if the reduction is an in-place update of the {node}.
Node* const replacement = reduction.replacement();
if (replacement == node) {
if (FLAG_trace_turbo_reduction) {
OFStream os(stdout);
os << "- In-place update of " << *replacement << std::endl;
}
// In-place update of {node}, may need to recurse on an input.
Node::Inputs node_inputs = node->inputs();
for (int i = 0; i < node_inputs.count(); ++i) {
......@@ -183,10 +190,6 @@ void GraphReducer::Replace(Node* node, Node* replacement) {
void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) {
if (FLAG_trace_turbo_reduction) {
OFStream os(stdout);
os << "- Replacing " << *node << " with " << *replacement << std::endl;
}
if (node == graph()->start()) graph()->SetStart(replacement);
if (node == graph()->end()) graph()->SetEnd(replacement);
if (replacement->id() <= max_id) {
......
......@@ -46,6 +46,9 @@ class V8_EXPORT_PRIVATE Reducer {
public:
virtual ~Reducer() {}
// Only used for tracing, when using the --trace_turbo_reduction flag.
virtual const char* reducer_name() const = 0;
// Try to reduce a node if possible.
virtual Reduction Reduce(Node* node) = 0;
......
......@@ -42,6 +42,8 @@ class V8_EXPORT_PRIVATE JSBuiltinReducer final
Handle<Context> native_context);
~JSBuiltinReducer() final {}
const char* reducer_name() const override { return "JSBuiltinReducer"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -42,6 +42,8 @@ class JSCallReducer final : public AdvancedReducer {
native_context_(native_context),
dependencies_(dependencies) {}
const char* reducer_name() const override { return "JSCallReducer"; }
Reduction Reduce(Node* node) final;
// Processes the waitlist gathered while the reducer was running,
......
......@@ -40,6 +40,10 @@ class JSContextSpecialization final : public AdvancedReducer {
outer_(outer),
closure_(closure) {}
const char* reducer_name() const override {
return "JSContextSpecialization";
}
Reduction Reduce(Node* node) final;
private:
......
......@@ -44,6 +44,8 @@ class V8_EXPORT_PRIVATE JSCreateLowering final
zone_(zone) {}
~JSCreateLowering() final {}
const char* reducer_name() const override { return "JSCreateLowering"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -25,6 +25,8 @@ class JSFrameSpecialization final : public AdvancedReducer {
: AdvancedReducer(editor), frame_(frame), jsgraph_(jsgraph) {}
~JSFrameSpecialization() final {}
const char* reducer_name() const override { return "JSFrameSpecialization"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -27,6 +27,8 @@ class JSGenericLowering final : public Reducer {
explicit JSGenericLowering(JSGraph* jsgraph);
~JSGenericLowering() final;
const char* reducer_name() const override { return "JSGenericLowering"; }
Reduction Reduce(Node* node) final;
protected:
......
......@@ -24,6 +24,8 @@ class JSInliningHeuristic final : public AdvancedReducer {
seen_(local_zone),
jsgraph_(jsgraph) {}
const char* reducer_name() const override { return "JSInliningHeuristic"; }
Reduction Reduce(Node* node) final;
// Processes the list of candidates gathered while the reducer was running,
......
......@@ -31,6 +31,8 @@ class JSInliner final : public AdvancedReducer {
jsgraph_(jsgraph),
source_positions_(source_positions) {}
const char* reducer_name() const override { return "JSInliner"; }
// Reducer interface, eagerly inlines everything.
Reduction Reduce(Node* node) final;
......
......@@ -37,6 +37,8 @@ class V8_EXPORT_PRIVATE JSIntrinsicLowering final
DeoptimizationMode mode);
~JSIntrinsicLowering() final {}
const char* reducer_name() const override { return "JSIntrinsicLowering"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -50,6 +50,10 @@ class JSNativeContextSpecialization final : public AdvancedReducer {
CompilationDependencies* dependencies,
Zone* zone);
const char* reducer_name() const override {
return "JSNativeContextSpecialization";
}
Reduction Reduce(Node* node) final;
private:
......
......@@ -42,6 +42,8 @@ class V8_EXPORT_PRIVATE JSTypedLowering final
Flags flags, JSGraph* jsgraph, Zone* zone);
~JSTypedLowering() final {}
const char* reducer_name() const override { return "JSTypedLowering"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -32,6 +32,8 @@ class V8_EXPORT_PRIVATE LoadElimination final
: AdvancedReducer(editor), node_states_(zone), jsgraph_(jsgraph) {}
~LoadElimination() final {}
const char* reducer_name() const override { return "LoadElimination"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -28,6 +28,8 @@ class V8_EXPORT_PRIVATE MachineOperatorReducer final
bool allow_signalling_nan = true);
~MachineOperatorReducer();
const char* reducer_name() const override { return "MachineOperatorReducer"; }
Reduction Reduce(Node* node) override;
private:
......
......@@ -485,6 +485,8 @@ class SourcePositionWrapper final : public Reducer {
: reducer_(reducer), table_(table) {}
~SourcePositionWrapper() final {}
const char* reducer_name() const override { return reducer_->reducer_name(); }
Reduction Reduce(Node* node) final {
SourcePosition const pos = table_->GetSourcePosition(node);
SourcePositionTable::Scope position(table_, pos);
......@@ -994,6 +996,7 @@ struct UntyperPhase {
void Run(PipelineData* data, Zone* temp_zone) {
class RemoveTypeReducer final : public Reducer {
public:
const char* reducer_name() const override { return "RemoveTypeReducer"; }
Reduction Reduce(Node* node) final {
if (NodeProperties::IsTyped(node)) {
NodeProperties::RemoveType(node);
......
......@@ -16,6 +16,8 @@ class RedundancyElimination final : public AdvancedReducer {
RedundancyElimination(Editor* editor, Zone* zone);
~RedundancyElimination() final;
const char* reducer_name() const override { return "RedundancyElimination"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -22,6 +22,8 @@ class SelectLowering final : public Reducer {
SelectLowering(Graph* graph, CommonOperatorBuilder* common);
~SelectLowering();
const char* reducer_name() const override { return "SelectLowering"; }
Reduction Reduce(Node* node) override;
private:
......
......@@ -29,6 +29,10 @@ class V8_EXPORT_PRIVATE SimplifiedOperatorReducer final
SimplifiedOperatorReducer(Editor* editor, JSGraph* jsgraph);
~SimplifiedOperatorReducer() final;
const char* reducer_name() const override {
return "SimplifiedOperatorReducer";
}
Reduction Reduce(Node* node) final;
private:
......
......@@ -24,6 +24,8 @@ class V8_EXPORT_PRIVATE TailCallOptimization final : public Reducer {
TailCallOptimization(CommonOperatorBuilder* common, Graph* graph)
: common_(common), graph_(graph) {}
const char* reducer_name() const override { return "TailCallOptimization"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -39,6 +39,8 @@ class V8_EXPORT_PRIVATE TypedOptimization final
Flags flags, JSGraph* jsgraph);
~TypedOptimization();
const char* reducer_name() const override { return "TypedOptimization"; }
Reduction Reduce(Node* node) final;
private:
......
......@@ -73,6 +73,8 @@ class Typer::Visitor : public Reducer {
induction_vars_(induction_vars),
weakened_nodes_(typer->zone()) {}
const char* reducer_name() const override { return "Typer"; }
Reduction Reduce(Node* node) override {
if (node->op()->ValueOutputCount() == 0) return NoChange();
switch (node->opcode()) {
......
......@@ -19,6 +19,8 @@ class V8_EXPORT_PRIVATE ValueNumberingReducer final
explicit ValueNumberingReducer(Zone* temp_zone, Zone* graph_zone);
~ValueNumberingReducer();
const char* reducer_name() const override { return "ValueNumberingReducer"; }
Reduction Reduce(Node* node) override;
private:
......
......@@ -53,6 +53,7 @@ static TestOperator kOpC1(kOpcodeC1, Operator::kNoWrite, "opc1", 1, 0);
static TestOperator kOpC2(kOpcodeC2, Operator::kNoWrite, "opc2", 2, 0);
struct MockReducer : public Reducer {
MOCK_CONST_METHOD0(reducer_name, const char*());
MOCK_METHOD1(Reduce, Reduction(Node*));
};
......@@ -60,6 +61,7 @@ struct MockReducer : public Reducer {
// Replaces all "A" operators with "B" operators without creating new nodes.
class InPlaceABReducer final : public Reducer {
public:
const char* reducer_name() const override { return "InPlaceABReducer"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA0:
......@@ -85,6 +87,8 @@ class NewABReducer final : public Reducer {
public:
explicit NewABReducer(Graph* graph) : graph_(graph) {}
const char* reducer_name() const override { return "NewABReducer"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA0:
......@@ -111,6 +115,8 @@ class A0Wrapper final : public Reducer {
public:
explicit A0Wrapper(Graph* graph) : graph_(graph) {}
const char* reducer_name() const override { return "A0Wrapper"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA0:
......@@ -130,6 +136,8 @@ class B0Wrapper final : public Reducer {
public:
explicit B0Wrapper(Graph* graph) : graph_(graph) {}
const char* reducer_name() const override { return "B0Wrapper"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeB0:
......@@ -147,6 +155,7 @@ class B0Wrapper final : public Reducer {
// Replaces all "kOpA1" nodes with the first input.
class A1Forwarder final : public Reducer {
public:
const char* reducer_name() const override { return "A1Forwarder"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA1:
......@@ -161,6 +170,7 @@ class A1Forwarder final : public Reducer {
// Replaces all "kOpB1" nodes with the first input.
class B1Forwarder final : public Reducer {
public:
const char* reducer_name() const override { return "B1Forwarder"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeB1:
......@@ -175,6 +185,7 @@ class B1Forwarder final : public Reducer {
// Replaces all "B" operators with "C" operators without creating new nodes.
class InPlaceBCReducer final : public Reducer {
public:
const char* reducer_name() const override { return "InPlaceBCReducer"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeB0:
......@@ -198,6 +209,7 @@ class InPlaceBCReducer final : public Reducer {
// Swaps the inputs to "kOp2A" and "kOp2B" nodes based on ids.
class AB2Sorter final : public Reducer {
public:
const char* reducer_name() const override { return "AB2Sorter"; }
Reduction Reduce(Node* node) final {
switch (node->op()->opcode()) {
case kOpcodeA2:
......@@ -233,6 +245,7 @@ class AdvancedReducerTest : public TestWithZone {
TEST_F(AdvancedReducerTest, Replace) {
struct DummyReducer final : public AdvancedReducer {
explicit DummyReducer(Editor* editor) : AdvancedReducer(editor) {}
const char* reducer_name() const override { return "DummyReducer"; }
Reduction Reduce(Node* node) final {
Replace(node, node);
return NoChange();
......@@ -252,6 +265,7 @@ TEST_F(AdvancedReducerTest, Replace) {
TEST_F(AdvancedReducerTest, Revisit) {
struct DummyReducer final : public AdvancedReducer {
explicit DummyReducer(Editor* editor) : AdvancedReducer(editor) {}
const char* reducer_name() const override { return "DummyReducer"; }
Reduction Reduce(Node* node) final {
Revisit(node);
return NoChange();
......@@ -272,6 +286,9 @@ namespace {
struct ReplaceWithValueReducer final : public AdvancedReducer {
explicit ReplaceWithValueReducer(Editor* editor) : AdvancedReducer(editor) {}
const char* reducer_name() const override {
return "ReplaceWithValueReducer";
}
Reduction Reduce(Node* node) final { return NoChange(); }
using AdvancedReducer::ReplaceWithValue;
};
......
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