Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "test/unittests/compiler/graph-unittest.h"
6 :
7 : #include "src/compiler/js-heap-copy-reducer.h"
8 : #include "src/compiler/node-properties.h"
9 : #include "src/heap/factory.h"
10 : #include "src/objects-inl.h" // TODO(everyone): Make typer.h IWYU compliant.
11 : #include "test/unittests/compiler/node-test-utils.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 : namespace compiler {
16 :
17 587 : GraphTest::GraphTest(int num_parameters)
18 : : canonical_(isolate()),
19 : common_(zone()),
20 : graph_(zone()),
21 : broker_(isolate(), zone()),
22 : source_positions_(&graph_),
23 2348 : node_origins_(&graph_) {
24 587 : graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
25 587 : graph()->SetEnd(graph()->NewNode(common()->End(1), graph()->start()));
26 587 : broker()->SetNativeContextRef();
27 587 : }
28 :
29 :
30 : GraphTest::~GraphTest() = default;
31 :
32 :
33 33754 : Node* GraphTest::Parameter(int32_t index) {
34 67508 : return graph()->NewNode(common()->Parameter(index), graph()->start());
35 : }
36 :
37 995 : Node* GraphTest::Parameter(Type type, int32_t index) {
38 995 : Node* node = GraphTest::Parameter(index);
39 : NodeProperties::SetType(node, type);
40 995 : return node;
41 : }
42 :
43 109 : Node* GraphTest::Float32Constant(volatile float value) {
44 327 : return graph()->NewNode(common()->Float32Constant(value));
45 : }
46 :
47 :
48 114606 : Node* GraphTest::Float64Constant(volatile double value) {
49 343818 : return graph()->NewNode(common()->Float64Constant(value));
50 : }
51 :
52 :
53 323291 : Node* GraphTest::Int32Constant(int32_t value) {
54 646582 : return graph()->NewNode(common()->Int32Constant(value));
55 : }
56 :
57 :
58 256 : Node* GraphTest::Int64Constant(int64_t value) {
59 512 : return graph()->NewNode(common()->Int64Constant(value));
60 : }
61 :
62 :
63 11197 : Node* GraphTest::NumberConstant(volatile double value) {
64 33591 : return graph()->NewNode(common()->NumberConstant(value));
65 : }
66 :
67 :
68 10869 : Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) {
69 10869 : Node* node = graph()->NewNode(common()->HeapConstant(value));
70 10869 : Type type = Type::NewConstant(broker(), value, zone());
71 : NodeProperties::SetType(node, type);
72 10869 : return node;
73 : }
74 :
75 :
76 9 : Node* GraphTest::FalseConstant() {
77 9 : return HeapConstant(factory()->false_value());
78 : }
79 :
80 :
81 9 : Node* GraphTest::TrueConstant() {
82 9 : return HeapConstant(factory()->true_value());
83 : }
84 :
85 :
86 116 : Node* GraphTest::UndefinedConstant() {
87 10791 : return HeapConstant(factory()->undefined_value());
88 : }
89 :
90 :
91 10675 : Node* GraphTest::EmptyFrameState() {
92 : Node* state_values =
93 10675 : graph()->NewNode(common()->StateValues(0, SparseInputMask::Dense()));
94 10675 : return graph()->NewNode(
95 : common()->FrameState(BailoutId::None(), OutputFrameStateCombine::Ignore(),
96 : nullptr),
97 : state_values, state_values, state_values, NumberConstant(0),
98 10675 : UndefinedConstant(), graph()->start());
99 : }
100 :
101 :
102 88 : Matcher<Node*> GraphTest::IsFalseConstant() {
103 88 : return IsHeapConstant(factory()->false_value());
104 : }
105 :
106 :
107 33 : Matcher<Node*> GraphTest::IsTrueConstant() {
108 33 : return IsHeapConstant(factory()->true_value());
109 : }
110 :
111 1 : Matcher<Node*> GraphTest::IsNullConstant() {
112 1 : return IsHeapConstant(factory()->null_value());
113 : }
114 :
115 0 : Matcher<Node*> GraphTest::IsUndefinedConstant() {
116 0 : return IsHeapConstant(factory()->undefined_value());
117 : }
118 :
119 238 : TypedGraphTest::TypedGraphTest(int num_parameters)
120 476 : : GraphTest(num_parameters), typer_(broker(), Typer::kNoFlags, graph()) {}
121 :
122 : TypedGraphTest::~TypedGraphTest() = default;
123 :
124 : namespace graph_unittest {
125 :
126 6176 : const Operator kDummyOperator(0, Operator::kNoProperties, "Dummy", 0, 0, 0, 1,
127 3088 : 0, 0);
128 :
129 :
130 15443 : TEST_F(GraphTest, NewNode) {
131 1 : Node* n0 = graph()->NewNode(&kDummyOperator);
132 1 : Node* n1 = graph()->NewNode(&kDummyOperator);
133 1 : EXPECT_NE(n0, n1);
134 2 : EXPECT_LT(0u, n0->id());
135 2 : EXPECT_LT(0u, n1->id());
136 3 : EXPECT_NE(n0->id(), n1->id());
137 2 : EXPECT_EQ(&kDummyOperator, n0->op());
138 2 : EXPECT_EQ(&kDummyOperator, n1->op());
139 1 : }
140 :
141 : } // namespace graph_unittest
142 : } // namespace compiler
143 : } // namespace internal
144 9264 : } // namespace v8
|