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
|
|
|
|
2015-01-29 09:17:45 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
2015-09-01 10:30:40 +00:00
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/objects-inl.h" // TODO(everyone): Make typer.h IWYU compliant.
|
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 {
|
|
|
|
|
2016-10-10 05:53:31 +00:00
|
|
|
GraphTest::GraphTest(int num_parameters)
|
|
|
|
: TestWithNativeContext(),
|
|
|
|
TestWithIsolateAndZone(),
|
|
|
|
common_(zone()),
|
|
|
|
graph_(zone()) {
|
2014-08-18 06:54:07 +00:00
|
|
|
graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
|
2015-05-26 10:31:55 +00:00
|
|
|
graph()->SetEnd(graph()->NewNode(common()->End(1), 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) {
|
|
|
|
Node* node = graph()->NewNode(common()->HeapConstant(value));
|
2016-10-13 07:26:26 +00:00
|
|
|
Type* type = Type::NewConstant(value, zone());
|
2015-09-16 11:55:27 +00:00
|
|
|
NodeProperties::SetType(node, type);
|
2014-10-07 07:36:21 +00:00
|
|
|
return node;
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* GraphTest::FalseConstant() {
|
2015-08-31 08:24:52 +00:00
|
|
|
return HeapConstant(factory()->false_value());
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* GraphTest::TrueConstant() {
|
2015-08-31 08:24:52 +00:00
|
|
|
return HeapConstant(factory()->true_value());
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
Node* GraphTest::UndefinedConstant() {
|
2015-08-31 08:24:52 +00:00
|
|
|
return HeapConstant(factory()->undefined_value());
|
2014-10-07 07:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 09:12:50 +00:00
|
|
|
Node* GraphTest::EmptyFrameState() {
|
2017-01-05 10:44:44 +00:00
|
|
|
Node* state_values =
|
|
|
|
graph()->NewNode(common()->StateValues(0, SparseInputMask::Dense()));
|
2015-05-28 09:12:50 +00:00
|
|
|
return graph()->NewNode(
|
2015-06-23 07:17:07 +00:00
|
|
|
common()->FrameState(BailoutId::None(), OutputFrameStateCombine::Ignore(),
|
|
|
|
nullptr),
|
2015-05-28 09:12:50 +00:00
|
|
|
state_values, state_values, state_values, NumberConstant(0),
|
|
|
|
UndefinedConstant(), graph()->start());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 04:47:55 +00:00
|
|
|
Matcher<Node*> GraphTest::IsFalseConstant() {
|
2015-08-31 08:24:52 +00:00
|
|
|
return IsHeapConstant(factory()->false_value());
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher<Node*> GraphTest::IsTrueConstant() {
|
2015-08-31 08:24:52 +00:00
|
|
|
return IsHeapConstant(factory()->true_value());
|
2014-08-22 04:47:55 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 06:36:46 +00:00
|
|
|
Matcher<Node*> GraphTest::IsNullConstant() {
|
|
|
|
return IsHeapConstant(factory()->null_value());
|
|
|
|
}
|
2014-12-22 14:37:16 +00:00
|
|
|
|
2015-01-27 14:02:21 +00:00
|
|
|
Matcher<Node*> GraphTest::IsUndefinedConstant() {
|
2015-08-31 08:24:52 +00:00
|
|
|
return IsHeapConstant(factory()->undefined_value());
|
2015-01-27 14:02:21 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 14:37:16 +00:00
|
|
|
TypedGraphTest::TypedGraphTest(int num_parameters)
|
2016-11-02 09:33:29 +00:00
|
|
|
: GraphTest(num_parameters), typer_(isolate(), Typer::kNoFlags, graph()) {}
|
2014-12-22 14:37:16 +00:00
|
|
|
|
|
|
|
TypedGraphTest::~TypedGraphTest() {}
|
|
|
|
|
|
|
|
|
|
|
|
Node* TypedGraphTest::Parameter(Type* type, int32_t index) {
|
|
|
|
Node* node = GraphTest::Parameter(index);
|
2015-09-16 11:55:27 +00:00
|
|
|
NodeProperties::SetType(node, type);
|
2014-12-22 14:37:16 +00:00
|
|
|
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);
|
2015-06-12 12:03:03 +00:00
|
|
|
EXPECT_LT(0u, n0->id());
|
|
|
|
EXPECT_LT(0u, n1->id());
|
2015-01-16 11:04:01 +00:00
|
|
|
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
|