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"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/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)
|
2020-07-23 10:06:02 +00:00
|
|
|
: TestWithNativeContextAndZone(kCompressGraphZone),
|
|
|
|
canonical_(isolate()),
|
2016-10-10 05:53:31 +00:00
|
|
|
common_(zone()),
|
2017-12-13 08:48:00 +00:00
|
|
|
graph_(zone()),
|
2020-08-12 14:39:53 +00:00
|
|
|
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()));
|
2019-08-30 09:39:59 +00:00
|
|
|
broker()->SetTargetNativeContextRef(isolate()->native_context());
|
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
|
|
|
|
2022-05-05 18:18:35 +00:00
|
|
|
Node* GraphTest::Float32Constant(float value) {
|
2014-09-22 11:42:10 +00:00
|
|
|
return graph()->NewNode(common()->Float32Constant(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-05 18:18:35 +00:00
|
|
|
Node* GraphTest::Float64Constant(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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-05 18:18:35 +00:00
|
|
|
Node* GraphTest::NumberConstant(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));
|
2020-03-12 07:31:47 +00:00
|
|
|
Type type = Type::Constant(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()));
|
2019-11-21 11:58:16 +00:00
|
|
|
FrameStateFunctionInfo const* function_info =
|
|
|
|
common()->CreateFrameStateFunctionInfo(
|
2021-02-15 13:27:04 +00:00
|
|
|
FrameStateType::kUnoptimizedFunction, 0, 0,
|
2019-11-21 11:58:16 +00:00
|
|
|
Handle<SharedFunctionInfo>());
|
2015-05-28 09:12:50 +00:00
|
|
|
return graph()->NewNode(
|
2021-01-20 12:07:43 +00:00
|
|
|
common()->FrameState(BytecodeOffset::None(),
|
|
|
|
OutputFrameStateCombine::Ignore(), function_info),
|
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)
|
2019-07-16 21:46:08 +00:00
|
|
|
: GraphTest(num_parameters),
|
|
|
|
typer_(broker(), Typer::kNoFlags, graph(), tick_counter()) {}
|
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
|