Deprecate LoweringBuilder in favor of Reducer.

R=bmeurer@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23128 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0caf06db
......@@ -505,8 +505,6 @@ source_set("v8_base") {
"src/compiler/linkage-impl.h",
"src/compiler/linkage.cc",
"src/compiler/linkage.h",
"src/compiler/lowering-builder.cc",
"src/compiler/lowering-builder.h",
"src/compiler/machine-node-factory.h",
"src/compiler/machine-operator-reducer.cc",
"src/compiler/machine-operator-reducer.h",
......
......@@ -156,10 +156,8 @@ class KeyedStoreICStubShim : public HydrogenCodeStub {
JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph,
MachineOperatorBuilder* machine,
SourcePositionTable* source_positions)
: LoweringBuilder(jsgraph->graph(), source_positions),
info_(info),
MachineOperatorBuilder* machine)
: info_(info),
jsgraph_(jsgraph),
linkage_(new (jsgraph->zone()) Linkage(info)),
machine_(machine) {}
......@@ -200,7 +198,7 @@ Node* JSGenericLowering::ExternalConstant(ExternalReference ref) {
}
void JSGenericLowering::Lower(Node* node) {
Reduction JSGenericLowering::Reduce(Node* node) {
Node* replacement = NULL;
// Dispatch according to the opcode.
switch (node->opcode()) {
......@@ -213,14 +211,10 @@ void JSGenericLowering::Lower(Node* node) {
#undef DECLARE_CASE
default:
// Nothing to see.
return;
return NoChange();
}
// Nothing to do if lowering was done by patching the existing node.
if (replacement == node) return;
// Iterate through uses of the original node and replace uses accordingly.
UNIMPLEMENTED();
DCHECK_EQ(node, replacement);
return Changed(replacement);
}
......
......@@ -9,8 +9,8 @@
#include "src/allocation.h"
#include "src/compiler/graph.h"
#include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/lowering-builder.h"
#include "src/compiler/opcodes.h"
#include "src/unique.h"
......@@ -28,14 +28,13 @@ class MachineOperatorBuilder;
class Linkage;
// Lowers JS-level operators to runtime and IC calls in the "generic" case.
class JSGenericLowering : public LoweringBuilder {
class JSGenericLowering : public Reducer {
public:
JSGenericLowering(CompilationInfo* info, JSGraph* graph,
MachineOperatorBuilder* machine,
SourcePositionTable* source_positions);
MachineOperatorBuilder* machine);
virtual ~JSGenericLowering() {}
virtual void Lower(Node* node);
virtual Reduction Reduce(Node* node);
protected:
// Dispatched depending on opcode.
......
......@@ -7,7 +7,6 @@
#include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/lowering-builder.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/simplified-operator.h"
......@@ -17,18 +16,15 @@ namespace internal {
namespace compiler {
// Lowers JS-level operators to simplified operators based on types.
class JSTypedLowering : public LoweringBuilder {
class JSTypedLowering : public Reducer {
public:
explicit JSTypedLowering(JSGraph* jsgraph,
SourcePositionTable* source_positions)
: LoweringBuilder(jsgraph->graph(), source_positions),
jsgraph_(jsgraph),
explicit JSTypedLowering(JSGraph* jsgraph)
: jsgraph_(jsgraph),
simplified_(jsgraph->zone()),
machine_(jsgraph->zone()) {}
virtual ~JSTypedLowering() {}
Reduction Reduce(Node* node);
virtual void Lower(Node* node) { Reduce(node); }
virtual Reduction Reduce(Node* node);
JSGraph* jsgraph() { return jsgraph_; }
Graph* graph() { return jsgraph_->graph(); }
......@@ -40,9 +36,7 @@ class JSTypedLowering : public LoweringBuilder {
MachineOperatorBuilder machine_;
Reduction ReplaceEagerly(Node* old, Node* node);
Reduction NoChange() { return Reducer::NoChange(); }
Reduction ReplaceWith(Node* node) { return Reducer::Replace(node); }
Reduction Changed(Node* node) { return Reducer::Changed(node); }
Reduction ReduceJSAdd(Node* node);
Reduction ReduceJSComparison(Node* node);
Reduction ReduceJSEqual(Node* node, bool invert);
......
// Copyright 2014 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/graph-inl.h"
#include "src/compiler/lowering-builder.h"
#include "src/compiler/node-aux-data-inl.h"
#include "src/compiler/node-properties-inl.h"
namespace v8 {
namespace internal {
namespace compiler {
class LoweringBuilder::NodeVisitor : public NullNodeVisitor {
public:
explicit NodeVisitor(LoweringBuilder* lowering) : lowering_(lowering) {}
GenericGraphVisit::Control Post(Node* node) {
if (lowering_->source_positions_ != NULL) {
SourcePositionTable::Scope pos(lowering_->source_positions_, node);
lowering_->Lower(node);
} else {
lowering_->Lower(node);
}
return GenericGraphVisit::CONTINUE;
}
private:
LoweringBuilder* lowering_;
};
LoweringBuilder::LoweringBuilder(Graph* graph,
SourcePositionTable* source_positions)
: graph_(graph), source_positions_(source_positions) {}
void LoweringBuilder::LowerAllNodes() {
NodeVisitor visitor(this);
graph()->VisitNodeInputsFromEnd(&visitor);
}
} // namespace compiler
} // namespace internal
} // namespace v8
// Copyright 2014 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.
#ifndef V8_COMPILER_LOWERING_BUILDER_H_
#define V8_COMPILER_LOWERING_BUILDER_H_
#include "src/v8.h"
#include "src/compiler/graph.h"
namespace v8 {
namespace internal {
namespace compiler {
// TODO(dcarney): rename this class.
class LoweringBuilder {
public:
explicit LoweringBuilder(Graph* graph, SourcePositionTable* source_positions);
virtual ~LoweringBuilder() {}
void LowerAllNodes();
virtual void Lower(Node* node) = 0; // Exposed for testing.
Graph* graph() const { return graph_; }
private:
class NodeVisitor;
Graph* graph_;
SourcePositionTable* source_positions_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_LOWERING_BUILDER_H_
......@@ -211,8 +211,12 @@ Handle<Code> Pipeline::GenerateCode() {
// Lower JSOperators where we can determine types.
PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH,
"typed lowering");
JSTypedLowering lowering(&jsgraph, &source_positions);
lowering.LowerAllNodes();
SourcePositionTable::Scope pos(&source_positions,
SourcePosition::Unknown());
JSTypedLowering lowering(&jsgraph);
GraphReducer graph_reducer(&graph);
graph_reducer.AddReducer(&lowering);
graph_reducer.ReduceGraph();
VerifyAndPrintGraph(&graph, "Lowered typed");
}
......@@ -224,9 +228,13 @@ Handle<Code> Pipeline::GenerateCode() {
// Lower any remaining generic JSOperators.
PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH,
"generic lowering");
SourcePositionTable::Scope pos(&source_positions,
SourcePosition::Unknown());
MachineOperatorBuilder machine(zone());
JSGenericLowering lowering(info(), &jsgraph, &machine, &source_positions);
lowering.LowerAllNodes();
JSGenericLowering lowering(info(), &jsgraph, &machine);
GraphReducer graph_reducer(&graph);
graph_reducer.AddReducer(&lowering);
graph_reducer.ReduceGraph();
VerifyAndPrintGraph(&graph, "Lowered generic");
}
......
......@@ -728,7 +728,9 @@ void SimplifiedLowering::LowerAllNodes() {
RepresentationSelector selector(jsgraph(), zone(), &changer);
selector.Run(this);
LoweringBuilder::LowerAllNodes();
GraphReducer graph_reducer(graph());
graph_reducer.AddReducer(this);
graph_reducer.ReduceGraph();
}
......@@ -963,7 +965,7 @@ void SimplifiedLowering::DoStoreElement(Node* node) {
}
void SimplifiedLowering::Lower(Node* node) {}
Reduction SimplifiedLowering::Reduce(Node* node) { return NoChange(); }
void SimplifiedLowering::LowerChange(Node* node, Node* effect, Node* control) {
......
......@@ -7,7 +7,6 @@
#include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/lowering-builder.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/simplified-operator.h"
......@@ -16,18 +15,15 @@ namespace v8 {
namespace internal {
namespace compiler {
class SimplifiedLowering : public LoweringBuilder {
class SimplifiedLowering : public Reducer {
public:
explicit SimplifiedLowering(JSGraph* jsgraph,
SourcePositionTable* source_positions)
: LoweringBuilder(jsgraph->graph(), source_positions),
jsgraph_(jsgraph),
machine_(jsgraph->zone()) {}
explicit SimplifiedLowering(JSGraph* jsgraph)
: jsgraph_(jsgraph), machine_(jsgraph->zone()) {}
virtual ~SimplifiedLowering() {}
void LowerAllNodes();
virtual void Lower(Node* node);
virtual Reduction Reduce(Node* node);
void LowerChange(Node* node, Node* effect, Node* control);
// TODO(titzer): These are exposed for direct testing. Use a friend class.
......
......@@ -30,13 +30,11 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
explicit ChangesLoweringTester(MachineType p0 = kMachNone)
: GraphBuilderTester<ReturnType>(p0),
typer(this->zone()),
source_positions(this->graph()),
jsgraph(this->graph(), this->common(), &typer),
lowering(&jsgraph, &source_positions),
lowering(&jsgraph),
function(Handle<JSFunction>::null()) {}
Typer typer;
SourcePositionTable source_positions;
JSGraph jsgraph;
SimplifiedLowering lowering;
Handle<JSFunction> function;
......
......@@ -26,7 +26,6 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
common(main_zone()),
graph(main_zone()),
typer(main_zone()),
source_positions(&graph),
context_node(NULL) {
typer.DecorateGraph(&graph);
Node* s = graph.NewNode(common.Start(num_parameters));
......@@ -42,7 +41,6 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
CommonOperatorBuilder common;
Graph graph;
Typer typer;
SourcePositionTable source_positions;
Node* context_node;
Node* Parameter(Type* t, int32_t index = 0) {
......@@ -53,7 +51,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
Node* reduce(Node* node) {
JSGraph jsgraph(&graph, &common, &typer);
JSTypedLowering reducer(&jsgraph, &source_positions);
JSTypedLowering reducer(&jsgraph);
Reduction reduction = reducer.Reduce(node);
if (reduction.Changed()) return reduction.replacement();
return node;
......
......@@ -36,12 +36,10 @@ class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> {
MachineType p4 = kMachNone)
: GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4),
typer(this->zone()),
source_positions(this->graph()),
jsgraph(this->graph(), this->common(), &typer),
lowering(&jsgraph, &source_positions) {}
lowering(&jsgraph) {}
Typer typer;
SourcePositionTable source_positions;
JSGraph jsgraph;
SimplifiedLowering lowering;
......@@ -645,7 +643,7 @@ class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders {
}
void Lower() {
SimplifiedLowering lowering(&jsgraph, NULL);
SimplifiedLowering lowering(&jsgraph);
lowering.LowerAllNodes();
}
......
......@@ -390,8 +390,6 @@
'../../src/compiler/linkage-impl.h',
'../../src/compiler/linkage.cc',
'../../src/compiler/linkage.h',
'../../src/compiler/lowering-builder.cc',
'../../src/compiler/lowering-builder.h',
'../../src/compiler/machine-node-factory.h',
'../../src/compiler/machine-operator-reducer.cc',
'../../src/compiler/machine-operator-reducer.h',
......
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