summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/compiler/graph-unittest.cc
blob: 9da3950e5499ebae4c1f82ce2613c76113cf37e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// 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.

#include "test/unittests/compiler/graph-unittest.h"

#include "src/compiler/node-properties.h"
#include "test/unittests/compiler/node-test-utils.h"

namespace v8 {
namespace internal {
namespace compiler {

GraphTest::GraphTest(int num_parameters) : common_(zone()), graph_(zone()) {
  graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
  graph()->SetEnd(graph()->NewNode(common()->End(), graph()->start()));
}


GraphTest::~GraphTest() {}


Node* GraphTest::Parameter(int32_t index) {
  return graph()->NewNode(common()->Parameter(index), graph()->start());
}


Node* GraphTest::Float32Constant(volatile float value) {
  return graph()->NewNode(common()->Float32Constant(value));
}


Node* GraphTest::Float64Constant(volatile double value) {
  return graph()->NewNode(common()->Float64Constant(value));
}


Node* GraphTest::Int32Constant(int32_t value) {
  return graph()->NewNode(common()->Int32Constant(value));
}


Node* GraphTest::Int64Constant(int64_t value) {
  return graph()->NewNode(common()->Int64Constant(value));
}


Node* GraphTest::NumberConstant(volatile double value) {
  return graph()->NewNode(common()->NumberConstant(value));
}


Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) {
  return HeapConstant(Unique<HeapObject>::CreateUninitialized(value));
}


Node* GraphTest::HeapConstant(const Unique<HeapObject>& value) {
  Node* node = graph()->NewNode(common()->HeapConstant(value));
  Type* type = Type::Constant(value.handle(), zone());
  NodeProperties::SetBounds(node, Bounds(type));
  return node;
}


Node* GraphTest::FalseConstant() {
  return HeapConstant(
      Unique<HeapObject>::CreateImmovable(factory()->false_value()));
}


Node* GraphTest::TrueConstant() {
  return HeapConstant(
      Unique<HeapObject>::CreateImmovable(factory()->true_value()));
}


Node* GraphTest::UndefinedConstant() {
  return HeapConstant(
      Unique<HeapObject>::CreateImmovable(factory()->undefined_value()));
}


Matcher<Node*> GraphTest::IsFalseConstant() {
  return IsHeapConstant(
      Unique<HeapObject>::CreateImmovable(factory()->false_value()));
}


Matcher<Node*> GraphTest::IsTrueConstant() {
  return IsHeapConstant(
      Unique<HeapObject>::CreateImmovable(factory()->true_value()));
}


Matcher<Node*> GraphTest::IsUndefinedConstant() {
  return IsHeapConstant(
      Unique<HeapObject>::CreateImmovable(factory()->undefined_value()));
}


TypedGraphTest::TypedGraphTest(int num_parameters)
    : GraphTest(num_parameters),
      typer_(isolate(), graph(), MaybeHandle<Context>()) {}


TypedGraphTest::~TypedGraphTest() {}


Node* TypedGraphTest::Parameter(Type* type, int32_t index) {
  Node* node = GraphTest::Parameter(index);
  NodeProperties::SetBounds(node, Bounds(type));
  return node;
}


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());
}

}  // namespace compiler
}  // namespace internal
}  // namespace v8