Commit 0788c98d authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Remove bloated GraphBuilder base class.

Using the GraphBuilder base class forces each node creation to go
through a virtual function dispatch just for the sake of saving the
duplication of the NewNode helper methods. In total that added up to
saving minus (sic!) six lines of code.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#29799}
parent 937d4efb
......@@ -694,7 +694,6 @@ source_set("v8_base") {
"src/compiler/frame-states.h",
"src/compiler/gap-resolver.cc",
"src/compiler/gap-resolver.h",
"src/compiler/graph-builder.h",
"src/compiler/graph-reducer.cc",
"src/compiler/graph-reducer.h",
"src/compiler/graph-replay.cc",
......
// Copyright 2013 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_GRAPH_BUILDER_H_
#define V8_COMPILER_GRAPH_BUILDER_H_
#include "src/allocation.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/node.h"
#include "src/unique.h"
namespace v8 {
namespace internal {
namespace compiler {
// A common base class for anything that creates nodes in a graph.
class GraphBuilder {
public:
GraphBuilder(Isolate* isolate, Graph* graph)
: isolate_(isolate), graph_(graph) {}
virtual ~GraphBuilder() {}
Node* NewNode(const Operator* op, bool incomplete = false) {
return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete);
}
Node* NewNode(const Operator* op, Node* n1) {
return MakeNode(op, 1, &n1, false);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2) {
Node* buffer[] = {n1, n2};
return MakeNode(op, arraysize(buffer), buffer, false);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) {
Node* buffer[] = {n1, n2, n3};
return MakeNode(op, arraysize(buffer), buffer, false);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
Node* buffer[] = {n1, n2, n3, n4};
return MakeNode(op, arraysize(buffer), buffer, false);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5) {
Node* buffer[] = {n1, n2, n3, n4, n5};
return MakeNode(op, arraysize(buffer), buffer, false);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5, Node* n6) {
Node* nodes[] = {n1, n2, n3, n4, n5, n6};
return MakeNode(op, arraysize(nodes), nodes, false);
}
Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs,
bool incomplete = false) {
return MakeNode(op, value_input_count, value_inputs, incomplete);
}
Isolate* isolate() const { return isolate_; }
Graph* graph() const { return graph_; }
protected:
// Base implementation used by all factory methods.
virtual Node* MakeNode(const Operator* op, int value_input_count,
Node** value_inputs, bool incomplete) = 0;
private:
Isolate* isolate_;
Graph* graph_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_GRAPH_BUILDER_H__
......@@ -15,7 +15,8 @@ RawMachineAssembler::RawMachineAssembler(Isolate* isolate, Graph* graph,
CallDescriptor* call_descriptor,
MachineType word,
MachineOperatorBuilder::Flags flags)
: GraphBuilder(isolate, graph),
: isolate_(isolate),
graph_(graph),
schedule_(new (zone()) Schedule(zone())),
machine_(zone(), word, flags),
common_(zone()),
......@@ -241,10 +242,10 @@ BasicBlock* RawMachineAssembler::CurrentBlock() {
Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
Node** inputs, bool incomplete) {
Node** inputs) {
DCHECK(ScheduleValid());
DCHECK(current_block_ != NULL);
Node* node = graph()->NewNode(op, input_count, inputs, incomplete);
Node* node = graph()->NewNode(op, input_count, inputs);
BasicBlock* block = op->opcode() == IrOpcode::kParameter ? schedule()->start()
: CurrentBlock();
if (op->opcode() != IrOpcode::kReturn) {
......
......@@ -6,7 +6,7 @@
#define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-builder.h"
#include "src/compiler/graph.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
......@@ -21,7 +21,7 @@ class BasicBlock;
class Schedule;
class RawMachineAssembler : public GraphBuilder {
class RawMachineAssembler {
public:
class Label {
public:
......@@ -47,8 +47,10 @@ class RawMachineAssembler : public GraphBuilder {
MachineType word = kMachPtr,
MachineOperatorBuilder::Flags flags =
MachineOperatorBuilder::Flag::kNoFlags);
~RawMachineAssembler() override {}
~RawMachineAssembler() {}
Isolate* isolate() const { return isolate_; }
Graph* graph() const { return graph_; }
Zone* zone() const { return graph()->zone(); }
MachineOperatorBuilder* machine() { return &machine_; }
CommonOperatorBuilder* common() { return &common_; }
......@@ -511,9 +513,46 @@ class RawMachineAssembler : public GraphBuilder {
// MachineAssembler is invalid after export.
Schedule* Export();
Node* NewNode(const Operator* op) {
return MakeNode(op, 0, static_cast<Node**>(NULL));
}
Node* NewNode(const Operator* op, Node* n1) { return MakeNode(op, 1, &n1); }
Node* NewNode(const Operator* op, Node* n1, Node* n2) {
Node* buffer[] = {n1, n2};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) {
Node* buffer[] = {n1, n2, n3};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
Node* buffer[] = {n1, n2, n3, n4};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5) {
Node* buffer[] = {n1, n2, n3, n4, n5};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5, Node* n6) {
Node* nodes[] = {n1, n2, n3, n4, n5, n6};
return MakeNode(op, arraysize(nodes), nodes);
}
Node* NewNode(const Operator* op, int value_input_count,
Node** value_inputs) {
return MakeNode(op, value_input_count, value_inputs);
}
protected:
Node* MakeNode(const Operator* op, int input_count, Node** inputs,
bool incomplete) final;
Node* MakeNode(const Operator* op, int input_count, Node** inputs);
bool ScheduleValid() { return schedule_ != NULL; }
......@@ -527,6 +566,8 @@ class RawMachineAssembler : public GraphBuilder {
BasicBlock* EnsureBlock(Label* label);
BasicBlock* CurrentBlock();
Isolate* isolate_;
Graph* graph_;
Schedule* schedule_;
MachineOperatorBuilder machine_;
CommonOperatorBuilder common_;
......
......@@ -9,7 +9,6 @@
#include "test/cctest/cctest.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-builder.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/operator-properties.h"
......@@ -41,8 +40,7 @@ class GraphAndBuilders {
template <typename ReturnType>
class GraphBuilderTester : public HandleAndZoneScope,
private GraphAndBuilders,
public CallHelper<ReturnType>,
public GraphBuilder {
public CallHelper<ReturnType> {
public:
explicit GraphBuilderTester(MachineType p0 = kMachNone,
MachineType p1 = kMachNone,
......@@ -54,7 +52,6 @@ class GraphBuilderTester : public HandleAndZoneScope,
main_isolate(),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1,
p2, p3, p4)),
GraphBuilder(main_isolate(), main_graph_),
effect_(NULL),
return_(NULL),
parameters_(main_zone()->template NewArray<Node*>(parameter_count())) {
......@@ -69,8 +66,10 @@ class GraphBuilderTester : public HandleAndZoneScope,
return parameters_[index];
}
Isolate* isolate() { return main_isolate(); }
Graph* graph() const { return main_graph_; }
Zone* zone() const { return graph()->zone(); }
Factory* factory() const { return isolate()->factory(); }
Factory* factory() { return isolate()->factory(); }
CommonOperatorBuilder* common() { return &main_common_; }
MachineOperatorBuilder* machine() { return &main_machine_; }
SimplifiedOperatorBuilder* simplified() { return &main_simplified_; }
......@@ -190,9 +189,47 @@ class GraphBuilderTester : public HandleAndZoneScope,
return NewNode(simplified()->StoreElement(access), object, index, value);
}
Node* NewNode(const Operator* op) {
return MakeNode(op, 0, static_cast<Node**>(NULL));
}
Node* NewNode(const Operator* op, Node* n1) { return MakeNode(op, 1, &n1); }
Node* NewNode(const Operator* op, Node* n1, Node* n2) {
Node* buffer[] = {n1, n2};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) {
Node* buffer[] = {n1, n2, n3};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
Node* buffer[] = {n1, n2, n3, n4};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5) {
Node* buffer[] = {n1, n2, n3, n4, n5};
return MakeNode(op, arraysize(buffer), buffer);
}
Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5, Node* n6) {
Node* nodes[] = {n1, n2, n3, n4, n5, n6};
return MakeNode(op, arraysize(nodes), nodes);
}
Node* NewNode(const Operator* op, int value_input_count,
Node** value_inputs) {
return MakeNode(op, value_input_count, value_inputs);
}
protected:
virtual Node* MakeNode(const Operator* op, int value_input_count,
Node** value_inputs, bool incomplete) final {
Node* MakeNode(const Operator* op, int value_input_count,
Node** value_inputs) {
DCHECK(op->ValueInputCount() == value_input_count);
DCHECK(!OperatorProperties::HasContextInput(op));
......@@ -205,8 +242,7 @@ class GraphBuilderTester : public HandleAndZoneScope,
Node* result = NULL;
if (!has_control && !has_effect) {
result =
graph()->NewNode(op, value_input_count, value_inputs, incomplete);
result = graph()->NewNode(op, value_input_count, value_inputs);
} else {
int input_count_with_deps = value_input_count;
if (has_control) ++input_count_with_deps;
......@@ -220,7 +256,7 @@ class GraphBuilderTester : public HandleAndZoneScope,
if (has_control) {
*current_input++ = graph()->start();
}
result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete);
result = graph()->NewNode(op, input_count_with_deps, buffer);
if (has_effect) {
effect_ = result;
}
......
......@@ -486,7 +486,6 @@
"../../src/compiler/frame-states.h",
'../../src/compiler/gap-resolver.cc',
'../../src/compiler/gap-resolver.h',
'../../src/compiler/graph-builder.h',
'../../src/compiler/graph-reducer.cc',
'../../src/compiler/graph-reducer.h',
'../../src/compiler/graph-replay.cc',
......
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