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