Commit 1c43c3ae authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Get rid of overly abstract SimplifiedGraphBuilder.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#29792}
parent d1a6dfaf
......@@ -49,8 +49,6 @@
'compiler/codegen-tester.h',
'compiler/function-tester.h',
'compiler/graph-builder-tester.h',
'compiler/simplified-graph-builder.cc',
'compiler/simplified-graph-builder.h',
'compiler/test-basic-block-profiler.cc',
'compiler/test-branch-combine.cc',
'compiler/test-changes-lowering.cc',
......
......@@ -12,10 +12,10 @@
#include "src/compiler/graph-builder.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/operator-properties.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/simplified-operator.h"
#include "test/cctest/compiler/call-tester.h"
#include "test/cctest/compiler/simplified-graph-builder.h"
namespace v8 {
namespace internal {
......@@ -42,7 +42,7 @@ template <typename ReturnType>
class GraphBuilderTester : public HandleAndZoneScope,
private GraphAndBuilders,
public CallHelper<ReturnType>,
public SimplifiedGraphBuilder {
public GraphBuilder {
public:
explicit GraphBuilderTester(MachineType p0 = kMachNone,
MachineType p1 = kMachNone,
......@@ -54,8 +54,9 @@ class GraphBuilderTester : public HandleAndZoneScope,
main_isolate(),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1,
p2, p3, p4)),
SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_,
&main_machine_, &main_simplified_),
GraphBuilder(main_isolate(), main_graph_),
effect_(NULL),
return_(NULL),
parameters_(main_zone()->template NewArray<Node*>(parameter_count())) {
Begin(static_cast<int>(parameter_count()));
InitParameters();
......@@ -68,9 +69,168 @@ class GraphBuilderTester : public HandleAndZoneScope,
return parameters_[index];
}
Zone* zone() const { return graph()->zone(); }
Factory* factory() const { return isolate()->factory(); }
CommonOperatorBuilder* common() { return &main_common_; }
MachineOperatorBuilder* machine() { return &main_machine_; }
SimplifiedOperatorBuilder* simplified() { return &main_simplified_; }
// Initialize graph and builder.
void Begin(int num_parameters) {
DCHECK(graph()->start() == NULL);
Node* start = graph()->NewNode(common()->Start(num_parameters + 3));
graph()->SetStart(start);
effect_ = start;
}
void Return(Node* value) {
return_ =
graph()->NewNode(common()->Return(), value, effect_, graph()->start());
effect_ = NULL;
}
// Close the graph.
void End() {
Node* end = graph()->NewNode(common()->End(1), return_);
graph()->SetEnd(end);
}
Node* PointerConstant(void* value) {
intptr_t intptr_value = reinterpret_cast<intptr_t>(value);
return kPointerSize == 8 ? NewNode(common()->Int64Constant(intptr_value))
: Int32Constant(static_cast<int>(intptr_value));
}
Node* Int32Constant(int32_t value) {
return NewNode(common()->Int32Constant(value));
}
Node* HeapConstant(Handle<HeapObject> object) {
Unique<HeapObject> val = Unique<HeapObject>::CreateUninitialized(object);
return NewNode(common()->HeapConstant(val));
}
Node* BooleanNot(Node* a) { return NewNode(simplified()->BooleanNot(), a); }
Node* NumberEqual(Node* a, Node* b) {
return NewNode(simplified()->NumberEqual(), a, b);
}
Node* NumberLessThan(Node* a, Node* b) {
return NewNode(simplified()->NumberLessThan(), a, b);
}
Node* NumberLessThanOrEqual(Node* a, Node* b) {
return NewNode(simplified()->NumberLessThanOrEqual(), a, b);
}
Node* NumberAdd(Node* a, Node* b) {
return NewNode(simplified()->NumberAdd(), a, b);
}
Node* NumberSubtract(Node* a, Node* b) {
return NewNode(simplified()->NumberSubtract(), a, b);
}
Node* NumberMultiply(Node* a, Node* b) {
return NewNode(simplified()->NumberMultiply(), a, b);
}
Node* NumberDivide(Node* a, Node* b) {
return NewNode(simplified()->NumberDivide(), a, b);
}
Node* NumberModulus(Node* a, Node* b) {
return NewNode(simplified()->NumberModulus(), a, b);
}
Node* NumberToInt32(Node* a) {
return NewNode(simplified()->NumberToInt32(), a);
}
Node* NumberToUint32(Node* a) {
return NewNode(simplified()->NumberToUint32(), a);
}
Node* StringEqual(Node* a, Node* b) {
return NewNode(simplified()->StringEqual(), a, b);
}
Node* StringLessThan(Node* a, Node* b) {
return NewNode(simplified()->StringLessThan(), a, b);
}
Node* StringLessThanOrEqual(Node* a, Node* b) {
return NewNode(simplified()->StringLessThanOrEqual(), a, b);
}
Node* ChangeTaggedToInt32(Node* a) {
return NewNode(simplified()->ChangeTaggedToInt32(), a);
}
Node* ChangeTaggedToUint32(Node* a) {
return NewNode(simplified()->ChangeTaggedToUint32(), a);
}
Node* ChangeTaggedToFloat64(Node* a) {
return NewNode(simplified()->ChangeTaggedToFloat64(), a);
}
Node* ChangeInt32ToTagged(Node* a) {
return NewNode(simplified()->ChangeInt32ToTagged(), a);
}
Node* ChangeUint32ToTagged(Node* a) {
return NewNode(simplified()->ChangeUint32ToTagged(), a);
}
Node* ChangeFloat64ToTagged(Node* a) {
return NewNode(simplified()->ChangeFloat64ToTagged(), a);
}
Node* ChangeBoolToBit(Node* a) {
return NewNode(simplified()->ChangeBoolToBit(), a);
}
Node* ChangeBitToBool(Node* a) {
return NewNode(simplified()->ChangeBitToBool(), a);
}
Node* LoadField(const FieldAccess& access, Node* object) {
return NewNode(simplified()->LoadField(access), object);
}
Node* StoreField(const FieldAccess& access, Node* object, Node* value) {
return NewNode(simplified()->StoreField(access), object, value);
}
Node* LoadElement(const ElementAccess& access, Node* object, Node* index) {
return NewNode(simplified()->LoadElement(access), object, index);
}
Node* StoreElement(const ElementAccess& access, Node* object, Node* index,
Node* value) {
return NewNode(simplified()->StoreElement(access), object, index, value);
}
protected:
virtual Node* MakeNode(const Operator* op, int value_input_count,
Node** value_inputs, bool incomplete) final {
DCHECK(op->ValueInputCount() == value_input_count);
DCHECK(!OperatorProperties::HasContextInput(op));
DCHECK_EQ(0, OperatorProperties::GetFrameStateInputCount(op));
bool has_control = op->ControlInputCount() == 1;
bool has_effect = op->EffectInputCount() == 1;
DCHECK(op->ControlInputCount() < 2);
DCHECK(op->EffectInputCount() < 2);
Node* result = NULL;
if (!has_control && !has_effect) {
result =
graph()->NewNode(op, value_input_count, value_inputs, incomplete);
} else {
int input_count_with_deps = value_input_count;
if (has_control) ++input_count_with_deps;
if (has_effect) ++input_count_with_deps;
Node** buffer = zone()->template NewArray<Node*>(input_count_with_deps);
memcpy(buffer, value_inputs, kPointerSize * value_input_count);
Node** current_input = buffer + value_input_count;
if (has_effect) {
*current_input++ = effect_;
}
if (has_control) {
*current_input++ = graph()->start();
}
result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete);
if (has_effect) {
effect_ = result;
}
// This graph builder does not support control flow.
CHECK_EQ(0, op->ControlOutputCount());
}
return result;
}
virtual byte* Generate() {
if (!Pipeline::SupportedBackend()) return NULL;
if (code_.is_null()) {
......@@ -92,6 +252,8 @@ class GraphBuilderTester : public HandleAndZoneScope,
size_t parameter_count() const { return this->csig_->parameter_count(); }
private:
Node* effect_;
Node* return_;
Node** parameters_;
MaybeHandle<Code> code_;
};
......
// 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 "test/cctest/compiler/simplified-graph-builder.h"
#include "src/compiler/operator-properties.h"
namespace v8 {
namespace internal {
namespace compiler {
SimplifiedGraphBuilder::SimplifiedGraphBuilder(
Isolate* isolate, Graph* graph, CommonOperatorBuilder* common,
MachineOperatorBuilder* machine, SimplifiedOperatorBuilder* simplified)
: GraphBuilder(isolate, graph),
effect_(NULL),
return_(NULL),
common_(common),
machine_(machine),
simplified_(simplified) {}
void SimplifiedGraphBuilder::Begin(int num_parameters) {
DCHECK(graph()->start() == NULL);
Node* start = graph()->NewNode(common()->Start(num_parameters + 3));
graph()->SetStart(start);
effect_ = start;
}
void SimplifiedGraphBuilder::Return(Node* value) {
return_ =
graph()->NewNode(common()->Return(), value, effect_, graph()->start());
effect_ = NULL;
}
void SimplifiedGraphBuilder::End() {
Node* end = graph()->NewNode(common()->End(1), return_);
graph()->SetEnd(end);
}
Node* SimplifiedGraphBuilder::MakeNode(const Operator* op,
int value_input_count,
Node** value_inputs, bool incomplete) {
DCHECK(op->ValueInputCount() == value_input_count);
DCHECK(!OperatorProperties::HasContextInput(op));
DCHECK_EQ(0, OperatorProperties::GetFrameStateInputCount(op));
bool has_control = op->ControlInputCount() == 1;
bool has_effect = op->EffectInputCount() == 1;
DCHECK(op->ControlInputCount() < 2);
DCHECK(op->EffectInputCount() < 2);
Node* result = NULL;
if (!has_control && !has_effect) {
result = graph()->NewNode(op, value_input_count, value_inputs, incomplete);
} else {
int input_count_with_deps = value_input_count;
if (has_control) ++input_count_with_deps;
if (has_effect) ++input_count_with_deps;
Node** buffer = zone()->NewArray<Node*>(input_count_with_deps);
memcpy(buffer, value_inputs, kPointerSize * value_input_count);
Node** current_input = buffer + value_input_count;
if (has_effect) {
*current_input++ = effect_;
}
if (has_control) {
*current_input++ = graph()->start();
}
result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete);
if (has_effect) {
effect_ = result;
}
// This graph builder does not support control flow.
CHECK_EQ(0, op->ControlOutputCount());
}
return result;
}
} // 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_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_H_
#define V8_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_H_
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-builder.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/simplified-operator.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/call-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
class SimplifiedGraphBuilder : public GraphBuilder {
public:
SimplifiedGraphBuilder(Isolate* isolate, Graph* graph,
CommonOperatorBuilder* common,
MachineOperatorBuilder* machine,
SimplifiedOperatorBuilder* simplified);
virtual ~SimplifiedGraphBuilder() {}
Zone* zone() const { return graph()->zone(); }
CommonOperatorBuilder* common() const { return common_; }
MachineOperatorBuilder* machine() const { return machine_; }
SimplifiedOperatorBuilder* simplified() const { return simplified_; }
// Initialize graph and builder.
void Begin(int num_parameters);
void Return(Node* value);
// Close the graph.
void End();
Node* PointerConstant(void* value) {
intptr_t intptr_value = reinterpret_cast<intptr_t>(value);
return kPointerSize == 8 ? NewNode(common()->Int64Constant(intptr_value))
: Int32Constant(static_cast<int>(intptr_value));
}
Node* Int32Constant(int32_t value) {
return NewNode(common()->Int32Constant(value));
}
Node* HeapConstant(Handle<HeapObject> object) {
Unique<HeapObject> val = Unique<HeapObject>::CreateUninitialized(object);
return NewNode(common()->HeapConstant(val));
}
Node* BooleanNot(Node* a) { return NewNode(simplified()->BooleanNot(), a); }
Node* NumberEqual(Node* a, Node* b) {
return NewNode(simplified()->NumberEqual(), a, b);
}
Node* NumberLessThan(Node* a, Node* b) {
return NewNode(simplified()->NumberLessThan(), a, b);
}
Node* NumberLessThanOrEqual(Node* a, Node* b) {
return NewNode(simplified()->NumberLessThanOrEqual(), a, b);
}
Node* NumberAdd(Node* a, Node* b) {
return NewNode(simplified()->NumberAdd(), a, b);
}
Node* NumberSubtract(Node* a, Node* b) {
return NewNode(simplified()->NumberSubtract(), a, b);
}
Node* NumberMultiply(Node* a, Node* b) {
return NewNode(simplified()->NumberMultiply(), a, b);
}
Node* NumberDivide(Node* a, Node* b) {
return NewNode(simplified()->NumberDivide(), a, b);
}
Node* NumberModulus(Node* a, Node* b) {
return NewNode(simplified()->NumberModulus(), a, b);
}
Node* NumberToInt32(Node* a) {
return NewNode(simplified()->NumberToInt32(), a);
}
Node* NumberToUint32(Node* a) {
return NewNode(simplified()->NumberToUint32(), a);
}
Node* StringEqual(Node* a, Node* b) {
return NewNode(simplified()->StringEqual(), a, b);
}
Node* StringLessThan(Node* a, Node* b) {
return NewNode(simplified()->StringLessThan(), a, b);
}
Node* StringLessThanOrEqual(Node* a, Node* b) {
return NewNode(simplified()->StringLessThanOrEqual(), a, b);
}
Node* ChangeTaggedToInt32(Node* a) {
return NewNode(simplified()->ChangeTaggedToInt32(), a);
}
Node* ChangeTaggedToUint32(Node* a) {
return NewNode(simplified()->ChangeTaggedToUint32(), a);
}
Node* ChangeTaggedToFloat64(Node* a) {
return NewNode(simplified()->ChangeTaggedToFloat64(), a);
}
Node* ChangeInt32ToTagged(Node* a) {
return NewNode(simplified()->ChangeInt32ToTagged(), a);
}
Node* ChangeUint32ToTagged(Node* a) {
return NewNode(simplified()->ChangeUint32ToTagged(), a);
}
Node* ChangeFloat64ToTagged(Node* a) {
return NewNode(simplified()->ChangeFloat64ToTagged(), a);
}
Node* ChangeBoolToBit(Node* a) {
return NewNode(simplified()->ChangeBoolToBit(), a);
}
Node* ChangeBitToBool(Node* a) {
return NewNode(simplified()->ChangeBitToBool(), a);
}
Node* LoadField(const FieldAccess& access, Node* object) {
return NewNode(simplified()->LoadField(access), object);
}
Node* StoreField(const FieldAccess& access, Node* object, Node* value) {
return NewNode(simplified()->StoreField(access), object, value);
}
Node* LoadElement(const ElementAccess& access, Node* object, Node* index) {
return NewNode(simplified()->LoadElement(access), object, index);
}
Node* StoreElement(const ElementAccess& access, Node* object, Node* index,
Node* value) {
return NewNode(simplified()->StoreElement(access), object, index, value);
}
protected:
virtual Node* MakeNode(const Operator* op, int value_input_count,
Node** value_inputs, bool incomplete) final;
private:
Node* effect_;
Node* return_;
CommonOperatorBuilder* common_;
MachineOperatorBuilder* machine_;
SimplifiedOperatorBuilder* simplified_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_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