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"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2015-09-01 10:30:40 +00:00
|
|
|
#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(),
|
2018-07-31 11:12:53 +00:00
|
|
|
canonical_(isolate()),
|
2016-10-10 05:53:31 +00:00
|
|
|
common_(zone()),
|
2017-12-13 08:48:00 +00:00
|
|
|
graph_(zone()),
|
2018-07-23 16:36:52 +00:00
|
|
|
js_heap_broker_(isolate(), zone()),
|
2018-05-18 14:04:36 +00:00
|
|
|
source_positions_(&graph_),
|
|
|
|
node_origins_(&graph_) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-17 11:30:48 +00:00
|
|
|
GraphTest::~GraphTest() = default;
|
2014-08-18 06:54:07 +00:00
|
|
|
|
|
|
|
|
2014-08-22 04:47:55 +00:00
|
|
|
Node* GraphTest::Parameter(int32_t index) {
|
|
|
|
return graph()->NewNode(common()->Parameter(index), graph()->start());
|
|
|
|
}
|
|
|
|
|
2018-09-20 11:15:25 +00:00
|
|
|
Node* GraphTest::Parameter(Type type, int32_t index) {
|
|
|
|
Node* node = GraphTest::Parameter(index);
|
|
|
|
NodeProperties::SetType(node, type);
|
|
|
|
return node;
|
|
|
|
}
|
2014-08-22 04:47:55 +00:00
|
|
|
|
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));
|
2018-06-07 07:03:46 +00:00
|
|
|
Type type = Type::NewConstant(js_heap_broker(), 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)
|
2018-06-07 07:03:46 +00:00
|
|
|
: GraphTest(num_parameters),
|
|
|
|
typer_(isolate(), js_heap_broker(), Typer::kNoFlags, graph()) {}
|
2014-12-22 14:37:16 +00:00
|
|
|
|
2018-09-17 11:30:48 +00:00
|
|
|
TypedGraphTest::~TypedGraphTest() = default;
|
2014-12-22 14:37:16 +00:00
|
|
|
|
2017-10-20 08:35:08 +00:00
|
|
|
namespace graph_unittest {
|
2015-01-16 11:04:01 +00:00
|
|
|
|
|
|
|
const Operator kDummyOperator(0, Operator::kNoProperties, "Dummy", 0, 0, 0, 1,
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2017-10-20 08:35:08 +00:00
|
|
|
} // namespace graph_unittest
|
2014-08-12 08:24:20 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|