Commit 4c583fee authored by Benedikt Meurer's avatar Benedikt Meurer

[turbofan] Various cleanups.

- Decouple JSBuiltinReducer from JSTypedLowering.
- Unify JSTypedLowering::ReduceJSToXXX() lowering.
- Cleanup several includes and forward declarations.
- Unify helper methods.

TEST=cctest
R=svenpanne@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25790}
parent c78a6596
...@@ -16,8 +16,10 @@ namespace v8 { ...@@ -16,8 +16,10 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
// Forward declarations.
class GraphDecorator; class GraphDecorator;
class Graph : public ZoneObject { class Graph : public ZoneObject {
public: public:
explicit Graph(Zone* zone); explicit Graph(Zone* zone);
...@@ -28,7 +30,7 @@ class Graph : public ZoneObject { ...@@ -28,7 +30,7 @@ class Graph : public ZoneObject {
// Factories for nodes with static input counts. // Factories for nodes with static input counts.
Node* NewNode(const Operator* op) { Node* NewNode(const Operator* op) {
return NewNode(op, 0, static_cast<Node**>(NULL)); return NewNode(op, 0, static_cast<Node**>(nullptr));
} }
Node* NewNode(const Operator* op, Node* n1) { return NewNode(op, 1, &n1); } Node* NewNode(const Operator* op, Node* n1) { return NewNode(op, 1, &n1); }
Node* NewNode(const Operator* op, Node* n1, Node* n2) { Node* NewNode(const Operator* op, Node* n1, Node* n2) {
...@@ -60,7 +62,7 @@ class Graph : public ZoneObject { ...@@ -60,7 +62,7 @@ class Graph : public ZoneObject {
} }
template <class Visitor> template <class Visitor>
void VisitNodeInputsFromEnd(Visitor* visitor); inline void VisitNodeInputsFromEnd(Visitor* visitor);
Zone* zone() const { return zone_; } Zone* zone() const { return zone_; }
Node* start() const { return start_; } Node* start() const { return start_; }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "src/compiler/diamond.h" #include "src/compiler/diamond.h"
#include "src/compiler/graph-inl.h" #include "src/compiler/graph-inl.h"
#include "src/compiler/js-builtin-reducer.h" #include "src/compiler/js-builtin-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/node-matchers.h" #include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h" #include "src/compiler/node-properties-inl.h"
#include "src/types.h" #include "src/types.h"
...@@ -96,6 +97,10 @@ class JSCallReduction { ...@@ -96,6 +97,10 @@ class JSCallReduction {
}; };
JSBuiltinReducer::JSBuiltinReducer(JSGraph* jsgraph)
: jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
// ECMA-262, section 15.8.2.1. // ECMA-262, section 15.8.2.1.
Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
JSCallReduction r(node); JSCallReduction r(node);
...@@ -232,6 +237,19 @@ Reduction JSBuiltinReducer::Reduce(Node* node) { ...@@ -232,6 +237,19 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
return NoChange(); return NoChange();
} }
Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); }
CommonOperatorBuilder* JSBuiltinReducer::common() const {
return jsgraph()->common();
}
MachineOperatorBuilder* JSBuiltinReducer::machine() const {
return jsgraph()->machine();
}
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -6,30 +6,26 @@ ...@@ -6,30 +6,26 @@
#define V8_COMPILER_JS_BUILTIN_REDUCER_H_ #define V8_COMPILER_JS_BUILTIN_REDUCER_H_
#include "src/compiler/graph-reducer.h" #include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/simplified-operator.h" #include "src/compiler/simplified-operator.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
// Forward declarations.
class CommonOperatorBuilder;
class JSGraph;
class MachineOperatorBuilder;
class JSBuiltinReducer FINAL : public Reducer { class JSBuiltinReducer FINAL : public Reducer {
public: public:
explicit JSBuiltinReducer(JSGraph* jsgraph) explicit JSBuiltinReducer(JSGraph* jsgraph);
: jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} ~JSBuiltinReducer() FINAL {}
virtual ~JSBuiltinReducer() {}
virtual Reduction Reduce(Node* node) OVERRIDE; Reduction Reduce(Node* node) FINAL;
private: private:
JSGraph* jsgraph() const { return jsgraph_; }
Graph* graph() const { return jsgraph_->graph(); }
CommonOperatorBuilder* common() const { return jsgraph_->common(); }
MachineOperatorBuilder* machine() const { return jsgraph_->machine(); }
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
Reduction ReduceMathAbs(Node* node); Reduction ReduceMathAbs(Node* node);
Reduction ReduceMathSqrt(Node* node); Reduction ReduceMathSqrt(Node* node);
Reduction ReduceMathMax(Node* node); Reduction ReduceMathMax(Node* node);
...@@ -38,6 +34,12 @@ class JSBuiltinReducer FINAL : public Reducer { ...@@ -38,6 +34,12 @@ class JSBuiltinReducer FINAL : public Reducer {
Reduction ReduceMathFloor(Node* node); Reduction ReduceMathFloor(Node* node);
Reduction ReduceMathCeil(Node* node); Reduction ReduceMathCeil(Node* node);
JSGraph* jsgraph() const { return jsgraph_; }
Graph* graph() const;
CommonOperatorBuilder* common() const;
MachineOperatorBuilder* machine() const;
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
JSGraph* jsgraph_; JSGraph* jsgraph_;
SimplifiedOperatorBuilder simplified_; SimplifiedOperatorBuilder simplified_;
}; };
......
...@@ -115,6 +115,7 @@ class JSGraph : public ZoneObject { ...@@ -115,6 +115,7 @@ class JSGraph : public ZoneObject {
Graph* graph() { return graph_; } Graph* graph() { return graph_; }
Zone* zone() { return graph()->zone(); } Zone* zone() { return graph()->zone(); }
Isolate* isolate() { return zone()->isolate(); } Isolate* isolate() { return zone()->isolate(); }
Factory* factory() { return isolate()->factory(); }
void GetCachedNodes(NodeVector* nodes); void GetCachedNodes(NodeVector* nodes);
...@@ -140,8 +141,6 @@ class JSGraph : public ZoneObject { ...@@ -140,8 +141,6 @@ class JSGraph : public ZoneObject {
Node* ImmovableHeapConstant(Handle<HeapObject> value); Node* ImmovableHeapConstant(Handle<HeapObject> value);
Node* NumberConstant(double value); Node* NumberConstant(double value);
Factory* factory() { return isolate()->factory(); }
DISALLOW_COPY_AND_ASSIGN(JSGraph); DISALLOW_COPY_AND_ASSIGN(JSGraph);
}; };
......
This diff is collapsed.
...@@ -6,26 +6,26 @@ ...@@ -6,26 +6,26 @@
#define V8_COMPILER_JS_TYPED_LOWERING_H_ #define V8_COMPILER_JS_TYPED_LOWERING_H_
#include "src/compiler/graph-reducer.h" #include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/simplified-operator.h" #include "src/compiler/simplified-operator.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
// Forward declarations.
class CommonOperatorBuilder;
class JSGraph;
class JSOperatorBuilder;
class MachineOperatorBuilder;
// Lowers JS-level operators to simplified operators based on types. // Lowers JS-level operators to simplified operators based on types.
class JSTypedLowering FINAL : public Reducer { class JSTypedLowering FINAL : public Reducer {
public: public:
explicit JSTypedLowering(JSGraph* jsgraph); explicit JSTypedLowering(JSGraph* jsgraph);
~JSTypedLowering() {} ~JSTypedLowering() FINAL {}
Reduction Reduce(Node* node) OVERRIDE; Reduction Reduce(Node* node) FINAL;
JSGraph* jsgraph() { return jsgraph_; }
Graph* graph() { return jsgraph_->graph(); }
Zone* zone() { return jsgraph_->zone(); }
private: private:
friend class JSBinopReduction; friend class JSBinopReduction;
...@@ -41,23 +41,26 @@ class JSTypedLowering FINAL : public Reducer { ...@@ -41,23 +41,26 @@ class JSTypedLowering FINAL : public Reducer {
Reduction ReduceJSStoreContext(Node* node); Reduction ReduceJSStoreContext(Node* node);
Reduction ReduceJSEqual(Node* node, bool invert); Reduction ReduceJSEqual(Node* node, bool invert);
Reduction ReduceJSStrictEqual(Node* node, bool invert); Reduction ReduceJSStrictEqual(Node* node, bool invert);
Reduction ReduceJSToBooleanInput(Node* input);
Reduction ReduceJSToBoolean(Node* node);
Reduction ReduceJSToNumberInput(Node* input); Reduction ReduceJSToNumberInput(Node* input);
Reduction ReduceJSToNumber(Node* node); Reduction ReduceJSToNumber(Node* node);
Reduction ReduceJSToStringInput(Node* input); Reduction ReduceJSToStringInput(Node* input);
Reduction ReduceJSToBooleanInput(Node* input); Reduction ReduceJSToString(Node* node);
Reduction ReduceJSToBoolean(Node* node);
Reduction ReduceNumberBinop(Node* node, const Operator* numberOp); Reduction ReduceNumberBinop(Node* node, const Operator* numberOp);
Reduction ReduceI32Binop(Node* node, bool left_signed, bool right_signed, Reduction ReduceInt32Binop(Node* node, const Operator* intOp);
const Operator* intOp); Reduction ReduceUI32Shift(Node* node, Signedness left_signedness,
Reduction ReduceI32Shift(Node* node, bool left_signed, const Operator* shift_op);
const Operator* shift_op);
Node* Word32Shl(Node* const lhs, int32_t const rhs); Node* Word32Shl(Node* const lhs, int32_t const rhs);
JSOperatorBuilder* javascript() { return jsgraph_->javascript(); } Factory* factory() const;
CommonOperatorBuilder* common() { return jsgraph_->common(); } Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; }
JSOperatorBuilder* javascript() const;
CommonOperatorBuilder* common() const;
SimplifiedOperatorBuilder* simplified() { return &simplified_; } SimplifiedOperatorBuilder* simplified() { return &simplified_; }
MachineOperatorBuilder* machine() { return jsgraph_->machine(); } MachineOperatorBuilder* machine() const;
JSGraph* jsgraph_; JSGraph* jsgraph_;
SimplifiedOperatorBuilder simplified_; SimplifiedOperatorBuilder simplified_;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "src/compiler/graph-visualizer.h" #include "src/compiler/graph-visualizer.h"
#include "src/compiler/instruction.h" #include "src/compiler/instruction.h"
#include "src/compiler/instruction-selector.h" #include "src/compiler/instruction-selector.h"
#include "src/compiler/js-builtin-reducer.h"
#include "src/compiler/js-context-specialization.h" #include "src/compiler/js-context-specialization.h"
#include "src/compiler/js-generic-lowering.h" #include "src/compiler/js-generic-lowering.h"
#include "src/compiler/js-inlining.h" #include "src/compiler/js-inlining.h"
...@@ -417,11 +418,13 @@ struct TypedLoweringPhase { ...@@ -417,11 +418,13 @@ struct TypedLoweringPhase {
SourcePosition::Unknown()); SourcePosition::Unknown());
ValueNumberingReducer vn_reducer(temp_zone); ValueNumberingReducer vn_reducer(temp_zone);
LoadElimination load_elimination; LoadElimination load_elimination;
JSTypedLowering lowering(data->jsgraph()); JSBuiltinReducer builtin_reducer(data->jsgraph());
JSTypedLowering typed_lowering(data->jsgraph());
SimplifiedOperatorReducer simple_reducer(data->jsgraph()); SimplifiedOperatorReducer simple_reducer(data->jsgraph());
GraphReducer graph_reducer(data->graph(), temp_zone); GraphReducer graph_reducer(data->graph(), temp_zone);
graph_reducer.AddReducer(&vn_reducer); graph_reducer.AddReducer(&vn_reducer);
graph_reducer.AddReducer(&lowering); graph_reducer.AddReducer(&builtin_reducer);
graph_reducer.AddReducer(&typed_lowering);
graph_reducer.AddReducer(&load_elimination); graph_reducer.AddReducer(&load_elimination);
graph_reducer.AddReducer(&simple_reducer); graph_reducer.AddReducer(&simple_reducer);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
......
...@@ -231,6 +231,7 @@ namespace internal { ...@@ -231,6 +231,7 @@ namespace internal {
V(Detectable, kDetectableReceiver | kNumber | kName) \ V(Detectable, kDetectableReceiver | kNumber | kName) \
V(Object, kDetectableObject | kUndetectable) \ V(Object, kDetectableObject | kUndetectable) \
V(Receiver, kObject | kProxy) \ V(Receiver, kObject | kProxy) \
V(StringOrReceiver, kString | kReceiver) \
V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \ V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \
kReceiver) \ kReceiver) \
V(NonNumber, kUnique | kString | kInternal) \ V(NonNumber, kUnique | kString | kInternal) \
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/v8.h"
#include "test/cctest/cctest.h"
#include "src/compiler/graph-inl.h" #include "src/compiler/graph-inl.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/js-typed-lowering.h" #include "src/compiler/js-typed-lowering.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-properties-inl.h" #include "src/compiler/node-properties-inl.h"
#include "src/compiler/opcodes.h" #include "src/compiler/opcodes.h"
#include "src/compiler/typer.h" #include "src/compiler/typer.h"
#include "test/cctest/cctest.h"
using namespace v8::internal; using namespace v8::internal;
using namespace v8::internal::compiler; using namespace v8::internal::compiler;
......
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