2014-08-12 08:24:20 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
2014-08-12 08:24:20 +00:00
|
|
|
|
|
|
|
#include "src/compiler/node-properties-inl.h"
|
2014-10-20 11:26:23 +00:00
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
2014-08-12 08:24:20 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2014-09-01 10:26:12 +00:00
|
|
|
GraphTest::GraphTest(int num_parameters) : common_(zone()), graph_(zone()) {
|
2014-08-18 06:54:07 +00:00
|
|
|
graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
|
2015-01-27 14:02:21 +00:00
|
|
|
graph()->SetEnd(graph()->NewNode(common()->End(), graph()->start()));
|
2014-08-18 06:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GraphTest::~GraphTest() {}
|
|
|
|
|
|
|
|
|
2014-08-22 04:47:55 +00:00
|
|
|
Node* GraphTest::Parameter(int32_t index) {
|
|
|
|
return graph()->NewNode(common()->Parameter(index), graph()->start());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-22 11:42:10 +00:00
|
|
|
Node* GraphTest::Float32Constant(volatile float value) {
|
|
|
|
return graph()->NewNode(common()->Float32Constant(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* GraphTest::Float64Constant(volatile double value) {
|
2014-08-22 04:47:55 +00:00
|
|
|
return graph()->NewNode(common()->Float64Constant(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* GraphTest::Int32Constant(int32_t value) {
|
|
|
|
return graph()->NewNode(common()->Int32Constant(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 07:54:09 +00:00
|
|
|
Node* GraphTest::Int64Constant(int64_t value) {
|
|
|
|
return graph()->NewNode(common()->Int64Constant(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-22 11:42:10 +00:00
|
|
|
Node* GraphTest::NumberConstant(volatile double value) {
|
2014-08-22 04:47:55 +00:00
|
|
|
return graph()->NewNode(common()->NumberConstant(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) {
|
|
|
|
return HeapConstant(Unique<HeapObject>::CreateUninitialized(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-04 13:45:05 +00:00
|
|
|
Node* GraphTest::HeapConstant(const Unique<HeapObject>& value) {
|
2014-10-07 07:36:21 +00:00
|
|
|
Node* node = graph()->NewNode(common()->HeapConstant(value));
|
|
|
|
Type* type = Type::Constant(value.handle(), zone());
|
|
|
|
NodeProperties::SetBounds(node, Bounds(type));
|
|
|
|
return node;
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* GraphTest::FalseConstant() {
|
2014-09-04 13:45:05 +00:00
|
|
|
return HeapConstant(
|
|
|
|
Unique<HeapObject>::CreateImmovable(factory()->false_value()));
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* GraphTest::TrueConstant() {
|
2014-09-04 13:45:05 +00:00
|
|
|
return HeapConstant(
|
|
|
|
Unique<HeapObject>::CreateImmovable(factory()->true_value()));
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
Node* GraphTest::UndefinedConstant() {
|
|
|
|
return HeapConstant(
|
|
|
|
Unique<HeapObject>::CreateImmovable(factory()->undefined_value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 04:47:55 +00:00
|
|
|
Matcher<Node*> GraphTest::IsFalseConstant() {
|
2014-09-04 13:45:05 +00:00
|
|
|
return IsHeapConstant(
|
|
|
|
Unique<HeapObject>::CreateImmovable(factory()->false_value()));
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher<Node*> GraphTest::IsTrueConstant() {
|
2014-09-04 13:45:05 +00:00
|
|
|
return IsHeapConstant(
|
|
|
|
Unique<HeapObject>::CreateImmovable(factory()->true_value()));
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 14:37:16 +00:00
|
|
|
|
2015-01-27 14:02:21 +00:00
|
|
|
Matcher<Node*> GraphTest::IsUndefinedConstant() {
|
|
|
|
return IsHeapConstant(
|
|
|
|
Unique<HeapObject>::CreateImmovable(factory()->undefined_value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-22 14:37:16 +00:00
|
|
|
TypedGraphTest::TypedGraphTest(int num_parameters)
|
2015-01-23 15:19:34 +00:00
|
|
|
: GraphTest(num_parameters),
|
|
|
|
typer_(isolate(), graph(), MaybeHandle<Context>()) {}
|
2014-12-22 14:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
TypedGraphTest::~TypedGraphTest() {}
|
|
|
|
|
|
|
|
|
|
|
|
Node* TypedGraphTest::Parameter(Type* type, int32_t index) {
|
|
|
|
Node* node = GraphTest::Parameter(index);
|
|
|
|
NodeProperties::SetBounds(node, Bounds(type));
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2015-01-16 11:04:01 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const Operator kDummyOperator(0, Operator::kNoProperties, "Dummy", 0, 0, 0, 1,
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GraphTest, NewNode) {
|
|
|
|
Node* n0 = graph()->NewNode(&kDummyOperator);
|
|
|
|
Node* n1 = graph()->NewNode(&kDummyOperator);
|
|
|
|
EXPECT_NE(n0, n1);
|
|
|
|
EXPECT_LT(0, n0->id());
|
|
|
|
EXPECT_LT(0, n1->id());
|
|
|
|
EXPECT_NE(n0->id(), n1->id());
|
|
|
|
EXPECT_EQ(&kDummyOperator, n0->op());
|
|
|
|
EXPECT_EQ(&kDummyOperator, n1->op());
|
|
|
|
}
|
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|